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"
40 #include "dwarf2/dwz.h"
41 #include "dwarf2/macro.h"
42 #include "dwarf2/die.h"
43 #include "dwarf2/stringify.h"
52 #include "gdb-demangle.h"
53 #include "filenames.h" /* for DOSish file names */
55 #include "complaints.h"
56 #include "dwarf2/expr.h"
57 #include "dwarf2/loc.h"
58 #include "cp-support.h"
64 #include "typeprint.h"
69 #include "gdbcore.h" /* for gnutarget */
70 #include "gdb/gdb-index.h"
75 #include "namespace.h"
76 #include "gdbsupport/function-view.h"
77 #include "gdbsupport/gdb_optional.h"
78 #include "gdbsupport/underlying.h"
79 #include "gdbsupport/hash_enum.h"
80 #include "filename-seen-cache.h"
84 #include <unordered_map>
85 #include "gdbsupport/selftest.h"
86 #include "rust-lang.h"
87 #include "gdbsupport/pathstuff.h"
88 #include "count-one-bits.h"
89 #include "debuginfod-support.h"
91 /* When == 1, print basic high level tracing messages.
92 When > 1, be more verbose.
93 This is in contrast to the low level DIE reading of dwarf_die_debug. */
94 static unsigned int dwarf_read_debug
= 0;
96 /* When non-zero, dump DIEs after they are read in. */
97 static unsigned int dwarf_die_debug
= 0;
99 /* When non-zero, dump line number entries as they are read in. */
100 unsigned int dwarf_line_debug
= 0;
102 /* When true, cross-check physname against demangler. */
103 static bool check_physname
= false;
105 /* When true, do not reject deprecated .gdb_index sections. */
106 static bool use_deprecated_index_sections
= false;
108 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
110 /* The "aclass" indices for various kinds of computed DWARF symbols. */
112 static int dwarf2_locexpr_index
;
113 static int dwarf2_loclist_index
;
114 static int dwarf2_locexpr_block_index
;
115 static int dwarf2_loclist_block_index
;
117 /* An index into a (C++) symbol name component in a symbol name as
118 recorded in the mapped_index's symbol table. For each C++ symbol
119 in the symbol table, we record one entry for the start of each
120 component in the symbol in a table of name components, and then
121 sort the table, in order to be able to binary search symbol names,
122 ignoring leading namespaces, both completion and regular look up.
123 For example, for symbol "A::B::C", we'll have an entry that points
124 to "A::B::C", another that points to "B::C", and another for "C".
125 Note that function symbols in GDB index have no parameter
126 information, just the function/method names. You can convert a
127 name_component to a "const char *" using the
128 'mapped_index::symbol_name_at(offset_type)' method. */
130 struct name_component
132 /* Offset in the symbol name where the component starts. Stored as
133 a (32-bit) offset instead of a pointer to save memory and improve
134 locality on 64-bit architectures. */
135 offset_type name_offset
;
137 /* The symbol's index in the symbol and constant pool tables of a
142 /* Base class containing bits shared by both .gdb_index and
143 .debug_name indexes. */
145 struct mapped_index_base
147 mapped_index_base () = default;
148 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
150 /* The name_component table (a sorted vector). See name_component's
151 description above. */
152 std::vector
<name_component
> name_components
;
154 /* How NAME_COMPONENTS is sorted. */
155 enum case_sensitivity name_components_casing
;
157 /* Return the number of names in the symbol table. */
158 virtual size_t symbol_name_count () const = 0;
160 /* Get the name of the symbol at IDX in the symbol table. */
161 virtual const char *symbol_name_at (offset_type idx
) const = 0;
163 /* Return whether the name at IDX in the symbol table should be
165 virtual bool symbol_name_slot_invalid (offset_type idx
) const
170 /* Build the symbol name component sorted vector, if we haven't
172 void build_name_components ();
174 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
175 possible matches for LN_NO_PARAMS in the name component
177 std::pair
<std::vector
<name_component
>::const_iterator
,
178 std::vector
<name_component
>::const_iterator
>
179 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
180 enum language lang
) const;
182 /* Prevent deleting/destroying via a base class pointer. */
184 ~mapped_index_base() = default;
187 /* A description of the mapped index. The file format is described in
188 a comment by the code that writes the index. */
189 struct mapped_index final
: public mapped_index_base
191 /* A slot/bucket in the symbol table hash. */
192 struct symbol_table_slot
194 const offset_type name
;
195 const offset_type vec
;
198 /* Index data format version. */
201 /* The address table data. */
202 gdb::array_view
<const gdb_byte
> address_table
;
204 /* The symbol table, implemented as a hash table. */
205 gdb::array_view
<symbol_table_slot
> symbol_table
;
207 /* A pointer to the constant pool. */
208 const char *constant_pool
= nullptr;
210 bool symbol_name_slot_invalid (offset_type idx
) const override
212 const auto &bucket
= this->symbol_table
[idx
];
213 return bucket
.name
== 0 && bucket
.vec
== 0;
216 /* Convenience method to get at the name of the symbol at IDX in the
218 const char *symbol_name_at (offset_type idx
) const override
219 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
221 size_t symbol_name_count () const override
222 { return this->symbol_table
.size (); }
225 /* A description of the mapped .debug_names.
226 Uninitialized map has CU_COUNT 0. */
227 struct mapped_debug_names final
: public mapped_index_base
229 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
230 : dwarf2_per_objfile (dwarf2_per_objfile_
)
233 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
234 bfd_endian dwarf5_byte_order
;
235 bool dwarf5_is_dwarf64
;
236 bool augmentation_is_gdb
;
238 uint32_t cu_count
= 0;
239 uint32_t tu_count
, bucket_count
, name_count
;
240 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
241 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
242 const gdb_byte
*name_table_string_offs_reordered
;
243 const gdb_byte
*name_table_entry_offs_reordered
;
244 const gdb_byte
*entry_pool
;
251 /* Attribute name DW_IDX_*. */
254 /* Attribute form DW_FORM_*. */
257 /* Value if FORM is DW_FORM_implicit_const. */
258 LONGEST implicit_const
;
260 std::vector
<attr
> attr_vec
;
263 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
265 const char *namei_to_name (uint32_t namei
) const;
267 /* Implementation of the mapped_index_base virtual interface, for
268 the name_components cache. */
270 const char *symbol_name_at (offset_type idx
) const override
271 { return namei_to_name (idx
); }
273 size_t symbol_name_count () const override
274 { return this->name_count
; }
277 /* See dwarf2read.h. */
280 get_dwarf2_per_objfile (struct objfile
*objfile
)
282 return dwarf2_objfile_data_key
.get (objfile
);
285 /* Default names of the debugging sections. */
287 /* Note that if the debugging section has been compressed, it might
288 have a name like .zdebug_info. */
290 static const struct dwarf2_debug_sections dwarf2_elf_names
=
292 { ".debug_info", ".zdebug_info" },
293 { ".debug_abbrev", ".zdebug_abbrev" },
294 { ".debug_line", ".zdebug_line" },
295 { ".debug_loc", ".zdebug_loc" },
296 { ".debug_loclists", ".zdebug_loclists" },
297 { ".debug_macinfo", ".zdebug_macinfo" },
298 { ".debug_macro", ".zdebug_macro" },
299 { ".debug_str", ".zdebug_str" },
300 { ".debug_str_offsets", ".zdebug_str_offsets" },
301 { ".debug_line_str", ".zdebug_line_str" },
302 { ".debug_ranges", ".zdebug_ranges" },
303 { ".debug_rnglists", ".zdebug_rnglists" },
304 { ".debug_types", ".zdebug_types" },
305 { ".debug_addr", ".zdebug_addr" },
306 { ".debug_frame", ".zdebug_frame" },
307 { ".eh_frame", NULL
},
308 { ".gdb_index", ".zgdb_index" },
309 { ".debug_names", ".zdebug_names" },
310 { ".debug_aranges", ".zdebug_aranges" },
314 /* List of DWO/DWP sections. */
316 static const struct dwop_section_names
318 struct dwarf2_section_names abbrev_dwo
;
319 struct dwarf2_section_names info_dwo
;
320 struct dwarf2_section_names line_dwo
;
321 struct dwarf2_section_names loc_dwo
;
322 struct dwarf2_section_names loclists_dwo
;
323 struct dwarf2_section_names macinfo_dwo
;
324 struct dwarf2_section_names macro_dwo
;
325 struct dwarf2_section_names str_dwo
;
326 struct dwarf2_section_names str_offsets_dwo
;
327 struct dwarf2_section_names types_dwo
;
328 struct dwarf2_section_names cu_index
;
329 struct dwarf2_section_names tu_index
;
333 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
334 { ".debug_info.dwo", ".zdebug_info.dwo" },
335 { ".debug_line.dwo", ".zdebug_line.dwo" },
336 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
337 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
338 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
339 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
340 { ".debug_str.dwo", ".zdebug_str.dwo" },
341 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
342 { ".debug_types.dwo", ".zdebug_types.dwo" },
343 { ".debug_cu_index", ".zdebug_cu_index" },
344 { ".debug_tu_index", ".zdebug_tu_index" },
347 /* local data types */
349 /* Type used for delaying computation of method physnames.
350 See comments for compute_delayed_physnames. */
351 struct delayed_method_info
353 /* The type to which the method is attached, i.e., its parent class. */
356 /* The index of the method in the type's function fieldlists. */
359 /* The index of the method in the fieldlist. */
362 /* The name of the DIE. */
365 /* The DIE associated with this method. */
366 struct die_info
*die
;
369 /* Internal state when decoding a particular compilation unit. */
372 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
375 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
377 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
378 Create the set of symtabs used by this TU, or if this TU is sharing
379 symtabs with another TU and the symtabs have already been created
380 then restore those symtabs in the line header.
381 We don't need the pc/line-number mapping for type units. */
382 void setup_type_unit_groups (struct die_info
*die
);
384 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
385 buildsym_compunit constructor. */
386 struct compunit_symtab
*start_symtab (const char *name
,
387 const char *comp_dir
,
390 /* Reset the builder. */
391 void reset_builder () { m_builder
.reset (); }
393 /* The header of the compilation unit. */
394 struct comp_unit_head header
{};
396 /* Base address of this compilation unit. */
397 gdb::optional
<CORE_ADDR
> base_address
;
399 /* The language we are debugging. */
400 enum language language
= language_unknown
;
401 const struct language_defn
*language_defn
= nullptr;
403 const char *producer
= nullptr;
406 /* The symtab builder for this CU. This is only non-NULL when full
407 symbols are being read. */
408 std::unique_ptr
<buildsym_compunit
> m_builder
;
411 /* The generic symbol table building routines have separate lists for
412 file scope symbols and all all other scopes (local scopes). So
413 we need to select the right one to pass to add_symbol_to_list().
414 We do it by keeping a pointer to the correct list in list_in_scope.
416 FIXME: The original dwarf code just treated the file scope as the
417 first local scope, and all other local scopes as nested local
418 scopes, and worked fine. Check to see if we really need to
419 distinguish these in buildsym.c. */
420 struct pending
**list_in_scope
= nullptr;
422 /* Hash table holding all the loaded partial DIEs
423 with partial_die->offset.SECT_OFF as hash. */
424 htab_t partial_dies
= nullptr;
426 /* Storage for things with the same lifetime as this read-in compilation
427 unit, including partial DIEs. */
428 auto_obstack comp_unit_obstack
;
430 /* When multiple dwarf2_cu structures are living in memory, this field
431 chains them all together, so that they can be released efficiently.
432 We will probably also want a generation counter so that most-recently-used
433 compilation units are cached... */
434 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
436 /* Backlink to our per_cu entry. */
437 struct dwarf2_per_cu_data
*per_cu
;
439 /* How many compilation units ago was this CU last referenced? */
442 /* A hash table of DIE cu_offset for following references with
443 die_info->offset.sect_off as hash. */
444 htab_t die_hash
= nullptr;
446 /* Full DIEs if read in. */
447 struct die_info
*dies
= nullptr;
449 /* A set of pointers to dwarf2_per_cu_data objects for compilation
450 units referenced by this one. Only set during full symbol processing;
451 partial symbol tables do not have dependencies. */
452 htab_t dependencies
= nullptr;
454 /* Header data from the line table, during full symbol processing. */
455 struct line_header
*line_header
= nullptr;
456 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
457 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
458 this is the DW_TAG_compile_unit die for this CU. We'll hold on
459 to the line header as long as this DIE is being processed. See
460 process_die_scope. */
461 die_info
*line_header_die_owner
= nullptr;
463 /* A list of methods which need to have physnames computed
464 after all type information has been read. */
465 std::vector
<delayed_method_info
> method_list
;
467 /* To be copied to symtab->call_site_htab. */
468 htab_t call_site_htab
= nullptr;
470 /* Non-NULL if this CU came from a DWO file.
471 There is an invariant here that is important to remember:
472 Except for attributes copied from the top level DIE in the "main"
473 (or "stub") file in preparation for reading the DWO file
474 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
475 Either there isn't a DWO file (in which case this is NULL and the point
476 is moot), or there is and either we're not going to read it (in which
477 case this is NULL) or there is and we are reading it (in which case this
479 struct dwo_unit
*dwo_unit
= nullptr;
481 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
482 Note this value comes from the Fission stub CU/TU's DIE. */
483 gdb::optional
<ULONGEST
> addr_base
;
485 /* The DW_AT_rnglists_base attribute if present.
486 Note this value comes from the Fission stub CU/TU's DIE.
487 Also note that the value is zero in the non-DWO case so this value can
488 be used without needing to know whether DWO files are in use or not.
489 N.B. This does not apply to DW_AT_ranges appearing in
490 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
491 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
492 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
493 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
494 ULONGEST ranges_base
= 0;
496 /* When reading debug info generated by older versions of rustc, we
497 have to rewrite some union types to be struct types with a
498 variant part. This rewriting must be done after the CU is fully
499 read in, because otherwise at the point of rewriting some struct
500 type might not have been fully processed. So, we keep a list of
501 all such types here and process them after expansion. */
502 std::vector
<struct type
*> rust_unions
;
504 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
505 files, the value is implicitly zero. For DWARF 5 version DWO files, the
506 value is often implicit and is the size of the header of
507 .debug_str_offsets section (8 or 4, depending on the address size). */
508 gdb::optional
<ULONGEST
> str_offsets_base
;
510 /* Mark used when releasing cached dies. */
513 /* This CU references .debug_loc. See the symtab->locations_valid field.
514 This test is imperfect as there may exist optimized debug code not using
515 any location list and still facing inlining issues if handled as
516 unoptimized code. For a future better test see GCC PR other/32998. */
517 bool has_loclist
: 1;
519 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
520 if all the producer_is_* fields are valid. This information is cached
521 because profiling CU expansion showed excessive time spent in
522 producer_is_gxx_lt_4_6. */
523 bool checked_producer
: 1;
524 bool producer_is_gxx_lt_4_6
: 1;
525 bool producer_is_gcc_lt_4_3
: 1;
526 bool producer_is_icc
: 1;
527 bool producer_is_icc_lt_14
: 1;
528 bool producer_is_codewarrior
: 1;
530 /* When true, the file that we're processing is known to have
531 debugging info for C++ namespaces. GCC 3.3.x did not produce
532 this information, but later versions do. */
534 bool processing_has_namespace_info
: 1;
536 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
538 /* If this CU was inherited by another CU (via specification,
539 abstract_origin, etc), this is the ancestor CU. */
542 /* Get the buildsym_compunit for this CU. */
543 buildsym_compunit
*get_builder ()
545 /* If this CU has a builder associated with it, use that. */
546 if (m_builder
!= nullptr)
547 return m_builder
.get ();
549 /* Otherwise, search ancestors for a valid builder. */
550 if (ancestor
!= nullptr)
551 return ancestor
->get_builder ();
557 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
558 This includes type_unit_group and quick_file_names. */
560 struct stmt_list_hash
562 /* The DWO unit this table is from or NULL if there is none. */
563 struct dwo_unit
*dwo_unit
;
565 /* Offset in .debug_line or .debug_line.dwo. */
566 sect_offset line_sect_off
;
569 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
570 an object of this type. */
572 struct type_unit_group
574 /* dwarf2read.c's main "handle" on a TU symtab.
575 To simplify things we create an artificial CU that "includes" all the
576 type units using this stmt_list so that the rest of the code still has
577 a "per_cu" handle on the symtab. */
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 symbol tables for this TU (obtained from the files listed in
595 WARNING: The order of entries here must match the order of entries
596 in the line header. After the first TU using this type_unit_group, the
597 line header for the subsequent TUs is recreated from this. This is done
598 because we need to use the same symtabs for each TU using the same
599 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
600 there's no guarantee the line header doesn't have duplicate entries. */
601 struct symtab
**symtabs
;
604 /* These sections are what may appear in a (real or virtual) DWO file. */
608 struct dwarf2_section_info abbrev
;
609 struct dwarf2_section_info line
;
610 struct dwarf2_section_info loc
;
611 struct dwarf2_section_info loclists
;
612 struct dwarf2_section_info macinfo
;
613 struct dwarf2_section_info macro
;
614 struct dwarf2_section_info str
;
615 struct dwarf2_section_info str_offsets
;
616 /* In the case of a virtual DWO file, these two are unused. */
617 struct dwarf2_section_info info
;
618 std::vector
<dwarf2_section_info
> types
;
621 /* CUs/TUs in DWP/DWO files. */
625 /* Backlink to the containing struct dwo_file. */
626 struct dwo_file
*dwo_file
;
628 /* The "id" that distinguishes this CU/TU.
629 .debug_info calls this "dwo_id", .debug_types calls this "signature".
630 Since signatures came first, we stick with it for consistency. */
633 /* The section this CU/TU lives in, in the DWO file. */
634 struct dwarf2_section_info
*section
;
636 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
637 sect_offset sect_off
;
640 /* For types, offset in the type's DIE of the type defined by this TU. */
641 cu_offset type_offset_in_tu
;
644 /* include/dwarf2.h defines the DWP section codes.
645 It defines a max value but it doesn't define a min value, which we
646 use for error checking, so provide one. */
648 enum dwp_v2_section_ids
653 /* Data for one DWO file.
655 This includes virtual DWO files (a virtual DWO file is a DWO file as it
656 appears in a DWP file). DWP files don't really have DWO files per se -
657 comdat folding of types "loses" the DWO file they came from, and from
658 a high level view DWP files appear to contain a mass of random types.
659 However, to maintain consistency with the non-DWP case we pretend DWP
660 files contain virtual DWO files, and we assign each TU with one virtual
661 DWO file (generally based on the line and abbrev section offsets -
662 a heuristic that seems to work in practice). */
666 dwo_file () = default;
667 DISABLE_COPY_AND_ASSIGN (dwo_file
);
669 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
670 For virtual DWO files the name is constructed from the section offsets
671 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
672 from related CU+TUs. */
673 const char *dwo_name
= nullptr;
675 /* The DW_AT_comp_dir attribute. */
676 const char *comp_dir
= nullptr;
678 /* The bfd, when the file is open. Otherwise this is NULL.
679 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
680 gdb_bfd_ref_ptr dbfd
;
682 /* The sections that make up this DWO file.
683 Remember that for virtual DWO files in DWP V2, these are virtual
684 sections (for lack of a better name). */
685 struct dwo_sections sections
{};
687 /* The CUs in the file.
688 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
689 an extension to handle LLVM's Link Time Optimization output (where
690 multiple source files may be compiled into a single object/dwo pair). */
693 /* Table of TUs in the file.
694 Each element is a struct dwo_unit. */
698 /* These sections are what may appear in a DWP file. */
702 /* These are used by both DWP version 1 and 2. */
703 struct dwarf2_section_info str
;
704 struct dwarf2_section_info cu_index
;
705 struct dwarf2_section_info tu_index
;
707 /* These are only used by DWP version 2 files.
708 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
709 sections are referenced by section number, and are not recorded here.
710 In DWP version 2 there is at most one copy of all these sections, each
711 section being (effectively) comprised of the concatenation of all of the
712 individual sections that exist in the version 1 format.
713 To keep the code simple we treat each of these concatenated pieces as a
714 section itself (a virtual section?). */
715 struct dwarf2_section_info abbrev
;
716 struct dwarf2_section_info info
;
717 struct dwarf2_section_info line
;
718 struct dwarf2_section_info loc
;
719 struct dwarf2_section_info macinfo
;
720 struct dwarf2_section_info macro
;
721 struct dwarf2_section_info str_offsets
;
722 struct dwarf2_section_info types
;
725 /* These sections are what may appear in a virtual DWO file in DWP version 1.
726 A virtual DWO file is a DWO file as it appears in a DWP file. */
728 struct virtual_v1_dwo_sections
730 struct dwarf2_section_info abbrev
;
731 struct dwarf2_section_info line
;
732 struct dwarf2_section_info loc
;
733 struct dwarf2_section_info macinfo
;
734 struct dwarf2_section_info macro
;
735 struct dwarf2_section_info str_offsets
;
736 /* Each DWP hash table entry records one CU or one TU.
737 That is recorded here, and copied to dwo_unit.section. */
738 struct dwarf2_section_info info_or_types
;
741 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
742 In version 2, the sections of the DWO files are concatenated together
743 and stored in one section of that name. Thus each ELF section contains
744 several "virtual" sections. */
746 struct virtual_v2_dwo_sections
748 bfd_size_type abbrev_offset
;
749 bfd_size_type abbrev_size
;
751 bfd_size_type line_offset
;
752 bfd_size_type line_size
;
754 bfd_size_type loc_offset
;
755 bfd_size_type loc_size
;
757 bfd_size_type macinfo_offset
;
758 bfd_size_type macinfo_size
;
760 bfd_size_type macro_offset
;
761 bfd_size_type macro_size
;
763 bfd_size_type str_offsets_offset
;
764 bfd_size_type str_offsets_size
;
766 /* Each DWP hash table entry records one CU or one TU.
767 That is recorded here, and copied to dwo_unit.section. */
768 bfd_size_type info_or_types_offset
;
769 bfd_size_type info_or_types_size
;
772 /* Contents of DWP hash tables. */
774 struct dwp_hash_table
776 uint32_t version
, nr_columns
;
777 uint32_t nr_units
, nr_slots
;
778 const gdb_byte
*hash_table
, *unit_table
;
783 const gdb_byte
*indices
;
787 /* This is indexed by column number and gives the id of the section
789 #define MAX_NR_V2_DWO_SECTIONS \
790 (1 /* .debug_info or .debug_types */ \
791 + 1 /* .debug_abbrev */ \
792 + 1 /* .debug_line */ \
793 + 1 /* .debug_loc */ \
794 + 1 /* .debug_str_offsets */ \
795 + 1 /* .debug_macro or .debug_macinfo */)
796 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
797 const gdb_byte
*offsets
;
798 const gdb_byte
*sizes
;
803 /* Data for one DWP file. */
807 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
809 dbfd (std::move (abfd
))
813 /* Name of the file. */
816 /* File format version. */
820 gdb_bfd_ref_ptr dbfd
;
822 /* Section info for this file. */
823 struct dwp_sections sections
{};
825 /* Table of CUs in the file. */
826 const struct dwp_hash_table
*cus
= nullptr;
828 /* Table of TUs in the file. */
829 const struct dwp_hash_table
*tus
= nullptr;
831 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
835 /* Table to map ELF section numbers to their sections.
836 This is only needed for the DWP V1 file format. */
837 unsigned int num_sections
= 0;
838 asection
**elf_sections
= nullptr;
841 /* Struct used to pass misc. parameters to read_die_and_children, et
842 al. which are used for both .debug_info and .debug_types dies.
843 All parameters here are unchanging for the life of the call. This
844 struct exists to abstract away the constant parameters of die reading. */
846 struct die_reader_specs
848 /* The bfd of die_section. */
851 /* The CU of the DIE we are parsing. */
852 struct dwarf2_cu
*cu
;
854 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
855 struct dwo_file
*dwo_file
;
857 /* The section the die comes from.
858 This is either .debug_info or .debug_types, or the .dwo variants. */
859 struct dwarf2_section_info
*die_section
;
861 /* die_section->buffer. */
862 const gdb_byte
*buffer
;
864 /* The end of the buffer. */
865 const gdb_byte
*buffer_end
;
867 /* The abbreviation table to use when reading the DIEs. */
868 struct abbrev_table
*abbrev_table
;
871 /* A subclass of die_reader_specs that holds storage and has complex
872 constructor and destructor behavior. */
874 class cutu_reader
: public die_reader_specs
878 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
879 struct abbrev_table
*abbrev_table
,
883 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
884 struct dwarf2_cu
*parent_cu
= nullptr,
885 struct dwo_file
*dwo_file
= nullptr);
887 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
889 const gdb_byte
*info_ptr
= nullptr;
890 struct die_info
*comp_unit_die
= nullptr;
891 bool dummy_p
= false;
893 /* Release the new CU, putting it on the chain. This cannot be done
898 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
899 int use_existing_cu
);
901 struct dwarf2_per_cu_data
*m_this_cu
;
902 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
904 /* The ordinary abbreviation table. */
905 abbrev_table_up m_abbrev_table_holder
;
907 /* The DWO abbreviation table. */
908 abbrev_table_up m_dwo_abbrev_table
;
911 /* When we construct a partial symbol table entry we only
912 need this much information. */
913 struct partial_die_info
: public allocate_on_obstack
915 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
917 /* Disable assign but still keep copy ctor, which is needed
918 load_partial_dies. */
919 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
921 /* Adjust the partial die before generating a symbol for it. This
922 function may set the is_external flag or change the DIE's
924 void fixup (struct dwarf2_cu
*cu
);
926 /* Read a minimal amount of information into the minimal die
928 const gdb_byte
*read (const struct die_reader_specs
*reader
,
929 const struct abbrev_info
&abbrev
,
930 const gdb_byte
*info_ptr
);
932 /* Offset of this DIE. */
933 const sect_offset sect_off
;
935 /* DWARF-2 tag for this DIE. */
936 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
938 /* Assorted flags describing the data found in this DIE. */
939 const unsigned int has_children
: 1;
941 unsigned int is_external
: 1;
942 unsigned int is_declaration
: 1;
943 unsigned int has_type
: 1;
944 unsigned int has_specification
: 1;
945 unsigned int has_pc_info
: 1;
946 unsigned int may_be_inlined
: 1;
948 /* This DIE has been marked DW_AT_main_subprogram. */
949 unsigned int main_subprogram
: 1;
951 /* Flag set if the SCOPE field of this structure has been
953 unsigned int scope_set
: 1;
955 /* Flag set if the DIE has a byte_size attribute. */
956 unsigned int has_byte_size
: 1;
958 /* Flag set if the DIE has a DW_AT_const_value attribute. */
959 unsigned int has_const_value
: 1;
961 /* Flag set if any of the DIE's children are template arguments. */
962 unsigned int has_template_arguments
: 1;
964 /* Flag set if fixup has been called on this die. */
965 unsigned int fixup_called
: 1;
967 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
968 unsigned int is_dwz
: 1;
970 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
971 unsigned int spec_is_dwz
: 1;
973 /* The name of this DIE. Normally the value of DW_AT_name, but
974 sometimes a default name for unnamed DIEs. */
975 const char *name
= nullptr;
977 /* The linkage name, if present. */
978 const char *linkage_name
= nullptr;
980 /* The scope to prepend to our children. This is generally
981 allocated on the comp_unit_obstack, so will disappear
982 when this compilation unit leaves the cache. */
983 const char *scope
= nullptr;
985 /* Some data associated with the partial DIE. The tag determines
986 which field is live. */
989 /* The location description associated with this DIE, if any. */
990 struct dwarf_block
*locdesc
;
991 /* The offset of an import, for DW_TAG_imported_unit. */
992 sect_offset sect_off
;
995 /* If HAS_PC_INFO, the PC range associated with this DIE. */
997 CORE_ADDR highpc
= 0;
999 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1000 DW_AT_sibling, if any. */
1001 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1002 could return DW_AT_sibling values to its caller load_partial_dies. */
1003 const gdb_byte
*sibling
= nullptr;
1005 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1006 DW_AT_specification (or DW_AT_abstract_origin or
1007 DW_AT_extension). */
1008 sect_offset spec_offset
{};
1010 /* Pointers to this DIE's parent, first child, and next sibling,
1012 struct partial_die_info
*die_parent
= nullptr;
1013 struct partial_die_info
*die_child
= nullptr;
1014 struct partial_die_info
*die_sibling
= nullptr;
1016 friend struct partial_die_info
*
1017 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1020 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1021 partial_die_info (sect_offset sect_off
)
1022 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1026 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1028 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1033 has_specification
= 0;
1036 main_subprogram
= 0;
1039 has_const_value
= 0;
1040 has_template_arguments
= 0;
1047 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1048 but this would require a corresponding change in unpack_field_as_long
1050 static int bits_per_byte
= 8;
1052 /* When reading a variant or variant part, we track a bit more
1053 information about the field, and store it in an object of this
1056 struct variant_field
1058 /* If we see a DW_TAG_variant, then this will be the discriminant
1060 ULONGEST discriminant_value
;
1061 /* If we see a DW_TAG_variant, then this will be set if this is the
1063 bool default_branch
;
1064 /* While reading a DW_TAG_variant_part, this will be set if this
1065 field is the discriminant. */
1066 bool is_discriminant
;
1071 int accessibility
= 0;
1073 /* Extra information to describe a variant or variant part. */
1074 struct variant_field variant
{};
1075 struct field field
{};
1080 const char *name
= nullptr;
1081 std::vector
<struct fn_field
> fnfields
;
1084 /* The routines that read and process dies for a C struct or C++ class
1085 pass lists of data member fields and lists of member function fields
1086 in an instance of a field_info structure, as defined below. */
1089 /* List of data member and baseclasses fields. */
1090 std::vector
<struct nextfield
> fields
;
1091 std::vector
<struct nextfield
> baseclasses
;
1093 /* Set if the accessibility of one of the fields is not public. */
1094 int non_public_fields
= 0;
1096 /* Member function fieldlist array, contains name of possibly overloaded
1097 member function, number of overloaded member functions and a pointer
1098 to the head of the member function field chain. */
1099 std::vector
<struct fnfieldlist
> fnfieldlists
;
1101 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1102 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1103 std::vector
<struct decl_field
> typedef_field_list
;
1105 /* Nested types defined by this class and the number of elements in this
1107 std::vector
<struct decl_field
> nested_types_list
;
1109 /* Return the total number of fields (including baseclasses). */
1110 int nfields () const
1112 return fields
.size () + baseclasses
.size ();
1116 /* Loaded secondary compilation units are kept in memory until they
1117 have not been referenced for the processing of this many
1118 compilation units. Set this to zero to disable caching. Cache
1119 sizes of up to at least twenty will improve startup time for
1120 typical inter-CU-reference binaries, at an obvious memory cost. */
1121 static int dwarf_max_cache_age
= 5;
1123 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1124 struct cmd_list_element
*c
, const char *value
)
1126 fprintf_filtered (file
, _("The upper bound on the age of cached "
1127 "DWARF compilation units is %s.\n"),
1131 /* local function prototypes */
1133 static void dwarf2_find_base_address (struct die_info
*die
,
1134 struct dwarf2_cu
*cu
);
1136 static dwarf2_psymtab
*create_partial_symtab
1137 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1139 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1140 const gdb_byte
*info_ptr
,
1141 struct die_info
*type_unit_die
);
1143 static void dwarf2_build_psymtabs_hard
1144 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1146 static void scan_partial_symbols (struct partial_die_info
*,
1147 CORE_ADDR
*, CORE_ADDR
*,
1148 int, struct dwarf2_cu
*);
1150 static void add_partial_symbol (struct partial_die_info
*,
1151 struct dwarf2_cu
*);
1153 static void add_partial_namespace (struct partial_die_info
*pdi
,
1154 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1155 int set_addrmap
, struct dwarf2_cu
*cu
);
1157 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1158 CORE_ADDR
*highpc
, int set_addrmap
,
1159 struct dwarf2_cu
*cu
);
1161 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1162 struct dwarf2_cu
*cu
);
1164 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1165 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1166 int need_pc
, struct dwarf2_cu
*cu
);
1168 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1170 static struct partial_die_info
*load_partial_dies
1171 (const struct die_reader_specs
*, const gdb_byte
*, int);
1173 /* A pair of partial_die_info and compilation unit. */
1174 struct cu_partial_die_info
1176 /* The compilation unit of the partial_die_info. */
1177 struct dwarf2_cu
*cu
;
1178 /* A partial_die_info. */
1179 struct partial_die_info
*pdi
;
1181 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1187 cu_partial_die_info () = delete;
1190 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1191 struct dwarf2_cu
*);
1193 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1194 struct attribute
*, struct attr_abbrev
*,
1195 const gdb_byte
*, bool *need_reprocess
);
1197 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1198 struct attribute
*attr
);
1200 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1202 static sect_offset read_abbrev_offset
1203 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1204 struct dwarf2_section_info
*, sect_offset
);
1206 static const char *read_indirect_string
1207 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1208 const struct comp_unit_head
*, unsigned int *);
1210 static const char *read_indirect_string_at_offset
1211 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, LONGEST str_offset
);
1213 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1217 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1218 ULONGEST str_index
);
1220 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1221 ULONGEST str_index
);
1223 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1225 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1226 struct dwarf2_cu
*);
1228 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1229 struct dwarf2_cu
*cu
);
1231 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1233 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1234 struct dwarf2_cu
*cu
);
1236 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1238 static struct die_info
*die_specification (struct die_info
*die
,
1239 struct dwarf2_cu
**);
1241 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1242 struct dwarf2_cu
*cu
);
1244 static void dwarf_decode_lines (struct line_header
*, const char *,
1245 struct dwarf2_cu
*, dwarf2_psymtab
*,
1246 CORE_ADDR
, int decode_mapping
);
1248 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1251 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1252 struct dwarf2_cu
*, struct symbol
* = NULL
);
1254 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1255 struct dwarf2_cu
*);
1257 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1260 struct obstack
*obstack
,
1261 struct dwarf2_cu
*cu
, LONGEST
*value
,
1262 const gdb_byte
**bytes
,
1263 struct dwarf2_locexpr_baton
**baton
);
1265 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1267 static int need_gnat_info (struct dwarf2_cu
*);
1269 static struct type
*die_descriptive_type (struct die_info
*,
1270 struct dwarf2_cu
*);
1272 static void set_descriptive_type (struct type
*, struct die_info
*,
1273 struct dwarf2_cu
*);
1275 static struct type
*die_containing_type (struct die_info
*,
1276 struct dwarf2_cu
*);
1278 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1279 struct dwarf2_cu
*);
1281 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1283 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1285 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1287 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1288 const char *suffix
, int physname
,
1289 struct dwarf2_cu
*cu
);
1291 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1293 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1295 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1297 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1299 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1301 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1303 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1304 struct dwarf2_cu
*, dwarf2_psymtab
*);
1306 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1307 values. Keep the items ordered with increasing constraints compliance. */
1310 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1311 PC_BOUNDS_NOT_PRESENT
,
1313 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1314 were present but they do not form a valid range of PC addresses. */
1317 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1320 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1324 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1325 CORE_ADDR
*, CORE_ADDR
*,
1329 static void get_scope_pc_bounds (struct die_info
*,
1330 CORE_ADDR
*, CORE_ADDR
*,
1331 struct dwarf2_cu
*);
1333 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1334 CORE_ADDR
, struct dwarf2_cu
*);
1336 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1337 struct dwarf2_cu
*);
1339 static void dwarf2_attach_fields_to_type (struct field_info
*,
1340 struct type
*, struct dwarf2_cu
*);
1342 static void dwarf2_add_member_fn (struct field_info
*,
1343 struct die_info
*, struct type
*,
1344 struct dwarf2_cu
*);
1346 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1348 struct dwarf2_cu
*);
1350 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1352 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1354 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1356 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1358 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1360 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1362 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1364 static struct type
*read_module_type (struct die_info
*die
,
1365 struct dwarf2_cu
*cu
);
1367 static const char *namespace_name (struct die_info
*die
,
1368 int *is_anonymous
, struct dwarf2_cu
*);
1370 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1372 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1374 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1375 struct dwarf2_cu
*);
1377 static struct die_info
*read_die_and_siblings_1
1378 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1381 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1382 const gdb_byte
*info_ptr
,
1383 const gdb_byte
**new_info_ptr
,
1384 struct die_info
*parent
);
1386 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1387 struct die_info
**, const gdb_byte
*,
1390 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1391 struct die_info
**, const gdb_byte
*);
1393 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1395 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1398 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1400 static const char *dwarf2_full_name (const char *name
,
1401 struct die_info
*die
,
1402 struct dwarf2_cu
*cu
);
1404 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1405 struct dwarf2_cu
*cu
);
1407 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1408 struct dwarf2_cu
**);
1410 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1412 static void dump_die_for_error (struct die_info
*);
1414 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1417 /*static*/ void dump_die (struct die_info
*, int max_level
);
1419 static void store_in_ref_table (struct die_info
*,
1420 struct dwarf2_cu
*);
1422 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1423 const struct attribute
*,
1424 struct dwarf2_cu
**);
1426 static struct die_info
*follow_die_ref (struct die_info
*,
1427 const struct attribute
*,
1428 struct dwarf2_cu
**);
1430 static struct die_info
*follow_die_sig (struct die_info
*,
1431 const struct attribute
*,
1432 struct dwarf2_cu
**);
1434 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1435 struct dwarf2_cu
*);
1437 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1438 const struct attribute
*,
1439 struct dwarf2_cu
*);
1441 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1443 static void read_signatured_type (struct signatured_type
*);
1445 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1446 struct die_info
*die
, struct dwarf2_cu
*cu
,
1447 struct dynamic_prop
*prop
, struct type
*type
);
1449 /* memory allocation interface */
1451 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1453 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1455 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1457 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1458 struct dwarf2_loclist_baton
*baton
,
1459 const struct attribute
*attr
);
1461 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1463 struct dwarf2_cu
*cu
,
1466 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1467 const gdb_byte
*info_ptr
,
1468 struct abbrev_info
*abbrev
);
1470 static hashval_t
partial_die_hash (const void *item
);
1472 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1474 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1475 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1476 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1478 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1479 struct die_info
*comp_unit_die
,
1480 enum language pretend_language
);
1482 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1484 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1486 static struct type
*set_die_type (struct die_info
*, struct type
*,
1487 struct dwarf2_cu
*);
1489 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1491 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1493 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1496 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1499 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1502 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1503 struct dwarf2_per_cu_data
*);
1505 static void dwarf2_mark (struct dwarf2_cu
*);
1507 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1509 static struct type
*get_die_type_at_offset (sect_offset
,
1510 struct dwarf2_per_cu_data
*);
1512 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1514 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1515 enum language pretend_language
);
1517 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1519 /* Class, the destructor of which frees all allocated queue entries. This
1520 will only have work to do if an error was thrown while processing the
1521 dwarf. If no error was thrown then the queue entries should have all
1522 been processed, and freed, as we went along. */
1524 class dwarf2_queue_guard
1527 explicit dwarf2_queue_guard (dwarf2_per_objfile
*per_objfile
)
1528 : m_per_objfile (per_objfile
)
1532 /* Free any entries remaining on the queue. There should only be
1533 entries left if we hit an error while processing the dwarf. */
1534 ~dwarf2_queue_guard ()
1536 /* Ensure that no memory is allocated by the queue. */
1537 std::queue
<dwarf2_queue_item
> empty
;
1538 std::swap (m_per_objfile
->queue
, empty
);
1541 DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard
);
1544 dwarf2_per_objfile
*m_per_objfile
;
1547 dwarf2_queue_item::~dwarf2_queue_item ()
1549 /* Anything still marked queued is likely to be in an
1550 inconsistent state, so discard it. */
1553 if (per_cu
->cu
!= NULL
)
1554 free_one_cached_comp_unit (per_cu
);
1559 /* The return type of find_file_and_directory. Note, the enclosed
1560 string pointers are only valid while this object is valid. */
1562 struct file_and_directory
1564 /* The filename. This is never NULL. */
1567 /* The compilation directory. NULL if not known. If we needed to
1568 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1569 points directly to the DW_AT_comp_dir string attribute owned by
1570 the obstack that owns the DIE. */
1571 const char *comp_dir
;
1573 /* If we needed to build a new string for comp_dir, this is what
1574 owns the storage. */
1575 std::string comp_dir_storage
;
1578 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1579 struct dwarf2_cu
*cu
);
1581 static htab_up
allocate_signatured_type_table ();
1583 static htab_up
allocate_dwo_unit_table ();
1585 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1586 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1587 struct dwp_file
*dwp_file
, const char *comp_dir
,
1588 ULONGEST signature
, int is_debug_types
);
1590 static struct dwp_file
*get_dwp_file
1591 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1593 static struct dwo_unit
*lookup_dwo_comp_unit
1594 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1596 static struct dwo_unit
*lookup_dwo_type_unit
1597 (struct signatured_type
*, const char *, const char *);
1599 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1601 /* A unique pointer to a dwo_file. */
1603 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1605 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1607 static void check_producer (struct dwarf2_cu
*cu
);
1609 static void free_line_header_voidp (void *arg
);
1611 /* Various complaints about symbol reading that don't abort the process. */
1614 dwarf2_debug_line_missing_file_complaint (void)
1616 complaint (_(".debug_line section has line data without a file"));
1620 dwarf2_debug_line_missing_end_sequence_complaint (void)
1622 complaint (_(".debug_line section has line "
1623 "program sequence without an end"));
1627 dwarf2_complex_location_expr_complaint (void)
1629 complaint (_("location expression too complex"));
1633 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1636 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1641 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
1643 complaint (_("invalid attribute class or form for '%s' in '%s'"),
1647 /* Hash function for line_header_hash. */
1650 line_header_hash (const struct line_header
*ofs
)
1652 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
1655 /* Hash function for htab_create_alloc_ex for line_header_hash. */
1658 line_header_hash_voidp (const void *item
)
1660 const struct line_header
*ofs
= (const struct line_header
*) item
;
1662 return line_header_hash (ofs
);
1665 /* Equality function for line_header_hash. */
1668 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
1670 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
1671 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
1673 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
1674 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
1679 /* See declaration. */
1681 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
1682 const dwarf2_debug_sections
*names
,
1684 : objfile (objfile_
),
1685 can_copy (can_copy_
)
1688 names
= &dwarf2_elf_names
;
1690 bfd
*obfd
= objfile
->obfd
;
1692 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
1693 locate_sections (obfd
, sec
, *names
);
1696 dwarf2_per_objfile::~dwarf2_per_objfile ()
1698 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
1699 free_cached_comp_units ();
1701 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
1702 per_cu
->imported_symtabs_free ();
1704 for (signatured_type
*sig_type
: all_type_units
)
1705 sig_type
->per_cu
.imported_symtabs_free ();
1707 /* Everything else should be on the objfile obstack. */
1710 /* See declaration. */
1713 dwarf2_per_objfile::free_cached_comp_units ()
1715 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
1716 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
1717 while (per_cu
!= NULL
)
1719 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
1722 *last_chain
= next_cu
;
1727 /* A helper class that calls free_cached_comp_units on
1730 class free_cached_comp_units
1734 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
1735 : m_per_objfile (per_objfile
)
1739 ~free_cached_comp_units ()
1741 m_per_objfile
->free_cached_comp_units ();
1744 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
1748 dwarf2_per_objfile
*m_per_objfile
;
1751 /* Try to locate the sections we need for DWARF 2 debugging
1752 information and return true if we have enough to do something.
1753 NAMES points to the dwarf2 section names, or is NULL if the standard
1754 ELF names are used. CAN_COPY is true for formats where symbol
1755 interposition is possible and so symbol values must follow copy
1756 relocation rules. */
1759 dwarf2_has_info (struct objfile
*objfile
,
1760 const struct dwarf2_debug_sections
*names
,
1763 if (objfile
->flags
& OBJF_READNEVER
)
1766 struct dwarf2_per_objfile
*dwarf2_per_objfile
1767 = get_dwarf2_per_objfile (objfile
);
1769 if (dwarf2_per_objfile
== NULL
)
1770 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
1774 return (!dwarf2_per_objfile
->info
.is_virtual
1775 && dwarf2_per_objfile
->info
.s
.section
!= NULL
1776 && !dwarf2_per_objfile
->abbrev
.is_virtual
1777 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
1780 /* When loading sections, we look either for uncompressed section or for
1781 compressed section names. */
1784 section_is_p (const char *section_name
,
1785 const struct dwarf2_section_names
*names
)
1787 if (names
->normal
!= NULL
1788 && strcmp (section_name
, names
->normal
) == 0)
1790 if (names
->compressed
!= NULL
1791 && strcmp (section_name
, names
->compressed
) == 0)
1796 /* See declaration. */
1799 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
1800 const dwarf2_debug_sections
&names
)
1802 flagword aflag
= bfd_section_flags (sectp
);
1804 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
1807 else if (elf_section_data (sectp
)->this_hdr
.sh_size
1808 > bfd_get_file_size (abfd
))
1810 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
1811 warning (_("Discarding section %s which has a section size (%s"
1812 ") larger than the file size [in module %s]"),
1813 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
1814 bfd_get_filename (abfd
));
1816 else if (section_is_p (sectp
->name
, &names
.info
))
1818 this->info
.s
.section
= sectp
;
1819 this->info
.size
= bfd_section_size (sectp
);
1821 else if (section_is_p (sectp
->name
, &names
.abbrev
))
1823 this->abbrev
.s
.section
= sectp
;
1824 this->abbrev
.size
= bfd_section_size (sectp
);
1826 else if (section_is_p (sectp
->name
, &names
.line
))
1828 this->line
.s
.section
= sectp
;
1829 this->line
.size
= bfd_section_size (sectp
);
1831 else if (section_is_p (sectp
->name
, &names
.loc
))
1833 this->loc
.s
.section
= sectp
;
1834 this->loc
.size
= bfd_section_size (sectp
);
1836 else if (section_is_p (sectp
->name
, &names
.loclists
))
1838 this->loclists
.s
.section
= sectp
;
1839 this->loclists
.size
= bfd_section_size (sectp
);
1841 else if (section_is_p (sectp
->name
, &names
.macinfo
))
1843 this->macinfo
.s
.section
= sectp
;
1844 this->macinfo
.size
= bfd_section_size (sectp
);
1846 else if (section_is_p (sectp
->name
, &names
.macro
))
1848 this->macro
.s
.section
= sectp
;
1849 this->macro
.size
= bfd_section_size (sectp
);
1851 else if (section_is_p (sectp
->name
, &names
.str
))
1853 this->str
.s
.section
= sectp
;
1854 this->str
.size
= bfd_section_size (sectp
);
1856 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
1858 this->str_offsets
.s
.section
= sectp
;
1859 this->str_offsets
.size
= bfd_section_size (sectp
);
1861 else if (section_is_p (sectp
->name
, &names
.line_str
))
1863 this->line_str
.s
.section
= sectp
;
1864 this->line_str
.size
= bfd_section_size (sectp
);
1866 else if (section_is_p (sectp
->name
, &names
.addr
))
1868 this->addr
.s
.section
= sectp
;
1869 this->addr
.size
= bfd_section_size (sectp
);
1871 else if (section_is_p (sectp
->name
, &names
.frame
))
1873 this->frame
.s
.section
= sectp
;
1874 this->frame
.size
= bfd_section_size (sectp
);
1876 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
1878 this->eh_frame
.s
.section
= sectp
;
1879 this->eh_frame
.size
= bfd_section_size (sectp
);
1881 else if (section_is_p (sectp
->name
, &names
.ranges
))
1883 this->ranges
.s
.section
= sectp
;
1884 this->ranges
.size
= bfd_section_size (sectp
);
1886 else if (section_is_p (sectp
->name
, &names
.rnglists
))
1888 this->rnglists
.s
.section
= sectp
;
1889 this->rnglists
.size
= bfd_section_size (sectp
);
1891 else if (section_is_p (sectp
->name
, &names
.types
))
1893 struct dwarf2_section_info type_section
;
1895 memset (&type_section
, 0, sizeof (type_section
));
1896 type_section
.s
.section
= sectp
;
1897 type_section
.size
= bfd_section_size (sectp
);
1899 this->types
.push_back (type_section
);
1901 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
1903 this->gdb_index
.s
.section
= sectp
;
1904 this->gdb_index
.size
= bfd_section_size (sectp
);
1906 else if (section_is_p (sectp
->name
, &names
.debug_names
))
1908 this->debug_names
.s
.section
= sectp
;
1909 this->debug_names
.size
= bfd_section_size (sectp
);
1911 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
1913 this->debug_aranges
.s
.section
= sectp
;
1914 this->debug_aranges
.size
= bfd_section_size (sectp
);
1917 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
1918 && bfd_section_vma (sectp
) == 0)
1919 this->has_section_at_zero
= true;
1922 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1926 dwarf2_get_section_info (struct objfile
*objfile
,
1927 enum dwarf2_section_enum sect
,
1928 asection
**sectp
, const gdb_byte
**bufp
,
1929 bfd_size_type
*sizep
)
1931 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
1932 struct dwarf2_section_info
*info
;
1934 /* We may see an objfile without any DWARF, in which case we just
1945 case DWARF2_DEBUG_FRAME
:
1946 info
= &data
->frame
;
1948 case DWARF2_EH_FRAME
:
1949 info
= &data
->eh_frame
;
1952 gdb_assert_not_reached ("unexpected section");
1955 info
->read (objfile
);
1957 *sectp
= info
->get_bfd_section ();
1958 *bufp
= info
->buffer
;
1959 *sizep
= info
->size
;
1962 /* A helper function to find the sections for a .dwz file. */
1965 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
1967 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
1969 /* Note that we only support the standard ELF names, because .dwz
1970 is ELF-only (at the time of writing). */
1971 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
1973 dwz_file
->abbrev
.s
.section
= sectp
;
1974 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
1976 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
1978 dwz_file
->info
.s
.section
= sectp
;
1979 dwz_file
->info
.size
= bfd_section_size (sectp
);
1981 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
1983 dwz_file
->str
.s
.section
= sectp
;
1984 dwz_file
->str
.size
= bfd_section_size (sectp
);
1986 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
1988 dwz_file
->line
.s
.section
= sectp
;
1989 dwz_file
->line
.size
= bfd_section_size (sectp
);
1991 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
1993 dwz_file
->macro
.s
.section
= sectp
;
1994 dwz_file
->macro
.size
= bfd_section_size (sectp
);
1996 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
1998 dwz_file
->gdb_index
.s
.section
= sectp
;
1999 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2001 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2003 dwz_file
->debug_names
.s
.section
= sectp
;
2004 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2008 /* See dwarf2read.h. */
2011 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2013 const char *filename
;
2014 bfd_size_type buildid_len_arg
;
2018 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2019 return dwarf2_per_objfile
->dwz_file
.get ();
2021 bfd_set_error (bfd_error_no_error
);
2022 gdb::unique_xmalloc_ptr
<char> data
2023 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2024 &buildid_len_arg
, &buildid
));
2027 if (bfd_get_error () == bfd_error_no_error
)
2029 error (_("could not read '.gnu_debugaltlink' section: %s"),
2030 bfd_errmsg (bfd_get_error ()));
2033 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2035 buildid_len
= (size_t) buildid_len_arg
;
2037 filename
= data
.get ();
2039 std::string abs_storage
;
2040 if (!IS_ABSOLUTE_PATH (filename
))
2042 gdb::unique_xmalloc_ptr
<char> abs
2043 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2045 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2046 filename
= abs_storage
.c_str ();
2049 /* First try the file name given in the section. If that doesn't
2050 work, try to use the build-id instead. */
2051 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2052 if (dwz_bfd
!= NULL
)
2054 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2055 dwz_bfd
.reset (nullptr);
2058 if (dwz_bfd
== NULL
)
2059 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2061 if (dwz_bfd
== nullptr)
2063 gdb::unique_xmalloc_ptr
<char> alt_filename
;
2064 const char *origname
= dwarf2_per_objfile
->objfile
->original_name
;
2066 scoped_fd
fd (debuginfod_debuginfo_query (buildid
,
2073 /* File successfully retrieved from server. */
2074 dwz_bfd
= gdb_bfd_open (alt_filename
.get (), gnutarget
, -1);
2076 if (dwz_bfd
== nullptr)
2077 warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
2078 alt_filename
.get ());
2079 else if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2080 dwz_bfd
.reset (nullptr);
2084 if (dwz_bfd
== NULL
)
2085 error (_("could not find '.gnu_debugaltlink' file for %s"),
2086 objfile_name (dwarf2_per_objfile
->objfile
));
2088 std::unique_ptr
<struct dwz_file
> result
2089 (new struct dwz_file (std::move (dwz_bfd
)));
2091 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2094 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2095 result
->dwz_bfd
.get ());
2096 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2097 return dwarf2_per_objfile
->dwz_file
.get ();
2100 /* DWARF quick_symbols_functions support. */
2102 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2103 unique line tables, so we maintain a separate table of all .debug_line
2104 derived entries to support the sharing.
2105 All the quick functions need is the list of file names. We discard the
2106 line_header when we're done and don't need to record it here. */
2107 struct quick_file_names
2109 /* The data used to construct the hash key. */
2110 struct stmt_list_hash hash
;
2112 /* The number of entries in file_names, real_names. */
2113 unsigned int num_file_names
;
2115 /* The file names from the line table, after being run through
2117 const char **file_names
;
2119 /* The file names from the line table after being run through
2120 gdb_realpath. These are computed lazily. */
2121 const char **real_names
;
2124 /* When using the index (and thus not using psymtabs), each CU has an
2125 object of this type. This is used to hold information needed by
2126 the various "quick" methods. */
2127 struct dwarf2_per_cu_quick_data
2129 /* The file table. This can be NULL if there was no file table
2130 or it's currently not read in.
2131 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2132 struct quick_file_names
*file_names
;
2134 /* The corresponding symbol table. This is NULL if symbols for this
2135 CU have not yet been read. */
2136 struct compunit_symtab
*compunit_symtab
;
2138 /* A temporary mark bit used when iterating over all CUs in
2139 expand_symtabs_matching. */
2140 unsigned int mark
: 1;
2142 /* True if we've tried to read the file table and found there isn't one.
2143 There will be no point in trying to read it again next time. */
2144 unsigned int no_file_data
: 1;
2147 /* Utility hash function for a stmt_list_hash. */
2150 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2154 if (stmt_list_hash
->dwo_unit
!= NULL
)
2155 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2156 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2160 /* Utility equality function for a stmt_list_hash. */
2163 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2164 const struct stmt_list_hash
*rhs
)
2166 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2168 if (lhs
->dwo_unit
!= NULL
2169 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2172 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2175 /* Hash function for a quick_file_names. */
2178 hash_file_name_entry (const void *e
)
2180 const struct quick_file_names
*file_data
2181 = (const struct quick_file_names
*) e
;
2183 return hash_stmt_list_entry (&file_data
->hash
);
2186 /* Equality function for a quick_file_names. */
2189 eq_file_name_entry (const void *a
, const void *b
)
2191 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2192 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2194 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2197 /* Delete function for a quick_file_names. */
2200 delete_file_name_entry (void *e
)
2202 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2205 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2207 xfree ((void*) file_data
->file_names
[i
]);
2208 if (file_data
->real_names
)
2209 xfree ((void*) file_data
->real_names
[i
]);
2212 /* The space for the struct itself lives on objfile_obstack,
2213 so we don't free it here. */
2216 /* Create a quick_file_names hash table. */
2219 create_quick_file_names_table (unsigned int nr_initial_entries
)
2221 return htab_up (htab_create_alloc (nr_initial_entries
,
2222 hash_file_name_entry
, eq_file_name_entry
,
2223 delete_file_name_entry
, xcalloc
, xfree
));
2226 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2227 have to be created afterwards. You should call age_cached_comp_units after
2228 processing PER_CU->CU. dw2_setup must have been already called. */
2231 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2233 if (per_cu
->is_debug_types
)
2234 load_full_type_unit (per_cu
);
2236 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2238 if (per_cu
->cu
== NULL
)
2239 return; /* Dummy CU. */
2241 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2244 /* Read in the symbols for PER_CU. */
2247 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2249 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2251 /* Skip type_unit_groups, reading the type units they contain
2252 is handled elsewhere. */
2253 if (per_cu
->type_unit_group_p ())
2256 /* The destructor of dwarf2_queue_guard frees any entries left on
2257 the queue. After this point we're guaranteed to leave this function
2258 with the dwarf queue empty. */
2259 dwarf2_queue_guard
q_guard (dwarf2_per_objfile
);
2261 if (dwarf2_per_objfile
->using_index
2262 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2263 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2265 queue_comp_unit (per_cu
, language_minimal
);
2266 load_cu (per_cu
, skip_partial
);
2268 /* If we just loaded a CU from a DWO, and we're working with an index
2269 that may badly handle TUs, load all the TUs in that DWO as well.
2270 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2271 if (!per_cu
->is_debug_types
2272 && per_cu
->cu
!= NULL
2273 && per_cu
->cu
->dwo_unit
!= NULL
2274 && dwarf2_per_objfile
->index_table
!= NULL
2275 && dwarf2_per_objfile
->index_table
->version
<= 7
2276 /* DWP files aren't supported yet. */
2277 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2278 queue_and_load_all_dwo_tus (per_cu
);
2281 process_queue (dwarf2_per_objfile
);
2283 /* Age the cache, releasing compilation units that have not
2284 been used recently. */
2285 age_cached_comp_units (dwarf2_per_objfile
);
2288 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2289 the objfile from which this CU came. Returns the resulting symbol
2292 static struct compunit_symtab
*
2293 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2295 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2297 gdb_assert (dwarf2_per_objfile
->using_index
);
2298 if (!per_cu
->v
.quick
->compunit_symtab
)
2300 free_cached_comp_units
freer (dwarf2_per_objfile
);
2301 scoped_restore decrementer
= increment_reading_symtab ();
2302 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2303 process_cu_includes (dwarf2_per_objfile
);
2306 return per_cu
->v
.quick
->compunit_symtab
;
2309 /* See declaration. */
2311 dwarf2_per_cu_data
*
2312 dwarf2_per_objfile::get_cutu (int index
)
2314 if (index
>= this->all_comp_units
.size ())
2316 index
-= this->all_comp_units
.size ();
2317 gdb_assert (index
< this->all_type_units
.size ());
2318 return &this->all_type_units
[index
]->per_cu
;
2321 return this->all_comp_units
[index
];
2324 /* See declaration. */
2326 dwarf2_per_cu_data
*
2327 dwarf2_per_objfile::get_cu (int index
)
2329 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2331 return this->all_comp_units
[index
];
2334 /* See declaration. */
2337 dwarf2_per_objfile::get_tu (int index
)
2339 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2341 return this->all_type_units
[index
];
2344 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2345 objfile_obstack, and constructed with the specified field
2348 static dwarf2_per_cu_data
*
2349 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2350 struct dwarf2_section_info
*section
,
2352 sect_offset sect_off
, ULONGEST length
)
2354 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2355 dwarf2_per_cu_data
*the_cu
2356 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2357 struct dwarf2_per_cu_data
);
2358 the_cu
->sect_off
= sect_off
;
2359 the_cu
->length
= length
;
2360 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2361 the_cu
->section
= section
;
2362 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2363 struct dwarf2_per_cu_quick_data
);
2364 the_cu
->is_dwz
= is_dwz
;
2368 /* A helper for create_cus_from_index that handles a given list of
2372 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2373 const gdb_byte
*cu_list
, offset_type n_elements
,
2374 struct dwarf2_section_info
*section
,
2377 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2379 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2381 sect_offset sect_off
2382 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2383 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2386 dwarf2_per_cu_data
*per_cu
2387 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2389 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2393 /* Read the CU list from the mapped index, and use it to create all
2394 the CU objects for this objfile. */
2397 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2398 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2399 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2401 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2402 dwarf2_per_objfile
->all_comp_units
.reserve
2403 ((cu_list_elements
+ dwz_elements
) / 2);
2405 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2406 &dwarf2_per_objfile
->info
, 0);
2408 if (dwz_elements
== 0)
2411 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2412 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2416 /* Create the signatured type hash table from the index. */
2419 create_signatured_type_table_from_index
2420 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2421 struct dwarf2_section_info
*section
,
2422 const gdb_byte
*bytes
,
2423 offset_type elements
)
2425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2427 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2428 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2430 htab_up sig_types_hash
= allocate_signatured_type_table ();
2432 for (offset_type i
= 0; i
< elements
; i
+= 3)
2434 struct signatured_type
*sig_type
;
2437 cu_offset type_offset_in_tu
;
2439 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2440 sect_offset sect_off
2441 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2443 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2445 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2448 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2449 struct signatured_type
);
2450 sig_type
->signature
= signature
;
2451 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2452 sig_type
->per_cu
.is_debug_types
= 1;
2453 sig_type
->per_cu
.section
= section
;
2454 sig_type
->per_cu
.sect_off
= sect_off
;
2455 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2456 sig_type
->per_cu
.v
.quick
2457 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2458 struct dwarf2_per_cu_quick_data
);
2460 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2463 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2466 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2469 /* Create the signatured type hash table from .debug_names. */
2472 create_signatured_type_table_from_debug_names
2473 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2474 const mapped_debug_names
&map
,
2475 struct dwarf2_section_info
*section
,
2476 struct dwarf2_section_info
*abbrev_section
)
2478 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2480 section
->read (objfile
);
2481 abbrev_section
->read (objfile
);
2483 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2484 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2486 htab_up sig_types_hash
= allocate_signatured_type_table ();
2488 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2490 struct signatured_type
*sig_type
;
2493 sect_offset sect_off
2494 = (sect_offset
) (extract_unsigned_integer
2495 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2497 map
.dwarf5_byte_order
));
2499 comp_unit_head cu_header
;
2500 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2502 section
->buffer
+ to_underlying (sect_off
),
2505 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2506 struct signatured_type
);
2507 sig_type
->signature
= cu_header
.signature
;
2508 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2509 sig_type
->per_cu
.is_debug_types
= 1;
2510 sig_type
->per_cu
.section
= section
;
2511 sig_type
->per_cu
.sect_off
= sect_off
;
2512 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2513 sig_type
->per_cu
.v
.quick
2514 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2515 struct dwarf2_per_cu_quick_data
);
2517 slot
= htab_find_slot (sig_types_hash
.get (), sig_type
, INSERT
);
2520 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2523 dwarf2_per_objfile
->signatured_types
= std::move (sig_types_hash
);
2526 /* Read the address map data from the mapped index, and use it to
2527 populate the objfile's psymtabs_addrmap. */
2530 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2531 struct mapped_index
*index
)
2533 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2534 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2535 const gdb_byte
*iter
, *end
;
2536 struct addrmap
*mutable_map
;
2539 auto_obstack temp_obstack
;
2541 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2543 iter
= index
->address_table
.data ();
2544 end
= iter
+ index
->address_table
.size ();
2546 baseaddr
= objfile
->text_section_offset ();
2550 ULONGEST hi
, lo
, cu_index
;
2551 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2553 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2555 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2560 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2561 hex_string (lo
), hex_string (hi
));
2565 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2567 complaint (_(".gdb_index address table has invalid CU number %u"),
2568 (unsigned) cu_index
);
2572 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2573 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2574 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2575 dwarf2_per_objfile
->get_cu (cu_index
));
2578 objfile
->partial_symtabs
->psymtabs_addrmap
2579 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2582 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2583 populate the objfile's psymtabs_addrmap. */
2586 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2587 struct dwarf2_section_info
*section
)
2589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2590 bfd
*abfd
= objfile
->obfd
;
2591 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2592 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2594 auto_obstack temp_obstack
;
2595 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
2597 std::unordered_map
<sect_offset
,
2598 dwarf2_per_cu_data
*,
2599 gdb::hash_enum
<sect_offset
>>
2600 debug_info_offset_to_per_cu
;
2601 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
2603 const auto insertpair
2604 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
2605 if (!insertpair
.second
)
2607 warning (_("Section .debug_aranges in %s has duplicate "
2608 "debug_info_offset %s, ignoring .debug_aranges."),
2609 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
2614 section
->read (objfile
);
2616 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
2618 const gdb_byte
*addr
= section
->buffer
;
2620 while (addr
< section
->buffer
+ section
->size
)
2622 const gdb_byte
*const entry_addr
= addr
;
2623 unsigned int bytes_read
;
2625 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
2629 const gdb_byte
*const entry_end
= addr
+ entry_length
;
2630 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
2631 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
2632 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
2634 warning (_("Section .debug_aranges in %s entry at offset %s "
2635 "length %s exceeds section length %s, "
2636 "ignoring .debug_aranges."),
2637 objfile_name (objfile
),
2638 plongest (entry_addr
- section
->buffer
),
2639 plongest (bytes_read
+ entry_length
),
2640 pulongest (section
->size
));
2644 /* The version number. */
2645 const uint16_t version
= read_2_bytes (abfd
, addr
);
2649 warning (_("Section .debug_aranges in %s entry at offset %s "
2650 "has unsupported version %d, ignoring .debug_aranges."),
2651 objfile_name (objfile
),
2652 plongest (entry_addr
- section
->buffer
), version
);
2656 const uint64_t debug_info_offset
2657 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
2658 addr
+= offset_size
;
2659 const auto per_cu_it
2660 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
2661 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
2663 warning (_("Section .debug_aranges in %s entry at offset %s "
2664 "debug_info_offset %s does not exists, "
2665 "ignoring .debug_aranges."),
2666 objfile_name (objfile
),
2667 plongest (entry_addr
- section
->buffer
),
2668 pulongest (debug_info_offset
));
2671 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
2673 const uint8_t address_size
= *addr
++;
2674 if (address_size
< 1 || address_size
> 8)
2676 warning (_("Section .debug_aranges in %s entry at offset %s "
2677 "address_size %u is invalid, ignoring .debug_aranges."),
2678 objfile_name (objfile
),
2679 plongest (entry_addr
- section
->buffer
), address_size
);
2683 const uint8_t segment_selector_size
= *addr
++;
2684 if (segment_selector_size
!= 0)
2686 warning (_("Section .debug_aranges in %s entry at offset %s "
2687 "segment_selector_size %u is not supported, "
2688 "ignoring .debug_aranges."),
2689 objfile_name (objfile
),
2690 plongest (entry_addr
- section
->buffer
),
2691 segment_selector_size
);
2695 /* Must pad to an alignment boundary that is twice the address
2696 size. It is undocumented by the DWARF standard but GCC does
2698 for (size_t padding
= ((-(addr
- section
->buffer
))
2699 & (2 * address_size
- 1));
2700 padding
> 0; padding
--)
2703 warning (_("Section .debug_aranges in %s entry at offset %s "
2704 "padding is not zero, ignoring .debug_aranges."),
2705 objfile_name (objfile
),
2706 plongest (entry_addr
- section
->buffer
));
2712 if (addr
+ 2 * address_size
> entry_end
)
2714 warning (_("Section .debug_aranges in %s entry at offset %s "
2715 "address list is not properly terminated, "
2716 "ignoring .debug_aranges."),
2717 objfile_name (objfile
),
2718 plongest (entry_addr
- section
->buffer
));
2721 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
2723 addr
+= address_size
;
2724 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
2726 addr
+= address_size
;
2727 if (start
== 0 && length
== 0)
2729 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
2731 /* Symbol was eliminated due to a COMDAT group. */
2734 ULONGEST end
= start
+ length
;
2735 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
2737 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
2739 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
2743 objfile
->partial_symtabs
->psymtabs_addrmap
2744 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2747 /* Find a slot in the mapped index INDEX for the object named NAME.
2748 If NAME is found, set *VEC_OUT to point to the CU vector in the
2749 constant pool and return true. If NAME cannot be found, return
2753 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2754 offset_type
**vec_out
)
2757 offset_type slot
, step
;
2758 int (*cmp
) (const char *, const char *);
2760 gdb::unique_xmalloc_ptr
<char> without_params
;
2761 if (current_language
->la_language
== language_cplus
2762 || current_language
->la_language
== language_fortran
2763 || current_language
->la_language
== language_d
)
2765 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2768 if (strchr (name
, '(') != NULL
)
2770 without_params
= cp_remove_params (name
);
2772 if (without_params
!= NULL
)
2773 name
= without_params
.get ();
2777 /* Index version 4 did not support case insensitive searches. But the
2778 indices for case insensitive languages are built in lowercase, therefore
2779 simulate our NAME being searched is also lowercased. */
2780 hash
= mapped_index_string_hash ((index
->version
== 4
2781 && case_sensitivity
== case_sensitive_off
2782 ? 5 : index
->version
),
2785 slot
= hash
& (index
->symbol_table
.size () - 1);
2786 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
2787 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2793 const auto &bucket
= index
->symbol_table
[slot
];
2794 if (bucket
.name
== 0 && bucket
.vec
== 0)
2797 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
2798 if (!cmp (name
, str
))
2800 *vec_out
= (offset_type
*) (index
->constant_pool
2801 + MAYBE_SWAP (bucket
.vec
));
2805 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
2809 /* A helper function that reads the .gdb_index from BUFFER and fills
2810 in MAP. FILENAME is the name of the file containing the data;
2811 it is used for error reporting. DEPRECATED_OK is true if it is
2812 ok to use deprecated sections.
2814 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
2815 out parameters that are filled in with information about the CU and
2816 TU lists in the section.
2818 Returns true if all went well, false otherwise. */
2821 read_gdb_index_from_buffer (struct objfile
*objfile
,
2822 const char *filename
,
2824 gdb::array_view
<const gdb_byte
> buffer
,
2825 struct mapped_index
*map
,
2826 const gdb_byte
**cu_list
,
2827 offset_type
*cu_list_elements
,
2828 const gdb_byte
**types_list
,
2829 offset_type
*types_list_elements
)
2831 const gdb_byte
*addr
= &buffer
[0];
2833 /* Version check. */
2834 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
2835 /* Versions earlier than 3 emitted every copy of a psymbol. This
2836 causes the index to behave very poorly for certain requests. Version 3
2837 contained incomplete addrmap. So, it seems better to just ignore such
2841 static int warning_printed
= 0;
2842 if (!warning_printed
)
2844 warning (_("Skipping obsolete .gdb_index section in %s."),
2846 warning_printed
= 1;
2850 /* Index version 4 uses a different hash function than index version
2853 Versions earlier than 6 did not emit psymbols for inlined
2854 functions. Using these files will cause GDB not to be able to
2855 set breakpoints on inlined functions by name, so we ignore these
2856 indices unless the user has done
2857 "set use-deprecated-index-sections on". */
2858 if (version
< 6 && !deprecated_ok
)
2860 static int warning_printed
= 0;
2861 if (!warning_printed
)
2864 Skipping deprecated .gdb_index section in %s.\n\
2865 Do \"set use-deprecated-index-sections on\" before the file is read\n\
2866 to use the section anyway."),
2868 warning_printed
= 1;
2872 /* Version 7 indices generated by gold refer to the CU for a symbol instead
2873 of the TU (for symbols coming from TUs),
2874 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
2875 Plus gold-generated indices can have duplicate entries for global symbols,
2876 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
2877 These are just performance bugs, and we can't distinguish gdb-generated
2878 indices from gold-generated ones, so issue no warning here. */
2880 /* Indexes with higher version than the one supported by GDB may be no
2881 longer backward compatible. */
2885 map
->version
= version
;
2887 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2890 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2891 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2895 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2896 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2897 - MAYBE_SWAP (metadata
[i
]))
2901 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2902 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2904 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
2907 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2908 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
2910 = gdb::array_view
<mapped_index::symbol_table_slot
>
2911 ((mapped_index::symbol_table_slot
*) symbol_table
,
2912 (mapped_index::symbol_table_slot
*) symbol_table_end
);
2915 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
2920 /* Callback types for dwarf2_read_gdb_index. */
2922 typedef gdb::function_view
2923 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
2924 get_gdb_index_contents_ftype
;
2925 typedef gdb::function_view
2926 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
2927 get_gdb_index_contents_dwz_ftype
;
2929 /* Read .gdb_index. If everything went ok, initialize the "quick"
2930 elements of all the CUs and return 1. Otherwise, return 0. */
2933 dwarf2_read_gdb_index
2934 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2935 get_gdb_index_contents_ftype get_gdb_index_contents
,
2936 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
2938 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
2939 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
2940 struct dwz_file
*dwz
;
2941 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2943 gdb::array_view
<const gdb_byte
> main_index_contents
2944 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
2946 if (main_index_contents
.empty ())
2949 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
2950 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
2951 use_deprecated_index_sections
,
2952 main_index_contents
, map
.get (), &cu_list
,
2953 &cu_list_elements
, &types_list
,
2954 &types_list_elements
))
2957 /* Don't use the index if it's empty. */
2958 if (map
->symbol_table
.empty ())
2961 /* If there is a .dwz file, read it so we can get its CU list as
2963 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2966 struct mapped_index dwz_map
;
2967 const gdb_byte
*dwz_types_ignore
;
2968 offset_type dwz_types_elements_ignore
;
2970 gdb::array_view
<const gdb_byte
> dwz_index_content
2971 = get_gdb_index_contents_dwz (objfile
, dwz
);
2973 if (dwz_index_content
.empty ())
2976 if (!read_gdb_index_from_buffer (objfile
,
2977 bfd_get_filename (dwz
->dwz_bfd
.get ()),
2978 1, dwz_index_content
, &dwz_map
,
2979 &dwz_list
, &dwz_list_elements
,
2981 &dwz_types_elements_ignore
))
2983 warning (_("could not read '.gdb_index' section from %s; skipping"),
2984 bfd_get_filename (dwz
->dwz_bfd
.get ()));
2989 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2990 dwz_list
, dwz_list_elements
);
2992 if (types_list_elements
)
2994 /* We can only handle a single .debug_types when we have an
2996 if (dwarf2_per_objfile
->types
.size () != 1)
2999 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3001 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3002 types_list
, types_list_elements
);
3005 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3007 dwarf2_per_objfile
->index_table
= std::move (map
);
3008 dwarf2_per_objfile
->using_index
= 1;
3009 dwarf2_per_objfile
->quick_file_names_table
=
3010 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3015 /* die_reader_func for dw2_get_file_names. */
3018 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3019 const gdb_byte
*info_ptr
,
3020 struct die_info
*comp_unit_die
)
3022 struct dwarf2_cu
*cu
= reader
->cu
;
3023 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3024 struct dwarf2_per_objfile
*dwarf2_per_objfile
3025 = cu
->per_cu
->dwarf2_per_objfile
;
3026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3027 struct dwarf2_per_cu_data
*lh_cu
;
3028 struct attribute
*attr
;
3030 struct quick_file_names
*qfn
;
3032 gdb_assert (! this_cu
->is_debug_types
);
3034 /* Our callers never want to match partial units -- instead they
3035 will match the enclosing full CU. */
3036 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3038 this_cu
->v
.quick
->no_file_data
= 1;
3046 sect_offset line_offset
{};
3048 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3049 if (attr
!= nullptr)
3051 struct quick_file_names find_entry
;
3053 line_offset
= (sect_offset
) DW_UNSND (attr
);
3055 /* We may have already read in this line header (TU line header sharing).
3056 If we have we're done. */
3057 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3058 find_entry
.hash
.line_sect_off
= line_offset
;
3059 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
.get (),
3060 &find_entry
, INSERT
);
3063 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3067 lh
= dwarf_decode_line_header (line_offset
, cu
);
3071 lh_cu
->v
.quick
->no_file_data
= 1;
3075 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3076 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3077 qfn
->hash
.line_sect_off
= line_offset
;
3078 gdb_assert (slot
!= NULL
);
3081 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3084 if (strcmp (fnd
.name
, "<unknown>") != 0)
3087 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3089 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3091 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3092 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3093 qfn
->file_names
[i
+ offset
] = lh
->file_full_name (i
+ 1,
3094 fnd
.comp_dir
).release ();
3095 qfn
->real_names
= NULL
;
3097 lh_cu
->v
.quick
->file_names
= qfn
;
3100 /* A helper for the "quick" functions which attempts to read the line
3101 table for THIS_CU. */
3103 static struct quick_file_names
*
3104 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3106 /* This should never be called for TUs. */
3107 gdb_assert (! this_cu
->is_debug_types
);
3108 /* Nor type unit groups. */
3109 gdb_assert (! this_cu
->type_unit_group_p ());
3111 if (this_cu
->v
.quick
->file_names
!= NULL
)
3112 return this_cu
->v
.quick
->file_names
;
3113 /* If we know there is no line data, no point in looking again. */
3114 if (this_cu
->v
.quick
->no_file_data
)
3117 cutu_reader
reader (this_cu
);
3118 if (!reader
.dummy_p
)
3119 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
);
3121 if (this_cu
->v
.quick
->no_file_data
)
3123 return this_cu
->v
.quick
->file_names
;
3126 /* A helper for the "quick" functions which computes and caches the
3127 real path for a given file name from the line table. */
3130 dw2_get_real_path (struct objfile
*objfile
,
3131 struct quick_file_names
*qfn
, int index
)
3133 if (qfn
->real_names
== NULL
)
3134 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3135 qfn
->num_file_names
, const char *);
3137 if (qfn
->real_names
[index
] == NULL
)
3138 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3140 return qfn
->real_names
[index
];
3143 static struct symtab
*
3144 dw2_find_last_source_symtab (struct objfile
*objfile
)
3146 struct dwarf2_per_objfile
*dwarf2_per_objfile
3147 = get_dwarf2_per_objfile (objfile
);
3148 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3149 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3154 return compunit_primary_filetab (cust
);
3157 /* Traversal function for dw2_forget_cached_source_info. */
3160 dw2_free_cached_file_names (void **slot
, void *info
)
3162 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3164 if (file_data
->real_names
)
3168 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3170 xfree ((void*) file_data
->real_names
[i
]);
3171 file_data
->real_names
[i
] = NULL
;
3179 dw2_forget_cached_source_info (struct objfile
*objfile
)
3181 struct dwarf2_per_objfile
*dwarf2_per_objfile
3182 = get_dwarf2_per_objfile (objfile
);
3184 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
.get (),
3185 dw2_free_cached_file_names
, NULL
);
3188 /* Helper function for dw2_map_symtabs_matching_filename that expands
3189 the symtabs and calls the iterator. */
3192 dw2_map_expand_apply (struct objfile
*objfile
,
3193 struct dwarf2_per_cu_data
*per_cu
,
3194 const char *name
, const char *real_path
,
3195 gdb::function_view
<bool (symtab
*)> callback
)
3197 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3199 /* Don't visit already-expanded CUs. */
3200 if (per_cu
->v
.quick
->compunit_symtab
)
3203 /* This may expand more than one symtab, and we want to iterate over
3205 dw2_instantiate_symtab (per_cu
, false);
3207 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3208 last_made
, callback
);
3211 /* Implementation of the map_symtabs_matching_filename method. */
3214 dw2_map_symtabs_matching_filename
3215 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3216 gdb::function_view
<bool (symtab
*)> callback
)
3218 const char *name_basename
= lbasename (name
);
3219 struct dwarf2_per_objfile
*dwarf2_per_objfile
3220 = get_dwarf2_per_objfile (objfile
);
3222 /* The rule is CUs specify all the files, including those used by
3223 any TU, so there's no need to scan TUs here. */
3225 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3227 /* We only need to look at symtabs not already expanded. */
3228 if (per_cu
->v
.quick
->compunit_symtab
)
3231 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3232 if (file_data
== NULL
)
3235 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3237 const char *this_name
= file_data
->file_names
[j
];
3238 const char *this_real_name
;
3240 if (compare_filenames_for_search (this_name
, name
))
3242 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3248 /* Before we invoke realpath, which can get expensive when many
3249 files are involved, do a quick comparison of the basenames. */
3250 if (! basenames_may_differ
3251 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3254 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3255 if (compare_filenames_for_search (this_real_name
, name
))
3257 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3263 if (real_path
!= NULL
)
3265 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3266 gdb_assert (IS_ABSOLUTE_PATH (name
));
3267 if (this_real_name
!= NULL
3268 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3270 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3282 /* Struct used to manage iterating over all CUs looking for a symbol. */
3284 struct dw2_symtab_iterator
3286 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3287 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3288 /* If set, only look for symbols that match that block. Valid values are
3289 GLOBAL_BLOCK and STATIC_BLOCK. */
3290 gdb::optional
<block_enum
> block_index
;
3291 /* The kind of symbol we're looking for. */
3293 /* The list of CUs from the index entry of the symbol,
3294 or NULL if not found. */
3296 /* The next element in VEC to look at. */
3298 /* The number of elements in VEC, or zero if there is no match. */
3300 /* Have we seen a global version of the symbol?
3301 If so we can ignore all further global instances.
3302 This is to work around gold/15646, inefficient gold-generated
3307 /* Initialize the index symtab iterator ITER. */
3310 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3311 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3312 gdb::optional
<block_enum
> block_index
,
3316 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3317 iter
->block_index
= block_index
;
3318 iter
->domain
= domain
;
3320 iter
->global_seen
= 0;
3322 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3324 /* index is NULL if OBJF_READNOW. */
3325 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3326 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3334 /* Return the next matching CU or NULL if there are no more. */
3336 static struct dwarf2_per_cu_data
*
3337 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3339 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3341 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3343 offset_type cu_index_and_attrs
=
3344 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3345 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3346 gdb_index_symbol_kind symbol_kind
=
3347 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3348 /* Only check the symbol attributes if they're present.
3349 Indices prior to version 7 don't record them,
3350 and indices >= 7 may elide them for certain symbols
3351 (gold does this). */
3353 (dwarf2_per_objfile
->index_table
->version
>= 7
3354 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3356 /* Don't crash on bad data. */
3357 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3358 + dwarf2_per_objfile
->all_type_units
.size ()))
3360 complaint (_(".gdb_index entry has bad CU index"
3362 objfile_name (dwarf2_per_objfile
->objfile
));
3366 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3368 /* Skip if already read in. */
3369 if (per_cu
->v
.quick
->compunit_symtab
)
3372 /* Check static vs global. */
3375 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3377 if (iter
->block_index
.has_value ())
3379 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3381 if (is_static
!= want_static
)
3385 /* Work around gold/15646. */
3386 if (!is_static
&& iter
->global_seen
)
3389 iter
->global_seen
= 1;
3392 /* Only check the symbol's kind if it has one. */
3395 switch (iter
->domain
)
3398 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3399 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3400 /* Some types are also in VAR_DOMAIN. */
3401 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3405 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3409 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3413 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3428 static struct compunit_symtab
*
3429 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3430 const char *name
, domain_enum domain
)
3432 struct compunit_symtab
*stab_best
= NULL
;
3433 struct dwarf2_per_objfile
*dwarf2_per_objfile
3434 = get_dwarf2_per_objfile (objfile
);
3436 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3438 struct dw2_symtab_iterator iter
;
3439 struct dwarf2_per_cu_data
*per_cu
;
3441 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3443 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3445 struct symbol
*sym
, *with_opaque
= NULL
;
3446 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3447 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3448 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3450 sym
= block_find_symbol (block
, name
, domain
,
3451 block_find_non_opaque_type_preferred
,
3454 /* Some caution must be observed with overloaded functions
3455 and methods, since the index will not contain any overload
3456 information (but NAME might contain it). */
3459 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3461 if (with_opaque
!= NULL
3462 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3465 /* Keep looking through other CUs. */
3472 dw2_print_stats (struct objfile
*objfile
)
3474 struct dwarf2_per_objfile
*dwarf2_per_objfile
3475 = get_dwarf2_per_objfile (objfile
);
3476 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3477 + dwarf2_per_objfile
->all_type_units
.size ());
3480 for (int i
= 0; i
< total
; ++i
)
3482 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3484 if (!per_cu
->v
.quick
->compunit_symtab
)
3487 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3488 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3491 /* This dumps minimal information about the index.
3492 It is called via "mt print objfiles".
3493 One use is to verify .gdb_index has been loaded by the
3494 gdb.dwarf2/gdb-index.exp testcase. */
3497 dw2_dump (struct objfile
*objfile
)
3499 struct dwarf2_per_objfile
*dwarf2_per_objfile
3500 = get_dwarf2_per_objfile (objfile
);
3502 gdb_assert (dwarf2_per_objfile
->using_index
);
3503 printf_filtered (".gdb_index:");
3504 if (dwarf2_per_objfile
->index_table
!= NULL
)
3506 printf_filtered (" version %d\n",
3507 dwarf2_per_objfile
->index_table
->version
);
3510 printf_filtered (" faked for \"readnow\"\n");
3511 printf_filtered ("\n");
3515 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3516 const char *func_name
)
3518 struct dwarf2_per_objfile
*dwarf2_per_objfile
3519 = get_dwarf2_per_objfile (objfile
);
3521 struct dw2_symtab_iterator iter
;
3522 struct dwarf2_per_cu_data
*per_cu
;
3524 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3526 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3527 dw2_instantiate_symtab (per_cu
, false);
3532 dw2_expand_all_symtabs (struct objfile
*objfile
)
3534 struct dwarf2_per_objfile
*dwarf2_per_objfile
3535 = get_dwarf2_per_objfile (objfile
);
3536 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3537 + dwarf2_per_objfile
->all_type_units
.size ());
3539 for (int i
= 0; i
< total_units
; ++i
)
3541 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3543 /* We don't want to directly expand a partial CU, because if we
3544 read it with the wrong language, then assertion failures can
3545 be triggered later on. See PR symtab/23010. So, tell
3546 dw2_instantiate_symtab to skip partial CUs -- any important
3547 partial CU will be read via DW_TAG_imported_unit anyway. */
3548 dw2_instantiate_symtab (per_cu
, true);
3553 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3554 const char *fullname
)
3556 struct dwarf2_per_objfile
*dwarf2_per_objfile
3557 = get_dwarf2_per_objfile (objfile
);
3559 /* We don't need to consider type units here.
3560 This is only called for examining code, e.g. expand_line_sal.
3561 There can be an order of magnitude (or more) more type units
3562 than comp units, and we avoid them if we can. */
3564 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3566 /* We only need to look at symtabs not already expanded. */
3567 if (per_cu
->v
.quick
->compunit_symtab
)
3570 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3571 if (file_data
== NULL
)
3574 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3576 const char *this_fullname
= file_data
->file_names
[j
];
3578 if (filename_cmp (this_fullname
, fullname
) == 0)
3580 dw2_instantiate_symtab (per_cu
, false);
3588 dw2_map_matching_symbols
3589 (struct objfile
*objfile
,
3590 const lookup_name_info
&name
, domain_enum domain
,
3592 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3593 symbol_compare_ftype
*ordered_compare
)
3596 struct dwarf2_per_objfile
*dwarf2_per_objfile
3597 = get_dwarf2_per_objfile (objfile
);
3599 if (dwarf2_per_objfile
->index_table
!= nullptr)
3601 /* Ada currently doesn't support .gdb_index (see PR24713). We can get
3602 here though if the current language is Ada for a non-Ada objfile
3603 using GNU index. As Ada does not look for non-Ada symbols this
3604 function should just return. */
3608 /* We have -readnow: no .gdb_index, but no partial symtabs either. So,
3609 inline psym_map_matching_symbols here, assuming all partial symtabs have
3611 const int block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
3613 for (compunit_symtab
*cust
: objfile
->compunits ())
3615 const struct block
*block
;
3619 block
= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
3620 if (!iterate_over_symbols_terminated (block
, name
,
3626 /* Starting from a search name, return the string that finds the upper
3627 bound of all strings that start with SEARCH_NAME in a sorted name
3628 list. Returns the empty string to indicate that the upper bound is
3629 the end of the list. */
3632 make_sort_after_prefix_name (const char *search_name
)
3634 /* When looking to complete "func", we find the upper bound of all
3635 symbols that start with "func" by looking for where we'd insert
3636 the closest string that would follow "func" in lexicographical
3637 order. Usually, that's "func"-with-last-character-incremented,
3638 i.e. "fund". Mind non-ASCII characters, though. Usually those
3639 will be UTF-8 multi-byte sequences, but we can't be certain.
3640 Especially mind the 0xff character, which is a valid character in
3641 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3642 rule out compilers allowing it in identifiers. Note that
3643 conveniently, strcmp/strcasecmp are specified to compare
3644 characters interpreted as unsigned char. So what we do is treat
3645 the whole string as a base 256 number composed of a sequence of
3646 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3647 to 0, and carries 1 to the following more-significant position.
3648 If the very first character in SEARCH_NAME ends up incremented
3649 and carries/overflows, then the upper bound is the end of the
3650 list. The string after the empty string is also the empty
3653 Some examples of this operation:
3655 SEARCH_NAME => "+1" RESULT
3659 "\xff" "a" "\xff" => "\xff" "b"
3664 Then, with these symbols for example:
3670 completing "func" looks for symbols between "func" and
3671 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3672 which finds "func" and "func1", but not "fund".
3676 funcÿ (Latin1 'ÿ' [0xff])
3680 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3681 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3685 ÿÿ (Latin1 'ÿ' [0xff])
3688 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3689 the end of the list.
3691 std::string after
= search_name
;
3692 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3694 if (!after
.empty ())
3695 after
.back () = (unsigned char) after
.back () + 1;
3699 /* See declaration. */
3701 std::pair
<std::vector
<name_component
>::const_iterator
,
3702 std::vector
<name_component
>::const_iterator
>
3703 mapped_index_base::find_name_components_bounds
3704 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3707 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3709 const char *lang_name
3710 = lookup_name_without_params
.language_lookup_name (lang
);
3712 /* Comparison function object for lower_bound that matches against a
3713 given symbol name. */
3714 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3717 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3718 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3719 return name_cmp (elem_name
, name
) < 0;
3722 /* Comparison function object for upper_bound that matches against a
3723 given symbol name. */
3724 auto lookup_compare_upper
= [&] (const char *name
,
3725 const name_component
&elem
)
3727 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3728 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3729 return name_cmp (name
, elem_name
) < 0;
3732 auto begin
= this->name_components
.begin ();
3733 auto end
= this->name_components
.end ();
3735 /* Find the lower bound. */
3738 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3741 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3744 /* Find the upper bound. */
3747 if (lookup_name_without_params
.completion_mode ())
3749 /* In completion mode, we want UPPER to point past all
3750 symbols names that have the same prefix. I.e., with
3751 these symbols, and completing "func":
3753 function << lower bound
3755 other_function << upper bound
3757 We find the upper bound by looking for the insertion
3758 point of "func"-with-last-character-incremented,
3760 std::string after
= make_sort_after_prefix_name (lang_name
);
3763 return std::lower_bound (lower
, end
, after
.c_str (),
3764 lookup_compare_lower
);
3767 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3770 return {lower
, upper
};
3773 /* See declaration. */
3776 mapped_index_base::build_name_components ()
3778 if (!this->name_components
.empty ())
3781 this->name_components_casing
= case_sensitivity
;
3783 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3785 /* The code below only knows how to break apart components of C++
3786 symbol names (and other languages that use '::' as
3787 namespace/module separator) and Ada symbol names. */
3788 auto count
= this->symbol_name_count ();
3789 for (offset_type idx
= 0; idx
< count
; idx
++)
3791 if (this->symbol_name_slot_invalid (idx
))
3794 const char *name
= this->symbol_name_at (idx
);
3796 /* Add each name component to the name component table. */
3797 unsigned int previous_len
= 0;
3799 if (strstr (name
, "::") != nullptr)
3801 for (unsigned int current_len
= cp_find_first_component (name
);
3802 name
[current_len
] != '\0';
3803 current_len
+= cp_find_first_component (name
+ current_len
))
3805 gdb_assert (name
[current_len
] == ':');
3806 this->name_components
.push_back ({previous_len
, idx
});
3807 /* Skip the '::'. */
3809 previous_len
= current_len
;
3814 /* Handle the Ada encoded (aka mangled) form here. */
3815 for (const char *iter
= strstr (name
, "__");
3817 iter
= strstr (iter
, "__"))
3819 this->name_components
.push_back ({previous_len
, idx
});
3821 previous_len
= iter
- name
;
3825 this->name_components
.push_back ({previous_len
, idx
});
3828 /* Sort name_components elements by name. */
3829 auto name_comp_compare
= [&] (const name_component
&left
,
3830 const name_component
&right
)
3832 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3833 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3835 const char *left_name
= left_qualified
+ left
.name_offset
;
3836 const char *right_name
= right_qualified
+ right
.name_offset
;
3838 return name_cmp (left_name
, right_name
) < 0;
3841 std::sort (this->name_components
.begin (),
3842 this->name_components
.end (),
3846 /* Helper for dw2_expand_symtabs_matching that works with a
3847 mapped_index_base instead of the containing objfile. This is split
3848 to a separate function in order to be able to unit test the
3849 name_components matching using a mock mapped_index_base. For each
3850 symbol name that matches, calls MATCH_CALLBACK, passing it the
3851 symbol's index in the mapped_index_base symbol table. */
3854 dw2_expand_symtabs_matching_symbol
3855 (mapped_index_base
&index
,
3856 const lookup_name_info
&lookup_name_in
,
3857 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3858 enum search_domain kind
,
3859 gdb::function_view
<bool (offset_type
)> match_callback
)
3861 lookup_name_info lookup_name_without_params
3862 = lookup_name_in
.make_ignore_params ();
3864 /* Build the symbol name component sorted vector, if we haven't
3866 index
.build_name_components ();
3868 /* The same symbol may appear more than once in the range though.
3869 E.g., if we're looking for symbols that complete "w", and we have
3870 a symbol named "w1::w2", we'll find the two name components for
3871 that same symbol in the range. To be sure we only call the
3872 callback once per symbol, we first collect the symbol name
3873 indexes that matched in a temporary vector and ignore
3875 std::vector
<offset_type
> matches
;
3877 struct name_and_matcher
3879 symbol_name_matcher_ftype
*matcher
;
3880 const std::string
&name
;
3882 bool operator== (const name_and_matcher
&other
) const
3884 return matcher
== other
.matcher
&& name
== other
.name
;
3888 /* A vector holding all the different symbol name matchers, for all
3890 std::vector
<name_and_matcher
> matchers
;
3892 for (int i
= 0; i
< nr_languages
; i
++)
3894 enum language lang_e
= (enum language
) i
;
3896 const language_defn
*lang
= language_def (lang_e
);
3897 symbol_name_matcher_ftype
*name_matcher
3898 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3900 name_and_matcher key
{
3902 lookup_name_without_params
.language_lookup_name (lang_e
)
3905 /* Don't insert the same comparison routine more than once.
3906 Note that we do this linear walk. This is not a problem in
3907 practice because the number of supported languages is
3909 if (std::find (matchers
.begin (), matchers
.end (), key
)
3912 matchers
.push_back (std::move (key
));
3915 = index
.find_name_components_bounds (lookup_name_without_params
,
3918 /* Now for each symbol name in range, check to see if we have a name
3919 match, and if so, call the MATCH_CALLBACK callback. */
3921 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3923 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3925 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3926 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3929 matches
.push_back (bounds
.first
->idx
);
3933 std::sort (matches
.begin (), matches
.end ());
3935 /* Finally call the callback, once per match. */
3937 for (offset_type idx
: matches
)
3941 if (!match_callback (idx
))
3947 /* Above we use a type wider than idx's for 'prev', since 0 and
3948 (offset_type)-1 are both possible values. */
3949 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3954 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3956 /* A mock .gdb_index/.debug_names-like name index table, enough to
3957 exercise dw2_expand_symtabs_matching_symbol, which works with the
3958 mapped_index_base interface. Builds an index from the symbol list
3959 passed as parameter to the constructor. */
3960 class mock_mapped_index
: public mapped_index_base
3963 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3964 : m_symbol_table (symbols
)
3967 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3969 /* Return the number of names in the symbol table. */
3970 size_t symbol_name_count () const override
3972 return m_symbol_table
.size ();
3975 /* Get the name of the symbol at IDX in the symbol table. */
3976 const char *symbol_name_at (offset_type idx
) const override
3978 return m_symbol_table
[idx
];
3982 gdb::array_view
<const char *> m_symbol_table
;
3985 /* Convenience function that converts a NULL pointer to a "<null>"
3986 string, to pass to print routines. */
3989 string_or_null (const char *str
)
3991 return str
!= NULL
? str
: "<null>";
3994 /* Check if a lookup_name_info built from
3995 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3996 index. EXPECTED_LIST is the list of expected matches, in expected
3997 matching order. If no match expected, then an empty list is
3998 specified. Returns true on success. On failure prints a warning
3999 indicating the file:line that failed, and returns false. */
4002 check_match (const char *file
, int line
,
4003 mock_mapped_index
&mock_index
,
4004 const char *name
, symbol_name_match_type match_type
,
4005 bool completion_mode
,
4006 std::initializer_list
<const char *> expected_list
)
4008 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4010 bool matched
= true;
4012 auto mismatch
= [&] (const char *expected_str
,
4015 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4016 "expected=\"%s\", got=\"%s\"\n"),
4018 (match_type
== symbol_name_match_type::FULL
4020 name
, string_or_null (expected_str
), string_or_null (got
));
4024 auto expected_it
= expected_list
.begin ();
4025 auto expected_end
= expected_list
.end ();
4027 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4029 [&] (offset_type idx
)
4031 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4032 const char *expected_str
4033 = expected_it
== expected_end
? NULL
: *expected_it
++;
4035 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4036 mismatch (expected_str
, matched_name
);
4040 const char *expected_str
4041 = expected_it
== expected_end
? NULL
: *expected_it
++;
4042 if (expected_str
!= NULL
)
4043 mismatch (expected_str
, NULL
);
4048 /* The symbols added to the mock mapped_index for testing (in
4050 static const char *test_symbols
[] = {
4059 "ns2::tmpl<int>::foo2",
4060 "(anonymous namespace)::A::B::C",
4062 /* These are used to check that the increment-last-char in the
4063 matching algorithm for completion doesn't match "t1_fund" when
4064 completing "t1_func". */
4070 /* A UTF-8 name with multi-byte sequences to make sure that
4071 cp-name-parser understands this as a single identifier ("função"
4072 is "function" in PT). */
4075 /* \377 (0xff) is Latin1 'ÿ'. */
4078 /* \377 (0xff) is Latin1 'ÿ'. */
4082 /* A name with all sorts of complications. Starts with "z" to make
4083 it easier for the completion tests below. */
4084 #define Z_SYM_NAME \
4085 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4086 "::tuple<(anonymous namespace)::ui*, " \
4087 "std::default_delete<(anonymous namespace)::ui>, void>"
4092 /* Returns true if the mapped_index_base::find_name_component_bounds
4093 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4094 in completion mode. */
4097 check_find_bounds_finds (mapped_index_base
&index
,
4098 const char *search_name
,
4099 gdb::array_view
<const char *> expected_syms
)
4101 lookup_name_info
lookup_name (search_name
,
4102 symbol_name_match_type::FULL
, true);
4104 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4107 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4108 if (distance
!= expected_syms
.size ())
4111 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4113 auto nc_elem
= bounds
.first
+ exp_elem
;
4114 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4115 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4122 /* Test the lower-level mapped_index::find_name_component_bounds
4126 test_mapped_index_find_name_component_bounds ()
4128 mock_mapped_index
mock_index (test_symbols
);
4130 mock_index
.build_name_components ();
4132 /* Test the lower-level mapped_index::find_name_component_bounds
4133 method in completion mode. */
4135 static const char *expected_syms
[] = {
4140 SELF_CHECK (check_find_bounds_finds (mock_index
,
4141 "t1_func", expected_syms
));
4144 /* Check that the increment-last-char in the name matching algorithm
4145 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4147 static const char *expected_syms1
[] = {
4151 SELF_CHECK (check_find_bounds_finds (mock_index
,
4152 "\377", expected_syms1
));
4154 static const char *expected_syms2
[] = {
4157 SELF_CHECK (check_find_bounds_finds (mock_index
,
4158 "\377\377", expected_syms2
));
4162 /* Test dw2_expand_symtabs_matching_symbol. */
4165 test_dw2_expand_symtabs_matching_symbol ()
4167 mock_mapped_index
mock_index (test_symbols
);
4169 /* We let all tests run until the end even if some fails, for debug
4171 bool any_mismatch
= false;
4173 /* Create the expected symbols list (an initializer_list). Needed
4174 because lists have commas, and we need to pass them to CHECK,
4175 which is a macro. */
4176 #define EXPECT(...) { __VA_ARGS__ }
4178 /* Wrapper for check_match that passes down the current
4179 __FILE__/__LINE__. */
4180 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4181 any_mismatch |= !check_match (__FILE__, __LINE__, \
4183 NAME, MATCH_TYPE, COMPLETION_MODE, \
4186 /* Identity checks. */
4187 for (const char *sym
: test_symbols
)
4189 /* Should be able to match all existing symbols. */
4190 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4193 /* Should be able to match all existing symbols with
4195 std::string with_params
= std::string (sym
) + "(int)";
4196 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4199 /* Should be able to match all existing symbols with
4200 parameters and qualifiers. */
4201 with_params
= std::string (sym
) + " ( int ) const";
4202 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4205 /* This should really find sym, but cp-name-parser.y doesn't
4206 know about lvalue/rvalue qualifiers yet. */
4207 with_params
= std::string (sym
) + " ( int ) &&";
4208 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4212 /* Check that the name matching algorithm for completion doesn't get
4213 confused with Latin1 'ÿ' / 0xff. */
4215 static const char str
[] = "\377";
4216 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4217 EXPECT ("\377", "\377\377123"));
4220 /* Check that the increment-last-char in the matching algorithm for
4221 completion doesn't match "t1_fund" when completing "t1_func". */
4223 static const char str
[] = "t1_func";
4224 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4225 EXPECT ("t1_func", "t1_func1"));
4228 /* Check that completion mode works at each prefix of the expected
4231 static const char str
[] = "function(int)";
4232 size_t len
= strlen (str
);
4235 for (size_t i
= 1; i
< len
; i
++)
4237 lookup
.assign (str
, i
);
4238 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4239 EXPECT ("function"));
4243 /* While "w" is a prefix of both components, the match function
4244 should still only be called once. */
4246 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4248 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4252 /* Same, with a "complicated" symbol. */
4254 static const char str
[] = Z_SYM_NAME
;
4255 size_t len
= strlen (str
);
4258 for (size_t i
= 1; i
< len
; i
++)
4260 lookup
.assign (str
, i
);
4261 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4262 EXPECT (Z_SYM_NAME
));
4266 /* In FULL mode, an incomplete symbol doesn't match. */
4268 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4272 /* A complete symbol with parameters matches any overload, since the
4273 index has no overload info. */
4275 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4276 EXPECT ("std::zfunction", "std::zfunction2"));
4277 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4278 EXPECT ("std::zfunction", "std::zfunction2"));
4279 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4280 EXPECT ("std::zfunction", "std::zfunction2"));
4283 /* Check that whitespace is ignored appropriately. A symbol with a
4284 template argument list. */
4286 static const char expected
[] = "ns::foo<int>";
4287 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4289 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4293 /* Check that whitespace is ignored appropriately. A symbol with a
4294 template argument list that includes a pointer. */
4296 static const char expected
[] = "ns::foo<char*>";
4297 /* Try both completion and non-completion modes. */
4298 static const bool completion_mode
[2] = {false, true};
4299 for (size_t i
= 0; i
< 2; i
++)
4301 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4302 completion_mode
[i
], EXPECT (expected
));
4303 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4304 completion_mode
[i
], EXPECT (expected
));
4306 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4307 completion_mode
[i
], EXPECT (expected
));
4308 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4309 completion_mode
[i
], EXPECT (expected
));
4314 /* Check method qualifiers are ignored. */
4315 static const char expected
[] = "ns::foo<char*>";
4316 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4317 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4318 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4319 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4320 CHECK_MATCH ("foo < char * > ( int ) const",
4321 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4322 CHECK_MATCH ("foo < char * > ( int ) &&",
4323 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4326 /* Test lookup names that don't match anything. */
4328 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4331 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4335 /* Some wild matching tests, exercising "(anonymous namespace)",
4336 which should not be confused with a parameter list. */
4338 static const char *syms
[] = {
4342 "A :: B :: C ( int )",
4347 for (const char *s
: syms
)
4349 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4350 EXPECT ("(anonymous namespace)::A::B::C"));
4355 static const char expected
[] = "ns2::tmpl<int>::foo2";
4356 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4358 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4362 SELF_CHECK (!any_mismatch
);
4371 test_mapped_index_find_name_component_bounds ();
4372 test_dw2_expand_symtabs_matching_symbol ();
4375 }} // namespace selftests::dw2_expand_symtabs_matching
4377 #endif /* GDB_SELF_TEST */
4379 /* If FILE_MATCHER is NULL or if PER_CU has
4380 dwarf2_per_cu_quick_data::MARK set (see
4381 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4382 EXPANSION_NOTIFY on it. */
4385 dw2_expand_symtabs_matching_one
4386 (struct dwarf2_per_cu_data
*per_cu
,
4387 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4388 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4390 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4392 bool symtab_was_null
4393 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4395 dw2_instantiate_symtab (per_cu
, false);
4397 if (expansion_notify
!= NULL
4399 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4400 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4404 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4405 matched, to expand corresponding CUs that were marked. IDX is the
4406 index of the symbol name that matched. */
4409 dw2_expand_marked_cus
4410 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4411 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4412 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4415 offset_type
*vec
, vec_len
, vec_idx
;
4416 bool global_seen
= false;
4417 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4419 vec
= (offset_type
*) (index
.constant_pool
4420 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4421 vec_len
= MAYBE_SWAP (vec
[0]);
4422 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4424 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4425 /* This value is only valid for index versions >= 7. */
4426 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4427 gdb_index_symbol_kind symbol_kind
=
4428 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4429 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4430 /* Only check the symbol attributes if they're present.
4431 Indices prior to version 7 don't record them,
4432 and indices >= 7 may elide them for certain symbols
4433 (gold does this). */
4436 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4438 /* Work around gold/15646. */
4441 if (!is_static
&& global_seen
)
4447 /* Only check the symbol's kind if it has one. */
4452 case VARIABLES_DOMAIN
:
4453 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4456 case FUNCTIONS_DOMAIN
:
4457 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4461 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4464 case MODULES_DOMAIN
:
4465 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4473 /* Don't crash on bad data. */
4474 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4475 + dwarf2_per_objfile
->all_type_units
.size ()))
4477 complaint (_(".gdb_index entry has bad CU index"
4479 objfile_name (dwarf2_per_objfile
->objfile
));
4483 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4484 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4489 /* If FILE_MATCHER is non-NULL, set all the
4490 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4491 that match FILE_MATCHER. */
4494 dw_expand_symtabs_matching_file_matcher
4495 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4496 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4498 if (file_matcher
== NULL
)
4501 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4503 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4505 NULL
, xcalloc
, xfree
));
4506 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4508 NULL
, xcalloc
, xfree
));
4510 /* The rule is CUs specify all the files, including those used by
4511 any TU, so there's no need to scan TUs here. */
4513 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4517 per_cu
->v
.quick
->mark
= 0;
4519 /* We only need to look at symtabs not already expanded. */
4520 if (per_cu
->v
.quick
->compunit_symtab
)
4523 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4524 if (file_data
== NULL
)
4527 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4529 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4531 per_cu
->v
.quick
->mark
= 1;
4535 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4537 const char *this_real_name
;
4539 if (file_matcher (file_data
->file_names
[j
], false))
4541 per_cu
->v
.quick
->mark
= 1;
4545 /* Before we invoke realpath, which can get expensive when many
4546 files are involved, do a quick comparison of the basenames. */
4547 if (!basenames_may_differ
4548 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4552 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4553 if (file_matcher (this_real_name
, false))
4555 per_cu
->v
.quick
->mark
= 1;
4560 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4561 ? visited_found
.get ()
4562 : visited_not_found
.get (),
4569 dw2_expand_symtabs_matching
4570 (struct objfile
*objfile
,
4571 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4572 const lookup_name_info
&lookup_name
,
4573 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4574 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4575 enum search_domain kind
)
4577 struct dwarf2_per_objfile
*dwarf2_per_objfile
4578 = get_dwarf2_per_objfile (objfile
);
4580 /* index_table is NULL if OBJF_READNOW. */
4581 if (!dwarf2_per_objfile
->index_table
)
4584 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4586 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4588 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4590 kind
, [&] (offset_type idx
)
4592 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4593 expansion_notify
, kind
);
4598 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4601 static struct compunit_symtab
*
4602 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4607 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4608 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4611 if (cust
->includes
== NULL
)
4614 for (i
= 0; cust
->includes
[i
]; ++i
)
4616 struct compunit_symtab
*s
= cust
->includes
[i
];
4618 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4626 static struct compunit_symtab
*
4627 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4628 struct bound_minimal_symbol msymbol
,
4630 struct obj_section
*section
,
4633 struct dwarf2_per_cu_data
*data
;
4634 struct compunit_symtab
*result
;
4636 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4639 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4640 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4641 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4645 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4646 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4647 paddress (get_objfile_arch (objfile
), pc
));
4650 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4653 gdb_assert (result
!= NULL
);
4658 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4659 void *data
, int need_fullname
)
4661 struct dwarf2_per_objfile
*dwarf2_per_objfile
4662 = get_dwarf2_per_objfile (objfile
);
4664 if (!dwarf2_per_objfile
->filenames_cache
)
4666 dwarf2_per_objfile
->filenames_cache
.emplace ();
4668 htab_up
visited (htab_create_alloc (10,
4669 htab_hash_pointer
, htab_eq_pointer
,
4670 NULL
, xcalloc
, xfree
));
4672 /* The rule is CUs specify all the files, including those used
4673 by any TU, so there's no need to scan TUs here. We can
4674 ignore file names coming from already-expanded CUs. */
4676 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4678 if (per_cu
->v
.quick
->compunit_symtab
)
4680 void **slot
= htab_find_slot (visited
.get (),
4681 per_cu
->v
.quick
->file_names
,
4684 *slot
= per_cu
->v
.quick
->file_names
;
4688 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4690 /* We only need to look at symtabs not already expanded. */
4691 if (per_cu
->v
.quick
->compunit_symtab
)
4694 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4695 if (file_data
== NULL
)
4698 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4701 /* Already visited. */
4706 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4708 const char *filename
= file_data
->file_names
[j
];
4709 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4714 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4716 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4719 this_real_name
= gdb_realpath (filename
);
4720 (*fun
) (filename
, this_real_name
.get (), data
);
4725 dw2_has_symbols (struct objfile
*objfile
)
4730 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4733 dw2_find_last_source_symtab
,
4734 dw2_forget_cached_source_info
,
4735 dw2_map_symtabs_matching_filename
,
4740 dw2_expand_symtabs_for_function
,
4741 dw2_expand_all_symtabs
,
4742 dw2_expand_symtabs_with_fullname
,
4743 dw2_map_matching_symbols
,
4744 dw2_expand_symtabs_matching
,
4745 dw2_find_pc_sect_compunit_symtab
,
4747 dw2_map_symbol_filenames
4750 /* DWARF-5 debug_names reader. */
4752 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4753 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4755 /* A helper function that reads the .debug_names section in SECTION
4756 and fills in MAP. FILENAME is the name of the file containing the
4757 section; it is used for error reporting.
4759 Returns true if all went well, false otherwise. */
4762 read_debug_names_from_section (struct objfile
*objfile
,
4763 const char *filename
,
4764 struct dwarf2_section_info
*section
,
4765 mapped_debug_names
&map
)
4767 if (section
->empty ())
4770 /* Older elfutils strip versions could keep the section in the main
4771 executable while splitting it for the separate debug info file. */
4772 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4775 section
->read (objfile
);
4777 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4779 const gdb_byte
*addr
= section
->buffer
;
4781 bfd
*const abfd
= section
->get_bfd_owner ();
4783 unsigned int bytes_read
;
4784 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4787 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4788 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4789 if (bytes_read
+ length
!= section
->size
)
4791 /* There may be multiple per-CU indices. */
4792 warning (_("Section .debug_names in %s length %s does not match "
4793 "section length %s, ignoring .debug_names."),
4794 filename
, plongest (bytes_read
+ length
),
4795 pulongest (section
->size
));
4799 /* The version number. */
4800 uint16_t version
= read_2_bytes (abfd
, addr
);
4804 warning (_("Section .debug_names in %s has unsupported version %d, "
4805 "ignoring .debug_names."),
4811 uint16_t padding
= read_2_bytes (abfd
, addr
);
4815 warning (_("Section .debug_names in %s has unsupported padding %d, "
4816 "ignoring .debug_names."),
4821 /* comp_unit_count - The number of CUs in the CU list. */
4822 map
.cu_count
= read_4_bytes (abfd
, addr
);
4825 /* local_type_unit_count - The number of TUs in the local TU
4827 map
.tu_count
= read_4_bytes (abfd
, addr
);
4830 /* foreign_type_unit_count - The number of TUs in the foreign TU
4832 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4834 if (foreign_tu_count
!= 0)
4836 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4837 "ignoring .debug_names."),
4838 filename
, static_cast<unsigned long> (foreign_tu_count
));
4842 /* bucket_count - The number of hash buckets in the hash lookup
4844 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4847 /* name_count - The number of unique names in the index. */
4848 map
.name_count
= read_4_bytes (abfd
, addr
);
4851 /* abbrev_table_size - The size in bytes of the abbreviations
4853 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4856 /* augmentation_string_size - The size in bytes of the augmentation
4857 string. This value is rounded up to a multiple of 4. */
4858 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4860 map
.augmentation_is_gdb
= ((augmentation_string_size
4861 == sizeof (dwarf5_augmentation
))
4862 && memcmp (addr
, dwarf5_augmentation
,
4863 sizeof (dwarf5_augmentation
)) == 0);
4864 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4865 addr
+= augmentation_string_size
;
4868 map
.cu_table_reordered
= addr
;
4869 addr
+= map
.cu_count
* map
.offset_size
;
4871 /* List of Local TUs */
4872 map
.tu_table_reordered
= addr
;
4873 addr
+= map
.tu_count
* map
.offset_size
;
4875 /* Hash Lookup Table */
4876 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4877 addr
+= map
.bucket_count
* 4;
4878 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4879 addr
+= map
.name_count
* 4;
4882 map
.name_table_string_offs_reordered
= addr
;
4883 addr
+= map
.name_count
* map
.offset_size
;
4884 map
.name_table_entry_offs_reordered
= addr
;
4885 addr
+= map
.name_count
* map
.offset_size
;
4887 const gdb_byte
*abbrev_table_start
= addr
;
4890 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4895 const auto insertpair
4896 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4897 if (!insertpair
.second
)
4899 warning (_("Section .debug_names in %s has duplicate index %s, "
4900 "ignoring .debug_names."),
4901 filename
, pulongest (index_num
));
4904 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4905 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4910 mapped_debug_names::index_val::attr attr
;
4911 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4913 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4915 if (attr
.form
== DW_FORM_implicit_const
)
4917 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4921 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4923 indexval
.attr_vec
.push_back (std::move (attr
));
4926 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4928 warning (_("Section .debug_names in %s has abbreviation_table "
4929 "of size %s vs. written as %u, ignoring .debug_names."),
4930 filename
, plongest (addr
- abbrev_table_start
),
4934 map
.entry_pool
= addr
;
4939 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4943 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4944 const mapped_debug_names
&map
,
4945 dwarf2_section_info
§ion
,
4948 sect_offset sect_off_prev
;
4949 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4951 sect_offset sect_off_next
;
4952 if (i
< map
.cu_count
)
4955 = (sect_offset
) (extract_unsigned_integer
4956 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4958 map
.dwarf5_byte_order
));
4961 sect_off_next
= (sect_offset
) section
.size
;
4964 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4965 dwarf2_per_cu_data
*per_cu
4966 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4967 sect_off_prev
, length
);
4968 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4970 sect_off_prev
= sect_off_next
;
4974 /* Read the CU list from the mapped index, and use it to create all
4975 the CU objects for this dwarf2_per_objfile. */
4978 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4979 const mapped_debug_names
&map
,
4980 const mapped_debug_names
&dwz_map
)
4982 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4983 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4985 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4986 dwarf2_per_objfile
->info
,
4987 false /* is_dwz */);
4989 if (dwz_map
.cu_count
== 0)
4992 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4993 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4997 /* Read .debug_names. If everything went ok, initialize the "quick"
4998 elements of all the CUs and return true. Otherwise, return false. */
5001 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5003 std::unique_ptr
<mapped_debug_names
> map
5004 (new mapped_debug_names (dwarf2_per_objfile
));
5005 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5008 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5009 &dwarf2_per_objfile
->debug_names
,
5013 /* Don't use the index if it's empty. */
5014 if (map
->name_count
== 0)
5017 /* If there is a .dwz file, read it so we can get its CU list as
5019 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5022 if (!read_debug_names_from_section (objfile
,
5023 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5024 &dwz
->debug_names
, dwz_map
))
5026 warning (_("could not read '.debug_names' section from %s; skipping"),
5027 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5032 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5034 if (map
->tu_count
!= 0)
5036 /* We can only handle a single .debug_types when we have an
5038 if (dwarf2_per_objfile
->types
.size () != 1)
5041 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5043 create_signatured_type_table_from_debug_names
5044 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5047 create_addrmap_from_aranges (dwarf2_per_objfile
,
5048 &dwarf2_per_objfile
->debug_aranges
);
5050 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5051 dwarf2_per_objfile
->using_index
= 1;
5052 dwarf2_per_objfile
->quick_file_names_table
=
5053 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5058 /* Type used to manage iterating over all CUs looking for a symbol for
5061 class dw2_debug_names_iterator
5064 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5065 gdb::optional
<block_enum
> block_index
,
5068 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5069 m_addr (find_vec_in_debug_names (map
, name
))
5072 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5073 search_domain search
, uint32_t namei
)
5076 m_addr (find_vec_in_debug_names (map
, namei
))
5079 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5080 block_enum block_index
, domain_enum domain
,
5082 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5083 m_addr (find_vec_in_debug_names (map
, namei
))
5086 /* Return the next matching CU or NULL if there are no more. */
5087 dwarf2_per_cu_data
*next ();
5090 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5092 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5095 /* The internalized form of .debug_names. */
5096 const mapped_debug_names
&m_map
;
5098 /* If set, only look for symbols that match that block. Valid values are
5099 GLOBAL_BLOCK and STATIC_BLOCK. */
5100 const gdb::optional
<block_enum
> m_block_index
;
5102 /* The kind of symbol we're looking for. */
5103 const domain_enum m_domain
= UNDEF_DOMAIN
;
5104 const search_domain m_search
= ALL_DOMAIN
;
5106 /* The list of CUs from the index entry of the symbol, or NULL if
5108 const gdb_byte
*m_addr
;
5112 mapped_debug_names::namei_to_name (uint32_t namei
) const
5114 const ULONGEST namei_string_offs
5115 = extract_unsigned_integer ((name_table_string_offs_reordered
5116 + namei
* offset_size
),
5119 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5123 /* Find a slot in .debug_names for the object named NAME. If NAME is
5124 found, return pointer to its pool data. If NAME cannot be found,
5128 dw2_debug_names_iterator::find_vec_in_debug_names
5129 (const mapped_debug_names
&map
, const char *name
)
5131 int (*cmp
) (const char *, const char *);
5133 gdb::unique_xmalloc_ptr
<char> without_params
;
5134 if (current_language
->la_language
== language_cplus
5135 || current_language
->la_language
== language_fortran
5136 || current_language
->la_language
== language_d
)
5138 /* NAME is already canonical. Drop any qualifiers as
5139 .debug_names does not contain any. */
5141 if (strchr (name
, '(') != NULL
)
5143 without_params
= cp_remove_params (name
);
5144 if (without_params
!= NULL
)
5145 name
= without_params
.get ();
5149 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5151 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5153 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5154 (map
.bucket_table_reordered
5155 + (full_hash
% map
.bucket_count
)), 4,
5156 map
.dwarf5_byte_order
);
5160 if (namei
>= map
.name_count
)
5162 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5164 namei
, map
.name_count
,
5165 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5171 const uint32_t namei_full_hash
5172 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5173 (map
.hash_table_reordered
+ namei
), 4,
5174 map
.dwarf5_byte_order
);
5175 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5178 if (full_hash
== namei_full_hash
)
5180 const char *const namei_string
= map
.namei_to_name (namei
);
5182 #if 0 /* An expensive sanity check. */
5183 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5185 complaint (_("Wrong .debug_names hash for string at index %u "
5187 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5192 if (cmp (namei_string
, name
) == 0)
5194 const ULONGEST namei_entry_offs
5195 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5196 + namei
* map
.offset_size
),
5197 map
.offset_size
, map
.dwarf5_byte_order
);
5198 return map
.entry_pool
+ namei_entry_offs
;
5203 if (namei
>= map
.name_count
)
5209 dw2_debug_names_iterator::find_vec_in_debug_names
5210 (const mapped_debug_names
&map
, uint32_t namei
)
5212 if (namei
>= map
.name_count
)
5214 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5216 namei
, map
.name_count
,
5217 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5221 const ULONGEST namei_entry_offs
5222 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5223 + namei
* map
.offset_size
),
5224 map
.offset_size
, map
.dwarf5_byte_order
);
5225 return map
.entry_pool
+ namei_entry_offs
;
5228 /* See dw2_debug_names_iterator. */
5230 dwarf2_per_cu_data
*
5231 dw2_debug_names_iterator::next ()
5236 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5237 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5238 bfd
*const abfd
= objfile
->obfd
;
5242 unsigned int bytes_read
;
5243 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5244 m_addr
+= bytes_read
;
5248 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5249 if (indexval_it
== m_map
.abbrev_map
.cend ())
5251 complaint (_("Wrong .debug_names undefined abbrev code %s "
5253 pulongest (abbrev
), objfile_name (objfile
));
5256 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5257 enum class symbol_linkage
{
5261 } symbol_linkage_
= symbol_linkage::unknown
;
5262 dwarf2_per_cu_data
*per_cu
= NULL
;
5263 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5268 case DW_FORM_implicit_const
:
5269 ull
= attr
.implicit_const
;
5271 case DW_FORM_flag_present
:
5275 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5276 m_addr
+= bytes_read
;
5279 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5280 dwarf_form_name (attr
.form
),
5281 objfile_name (objfile
));
5284 switch (attr
.dw_idx
)
5286 case DW_IDX_compile_unit
:
5287 /* Don't crash on bad data. */
5288 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5290 complaint (_(".debug_names entry has bad CU index %s"
5293 objfile_name (dwarf2_per_objfile
->objfile
));
5296 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5298 case DW_IDX_type_unit
:
5299 /* Don't crash on bad data. */
5300 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5302 complaint (_(".debug_names entry has bad TU index %s"
5305 objfile_name (dwarf2_per_objfile
->objfile
));
5308 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5310 case DW_IDX_GNU_internal
:
5311 if (!m_map
.augmentation_is_gdb
)
5313 symbol_linkage_
= symbol_linkage::static_
;
5315 case DW_IDX_GNU_external
:
5316 if (!m_map
.augmentation_is_gdb
)
5318 symbol_linkage_
= symbol_linkage::extern_
;
5323 /* Skip if already read in. */
5324 if (per_cu
->v
.quick
->compunit_symtab
)
5327 /* Check static vs global. */
5328 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5330 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5331 const bool symbol_is_static
=
5332 symbol_linkage_
== symbol_linkage::static_
;
5333 if (want_static
!= symbol_is_static
)
5337 /* Match dw2_symtab_iter_next, symbol_kind
5338 and debug_names::psymbol_tag. */
5342 switch (indexval
.dwarf_tag
)
5344 case DW_TAG_variable
:
5345 case DW_TAG_subprogram
:
5346 /* Some types are also in VAR_DOMAIN. */
5347 case DW_TAG_typedef
:
5348 case DW_TAG_structure_type
:
5355 switch (indexval
.dwarf_tag
)
5357 case DW_TAG_typedef
:
5358 case DW_TAG_structure_type
:
5365 switch (indexval
.dwarf_tag
)
5368 case DW_TAG_variable
:
5375 switch (indexval
.dwarf_tag
)
5387 /* Match dw2_expand_symtabs_matching, symbol_kind and
5388 debug_names::psymbol_tag. */
5391 case VARIABLES_DOMAIN
:
5392 switch (indexval
.dwarf_tag
)
5394 case DW_TAG_variable
:
5400 case FUNCTIONS_DOMAIN
:
5401 switch (indexval
.dwarf_tag
)
5403 case DW_TAG_subprogram
:
5410 switch (indexval
.dwarf_tag
)
5412 case DW_TAG_typedef
:
5413 case DW_TAG_structure_type
:
5419 case MODULES_DOMAIN
:
5420 switch (indexval
.dwarf_tag
)
5434 static struct compunit_symtab
*
5435 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5436 const char *name
, domain_enum domain
)
5438 struct dwarf2_per_objfile
*dwarf2_per_objfile
5439 = get_dwarf2_per_objfile (objfile
);
5441 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5444 /* index is NULL if OBJF_READNOW. */
5447 const auto &map
= *mapp
;
5449 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5451 struct compunit_symtab
*stab_best
= NULL
;
5452 struct dwarf2_per_cu_data
*per_cu
;
5453 while ((per_cu
= iter
.next ()) != NULL
)
5455 struct symbol
*sym
, *with_opaque
= NULL
;
5456 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5457 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5458 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5460 sym
= block_find_symbol (block
, name
, domain
,
5461 block_find_non_opaque_type_preferred
,
5464 /* Some caution must be observed with overloaded functions and
5465 methods, since the index will not contain any overload
5466 information (but NAME might contain it). */
5469 && strcmp_iw (sym
->search_name (), name
) == 0)
5471 if (with_opaque
!= NULL
5472 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5475 /* Keep looking through other CUs. */
5481 /* This dumps minimal information about .debug_names. It is called
5482 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5483 uses this to verify that .debug_names has been loaded. */
5486 dw2_debug_names_dump (struct objfile
*objfile
)
5488 struct dwarf2_per_objfile
*dwarf2_per_objfile
5489 = get_dwarf2_per_objfile (objfile
);
5491 gdb_assert (dwarf2_per_objfile
->using_index
);
5492 printf_filtered (".debug_names:");
5493 if (dwarf2_per_objfile
->debug_names_table
)
5494 printf_filtered (" exists\n");
5496 printf_filtered (" faked for \"readnow\"\n");
5497 printf_filtered ("\n");
5501 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5502 const char *func_name
)
5504 struct dwarf2_per_objfile
*dwarf2_per_objfile
5505 = get_dwarf2_per_objfile (objfile
);
5507 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5508 if (dwarf2_per_objfile
->debug_names_table
)
5510 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5512 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5514 struct dwarf2_per_cu_data
*per_cu
;
5515 while ((per_cu
= iter
.next ()) != NULL
)
5516 dw2_instantiate_symtab (per_cu
, false);
5521 dw2_debug_names_map_matching_symbols
5522 (struct objfile
*objfile
,
5523 const lookup_name_info
&name
, domain_enum domain
,
5525 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5526 symbol_compare_ftype
*ordered_compare
)
5528 struct dwarf2_per_objfile
*dwarf2_per_objfile
5529 = get_dwarf2_per_objfile (objfile
);
5531 /* debug_names_table is NULL if OBJF_READNOW. */
5532 if (!dwarf2_per_objfile
->debug_names_table
)
5535 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5536 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5538 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5539 auto matcher
= [&] (const char *symname
)
5541 if (ordered_compare
== nullptr)
5543 return ordered_compare (symname
, match_name
) == 0;
5546 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5547 [&] (offset_type namei
)
5549 /* The name was matched, now expand corresponding CUs that were
5551 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5553 struct dwarf2_per_cu_data
*per_cu
;
5554 while ((per_cu
= iter
.next ()) != NULL
)
5555 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5559 /* It's a shame we couldn't do this inside the
5560 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5561 that have already been expanded. Instead, this loop matches what
5562 the psymtab code does. */
5563 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5565 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5566 if (cust
!= nullptr)
5568 const struct block
*block
5569 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5570 if (!iterate_over_symbols_terminated (block
, name
,
5578 dw2_debug_names_expand_symtabs_matching
5579 (struct objfile
*objfile
,
5580 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5581 const lookup_name_info
&lookup_name
,
5582 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5583 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5584 enum search_domain kind
)
5586 struct dwarf2_per_objfile
*dwarf2_per_objfile
5587 = get_dwarf2_per_objfile (objfile
);
5589 /* debug_names_table is NULL if OBJF_READNOW. */
5590 if (!dwarf2_per_objfile
->debug_names_table
)
5593 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5595 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5597 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5599 kind
, [&] (offset_type namei
)
5601 /* The name was matched, now expand corresponding CUs that were
5603 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5605 struct dwarf2_per_cu_data
*per_cu
;
5606 while ((per_cu
= iter
.next ()) != NULL
)
5607 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5613 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5616 dw2_find_last_source_symtab
,
5617 dw2_forget_cached_source_info
,
5618 dw2_map_symtabs_matching_filename
,
5619 dw2_debug_names_lookup_symbol
,
5622 dw2_debug_names_dump
,
5623 dw2_debug_names_expand_symtabs_for_function
,
5624 dw2_expand_all_symtabs
,
5625 dw2_expand_symtabs_with_fullname
,
5626 dw2_debug_names_map_matching_symbols
,
5627 dw2_debug_names_expand_symtabs_matching
,
5628 dw2_find_pc_sect_compunit_symtab
,
5630 dw2_map_symbol_filenames
5633 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5634 to either a dwarf2_per_objfile or dwz_file object. */
5636 template <typename T
>
5637 static gdb::array_view
<const gdb_byte
>
5638 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5640 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5642 if (section
->empty ())
5645 /* Older elfutils strip versions could keep the section in the main
5646 executable while splitting it for the separate debug info file. */
5647 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5650 section
->read (obj
);
5652 /* dwarf2_section_info::size is a bfd_size_type, while
5653 gdb::array_view works with size_t. On 32-bit hosts, with
5654 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5655 is 32-bit. So we need an explicit narrowing conversion here.
5656 This is fine, because it's impossible to allocate or mmap an
5657 array/buffer larger than what size_t can represent. */
5658 return gdb::make_array_view (section
->buffer
, section
->size
);
5661 /* Lookup the index cache for the contents of the index associated to
5664 static gdb::array_view
<const gdb_byte
>
5665 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5667 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5668 if (build_id
== nullptr)
5671 return global_index_cache
.lookup_gdb_index (build_id
,
5672 &dwarf2_obj
->index_cache_res
);
5675 /* Same as the above, but for DWZ. */
5677 static gdb::array_view
<const gdb_byte
>
5678 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5680 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5681 if (build_id
== nullptr)
5684 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5687 /* See symfile.h. */
5690 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5692 struct dwarf2_per_objfile
*dwarf2_per_objfile
5693 = get_dwarf2_per_objfile (objfile
);
5695 /* If we're about to read full symbols, don't bother with the
5696 indices. In this case we also don't care if some other debug
5697 format is making psymtabs, because they are all about to be
5699 if ((objfile
->flags
& OBJF_READNOW
))
5701 dwarf2_per_objfile
->using_index
= 1;
5702 create_all_comp_units (dwarf2_per_objfile
);
5703 create_all_type_units (dwarf2_per_objfile
);
5704 dwarf2_per_objfile
->quick_file_names_table
5705 = create_quick_file_names_table
5706 (dwarf2_per_objfile
->all_comp_units
.size ());
5708 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5709 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5711 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5713 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5714 struct dwarf2_per_cu_quick_data
);
5717 /* Return 1 so that gdb sees the "quick" functions. However,
5718 these functions will be no-ops because we will have expanded
5720 *index_kind
= dw_index_kind::GDB_INDEX
;
5724 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5726 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5730 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5731 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5732 get_gdb_index_contents_from_section
<dwz_file
>))
5734 *index_kind
= dw_index_kind::GDB_INDEX
;
5738 /* ... otherwise, try to find the index in the index cache. */
5739 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5740 get_gdb_index_contents_from_cache
,
5741 get_gdb_index_contents_from_cache_dwz
))
5743 global_index_cache
.hit ();
5744 *index_kind
= dw_index_kind::GDB_INDEX
;
5748 global_index_cache
.miss ();
5754 /* Build a partial symbol table. */
5757 dwarf2_build_psymtabs (struct objfile
*objfile
)
5759 struct dwarf2_per_objfile
*dwarf2_per_objfile
5760 = get_dwarf2_per_objfile (objfile
);
5762 init_psymbol_list (objfile
, 1024);
5766 /* This isn't really ideal: all the data we allocate on the
5767 objfile's obstack is still uselessly kept around. However,
5768 freeing it seems unsafe. */
5769 psymtab_discarder
psymtabs (objfile
);
5770 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5773 /* (maybe) store an index in the cache. */
5774 global_index_cache
.store (dwarf2_per_objfile
);
5776 catch (const gdb_exception_error
&except
)
5778 exception_print (gdb_stderr
, except
);
5782 /* Find the base address of the compilation unit for range lists and
5783 location lists. It will normally be specified by DW_AT_low_pc.
5784 In DWARF-3 draft 4, the base address could be overridden by
5785 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5786 compilation units with discontinuous ranges. */
5789 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5791 struct attribute
*attr
;
5793 cu
->base_address
.reset ();
5795 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5796 if (attr
!= nullptr)
5797 cu
->base_address
= attr
->value_as_address ();
5800 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5801 if (attr
!= nullptr)
5802 cu
->base_address
= attr
->value_as_address ();
5806 /* Helper function that returns the proper abbrev section for
5809 static struct dwarf2_section_info
*
5810 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5812 struct dwarf2_section_info
*abbrev
;
5813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5815 if (this_cu
->is_dwz
)
5816 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5818 abbrev
= &dwarf2_per_objfile
->abbrev
;
5823 /* Fetch the abbreviation table offset from a comp or type unit header. */
5826 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5827 struct dwarf2_section_info
*section
,
5828 sect_offset sect_off
)
5830 bfd
*abfd
= section
->get_bfd_owner ();
5831 const gdb_byte
*info_ptr
;
5832 unsigned int initial_length_size
, offset_size
;
5835 section
->read (dwarf2_per_objfile
->objfile
);
5836 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5837 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5838 offset_size
= initial_length_size
== 4 ? 4 : 8;
5839 info_ptr
+= initial_length_size
;
5841 version
= read_2_bytes (abfd
, info_ptr
);
5845 /* Skip unit type and address size. */
5849 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5852 /* A partial symtab that is used only for include files. */
5853 struct dwarf2_include_psymtab
: public partial_symtab
5855 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5856 : partial_symtab (filename
, objfile
)
5860 void read_symtab (struct objfile
*objfile
) override
5862 expand_psymtab (objfile
);
5865 void expand_psymtab (struct objfile
*objfile
) override
5869 /* It's an include file, no symbols to read for it.
5870 Everything is in the parent symtab. */
5871 expand_dependencies (objfile
);
5875 bool readin_p () const override
5880 struct compunit_symtab
*get_compunit_symtab () const override
5887 bool m_readin
= false;
5890 /* Allocate a new partial symtab for file named NAME and mark this new
5891 partial symtab as being an include of PST. */
5894 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5895 struct objfile
*objfile
)
5897 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5899 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5901 /* It shares objfile->objfile_obstack. */
5902 subpst
->dirname
= pst
->dirname
;
5905 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5906 subpst
->dependencies
[0] = pst
;
5907 subpst
->number_of_dependencies
= 1;
5910 /* Read the Line Number Program data and extract the list of files
5911 included by the source file represented by PST. Build an include
5912 partial symtab for each of these included files. */
5915 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5916 struct die_info
*die
,
5917 dwarf2_psymtab
*pst
)
5920 struct attribute
*attr
;
5922 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5923 if (attr
!= nullptr)
5924 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5926 return; /* No linetable, so no includes. */
5928 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5929 that we pass in the raw text_low here; that is ok because we're
5930 only decoding the line table to make include partial symtabs, and
5931 so the addresses aren't really used. */
5932 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5933 pst
->raw_text_low (), 1);
5937 hash_signatured_type (const void *item
)
5939 const struct signatured_type
*sig_type
5940 = (const struct signatured_type
*) item
;
5942 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5943 return sig_type
->signature
;
5947 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5949 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5950 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5952 return lhs
->signature
== rhs
->signature
;
5955 /* Allocate a hash table for signatured types. */
5958 allocate_signatured_type_table ()
5960 return htab_up (htab_create_alloc (41,
5961 hash_signatured_type
,
5963 NULL
, xcalloc
, xfree
));
5966 /* A helper function to add a signatured type CU to a table. */
5969 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5971 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5972 std::vector
<signatured_type
*> *all_type_units
5973 = (std::vector
<signatured_type
*> *) datum
;
5975 all_type_units
->push_back (sigt
);
5980 /* A helper for create_debug_types_hash_table. Read types from SECTION
5981 and fill them into TYPES_HTAB. It will process only type units,
5982 therefore DW_UT_type. */
5985 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5986 struct dwo_file
*dwo_file
,
5987 dwarf2_section_info
*section
, htab_up
&types_htab
,
5988 rcuh_kind section_kind
)
5990 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5991 struct dwarf2_section_info
*abbrev_section
;
5993 const gdb_byte
*info_ptr
, *end_ptr
;
5995 abbrev_section
= (dwo_file
!= NULL
5996 ? &dwo_file
->sections
.abbrev
5997 : &dwarf2_per_objfile
->abbrev
);
5999 if (dwarf_read_debug
)
6000 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6001 section
->get_name (),
6002 abbrev_section
->get_file_name ());
6004 section
->read (objfile
);
6005 info_ptr
= section
->buffer
;
6007 if (info_ptr
== NULL
)
6010 /* We can't set abfd until now because the section may be empty or
6011 not present, in which case the bfd is unknown. */
6012 abfd
= section
->get_bfd_owner ();
6014 /* We don't use cutu_reader here because we don't need to read
6015 any dies: the signature is in the header. */
6017 end_ptr
= info_ptr
+ section
->size
;
6018 while (info_ptr
< end_ptr
)
6020 struct signatured_type
*sig_type
;
6021 struct dwo_unit
*dwo_tu
;
6023 const gdb_byte
*ptr
= info_ptr
;
6024 struct comp_unit_head header
;
6025 unsigned int length
;
6027 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6029 /* Initialize it due to a false compiler warning. */
6030 header
.signature
= -1;
6031 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6033 /* We need to read the type's signature in order to build the hash
6034 table, but we don't need anything else just yet. */
6036 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6037 abbrev_section
, ptr
, section_kind
);
6039 length
= header
.get_length ();
6041 /* Skip dummy type units. */
6042 if (ptr
>= info_ptr
+ length
6043 || peek_abbrev_code (abfd
, ptr
) == 0
6044 || header
.unit_type
!= DW_UT_type
)
6050 if (types_htab
== NULL
)
6053 types_htab
= allocate_dwo_unit_table ();
6055 types_htab
= allocate_signatured_type_table ();
6061 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6063 dwo_tu
->dwo_file
= dwo_file
;
6064 dwo_tu
->signature
= header
.signature
;
6065 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6066 dwo_tu
->section
= section
;
6067 dwo_tu
->sect_off
= sect_off
;
6068 dwo_tu
->length
= length
;
6072 /* N.B.: type_offset is not usable if this type uses a DWO file.
6073 The real type_offset is in the DWO file. */
6075 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6076 struct signatured_type
);
6077 sig_type
->signature
= header
.signature
;
6078 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6079 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6080 sig_type
->per_cu
.is_debug_types
= 1;
6081 sig_type
->per_cu
.section
= section
;
6082 sig_type
->per_cu
.sect_off
= sect_off
;
6083 sig_type
->per_cu
.length
= length
;
6086 slot
= htab_find_slot (types_htab
.get (),
6087 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6089 gdb_assert (slot
!= NULL
);
6092 sect_offset dup_sect_off
;
6096 const struct dwo_unit
*dup_tu
6097 = (const struct dwo_unit
*) *slot
;
6099 dup_sect_off
= dup_tu
->sect_off
;
6103 const struct signatured_type
*dup_tu
6104 = (const struct signatured_type
*) *slot
;
6106 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6109 complaint (_("debug type entry at offset %s is duplicate to"
6110 " the entry at offset %s, signature %s"),
6111 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6112 hex_string (header
.signature
));
6114 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6116 if (dwarf_read_debug
> 1)
6117 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6118 sect_offset_str (sect_off
),
6119 hex_string (header
.signature
));
6125 /* Create the hash table of all entries in the .debug_types
6126 (or .debug_types.dwo) section(s).
6127 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6128 otherwise it is NULL.
6130 The result is a pointer to the hash table or NULL if there are no types.
6132 Note: This function processes DWO files only, not DWP files. */
6135 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6136 struct dwo_file
*dwo_file
,
6137 gdb::array_view
<dwarf2_section_info
> type_sections
,
6138 htab_up
&types_htab
)
6140 for (dwarf2_section_info
§ion
: type_sections
)
6141 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6142 types_htab
, rcuh_kind::TYPE
);
6145 /* Create the hash table of all entries in the .debug_types section,
6146 and initialize all_type_units.
6147 The result is zero if there is an error (e.g. missing .debug_types section),
6148 otherwise non-zero. */
6151 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6155 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6156 &dwarf2_per_objfile
->info
, types_htab
,
6157 rcuh_kind::COMPILE
);
6158 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6159 dwarf2_per_objfile
->types
, types_htab
);
6160 if (types_htab
== NULL
)
6162 dwarf2_per_objfile
->signatured_types
= NULL
;
6166 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6168 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6169 dwarf2_per_objfile
->all_type_units
.reserve
6170 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6172 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6173 add_signatured_type_cu_to_table
,
6174 &dwarf2_per_objfile
->all_type_units
);
6179 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6180 If SLOT is non-NULL, it is the entry to use in the hash table.
6181 Otherwise we find one. */
6183 static struct signatured_type
*
6184 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6187 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6189 if (dwarf2_per_objfile
->all_type_units
.size ()
6190 == dwarf2_per_objfile
->all_type_units
.capacity ())
6191 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6193 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6194 struct signatured_type
);
6196 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6197 sig_type
->signature
= sig
;
6198 sig_type
->per_cu
.is_debug_types
= 1;
6199 if (dwarf2_per_objfile
->using_index
)
6201 sig_type
->per_cu
.v
.quick
=
6202 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6203 struct dwarf2_per_cu_quick_data
);
6208 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6211 gdb_assert (*slot
== NULL
);
6213 /* The rest of sig_type must be filled in by the caller. */
6217 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6218 Fill in SIG_ENTRY with DWO_ENTRY. */
6221 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6222 struct signatured_type
*sig_entry
,
6223 struct dwo_unit
*dwo_entry
)
6225 /* Make sure we're not clobbering something we don't expect to. */
6226 gdb_assert (! sig_entry
->per_cu
.queued
);
6227 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6228 if (dwarf2_per_objfile
->using_index
)
6230 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6231 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6234 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6235 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6236 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6237 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6238 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6240 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6241 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6242 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6243 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6244 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6245 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6246 sig_entry
->dwo_unit
= dwo_entry
;
6249 /* Subroutine of lookup_signatured_type.
6250 If we haven't read the TU yet, create the signatured_type data structure
6251 for a TU to be read in directly from a DWO file, bypassing the stub.
6252 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6253 using .gdb_index, then when reading a CU we want to stay in the DWO file
6254 containing that CU. Otherwise we could end up reading several other DWO
6255 files (due to comdat folding) to process the transitive closure of all the
6256 mentioned TUs, and that can be slow. The current DWO file will have every
6257 type signature that it needs.
6258 We only do this for .gdb_index because in the psymtab case we already have
6259 to read all the DWOs to build the type unit groups. */
6261 static struct signatured_type
*
6262 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6264 struct dwarf2_per_objfile
*dwarf2_per_objfile
6265 = cu
->per_cu
->dwarf2_per_objfile
;
6266 struct dwo_file
*dwo_file
;
6267 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6268 struct signatured_type find_sig_entry
, *sig_entry
;
6271 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6273 /* If TU skeletons have been removed then we may not have read in any
6275 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6276 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6278 /* We only ever need to read in one copy of a signatured type.
6279 Use the global signatured_types array to do our own comdat-folding
6280 of types. If this is the first time we're reading this TU, and
6281 the TU has an entry in .gdb_index, replace the recorded data from
6282 .gdb_index with this TU. */
6284 find_sig_entry
.signature
= sig
;
6285 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6286 &find_sig_entry
, INSERT
);
6287 sig_entry
= (struct signatured_type
*) *slot
;
6289 /* We can get here with the TU already read, *or* in the process of being
6290 read. Don't reassign the global entry to point to this DWO if that's
6291 the case. Also note that if the TU is already being read, it may not
6292 have come from a DWO, the program may be a mix of Fission-compiled
6293 code and non-Fission-compiled code. */
6295 /* Have we already tried to read this TU?
6296 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6297 needn't exist in the global table yet). */
6298 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6301 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6302 dwo_unit of the TU itself. */
6303 dwo_file
= cu
->dwo_unit
->dwo_file
;
6305 /* Ok, this is the first time we're reading this TU. */
6306 if (dwo_file
->tus
== NULL
)
6308 find_dwo_entry
.signature
= sig
;
6309 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6311 if (dwo_entry
== NULL
)
6314 /* If the global table doesn't have an entry for this TU, add one. */
6315 if (sig_entry
== NULL
)
6316 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6318 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6319 sig_entry
->per_cu
.tu_read
= 1;
6323 /* Subroutine of lookup_signatured_type.
6324 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6325 then try the DWP file. If the TU stub (skeleton) has been removed then
6326 it won't be in .gdb_index. */
6328 static struct signatured_type
*
6329 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6331 struct dwarf2_per_objfile
*dwarf2_per_objfile
6332 = cu
->per_cu
->dwarf2_per_objfile
;
6333 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6334 struct dwo_unit
*dwo_entry
;
6335 struct signatured_type find_sig_entry
, *sig_entry
;
6338 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6339 gdb_assert (dwp_file
!= NULL
);
6341 /* If TU skeletons have been removed then we may not have read in any
6343 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6344 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6346 find_sig_entry
.signature
= sig
;
6347 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6348 &find_sig_entry
, INSERT
);
6349 sig_entry
= (struct signatured_type
*) *slot
;
6351 /* Have we already tried to read this TU?
6352 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6353 needn't exist in the global table yet). */
6354 if (sig_entry
!= NULL
)
6357 if (dwp_file
->tus
== NULL
)
6359 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6360 sig
, 1 /* is_debug_types */);
6361 if (dwo_entry
== NULL
)
6364 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6365 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6370 /* Lookup a signature based type for DW_FORM_ref_sig8.
6371 Returns NULL if signature SIG is not present in the table.
6372 It is up to the caller to complain about this. */
6374 static struct signatured_type
*
6375 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6377 struct dwarf2_per_objfile
*dwarf2_per_objfile
6378 = cu
->per_cu
->dwarf2_per_objfile
;
6381 && dwarf2_per_objfile
->using_index
)
6383 /* We're in a DWO/DWP file, and we're using .gdb_index.
6384 These cases require special processing. */
6385 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6386 return lookup_dwo_signatured_type (cu
, sig
);
6388 return lookup_dwp_signatured_type (cu
, sig
);
6392 struct signatured_type find_entry
, *entry
;
6394 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6396 find_entry
.signature
= sig
;
6397 entry
= ((struct signatured_type
*)
6398 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6404 /* Low level DIE reading support. */
6406 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6409 init_cu_die_reader (struct die_reader_specs
*reader
,
6410 struct dwarf2_cu
*cu
,
6411 struct dwarf2_section_info
*section
,
6412 struct dwo_file
*dwo_file
,
6413 struct abbrev_table
*abbrev_table
)
6415 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6416 reader
->abfd
= section
->get_bfd_owner ();
6418 reader
->dwo_file
= dwo_file
;
6419 reader
->die_section
= section
;
6420 reader
->buffer
= section
->buffer
;
6421 reader
->buffer_end
= section
->buffer
+ section
->size
;
6422 reader
->abbrev_table
= abbrev_table
;
6425 /* Subroutine of cutu_reader to simplify it.
6426 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6427 There's just a lot of work to do, and cutu_reader is big enough
6430 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6431 from it to the DIE in the DWO. If NULL we are skipping the stub.
6432 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6433 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6434 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6435 STUB_COMP_DIR may be non-NULL.
6436 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6437 are filled in with the info of the DIE from the DWO file.
6438 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6439 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6440 kept around for at least as long as *RESULT_READER.
6442 The result is non-zero if a valid (non-dummy) DIE was found. */
6445 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6446 struct dwo_unit
*dwo_unit
,
6447 struct die_info
*stub_comp_unit_die
,
6448 const char *stub_comp_dir
,
6449 struct die_reader_specs
*result_reader
,
6450 const gdb_byte
**result_info_ptr
,
6451 struct die_info
**result_comp_unit_die
,
6452 abbrev_table_up
*result_dwo_abbrev_table
)
6454 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6455 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6456 struct dwarf2_cu
*cu
= this_cu
->cu
;
6458 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6459 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6460 int i
,num_extra_attrs
;
6461 struct dwarf2_section_info
*dwo_abbrev_section
;
6462 struct die_info
*comp_unit_die
;
6464 /* At most one of these may be provided. */
6465 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6467 /* These attributes aren't processed until later:
6468 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6469 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6470 referenced later. However, these attributes are found in the stub
6471 which we won't have later. In order to not impose this complication
6472 on the rest of the code, we read them here and copy them to the
6481 if (stub_comp_unit_die
!= NULL
)
6483 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6485 if (! this_cu
->is_debug_types
)
6486 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6487 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6488 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6489 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6490 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6492 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6494 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6495 here (if needed). We need the value before we can process
6497 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6499 else if (stub_comp_dir
!= NULL
)
6501 /* Reconstruct the comp_dir attribute to simplify the code below. */
6502 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6503 comp_dir
->name
= DW_AT_comp_dir
;
6504 comp_dir
->form
= DW_FORM_string
;
6505 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6506 DW_STRING (comp_dir
) = stub_comp_dir
;
6509 /* Set up for reading the DWO CU/TU. */
6510 cu
->dwo_unit
= dwo_unit
;
6511 dwarf2_section_info
*section
= dwo_unit
->section
;
6512 section
->read (objfile
);
6513 abfd
= section
->get_bfd_owner ();
6514 begin_info_ptr
= info_ptr
= (section
->buffer
6515 + to_underlying (dwo_unit
->sect_off
));
6516 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6518 if (this_cu
->is_debug_types
)
6520 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6522 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6523 &cu
->header
, section
,
6525 info_ptr
, rcuh_kind::TYPE
);
6526 /* This is not an assert because it can be caused by bad debug info. */
6527 if (sig_type
->signature
!= cu
->header
.signature
)
6529 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6530 " TU at offset %s [in module %s]"),
6531 hex_string (sig_type
->signature
),
6532 hex_string (cu
->header
.signature
),
6533 sect_offset_str (dwo_unit
->sect_off
),
6534 bfd_get_filename (abfd
));
6536 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6537 /* For DWOs coming from DWP files, we don't know the CU length
6538 nor the type's offset in the TU until now. */
6539 dwo_unit
->length
= cu
->header
.get_length ();
6540 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6542 /* Establish the type offset that can be used to lookup the type.
6543 For DWO files, we don't know it until now. */
6544 sig_type
->type_offset_in_section
6545 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6549 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6550 &cu
->header
, section
,
6552 info_ptr
, rcuh_kind::COMPILE
);
6553 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6554 /* For DWOs coming from DWP files, we don't know the CU length
6556 dwo_unit
->length
= cu
->header
.get_length ();
6559 *result_dwo_abbrev_table
6560 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6561 cu
->header
.abbrev_sect_off
);
6562 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6563 result_dwo_abbrev_table
->get ());
6565 /* Read in the die, but leave space to copy over the attributes
6566 from the stub. This has the benefit of simplifying the rest of
6567 the code - all the work to maintain the illusion of a single
6568 DW_TAG_{compile,type}_unit DIE is done here. */
6569 num_extra_attrs
= ((stmt_list
!= NULL
)
6573 + (comp_dir
!= NULL
));
6574 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6577 /* Copy over the attributes from the stub to the DIE we just read in. */
6578 comp_unit_die
= *result_comp_unit_die
;
6579 i
= comp_unit_die
->num_attrs
;
6580 if (stmt_list
!= NULL
)
6581 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6583 comp_unit_die
->attrs
[i
++] = *low_pc
;
6584 if (high_pc
!= NULL
)
6585 comp_unit_die
->attrs
[i
++] = *high_pc
;
6587 comp_unit_die
->attrs
[i
++] = *ranges
;
6588 if (comp_dir
!= NULL
)
6589 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6590 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6592 if (dwarf_die_debug
)
6594 fprintf_unfiltered (gdb_stdlog
,
6595 "Read die from %s@0x%x of %s:\n",
6596 section
->get_name (),
6597 (unsigned) (begin_info_ptr
- section
->buffer
),
6598 bfd_get_filename (abfd
));
6599 dump_die (comp_unit_die
, dwarf_die_debug
);
6602 /* Skip dummy compilation units. */
6603 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6604 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6607 *result_info_ptr
= info_ptr
;
6611 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6612 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6613 signature is part of the header. */
6614 static gdb::optional
<ULONGEST
>
6615 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6617 if (cu
->header
.version
>= 5)
6618 return cu
->header
.signature
;
6619 struct attribute
*attr
;
6620 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6621 if (attr
== nullptr)
6622 return gdb::optional
<ULONGEST
> ();
6623 return DW_UNSND (attr
);
6626 /* Subroutine of cutu_reader to simplify it.
6627 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6628 Returns NULL if the specified DWO unit cannot be found. */
6630 static struct dwo_unit
*
6631 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6632 struct die_info
*comp_unit_die
,
6633 const char *dwo_name
)
6635 struct dwarf2_cu
*cu
= this_cu
->cu
;
6636 struct dwo_unit
*dwo_unit
;
6637 const char *comp_dir
;
6639 gdb_assert (cu
!= NULL
);
6641 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6642 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6643 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6645 if (this_cu
->is_debug_types
)
6647 struct signatured_type
*sig_type
;
6649 /* Since this_cu is the first member of struct signatured_type,
6650 we can go from a pointer to one to a pointer to the other. */
6651 sig_type
= (struct signatured_type
*) this_cu
;
6652 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6656 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6657 if (!signature
.has_value ())
6658 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6660 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6661 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6668 /* Subroutine of cutu_reader to simplify it.
6669 See it for a description of the parameters.
6670 Read a TU directly from a DWO file, bypassing the stub. */
6673 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6674 int use_existing_cu
)
6676 struct signatured_type
*sig_type
;
6678 /* Verify we can do the following downcast, and that we have the
6680 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6681 sig_type
= (struct signatured_type
*) this_cu
;
6682 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6684 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6686 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6687 /* There's no need to do the rereading_dwo_cu handling that
6688 cutu_reader does since we don't read the stub. */
6692 /* If !use_existing_cu, this_cu->cu must be NULL. */
6693 gdb_assert (this_cu
->cu
== NULL
);
6694 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6697 /* A future optimization, if needed, would be to use an existing
6698 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6699 could share abbrev tables. */
6701 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6702 NULL
/* stub_comp_unit_die */,
6703 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6706 &m_dwo_abbrev_table
) == 0)
6713 /* Initialize a CU (or TU) and read its DIEs.
6714 If the CU defers to a DWO file, read the DWO file as well.
6716 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6717 Otherwise the table specified in the comp unit header is read in and used.
6718 This is an optimization for when we already have the abbrev table.
6720 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6721 Otherwise, a new CU is allocated with xmalloc. */
6723 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6724 struct abbrev_table
*abbrev_table
,
6725 int use_existing_cu
,
6727 : die_reader_specs
{},
6730 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6731 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6732 struct dwarf2_section_info
*section
= this_cu
->section
;
6733 bfd
*abfd
= section
->get_bfd_owner ();
6734 struct dwarf2_cu
*cu
;
6735 const gdb_byte
*begin_info_ptr
;
6736 struct signatured_type
*sig_type
= NULL
;
6737 struct dwarf2_section_info
*abbrev_section
;
6738 /* Non-zero if CU currently points to a DWO file and we need to
6739 reread it. When this happens we need to reread the skeleton die
6740 before we can reread the DWO file (this only applies to CUs, not TUs). */
6741 int rereading_dwo_cu
= 0;
6743 if (dwarf_die_debug
)
6744 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6745 this_cu
->is_debug_types
? "type" : "comp",
6746 sect_offset_str (this_cu
->sect_off
));
6748 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6749 file (instead of going through the stub), short-circuit all of this. */
6750 if (this_cu
->reading_dwo_directly
)
6752 /* Narrow down the scope of possibilities to have to understand. */
6753 gdb_assert (this_cu
->is_debug_types
);
6754 gdb_assert (abbrev_table
== NULL
);
6755 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6759 /* This is cheap if the section is already read in. */
6760 section
->read (objfile
);
6762 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6764 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6766 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6769 /* If this CU is from a DWO file we need to start over, we need to
6770 refetch the attributes from the skeleton CU.
6771 This could be optimized by retrieving those attributes from when we
6772 were here the first time: the previous comp_unit_die was stored in
6773 comp_unit_obstack. But there's no data yet that we need this
6775 if (cu
->dwo_unit
!= NULL
)
6776 rereading_dwo_cu
= 1;
6780 /* If !use_existing_cu, this_cu->cu must be NULL. */
6781 gdb_assert (this_cu
->cu
== NULL
);
6782 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6783 cu
= m_new_cu
.get ();
6786 /* Get the header. */
6787 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6789 /* We already have the header, there's no need to read it in again. */
6790 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6794 if (this_cu
->is_debug_types
)
6796 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6797 &cu
->header
, section
,
6798 abbrev_section
, info_ptr
,
6801 /* Since per_cu is the first member of struct signatured_type,
6802 we can go from a pointer to one to a pointer to the other. */
6803 sig_type
= (struct signatured_type
*) this_cu
;
6804 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6805 gdb_assert (sig_type
->type_offset_in_tu
6806 == cu
->header
.type_cu_offset_in_tu
);
6807 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6809 /* LENGTH has not been set yet for type units if we're
6810 using .gdb_index. */
6811 this_cu
->length
= cu
->header
.get_length ();
6813 /* Establish the type offset that can be used to lookup the type. */
6814 sig_type
->type_offset_in_section
=
6815 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6817 this_cu
->dwarf_version
= cu
->header
.version
;
6821 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6822 &cu
->header
, section
,
6825 rcuh_kind::COMPILE
);
6827 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6828 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6829 this_cu
->dwarf_version
= cu
->header
.version
;
6833 /* Skip dummy compilation units. */
6834 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6835 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6841 /* If we don't have them yet, read the abbrevs for this compilation unit.
6842 And if we need to read them now, make sure they're freed when we're
6844 if (abbrev_table
!= NULL
)
6845 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6848 m_abbrev_table_holder
6849 = abbrev_table::read (objfile
, abbrev_section
,
6850 cu
->header
.abbrev_sect_off
);
6851 abbrev_table
= m_abbrev_table_holder
.get ();
6854 /* Read the top level CU/TU die. */
6855 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6856 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6858 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6864 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6865 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6866 table from the DWO file and pass the ownership over to us. It will be
6867 referenced from READER, so we must make sure to free it after we're done
6870 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6871 DWO CU, that this test will fail (the attribute will not be present). */
6872 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6873 if (dwo_name
!= nullptr)
6875 struct dwo_unit
*dwo_unit
;
6876 struct die_info
*dwo_comp_unit_die
;
6878 if (comp_unit_die
->has_children
)
6880 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6881 " has children (offset %s) [in module %s]"),
6882 sect_offset_str (this_cu
->sect_off
),
6883 bfd_get_filename (abfd
));
6885 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6886 if (dwo_unit
!= NULL
)
6888 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6889 comp_unit_die
, NULL
,
6892 &m_dwo_abbrev_table
) == 0)
6898 comp_unit_die
= dwo_comp_unit_die
;
6902 /* Yikes, we couldn't find the rest of the DIE, we only have
6903 the stub. A complaint has already been logged. There's
6904 not much more we can do except pass on the stub DIE to
6905 die_reader_func. We don't want to throw an error on bad
6912 cutu_reader::keep ()
6914 /* Done, clean up. */
6915 gdb_assert (!dummy_p
);
6916 if (m_new_cu
!= NULL
)
6918 struct dwarf2_per_objfile
*dwarf2_per_objfile
6919 = m_this_cu
->dwarf2_per_objfile
;
6920 /* Link this CU into read_in_chain. */
6921 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6922 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6923 /* The chain owns it now. */
6924 m_new_cu
.release ();
6928 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6929 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6930 assumed to have already done the lookup to find the DWO file).
6932 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6933 THIS_CU->is_debug_types, but nothing else.
6935 We fill in THIS_CU->length.
6937 THIS_CU->cu is always freed when done.
6938 This is done in order to not leave THIS_CU->cu in a state where we have
6939 to care whether it refers to the "main" CU or the DWO CU.
6941 When parent_cu is passed, it is used to provide a default value for
6942 str_offsets_base and addr_base from the parent. */
6944 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6945 struct dwarf2_cu
*parent_cu
,
6946 struct dwo_file
*dwo_file
)
6947 : die_reader_specs
{},
6950 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6952 struct dwarf2_section_info
*section
= this_cu
->section
;
6953 bfd
*abfd
= section
->get_bfd_owner ();
6954 struct dwarf2_section_info
*abbrev_section
;
6955 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6957 if (dwarf_die_debug
)
6958 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6959 this_cu
->is_debug_types
? "type" : "comp",
6960 sect_offset_str (this_cu
->sect_off
));
6962 gdb_assert (this_cu
->cu
== NULL
);
6964 abbrev_section
= (dwo_file
!= NULL
6965 ? &dwo_file
->sections
.abbrev
6966 : get_abbrev_section_for_cu (this_cu
));
6968 /* This is cheap if the section is already read in. */
6969 section
->read (objfile
);
6971 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6973 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6974 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6975 &m_new_cu
->header
, section
,
6976 abbrev_section
, info_ptr
,
6977 (this_cu
->is_debug_types
6979 : rcuh_kind::COMPILE
));
6981 if (parent_cu
!= nullptr)
6983 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6984 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6986 this_cu
->length
= m_new_cu
->header
.get_length ();
6988 /* Skip dummy compilation units. */
6989 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6990 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6996 m_abbrev_table_holder
6997 = abbrev_table::read (objfile
, abbrev_section
,
6998 m_new_cu
->header
.abbrev_sect_off
);
7000 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7001 m_abbrev_table_holder
.get ());
7002 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
7006 /* Type Unit Groups.
7008 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7009 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7010 so that all types coming from the same compilation (.o file) are grouped
7011 together. A future step could be to put the types in the same symtab as
7012 the CU the types ultimately came from. */
7015 hash_type_unit_group (const void *item
)
7017 const struct type_unit_group
*tu_group
7018 = (const struct type_unit_group
*) item
;
7020 return hash_stmt_list_entry (&tu_group
->hash
);
7024 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7026 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7027 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7029 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7032 /* Allocate a hash table for type unit groups. */
7035 allocate_type_unit_groups_table ()
7037 return htab_up (htab_create_alloc (3,
7038 hash_type_unit_group
,
7040 NULL
, xcalloc
, xfree
));
7043 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7044 partial symtabs. We combine several TUs per psymtab to not let the size
7045 of any one psymtab grow too big. */
7046 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7047 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7049 /* Helper routine for get_type_unit_group.
7050 Create the type_unit_group object used to hold one or more TUs. */
7052 static struct type_unit_group
*
7053 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7055 struct dwarf2_per_objfile
*dwarf2_per_objfile
7056 = cu
->per_cu
->dwarf2_per_objfile
;
7057 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7058 struct dwarf2_per_cu_data
*per_cu
;
7059 struct type_unit_group
*tu_group
;
7061 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7062 struct type_unit_group
);
7063 per_cu
= &tu_group
->per_cu
;
7064 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7066 if (dwarf2_per_objfile
->using_index
)
7068 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7069 struct dwarf2_per_cu_quick_data
);
7073 unsigned int line_offset
= to_underlying (line_offset_struct
);
7074 dwarf2_psymtab
*pst
;
7077 /* Give the symtab a useful name for debug purposes. */
7078 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7079 name
= string_printf ("<type_units_%d>",
7080 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7082 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7084 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7085 pst
->anonymous
= true;
7088 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7089 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7094 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7095 STMT_LIST is a DW_AT_stmt_list attribute. */
7097 static struct type_unit_group
*
7098 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7100 struct dwarf2_per_objfile
*dwarf2_per_objfile
7101 = cu
->per_cu
->dwarf2_per_objfile
;
7102 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7103 struct type_unit_group
*tu_group
;
7105 unsigned int line_offset
;
7106 struct type_unit_group type_unit_group_for_lookup
;
7108 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7109 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7111 /* Do we need to create a new group, or can we use an existing one? */
7115 line_offset
= DW_UNSND (stmt_list
);
7116 ++tu_stats
->nr_symtab_sharers
;
7120 /* Ugh, no stmt_list. Rare, but we have to handle it.
7121 We can do various things here like create one group per TU or
7122 spread them over multiple groups to split up the expansion work.
7123 To avoid worst case scenarios (too many groups or too large groups)
7124 we, umm, group them in bunches. */
7125 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7126 | (tu_stats
->nr_stmt_less_type_units
7127 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7128 ++tu_stats
->nr_stmt_less_type_units
;
7131 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7132 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7133 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7134 &type_unit_group_for_lookup
, INSERT
);
7137 tu_group
= (struct type_unit_group
*) *slot
;
7138 gdb_assert (tu_group
!= NULL
);
7142 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7143 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7145 ++tu_stats
->nr_symtabs
;
7151 /* Partial symbol tables. */
7153 /* Create a psymtab named NAME and assign it to PER_CU.
7155 The caller must fill in the following details:
7156 dirname, textlow, texthigh. */
7158 static dwarf2_psymtab
*
7159 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7161 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7162 dwarf2_psymtab
*pst
;
7164 pst
= new dwarf2_psymtab (name
, objfile
, per_cu
);
7166 pst
->psymtabs_addrmap_supported
= true;
7168 /* This is the glue that links PST into GDB's symbol API. */
7169 per_cu
->v
.psymtab
= pst
;
7174 /* DIE reader function for process_psymtab_comp_unit. */
7177 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7178 const gdb_byte
*info_ptr
,
7179 struct die_info
*comp_unit_die
,
7180 enum language pretend_language
)
7182 struct dwarf2_cu
*cu
= reader
->cu
;
7183 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7184 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7185 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7187 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7188 dwarf2_psymtab
*pst
;
7189 enum pc_bounds_kind cu_bounds_kind
;
7190 const char *filename
;
7192 gdb_assert (! per_cu
->is_debug_types
);
7194 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7196 /* Allocate a new partial symbol table structure. */
7197 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7198 static const char artificial
[] = "<artificial>";
7199 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7200 if (filename
== NULL
)
7202 else if (strcmp (filename
, artificial
) == 0)
7204 debug_filename
.reset (concat (artificial
, "@",
7205 sect_offset_str (per_cu
->sect_off
),
7207 filename
= debug_filename
.get ();
7210 pst
= create_partial_symtab (per_cu
, filename
);
7212 /* This must be done before calling dwarf2_build_include_psymtabs. */
7213 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7215 baseaddr
= objfile
->text_section_offset ();
7217 dwarf2_find_base_address (comp_unit_die
, cu
);
7219 /* Possibly set the default values of LOWPC and HIGHPC from
7221 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7222 &best_highpc
, cu
, pst
);
7223 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7226 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7229 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7231 /* Store the contiguous range if it is not empty; it can be
7232 empty for CUs with no code. */
7233 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7237 /* Check if comp unit has_children.
7238 If so, read the rest of the partial symbols from this comp unit.
7239 If not, there's no more debug_info for this comp unit. */
7240 if (comp_unit_die
->has_children
)
7242 struct partial_die_info
*first_die
;
7243 CORE_ADDR lowpc
, highpc
;
7245 lowpc
= ((CORE_ADDR
) -1);
7246 highpc
= ((CORE_ADDR
) 0);
7248 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7250 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7251 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7253 /* If we didn't find a lowpc, set it to highpc to avoid
7254 complaints from `maint check'. */
7255 if (lowpc
== ((CORE_ADDR
) -1))
7258 /* If the compilation unit didn't have an explicit address range,
7259 then use the information extracted from its child dies. */
7260 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7263 best_highpc
= highpc
;
7266 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7267 best_lowpc
+ baseaddr
)
7269 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7270 best_highpc
+ baseaddr
)
7273 end_psymtab_common (objfile
, pst
);
7275 if (!cu
->per_cu
->imported_symtabs_empty ())
7278 int len
= cu
->per_cu
->imported_symtabs_size ();
7280 /* Fill in 'dependencies' here; we fill in 'users' in a
7282 pst
->number_of_dependencies
= len
;
7284 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7285 for (i
= 0; i
< len
; ++i
)
7287 pst
->dependencies
[i
]
7288 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7291 cu
->per_cu
->imported_symtabs_free ();
7294 /* Get the list of files included in the current compilation unit,
7295 and build a psymtab for each of them. */
7296 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7298 if (dwarf_read_debug
)
7299 fprintf_unfiltered (gdb_stdlog
,
7300 "Psymtab for %s unit @%s: %s - %s"
7301 ", %d global, %d static syms\n",
7302 per_cu
->is_debug_types
? "type" : "comp",
7303 sect_offset_str (per_cu
->sect_off
),
7304 paddress (gdbarch
, pst
->text_low (objfile
)),
7305 paddress (gdbarch
, pst
->text_high (objfile
)),
7306 pst
->n_global_syms
, pst
->n_static_syms
);
7309 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7310 Process compilation unit THIS_CU for a psymtab. */
7313 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7314 bool want_partial_unit
,
7315 enum language pretend_language
)
7317 /* If this compilation unit was already read in, free the
7318 cached copy in order to read it in again. This is
7319 necessary because we skipped some symbols when we first
7320 read in the compilation unit (see load_partial_dies).
7321 This problem could be avoided, but the benefit is unclear. */
7322 if (this_cu
->cu
!= NULL
)
7323 free_one_cached_comp_unit (this_cu
);
7325 cutu_reader
reader (this_cu
, NULL
, 0, false);
7327 switch (reader
.comp_unit_die
->tag
)
7329 case DW_TAG_compile_unit
:
7330 this_cu
->unit_type
= DW_UT_compile
;
7332 case DW_TAG_partial_unit
:
7333 this_cu
->unit_type
= DW_UT_partial
;
7343 else if (this_cu
->is_debug_types
)
7344 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7345 reader
.comp_unit_die
);
7346 else if (want_partial_unit
7347 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7348 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7349 reader
.comp_unit_die
,
7352 this_cu
->lang
= this_cu
->cu
->language
;
7354 /* Age out any secondary CUs. */
7355 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7358 /* Reader function for build_type_psymtabs. */
7361 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7362 const gdb_byte
*info_ptr
,
7363 struct die_info
*type_unit_die
)
7365 struct dwarf2_per_objfile
*dwarf2_per_objfile
7366 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7368 struct dwarf2_cu
*cu
= reader
->cu
;
7369 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7370 struct signatured_type
*sig_type
;
7371 struct type_unit_group
*tu_group
;
7372 struct attribute
*attr
;
7373 struct partial_die_info
*first_die
;
7374 CORE_ADDR lowpc
, highpc
;
7375 dwarf2_psymtab
*pst
;
7377 gdb_assert (per_cu
->is_debug_types
);
7378 sig_type
= (struct signatured_type
*) per_cu
;
7380 if (! type_unit_die
->has_children
)
7383 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7384 tu_group
= get_type_unit_group (cu
, attr
);
7386 if (tu_group
->tus
== nullptr)
7387 tu_group
->tus
= new std::vector
<signatured_type
*>;
7388 tu_group
->tus
->push_back (sig_type
);
7390 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7391 pst
= create_partial_symtab (per_cu
, "");
7392 pst
->anonymous
= true;
7394 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7396 lowpc
= (CORE_ADDR
) -1;
7397 highpc
= (CORE_ADDR
) 0;
7398 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7400 end_psymtab_common (objfile
, pst
);
7403 /* Struct used to sort TUs by their abbreviation table offset. */
7405 struct tu_abbrev_offset
7407 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7408 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7411 signatured_type
*sig_type
;
7412 sect_offset abbrev_offset
;
7415 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7418 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7419 const struct tu_abbrev_offset
&b
)
7421 return a
.abbrev_offset
< b
.abbrev_offset
;
7424 /* Efficiently read all the type units.
7425 This does the bulk of the work for build_type_psymtabs.
7427 The efficiency is because we sort TUs by the abbrev table they use and
7428 only read each abbrev table once. In one program there are 200K TUs
7429 sharing 8K abbrev tables.
7431 The main purpose of this function is to support building the
7432 dwarf2_per_objfile->type_unit_groups table.
7433 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7434 can collapse the search space by grouping them by stmt_list.
7435 The savings can be significant, in the same program from above the 200K TUs
7436 share 8K stmt_list tables.
7438 FUNC is expected to call get_type_unit_group, which will create the
7439 struct type_unit_group if necessary and add it to
7440 dwarf2_per_objfile->type_unit_groups. */
7443 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7445 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7446 abbrev_table_up abbrev_table
;
7447 sect_offset abbrev_offset
;
7449 /* It's up to the caller to not call us multiple times. */
7450 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7452 if (dwarf2_per_objfile
->all_type_units
.empty ())
7455 /* TUs typically share abbrev tables, and there can be way more TUs than
7456 abbrev tables. Sort by abbrev table to reduce the number of times we
7457 read each abbrev table in.
7458 Alternatives are to punt or to maintain a cache of abbrev tables.
7459 This is simpler and efficient enough for now.
7461 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7462 symtab to use). Typically TUs with the same abbrev offset have the same
7463 stmt_list value too so in practice this should work well.
7465 The basic algorithm here is:
7467 sort TUs by abbrev table
7468 for each TU with same abbrev table:
7469 read abbrev table if first user
7470 read TU top level DIE
7471 [IWBN if DWO skeletons had DW_AT_stmt_list]
7474 if (dwarf_read_debug
)
7475 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7477 /* Sort in a separate table to maintain the order of all_type_units
7478 for .gdb_index: TU indices directly index all_type_units. */
7479 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7480 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7482 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7483 sorted_by_abbrev
.emplace_back
7484 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7485 sig_type
->per_cu
.section
,
7486 sig_type
->per_cu
.sect_off
));
7488 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7489 sort_tu_by_abbrev_offset
);
7491 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7493 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7495 /* Switch to the next abbrev table if necessary. */
7496 if (abbrev_table
== NULL
7497 || tu
.abbrev_offset
!= abbrev_offset
)
7499 abbrev_offset
= tu
.abbrev_offset
;
7501 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7502 &dwarf2_per_objfile
->abbrev
,
7504 ++tu_stats
->nr_uniq_abbrev_tables
;
7507 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7509 if (!reader
.dummy_p
)
7510 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7511 reader
.comp_unit_die
);
7515 /* Print collected type unit statistics. */
7518 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7520 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7522 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7523 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7524 dwarf2_per_objfile
->all_type_units
.size ());
7525 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7526 tu_stats
->nr_uniq_abbrev_tables
);
7527 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7528 tu_stats
->nr_symtabs
);
7529 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7530 tu_stats
->nr_symtab_sharers
);
7531 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7532 tu_stats
->nr_stmt_less_type_units
);
7533 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7534 tu_stats
->nr_all_type_units_reallocs
);
7537 /* Traversal function for build_type_psymtabs. */
7540 build_type_psymtab_dependencies (void **slot
, void *info
)
7542 struct dwarf2_per_objfile
*dwarf2_per_objfile
7543 = (struct dwarf2_per_objfile
*) info
;
7544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7545 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7546 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7547 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7548 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7551 gdb_assert (len
> 0);
7552 gdb_assert (per_cu
->type_unit_group_p ());
7554 pst
->number_of_dependencies
= len
;
7555 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7556 for (i
= 0; i
< len
; ++i
)
7558 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7559 gdb_assert (iter
->per_cu
.is_debug_types
);
7560 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7561 iter
->type_unit_group
= tu_group
;
7564 delete tu_group
->tus
;
7565 tu_group
->tus
= nullptr;
7570 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7571 Build partial symbol tables for the .debug_types comp-units. */
7574 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7576 if (! create_all_type_units (dwarf2_per_objfile
))
7579 build_type_psymtabs_1 (dwarf2_per_objfile
);
7582 /* Traversal function for process_skeletonless_type_unit.
7583 Read a TU in a DWO file and build partial symbols for it. */
7586 process_skeletonless_type_unit (void **slot
, void *info
)
7588 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7589 struct dwarf2_per_objfile
*dwarf2_per_objfile
7590 = (struct dwarf2_per_objfile
*) info
;
7591 struct signatured_type find_entry
, *entry
;
7593 /* If this TU doesn't exist in the global table, add it and read it in. */
7595 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7596 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7598 find_entry
.signature
= dwo_unit
->signature
;
7599 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7600 &find_entry
, INSERT
);
7601 /* If we've already seen this type there's nothing to do. What's happening
7602 is we're doing our own version of comdat-folding here. */
7606 /* This does the job that create_all_type_units would have done for
7608 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7609 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7612 /* This does the job that build_type_psymtabs_1 would have done. */
7613 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7614 if (!reader
.dummy_p
)
7615 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7616 reader
.comp_unit_die
);
7621 /* Traversal function for process_skeletonless_type_units. */
7624 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7626 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7628 if (dwo_file
->tus
!= NULL
)
7629 htab_traverse_noresize (dwo_file
->tus
.get (),
7630 process_skeletonless_type_unit
, info
);
7635 /* Scan all TUs of DWO files, verifying we've processed them.
7636 This is needed in case a TU was emitted without its skeleton.
7637 Note: This can't be done until we know what all the DWO files are. */
7640 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7642 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7643 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7644 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7646 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7647 process_dwo_file_for_skeletonless_type_units
,
7648 dwarf2_per_objfile
);
7652 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7655 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7657 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7659 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7664 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7666 /* Set the 'user' field only if it is not already set. */
7667 if (pst
->dependencies
[j
]->user
== NULL
)
7668 pst
->dependencies
[j
]->user
= pst
;
7673 /* Build the partial symbol table by doing a quick pass through the
7674 .debug_info and .debug_abbrev sections. */
7677 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7679 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7681 if (dwarf_read_debug
)
7683 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7684 objfile_name (objfile
));
7687 scoped_restore restore_reading_psyms
7688 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7691 dwarf2_per_objfile
->info
.read (objfile
);
7693 /* Any cached compilation units will be linked by the per-objfile
7694 read_in_chain. Make sure to free them when we're done. */
7695 free_cached_comp_units
freer (dwarf2_per_objfile
);
7697 build_type_psymtabs (dwarf2_per_objfile
);
7699 create_all_comp_units (dwarf2_per_objfile
);
7701 /* Create a temporary address map on a temporary obstack. We later
7702 copy this to the final obstack. */
7703 auto_obstack temp_obstack
;
7705 scoped_restore save_psymtabs_addrmap
7706 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7707 addrmap_create_mutable (&temp_obstack
));
7709 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7710 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7712 /* This has to wait until we read the CUs, we need the list of DWOs. */
7713 process_skeletonless_type_units (dwarf2_per_objfile
);
7715 /* Now that all TUs have been processed we can fill in the dependencies. */
7716 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7718 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7719 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7722 if (dwarf_read_debug
)
7723 print_tu_stats (dwarf2_per_objfile
);
7725 set_partial_user (dwarf2_per_objfile
);
7727 objfile
->partial_symtabs
->psymtabs_addrmap
7728 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7729 objfile
->partial_symtabs
->obstack ());
7730 /* At this point we want to keep the address map. */
7731 save_psymtabs_addrmap
.release ();
7733 if (dwarf_read_debug
)
7734 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7735 objfile_name (objfile
));
7738 /* Load the partial DIEs for a secondary CU into memory.
7739 This is also used when rereading a primary CU with load_all_dies. */
7742 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7744 cutu_reader
reader (this_cu
, NULL
, 1, false);
7746 if (!reader
.dummy_p
)
7748 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7751 /* Check if comp unit has_children.
7752 If so, read the rest of the partial symbols from this comp unit.
7753 If not, there's no more debug_info for this comp unit. */
7754 if (reader
.comp_unit_die
->has_children
)
7755 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7762 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7763 struct dwarf2_section_info
*section
,
7764 struct dwarf2_section_info
*abbrev_section
,
7765 unsigned int is_dwz
)
7767 const gdb_byte
*info_ptr
;
7768 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7770 if (dwarf_read_debug
)
7771 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7772 section
->get_name (),
7773 section
->get_file_name ());
7775 section
->read (objfile
);
7777 info_ptr
= section
->buffer
;
7779 while (info_ptr
< section
->buffer
+ section
->size
)
7781 struct dwarf2_per_cu_data
*this_cu
;
7783 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7785 comp_unit_head cu_header
;
7786 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7787 abbrev_section
, info_ptr
,
7788 rcuh_kind::COMPILE
);
7790 /* Save the compilation unit for later lookup. */
7791 if (cu_header
.unit_type
!= DW_UT_type
)
7793 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7794 struct dwarf2_per_cu_data
);
7795 memset (this_cu
, 0, sizeof (*this_cu
));
7799 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7800 struct signatured_type
);
7801 memset (sig_type
, 0, sizeof (*sig_type
));
7802 sig_type
->signature
= cu_header
.signature
;
7803 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7804 this_cu
= &sig_type
->per_cu
;
7806 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7807 this_cu
->sect_off
= sect_off
;
7808 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7809 this_cu
->is_dwz
= is_dwz
;
7810 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7811 this_cu
->section
= section
;
7813 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7815 info_ptr
= info_ptr
+ this_cu
->length
;
7819 /* Create a list of all compilation units in OBJFILE.
7820 This is only done for -readnow and building partial symtabs. */
7823 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7825 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7826 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7827 &dwarf2_per_objfile
->abbrev
, 0);
7829 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7831 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7835 /* Process all loaded DIEs for compilation unit CU, starting at
7836 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7837 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7838 DW_AT_ranges). See the comments of add_partial_subprogram on how
7839 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7842 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7843 CORE_ADDR
*highpc
, int set_addrmap
,
7844 struct dwarf2_cu
*cu
)
7846 struct partial_die_info
*pdi
;
7848 /* Now, march along the PDI's, descending into ones which have
7849 interesting children but skipping the children of the other ones,
7850 until we reach the end of the compilation unit. */
7858 /* Anonymous namespaces or modules have no name but have interesting
7859 children, so we need to look at them. Ditto for anonymous
7862 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7863 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7864 || pdi
->tag
== DW_TAG_imported_unit
7865 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7869 case DW_TAG_subprogram
:
7870 case DW_TAG_inlined_subroutine
:
7871 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7873 case DW_TAG_constant
:
7874 case DW_TAG_variable
:
7875 case DW_TAG_typedef
:
7876 case DW_TAG_union_type
:
7877 if (!pdi
->is_declaration
)
7879 add_partial_symbol (pdi
, cu
);
7882 case DW_TAG_class_type
:
7883 case DW_TAG_interface_type
:
7884 case DW_TAG_structure_type
:
7885 if (!pdi
->is_declaration
)
7887 add_partial_symbol (pdi
, cu
);
7889 if ((cu
->language
== language_rust
7890 || cu
->language
== language_cplus
) && pdi
->has_children
)
7891 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7894 case DW_TAG_enumeration_type
:
7895 if (!pdi
->is_declaration
)
7896 add_partial_enumeration (pdi
, cu
);
7898 case DW_TAG_base_type
:
7899 case DW_TAG_subrange_type
:
7900 /* File scope base type definitions are added to the partial
7902 add_partial_symbol (pdi
, cu
);
7904 case DW_TAG_namespace
:
7905 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7908 if (!pdi
->is_declaration
)
7909 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7911 case DW_TAG_imported_unit
:
7913 struct dwarf2_per_cu_data
*per_cu
;
7915 /* For now we don't handle imported units in type units. */
7916 if (cu
->per_cu
->is_debug_types
)
7918 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7919 " supported in type units [in module %s]"),
7920 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7923 per_cu
= dwarf2_find_containing_comp_unit
7924 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7925 cu
->per_cu
->dwarf2_per_objfile
);
7927 /* Go read the partial unit, if needed. */
7928 if (per_cu
->v
.psymtab
== NULL
)
7929 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7931 cu
->per_cu
->imported_symtabs_push (per_cu
);
7934 case DW_TAG_imported_declaration
:
7935 add_partial_symbol (pdi
, cu
);
7942 /* If the die has a sibling, skip to the sibling. */
7944 pdi
= pdi
->die_sibling
;
7948 /* Functions used to compute the fully scoped name of a partial DIE.
7950 Normally, this is simple. For C++, the parent DIE's fully scoped
7951 name is concatenated with "::" and the partial DIE's name.
7952 Enumerators are an exception; they use the scope of their parent
7953 enumeration type, i.e. the name of the enumeration type is not
7954 prepended to the enumerator.
7956 There are two complexities. One is DW_AT_specification; in this
7957 case "parent" means the parent of the target of the specification,
7958 instead of the direct parent of the DIE. The other is compilers
7959 which do not emit DW_TAG_namespace; in this case we try to guess
7960 the fully qualified name of structure types from their members'
7961 linkage names. This must be done using the DIE's children rather
7962 than the children of any DW_AT_specification target. We only need
7963 to do this for structures at the top level, i.e. if the target of
7964 any DW_AT_specification (if any; otherwise the DIE itself) does not
7967 /* Compute the scope prefix associated with PDI's parent, in
7968 compilation unit CU. The result will be allocated on CU's
7969 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7970 field. NULL is returned if no prefix is necessary. */
7972 partial_die_parent_scope (struct partial_die_info
*pdi
,
7973 struct dwarf2_cu
*cu
)
7975 const char *grandparent_scope
;
7976 struct partial_die_info
*parent
, *real_pdi
;
7978 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7979 then this means the parent of the specification DIE. */
7982 while (real_pdi
->has_specification
)
7984 auto res
= find_partial_die (real_pdi
->spec_offset
,
7985 real_pdi
->spec_is_dwz
, cu
);
7990 parent
= real_pdi
->die_parent
;
7994 if (parent
->scope_set
)
7995 return parent
->scope
;
7999 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8001 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8002 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8003 Work around this problem here. */
8004 if (cu
->language
== language_cplus
8005 && parent
->tag
== DW_TAG_namespace
8006 && strcmp (parent
->name
, "::") == 0
8007 && grandparent_scope
== NULL
)
8009 parent
->scope
= NULL
;
8010 parent
->scope_set
= 1;
8014 /* Nested subroutines in Fortran get a prefix. */
8015 if (pdi
->tag
== DW_TAG_enumerator
)
8016 /* Enumerators should not get the name of the enumeration as a prefix. */
8017 parent
->scope
= grandparent_scope
;
8018 else if (parent
->tag
== DW_TAG_namespace
8019 || parent
->tag
== DW_TAG_module
8020 || parent
->tag
== DW_TAG_structure_type
8021 || parent
->tag
== DW_TAG_class_type
8022 || parent
->tag
== DW_TAG_interface_type
8023 || parent
->tag
== DW_TAG_union_type
8024 || parent
->tag
== DW_TAG_enumeration_type
8025 || (cu
->language
== language_fortran
8026 && parent
->tag
== DW_TAG_subprogram
8027 && pdi
->tag
== DW_TAG_subprogram
))
8029 if (grandparent_scope
== NULL
)
8030 parent
->scope
= parent
->name
;
8032 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8034 parent
->name
, 0, cu
);
8038 /* FIXME drow/2004-04-01: What should we be doing with
8039 function-local names? For partial symbols, we should probably be
8041 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8042 dwarf_tag_name (parent
->tag
),
8043 sect_offset_str (pdi
->sect_off
));
8044 parent
->scope
= grandparent_scope
;
8047 parent
->scope_set
= 1;
8048 return parent
->scope
;
8051 /* Return the fully scoped name associated with PDI, from compilation unit
8052 CU. The result will be allocated with malloc. */
8054 static gdb::unique_xmalloc_ptr
<char>
8055 partial_die_full_name (struct partial_die_info
*pdi
,
8056 struct dwarf2_cu
*cu
)
8058 const char *parent_scope
;
8060 /* If this is a template instantiation, we can not work out the
8061 template arguments from partial DIEs. So, unfortunately, we have
8062 to go through the full DIEs. At least any work we do building
8063 types here will be reused if full symbols are loaded later. */
8064 if (pdi
->has_template_arguments
)
8068 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8070 struct die_info
*die
;
8071 struct attribute attr
;
8072 struct dwarf2_cu
*ref_cu
= cu
;
8074 /* DW_FORM_ref_addr is using section offset. */
8075 attr
.name
= (enum dwarf_attribute
) 0;
8076 attr
.form
= DW_FORM_ref_addr
;
8077 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8078 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8080 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8084 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8085 if (parent_scope
== NULL
)
8088 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8093 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8095 struct dwarf2_per_objfile
*dwarf2_per_objfile
8096 = cu
->per_cu
->dwarf2_per_objfile
;
8097 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8098 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8100 const char *actual_name
= NULL
;
8103 baseaddr
= objfile
->text_section_offset ();
8105 gdb::unique_xmalloc_ptr
<char> built_actual_name
8106 = partial_die_full_name (pdi
, cu
);
8107 if (built_actual_name
!= NULL
)
8108 actual_name
= built_actual_name
.get ();
8110 if (actual_name
== NULL
)
8111 actual_name
= pdi
->name
;
8115 case DW_TAG_inlined_subroutine
:
8116 case DW_TAG_subprogram
:
8117 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8119 if (pdi
->is_external
8120 || cu
->language
== language_ada
8121 || (cu
->language
== language_fortran
8122 && pdi
->die_parent
!= NULL
8123 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8125 /* Normally, only "external" DIEs are part of the global scope.
8126 But in Ada and Fortran, we want to be able to access nested
8127 procedures globally. So all Ada and Fortran subprograms are
8128 stored in the global scope. */
8129 add_psymbol_to_list (actual_name
,
8130 built_actual_name
!= NULL
,
8131 VAR_DOMAIN
, LOC_BLOCK
,
8132 SECT_OFF_TEXT (objfile
),
8133 psymbol_placement::GLOBAL
,
8135 cu
->language
, objfile
);
8139 add_psymbol_to_list (actual_name
,
8140 built_actual_name
!= NULL
,
8141 VAR_DOMAIN
, LOC_BLOCK
,
8142 SECT_OFF_TEXT (objfile
),
8143 psymbol_placement::STATIC
,
8144 addr
, cu
->language
, objfile
);
8147 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8148 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8150 case DW_TAG_constant
:
8151 add_psymbol_to_list (actual_name
,
8152 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8153 -1, (pdi
->is_external
8154 ? psymbol_placement::GLOBAL
8155 : psymbol_placement::STATIC
),
8156 0, cu
->language
, objfile
);
8158 case DW_TAG_variable
:
8160 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8164 && !dwarf2_per_objfile
->has_section_at_zero
)
8166 /* A global or static variable may also have been stripped
8167 out by the linker if unused, in which case its address
8168 will be nullified; do not add such variables into partial
8169 symbol table then. */
8171 else if (pdi
->is_external
)
8174 Don't enter into the minimal symbol tables as there is
8175 a minimal symbol table entry from the ELF symbols already.
8176 Enter into partial symbol table if it has a location
8177 descriptor or a type.
8178 If the location descriptor is missing, new_symbol will create
8179 a LOC_UNRESOLVED symbol, the address of the variable will then
8180 be determined from the minimal symbol table whenever the variable
8182 The address for the partial symbol table entry is not
8183 used by GDB, but it comes in handy for debugging partial symbol
8186 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8187 add_psymbol_to_list (actual_name
,
8188 built_actual_name
!= NULL
,
8189 VAR_DOMAIN
, LOC_STATIC
,
8190 SECT_OFF_TEXT (objfile
),
8191 psymbol_placement::GLOBAL
,
8192 addr
, cu
->language
, objfile
);
8196 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8198 /* Static Variable. Skip symbols whose value we cannot know (those
8199 without location descriptors or constant values). */
8200 if (!has_loc
&& !pdi
->has_const_value
)
8203 add_psymbol_to_list (actual_name
,
8204 built_actual_name
!= NULL
,
8205 VAR_DOMAIN
, LOC_STATIC
,
8206 SECT_OFF_TEXT (objfile
),
8207 psymbol_placement::STATIC
,
8209 cu
->language
, objfile
);
8212 case DW_TAG_typedef
:
8213 case DW_TAG_base_type
:
8214 case DW_TAG_subrange_type
:
8215 add_psymbol_to_list (actual_name
,
8216 built_actual_name
!= NULL
,
8217 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8218 psymbol_placement::STATIC
,
8219 0, cu
->language
, objfile
);
8221 case DW_TAG_imported_declaration
:
8222 case DW_TAG_namespace
:
8223 add_psymbol_to_list (actual_name
,
8224 built_actual_name
!= NULL
,
8225 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8226 psymbol_placement::GLOBAL
,
8227 0, cu
->language
, objfile
);
8230 /* With Fortran 77 there might be a "BLOCK DATA" module
8231 available without any name. If so, we skip the module as it
8232 doesn't bring any value. */
8233 if (actual_name
!= nullptr)
8234 add_psymbol_to_list (actual_name
,
8235 built_actual_name
!= NULL
,
8236 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8237 psymbol_placement::GLOBAL
,
8238 0, cu
->language
, objfile
);
8240 case DW_TAG_class_type
:
8241 case DW_TAG_interface_type
:
8242 case DW_TAG_structure_type
:
8243 case DW_TAG_union_type
:
8244 case DW_TAG_enumeration_type
:
8245 /* Skip external references. The DWARF standard says in the section
8246 about "Structure, Union, and Class Type Entries": "An incomplete
8247 structure, union or class type is represented by a structure,
8248 union or class entry that does not have a byte size attribute
8249 and that has a DW_AT_declaration attribute." */
8250 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8253 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8254 static vs. global. */
8255 add_psymbol_to_list (actual_name
,
8256 built_actual_name
!= NULL
,
8257 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8258 cu
->language
== language_cplus
8259 ? psymbol_placement::GLOBAL
8260 : psymbol_placement::STATIC
,
8261 0, cu
->language
, objfile
);
8264 case DW_TAG_enumerator
:
8265 add_psymbol_to_list (actual_name
,
8266 built_actual_name
!= NULL
,
8267 VAR_DOMAIN
, LOC_CONST
, -1,
8268 cu
->language
== language_cplus
8269 ? psymbol_placement::GLOBAL
8270 : psymbol_placement::STATIC
,
8271 0, cu
->language
, objfile
);
8278 /* Read a partial die corresponding to a namespace; also, add a symbol
8279 corresponding to that namespace to the symbol table. NAMESPACE is
8280 the name of the enclosing namespace. */
8283 add_partial_namespace (struct partial_die_info
*pdi
,
8284 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8285 int set_addrmap
, struct dwarf2_cu
*cu
)
8287 /* Add a symbol for the namespace. */
8289 add_partial_symbol (pdi
, cu
);
8291 /* Now scan partial symbols in that namespace. */
8293 if (pdi
->has_children
)
8294 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8297 /* Read a partial die corresponding to a Fortran module. */
8300 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8301 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8303 /* Add a symbol for the namespace. */
8305 add_partial_symbol (pdi
, cu
);
8307 /* Now scan partial symbols in that module. */
8309 if (pdi
->has_children
)
8310 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8313 /* Read a partial die corresponding to a subprogram or an inlined
8314 subprogram and create a partial symbol for that subprogram.
8315 When the CU language allows it, this routine also defines a partial
8316 symbol for each nested subprogram that this subprogram contains.
8317 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8318 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8320 PDI may also be a lexical block, in which case we simply search
8321 recursively for subprograms defined inside that lexical block.
8322 Again, this is only performed when the CU language allows this
8323 type of definitions. */
8326 add_partial_subprogram (struct partial_die_info
*pdi
,
8327 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8328 int set_addrmap
, struct dwarf2_cu
*cu
)
8330 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8332 if (pdi
->has_pc_info
)
8334 if (pdi
->lowpc
< *lowpc
)
8335 *lowpc
= pdi
->lowpc
;
8336 if (pdi
->highpc
> *highpc
)
8337 *highpc
= pdi
->highpc
;
8340 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8341 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8343 CORE_ADDR this_highpc
;
8344 CORE_ADDR this_lowpc
;
8346 baseaddr
= objfile
->text_section_offset ();
8348 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8349 pdi
->lowpc
+ baseaddr
)
8352 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8353 pdi
->highpc
+ baseaddr
)
8355 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8356 this_lowpc
, this_highpc
- 1,
8357 cu
->per_cu
->v
.psymtab
);
8361 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8363 if (!pdi
->is_declaration
)
8364 /* Ignore subprogram DIEs that do not have a name, they are
8365 illegal. Do not emit a complaint at this point, we will
8366 do so when we convert this psymtab into a symtab. */
8368 add_partial_symbol (pdi
, cu
);
8372 if (! pdi
->has_children
)
8375 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8377 pdi
= pdi
->die_child
;
8381 if (pdi
->tag
== DW_TAG_subprogram
8382 || pdi
->tag
== DW_TAG_inlined_subroutine
8383 || pdi
->tag
== DW_TAG_lexical_block
)
8384 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8385 pdi
= pdi
->die_sibling
;
8390 /* Read a partial die corresponding to an enumeration type. */
8393 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8394 struct dwarf2_cu
*cu
)
8396 struct partial_die_info
*pdi
;
8398 if (enum_pdi
->name
!= NULL
)
8399 add_partial_symbol (enum_pdi
, cu
);
8401 pdi
= enum_pdi
->die_child
;
8404 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8405 complaint (_("malformed enumerator DIE ignored"));
8407 add_partial_symbol (pdi
, cu
);
8408 pdi
= pdi
->die_sibling
;
8412 /* Return the initial uleb128 in the die at INFO_PTR. */
8415 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8417 unsigned int bytes_read
;
8419 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8422 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8423 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8425 Return the corresponding abbrev, or NULL if the number is zero (indicating
8426 an empty DIE). In either case *BYTES_READ will be set to the length of
8427 the initial number. */
8429 static struct abbrev_info
*
8430 peek_die_abbrev (const die_reader_specs
&reader
,
8431 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8433 dwarf2_cu
*cu
= reader
.cu
;
8434 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8435 unsigned int abbrev_number
8436 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8438 if (abbrev_number
== 0)
8441 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8444 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8445 " at offset %s [in module %s]"),
8446 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8447 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8453 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8454 Returns a pointer to the end of a series of DIEs, terminated by an empty
8455 DIE. Any children of the skipped DIEs will also be skipped. */
8457 static const gdb_byte
*
8458 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8462 unsigned int bytes_read
;
8463 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8466 return info_ptr
+ bytes_read
;
8468 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8472 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8473 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8474 abbrev corresponding to that skipped uleb128 should be passed in
8475 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8478 static const gdb_byte
*
8479 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8480 struct abbrev_info
*abbrev
)
8482 unsigned int bytes_read
;
8483 struct attribute attr
;
8484 bfd
*abfd
= reader
->abfd
;
8485 struct dwarf2_cu
*cu
= reader
->cu
;
8486 const gdb_byte
*buffer
= reader
->buffer
;
8487 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8488 unsigned int form
, i
;
8490 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8492 /* The only abbrev we care about is DW_AT_sibling. */
8493 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8496 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8498 if (attr
.form
== DW_FORM_ref_addr
)
8499 complaint (_("ignoring absolute DW_AT_sibling"));
8502 sect_offset off
= attr
.get_ref_die_offset ();
8503 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8505 if (sibling_ptr
< info_ptr
)
8506 complaint (_("DW_AT_sibling points backwards"));
8507 else if (sibling_ptr
> reader
->buffer_end
)
8508 reader
->die_section
->overflow_complaint ();
8514 /* If it isn't DW_AT_sibling, skip this attribute. */
8515 form
= abbrev
->attrs
[i
].form
;
8519 case DW_FORM_ref_addr
:
8520 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8521 and later it is offset sized. */
8522 if (cu
->header
.version
== 2)
8523 info_ptr
+= cu
->header
.addr_size
;
8525 info_ptr
+= cu
->header
.offset_size
;
8527 case DW_FORM_GNU_ref_alt
:
8528 info_ptr
+= cu
->header
.offset_size
;
8531 info_ptr
+= cu
->header
.addr_size
;
8539 case DW_FORM_flag_present
:
8540 case DW_FORM_implicit_const
:
8557 case DW_FORM_ref_sig8
:
8560 case DW_FORM_data16
:
8563 case DW_FORM_string
:
8564 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8565 info_ptr
+= bytes_read
;
8567 case DW_FORM_sec_offset
:
8569 case DW_FORM_GNU_strp_alt
:
8570 info_ptr
+= cu
->header
.offset_size
;
8572 case DW_FORM_exprloc
:
8574 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8575 info_ptr
+= bytes_read
;
8577 case DW_FORM_block1
:
8578 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8580 case DW_FORM_block2
:
8581 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8583 case DW_FORM_block4
:
8584 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8590 case DW_FORM_ref_udata
:
8591 case DW_FORM_GNU_addr_index
:
8592 case DW_FORM_GNU_str_index
:
8593 case DW_FORM_rnglistx
:
8594 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8596 case DW_FORM_indirect
:
8597 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8598 info_ptr
+= bytes_read
;
8599 /* We need to continue parsing from here, so just go back to
8601 goto skip_attribute
;
8604 error (_("Dwarf Error: Cannot handle %s "
8605 "in DWARF reader [in module %s]"),
8606 dwarf_form_name (form
),
8607 bfd_get_filename (abfd
));
8611 if (abbrev
->has_children
)
8612 return skip_children (reader
, info_ptr
);
8617 /* Locate ORIG_PDI's sibling.
8618 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8620 static const gdb_byte
*
8621 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8622 struct partial_die_info
*orig_pdi
,
8623 const gdb_byte
*info_ptr
)
8625 /* Do we know the sibling already? */
8627 if (orig_pdi
->sibling
)
8628 return orig_pdi
->sibling
;
8630 /* Are there any children to deal with? */
8632 if (!orig_pdi
->has_children
)
8635 /* Skip the children the long way. */
8637 return skip_children (reader
, info_ptr
);
8640 /* Expand this partial symbol table into a full symbol table. SELF is
8644 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8646 struct dwarf2_per_objfile
*dwarf2_per_objfile
8647 = get_dwarf2_per_objfile (objfile
);
8649 gdb_assert (!readin
);
8650 /* If this psymtab is constructed from a debug-only objfile, the
8651 has_section_at_zero flag will not necessarily be correct. We
8652 can get the correct value for this flag by looking at the data
8653 associated with the (presumably stripped) associated objfile. */
8654 if (objfile
->separate_debug_objfile_backlink
)
8656 struct dwarf2_per_objfile
*dpo_backlink
8657 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8659 dwarf2_per_objfile
->has_section_at_zero
8660 = dpo_backlink
->has_section_at_zero
;
8663 expand_psymtab (objfile
);
8665 process_cu_includes (dwarf2_per_objfile
);
8668 /* Reading in full CUs. */
8670 /* Add PER_CU to the queue. */
8673 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8674 enum language pretend_language
)
8677 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8680 /* If PER_CU is not yet queued, add it to the queue.
8681 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8683 The result is non-zero if PER_CU was queued, otherwise the result is zero
8684 meaning either PER_CU is already queued or it is already loaded.
8686 N.B. There is an invariant here that if a CU is queued then it is loaded.
8687 The caller is required to load PER_CU if we return non-zero. */
8690 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8691 struct dwarf2_per_cu_data
*per_cu
,
8692 enum language pretend_language
)
8694 /* We may arrive here during partial symbol reading, if we need full
8695 DIEs to process an unusual case (e.g. template arguments). Do
8696 not queue PER_CU, just tell our caller to load its DIEs. */
8697 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8699 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8704 /* Mark the dependence relation so that we don't flush PER_CU
8706 if (dependent_cu
!= NULL
)
8707 dwarf2_add_dependence (dependent_cu
, per_cu
);
8709 /* If it's already on the queue, we have nothing to do. */
8713 /* If the compilation unit is already loaded, just mark it as
8715 if (per_cu
->cu
!= NULL
)
8717 per_cu
->cu
->last_used
= 0;
8721 /* Add it to the queue. */
8722 queue_comp_unit (per_cu
, pretend_language
);
8727 /* Process the queue. */
8730 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8732 if (dwarf_read_debug
)
8734 fprintf_unfiltered (gdb_stdlog
,
8735 "Expanding one or more symtabs of objfile %s ...\n",
8736 objfile_name (dwarf2_per_objfile
->objfile
));
8739 /* The queue starts out with one item, but following a DIE reference
8740 may load a new CU, adding it to the end of the queue. */
8741 while (!dwarf2_per_objfile
->queue
.empty ())
8743 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8745 if ((dwarf2_per_objfile
->using_index
8746 ? !item
.per_cu
->v
.quick
->compunit_symtab
8747 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8748 /* Skip dummy CUs. */
8749 && item
.per_cu
->cu
!= NULL
)
8751 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8752 unsigned int debug_print_threshold
;
8755 if (per_cu
->is_debug_types
)
8757 struct signatured_type
*sig_type
=
8758 (struct signatured_type
*) per_cu
;
8760 sprintf (buf
, "TU %s at offset %s",
8761 hex_string (sig_type
->signature
),
8762 sect_offset_str (per_cu
->sect_off
));
8763 /* There can be 100s of TUs.
8764 Only print them in verbose mode. */
8765 debug_print_threshold
= 2;
8769 sprintf (buf
, "CU at offset %s",
8770 sect_offset_str (per_cu
->sect_off
));
8771 debug_print_threshold
= 1;
8774 if (dwarf_read_debug
>= debug_print_threshold
)
8775 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8777 if (per_cu
->is_debug_types
)
8778 process_full_type_unit (per_cu
, item
.pretend_language
);
8780 process_full_comp_unit (per_cu
, item
.pretend_language
);
8782 if (dwarf_read_debug
>= debug_print_threshold
)
8783 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8786 item
.per_cu
->queued
= 0;
8787 dwarf2_per_objfile
->queue
.pop ();
8790 if (dwarf_read_debug
)
8792 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8793 objfile_name (dwarf2_per_objfile
->objfile
));
8797 /* Read in full symbols for PST, and anything it depends on. */
8800 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8805 expand_dependencies (objfile
);
8807 dw2_do_instantiate_symtab (per_cu_data
, false);
8808 gdb_assert (get_compunit_symtab () != nullptr);
8811 /* Trivial hash function for die_info: the hash value of a DIE
8812 is its offset in .debug_info for this objfile. */
8815 die_hash (const void *item
)
8817 const struct die_info
*die
= (const struct die_info
*) item
;
8819 return to_underlying (die
->sect_off
);
8822 /* Trivial comparison function for die_info structures: two DIEs
8823 are equal if they have the same offset. */
8826 die_eq (const void *item_lhs
, const void *item_rhs
)
8828 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8829 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8831 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8834 /* Load the DIEs associated with PER_CU into memory. */
8837 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8839 enum language pretend_language
)
8841 gdb_assert (! this_cu
->is_debug_types
);
8843 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8847 struct dwarf2_cu
*cu
= reader
.cu
;
8848 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8850 gdb_assert (cu
->die_hash
== NULL
);
8852 htab_create_alloc_ex (cu
->header
.length
/ 12,
8856 &cu
->comp_unit_obstack
,
8857 hashtab_obstack_allocate
,
8858 dummy_obstack_deallocate
);
8860 if (reader
.comp_unit_die
->has_children
)
8861 reader
.comp_unit_die
->child
8862 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8863 &info_ptr
, reader
.comp_unit_die
);
8864 cu
->dies
= reader
.comp_unit_die
;
8865 /* comp_unit_die is not stored in die_hash, no need. */
8867 /* We try not to read any attributes in this function, because not
8868 all CUs needed for references have been loaded yet, and symbol
8869 table processing isn't initialized. But we have to set the CU language,
8870 or we won't be able to build types correctly.
8871 Similarly, if we do not read the producer, we can not apply
8872 producer-specific interpretation. */
8873 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8878 /* Add a DIE to the delayed physname list. */
8881 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8882 const char *name
, struct die_info
*die
,
8883 struct dwarf2_cu
*cu
)
8885 struct delayed_method_info mi
;
8887 mi
.fnfield_index
= fnfield_index
;
8891 cu
->method_list
.push_back (mi
);
8894 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8895 "const" / "volatile". If so, decrements LEN by the length of the
8896 modifier and return true. Otherwise return false. */
8900 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8902 size_t mod_len
= sizeof (mod
) - 1;
8903 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8911 /* Compute the physnames of any methods on the CU's method list.
8913 The computation of method physnames is delayed in order to avoid the
8914 (bad) condition that one of the method's formal parameters is of an as yet
8918 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8920 /* Only C++ delays computing physnames. */
8921 if (cu
->method_list
.empty ())
8923 gdb_assert (cu
->language
== language_cplus
);
8925 for (const delayed_method_info
&mi
: cu
->method_list
)
8927 const char *physname
;
8928 struct fn_fieldlist
*fn_flp
8929 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8930 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8931 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8932 = physname
? physname
: "";
8934 /* Since there's no tag to indicate whether a method is a
8935 const/volatile overload, extract that information out of the
8937 if (physname
!= NULL
)
8939 size_t len
= strlen (physname
);
8943 if (physname
[len
] == ')') /* shortcut */
8945 else if (check_modifier (physname
, len
, " const"))
8946 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8947 else if (check_modifier (physname
, len
, " volatile"))
8948 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8955 /* The list is no longer needed. */
8956 cu
->method_list
.clear ();
8959 /* Go objects should be embedded in a DW_TAG_module DIE,
8960 and it's not clear if/how imported objects will appear.
8961 To keep Go support simple until that's worked out,
8962 go back through what we've read and create something usable.
8963 We could do this while processing each DIE, and feels kinda cleaner,
8964 but that way is more invasive.
8965 This is to, for example, allow the user to type "p var" or "b main"
8966 without having to specify the package name, and allow lookups
8967 of module.object to work in contexts that use the expression
8971 fixup_go_packaging (struct dwarf2_cu
*cu
)
8973 gdb::unique_xmalloc_ptr
<char> package_name
;
8974 struct pending
*list
;
8977 for (list
= *cu
->get_builder ()->get_global_symbols ();
8981 for (i
= 0; i
< list
->nsyms
; ++i
)
8983 struct symbol
*sym
= list
->symbol
[i
];
8985 if (sym
->language () == language_go
8986 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8988 gdb::unique_xmalloc_ptr
<char> this_package_name
8989 (go_symbol_package_name (sym
));
8991 if (this_package_name
== NULL
)
8993 if (package_name
== NULL
)
8994 package_name
= std::move (this_package_name
);
8997 struct objfile
*objfile
8998 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8999 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9000 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9001 (symbol_symtab (sym
) != NULL
9002 ? symtab_to_filename_for_display
9003 (symbol_symtab (sym
))
9004 : objfile_name (objfile
)),
9005 this_package_name
.get (), package_name
.get ());
9011 if (package_name
!= NULL
)
9013 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9014 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9015 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9016 saved_package_name
);
9019 sym
= allocate_symbol (objfile
);
9020 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9021 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9022 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9023 e.g., "main" finds the "main" module and not C's main(). */
9024 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9025 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9026 SYMBOL_TYPE (sym
) = type
;
9028 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9032 /* Allocate a fully-qualified name consisting of the two parts on the
9036 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9038 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9041 /* A helper that allocates a struct discriminant_info to attach to a
9044 static struct discriminant_info
*
9045 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9048 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9049 gdb_assert (discriminant_index
== -1
9050 || (discriminant_index
>= 0
9051 && discriminant_index
< TYPE_NFIELDS (type
)));
9052 gdb_assert (default_index
== -1
9053 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9055 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9057 struct discriminant_info
*disc
9058 = ((struct discriminant_info
*)
9060 offsetof (struct discriminant_info
, discriminants
)
9061 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9062 disc
->default_index
= default_index
;
9063 disc
->discriminant_index
= discriminant_index
;
9065 struct dynamic_prop prop
;
9066 prop
.kind
= PROP_UNDEFINED
;
9067 prop
.data
.baton
= disc
;
9069 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9074 /* Some versions of rustc emitted enums in an unusual way.
9076 Ordinary enums were emitted as unions. The first element of each
9077 structure in the union was named "RUST$ENUM$DISR". This element
9078 held the discriminant.
9080 These versions of Rust also implemented the "non-zero"
9081 optimization. When the enum had two values, and one is empty and
9082 the other holds a pointer that cannot be zero, the pointer is used
9083 as the discriminant, with a zero value meaning the empty variant.
9084 Here, the union's first member is of the form
9085 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9086 where the fieldnos are the indices of the fields that should be
9087 traversed in order to find the field (which may be several fields deep)
9088 and the variantname is the name of the variant of the case when the
9091 This function recognizes whether TYPE is of one of these forms,
9092 and, if so, smashes it to be a variant type. */
9095 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9097 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9099 /* We don't need to deal with empty enums. */
9100 if (TYPE_NFIELDS (type
) == 0)
9103 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9104 if (TYPE_NFIELDS (type
) == 1
9105 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9107 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9109 /* Decode the field name to find the offset of the
9111 ULONGEST bit_offset
= 0;
9112 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9113 while (name
[0] >= '0' && name
[0] <= '9')
9116 unsigned long index
= strtoul (name
, &tail
, 10);
9119 || index
>= TYPE_NFIELDS (field_type
)
9120 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9121 != FIELD_LOC_KIND_BITPOS
))
9123 complaint (_("Could not parse Rust enum encoding string \"%s\""
9125 TYPE_FIELD_NAME (type
, 0),
9126 objfile_name (objfile
));
9131 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9132 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9135 /* Make a union to hold the variants. */
9136 struct type
*union_type
= alloc_type (objfile
);
9137 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9138 TYPE_NFIELDS (union_type
) = 3;
9139 TYPE_FIELDS (union_type
)
9140 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9141 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9142 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9144 /* Put the discriminant must at index 0. */
9145 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9146 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9147 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9148 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9150 /* The order of fields doesn't really matter, so put the real
9151 field at index 1 and the data-less field at index 2. */
9152 struct discriminant_info
*disc
9153 = alloc_discriminant_info (union_type
, 0, 1);
9154 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9155 TYPE_FIELD_NAME (union_type
, 1)
9156 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9157 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9158 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9159 TYPE_FIELD_NAME (union_type
, 1));
9161 const char *dataless_name
9162 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9164 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9166 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9167 /* NAME points into the original discriminant name, which
9168 already has the correct lifetime. */
9169 TYPE_FIELD_NAME (union_type
, 2) = name
;
9170 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9171 disc
->discriminants
[2] = 0;
9173 /* Smash this type to be a structure type. We have to do this
9174 because the type has already been recorded. */
9175 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9176 TYPE_NFIELDS (type
) = 1;
9178 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9180 /* Install the variant part. */
9181 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9182 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9183 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9185 /* A union with a single anonymous field is probably an old-style
9187 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9189 /* Smash this type to be a structure type. We have to do this
9190 because the type has already been recorded. */
9191 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9193 /* Make a union to hold the variants. */
9194 struct type
*union_type
= alloc_type (objfile
);
9195 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9196 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9197 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9198 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9199 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9201 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9202 const char *variant_name
9203 = rust_last_path_segment (TYPE_NAME (field_type
));
9204 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9205 TYPE_NAME (field_type
)
9206 = rust_fully_qualify (&objfile
->objfile_obstack
,
9207 TYPE_NAME (type
), variant_name
);
9209 /* Install the union in the outer struct type. */
9210 TYPE_NFIELDS (type
) = 1;
9212 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9213 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9214 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9215 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9217 alloc_discriminant_info (union_type
, -1, 0);
9221 struct type
*disr_type
= nullptr;
9222 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9224 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9226 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9228 /* All fields of a true enum will be structs. */
9231 else if (TYPE_NFIELDS (disr_type
) == 0)
9233 /* Could be data-less variant, so keep going. */
9234 disr_type
= nullptr;
9236 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9237 "RUST$ENUM$DISR") != 0)
9239 /* Not a Rust enum. */
9249 /* If we got here without a discriminant, then it's probably
9251 if (disr_type
== nullptr)
9254 /* Smash this type to be a structure type. We have to do this
9255 because the type has already been recorded. */
9256 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9258 /* Make a union to hold the variants. */
9259 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9260 struct type
*union_type
= alloc_type (objfile
);
9261 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9262 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9263 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9264 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9265 TYPE_FIELDS (union_type
)
9266 = (struct field
*) TYPE_ZALLOC (union_type
,
9267 (TYPE_NFIELDS (union_type
)
9268 * sizeof (struct field
)));
9270 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9271 TYPE_NFIELDS (type
) * sizeof (struct field
));
9273 /* Install the discriminant at index 0 in the union. */
9274 TYPE_FIELD (union_type
, 0) = *disr_field
;
9275 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9276 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9278 /* Install the union in the outer struct type. */
9279 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9280 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9281 TYPE_NFIELDS (type
) = 1;
9283 /* Set the size and offset of the union type. */
9284 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9286 /* We need a way to find the correct discriminant given a
9287 variant name. For convenience we build a map here. */
9288 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9289 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9290 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9292 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9295 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9296 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9300 int n_fields
= TYPE_NFIELDS (union_type
);
9301 struct discriminant_info
*disc
9302 = alloc_discriminant_info (union_type
, 0, -1);
9303 /* Skip the discriminant here. */
9304 for (int i
= 1; i
< n_fields
; ++i
)
9306 /* Find the final word in the name of this variant's type.
9307 That name can be used to look up the correct
9309 const char *variant_name
9310 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9313 auto iter
= discriminant_map
.find (variant_name
);
9314 if (iter
!= discriminant_map
.end ())
9315 disc
->discriminants
[i
] = iter
->second
;
9317 /* Remove the discriminant field, if it exists. */
9318 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9319 if (TYPE_NFIELDS (sub_type
) > 0)
9321 --TYPE_NFIELDS (sub_type
);
9322 ++TYPE_FIELDS (sub_type
);
9324 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9325 TYPE_NAME (sub_type
)
9326 = rust_fully_qualify (&objfile
->objfile_obstack
,
9327 TYPE_NAME (type
), variant_name
);
9332 /* Rewrite some Rust unions to be structures with variants parts. */
9335 rust_union_quirks (struct dwarf2_cu
*cu
)
9337 gdb_assert (cu
->language
== language_rust
);
9338 for (type
*type_
: cu
->rust_unions
)
9339 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9340 /* We don't need this any more. */
9341 cu
->rust_unions
.clear ();
9344 /* Return the symtab for PER_CU. This works properly regardless of
9345 whether we're using the index or psymtabs. */
9347 static struct compunit_symtab
*
9348 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9350 return (per_cu
->dwarf2_per_objfile
->using_index
9351 ? per_cu
->v
.quick
->compunit_symtab
9352 : per_cu
->v
.psymtab
->compunit_symtab
);
9355 /* A helper function for computing the list of all symbol tables
9356 included by PER_CU. */
9359 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9360 htab_t all_children
, htab_t all_type_symtabs
,
9361 struct dwarf2_per_cu_data
*per_cu
,
9362 struct compunit_symtab
*immediate_parent
)
9365 struct compunit_symtab
*cust
;
9367 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9370 /* This inclusion and its children have been processed. */
9375 /* Only add a CU if it has a symbol table. */
9376 cust
= get_compunit_symtab (per_cu
);
9379 /* If this is a type unit only add its symbol table if we haven't
9380 seen it yet (type unit per_cu's can share symtabs). */
9381 if (per_cu
->is_debug_types
)
9383 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9387 result
->push_back (cust
);
9388 if (cust
->user
== NULL
)
9389 cust
->user
= immediate_parent
;
9394 result
->push_back (cust
);
9395 if (cust
->user
== NULL
)
9396 cust
->user
= immediate_parent
;
9400 if (!per_cu
->imported_symtabs_empty ())
9401 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9403 recursively_compute_inclusions (result
, all_children
,
9404 all_type_symtabs
, ptr
, cust
);
9408 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9412 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9414 gdb_assert (! per_cu
->is_debug_types
);
9416 if (!per_cu
->imported_symtabs_empty ())
9419 std::vector
<compunit_symtab
*> result_symtabs
;
9420 htab_t all_children
, all_type_symtabs
;
9421 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9423 /* If we don't have a symtab, we can just skip this case. */
9427 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9428 NULL
, xcalloc
, xfree
);
9429 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9430 NULL
, xcalloc
, xfree
);
9432 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9434 recursively_compute_inclusions (&result_symtabs
, all_children
,
9435 all_type_symtabs
, ptr
, cust
);
9438 /* Now we have a transitive closure of all the included symtabs. */
9439 len
= result_symtabs
.size ();
9441 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9442 struct compunit_symtab
*, len
+ 1);
9443 memcpy (cust
->includes
, result_symtabs
.data (),
9444 len
* sizeof (compunit_symtab
*));
9445 cust
->includes
[len
] = NULL
;
9447 htab_delete (all_children
);
9448 htab_delete (all_type_symtabs
);
9452 /* Compute the 'includes' field for the symtabs of all the CUs we just
9456 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9458 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9460 if (! iter
->is_debug_types
)
9461 compute_compunit_symtab_includes (iter
);
9464 dwarf2_per_objfile
->just_read_cus
.clear ();
9467 /* Generate full symbol information for PER_CU, whose DIEs have
9468 already been loaded into memory. */
9471 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9472 enum language pretend_language
)
9474 struct dwarf2_cu
*cu
= per_cu
->cu
;
9475 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9476 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9477 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9478 CORE_ADDR lowpc
, highpc
;
9479 struct compunit_symtab
*cust
;
9481 struct block
*static_block
;
9484 baseaddr
= objfile
->text_section_offset ();
9486 /* Clear the list here in case something was left over. */
9487 cu
->method_list
.clear ();
9489 cu
->language
= pretend_language
;
9490 cu
->language_defn
= language_def (cu
->language
);
9492 /* Do line number decoding in read_file_scope () */
9493 process_die (cu
->dies
, cu
);
9495 /* For now fudge the Go package. */
9496 if (cu
->language
== language_go
)
9497 fixup_go_packaging (cu
);
9499 /* Now that we have processed all the DIEs in the CU, all the types
9500 should be complete, and it should now be safe to compute all of the
9502 compute_delayed_physnames (cu
);
9504 if (cu
->language
== language_rust
)
9505 rust_union_quirks (cu
);
9507 /* Some compilers don't define a DW_AT_high_pc attribute for the
9508 compilation unit. If the DW_AT_high_pc is missing, synthesize
9509 it, by scanning the DIE's below the compilation unit. */
9510 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9512 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9513 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9515 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9516 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9517 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9518 addrmap to help ensure it has an accurate map of pc values belonging to
9520 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9522 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9523 SECT_OFF_TEXT (objfile
),
9528 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9530 /* Set symtab language to language from DW_AT_language. If the
9531 compilation is from a C file generated by language preprocessors, do
9532 not set the language if it was already deduced by start_subfile. */
9533 if (!(cu
->language
== language_c
9534 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9535 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9537 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9538 produce DW_AT_location with location lists but it can be possibly
9539 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9540 there were bugs in prologue debug info, fixed later in GCC-4.5
9541 by "unwind info for epilogues" patch (which is not directly related).
9543 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9544 needed, it would be wrong due to missing DW_AT_producer there.
9546 Still one can confuse GDB by using non-standard GCC compilation
9547 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9549 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9550 cust
->locations_valid
= 1;
9552 if (gcc_4_minor
>= 5)
9553 cust
->epilogue_unwind_valid
= 1;
9555 cust
->call_site_htab
= cu
->call_site_htab
;
9558 if (dwarf2_per_objfile
->using_index
)
9559 per_cu
->v
.quick
->compunit_symtab
= cust
;
9562 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9563 pst
->compunit_symtab
= cust
;
9567 /* Push it for inclusion processing later. */
9568 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9570 /* Not needed any more. */
9571 cu
->reset_builder ();
9574 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9575 already been loaded into memory. */
9578 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9579 enum language pretend_language
)
9581 struct dwarf2_cu
*cu
= per_cu
->cu
;
9582 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9584 struct compunit_symtab
*cust
;
9585 struct signatured_type
*sig_type
;
9587 gdb_assert (per_cu
->is_debug_types
);
9588 sig_type
= (struct signatured_type
*) per_cu
;
9590 /* Clear the list here in case something was left over. */
9591 cu
->method_list
.clear ();
9593 cu
->language
= pretend_language
;
9594 cu
->language_defn
= language_def (cu
->language
);
9596 /* The symbol tables are set up in read_type_unit_scope. */
9597 process_die (cu
->dies
, cu
);
9599 /* For now fudge the Go package. */
9600 if (cu
->language
== language_go
)
9601 fixup_go_packaging (cu
);
9603 /* Now that we have processed all the DIEs in the CU, all the types
9604 should be complete, and it should now be safe to compute all of the
9606 compute_delayed_physnames (cu
);
9608 if (cu
->language
== language_rust
)
9609 rust_union_quirks (cu
);
9611 /* TUs share symbol tables.
9612 If this is the first TU to use this symtab, complete the construction
9613 of it with end_expandable_symtab. Otherwise, complete the addition of
9614 this TU's symbols to the existing symtab. */
9615 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9617 buildsym_compunit
*builder
= cu
->get_builder ();
9618 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9619 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9623 /* Set symtab language to language from DW_AT_language. If the
9624 compilation is from a C file generated by language preprocessors,
9625 do not set the language if it was already deduced by
9627 if (!(cu
->language
== language_c
9628 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9629 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9634 cu
->get_builder ()->augment_type_symtab ();
9635 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9638 if (dwarf2_per_objfile
->using_index
)
9639 per_cu
->v
.quick
->compunit_symtab
= cust
;
9642 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9643 pst
->compunit_symtab
= cust
;
9647 /* Not needed any more. */
9648 cu
->reset_builder ();
9651 /* Process an imported unit DIE. */
9654 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9656 struct attribute
*attr
;
9658 /* For now we don't handle imported units in type units. */
9659 if (cu
->per_cu
->is_debug_types
)
9661 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9662 " supported in type units [in module %s]"),
9663 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9666 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9669 sect_offset sect_off
= attr
->get_ref_die_offset ();
9670 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9671 dwarf2_per_cu_data
*per_cu
9672 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9673 cu
->per_cu
->dwarf2_per_objfile
);
9675 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9676 into another compilation unit, at root level. Regard this as a hint,
9678 if (die
->parent
&& die
->parent
->parent
== NULL
9679 && per_cu
->unit_type
== DW_UT_compile
9680 && per_cu
->lang
== language_cplus
)
9683 /* If necessary, add it to the queue and load its DIEs. */
9684 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9685 load_full_comp_unit (per_cu
, false, cu
->language
);
9687 cu
->per_cu
->imported_symtabs_push (per_cu
);
9691 /* RAII object that represents a process_die scope: i.e.,
9692 starts/finishes processing a DIE. */
9693 class process_die_scope
9696 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9697 : m_die (die
), m_cu (cu
)
9699 /* We should only be processing DIEs not already in process. */
9700 gdb_assert (!m_die
->in_process
);
9701 m_die
->in_process
= true;
9704 ~process_die_scope ()
9706 m_die
->in_process
= false;
9708 /* If we're done processing the DIE for the CU that owns the line
9709 header, we don't need the line header anymore. */
9710 if (m_cu
->line_header_die_owner
== m_die
)
9712 delete m_cu
->line_header
;
9713 m_cu
->line_header
= NULL
;
9714 m_cu
->line_header_die_owner
= NULL
;
9723 /* Process a die and its children. */
9726 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9728 process_die_scope
scope (die
, cu
);
9732 case DW_TAG_padding
:
9734 case DW_TAG_compile_unit
:
9735 case DW_TAG_partial_unit
:
9736 read_file_scope (die
, cu
);
9738 case DW_TAG_type_unit
:
9739 read_type_unit_scope (die
, cu
);
9741 case DW_TAG_subprogram
:
9742 /* Nested subprograms in Fortran get a prefix. */
9743 if (cu
->language
== language_fortran
9744 && die
->parent
!= NULL
9745 && die
->parent
->tag
== DW_TAG_subprogram
)
9746 cu
->processing_has_namespace_info
= true;
9748 case DW_TAG_inlined_subroutine
:
9749 read_func_scope (die
, cu
);
9751 case DW_TAG_lexical_block
:
9752 case DW_TAG_try_block
:
9753 case DW_TAG_catch_block
:
9754 read_lexical_block_scope (die
, cu
);
9756 case DW_TAG_call_site
:
9757 case DW_TAG_GNU_call_site
:
9758 read_call_site_scope (die
, cu
);
9760 case DW_TAG_class_type
:
9761 case DW_TAG_interface_type
:
9762 case DW_TAG_structure_type
:
9763 case DW_TAG_union_type
:
9764 process_structure_scope (die
, cu
);
9766 case DW_TAG_enumeration_type
:
9767 process_enumeration_scope (die
, cu
);
9770 /* These dies have a type, but processing them does not create
9771 a symbol or recurse to process the children. Therefore we can
9772 read them on-demand through read_type_die. */
9773 case DW_TAG_subroutine_type
:
9774 case DW_TAG_set_type
:
9775 case DW_TAG_array_type
:
9776 case DW_TAG_pointer_type
:
9777 case DW_TAG_ptr_to_member_type
:
9778 case DW_TAG_reference_type
:
9779 case DW_TAG_rvalue_reference_type
:
9780 case DW_TAG_string_type
:
9783 case DW_TAG_base_type
:
9784 case DW_TAG_subrange_type
:
9785 case DW_TAG_typedef
:
9786 /* Add a typedef symbol for the type definition, if it has a
9788 new_symbol (die
, read_type_die (die
, cu
), cu
);
9790 case DW_TAG_common_block
:
9791 read_common_block (die
, cu
);
9793 case DW_TAG_common_inclusion
:
9795 case DW_TAG_namespace
:
9796 cu
->processing_has_namespace_info
= true;
9797 read_namespace (die
, cu
);
9800 cu
->processing_has_namespace_info
= true;
9801 read_module (die
, cu
);
9803 case DW_TAG_imported_declaration
:
9804 cu
->processing_has_namespace_info
= true;
9805 if (read_namespace_alias (die
, cu
))
9807 /* The declaration is not a global namespace alias. */
9809 case DW_TAG_imported_module
:
9810 cu
->processing_has_namespace_info
= true;
9811 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9812 || cu
->language
!= language_fortran
))
9813 complaint (_("Tag '%s' has unexpected children"),
9814 dwarf_tag_name (die
->tag
));
9815 read_import_statement (die
, cu
);
9818 case DW_TAG_imported_unit
:
9819 process_imported_unit_die (die
, cu
);
9822 case DW_TAG_variable
:
9823 read_variable (die
, cu
);
9827 new_symbol (die
, NULL
, cu
);
9832 /* DWARF name computation. */
9834 /* A helper function for dwarf2_compute_name which determines whether DIE
9835 needs to have the name of the scope prepended to the name listed in the
9839 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9841 struct attribute
*attr
;
9845 case DW_TAG_namespace
:
9846 case DW_TAG_typedef
:
9847 case DW_TAG_class_type
:
9848 case DW_TAG_interface_type
:
9849 case DW_TAG_structure_type
:
9850 case DW_TAG_union_type
:
9851 case DW_TAG_enumeration_type
:
9852 case DW_TAG_enumerator
:
9853 case DW_TAG_subprogram
:
9854 case DW_TAG_inlined_subroutine
:
9856 case DW_TAG_imported_declaration
:
9859 case DW_TAG_variable
:
9860 case DW_TAG_constant
:
9861 /* We only need to prefix "globally" visible variables. These include
9862 any variable marked with DW_AT_external or any variable that
9863 lives in a namespace. [Variables in anonymous namespaces
9864 require prefixing, but they are not DW_AT_external.] */
9866 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9868 struct dwarf2_cu
*spec_cu
= cu
;
9870 return die_needs_namespace (die_specification (die
, &spec_cu
),
9874 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9875 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9876 && die
->parent
->tag
!= DW_TAG_module
)
9878 /* A variable in a lexical block of some kind does not need a
9879 namespace, even though in C++ such variables may be external
9880 and have a mangled name. */
9881 if (die
->parent
->tag
== DW_TAG_lexical_block
9882 || die
->parent
->tag
== DW_TAG_try_block
9883 || die
->parent
->tag
== DW_TAG_catch_block
9884 || die
->parent
->tag
== DW_TAG_subprogram
)
9893 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9894 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9895 defined for the given DIE. */
9897 static struct attribute
*
9898 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9900 struct attribute
*attr
;
9902 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9904 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9909 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9910 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9911 defined for the given DIE. */
9914 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9916 const char *linkage_name
;
9918 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9919 if (linkage_name
== NULL
)
9920 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9922 return linkage_name
;
9925 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9926 compute the physname for the object, which include a method's:
9927 - formal parameters (C++),
9928 - receiver type (Go),
9930 The term "physname" is a bit confusing.
9931 For C++, for example, it is the demangled name.
9932 For Go, for example, it's the mangled name.
9934 For Ada, return the DIE's linkage name rather than the fully qualified
9935 name. PHYSNAME is ignored..
9937 The result is allocated on the objfile_obstack and canonicalized. */
9940 dwarf2_compute_name (const char *name
,
9941 struct die_info
*die
, struct dwarf2_cu
*cu
,
9944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9947 name
= dwarf2_name (die
, cu
);
9949 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9950 but otherwise compute it by typename_concat inside GDB.
9951 FIXME: Actually this is not really true, or at least not always true.
9952 It's all very confusing. compute_and_set_names doesn't try to demangle
9953 Fortran names because there is no mangling standard. So new_symbol
9954 will set the demangled name to the result of dwarf2_full_name, and it is
9955 the demangled name that GDB uses if it exists. */
9956 if (cu
->language
== language_ada
9957 || (cu
->language
== language_fortran
&& physname
))
9959 /* For Ada unit, we prefer the linkage name over the name, as
9960 the former contains the exported name, which the user expects
9961 to be able to reference. Ideally, we want the user to be able
9962 to reference this entity using either natural or linkage name,
9963 but we haven't started looking at this enhancement yet. */
9964 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9966 if (linkage_name
!= NULL
)
9967 return linkage_name
;
9970 /* These are the only languages we know how to qualify names in. */
9972 && (cu
->language
== language_cplus
9973 || cu
->language
== language_fortran
|| cu
->language
== language_d
9974 || cu
->language
== language_rust
))
9976 if (die_needs_namespace (die
, cu
))
9979 const char *canonical_name
= NULL
;
9983 prefix
= determine_prefix (die
, cu
);
9984 if (*prefix
!= '\0')
9986 gdb::unique_xmalloc_ptr
<char> prefixed_name
9987 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9989 buf
.puts (prefixed_name
.get ());
9994 /* Template parameters may be specified in the DIE's DW_AT_name, or
9995 as children with DW_TAG_template_type_param or
9996 DW_TAG_value_type_param. If the latter, add them to the name
9997 here. If the name already has template parameters, then
9998 skip this step; some versions of GCC emit both, and
9999 it is more efficient to use the pre-computed name.
10001 Something to keep in mind about this process: it is very
10002 unlikely, or in some cases downright impossible, to produce
10003 something that will match the mangled name of a function.
10004 If the definition of the function has the same debug info,
10005 we should be able to match up with it anyway. But fallbacks
10006 using the minimal symbol, for instance to find a method
10007 implemented in a stripped copy of libstdc++, will not work.
10008 If we do not have debug info for the definition, we will have to
10009 match them up some other way.
10011 When we do name matching there is a related problem with function
10012 templates; two instantiated function templates are allowed to
10013 differ only by their return types, which we do not add here. */
10015 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10017 struct attribute
*attr
;
10018 struct die_info
*child
;
10021 die
->building_fullname
= 1;
10023 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10027 const gdb_byte
*bytes
;
10028 struct dwarf2_locexpr_baton
*baton
;
10031 if (child
->tag
!= DW_TAG_template_type_param
10032 && child
->tag
!= DW_TAG_template_value_param
)
10043 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10046 complaint (_("template parameter missing DW_AT_type"));
10047 buf
.puts ("UNKNOWN_TYPE");
10050 type
= die_type (child
, cu
);
10052 if (child
->tag
== DW_TAG_template_type_param
)
10054 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10055 &type_print_raw_options
);
10059 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10062 complaint (_("template parameter missing "
10063 "DW_AT_const_value"));
10064 buf
.puts ("UNKNOWN_VALUE");
10068 dwarf2_const_value_attr (attr
, type
, name
,
10069 &cu
->comp_unit_obstack
, cu
,
10070 &value
, &bytes
, &baton
);
10072 if (TYPE_NOSIGN (type
))
10073 /* GDB prints characters as NUMBER 'CHAR'. If that's
10074 changed, this can use value_print instead. */
10075 c_printchar (value
, type
, &buf
);
10078 struct value_print_options opts
;
10081 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10085 else if (bytes
!= NULL
)
10087 v
= allocate_value (type
);
10088 memcpy (value_contents_writeable (v
), bytes
,
10089 TYPE_LENGTH (type
));
10092 v
= value_from_longest (type
, value
);
10094 /* Specify decimal so that we do not depend on
10096 get_formatted_print_options (&opts
, 'd');
10098 value_print (v
, &buf
, &opts
);
10103 die
->building_fullname
= 0;
10107 /* Close the argument list, with a space if necessary
10108 (nested templates). */
10109 if (!buf
.empty () && buf
.string ().back () == '>')
10116 /* For C++ methods, append formal parameter type
10117 information, if PHYSNAME. */
10119 if (physname
&& die
->tag
== DW_TAG_subprogram
10120 && cu
->language
== language_cplus
)
10122 struct type
*type
= read_type_die (die
, cu
);
10124 c_type_print_args (type
, &buf
, 1, cu
->language
,
10125 &type_print_raw_options
);
10127 if (cu
->language
== language_cplus
)
10129 /* Assume that an artificial first parameter is
10130 "this", but do not crash if it is not. RealView
10131 marks unnamed (and thus unused) parameters as
10132 artificial; there is no way to differentiate
10134 if (TYPE_NFIELDS (type
) > 0
10135 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10136 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10137 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10139 buf
.puts (" const");
10143 const std::string
&intermediate_name
= buf
.string ();
10145 if (cu
->language
== language_cplus
)
10147 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10150 /* If we only computed INTERMEDIATE_NAME, or if
10151 INTERMEDIATE_NAME is already canonical, then we need to
10153 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10154 name
= objfile
->intern (intermediate_name
);
10156 name
= canonical_name
;
10163 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10164 If scope qualifiers are appropriate they will be added. The result
10165 will be allocated on the storage_obstack, or NULL if the DIE does
10166 not have a name. NAME may either be from a previous call to
10167 dwarf2_name or NULL.
10169 The output string will be canonicalized (if C++). */
10171 static const char *
10172 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10174 return dwarf2_compute_name (name
, die
, cu
, 0);
10177 /* Construct a physname for the given DIE in CU. NAME may either be
10178 from a previous call to dwarf2_name or NULL. The result will be
10179 allocated on the objfile_objstack or NULL if the DIE does not have a
10182 The output string will be canonicalized (if C++). */
10184 static const char *
10185 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10187 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10188 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10191 /* In this case dwarf2_compute_name is just a shortcut not building anything
10193 if (!die_needs_namespace (die
, cu
))
10194 return dwarf2_compute_name (name
, die
, cu
, 1);
10196 mangled
= dw2_linkage_name (die
, cu
);
10198 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10199 See https://github.com/rust-lang/rust/issues/32925. */
10200 if (cu
->language
== language_rust
&& mangled
!= NULL
10201 && strchr (mangled
, '{') != NULL
)
10204 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10206 gdb::unique_xmalloc_ptr
<char> demangled
;
10207 if (mangled
!= NULL
)
10210 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10212 /* Do nothing (do not demangle the symbol name). */
10214 else if (cu
->language
== language_go
)
10216 /* This is a lie, but we already lie to the caller new_symbol.
10217 new_symbol assumes we return the mangled name.
10218 This just undoes that lie until things are cleaned up. */
10222 /* Use DMGL_RET_DROP for C++ template functions to suppress
10223 their return type. It is easier for GDB users to search
10224 for such functions as `name(params)' than `long name(params)'.
10225 In such case the minimal symbol names do not match the full
10226 symbol names but for template functions there is never a need
10227 to look up their definition from their declaration so
10228 the only disadvantage remains the minimal symbol variant
10229 `long name(params)' does not have the proper inferior type. */
10230 demangled
.reset (gdb_demangle (mangled
,
10231 (DMGL_PARAMS
| DMGL_ANSI
10232 | DMGL_RET_DROP
)));
10235 canon
= demangled
.get ();
10243 if (canon
== NULL
|| check_physname
)
10245 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10247 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10249 /* It may not mean a bug in GDB. The compiler could also
10250 compute DW_AT_linkage_name incorrectly. But in such case
10251 GDB would need to be bug-to-bug compatible. */
10253 complaint (_("Computed physname <%s> does not match demangled <%s> "
10254 "(from linkage <%s>) - DIE at %s [in module %s]"),
10255 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10256 objfile_name (objfile
));
10258 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10259 is available here - over computed PHYSNAME. It is safer
10260 against both buggy GDB and buggy compilers. */
10274 retval
= objfile
->intern (retval
);
10279 /* Inspect DIE in CU for a namespace alias. If one exists, record
10280 a new symbol for it.
10282 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10285 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10287 struct attribute
*attr
;
10289 /* If the die does not have a name, this is not a namespace
10291 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10295 struct die_info
*d
= die
;
10296 struct dwarf2_cu
*imported_cu
= cu
;
10298 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10299 keep inspecting DIEs until we hit the underlying import. */
10300 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10301 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10303 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10307 d
= follow_die_ref (d
, attr
, &imported_cu
);
10308 if (d
->tag
!= DW_TAG_imported_declaration
)
10312 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10314 complaint (_("DIE at %s has too many recursively imported "
10315 "declarations"), sect_offset_str (d
->sect_off
));
10322 sect_offset sect_off
= attr
->get_ref_die_offset ();
10324 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10325 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10327 /* This declaration is a global namespace alias. Add
10328 a symbol for it whose type is the aliased namespace. */
10329 new_symbol (die
, type
, cu
);
10338 /* Return the using directives repository (global or local?) to use in the
10339 current context for CU.
10341 For Ada, imported declarations can materialize renamings, which *may* be
10342 global. However it is impossible (for now?) in DWARF to distinguish
10343 "external" imported declarations and "static" ones. As all imported
10344 declarations seem to be static in all other languages, make them all CU-wide
10345 global only in Ada. */
10347 static struct using_direct
**
10348 using_directives (struct dwarf2_cu
*cu
)
10350 if (cu
->language
== language_ada
10351 && cu
->get_builder ()->outermost_context_p ())
10352 return cu
->get_builder ()->get_global_using_directives ();
10354 return cu
->get_builder ()->get_local_using_directives ();
10357 /* Read the import statement specified by the given die and record it. */
10360 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10362 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10363 struct attribute
*import_attr
;
10364 struct die_info
*imported_die
, *child_die
;
10365 struct dwarf2_cu
*imported_cu
;
10366 const char *imported_name
;
10367 const char *imported_name_prefix
;
10368 const char *canonical_name
;
10369 const char *import_alias
;
10370 const char *imported_declaration
= NULL
;
10371 const char *import_prefix
;
10372 std::vector
<const char *> excludes
;
10374 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10375 if (import_attr
== NULL
)
10377 complaint (_("Tag '%s' has no DW_AT_import"),
10378 dwarf_tag_name (die
->tag
));
10383 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10384 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10385 if (imported_name
== NULL
)
10387 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10389 The import in the following code:
10403 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10404 <52> DW_AT_decl_file : 1
10405 <53> DW_AT_decl_line : 6
10406 <54> DW_AT_import : <0x75>
10407 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10408 <59> DW_AT_name : B
10409 <5b> DW_AT_decl_file : 1
10410 <5c> DW_AT_decl_line : 2
10411 <5d> DW_AT_type : <0x6e>
10413 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10414 <76> DW_AT_byte_size : 4
10415 <77> DW_AT_encoding : 5 (signed)
10417 imports the wrong die ( 0x75 instead of 0x58 ).
10418 This case will be ignored until the gcc bug is fixed. */
10422 /* Figure out the local name after import. */
10423 import_alias
= dwarf2_name (die
, cu
);
10425 /* Figure out where the statement is being imported to. */
10426 import_prefix
= determine_prefix (die
, cu
);
10428 /* Figure out what the scope of the imported die is and prepend it
10429 to the name of the imported die. */
10430 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10432 if (imported_die
->tag
!= DW_TAG_namespace
10433 && imported_die
->tag
!= DW_TAG_module
)
10435 imported_declaration
= imported_name
;
10436 canonical_name
= imported_name_prefix
;
10438 else if (strlen (imported_name_prefix
) > 0)
10439 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10440 imported_name_prefix
,
10441 (cu
->language
== language_d
? "." : "::"),
10442 imported_name
, (char *) NULL
);
10444 canonical_name
= imported_name
;
10446 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10447 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10448 child_die
= child_die
->sibling
)
10450 /* DWARF-4: A Fortran use statement with a “rename list” may be
10451 represented by an imported module entry with an import attribute
10452 referring to the module and owned entries corresponding to those
10453 entities that are renamed as part of being imported. */
10455 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10457 complaint (_("child DW_TAG_imported_declaration expected "
10458 "- DIE at %s [in module %s]"),
10459 sect_offset_str (child_die
->sect_off
),
10460 objfile_name (objfile
));
10464 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10465 if (import_attr
== NULL
)
10467 complaint (_("Tag '%s' has no DW_AT_import"),
10468 dwarf_tag_name (child_die
->tag
));
10473 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10475 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10476 if (imported_name
== NULL
)
10478 complaint (_("child DW_TAG_imported_declaration has unknown "
10479 "imported name - DIE at %s [in module %s]"),
10480 sect_offset_str (child_die
->sect_off
),
10481 objfile_name (objfile
));
10485 excludes
.push_back (imported_name
);
10487 process_die (child_die
, cu
);
10490 add_using_directive (using_directives (cu
),
10494 imported_declaration
,
10497 &objfile
->objfile_obstack
);
10500 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10501 types, but gives them a size of zero. Starting with version 14,
10502 ICC is compatible with GCC. */
10505 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10507 if (!cu
->checked_producer
)
10508 check_producer (cu
);
10510 return cu
->producer_is_icc_lt_14
;
10513 /* ICC generates a DW_AT_type for C void functions. This was observed on
10514 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10515 which says that void functions should not have a DW_AT_type. */
10518 producer_is_icc (struct dwarf2_cu
*cu
)
10520 if (!cu
->checked_producer
)
10521 check_producer (cu
);
10523 return cu
->producer_is_icc
;
10526 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10527 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10528 this, it was first present in GCC release 4.3.0. */
10531 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10533 if (!cu
->checked_producer
)
10534 check_producer (cu
);
10536 return cu
->producer_is_gcc_lt_4_3
;
10539 static file_and_directory
10540 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10542 file_and_directory res
;
10544 /* Find the filename. Do not use dwarf2_name here, since the filename
10545 is not a source language identifier. */
10546 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10547 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10549 if (res
.comp_dir
== NULL
10550 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10551 && IS_ABSOLUTE_PATH (res
.name
))
10553 res
.comp_dir_storage
= ldirname (res
.name
);
10554 if (!res
.comp_dir_storage
.empty ())
10555 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10557 if (res
.comp_dir
!= NULL
)
10559 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10560 directory, get rid of it. */
10561 const char *cp
= strchr (res
.comp_dir
, ':');
10563 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10564 res
.comp_dir
= cp
+ 1;
10567 if (res
.name
== NULL
)
10568 res
.name
= "<unknown>";
10573 /* Handle DW_AT_stmt_list for a compilation unit.
10574 DIE is the DW_TAG_compile_unit die for CU.
10575 COMP_DIR is the compilation directory. LOWPC is passed to
10576 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10579 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10580 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10582 struct dwarf2_per_objfile
*dwarf2_per_objfile
10583 = cu
->per_cu
->dwarf2_per_objfile
;
10584 struct attribute
*attr
;
10585 struct line_header line_header_local
;
10586 hashval_t line_header_local_hash
;
10588 int decode_mapping
;
10590 gdb_assert (! cu
->per_cu
->is_debug_types
);
10592 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10596 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10598 /* The line header hash table is only created if needed (it exists to
10599 prevent redundant reading of the line table for partial_units).
10600 If we're given a partial_unit, we'll need it. If we're given a
10601 compile_unit, then use the line header hash table if it's already
10602 created, but don't create one just yet. */
10604 if (dwarf2_per_objfile
->line_header_hash
== NULL
10605 && die
->tag
== DW_TAG_partial_unit
)
10607 dwarf2_per_objfile
->line_header_hash
10608 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10609 line_header_eq_voidp
,
10610 free_line_header_voidp
,
10614 line_header_local
.sect_off
= line_offset
;
10615 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10616 line_header_local_hash
= line_header_hash (&line_header_local
);
10617 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10619 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10620 &line_header_local
,
10621 line_header_local_hash
, NO_INSERT
);
10623 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10624 is not present in *SLOT (since if there is something in *SLOT then
10625 it will be for a partial_unit). */
10626 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10628 gdb_assert (*slot
!= NULL
);
10629 cu
->line_header
= (struct line_header
*) *slot
;
10634 /* dwarf_decode_line_header does not yet provide sufficient information.
10635 We always have to call also dwarf_decode_lines for it. */
10636 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10640 cu
->line_header
= lh
.release ();
10641 cu
->line_header_die_owner
= die
;
10643 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10647 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10648 &line_header_local
,
10649 line_header_local_hash
, INSERT
);
10650 gdb_assert (slot
!= NULL
);
10652 if (slot
!= NULL
&& *slot
== NULL
)
10654 /* This newly decoded line number information unit will be owned
10655 by line_header_hash hash table. */
10656 *slot
= cu
->line_header
;
10657 cu
->line_header_die_owner
= NULL
;
10661 /* We cannot free any current entry in (*slot) as that struct line_header
10662 may be already used by multiple CUs. Create only temporary decoded
10663 line_header for this CU - it may happen at most once for each line
10664 number information unit. And if we're not using line_header_hash
10665 then this is what we want as well. */
10666 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10668 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10669 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10674 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10677 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10679 struct dwarf2_per_objfile
*dwarf2_per_objfile
10680 = cu
->per_cu
->dwarf2_per_objfile
;
10681 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10682 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10683 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10684 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10685 struct attribute
*attr
;
10686 struct die_info
*child_die
;
10687 CORE_ADDR baseaddr
;
10689 prepare_one_comp_unit (cu
, die
, cu
->language
);
10690 baseaddr
= objfile
->text_section_offset ();
10692 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10694 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10695 from finish_block. */
10696 if (lowpc
== ((CORE_ADDR
) -1))
10698 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10700 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10702 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10703 standardised yet. As a workaround for the language detection we fall
10704 back to the DW_AT_producer string. */
10705 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10706 cu
->language
= language_opencl
;
10708 /* Similar hack for Go. */
10709 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10710 set_cu_language (DW_LANG_Go
, cu
);
10712 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10714 /* Decode line number information if present. We do this before
10715 processing child DIEs, so that the line header table is available
10716 for DW_AT_decl_file. */
10717 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10719 /* Process all dies in compilation unit. */
10720 if (die
->child
!= NULL
)
10722 child_die
= die
->child
;
10723 while (child_die
&& child_die
->tag
)
10725 process_die (child_die
, cu
);
10726 child_die
= child_die
->sibling
;
10730 /* Decode macro information, if present. Dwarf 2 macro information
10731 refers to information in the line number info statement program
10732 header, so we can only read it if we've read the header
10734 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10736 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10737 if (attr
&& cu
->line_header
)
10739 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10740 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10742 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10746 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10747 if (attr
&& cu
->line_header
)
10749 unsigned int macro_offset
= DW_UNSND (attr
);
10751 dwarf_decode_macros (cu
, macro_offset
, 0);
10757 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10759 struct type_unit_group
*tu_group
;
10761 struct attribute
*attr
;
10763 struct signatured_type
*sig_type
;
10765 gdb_assert (per_cu
->is_debug_types
);
10766 sig_type
= (struct signatured_type
*) per_cu
;
10768 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10770 /* If we're using .gdb_index (includes -readnow) then
10771 per_cu->type_unit_group may not have been set up yet. */
10772 if (sig_type
->type_unit_group
== NULL
)
10773 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10774 tu_group
= sig_type
->type_unit_group
;
10776 /* If we've already processed this stmt_list there's no real need to
10777 do it again, we could fake it and just recreate the part we need
10778 (file name,index -> symtab mapping). If data shows this optimization
10779 is useful we can do it then. */
10780 first_time
= tu_group
->compunit_symtab
== NULL
;
10782 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10787 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10788 lh
= dwarf_decode_line_header (line_offset
, this);
10793 start_symtab ("", NULL
, 0);
10796 gdb_assert (tu_group
->symtabs
== NULL
);
10797 gdb_assert (m_builder
== nullptr);
10798 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10799 m_builder
.reset (new struct buildsym_compunit
10800 (COMPUNIT_OBJFILE (cust
), "",
10801 COMPUNIT_DIRNAME (cust
),
10802 compunit_language (cust
),
10808 line_header
= lh
.release ();
10809 line_header_die_owner
= die
;
10813 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10815 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10816 still initializing it, and our caller (a few levels up)
10817 process_full_type_unit still needs to know if this is the first
10821 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10822 struct symtab
*, line_header
->file_names_size ());
10824 auto &file_names
= line_header
->file_names ();
10825 for (i
= 0; i
< file_names
.size (); ++i
)
10827 file_entry
&fe
= file_names
[i
];
10828 dwarf2_start_subfile (this, fe
.name
,
10829 fe
.include_dir (line_header
));
10830 buildsym_compunit
*b
= get_builder ();
10831 if (b
->get_current_subfile ()->symtab
== NULL
)
10833 /* NOTE: start_subfile will recognize when it's been
10834 passed a file it has already seen. So we can't
10835 assume there's a simple mapping from
10836 cu->line_header->file_names to subfiles, plus
10837 cu->line_header->file_names may contain dups. */
10838 b
->get_current_subfile ()->symtab
10839 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10842 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10843 tu_group
->symtabs
[i
] = fe
.symtab
;
10848 gdb_assert (m_builder
== nullptr);
10849 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10850 m_builder
.reset (new struct buildsym_compunit
10851 (COMPUNIT_OBJFILE (cust
), "",
10852 COMPUNIT_DIRNAME (cust
),
10853 compunit_language (cust
),
10856 auto &file_names
= line_header
->file_names ();
10857 for (i
= 0; i
< file_names
.size (); ++i
)
10859 file_entry
&fe
= file_names
[i
];
10860 fe
.symtab
= tu_group
->symtabs
[i
];
10864 /* The main symtab is allocated last. Type units don't have DW_AT_name
10865 so they don't have a "real" (so to speak) symtab anyway.
10866 There is later code that will assign the main symtab to all symbols
10867 that don't have one. We need to handle the case of a symbol with a
10868 missing symtab (DW_AT_decl_file) anyway. */
10871 /* Process DW_TAG_type_unit.
10872 For TUs we want to skip the first top level sibling if it's not the
10873 actual type being defined by this TU. In this case the first top
10874 level sibling is there to provide context only. */
10877 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10879 struct die_info
*child_die
;
10881 prepare_one_comp_unit (cu
, die
, language_minimal
);
10883 /* Initialize (or reinitialize) the machinery for building symtabs.
10884 We do this before processing child DIEs, so that the line header table
10885 is available for DW_AT_decl_file. */
10886 cu
->setup_type_unit_groups (die
);
10888 if (die
->child
!= NULL
)
10890 child_die
= die
->child
;
10891 while (child_die
&& child_die
->tag
)
10893 process_die (child_die
, cu
);
10894 child_die
= child_die
->sibling
;
10901 http://gcc.gnu.org/wiki/DebugFission
10902 http://gcc.gnu.org/wiki/DebugFissionDWP
10904 To simplify handling of both DWO files ("object" files with the DWARF info)
10905 and DWP files (a file with the DWOs packaged up into one file), we treat
10906 DWP files as having a collection of virtual DWO files. */
10909 hash_dwo_file (const void *item
)
10911 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10914 hash
= htab_hash_string (dwo_file
->dwo_name
);
10915 if (dwo_file
->comp_dir
!= NULL
)
10916 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10921 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10923 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10924 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10926 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10928 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10929 return lhs
->comp_dir
== rhs
->comp_dir
;
10930 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10933 /* Allocate a hash table for DWO files. */
10936 allocate_dwo_file_hash_table ()
10938 auto delete_dwo_file
= [] (void *item
)
10940 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10945 return htab_up (htab_create_alloc (41,
10952 /* Lookup DWO file DWO_NAME. */
10955 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10956 const char *dwo_name
,
10957 const char *comp_dir
)
10959 struct dwo_file find_entry
;
10962 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10963 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10965 find_entry
.dwo_name
= dwo_name
;
10966 find_entry
.comp_dir
= comp_dir
;
10967 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10974 hash_dwo_unit (const void *item
)
10976 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10978 /* This drops the top 32 bits of the id, but is ok for a hash. */
10979 return dwo_unit
->signature
;
10983 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10985 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10986 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10988 /* The signature is assumed to be unique within the DWO file.
10989 So while object file CU dwo_id's always have the value zero,
10990 that's OK, assuming each object file DWO file has only one CU,
10991 and that's the rule for now. */
10992 return lhs
->signature
== rhs
->signature
;
10995 /* Allocate a hash table for DWO CUs,TUs.
10996 There is one of these tables for each of CUs,TUs for each DWO file. */
10999 allocate_dwo_unit_table ()
11001 /* Start out with a pretty small number.
11002 Generally DWO files contain only one CU and maybe some TUs. */
11003 return htab_up (htab_create_alloc (3,
11006 NULL
, xcalloc
, xfree
));
11009 /* die_reader_func for create_dwo_cu. */
11012 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11013 const gdb_byte
*info_ptr
,
11014 struct die_info
*comp_unit_die
,
11015 struct dwo_file
*dwo_file
,
11016 struct dwo_unit
*dwo_unit
)
11018 struct dwarf2_cu
*cu
= reader
->cu
;
11019 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11020 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11022 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11023 if (!signature
.has_value ())
11025 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11026 " its dwo_id [in module %s]"),
11027 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11031 dwo_unit
->dwo_file
= dwo_file
;
11032 dwo_unit
->signature
= *signature
;
11033 dwo_unit
->section
= section
;
11034 dwo_unit
->sect_off
= sect_off
;
11035 dwo_unit
->length
= cu
->per_cu
->length
;
11037 if (dwarf_read_debug
)
11038 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11039 sect_offset_str (sect_off
),
11040 hex_string (dwo_unit
->signature
));
11043 /* Create the dwo_units for the CUs in a DWO_FILE.
11044 Note: This function processes DWO files only, not DWP files. */
11047 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11048 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11049 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11051 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11052 const gdb_byte
*info_ptr
, *end_ptr
;
11054 section
.read (objfile
);
11055 info_ptr
= section
.buffer
;
11057 if (info_ptr
== NULL
)
11060 if (dwarf_read_debug
)
11062 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11063 section
.get_name (),
11064 section
.get_file_name ());
11067 end_ptr
= info_ptr
+ section
.size
;
11068 while (info_ptr
< end_ptr
)
11070 struct dwarf2_per_cu_data per_cu
;
11071 struct dwo_unit read_unit
{};
11072 struct dwo_unit
*dwo_unit
;
11074 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11076 memset (&per_cu
, 0, sizeof (per_cu
));
11077 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11078 per_cu
.is_debug_types
= 0;
11079 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11080 per_cu
.section
= §ion
;
11082 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11083 if (!reader
.dummy_p
)
11084 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11085 &dwo_file
, &read_unit
);
11086 info_ptr
+= per_cu
.length
;
11088 // If the unit could not be parsed, skip it.
11089 if (read_unit
.dwo_file
== NULL
)
11092 if (cus_htab
== NULL
)
11093 cus_htab
= allocate_dwo_unit_table ();
11095 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11096 *dwo_unit
= read_unit
;
11097 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11098 gdb_assert (slot
!= NULL
);
11101 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11102 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11104 complaint (_("debug cu entry at offset %s is duplicate to"
11105 " the entry at offset %s, signature %s"),
11106 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11107 hex_string (dwo_unit
->signature
));
11109 *slot
= (void *)dwo_unit
;
11113 /* DWP file .debug_{cu,tu}_index section format:
11114 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11118 Both index sections have the same format, and serve to map a 64-bit
11119 signature to a set of section numbers. Each section begins with a header,
11120 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11121 indexes, and a pool of 32-bit section numbers. The index sections will be
11122 aligned at 8-byte boundaries in the file.
11124 The index section header consists of:
11126 V, 32 bit version number
11128 N, 32 bit number of compilation units or type units in the index
11129 M, 32 bit number of slots in the hash table
11131 Numbers are recorded using the byte order of the application binary.
11133 The hash table begins at offset 16 in the section, and consists of an array
11134 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11135 order of the application binary). Unused slots in the hash table are 0.
11136 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11138 The parallel table begins immediately after the hash table
11139 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11140 array of 32-bit indexes (using the byte order of the application binary),
11141 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11142 table contains a 32-bit index into the pool of section numbers. For unused
11143 hash table slots, the corresponding entry in the parallel table will be 0.
11145 The pool of section numbers begins immediately following the hash table
11146 (at offset 16 + 12 * M from the beginning of the section). The pool of
11147 section numbers consists of an array of 32-bit words (using the byte order
11148 of the application binary). Each item in the array is indexed starting
11149 from 0. The hash table entry provides the index of the first section
11150 number in the set. Additional section numbers in the set follow, and the
11151 set is terminated by a 0 entry (section number 0 is not used in ELF).
11153 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11154 section must be the first entry in the set, and the .debug_abbrev.dwo must
11155 be the second entry. Other members of the set may follow in any order.
11161 DWP Version 2 combines all the .debug_info, etc. sections into one,
11162 and the entries in the index tables are now offsets into these sections.
11163 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11166 Index Section Contents:
11168 Hash Table of Signatures dwp_hash_table.hash_table
11169 Parallel Table of Indices dwp_hash_table.unit_table
11170 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11171 Table of Section Sizes dwp_hash_table.v2.sizes
11173 The index section header consists of:
11175 V, 32 bit version number
11176 L, 32 bit number of columns in the table of section offsets
11177 N, 32 bit number of compilation units or type units in the index
11178 M, 32 bit number of slots in the hash table
11180 Numbers are recorded using the byte order of the application binary.
11182 The hash table has the same format as version 1.
11183 The parallel table of indices has the same format as version 1,
11184 except that the entries are origin-1 indices into the table of sections
11185 offsets and the table of section sizes.
11187 The table of offsets begins immediately following the parallel table
11188 (at offset 16 + 12 * M from the beginning of the section). The table is
11189 a two-dimensional array of 32-bit words (using the byte order of the
11190 application binary), with L columns and N+1 rows, in row-major order.
11191 Each row in the array is indexed starting from 0. The first row provides
11192 a key to the remaining rows: each column in this row provides an identifier
11193 for a debug section, and the offsets in the same column of subsequent rows
11194 refer to that section. The section identifiers are:
11196 DW_SECT_INFO 1 .debug_info.dwo
11197 DW_SECT_TYPES 2 .debug_types.dwo
11198 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11199 DW_SECT_LINE 4 .debug_line.dwo
11200 DW_SECT_LOC 5 .debug_loc.dwo
11201 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11202 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11203 DW_SECT_MACRO 8 .debug_macro.dwo
11205 The offsets provided by the CU and TU index sections are the base offsets
11206 for the contributions made by each CU or TU to the corresponding section
11207 in the package file. Each CU and TU header contains an abbrev_offset
11208 field, used to find the abbreviations table for that CU or TU within the
11209 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11210 be interpreted as relative to the base offset given in the index section.
11211 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11212 should be interpreted as relative to the base offset for .debug_line.dwo,
11213 and offsets into other debug sections obtained from DWARF attributes should
11214 also be interpreted as relative to the corresponding base offset.
11216 The table of sizes begins immediately following the table of offsets.
11217 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11218 with L columns and N rows, in row-major order. Each row in the array is
11219 indexed starting from 1 (row 0 is shared by the two tables).
11223 Hash table lookup is handled the same in version 1 and 2:
11225 We assume that N and M will not exceed 2^32 - 1.
11226 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11228 Given a 64-bit compilation unit signature or a type signature S, an entry
11229 in the hash table is located as follows:
11231 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11232 the low-order k bits all set to 1.
11234 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11236 3) If the hash table entry at index H matches the signature, use that
11237 entry. If the hash table entry at index H is unused (all zeroes),
11238 terminate the search: the signature is not present in the table.
11240 4) Let H = (H + H') modulo M. Repeat at Step 3.
11242 Because M > N and H' and M are relatively prime, the search is guaranteed
11243 to stop at an unused slot or find the match. */
11245 /* Create a hash table to map DWO IDs to their CU/TU entry in
11246 .debug_{info,types}.dwo in DWP_FILE.
11247 Returns NULL if there isn't one.
11248 Note: This function processes DWP files only, not DWO files. */
11250 static struct dwp_hash_table
*
11251 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11252 struct dwp_file
*dwp_file
, int is_debug_types
)
11254 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11255 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11256 const gdb_byte
*index_ptr
, *index_end
;
11257 struct dwarf2_section_info
*index
;
11258 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11259 struct dwp_hash_table
*htab
;
11261 if (is_debug_types
)
11262 index
= &dwp_file
->sections
.tu_index
;
11264 index
= &dwp_file
->sections
.cu_index
;
11266 if (index
->empty ())
11268 index
->read (objfile
);
11270 index_ptr
= index
->buffer
;
11271 index_end
= index_ptr
+ index
->size
;
11273 version
= read_4_bytes (dbfd
, index_ptr
);
11276 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11280 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11282 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11285 if (version
!= 1 && version
!= 2)
11287 error (_("Dwarf Error: unsupported DWP file version (%s)"
11288 " [in module %s]"),
11289 pulongest (version
), dwp_file
->name
);
11291 if (nr_slots
!= (nr_slots
& -nr_slots
))
11293 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11294 " is not power of 2 [in module %s]"),
11295 pulongest (nr_slots
), dwp_file
->name
);
11298 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11299 htab
->version
= version
;
11300 htab
->nr_columns
= nr_columns
;
11301 htab
->nr_units
= nr_units
;
11302 htab
->nr_slots
= nr_slots
;
11303 htab
->hash_table
= index_ptr
;
11304 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11306 /* Exit early if the table is empty. */
11307 if (nr_slots
== 0 || nr_units
== 0
11308 || (version
== 2 && nr_columns
== 0))
11310 /* All must be zero. */
11311 if (nr_slots
!= 0 || nr_units
!= 0
11312 || (version
== 2 && nr_columns
!= 0))
11314 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11315 " all zero [in modules %s]"),
11323 htab
->section_pool
.v1
.indices
=
11324 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11325 /* It's harder to decide whether the section is too small in v1.
11326 V1 is deprecated anyway so we punt. */
11330 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11331 int *ids
= htab
->section_pool
.v2
.section_ids
;
11332 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11333 /* Reverse map for error checking. */
11334 int ids_seen
[DW_SECT_MAX
+ 1];
11337 if (nr_columns
< 2)
11339 error (_("Dwarf Error: bad DWP hash table, too few columns"
11340 " in section table [in module %s]"),
11343 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11345 error (_("Dwarf Error: bad DWP hash table, too many columns"
11346 " in section table [in module %s]"),
11349 memset (ids
, 255, sizeof_ids
);
11350 memset (ids_seen
, 255, sizeof (ids_seen
));
11351 for (i
= 0; i
< nr_columns
; ++i
)
11353 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11355 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11357 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11358 " in section table [in module %s]"),
11359 id
, dwp_file
->name
);
11361 if (ids_seen
[id
] != -1)
11363 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11364 " id %d in section table [in module %s]"),
11365 id
, dwp_file
->name
);
11370 /* Must have exactly one info or types section. */
11371 if (((ids_seen
[DW_SECT_INFO
] != -1)
11372 + (ids_seen
[DW_SECT_TYPES
] != -1))
11375 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11376 " DWO info/types section [in module %s]"),
11379 /* Must have an abbrev section. */
11380 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11382 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11383 " section [in module %s]"),
11386 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11387 htab
->section_pool
.v2
.sizes
=
11388 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11389 * nr_units
* nr_columns
);
11390 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11391 * nr_units
* nr_columns
))
11394 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11395 " [in module %s]"),
11403 /* Update SECTIONS with the data from SECTP.
11405 This function is like the other "locate" section routines that are
11406 passed to bfd_map_over_sections, but in this context the sections to
11407 read comes from the DWP V1 hash table, not the full ELF section table.
11409 The result is non-zero for success, or zero if an error was found. */
11412 locate_v1_virtual_dwo_sections (asection
*sectp
,
11413 struct virtual_v1_dwo_sections
*sections
)
11415 const struct dwop_section_names
*names
= &dwop_section_names
;
11417 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11419 /* There can be only one. */
11420 if (sections
->abbrev
.s
.section
!= NULL
)
11422 sections
->abbrev
.s
.section
= sectp
;
11423 sections
->abbrev
.size
= bfd_section_size (sectp
);
11425 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11426 || section_is_p (sectp
->name
, &names
->types_dwo
))
11428 /* There can be only one. */
11429 if (sections
->info_or_types
.s
.section
!= NULL
)
11431 sections
->info_or_types
.s
.section
= sectp
;
11432 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11434 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11436 /* There can be only one. */
11437 if (sections
->line
.s
.section
!= NULL
)
11439 sections
->line
.s
.section
= sectp
;
11440 sections
->line
.size
= bfd_section_size (sectp
);
11442 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11444 /* There can be only one. */
11445 if (sections
->loc
.s
.section
!= NULL
)
11447 sections
->loc
.s
.section
= sectp
;
11448 sections
->loc
.size
= bfd_section_size (sectp
);
11450 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11452 /* There can be only one. */
11453 if (sections
->macinfo
.s
.section
!= NULL
)
11455 sections
->macinfo
.s
.section
= sectp
;
11456 sections
->macinfo
.size
= bfd_section_size (sectp
);
11458 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11460 /* There can be only one. */
11461 if (sections
->macro
.s
.section
!= NULL
)
11463 sections
->macro
.s
.section
= sectp
;
11464 sections
->macro
.size
= bfd_section_size (sectp
);
11466 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11468 /* There can be only one. */
11469 if (sections
->str_offsets
.s
.section
!= NULL
)
11471 sections
->str_offsets
.s
.section
= sectp
;
11472 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11476 /* No other kind of section is valid. */
11483 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11484 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11485 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11486 This is for DWP version 1 files. */
11488 static struct dwo_unit
*
11489 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11490 struct dwp_file
*dwp_file
,
11491 uint32_t unit_index
,
11492 const char *comp_dir
,
11493 ULONGEST signature
, int is_debug_types
)
11495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11496 const struct dwp_hash_table
*dwp_htab
=
11497 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11498 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11499 const char *kind
= is_debug_types
? "TU" : "CU";
11500 struct dwo_file
*dwo_file
;
11501 struct dwo_unit
*dwo_unit
;
11502 struct virtual_v1_dwo_sections sections
;
11503 void **dwo_file_slot
;
11506 gdb_assert (dwp_file
->version
== 1);
11508 if (dwarf_read_debug
)
11510 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11512 pulongest (unit_index
), hex_string (signature
),
11516 /* Fetch the sections of this DWO unit.
11517 Put a limit on the number of sections we look for so that bad data
11518 doesn't cause us to loop forever. */
11520 #define MAX_NR_V1_DWO_SECTIONS \
11521 (1 /* .debug_info or .debug_types */ \
11522 + 1 /* .debug_abbrev */ \
11523 + 1 /* .debug_line */ \
11524 + 1 /* .debug_loc */ \
11525 + 1 /* .debug_str_offsets */ \
11526 + 1 /* .debug_macro or .debug_macinfo */ \
11527 + 1 /* trailing zero */)
11529 memset (§ions
, 0, sizeof (sections
));
11531 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11534 uint32_t section_nr
=
11535 read_4_bytes (dbfd
,
11536 dwp_htab
->section_pool
.v1
.indices
11537 + (unit_index
+ i
) * sizeof (uint32_t));
11539 if (section_nr
== 0)
11541 if (section_nr
>= dwp_file
->num_sections
)
11543 error (_("Dwarf Error: bad DWP hash table, section number too large"
11544 " [in module %s]"),
11548 sectp
= dwp_file
->elf_sections
[section_nr
];
11549 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11551 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11552 " [in module %s]"),
11558 || sections
.info_or_types
.empty ()
11559 || sections
.abbrev
.empty ())
11561 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11562 " [in module %s]"),
11565 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11567 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11568 " [in module %s]"),
11572 /* It's easier for the rest of the code if we fake a struct dwo_file and
11573 have dwo_unit "live" in that. At least for now.
11575 The DWP file can be made up of a random collection of CUs and TUs.
11576 However, for each CU + set of TUs that came from the same original DWO
11577 file, we can combine them back into a virtual DWO file to save space
11578 (fewer struct dwo_file objects to allocate). Remember that for really
11579 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11581 std::string virtual_dwo_name
=
11582 string_printf ("virtual-dwo/%d-%d-%d-%d",
11583 sections
.abbrev
.get_id (),
11584 sections
.line
.get_id (),
11585 sections
.loc
.get_id (),
11586 sections
.str_offsets
.get_id ());
11587 /* Can we use an existing virtual DWO file? */
11588 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11589 virtual_dwo_name
.c_str (),
11591 /* Create one if necessary. */
11592 if (*dwo_file_slot
== NULL
)
11594 if (dwarf_read_debug
)
11596 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11597 virtual_dwo_name
.c_str ());
11599 dwo_file
= new struct dwo_file
;
11600 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11601 dwo_file
->comp_dir
= comp_dir
;
11602 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11603 dwo_file
->sections
.line
= sections
.line
;
11604 dwo_file
->sections
.loc
= sections
.loc
;
11605 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11606 dwo_file
->sections
.macro
= sections
.macro
;
11607 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11608 /* The "str" section is global to the entire DWP file. */
11609 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11610 /* The info or types section is assigned below to dwo_unit,
11611 there's no need to record it in dwo_file.
11612 Also, we can't simply record type sections in dwo_file because
11613 we record a pointer into the vector in dwo_unit. As we collect more
11614 types we'll grow the vector and eventually have to reallocate space
11615 for it, invalidating all copies of pointers into the previous
11617 *dwo_file_slot
= dwo_file
;
11621 if (dwarf_read_debug
)
11623 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11624 virtual_dwo_name
.c_str ());
11626 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11629 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11630 dwo_unit
->dwo_file
= dwo_file
;
11631 dwo_unit
->signature
= signature
;
11632 dwo_unit
->section
=
11633 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11634 *dwo_unit
->section
= sections
.info_or_types
;
11635 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11640 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11641 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11642 piece within that section used by a TU/CU, return a virtual section
11643 of just that piece. */
11645 static struct dwarf2_section_info
11646 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11647 struct dwarf2_section_info
*section
,
11648 bfd_size_type offset
, bfd_size_type size
)
11650 struct dwarf2_section_info result
;
11653 gdb_assert (section
!= NULL
);
11654 gdb_assert (!section
->is_virtual
);
11656 memset (&result
, 0, sizeof (result
));
11657 result
.s
.containing_section
= section
;
11658 result
.is_virtual
= true;
11663 sectp
= section
->get_bfd_section ();
11665 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11666 bounds of the real section. This is a pretty-rare event, so just
11667 flag an error (easier) instead of a warning and trying to cope. */
11669 || offset
+ size
> bfd_section_size (sectp
))
11671 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11672 " in section %s [in module %s]"),
11673 sectp
? bfd_section_name (sectp
) : "<unknown>",
11674 objfile_name (dwarf2_per_objfile
->objfile
));
11677 result
.virtual_offset
= offset
;
11678 result
.size
= size
;
11682 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11683 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11684 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11685 This is for DWP version 2 files. */
11687 static struct dwo_unit
*
11688 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11689 struct dwp_file
*dwp_file
,
11690 uint32_t unit_index
,
11691 const char *comp_dir
,
11692 ULONGEST signature
, int is_debug_types
)
11694 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11695 const struct dwp_hash_table
*dwp_htab
=
11696 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11697 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11698 const char *kind
= is_debug_types
? "TU" : "CU";
11699 struct dwo_file
*dwo_file
;
11700 struct dwo_unit
*dwo_unit
;
11701 struct virtual_v2_dwo_sections sections
;
11702 void **dwo_file_slot
;
11705 gdb_assert (dwp_file
->version
== 2);
11707 if (dwarf_read_debug
)
11709 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11711 pulongest (unit_index
), hex_string (signature
),
11715 /* Fetch the section offsets of this DWO unit. */
11717 memset (§ions
, 0, sizeof (sections
));
11719 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11721 uint32_t offset
= read_4_bytes (dbfd
,
11722 dwp_htab
->section_pool
.v2
.offsets
11723 + (((unit_index
- 1) * dwp_htab
->nr_columns
11725 * sizeof (uint32_t)));
11726 uint32_t size
= read_4_bytes (dbfd
,
11727 dwp_htab
->section_pool
.v2
.sizes
11728 + (((unit_index
- 1) * dwp_htab
->nr_columns
11730 * sizeof (uint32_t)));
11732 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11735 case DW_SECT_TYPES
:
11736 sections
.info_or_types_offset
= offset
;
11737 sections
.info_or_types_size
= size
;
11739 case DW_SECT_ABBREV
:
11740 sections
.abbrev_offset
= offset
;
11741 sections
.abbrev_size
= size
;
11744 sections
.line_offset
= offset
;
11745 sections
.line_size
= size
;
11748 sections
.loc_offset
= offset
;
11749 sections
.loc_size
= size
;
11751 case DW_SECT_STR_OFFSETS
:
11752 sections
.str_offsets_offset
= offset
;
11753 sections
.str_offsets_size
= size
;
11755 case DW_SECT_MACINFO
:
11756 sections
.macinfo_offset
= offset
;
11757 sections
.macinfo_size
= size
;
11759 case DW_SECT_MACRO
:
11760 sections
.macro_offset
= offset
;
11761 sections
.macro_size
= size
;
11766 /* It's easier for the rest of the code if we fake a struct dwo_file and
11767 have dwo_unit "live" in that. At least for now.
11769 The DWP file can be made up of a random collection of CUs and TUs.
11770 However, for each CU + set of TUs that came from the same original DWO
11771 file, we can combine them back into a virtual DWO file to save space
11772 (fewer struct dwo_file objects to allocate). Remember that for really
11773 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11775 std::string virtual_dwo_name
=
11776 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11777 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11778 (long) (sections
.line_size
? sections
.line_offset
: 0),
11779 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11780 (long) (sections
.str_offsets_size
11781 ? sections
.str_offsets_offset
: 0));
11782 /* Can we use an existing virtual DWO file? */
11783 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11784 virtual_dwo_name
.c_str (),
11786 /* Create one if necessary. */
11787 if (*dwo_file_slot
== NULL
)
11789 if (dwarf_read_debug
)
11791 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11792 virtual_dwo_name
.c_str ());
11794 dwo_file
= new struct dwo_file
;
11795 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11796 dwo_file
->comp_dir
= comp_dir
;
11797 dwo_file
->sections
.abbrev
=
11798 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11799 sections
.abbrev_offset
, sections
.abbrev_size
);
11800 dwo_file
->sections
.line
=
11801 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11802 sections
.line_offset
, sections
.line_size
);
11803 dwo_file
->sections
.loc
=
11804 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11805 sections
.loc_offset
, sections
.loc_size
);
11806 dwo_file
->sections
.macinfo
=
11807 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11808 sections
.macinfo_offset
, sections
.macinfo_size
);
11809 dwo_file
->sections
.macro
=
11810 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11811 sections
.macro_offset
, sections
.macro_size
);
11812 dwo_file
->sections
.str_offsets
=
11813 create_dwp_v2_section (dwarf2_per_objfile
,
11814 &dwp_file
->sections
.str_offsets
,
11815 sections
.str_offsets_offset
,
11816 sections
.str_offsets_size
);
11817 /* The "str" section is global to the entire DWP file. */
11818 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11819 /* The info or types section is assigned below to dwo_unit,
11820 there's no need to record it in dwo_file.
11821 Also, we can't simply record type sections in dwo_file because
11822 we record a pointer into the vector in dwo_unit. As we collect more
11823 types we'll grow the vector and eventually have to reallocate space
11824 for it, invalidating all copies of pointers into the previous
11826 *dwo_file_slot
= dwo_file
;
11830 if (dwarf_read_debug
)
11832 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11833 virtual_dwo_name
.c_str ());
11835 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11838 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11839 dwo_unit
->dwo_file
= dwo_file
;
11840 dwo_unit
->signature
= signature
;
11841 dwo_unit
->section
=
11842 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11843 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11845 ? &dwp_file
->sections
.types
11846 : &dwp_file
->sections
.info
,
11847 sections
.info_or_types_offset
,
11848 sections
.info_or_types_size
);
11849 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11854 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11855 Returns NULL if the signature isn't found. */
11857 static struct dwo_unit
*
11858 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11859 struct dwp_file
*dwp_file
, const char *comp_dir
,
11860 ULONGEST signature
, int is_debug_types
)
11862 const struct dwp_hash_table
*dwp_htab
=
11863 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11864 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11865 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11866 uint32_t hash
= signature
& mask
;
11867 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11870 struct dwo_unit find_dwo_cu
;
11872 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11873 find_dwo_cu
.signature
= signature
;
11874 slot
= htab_find_slot (is_debug_types
11875 ? dwp_file
->loaded_tus
.get ()
11876 : dwp_file
->loaded_cus
.get (),
11877 &find_dwo_cu
, INSERT
);
11880 return (struct dwo_unit
*) *slot
;
11882 /* Use a for loop so that we don't loop forever on bad debug info. */
11883 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11885 ULONGEST signature_in_table
;
11887 signature_in_table
=
11888 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11889 if (signature_in_table
== signature
)
11891 uint32_t unit_index
=
11892 read_4_bytes (dbfd
,
11893 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11895 if (dwp_file
->version
== 1)
11897 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11898 dwp_file
, unit_index
,
11899 comp_dir
, signature
,
11904 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11905 dwp_file
, unit_index
,
11906 comp_dir
, signature
,
11909 return (struct dwo_unit
*) *slot
;
11911 if (signature_in_table
== 0)
11913 hash
= (hash
+ hash2
) & mask
;
11916 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11917 " [in module %s]"),
11921 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11922 Open the file specified by FILE_NAME and hand it off to BFD for
11923 preliminary analysis. Return a newly initialized bfd *, which
11924 includes a canonicalized copy of FILE_NAME.
11925 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11926 SEARCH_CWD is true if the current directory is to be searched.
11927 It will be searched before debug-file-directory.
11928 If successful, the file is added to the bfd include table of the
11929 objfile's bfd (see gdb_bfd_record_inclusion).
11930 If unable to find/open the file, return NULL.
11931 NOTE: This function is derived from symfile_bfd_open. */
11933 static gdb_bfd_ref_ptr
11934 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11935 const char *file_name
, int is_dwp
, int search_cwd
)
11938 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11939 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11940 to debug_file_directory. */
11941 const char *search_path
;
11942 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11944 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11947 if (*debug_file_directory
!= '\0')
11949 search_path_holder
.reset (concat (".", dirname_separator_string
,
11950 debug_file_directory
,
11952 search_path
= search_path_holder
.get ();
11958 search_path
= debug_file_directory
;
11960 openp_flags flags
= OPF_RETURN_REALPATH
;
11962 flags
|= OPF_SEARCH_IN_PATH
;
11964 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11965 desc
= openp (search_path
, flags
, file_name
,
11966 O_RDONLY
| O_BINARY
, &absolute_name
);
11970 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11972 if (sym_bfd
== NULL
)
11974 bfd_set_cacheable (sym_bfd
.get (), 1);
11976 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11979 /* Success. Record the bfd as having been included by the objfile's bfd.
11980 This is important because things like demangled_names_hash lives in the
11981 objfile's per_bfd space and may have references to things like symbol
11982 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11983 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11988 /* Try to open DWO file FILE_NAME.
11989 COMP_DIR is the DW_AT_comp_dir attribute.
11990 The result is the bfd handle of the file.
11991 If there is a problem finding or opening the file, return NULL.
11992 Upon success, the canonicalized path of the file is stored in the bfd,
11993 same as symfile_bfd_open. */
11995 static gdb_bfd_ref_ptr
11996 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11997 const char *file_name
, const char *comp_dir
)
11999 if (IS_ABSOLUTE_PATH (file_name
))
12000 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12001 0 /*is_dwp*/, 0 /*search_cwd*/);
12003 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12005 if (comp_dir
!= NULL
)
12007 gdb::unique_xmalloc_ptr
<char> path_to_try
12008 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12010 /* NOTE: If comp_dir is a relative path, this will also try the
12011 search path, which seems useful. */
12012 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12013 path_to_try
.get (),
12015 1 /*search_cwd*/));
12020 /* That didn't work, try debug-file-directory, which, despite its name,
12021 is a list of paths. */
12023 if (*debug_file_directory
== '\0')
12026 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12027 0 /*is_dwp*/, 1 /*search_cwd*/);
12030 /* This function is mapped across the sections and remembers the offset and
12031 size of each of the DWO debugging sections we are interested in. */
12034 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12036 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12037 const struct dwop_section_names
*names
= &dwop_section_names
;
12039 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12041 dwo_sections
->abbrev
.s
.section
= sectp
;
12042 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12044 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12046 dwo_sections
->info
.s
.section
= sectp
;
12047 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12049 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12051 dwo_sections
->line
.s
.section
= sectp
;
12052 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12054 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12056 dwo_sections
->loc
.s
.section
= sectp
;
12057 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12059 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12061 dwo_sections
->macinfo
.s
.section
= sectp
;
12062 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12064 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12066 dwo_sections
->macro
.s
.section
= sectp
;
12067 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12069 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12071 dwo_sections
->str
.s
.section
= sectp
;
12072 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12074 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12076 dwo_sections
->str_offsets
.s
.section
= sectp
;
12077 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12079 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12081 struct dwarf2_section_info type_section
;
12083 memset (&type_section
, 0, sizeof (type_section
));
12084 type_section
.s
.section
= sectp
;
12085 type_section
.size
= bfd_section_size (sectp
);
12086 dwo_sections
->types
.push_back (type_section
);
12090 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12091 by PER_CU. This is for the non-DWP case.
12092 The result is NULL if DWO_NAME can't be found. */
12094 static struct dwo_file
*
12095 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12096 const char *dwo_name
, const char *comp_dir
)
12098 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12100 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12103 if (dwarf_read_debug
)
12104 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12108 dwo_file_up
dwo_file (new struct dwo_file
);
12109 dwo_file
->dwo_name
= dwo_name
;
12110 dwo_file
->comp_dir
= comp_dir
;
12111 dwo_file
->dbfd
= std::move (dbfd
);
12113 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12114 &dwo_file
->sections
);
12116 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12117 dwo_file
->sections
.info
, dwo_file
->cus
);
12119 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12120 dwo_file
->sections
.types
, dwo_file
->tus
);
12122 if (dwarf_read_debug
)
12123 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12125 return dwo_file
.release ();
12128 /* This function is mapped across the sections and remembers the offset and
12129 size of each of the DWP debugging sections common to version 1 and 2 that
12130 we are interested in. */
12133 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12134 void *dwp_file_ptr
)
12136 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12137 const struct dwop_section_names
*names
= &dwop_section_names
;
12138 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12140 /* Record the ELF section number for later lookup: this is what the
12141 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12142 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12143 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12145 /* Look for specific sections that we need. */
12146 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12148 dwp_file
->sections
.str
.s
.section
= sectp
;
12149 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12151 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12153 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12154 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12156 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12158 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12159 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12163 /* This function is mapped across the sections and remembers the offset and
12164 size of each of the DWP version 2 debugging sections that we are interested
12165 in. This is split into a separate function because we don't know if we
12166 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12169 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12171 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12172 const struct dwop_section_names
*names
= &dwop_section_names
;
12173 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12175 /* Record the ELF section number for later lookup: this is what the
12176 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12177 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12178 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12180 /* Look for specific sections that we need. */
12181 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12183 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12184 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12186 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12188 dwp_file
->sections
.info
.s
.section
= sectp
;
12189 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12191 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12193 dwp_file
->sections
.line
.s
.section
= sectp
;
12194 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12196 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12198 dwp_file
->sections
.loc
.s
.section
= sectp
;
12199 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12201 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12203 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12204 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12206 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12208 dwp_file
->sections
.macro
.s
.section
= sectp
;
12209 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12211 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12213 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12214 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12216 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12218 dwp_file
->sections
.types
.s
.section
= sectp
;
12219 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12223 /* Hash function for dwp_file loaded CUs/TUs. */
12226 hash_dwp_loaded_cutus (const void *item
)
12228 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12230 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12231 return dwo_unit
->signature
;
12234 /* Equality function for dwp_file loaded CUs/TUs. */
12237 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12239 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12240 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12242 return dua
->signature
== dub
->signature
;
12245 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12248 allocate_dwp_loaded_cutus_table ()
12250 return htab_up (htab_create_alloc (3,
12251 hash_dwp_loaded_cutus
,
12252 eq_dwp_loaded_cutus
,
12253 NULL
, xcalloc
, xfree
));
12256 /* Try to open DWP file FILE_NAME.
12257 The result is the bfd handle of the file.
12258 If there is a problem finding or opening the file, return NULL.
12259 Upon success, the canonicalized path of the file is stored in the bfd,
12260 same as symfile_bfd_open. */
12262 static gdb_bfd_ref_ptr
12263 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12264 const char *file_name
)
12266 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12268 1 /*search_cwd*/));
12272 /* Work around upstream bug 15652.
12273 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12274 [Whether that's a "bug" is debatable, but it is getting in our way.]
12275 We have no real idea where the dwp file is, because gdb's realpath-ing
12276 of the executable's path may have discarded the needed info.
12277 [IWBN if the dwp file name was recorded in the executable, akin to
12278 .gnu_debuglink, but that doesn't exist yet.]
12279 Strip the directory from FILE_NAME and search again. */
12280 if (*debug_file_directory
!= '\0')
12282 /* Don't implicitly search the current directory here.
12283 If the user wants to search "." to handle this case,
12284 it must be added to debug-file-directory. */
12285 return try_open_dwop_file (dwarf2_per_objfile
,
12286 lbasename (file_name
), 1 /*is_dwp*/,
12293 /* Initialize the use of the DWP file for the current objfile.
12294 By convention the name of the DWP file is ${objfile}.dwp.
12295 The result is NULL if it can't be found. */
12297 static std::unique_ptr
<struct dwp_file
>
12298 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12300 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12302 /* Try to find first .dwp for the binary file before any symbolic links
12305 /* If the objfile is a debug file, find the name of the real binary
12306 file and get the name of dwp file from there. */
12307 std::string dwp_name
;
12308 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12310 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12311 const char *backlink_basename
= lbasename (backlink
->original_name
);
12313 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12316 dwp_name
= objfile
->original_name
;
12318 dwp_name
+= ".dwp";
12320 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12322 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12324 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12325 dwp_name
= objfile_name (objfile
);
12326 dwp_name
+= ".dwp";
12327 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12332 if (dwarf_read_debug
)
12333 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12334 return std::unique_ptr
<dwp_file
> ();
12337 const char *name
= bfd_get_filename (dbfd
.get ());
12338 std::unique_ptr
<struct dwp_file
> dwp_file
12339 (new struct dwp_file (name
, std::move (dbfd
)));
12341 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12342 dwp_file
->elf_sections
=
12343 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12344 dwp_file
->num_sections
, asection
*);
12346 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12347 dwarf2_locate_common_dwp_sections
,
12350 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12353 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12356 /* The DWP file version is stored in the hash table. Oh well. */
12357 if (dwp_file
->cus
&& dwp_file
->tus
12358 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12360 /* Technically speaking, we should try to limp along, but this is
12361 pretty bizarre. We use pulongest here because that's the established
12362 portability solution (e.g, we cannot use %u for uint32_t). */
12363 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12364 " TU version %s [in DWP file %s]"),
12365 pulongest (dwp_file
->cus
->version
),
12366 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12370 dwp_file
->version
= dwp_file
->cus
->version
;
12371 else if (dwp_file
->tus
)
12372 dwp_file
->version
= dwp_file
->tus
->version
;
12374 dwp_file
->version
= 2;
12376 if (dwp_file
->version
== 2)
12377 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12378 dwarf2_locate_v2_dwp_sections
,
12381 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12382 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12384 if (dwarf_read_debug
)
12386 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12387 fprintf_unfiltered (gdb_stdlog
,
12388 " %s CUs, %s TUs\n",
12389 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12390 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12396 /* Wrapper around open_and_init_dwp_file, only open it once. */
12398 static struct dwp_file
*
12399 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12401 if (! dwarf2_per_objfile
->dwp_checked
)
12403 dwarf2_per_objfile
->dwp_file
12404 = open_and_init_dwp_file (dwarf2_per_objfile
);
12405 dwarf2_per_objfile
->dwp_checked
= 1;
12407 return dwarf2_per_objfile
->dwp_file
.get ();
12410 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12411 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12412 or in the DWP file for the objfile, referenced by THIS_UNIT.
12413 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12414 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12416 This is called, for example, when wanting to read a variable with a
12417 complex location. Therefore we don't want to do file i/o for every call.
12418 Therefore we don't want to look for a DWO file on every call.
12419 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12420 then we check if we've already seen DWO_NAME, and only THEN do we check
12423 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12424 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12426 static struct dwo_unit
*
12427 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12428 const char *dwo_name
, const char *comp_dir
,
12429 ULONGEST signature
, int is_debug_types
)
12431 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12432 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12433 const char *kind
= is_debug_types
? "TU" : "CU";
12434 void **dwo_file_slot
;
12435 struct dwo_file
*dwo_file
;
12436 struct dwp_file
*dwp_file
;
12438 /* First see if there's a DWP file.
12439 If we have a DWP file but didn't find the DWO inside it, don't
12440 look for the original DWO file. It makes gdb behave differently
12441 depending on whether one is debugging in the build tree. */
12443 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12444 if (dwp_file
!= NULL
)
12446 const struct dwp_hash_table
*dwp_htab
=
12447 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12449 if (dwp_htab
!= NULL
)
12451 struct dwo_unit
*dwo_cutu
=
12452 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12453 signature
, is_debug_types
);
12455 if (dwo_cutu
!= NULL
)
12457 if (dwarf_read_debug
)
12459 fprintf_unfiltered (gdb_stdlog
,
12460 "Virtual DWO %s %s found: @%s\n",
12461 kind
, hex_string (signature
),
12462 host_address_to_string (dwo_cutu
));
12470 /* No DWP file, look for the DWO file. */
12472 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12473 dwo_name
, comp_dir
);
12474 if (*dwo_file_slot
== NULL
)
12476 /* Read in the file and build a table of the CUs/TUs it contains. */
12477 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12479 /* NOTE: This will be NULL if unable to open the file. */
12480 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12482 if (dwo_file
!= NULL
)
12484 struct dwo_unit
*dwo_cutu
= NULL
;
12486 if (is_debug_types
&& dwo_file
->tus
)
12488 struct dwo_unit find_dwo_cutu
;
12490 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12491 find_dwo_cutu
.signature
= signature
;
12493 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12496 else if (!is_debug_types
&& dwo_file
->cus
)
12498 struct dwo_unit find_dwo_cutu
;
12500 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12501 find_dwo_cutu
.signature
= signature
;
12502 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12506 if (dwo_cutu
!= NULL
)
12508 if (dwarf_read_debug
)
12510 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12511 kind
, dwo_name
, hex_string (signature
),
12512 host_address_to_string (dwo_cutu
));
12519 /* We didn't find it. This could mean a dwo_id mismatch, or
12520 someone deleted the DWO/DWP file, or the search path isn't set up
12521 correctly to find the file. */
12523 if (dwarf_read_debug
)
12525 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12526 kind
, dwo_name
, hex_string (signature
));
12529 /* This is a warning and not a complaint because it can be caused by
12530 pilot error (e.g., user accidentally deleting the DWO). */
12532 /* Print the name of the DWP file if we looked there, helps the user
12533 better diagnose the problem. */
12534 std::string dwp_text
;
12536 if (dwp_file
!= NULL
)
12537 dwp_text
= string_printf (" [in DWP file %s]",
12538 lbasename (dwp_file
->name
));
12540 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12541 " [in module %s]"),
12542 kind
, dwo_name
, hex_string (signature
),
12544 this_unit
->is_debug_types
? "TU" : "CU",
12545 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12550 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12551 See lookup_dwo_cutu_unit for details. */
12553 static struct dwo_unit
*
12554 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12555 const char *dwo_name
, const char *comp_dir
,
12556 ULONGEST signature
)
12558 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12561 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12562 See lookup_dwo_cutu_unit for details. */
12564 static struct dwo_unit
*
12565 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12566 const char *dwo_name
, const char *comp_dir
)
12568 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12571 /* Traversal function for queue_and_load_all_dwo_tus. */
12574 queue_and_load_dwo_tu (void **slot
, void *info
)
12576 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12577 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12578 ULONGEST signature
= dwo_unit
->signature
;
12579 struct signatured_type
*sig_type
=
12580 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12582 if (sig_type
!= NULL
)
12584 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12586 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12587 a real dependency of PER_CU on SIG_TYPE. That is detected later
12588 while processing PER_CU. */
12589 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12590 load_full_type_unit (sig_cu
);
12591 per_cu
->imported_symtabs_push (sig_cu
);
12597 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12598 The DWO may have the only definition of the type, though it may not be
12599 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12600 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12603 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12605 struct dwo_unit
*dwo_unit
;
12606 struct dwo_file
*dwo_file
;
12608 gdb_assert (!per_cu
->is_debug_types
);
12609 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12610 gdb_assert (per_cu
->cu
!= NULL
);
12612 dwo_unit
= per_cu
->cu
->dwo_unit
;
12613 gdb_assert (dwo_unit
!= NULL
);
12615 dwo_file
= dwo_unit
->dwo_file
;
12616 if (dwo_file
->tus
!= NULL
)
12617 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12621 /* Read in various DIEs. */
12623 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12624 Inherit only the children of the DW_AT_abstract_origin DIE not being
12625 already referenced by DW_AT_abstract_origin from the children of the
12629 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12631 struct die_info
*child_die
;
12632 sect_offset
*offsetp
;
12633 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12634 struct die_info
*origin_die
;
12635 /* Iterator of the ORIGIN_DIE children. */
12636 struct die_info
*origin_child_die
;
12637 struct attribute
*attr
;
12638 struct dwarf2_cu
*origin_cu
;
12639 struct pending
**origin_previous_list_in_scope
;
12641 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12645 /* Note that following die references may follow to a die in a
12649 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12651 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12653 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12654 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12656 if (die
->tag
!= origin_die
->tag
12657 && !(die
->tag
== DW_TAG_inlined_subroutine
12658 && origin_die
->tag
== DW_TAG_subprogram
))
12659 complaint (_("DIE %s and its abstract origin %s have different tags"),
12660 sect_offset_str (die
->sect_off
),
12661 sect_offset_str (origin_die
->sect_off
));
12663 std::vector
<sect_offset
> offsets
;
12665 for (child_die
= die
->child
;
12666 child_die
&& child_die
->tag
;
12667 child_die
= child_die
->sibling
)
12669 struct die_info
*child_origin_die
;
12670 struct dwarf2_cu
*child_origin_cu
;
12672 /* We are trying to process concrete instance entries:
12673 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12674 it's not relevant to our analysis here. i.e. detecting DIEs that are
12675 present in the abstract instance but not referenced in the concrete
12677 if (child_die
->tag
== DW_TAG_call_site
12678 || child_die
->tag
== DW_TAG_GNU_call_site
)
12681 /* For each CHILD_DIE, find the corresponding child of
12682 ORIGIN_DIE. If there is more than one layer of
12683 DW_AT_abstract_origin, follow them all; there shouldn't be,
12684 but GCC versions at least through 4.4 generate this (GCC PR
12686 child_origin_die
= child_die
;
12687 child_origin_cu
= cu
;
12690 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12694 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12698 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12699 counterpart may exist. */
12700 if (child_origin_die
!= child_die
)
12702 if (child_die
->tag
!= child_origin_die
->tag
12703 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12704 && child_origin_die
->tag
== DW_TAG_subprogram
))
12705 complaint (_("Child DIE %s and its abstract origin %s have "
12707 sect_offset_str (child_die
->sect_off
),
12708 sect_offset_str (child_origin_die
->sect_off
));
12709 if (child_origin_die
->parent
!= origin_die
)
12710 complaint (_("Child DIE %s and its abstract origin %s have "
12711 "different parents"),
12712 sect_offset_str (child_die
->sect_off
),
12713 sect_offset_str (child_origin_die
->sect_off
));
12715 offsets
.push_back (child_origin_die
->sect_off
);
12718 std::sort (offsets
.begin (), offsets
.end ());
12719 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12720 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12721 if (offsetp
[-1] == *offsetp
)
12722 complaint (_("Multiple children of DIE %s refer "
12723 "to DIE %s as their abstract origin"),
12724 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12726 offsetp
= offsets
.data ();
12727 origin_child_die
= origin_die
->child
;
12728 while (origin_child_die
&& origin_child_die
->tag
)
12730 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12731 while (offsetp
< offsets_end
12732 && *offsetp
< origin_child_die
->sect_off
)
12734 if (offsetp
>= offsets_end
12735 || *offsetp
> origin_child_die
->sect_off
)
12737 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12738 Check whether we're already processing ORIGIN_CHILD_DIE.
12739 This can happen with mutually referenced abstract_origins.
12741 if (!origin_child_die
->in_process
)
12742 process_die (origin_child_die
, origin_cu
);
12744 origin_child_die
= origin_child_die
->sibling
;
12746 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12748 if (cu
!= origin_cu
)
12749 compute_delayed_physnames (origin_cu
);
12753 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12755 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12756 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12757 struct context_stack
*newobj
;
12760 struct die_info
*child_die
;
12761 struct attribute
*attr
, *call_line
, *call_file
;
12763 CORE_ADDR baseaddr
;
12764 struct block
*block
;
12765 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12766 std::vector
<struct symbol
*> template_args
;
12767 struct template_symbol
*templ_func
= NULL
;
12771 /* If we do not have call site information, we can't show the
12772 caller of this inlined function. That's too confusing, so
12773 only use the scope for local variables. */
12774 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12775 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12776 if (call_line
== NULL
|| call_file
== NULL
)
12778 read_lexical_block_scope (die
, cu
);
12783 baseaddr
= objfile
->text_section_offset ();
12785 name
= dwarf2_name (die
, cu
);
12787 /* Ignore functions with missing or empty names. These are actually
12788 illegal according to the DWARF standard. */
12791 complaint (_("missing name for subprogram DIE at %s"),
12792 sect_offset_str (die
->sect_off
));
12796 /* Ignore functions with missing or invalid low and high pc attributes. */
12797 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12798 <= PC_BOUNDS_INVALID
)
12800 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12801 if (!attr
|| !DW_UNSND (attr
))
12802 complaint (_("cannot get low and high bounds "
12803 "for subprogram DIE at %s"),
12804 sect_offset_str (die
->sect_off
));
12808 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12809 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12811 /* If we have any template arguments, then we must allocate a
12812 different sort of symbol. */
12813 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12815 if (child_die
->tag
== DW_TAG_template_type_param
12816 || child_die
->tag
== DW_TAG_template_value_param
)
12818 templ_func
= allocate_template_symbol (objfile
);
12819 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12824 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12825 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12826 (struct symbol
*) templ_func
);
12828 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12829 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12832 /* If there is a location expression for DW_AT_frame_base, record
12834 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12835 if (attr
!= nullptr)
12836 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12838 /* If there is a location for the static link, record it. */
12839 newobj
->static_link
= NULL
;
12840 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12841 if (attr
!= nullptr)
12843 newobj
->static_link
12844 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12845 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12846 cu
->per_cu
->addr_type ());
12849 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12851 if (die
->child
!= NULL
)
12853 child_die
= die
->child
;
12854 while (child_die
&& child_die
->tag
)
12856 if (child_die
->tag
== DW_TAG_template_type_param
12857 || child_die
->tag
== DW_TAG_template_value_param
)
12859 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12862 template_args
.push_back (arg
);
12865 process_die (child_die
, cu
);
12866 child_die
= child_die
->sibling
;
12870 inherit_abstract_dies (die
, cu
);
12872 /* If we have a DW_AT_specification, we might need to import using
12873 directives from the context of the specification DIE. See the
12874 comment in determine_prefix. */
12875 if (cu
->language
== language_cplus
12876 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12878 struct dwarf2_cu
*spec_cu
= cu
;
12879 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12883 child_die
= spec_die
->child
;
12884 while (child_die
&& child_die
->tag
)
12886 if (child_die
->tag
== DW_TAG_imported_module
)
12887 process_die (child_die
, spec_cu
);
12888 child_die
= child_die
->sibling
;
12891 /* In some cases, GCC generates specification DIEs that
12892 themselves contain DW_AT_specification attributes. */
12893 spec_die
= die_specification (spec_die
, &spec_cu
);
12897 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12898 /* Make a block for the local symbols within. */
12899 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12900 cstk
.static_link
, lowpc
, highpc
);
12902 /* For C++, set the block's scope. */
12903 if ((cu
->language
== language_cplus
12904 || cu
->language
== language_fortran
12905 || cu
->language
== language_d
12906 || cu
->language
== language_rust
)
12907 && cu
->processing_has_namespace_info
)
12908 block_set_scope (block
, determine_prefix (die
, cu
),
12909 &objfile
->objfile_obstack
);
12911 /* If we have address ranges, record them. */
12912 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12914 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12916 /* Attach template arguments to function. */
12917 if (!template_args
.empty ())
12919 gdb_assert (templ_func
!= NULL
);
12921 templ_func
->n_template_arguments
= template_args
.size ();
12922 templ_func
->template_arguments
12923 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12924 templ_func
->n_template_arguments
);
12925 memcpy (templ_func
->template_arguments
,
12926 template_args
.data (),
12927 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12929 /* Make sure that the symtab is set on the new symbols. Even
12930 though they don't appear in this symtab directly, other parts
12931 of gdb assume that symbols do, and this is reasonably
12933 for (symbol
*sym
: template_args
)
12934 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12937 /* In C++, we can have functions nested inside functions (e.g., when
12938 a function declares a class that has methods). This means that
12939 when we finish processing a function scope, we may need to go
12940 back to building a containing block's symbol lists. */
12941 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12942 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12944 /* If we've finished processing a top-level function, subsequent
12945 symbols go in the file symbol list. */
12946 if (cu
->get_builder ()->outermost_context_p ())
12947 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12950 /* Process all the DIES contained within a lexical block scope. Start
12951 a new scope, process the dies, and then close the scope. */
12954 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12956 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12957 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12958 CORE_ADDR lowpc
, highpc
;
12959 struct die_info
*child_die
;
12960 CORE_ADDR baseaddr
;
12962 baseaddr
= objfile
->text_section_offset ();
12964 /* Ignore blocks with missing or invalid low and high pc attributes. */
12965 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12966 as multiple lexical blocks? Handling children in a sane way would
12967 be nasty. Might be easier to properly extend generic blocks to
12968 describe ranges. */
12969 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12971 case PC_BOUNDS_NOT_PRESENT
:
12972 /* DW_TAG_lexical_block has no attributes, process its children as if
12973 there was no wrapping by that DW_TAG_lexical_block.
12974 GCC does no longer produces such DWARF since GCC r224161. */
12975 for (child_die
= die
->child
;
12976 child_die
!= NULL
&& child_die
->tag
;
12977 child_die
= child_die
->sibling
)
12978 process_die (child_die
, cu
);
12980 case PC_BOUNDS_INVALID
:
12983 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12984 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12986 cu
->get_builder ()->push_context (0, lowpc
);
12987 if (die
->child
!= NULL
)
12989 child_die
= die
->child
;
12990 while (child_die
&& child_die
->tag
)
12992 process_die (child_die
, cu
);
12993 child_die
= child_die
->sibling
;
12996 inherit_abstract_dies (die
, cu
);
12997 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12999 if (*cu
->get_builder ()->get_local_symbols () != NULL
13000 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13002 struct block
*block
13003 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13004 cstk
.start_addr
, highpc
);
13006 /* Note that recording ranges after traversing children, as we
13007 do here, means that recording a parent's ranges entails
13008 walking across all its children's ranges as they appear in
13009 the address map, which is quadratic behavior.
13011 It would be nicer to record the parent's ranges before
13012 traversing its children, simply overriding whatever you find
13013 there. But since we don't even decide whether to create a
13014 block until after we've traversed its children, that's hard
13016 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13018 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13019 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13022 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13025 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13027 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13028 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13029 CORE_ADDR pc
, baseaddr
;
13030 struct attribute
*attr
;
13031 struct call_site
*call_site
, call_site_local
;
13034 struct die_info
*child_die
;
13036 baseaddr
= objfile
->text_section_offset ();
13038 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13041 /* This was a pre-DWARF-5 GNU extension alias
13042 for DW_AT_call_return_pc. */
13043 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13047 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13048 "DIE %s [in module %s]"),
13049 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13052 pc
= attr
->value_as_address () + baseaddr
;
13053 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13055 if (cu
->call_site_htab
== NULL
)
13056 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13057 NULL
, &objfile
->objfile_obstack
,
13058 hashtab_obstack_allocate
, NULL
);
13059 call_site_local
.pc
= pc
;
13060 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13063 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13064 "DIE %s [in module %s]"),
13065 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13066 objfile_name (objfile
));
13070 /* Count parameters at the caller. */
13073 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13074 child_die
= child_die
->sibling
)
13076 if (child_die
->tag
!= DW_TAG_call_site_parameter
13077 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13079 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13080 "DW_TAG_call_site child DIE %s [in module %s]"),
13081 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13082 objfile_name (objfile
));
13090 = ((struct call_site
*)
13091 obstack_alloc (&objfile
->objfile_obstack
,
13092 sizeof (*call_site
)
13093 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13095 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13096 call_site
->pc
= pc
;
13098 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13099 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13101 struct die_info
*func_die
;
13103 /* Skip also over DW_TAG_inlined_subroutine. */
13104 for (func_die
= die
->parent
;
13105 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13106 && func_die
->tag
!= DW_TAG_subroutine_type
;
13107 func_die
= func_die
->parent
);
13109 /* DW_AT_call_all_calls is a superset
13110 of DW_AT_call_all_tail_calls. */
13112 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13113 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13114 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13115 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13117 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13118 not complete. But keep CALL_SITE for look ups via call_site_htab,
13119 both the initial caller containing the real return address PC and
13120 the final callee containing the current PC of a chain of tail
13121 calls do not need to have the tail call list complete. But any
13122 function candidate for a virtual tail call frame searched via
13123 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13124 determined unambiguously. */
13128 struct type
*func_type
= NULL
;
13131 func_type
= get_die_type (func_die
, cu
);
13132 if (func_type
!= NULL
)
13134 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13136 /* Enlist this call site to the function. */
13137 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13138 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13141 complaint (_("Cannot find function owning DW_TAG_call_site "
13142 "DIE %s [in module %s]"),
13143 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13147 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13149 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13151 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13154 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13155 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13157 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13158 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13159 /* Keep NULL DWARF_BLOCK. */;
13160 else if (attr
->form_is_block ())
13162 struct dwarf2_locexpr_baton
*dlbaton
;
13164 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13165 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13166 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13167 dlbaton
->per_cu
= cu
->per_cu
;
13169 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13171 else if (attr
->form_is_ref ())
13173 struct dwarf2_cu
*target_cu
= cu
;
13174 struct die_info
*target_die
;
13176 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13177 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13178 if (die_is_declaration (target_die
, target_cu
))
13180 const char *target_physname
;
13182 /* Prefer the mangled name; otherwise compute the demangled one. */
13183 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13184 if (target_physname
== NULL
)
13185 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13186 if (target_physname
== NULL
)
13187 complaint (_("DW_AT_call_target target DIE has invalid "
13188 "physname, for referencing DIE %s [in module %s]"),
13189 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13191 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13197 /* DW_AT_entry_pc should be preferred. */
13198 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13199 <= PC_BOUNDS_INVALID
)
13200 complaint (_("DW_AT_call_target target DIE has invalid "
13201 "low pc, for referencing DIE %s [in module %s]"),
13202 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13205 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13206 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13211 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13212 "block nor reference, for DIE %s [in module %s]"),
13213 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13215 call_site
->per_cu
= cu
->per_cu
;
13217 for (child_die
= die
->child
;
13218 child_die
&& child_die
->tag
;
13219 child_die
= child_die
->sibling
)
13221 struct call_site_parameter
*parameter
;
13222 struct attribute
*loc
, *origin
;
13224 if (child_die
->tag
!= DW_TAG_call_site_parameter
13225 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13227 /* Already printed the complaint above. */
13231 gdb_assert (call_site
->parameter_count
< nparams
);
13232 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13234 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13235 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13236 register is contained in DW_AT_call_value. */
13238 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13239 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13240 if (origin
== NULL
)
13242 /* This was a pre-DWARF-5 GNU extension alias
13243 for DW_AT_call_parameter. */
13244 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13246 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13248 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13250 sect_offset sect_off
= origin
->get_ref_die_offset ();
13251 if (!cu
->header
.offset_in_cu_p (sect_off
))
13253 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13254 binding can be done only inside one CU. Such referenced DIE
13255 therefore cannot be even moved to DW_TAG_partial_unit. */
13256 complaint (_("DW_AT_call_parameter offset is not in CU for "
13257 "DW_TAG_call_site child DIE %s [in module %s]"),
13258 sect_offset_str (child_die
->sect_off
),
13259 objfile_name (objfile
));
13262 parameter
->u
.param_cu_off
13263 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13265 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13267 complaint (_("No DW_FORM_block* DW_AT_location for "
13268 "DW_TAG_call_site child DIE %s [in module %s]"),
13269 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13274 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13275 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13276 if (parameter
->u
.dwarf_reg
!= -1)
13277 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13278 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13279 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13280 ¶meter
->u
.fb_offset
))
13281 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13284 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13285 "for DW_FORM_block* DW_AT_location is supported for "
13286 "DW_TAG_call_site child DIE %s "
13288 sect_offset_str (child_die
->sect_off
),
13289 objfile_name (objfile
));
13294 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13296 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13297 if (attr
== NULL
|| !attr
->form_is_block ())
13299 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13300 "DW_TAG_call_site child DIE %s [in module %s]"),
13301 sect_offset_str (child_die
->sect_off
),
13302 objfile_name (objfile
));
13305 parameter
->value
= DW_BLOCK (attr
)->data
;
13306 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13308 /* Parameters are not pre-cleared by memset above. */
13309 parameter
->data_value
= NULL
;
13310 parameter
->data_value_size
= 0;
13311 call_site
->parameter_count
++;
13313 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13315 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13316 if (attr
!= nullptr)
13318 if (!attr
->form_is_block ())
13319 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13320 "DW_TAG_call_site child DIE %s [in module %s]"),
13321 sect_offset_str (child_die
->sect_off
),
13322 objfile_name (objfile
));
13325 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13326 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13332 /* Helper function for read_variable. If DIE represents a virtual
13333 table, then return the type of the concrete object that is
13334 associated with the virtual table. Otherwise, return NULL. */
13336 static struct type
*
13337 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13339 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13343 /* Find the type DIE. */
13344 struct die_info
*type_die
= NULL
;
13345 struct dwarf2_cu
*type_cu
= cu
;
13347 if (attr
->form_is_ref ())
13348 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13349 if (type_die
== NULL
)
13352 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13354 return die_containing_type (type_die
, type_cu
);
13357 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13360 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13362 struct rust_vtable_symbol
*storage
= NULL
;
13364 if (cu
->language
== language_rust
)
13366 struct type
*containing_type
= rust_containing_type (die
, cu
);
13368 if (containing_type
!= NULL
)
13370 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13372 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13373 initialize_objfile_symbol (storage
);
13374 storage
->concrete_type
= containing_type
;
13375 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13379 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13380 struct attribute
*abstract_origin
13381 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13382 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13383 if (res
== NULL
&& loc
&& abstract_origin
)
13385 /* We have a variable without a name, but with a location and an abstract
13386 origin. This may be a concrete instance of an abstract variable
13387 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13389 struct dwarf2_cu
*origin_cu
= cu
;
13390 struct die_info
*origin_die
13391 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13392 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13393 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13397 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13398 reading .debug_rnglists.
13399 Callback's type should be:
13400 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13401 Return true if the attributes are present and valid, otherwise,
13404 template <typename Callback
>
13406 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13407 Callback
&&callback
)
13409 struct dwarf2_per_objfile
*dwarf2_per_objfile
13410 = cu
->per_cu
->dwarf2_per_objfile
;
13411 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13412 bfd
*obfd
= objfile
->obfd
;
13413 /* Base address selection entry. */
13414 gdb::optional
<CORE_ADDR
> base
;
13415 const gdb_byte
*buffer
;
13416 CORE_ADDR baseaddr
;
13417 bool overflow
= false;
13419 base
= cu
->base_address
;
13421 dwarf2_per_objfile
->rnglists
.read (objfile
);
13422 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13424 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13428 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13430 baseaddr
= objfile
->text_section_offset ();
13434 /* Initialize it due to a false compiler warning. */
13435 CORE_ADDR range_beginning
= 0, range_end
= 0;
13436 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13437 + dwarf2_per_objfile
->rnglists
.size
);
13438 unsigned int bytes_read
;
13440 if (buffer
== buf_end
)
13445 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13448 case DW_RLE_end_of_list
:
13450 case DW_RLE_base_address
:
13451 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13456 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13457 buffer
+= bytes_read
;
13459 case DW_RLE_start_length
:
13460 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13465 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13467 buffer
+= bytes_read
;
13468 range_end
= (range_beginning
13469 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13470 buffer
+= bytes_read
;
13471 if (buffer
> buf_end
)
13477 case DW_RLE_offset_pair
:
13478 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13479 buffer
+= bytes_read
;
13480 if (buffer
> buf_end
)
13485 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13486 buffer
+= bytes_read
;
13487 if (buffer
> buf_end
)
13493 case DW_RLE_start_end
:
13494 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13499 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13501 buffer
+= bytes_read
;
13502 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13503 buffer
+= bytes_read
;
13506 complaint (_("Invalid .debug_rnglists data (no base address)"));
13509 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13511 if (rlet
== DW_RLE_base_address
)
13514 if (!base
.has_value ())
13516 /* We have no valid base address for the ranges
13518 complaint (_("Invalid .debug_rnglists data (no base address)"));
13522 if (range_beginning
> range_end
)
13524 /* Inverted range entries are invalid. */
13525 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13529 /* Empty range entries have no effect. */
13530 if (range_beginning
== range_end
)
13533 range_beginning
+= *base
;
13534 range_end
+= *base
;
13536 /* A not-uncommon case of bad debug info.
13537 Don't pollute the addrmap with bad data. */
13538 if (range_beginning
+ baseaddr
== 0
13539 && !dwarf2_per_objfile
->has_section_at_zero
)
13541 complaint (_(".debug_rnglists entry has start address of zero"
13542 " [in module %s]"), objfile_name (objfile
));
13546 callback (range_beginning
, range_end
);
13551 complaint (_("Offset %d is not terminated "
13552 "for DW_AT_ranges attribute"),
13560 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13561 Callback's type should be:
13562 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13563 Return 1 if the attributes are present and valid, otherwise, return 0. */
13565 template <typename Callback
>
13567 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13568 Callback
&&callback
)
13570 struct dwarf2_per_objfile
*dwarf2_per_objfile
13571 = cu
->per_cu
->dwarf2_per_objfile
;
13572 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13573 struct comp_unit_head
*cu_header
= &cu
->header
;
13574 bfd
*obfd
= objfile
->obfd
;
13575 unsigned int addr_size
= cu_header
->addr_size
;
13576 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13577 /* Base address selection entry. */
13578 gdb::optional
<CORE_ADDR
> base
;
13579 unsigned int dummy
;
13580 const gdb_byte
*buffer
;
13581 CORE_ADDR baseaddr
;
13583 if (cu_header
->version
>= 5)
13584 return dwarf2_rnglists_process (offset
, cu
, callback
);
13586 base
= cu
->base_address
;
13588 dwarf2_per_objfile
->ranges
.read (objfile
);
13589 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13591 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13595 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13597 baseaddr
= objfile
->text_section_offset ();
13601 CORE_ADDR range_beginning
, range_end
;
13603 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13604 buffer
+= addr_size
;
13605 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13606 buffer
+= addr_size
;
13607 offset
+= 2 * addr_size
;
13609 /* An end of list marker is a pair of zero addresses. */
13610 if (range_beginning
== 0 && range_end
== 0)
13611 /* Found the end of list entry. */
13614 /* Each base address selection entry is a pair of 2 values.
13615 The first is the largest possible address, the second is
13616 the base address. Check for a base address here. */
13617 if ((range_beginning
& mask
) == mask
)
13619 /* If we found the largest possible address, then we already
13620 have the base address in range_end. */
13625 if (!base
.has_value ())
13627 /* We have no valid base address for the ranges
13629 complaint (_("Invalid .debug_ranges data (no base address)"));
13633 if (range_beginning
> range_end
)
13635 /* Inverted range entries are invalid. */
13636 complaint (_("Invalid .debug_ranges data (inverted range)"));
13640 /* Empty range entries have no effect. */
13641 if (range_beginning
== range_end
)
13644 range_beginning
+= *base
;
13645 range_end
+= *base
;
13647 /* A not-uncommon case of bad debug info.
13648 Don't pollute the addrmap with bad data. */
13649 if (range_beginning
+ baseaddr
== 0
13650 && !dwarf2_per_objfile
->has_section_at_zero
)
13652 complaint (_(".debug_ranges entry has start address of zero"
13653 " [in module %s]"), objfile_name (objfile
));
13657 callback (range_beginning
, range_end
);
13663 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13664 Return 1 if the attributes are present and valid, otherwise, return 0.
13665 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13668 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13669 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13670 dwarf2_psymtab
*ranges_pst
)
13672 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13673 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13674 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13677 CORE_ADDR high
= 0;
13680 retval
= dwarf2_ranges_process (offset
, cu
,
13681 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13683 if (ranges_pst
!= NULL
)
13688 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13689 range_beginning
+ baseaddr
)
13691 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13692 range_end
+ baseaddr
)
13694 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13695 lowpc
, highpc
- 1, ranges_pst
);
13698 /* FIXME: This is recording everything as a low-high
13699 segment of consecutive addresses. We should have a
13700 data structure for discontiguous block ranges
13704 low
= range_beginning
;
13710 if (range_beginning
< low
)
13711 low
= range_beginning
;
13712 if (range_end
> high
)
13720 /* If the first entry is an end-of-list marker, the range
13721 describes an empty scope, i.e. no instructions. */
13727 *high_return
= high
;
13731 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13732 definition for the return value. *LOWPC and *HIGHPC are set iff
13733 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13735 static enum pc_bounds_kind
13736 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13737 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13738 dwarf2_psymtab
*pst
)
13740 struct dwarf2_per_objfile
*dwarf2_per_objfile
13741 = cu
->per_cu
->dwarf2_per_objfile
;
13742 struct attribute
*attr
;
13743 struct attribute
*attr_high
;
13745 CORE_ADDR high
= 0;
13746 enum pc_bounds_kind ret
;
13748 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13751 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13752 if (attr
!= nullptr)
13754 low
= attr
->value_as_address ();
13755 high
= attr_high
->value_as_address ();
13756 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13760 /* Found high w/o low attribute. */
13761 return PC_BOUNDS_INVALID
;
13763 /* Found consecutive range of addresses. */
13764 ret
= PC_BOUNDS_HIGH_LOW
;
13768 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13771 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13772 We take advantage of the fact that DW_AT_ranges does not appear
13773 in DW_TAG_compile_unit of DWO files. */
13774 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13775 unsigned int ranges_offset
= (DW_UNSND (attr
)
13776 + (need_ranges_base
13780 /* Value of the DW_AT_ranges attribute is the offset in the
13781 .debug_ranges section. */
13782 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13783 return PC_BOUNDS_INVALID
;
13784 /* Found discontinuous range of addresses. */
13785 ret
= PC_BOUNDS_RANGES
;
13788 return PC_BOUNDS_NOT_PRESENT
;
13791 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13793 return PC_BOUNDS_INVALID
;
13795 /* When using the GNU linker, .gnu.linkonce. sections are used to
13796 eliminate duplicate copies of functions and vtables and such.
13797 The linker will arbitrarily choose one and discard the others.
13798 The AT_*_pc values for such functions refer to local labels in
13799 these sections. If the section from that file was discarded, the
13800 labels are not in the output, so the relocs get a value of 0.
13801 If this is a discarded function, mark the pc bounds as invalid,
13802 so that GDB will ignore it. */
13803 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13804 return PC_BOUNDS_INVALID
;
13812 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13813 its low and high PC addresses. Do nothing if these addresses could not
13814 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13815 and HIGHPC to the high address if greater than HIGHPC. */
13818 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13819 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13820 struct dwarf2_cu
*cu
)
13822 CORE_ADDR low
, high
;
13823 struct die_info
*child
= die
->child
;
13825 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13827 *lowpc
= std::min (*lowpc
, low
);
13828 *highpc
= std::max (*highpc
, high
);
13831 /* If the language does not allow nested subprograms (either inside
13832 subprograms or lexical blocks), we're done. */
13833 if (cu
->language
!= language_ada
)
13836 /* Check all the children of the given DIE. If it contains nested
13837 subprograms, then check their pc bounds. Likewise, we need to
13838 check lexical blocks as well, as they may also contain subprogram
13840 while (child
&& child
->tag
)
13842 if (child
->tag
== DW_TAG_subprogram
13843 || child
->tag
== DW_TAG_lexical_block
)
13844 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13845 child
= child
->sibling
;
13849 /* Get the low and high pc's represented by the scope DIE, and store
13850 them in *LOWPC and *HIGHPC. If the correct values can't be
13851 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13854 get_scope_pc_bounds (struct die_info
*die
,
13855 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13856 struct dwarf2_cu
*cu
)
13858 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13859 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13860 CORE_ADDR current_low
, current_high
;
13862 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13863 >= PC_BOUNDS_RANGES
)
13865 best_low
= current_low
;
13866 best_high
= current_high
;
13870 struct die_info
*child
= die
->child
;
13872 while (child
&& child
->tag
)
13874 switch (child
->tag
) {
13875 case DW_TAG_subprogram
:
13876 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13878 case DW_TAG_namespace
:
13879 case DW_TAG_module
:
13880 /* FIXME: carlton/2004-01-16: Should we do this for
13881 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13882 that current GCC's always emit the DIEs corresponding
13883 to definitions of methods of classes as children of a
13884 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13885 the DIEs giving the declarations, which could be
13886 anywhere). But I don't see any reason why the
13887 standards says that they have to be there. */
13888 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13890 if (current_low
!= ((CORE_ADDR
) -1))
13892 best_low
= std::min (best_low
, current_low
);
13893 best_high
= std::max (best_high
, current_high
);
13901 child
= child
->sibling
;
13906 *highpc
= best_high
;
13909 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13913 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13914 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13916 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13917 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13918 struct attribute
*attr
;
13919 struct attribute
*attr_high
;
13921 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13924 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13925 if (attr
!= nullptr)
13927 CORE_ADDR low
= attr
->value_as_address ();
13928 CORE_ADDR high
= attr_high
->value_as_address ();
13930 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13933 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13934 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13935 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13939 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13940 if (attr
!= nullptr)
13942 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13943 We take advantage of the fact that DW_AT_ranges does not appear
13944 in DW_TAG_compile_unit of DWO files. */
13945 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13947 /* The value of the DW_AT_ranges attribute is the offset of the
13948 address range list in the .debug_ranges section. */
13949 unsigned long offset
= (DW_UNSND (attr
)
13950 + (need_ranges_base
? cu
->ranges_base
: 0));
13952 std::vector
<blockrange
> blockvec
;
13953 dwarf2_ranges_process (offset
, cu
,
13954 [&] (CORE_ADDR start
, CORE_ADDR end
)
13958 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13959 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13960 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13961 blockvec
.emplace_back (start
, end
);
13964 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13968 /* Check whether the producer field indicates either of GCC < 4.6, or the
13969 Intel C/C++ compiler, and cache the result in CU. */
13972 check_producer (struct dwarf2_cu
*cu
)
13976 if (cu
->producer
== NULL
)
13978 /* For unknown compilers expect their behavior is DWARF version
13981 GCC started to support .debug_types sections by -gdwarf-4 since
13982 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13983 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13984 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13985 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13987 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13989 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13990 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13992 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13994 cu
->producer_is_icc
= true;
13995 cu
->producer_is_icc_lt_14
= major
< 14;
13997 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13998 cu
->producer_is_codewarrior
= true;
14001 /* For other non-GCC compilers, expect their behavior is DWARF version
14005 cu
->checked_producer
= true;
14008 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14009 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14010 during 4.6.0 experimental. */
14013 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14015 if (!cu
->checked_producer
)
14016 check_producer (cu
);
14018 return cu
->producer_is_gxx_lt_4_6
;
14022 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14023 with incorrect is_stmt attributes. */
14026 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14028 if (!cu
->checked_producer
)
14029 check_producer (cu
);
14031 return cu
->producer_is_codewarrior
;
14034 /* Return the default accessibility type if it is not overridden by
14035 DW_AT_accessibility. */
14037 static enum dwarf_access_attribute
14038 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14040 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14042 /* The default DWARF 2 accessibility for members is public, the default
14043 accessibility for inheritance is private. */
14045 if (die
->tag
!= DW_TAG_inheritance
)
14046 return DW_ACCESS_public
;
14048 return DW_ACCESS_private
;
14052 /* DWARF 3+ defines the default accessibility a different way. The same
14053 rules apply now for DW_TAG_inheritance as for the members and it only
14054 depends on the container kind. */
14056 if (die
->parent
->tag
== DW_TAG_class_type
)
14057 return DW_ACCESS_private
;
14059 return DW_ACCESS_public
;
14063 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14064 offset. If the attribute was not found return 0, otherwise return
14065 1. If it was found but could not properly be handled, set *OFFSET
14069 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14072 struct attribute
*attr
;
14074 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14079 /* Note that we do not check for a section offset first here.
14080 This is because DW_AT_data_member_location is new in DWARF 4,
14081 so if we see it, we can assume that a constant form is really
14082 a constant and not a section offset. */
14083 if (attr
->form_is_constant ())
14084 *offset
= attr
->constant_value (0);
14085 else if (attr
->form_is_section_offset ())
14086 dwarf2_complex_location_expr_complaint ();
14087 else if (attr
->form_is_block ())
14088 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14090 dwarf2_complex_location_expr_complaint ();
14098 /* Add an aggregate field to the field list. */
14101 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14102 struct dwarf2_cu
*cu
)
14104 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14105 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14106 struct nextfield
*new_field
;
14107 struct attribute
*attr
;
14109 const char *fieldname
= "";
14111 if (die
->tag
== DW_TAG_inheritance
)
14113 fip
->baseclasses
.emplace_back ();
14114 new_field
= &fip
->baseclasses
.back ();
14118 fip
->fields
.emplace_back ();
14119 new_field
= &fip
->fields
.back ();
14122 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14123 if (attr
!= nullptr)
14124 new_field
->accessibility
= DW_UNSND (attr
);
14126 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14127 if (new_field
->accessibility
!= DW_ACCESS_public
)
14128 fip
->non_public_fields
= 1;
14130 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14131 if (attr
!= nullptr)
14132 new_field
->virtuality
= DW_UNSND (attr
);
14134 new_field
->virtuality
= DW_VIRTUALITY_none
;
14136 fp
= &new_field
->field
;
14138 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14142 /* Data member other than a C++ static data member. */
14144 /* Get type of field. */
14145 fp
->type
= die_type (die
, cu
);
14147 SET_FIELD_BITPOS (*fp
, 0);
14149 /* Get bit size of field (zero if none). */
14150 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14151 if (attr
!= nullptr)
14153 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14157 FIELD_BITSIZE (*fp
) = 0;
14160 /* Get bit offset of field. */
14161 if (handle_data_member_location (die
, cu
, &offset
))
14162 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14163 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14164 if (attr
!= nullptr)
14166 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14168 /* For big endian bits, the DW_AT_bit_offset gives the
14169 additional bit offset from the MSB of the containing
14170 anonymous object to the MSB of the field. We don't
14171 have to do anything special since we don't need to
14172 know the size of the anonymous object. */
14173 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14177 /* For little endian bits, compute the bit offset to the
14178 MSB of the anonymous object, subtract off the number of
14179 bits from the MSB of the field to the MSB of the
14180 object, and then subtract off the number of bits of
14181 the field itself. The result is the bit offset of
14182 the LSB of the field. */
14183 int anonymous_size
;
14184 int bit_offset
= DW_UNSND (attr
);
14186 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14187 if (attr
!= nullptr)
14189 /* The size of the anonymous object containing
14190 the bit field is explicit, so use the
14191 indicated size (in bytes). */
14192 anonymous_size
= DW_UNSND (attr
);
14196 /* The size of the anonymous object containing
14197 the bit field must be inferred from the type
14198 attribute of the data member containing the
14200 anonymous_size
= TYPE_LENGTH (fp
->type
);
14202 SET_FIELD_BITPOS (*fp
,
14203 (FIELD_BITPOS (*fp
)
14204 + anonymous_size
* bits_per_byte
14205 - bit_offset
- FIELD_BITSIZE (*fp
)));
14208 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14210 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14211 + attr
->constant_value (0)));
14213 /* Get name of field. */
14214 fieldname
= dwarf2_name (die
, cu
);
14215 if (fieldname
== NULL
)
14218 /* The name is already allocated along with this objfile, so we don't
14219 need to duplicate it for the type. */
14220 fp
->name
= fieldname
;
14222 /* Change accessibility for artificial fields (e.g. virtual table
14223 pointer or virtual base class pointer) to private. */
14224 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14226 FIELD_ARTIFICIAL (*fp
) = 1;
14227 new_field
->accessibility
= DW_ACCESS_private
;
14228 fip
->non_public_fields
= 1;
14231 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14233 /* C++ static member. */
14235 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14236 is a declaration, but all versions of G++ as of this writing
14237 (so through at least 3.2.1) incorrectly generate
14238 DW_TAG_variable tags. */
14240 const char *physname
;
14242 /* Get name of field. */
14243 fieldname
= dwarf2_name (die
, cu
);
14244 if (fieldname
== NULL
)
14247 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14249 /* Only create a symbol if this is an external value.
14250 new_symbol checks this and puts the value in the global symbol
14251 table, which we want. If it is not external, new_symbol
14252 will try to put the value in cu->list_in_scope which is wrong. */
14253 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14255 /* A static const member, not much different than an enum as far as
14256 we're concerned, except that we can support more types. */
14257 new_symbol (die
, NULL
, cu
);
14260 /* Get physical name. */
14261 physname
= dwarf2_physname (fieldname
, die
, cu
);
14263 /* The name is already allocated along with this objfile, so we don't
14264 need to duplicate it for the type. */
14265 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14266 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14267 FIELD_NAME (*fp
) = fieldname
;
14269 else if (die
->tag
== DW_TAG_inheritance
)
14273 /* C++ base class field. */
14274 if (handle_data_member_location (die
, cu
, &offset
))
14275 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14276 FIELD_BITSIZE (*fp
) = 0;
14277 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14278 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14280 else if (die
->tag
== DW_TAG_variant_part
)
14282 /* process_structure_scope will treat this DIE as a union. */
14283 process_structure_scope (die
, cu
);
14285 /* The variant part is relative to the start of the enclosing
14287 SET_FIELD_BITPOS (*fp
, 0);
14288 fp
->type
= get_die_type (die
, cu
);
14289 fp
->artificial
= 1;
14290 fp
->name
= "<<variant>>";
14292 /* Normally a DW_TAG_variant_part won't have a size, but our
14293 representation requires one, so set it to the maximum of the
14294 child sizes, being sure to account for the offset at which
14295 each child is seen. */
14296 if (TYPE_LENGTH (fp
->type
) == 0)
14299 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14301 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14302 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14306 TYPE_LENGTH (fp
->type
) = max
;
14310 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14313 /* Can the type given by DIE define another type? */
14316 type_can_define_types (const struct die_info
*die
)
14320 case DW_TAG_typedef
:
14321 case DW_TAG_class_type
:
14322 case DW_TAG_structure_type
:
14323 case DW_TAG_union_type
:
14324 case DW_TAG_enumeration_type
:
14332 /* Add a type definition defined in the scope of the FIP's class. */
14335 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14336 struct dwarf2_cu
*cu
)
14338 struct decl_field fp
;
14339 memset (&fp
, 0, sizeof (fp
));
14341 gdb_assert (type_can_define_types (die
));
14343 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14344 fp
.name
= dwarf2_name (die
, cu
);
14345 fp
.type
= read_type_die (die
, cu
);
14347 /* Save accessibility. */
14348 enum dwarf_access_attribute accessibility
;
14349 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14351 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14353 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14354 switch (accessibility
)
14356 case DW_ACCESS_public
:
14357 /* The assumed value if neither private nor protected. */
14359 case DW_ACCESS_private
:
14362 case DW_ACCESS_protected
:
14363 fp
.is_protected
= 1;
14366 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14369 if (die
->tag
== DW_TAG_typedef
)
14370 fip
->typedef_field_list
.push_back (fp
);
14372 fip
->nested_types_list
.push_back (fp
);
14375 /* Create the vector of fields, and attach it to the type. */
14378 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14379 struct dwarf2_cu
*cu
)
14381 int nfields
= fip
->nfields ();
14383 /* Record the field count, allocate space for the array of fields,
14384 and create blank accessibility bitfields if necessary. */
14385 TYPE_NFIELDS (type
) = nfields
;
14386 TYPE_FIELDS (type
) = (struct field
*)
14387 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14389 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14391 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14393 TYPE_FIELD_PRIVATE_BITS (type
) =
14394 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14395 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14397 TYPE_FIELD_PROTECTED_BITS (type
) =
14398 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14399 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14401 TYPE_FIELD_IGNORE_BITS (type
) =
14402 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14403 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14406 /* If the type has baseclasses, allocate and clear a bit vector for
14407 TYPE_FIELD_VIRTUAL_BITS. */
14408 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14410 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14411 unsigned char *pointer
;
14413 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14414 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14415 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14416 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14417 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14420 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14422 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14424 for (int index
= 0; index
< nfields
; ++index
)
14426 struct nextfield
&field
= fip
->fields
[index
];
14428 if (field
.variant
.is_discriminant
)
14429 di
->discriminant_index
= index
;
14430 else if (field
.variant
.default_branch
)
14431 di
->default_index
= index
;
14433 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14437 /* Copy the saved-up fields into the field vector. */
14438 for (int i
= 0; i
< nfields
; ++i
)
14440 struct nextfield
&field
14441 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14442 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14444 TYPE_FIELD (type
, i
) = field
.field
;
14445 switch (field
.accessibility
)
14447 case DW_ACCESS_private
:
14448 if (cu
->language
!= language_ada
)
14449 SET_TYPE_FIELD_PRIVATE (type
, i
);
14452 case DW_ACCESS_protected
:
14453 if (cu
->language
!= language_ada
)
14454 SET_TYPE_FIELD_PROTECTED (type
, i
);
14457 case DW_ACCESS_public
:
14461 /* Unknown accessibility. Complain and treat it as public. */
14463 complaint (_("unsupported accessibility %d"),
14464 field
.accessibility
);
14468 if (i
< fip
->baseclasses
.size ())
14470 switch (field
.virtuality
)
14472 case DW_VIRTUALITY_virtual
:
14473 case DW_VIRTUALITY_pure_virtual
:
14474 if (cu
->language
== language_ada
)
14475 error (_("unexpected virtuality in component of Ada type"));
14476 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14483 /* Return true if this member function is a constructor, false
14487 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14489 const char *fieldname
;
14490 const char *type_name
;
14493 if (die
->parent
== NULL
)
14496 if (die
->parent
->tag
!= DW_TAG_structure_type
14497 && die
->parent
->tag
!= DW_TAG_union_type
14498 && die
->parent
->tag
!= DW_TAG_class_type
)
14501 fieldname
= dwarf2_name (die
, cu
);
14502 type_name
= dwarf2_name (die
->parent
, cu
);
14503 if (fieldname
== NULL
|| type_name
== NULL
)
14506 len
= strlen (fieldname
);
14507 return (strncmp (fieldname
, type_name
, len
) == 0
14508 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14511 /* Check if the given VALUE is a recognized enum
14512 dwarf_defaulted_attribute constant according to DWARF5 spec,
14516 is_valid_DW_AT_defaulted (ULONGEST value
)
14520 case DW_DEFAULTED_no
:
14521 case DW_DEFAULTED_in_class
:
14522 case DW_DEFAULTED_out_of_class
:
14526 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14530 /* Add a member function to the proper fieldlist. */
14533 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14534 struct type
*type
, struct dwarf2_cu
*cu
)
14536 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14537 struct attribute
*attr
;
14539 struct fnfieldlist
*flp
= nullptr;
14540 struct fn_field
*fnp
;
14541 const char *fieldname
;
14542 struct type
*this_type
;
14543 enum dwarf_access_attribute accessibility
;
14545 if (cu
->language
== language_ada
)
14546 error (_("unexpected member function in Ada type"));
14548 /* Get name of member function. */
14549 fieldname
= dwarf2_name (die
, cu
);
14550 if (fieldname
== NULL
)
14553 /* Look up member function name in fieldlist. */
14554 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14556 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14558 flp
= &fip
->fnfieldlists
[i
];
14563 /* Create a new fnfieldlist if necessary. */
14564 if (flp
== nullptr)
14566 fip
->fnfieldlists
.emplace_back ();
14567 flp
= &fip
->fnfieldlists
.back ();
14568 flp
->name
= fieldname
;
14569 i
= fip
->fnfieldlists
.size () - 1;
14572 /* Create a new member function field and add it to the vector of
14574 flp
->fnfields
.emplace_back ();
14575 fnp
= &flp
->fnfields
.back ();
14577 /* Delay processing of the physname until later. */
14578 if (cu
->language
== language_cplus
)
14579 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14583 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14584 fnp
->physname
= physname
? physname
: "";
14587 fnp
->type
= alloc_type (objfile
);
14588 this_type
= read_type_die (die
, cu
);
14589 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14591 int nparams
= TYPE_NFIELDS (this_type
);
14593 /* TYPE is the domain of this method, and THIS_TYPE is the type
14594 of the method itself (TYPE_CODE_METHOD). */
14595 smash_to_method_type (fnp
->type
, type
,
14596 TYPE_TARGET_TYPE (this_type
),
14597 TYPE_FIELDS (this_type
),
14598 TYPE_NFIELDS (this_type
),
14599 TYPE_VARARGS (this_type
));
14601 /* Handle static member functions.
14602 Dwarf2 has no clean way to discern C++ static and non-static
14603 member functions. G++ helps GDB by marking the first
14604 parameter for non-static member functions (which is the this
14605 pointer) as artificial. We obtain this information from
14606 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14607 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14608 fnp
->voffset
= VOFFSET_STATIC
;
14611 complaint (_("member function type missing for '%s'"),
14612 dwarf2_full_name (fieldname
, die
, cu
));
14614 /* Get fcontext from DW_AT_containing_type if present. */
14615 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14616 fnp
->fcontext
= die_containing_type (die
, cu
);
14618 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14619 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14621 /* Get accessibility. */
14622 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14623 if (attr
!= nullptr)
14624 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14626 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14627 switch (accessibility
)
14629 case DW_ACCESS_private
:
14630 fnp
->is_private
= 1;
14632 case DW_ACCESS_protected
:
14633 fnp
->is_protected
= 1;
14637 /* Check for artificial methods. */
14638 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14639 if (attr
&& DW_UNSND (attr
) != 0)
14640 fnp
->is_artificial
= 1;
14642 /* Check for defaulted methods. */
14643 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14644 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14645 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14647 /* Check for deleted methods. */
14648 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14649 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14650 fnp
->is_deleted
= 1;
14652 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14654 /* Get index in virtual function table if it is a virtual member
14655 function. For older versions of GCC, this is an offset in the
14656 appropriate virtual table, as specified by DW_AT_containing_type.
14657 For everyone else, it is an expression to be evaluated relative
14658 to the object address. */
14660 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14661 if (attr
!= nullptr)
14663 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14665 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14667 /* Old-style GCC. */
14668 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14670 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14671 || (DW_BLOCK (attr
)->size
> 1
14672 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14673 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14675 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14676 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14677 dwarf2_complex_location_expr_complaint ();
14679 fnp
->voffset
/= cu
->header
.addr_size
;
14683 dwarf2_complex_location_expr_complaint ();
14685 if (!fnp
->fcontext
)
14687 /* If there is no `this' field and no DW_AT_containing_type,
14688 we cannot actually find a base class context for the
14690 if (TYPE_NFIELDS (this_type
) == 0
14691 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14693 complaint (_("cannot determine context for virtual member "
14694 "function \"%s\" (offset %s)"),
14695 fieldname
, sect_offset_str (die
->sect_off
));
14700 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14704 else if (attr
->form_is_section_offset ())
14706 dwarf2_complex_location_expr_complaint ();
14710 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14716 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14717 if (attr
&& DW_UNSND (attr
))
14719 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14720 complaint (_("Member function \"%s\" (offset %s) is virtual "
14721 "but the vtable offset is not specified"),
14722 fieldname
, sect_offset_str (die
->sect_off
));
14723 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14724 TYPE_CPLUS_DYNAMIC (type
) = 1;
14729 /* Create the vector of member function fields, and attach it to the type. */
14732 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14733 struct dwarf2_cu
*cu
)
14735 if (cu
->language
== language_ada
)
14736 error (_("unexpected member functions in Ada type"));
14738 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14739 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14741 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14743 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14745 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14746 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14748 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14749 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14750 fn_flp
->fn_fields
= (struct fn_field
*)
14751 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14753 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14754 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14757 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14760 /* Returns non-zero if NAME is the name of a vtable member in CU's
14761 language, zero otherwise. */
14763 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14765 static const char vptr
[] = "_vptr";
14767 /* Look for the C++ form of the vtable. */
14768 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14774 /* GCC outputs unnamed structures that are really pointers to member
14775 functions, with the ABI-specified layout. If TYPE describes
14776 such a structure, smash it into a member function type.
14778 GCC shouldn't do this; it should just output pointer to member DIEs.
14779 This is GCC PR debug/28767. */
14782 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14784 struct type
*pfn_type
, *self_type
, *new_type
;
14786 /* Check for a structure with no name and two children. */
14787 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14790 /* Check for __pfn and __delta members. */
14791 if (TYPE_FIELD_NAME (type
, 0) == NULL
14792 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14793 || TYPE_FIELD_NAME (type
, 1) == NULL
14794 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14797 /* Find the type of the method. */
14798 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14799 if (pfn_type
== NULL
14800 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14801 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14804 /* Look for the "this" argument. */
14805 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14806 if (TYPE_NFIELDS (pfn_type
) == 0
14807 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14808 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14811 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14812 new_type
= alloc_type (objfile
);
14813 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14814 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14815 TYPE_VARARGS (pfn_type
));
14816 smash_to_methodptr_type (type
, new_type
);
14819 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14820 appropriate error checking and issuing complaints if there is a
14824 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14826 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14828 if (attr
== nullptr)
14831 if (!attr
->form_is_constant ())
14833 complaint (_("DW_AT_alignment must have constant form"
14834 " - DIE at %s [in module %s]"),
14835 sect_offset_str (die
->sect_off
),
14836 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14841 if (attr
->form
== DW_FORM_sdata
)
14843 LONGEST val
= DW_SND (attr
);
14846 complaint (_("DW_AT_alignment value must not be negative"
14847 " - DIE at %s [in module %s]"),
14848 sect_offset_str (die
->sect_off
),
14849 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14855 align
= DW_UNSND (attr
);
14859 complaint (_("DW_AT_alignment value must not be zero"
14860 " - DIE at %s [in module %s]"),
14861 sect_offset_str (die
->sect_off
),
14862 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14865 if ((align
& (align
- 1)) != 0)
14867 complaint (_("DW_AT_alignment value must be a power of 2"
14868 " - DIE at %s [in module %s]"),
14869 sect_offset_str (die
->sect_off
),
14870 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14877 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14878 the alignment for TYPE. */
14881 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14884 if (!set_type_align (type
, get_alignment (cu
, die
)))
14885 complaint (_("DW_AT_alignment value too large"
14886 " - DIE at %s [in module %s]"),
14887 sect_offset_str (die
->sect_off
),
14888 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14891 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14892 constant for a type, according to DWARF5 spec, Table 5.5. */
14895 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14900 case DW_CC_pass_by_reference
:
14901 case DW_CC_pass_by_value
:
14905 complaint (_("unrecognized DW_AT_calling_convention value "
14906 "(%s) for a type"), pulongest (value
));
14911 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14912 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14913 also according to GNU-specific values (see include/dwarf2.h). */
14916 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14921 case DW_CC_program
:
14925 case DW_CC_GNU_renesas_sh
:
14926 case DW_CC_GNU_borland_fastcall_i386
:
14927 case DW_CC_GDB_IBM_OpenCL
:
14931 complaint (_("unrecognized DW_AT_calling_convention value "
14932 "(%s) for a subroutine"), pulongest (value
));
14937 /* Called when we find the DIE that starts a structure or union scope
14938 (definition) to create a type for the structure or union. Fill in
14939 the type's name and general properties; the members will not be
14940 processed until process_structure_scope. A symbol table entry for
14941 the type will also not be done until process_structure_scope (assuming
14942 the type has a name).
14944 NOTE: we need to call these functions regardless of whether or not the
14945 DIE has a DW_AT_name attribute, since it might be an anonymous
14946 structure or union. This gets the type entered into our set of
14947 user defined types. */
14949 static struct type
*
14950 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14952 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14954 struct attribute
*attr
;
14957 /* If the definition of this type lives in .debug_types, read that type.
14958 Don't follow DW_AT_specification though, that will take us back up
14959 the chain and we want to go down. */
14960 attr
= die
->attr (DW_AT_signature
);
14961 if (attr
!= nullptr)
14963 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14965 /* The type's CU may not be the same as CU.
14966 Ensure TYPE is recorded with CU in die_type_hash. */
14967 return set_die_type (die
, type
, cu
);
14970 type
= alloc_type (objfile
);
14971 INIT_CPLUS_SPECIFIC (type
);
14973 name
= dwarf2_name (die
, cu
);
14976 if (cu
->language
== language_cplus
14977 || cu
->language
== language_d
14978 || cu
->language
== language_rust
)
14980 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14982 /* dwarf2_full_name might have already finished building the DIE's
14983 type. If so, there is no need to continue. */
14984 if (get_die_type (die
, cu
) != NULL
)
14985 return get_die_type (die
, cu
);
14987 TYPE_NAME (type
) = full_name
;
14991 /* The name is already allocated along with this objfile, so
14992 we don't need to duplicate it for the type. */
14993 TYPE_NAME (type
) = name
;
14997 if (die
->tag
== DW_TAG_structure_type
)
14999 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15001 else if (die
->tag
== DW_TAG_union_type
)
15003 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15005 else if (die
->tag
== DW_TAG_variant_part
)
15007 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15008 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15012 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15015 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15016 TYPE_DECLARED_CLASS (type
) = 1;
15018 /* Store the calling convention in the type if it's available in
15019 the die. Otherwise the calling convention remains set to
15020 the default value DW_CC_normal. */
15021 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15022 if (attr
!= nullptr
15023 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15025 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15026 TYPE_CPLUS_CALLING_CONVENTION (type
)
15027 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15030 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15031 if (attr
!= nullptr)
15033 if (attr
->form_is_constant ())
15034 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15037 /* For the moment, dynamic type sizes are not supported
15038 by GDB's struct type. The actual size is determined
15039 on-demand when resolving the type of a given object,
15040 so set the type's length to zero for now. Otherwise,
15041 we record an expression as the length, and that expression
15042 could lead to a very large value, which could eventually
15043 lead to us trying to allocate that much memory when creating
15044 a value of that type. */
15045 TYPE_LENGTH (type
) = 0;
15050 TYPE_LENGTH (type
) = 0;
15053 maybe_set_alignment (cu
, die
, type
);
15055 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15057 /* ICC<14 does not output the required DW_AT_declaration on
15058 incomplete types, but gives them a size of zero. */
15059 TYPE_STUB (type
) = 1;
15062 TYPE_STUB_SUPPORTED (type
) = 1;
15064 if (die_is_declaration (die
, cu
))
15065 TYPE_STUB (type
) = 1;
15066 else if (attr
== NULL
&& die
->child
== NULL
15067 && producer_is_realview (cu
->producer
))
15068 /* RealView does not output the required DW_AT_declaration
15069 on incomplete types. */
15070 TYPE_STUB (type
) = 1;
15072 /* We need to add the type field to the die immediately so we don't
15073 infinitely recurse when dealing with pointers to the structure
15074 type within the structure itself. */
15075 set_die_type (die
, type
, cu
);
15077 /* set_die_type should be already done. */
15078 set_descriptive_type (type
, die
, cu
);
15083 /* A helper for process_structure_scope that handles a single member
15087 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15088 struct field_info
*fi
,
15089 std::vector
<struct symbol
*> *template_args
,
15090 struct dwarf2_cu
*cu
)
15092 if (child_die
->tag
== DW_TAG_member
15093 || child_die
->tag
== DW_TAG_variable
15094 || child_die
->tag
== DW_TAG_variant_part
)
15096 /* NOTE: carlton/2002-11-05: A C++ static data member
15097 should be a DW_TAG_member that is a declaration, but
15098 all versions of G++ as of this writing (so through at
15099 least 3.2.1) incorrectly generate DW_TAG_variable
15100 tags for them instead. */
15101 dwarf2_add_field (fi
, child_die
, cu
);
15103 else if (child_die
->tag
== DW_TAG_subprogram
)
15105 /* Rust doesn't have member functions in the C++ sense.
15106 However, it does emit ordinary functions as children
15107 of a struct DIE. */
15108 if (cu
->language
== language_rust
)
15109 read_func_scope (child_die
, cu
);
15112 /* C++ member function. */
15113 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15116 else if (child_die
->tag
== DW_TAG_inheritance
)
15118 /* C++ base class field. */
15119 dwarf2_add_field (fi
, child_die
, cu
);
15121 else if (type_can_define_types (child_die
))
15122 dwarf2_add_type_defn (fi
, child_die
, cu
);
15123 else if (child_die
->tag
== DW_TAG_template_type_param
15124 || child_die
->tag
== DW_TAG_template_value_param
)
15126 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15129 template_args
->push_back (arg
);
15131 else if (child_die
->tag
== DW_TAG_variant
)
15133 /* In a variant we want to get the discriminant and also add a
15134 field for our sole member child. */
15135 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15137 for (die_info
*variant_child
= child_die
->child
;
15138 variant_child
!= NULL
;
15139 variant_child
= variant_child
->sibling
)
15141 if (variant_child
->tag
== DW_TAG_member
)
15143 handle_struct_member_die (variant_child
, type
, fi
,
15144 template_args
, cu
);
15145 /* Only handle the one. */
15150 /* We don't handle this but we might as well report it if we see
15152 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15153 complaint (_("DW_AT_discr_list is not supported yet"
15154 " - DIE at %s [in module %s]"),
15155 sect_offset_str (child_die
->sect_off
),
15156 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15158 /* The first field was just added, so we can stash the
15159 discriminant there. */
15160 gdb_assert (!fi
->fields
.empty ());
15162 fi
->fields
.back ().variant
.default_branch
= true;
15164 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15168 /* Finish creating a structure or union type, including filling in
15169 its members and creating a symbol for it. */
15172 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15174 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15175 struct die_info
*child_die
;
15178 type
= get_die_type (die
, cu
);
15180 type
= read_structure_type (die
, cu
);
15182 /* When reading a DW_TAG_variant_part, we need to notice when we
15183 read the discriminant member, so we can record it later in the
15184 discriminant_info. */
15185 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15186 sect_offset discr_offset
{};
15187 bool has_template_parameters
= false;
15189 if (is_variant_part
)
15191 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15194 /* Maybe it's a univariant form, an extension we support.
15195 In this case arrange not to check the offset. */
15196 is_variant_part
= false;
15198 else if (discr
->form_is_ref ())
15200 struct dwarf2_cu
*target_cu
= cu
;
15201 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15203 discr_offset
= target_die
->sect_off
;
15207 complaint (_("DW_AT_discr does not have DIE reference form"
15208 " - DIE at %s [in module %s]"),
15209 sect_offset_str (die
->sect_off
),
15210 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15211 is_variant_part
= false;
15215 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15217 struct field_info fi
;
15218 std::vector
<struct symbol
*> template_args
;
15220 child_die
= die
->child
;
15222 while (child_die
&& child_die
->tag
)
15224 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15226 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15227 fi
.fields
.back ().variant
.is_discriminant
= true;
15229 child_die
= child_die
->sibling
;
15232 /* Attach template arguments to type. */
15233 if (!template_args
.empty ())
15235 has_template_parameters
= true;
15236 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15237 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15238 TYPE_TEMPLATE_ARGUMENTS (type
)
15239 = XOBNEWVEC (&objfile
->objfile_obstack
,
15241 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15242 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15243 template_args
.data (),
15244 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15245 * sizeof (struct symbol
*)));
15248 /* Attach fields and member functions to the type. */
15249 if (fi
.nfields () > 0)
15250 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15251 if (!fi
.fnfieldlists
.empty ())
15253 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15255 /* Get the type which refers to the base class (possibly this
15256 class itself) which contains the vtable pointer for the current
15257 class from the DW_AT_containing_type attribute. This use of
15258 DW_AT_containing_type is a GNU extension. */
15260 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15262 struct type
*t
= die_containing_type (die
, cu
);
15264 set_type_vptr_basetype (type
, t
);
15269 /* Our own class provides vtbl ptr. */
15270 for (i
= TYPE_NFIELDS (t
) - 1;
15271 i
>= TYPE_N_BASECLASSES (t
);
15274 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15276 if (is_vtable_name (fieldname
, cu
))
15278 set_type_vptr_fieldno (type
, i
);
15283 /* Complain if virtual function table field not found. */
15284 if (i
< TYPE_N_BASECLASSES (t
))
15285 complaint (_("virtual function table pointer "
15286 "not found when defining class '%s'"),
15287 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15291 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15294 else if (cu
->producer
15295 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15297 /* The IBM XLC compiler does not provide direct indication
15298 of the containing type, but the vtable pointer is
15299 always named __vfp. */
15303 for (i
= TYPE_NFIELDS (type
) - 1;
15304 i
>= TYPE_N_BASECLASSES (type
);
15307 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15309 set_type_vptr_fieldno (type
, i
);
15310 set_type_vptr_basetype (type
, type
);
15317 /* Copy fi.typedef_field_list linked list elements content into the
15318 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15319 if (!fi
.typedef_field_list
.empty ())
15321 int count
= fi
.typedef_field_list
.size ();
15323 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15324 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15325 = ((struct decl_field
*)
15327 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15328 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15330 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15331 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15334 /* Copy fi.nested_types_list linked list elements content into the
15335 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15336 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15338 int count
= fi
.nested_types_list
.size ();
15340 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15341 TYPE_NESTED_TYPES_ARRAY (type
)
15342 = ((struct decl_field
*)
15343 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15344 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15346 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15347 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15351 quirk_gcc_member_function_pointer (type
, objfile
);
15352 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15353 cu
->rust_unions
.push_back (type
);
15355 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15356 snapshots) has been known to create a die giving a declaration
15357 for a class that has, as a child, a die giving a definition for a
15358 nested class. So we have to process our children even if the
15359 current die is a declaration. Normally, of course, a declaration
15360 won't have any children at all. */
15362 child_die
= die
->child
;
15364 while (child_die
!= NULL
&& child_die
->tag
)
15366 if (child_die
->tag
== DW_TAG_member
15367 || child_die
->tag
== DW_TAG_variable
15368 || child_die
->tag
== DW_TAG_inheritance
15369 || child_die
->tag
== DW_TAG_template_value_param
15370 || child_die
->tag
== DW_TAG_template_type_param
)
15375 process_die (child_die
, cu
);
15377 child_die
= child_die
->sibling
;
15380 /* Do not consider external references. According to the DWARF standard,
15381 these DIEs are identified by the fact that they have no byte_size
15382 attribute, and a declaration attribute. */
15383 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15384 || !die_is_declaration (die
, cu
))
15386 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15388 if (has_template_parameters
)
15390 struct symtab
*symtab
;
15391 if (sym
!= nullptr)
15392 symtab
= symbol_symtab (sym
);
15393 else if (cu
->line_header
!= nullptr)
15395 /* Any related symtab will do. */
15397 = cu
->line_header
->file_names ()[0].symtab
;
15402 complaint (_("could not find suitable "
15403 "symtab for template parameter"
15404 " - DIE at %s [in module %s]"),
15405 sect_offset_str (die
->sect_off
),
15406 objfile_name (objfile
));
15409 if (symtab
!= nullptr)
15411 /* Make sure that the symtab is set on the new symbols.
15412 Even though they don't appear in this symtab directly,
15413 other parts of gdb assume that symbols do, and this is
15414 reasonably true. */
15415 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15416 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15422 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15423 update TYPE using some information only available in DIE's children. */
15426 update_enumeration_type_from_children (struct die_info
*die
,
15428 struct dwarf2_cu
*cu
)
15430 struct die_info
*child_die
;
15431 int unsigned_enum
= 1;
15434 auto_obstack obstack
;
15436 for (child_die
= die
->child
;
15437 child_die
!= NULL
&& child_die
->tag
;
15438 child_die
= child_die
->sibling
)
15440 struct attribute
*attr
;
15442 const gdb_byte
*bytes
;
15443 struct dwarf2_locexpr_baton
*baton
;
15446 if (child_die
->tag
!= DW_TAG_enumerator
)
15449 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15453 name
= dwarf2_name (child_die
, cu
);
15455 name
= "<anonymous enumerator>";
15457 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15458 &value
, &bytes
, &baton
);
15466 if (count_one_bits_ll (value
) >= 2)
15470 /* If we already know that the enum type is neither unsigned, nor
15471 a flag type, no need to look at the rest of the enumerates. */
15472 if (!unsigned_enum
&& !flag_enum
)
15477 TYPE_UNSIGNED (type
) = 1;
15479 TYPE_FLAG_ENUM (type
) = 1;
15482 /* Given a DW_AT_enumeration_type die, set its type. We do not
15483 complete the type's fields yet, or create any symbols. */
15485 static struct type
*
15486 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15488 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15490 struct attribute
*attr
;
15493 /* If the definition of this type lives in .debug_types, read that type.
15494 Don't follow DW_AT_specification though, that will take us back up
15495 the chain and we want to go down. */
15496 attr
= die
->attr (DW_AT_signature
);
15497 if (attr
!= nullptr)
15499 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15501 /* The type's CU may not be the same as CU.
15502 Ensure TYPE is recorded with CU in die_type_hash. */
15503 return set_die_type (die
, type
, cu
);
15506 type
= alloc_type (objfile
);
15508 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15509 name
= dwarf2_full_name (NULL
, die
, cu
);
15511 TYPE_NAME (type
) = name
;
15513 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15516 struct type
*underlying_type
= die_type (die
, cu
);
15518 TYPE_TARGET_TYPE (type
) = underlying_type
;
15521 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15522 if (attr
!= nullptr)
15524 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15528 TYPE_LENGTH (type
) = 0;
15531 maybe_set_alignment (cu
, die
, type
);
15533 /* The enumeration DIE can be incomplete. In Ada, any type can be
15534 declared as private in the package spec, and then defined only
15535 inside the package body. Such types are known as Taft Amendment
15536 Types. When another package uses such a type, an incomplete DIE
15537 may be generated by the compiler. */
15538 if (die_is_declaration (die
, cu
))
15539 TYPE_STUB (type
) = 1;
15541 /* Finish the creation of this type by using the enum's children.
15542 We must call this even when the underlying type has been provided
15543 so that we can determine if we're looking at a "flag" enum. */
15544 update_enumeration_type_from_children (die
, type
, cu
);
15546 /* If this type has an underlying type that is not a stub, then we
15547 may use its attributes. We always use the "unsigned" attribute
15548 in this situation, because ordinarily we guess whether the type
15549 is unsigned -- but the guess can be wrong and the underlying type
15550 can tell us the reality. However, we defer to a local size
15551 attribute if one exists, because this lets the compiler override
15552 the underlying type if needed. */
15553 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15555 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15556 underlying_type
= check_typedef (underlying_type
);
15557 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15558 if (TYPE_LENGTH (type
) == 0)
15559 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15560 if (TYPE_RAW_ALIGN (type
) == 0
15561 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15562 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15565 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15567 return set_die_type (die
, type
, cu
);
15570 /* Given a pointer to a die which begins an enumeration, process all
15571 the dies that define the members of the enumeration, and create the
15572 symbol for the enumeration type.
15574 NOTE: We reverse the order of the element list. */
15577 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15579 struct type
*this_type
;
15581 this_type
= get_die_type (die
, cu
);
15582 if (this_type
== NULL
)
15583 this_type
= read_enumeration_type (die
, cu
);
15585 if (die
->child
!= NULL
)
15587 struct die_info
*child_die
;
15588 struct symbol
*sym
;
15589 std::vector
<struct field
> fields
;
15592 child_die
= die
->child
;
15593 while (child_die
&& child_die
->tag
)
15595 if (child_die
->tag
!= DW_TAG_enumerator
)
15597 process_die (child_die
, cu
);
15601 name
= dwarf2_name (child_die
, cu
);
15604 sym
= new_symbol (child_die
, this_type
, cu
);
15606 fields
.emplace_back ();
15607 struct field
&field
= fields
.back ();
15609 FIELD_NAME (field
) = sym
->linkage_name ();
15610 FIELD_TYPE (field
) = NULL
;
15611 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15612 FIELD_BITSIZE (field
) = 0;
15616 child_die
= child_die
->sibling
;
15619 if (!fields
.empty ())
15621 TYPE_NFIELDS (this_type
) = fields
.size ();
15622 TYPE_FIELDS (this_type
) = (struct field
*)
15623 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15624 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15625 sizeof (struct field
) * fields
.size ());
15629 /* If we are reading an enum from a .debug_types unit, and the enum
15630 is a declaration, and the enum is not the signatured type in the
15631 unit, then we do not want to add a symbol for it. Adding a
15632 symbol would in some cases obscure the true definition of the
15633 enum, giving users an incomplete type when the definition is
15634 actually available. Note that we do not want to do this for all
15635 enums which are just declarations, because C++0x allows forward
15636 enum declarations. */
15637 if (cu
->per_cu
->is_debug_types
15638 && die_is_declaration (die
, cu
))
15640 struct signatured_type
*sig_type
;
15642 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15643 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15644 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15648 new_symbol (die
, this_type
, cu
);
15651 /* Extract all information from a DW_TAG_array_type DIE and put it in
15652 the DIE's type field. For now, this only handles one dimensional
15655 static struct type
*
15656 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15659 struct die_info
*child_die
;
15661 struct type
*element_type
, *range_type
, *index_type
;
15662 struct attribute
*attr
;
15664 struct dynamic_prop
*byte_stride_prop
= NULL
;
15665 unsigned int bit_stride
= 0;
15667 element_type
= die_type (die
, cu
);
15669 /* The die_type call above may have already set the type for this DIE. */
15670 type
= get_die_type (die
, cu
);
15674 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15678 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15681 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15682 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15686 complaint (_("unable to read array DW_AT_byte_stride "
15687 " - DIE at %s [in module %s]"),
15688 sect_offset_str (die
->sect_off
),
15689 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15690 /* Ignore this attribute. We will likely not be able to print
15691 arrays of this type correctly, but there is little we can do
15692 to help if we cannot read the attribute's value. */
15693 byte_stride_prop
= NULL
;
15697 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15699 bit_stride
= DW_UNSND (attr
);
15701 /* Irix 6.2 native cc creates array types without children for
15702 arrays with unspecified length. */
15703 if (die
->child
== NULL
)
15705 index_type
= objfile_type (objfile
)->builtin_int
;
15706 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15707 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15708 byte_stride_prop
, bit_stride
);
15709 return set_die_type (die
, type
, cu
);
15712 std::vector
<struct type
*> range_types
;
15713 child_die
= die
->child
;
15714 while (child_die
&& child_die
->tag
)
15716 if (child_die
->tag
== DW_TAG_subrange_type
)
15718 struct type
*child_type
= read_type_die (child_die
, cu
);
15720 if (child_type
!= NULL
)
15722 /* The range type was succesfully read. Save it for the
15723 array type creation. */
15724 range_types
.push_back (child_type
);
15727 child_die
= child_die
->sibling
;
15730 /* Dwarf2 dimensions are output from left to right, create the
15731 necessary array types in backwards order. */
15733 type
= element_type
;
15735 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15739 while (i
< range_types
.size ())
15740 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15741 byte_stride_prop
, bit_stride
);
15745 size_t ndim
= range_types
.size ();
15747 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15748 byte_stride_prop
, bit_stride
);
15751 /* Understand Dwarf2 support for vector types (like they occur on
15752 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15753 array type. This is not part of the Dwarf2/3 standard yet, but a
15754 custom vendor extension. The main difference between a regular
15755 array and the vector variant is that vectors are passed by value
15757 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15758 if (attr
!= nullptr)
15759 make_vector_type (type
);
15761 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15762 implementation may choose to implement triple vectors using this
15764 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15765 if (attr
!= nullptr)
15767 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15768 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15770 complaint (_("DW_AT_byte_size for array type smaller "
15771 "than the total size of elements"));
15774 name
= dwarf2_name (die
, cu
);
15776 TYPE_NAME (type
) = name
;
15778 maybe_set_alignment (cu
, die
, type
);
15780 /* Install the type in the die. */
15781 set_die_type (die
, type
, cu
);
15783 /* set_die_type should be already done. */
15784 set_descriptive_type (type
, die
, cu
);
15789 static enum dwarf_array_dim_ordering
15790 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15792 struct attribute
*attr
;
15794 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15796 if (attr
!= nullptr)
15797 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15799 /* GNU F77 is a special case, as at 08/2004 array type info is the
15800 opposite order to the dwarf2 specification, but data is still
15801 laid out as per normal fortran.
15803 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15804 version checking. */
15806 if (cu
->language
== language_fortran
15807 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15809 return DW_ORD_row_major
;
15812 switch (cu
->language_defn
->la_array_ordering
)
15814 case array_column_major
:
15815 return DW_ORD_col_major
;
15816 case array_row_major
:
15818 return DW_ORD_row_major
;
15822 /* Extract all information from a DW_TAG_set_type DIE and put it in
15823 the DIE's type field. */
15825 static struct type
*
15826 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15828 struct type
*domain_type
, *set_type
;
15829 struct attribute
*attr
;
15831 domain_type
= die_type (die
, cu
);
15833 /* The die_type call above may have already set the type for this DIE. */
15834 set_type
= get_die_type (die
, cu
);
15838 set_type
= create_set_type (NULL
, domain_type
);
15840 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15841 if (attr
!= nullptr)
15842 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15844 maybe_set_alignment (cu
, die
, set_type
);
15846 return set_die_type (die
, set_type
, cu
);
15849 /* A helper for read_common_block that creates a locexpr baton.
15850 SYM is the symbol which we are marking as computed.
15851 COMMON_DIE is the DIE for the common block.
15852 COMMON_LOC is the location expression attribute for the common
15854 MEMBER_LOC is the location expression attribute for the particular
15855 member of the common block that we are processing.
15856 CU is the CU from which the above come. */
15859 mark_common_block_symbol_computed (struct symbol
*sym
,
15860 struct die_info
*common_die
,
15861 struct attribute
*common_loc
,
15862 struct attribute
*member_loc
,
15863 struct dwarf2_cu
*cu
)
15865 struct dwarf2_per_objfile
*dwarf2_per_objfile
15866 = cu
->per_cu
->dwarf2_per_objfile
;
15867 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15868 struct dwarf2_locexpr_baton
*baton
;
15870 unsigned int cu_off
;
15871 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15872 LONGEST offset
= 0;
15874 gdb_assert (common_loc
&& member_loc
);
15875 gdb_assert (common_loc
->form_is_block ());
15876 gdb_assert (member_loc
->form_is_block ()
15877 || member_loc
->form_is_constant ());
15879 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15880 baton
->per_cu
= cu
->per_cu
;
15881 gdb_assert (baton
->per_cu
);
15883 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15885 if (member_loc
->form_is_constant ())
15887 offset
= member_loc
->constant_value (0);
15888 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15891 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15893 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15896 *ptr
++ = DW_OP_call4
;
15897 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15898 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15901 if (member_loc
->form_is_constant ())
15903 *ptr
++ = DW_OP_addr
;
15904 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15905 ptr
+= cu
->header
.addr_size
;
15909 /* We have to copy the data here, because DW_OP_call4 will only
15910 use a DW_AT_location attribute. */
15911 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15912 ptr
+= DW_BLOCK (member_loc
)->size
;
15915 *ptr
++ = DW_OP_plus
;
15916 gdb_assert (ptr
- baton
->data
== baton
->size
);
15918 SYMBOL_LOCATION_BATON (sym
) = baton
;
15919 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15922 /* Create appropriate locally-scoped variables for all the
15923 DW_TAG_common_block entries. Also create a struct common_block
15924 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15925 is used to separate the common blocks name namespace from regular
15929 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15931 struct attribute
*attr
;
15933 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15934 if (attr
!= nullptr)
15936 /* Support the .debug_loc offsets. */
15937 if (attr
->form_is_block ())
15941 else if (attr
->form_is_section_offset ())
15943 dwarf2_complex_location_expr_complaint ();
15948 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15949 "common block member");
15954 if (die
->child
!= NULL
)
15956 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15957 struct die_info
*child_die
;
15958 size_t n_entries
= 0, size
;
15959 struct common_block
*common_block
;
15960 struct symbol
*sym
;
15962 for (child_die
= die
->child
;
15963 child_die
&& child_die
->tag
;
15964 child_die
= child_die
->sibling
)
15967 size
= (sizeof (struct common_block
)
15968 + (n_entries
- 1) * sizeof (struct symbol
*));
15970 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15972 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15973 common_block
->n_entries
= 0;
15975 for (child_die
= die
->child
;
15976 child_die
&& child_die
->tag
;
15977 child_die
= child_die
->sibling
)
15979 /* Create the symbol in the DW_TAG_common_block block in the current
15981 sym
= new_symbol (child_die
, NULL
, cu
);
15984 struct attribute
*member_loc
;
15986 common_block
->contents
[common_block
->n_entries
++] = sym
;
15988 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15992 /* GDB has handled this for a long time, but it is
15993 not specified by DWARF. It seems to have been
15994 emitted by gfortran at least as recently as:
15995 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15996 complaint (_("Variable in common block has "
15997 "DW_AT_data_member_location "
15998 "- DIE at %s [in module %s]"),
15999 sect_offset_str (child_die
->sect_off
),
16000 objfile_name (objfile
));
16002 if (member_loc
->form_is_section_offset ())
16003 dwarf2_complex_location_expr_complaint ();
16004 else if (member_loc
->form_is_constant ()
16005 || member_loc
->form_is_block ())
16007 if (attr
!= nullptr)
16008 mark_common_block_symbol_computed (sym
, die
, attr
,
16012 dwarf2_complex_location_expr_complaint ();
16017 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16018 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16022 /* Create a type for a C++ namespace. */
16024 static struct type
*
16025 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16027 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16028 const char *previous_prefix
, *name
;
16032 /* For extensions, reuse the type of the original namespace. */
16033 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16035 struct die_info
*ext_die
;
16036 struct dwarf2_cu
*ext_cu
= cu
;
16038 ext_die
= dwarf2_extension (die
, &ext_cu
);
16039 type
= read_type_die (ext_die
, ext_cu
);
16041 /* EXT_CU may not be the same as CU.
16042 Ensure TYPE is recorded with CU in die_type_hash. */
16043 return set_die_type (die
, type
, cu
);
16046 name
= namespace_name (die
, &is_anonymous
, cu
);
16048 /* Now build the name of the current namespace. */
16050 previous_prefix
= determine_prefix (die
, cu
);
16051 if (previous_prefix
[0] != '\0')
16052 name
= typename_concat (&objfile
->objfile_obstack
,
16053 previous_prefix
, name
, 0, cu
);
16055 /* Create the type. */
16056 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16058 return set_die_type (die
, type
, cu
);
16061 /* Read a namespace scope. */
16064 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16066 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16069 /* Add a symbol associated to this if we haven't seen the namespace
16070 before. Also, add a using directive if it's an anonymous
16073 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16077 type
= read_type_die (die
, cu
);
16078 new_symbol (die
, type
, cu
);
16080 namespace_name (die
, &is_anonymous
, cu
);
16083 const char *previous_prefix
= determine_prefix (die
, cu
);
16085 std::vector
<const char *> excludes
;
16086 add_using_directive (using_directives (cu
),
16087 previous_prefix
, TYPE_NAME (type
), NULL
,
16088 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16092 if (die
->child
!= NULL
)
16094 struct die_info
*child_die
= die
->child
;
16096 while (child_die
&& child_die
->tag
)
16098 process_die (child_die
, cu
);
16099 child_die
= child_die
->sibling
;
16104 /* Read a Fortran module as type. This DIE can be only a declaration used for
16105 imported module. Still we need that type as local Fortran "use ... only"
16106 declaration imports depend on the created type in determine_prefix. */
16108 static struct type
*
16109 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16111 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16112 const char *module_name
;
16115 module_name
= dwarf2_name (die
, cu
);
16116 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16118 return set_die_type (die
, type
, cu
);
16121 /* Read a Fortran module. */
16124 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16126 struct die_info
*child_die
= die
->child
;
16129 type
= read_type_die (die
, cu
);
16130 new_symbol (die
, type
, cu
);
16132 while (child_die
&& child_die
->tag
)
16134 process_die (child_die
, cu
);
16135 child_die
= child_die
->sibling
;
16139 /* Return the name of the namespace represented by DIE. Set
16140 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16143 static const char *
16144 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16146 struct die_info
*current_die
;
16147 const char *name
= NULL
;
16149 /* Loop through the extensions until we find a name. */
16151 for (current_die
= die
;
16152 current_die
!= NULL
;
16153 current_die
= dwarf2_extension (die
, &cu
))
16155 /* We don't use dwarf2_name here so that we can detect the absence
16156 of a name -> anonymous namespace. */
16157 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16163 /* Is it an anonymous namespace? */
16165 *is_anonymous
= (name
== NULL
);
16167 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16172 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16173 the user defined type vector. */
16175 static struct type
*
16176 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16178 struct gdbarch
*gdbarch
16179 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16180 struct comp_unit_head
*cu_header
= &cu
->header
;
16182 struct attribute
*attr_byte_size
;
16183 struct attribute
*attr_address_class
;
16184 int byte_size
, addr_class
;
16185 struct type
*target_type
;
16187 target_type
= die_type (die
, cu
);
16189 /* The die_type call above may have already set the type for this DIE. */
16190 type
= get_die_type (die
, cu
);
16194 type
= lookup_pointer_type (target_type
);
16196 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16197 if (attr_byte_size
)
16198 byte_size
= DW_UNSND (attr_byte_size
);
16200 byte_size
= cu_header
->addr_size
;
16202 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16203 if (attr_address_class
)
16204 addr_class
= DW_UNSND (attr_address_class
);
16206 addr_class
= DW_ADDR_none
;
16208 ULONGEST alignment
= get_alignment (cu
, die
);
16210 /* If the pointer size, alignment, or address class is different
16211 than the default, create a type variant marked as such and set
16212 the length accordingly. */
16213 if (TYPE_LENGTH (type
) != byte_size
16214 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16215 && alignment
!= TYPE_RAW_ALIGN (type
))
16216 || addr_class
!= DW_ADDR_none
)
16218 if (gdbarch_address_class_type_flags_p (gdbarch
))
16222 type_flags
= gdbarch_address_class_type_flags
16223 (gdbarch
, byte_size
, addr_class
);
16224 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16226 type
= make_type_with_address_space (type
, type_flags
);
16228 else if (TYPE_LENGTH (type
) != byte_size
)
16230 complaint (_("invalid pointer size %d"), byte_size
);
16232 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16234 complaint (_("Invalid DW_AT_alignment"
16235 " - DIE at %s [in module %s]"),
16236 sect_offset_str (die
->sect_off
),
16237 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16241 /* Should we also complain about unhandled address classes? */
16245 TYPE_LENGTH (type
) = byte_size
;
16246 set_type_align (type
, alignment
);
16247 return set_die_type (die
, type
, cu
);
16250 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16251 the user defined type vector. */
16253 static struct type
*
16254 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16257 struct type
*to_type
;
16258 struct type
*domain
;
16260 to_type
= die_type (die
, cu
);
16261 domain
= die_containing_type (die
, cu
);
16263 /* The calls above may have already set the type for this DIE. */
16264 type
= get_die_type (die
, cu
);
16268 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16269 type
= lookup_methodptr_type (to_type
);
16270 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16272 struct type
*new_type
16273 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16275 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16276 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16277 TYPE_VARARGS (to_type
));
16278 type
= lookup_methodptr_type (new_type
);
16281 type
= lookup_memberptr_type (to_type
, domain
);
16283 return set_die_type (die
, type
, cu
);
16286 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16287 the user defined type vector. */
16289 static struct type
*
16290 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16291 enum type_code refcode
)
16293 struct comp_unit_head
*cu_header
= &cu
->header
;
16294 struct type
*type
, *target_type
;
16295 struct attribute
*attr
;
16297 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16299 target_type
= die_type (die
, cu
);
16301 /* The die_type call above may have already set the type for this DIE. */
16302 type
= get_die_type (die
, cu
);
16306 type
= lookup_reference_type (target_type
, refcode
);
16307 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16308 if (attr
!= nullptr)
16310 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16314 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16316 maybe_set_alignment (cu
, die
, type
);
16317 return set_die_type (die
, type
, cu
);
16320 /* Add the given cv-qualifiers to the element type of the array. GCC
16321 outputs DWARF type qualifiers that apply to an array, not the
16322 element type. But GDB relies on the array element type to carry
16323 the cv-qualifiers. This mimics section 6.7.3 of the C99
16326 static struct type
*
16327 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16328 struct type
*base_type
, int cnst
, int voltl
)
16330 struct type
*el_type
, *inner_array
;
16332 base_type
= copy_type (base_type
);
16333 inner_array
= base_type
;
16335 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16337 TYPE_TARGET_TYPE (inner_array
) =
16338 copy_type (TYPE_TARGET_TYPE (inner_array
));
16339 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16342 el_type
= TYPE_TARGET_TYPE (inner_array
);
16343 cnst
|= TYPE_CONST (el_type
);
16344 voltl
|= TYPE_VOLATILE (el_type
);
16345 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16347 return set_die_type (die
, base_type
, cu
);
16350 static struct type
*
16351 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16353 struct type
*base_type
, *cv_type
;
16355 base_type
= die_type (die
, cu
);
16357 /* The die_type call above may have already set the type for this DIE. */
16358 cv_type
= get_die_type (die
, cu
);
16362 /* In case the const qualifier is applied to an array type, the element type
16363 is so qualified, not the array type (section 6.7.3 of C99). */
16364 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16365 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16367 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16368 return set_die_type (die
, cv_type
, cu
);
16371 static struct type
*
16372 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16374 struct type
*base_type
, *cv_type
;
16376 base_type
= die_type (die
, cu
);
16378 /* The die_type call above may have already set the type for this DIE. */
16379 cv_type
= get_die_type (die
, cu
);
16383 /* In case the volatile qualifier is applied to an array type, the
16384 element type is so qualified, not the array type (section 6.7.3
16386 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16387 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16389 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16390 return set_die_type (die
, cv_type
, cu
);
16393 /* Handle DW_TAG_restrict_type. */
16395 static struct type
*
16396 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16398 struct type
*base_type
, *cv_type
;
16400 base_type
= die_type (die
, cu
);
16402 /* The die_type call above may have already set the type for this DIE. */
16403 cv_type
= get_die_type (die
, cu
);
16407 cv_type
= make_restrict_type (base_type
);
16408 return set_die_type (die
, cv_type
, cu
);
16411 /* Handle DW_TAG_atomic_type. */
16413 static struct type
*
16414 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16416 struct type
*base_type
, *cv_type
;
16418 base_type
= die_type (die
, cu
);
16420 /* The die_type call above may have already set the type for this DIE. */
16421 cv_type
= get_die_type (die
, cu
);
16425 cv_type
= make_atomic_type (base_type
);
16426 return set_die_type (die
, cv_type
, cu
);
16429 /* Extract all information from a DW_TAG_string_type DIE and add to
16430 the user defined type vector. It isn't really a user defined type,
16431 but it behaves like one, with other DIE's using an AT_user_def_type
16432 attribute to reference it. */
16434 static struct type
*
16435 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16437 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16438 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16439 struct type
*type
, *range_type
, *index_type
, *char_type
;
16440 struct attribute
*attr
;
16441 struct dynamic_prop prop
;
16442 bool length_is_constant
= true;
16445 /* There are a couple of places where bit sizes might be made use of
16446 when parsing a DW_TAG_string_type, however, no producer that we know
16447 of make use of these. Handling bit sizes that are a multiple of the
16448 byte size is easy enough, but what about other bit sizes? Lets deal
16449 with that problem when we have to. Warn about these attributes being
16450 unsupported, then parse the type and ignore them like we always
16452 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16453 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16455 static bool warning_printed
= false;
16456 if (!warning_printed
)
16458 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16459 "currently supported on DW_TAG_string_type."));
16460 warning_printed
= true;
16464 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16465 if (attr
!= nullptr && !attr
->form_is_constant ())
16467 /* The string length describes the location at which the length of
16468 the string can be found. The size of the length field can be
16469 specified with one of the attributes below. */
16470 struct type
*prop_type
;
16471 struct attribute
*len
16472 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16473 if (len
== nullptr)
16474 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16475 if (len
!= nullptr && len
->form_is_constant ())
16477 /* Pass 0 as the default as we know this attribute is constant
16478 and the default value will not be returned. */
16479 LONGEST sz
= len
->constant_value (0);
16480 prop_type
= cu
->per_cu
->int_type (sz
, true);
16484 /* If the size is not specified then we assume it is the size of
16485 an address on this target. */
16486 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16489 /* Convert the attribute into a dynamic property. */
16490 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16493 length_is_constant
= false;
16495 else if (attr
!= nullptr)
16497 /* This DW_AT_string_length just contains the length with no
16498 indirection. There's no need to create a dynamic property in this
16499 case. Pass 0 for the default value as we know it will not be
16500 returned in this case. */
16501 length
= attr
->constant_value (0);
16503 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16505 /* We don't currently support non-constant byte sizes for strings. */
16506 length
= attr
->constant_value (1);
16510 /* Use 1 as a fallback length if we have nothing else. */
16514 index_type
= objfile_type (objfile
)->builtin_int
;
16515 if (length_is_constant
)
16516 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16519 struct dynamic_prop low_bound
;
16521 low_bound
.kind
= PROP_CONST
;
16522 low_bound
.data
.const_val
= 1;
16523 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16525 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16526 type
= create_string_type (NULL
, char_type
, range_type
);
16528 return set_die_type (die
, type
, cu
);
16531 /* Assuming that DIE corresponds to a function, returns nonzero
16532 if the function is prototyped. */
16535 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16537 struct attribute
*attr
;
16539 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16540 if (attr
&& (DW_UNSND (attr
) != 0))
16543 /* The DWARF standard implies that the DW_AT_prototyped attribute
16544 is only meaningful for C, but the concept also extends to other
16545 languages that allow unprototyped functions (Eg: Objective C).
16546 For all other languages, assume that functions are always
16548 if (cu
->language
!= language_c
16549 && cu
->language
!= language_objc
16550 && cu
->language
!= language_opencl
)
16553 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16554 prototyped and unprototyped functions; default to prototyped,
16555 since that is more common in modern code (and RealView warns
16556 about unprototyped functions). */
16557 if (producer_is_realview (cu
->producer
))
16563 /* Handle DIES due to C code like:
16567 int (*funcp)(int a, long l);
16571 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16573 static struct type
*
16574 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16576 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16577 struct type
*type
; /* Type that this function returns. */
16578 struct type
*ftype
; /* Function that returns above type. */
16579 struct attribute
*attr
;
16581 type
= die_type (die
, cu
);
16583 /* The die_type call above may have already set the type for this DIE. */
16584 ftype
= get_die_type (die
, cu
);
16588 ftype
= lookup_function_type (type
);
16590 if (prototyped_function_p (die
, cu
))
16591 TYPE_PROTOTYPED (ftype
) = 1;
16593 /* Store the calling convention in the type if it's available in
16594 the subroutine die. Otherwise set the calling convention to
16595 the default value DW_CC_normal. */
16596 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16597 if (attr
!= nullptr
16598 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16599 TYPE_CALLING_CONVENTION (ftype
)
16600 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16601 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16602 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16604 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16606 /* Record whether the function returns normally to its caller or not
16607 if the DWARF producer set that information. */
16608 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16609 if (attr
&& (DW_UNSND (attr
) != 0))
16610 TYPE_NO_RETURN (ftype
) = 1;
16612 /* We need to add the subroutine type to the die immediately so
16613 we don't infinitely recurse when dealing with parameters
16614 declared as the same subroutine type. */
16615 set_die_type (die
, ftype
, cu
);
16617 if (die
->child
!= NULL
)
16619 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16620 struct die_info
*child_die
;
16621 int nparams
, iparams
;
16623 /* Count the number of parameters.
16624 FIXME: GDB currently ignores vararg functions, but knows about
16625 vararg member functions. */
16627 child_die
= die
->child
;
16628 while (child_die
&& child_die
->tag
)
16630 if (child_die
->tag
== DW_TAG_formal_parameter
)
16632 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16633 TYPE_VARARGS (ftype
) = 1;
16634 child_die
= child_die
->sibling
;
16637 /* Allocate storage for parameters and fill them in. */
16638 TYPE_NFIELDS (ftype
) = nparams
;
16639 TYPE_FIELDS (ftype
) = (struct field
*)
16640 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16642 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16643 even if we error out during the parameters reading below. */
16644 for (iparams
= 0; iparams
< nparams
; iparams
++)
16645 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16648 child_die
= die
->child
;
16649 while (child_die
&& child_die
->tag
)
16651 if (child_die
->tag
== DW_TAG_formal_parameter
)
16653 struct type
*arg_type
;
16655 /* DWARF version 2 has no clean way to discern C++
16656 static and non-static member functions. G++ helps
16657 GDB by marking the first parameter for non-static
16658 member functions (which is the this pointer) as
16659 artificial. We pass this information to
16660 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16662 DWARF version 3 added DW_AT_object_pointer, which GCC
16663 4.5 does not yet generate. */
16664 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16665 if (attr
!= nullptr)
16666 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16668 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16669 arg_type
= die_type (child_die
, cu
);
16671 /* RealView does not mark THIS as const, which the testsuite
16672 expects. GCC marks THIS as const in method definitions,
16673 but not in the class specifications (GCC PR 43053). */
16674 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16675 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16678 struct dwarf2_cu
*arg_cu
= cu
;
16679 const char *name
= dwarf2_name (child_die
, cu
);
16681 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16682 if (attr
!= nullptr)
16684 /* If the compiler emits this, use it. */
16685 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16688 else if (name
&& strcmp (name
, "this") == 0)
16689 /* Function definitions will have the argument names. */
16691 else if (name
== NULL
&& iparams
== 0)
16692 /* Declarations may not have the names, so like
16693 elsewhere in GDB, assume an artificial first
16694 argument is "this". */
16698 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16702 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16705 child_die
= child_die
->sibling
;
16712 static struct type
*
16713 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16715 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16716 const char *name
= NULL
;
16717 struct type
*this_type
, *target_type
;
16719 name
= dwarf2_full_name (NULL
, die
, cu
);
16720 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16721 TYPE_TARGET_STUB (this_type
) = 1;
16722 set_die_type (die
, this_type
, cu
);
16723 target_type
= die_type (die
, cu
);
16724 if (target_type
!= this_type
)
16725 TYPE_TARGET_TYPE (this_type
) = target_type
;
16728 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16729 spec and cause infinite loops in GDB. */
16730 complaint (_("Self-referential DW_TAG_typedef "
16731 "- DIE at %s [in module %s]"),
16732 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16733 TYPE_TARGET_TYPE (this_type
) = NULL
;
16737 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16738 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16739 Handle these by just returning the target type, rather than
16740 constructing an anonymous typedef type and trying to handle this
16742 set_die_type (die
, target_type
, cu
);
16743 return target_type
;
16748 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16749 (which may be different from NAME) to the architecture back-end to allow
16750 it to guess the correct format if necessary. */
16752 static struct type
*
16753 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16754 const char *name_hint
, enum bfd_endian byte_order
)
16756 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16757 const struct floatformat
**format
;
16760 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16762 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16764 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16769 /* Allocate an integer type of size BITS and name NAME. */
16771 static struct type
*
16772 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16773 int bits
, int unsigned_p
, const char *name
)
16777 /* Versions of Intel's C Compiler generate an integer type called "void"
16778 instead of using DW_TAG_unspecified_type. This has been seen on
16779 at least versions 14, 17, and 18. */
16780 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16781 && strcmp (name
, "void") == 0)
16782 type
= objfile_type (objfile
)->builtin_void
;
16784 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16789 /* Initialise and return a floating point type of size BITS suitable for
16790 use as a component of a complex number. The NAME_HINT is passed through
16791 when initialising the floating point type and is the name of the complex
16794 As DWARF doesn't currently provide an explicit name for the components
16795 of a complex number, but it can be helpful to have these components
16796 named, we try to select a suitable name based on the size of the
16798 static struct type
*
16799 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16800 struct objfile
*objfile
,
16801 int bits
, const char *name_hint
,
16802 enum bfd_endian byte_order
)
16804 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16805 struct type
*tt
= nullptr;
16807 /* Try to find a suitable floating point builtin type of size BITS.
16808 We're going to use the name of this type as the name for the complex
16809 target type that we are about to create. */
16810 switch (cu
->language
)
16812 case language_fortran
:
16816 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16819 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16821 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16823 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16831 tt
= builtin_type (gdbarch
)->builtin_float
;
16834 tt
= builtin_type (gdbarch
)->builtin_double
;
16836 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16838 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16844 /* If the type we found doesn't match the size we were looking for, then
16845 pretend we didn't find a type at all, the complex target type we
16846 create will then be nameless. */
16847 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16850 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16851 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16854 /* Find a representation of a given base type and install
16855 it in the TYPE field of the die. */
16857 static struct type
*
16858 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16860 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16862 struct attribute
*attr
;
16863 int encoding
= 0, bits
= 0;
16867 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16868 if (attr
!= nullptr)
16869 encoding
= DW_UNSND (attr
);
16870 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16871 if (attr
!= nullptr)
16872 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16873 name
= dwarf2_name (die
, cu
);
16875 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16877 arch
= get_objfile_arch (objfile
);
16878 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16880 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16883 int endianity
= DW_UNSND (attr
);
16888 byte_order
= BFD_ENDIAN_BIG
;
16890 case DW_END_little
:
16891 byte_order
= BFD_ENDIAN_LITTLE
;
16894 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16901 case DW_ATE_address
:
16902 /* Turn DW_ATE_address into a void * pointer. */
16903 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16904 type
= init_pointer_type (objfile
, bits
, name
, type
);
16906 case DW_ATE_boolean
:
16907 type
= init_boolean_type (objfile
, bits
, 1, name
);
16909 case DW_ATE_complex_float
:
16910 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16912 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
16914 if (name
== nullptr)
16916 struct obstack
*obstack
16917 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16918 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
16921 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16924 type
= init_complex_type (name
, type
);
16926 case DW_ATE_decimal_float
:
16927 type
= init_decfloat_type (objfile
, bits
, name
);
16930 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16932 case DW_ATE_signed
:
16933 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16935 case DW_ATE_unsigned
:
16936 if (cu
->language
== language_fortran
16938 && startswith (name
, "character("))
16939 type
= init_character_type (objfile
, bits
, 1, name
);
16941 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16943 case DW_ATE_signed_char
:
16944 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16945 || cu
->language
== language_pascal
16946 || cu
->language
== language_fortran
)
16947 type
= init_character_type (objfile
, bits
, 0, name
);
16949 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16951 case DW_ATE_unsigned_char
:
16952 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16953 || cu
->language
== language_pascal
16954 || cu
->language
== language_fortran
16955 || cu
->language
== language_rust
)
16956 type
= init_character_type (objfile
, bits
, 1, name
);
16958 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16963 type
= builtin_type (arch
)->builtin_char16
;
16964 else if (bits
== 32)
16965 type
= builtin_type (arch
)->builtin_char32
;
16968 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16970 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16972 return set_die_type (die
, type
, cu
);
16977 complaint (_("unsupported DW_AT_encoding: '%s'"),
16978 dwarf_type_encoding_name (encoding
));
16979 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16983 if (name
&& strcmp (name
, "char") == 0)
16984 TYPE_NOSIGN (type
) = 1;
16986 maybe_set_alignment (cu
, die
, type
);
16988 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16990 return set_die_type (die
, type
, cu
);
16993 /* Parse dwarf attribute if it's a block, reference or constant and put the
16994 resulting value of the attribute into struct bound_prop.
16995 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
16998 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
16999 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17000 struct type
*default_type
)
17002 struct dwarf2_property_baton
*baton
;
17003 struct obstack
*obstack
17004 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17006 gdb_assert (default_type
!= NULL
);
17008 if (attr
== NULL
|| prop
== NULL
)
17011 if (attr
->form_is_block ())
17013 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17014 baton
->property_type
= default_type
;
17015 baton
->locexpr
.per_cu
= cu
->per_cu
;
17016 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17017 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17018 switch (attr
->name
)
17020 case DW_AT_string_length
:
17021 baton
->locexpr
.is_reference
= true;
17024 baton
->locexpr
.is_reference
= false;
17027 prop
->data
.baton
= baton
;
17028 prop
->kind
= PROP_LOCEXPR
;
17029 gdb_assert (prop
->data
.baton
!= NULL
);
17031 else if (attr
->form_is_ref ())
17033 struct dwarf2_cu
*target_cu
= cu
;
17034 struct die_info
*target_die
;
17035 struct attribute
*target_attr
;
17037 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17038 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17039 if (target_attr
== NULL
)
17040 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17042 if (target_attr
== NULL
)
17045 switch (target_attr
->name
)
17047 case DW_AT_location
:
17048 if (target_attr
->form_is_section_offset ())
17050 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17051 baton
->property_type
= die_type (target_die
, target_cu
);
17052 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17053 prop
->data
.baton
= baton
;
17054 prop
->kind
= PROP_LOCLIST
;
17055 gdb_assert (prop
->data
.baton
!= NULL
);
17057 else if (target_attr
->form_is_block ())
17059 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17060 baton
->property_type
= die_type (target_die
, target_cu
);
17061 baton
->locexpr
.per_cu
= cu
->per_cu
;
17062 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17063 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17064 baton
->locexpr
.is_reference
= true;
17065 prop
->data
.baton
= baton
;
17066 prop
->kind
= PROP_LOCEXPR
;
17067 gdb_assert (prop
->data
.baton
!= NULL
);
17071 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17072 "dynamic property");
17076 case DW_AT_data_member_location
:
17080 if (!handle_data_member_location (target_die
, target_cu
,
17084 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17085 baton
->property_type
= read_type_die (target_die
->parent
,
17087 baton
->offset_info
.offset
= offset
;
17088 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17089 prop
->data
.baton
= baton
;
17090 prop
->kind
= PROP_ADDR_OFFSET
;
17095 else if (attr
->form_is_constant ())
17097 prop
->data
.const_val
= attr
->constant_value (0);
17098 prop
->kind
= PROP_CONST
;
17102 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17103 dwarf2_name (die
, cu
));
17113 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17115 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17116 struct type
*int_type
;
17118 /* Helper macro to examine the various builtin types. */
17119 #define TRY_TYPE(F) \
17120 int_type = (unsigned_p \
17121 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17122 : objfile_type (objfile)->builtin_ ## F); \
17123 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17130 TRY_TYPE (long_long
);
17134 gdb_assert_not_reached ("unable to find suitable integer type");
17140 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17142 int addr_size
= this->addr_size ();
17143 return int_type (addr_size
, unsigned_p
);
17146 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17147 present (which is valid) then compute the default type based on the
17148 compilation units address size. */
17150 static struct type
*
17151 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17153 struct type
*index_type
= die_type (die
, cu
);
17155 /* Dwarf-2 specifications explicitly allows to create subrange types
17156 without specifying a base type.
17157 In that case, the base type must be set to the type of
17158 the lower bound, upper bound or count, in that order, if any of these
17159 three attributes references an object that has a type.
17160 If no base type is found, the Dwarf-2 specifications say that
17161 a signed integer type of size equal to the size of an address should
17163 For the following C code: `extern char gdb_int [];'
17164 GCC produces an empty range DIE.
17165 FIXME: muller/2010-05-28: Possible references to object for low bound,
17166 high bound or count are not yet handled by this code. */
17167 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17168 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17173 /* Read the given DW_AT_subrange DIE. */
17175 static struct type
*
17176 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17178 struct type
*base_type
, *orig_base_type
;
17179 struct type
*range_type
;
17180 struct attribute
*attr
;
17181 struct dynamic_prop low
, high
;
17182 int low_default_is_valid
;
17183 int high_bound_is_count
= 0;
17185 ULONGEST negative_mask
;
17187 orig_base_type
= read_subrange_index_type (die
, cu
);
17189 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17190 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17191 creating the range type, but we use the result of check_typedef
17192 when examining properties of the type. */
17193 base_type
= check_typedef (orig_base_type
);
17195 /* The die_type call above may have already set the type for this DIE. */
17196 range_type
= get_die_type (die
, cu
);
17200 low
.kind
= PROP_CONST
;
17201 high
.kind
= PROP_CONST
;
17202 high
.data
.const_val
= 0;
17204 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17205 omitting DW_AT_lower_bound. */
17206 switch (cu
->language
)
17209 case language_cplus
:
17210 low
.data
.const_val
= 0;
17211 low_default_is_valid
= 1;
17213 case language_fortran
:
17214 low
.data
.const_val
= 1;
17215 low_default_is_valid
= 1;
17218 case language_objc
:
17219 case language_rust
:
17220 low
.data
.const_val
= 0;
17221 low_default_is_valid
= (cu
->header
.version
>= 4);
17225 case language_pascal
:
17226 low
.data
.const_val
= 1;
17227 low_default_is_valid
= (cu
->header
.version
>= 4);
17230 low
.data
.const_val
= 0;
17231 low_default_is_valid
= 0;
17235 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17236 if (attr
!= nullptr)
17237 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17238 else if (!low_default_is_valid
)
17239 complaint (_("Missing DW_AT_lower_bound "
17240 "- DIE at %s [in module %s]"),
17241 sect_offset_str (die
->sect_off
),
17242 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17244 struct attribute
*attr_ub
, *attr_count
;
17245 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17246 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17248 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17249 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17251 /* If bounds are constant do the final calculation here. */
17252 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17253 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17255 high_bound_is_count
= 1;
17259 if (attr_ub
!= NULL
)
17260 complaint (_("Unresolved DW_AT_upper_bound "
17261 "- DIE at %s [in module %s]"),
17262 sect_offset_str (die
->sect_off
),
17263 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17264 if (attr_count
!= NULL
)
17265 complaint (_("Unresolved DW_AT_count "
17266 "- DIE at %s [in module %s]"),
17267 sect_offset_str (die
->sect_off
),
17268 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17273 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17274 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17275 bias
= bias_attr
->constant_value (0);
17277 /* Normally, the DWARF producers are expected to use a signed
17278 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17279 But this is unfortunately not always the case, as witnessed
17280 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17281 is used instead. To work around that ambiguity, we treat
17282 the bounds as signed, and thus sign-extend their values, when
17283 the base type is signed. */
17285 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17286 if (low
.kind
== PROP_CONST
17287 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17288 low
.data
.const_val
|= negative_mask
;
17289 if (high
.kind
== PROP_CONST
17290 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17291 high
.data
.const_val
|= negative_mask
;
17293 /* Check for bit and byte strides. */
17294 struct dynamic_prop byte_stride_prop
;
17295 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17296 if (attr_byte_stride
!= nullptr)
17298 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17299 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17303 struct dynamic_prop bit_stride_prop
;
17304 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17305 if (attr_bit_stride
!= nullptr)
17307 /* It only makes sense to have either a bit or byte stride. */
17308 if (attr_byte_stride
!= nullptr)
17310 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17311 "- DIE at %s [in module %s]"),
17312 sect_offset_str (die
->sect_off
),
17313 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17314 attr_bit_stride
= nullptr;
17318 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17319 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17324 if (attr_byte_stride
!= nullptr
17325 || attr_bit_stride
!= nullptr)
17327 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17328 struct dynamic_prop
*stride
17329 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17332 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17333 &high
, bias
, stride
, byte_stride_p
);
17336 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17338 if (high_bound_is_count
)
17339 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17341 /* Ada expects an empty array on no boundary attributes. */
17342 if (attr
== NULL
&& cu
->language
!= language_ada
)
17343 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17345 name
= dwarf2_name (die
, cu
);
17347 TYPE_NAME (range_type
) = name
;
17349 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17350 if (attr
!= nullptr)
17351 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17353 maybe_set_alignment (cu
, die
, range_type
);
17355 set_die_type (die
, range_type
, cu
);
17357 /* set_die_type should be already done. */
17358 set_descriptive_type (range_type
, die
, cu
);
17363 static struct type
*
17364 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17368 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17370 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17372 /* In Ada, an unspecified type is typically used when the description
17373 of the type is deferred to a different unit. When encountering
17374 such a type, we treat it as a stub, and try to resolve it later on,
17376 if (cu
->language
== language_ada
)
17377 TYPE_STUB (type
) = 1;
17379 return set_die_type (die
, type
, cu
);
17382 /* Read a single die and all its descendents. Set the die's sibling
17383 field to NULL; set other fields in the die correctly, and set all
17384 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17385 location of the info_ptr after reading all of those dies. PARENT
17386 is the parent of the die in question. */
17388 static struct die_info
*
17389 read_die_and_children (const struct die_reader_specs
*reader
,
17390 const gdb_byte
*info_ptr
,
17391 const gdb_byte
**new_info_ptr
,
17392 struct die_info
*parent
)
17394 struct die_info
*die
;
17395 const gdb_byte
*cur_ptr
;
17397 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17400 *new_info_ptr
= cur_ptr
;
17403 store_in_ref_table (die
, reader
->cu
);
17405 if (die
->has_children
)
17406 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17410 *new_info_ptr
= cur_ptr
;
17413 die
->sibling
= NULL
;
17414 die
->parent
= parent
;
17418 /* Read a die, all of its descendents, and all of its siblings; set
17419 all of the fields of all of the dies correctly. Arguments are as
17420 in read_die_and_children. */
17422 static struct die_info
*
17423 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17424 const gdb_byte
*info_ptr
,
17425 const gdb_byte
**new_info_ptr
,
17426 struct die_info
*parent
)
17428 struct die_info
*first_die
, *last_sibling
;
17429 const gdb_byte
*cur_ptr
;
17431 cur_ptr
= info_ptr
;
17432 first_die
= last_sibling
= NULL
;
17436 struct die_info
*die
17437 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17441 *new_info_ptr
= cur_ptr
;
17448 last_sibling
->sibling
= die
;
17450 last_sibling
= die
;
17454 /* Read a die, all of its descendents, and all of its siblings; set
17455 all of the fields of all of the dies correctly. Arguments are as
17456 in read_die_and_children.
17457 This the main entry point for reading a DIE and all its children. */
17459 static struct die_info
*
17460 read_die_and_siblings (const struct die_reader_specs
*reader
,
17461 const gdb_byte
*info_ptr
,
17462 const gdb_byte
**new_info_ptr
,
17463 struct die_info
*parent
)
17465 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17466 new_info_ptr
, parent
);
17468 if (dwarf_die_debug
)
17470 fprintf_unfiltered (gdb_stdlog
,
17471 "Read die from %s@0x%x of %s:\n",
17472 reader
->die_section
->get_name (),
17473 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17474 bfd_get_filename (reader
->abfd
));
17475 dump_die (die
, dwarf_die_debug
);
17481 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17483 The caller is responsible for filling in the extra attributes
17484 and updating (*DIEP)->num_attrs.
17485 Set DIEP to point to a newly allocated die with its information,
17486 except for its child, sibling, and parent fields. */
17488 static const gdb_byte
*
17489 read_full_die_1 (const struct die_reader_specs
*reader
,
17490 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17491 int num_extra_attrs
)
17493 unsigned int abbrev_number
, bytes_read
, i
;
17494 struct abbrev_info
*abbrev
;
17495 struct die_info
*die
;
17496 struct dwarf2_cu
*cu
= reader
->cu
;
17497 bfd
*abfd
= reader
->abfd
;
17499 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17500 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17501 info_ptr
+= bytes_read
;
17502 if (!abbrev_number
)
17508 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17510 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17512 bfd_get_filename (abfd
));
17514 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17515 die
->sect_off
= sect_off
;
17516 die
->tag
= abbrev
->tag
;
17517 die
->abbrev
= abbrev_number
;
17518 die
->has_children
= abbrev
->has_children
;
17520 /* Make the result usable.
17521 The caller needs to update num_attrs after adding the extra
17523 die
->num_attrs
= abbrev
->num_attrs
;
17525 std::vector
<int> indexes_that_need_reprocess
;
17526 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17528 bool need_reprocess
;
17530 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17531 info_ptr
, &need_reprocess
);
17532 if (need_reprocess
)
17533 indexes_that_need_reprocess
.push_back (i
);
17536 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17537 if (attr
!= nullptr)
17538 cu
->str_offsets_base
= DW_UNSND (attr
);
17540 auto maybe_addr_base
= die
->addr_base ();
17541 if (maybe_addr_base
.has_value ())
17542 cu
->addr_base
= *maybe_addr_base
;
17543 for (int index
: indexes_that_need_reprocess
)
17544 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17549 /* Read a die and all its attributes.
17550 Set DIEP to point to a newly allocated die with its information,
17551 except for its child, sibling, and parent fields. */
17553 static const gdb_byte
*
17554 read_full_die (const struct die_reader_specs
*reader
,
17555 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17557 const gdb_byte
*result
;
17559 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17561 if (dwarf_die_debug
)
17563 fprintf_unfiltered (gdb_stdlog
,
17564 "Read die from %s@0x%x of %s:\n",
17565 reader
->die_section
->get_name (),
17566 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17567 bfd_get_filename (reader
->abfd
));
17568 dump_die (*diep
, dwarf_die_debug
);
17575 /* Returns nonzero if TAG represents a type that we might generate a partial
17579 is_type_tag_for_partial (int tag
)
17584 /* Some types that would be reasonable to generate partial symbols for,
17585 that we don't at present. */
17586 case DW_TAG_array_type
:
17587 case DW_TAG_file_type
:
17588 case DW_TAG_ptr_to_member_type
:
17589 case DW_TAG_set_type
:
17590 case DW_TAG_string_type
:
17591 case DW_TAG_subroutine_type
:
17593 case DW_TAG_base_type
:
17594 case DW_TAG_class_type
:
17595 case DW_TAG_interface_type
:
17596 case DW_TAG_enumeration_type
:
17597 case DW_TAG_structure_type
:
17598 case DW_TAG_subrange_type
:
17599 case DW_TAG_typedef
:
17600 case DW_TAG_union_type
:
17607 /* Load all DIEs that are interesting for partial symbols into memory. */
17609 static struct partial_die_info
*
17610 load_partial_dies (const struct die_reader_specs
*reader
,
17611 const gdb_byte
*info_ptr
, int building_psymtab
)
17613 struct dwarf2_cu
*cu
= reader
->cu
;
17614 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17615 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17616 unsigned int bytes_read
;
17617 unsigned int load_all
= 0;
17618 int nesting_level
= 1;
17623 gdb_assert (cu
->per_cu
!= NULL
);
17624 if (cu
->per_cu
->load_all_dies
)
17628 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17632 &cu
->comp_unit_obstack
,
17633 hashtab_obstack_allocate
,
17634 dummy_obstack_deallocate
);
17638 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17640 /* A NULL abbrev means the end of a series of children. */
17641 if (abbrev
== NULL
)
17643 if (--nesting_level
== 0)
17646 info_ptr
+= bytes_read
;
17647 last_die
= parent_die
;
17648 parent_die
= parent_die
->die_parent
;
17652 /* Check for template arguments. We never save these; if
17653 they're seen, we just mark the parent, and go on our way. */
17654 if (parent_die
!= NULL
17655 && cu
->language
== language_cplus
17656 && (abbrev
->tag
== DW_TAG_template_type_param
17657 || abbrev
->tag
== DW_TAG_template_value_param
))
17659 parent_die
->has_template_arguments
= 1;
17663 /* We don't need a partial DIE for the template argument. */
17664 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17669 /* We only recurse into c++ subprograms looking for template arguments.
17670 Skip their other children. */
17672 && cu
->language
== language_cplus
17673 && parent_die
!= NULL
17674 && parent_die
->tag
== DW_TAG_subprogram
)
17676 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17680 /* Check whether this DIE is interesting enough to save. Normally
17681 we would not be interested in members here, but there may be
17682 later variables referencing them via DW_AT_specification (for
17683 static members). */
17685 && !is_type_tag_for_partial (abbrev
->tag
)
17686 && abbrev
->tag
!= DW_TAG_constant
17687 && abbrev
->tag
!= DW_TAG_enumerator
17688 && abbrev
->tag
!= DW_TAG_subprogram
17689 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17690 && abbrev
->tag
!= DW_TAG_lexical_block
17691 && abbrev
->tag
!= DW_TAG_variable
17692 && abbrev
->tag
!= DW_TAG_namespace
17693 && abbrev
->tag
!= DW_TAG_module
17694 && abbrev
->tag
!= DW_TAG_member
17695 && abbrev
->tag
!= DW_TAG_imported_unit
17696 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17698 /* Otherwise we skip to the next sibling, if any. */
17699 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17703 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17706 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17708 /* This two-pass algorithm for processing partial symbols has a
17709 high cost in cache pressure. Thus, handle some simple cases
17710 here which cover the majority of C partial symbols. DIEs
17711 which neither have specification tags in them, nor could have
17712 specification tags elsewhere pointing at them, can simply be
17713 processed and discarded.
17715 This segment is also optional; scan_partial_symbols and
17716 add_partial_symbol will handle these DIEs if we chain
17717 them in normally. When compilers which do not emit large
17718 quantities of duplicate debug information are more common,
17719 this code can probably be removed. */
17721 /* Any complete simple types at the top level (pretty much all
17722 of them, for a language without namespaces), can be processed
17724 if (parent_die
== NULL
17725 && pdi
.has_specification
== 0
17726 && pdi
.is_declaration
== 0
17727 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17728 || pdi
.tag
== DW_TAG_base_type
17729 || pdi
.tag
== DW_TAG_subrange_type
))
17731 if (building_psymtab
&& pdi
.name
!= NULL
)
17732 add_psymbol_to_list (pdi
.name
, false,
17733 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17734 psymbol_placement::STATIC
,
17735 0, cu
->language
, objfile
);
17736 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17740 /* The exception for DW_TAG_typedef with has_children above is
17741 a workaround of GCC PR debug/47510. In the case of this complaint
17742 type_name_or_error will error on such types later.
17744 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17745 it could not find the child DIEs referenced later, this is checked
17746 above. In correct DWARF DW_TAG_typedef should have no children. */
17748 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17749 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17750 "- DIE at %s [in module %s]"),
17751 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17753 /* If we're at the second level, and we're an enumerator, and
17754 our parent has no specification (meaning possibly lives in a
17755 namespace elsewhere), then we can add the partial symbol now
17756 instead of queueing it. */
17757 if (pdi
.tag
== DW_TAG_enumerator
17758 && parent_die
!= NULL
17759 && parent_die
->die_parent
== NULL
17760 && parent_die
->tag
== DW_TAG_enumeration_type
17761 && parent_die
->has_specification
== 0)
17763 if (pdi
.name
== NULL
)
17764 complaint (_("malformed enumerator DIE ignored"));
17765 else if (building_psymtab
)
17766 add_psymbol_to_list (pdi
.name
, false,
17767 VAR_DOMAIN
, LOC_CONST
, -1,
17768 cu
->language
== language_cplus
17769 ? psymbol_placement::GLOBAL
17770 : psymbol_placement::STATIC
,
17771 0, cu
->language
, objfile
);
17773 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17777 struct partial_die_info
*part_die
17778 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17780 /* We'll save this DIE so link it in. */
17781 part_die
->die_parent
= parent_die
;
17782 part_die
->die_sibling
= NULL
;
17783 part_die
->die_child
= NULL
;
17785 if (last_die
&& last_die
== parent_die
)
17786 last_die
->die_child
= part_die
;
17788 last_die
->die_sibling
= part_die
;
17790 last_die
= part_die
;
17792 if (first_die
== NULL
)
17793 first_die
= part_die
;
17795 /* Maybe add the DIE to the hash table. Not all DIEs that we
17796 find interesting need to be in the hash table, because we
17797 also have the parent/sibling/child chains; only those that we
17798 might refer to by offset later during partial symbol reading.
17800 For now this means things that might have be the target of a
17801 DW_AT_specification, DW_AT_abstract_origin, or
17802 DW_AT_extension. DW_AT_extension will refer only to
17803 namespaces; DW_AT_abstract_origin refers to functions (and
17804 many things under the function DIE, but we do not recurse
17805 into function DIEs during partial symbol reading) and
17806 possibly variables as well; DW_AT_specification refers to
17807 declarations. Declarations ought to have the DW_AT_declaration
17808 flag. It happens that GCC forgets to put it in sometimes, but
17809 only for functions, not for types.
17811 Adding more things than necessary to the hash table is harmless
17812 except for the performance cost. Adding too few will result in
17813 wasted time in find_partial_die, when we reread the compilation
17814 unit with load_all_dies set. */
17817 || abbrev
->tag
== DW_TAG_constant
17818 || abbrev
->tag
== DW_TAG_subprogram
17819 || abbrev
->tag
== DW_TAG_variable
17820 || abbrev
->tag
== DW_TAG_namespace
17821 || part_die
->is_declaration
)
17825 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17826 to_underlying (part_die
->sect_off
),
17831 /* For some DIEs we want to follow their children (if any). For C
17832 we have no reason to follow the children of structures; for other
17833 languages we have to, so that we can get at method physnames
17834 to infer fully qualified class names, for DW_AT_specification,
17835 and for C++ template arguments. For C++, we also look one level
17836 inside functions to find template arguments (if the name of the
17837 function does not already contain the template arguments).
17839 For Ada and Fortran, we need to scan the children of subprograms
17840 and lexical blocks as well because these languages allow the
17841 definition of nested entities that could be interesting for the
17842 debugger, such as nested subprograms for instance. */
17843 if (last_die
->has_children
17845 || last_die
->tag
== DW_TAG_namespace
17846 || last_die
->tag
== DW_TAG_module
17847 || last_die
->tag
== DW_TAG_enumeration_type
17848 || (cu
->language
== language_cplus
17849 && last_die
->tag
== DW_TAG_subprogram
17850 && (last_die
->name
== NULL
17851 || strchr (last_die
->name
, '<') == NULL
))
17852 || (cu
->language
!= language_c
17853 && (last_die
->tag
== DW_TAG_class_type
17854 || last_die
->tag
== DW_TAG_interface_type
17855 || last_die
->tag
== DW_TAG_structure_type
17856 || last_die
->tag
== DW_TAG_union_type
))
17857 || ((cu
->language
== language_ada
17858 || cu
->language
== language_fortran
)
17859 && (last_die
->tag
== DW_TAG_subprogram
17860 || last_die
->tag
== DW_TAG_lexical_block
))))
17863 parent_die
= last_die
;
17867 /* Otherwise we skip to the next sibling, if any. */
17868 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17870 /* Back to the top, do it again. */
17874 partial_die_info::partial_die_info (sect_offset sect_off_
,
17875 struct abbrev_info
*abbrev
)
17876 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17880 /* Read a minimal amount of information into the minimal die structure.
17881 INFO_PTR should point just after the initial uleb128 of a DIE. */
17884 partial_die_info::read (const struct die_reader_specs
*reader
,
17885 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17887 struct dwarf2_cu
*cu
= reader
->cu
;
17888 struct dwarf2_per_objfile
*dwarf2_per_objfile
17889 = cu
->per_cu
->dwarf2_per_objfile
;
17891 int has_low_pc_attr
= 0;
17892 int has_high_pc_attr
= 0;
17893 int high_pc_relative
= 0;
17895 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17898 bool need_reprocess
;
17899 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
17900 info_ptr
, &need_reprocess
);
17901 /* String and address offsets that need to do the reprocessing have
17902 already been read at this point, so there is no need to wait until
17903 the loop terminates to do the reprocessing. */
17904 if (need_reprocess
)
17905 read_attribute_reprocess (reader
, &attr
);
17906 /* Store the data if it is of an attribute we want to keep in a
17907 partial symbol table. */
17913 case DW_TAG_compile_unit
:
17914 case DW_TAG_partial_unit
:
17915 case DW_TAG_type_unit
:
17916 /* Compilation units have a DW_AT_name that is a filename, not
17917 a source language identifier. */
17918 case DW_TAG_enumeration_type
:
17919 case DW_TAG_enumerator
:
17920 /* These tags always have simple identifiers already; no need
17921 to canonicalize them. */
17922 name
= DW_STRING (&attr
);
17926 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17929 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17934 case DW_AT_linkage_name
:
17935 case DW_AT_MIPS_linkage_name
:
17936 /* Note that both forms of linkage name might appear. We
17937 assume they will be the same, and we only store the last
17939 linkage_name
= DW_STRING (&attr
);
17942 has_low_pc_attr
= 1;
17943 lowpc
= attr
.value_as_address ();
17945 case DW_AT_high_pc
:
17946 has_high_pc_attr
= 1;
17947 highpc
= attr
.value_as_address ();
17948 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17949 high_pc_relative
= 1;
17951 case DW_AT_location
:
17952 /* Support the .debug_loc offsets. */
17953 if (attr
.form_is_block ())
17955 d
.locdesc
= DW_BLOCK (&attr
);
17957 else if (attr
.form_is_section_offset ())
17959 dwarf2_complex_location_expr_complaint ();
17963 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17964 "partial symbol information");
17967 case DW_AT_external
:
17968 is_external
= DW_UNSND (&attr
);
17970 case DW_AT_declaration
:
17971 is_declaration
= DW_UNSND (&attr
);
17976 case DW_AT_abstract_origin
:
17977 case DW_AT_specification
:
17978 case DW_AT_extension
:
17979 has_specification
= 1;
17980 spec_offset
= attr
.get_ref_die_offset ();
17981 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17982 || cu
->per_cu
->is_dwz
);
17984 case DW_AT_sibling
:
17985 /* Ignore absolute siblings, they might point outside of
17986 the current compile unit. */
17987 if (attr
.form
== DW_FORM_ref_addr
)
17988 complaint (_("ignoring absolute DW_AT_sibling"));
17991 const gdb_byte
*buffer
= reader
->buffer
;
17992 sect_offset off
= attr
.get_ref_die_offset ();
17993 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17995 if (sibling_ptr
< info_ptr
)
17996 complaint (_("DW_AT_sibling points backwards"));
17997 else if (sibling_ptr
> reader
->buffer_end
)
17998 reader
->die_section
->overflow_complaint ();
18000 sibling
= sibling_ptr
;
18003 case DW_AT_byte_size
:
18006 case DW_AT_const_value
:
18007 has_const_value
= 1;
18009 case DW_AT_calling_convention
:
18010 /* DWARF doesn't provide a way to identify a program's source-level
18011 entry point. DW_AT_calling_convention attributes are only meant
18012 to describe functions' calling conventions.
18014 However, because it's a necessary piece of information in
18015 Fortran, and before DWARF 4 DW_CC_program was the only
18016 piece of debugging information whose definition refers to
18017 a 'main program' at all, several compilers marked Fortran
18018 main programs with DW_CC_program --- even when those
18019 functions use the standard calling conventions.
18021 Although DWARF now specifies a way to provide this
18022 information, we support this practice for backward
18024 if (DW_UNSND (&attr
) == DW_CC_program
18025 && cu
->language
== language_fortran
)
18026 main_subprogram
= 1;
18029 if (DW_UNSND (&attr
) == DW_INL_inlined
18030 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18031 may_be_inlined
= 1;
18035 if (tag
== DW_TAG_imported_unit
)
18037 d
.sect_off
= attr
.get_ref_die_offset ();
18038 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18039 || cu
->per_cu
->is_dwz
);
18043 case DW_AT_main_subprogram
:
18044 main_subprogram
= DW_UNSND (&attr
);
18049 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18050 but that requires a full DIE, so instead we just
18052 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18053 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18054 + (need_ranges_base
18058 /* Value of the DW_AT_ranges attribute is the offset in the
18059 .debug_ranges section. */
18060 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18071 /* For Ada, if both the name and the linkage name appear, we prefer
18072 the latter. This lets "catch exception" work better, regardless
18073 of the order in which the name and linkage name were emitted.
18074 Really, though, this is just a workaround for the fact that gdb
18075 doesn't store both the name and the linkage name. */
18076 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18077 name
= linkage_name
;
18079 if (high_pc_relative
)
18082 if (has_low_pc_attr
&& has_high_pc_attr
)
18084 /* When using the GNU linker, .gnu.linkonce. sections are used to
18085 eliminate duplicate copies of functions and vtables and such.
18086 The linker will arbitrarily choose one and discard the others.
18087 The AT_*_pc values for such functions refer to local labels in
18088 these sections. If the section from that file was discarded, the
18089 labels are not in the output, so the relocs get a value of 0.
18090 If this is a discarded function, mark the pc bounds as invalid,
18091 so that GDB will ignore it. */
18092 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18094 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18095 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18097 complaint (_("DW_AT_low_pc %s is zero "
18098 "for DIE at %s [in module %s]"),
18099 paddress (gdbarch
, lowpc
),
18100 sect_offset_str (sect_off
),
18101 objfile_name (objfile
));
18103 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18104 else if (lowpc
>= highpc
)
18106 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18107 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18109 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18110 "for DIE at %s [in module %s]"),
18111 paddress (gdbarch
, lowpc
),
18112 paddress (gdbarch
, highpc
),
18113 sect_offset_str (sect_off
),
18114 objfile_name (objfile
));
18123 /* Find a cached partial DIE at OFFSET in CU. */
18125 struct partial_die_info
*
18126 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18128 struct partial_die_info
*lookup_die
= NULL
;
18129 struct partial_die_info
part_die (sect_off
);
18131 lookup_die
= ((struct partial_die_info
*)
18132 htab_find_with_hash (partial_dies
, &part_die
,
18133 to_underlying (sect_off
)));
18138 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18139 except in the case of .debug_types DIEs which do not reference
18140 outside their CU (they do however referencing other types via
18141 DW_FORM_ref_sig8). */
18143 static const struct cu_partial_die_info
18144 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18146 struct dwarf2_per_objfile
*dwarf2_per_objfile
18147 = cu
->per_cu
->dwarf2_per_objfile
;
18148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18149 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18150 struct partial_die_info
*pd
= NULL
;
18152 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18153 && cu
->header
.offset_in_cu_p (sect_off
))
18155 pd
= cu
->find_partial_die (sect_off
);
18158 /* We missed recording what we needed.
18159 Load all dies and try again. */
18160 per_cu
= cu
->per_cu
;
18164 /* TUs don't reference other CUs/TUs (except via type signatures). */
18165 if (cu
->per_cu
->is_debug_types
)
18167 error (_("Dwarf Error: Type Unit at offset %s contains"
18168 " external reference to offset %s [in module %s].\n"),
18169 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18170 bfd_get_filename (objfile
->obfd
));
18172 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18173 dwarf2_per_objfile
);
18175 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18176 load_partial_comp_unit (per_cu
);
18178 per_cu
->cu
->last_used
= 0;
18179 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18182 /* If we didn't find it, and not all dies have been loaded,
18183 load them all and try again. */
18185 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18187 per_cu
->load_all_dies
= 1;
18189 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18190 THIS_CU->cu may already be in use. So we can't just free it and
18191 replace its DIEs with the ones we read in. Instead, we leave those
18192 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18193 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18195 load_partial_comp_unit (per_cu
);
18197 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18201 internal_error (__FILE__
, __LINE__
,
18202 _("could not find partial DIE %s "
18203 "in cache [from module %s]\n"),
18204 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18205 return { per_cu
->cu
, pd
};
18208 /* See if we can figure out if the class lives in a namespace. We do
18209 this by looking for a member function; its demangled name will
18210 contain namespace info, if there is any. */
18213 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18214 struct dwarf2_cu
*cu
)
18216 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18217 what template types look like, because the demangler
18218 frequently doesn't give the same name as the debug info. We
18219 could fix this by only using the demangled name to get the
18220 prefix (but see comment in read_structure_type). */
18222 struct partial_die_info
*real_pdi
;
18223 struct partial_die_info
*child_pdi
;
18225 /* If this DIE (this DIE's specification, if any) has a parent, then
18226 we should not do this. We'll prepend the parent's fully qualified
18227 name when we create the partial symbol. */
18229 real_pdi
= struct_pdi
;
18230 while (real_pdi
->has_specification
)
18232 auto res
= find_partial_die (real_pdi
->spec_offset
,
18233 real_pdi
->spec_is_dwz
, cu
);
18234 real_pdi
= res
.pdi
;
18238 if (real_pdi
->die_parent
!= NULL
)
18241 for (child_pdi
= struct_pdi
->die_child
;
18243 child_pdi
= child_pdi
->die_sibling
)
18245 if (child_pdi
->tag
== DW_TAG_subprogram
18246 && child_pdi
->linkage_name
!= NULL
)
18248 gdb::unique_xmalloc_ptr
<char> actual_class_name
18249 (language_class_name_from_physname (cu
->language_defn
,
18250 child_pdi
->linkage_name
));
18251 if (actual_class_name
!= NULL
)
18253 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18254 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18261 /* Return true if a DIE with TAG may have the DW_AT_const_value
18265 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18269 case DW_TAG_constant
:
18270 case DW_TAG_enumerator
:
18271 case DW_TAG_formal_parameter
:
18272 case DW_TAG_template_value_param
:
18273 case DW_TAG_variable
:
18281 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18283 /* Once we've fixed up a die, there's no point in doing so again.
18284 This also avoids a memory leak if we were to call
18285 guess_partial_die_structure_name multiple times. */
18289 /* If we found a reference attribute and the DIE has no name, try
18290 to find a name in the referred to DIE. */
18292 if (name
== NULL
&& has_specification
)
18294 struct partial_die_info
*spec_die
;
18296 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18297 spec_die
= res
.pdi
;
18300 spec_die
->fixup (cu
);
18302 if (spec_die
->name
)
18304 name
= spec_die
->name
;
18306 /* Copy DW_AT_external attribute if it is set. */
18307 if (spec_die
->is_external
)
18308 is_external
= spec_die
->is_external
;
18312 if (!has_const_value
&& has_specification
18313 && can_have_DW_AT_const_value_p (tag
))
18315 struct partial_die_info
*spec_die
;
18317 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18318 spec_die
= res
.pdi
;
18321 spec_die
->fixup (cu
);
18323 if (spec_die
->has_const_value
)
18325 /* Copy DW_AT_const_value attribute if it is set. */
18326 has_const_value
= spec_die
->has_const_value
;
18330 /* Set default names for some unnamed DIEs. */
18332 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18333 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18335 /* If there is no parent die to provide a namespace, and there are
18336 children, see if we can determine the namespace from their linkage
18338 if (cu
->language
== language_cplus
18339 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18340 && die_parent
== NULL
18342 && (tag
== DW_TAG_class_type
18343 || tag
== DW_TAG_structure_type
18344 || tag
== DW_TAG_union_type
))
18345 guess_partial_die_structure_name (this, cu
);
18347 /* GCC might emit a nameless struct or union that has a linkage
18348 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18350 && (tag
== DW_TAG_class_type
18351 || tag
== DW_TAG_interface_type
18352 || tag
== DW_TAG_structure_type
18353 || tag
== DW_TAG_union_type
)
18354 && linkage_name
!= NULL
)
18356 gdb::unique_xmalloc_ptr
<char> demangled
18357 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18358 if (demangled
!= nullptr)
18362 /* Strip any leading namespaces/classes, keep only the base name.
18363 DW_AT_name for named DIEs does not contain the prefixes. */
18364 base
= strrchr (demangled
.get (), ':');
18365 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18368 base
= demangled
.get ();
18370 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18371 name
= objfile
->intern (base
);
18378 /* Process the attributes that had to be skipped in the first round. These
18379 attributes are the ones that need str_offsets_base or addr_base attributes.
18380 They could not have been processed in the first round, because at the time
18381 the values of str_offsets_base or addr_base may not have been known. */
18383 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18384 struct attribute
*attr
)
18386 struct dwarf2_cu
*cu
= reader
->cu
;
18387 switch (attr
->form
)
18389 case DW_FORM_addrx
:
18390 case DW_FORM_GNU_addr_index
:
18391 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18394 case DW_FORM_strx1
:
18395 case DW_FORM_strx2
:
18396 case DW_FORM_strx3
:
18397 case DW_FORM_strx4
:
18398 case DW_FORM_GNU_str_index
:
18400 unsigned int str_index
= DW_UNSND (attr
);
18401 if (reader
->dwo_file
!= NULL
)
18403 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18404 DW_STRING_IS_CANONICAL (attr
) = 0;
18408 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18409 DW_STRING_IS_CANONICAL (attr
) = 0;
18414 gdb_assert_not_reached (_("Unexpected DWARF form."));
18418 /* Read an attribute value described by an attribute form. */
18420 static const gdb_byte
*
18421 read_attribute_value (const struct die_reader_specs
*reader
,
18422 struct attribute
*attr
, unsigned form
,
18423 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18424 bool *need_reprocess
)
18426 struct dwarf2_cu
*cu
= reader
->cu
;
18427 struct dwarf2_per_objfile
*dwarf2_per_objfile
18428 = cu
->per_cu
->dwarf2_per_objfile
;
18429 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18430 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18431 bfd
*abfd
= reader
->abfd
;
18432 struct comp_unit_head
*cu_header
= &cu
->header
;
18433 unsigned int bytes_read
;
18434 struct dwarf_block
*blk
;
18435 *need_reprocess
= false;
18437 attr
->form
= (enum dwarf_form
) form
;
18440 case DW_FORM_ref_addr
:
18441 if (cu
->header
.version
== 2)
18442 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18445 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18447 info_ptr
+= bytes_read
;
18449 case DW_FORM_GNU_ref_alt
:
18450 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18451 info_ptr
+= bytes_read
;
18454 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18455 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18456 info_ptr
+= bytes_read
;
18458 case DW_FORM_block2
:
18459 blk
= dwarf_alloc_block (cu
);
18460 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18462 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18463 info_ptr
+= blk
->size
;
18464 DW_BLOCK (attr
) = blk
;
18466 case DW_FORM_block4
:
18467 blk
= dwarf_alloc_block (cu
);
18468 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18470 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18471 info_ptr
+= blk
->size
;
18472 DW_BLOCK (attr
) = blk
;
18474 case DW_FORM_data2
:
18475 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18478 case DW_FORM_data4
:
18479 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18482 case DW_FORM_data8
:
18483 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18486 case DW_FORM_data16
:
18487 blk
= dwarf_alloc_block (cu
);
18489 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18491 DW_BLOCK (attr
) = blk
;
18493 case DW_FORM_sec_offset
:
18494 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18495 info_ptr
+= bytes_read
;
18497 case DW_FORM_string
:
18498 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18499 DW_STRING_IS_CANONICAL (attr
) = 0;
18500 info_ptr
+= bytes_read
;
18503 if (!cu
->per_cu
->is_dwz
)
18505 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18506 abfd
, info_ptr
, cu_header
,
18508 DW_STRING_IS_CANONICAL (attr
) = 0;
18509 info_ptr
+= bytes_read
;
18513 case DW_FORM_line_strp
:
18514 if (!cu
->per_cu
->is_dwz
)
18517 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18519 DW_STRING_IS_CANONICAL (attr
) = 0;
18520 info_ptr
+= bytes_read
;
18524 case DW_FORM_GNU_strp_alt
:
18526 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18527 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18530 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18531 DW_STRING_IS_CANONICAL (attr
) = 0;
18532 info_ptr
+= bytes_read
;
18535 case DW_FORM_exprloc
:
18536 case DW_FORM_block
:
18537 blk
= dwarf_alloc_block (cu
);
18538 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18539 info_ptr
+= bytes_read
;
18540 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18541 info_ptr
+= blk
->size
;
18542 DW_BLOCK (attr
) = blk
;
18544 case DW_FORM_block1
:
18545 blk
= dwarf_alloc_block (cu
);
18546 blk
->size
= read_1_byte (abfd
, info_ptr
);
18548 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18549 info_ptr
+= blk
->size
;
18550 DW_BLOCK (attr
) = blk
;
18552 case DW_FORM_data1
:
18553 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18557 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18560 case DW_FORM_flag_present
:
18561 DW_UNSND (attr
) = 1;
18563 case DW_FORM_sdata
:
18564 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18565 info_ptr
+= bytes_read
;
18567 case DW_FORM_udata
:
18568 case DW_FORM_rnglistx
:
18569 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18570 info_ptr
+= bytes_read
;
18573 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18574 + read_1_byte (abfd
, info_ptr
));
18578 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18579 + read_2_bytes (abfd
, info_ptr
));
18583 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18584 + read_4_bytes (abfd
, info_ptr
));
18588 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18589 + read_8_bytes (abfd
, info_ptr
));
18592 case DW_FORM_ref_sig8
:
18593 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18596 case DW_FORM_ref_udata
:
18597 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18598 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18599 info_ptr
+= bytes_read
;
18601 case DW_FORM_indirect
:
18602 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18603 info_ptr
+= bytes_read
;
18604 if (form
== DW_FORM_implicit_const
)
18606 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18607 info_ptr
+= bytes_read
;
18609 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18610 info_ptr
, need_reprocess
);
18612 case DW_FORM_implicit_const
:
18613 DW_SND (attr
) = implicit_const
;
18615 case DW_FORM_addrx
:
18616 case DW_FORM_GNU_addr_index
:
18617 *need_reprocess
= true;
18618 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18619 info_ptr
+= bytes_read
;
18622 case DW_FORM_strx1
:
18623 case DW_FORM_strx2
:
18624 case DW_FORM_strx3
:
18625 case DW_FORM_strx4
:
18626 case DW_FORM_GNU_str_index
:
18628 ULONGEST str_index
;
18629 if (form
== DW_FORM_strx1
)
18631 str_index
= read_1_byte (abfd
, info_ptr
);
18634 else if (form
== DW_FORM_strx2
)
18636 str_index
= read_2_bytes (abfd
, info_ptr
);
18639 else if (form
== DW_FORM_strx3
)
18641 str_index
= read_3_bytes (abfd
, info_ptr
);
18644 else if (form
== DW_FORM_strx4
)
18646 str_index
= read_4_bytes (abfd
, info_ptr
);
18651 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18652 info_ptr
+= bytes_read
;
18654 *need_reprocess
= true;
18655 DW_UNSND (attr
) = str_index
;
18659 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18660 dwarf_form_name (form
),
18661 bfd_get_filename (abfd
));
18665 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18666 attr
->form
= DW_FORM_GNU_ref_alt
;
18668 /* We have seen instances where the compiler tried to emit a byte
18669 size attribute of -1 which ended up being encoded as an unsigned
18670 0xffffffff. Although 0xffffffff is technically a valid size value,
18671 an object of this size seems pretty unlikely so we can relatively
18672 safely treat these cases as if the size attribute was invalid and
18673 treat them as zero by default. */
18674 if (attr
->name
== DW_AT_byte_size
18675 && form
== DW_FORM_data4
18676 && DW_UNSND (attr
) >= 0xffffffff)
18679 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18680 hex_string (DW_UNSND (attr
)));
18681 DW_UNSND (attr
) = 0;
18687 /* Read an attribute described by an abbreviated attribute. */
18689 static const gdb_byte
*
18690 read_attribute (const struct die_reader_specs
*reader
,
18691 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18692 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18694 attr
->name
= abbrev
->name
;
18695 return read_attribute_value (reader
, attr
, abbrev
->form
,
18696 abbrev
->implicit_const
, info_ptr
,
18700 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18702 static const char *
18703 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18704 LONGEST str_offset
)
18706 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18707 str_offset
, "DW_FORM_strp");
18710 /* Return pointer to string at .debug_str offset as read from BUF.
18711 BUF is assumed to be in a compilation unit described by CU_HEADER.
18712 Return *BYTES_READ_PTR count of bytes read from BUF. */
18714 static const char *
18715 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18716 const gdb_byte
*buf
,
18717 const struct comp_unit_head
*cu_header
,
18718 unsigned int *bytes_read_ptr
)
18720 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18722 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18728 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18729 const struct comp_unit_head
*cu_header
,
18730 unsigned int *bytes_read_ptr
)
18732 bfd
*abfd
= objfile
->obfd
;
18733 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18735 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18738 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18739 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18740 ADDR_SIZE is the size of addresses from the CU header. */
18743 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18744 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18747 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18748 bfd
*abfd
= objfile
->obfd
;
18749 const gdb_byte
*info_ptr
;
18750 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18752 dwarf2_per_objfile
->addr
.read (objfile
);
18753 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18754 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18755 objfile_name (objfile
));
18756 if (addr_base_or_zero
+ addr_index
* addr_size
18757 >= dwarf2_per_objfile
->addr
.size
)
18758 error (_("DW_FORM_addr_index pointing outside of "
18759 ".debug_addr section [in module %s]"),
18760 objfile_name (objfile
));
18761 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18762 + addr_base_or_zero
+ addr_index
* addr_size
);
18763 if (addr_size
== 4)
18764 return bfd_get_32 (abfd
, info_ptr
);
18766 return bfd_get_64 (abfd
, info_ptr
);
18769 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18772 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18774 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18775 cu
->addr_base
, cu
->header
.addr_size
);
18778 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18781 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18782 unsigned int *bytes_read
)
18784 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18785 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18787 return read_addr_index (cu
, addr_index
);
18793 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18795 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18796 struct dwarf2_cu
*cu
= per_cu
->cu
;
18797 gdb::optional
<ULONGEST
> addr_base
;
18800 /* We need addr_base and addr_size.
18801 If we don't have PER_CU->cu, we have to get it.
18802 Nasty, but the alternative is storing the needed info in PER_CU,
18803 which at this point doesn't seem justified: it's not clear how frequently
18804 it would get used and it would increase the size of every PER_CU.
18805 Entry points like dwarf2_per_cu_addr_size do a similar thing
18806 so we're not in uncharted territory here.
18807 Alas we need to be a bit more complicated as addr_base is contained
18810 We don't need to read the entire CU(/TU).
18811 We just need the header and top level die.
18813 IWBN to use the aging mechanism to let us lazily later discard the CU.
18814 For now we skip this optimization. */
18818 addr_base
= cu
->addr_base
;
18819 addr_size
= cu
->header
.addr_size
;
18823 cutu_reader
reader (per_cu
, NULL
, 0, false);
18824 addr_base
= reader
.cu
->addr_base
;
18825 addr_size
= reader
.cu
->header
.addr_size
;
18828 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18832 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18833 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18836 static const char *
18837 read_str_index (struct dwarf2_cu
*cu
,
18838 struct dwarf2_section_info
*str_section
,
18839 struct dwarf2_section_info
*str_offsets_section
,
18840 ULONGEST str_offsets_base
, ULONGEST str_index
)
18842 struct dwarf2_per_objfile
*dwarf2_per_objfile
18843 = cu
->per_cu
->dwarf2_per_objfile
;
18844 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18845 const char *objf_name
= objfile_name (objfile
);
18846 bfd
*abfd
= objfile
->obfd
;
18847 const gdb_byte
*info_ptr
;
18848 ULONGEST str_offset
;
18849 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18851 str_section
->read (objfile
);
18852 str_offsets_section
->read (objfile
);
18853 if (str_section
->buffer
== NULL
)
18854 error (_("%s used without %s section"
18855 " in CU at offset %s [in module %s]"),
18856 form_name
, str_section
->get_name (),
18857 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18858 if (str_offsets_section
->buffer
== NULL
)
18859 error (_("%s used without %s section"
18860 " in CU at offset %s [in module %s]"),
18861 form_name
, str_section
->get_name (),
18862 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18863 info_ptr
= (str_offsets_section
->buffer
18865 + str_index
* cu
->header
.offset_size
);
18866 if (cu
->header
.offset_size
== 4)
18867 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18869 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18870 if (str_offset
>= str_section
->size
)
18871 error (_("Offset from %s pointing outside of"
18872 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18873 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18874 return (const char *) (str_section
->buffer
+ str_offset
);
18877 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18879 static const char *
18880 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18882 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18883 ? reader
->cu
->header
.addr_size
: 0;
18884 return read_str_index (reader
->cu
,
18885 &reader
->dwo_file
->sections
.str
,
18886 &reader
->dwo_file
->sections
.str_offsets
,
18887 str_offsets_base
, str_index
);
18890 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18892 static const char *
18893 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18895 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18896 const char *objf_name
= objfile_name (objfile
);
18897 static const char form_name
[] = "DW_FORM_GNU_str_index";
18898 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18900 if (!cu
->str_offsets_base
.has_value ())
18901 error (_("%s used in Fission stub without %s"
18902 " in CU at offset 0x%lx [in module %s]"),
18903 form_name
, str_offsets_attr_name
,
18904 (long) cu
->header
.offset_size
, objf_name
);
18906 return read_str_index (cu
,
18907 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18908 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18909 *cu
->str_offsets_base
, str_index
);
18912 /* Return the length of an LEB128 number in BUF. */
18915 leb128_size (const gdb_byte
*buf
)
18917 const gdb_byte
*begin
= buf
;
18923 if ((byte
& 128) == 0)
18924 return buf
- begin
;
18929 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18938 cu
->language
= language_c
;
18941 case DW_LANG_C_plus_plus
:
18942 case DW_LANG_C_plus_plus_11
:
18943 case DW_LANG_C_plus_plus_14
:
18944 cu
->language
= language_cplus
;
18947 cu
->language
= language_d
;
18949 case DW_LANG_Fortran77
:
18950 case DW_LANG_Fortran90
:
18951 case DW_LANG_Fortran95
:
18952 case DW_LANG_Fortran03
:
18953 case DW_LANG_Fortran08
:
18954 cu
->language
= language_fortran
;
18957 cu
->language
= language_go
;
18959 case DW_LANG_Mips_Assembler
:
18960 cu
->language
= language_asm
;
18962 case DW_LANG_Ada83
:
18963 case DW_LANG_Ada95
:
18964 cu
->language
= language_ada
;
18966 case DW_LANG_Modula2
:
18967 cu
->language
= language_m2
;
18969 case DW_LANG_Pascal83
:
18970 cu
->language
= language_pascal
;
18973 cu
->language
= language_objc
;
18976 case DW_LANG_Rust_old
:
18977 cu
->language
= language_rust
;
18979 case DW_LANG_Cobol74
:
18980 case DW_LANG_Cobol85
:
18982 cu
->language
= language_minimal
;
18985 cu
->language_defn
= language_def (cu
->language
);
18988 /* Return the named attribute or NULL if not there. */
18990 static struct attribute
*
18991 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18996 struct attribute
*spec
= NULL
;
18998 for (i
= 0; i
< die
->num_attrs
; ++i
)
19000 if (die
->attrs
[i
].name
== name
)
19001 return &die
->attrs
[i
];
19002 if (die
->attrs
[i
].name
== DW_AT_specification
19003 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19004 spec
= &die
->attrs
[i
];
19010 die
= follow_die_ref (die
, spec
, &cu
);
19016 /* Return the string associated with a string-typed attribute, or NULL if it
19017 is either not found or is of an incorrect type. */
19019 static const char *
19020 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19022 struct attribute
*attr
;
19023 const char *str
= NULL
;
19025 attr
= dwarf2_attr (die
, name
, cu
);
19029 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19030 || attr
->form
== DW_FORM_string
19031 || attr
->form
== DW_FORM_strx
19032 || attr
->form
== DW_FORM_strx1
19033 || attr
->form
== DW_FORM_strx2
19034 || attr
->form
== DW_FORM_strx3
19035 || attr
->form
== DW_FORM_strx4
19036 || attr
->form
== DW_FORM_GNU_str_index
19037 || attr
->form
== DW_FORM_GNU_strp_alt
)
19038 str
= DW_STRING (attr
);
19040 complaint (_("string type expected for attribute %s for "
19041 "DIE at %s in module %s"),
19042 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19043 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19049 /* Return the dwo name or NULL if not present. If present, it is in either
19050 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19051 static const char *
19052 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19054 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19055 if (dwo_name
== nullptr)
19056 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19060 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19061 and holds a non-zero value. This function should only be used for
19062 DW_FORM_flag or DW_FORM_flag_present attributes. */
19065 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19067 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19069 return (attr
&& DW_UNSND (attr
));
19073 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19075 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19076 which value is non-zero. However, we have to be careful with
19077 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19078 (via dwarf2_flag_true_p) follows this attribute. So we may
19079 end up accidently finding a declaration attribute that belongs
19080 to a different DIE referenced by the specification attribute,
19081 even though the given DIE does not have a declaration attribute. */
19082 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19083 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19086 /* Return the die giving the specification for DIE, if there is
19087 one. *SPEC_CU is the CU containing DIE on input, and the CU
19088 containing the return value on output. If there is no
19089 specification, but there is an abstract origin, that is
19092 static struct die_info
*
19093 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19095 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19098 if (spec_attr
== NULL
)
19099 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19101 if (spec_attr
== NULL
)
19104 return follow_die_ref (die
, spec_attr
, spec_cu
);
19107 /* Stub for free_line_header to match void * callback types. */
19110 free_line_header_voidp (void *arg
)
19112 struct line_header
*lh
= (struct line_header
*) arg
;
19117 /* A convenience function to find the proper .debug_line section for a CU. */
19119 static struct dwarf2_section_info
*
19120 get_debug_line_section (struct dwarf2_cu
*cu
)
19122 struct dwarf2_section_info
*section
;
19123 struct dwarf2_per_objfile
*dwarf2_per_objfile
19124 = cu
->per_cu
->dwarf2_per_objfile
;
19126 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19128 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19129 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19130 else if (cu
->per_cu
->is_dwz
)
19132 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19134 section
= &dwz
->line
;
19137 section
= &dwarf2_per_objfile
->line
;
19142 /* Read the statement program header starting at OFFSET in
19143 .debug_line, or .debug_line.dwo. Return a pointer
19144 to a struct line_header, allocated using xmalloc.
19145 Returns NULL if there is a problem reading the header, e.g., if it
19146 has a version we don't understand.
19148 NOTE: the strings in the include directory and file name tables of
19149 the returned object point into the dwarf line section buffer,
19150 and must not be freed. */
19152 static line_header_up
19153 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19155 struct dwarf2_section_info
*section
;
19156 struct dwarf2_per_objfile
*dwarf2_per_objfile
19157 = cu
->per_cu
->dwarf2_per_objfile
;
19159 section
= get_debug_line_section (cu
);
19160 section
->read (dwarf2_per_objfile
->objfile
);
19161 if (section
->buffer
== NULL
)
19163 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19164 complaint (_("missing .debug_line.dwo section"));
19166 complaint (_("missing .debug_line section"));
19170 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19171 dwarf2_per_objfile
, section
,
19175 /* Subroutine of dwarf_decode_lines to simplify it.
19176 Return the file name of the psymtab for the given file_entry.
19177 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19178 If space for the result is malloc'd, *NAME_HOLDER will be set.
19179 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19181 static const char *
19182 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19183 const dwarf2_psymtab
*pst
,
19184 const char *comp_dir
,
19185 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19187 const char *include_name
= fe
.name
;
19188 const char *include_name_to_compare
= include_name
;
19189 const char *pst_filename
;
19192 const char *dir_name
= fe
.include_dir (lh
);
19194 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19195 if (!IS_ABSOLUTE_PATH (include_name
)
19196 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19198 /* Avoid creating a duplicate psymtab for PST.
19199 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19200 Before we do the comparison, however, we need to account
19201 for DIR_NAME and COMP_DIR.
19202 First prepend dir_name (if non-NULL). If we still don't
19203 have an absolute path prepend comp_dir (if non-NULL).
19204 However, the directory we record in the include-file's
19205 psymtab does not contain COMP_DIR (to match the
19206 corresponding symtab(s)).
19211 bash$ gcc -g ./hello.c
19212 include_name = "hello.c"
19214 DW_AT_comp_dir = comp_dir = "/tmp"
19215 DW_AT_name = "./hello.c"
19219 if (dir_name
!= NULL
)
19221 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19222 include_name
, (char *) NULL
));
19223 include_name
= name_holder
->get ();
19224 include_name_to_compare
= include_name
;
19226 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19228 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19229 include_name
, (char *) NULL
));
19230 include_name_to_compare
= hold_compare
.get ();
19234 pst_filename
= pst
->filename
;
19235 gdb::unique_xmalloc_ptr
<char> copied_name
;
19236 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19238 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19239 pst_filename
, (char *) NULL
));
19240 pst_filename
= copied_name
.get ();
19243 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19247 return include_name
;
19250 /* State machine to track the state of the line number program. */
19252 class lnp_state_machine
19255 /* Initialize a machine state for the start of a line number
19257 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19258 bool record_lines_p
);
19260 file_entry
*current_file ()
19262 /* lh->file_names is 0-based, but the file name numbers in the
19263 statement program are 1-based. */
19264 return m_line_header
->file_name_at (m_file
);
19267 /* Record the line in the state machine. END_SEQUENCE is true if
19268 we're processing the end of a sequence. */
19269 void record_line (bool end_sequence
);
19271 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19272 nop-out rest of the lines in this sequence. */
19273 void check_line_address (struct dwarf2_cu
*cu
,
19274 const gdb_byte
*line_ptr
,
19275 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19277 void handle_set_discriminator (unsigned int discriminator
)
19279 m_discriminator
= discriminator
;
19280 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19283 /* Handle DW_LNE_set_address. */
19284 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19287 address
+= baseaddr
;
19288 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19291 /* Handle DW_LNS_advance_pc. */
19292 void handle_advance_pc (CORE_ADDR adjust
);
19294 /* Handle a special opcode. */
19295 void handle_special_opcode (unsigned char op_code
);
19297 /* Handle DW_LNS_advance_line. */
19298 void handle_advance_line (int line_delta
)
19300 advance_line (line_delta
);
19303 /* Handle DW_LNS_set_file. */
19304 void handle_set_file (file_name_index file
);
19306 /* Handle DW_LNS_negate_stmt. */
19307 void handle_negate_stmt ()
19309 m_is_stmt
= !m_is_stmt
;
19312 /* Handle DW_LNS_const_add_pc. */
19313 void handle_const_add_pc ();
19315 /* Handle DW_LNS_fixed_advance_pc. */
19316 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19318 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19322 /* Handle DW_LNS_copy. */
19323 void handle_copy ()
19325 record_line (false);
19326 m_discriminator
= 0;
19329 /* Handle DW_LNE_end_sequence. */
19330 void handle_end_sequence ()
19332 m_currently_recording_lines
= true;
19336 /* Advance the line by LINE_DELTA. */
19337 void advance_line (int line_delta
)
19339 m_line
+= line_delta
;
19341 if (line_delta
!= 0)
19342 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19345 struct dwarf2_cu
*m_cu
;
19347 gdbarch
*m_gdbarch
;
19349 /* True if we're recording lines.
19350 Otherwise we're building partial symtabs and are just interested in
19351 finding include files mentioned by the line number program. */
19352 bool m_record_lines_p
;
19354 /* The line number header. */
19355 line_header
*m_line_header
;
19357 /* These are part of the standard DWARF line number state machine,
19358 and initialized according to the DWARF spec. */
19360 unsigned char m_op_index
= 0;
19361 /* The line table index of the current file. */
19362 file_name_index m_file
= 1;
19363 unsigned int m_line
= 1;
19365 /* These are initialized in the constructor. */
19367 CORE_ADDR m_address
;
19369 unsigned int m_discriminator
;
19371 /* Additional bits of state we need to track. */
19373 /* The last file that we called dwarf2_start_subfile for.
19374 This is only used for TLLs. */
19375 unsigned int m_last_file
= 0;
19376 /* The last file a line number was recorded for. */
19377 struct subfile
*m_last_subfile
= NULL
;
19379 /* When true, record the lines we decode. */
19380 bool m_currently_recording_lines
= false;
19382 /* The last line number that was recorded, used to coalesce
19383 consecutive entries for the same line. This can happen, for
19384 example, when discriminators are present. PR 17276. */
19385 unsigned int m_last_line
= 0;
19386 bool m_line_has_non_zero_discriminator
= false;
19390 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19392 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19393 / m_line_header
->maximum_ops_per_instruction
)
19394 * m_line_header
->minimum_instruction_length
);
19395 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19396 m_op_index
= ((m_op_index
+ adjust
)
19397 % m_line_header
->maximum_ops_per_instruction
);
19401 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19403 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19404 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19405 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19406 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19407 / m_line_header
->maximum_ops_per_instruction
)
19408 * m_line_header
->minimum_instruction_length
);
19409 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19410 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19411 % m_line_header
->maximum_ops_per_instruction
);
19413 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19414 advance_line (line_delta
);
19415 record_line (false);
19416 m_discriminator
= 0;
19420 lnp_state_machine::handle_set_file (file_name_index file
)
19424 const file_entry
*fe
= current_file ();
19426 dwarf2_debug_line_missing_file_complaint ();
19427 else if (m_record_lines_p
)
19429 const char *dir
= fe
->include_dir (m_line_header
);
19431 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19432 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19433 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19438 lnp_state_machine::handle_const_add_pc ()
19441 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19444 = (((m_op_index
+ adjust
)
19445 / m_line_header
->maximum_ops_per_instruction
)
19446 * m_line_header
->minimum_instruction_length
);
19448 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19449 m_op_index
= ((m_op_index
+ adjust
)
19450 % m_line_header
->maximum_ops_per_instruction
);
19453 /* Return non-zero if we should add LINE to the line number table.
19454 LINE is the line to add, LAST_LINE is the last line that was added,
19455 LAST_SUBFILE is the subfile for LAST_LINE.
19456 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19457 had a non-zero discriminator.
19459 We have to be careful in the presence of discriminators.
19460 E.g., for this line:
19462 for (i = 0; i < 100000; i++);
19464 clang can emit four line number entries for that one line,
19465 each with a different discriminator.
19466 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19468 However, we want gdb to coalesce all four entries into one.
19469 Otherwise the user could stepi into the middle of the line and
19470 gdb would get confused about whether the pc really was in the
19471 middle of the line.
19473 Things are further complicated by the fact that two consecutive
19474 line number entries for the same line is a heuristic used by gcc
19475 to denote the end of the prologue. So we can't just discard duplicate
19476 entries, we have to be selective about it. The heuristic we use is
19477 that we only collapse consecutive entries for the same line if at least
19478 one of those entries has a non-zero discriminator. PR 17276.
19480 Note: Addresses in the line number state machine can never go backwards
19481 within one sequence, thus this coalescing is ok. */
19484 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19485 unsigned int line
, unsigned int last_line
,
19486 int line_has_non_zero_discriminator
,
19487 struct subfile
*last_subfile
)
19489 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19491 if (line
!= last_line
)
19493 /* Same line for the same file that we've seen already.
19494 As a last check, for pr 17276, only record the line if the line
19495 has never had a non-zero discriminator. */
19496 if (!line_has_non_zero_discriminator
)
19501 /* Use the CU's builder to record line number LINE beginning at
19502 address ADDRESS in the line table of subfile SUBFILE. */
19505 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19506 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19507 struct dwarf2_cu
*cu
)
19509 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19511 if (dwarf_line_debug
)
19513 fprintf_unfiltered (gdb_stdlog
,
19514 "Recording line %u, file %s, address %s\n",
19515 line
, lbasename (subfile
->name
),
19516 paddress (gdbarch
, address
));
19520 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19523 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19524 Mark the end of a set of line number records.
19525 The arguments are the same as for dwarf_record_line_1.
19526 If SUBFILE is NULL the request is ignored. */
19529 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19530 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19532 if (subfile
== NULL
)
19535 if (dwarf_line_debug
)
19537 fprintf_unfiltered (gdb_stdlog
,
19538 "Finishing current line, file %s, address %s\n",
19539 lbasename (subfile
->name
),
19540 paddress (gdbarch
, address
));
19543 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19547 lnp_state_machine::record_line (bool end_sequence
)
19549 if (dwarf_line_debug
)
19551 fprintf_unfiltered (gdb_stdlog
,
19552 "Processing actual line %u: file %u,"
19553 " address %s, is_stmt %u, discrim %u%s\n",
19555 paddress (m_gdbarch
, m_address
),
19556 m_is_stmt
, m_discriminator
,
19557 (end_sequence
? "\t(end sequence)" : ""));
19560 file_entry
*fe
= current_file ();
19563 dwarf2_debug_line_missing_file_complaint ();
19564 /* For now we ignore lines not starting on an instruction boundary.
19565 But not when processing end_sequence for compatibility with the
19566 previous version of the code. */
19567 else if (m_op_index
== 0 || end_sequence
)
19569 fe
->included_p
= 1;
19570 if (m_record_lines_p
)
19572 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19575 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19576 m_currently_recording_lines
? m_cu
: nullptr);
19581 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19583 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19584 m_line_has_non_zero_discriminator
,
19587 buildsym_compunit
*builder
= m_cu
->get_builder ();
19588 dwarf_record_line_1 (m_gdbarch
,
19589 builder
->get_current_subfile (),
19590 m_line
, m_address
, is_stmt
,
19591 m_currently_recording_lines
? m_cu
: nullptr);
19593 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19594 m_last_line
= m_line
;
19600 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19601 line_header
*lh
, bool record_lines_p
)
19605 m_record_lines_p
= record_lines_p
;
19606 m_line_header
= lh
;
19608 m_currently_recording_lines
= true;
19610 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19611 was a line entry for it so that the backend has a chance to adjust it
19612 and also record it in case it needs it. This is currently used by MIPS
19613 code, cf. `mips_adjust_dwarf2_line'. */
19614 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19615 m_is_stmt
= lh
->default_is_stmt
;
19616 m_discriminator
= 0;
19620 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19621 const gdb_byte
*line_ptr
,
19622 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19624 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19625 the pc range of the CU. However, we restrict the test to only ADDRESS
19626 values of zero to preserve GDB's previous behaviour which is to handle
19627 the specific case of a function being GC'd by the linker. */
19629 if (address
== 0 && address
< unrelocated_lowpc
)
19631 /* This line table is for a function which has been
19632 GCd by the linker. Ignore it. PR gdb/12528 */
19634 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19635 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19637 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19638 line_offset
, objfile_name (objfile
));
19639 m_currently_recording_lines
= false;
19640 /* Note: m_currently_recording_lines is left as false until we see
19641 DW_LNE_end_sequence. */
19645 /* Subroutine of dwarf_decode_lines to simplify it.
19646 Process the line number information in LH.
19647 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19648 program in order to set included_p for every referenced header. */
19651 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19652 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19654 const gdb_byte
*line_ptr
, *extended_end
;
19655 const gdb_byte
*line_end
;
19656 unsigned int bytes_read
, extended_len
;
19657 unsigned char op_code
, extended_op
;
19658 CORE_ADDR baseaddr
;
19659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19660 bfd
*abfd
= objfile
->obfd
;
19661 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19662 /* True if we're recording line info (as opposed to building partial
19663 symtabs and just interested in finding include files mentioned by
19664 the line number program). */
19665 bool record_lines_p
= !decode_for_pst_p
;
19667 baseaddr
= objfile
->text_section_offset ();
19669 line_ptr
= lh
->statement_program_start
;
19670 line_end
= lh
->statement_program_end
;
19672 /* Read the statement sequences until there's nothing left. */
19673 while (line_ptr
< line_end
)
19675 /* The DWARF line number program state machine. Reset the state
19676 machine at the start of each sequence. */
19677 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19678 bool end_sequence
= false;
19680 if (record_lines_p
)
19682 /* Start a subfile for the current file of the state
19684 const file_entry
*fe
= state_machine
.current_file ();
19687 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19690 /* Decode the table. */
19691 while (line_ptr
< line_end
&& !end_sequence
)
19693 op_code
= read_1_byte (abfd
, line_ptr
);
19696 if (op_code
>= lh
->opcode_base
)
19698 /* Special opcode. */
19699 state_machine
.handle_special_opcode (op_code
);
19701 else switch (op_code
)
19703 case DW_LNS_extended_op
:
19704 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19706 line_ptr
+= bytes_read
;
19707 extended_end
= line_ptr
+ extended_len
;
19708 extended_op
= read_1_byte (abfd
, line_ptr
);
19710 switch (extended_op
)
19712 case DW_LNE_end_sequence
:
19713 state_machine
.handle_end_sequence ();
19714 end_sequence
= true;
19716 case DW_LNE_set_address
:
19719 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19720 line_ptr
+= bytes_read
;
19722 state_machine
.check_line_address (cu
, line_ptr
,
19723 lowpc
- baseaddr
, address
);
19724 state_machine
.handle_set_address (baseaddr
, address
);
19727 case DW_LNE_define_file
:
19729 const char *cur_file
;
19730 unsigned int mod_time
, length
;
19733 cur_file
= read_direct_string (abfd
, line_ptr
,
19735 line_ptr
+= bytes_read
;
19736 dindex
= (dir_index
)
19737 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19738 line_ptr
+= bytes_read
;
19740 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19741 line_ptr
+= bytes_read
;
19743 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19744 line_ptr
+= bytes_read
;
19745 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19748 case DW_LNE_set_discriminator
:
19750 /* The discriminator is not interesting to the
19751 debugger; just ignore it. We still need to
19752 check its value though:
19753 if there are consecutive entries for the same
19754 (non-prologue) line we want to coalesce them.
19757 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19758 line_ptr
+= bytes_read
;
19760 state_machine
.handle_set_discriminator (discr
);
19764 complaint (_("mangled .debug_line section"));
19767 /* Make sure that we parsed the extended op correctly. If e.g.
19768 we expected a different address size than the producer used,
19769 we may have read the wrong number of bytes. */
19770 if (line_ptr
!= extended_end
)
19772 complaint (_("mangled .debug_line section"));
19777 state_machine
.handle_copy ();
19779 case DW_LNS_advance_pc
:
19782 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19783 line_ptr
+= bytes_read
;
19785 state_machine
.handle_advance_pc (adjust
);
19788 case DW_LNS_advance_line
:
19791 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19792 line_ptr
+= bytes_read
;
19794 state_machine
.handle_advance_line (line_delta
);
19797 case DW_LNS_set_file
:
19799 file_name_index file
19800 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19802 line_ptr
+= bytes_read
;
19804 state_machine
.handle_set_file (file
);
19807 case DW_LNS_set_column
:
19808 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19809 line_ptr
+= bytes_read
;
19811 case DW_LNS_negate_stmt
:
19812 state_machine
.handle_negate_stmt ();
19814 case DW_LNS_set_basic_block
:
19816 /* Add to the address register of the state machine the
19817 address increment value corresponding to special opcode
19818 255. I.e., this value is scaled by the minimum
19819 instruction length since special opcode 255 would have
19820 scaled the increment. */
19821 case DW_LNS_const_add_pc
:
19822 state_machine
.handle_const_add_pc ();
19824 case DW_LNS_fixed_advance_pc
:
19826 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19829 state_machine
.handle_fixed_advance_pc (addr_adj
);
19834 /* Unknown standard opcode, ignore it. */
19837 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19839 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19840 line_ptr
+= bytes_read
;
19847 dwarf2_debug_line_missing_end_sequence_complaint ();
19849 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19850 in which case we still finish recording the last line). */
19851 state_machine
.record_line (true);
19855 /* Decode the Line Number Program (LNP) for the given line_header
19856 structure and CU. The actual information extracted and the type
19857 of structures created from the LNP depends on the value of PST.
19859 1. If PST is NULL, then this procedure uses the data from the program
19860 to create all necessary symbol tables, and their linetables.
19862 2. If PST is not NULL, this procedure reads the program to determine
19863 the list of files included by the unit represented by PST, and
19864 builds all the associated partial symbol tables.
19866 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19867 It is used for relative paths in the line table.
19868 NOTE: When processing partial symtabs (pst != NULL),
19869 comp_dir == pst->dirname.
19871 NOTE: It is important that psymtabs have the same file name (via strcmp)
19872 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19873 symtab we don't use it in the name of the psymtabs we create.
19874 E.g. expand_line_sal requires this when finding psymtabs to expand.
19875 A good testcase for this is mb-inline.exp.
19877 LOWPC is the lowest address in CU (or 0 if not known).
19879 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19880 for its PC<->lines mapping information. Otherwise only the filename
19881 table is read in. */
19884 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19885 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19886 CORE_ADDR lowpc
, int decode_mapping
)
19888 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19889 const int decode_for_pst_p
= (pst
!= NULL
);
19891 if (decode_mapping
)
19892 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19894 if (decode_for_pst_p
)
19896 /* Now that we're done scanning the Line Header Program, we can
19897 create the psymtab of each included file. */
19898 for (auto &file_entry
: lh
->file_names ())
19899 if (file_entry
.included_p
== 1)
19901 gdb::unique_xmalloc_ptr
<char> name_holder
;
19902 const char *include_name
=
19903 psymtab_include_file_name (lh
, file_entry
, pst
,
19904 comp_dir
, &name_holder
);
19905 if (include_name
!= NULL
)
19906 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19911 /* Make sure a symtab is created for every file, even files
19912 which contain only variables (i.e. no code with associated
19914 buildsym_compunit
*builder
= cu
->get_builder ();
19915 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19917 for (auto &fe
: lh
->file_names ())
19919 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19920 if (builder
->get_current_subfile ()->symtab
== NULL
)
19922 builder
->get_current_subfile ()->symtab
19923 = allocate_symtab (cust
,
19924 builder
->get_current_subfile ()->name
);
19926 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19931 /* Start a subfile for DWARF. FILENAME is the name of the file and
19932 DIRNAME the name of the source directory which contains FILENAME
19933 or NULL if not known.
19934 This routine tries to keep line numbers from identical absolute and
19935 relative file names in a common subfile.
19937 Using the `list' example from the GDB testsuite, which resides in
19938 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19939 of /srcdir/list0.c yields the following debugging information for list0.c:
19941 DW_AT_name: /srcdir/list0.c
19942 DW_AT_comp_dir: /compdir
19943 files.files[0].name: list0.h
19944 files.files[0].dir: /srcdir
19945 files.files[1].name: list0.c
19946 files.files[1].dir: /srcdir
19948 The line number information for list0.c has to end up in a single
19949 subfile, so that `break /srcdir/list0.c:1' works as expected.
19950 start_subfile will ensure that this happens provided that we pass the
19951 concatenation of files.files[1].dir and files.files[1].name as the
19955 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19956 const char *dirname
)
19958 gdb::unique_xmalloc_ptr
<char> copy
;
19960 /* In order not to lose the line information directory,
19961 we concatenate it to the filename when it makes sense.
19962 Note that the Dwarf3 standard says (speaking of filenames in line
19963 information): ``The directory index is ignored for file names
19964 that represent full path names''. Thus ignoring dirname in the
19965 `else' branch below isn't an issue. */
19967 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19969 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19970 filename
= copy
.get ();
19973 cu
->get_builder ()->start_subfile (filename
);
19976 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19977 buildsym_compunit constructor. */
19979 struct compunit_symtab
*
19980 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19983 gdb_assert (m_builder
== nullptr);
19985 m_builder
.reset (new struct buildsym_compunit
19986 (per_cu
->dwarf2_per_objfile
->objfile
,
19987 name
, comp_dir
, language
, low_pc
));
19989 list_in_scope
= get_builder ()->get_file_symbols ();
19991 get_builder ()->record_debugformat ("DWARF 2");
19992 get_builder ()->record_producer (producer
);
19994 processing_has_namespace_info
= false;
19996 return get_builder ()->get_compunit_symtab ();
20000 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20001 struct dwarf2_cu
*cu
)
20003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20004 struct comp_unit_head
*cu_header
= &cu
->header
;
20006 /* NOTE drow/2003-01-30: There used to be a comment and some special
20007 code here to turn a symbol with DW_AT_external and a
20008 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20009 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20010 with some versions of binutils) where shared libraries could have
20011 relocations against symbols in their debug information - the
20012 minimal symbol would have the right address, but the debug info
20013 would not. It's no longer necessary, because we will explicitly
20014 apply relocations when we read in the debug information now. */
20016 /* A DW_AT_location attribute with no contents indicates that a
20017 variable has been optimized away. */
20018 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20020 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20024 /* Handle one degenerate form of location expression specially, to
20025 preserve GDB's previous behavior when section offsets are
20026 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20027 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20029 if (attr
->form_is_block ()
20030 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20031 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20032 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20033 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20034 && (DW_BLOCK (attr
)->size
20035 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20037 unsigned int dummy
;
20039 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20040 SET_SYMBOL_VALUE_ADDRESS
20041 (sym
, cu
->header
.read_address (objfile
->obfd
,
20042 DW_BLOCK (attr
)->data
+ 1,
20045 SET_SYMBOL_VALUE_ADDRESS
20046 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20048 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20049 fixup_symbol_section (sym
, objfile
);
20050 SET_SYMBOL_VALUE_ADDRESS
20052 SYMBOL_VALUE_ADDRESS (sym
)
20053 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20057 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20058 expression evaluator, and use LOC_COMPUTED only when necessary
20059 (i.e. when the value of a register or memory location is
20060 referenced, or a thread-local block, etc.). Then again, it might
20061 not be worthwhile. I'm assuming that it isn't unless performance
20062 or memory numbers show me otherwise. */
20064 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20066 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20067 cu
->has_loclist
= true;
20070 /* Given a pointer to a DWARF information entry, figure out if we need
20071 to make a symbol table entry for it, and if so, create a new entry
20072 and return a pointer to it.
20073 If TYPE is NULL, determine symbol type from the die, otherwise
20074 used the passed type.
20075 If SPACE is not NULL, use it to hold the new symbol. If it is
20076 NULL, allocate a new symbol on the objfile's obstack. */
20078 static struct symbol
*
20079 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20080 struct symbol
*space
)
20082 struct dwarf2_per_objfile
*dwarf2_per_objfile
20083 = cu
->per_cu
->dwarf2_per_objfile
;
20084 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20085 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20086 struct symbol
*sym
= NULL
;
20088 struct attribute
*attr
= NULL
;
20089 struct attribute
*attr2
= NULL
;
20090 CORE_ADDR baseaddr
;
20091 struct pending
**list_to_add
= NULL
;
20093 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20095 baseaddr
= objfile
->text_section_offset ();
20097 name
= dwarf2_name (die
, cu
);
20100 const char *linkagename
;
20101 int suppress_add
= 0;
20106 sym
= allocate_symbol (objfile
);
20107 OBJSTAT (objfile
, n_syms
++);
20109 /* Cache this symbol's name and the name's demangled form (if any). */
20110 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20111 linkagename
= dwarf2_physname (name
, die
, cu
);
20112 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20114 /* Fortran does not have mangling standard and the mangling does differ
20115 between gfortran, iFort etc. */
20116 if (cu
->language
== language_fortran
20117 && symbol_get_demangled_name (sym
) == NULL
)
20118 symbol_set_demangled_name (sym
,
20119 dwarf2_full_name (name
, die
, cu
),
20122 /* Default assumptions.
20123 Use the passed type or decode it from the die. */
20124 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20125 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20127 SYMBOL_TYPE (sym
) = type
;
20129 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20130 attr
= dwarf2_attr (die
,
20131 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20133 if (attr
!= nullptr)
20135 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20138 attr
= dwarf2_attr (die
,
20139 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20141 if (attr
!= nullptr)
20143 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20144 struct file_entry
*fe
;
20146 if (cu
->line_header
!= NULL
)
20147 fe
= cu
->line_header
->file_name_at (file_index
);
20152 complaint (_("file index out of range"));
20154 symbol_set_symtab (sym
, fe
->symtab
);
20160 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20161 if (attr
!= nullptr)
20165 addr
= attr
->value_as_address ();
20166 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20167 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20169 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20170 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20171 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20172 add_symbol_to_list (sym
, cu
->list_in_scope
);
20174 case DW_TAG_subprogram
:
20175 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20177 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20178 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20179 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20180 || cu
->language
== language_ada
20181 || cu
->language
== language_fortran
)
20183 /* Subprograms marked external are stored as a global symbol.
20184 Ada and Fortran subprograms, whether marked external or
20185 not, are always stored as a global symbol, because we want
20186 to be able to access them globally. For instance, we want
20187 to be able to break on a nested subprogram without having
20188 to specify the context. */
20189 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20193 list_to_add
= cu
->list_in_scope
;
20196 case DW_TAG_inlined_subroutine
:
20197 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20199 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20200 SYMBOL_INLINED (sym
) = 1;
20201 list_to_add
= cu
->list_in_scope
;
20203 case DW_TAG_template_value_param
:
20205 /* Fall through. */
20206 case DW_TAG_constant
:
20207 case DW_TAG_variable
:
20208 case DW_TAG_member
:
20209 /* Compilation with minimal debug info may result in
20210 variables with missing type entries. Change the
20211 misleading `void' type to something sensible. */
20212 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20213 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20215 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20216 /* In the case of DW_TAG_member, we should only be called for
20217 static const members. */
20218 if (die
->tag
== DW_TAG_member
)
20220 /* dwarf2_add_field uses die_is_declaration,
20221 so we do the same. */
20222 gdb_assert (die_is_declaration (die
, cu
));
20225 if (attr
!= nullptr)
20227 dwarf2_const_value (attr
, sym
, cu
);
20228 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20231 if (attr2
&& (DW_UNSND (attr2
) != 0))
20232 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20234 list_to_add
= cu
->list_in_scope
;
20238 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20239 if (attr
!= nullptr)
20241 var_decode_location (attr
, sym
, cu
);
20242 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20244 /* Fortran explicitly imports any global symbols to the local
20245 scope by DW_TAG_common_block. */
20246 if (cu
->language
== language_fortran
&& die
->parent
20247 && die
->parent
->tag
== DW_TAG_common_block
)
20250 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20251 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20252 && !dwarf2_per_objfile
->has_section_at_zero
)
20254 /* When a static variable is eliminated by the linker,
20255 the corresponding debug information is not stripped
20256 out, but the variable address is set to null;
20257 do not add such variables into symbol table. */
20259 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20261 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20262 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20263 && dwarf2_per_objfile
->can_copy
)
20265 /* A global static variable might be subject to
20266 copy relocation. We first check for a local
20267 minsym, though, because maybe the symbol was
20268 marked hidden, in which case this would not
20270 bound_minimal_symbol found
20271 = (lookup_minimal_symbol_linkage
20272 (sym
->linkage_name (), objfile
));
20273 if (found
.minsym
!= nullptr)
20274 sym
->maybe_copied
= 1;
20277 /* A variable with DW_AT_external is never static,
20278 but it may be block-scoped. */
20280 = ((cu
->list_in_scope
20281 == cu
->get_builder ()->get_file_symbols ())
20282 ? cu
->get_builder ()->get_global_symbols ()
20283 : cu
->list_in_scope
);
20286 list_to_add
= cu
->list_in_scope
;
20290 /* We do not know the address of this symbol.
20291 If it is an external symbol and we have type information
20292 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20293 The address of the variable will then be determined from
20294 the minimal symbol table whenever the variable is
20296 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20298 /* Fortran explicitly imports any global symbols to the local
20299 scope by DW_TAG_common_block. */
20300 if (cu
->language
== language_fortran
&& die
->parent
20301 && die
->parent
->tag
== DW_TAG_common_block
)
20303 /* SYMBOL_CLASS doesn't matter here because
20304 read_common_block is going to reset it. */
20306 list_to_add
= cu
->list_in_scope
;
20308 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20309 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20311 /* A variable with DW_AT_external is never static, but it
20312 may be block-scoped. */
20314 = ((cu
->list_in_scope
20315 == cu
->get_builder ()->get_file_symbols ())
20316 ? cu
->get_builder ()->get_global_symbols ()
20317 : cu
->list_in_scope
);
20319 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20321 else if (!die_is_declaration (die
, cu
))
20323 /* Use the default LOC_OPTIMIZED_OUT class. */
20324 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20326 list_to_add
= cu
->list_in_scope
;
20330 case DW_TAG_formal_parameter
:
20332 /* If we are inside a function, mark this as an argument. If
20333 not, we might be looking at an argument to an inlined function
20334 when we do not have enough information to show inlined frames;
20335 pretend it's a local variable in that case so that the user can
20337 struct context_stack
*curr
20338 = cu
->get_builder ()->get_current_context_stack ();
20339 if (curr
!= nullptr && curr
->name
!= nullptr)
20340 SYMBOL_IS_ARGUMENT (sym
) = 1;
20341 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20342 if (attr
!= nullptr)
20344 var_decode_location (attr
, sym
, cu
);
20346 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20347 if (attr
!= nullptr)
20349 dwarf2_const_value (attr
, sym
, cu
);
20352 list_to_add
= cu
->list_in_scope
;
20355 case DW_TAG_unspecified_parameters
:
20356 /* From varargs functions; gdb doesn't seem to have any
20357 interest in this information, so just ignore it for now.
20360 case DW_TAG_template_type_param
:
20362 /* Fall through. */
20363 case DW_TAG_class_type
:
20364 case DW_TAG_interface_type
:
20365 case DW_TAG_structure_type
:
20366 case DW_TAG_union_type
:
20367 case DW_TAG_set_type
:
20368 case DW_TAG_enumeration_type
:
20369 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20370 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20373 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20374 really ever be static objects: otherwise, if you try
20375 to, say, break of a class's method and you're in a file
20376 which doesn't mention that class, it won't work unless
20377 the check for all static symbols in lookup_symbol_aux
20378 saves you. See the OtherFileClass tests in
20379 gdb.c++/namespace.exp. */
20383 buildsym_compunit
*builder
= cu
->get_builder ();
20385 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20386 && cu
->language
== language_cplus
20387 ? builder
->get_global_symbols ()
20388 : cu
->list_in_scope
);
20390 /* The semantics of C++ state that "struct foo {
20391 ... }" also defines a typedef for "foo". */
20392 if (cu
->language
== language_cplus
20393 || cu
->language
== language_ada
20394 || cu
->language
== language_d
20395 || cu
->language
== language_rust
)
20397 /* The symbol's name is already allocated along
20398 with this objfile, so we don't need to
20399 duplicate it for the type. */
20400 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20401 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20406 case DW_TAG_typedef
:
20407 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20408 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20409 list_to_add
= cu
->list_in_scope
;
20411 case DW_TAG_base_type
:
20412 case DW_TAG_subrange_type
:
20413 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20414 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20415 list_to_add
= cu
->list_in_scope
;
20417 case DW_TAG_enumerator
:
20418 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20419 if (attr
!= nullptr)
20421 dwarf2_const_value (attr
, sym
, cu
);
20424 /* NOTE: carlton/2003-11-10: See comment above in the
20425 DW_TAG_class_type, etc. block. */
20428 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20429 && cu
->language
== language_cplus
20430 ? cu
->get_builder ()->get_global_symbols ()
20431 : cu
->list_in_scope
);
20434 case DW_TAG_imported_declaration
:
20435 case DW_TAG_namespace
:
20436 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20437 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20439 case DW_TAG_module
:
20440 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20441 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20442 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20444 case DW_TAG_common_block
:
20445 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20446 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20447 add_symbol_to_list (sym
, cu
->list_in_scope
);
20450 /* Not a tag we recognize. Hopefully we aren't processing
20451 trash data, but since we must specifically ignore things
20452 we don't recognize, there is nothing else we should do at
20454 complaint (_("unsupported tag: '%s'"),
20455 dwarf_tag_name (die
->tag
));
20461 sym
->hash_next
= objfile
->template_symbols
;
20462 objfile
->template_symbols
= sym
;
20463 list_to_add
= NULL
;
20466 if (list_to_add
!= NULL
)
20467 add_symbol_to_list (sym
, list_to_add
);
20469 /* For the benefit of old versions of GCC, check for anonymous
20470 namespaces based on the demangled name. */
20471 if (!cu
->processing_has_namespace_info
20472 && cu
->language
== language_cplus
)
20473 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20478 /* Given an attr with a DW_FORM_dataN value in host byte order,
20479 zero-extend it as appropriate for the symbol's type. The DWARF
20480 standard (v4) is not entirely clear about the meaning of using
20481 DW_FORM_dataN for a constant with a signed type, where the type is
20482 wider than the data. The conclusion of a discussion on the DWARF
20483 list was that this is unspecified. We choose to always zero-extend
20484 because that is the interpretation long in use by GCC. */
20487 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20488 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20490 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20491 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20492 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20493 LONGEST l
= DW_UNSND (attr
);
20495 if (bits
< sizeof (*value
) * 8)
20497 l
&= ((LONGEST
) 1 << bits
) - 1;
20500 else if (bits
== sizeof (*value
) * 8)
20504 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20505 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20512 /* Read a constant value from an attribute. Either set *VALUE, or if
20513 the value does not fit in *VALUE, set *BYTES - either already
20514 allocated on the objfile obstack, or newly allocated on OBSTACK,
20515 or, set *BATON, if we translated the constant to a location
20519 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20520 const char *name
, struct obstack
*obstack
,
20521 struct dwarf2_cu
*cu
,
20522 LONGEST
*value
, const gdb_byte
**bytes
,
20523 struct dwarf2_locexpr_baton
**baton
)
20525 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20526 struct comp_unit_head
*cu_header
= &cu
->header
;
20527 struct dwarf_block
*blk
;
20528 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20529 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20535 switch (attr
->form
)
20538 case DW_FORM_addrx
:
20539 case DW_FORM_GNU_addr_index
:
20543 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20544 dwarf2_const_value_length_mismatch_complaint (name
,
20545 cu_header
->addr_size
,
20546 TYPE_LENGTH (type
));
20547 /* Symbols of this form are reasonably rare, so we just
20548 piggyback on the existing location code rather than writing
20549 a new implementation of symbol_computed_ops. */
20550 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20551 (*baton
)->per_cu
= cu
->per_cu
;
20552 gdb_assert ((*baton
)->per_cu
);
20554 (*baton
)->size
= 2 + cu_header
->addr_size
;
20555 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20556 (*baton
)->data
= data
;
20558 data
[0] = DW_OP_addr
;
20559 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20560 byte_order
, DW_ADDR (attr
));
20561 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20564 case DW_FORM_string
:
20567 case DW_FORM_GNU_str_index
:
20568 case DW_FORM_GNU_strp_alt
:
20569 /* DW_STRING is already allocated on the objfile obstack, point
20571 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20573 case DW_FORM_block1
:
20574 case DW_FORM_block2
:
20575 case DW_FORM_block4
:
20576 case DW_FORM_block
:
20577 case DW_FORM_exprloc
:
20578 case DW_FORM_data16
:
20579 blk
= DW_BLOCK (attr
);
20580 if (TYPE_LENGTH (type
) != blk
->size
)
20581 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20582 TYPE_LENGTH (type
));
20583 *bytes
= blk
->data
;
20586 /* The DW_AT_const_value attributes are supposed to carry the
20587 symbol's value "represented as it would be on the target
20588 architecture." By the time we get here, it's already been
20589 converted to host endianness, so we just need to sign- or
20590 zero-extend it as appropriate. */
20591 case DW_FORM_data1
:
20592 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20594 case DW_FORM_data2
:
20595 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20597 case DW_FORM_data4
:
20598 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20600 case DW_FORM_data8
:
20601 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20604 case DW_FORM_sdata
:
20605 case DW_FORM_implicit_const
:
20606 *value
= DW_SND (attr
);
20609 case DW_FORM_udata
:
20610 *value
= DW_UNSND (attr
);
20614 complaint (_("unsupported const value attribute form: '%s'"),
20615 dwarf_form_name (attr
->form
));
20622 /* Copy constant value from an attribute to a symbol. */
20625 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20626 struct dwarf2_cu
*cu
)
20628 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20630 const gdb_byte
*bytes
;
20631 struct dwarf2_locexpr_baton
*baton
;
20633 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20634 sym
->print_name (),
20635 &objfile
->objfile_obstack
, cu
,
20636 &value
, &bytes
, &baton
);
20640 SYMBOL_LOCATION_BATON (sym
) = baton
;
20641 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20643 else if (bytes
!= NULL
)
20645 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20646 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20650 SYMBOL_VALUE (sym
) = value
;
20651 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20655 /* Return the type of the die in question using its DW_AT_type attribute. */
20657 static struct type
*
20658 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20660 struct attribute
*type_attr
;
20662 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20665 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20666 /* A missing DW_AT_type represents a void type. */
20667 return objfile_type (objfile
)->builtin_void
;
20670 return lookup_die_type (die
, type_attr
, cu
);
20673 /* True iff CU's producer generates GNAT Ada auxiliary information
20674 that allows to find parallel types through that information instead
20675 of having to do expensive parallel lookups by type name. */
20678 need_gnat_info (struct dwarf2_cu
*cu
)
20680 /* Assume that the Ada compiler was GNAT, which always produces
20681 the auxiliary information. */
20682 return (cu
->language
== language_ada
);
20685 /* Return the auxiliary type of the die in question using its
20686 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20687 attribute is not present. */
20689 static struct type
*
20690 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20692 struct attribute
*type_attr
;
20694 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20698 return lookup_die_type (die
, type_attr
, cu
);
20701 /* If DIE has a descriptive_type attribute, then set the TYPE's
20702 descriptive type accordingly. */
20705 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20706 struct dwarf2_cu
*cu
)
20708 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20710 if (descriptive_type
)
20712 ALLOCATE_GNAT_AUX_TYPE (type
);
20713 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20717 /* Return the containing type of the die in question using its
20718 DW_AT_containing_type attribute. */
20720 static struct type
*
20721 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20723 struct attribute
*type_attr
;
20724 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20726 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20728 error (_("Dwarf Error: Problem turning containing type into gdb type "
20729 "[in module %s]"), objfile_name (objfile
));
20731 return lookup_die_type (die
, type_attr
, cu
);
20734 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20736 static struct type
*
20737 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20739 struct dwarf2_per_objfile
*dwarf2_per_objfile
20740 = cu
->per_cu
->dwarf2_per_objfile
;
20741 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20744 std::string message
20745 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20746 objfile_name (objfile
),
20747 sect_offset_str (cu
->header
.sect_off
),
20748 sect_offset_str (die
->sect_off
));
20749 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20751 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20754 /* Look up the type of DIE in CU using its type attribute ATTR.
20755 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20756 DW_AT_containing_type.
20757 If there is no type substitute an error marker. */
20759 static struct type
*
20760 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20761 struct dwarf2_cu
*cu
)
20763 struct dwarf2_per_objfile
*dwarf2_per_objfile
20764 = cu
->per_cu
->dwarf2_per_objfile
;
20765 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20766 struct type
*this_type
;
20768 gdb_assert (attr
->name
== DW_AT_type
20769 || attr
->name
== DW_AT_GNAT_descriptive_type
20770 || attr
->name
== DW_AT_containing_type
);
20772 /* First see if we have it cached. */
20774 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20776 struct dwarf2_per_cu_data
*per_cu
;
20777 sect_offset sect_off
= attr
->get_ref_die_offset ();
20779 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20780 dwarf2_per_objfile
);
20781 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20783 else if (attr
->form_is_ref ())
20785 sect_offset sect_off
= attr
->get_ref_die_offset ();
20787 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20789 else if (attr
->form
== DW_FORM_ref_sig8
)
20791 ULONGEST signature
= DW_SIGNATURE (attr
);
20793 return get_signatured_type (die
, signature
, cu
);
20797 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20798 " at %s [in module %s]"),
20799 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20800 objfile_name (objfile
));
20801 return build_error_marker_type (cu
, die
);
20804 /* If not cached we need to read it in. */
20806 if (this_type
== NULL
)
20808 struct die_info
*type_die
= NULL
;
20809 struct dwarf2_cu
*type_cu
= cu
;
20811 if (attr
->form_is_ref ())
20812 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20813 if (type_die
== NULL
)
20814 return build_error_marker_type (cu
, die
);
20815 /* If we find the type now, it's probably because the type came
20816 from an inter-CU reference and the type's CU got expanded before
20818 this_type
= read_type_die (type_die
, type_cu
);
20821 /* If we still don't have a type use an error marker. */
20823 if (this_type
== NULL
)
20824 return build_error_marker_type (cu
, die
);
20829 /* Return the type in DIE, CU.
20830 Returns NULL for invalid types.
20832 This first does a lookup in die_type_hash,
20833 and only reads the die in if necessary.
20835 NOTE: This can be called when reading in partial or full symbols. */
20837 static struct type
*
20838 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20840 struct type
*this_type
;
20842 this_type
= get_die_type (die
, cu
);
20846 return read_type_die_1 (die
, cu
);
20849 /* Read the type in DIE, CU.
20850 Returns NULL for invalid types. */
20852 static struct type
*
20853 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20855 struct type
*this_type
= NULL
;
20859 case DW_TAG_class_type
:
20860 case DW_TAG_interface_type
:
20861 case DW_TAG_structure_type
:
20862 case DW_TAG_union_type
:
20863 this_type
= read_structure_type (die
, cu
);
20865 case DW_TAG_enumeration_type
:
20866 this_type
= read_enumeration_type (die
, cu
);
20868 case DW_TAG_subprogram
:
20869 case DW_TAG_subroutine_type
:
20870 case DW_TAG_inlined_subroutine
:
20871 this_type
= read_subroutine_type (die
, cu
);
20873 case DW_TAG_array_type
:
20874 this_type
= read_array_type (die
, cu
);
20876 case DW_TAG_set_type
:
20877 this_type
= read_set_type (die
, cu
);
20879 case DW_TAG_pointer_type
:
20880 this_type
= read_tag_pointer_type (die
, cu
);
20882 case DW_TAG_ptr_to_member_type
:
20883 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20885 case DW_TAG_reference_type
:
20886 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20888 case DW_TAG_rvalue_reference_type
:
20889 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20891 case DW_TAG_const_type
:
20892 this_type
= read_tag_const_type (die
, cu
);
20894 case DW_TAG_volatile_type
:
20895 this_type
= read_tag_volatile_type (die
, cu
);
20897 case DW_TAG_restrict_type
:
20898 this_type
= read_tag_restrict_type (die
, cu
);
20900 case DW_TAG_string_type
:
20901 this_type
= read_tag_string_type (die
, cu
);
20903 case DW_TAG_typedef
:
20904 this_type
= read_typedef (die
, cu
);
20906 case DW_TAG_subrange_type
:
20907 this_type
= read_subrange_type (die
, cu
);
20909 case DW_TAG_base_type
:
20910 this_type
= read_base_type (die
, cu
);
20912 case DW_TAG_unspecified_type
:
20913 this_type
= read_unspecified_type (die
, cu
);
20915 case DW_TAG_namespace
:
20916 this_type
= read_namespace_type (die
, cu
);
20918 case DW_TAG_module
:
20919 this_type
= read_module_type (die
, cu
);
20921 case DW_TAG_atomic_type
:
20922 this_type
= read_tag_atomic_type (die
, cu
);
20925 complaint (_("unexpected tag in read_type_die: '%s'"),
20926 dwarf_tag_name (die
->tag
));
20933 /* See if we can figure out if the class lives in a namespace. We do
20934 this by looking for a member function; its demangled name will
20935 contain namespace info, if there is any.
20936 Return the computed name or NULL.
20937 Space for the result is allocated on the objfile's obstack.
20938 This is the full-die version of guess_partial_die_structure_name.
20939 In this case we know DIE has no useful parent. */
20941 static const char *
20942 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20944 struct die_info
*spec_die
;
20945 struct dwarf2_cu
*spec_cu
;
20946 struct die_info
*child
;
20947 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20950 spec_die
= die_specification (die
, &spec_cu
);
20951 if (spec_die
!= NULL
)
20957 for (child
= die
->child
;
20959 child
= child
->sibling
)
20961 if (child
->tag
== DW_TAG_subprogram
)
20963 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20965 if (linkage_name
!= NULL
)
20967 gdb::unique_xmalloc_ptr
<char> actual_name
20968 (language_class_name_from_physname (cu
->language_defn
,
20970 const char *name
= NULL
;
20972 if (actual_name
!= NULL
)
20974 const char *die_name
= dwarf2_name (die
, cu
);
20976 if (die_name
!= NULL
20977 && strcmp (die_name
, actual_name
.get ()) != 0)
20979 /* Strip off the class name from the full name.
20980 We want the prefix. */
20981 int die_name_len
= strlen (die_name
);
20982 int actual_name_len
= strlen (actual_name
.get ());
20983 const char *ptr
= actual_name
.get ();
20985 /* Test for '::' as a sanity check. */
20986 if (actual_name_len
> die_name_len
+ 2
20987 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20988 name
= obstack_strndup (
20989 &objfile
->per_bfd
->storage_obstack
,
20990 ptr
, actual_name_len
- die_name_len
- 2);
21001 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21002 prefix part in such case. See
21003 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21005 static const char *
21006 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21008 struct attribute
*attr
;
21011 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21012 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21015 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21018 attr
= dw2_linkage_name_attr (die
, cu
);
21019 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21022 /* dwarf2_name had to be already called. */
21023 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21025 /* Strip the base name, keep any leading namespaces/classes. */
21026 base
= strrchr (DW_STRING (attr
), ':');
21027 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21030 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21031 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21033 &base
[-1] - DW_STRING (attr
));
21036 /* Return the name of the namespace/class that DIE is defined within,
21037 or "" if we can't tell. The caller should not xfree the result.
21039 For example, if we're within the method foo() in the following
21049 then determine_prefix on foo's die will return "N::C". */
21051 static const char *
21052 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21054 struct dwarf2_per_objfile
*dwarf2_per_objfile
21055 = cu
->per_cu
->dwarf2_per_objfile
;
21056 struct die_info
*parent
, *spec_die
;
21057 struct dwarf2_cu
*spec_cu
;
21058 struct type
*parent_type
;
21059 const char *retval
;
21061 if (cu
->language
!= language_cplus
21062 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21063 && cu
->language
!= language_rust
)
21066 retval
= anonymous_struct_prefix (die
, cu
);
21070 /* We have to be careful in the presence of DW_AT_specification.
21071 For example, with GCC 3.4, given the code
21075 // Definition of N::foo.
21079 then we'll have a tree of DIEs like this:
21081 1: DW_TAG_compile_unit
21082 2: DW_TAG_namespace // N
21083 3: DW_TAG_subprogram // declaration of N::foo
21084 4: DW_TAG_subprogram // definition of N::foo
21085 DW_AT_specification // refers to die #3
21087 Thus, when processing die #4, we have to pretend that we're in
21088 the context of its DW_AT_specification, namely the contex of die
21091 spec_die
= die_specification (die
, &spec_cu
);
21092 if (spec_die
== NULL
)
21093 parent
= die
->parent
;
21096 parent
= spec_die
->parent
;
21100 if (parent
== NULL
)
21102 else if (parent
->building_fullname
)
21105 const char *parent_name
;
21107 /* It has been seen on RealView 2.2 built binaries,
21108 DW_TAG_template_type_param types actually _defined_ as
21109 children of the parent class:
21112 template class <class Enum> Class{};
21113 Class<enum E> class_e;
21115 1: DW_TAG_class_type (Class)
21116 2: DW_TAG_enumeration_type (E)
21117 3: DW_TAG_enumerator (enum1:0)
21118 3: DW_TAG_enumerator (enum2:1)
21120 2: DW_TAG_template_type_param
21121 DW_AT_type DW_FORM_ref_udata (E)
21123 Besides being broken debug info, it can put GDB into an
21124 infinite loop. Consider:
21126 When we're building the full name for Class<E>, we'll start
21127 at Class, and go look over its template type parameters,
21128 finding E. We'll then try to build the full name of E, and
21129 reach here. We're now trying to build the full name of E,
21130 and look over the parent DIE for containing scope. In the
21131 broken case, if we followed the parent DIE of E, we'd again
21132 find Class, and once again go look at its template type
21133 arguments, etc., etc. Simply don't consider such parent die
21134 as source-level parent of this die (it can't be, the language
21135 doesn't allow it), and break the loop here. */
21136 name
= dwarf2_name (die
, cu
);
21137 parent_name
= dwarf2_name (parent
, cu
);
21138 complaint (_("template param type '%s' defined within parent '%s'"),
21139 name
? name
: "<unknown>",
21140 parent_name
? parent_name
: "<unknown>");
21144 switch (parent
->tag
)
21146 case DW_TAG_namespace
:
21147 parent_type
= read_type_die (parent
, cu
);
21148 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21149 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21150 Work around this problem here. */
21151 if (cu
->language
== language_cplus
21152 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21154 /* We give a name to even anonymous namespaces. */
21155 return TYPE_NAME (parent_type
);
21156 case DW_TAG_class_type
:
21157 case DW_TAG_interface_type
:
21158 case DW_TAG_structure_type
:
21159 case DW_TAG_union_type
:
21160 case DW_TAG_module
:
21161 parent_type
= read_type_die (parent
, cu
);
21162 if (TYPE_NAME (parent_type
) != NULL
)
21163 return TYPE_NAME (parent_type
);
21165 /* An anonymous structure is only allowed non-static data
21166 members; no typedefs, no member functions, et cetera.
21167 So it does not need a prefix. */
21169 case DW_TAG_compile_unit
:
21170 case DW_TAG_partial_unit
:
21171 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21172 if (cu
->language
== language_cplus
21173 && !dwarf2_per_objfile
->types
.empty ()
21174 && die
->child
!= NULL
21175 && (die
->tag
== DW_TAG_class_type
21176 || die
->tag
== DW_TAG_structure_type
21177 || die
->tag
== DW_TAG_union_type
))
21179 const char *name
= guess_full_die_structure_name (die
, cu
);
21184 case DW_TAG_subprogram
:
21185 /* Nested subroutines in Fortran get a prefix with the name
21186 of the parent's subroutine. */
21187 if (cu
->language
== language_fortran
)
21189 if ((die
->tag
== DW_TAG_subprogram
)
21190 && (dwarf2_name (parent
, cu
) != NULL
))
21191 return dwarf2_name (parent
, cu
);
21193 return determine_prefix (parent
, cu
);
21194 case DW_TAG_enumeration_type
:
21195 parent_type
= read_type_die (parent
, cu
);
21196 if (TYPE_DECLARED_CLASS (parent_type
))
21198 if (TYPE_NAME (parent_type
) != NULL
)
21199 return TYPE_NAME (parent_type
);
21202 /* Fall through. */
21204 return determine_prefix (parent
, cu
);
21208 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21209 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21210 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21211 an obconcat, otherwise allocate storage for the result. The CU argument is
21212 used to determine the language and hence, the appropriate separator. */
21214 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21217 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21218 int physname
, struct dwarf2_cu
*cu
)
21220 const char *lead
= "";
21223 if (suffix
== NULL
|| suffix
[0] == '\0'
21224 || prefix
== NULL
|| prefix
[0] == '\0')
21226 else if (cu
->language
== language_d
)
21228 /* For D, the 'main' function could be defined in any module, but it
21229 should never be prefixed. */
21230 if (strcmp (suffix
, "D main") == 0)
21238 else if (cu
->language
== language_fortran
&& physname
)
21240 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21241 DW_AT_MIPS_linkage_name is preferred and used instead. */
21249 if (prefix
== NULL
)
21251 if (suffix
== NULL
)
21258 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21260 strcpy (retval
, lead
);
21261 strcat (retval
, prefix
);
21262 strcat (retval
, sep
);
21263 strcat (retval
, suffix
);
21268 /* We have an obstack. */
21269 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21273 /* Get name of a die, return NULL if not found. */
21275 static const char *
21276 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21277 struct objfile
*objfile
)
21279 if (name
&& cu
->language
== language_cplus
)
21281 std::string canon_name
= cp_canonicalize_string (name
);
21283 if (!canon_name
.empty ())
21285 if (canon_name
!= name
)
21286 name
= objfile
->intern (canon_name
);
21293 /* Get name of a die, return NULL if not found.
21294 Anonymous namespaces are converted to their magic string. */
21296 static const char *
21297 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21299 struct attribute
*attr
;
21300 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21302 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21303 if ((!attr
|| !DW_STRING (attr
))
21304 && die
->tag
!= DW_TAG_namespace
21305 && die
->tag
!= DW_TAG_class_type
21306 && die
->tag
!= DW_TAG_interface_type
21307 && die
->tag
!= DW_TAG_structure_type
21308 && die
->tag
!= DW_TAG_union_type
)
21313 case DW_TAG_compile_unit
:
21314 case DW_TAG_partial_unit
:
21315 /* Compilation units have a DW_AT_name that is a filename, not
21316 a source language identifier. */
21317 case DW_TAG_enumeration_type
:
21318 case DW_TAG_enumerator
:
21319 /* These tags always have simple identifiers already; no need
21320 to canonicalize them. */
21321 return DW_STRING (attr
);
21323 case DW_TAG_namespace
:
21324 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21325 return DW_STRING (attr
);
21326 return CP_ANONYMOUS_NAMESPACE_STR
;
21328 case DW_TAG_class_type
:
21329 case DW_TAG_interface_type
:
21330 case DW_TAG_structure_type
:
21331 case DW_TAG_union_type
:
21332 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21333 structures or unions. These were of the form "._%d" in GCC 4.1,
21334 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21335 and GCC 4.4. We work around this problem by ignoring these. */
21336 if (attr
&& DW_STRING (attr
)
21337 && (startswith (DW_STRING (attr
), "._")
21338 || startswith (DW_STRING (attr
), "<anonymous")))
21341 /* GCC might emit a nameless typedef that has a linkage name. See
21342 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21343 if (!attr
|| DW_STRING (attr
) == NULL
)
21345 attr
= dw2_linkage_name_attr (die
, cu
);
21346 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21349 /* Avoid demangling DW_STRING (attr) the second time on a second
21350 call for the same DIE. */
21351 if (!DW_STRING_IS_CANONICAL (attr
))
21353 gdb::unique_xmalloc_ptr
<char> demangled
21354 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21355 if (demangled
== nullptr)
21358 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21359 DW_STRING_IS_CANONICAL (attr
) = 1;
21362 /* Strip any leading namespaces/classes, keep only the base name.
21363 DW_AT_name for named DIEs does not contain the prefixes. */
21364 const char *base
= strrchr (DW_STRING (attr
), ':');
21365 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21368 return DW_STRING (attr
);
21376 if (!DW_STRING_IS_CANONICAL (attr
))
21378 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21380 DW_STRING_IS_CANONICAL (attr
) = 1;
21382 return DW_STRING (attr
);
21385 /* Return the die that this die in an extension of, or NULL if there
21386 is none. *EXT_CU is the CU containing DIE on input, and the CU
21387 containing the return value on output. */
21389 static struct die_info
*
21390 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21392 struct attribute
*attr
;
21394 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21398 return follow_die_ref (die
, attr
, ext_cu
);
21402 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21406 print_spaces (indent
, f
);
21407 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21408 dwarf_tag_name (die
->tag
), die
->abbrev
,
21409 sect_offset_str (die
->sect_off
));
21411 if (die
->parent
!= NULL
)
21413 print_spaces (indent
, f
);
21414 fprintf_unfiltered (f
, " parent at offset: %s\n",
21415 sect_offset_str (die
->parent
->sect_off
));
21418 print_spaces (indent
, f
);
21419 fprintf_unfiltered (f
, " has children: %s\n",
21420 dwarf_bool_name (die
->child
!= NULL
));
21422 print_spaces (indent
, f
);
21423 fprintf_unfiltered (f
, " attributes:\n");
21425 for (i
= 0; i
< die
->num_attrs
; ++i
)
21427 print_spaces (indent
, f
);
21428 fprintf_unfiltered (f
, " %s (%s) ",
21429 dwarf_attr_name (die
->attrs
[i
].name
),
21430 dwarf_form_name (die
->attrs
[i
].form
));
21432 switch (die
->attrs
[i
].form
)
21435 case DW_FORM_addrx
:
21436 case DW_FORM_GNU_addr_index
:
21437 fprintf_unfiltered (f
, "address: ");
21438 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21440 case DW_FORM_block2
:
21441 case DW_FORM_block4
:
21442 case DW_FORM_block
:
21443 case DW_FORM_block1
:
21444 fprintf_unfiltered (f
, "block: size %s",
21445 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21447 case DW_FORM_exprloc
:
21448 fprintf_unfiltered (f
, "expression: size %s",
21449 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21451 case DW_FORM_data16
:
21452 fprintf_unfiltered (f
, "constant of 16 bytes");
21454 case DW_FORM_ref_addr
:
21455 fprintf_unfiltered (f
, "ref address: ");
21456 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21458 case DW_FORM_GNU_ref_alt
:
21459 fprintf_unfiltered (f
, "alt ref address: ");
21460 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21466 case DW_FORM_ref_udata
:
21467 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21468 (long) (DW_UNSND (&die
->attrs
[i
])));
21470 case DW_FORM_data1
:
21471 case DW_FORM_data2
:
21472 case DW_FORM_data4
:
21473 case DW_FORM_data8
:
21474 case DW_FORM_udata
:
21475 case DW_FORM_sdata
:
21476 fprintf_unfiltered (f
, "constant: %s",
21477 pulongest (DW_UNSND (&die
->attrs
[i
])));
21479 case DW_FORM_sec_offset
:
21480 fprintf_unfiltered (f
, "section offset: %s",
21481 pulongest (DW_UNSND (&die
->attrs
[i
])));
21483 case DW_FORM_ref_sig8
:
21484 fprintf_unfiltered (f
, "signature: %s",
21485 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21487 case DW_FORM_string
:
21489 case DW_FORM_line_strp
:
21491 case DW_FORM_GNU_str_index
:
21492 case DW_FORM_GNU_strp_alt
:
21493 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21494 DW_STRING (&die
->attrs
[i
])
21495 ? DW_STRING (&die
->attrs
[i
]) : "",
21496 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21499 if (DW_UNSND (&die
->attrs
[i
]))
21500 fprintf_unfiltered (f
, "flag: TRUE");
21502 fprintf_unfiltered (f
, "flag: FALSE");
21504 case DW_FORM_flag_present
:
21505 fprintf_unfiltered (f
, "flag: TRUE");
21507 case DW_FORM_indirect
:
21508 /* The reader will have reduced the indirect form to
21509 the "base form" so this form should not occur. */
21510 fprintf_unfiltered (f
,
21511 "unexpected attribute form: DW_FORM_indirect");
21513 case DW_FORM_implicit_const
:
21514 fprintf_unfiltered (f
, "constant: %s",
21515 plongest (DW_SND (&die
->attrs
[i
])));
21518 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21519 die
->attrs
[i
].form
);
21522 fprintf_unfiltered (f
, "\n");
21527 dump_die_for_error (struct die_info
*die
)
21529 dump_die_shallow (gdb_stderr
, 0, die
);
21533 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21535 int indent
= level
* 4;
21537 gdb_assert (die
!= NULL
);
21539 if (level
>= max_level
)
21542 dump_die_shallow (f
, indent
, die
);
21544 if (die
->child
!= NULL
)
21546 print_spaces (indent
, f
);
21547 fprintf_unfiltered (f
, " Children:");
21548 if (level
+ 1 < max_level
)
21550 fprintf_unfiltered (f
, "\n");
21551 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21555 fprintf_unfiltered (f
,
21556 " [not printed, max nesting level reached]\n");
21560 if (die
->sibling
!= NULL
&& level
> 0)
21562 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21566 /* This is called from the pdie macro in gdbinit.in.
21567 It's not static so gcc will keep a copy callable from gdb. */
21570 dump_die (struct die_info
*die
, int max_level
)
21572 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21576 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21580 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21581 to_underlying (die
->sect_off
),
21587 /* Follow reference or signature attribute ATTR of SRC_DIE.
21588 On entry *REF_CU is the CU of SRC_DIE.
21589 On exit *REF_CU is the CU of the result. */
21591 static struct die_info
*
21592 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21593 struct dwarf2_cu
**ref_cu
)
21595 struct die_info
*die
;
21597 if (attr
->form_is_ref ())
21598 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21599 else if (attr
->form
== DW_FORM_ref_sig8
)
21600 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21603 dump_die_for_error (src_die
);
21604 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21605 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21611 /* Follow reference OFFSET.
21612 On entry *REF_CU is the CU of the source die referencing OFFSET.
21613 On exit *REF_CU is the CU of the result.
21614 Returns NULL if OFFSET is invalid. */
21616 static struct die_info
*
21617 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21618 struct dwarf2_cu
**ref_cu
)
21620 struct die_info temp_die
;
21621 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21622 struct dwarf2_per_objfile
*dwarf2_per_objfile
21623 = cu
->per_cu
->dwarf2_per_objfile
;
21625 gdb_assert (cu
->per_cu
!= NULL
);
21629 if (cu
->per_cu
->is_debug_types
)
21631 /* .debug_types CUs cannot reference anything outside their CU.
21632 If they need to, they have to reference a signatured type via
21633 DW_FORM_ref_sig8. */
21634 if (!cu
->header
.offset_in_cu_p (sect_off
))
21637 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21638 || !cu
->header
.offset_in_cu_p (sect_off
))
21640 struct dwarf2_per_cu_data
*per_cu
;
21642 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21643 dwarf2_per_objfile
);
21645 /* If necessary, add it to the queue and load its DIEs. */
21646 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21647 load_full_comp_unit (per_cu
, false, cu
->language
);
21649 target_cu
= per_cu
->cu
;
21651 else if (cu
->dies
== NULL
)
21653 /* We're loading full DIEs during partial symbol reading. */
21654 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21655 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21658 *ref_cu
= target_cu
;
21659 temp_die
.sect_off
= sect_off
;
21661 if (target_cu
!= cu
)
21662 target_cu
->ancestor
= cu
;
21664 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21666 to_underlying (sect_off
));
21669 /* Follow reference attribute ATTR of SRC_DIE.
21670 On entry *REF_CU is the CU of SRC_DIE.
21671 On exit *REF_CU is the CU of the result. */
21673 static struct die_info
*
21674 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21675 struct dwarf2_cu
**ref_cu
)
21677 sect_offset sect_off
= attr
->get_ref_die_offset ();
21678 struct dwarf2_cu
*cu
= *ref_cu
;
21679 struct die_info
*die
;
21681 die
= follow_die_offset (sect_off
,
21682 (attr
->form
== DW_FORM_GNU_ref_alt
21683 || cu
->per_cu
->is_dwz
),
21686 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21687 "at %s [in module %s]"),
21688 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21689 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21696 struct dwarf2_locexpr_baton
21697 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21698 dwarf2_per_cu_data
*per_cu
,
21699 CORE_ADDR (*get_frame_pc
) (void *baton
),
21700 void *baton
, bool resolve_abstract_p
)
21702 struct dwarf2_cu
*cu
;
21703 struct die_info
*die
;
21704 struct attribute
*attr
;
21705 struct dwarf2_locexpr_baton retval
;
21706 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21707 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21709 if (per_cu
->cu
== NULL
)
21710 load_cu (per_cu
, false);
21714 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21715 Instead just throw an error, not much else we can do. */
21716 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21717 sect_offset_str (sect_off
), objfile_name (objfile
));
21720 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21722 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21723 sect_offset_str (sect_off
), objfile_name (objfile
));
21725 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21726 if (!attr
&& resolve_abstract_p
21727 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21728 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21730 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21731 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21732 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21734 for (const auto &cand_off
21735 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21737 struct dwarf2_cu
*cand_cu
= cu
;
21738 struct die_info
*cand
21739 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21742 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21745 CORE_ADDR pc_low
, pc_high
;
21746 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21747 if (pc_low
== ((CORE_ADDR
) -1))
21749 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21750 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21751 if (!(pc_low
<= pc
&& pc
< pc_high
))
21755 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21762 /* DWARF: "If there is no such attribute, then there is no effect.".
21763 DATA is ignored if SIZE is 0. */
21765 retval
.data
= NULL
;
21768 else if (attr
->form_is_section_offset ())
21770 struct dwarf2_loclist_baton loclist_baton
;
21771 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21774 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21776 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21778 retval
.size
= size
;
21782 if (!attr
->form_is_block ())
21783 error (_("Dwarf Error: DIE at %s referenced in module %s "
21784 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21785 sect_offset_str (sect_off
), objfile_name (objfile
));
21787 retval
.data
= DW_BLOCK (attr
)->data
;
21788 retval
.size
= DW_BLOCK (attr
)->size
;
21790 retval
.per_cu
= cu
->per_cu
;
21792 age_cached_comp_units (dwarf2_per_objfile
);
21799 struct dwarf2_locexpr_baton
21800 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21801 dwarf2_per_cu_data
*per_cu
,
21802 CORE_ADDR (*get_frame_pc
) (void *baton
),
21805 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21807 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21810 /* Write a constant of a given type as target-ordered bytes into
21813 static const gdb_byte
*
21814 write_constant_as_bytes (struct obstack
*obstack
,
21815 enum bfd_endian byte_order
,
21822 *len
= TYPE_LENGTH (type
);
21823 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21824 store_unsigned_integer (result
, *len
, byte_order
, value
);
21832 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21833 dwarf2_per_cu_data
*per_cu
,
21837 struct dwarf2_cu
*cu
;
21838 struct die_info
*die
;
21839 struct attribute
*attr
;
21840 const gdb_byte
*result
= NULL
;
21843 enum bfd_endian byte_order
;
21844 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21846 if (per_cu
->cu
== NULL
)
21847 load_cu (per_cu
, false);
21851 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21852 Instead just throw an error, not much else we can do. */
21853 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21854 sect_offset_str (sect_off
), objfile_name (objfile
));
21857 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21859 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21860 sect_offset_str (sect_off
), objfile_name (objfile
));
21862 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21866 byte_order
= (bfd_big_endian (objfile
->obfd
)
21867 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21869 switch (attr
->form
)
21872 case DW_FORM_addrx
:
21873 case DW_FORM_GNU_addr_index
:
21877 *len
= cu
->header
.addr_size
;
21878 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21879 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21883 case DW_FORM_string
:
21886 case DW_FORM_GNU_str_index
:
21887 case DW_FORM_GNU_strp_alt
:
21888 /* DW_STRING is already allocated on the objfile obstack, point
21890 result
= (const gdb_byte
*) DW_STRING (attr
);
21891 *len
= strlen (DW_STRING (attr
));
21893 case DW_FORM_block1
:
21894 case DW_FORM_block2
:
21895 case DW_FORM_block4
:
21896 case DW_FORM_block
:
21897 case DW_FORM_exprloc
:
21898 case DW_FORM_data16
:
21899 result
= DW_BLOCK (attr
)->data
;
21900 *len
= DW_BLOCK (attr
)->size
;
21903 /* The DW_AT_const_value attributes are supposed to carry the
21904 symbol's value "represented as it would be on the target
21905 architecture." By the time we get here, it's already been
21906 converted to host endianness, so we just need to sign- or
21907 zero-extend it as appropriate. */
21908 case DW_FORM_data1
:
21909 type
= die_type (die
, cu
);
21910 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21911 if (result
== NULL
)
21912 result
= write_constant_as_bytes (obstack
, byte_order
,
21915 case DW_FORM_data2
:
21916 type
= die_type (die
, cu
);
21917 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21918 if (result
== NULL
)
21919 result
= write_constant_as_bytes (obstack
, byte_order
,
21922 case DW_FORM_data4
:
21923 type
= die_type (die
, cu
);
21924 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21925 if (result
== NULL
)
21926 result
= write_constant_as_bytes (obstack
, byte_order
,
21929 case DW_FORM_data8
:
21930 type
= die_type (die
, cu
);
21931 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21932 if (result
== NULL
)
21933 result
= write_constant_as_bytes (obstack
, byte_order
,
21937 case DW_FORM_sdata
:
21938 case DW_FORM_implicit_const
:
21939 type
= die_type (die
, cu
);
21940 result
= write_constant_as_bytes (obstack
, byte_order
,
21941 type
, DW_SND (attr
), len
);
21944 case DW_FORM_udata
:
21945 type
= die_type (die
, cu
);
21946 result
= write_constant_as_bytes (obstack
, byte_order
,
21947 type
, DW_UNSND (attr
), len
);
21951 complaint (_("unsupported const value attribute form: '%s'"),
21952 dwarf_form_name (attr
->form
));
21962 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21963 dwarf2_per_cu_data
*per_cu
)
21965 struct dwarf2_cu
*cu
;
21966 struct die_info
*die
;
21968 if (per_cu
->cu
== NULL
)
21969 load_cu (per_cu
, false);
21974 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21978 return die_type (die
, cu
);
21984 dwarf2_get_die_type (cu_offset die_offset
,
21985 struct dwarf2_per_cu_data
*per_cu
)
21987 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21988 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21991 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21992 On entry *REF_CU is the CU of SRC_DIE.
21993 On exit *REF_CU is the CU of the result.
21994 Returns NULL if the referenced DIE isn't found. */
21996 static struct die_info
*
21997 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21998 struct dwarf2_cu
**ref_cu
)
22000 struct die_info temp_die
;
22001 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22002 struct die_info
*die
;
22004 /* While it might be nice to assert sig_type->type == NULL here,
22005 we can get here for DW_AT_imported_declaration where we need
22006 the DIE not the type. */
22008 /* If necessary, add it to the queue and load its DIEs. */
22010 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22011 read_signatured_type (sig_type
);
22013 sig_cu
= sig_type
->per_cu
.cu
;
22014 gdb_assert (sig_cu
!= NULL
);
22015 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22016 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22017 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22018 to_underlying (temp_die
.sect_off
));
22021 struct dwarf2_per_objfile
*dwarf2_per_objfile
22022 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22024 /* For .gdb_index version 7 keep track of included TUs.
22025 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22026 if (dwarf2_per_objfile
->index_table
!= NULL
22027 && dwarf2_per_objfile
->index_table
->version
<= 7)
22029 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22034 sig_cu
->ancestor
= cu
;
22042 /* Follow signatured type referenced by ATTR in SRC_DIE.
22043 On entry *REF_CU is the CU of SRC_DIE.
22044 On exit *REF_CU is the CU of the result.
22045 The result is the DIE of the type.
22046 If the referenced type cannot be found an error is thrown. */
22048 static struct die_info
*
22049 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22050 struct dwarf2_cu
**ref_cu
)
22052 ULONGEST signature
= DW_SIGNATURE (attr
);
22053 struct signatured_type
*sig_type
;
22054 struct die_info
*die
;
22056 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22058 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22059 /* sig_type will be NULL if the signatured type is missing from
22061 if (sig_type
== NULL
)
22063 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22064 " from DIE at %s [in module %s]"),
22065 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22066 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22069 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22072 dump_die_for_error (src_die
);
22073 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22074 " from DIE at %s [in module %s]"),
22075 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22076 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22082 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22083 reading in and processing the type unit if necessary. */
22085 static struct type
*
22086 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22087 struct dwarf2_cu
*cu
)
22089 struct dwarf2_per_objfile
*dwarf2_per_objfile
22090 = cu
->per_cu
->dwarf2_per_objfile
;
22091 struct signatured_type
*sig_type
;
22092 struct dwarf2_cu
*type_cu
;
22093 struct die_info
*type_die
;
22096 sig_type
= lookup_signatured_type (cu
, signature
);
22097 /* sig_type will be NULL if the signatured type is missing from
22099 if (sig_type
== NULL
)
22101 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22102 " from DIE at %s [in module %s]"),
22103 hex_string (signature
), sect_offset_str (die
->sect_off
),
22104 objfile_name (dwarf2_per_objfile
->objfile
));
22105 return build_error_marker_type (cu
, die
);
22108 /* If we already know the type we're done. */
22109 if (sig_type
->type
!= NULL
)
22110 return sig_type
->type
;
22113 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22114 if (type_die
!= NULL
)
22116 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22117 is created. This is important, for example, because for c++ classes
22118 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22119 type
= read_type_die (type_die
, type_cu
);
22122 complaint (_("Dwarf Error: Cannot build signatured type %s"
22123 " referenced from DIE at %s [in module %s]"),
22124 hex_string (signature
), sect_offset_str (die
->sect_off
),
22125 objfile_name (dwarf2_per_objfile
->objfile
));
22126 type
= build_error_marker_type (cu
, die
);
22131 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22132 " from DIE at %s [in module %s]"),
22133 hex_string (signature
), sect_offset_str (die
->sect_off
),
22134 objfile_name (dwarf2_per_objfile
->objfile
));
22135 type
= build_error_marker_type (cu
, die
);
22137 sig_type
->type
= type
;
22142 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22143 reading in and processing the type unit if necessary. */
22145 static struct type
*
22146 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22147 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22149 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22150 if (attr
->form_is_ref ())
22152 struct dwarf2_cu
*type_cu
= cu
;
22153 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22155 return read_type_die (type_die
, type_cu
);
22157 else if (attr
->form
== DW_FORM_ref_sig8
)
22159 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22163 struct dwarf2_per_objfile
*dwarf2_per_objfile
22164 = cu
->per_cu
->dwarf2_per_objfile
;
22166 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22167 " at %s [in module %s]"),
22168 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22169 objfile_name (dwarf2_per_objfile
->objfile
));
22170 return build_error_marker_type (cu
, die
);
22174 /* Load the DIEs associated with type unit PER_CU into memory. */
22177 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22179 struct signatured_type
*sig_type
;
22181 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22182 gdb_assert (! per_cu
->type_unit_group_p ());
22184 /* We have the per_cu, but we need the signatured_type.
22185 Fortunately this is an easy translation. */
22186 gdb_assert (per_cu
->is_debug_types
);
22187 sig_type
= (struct signatured_type
*) per_cu
;
22189 gdb_assert (per_cu
->cu
== NULL
);
22191 read_signatured_type (sig_type
);
22193 gdb_assert (per_cu
->cu
!= NULL
);
22196 /* Read in a signatured type and build its CU and DIEs.
22197 If the type is a stub for the real type in a DWO file,
22198 read in the real type from the DWO file as well. */
22201 read_signatured_type (struct signatured_type
*sig_type
)
22203 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22205 gdb_assert (per_cu
->is_debug_types
);
22206 gdb_assert (per_cu
->cu
== NULL
);
22208 cutu_reader
reader (per_cu
, NULL
, 0, false);
22210 if (!reader
.dummy_p
)
22212 struct dwarf2_cu
*cu
= reader
.cu
;
22213 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22215 gdb_assert (cu
->die_hash
== NULL
);
22217 htab_create_alloc_ex (cu
->header
.length
/ 12,
22221 &cu
->comp_unit_obstack
,
22222 hashtab_obstack_allocate
,
22223 dummy_obstack_deallocate
);
22225 if (reader
.comp_unit_die
->has_children
)
22226 reader
.comp_unit_die
->child
22227 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22228 reader
.comp_unit_die
);
22229 cu
->dies
= reader
.comp_unit_die
;
22230 /* comp_unit_die is not stored in die_hash, no need. */
22232 /* We try not to read any attributes in this function, because
22233 not all CUs needed for references have been loaded yet, and
22234 symbol table processing isn't initialized. But we have to
22235 set the CU language, or we won't be able to build types
22236 correctly. Similarly, if we do not read the producer, we can
22237 not apply producer-specific interpretation. */
22238 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22243 sig_type
->per_cu
.tu_read
= 1;
22246 /* Decode simple location descriptions.
22247 Given a pointer to a dwarf block that defines a location, compute
22248 the location and return the value.
22250 NOTE drow/2003-11-18: This function is called in two situations
22251 now: for the address of static or global variables (partial symbols
22252 only) and for offsets into structures which are expected to be
22253 (more or less) constant. The partial symbol case should go away,
22254 and only the constant case should remain. That will let this
22255 function complain more accurately. A few special modes are allowed
22256 without complaint for global variables (for instance, global
22257 register values and thread-local values).
22259 A location description containing no operations indicates that the
22260 object is optimized out. The return value is 0 for that case.
22261 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22262 callers will only want a very basic result and this can become a
22265 Note that stack[0] is unused except as a default error return. */
22268 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22270 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22272 size_t size
= blk
->size
;
22273 const gdb_byte
*data
= blk
->data
;
22274 CORE_ADDR stack
[64];
22276 unsigned int bytes_read
, unsnd
;
22282 stack
[++stacki
] = 0;
22321 stack
[++stacki
] = op
- DW_OP_lit0
;
22356 stack
[++stacki
] = op
- DW_OP_reg0
;
22358 dwarf2_complex_location_expr_complaint ();
22362 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22364 stack
[++stacki
] = unsnd
;
22366 dwarf2_complex_location_expr_complaint ();
22370 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22375 case DW_OP_const1u
:
22376 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22380 case DW_OP_const1s
:
22381 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22385 case DW_OP_const2u
:
22386 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22390 case DW_OP_const2s
:
22391 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22395 case DW_OP_const4u
:
22396 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22400 case DW_OP_const4s
:
22401 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22405 case DW_OP_const8u
:
22406 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22411 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22417 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22422 stack
[stacki
+ 1] = stack
[stacki
];
22427 stack
[stacki
- 1] += stack
[stacki
];
22431 case DW_OP_plus_uconst
:
22432 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22438 stack
[stacki
- 1] -= stack
[stacki
];
22443 /* If we're not the last op, then we definitely can't encode
22444 this using GDB's address_class enum. This is valid for partial
22445 global symbols, although the variable's address will be bogus
22448 dwarf2_complex_location_expr_complaint ();
22451 case DW_OP_GNU_push_tls_address
:
22452 case DW_OP_form_tls_address
:
22453 /* The top of the stack has the offset from the beginning
22454 of the thread control block at which the variable is located. */
22455 /* Nothing should follow this operator, so the top of stack would
22457 /* This is valid for partial global symbols, but the variable's
22458 address will be bogus in the psymtab. Make it always at least
22459 non-zero to not look as a variable garbage collected by linker
22460 which have DW_OP_addr 0. */
22462 dwarf2_complex_location_expr_complaint ();
22466 case DW_OP_GNU_uninit
:
22470 case DW_OP_GNU_addr_index
:
22471 case DW_OP_GNU_const_index
:
22472 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22479 const char *name
= get_DW_OP_name (op
);
22482 complaint (_("unsupported stack op: '%s'"),
22485 complaint (_("unsupported stack op: '%02x'"),
22489 return (stack
[stacki
]);
22492 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22493 outside of the allocated space. Also enforce minimum>0. */
22494 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22496 complaint (_("location description stack overflow"));
22502 complaint (_("location description stack underflow"));
22506 return (stack
[stacki
]);
22509 /* memory allocation interface */
22511 static struct dwarf_block
*
22512 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22514 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22517 static struct die_info
*
22518 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22520 struct die_info
*die
;
22521 size_t size
= sizeof (struct die_info
);
22524 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22526 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22527 memset (die
, 0, sizeof (struct die_info
));
22533 /* Macro support. */
22535 /* An overload of dwarf_decode_macros that finds the correct section
22536 and ensures it is read in before calling the other overload. */
22539 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22540 int section_is_gnu
)
22542 struct dwarf2_per_objfile
*dwarf2_per_objfile
22543 = cu
->per_cu
->dwarf2_per_objfile
;
22544 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22545 const struct line_header
*lh
= cu
->line_header
;
22546 unsigned int offset_size
= cu
->header
.offset_size
;
22547 struct dwarf2_section_info
*section
;
22548 const char *section_name
;
22550 if (cu
->dwo_unit
!= nullptr)
22552 if (section_is_gnu
)
22554 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22555 section_name
= ".debug_macro.dwo";
22559 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22560 section_name
= ".debug_macinfo.dwo";
22565 if (section_is_gnu
)
22567 section
= &dwarf2_per_objfile
->macro
;
22568 section_name
= ".debug_macro";
22572 section
= &dwarf2_per_objfile
->macinfo
;
22573 section_name
= ".debug_macinfo";
22577 section
->read (objfile
);
22578 if (section
->buffer
== nullptr)
22580 complaint (_("missing %s section"), section_name
);
22584 buildsym_compunit
*builder
= cu
->get_builder ();
22586 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22587 offset_size
, offset
, section_is_gnu
);
22590 /* Return the .debug_loc section to use for CU.
22591 For DWO files use .debug_loc.dwo. */
22593 static struct dwarf2_section_info
*
22594 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22596 struct dwarf2_per_objfile
*dwarf2_per_objfile
22597 = cu
->per_cu
->dwarf2_per_objfile
;
22601 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22603 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22605 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22606 : &dwarf2_per_objfile
->loc
);
22609 /* A helper function that fills in a dwarf2_loclist_baton. */
22612 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22613 struct dwarf2_loclist_baton
*baton
,
22614 const struct attribute
*attr
)
22616 struct dwarf2_per_objfile
*dwarf2_per_objfile
22617 = cu
->per_cu
->dwarf2_per_objfile
;
22618 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22620 section
->read (dwarf2_per_objfile
->objfile
);
22622 baton
->per_cu
= cu
->per_cu
;
22623 gdb_assert (baton
->per_cu
);
22624 /* We don't know how long the location list is, but make sure we
22625 don't run off the edge of the section. */
22626 baton
->size
= section
->size
- DW_UNSND (attr
);
22627 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22628 if (cu
->base_address
.has_value ())
22629 baton
->base_address
= *cu
->base_address
;
22631 baton
->base_address
= 0;
22632 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22636 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22637 struct dwarf2_cu
*cu
, int is_block
)
22639 struct dwarf2_per_objfile
*dwarf2_per_objfile
22640 = cu
->per_cu
->dwarf2_per_objfile
;
22641 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22642 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22644 if (attr
->form_is_section_offset ()
22645 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22646 the section. If so, fall through to the complaint in the
22648 && DW_UNSND (attr
) < section
->get_size (objfile
))
22650 struct dwarf2_loclist_baton
*baton
;
22652 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22654 fill_in_loclist_baton (cu
, baton
, attr
);
22656 if (!cu
->base_address
.has_value ())
22657 complaint (_("Location list used without "
22658 "specifying the CU base address."));
22660 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22661 ? dwarf2_loclist_block_index
22662 : dwarf2_loclist_index
);
22663 SYMBOL_LOCATION_BATON (sym
) = baton
;
22667 struct dwarf2_locexpr_baton
*baton
;
22669 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22670 baton
->per_cu
= cu
->per_cu
;
22671 gdb_assert (baton
->per_cu
);
22673 if (attr
->form_is_block ())
22675 /* Note that we're just copying the block's data pointer
22676 here, not the actual data. We're still pointing into the
22677 info_buffer for SYM's objfile; right now we never release
22678 that buffer, but when we do clean up properly this may
22680 baton
->size
= DW_BLOCK (attr
)->size
;
22681 baton
->data
= DW_BLOCK (attr
)->data
;
22685 dwarf2_invalid_attrib_class_complaint ("location description",
22686 sym
->natural_name ());
22690 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22691 ? dwarf2_locexpr_block_index
22692 : dwarf2_locexpr_index
);
22693 SYMBOL_LOCATION_BATON (sym
) = baton
;
22700 dwarf2_per_cu_data::objfile () const
22702 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22704 /* Return the master objfile, so that we can report and look up the
22705 correct file containing this variable. */
22706 if (objfile
->separate_debug_objfile_backlink
)
22707 objfile
= objfile
->separate_debug_objfile_backlink
;
22712 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22713 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22714 CU_HEADERP first. */
22716 static const struct comp_unit_head
*
22717 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22718 const struct dwarf2_per_cu_data
*per_cu
)
22720 const gdb_byte
*info_ptr
;
22723 return &per_cu
->cu
->header
;
22725 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22727 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22728 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22729 rcuh_kind::COMPILE
);
22737 dwarf2_per_cu_data::addr_size () const
22739 struct comp_unit_head cu_header_local
;
22740 const struct comp_unit_head
*cu_headerp
;
22742 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22744 return cu_headerp
->addr_size
;
22750 dwarf2_per_cu_data::offset_size () const
22752 struct comp_unit_head cu_header_local
;
22753 const struct comp_unit_head
*cu_headerp
;
22755 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22757 return cu_headerp
->offset_size
;
22763 dwarf2_per_cu_data::ref_addr_size () const
22765 struct comp_unit_head cu_header_local
;
22766 const struct comp_unit_head
*cu_headerp
;
22768 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22770 if (cu_headerp
->version
== 2)
22771 return cu_headerp
->addr_size
;
22773 return cu_headerp
->offset_size
;
22779 dwarf2_per_cu_data::text_offset () const
22781 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22783 return objfile
->text_section_offset ();
22789 dwarf2_per_cu_data::addr_type () const
22791 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22792 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22793 struct type
*addr_type
= lookup_pointer_type (void_type
);
22794 int addr_size
= this->addr_size ();
22796 if (TYPE_LENGTH (addr_type
) == addr_size
)
22799 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22803 /* A helper function for dwarf2_find_containing_comp_unit that returns
22804 the index of the result, and that searches a vector. It will
22805 return a result even if the offset in question does not actually
22806 occur in any CU. This is separate so that it can be unit
22810 dwarf2_find_containing_comp_unit
22811 (sect_offset sect_off
,
22812 unsigned int offset_in_dwz
,
22813 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22818 high
= all_comp_units
.size () - 1;
22821 struct dwarf2_per_cu_data
*mid_cu
;
22822 int mid
= low
+ (high
- low
) / 2;
22824 mid_cu
= all_comp_units
[mid
];
22825 if (mid_cu
->is_dwz
> offset_in_dwz
22826 || (mid_cu
->is_dwz
== offset_in_dwz
22827 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22832 gdb_assert (low
== high
);
22836 /* Locate the .debug_info compilation unit from CU's objfile which contains
22837 the DIE at OFFSET. Raises an error on failure. */
22839 static struct dwarf2_per_cu_data
*
22840 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22841 unsigned int offset_in_dwz
,
22842 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22845 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22846 dwarf2_per_objfile
->all_comp_units
);
22847 struct dwarf2_per_cu_data
*this_cu
22848 = dwarf2_per_objfile
->all_comp_units
[low
];
22850 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22852 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22853 error (_("Dwarf Error: could not find partial DIE containing "
22854 "offset %s [in module %s]"),
22855 sect_offset_str (sect_off
),
22856 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22858 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22860 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22864 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22865 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22866 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22867 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22874 namespace selftests
{
22875 namespace find_containing_comp_unit
{
22880 struct dwarf2_per_cu_data one
{};
22881 struct dwarf2_per_cu_data two
{};
22882 struct dwarf2_per_cu_data three
{};
22883 struct dwarf2_per_cu_data four
{};
22886 two
.sect_off
= sect_offset (one
.length
);
22891 four
.sect_off
= sect_offset (three
.length
);
22895 std::vector
<dwarf2_per_cu_data
*> units
;
22896 units
.push_back (&one
);
22897 units
.push_back (&two
);
22898 units
.push_back (&three
);
22899 units
.push_back (&four
);
22903 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22904 SELF_CHECK (units
[result
] == &one
);
22905 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
22906 SELF_CHECK (units
[result
] == &one
);
22907 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
22908 SELF_CHECK (units
[result
] == &two
);
22910 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
22911 SELF_CHECK (units
[result
] == &three
);
22912 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
22913 SELF_CHECK (units
[result
] == &three
);
22914 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
22915 SELF_CHECK (units
[result
] == &four
);
22921 #endif /* GDB_SELF_TEST */
22923 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22925 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
22926 : per_cu (per_cu_
),
22928 has_loclist (false),
22929 checked_producer (false),
22930 producer_is_gxx_lt_4_6 (false),
22931 producer_is_gcc_lt_4_3 (false),
22932 producer_is_icc (false),
22933 producer_is_icc_lt_14 (false),
22934 producer_is_codewarrior (false),
22935 processing_has_namespace_info (false)
22940 /* Destroy a dwarf2_cu. */
22942 dwarf2_cu::~dwarf2_cu ()
22947 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22950 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22951 enum language pretend_language
)
22953 struct attribute
*attr
;
22955 /* Set the language we're debugging. */
22956 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22957 if (attr
!= nullptr)
22958 set_cu_language (DW_UNSND (attr
), cu
);
22961 cu
->language
= pretend_language
;
22962 cu
->language_defn
= language_def (cu
->language
);
22965 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22968 /* Increase the age counter on each cached compilation unit, and free
22969 any that are too old. */
22972 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22974 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22976 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22977 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22978 while (per_cu
!= NULL
)
22980 per_cu
->cu
->last_used
++;
22981 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22982 dwarf2_mark (per_cu
->cu
);
22983 per_cu
= per_cu
->cu
->read_in_chain
;
22986 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22987 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22988 while (per_cu
!= NULL
)
22990 struct dwarf2_per_cu_data
*next_cu
;
22992 next_cu
= per_cu
->cu
->read_in_chain
;
22994 if (!per_cu
->cu
->mark
)
22997 *last_chain
= next_cu
;
23000 last_chain
= &per_cu
->cu
->read_in_chain
;
23006 /* Remove a single compilation unit from the cache. */
23009 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23011 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23012 struct dwarf2_per_objfile
*dwarf2_per_objfile
23013 = target_per_cu
->dwarf2_per_objfile
;
23015 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23016 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23017 while (per_cu
!= NULL
)
23019 struct dwarf2_per_cu_data
*next_cu
;
23021 next_cu
= per_cu
->cu
->read_in_chain
;
23023 if (per_cu
== target_per_cu
)
23027 *last_chain
= next_cu
;
23031 last_chain
= &per_cu
->cu
->read_in_chain
;
23037 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23038 We store these in a hash table separate from the DIEs, and preserve them
23039 when the DIEs are flushed out of cache.
23041 The CU "per_cu" pointer is needed because offset alone is not enough to
23042 uniquely identify the type. A file may have multiple .debug_types sections,
23043 or the type may come from a DWO file. Furthermore, while it's more logical
23044 to use per_cu->section+offset, with Fission the section with the data is in
23045 the DWO file but we don't know that section at the point we need it.
23046 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23047 because we can enter the lookup routine, get_die_type_at_offset, from
23048 outside this file, and thus won't necessarily have PER_CU->cu.
23049 Fortunately, PER_CU is stable for the life of the objfile. */
23051 struct dwarf2_per_cu_offset_and_type
23053 const struct dwarf2_per_cu_data
*per_cu
;
23054 sect_offset sect_off
;
23058 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23061 per_cu_offset_and_type_hash (const void *item
)
23063 const struct dwarf2_per_cu_offset_and_type
*ofs
23064 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23066 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23069 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23072 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23074 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23075 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23076 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23077 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23079 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23080 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23083 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23084 table if necessary. For convenience, return TYPE.
23086 The DIEs reading must have careful ordering to:
23087 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23088 reading current DIE.
23089 * Not trying to dereference contents of still incompletely read in types
23090 while reading in other DIEs.
23091 * Enable referencing still incompletely read in types just by a pointer to
23092 the type without accessing its fields.
23094 Therefore caller should follow these rules:
23095 * Try to fetch any prerequisite types we may need to build this DIE type
23096 before building the type and calling set_die_type.
23097 * After building type call set_die_type for current DIE as soon as
23098 possible before fetching more types to complete the current type.
23099 * Make the type as complete as possible before fetching more types. */
23101 static struct type
*
23102 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23104 struct dwarf2_per_objfile
*dwarf2_per_objfile
23105 = cu
->per_cu
->dwarf2_per_objfile
;
23106 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23107 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23108 struct attribute
*attr
;
23109 struct dynamic_prop prop
;
23111 /* For Ada types, make sure that the gnat-specific data is always
23112 initialized (if not already set). There are a few types where
23113 we should not be doing so, because the type-specific area is
23114 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23115 where the type-specific area is used to store the floatformat).
23116 But this is not a problem, because the gnat-specific information
23117 is actually not needed for these types. */
23118 if (need_gnat_info (cu
)
23119 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23120 && TYPE_CODE (type
) != TYPE_CODE_FLT
23121 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23122 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23123 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23124 && !HAVE_GNAT_AUX_INFO (type
))
23125 INIT_GNAT_SPECIFIC (type
);
23127 /* Read DW_AT_allocated and set in type. */
23128 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23129 if (attr
!= NULL
&& attr
->form_is_block ())
23131 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23132 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23133 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23135 else if (attr
!= NULL
)
23137 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23138 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23139 sect_offset_str (die
->sect_off
));
23142 /* Read DW_AT_associated and set in type. */
23143 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23144 if (attr
!= NULL
&& attr
->form_is_block ())
23146 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23147 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23148 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23150 else if (attr
!= NULL
)
23152 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23153 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23154 sect_offset_str (die
->sect_off
));
23157 /* Read DW_AT_data_location and set in type. */
23158 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23159 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23160 cu
->per_cu
->addr_type ()))
23161 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23163 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23164 dwarf2_per_objfile
->die_type_hash
23165 = htab_up (htab_create_alloc (127,
23166 per_cu_offset_and_type_hash
,
23167 per_cu_offset_and_type_eq
,
23168 NULL
, xcalloc
, xfree
));
23170 ofs
.per_cu
= cu
->per_cu
;
23171 ofs
.sect_off
= die
->sect_off
;
23173 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23174 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23176 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23177 sect_offset_str (die
->sect_off
));
23178 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23179 struct dwarf2_per_cu_offset_and_type
);
23184 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23185 or return NULL if the die does not have a saved type. */
23187 static struct type
*
23188 get_die_type_at_offset (sect_offset sect_off
,
23189 struct dwarf2_per_cu_data
*per_cu
)
23191 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23192 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23194 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23197 ofs
.per_cu
= per_cu
;
23198 ofs
.sect_off
= sect_off
;
23199 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23200 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23207 /* Look up the type for DIE in CU in die_type_hash,
23208 or return NULL if DIE does not have a saved type. */
23210 static struct type
*
23211 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23213 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23216 /* Add a dependence relationship from CU to REF_PER_CU. */
23219 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23220 struct dwarf2_per_cu_data
*ref_per_cu
)
23224 if (cu
->dependencies
== NULL
)
23226 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23227 NULL
, &cu
->comp_unit_obstack
,
23228 hashtab_obstack_allocate
,
23229 dummy_obstack_deallocate
);
23231 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23233 *slot
= ref_per_cu
;
23236 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23237 Set the mark field in every compilation unit in the
23238 cache that we must keep because we are keeping CU. */
23241 dwarf2_mark_helper (void **slot
, void *data
)
23243 struct dwarf2_per_cu_data
*per_cu
;
23245 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23247 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23248 reading of the chain. As such dependencies remain valid it is not much
23249 useful to track and undo them during QUIT cleanups. */
23250 if (per_cu
->cu
== NULL
)
23253 if (per_cu
->cu
->mark
)
23255 per_cu
->cu
->mark
= true;
23257 if (per_cu
->cu
->dependencies
!= NULL
)
23258 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23263 /* Set the mark field in CU and in every other compilation unit in the
23264 cache that we must keep because we are keeping CU. */
23267 dwarf2_mark (struct dwarf2_cu
*cu
)
23272 if (cu
->dependencies
!= NULL
)
23273 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23277 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23281 per_cu
->cu
->mark
= false;
23282 per_cu
= per_cu
->cu
->read_in_chain
;
23286 /* Trivial hash function for partial_die_info: the hash value of a DIE
23287 is its offset in .debug_info for this objfile. */
23290 partial_die_hash (const void *item
)
23292 const struct partial_die_info
*part_die
23293 = (const struct partial_die_info
*) item
;
23295 return to_underlying (part_die
->sect_off
);
23298 /* Trivial comparison function for partial_die_info structures: two DIEs
23299 are equal if they have the same offset. */
23302 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23304 const struct partial_die_info
*part_die_lhs
23305 = (const struct partial_die_info
*) item_lhs
;
23306 const struct partial_die_info
*part_die_rhs
23307 = (const struct partial_die_info
*) item_rhs
;
23309 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23312 struct cmd_list_element
*set_dwarf_cmdlist
;
23313 struct cmd_list_element
*show_dwarf_cmdlist
;
23316 set_dwarf_cmd (const char *args
, int from_tty
)
23318 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23323 show_dwarf_cmd (const char *args
, int from_tty
)
23325 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23329 show_check_physname (struct ui_file
*file
, int from_tty
,
23330 struct cmd_list_element
*c
, const char *value
)
23332 fprintf_filtered (file
,
23333 _("Whether to check \"physname\" is %s.\n"),
23337 void _initialize_dwarf2_read ();
23339 _initialize_dwarf2_read ()
23341 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23342 Set DWARF specific variables.\n\
23343 Configure DWARF variables such as the cache size."),
23344 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23345 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23347 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23348 Show DWARF specific variables.\n\
23349 Show DWARF variables such as the cache size."),
23350 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23351 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23353 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23354 &dwarf_max_cache_age
, _("\
23355 Set the upper bound on the age of cached DWARF compilation units."), _("\
23356 Show the upper bound on the age of cached DWARF compilation units."), _("\
23357 A higher limit means that cached compilation units will be stored\n\
23358 in memory longer, and more total memory will be used. Zero disables\n\
23359 caching, which can slow down startup."),
23361 show_dwarf_max_cache_age
,
23362 &set_dwarf_cmdlist
,
23363 &show_dwarf_cmdlist
);
23365 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23366 Set debugging of the DWARF reader."), _("\
23367 Show debugging of the DWARF reader."), _("\
23368 When enabled (non-zero), debugging messages are printed during DWARF\n\
23369 reading and symtab expansion. A value of 1 (one) provides basic\n\
23370 information. A value greater than 1 provides more verbose information."),
23373 &setdebuglist
, &showdebuglist
);
23375 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23376 Set debugging of the DWARF DIE reader."), _("\
23377 Show debugging of the DWARF DIE reader."), _("\
23378 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23379 The value is the maximum depth to print."),
23382 &setdebuglist
, &showdebuglist
);
23384 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23385 Set debugging of the dwarf line reader."), _("\
23386 Show debugging of the dwarf line reader."), _("\
23387 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23388 A value of 1 (one) provides basic information.\n\
23389 A value greater than 1 provides more verbose information."),
23392 &setdebuglist
, &showdebuglist
);
23394 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23395 Set cross-checking of \"physname\" code against demangler."), _("\
23396 Show cross-checking of \"physname\" code against demangler."), _("\
23397 When enabled, GDB's internal \"physname\" code is checked against\n\
23399 NULL
, show_check_physname
,
23400 &setdebuglist
, &showdebuglist
);
23402 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23403 no_class
, &use_deprecated_index_sections
, _("\
23404 Set whether to use deprecated gdb_index sections."), _("\
23405 Show whether to use deprecated gdb_index sections."), _("\
23406 When enabled, deprecated .gdb_index sections are used anyway.\n\
23407 Normally they are ignored either because of a missing feature or\n\
23408 performance issue.\n\
23409 Warning: This option must be enabled before gdb reads the file."),
23412 &setlist
, &showlist
);
23414 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23415 &dwarf2_locexpr_funcs
);
23416 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23417 &dwarf2_loclist_funcs
);
23419 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23420 &dwarf2_block_frame_base_locexpr_funcs
);
23421 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23422 &dwarf2_block_frame_base_loclist_funcs
);
23425 selftests::register_test ("dw2_expand_symtabs_matching",
23426 selftests::dw2_expand_symtabs_matching::run_test
);
23427 selftests::register_test ("dwarf2_find_containing_comp_unit",
23428 selftests::find_containing_comp_unit::run_test
);