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
, 0);
7166 pst
->psymtabs_addrmap_supported
= true;
7168 /* This is the glue that links PST into GDB's symbol API. */
7169 pst
->per_cu_data
= per_cu
;
7170 per_cu
->v
.psymtab
= pst
;
7175 /* DIE reader function for process_psymtab_comp_unit. */
7178 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7179 const gdb_byte
*info_ptr
,
7180 struct die_info
*comp_unit_die
,
7181 enum language pretend_language
)
7183 struct dwarf2_cu
*cu
= reader
->cu
;
7184 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7185 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7186 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7188 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7189 dwarf2_psymtab
*pst
;
7190 enum pc_bounds_kind cu_bounds_kind
;
7191 const char *filename
;
7193 gdb_assert (! per_cu
->is_debug_types
);
7195 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7197 /* Allocate a new partial symbol table structure. */
7198 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7199 static const char artificial
[] = "<artificial>";
7200 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7201 if (filename
== NULL
)
7203 else if (strcmp (filename
, artificial
) == 0)
7205 debug_filename
.reset (concat (artificial
, "@",
7206 sect_offset_str (per_cu
->sect_off
),
7208 filename
= debug_filename
.get ();
7211 pst
= create_partial_symtab (per_cu
, filename
);
7213 /* This must be done before calling dwarf2_build_include_psymtabs. */
7214 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7216 baseaddr
= objfile
->text_section_offset ();
7218 dwarf2_find_base_address (comp_unit_die
, cu
);
7220 /* Possibly set the default values of LOWPC and HIGHPC from
7222 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7223 &best_highpc
, cu
, pst
);
7224 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7227 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7230 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7232 /* Store the contiguous range if it is not empty; it can be
7233 empty for CUs with no code. */
7234 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7238 /* Check if comp unit has_children.
7239 If so, read the rest of the partial symbols from this comp unit.
7240 If not, there's no more debug_info for this comp unit. */
7241 if (comp_unit_die
->has_children
)
7243 struct partial_die_info
*first_die
;
7244 CORE_ADDR lowpc
, highpc
;
7246 lowpc
= ((CORE_ADDR
) -1);
7247 highpc
= ((CORE_ADDR
) 0);
7249 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7251 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7252 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7254 /* If we didn't find a lowpc, set it to highpc to avoid
7255 complaints from `maint check'. */
7256 if (lowpc
== ((CORE_ADDR
) -1))
7259 /* If the compilation unit didn't have an explicit address range,
7260 then use the information extracted from its child dies. */
7261 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7264 best_highpc
= highpc
;
7267 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7268 best_lowpc
+ baseaddr
)
7270 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7271 best_highpc
+ baseaddr
)
7274 end_psymtab_common (objfile
, pst
);
7276 if (!cu
->per_cu
->imported_symtabs_empty ())
7279 int len
= cu
->per_cu
->imported_symtabs_size ();
7281 /* Fill in 'dependencies' here; we fill in 'users' in a
7283 pst
->number_of_dependencies
= len
;
7285 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7286 for (i
= 0; i
< len
; ++i
)
7288 pst
->dependencies
[i
]
7289 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7292 cu
->per_cu
->imported_symtabs_free ();
7295 /* Get the list of files included in the current compilation unit,
7296 and build a psymtab for each of them. */
7297 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7299 if (dwarf_read_debug
)
7300 fprintf_unfiltered (gdb_stdlog
,
7301 "Psymtab for %s unit @%s: %s - %s"
7302 ", %d global, %d static syms\n",
7303 per_cu
->is_debug_types
? "type" : "comp",
7304 sect_offset_str (per_cu
->sect_off
),
7305 paddress (gdbarch
, pst
->text_low (objfile
)),
7306 paddress (gdbarch
, pst
->text_high (objfile
)),
7307 pst
->n_global_syms
, pst
->n_static_syms
);
7310 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7311 Process compilation unit THIS_CU for a psymtab. */
7314 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7315 bool want_partial_unit
,
7316 enum language pretend_language
)
7318 /* If this compilation unit was already read in, free the
7319 cached copy in order to read it in again. This is
7320 necessary because we skipped some symbols when we first
7321 read in the compilation unit (see load_partial_dies).
7322 This problem could be avoided, but the benefit is unclear. */
7323 if (this_cu
->cu
!= NULL
)
7324 free_one_cached_comp_unit (this_cu
);
7326 cutu_reader
reader (this_cu
, NULL
, 0, false);
7328 switch (reader
.comp_unit_die
->tag
)
7330 case DW_TAG_compile_unit
:
7331 this_cu
->unit_type
= DW_UT_compile
;
7333 case DW_TAG_partial_unit
:
7334 this_cu
->unit_type
= DW_UT_partial
;
7344 else if (this_cu
->is_debug_types
)
7345 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7346 reader
.comp_unit_die
);
7347 else if (want_partial_unit
7348 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7349 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7350 reader
.comp_unit_die
,
7353 this_cu
->lang
= this_cu
->cu
->language
;
7355 /* Age out any secondary CUs. */
7356 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7359 /* Reader function for build_type_psymtabs. */
7362 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7363 const gdb_byte
*info_ptr
,
7364 struct die_info
*type_unit_die
)
7366 struct dwarf2_per_objfile
*dwarf2_per_objfile
7367 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7368 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7369 struct dwarf2_cu
*cu
= reader
->cu
;
7370 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7371 struct signatured_type
*sig_type
;
7372 struct type_unit_group
*tu_group
;
7373 struct attribute
*attr
;
7374 struct partial_die_info
*first_die
;
7375 CORE_ADDR lowpc
, highpc
;
7376 dwarf2_psymtab
*pst
;
7378 gdb_assert (per_cu
->is_debug_types
);
7379 sig_type
= (struct signatured_type
*) per_cu
;
7381 if (! type_unit_die
->has_children
)
7384 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7385 tu_group
= get_type_unit_group (cu
, attr
);
7387 if (tu_group
->tus
== nullptr)
7388 tu_group
->tus
= new std::vector
<signatured_type
*>;
7389 tu_group
->tus
->push_back (sig_type
);
7391 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7392 pst
= create_partial_symtab (per_cu
, "");
7393 pst
->anonymous
= true;
7395 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7397 lowpc
= (CORE_ADDR
) -1;
7398 highpc
= (CORE_ADDR
) 0;
7399 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7401 end_psymtab_common (objfile
, pst
);
7404 /* Struct used to sort TUs by their abbreviation table offset. */
7406 struct tu_abbrev_offset
7408 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7409 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7412 signatured_type
*sig_type
;
7413 sect_offset abbrev_offset
;
7416 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7419 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7420 const struct tu_abbrev_offset
&b
)
7422 return a
.abbrev_offset
< b
.abbrev_offset
;
7425 /* Efficiently read all the type units.
7426 This does the bulk of the work for build_type_psymtabs.
7428 The efficiency is because we sort TUs by the abbrev table they use and
7429 only read each abbrev table once. In one program there are 200K TUs
7430 sharing 8K abbrev tables.
7432 The main purpose of this function is to support building the
7433 dwarf2_per_objfile->type_unit_groups table.
7434 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7435 can collapse the search space by grouping them by stmt_list.
7436 The savings can be significant, in the same program from above the 200K TUs
7437 share 8K stmt_list tables.
7439 FUNC is expected to call get_type_unit_group, which will create the
7440 struct type_unit_group if necessary and add it to
7441 dwarf2_per_objfile->type_unit_groups. */
7444 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7446 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7447 abbrev_table_up abbrev_table
;
7448 sect_offset abbrev_offset
;
7450 /* It's up to the caller to not call us multiple times. */
7451 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7453 if (dwarf2_per_objfile
->all_type_units
.empty ())
7456 /* TUs typically share abbrev tables, and there can be way more TUs than
7457 abbrev tables. Sort by abbrev table to reduce the number of times we
7458 read each abbrev table in.
7459 Alternatives are to punt or to maintain a cache of abbrev tables.
7460 This is simpler and efficient enough for now.
7462 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7463 symtab to use). Typically TUs with the same abbrev offset have the same
7464 stmt_list value too so in practice this should work well.
7466 The basic algorithm here is:
7468 sort TUs by abbrev table
7469 for each TU with same abbrev table:
7470 read abbrev table if first user
7471 read TU top level DIE
7472 [IWBN if DWO skeletons had DW_AT_stmt_list]
7475 if (dwarf_read_debug
)
7476 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7478 /* Sort in a separate table to maintain the order of all_type_units
7479 for .gdb_index: TU indices directly index all_type_units. */
7480 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7481 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7483 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7484 sorted_by_abbrev
.emplace_back
7485 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7486 sig_type
->per_cu
.section
,
7487 sig_type
->per_cu
.sect_off
));
7489 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7490 sort_tu_by_abbrev_offset
);
7492 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7494 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7496 /* Switch to the next abbrev table if necessary. */
7497 if (abbrev_table
== NULL
7498 || tu
.abbrev_offset
!= abbrev_offset
)
7500 abbrev_offset
= tu
.abbrev_offset
;
7502 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7503 &dwarf2_per_objfile
->abbrev
,
7505 ++tu_stats
->nr_uniq_abbrev_tables
;
7508 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7510 if (!reader
.dummy_p
)
7511 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7512 reader
.comp_unit_die
);
7516 /* Print collected type unit statistics. */
7519 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7521 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7523 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7524 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7525 dwarf2_per_objfile
->all_type_units
.size ());
7526 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7527 tu_stats
->nr_uniq_abbrev_tables
);
7528 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7529 tu_stats
->nr_symtabs
);
7530 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7531 tu_stats
->nr_symtab_sharers
);
7532 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7533 tu_stats
->nr_stmt_less_type_units
);
7534 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7535 tu_stats
->nr_all_type_units_reallocs
);
7538 /* Traversal function for build_type_psymtabs. */
7541 build_type_psymtab_dependencies (void **slot
, void *info
)
7543 struct dwarf2_per_objfile
*dwarf2_per_objfile
7544 = (struct dwarf2_per_objfile
*) info
;
7545 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7546 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7547 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7548 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7549 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7552 gdb_assert (len
> 0);
7553 gdb_assert (per_cu
->type_unit_group_p ());
7555 pst
->number_of_dependencies
= len
;
7556 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7557 for (i
= 0; i
< len
; ++i
)
7559 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7560 gdb_assert (iter
->per_cu
.is_debug_types
);
7561 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7562 iter
->type_unit_group
= tu_group
;
7565 delete tu_group
->tus
;
7566 tu_group
->tus
= nullptr;
7571 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7572 Build partial symbol tables for the .debug_types comp-units. */
7575 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7577 if (! create_all_type_units (dwarf2_per_objfile
))
7580 build_type_psymtabs_1 (dwarf2_per_objfile
);
7583 /* Traversal function for process_skeletonless_type_unit.
7584 Read a TU in a DWO file and build partial symbols for it. */
7587 process_skeletonless_type_unit (void **slot
, void *info
)
7589 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7590 struct dwarf2_per_objfile
*dwarf2_per_objfile
7591 = (struct dwarf2_per_objfile
*) info
;
7592 struct signatured_type find_entry
, *entry
;
7594 /* If this TU doesn't exist in the global table, add it and read it in. */
7596 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7597 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7599 find_entry
.signature
= dwo_unit
->signature
;
7600 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7601 &find_entry
, INSERT
);
7602 /* If we've already seen this type there's nothing to do. What's happening
7603 is we're doing our own version of comdat-folding here. */
7607 /* This does the job that create_all_type_units would have done for
7609 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7610 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7613 /* This does the job that build_type_psymtabs_1 would have done. */
7614 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7615 if (!reader
.dummy_p
)
7616 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7617 reader
.comp_unit_die
);
7622 /* Traversal function for process_skeletonless_type_units. */
7625 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7627 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7629 if (dwo_file
->tus
!= NULL
)
7630 htab_traverse_noresize (dwo_file
->tus
.get (),
7631 process_skeletonless_type_unit
, info
);
7636 /* Scan all TUs of DWO files, verifying we've processed them.
7637 This is needed in case a TU was emitted without its skeleton.
7638 Note: This can't be done until we know what all the DWO files are. */
7641 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7643 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7644 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7645 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7647 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7648 process_dwo_file_for_skeletonless_type_units
,
7649 dwarf2_per_objfile
);
7653 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7656 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7658 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7660 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7665 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7667 /* Set the 'user' field only if it is not already set. */
7668 if (pst
->dependencies
[j
]->user
== NULL
)
7669 pst
->dependencies
[j
]->user
= pst
;
7674 /* Build the partial symbol table by doing a quick pass through the
7675 .debug_info and .debug_abbrev sections. */
7678 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7680 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7682 if (dwarf_read_debug
)
7684 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7685 objfile_name (objfile
));
7688 scoped_restore restore_reading_psyms
7689 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7692 dwarf2_per_objfile
->info
.read (objfile
);
7694 /* Any cached compilation units will be linked by the per-objfile
7695 read_in_chain. Make sure to free them when we're done. */
7696 free_cached_comp_units
freer (dwarf2_per_objfile
);
7698 build_type_psymtabs (dwarf2_per_objfile
);
7700 create_all_comp_units (dwarf2_per_objfile
);
7702 /* Create a temporary address map on a temporary obstack. We later
7703 copy this to the final obstack. */
7704 auto_obstack temp_obstack
;
7706 scoped_restore save_psymtabs_addrmap
7707 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7708 addrmap_create_mutable (&temp_obstack
));
7710 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7711 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7713 /* This has to wait until we read the CUs, we need the list of DWOs. */
7714 process_skeletonless_type_units (dwarf2_per_objfile
);
7716 /* Now that all TUs have been processed we can fill in the dependencies. */
7717 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7719 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7720 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7723 if (dwarf_read_debug
)
7724 print_tu_stats (dwarf2_per_objfile
);
7726 set_partial_user (dwarf2_per_objfile
);
7728 objfile
->partial_symtabs
->psymtabs_addrmap
7729 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7730 objfile
->partial_symtabs
->obstack ());
7731 /* At this point we want to keep the address map. */
7732 save_psymtabs_addrmap
.release ();
7734 if (dwarf_read_debug
)
7735 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7736 objfile_name (objfile
));
7739 /* Load the partial DIEs for a secondary CU into memory.
7740 This is also used when rereading a primary CU with load_all_dies. */
7743 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7745 cutu_reader
reader (this_cu
, NULL
, 1, false);
7747 if (!reader
.dummy_p
)
7749 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7752 /* Check if comp unit has_children.
7753 If so, read the rest of the partial symbols from this comp unit.
7754 If not, there's no more debug_info for this comp unit. */
7755 if (reader
.comp_unit_die
->has_children
)
7756 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7763 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7764 struct dwarf2_section_info
*section
,
7765 struct dwarf2_section_info
*abbrev_section
,
7766 unsigned int is_dwz
)
7768 const gdb_byte
*info_ptr
;
7769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7771 if (dwarf_read_debug
)
7772 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7773 section
->get_name (),
7774 section
->get_file_name ());
7776 section
->read (objfile
);
7778 info_ptr
= section
->buffer
;
7780 while (info_ptr
< section
->buffer
+ section
->size
)
7782 struct dwarf2_per_cu_data
*this_cu
;
7784 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7786 comp_unit_head cu_header
;
7787 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7788 abbrev_section
, info_ptr
,
7789 rcuh_kind::COMPILE
);
7791 /* Save the compilation unit for later lookup. */
7792 if (cu_header
.unit_type
!= DW_UT_type
)
7794 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7795 struct dwarf2_per_cu_data
);
7796 memset (this_cu
, 0, sizeof (*this_cu
));
7800 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7801 struct signatured_type
);
7802 memset (sig_type
, 0, sizeof (*sig_type
));
7803 sig_type
->signature
= cu_header
.signature
;
7804 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7805 this_cu
= &sig_type
->per_cu
;
7807 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7808 this_cu
->sect_off
= sect_off
;
7809 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7810 this_cu
->is_dwz
= is_dwz
;
7811 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7812 this_cu
->section
= section
;
7814 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7816 info_ptr
= info_ptr
+ this_cu
->length
;
7820 /* Create a list of all compilation units in OBJFILE.
7821 This is only done for -readnow and building partial symtabs. */
7824 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7826 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7827 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7828 &dwarf2_per_objfile
->abbrev
, 0);
7830 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7832 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7836 /* Process all loaded DIEs for compilation unit CU, starting at
7837 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7838 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7839 DW_AT_ranges). See the comments of add_partial_subprogram on how
7840 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7843 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7844 CORE_ADDR
*highpc
, int set_addrmap
,
7845 struct dwarf2_cu
*cu
)
7847 struct partial_die_info
*pdi
;
7849 /* Now, march along the PDI's, descending into ones which have
7850 interesting children but skipping the children of the other ones,
7851 until we reach the end of the compilation unit. */
7859 /* Anonymous namespaces or modules have no name but have interesting
7860 children, so we need to look at them. Ditto for anonymous
7863 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7864 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7865 || pdi
->tag
== DW_TAG_imported_unit
7866 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7870 case DW_TAG_subprogram
:
7871 case DW_TAG_inlined_subroutine
:
7872 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7874 case DW_TAG_constant
:
7875 case DW_TAG_variable
:
7876 case DW_TAG_typedef
:
7877 case DW_TAG_union_type
:
7878 if (!pdi
->is_declaration
)
7880 add_partial_symbol (pdi
, cu
);
7883 case DW_TAG_class_type
:
7884 case DW_TAG_interface_type
:
7885 case DW_TAG_structure_type
:
7886 if (!pdi
->is_declaration
)
7888 add_partial_symbol (pdi
, cu
);
7890 if ((cu
->language
== language_rust
7891 || cu
->language
== language_cplus
) && pdi
->has_children
)
7892 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7895 case DW_TAG_enumeration_type
:
7896 if (!pdi
->is_declaration
)
7897 add_partial_enumeration (pdi
, cu
);
7899 case DW_TAG_base_type
:
7900 case DW_TAG_subrange_type
:
7901 /* File scope base type definitions are added to the partial
7903 add_partial_symbol (pdi
, cu
);
7905 case DW_TAG_namespace
:
7906 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7909 if (!pdi
->is_declaration
)
7910 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7912 case DW_TAG_imported_unit
:
7914 struct dwarf2_per_cu_data
*per_cu
;
7916 /* For now we don't handle imported units in type units. */
7917 if (cu
->per_cu
->is_debug_types
)
7919 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7920 " supported in type units [in module %s]"),
7921 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7924 per_cu
= dwarf2_find_containing_comp_unit
7925 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7926 cu
->per_cu
->dwarf2_per_objfile
);
7928 /* Go read the partial unit, if needed. */
7929 if (per_cu
->v
.psymtab
== NULL
)
7930 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7932 cu
->per_cu
->imported_symtabs_push (per_cu
);
7935 case DW_TAG_imported_declaration
:
7936 add_partial_symbol (pdi
, cu
);
7943 /* If the die has a sibling, skip to the sibling. */
7945 pdi
= pdi
->die_sibling
;
7949 /* Functions used to compute the fully scoped name of a partial DIE.
7951 Normally, this is simple. For C++, the parent DIE's fully scoped
7952 name is concatenated with "::" and the partial DIE's name.
7953 Enumerators are an exception; they use the scope of their parent
7954 enumeration type, i.e. the name of the enumeration type is not
7955 prepended to the enumerator.
7957 There are two complexities. One is DW_AT_specification; in this
7958 case "parent" means the parent of the target of the specification,
7959 instead of the direct parent of the DIE. The other is compilers
7960 which do not emit DW_TAG_namespace; in this case we try to guess
7961 the fully qualified name of structure types from their members'
7962 linkage names. This must be done using the DIE's children rather
7963 than the children of any DW_AT_specification target. We only need
7964 to do this for structures at the top level, i.e. if the target of
7965 any DW_AT_specification (if any; otherwise the DIE itself) does not
7968 /* Compute the scope prefix associated with PDI's parent, in
7969 compilation unit CU. The result will be allocated on CU's
7970 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7971 field. NULL is returned if no prefix is necessary. */
7973 partial_die_parent_scope (struct partial_die_info
*pdi
,
7974 struct dwarf2_cu
*cu
)
7976 const char *grandparent_scope
;
7977 struct partial_die_info
*parent
, *real_pdi
;
7979 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7980 then this means the parent of the specification DIE. */
7983 while (real_pdi
->has_specification
)
7985 auto res
= find_partial_die (real_pdi
->spec_offset
,
7986 real_pdi
->spec_is_dwz
, cu
);
7991 parent
= real_pdi
->die_parent
;
7995 if (parent
->scope_set
)
7996 return parent
->scope
;
8000 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8002 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8003 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8004 Work around this problem here. */
8005 if (cu
->language
== language_cplus
8006 && parent
->tag
== DW_TAG_namespace
8007 && strcmp (parent
->name
, "::") == 0
8008 && grandparent_scope
== NULL
)
8010 parent
->scope
= NULL
;
8011 parent
->scope_set
= 1;
8015 /* Nested subroutines in Fortran get a prefix. */
8016 if (pdi
->tag
== DW_TAG_enumerator
)
8017 /* Enumerators should not get the name of the enumeration as a prefix. */
8018 parent
->scope
= grandparent_scope
;
8019 else if (parent
->tag
== DW_TAG_namespace
8020 || parent
->tag
== DW_TAG_module
8021 || parent
->tag
== DW_TAG_structure_type
8022 || parent
->tag
== DW_TAG_class_type
8023 || parent
->tag
== DW_TAG_interface_type
8024 || parent
->tag
== DW_TAG_union_type
8025 || parent
->tag
== DW_TAG_enumeration_type
8026 || (cu
->language
== language_fortran
8027 && parent
->tag
== DW_TAG_subprogram
8028 && pdi
->tag
== DW_TAG_subprogram
))
8030 if (grandparent_scope
== NULL
)
8031 parent
->scope
= parent
->name
;
8033 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8035 parent
->name
, 0, cu
);
8039 /* FIXME drow/2004-04-01: What should we be doing with
8040 function-local names? For partial symbols, we should probably be
8042 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8043 dwarf_tag_name (parent
->tag
),
8044 sect_offset_str (pdi
->sect_off
));
8045 parent
->scope
= grandparent_scope
;
8048 parent
->scope_set
= 1;
8049 return parent
->scope
;
8052 /* Return the fully scoped name associated with PDI, from compilation unit
8053 CU. The result will be allocated with malloc. */
8055 static gdb::unique_xmalloc_ptr
<char>
8056 partial_die_full_name (struct partial_die_info
*pdi
,
8057 struct dwarf2_cu
*cu
)
8059 const char *parent_scope
;
8061 /* If this is a template instantiation, we can not work out the
8062 template arguments from partial DIEs. So, unfortunately, we have
8063 to go through the full DIEs. At least any work we do building
8064 types here will be reused if full symbols are loaded later. */
8065 if (pdi
->has_template_arguments
)
8069 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8071 struct die_info
*die
;
8072 struct attribute attr
;
8073 struct dwarf2_cu
*ref_cu
= cu
;
8075 /* DW_FORM_ref_addr is using section offset. */
8076 attr
.name
= (enum dwarf_attribute
) 0;
8077 attr
.form
= DW_FORM_ref_addr
;
8078 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8079 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8081 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8085 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8086 if (parent_scope
== NULL
)
8089 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8094 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8096 struct dwarf2_per_objfile
*dwarf2_per_objfile
8097 = cu
->per_cu
->dwarf2_per_objfile
;
8098 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8099 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8101 const char *actual_name
= NULL
;
8104 baseaddr
= objfile
->text_section_offset ();
8106 gdb::unique_xmalloc_ptr
<char> built_actual_name
8107 = partial_die_full_name (pdi
, cu
);
8108 if (built_actual_name
!= NULL
)
8109 actual_name
= built_actual_name
.get ();
8111 if (actual_name
== NULL
)
8112 actual_name
= pdi
->name
;
8116 case DW_TAG_inlined_subroutine
:
8117 case DW_TAG_subprogram
:
8118 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8120 if (pdi
->is_external
8121 || cu
->language
== language_ada
8122 || (cu
->language
== language_fortran
8123 && pdi
->die_parent
!= NULL
8124 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8126 /* Normally, only "external" DIEs are part of the global scope.
8127 But in Ada and Fortran, we want to be able to access nested
8128 procedures globally. So all Ada and Fortran subprograms are
8129 stored in the global scope. */
8130 add_psymbol_to_list (actual_name
,
8131 built_actual_name
!= NULL
,
8132 VAR_DOMAIN
, LOC_BLOCK
,
8133 SECT_OFF_TEXT (objfile
),
8134 psymbol_placement::GLOBAL
,
8136 cu
->language
, objfile
);
8140 add_psymbol_to_list (actual_name
,
8141 built_actual_name
!= NULL
,
8142 VAR_DOMAIN
, LOC_BLOCK
,
8143 SECT_OFF_TEXT (objfile
),
8144 psymbol_placement::STATIC
,
8145 addr
, cu
->language
, objfile
);
8148 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8149 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8151 case DW_TAG_constant
:
8152 add_psymbol_to_list (actual_name
,
8153 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8154 -1, (pdi
->is_external
8155 ? psymbol_placement::GLOBAL
8156 : psymbol_placement::STATIC
),
8157 0, cu
->language
, objfile
);
8159 case DW_TAG_variable
:
8161 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8165 && !dwarf2_per_objfile
->has_section_at_zero
)
8167 /* A global or static variable may also have been stripped
8168 out by the linker if unused, in which case its address
8169 will be nullified; do not add such variables into partial
8170 symbol table then. */
8172 else if (pdi
->is_external
)
8175 Don't enter into the minimal symbol tables as there is
8176 a minimal symbol table entry from the ELF symbols already.
8177 Enter into partial symbol table if it has a location
8178 descriptor or a type.
8179 If the location descriptor is missing, new_symbol will create
8180 a LOC_UNRESOLVED symbol, the address of the variable will then
8181 be determined from the minimal symbol table whenever the variable
8183 The address for the partial symbol table entry is not
8184 used by GDB, but it comes in handy for debugging partial symbol
8187 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8188 add_psymbol_to_list (actual_name
,
8189 built_actual_name
!= NULL
,
8190 VAR_DOMAIN
, LOC_STATIC
,
8191 SECT_OFF_TEXT (objfile
),
8192 psymbol_placement::GLOBAL
,
8193 addr
, cu
->language
, objfile
);
8197 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8199 /* Static Variable. Skip symbols whose value we cannot know (those
8200 without location descriptors or constant values). */
8201 if (!has_loc
&& !pdi
->has_const_value
)
8204 add_psymbol_to_list (actual_name
,
8205 built_actual_name
!= NULL
,
8206 VAR_DOMAIN
, LOC_STATIC
,
8207 SECT_OFF_TEXT (objfile
),
8208 psymbol_placement::STATIC
,
8210 cu
->language
, objfile
);
8213 case DW_TAG_typedef
:
8214 case DW_TAG_base_type
:
8215 case DW_TAG_subrange_type
:
8216 add_psymbol_to_list (actual_name
,
8217 built_actual_name
!= NULL
,
8218 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8219 psymbol_placement::STATIC
,
8220 0, cu
->language
, objfile
);
8222 case DW_TAG_imported_declaration
:
8223 case DW_TAG_namespace
:
8224 add_psymbol_to_list (actual_name
,
8225 built_actual_name
!= NULL
,
8226 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8227 psymbol_placement::GLOBAL
,
8228 0, cu
->language
, objfile
);
8231 /* With Fortran 77 there might be a "BLOCK DATA" module
8232 available without any name. If so, we skip the module as it
8233 doesn't bring any value. */
8234 if (actual_name
!= nullptr)
8235 add_psymbol_to_list (actual_name
,
8236 built_actual_name
!= NULL
,
8237 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8238 psymbol_placement::GLOBAL
,
8239 0, cu
->language
, objfile
);
8241 case DW_TAG_class_type
:
8242 case DW_TAG_interface_type
:
8243 case DW_TAG_structure_type
:
8244 case DW_TAG_union_type
:
8245 case DW_TAG_enumeration_type
:
8246 /* Skip external references. The DWARF standard says in the section
8247 about "Structure, Union, and Class Type Entries": "An incomplete
8248 structure, union or class type is represented by a structure,
8249 union or class entry that does not have a byte size attribute
8250 and that has a DW_AT_declaration attribute." */
8251 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8254 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8255 static vs. global. */
8256 add_psymbol_to_list (actual_name
,
8257 built_actual_name
!= NULL
,
8258 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8259 cu
->language
== language_cplus
8260 ? psymbol_placement::GLOBAL
8261 : psymbol_placement::STATIC
,
8262 0, cu
->language
, objfile
);
8265 case DW_TAG_enumerator
:
8266 add_psymbol_to_list (actual_name
,
8267 built_actual_name
!= NULL
,
8268 VAR_DOMAIN
, LOC_CONST
, -1,
8269 cu
->language
== language_cplus
8270 ? psymbol_placement::GLOBAL
8271 : psymbol_placement::STATIC
,
8272 0, cu
->language
, objfile
);
8279 /* Read a partial die corresponding to a namespace; also, add a symbol
8280 corresponding to that namespace to the symbol table. NAMESPACE is
8281 the name of the enclosing namespace. */
8284 add_partial_namespace (struct partial_die_info
*pdi
,
8285 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8286 int set_addrmap
, struct dwarf2_cu
*cu
)
8288 /* Add a symbol for the namespace. */
8290 add_partial_symbol (pdi
, cu
);
8292 /* Now scan partial symbols in that namespace. */
8294 if (pdi
->has_children
)
8295 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8298 /* Read a partial die corresponding to a Fortran module. */
8301 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8302 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8304 /* Add a symbol for the namespace. */
8306 add_partial_symbol (pdi
, cu
);
8308 /* Now scan partial symbols in that module. */
8310 if (pdi
->has_children
)
8311 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8314 /* Read a partial die corresponding to a subprogram or an inlined
8315 subprogram and create a partial symbol for that subprogram.
8316 When the CU language allows it, this routine also defines a partial
8317 symbol for each nested subprogram that this subprogram contains.
8318 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8319 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8321 PDI may also be a lexical block, in which case we simply search
8322 recursively for subprograms defined inside that lexical block.
8323 Again, this is only performed when the CU language allows this
8324 type of definitions. */
8327 add_partial_subprogram (struct partial_die_info
*pdi
,
8328 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8329 int set_addrmap
, struct dwarf2_cu
*cu
)
8331 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8333 if (pdi
->has_pc_info
)
8335 if (pdi
->lowpc
< *lowpc
)
8336 *lowpc
= pdi
->lowpc
;
8337 if (pdi
->highpc
> *highpc
)
8338 *highpc
= pdi
->highpc
;
8341 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8342 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8344 CORE_ADDR this_highpc
;
8345 CORE_ADDR this_lowpc
;
8347 baseaddr
= objfile
->text_section_offset ();
8349 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8350 pdi
->lowpc
+ baseaddr
)
8353 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8354 pdi
->highpc
+ baseaddr
)
8356 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8357 this_lowpc
, this_highpc
- 1,
8358 cu
->per_cu
->v
.psymtab
);
8362 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8364 if (!pdi
->is_declaration
)
8365 /* Ignore subprogram DIEs that do not have a name, they are
8366 illegal. Do not emit a complaint at this point, we will
8367 do so when we convert this psymtab into a symtab. */
8369 add_partial_symbol (pdi
, cu
);
8373 if (! pdi
->has_children
)
8376 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8378 pdi
= pdi
->die_child
;
8382 if (pdi
->tag
== DW_TAG_subprogram
8383 || pdi
->tag
== DW_TAG_inlined_subroutine
8384 || pdi
->tag
== DW_TAG_lexical_block
)
8385 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8386 pdi
= pdi
->die_sibling
;
8391 /* Read a partial die corresponding to an enumeration type. */
8394 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8395 struct dwarf2_cu
*cu
)
8397 struct partial_die_info
*pdi
;
8399 if (enum_pdi
->name
!= NULL
)
8400 add_partial_symbol (enum_pdi
, cu
);
8402 pdi
= enum_pdi
->die_child
;
8405 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8406 complaint (_("malformed enumerator DIE ignored"));
8408 add_partial_symbol (pdi
, cu
);
8409 pdi
= pdi
->die_sibling
;
8413 /* Return the initial uleb128 in the die at INFO_PTR. */
8416 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8418 unsigned int bytes_read
;
8420 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8423 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8424 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8426 Return the corresponding abbrev, or NULL if the number is zero (indicating
8427 an empty DIE). In either case *BYTES_READ will be set to the length of
8428 the initial number. */
8430 static struct abbrev_info
*
8431 peek_die_abbrev (const die_reader_specs
&reader
,
8432 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8434 dwarf2_cu
*cu
= reader
.cu
;
8435 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8436 unsigned int abbrev_number
8437 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8439 if (abbrev_number
== 0)
8442 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8445 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8446 " at offset %s [in module %s]"),
8447 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8448 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8454 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8455 Returns a pointer to the end of a series of DIEs, terminated by an empty
8456 DIE. Any children of the skipped DIEs will also be skipped. */
8458 static const gdb_byte
*
8459 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8463 unsigned int bytes_read
;
8464 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8467 return info_ptr
+ bytes_read
;
8469 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8473 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8474 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8475 abbrev corresponding to that skipped uleb128 should be passed in
8476 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8479 static const gdb_byte
*
8480 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8481 struct abbrev_info
*abbrev
)
8483 unsigned int bytes_read
;
8484 struct attribute attr
;
8485 bfd
*abfd
= reader
->abfd
;
8486 struct dwarf2_cu
*cu
= reader
->cu
;
8487 const gdb_byte
*buffer
= reader
->buffer
;
8488 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8489 unsigned int form
, i
;
8491 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8493 /* The only abbrev we care about is DW_AT_sibling. */
8494 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8497 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8499 if (attr
.form
== DW_FORM_ref_addr
)
8500 complaint (_("ignoring absolute DW_AT_sibling"));
8503 sect_offset off
= attr
.get_ref_die_offset ();
8504 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8506 if (sibling_ptr
< info_ptr
)
8507 complaint (_("DW_AT_sibling points backwards"));
8508 else if (sibling_ptr
> reader
->buffer_end
)
8509 reader
->die_section
->overflow_complaint ();
8515 /* If it isn't DW_AT_sibling, skip this attribute. */
8516 form
= abbrev
->attrs
[i
].form
;
8520 case DW_FORM_ref_addr
:
8521 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8522 and later it is offset sized. */
8523 if (cu
->header
.version
== 2)
8524 info_ptr
+= cu
->header
.addr_size
;
8526 info_ptr
+= cu
->header
.offset_size
;
8528 case DW_FORM_GNU_ref_alt
:
8529 info_ptr
+= cu
->header
.offset_size
;
8532 info_ptr
+= cu
->header
.addr_size
;
8540 case DW_FORM_flag_present
:
8541 case DW_FORM_implicit_const
:
8558 case DW_FORM_ref_sig8
:
8561 case DW_FORM_data16
:
8564 case DW_FORM_string
:
8565 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8566 info_ptr
+= bytes_read
;
8568 case DW_FORM_sec_offset
:
8570 case DW_FORM_GNU_strp_alt
:
8571 info_ptr
+= cu
->header
.offset_size
;
8573 case DW_FORM_exprloc
:
8575 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8576 info_ptr
+= bytes_read
;
8578 case DW_FORM_block1
:
8579 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8581 case DW_FORM_block2
:
8582 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8584 case DW_FORM_block4
:
8585 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8591 case DW_FORM_ref_udata
:
8592 case DW_FORM_GNU_addr_index
:
8593 case DW_FORM_GNU_str_index
:
8594 case DW_FORM_rnglistx
:
8595 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8597 case DW_FORM_indirect
:
8598 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8599 info_ptr
+= bytes_read
;
8600 /* We need to continue parsing from here, so just go back to
8602 goto skip_attribute
;
8605 error (_("Dwarf Error: Cannot handle %s "
8606 "in DWARF reader [in module %s]"),
8607 dwarf_form_name (form
),
8608 bfd_get_filename (abfd
));
8612 if (abbrev
->has_children
)
8613 return skip_children (reader
, info_ptr
);
8618 /* Locate ORIG_PDI's sibling.
8619 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8621 static const gdb_byte
*
8622 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8623 struct partial_die_info
*orig_pdi
,
8624 const gdb_byte
*info_ptr
)
8626 /* Do we know the sibling already? */
8628 if (orig_pdi
->sibling
)
8629 return orig_pdi
->sibling
;
8631 /* Are there any children to deal with? */
8633 if (!orig_pdi
->has_children
)
8636 /* Skip the children the long way. */
8638 return skip_children (reader
, info_ptr
);
8641 /* Expand this partial symbol table into a full symbol table. SELF is
8645 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8647 struct dwarf2_per_objfile
*dwarf2_per_objfile
8648 = get_dwarf2_per_objfile (objfile
);
8650 gdb_assert (!readin
);
8651 /* If this psymtab is constructed from a debug-only objfile, the
8652 has_section_at_zero flag will not necessarily be correct. We
8653 can get the correct value for this flag by looking at the data
8654 associated with the (presumably stripped) associated objfile. */
8655 if (objfile
->separate_debug_objfile_backlink
)
8657 struct dwarf2_per_objfile
*dpo_backlink
8658 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8660 dwarf2_per_objfile
->has_section_at_zero
8661 = dpo_backlink
->has_section_at_zero
;
8664 expand_psymtab (objfile
);
8666 process_cu_includes (dwarf2_per_objfile
);
8669 /* Reading in full CUs. */
8671 /* Add PER_CU to the queue. */
8674 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8675 enum language pretend_language
)
8678 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8681 /* If PER_CU is not yet queued, add it to the queue.
8682 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8684 The result is non-zero if PER_CU was queued, otherwise the result is zero
8685 meaning either PER_CU is already queued or it is already loaded.
8687 N.B. There is an invariant here that if a CU is queued then it is loaded.
8688 The caller is required to load PER_CU if we return non-zero. */
8691 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8692 struct dwarf2_per_cu_data
*per_cu
,
8693 enum language pretend_language
)
8695 /* We may arrive here during partial symbol reading, if we need full
8696 DIEs to process an unusual case (e.g. template arguments). Do
8697 not queue PER_CU, just tell our caller to load its DIEs. */
8698 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8700 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8705 /* Mark the dependence relation so that we don't flush PER_CU
8707 if (dependent_cu
!= NULL
)
8708 dwarf2_add_dependence (dependent_cu
, per_cu
);
8710 /* If it's already on the queue, we have nothing to do. */
8714 /* If the compilation unit is already loaded, just mark it as
8716 if (per_cu
->cu
!= NULL
)
8718 per_cu
->cu
->last_used
= 0;
8722 /* Add it to the queue. */
8723 queue_comp_unit (per_cu
, pretend_language
);
8728 /* Process the queue. */
8731 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8733 if (dwarf_read_debug
)
8735 fprintf_unfiltered (gdb_stdlog
,
8736 "Expanding one or more symtabs of objfile %s ...\n",
8737 objfile_name (dwarf2_per_objfile
->objfile
));
8740 /* The queue starts out with one item, but following a DIE reference
8741 may load a new CU, adding it to the end of the queue. */
8742 while (!dwarf2_per_objfile
->queue
.empty ())
8744 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8746 if ((dwarf2_per_objfile
->using_index
8747 ? !item
.per_cu
->v
.quick
->compunit_symtab
8748 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8749 /* Skip dummy CUs. */
8750 && item
.per_cu
->cu
!= NULL
)
8752 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8753 unsigned int debug_print_threshold
;
8756 if (per_cu
->is_debug_types
)
8758 struct signatured_type
*sig_type
=
8759 (struct signatured_type
*) per_cu
;
8761 sprintf (buf
, "TU %s at offset %s",
8762 hex_string (sig_type
->signature
),
8763 sect_offset_str (per_cu
->sect_off
));
8764 /* There can be 100s of TUs.
8765 Only print them in verbose mode. */
8766 debug_print_threshold
= 2;
8770 sprintf (buf
, "CU at offset %s",
8771 sect_offset_str (per_cu
->sect_off
));
8772 debug_print_threshold
= 1;
8775 if (dwarf_read_debug
>= debug_print_threshold
)
8776 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8778 if (per_cu
->is_debug_types
)
8779 process_full_type_unit (per_cu
, item
.pretend_language
);
8781 process_full_comp_unit (per_cu
, item
.pretend_language
);
8783 if (dwarf_read_debug
>= debug_print_threshold
)
8784 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8787 item
.per_cu
->queued
= 0;
8788 dwarf2_per_objfile
->queue
.pop ();
8791 if (dwarf_read_debug
)
8793 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8794 objfile_name (dwarf2_per_objfile
->objfile
));
8798 /* Read in full symbols for PST, and anything it depends on. */
8801 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8806 expand_dependencies (objfile
);
8808 dw2_do_instantiate_symtab (per_cu_data
, false);
8809 gdb_assert (get_compunit_symtab () != nullptr);
8812 /* Trivial hash function for die_info: the hash value of a DIE
8813 is its offset in .debug_info for this objfile. */
8816 die_hash (const void *item
)
8818 const struct die_info
*die
= (const struct die_info
*) item
;
8820 return to_underlying (die
->sect_off
);
8823 /* Trivial comparison function for die_info structures: two DIEs
8824 are equal if they have the same offset. */
8827 die_eq (const void *item_lhs
, const void *item_rhs
)
8829 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8830 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8832 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8835 /* Load the DIEs associated with PER_CU into memory. */
8838 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8840 enum language pretend_language
)
8842 gdb_assert (! this_cu
->is_debug_types
);
8844 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8848 struct dwarf2_cu
*cu
= reader
.cu
;
8849 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8851 gdb_assert (cu
->die_hash
== NULL
);
8853 htab_create_alloc_ex (cu
->header
.length
/ 12,
8857 &cu
->comp_unit_obstack
,
8858 hashtab_obstack_allocate
,
8859 dummy_obstack_deallocate
);
8861 if (reader
.comp_unit_die
->has_children
)
8862 reader
.comp_unit_die
->child
8863 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8864 &info_ptr
, reader
.comp_unit_die
);
8865 cu
->dies
= reader
.comp_unit_die
;
8866 /* comp_unit_die is not stored in die_hash, no need. */
8868 /* We try not to read any attributes in this function, because not
8869 all CUs needed for references have been loaded yet, and symbol
8870 table processing isn't initialized. But we have to set the CU language,
8871 or we won't be able to build types correctly.
8872 Similarly, if we do not read the producer, we can not apply
8873 producer-specific interpretation. */
8874 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8879 /* Add a DIE to the delayed physname list. */
8882 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8883 const char *name
, struct die_info
*die
,
8884 struct dwarf2_cu
*cu
)
8886 struct delayed_method_info mi
;
8888 mi
.fnfield_index
= fnfield_index
;
8892 cu
->method_list
.push_back (mi
);
8895 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8896 "const" / "volatile". If so, decrements LEN by the length of the
8897 modifier and return true. Otherwise return false. */
8901 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8903 size_t mod_len
= sizeof (mod
) - 1;
8904 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8912 /* Compute the physnames of any methods on the CU's method list.
8914 The computation of method physnames is delayed in order to avoid the
8915 (bad) condition that one of the method's formal parameters is of an as yet
8919 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8921 /* Only C++ delays computing physnames. */
8922 if (cu
->method_list
.empty ())
8924 gdb_assert (cu
->language
== language_cplus
);
8926 for (const delayed_method_info
&mi
: cu
->method_list
)
8928 const char *physname
;
8929 struct fn_fieldlist
*fn_flp
8930 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8931 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8932 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8933 = physname
? physname
: "";
8935 /* Since there's no tag to indicate whether a method is a
8936 const/volatile overload, extract that information out of the
8938 if (physname
!= NULL
)
8940 size_t len
= strlen (physname
);
8944 if (physname
[len
] == ')') /* shortcut */
8946 else if (check_modifier (physname
, len
, " const"))
8947 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8948 else if (check_modifier (physname
, len
, " volatile"))
8949 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8956 /* The list is no longer needed. */
8957 cu
->method_list
.clear ();
8960 /* Go objects should be embedded in a DW_TAG_module DIE,
8961 and it's not clear if/how imported objects will appear.
8962 To keep Go support simple until that's worked out,
8963 go back through what we've read and create something usable.
8964 We could do this while processing each DIE, and feels kinda cleaner,
8965 but that way is more invasive.
8966 This is to, for example, allow the user to type "p var" or "b main"
8967 without having to specify the package name, and allow lookups
8968 of module.object to work in contexts that use the expression
8972 fixup_go_packaging (struct dwarf2_cu
*cu
)
8974 gdb::unique_xmalloc_ptr
<char> package_name
;
8975 struct pending
*list
;
8978 for (list
= *cu
->get_builder ()->get_global_symbols ();
8982 for (i
= 0; i
< list
->nsyms
; ++i
)
8984 struct symbol
*sym
= list
->symbol
[i
];
8986 if (sym
->language () == language_go
8987 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8989 gdb::unique_xmalloc_ptr
<char> this_package_name
8990 (go_symbol_package_name (sym
));
8992 if (this_package_name
== NULL
)
8994 if (package_name
== NULL
)
8995 package_name
= std::move (this_package_name
);
8998 struct objfile
*objfile
8999 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9000 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9001 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9002 (symbol_symtab (sym
) != NULL
9003 ? symtab_to_filename_for_display
9004 (symbol_symtab (sym
))
9005 : objfile_name (objfile
)),
9006 this_package_name
.get (), package_name
.get ());
9012 if (package_name
!= NULL
)
9014 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9015 const char *saved_package_name
= objfile
->intern (package_name
.get ());
9016 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9017 saved_package_name
);
9020 sym
= allocate_symbol (objfile
);
9021 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9022 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9023 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9024 e.g., "main" finds the "main" module and not C's main(). */
9025 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9026 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9027 SYMBOL_TYPE (sym
) = type
;
9029 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9033 /* Allocate a fully-qualified name consisting of the two parts on the
9037 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9039 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9042 /* A helper that allocates a struct discriminant_info to attach to a
9045 static struct discriminant_info
*
9046 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9049 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9050 gdb_assert (discriminant_index
== -1
9051 || (discriminant_index
>= 0
9052 && discriminant_index
< TYPE_NFIELDS (type
)));
9053 gdb_assert (default_index
== -1
9054 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9056 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9058 struct discriminant_info
*disc
9059 = ((struct discriminant_info
*)
9061 offsetof (struct discriminant_info
, discriminants
)
9062 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9063 disc
->default_index
= default_index
;
9064 disc
->discriminant_index
= discriminant_index
;
9066 struct dynamic_prop prop
;
9067 prop
.kind
= PROP_UNDEFINED
;
9068 prop
.data
.baton
= disc
;
9070 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9075 /* Some versions of rustc emitted enums in an unusual way.
9077 Ordinary enums were emitted as unions. The first element of each
9078 structure in the union was named "RUST$ENUM$DISR". This element
9079 held the discriminant.
9081 These versions of Rust also implemented the "non-zero"
9082 optimization. When the enum had two values, and one is empty and
9083 the other holds a pointer that cannot be zero, the pointer is used
9084 as the discriminant, with a zero value meaning the empty variant.
9085 Here, the union's first member is of the form
9086 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9087 where the fieldnos are the indices of the fields that should be
9088 traversed in order to find the field (which may be several fields deep)
9089 and the variantname is the name of the variant of the case when the
9092 This function recognizes whether TYPE is of one of these forms,
9093 and, if so, smashes it to be a variant type. */
9096 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9098 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9100 /* We don't need to deal with empty enums. */
9101 if (TYPE_NFIELDS (type
) == 0)
9104 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9105 if (TYPE_NFIELDS (type
) == 1
9106 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9108 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9110 /* Decode the field name to find the offset of the
9112 ULONGEST bit_offset
= 0;
9113 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9114 while (name
[0] >= '0' && name
[0] <= '9')
9117 unsigned long index
= strtoul (name
, &tail
, 10);
9120 || index
>= TYPE_NFIELDS (field_type
)
9121 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9122 != FIELD_LOC_KIND_BITPOS
))
9124 complaint (_("Could not parse Rust enum encoding string \"%s\""
9126 TYPE_FIELD_NAME (type
, 0),
9127 objfile_name (objfile
));
9132 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9133 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9136 /* Make a union to hold the variants. */
9137 struct type
*union_type
= alloc_type (objfile
);
9138 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9139 TYPE_NFIELDS (union_type
) = 3;
9140 TYPE_FIELDS (union_type
)
9141 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9142 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9143 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9145 /* Put the discriminant must at index 0. */
9146 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9147 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9148 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9149 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9151 /* The order of fields doesn't really matter, so put the real
9152 field at index 1 and the data-less field at index 2. */
9153 struct discriminant_info
*disc
9154 = alloc_discriminant_info (union_type
, 0, 1);
9155 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9156 TYPE_FIELD_NAME (union_type
, 1)
9157 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9158 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9159 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9160 TYPE_FIELD_NAME (union_type
, 1));
9162 const char *dataless_name
9163 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9165 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9167 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9168 /* NAME points into the original discriminant name, which
9169 already has the correct lifetime. */
9170 TYPE_FIELD_NAME (union_type
, 2) = name
;
9171 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9172 disc
->discriminants
[2] = 0;
9174 /* Smash this type to be a structure type. We have to do this
9175 because the type has already been recorded. */
9176 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9177 TYPE_NFIELDS (type
) = 1;
9179 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9181 /* Install the variant part. */
9182 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9183 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9184 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9186 /* A union with a single anonymous field is probably an old-style
9188 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9190 /* Smash this type to be a structure type. We have to do this
9191 because the type has already been recorded. */
9192 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9194 /* Make a union to hold the variants. */
9195 struct type
*union_type
= alloc_type (objfile
);
9196 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9197 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9198 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9199 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9200 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9202 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9203 const char *variant_name
9204 = rust_last_path_segment (TYPE_NAME (field_type
));
9205 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9206 TYPE_NAME (field_type
)
9207 = rust_fully_qualify (&objfile
->objfile_obstack
,
9208 TYPE_NAME (type
), variant_name
);
9210 /* Install the union in the outer struct type. */
9211 TYPE_NFIELDS (type
) = 1;
9213 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9214 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9215 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9216 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9218 alloc_discriminant_info (union_type
, -1, 0);
9222 struct type
*disr_type
= nullptr;
9223 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9225 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9227 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9229 /* All fields of a true enum will be structs. */
9232 else if (TYPE_NFIELDS (disr_type
) == 0)
9234 /* Could be data-less variant, so keep going. */
9235 disr_type
= nullptr;
9237 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9238 "RUST$ENUM$DISR") != 0)
9240 /* Not a Rust enum. */
9250 /* If we got here without a discriminant, then it's probably
9252 if (disr_type
== nullptr)
9255 /* Smash this type to be a structure type. We have to do this
9256 because the type has already been recorded. */
9257 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9259 /* Make a union to hold the variants. */
9260 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9261 struct type
*union_type
= alloc_type (objfile
);
9262 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9263 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9264 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9265 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9266 TYPE_FIELDS (union_type
)
9267 = (struct field
*) TYPE_ZALLOC (union_type
,
9268 (TYPE_NFIELDS (union_type
)
9269 * sizeof (struct field
)));
9271 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9272 TYPE_NFIELDS (type
) * sizeof (struct field
));
9274 /* Install the discriminant at index 0 in the union. */
9275 TYPE_FIELD (union_type
, 0) = *disr_field
;
9276 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9277 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9279 /* Install the union in the outer struct type. */
9280 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9281 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9282 TYPE_NFIELDS (type
) = 1;
9284 /* Set the size and offset of the union type. */
9285 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9287 /* We need a way to find the correct discriminant given a
9288 variant name. For convenience we build a map here. */
9289 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9290 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9291 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9293 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9296 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9297 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9301 int n_fields
= TYPE_NFIELDS (union_type
);
9302 struct discriminant_info
*disc
9303 = alloc_discriminant_info (union_type
, 0, -1);
9304 /* Skip the discriminant here. */
9305 for (int i
= 1; i
< n_fields
; ++i
)
9307 /* Find the final word in the name of this variant's type.
9308 That name can be used to look up the correct
9310 const char *variant_name
9311 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9314 auto iter
= discriminant_map
.find (variant_name
);
9315 if (iter
!= discriminant_map
.end ())
9316 disc
->discriminants
[i
] = iter
->second
;
9318 /* Remove the discriminant field, if it exists. */
9319 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9320 if (TYPE_NFIELDS (sub_type
) > 0)
9322 --TYPE_NFIELDS (sub_type
);
9323 ++TYPE_FIELDS (sub_type
);
9325 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9326 TYPE_NAME (sub_type
)
9327 = rust_fully_qualify (&objfile
->objfile_obstack
,
9328 TYPE_NAME (type
), variant_name
);
9333 /* Rewrite some Rust unions to be structures with variants parts. */
9336 rust_union_quirks (struct dwarf2_cu
*cu
)
9338 gdb_assert (cu
->language
== language_rust
);
9339 for (type
*type_
: cu
->rust_unions
)
9340 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9341 /* We don't need this any more. */
9342 cu
->rust_unions
.clear ();
9345 /* Return the symtab for PER_CU. This works properly regardless of
9346 whether we're using the index or psymtabs. */
9348 static struct compunit_symtab
*
9349 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9351 return (per_cu
->dwarf2_per_objfile
->using_index
9352 ? per_cu
->v
.quick
->compunit_symtab
9353 : per_cu
->v
.psymtab
->compunit_symtab
);
9356 /* A helper function for computing the list of all symbol tables
9357 included by PER_CU. */
9360 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9361 htab_t all_children
, htab_t all_type_symtabs
,
9362 struct dwarf2_per_cu_data
*per_cu
,
9363 struct compunit_symtab
*immediate_parent
)
9366 struct compunit_symtab
*cust
;
9368 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9371 /* This inclusion and its children have been processed. */
9376 /* Only add a CU if it has a symbol table. */
9377 cust
= get_compunit_symtab (per_cu
);
9380 /* If this is a type unit only add its symbol table if we haven't
9381 seen it yet (type unit per_cu's can share symtabs). */
9382 if (per_cu
->is_debug_types
)
9384 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9388 result
->push_back (cust
);
9389 if (cust
->user
== NULL
)
9390 cust
->user
= immediate_parent
;
9395 result
->push_back (cust
);
9396 if (cust
->user
== NULL
)
9397 cust
->user
= immediate_parent
;
9401 if (!per_cu
->imported_symtabs_empty ())
9402 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9404 recursively_compute_inclusions (result
, all_children
,
9405 all_type_symtabs
, ptr
, cust
);
9409 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9413 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9415 gdb_assert (! per_cu
->is_debug_types
);
9417 if (!per_cu
->imported_symtabs_empty ())
9420 std::vector
<compunit_symtab
*> result_symtabs
;
9421 htab_t all_children
, all_type_symtabs
;
9422 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9424 /* If we don't have a symtab, we can just skip this case. */
9428 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9429 NULL
, xcalloc
, xfree
);
9430 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9431 NULL
, xcalloc
, xfree
);
9433 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9435 recursively_compute_inclusions (&result_symtabs
, all_children
,
9436 all_type_symtabs
, ptr
, cust
);
9439 /* Now we have a transitive closure of all the included symtabs. */
9440 len
= result_symtabs
.size ();
9442 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9443 struct compunit_symtab
*, len
+ 1);
9444 memcpy (cust
->includes
, result_symtabs
.data (),
9445 len
* sizeof (compunit_symtab
*));
9446 cust
->includes
[len
] = NULL
;
9448 htab_delete (all_children
);
9449 htab_delete (all_type_symtabs
);
9453 /* Compute the 'includes' field for the symtabs of all the CUs we just
9457 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9459 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9461 if (! iter
->is_debug_types
)
9462 compute_compunit_symtab_includes (iter
);
9465 dwarf2_per_objfile
->just_read_cus
.clear ();
9468 /* Generate full symbol information for PER_CU, whose DIEs have
9469 already been loaded into memory. */
9472 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9473 enum language pretend_language
)
9475 struct dwarf2_cu
*cu
= per_cu
->cu
;
9476 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9478 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9479 CORE_ADDR lowpc
, highpc
;
9480 struct compunit_symtab
*cust
;
9482 struct block
*static_block
;
9485 baseaddr
= objfile
->text_section_offset ();
9487 /* Clear the list here in case something was left over. */
9488 cu
->method_list
.clear ();
9490 cu
->language
= pretend_language
;
9491 cu
->language_defn
= language_def (cu
->language
);
9493 /* Do line number decoding in read_file_scope () */
9494 process_die (cu
->dies
, cu
);
9496 /* For now fudge the Go package. */
9497 if (cu
->language
== language_go
)
9498 fixup_go_packaging (cu
);
9500 /* Now that we have processed all the DIEs in the CU, all the types
9501 should be complete, and it should now be safe to compute all of the
9503 compute_delayed_physnames (cu
);
9505 if (cu
->language
== language_rust
)
9506 rust_union_quirks (cu
);
9508 /* Some compilers don't define a DW_AT_high_pc attribute for the
9509 compilation unit. If the DW_AT_high_pc is missing, synthesize
9510 it, by scanning the DIE's below the compilation unit. */
9511 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9513 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9514 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9516 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9517 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9518 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9519 addrmap to help ensure it has an accurate map of pc values belonging to
9521 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9523 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9524 SECT_OFF_TEXT (objfile
),
9529 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9531 /* Set symtab language to language from DW_AT_language. If the
9532 compilation is from a C file generated by language preprocessors, do
9533 not set the language if it was already deduced by start_subfile. */
9534 if (!(cu
->language
== language_c
9535 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9536 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9538 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9539 produce DW_AT_location with location lists but it can be possibly
9540 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9541 there were bugs in prologue debug info, fixed later in GCC-4.5
9542 by "unwind info for epilogues" patch (which is not directly related).
9544 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9545 needed, it would be wrong due to missing DW_AT_producer there.
9547 Still one can confuse GDB by using non-standard GCC compilation
9548 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9550 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9551 cust
->locations_valid
= 1;
9553 if (gcc_4_minor
>= 5)
9554 cust
->epilogue_unwind_valid
= 1;
9556 cust
->call_site_htab
= cu
->call_site_htab
;
9559 if (dwarf2_per_objfile
->using_index
)
9560 per_cu
->v
.quick
->compunit_symtab
= cust
;
9563 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9564 pst
->compunit_symtab
= cust
;
9568 /* Push it for inclusion processing later. */
9569 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9571 /* Not needed any more. */
9572 cu
->reset_builder ();
9575 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9576 already been loaded into memory. */
9579 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9580 enum language pretend_language
)
9582 struct dwarf2_cu
*cu
= per_cu
->cu
;
9583 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9585 struct compunit_symtab
*cust
;
9586 struct signatured_type
*sig_type
;
9588 gdb_assert (per_cu
->is_debug_types
);
9589 sig_type
= (struct signatured_type
*) per_cu
;
9591 /* Clear the list here in case something was left over. */
9592 cu
->method_list
.clear ();
9594 cu
->language
= pretend_language
;
9595 cu
->language_defn
= language_def (cu
->language
);
9597 /* The symbol tables are set up in read_type_unit_scope. */
9598 process_die (cu
->dies
, cu
);
9600 /* For now fudge the Go package. */
9601 if (cu
->language
== language_go
)
9602 fixup_go_packaging (cu
);
9604 /* Now that we have processed all the DIEs in the CU, all the types
9605 should be complete, and it should now be safe to compute all of the
9607 compute_delayed_physnames (cu
);
9609 if (cu
->language
== language_rust
)
9610 rust_union_quirks (cu
);
9612 /* TUs share symbol tables.
9613 If this is the first TU to use this symtab, complete the construction
9614 of it with end_expandable_symtab. Otherwise, complete the addition of
9615 this TU's symbols to the existing symtab. */
9616 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9618 buildsym_compunit
*builder
= cu
->get_builder ();
9619 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9620 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9624 /* Set symtab language to language from DW_AT_language. If the
9625 compilation is from a C file generated by language preprocessors,
9626 do not set the language if it was already deduced by
9628 if (!(cu
->language
== language_c
9629 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9630 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9635 cu
->get_builder ()->augment_type_symtab ();
9636 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9639 if (dwarf2_per_objfile
->using_index
)
9640 per_cu
->v
.quick
->compunit_symtab
= cust
;
9643 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9644 pst
->compunit_symtab
= cust
;
9648 /* Not needed any more. */
9649 cu
->reset_builder ();
9652 /* Process an imported unit DIE. */
9655 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9657 struct attribute
*attr
;
9659 /* For now we don't handle imported units in type units. */
9660 if (cu
->per_cu
->is_debug_types
)
9662 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9663 " supported in type units [in module %s]"),
9664 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9667 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9670 sect_offset sect_off
= attr
->get_ref_die_offset ();
9671 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9672 dwarf2_per_cu_data
*per_cu
9673 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9674 cu
->per_cu
->dwarf2_per_objfile
);
9676 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9677 into another compilation unit, at root level. Regard this as a hint,
9679 if (die
->parent
&& die
->parent
->parent
== NULL
9680 && per_cu
->unit_type
== DW_UT_compile
9681 && per_cu
->lang
== language_cplus
)
9684 /* If necessary, add it to the queue and load its DIEs. */
9685 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9686 load_full_comp_unit (per_cu
, false, cu
->language
);
9688 cu
->per_cu
->imported_symtabs_push (per_cu
);
9692 /* RAII object that represents a process_die scope: i.e.,
9693 starts/finishes processing a DIE. */
9694 class process_die_scope
9697 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9698 : m_die (die
), m_cu (cu
)
9700 /* We should only be processing DIEs not already in process. */
9701 gdb_assert (!m_die
->in_process
);
9702 m_die
->in_process
= true;
9705 ~process_die_scope ()
9707 m_die
->in_process
= false;
9709 /* If we're done processing the DIE for the CU that owns the line
9710 header, we don't need the line header anymore. */
9711 if (m_cu
->line_header_die_owner
== m_die
)
9713 delete m_cu
->line_header
;
9714 m_cu
->line_header
= NULL
;
9715 m_cu
->line_header_die_owner
= NULL
;
9724 /* Process a die and its children. */
9727 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9729 process_die_scope
scope (die
, cu
);
9733 case DW_TAG_padding
:
9735 case DW_TAG_compile_unit
:
9736 case DW_TAG_partial_unit
:
9737 read_file_scope (die
, cu
);
9739 case DW_TAG_type_unit
:
9740 read_type_unit_scope (die
, cu
);
9742 case DW_TAG_subprogram
:
9743 /* Nested subprograms in Fortran get a prefix. */
9744 if (cu
->language
== language_fortran
9745 && die
->parent
!= NULL
9746 && die
->parent
->tag
== DW_TAG_subprogram
)
9747 cu
->processing_has_namespace_info
= true;
9749 case DW_TAG_inlined_subroutine
:
9750 read_func_scope (die
, cu
);
9752 case DW_TAG_lexical_block
:
9753 case DW_TAG_try_block
:
9754 case DW_TAG_catch_block
:
9755 read_lexical_block_scope (die
, cu
);
9757 case DW_TAG_call_site
:
9758 case DW_TAG_GNU_call_site
:
9759 read_call_site_scope (die
, cu
);
9761 case DW_TAG_class_type
:
9762 case DW_TAG_interface_type
:
9763 case DW_TAG_structure_type
:
9764 case DW_TAG_union_type
:
9765 process_structure_scope (die
, cu
);
9767 case DW_TAG_enumeration_type
:
9768 process_enumeration_scope (die
, cu
);
9771 /* These dies have a type, but processing them does not create
9772 a symbol or recurse to process the children. Therefore we can
9773 read them on-demand through read_type_die. */
9774 case DW_TAG_subroutine_type
:
9775 case DW_TAG_set_type
:
9776 case DW_TAG_array_type
:
9777 case DW_TAG_pointer_type
:
9778 case DW_TAG_ptr_to_member_type
:
9779 case DW_TAG_reference_type
:
9780 case DW_TAG_rvalue_reference_type
:
9781 case DW_TAG_string_type
:
9784 case DW_TAG_base_type
:
9785 case DW_TAG_subrange_type
:
9786 case DW_TAG_typedef
:
9787 /* Add a typedef symbol for the type definition, if it has a
9789 new_symbol (die
, read_type_die (die
, cu
), cu
);
9791 case DW_TAG_common_block
:
9792 read_common_block (die
, cu
);
9794 case DW_TAG_common_inclusion
:
9796 case DW_TAG_namespace
:
9797 cu
->processing_has_namespace_info
= true;
9798 read_namespace (die
, cu
);
9801 cu
->processing_has_namespace_info
= true;
9802 read_module (die
, cu
);
9804 case DW_TAG_imported_declaration
:
9805 cu
->processing_has_namespace_info
= true;
9806 if (read_namespace_alias (die
, cu
))
9808 /* The declaration is not a global namespace alias. */
9810 case DW_TAG_imported_module
:
9811 cu
->processing_has_namespace_info
= true;
9812 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9813 || cu
->language
!= language_fortran
))
9814 complaint (_("Tag '%s' has unexpected children"),
9815 dwarf_tag_name (die
->tag
));
9816 read_import_statement (die
, cu
);
9819 case DW_TAG_imported_unit
:
9820 process_imported_unit_die (die
, cu
);
9823 case DW_TAG_variable
:
9824 read_variable (die
, cu
);
9828 new_symbol (die
, NULL
, cu
);
9833 /* DWARF name computation. */
9835 /* A helper function for dwarf2_compute_name which determines whether DIE
9836 needs to have the name of the scope prepended to the name listed in the
9840 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9842 struct attribute
*attr
;
9846 case DW_TAG_namespace
:
9847 case DW_TAG_typedef
:
9848 case DW_TAG_class_type
:
9849 case DW_TAG_interface_type
:
9850 case DW_TAG_structure_type
:
9851 case DW_TAG_union_type
:
9852 case DW_TAG_enumeration_type
:
9853 case DW_TAG_enumerator
:
9854 case DW_TAG_subprogram
:
9855 case DW_TAG_inlined_subroutine
:
9857 case DW_TAG_imported_declaration
:
9860 case DW_TAG_variable
:
9861 case DW_TAG_constant
:
9862 /* We only need to prefix "globally" visible variables. These include
9863 any variable marked with DW_AT_external or any variable that
9864 lives in a namespace. [Variables in anonymous namespaces
9865 require prefixing, but they are not DW_AT_external.] */
9867 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9869 struct dwarf2_cu
*spec_cu
= cu
;
9871 return die_needs_namespace (die_specification (die
, &spec_cu
),
9875 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9876 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9877 && die
->parent
->tag
!= DW_TAG_module
)
9879 /* A variable in a lexical block of some kind does not need a
9880 namespace, even though in C++ such variables may be external
9881 and have a mangled name. */
9882 if (die
->parent
->tag
== DW_TAG_lexical_block
9883 || die
->parent
->tag
== DW_TAG_try_block
9884 || die
->parent
->tag
== DW_TAG_catch_block
9885 || die
->parent
->tag
== DW_TAG_subprogram
)
9894 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9895 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9896 defined for the given DIE. */
9898 static struct attribute
*
9899 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9901 struct attribute
*attr
;
9903 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9905 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9910 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9911 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9912 defined for the given DIE. */
9915 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9917 const char *linkage_name
;
9919 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9920 if (linkage_name
== NULL
)
9921 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9923 return linkage_name
;
9926 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9927 compute the physname for the object, which include a method's:
9928 - formal parameters (C++),
9929 - receiver type (Go),
9931 The term "physname" is a bit confusing.
9932 For C++, for example, it is the demangled name.
9933 For Go, for example, it's the mangled name.
9935 For Ada, return the DIE's linkage name rather than the fully qualified
9936 name. PHYSNAME is ignored..
9938 The result is allocated on the objfile_obstack and canonicalized. */
9941 dwarf2_compute_name (const char *name
,
9942 struct die_info
*die
, struct dwarf2_cu
*cu
,
9945 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9948 name
= dwarf2_name (die
, cu
);
9950 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9951 but otherwise compute it by typename_concat inside GDB.
9952 FIXME: Actually this is not really true, or at least not always true.
9953 It's all very confusing. compute_and_set_names doesn't try to demangle
9954 Fortran names because there is no mangling standard. So new_symbol
9955 will set the demangled name to the result of dwarf2_full_name, and it is
9956 the demangled name that GDB uses if it exists. */
9957 if (cu
->language
== language_ada
9958 || (cu
->language
== language_fortran
&& physname
))
9960 /* For Ada unit, we prefer the linkage name over the name, as
9961 the former contains the exported name, which the user expects
9962 to be able to reference. Ideally, we want the user to be able
9963 to reference this entity using either natural or linkage name,
9964 but we haven't started looking at this enhancement yet. */
9965 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9967 if (linkage_name
!= NULL
)
9968 return linkage_name
;
9971 /* These are the only languages we know how to qualify names in. */
9973 && (cu
->language
== language_cplus
9974 || cu
->language
== language_fortran
|| cu
->language
== language_d
9975 || cu
->language
== language_rust
))
9977 if (die_needs_namespace (die
, cu
))
9980 const char *canonical_name
= NULL
;
9984 prefix
= determine_prefix (die
, cu
);
9985 if (*prefix
!= '\0')
9987 gdb::unique_xmalloc_ptr
<char> prefixed_name
9988 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9990 buf
.puts (prefixed_name
.get ());
9995 /* Template parameters may be specified in the DIE's DW_AT_name, or
9996 as children with DW_TAG_template_type_param or
9997 DW_TAG_value_type_param. If the latter, add them to the name
9998 here. If the name already has template parameters, then
9999 skip this step; some versions of GCC emit both, and
10000 it is more efficient to use the pre-computed name.
10002 Something to keep in mind about this process: it is very
10003 unlikely, or in some cases downright impossible, to produce
10004 something that will match the mangled name of a function.
10005 If the definition of the function has the same debug info,
10006 we should be able to match up with it anyway. But fallbacks
10007 using the minimal symbol, for instance to find a method
10008 implemented in a stripped copy of libstdc++, will not work.
10009 If we do not have debug info for the definition, we will have to
10010 match them up some other way.
10012 When we do name matching there is a related problem with function
10013 templates; two instantiated function templates are allowed to
10014 differ only by their return types, which we do not add here. */
10016 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10018 struct attribute
*attr
;
10019 struct die_info
*child
;
10022 die
->building_fullname
= 1;
10024 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10028 const gdb_byte
*bytes
;
10029 struct dwarf2_locexpr_baton
*baton
;
10032 if (child
->tag
!= DW_TAG_template_type_param
10033 && child
->tag
!= DW_TAG_template_value_param
)
10044 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10047 complaint (_("template parameter missing DW_AT_type"));
10048 buf
.puts ("UNKNOWN_TYPE");
10051 type
= die_type (child
, cu
);
10053 if (child
->tag
== DW_TAG_template_type_param
)
10055 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10056 &type_print_raw_options
);
10060 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10063 complaint (_("template parameter missing "
10064 "DW_AT_const_value"));
10065 buf
.puts ("UNKNOWN_VALUE");
10069 dwarf2_const_value_attr (attr
, type
, name
,
10070 &cu
->comp_unit_obstack
, cu
,
10071 &value
, &bytes
, &baton
);
10073 if (TYPE_NOSIGN (type
))
10074 /* GDB prints characters as NUMBER 'CHAR'. If that's
10075 changed, this can use value_print instead. */
10076 c_printchar (value
, type
, &buf
);
10079 struct value_print_options opts
;
10082 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10086 else if (bytes
!= NULL
)
10088 v
= allocate_value (type
);
10089 memcpy (value_contents_writeable (v
), bytes
,
10090 TYPE_LENGTH (type
));
10093 v
= value_from_longest (type
, value
);
10095 /* Specify decimal so that we do not depend on
10097 get_formatted_print_options (&opts
, 'd');
10099 value_print (v
, &buf
, &opts
);
10104 die
->building_fullname
= 0;
10108 /* Close the argument list, with a space if necessary
10109 (nested templates). */
10110 if (!buf
.empty () && buf
.string ().back () == '>')
10117 /* For C++ methods, append formal parameter type
10118 information, if PHYSNAME. */
10120 if (physname
&& die
->tag
== DW_TAG_subprogram
10121 && cu
->language
== language_cplus
)
10123 struct type
*type
= read_type_die (die
, cu
);
10125 c_type_print_args (type
, &buf
, 1, cu
->language
,
10126 &type_print_raw_options
);
10128 if (cu
->language
== language_cplus
)
10130 /* Assume that an artificial first parameter is
10131 "this", but do not crash if it is not. RealView
10132 marks unnamed (and thus unused) parameters as
10133 artificial; there is no way to differentiate
10135 if (TYPE_NFIELDS (type
) > 0
10136 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10137 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10138 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10140 buf
.puts (" const");
10144 const std::string
&intermediate_name
= buf
.string ();
10146 if (cu
->language
== language_cplus
)
10148 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10151 /* If we only computed INTERMEDIATE_NAME, or if
10152 INTERMEDIATE_NAME is already canonical, then we need to
10154 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10155 name
= objfile
->intern (intermediate_name
);
10157 name
= canonical_name
;
10164 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10165 If scope qualifiers are appropriate they will be added. The result
10166 will be allocated on the storage_obstack, or NULL if the DIE does
10167 not have a name. NAME may either be from a previous call to
10168 dwarf2_name or NULL.
10170 The output string will be canonicalized (if C++). */
10172 static const char *
10173 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10175 return dwarf2_compute_name (name
, die
, cu
, 0);
10178 /* Construct a physname for the given DIE in CU. NAME may either be
10179 from a previous call to dwarf2_name or NULL. The result will be
10180 allocated on the objfile_objstack or NULL if the DIE does not have a
10183 The output string will be canonicalized (if C++). */
10185 static const char *
10186 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10188 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10189 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10192 /* In this case dwarf2_compute_name is just a shortcut not building anything
10194 if (!die_needs_namespace (die
, cu
))
10195 return dwarf2_compute_name (name
, die
, cu
, 1);
10197 mangled
= dw2_linkage_name (die
, cu
);
10199 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10200 See https://github.com/rust-lang/rust/issues/32925. */
10201 if (cu
->language
== language_rust
&& mangled
!= NULL
10202 && strchr (mangled
, '{') != NULL
)
10205 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10207 gdb::unique_xmalloc_ptr
<char> demangled
;
10208 if (mangled
!= NULL
)
10211 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10213 /* Do nothing (do not demangle the symbol name). */
10215 else if (cu
->language
== language_go
)
10217 /* This is a lie, but we already lie to the caller new_symbol.
10218 new_symbol assumes we return the mangled name.
10219 This just undoes that lie until things are cleaned up. */
10223 /* Use DMGL_RET_DROP for C++ template functions to suppress
10224 their return type. It is easier for GDB users to search
10225 for such functions as `name(params)' than `long name(params)'.
10226 In such case the minimal symbol names do not match the full
10227 symbol names but for template functions there is never a need
10228 to look up their definition from their declaration so
10229 the only disadvantage remains the minimal symbol variant
10230 `long name(params)' does not have the proper inferior type. */
10231 demangled
.reset (gdb_demangle (mangled
,
10232 (DMGL_PARAMS
| DMGL_ANSI
10233 | DMGL_RET_DROP
)));
10236 canon
= demangled
.get ();
10244 if (canon
== NULL
|| check_physname
)
10246 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10248 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10250 /* It may not mean a bug in GDB. The compiler could also
10251 compute DW_AT_linkage_name incorrectly. But in such case
10252 GDB would need to be bug-to-bug compatible. */
10254 complaint (_("Computed physname <%s> does not match demangled <%s> "
10255 "(from linkage <%s>) - DIE at %s [in module %s]"),
10256 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10257 objfile_name (objfile
));
10259 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10260 is available here - over computed PHYSNAME. It is safer
10261 against both buggy GDB and buggy compilers. */
10275 retval
= objfile
->intern (retval
);
10280 /* Inspect DIE in CU for a namespace alias. If one exists, record
10281 a new symbol for it.
10283 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10286 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10288 struct attribute
*attr
;
10290 /* If the die does not have a name, this is not a namespace
10292 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10296 struct die_info
*d
= die
;
10297 struct dwarf2_cu
*imported_cu
= cu
;
10299 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10300 keep inspecting DIEs until we hit the underlying import. */
10301 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10302 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10304 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10308 d
= follow_die_ref (d
, attr
, &imported_cu
);
10309 if (d
->tag
!= DW_TAG_imported_declaration
)
10313 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10315 complaint (_("DIE at %s has too many recursively imported "
10316 "declarations"), sect_offset_str (d
->sect_off
));
10323 sect_offset sect_off
= attr
->get_ref_die_offset ();
10325 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10326 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10328 /* This declaration is a global namespace alias. Add
10329 a symbol for it whose type is the aliased namespace. */
10330 new_symbol (die
, type
, cu
);
10339 /* Return the using directives repository (global or local?) to use in the
10340 current context for CU.
10342 For Ada, imported declarations can materialize renamings, which *may* be
10343 global. However it is impossible (for now?) in DWARF to distinguish
10344 "external" imported declarations and "static" ones. As all imported
10345 declarations seem to be static in all other languages, make them all CU-wide
10346 global only in Ada. */
10348 static struct using_direct
**
10349 using_directives (struct dwarf2_cu
*cu
)
10351 if (cu
->language
== language_ada
10352 && cu
->get_builder ()->outermost_context_p ())
10353 return cu
->get_builder ()->get_global_using_directives ();
10355 return cu
->get_builder ()->get_local_using_directives ();
10358 /* Read the import statement specified by the given die and record it. */
10361 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10363 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10364 struct attribute
*import_attr
;
10365 struct die_info
*imported_die
, *child_die
;
10366 struct dwarf2_cu
*imported_cu
;
10367 const char *imported_name
;
10368 const char *imported_name_prefix
;
10369 const char *canonical_name
;
10370 const char *import_alias
;
10371 const char *imported_declaration
= NULL
;
10372 const char *import_prefix
;
10373 std::vector
<const char *> excludes
;
10375 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10376 if (import_attr
== NULL
)
10378 complaint (_("Tag '%s' has no DW_AT_import"),
10379 dwarf_tag_name (die
->tag
));
10384 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10385 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10386 if (imported_name
== NULL
)
10388 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10390 The import in the following code:
10404 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10405 <52> DW_AT_decl_file : 1
10406 <53> DW_AT_decl_line : 6
10407 <54> DW_AT_import : <0x75>
10408 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10409 <59> DW_AT_name : B
10410 <5b> DW_AT_decl_file : 1
10411 <5c> DW_AT_decl_line : 2
10412 <5d> DW_AT_type : <0x6e>
10414 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10415 <76> DW_AT_byte_size : 4
10416 <77> DW_AT_encoding : 5 (signed)
10418 imports the wrong die ( 0x75 instead of 0x58 ).
10419 This case will be ignored until the gcc bug is fixed. */
10423 /* Figure out the local name after import. */
10424 import_alias
= dwarf2_name (die
, cu
);
10426 /* Figure out where the statement is being imported to. */
10427 import_prefix
= determine_prefix (die
, cu
);
10429 /* Figure out what the scope of the imported die is and prepend it
10430 to the name of the imported die. */
10431 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10433 if (imported_die
->tag
!= DW_TAG_namespace
10434 && imported_die
->tag
!= DW_TAG_module
)
10436 imported_declaration
= imported_name
;
10437 canonical_name
= imported_name_prefix
;
10439 else if (strlen (imported_name_prefix
) > 0)
10440 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10441 imported_name_prefix
,
10442 (cu
->language
== language_d
? "." : "::"),
10443 imported_name
, (char *) NULL
);
10445 canonical_name
= imported_name
;
10447 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10448 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10449 child_die
= child_die
->sibling
)
10451 /* DWARF-4: A Fortran use statement with a “rename list” may be
10452 represented by an imported module entry with an import attribute
10453 referring to the module and owned entries corresponding to those
10454 entities that are renamed as part of being imported. */
10456 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10458 complaint (_("child DW_TAG_imported_declaration expected "
10459 "- DIE at %s [in module %s]"),
10460 sect_offset_str (child_die
->sect_off
),
10461 objfile_name (objfile
));
10465 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10466 if (import_attr
== NULL
)
10468 complaint (_("Tag '%s' has no DW_AT_import"),
10469 dwarf_tag_name (child_die
->tag
));
10474 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10476 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10477 if (imported_name
== NULL
)
10479 complaint (_("child DW_TAG_imported_declaration has unknown "
10480 "imported name - DIE at %s [in module %s]"),
10481 sect_offset_str (child_die
->sect_off
),
10482 objfile_name (objfile
));
10486 excludes
.push_back (imported_name
);
10488 process_die (child_die
, cu
);
10491 add_using_directive (using_directives (cu
),
10495 imported_declaration
,
10498 &objfile
->objfile_obstack
);
10501 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10502 types, but gives them a size of zero. Starting with version 14,
10503 ICC is compatible with GCC. */
10506 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10508 if (!cu
->checked_producer
)
10509 check_producer (cu
);
10511 return cu
->producer_is_icc_lt_14
;
10514 /* ICC generates a DW_AT_type for C void functions. This was observed on
10515 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10516 which says that void functions should not have a DW_AT_type. */
10519 producer_is_icc (struct dwarf2_cu
*cu
)
10521 if (!cu
->checked_producer
)
10522 check_producer (cu
);
10524 return cu
->producer_is_icc
;
10527 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10528 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10529 this, it was first present in GCC release 4.3.0. */
10532 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10534 if (!cu
->checked_producer
)
10535 check_producer (cu
);
10537 return cu
->producer_is_gcc_lt_4_3
;
10540 static file_and_directory
10541 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10543 file_and_directory res
;
10545 /* Find the filename. Do not use dwarf2_name here, since the filename
10546 is not a source language identifier. */
10547 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10548 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10550 if (res
.comp_dir
== NULL
10551 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10552 && IS_ABSOLUTE_PATH (res
.name
))
10554 res
.comp_dir_storage
= ldirname (res
.name
);
10555 if (!res
.comp_dir_storage
.empty ())
10556 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10558 if (res
.comp_dir
!= NULL
)
10560 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10561 directory, get rid of it. */
10562 const char *cp
= strchr (res
.comp_dir
, ':');
10564 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10565 res
.comp_dir
= cp
+ 1;
10568 if (res
.name
== NULL
)
10569 res
.name
= "<unknown>";
10574 /* Handle DW_AT_stmt_list for a compilation unit.
10575 DIE is the DW_TAG_compile_unit die for CU.
10576 COMP_DIR is the compilation directory. LOWPC is passed to
10577 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10580 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10581 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10583 struct dwarf2_per_objfile
*dwarf2_per_objfile
10584 = cu
->per_cu
->dwarf2_per_objfile
;
10585 struct attribute
*attr
;
10586 struct line_header line_header_local
;
10587 hashval_t line_header_local_hash
;
10589 int decode_mapping
;
10591 gdb_assert (! cu
->per_cu
->is_debug_types
);
10593 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10597 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10599 /* The line header hash table is only created if needed (it exists to
10600 prevent redundant reading of the line table for partial_units).
10601 If we're given a partial_unit, we'll need it. If we're given a
10602 compile_unit, then use the line header hash table if it's already
10603 created, but don't create one just yet. */
10605 if (dwarf2_per_objfile
->line_header_hash
== NULL
10606 && die
->tag
== DW_TAG_partial_unit
)
10608 dwarf2_per_objfile
->line_header_hash
10609 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10610 line_header_eq_voidp
,
10611 free_line_header_voidp
,
10615 line_header_local
.sect_off
= line_offset
;
10616 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10617 line_header_local_hash
= line_header_hash (&line_header_local
);
10618 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10620 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10621 &line_header_local
,
10622 line_header_local_hash
, NO_INSERT
);
10624 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10625 is not present in *SLOT (since if there is something in *SLOT then
10626 it will be for a partial_unit). */
10627 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10629 gdb_assert (*slot
!= NULL
);
10630 cu
->line_header
= (struct line_header
*) *slot
;
10635 /* dwarf_decode_line_header does not yet provide sufficient information.
10636 We always have to call also dwarf_decode_lines for it. */
10637 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10641 cu
->line_header
= lh
.release ();
10642 cu
->line_header_die_owner
= die
;
10644 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10648 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10649 &line_header_local
,
10650 line_header_local_hash
, INSERT
);
10651 gdb_assert (slot
!= NULL
);
10653 if (slot
!= NULL
&& *slot
== NULL
)
10655 /* This newly decoded line number information unit will be owned
10656 by line_header_hash hash table. */
10657 *slot
= cu
->line_header
;
10658 cu
->line_header_die_owner
= NULL
;
10662 /* We cannot free any current entry in (*slot) as that struct line_header
10663 may be already used by multiple CUs. Create only temporary decoded
10664 line_header for this CU - it may happen at most once for each line
10665 number information unit. And if we're not using line_header_hash
10666 then this is what we want as well. */
10667 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10669 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10670 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10675 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10678 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10680 struct dwarf2_per_objfile
*dwarf2_per_objfile
10681 = cu
->per_cu
->dwarf2_per_objfile
;
10682 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10683 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10684 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10685 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10686 struct attribute
*attr
;
10687 struct die_info
*child_die
;
10688 CORE_ADDR baseaddr
;
10690 prepare_one_comp_unit (cu
, die
, cu
->language
);
10691 baseaddr
= objfile
->text_section_offset ();
10693 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10695 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10696 from finish_block. */
10697 if (lowpc
== ((CORE_ADDR
) -1))
10699 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10701 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10703 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10704 standardised yet. As a workaround for the language detection we fall
10705 back to the DW_AT_producer string. */
10706 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10707 cu
->language
= language_opencl
;
10709 /* Similar hack for Go. */
10710 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10711 set_cu_language (DW_LANG_Go
, cu
);
10713 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10715 /* Decode line number information if present. We do this before
10716 processing child DIEs, so that the line header table is available
10717 for DW_AT_decl_file. */
10718 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10720 /* Process all dies in compilation unit. */
10721 if (die
->child
!= NULL
)
10723 child_die
= die
->child
;
10724 while (child_die
&& child_die
->tag
)
10726 process_die (child_die
, cu
);
10727 child_die
= child_die
->sibling
;
10731 /* Decode macro information, if present. Dwarf 2 macro information
10732 refers to information in the line number info statement program
10733 header, so we can only read it if we've read the header
10735 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10737 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10738 if (attr
&& cu
->line_header
)
10740 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10741 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10743 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10747 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10748 if (attr
&& cu
->line_header
)
10750 unsigned int macro_offset
= DW_UNSND (attr
);
10752 dwarf_decode_macros (cu
, macro_offset
, 0);
10758 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10760 struct type_unit_group
*tu_group
;
10762 struct attribute
*attr
;
10764 struct signatured_type
*sig_type
;
10766 gdb_assert (per_cu
->is_debug_types
);
10767 sig_type
= (struct signatured_type
*) per_cu
;
10769 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10771 /* If we're using .gdb_index (includes -readnow) then
10772 per_cu->type_unit_group may not have been set up yet. */
10773 if (sig_type
->type_unit_group
== NULL
)
10774 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10775 tu_group
= sig_type
->type_unit_group
;
10777 /* If we've already processed this stmt_list there's no real need to
10778 do it again, we could fake it and just recreate the part we need
10779 (file name,index -> symtab mapping). If data shows this optimization
10780 is useful we can do it then. */
10781 first_time
= tu_group
->compunit_symtab
== NULL
;
10783 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10788 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10789 lh
= dwarf_decode_line_header (line_offset
, this);
10794 start_symtab ("", NULL
, 0);
10797 gdb_assert (tu_group
->symtabs
== NULL
);
10798 gdb_assert (m_builder
== nullptr);
10799 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10800 m_builder
.reset (new struct buildsym_compunit
10801 (COMPUNIT_OBJFILE (cust
), "",
10802 COMPUNIT_DIRNAME (cust
),
10803 compunit_language (cust
),
10809 line_header
= lh
.release ();
10810 line_header_die_owner
= die
;
10814 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10816 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10817 still initializing it, and our caller (a few levels up)
10818 process_full_type_unit still needs to know if this is the first
10822 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10823 struct symtab
*, line_header
->file_names_size ());
10825 auto &file_names
= line_header
->file_names ();
10826 for (i
= 0; i
< file_names
.size (); ++i
)
10828 file_entry
&fe
= file_names
[i
];
10829 dwarf2_start_subfile (this, fe
.name
,
10830 fe
.include_dir (line_header
));
10831 buildsym_compunit
*b
= get_builder ();
10832 if (b
->get_current_subfile ()->symtab
== NULL
)
10834 /* NOTE: start_subfile will recognize when it's been
10835 passed a file it has already seen. So we can't
10836 assume there's a simple mapping from
10837 cu->line_header->file_names to subfiles, plus
10838 cu->line_header->file_names may contain dups. */
10839 b
->get_current_subfile ()->symtab
10840 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10843 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10844 tu_group
->symtabs
[i
] = fe
.symtab
;
10849 gdb_assert (m_builder
== nullptr);
10850 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10851 m_builder
.reset (new struct buildsym_compunit
10852 (COMPUNIT_OBJFILE (cust
), "",
10853 COMPUNIT_DIRNAME (cust
),
10854 compunit_language (cust
),
10857 auto &file_names
= line_header
->file_names ();
10858 for (i
= 0; i
< file_names
.size (); ++i
)
10860 file_entry
&fe
= file_names
[i
];
10861 fe
.symtab
= tu_group
->symtabs
[i
];
10865 /* The main symtab is allocated last. Type units don't have DW_AT_name
10866 so they don't have a "real" (so to speak) symtab anyway.
10867 There is later code that will assign the main symtab to all symbols
10868 that don't have one. We need to handle the case of a symbol with a
10869 missing symtab (DW_AT_decl_file) anyway. */
10872 /* Process DW_TAG_type_unit.
10873 For TUs we want to skip the first top level sibling if it's not the
10874 actual type being defined by this TU. In this case the first top
10875 level sibling is there to provide context only. */
10878 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10880 struct die_info
*child_die
;
10882 prepare_one_comp_unit (cu
, die
, language_minimal
);
10884 /* Initialize (or reinitialize) the machinery for building symtabs.
10885 We do this before processing child DIEs, so that the line header table
10886 is available for DW_AT_decl_file. */
10887 cu
->setup_type_unit_groups (die
);
10889 if (die
->child
!= NULL
)
10891 child_die
= die
->child
;
10892 while (child_die
&& child_die
->tag
)
10894 process_die (child_die
, cu
);
10895 child_die
= child_die
->sibling
;
10902 http://gcc.gnu.org/wiki/DebugFission
10903 http://gcc.gnu.org/wiki/DebugFissionDWP
10905 To simplify handling of both DWO files ("object" files with the DWARF info)
10906 and DWP files (a file with the DWOs packaged up into one file), we treat
10907 DWP files as having a collection of virtual DWO files. */
10910 hash_dwo_file (const void *item
)
10912 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10915 hash
= htab_hash_string (dwo_file
->dwo_name
);
10916 if (dwo_file
->comp_dir
!= NULL
)
10917 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10922 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10924 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10925 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10927 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10929 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10930 return lhs
->comp_dir
== rhs
->comp_dir
;
10931 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10934 /* Allocate a hash table for DWO files. */
10937 allocate_dwo_file_hash_table ()
10939 auto delete_dwo_file
= [] (void *item
)
10941 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10946 return htab_up (htab_create_alloc (41,
10953 /* Lookup DWO file DWO_NAME. */
10956 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10957 const char *dwo_name
,
10958 const char *comp_dir
)
10960 struct dwo_file find_entry
;
10963 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10964 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10966 find_entry
.dwo_name
= dwo_name
;
10967 find_entry
.comp_dir
= comp_dir
;
10968 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10975 hash_dwo_unit (const void *item
)
10977 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10979 /* This drops the top 32 bits of the id, but is ok for a hash. */
10980 return dwo_unit
->signature
;
10984 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10986 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10987 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10989 /* The signature is assumed to be unique within the DWO file.
10990 So while object file CU dwo_id's always have the value zero,
10991 that's OK, assuming each object file DWO file has only one CU,
10992 and that's the rule for now. */
10993 return lhs
->signature
== rhs
->signature
;
10996 /* Allocate a hash table for DWO CUs,TUs.
10997 There is one of these tables for each of CUs,TUs for each DWO file. */
11000 allocate_dwo_unit_table ()
11002 /* Start out with a pretty small number.
11003 Generally DWO files contain only one CU and maybe some TUs. */
11004 return htab_up (htab_create_alloc (3,
11007 NULL
, xcalloc
, xfree
));
11010 /* die_reader_func for create_dwo_cu. */
11013 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11014 const gdb_byte
*info_ptr
,
11015 struct die_info
*comp_unit_die
,
11016 struct dwo_file
*dwo_file
,
11017 struct dwo_unit
*dwo_unit
)
11019 struct dwarf2_cu
*cu
= reader
->cu
;
11020 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11021 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11023 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11024 if (!signature
.has_value ())
11026 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11027 " its dwo_id [in module %s]"),
11028 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11032 dwo_unit
->dwo_file
= dwo_file
;
11033 dwo_unit
->signature
= *signature
;
11034 dwo_unit
->section
= section
;
11035 dwo_unit
->sect_off
= sect_off
;
11036 dwo_unit
->length
= cu
->per_cu
->length
;
11038 if (dwarf_read_debug
)
11039 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11040 sect_offset_str (sect_off
),
11041 hex_string (dwo_unit
->signature
));
11044 /* Create the dwo_units for the CUs in a DWO_FILE.
11045 Note: This function processes DWO files only, not DWP files. */
11048 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11049 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11050 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11053 const gdb_byte
*info_ptr
, *end_ptr
;
11055 section
.read (objfile
);
11056 info_ptr
= section
.buffer
;
11058 if (info_ptr
== NULL
)
11061 if (dwarf_read_debug
)
11063 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11064 section
.get_name (),
11065 section
.get_file_name ());
11068 end_ptr
= info_ptr
+ section
.size
;
11069 while (info_ptr
< end_ptr
)
11071 struct dwarf2_per_cu_data per_cu
;
11072 struct dwo_unit read_unit
{};
11073 struct dwo_unit
*dwo_unit
;
11075 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11077 memset (&per_cu
, 0, sizeof (per_cu
));
11078 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11079 per_cu
.is_debug_types
= 0;
11080 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11081 per_cu
.section
= §ion
;
11083 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11084 if (!reader
.dummy_p
)
11085 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11086 &dwo_file
, &read_unit
);
11087 info_ptr
+= per_cu
.length
;
11089 // If the unit could not be parsed, skip it.
11090 if (read_unit
.dwo_file
== NULL
)
11093 if (cus_htab
== NULL
)
11094 cus_htab
= allocate_dwo_unit_table ();
11096 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11097 *dwo_unit
= read_unit
;
11098 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11099 gdb_assert (slot
!= NULL
);
11102 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11103 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11105 complaint (_("debug cu entry at offset %s is duplicate to"
11106 " the entry at offset %s, signature %s"),
11107 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11108 hex_string (dwo_unit
->signature
));
11110 *slot
= (void *)dwo_unit
;
11114 /* DWP file .debug_{cu,tu}_index section format:
11115 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11119 Both index sections have the same format, and serve to map a 64-bit
11120 signature to a set of section numbers. Each section begins with a header,
11121 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11122 indexes, and a pool of 32-bit section numbers. The index sections will be
11123 aligned at 8-byte boundaries in the file.
11125 The index section header consists of:
11127 V, 32 bit version number
11129 N, 32 bit number of compilation units or type units in the index
11130 M, 32 bit number of slots in the hash table
11132 Numbers are recorded using the byte order of the application binary.
11134 The hash table begins at offset 16 in the section, and consists of an array
11135 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11136 order of the application binary). Unused slots in the hash table are 0.
11137 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11139 The parallel table begins immediately after the hash table
11140 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11141 array of 32-bit indexes (using the byte order of the application binary),
11142 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11143 table contains a 32-bit index into the pool of section numbers. For unused
11144 hash table slots, the corresponding entry in the parallel table will be 0.
11146 The pool of section numbers begins immediately following the hash table
11147 (at offset 16 + 12 * M from the beginning of the section). The pool of
11148 section numbers consists of an array of 32-bit words (using the byte order
11149 of the application binary). Each item in the array is indexed starting
11150 from 0. The hash table entry provides the index of the first section
11151 number in the set. Additional section numbers in the set follow, and the
11152 set is terminated by a 0 entry (section number 0 is not used in ELF).
11154 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11155 section must be the first entry in the set, and the .debug_abbrev.dwo must
11156 be the second entry. Other members of the set may follow in any order.
11162 DWP Version 2 combines all the .debug_info, etc. sections into one,
11163 and the entries in the index tables are now offsets into these sections.
11164 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11167 Index Section Contents:
11169 Hash Table of Signatures dwp_hash_table.hash_table
11170 Parallel Table of Indices dwp_hash_table.unit_table
11171 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11172 Table of Section Sizes dwp_hash_table.v2.sizes
11174 The index section header consists of:
11176 V, 32 bit version number
11177 L, 32 bit number of columns in the table of section offsets
11178 N, 32 bit number of compilation units or type units in the index
11179 M, 32 bit number of slots in the hash table
11181 Numbers are recorded using the byte order of the application binary.
11183 The hash table has the same format as version 1.
11184 The parallel table of indices has the same format as version 1,
11185 except that the entries are origin-1 indices into the table of sections
11186 offsets and the table of section sizes.
11188 The table of offsets begins immediately following the parallel table
11189 (at offset 16 + 12 * M from the beginning of the section). The table is
11190 a two-dimensional array of 32-bit words (using the byte order of the
11191 application binary), with L columns and N+1 rows, in row-major order.
11192 Each row in the array is indexed starting from 0. The first row provides
11193 a key to the remaining rows: each column in this row provides an identifier
11194 for a debug section, and the offsets in the same column of subsequent rows
11195 refer to that section. The section identifiers are:
11197 DW_SECT_INFO 1 .debug_info.dwo
11198 DW_SECT_TYPES 2 .debug_types.dwo
11199 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11200 DW_SECT_LINE 4 .debug_line.dwo
11201 DW_SECT_LOC 5 .debug_loc.dwo
11202 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11203 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11204 DW_SECT_MACRO 8 .debug_macro.dwo
11206 The offsets provided by the CU and TU index sections are the base offsets
11207 for the contributions made by each CU or TU to the corresponding section
11208 in the package file. Each CU and TU header contains an abbrev_offset
11209 field, used to find the abbreviations table for that CU or TU within the
11210 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11211 be interpreted as relative to the base offset given in the index section.
11212 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11213 should be interpreted as relative to the base offset for .debug_line.dwo,
11214 and offsets into other debug sections obtained from DWARF attributes should
11215 also be interpreted as relative to the corresponding base offset.
11217 The table of sizes begins immediately following the table of offsets.
11218 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11219 with L columns and N rows, in row-major order. Each row in the array is
11220 indexed starting from 1 (row 0 is shared by the two tables).
11224 Hash table lookup is handled the same in version 1 and 2:
11226 We assume that N and M will not exceed 2^32 - 1.
11227 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11229 Given a 64-bit compilation unit signature or a type signature S, an entry
11230 in the hash table is located as follows:
11232 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11233 the low-order k bits all set to 1.
11235 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11237 3) If the hash table entry at index H matches the signature, use that
11238 entry. If the hash table entry at index H is unused (all zeroes),
11239 terminate the search: the signature is not present in the table.
11241 4) Let H = (H + H') modulo M. Repeat at Step 3.
11243 Because M > N and H' and M are relatively prime, the search is guaranteed
11244 to stop at an unused slot or find the match. */
11246 /* Create a hash table to map DWO IDs to their CU/TU entry in
11247 .debug_{info,types}.dwo in DWP_FILE.
11248 Returns NULL if there isn't one.
11249 Note: This function processes DWP files only, not DWO files. */
11251 static struct dwp_hash_table
*
11252 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11253 struct dwp_file
*dwp_file
, int is_debug_types
)
11255 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11256 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11257 const gdb_byte
*index_ptr
, *index_end
;
11258 struct dwarf2_section_info
*index
;
11259 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11260 struct dwp_hash_table
*htab
;
11262 if (is_debug_types
)
11263 index
= &dwp_file
->sections
.tu_index
;
11265 index
= &dwp_file
->sections
.cu_index
;
11267 if (index
->empty ())
11269 index
->read (objfile
);
11271 index_ptr
= index
->buffer
;
11272 index_end
= index_ptr
+ index
->size
;
11274 version
= read_4_bytes (dbfd
, index_ptr
);
11277 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11281 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11283 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11286 if (version
!= 1 && version
!= 2)
11288 error (_("Dwarf Error: unsupported DWP file version (%s)"
11289 " [in module %s]"),
11290 pulongest (version
), dwp_file
->name
);
11292 if (nr_slots
!= (nr_slots
& -nr_slots
))
11294 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11295 " is not power of 2 [in module %s]"),
11296 pulongest (nr_slots
), dwp_file
->name
);
11299 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11300 htab
->version
= version
;
11301 htab
->nr_columns
= nr_columns
;
11302 htab
->nr_units
= nr_units
;
11303 htab
->nr_slots
= nr_slots
;
11304 htab
->hash_table
= index_ptr
;
11305 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11307 /* Exit early if the table is empty. */
11308 if (nr_slots
== 0 || nr_units
== 0
11309 || (version
== 2 && nr_columns
== 0))
11311 /* All must be zero. */
11312 if (nr_slots
!= 0 || nr_units
!= 0
11313 || (version
== 2 && nr_columns
!= 0))
11315 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11316 " all zero [in modules %s]"),
11324 htab
->section_pool
.v1
.indices
=
11325 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11326 /* It's harder to decide whether the section is too small in v1.
11327 V1 is deprecated anyway so we punt. */
11331 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11332 int *ids
= htab
->section_pool
.v2
.section_ids
;
11333 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11334 /* Reverse map for error checking. */
11335 int ids_seen
[DW_SECT_MAX
+ 1];
11338 if (nr_columns
< 2)
11340 error (_("Dwarf Error: bad DWP hash table, too few columns"
11341 " in section table [in module %s]"),
11344 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11346 error (_("Dwarf Error: bad DWP hash table, too many columns"
11347 " in section table [in module %s]"),
11350 memset (ids
, 255, sizeof_ids
);
11351 memset (ids_seen
, 255, sizeof (ids_seen
));
11352 for (i
= 0; i
< nr_columns
; ++i
)
11354 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11356 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11358 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11359 " in section table [in module %s]"),
11360 id
, dwp_file
->name
);
11362 if (ids_seen
[id
] != -1)
11364 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11365 " id %d in section table [in module %s]"),
11366 id
, dwp_file
->name
);
11371 /* Must have exactly one info or types section. */
11372 if (((ids_seen
[DW_SECT_INFO
] != -1)
11373 + (ids_seen
[DW_SECT_TYPES
] != -1))
11376 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11377 " DWO info/types section [in module %s]"),
11380 /* Must have an abbrev section. */
11381 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11383 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11384 " section [in module %s]"),
11387 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11388 htab
->section_pool
.v2
.sizes
=
11389 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11390 * nr_units
* nr_columns
);
11391 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11392 * nr_units
* nr_columns
))
11395 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11396 " [in module %s]"),
11404 /* Update SECTIONS with the data from SECTP.
11406 This function is like the other "locate" section routines that are
11407 passed to bfd_map_over_sections, but in this context the sections to
11408 read comes from the DWP V1 hash table, not the full ELF section table.
11410 The result is non-zero for success, or zero if an error was found. */
11413 locate_v1_virtual_dwo_sections (asection
*sectp
,
11414 struct virtual_v1_dwo_sections
*sections
)
11416 const struct dwop_section_names
*names
= &dwop_section_names
;
11418 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11420 /* There can be only one. */
11421 if (sections
->abbrev
.s
.section
!= NULL
)
11423 sections
->abbrev
.s
.section
= sectp
;
11424 sections
->abbrev
.size
= bfd_section_size (sectp
);
11426 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11427 || section_is_p (sectp
->name
, &names
->types_dwo
))
11429 /* There can be only one. */
11430 if (sections
->info_or_types
.s
.section
!= NULL
)
11432 sections
->info_or_types
.s
.section
= sectp
;
11433 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11435 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11437 /* There can be only one. */
11438 if (sections
->line
.s
.section
!= NULL
)
11440 sections
->line
.s
.section
= sectp
;
11441 sections
->line
.size
= bfd_section_size (sectp
);
11443 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11445 /* There can be only one. */
11446 if (sections
->loc
.s
.section
!= NULL
)
11448 sections
->loc
.s
.section
= sectp
;
11449 sections
->loc
.size
= bfd_section_size (sectp
);
11451 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11453 /* There can be only one. */
11454 if (sections
->macinfo
.s
.section
!= NULL
)
11456 sections
->macinfo
.s
.section
= sectp
;
11457 sections
->macinfo
.size
= bfd_section_size (sectp
);
11459 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11461 /* There can be only one. */
11462 if (sections
->macro
.s
.section
!= NULL
)
11464 sections
->macro
.s
.section
= sectp
;
11465 sections
->macro
.size
= bfd_section_size (sectp
);
11467 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11469 /* There can be only one. */
11470 if (sections
->str_offsets
.s
.section
!= NULL
)
11472 sections
->str_offsets
.s
.section
= sectp
;
11473 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11477 /* No other kind of section is valid. */
11484 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11485 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11486 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11487 This is for DWP version 1 files. */
11489 static struct dwo_unit
*
11490 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11491 struct dwp_file
*dwp_file
,
11492 uint32_t unit_index
,
11493 const char *comp_dir
,
11494 ULONGEST signature
, int is_debug_types
)
11496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11497 const struct dwp_hash_table
*dwp_htab
=
11498 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11499 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11500 const char *kind
= is_debug_types
? "TU" : "CU";
11501 struct dwo_file
*dwo_file
;
11502 struct dwo_unit
*dwo_unit
;
11503 struct virtual_v1_dwo_sections sections
;
11504 void **dwo_file_slot
;
11507 gdb_assert (dwp_file
->version
== 1);
11509 if (dwarf_read_debug
)
11511 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11513 pulongest (unit_index
), hex_string (signature
),
11517 /* Fetch the sections of this DWO unit.
11518 Put a limit on the number of sections we look for so that bad data
11519 doesn't cause us to loop forever. */
11521 #define MAX_NR_V1_DWO_SECTIONS \
11522 (1 /* .debug_info or .debug_types */ \
11523 + 1 /* .debug_abbrev */ \
11524 + 1 /* .debug_line */ \
11525 + 1 /* .debug_loc */ \
11526 + 1 /* .debug_str_offsets */ \
11527 + 1 /* .debug_macro or .debug_macinfo */ \
11528 + 1 /* trailing zero */)
11530 memset (§ions
, 0, sizeof (sections
));
11532 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11535 uint32_t section_nr
=
11536 read_4_bytes (dbfd
,
11537 dwp_htab
->section_pool
.v1
.indices
11538 + (unit_index
+ i
) * sizeof (uint32_t));
11540 if (section_nr
== 0)
11542 if (section_nr
>= dwp_file
->num_sections
)
11544 error (_("Dwarf Error: bad DWP hash table, section number too large"
11545 " [in module %s]"),
11549 sectp
= dwp_file
->elf_sections
[section_nr
];
11550 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11552 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11553 " [in module %s]"),
11559 || sections
.info_or_types
.empty ()
11560 || sections
.abbrev
.empty ())
11562 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11563 " [in module %s]"),
11566 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11568 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11569 " [in module %s]"),
11573 /* It's easier for the rest of the code if we fake a struct dwo_file and
11574 have dwo_unit "live" in that. At least for now.
11576 The DWP file can be made up of a random collection of CUs and TUs.
11577 However, for each CU + set of TUs that came from the same original DWO
11578 file, we can combine them back into a virtual DWO file to save space
11579 (fewer struct dwo_file objects to allocate). Remember that for really
11580 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11582 std::string virtual_dwo_name
=
11583 string_printf ("virtual-dwo/%d-%d-%d-%d",
11584 sections
.abbrev
.get_id (),
11585 sections
.line
.get_id (),
11586 sections
.loc
.get_id (),
11587 sections
.str_offsets
.get_id ());
11588 /* Can we use an existing virtual DWO file? */
11589 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11590 virtual_dwo_name
.c_str (),
11592 /* Create one if necessary. */
11593 if (*dwo_file_slot
== NULL
)
11595 if (dwarf_read_debug
)
11597 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11598 virtual_dwo_name
.c_str ());
11600 dwo_file
= new struct dwo_file
;
11601 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11602 dwo_file
->comp_dir
= comp_dir
;
11603 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11604 dwo_file
->sections
.line
= sections
.line
;
11605 dwo_file
->sections
.loc
= sections
.loc
;
11606 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11607 dwo_file
->sections
.macro
= sections
.macro
;
11608 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11609 /* The "str" section is global to the entire DWP file. */
11610 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11611 /* The info or types section is assigned below to dwo_unit,
11612 there's no need to record it in dwo_file.
11613 Also, we can't simply record type sections in dwo_file because
11614 we record a pointer into the vector in dwo_unit. As we collect more
11615 types we'll grow the vector and eventually have to reallocate space
11616 for it, invalidating all copies of pointers into the previous
11618 *dwo_file_slot
= dwo_file
;
11622 if (dwarf_read_debug
)
11624 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11625 virtual_dwo_name
.c_str ());
11627 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11630 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11631 dwo_unit
->dwo_file
= dwo_file
;
11632 dwo_unit
->signature
= signature
;
11633 dwo_unit
->section
=
11634 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11635 *dwo_unit
->section
= sections
.info_or_types
;
11636 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11641 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11642 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11643 piece within that section used by a TU/CU, return a virtual section
11644 of just that piece. */
11646 static struct dwarf2_section_info
11647 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11648 struct dwarf2_section_info
*section
,
11649 bfd_size_type offset
, bfd_size_type size
)
11651 struct dwarf2_section_info result
;
11654 gdb_assert (section
!= NULL
);
11655 gdb_assert (!section
->is_virtual
);
11657 memset (&result
, 0, sizeof (result
));
11658 result
.s
.containing_section
= section
;
11659 result
.is_virtual
= true;
11664 sectp
= section
->get_bfd_section ();
11666 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11667 bounds of the real section. This is a pretty-rare event, so just
11668 flag an error (easier) instead of a warning and trying to cope. */
11670 || offset
+ size
> bfd_section_size (sectp
))
11672 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11673 " in section %s [in module %s]"),
11674 sectp
? bfd_section_name (sectp
) : "<unknown>",
11675 objfile_name (dwarf2_per_objfile
->objfile
));
11678 result
.virtual_offset
= offset
;
11679 result
.size
= size
;
11683 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11684 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11685 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11686 This is for DWP version 2 files. */
11688 static struct dwo_unit
*
11689 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11690 struct dwp_file
*dwp_file
,
11691 uint32_t unit_index
,
11692 const char *comp_dir
,
11693 ULONGEST signature
, int is_debug_types
)
11695 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11696 const struct dwp_hash_table
*dwp_htab
=
11697 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11698 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11699 const char *kind
= is_debug_types
? "TU" : "CU";
11700 struct dwo_file
*dwo_file
;
11701 struct dwo_unit
*dwo_unit
;
11702 struct virtual_v2_dwo_sections sections
;
11703 void **dwo_file_slot
;
11706 gdb_assert (dwp_file
->version
== 2);
11708 if (dwarf_read_debug
)
11710 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11712 pulongest (unit_index
), hex_string (signature
),
11716 /* Fetch the section offsets of this DWO unit. */
11718 memset (§ions
, 0, sizeof (sections
));
11720 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11722 uint32_t offset
= read_4_bytes (dbfd
,
11723 dwp_htab
->section_pool
.v2
.offsets
11724 + (((unit_index
- 1) * dwp_htab
->nr_columns
11726 * sizeof (uint32_t)));
11727 uint32_t size
= read_4_bytes (dbfd
,
11728 dwp_htab
->section_pool
.v2
.sizes
11729 + (((unit_index
- 1) * dwp_htab
->nr_columns
11731 * sizeof (uint32_t)));
11733 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11736 case DW_SECT_TYPES
:
11737 sections
.info_or_types_offset
= offset
;
11738 sections
.info_or_types_size
= size
;
11740 case DW_SECT_ABBREV
:
11741 sections
.abbrev_offset
= offset
;
11742 sections
.abbrev_size
= size
;
11745 sections
.line_offset
= offset
;
11746 sections
.line_size
= size
;
11749 sections
.loc_offset
= offset
;
11750 sections
.loc_size
= size
;
11752 case DW_SECT_STR_OFFSETS
:
11753 sections
.str_offsets_offset
= offset
;
11754 sections
.str_offsets_size
= size
;
11756 case DW_SECT_MACINFO
:
11757 sections
.macinfo_offset
= offset
;
11758 sections
.macinfo_size
= size
;
11760 case DW_SECT_MACRO
:
11761 sections
.macro_offset
= offset
;
11762 sections
.macro_size
= size
;
11767 /* It's easier for the rest of the code if we fake a struct dwo_file and
11768 have dwo_unit "live" in that. At least for now.
11770 The DWP file can be made up of a random collection of CUs and TUs.
11771 However, for each CU + set of TUs that came from the same original DWO
11772 file, we can combine them back into a virtual DWO file to save space
11773 (fewer struct dwo_file objects to allocate). Remember that for really
11774 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11776 std::string virtual_dwo_name
=
11777 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11778 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11779 (long) (sections
.line_size
? sections
.line_offset
: 0),
11780 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11781 (long) (sections
.str_offsets_size
11782 ? sections
.str_offsets_offset
: 0));
11783 /* Can we use an existing virtual DWO file? */
11784 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11785 virtual_dwo_name
.c_str (),
11787 /* Create one if necessary. */
11788 if (*dwo_file_slot
== NULL
)
11790 if (dwarf_read_debug
)
11792 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11793 virtual_dwo_name
.c_str ());
11795 dwo_file
= new struct dwo_file
;
11796 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11797 dwo_file
->comp_dir
= comp_dir
;
11798 dwo_file
->sections
.abbrev
=
11799 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11800 sections
.abbrev_offset
, sections
.abbrev_size
);
11801 dwo_file
->sections
.line
=
11802 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11803 sections
.line_offset
, sections
.line_size
);
11804 dwo_file
->sections
.loc
=
11805 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11806 sections
.loc_offset
, sections
.loc_size
);
11807 dwo_file
->sections
.macinfo
=
11808 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11809 sections
.macinfo_offset
, sections
.macinfo_size
);
11810 dwo_file
->sections
.macro
=
11811 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11812 sections
.macro_offset
, sections
.macro_size
);
11813 dwo_file
->sections
.str_offsets
=
11814 create_dwp_v2_section (dwarf2_per_objfile
,
11815 &dwp_file
->sections
.str_offsets
,
11816 sections
.str_offsets_offset
,
11817 sections
.str_offsets_size
);
11818 /* The "str" section is global to the entire DWP file. */
11819 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11820 /* The info or types section is assigned below to dwo_unit,
11821 there's no need to record it in dwo_file.
11822 Also, we can't simply record type sections in dwo_file because
11823 we record a pointer into the vector in dwo_unit. As we collect more
11824 types we'll grow the vector and eventually have to reallocate space
11825 for it, invalidating all copies of pointers into the previous
11827 *dwo_file_slot
= dwo_file
;
11831 if (dwarf_read_debug
)
11833 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11834 virtual_dwo_name
.c_str ());
11836 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11839 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11840 dwo_unit
->dwo_file
= dwo_file
;
11841 dwo_unit
->signature
= signature
;
11842 dwo_unit
->section
=
11843 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11844 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11846 ? &dwp_file
->sections
.types
11847 : &dwp_file
->sections
.info
,
11848 sections
.info_or_types_offset
,
11849 sections
.info_or_types_size
);
11850 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11855 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11856 Returns NULL if the signature isn't found. */
11858 static struct dwo_unit
*
11859 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11860 struct dwp_file
*dwp_file
, const char *comp_dir
,
11861 ULONGEST signature
, int is_debug_types
)
11863 const struct dwp_hash_table
*dwp_htab
=
11864 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11865 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11866 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11867 uint32_t hash
= signature
& mask
;
11868 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11871 struct dwo_unit find_dwo_cu
;
11873 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11874 find_dwo_cu
.signature
= signature
;
11875 slot
= htab_find_slot (is_debug_types
11876 ? dwp_file
->loaded_tus
.get ()
11877 : dwp_file
->loaded_cus
.get (),
11878 &find_dwo_cu
, INSERT
);
11881 return (struct dwo_unit
*) *slot
;
11883 /* Use a for loop so that we don't loop forever on bad debug info. */
11884 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11886 ULONGEST signature_in_table
;
11888 signature_in_table
=
11889 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11890 if (signature_in_table
== signature
)
11892 uint32_t unit_index
=
11893 read_4_bytes (dbfd
,
11894 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11896 if (dwp_file
->version
== 1)
11898 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11899 dwp_file
, unit_index
,
11900 comp_dir
, signature
,
11905 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11906 dwp_file
, unit_index
,
11907 comp_dir
, signature
,
11910 return (struct dwo_unit
*) *slot
;
11912 if (signature_in_table
== 0)
11914 hash
= (hash
+ hash2
) & mask
;
11917 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11918 " [in module %s]"),
11922 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11923 Open the file specified by FILE_NAME and hand it off to BFD for
11924 preliminary analysis. Return a newly initialized bfd *, which
11925 includes a canonicalized copy of FILE_NAME.
11926 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11927 SEARCH_CWD is true if the current directory is to be searched.
11928 It will be searched before debug-file-directory.
11929 If successful, the file is added to the bfd include table of the
11930 objfile's bfd (see gdb_bfd_record_inclusion).
11931 If unable to find/open the file, return NULL.
11932 NOTE: This function is derived from symfile_bfd_open. */
11934 static gdb_bfd_ref_ptr
11935 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11936 const char *file_name
, int is_dwp
, int search_cwd
)
11939 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11940 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11941 to debug_file_directory. */
11942 const char *search_path
;
11943 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11945 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11948 if (*debug_file_directory
!= '\0')
11950 search_path_holder
.reset (concat (".", dirname_separator_string
,
11951 debug_file_directory
,
11953 search_path
= search_path_holder
.get ();
11959 search_path
= debug_file_directory
;
11961 openp_flags flags
= OPF_RETURN_REALPATH
;
11963 flags
|= OPF_SEARCH_IN_PATH
;
11965 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11966 desc
= openp (search_path
, flags
, file_name
,
11967 O_RDONLY
| O_BINARY
, &absolute_name
);
11971 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11973 if (sym_bfd
== NULL
)
11975 bfd_set_cacheable (sym_bfd
.get (), 1);
11977 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11980 /* Success. Record the bfd as having been included by the objfile's bfd.
11981 This is important because things like demangled_names_hash lives in the
11982 objfile's per_bfd space and may have references to things like symbol
11983 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11984 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11989 /* Try to open DWO file FILE_NAME.
11990 COMP_DIR is the DW_AT_comp_dir attribute.
11991 The result is the bfd handle of the file.
11992 If there is a problem finding or opening the file, return NULL.
11993 Upon success, the canonicalized path of the file is stored in the bfd,
11994 same as symfile_bfd_open. */
11996 static gdb_bfd_ref_ptr
11997 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11998 const char *file_name
, const char *comp_dir
)
12000 if (IS_ABSOLUTE_PATH (file_name
))
12001 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12002 0 /*is_dwp*/, 0 /*search_cwd*/);
12004 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12006 if (comp_dir
!= NULL
)
12008 gdb::unique_xmalloc_ptr
<char> path_to_try
12009 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12011 /* NOTE: If comp_dir is a relative path, this will also try the
12012 search path, which seems useful. */
12013 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12014 path_to_try
.get (),
12016 1 /*search_cwd*/));
12021 /* That didn't work, try debug-file-directory, which, despite its name,
12022 is a list of paths. */
12024 if (*debug_file_directory
== '\0')
12027 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12028 0 /*is_dwp*/, 1 /*search_cwd*/);
12031 /* This function is mapped across the sections and remembers the offset and
12032 size of each of the DWO debugging sections we are interested in. */
12035 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12037 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12038 const struct dwop_section_names
*names
= &dwop_section_names
;
12040 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12042 dwo_sections
->abbrev
.s
.section
= sectp
;
12043 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12045 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12047 dwo_sections
->info
.s
.section
= sectp
;
12048 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12050 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12052 dwo_sections
->line
.s
.section
= sectp
;
12053 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12055 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12057 dwo_sections
->loc
.s
.section
= sectp
;
12058 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12060 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12062 dwo_sections
->macinfo
.s
.section
= sectp
;
12063 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12065 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12067 dwo_sections
->macro
.s
.section
= sectp
;
12068 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12070 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12072 dwo_sections
->str
.s
.section
= sectp
;
12073 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12075 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12077 dwo_sections
->str_offsets
.s
.section
= sectp
;
12078 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12080 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12082 struct dwarf2_section_info type_section
;
12084 memset (&type_section
, 0, sizeof (type_section
));
12085 type_section
.s
.section
= sectp
;
12086 type_section
.size
= bfd_section_size (sectp
);
12087 dwo_sections
->types
.push_back (type_section
);
12091 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12092 by PER_CU. This is for the non-DWP case.
12093 The result is NULL if DWO_NAME can't be found. */
12095 static struct dwo_file
*
12096 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12097 const char *dwo_name
, const char *comp_dir
)
12099 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12101 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12104 if (dwarf_read_debug
)
12105 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12109 dwo_file_up
dwo_file (new struct dwo_file
);
12110 dwo_file
->dwo_name
= dwo_name
;
12111 dwo_file
->comp_dir
= comp_dir
;
12112 dwo_file
->dbfd
= std::move (dbfd
);
12114 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12115 &dwo_file
->sections
);
12117 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12118 dwo_file
->sections
.info
, dwo_file
->cus
);
12120 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12121 dwo_file
->sections
.types
, dwo_file
->tus
);
12123 if (dwarf_read_debug
)
12124 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12126 return dwo_file
.release ();
12129 /* This function is mapped across the sections and remembers the offset and
12130 size of each of the DWP debugging sections common to version 1 and 2 that
12131 we are interested in. */
12134 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12135 void *dwp_file_ptr
)
12137 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12138 const struct dwop_section_names
*names
= &dwop_section_names
;
12139 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12141 /* Record the ELF section number for later lookup: this is what the
12142 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12143 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12144 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12146 /* Look for specific sections that we need. */
12147 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12149 dwp_file
->sections
.str
.s
.section
= sectp
;
12150 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12152 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12154 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12155 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12157 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12159 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12160 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12164 /* This function is mapped across the sections and remembers the offset and
12165 size of each of the DWP version 2 debugging sections that we are interested
12166 in. This is split into a separate function because we don't know if we
12167 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12170 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12172 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12173 const struct dwop_section_names
*names
= &dwop_section_names
;
12174 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12176 /* Record the ELF section number for later lookup: this is what the
12177 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12178 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12179 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12181 /* Look for specific sections that we need. */
12182 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12184 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12185 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12187 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12189 dwp_file
->sections
.info
.s
.section
= sectp
;
12190 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12192 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12194 dwp_file
->sections
.line
.s
.section
= sectp
;
12195 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12197 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12199 dwp_file
->sections
.loc
.s
.section
= sectp
;
12200 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12202 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12204 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12205 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12207 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12209 dwp_file
->sections
.macro
.s
.section
= sectp
;
12210 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12212 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12214 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12215 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12217 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12219 dwp_file
->sections
.types
.s
.section
= sectp
;
12220 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12224 /* Hash function for dwp_file loaded CUs/TUs. */
12227 hash_dwp_loaded_cutus (const void *item
)
12229 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12231 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12232 return dwo_unit
->signature
;
12235 /* Equality function for dwp_file loaded CUs/TUs. */
12238 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12240 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12241 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12243 return dua
->signature
== dub
->signature
;
12246 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12249 allocate_dwp_loaded_cutus_table ()
12251 return htab_up (htab_create_alloc (3,
12252 hash_dwp_loaded_cutus
,
12253 eq_dwp_loaded_cutus
,
12254 NULL
, xcalloc
, xfree
));
12257 /* Try to open DWP file FILE_NAME.
12258 The result is the bfd handle of the file.
12259 If there is a problem finding or opening the file, return NULL.
12260 Upon success, the canonicalized path of the file is stored in the bfd,
12261 same as symfile_bfd_open. */
12263 static gdb_bfd_ref_ptr
12264 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12265 const char *file_name
)
12267 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12269 1 /*search_cwd*/));
12273 /* Work around upstream bug 15652.
12274 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12275 [Whether that's a "bug" is debatable, but it is getting in our way.]
12276 We have no real idea where the dwp file is, because gdb's realpath-ing
12277 of the executable's path may have discarded the needed info.
12278 [IWBN if the dwp file name was recorded in the executable, akin to
12279 .gnu_debuglink, but that doesn't exist yet.]
12280 Strip the directory from FILE_NAME and search again. */
12281 if (*debug_file_directory
!= '\0')
12283 /* Don't implicitly search the current directory here.
12284 If the user wants to search "." to handle this case,
12285 it must be added to debug-file-directory. */
12286 return try_open_dwop_file (dwarf2_per_objfile
,
12287 lbasename (file_name
), 1 /*is_dwp*/,
12294 /* Initialize the use of the DWP file for the current objfile.
12295 By convention the name of the DWP file is ${objfile}.dwp.
12296 The result is NULL if it can't be found. */
12298 static std::unique_ptr
<struct dwp_file
>
12299 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12301 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12303 /* Try to find first .dwp for the binary file before any symbolic links
12306 /* If the objfile is a debug file, find the name of the real binary
12307 file and get the name of dwp file from there. */
12308 std::string dwp_name
;
12309 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12311 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12312 const char *backlink_basename
= lbasename (backlink
->original_name
);
12314 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12317 dwp_name
= objfile
->original_name
;
12319 dwp_name
+= ".dwp";
12321 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12323 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12325 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12326 dwp_name
= objfile_name (objfile
);
12327 dwp_name
+= ".dwp";
12328 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12333 if (dwarf_read_debug
)
12334 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12335 return std::unique_ptr
<dwp_file
> ();
12338 const char *name
= bfd_get_filename (dbfd
.get ());
12339 std::unique_ptr
<struct dwp_file
> dwp_file
12340 (new struct dwp_file (name
, std::move (dbfd
)));
12342 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12343 dwp_file
->elf_sections
=
12344 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12345 dwp_file
->num_sections
, asection
*);
12347 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12348 dwarf2_locate_common_dwp_sections
,
12351 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12354 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12357 /* The DWP file version is stored in the hash table. Oh well. */
12358 if (dwp_file
->cus
&& dwp_file
->tus
12359 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12361 /* Technically speaking, we should try to limp along, but this is
12362 pretty bizarre. We use pulongest here because that's the established
12363 portability solution (e.g, we cannot use %u for uint32_t). */
12364 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12365 " TU version %s [in DWP file %s]"),
12366 pulongest (dwp_file
->cus
->version
),
12367 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12371 dwp_file
->version
= dwp_file
->cus
->version
;
12372 else if (dwp_file
->tus
)
12373 dwp_file
->version
= dwp_file
->tus
->version
;
12375 dwp_file
->version
= 2;
12377 if (dwp_file
->version
== 2)
12378 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12379 dwarf2_locate_v2_dwp_sections
,
12382 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12383 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12385 if (dwarf_read_debug
)
12387 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12388 fprintf_unfiltered (gdb_stdlog
,
12389 " %s CUs, %s TUs\n",
12390 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12391 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12397 /* Wrapper around open_and_init_dwp_file, only open it once. */
12399 static struct dwp_file
*
12400 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12402 if (! dwarf2_per_objfile
->dwp_checked
)
12404 dwarf2_per_objfile
->dwp_file
12405 = open_and_init_dwp_file (dwarf2_per_objfile
);
12406 dwarf2_per_objfile
->dwp_checked
= 1;
12408 return dwarf2_per_objfile
->dwp_file
.get ();
12411 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12412 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12413 or in the DWP file for the objfile, referenced by THIS_UNIT.
12414 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12415 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12417 This is called, for example, when wanting to read a variable with a
12418 complex location. Therefore we don't want to do file i/o for every call.
12419 Therefore we don't want to look for a DWO file on every call.
12420 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12421 then we check if we've already seen DWO_NAME, and only THEN do we check
12424 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12425 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12427 static struct dwo_unit
*
12428 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12429 const char *dwo_name
, const char *comp_dir
,
12430 ULONGEST signature
, int is_debug_types
)
12432 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12433 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12434 const char *kind
= is_debug_types
? "TU" : "CU";
12435 void **dwo_file_slot
;
12436 struct dwo_file
*dwo_file
;
12437 struct dwp_file
*dwp_file
;
12439 /* First see if there's a DWP file.
12440 If we have a DWP file but didn't find the DWO inside it, don't
12441 look for the original DWO file. It makes gdb behave differently
12442 depending on whether one is debugging in the build tree. */
12444 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12445 if (dwp_file
!= NULL
)
12447 const struct dwp_hash_table
*dwp_htab
=
12448 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12450 if (dwp_htab
!= NULL
)
12452 struct dwo_unit
*dwo_cutu
=
12453 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12454 signature
, is_debug_types
);
12456 if (dwo_cutu
!= NULL
)
12458 if (dwarf_read_debug
)
12460 fprintf_unfiltered (gdb_stdlog
,
12461 "Virtual DWO %s %s found: @%s\n",
12462 kind
, hex_string (signature
),
12463 host_address_to_string (dwo_cutu
));
12471 /* No DWP file, look for the DWO file. */
12473 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12474 dwo_name
, comp_dir
);
12475 if (*dwo_file_slot
== NULL
)
12477 /* Read in the file and build a table of the CUs/TUs it contains. */
12478 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12480 /* NOTE: This will be NULL if unable to open the file. */
12481 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12483 if (dwo_file
!= NULL
)
12485 struct dwo_unit
*dwo_cutu
= NULL
;
12487 if (is_debug_types
&& dwo_file
->tus
)
12489 struct dwo_unit find_dwo_cutu
;
12491 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12492 find_dwo_cutu
.signature
= signature
;
12494 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12497 else if (!is_debug_types
&& dwo_file
->cus
)
12499 struct dwo_unit find_dwo_cutu
;
12501 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12502 find_dwo_cutu
.signature
= signature
;
12503 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12507 if (dwo_cutu
!= NULL
)
12509 if (dwarf_read_debug
)
12511 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12512 kind
, dwo_name
, hex_string (signature
),
12513 host_address_to_string (dwo_cutu
));
12520 /* We didn't find it. This could mean a dwo_id mismatch, or
12521 someone deleted the DWO/DWP file, or the search path isn't set up
12522 correctly to find the file. */
12524 if (dwarf_read_debug
)
12526 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12527 kind
, dwo_name
, hex_string (signature
));
12530 /* This is a warning and not a complaint because it can be caused by
12531 pilot error (e.g., user accidentally deleting the DWO). */
12533 /* Print the name of the DWP file if we looked there, helps the user
12534 better diagnose the problem. */
12535 std::string dwp_text
;
12537 if (dwp_file
!= NULL
)
12538 dwp_text
= string_printf (" [in DWP file %s]",
12539 lbasename (dwp_file
->name
));
12541 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12542 " [in module %s]"),
12543 kind
, dwo_name
, hex_string (signature
),
12545 this_unit
->is_debug_types
? "TU" : "CU",
12546 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12551 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12552 See lookup_dwo_cutu_unit for details. */
12554 static struct dwo_unit
*
12555 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12556 const char *dwo_name
, const char *comp_dir
,
12557 ULONGEST signature
)
12559 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12562 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12563 See lookup_dwo_cutu_unit for details. */
12565 static struct dwo_unit
*
12566 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12567 const char *dwo_name
, const char *comp_dir
)
12569 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12572 /* Traversal function for queue_and_load_all_dwo_tus. */
12575 queue_and_load_dwo_tu (void **slot
, void *info
)
12577 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12578 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12579 ULONGEST signature
= dwo_unit
->signature
;
12580 struct signatured_type
*sig_type
=
12581 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12583 if (sig_type
!= NULL
)
12585 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12587 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12588 a real dependency of PER_CU on SIG_TYPE. That is detected later
12589 while processing PER_CU. */
12590 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12591 load_full_type_unit (sig_cu
);
12592 per_cu
->imported_symtabs_push (sig_cu
);
12598 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12599 The DWO may have the only definition of the type, though it may not be
12600 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12601 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12604 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12606 struct dwo_unit
*dwo_unit
;
12607 struct dwo_file
*dwo_file
;
12609 gdb_assert (!per_cu
->is_debug_types
);
12610 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12611 gdb_assert (per_cu
->cu
!= NULL
);
12613 dwo_unit
= per_cu
->cu
->dwo_unit
;
12614 gdb_assert (dwo_unit
!= NULL
);
12616 dwo_file
= dwo_unit
->dwo_file
;
12617 if (dwo_file
->tus
!= NULL
)
12618 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12622 /* Read in various DIEs. */
12624 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12625 Inherit only the children of the DW_AT_abstract_origin DIE not being
12626 already referenced by DW_AT_abstract_origin from the children of the
12630 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12632 struct die_info
*child_die
;
12633 sect_offset
*offsetp
;
12634 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12635 struct die_info
*origin_die
;
12636 /* Iterator of the ORIGIN_DIE children. */
12637 struct die_info
*origin_child_die
;
12638 struct attribute
*attr
;
12639 struct dwarf2_cu
*origin_cu
;
12640 struct pending
**origin_previous_list_in_scope
;
12642 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12646 /* Note that following die references may follow to a die in a
12650 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12652 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12654 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12655 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12657 if (die
->tag
!= origin_die
->tag
12658 && !(die
->tag
== DW_TAG_inlined_subroutine
12659 && origin_die
->tag
== DW_TAG_subprogram
))
12660 complaint (_("DIE %s and its abstract origin %s have different tags"),
12661 sect_offset_str (die
->sect_off
),
12662 sect_offset_str (origin_die
->sect_off
));
12664 std::vector
<sect_offset
> offsets
;
12666 for (child_die
= die
->child
;
12667 child_die
&& child_die
->tag
;
12668 child_die
= child_die
->sibling
)
12670 struct die_info
*child_origin_die
;
12671 struct dwarf2_cu
*child_origin_cu
;
12673 /* We are trying to process concrete instance entries:
12674 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12675 it's not relevant to our analysis here. i.e. detecting DIEs that are
12676 present in the abstract instance but not referenced in the concrete
12678 if (child_die
->tag
== DW_TAG_call_site
12679 || child_die
->tag
== DW_TAG_GNU_call_site
)
12682 /* For each CHILD_DIE, find the corresponding child of
12683 ORIGIN_DIE. If there is more than one layer of
12684 DW_AT_abstract_origin, follow them all; there shouldn't be,
12685 but GCC versions at least through 4.4 generate this (GCC PR
12687 child_origin_die
= child_die
;
12688 child_origin_cu
= cu
;
12691 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12695 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12699 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12700 counterpart may exist. */
12701 if (child_origin_die
!= child_die
)
12703 if (child_die
->tag
!= child_origin_die
->tag
12704 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12705 && child_origin_die
->tag
== DW_TAG_subprogram
))
12706 complaint (_("Child DIE %s and its abstract origin %s have "
12708 sect_offset_str (child_die
->sect_off
),
12709 sect_offset_str (child_origin_die
->sect_off
));
12710 if (child_origin_die
->parent
!= origin_die
)
12711 complaint (_("Child DIE %s and its abstract origin %s have "
12712 "different parents"),
12713 sect_offset_str (child_die
->sect_off
),
12714 sect_offset_str (child_origin_die
->sect_off
));
12716 offsets
.push_back (child_origin_die
->sect_off
);
12719 std::sort (offsets
.begin (), offsets
.end ());
12720 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12721 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12722 if (offsetp
[-1] == *offsetp
)
12723 complaint (_("Multiple children of DIE %s refer "
12724 "to DIE %s as their abstract origin"),
12725 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12727 offsetp
= offsets
.data ();
12728 origin_child_die
= origin_die
->child
;
12729 while (origin_child_die
&& origin_child_die
->tag
)
12731 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12732 while (offsetp
< offsets_end
12733 && *offsetp
< origin_child_die
->sect_off
)
12735 if (offsetp
>= offsets_end
12736 || *offsetp
> origin_child_die
->sect_off
)
12738 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12739 Check whether we're already processing ORIGIN_CHILD_DIE.
12740 This can happen with mutually referenced abstract_origins.
12742 if (!origin_child_die
->in_process
)
12743 process_die (origin_child_die
, origin_cu
);
12745 origin_child_die
= origin_child_die
->sibling
;
12747 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12749 if (cu
!= origin_cu
)
12750 compute_delayed_physnames (origin_cu
);
12754 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12756 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12757 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12758 struct context_stack
*newobj
;
12761 struct die_info
*child_die
;
12762 struct attribute
*attr
, *call_line
, *call_file
;
12764 CORE_ADDR baseaddr
;
12765 struct block
*block
;
12766 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12767 std::vector
<struct symbol
*> template_args
;
12768 struct template_symbol
*templ_func
= NULL
;
12772 /* If we do not have call site information, we can't show the
12773 caller of this inlined function. That's too confusing, so
12774 only use the scope for local variables. */
12775 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12776 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12777 if (call_line
== NULL
|| call_file
== NULL
)
12779 read_lexical_block_scope (die
, cu
);
12784 baseaddr
= objfile
->text_section_offset ();
12786 name
= dwarf2_name (die
, cu
);
12788 /* Ignore functions with missing or empty names. These are actually
12789 illegal according to the DWARF standard. */
12792 complaint (_("missing name for subprogram DIE at %s"),
12793 sect_offset_str (die
->sect_off
));
12797 /* Ignore functions with missing or invalid low and high pc attributes. */
12798 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12799 <= PC_BOUNDS_INVALID
)
12801 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12802 if (!attr
|| !DW_UNSND (attr
))
12803 complaint (_("cannot get low and high bounds "
12804 "for subprogram DIE at %s"),
12805 sect_offset_str (die
->sect_off
));
12809 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12810 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12812 /* If we have any template arguments, then we must allocate a
12813 different sort of symbol. */
12814 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12816 if (child_die
->tag
== DW_TAG_template_type_param
12817 || child_die
->tag
== DW_TAG_template_value_param
)
12819 templ_func
= allocate_template_symbol (objfile
);
12820 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12825 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12826 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12827 (struct symbol
*) templ_func
);
12829 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12830 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12833 /* If there is a location expression for DW_AT_frame_base, record
12835 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12836 if (attr
!= nullptr)
12837 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12839 /* If there is a location for the static link, record it. */
12840 newobj
->static_link
= NULL
;
12841 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12842 if (attr
!= nullptr)
12844 newobj
->static_link
12845 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12846 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12847 cu
->per_cu
->addr_type ());
12850 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12852 if (die
->child
!= NULL
)
12854 child_die
= die
->child
;
12855 while (child_die
&& child_die
->tag
)
12857 if (child_die
->tag
== DW_TAG_template_type_param
12858 || child_die
->tag
== DW_TAG_template_value_param
)
12860 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12863 template_args
.push_back (arg
);
12866 process_die (child_die
, cu
);
12867 child_die
= child_die
->sibling
;
12871 inherit_abstract_dies (die
, cu
);
12873 /* If we have a DW_AT_specification, we might need to import using
12874 directives from the context of the specification DIE. See the
12875 comment in determine_prefix. */
12876 if (cu
->language
== language_cplus
12877 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12879 struct dwarf2_cu
*spec_cu
= cu
;
12880 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12884 child_die
= spec_die
->child
;
12885 while (child_die
&& child_die
->tag
)
12887 if (child_die
->tag
== DW_TAG_imported_module
)
12888 process_die (child_die
, spec_cu
);
12889 child_die
= child_die
->sibling
;
12892 /* In some cases, GCC generates specification DIEs that
12893 themselves contain DW_AT_specification attributes. */
12894 spec_die
= die_specification (spec_die
, &spec_cu
);
12898 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12899 /* Make a block for the local symbols within. */
12900 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12901 cstk
.static_link
, lowpc
, highpc
);
12903 /* For C++, set the block's scope. */
12904 if ((cu
->language
== language_cplus
12905 || cu
->language
== language_fortran
12906 || cu
->language
== language_d
12907 || cu
->language
== language_rust
)
12908 && cu
->processing_has_namespace_info
)
12909 block_set_scope (block
, determine_prefix (die
, cu
),
12910 &objfile
->objfile_obstack
);
12912 /* If we have address ranges, record them. */
12913 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12915 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12917 /* Attach template arguments to function. */
12918 if (!template_args
.empty ())
12920 gdb_assert (templ_func
!= NULL
);
12922 templ_func
->n_template_arguments
= template_args
.size ();
12923 templ_func
->template_arguments
12924 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12925 templ_func
->n_template_arguments
);
12926 memcpy (templ_func
->template_arguments
,
12927 template_args
.data (),
12928 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12930 /* Make sure that the symtab is set on the new symbols. Even
12931 though they don't appear in this symtab directly, other parts
12932 of gdb assume that symbols do, and this is reasonably
12934 for (symbol
*sym
: template_args
)
12935 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12938 /* In C++, we can have functions nested inside functions (e.g., when
12939 a function declares a class that has methods). This means that
12940 when we finish processing a function scope, we may need to go
12941 back to building a containing block's symbol lists. */
12942 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12943 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12945 /* If we've finished processing a top-level function, subsequent
12946 symbols go in the file symbol list. */
12947 if (cu
->get_builder ()->outermost_context_p ())
12948 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12951 /* Process all the DIES contained within a lexical block scope. Start
12952 a new scope, process the dies, and then close the scope. */
12955 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12957 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12958 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12959 CORE_ADDR lowpc
, highpc
;
12960 struct die_info
*child_die
;
12961 CORE_ADDR baseaddr
;
12963 baseaddr
= objfile
->text_section_offset ();
12965 /* Ignore blocks with missing or invalid low and high pc attributes. */
12966 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12967 as multiple lexical blocks? Handling children in a sane way would
12968 be nasty. Might be easier to properly extend generic blocks to
12969 describe ranges. */
12970 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12972 case PC_BOUNDS_NOT_PRESENT
:
12973 /* DW_TAG_lexical_block has no attributes, process its children as if
12974 there was no wrapping by that DW_TAG_lexical_block.
12975 GCC does no longer produces such DWARF since GCC r224161. */
12976 for (child_die
= die
->child
;
12977 child_die
!= NULL
&& child_die
->tag
;
12978 child_die
= child_die
->sibling
)
12979 process_die (child_die
, cu
);
12981 case PC_BOUNDS_INVALID
:
12984 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12985 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12987 cu
->get_builder ()->push_context (0, lowpc
);
12988 if (die
->child
!= NULL
)
12990 child_die
= die
->child
;
12991 while (child_die
&& child_die
->tag
)
12993 process_die (child_die
, cu
);
12994 child_die
= child_die
->sibling
;
12997 inherit_abstract_dies (die
, cu
);
12998 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13000 if (*cu
->get_builder ()->get_local_symbols () != NULL
13001 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13003 struct block
*block
13004 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13005 cstk
.start_addr
, highpc
);
13007 /* Note that recording ranges after traversing children, as we
13008 do here, means that recording a parent's ranges entails
13009 walking across all its children's ranges as they appear in
13010 the address map, which is quadratic behavior.
13012 It would be nicer to record the parent's ranges before
13013 traversing its children, simply overriding whatever you find
13014 there. But since we don't even decide whether to create a
13015 block until after we've traversed its children, that's hard
13017 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13019 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13020 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13023 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13026 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13028 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13029 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13030 CORE_ADDR pc
, baseaddr
;
13031 struct attribute
*attr
;
13032 struct call_site
*call_site
, call_site_local
;
13035 struct die_info
*child_die
;
13037 baseaddr
= objfile
->text_section_offset ();
13039 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13042 /* This was a pre-DWARF-5 GNU extension alias
13043 for DW_AT_call_return_pc. */
13044 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13048 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13049 "DIE %s [in module %s]"),
13050 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13053 pc
= attr
->value_as_address () + baseaddr
;
13054 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13056 if (cu
->call_site_htab
== NULL
)
13057 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13058 NULL
, &objfile
->objfile_obstack
,
13059 hashtab_obstack_allocate
, NULL
);
13060 call_site_local
.pc
= pc
;
13061 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13064 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13065 "DIE %s [in module %s]"),
13066 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13067 objfile_name (objfile
));
13071 /* Count parameters at the caller. */
13074 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13075 child_die
= child_die
->sibling
)
13077 if (child_die
->tag
!= DW_TAG_call_site_parameter
13078 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13080 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13081 "DW_TAG_call_site child DIE %s [in module %s]"),
13082 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13083 objfile_name (objfile
));
13091 = ((struct call_site
*)
13092 obstack_alloc (&objfile
->objfile_obstack
,
13093 sizeof (*call_site
)
13094 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13096 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13097 call_site
->pc
= pc
;
13099 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13100 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13102 struct die_info
*func_die
;
13104 /* Skip also over DW_TAG_inlined_subroutine. */
13105 for (func_die
= die
->parent
;
13106 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13107 && func_die
->tag
!= DW_TAG_subroutine_type
;
13108 func_die
= func_die
->parent
);
13110 /* DW_AT_call_all_calls is a superset
13111 of DW_AT_call_all_tail_calls. */
13113 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13114 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13115 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13116 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13118 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13119 not complete. But keep CALL_SITE for look ups via call_site_htab,
13120 both the initial caller containing the real return address PC and
13121 the final callee containing the current PC of a chain of tail
13122 calls do not need to have the tail call list complete. But any
13123 function candidate for a virtual tail call frame searched via
13124 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13125 determined unambiguously. */
13129 struct type
*func_type
= NULL
;
13132 func_type
= get_die_type (func_die
, cu
);
13133 if (func_type
!= NULL
)
13135 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13137 /* Enlist this call site to the function. */
13138 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13139 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13142 complaint (_("Cannot find function owning DW_TAG_call_site "
13143 "DIE %s [in module %s]"),
13144 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13148 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13150 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13152 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13155 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13156 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13158 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13159 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13160 /* Keep NULL DWARF_BLOCK. */;
13161 else if (attr
->form_is_block ())
13163 struct dwarf2_locexpr_baton
*dlbaton
;
13165 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13166 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13167 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13168 dlbaton
->per_cu
= cu
->per_cu
;
13170 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13172 else if (attr
->form_is_ref ())
13174 struct dwarf2_cu
*target_cu
= cu
;
13175 struct die_info
*target_die
;
13177 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13178 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13179 if (die_is_declaration (target_die
, target_cu
))
13181 const char *target_physname
;
13183 /* Prefer the mangled name; otherwise compute the demangled one. */
13184 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13185 if (target_physname
== NULL
)
13186 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13187 if (target_physname
== NULL
)
13188 complaint (_("DW_AT_call_target target DIE has invalid "
13189 "physname, for referencing DIE %s [in module %s]"),
13190 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13192 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13198 /* DW_AT_entry_pc should be preferred. */
13199 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13200 <= PC_BOUNDS_INVALID
)
13201 complaint (_("DW_AT_call_target target DIE has invalid "
13202 "low pc, for referencing DIE %s [in module %s]"),
13203 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13206 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13207 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13212 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13213 "block nor reference, for DIE %s [in module %s]"),
13214 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13216 call_site
->per_cu
= cu
->per_cu
;
13218 for (child_die
= die
->child
;
13219 child_die
&& child_die
->tag
;
13220 child_die
= child_die
->sibling
)
13222 struct call_site_parameter
*parameter
;
13223 struct attribute
*loc
, *origin
;
13225 if (child_die
->tag
!= DW_TAG_call_site_parameter
13226 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13228 /* Already printed the complaint above. */
13232 gdb_assert (call_site
->parameter_count
< nparams
);
13233 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13235 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13236 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13237 register is contained in DW_AT_call_value. */
13239 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13240 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13241 if (origin
== NULL
)
13243 /* This was a pre-DWARF-5 GNU extension alias
13244 for DW_AT_call_parameter. */
13245 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13247 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13249 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13251 sect_offset sect_off
= origin
->get_ref_die_offset ();
13252 if (!cu
->header
.offset_in_cu_p (sect_off
))
13254 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13255 binding can be done only inside one CU. Such referenced DIE
13256 therefore cannot be even moved to DW_TAG_partial_unit. */
13257 complaint (_("DW_AT_call_parameter offset is not in CU for "
13258 "DW_TAG_call_site child DIE %s [in module %s]"),
13259 sect_offset_str (child_die
->sect_off
),
13260 objfile_name (objfile
));
13263 parameter
->u
.param_cu_off
13264 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13266 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13268 complaint (_("No DW_FORM_block* DW_AT_location for "
13269 "DW_TAG_call_site child DIE %s [in module %s]"),
13270 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13275 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13276 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13277 if (parameter
->u
.dwarf_reg
!= -1)
13278 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13279 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13280 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13281 ¶meter
->u
.fb_offset
))
13282 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13285 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13286 "for DW_FORM_block* DW_AT_location is supported for "
13287 "DW_TAG_call_site child DIE %s "
13289 sect_offset_str (child_die
->sect_off
),
13290 objfile_name (objfile
));
13295 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13297 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13298 if (attr
== NULL
|| !attr
->form_is_block ())
13300 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13301 "DW_TAG_call_site child DIE %s [in module %s]"),
13302 sect_offset_str (child_die
->sect_off
),
13303 objfile_name (objfile
));
13306 parameter
->value
= DW_BLOCK (attr
)->data
;
13307 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13309 /* Parameters are not pre-cleared by memset above. */
13310 parameter
->data_value
= NULL
;
13311 parameter
->data_value_size
= 0;
13312 call_site
->parameter_count
++;
13314 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13316 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13317 if (attr
!= nullptr)
13319 if (!attr
->form_is_block ())
13320 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13321 "DW_TAG_call_site child DIE %s [in module %s]"),
13322 sect_offset_str (child_die
->sect_off
),
13323 objfile_name (objfile
));
13326 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13327 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13333 /* Helper function for read_variable. If DIE represents a virtual
13334 table, then return the type of the concrete object that is
13335 associated with the virtual table. Otherwise, return NULL. */
13337 static struct type
*
13338 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13340 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13344 /* Find the type DIE. */
13345 struct die_info
*type_die
= NULL
;
13346 struct dwarf2_cu
*type_cu
= cu
;
13348 if (attr
->form_is_ref ())
13349 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13350 if (type_die
== NULL
)
13353 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13355 return die_containing_type (type_die
, type_cu
);
13358 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13361 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13363 struct rust_vtable_symbol
*storage
= NULL
;
13365 if (cu
->language
== language_rust
)
13367 struct type
*containing_type
= rust_containing_type (die
, cu
);
13369 if (containing_type
!= NULL
)
13371 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13373 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13374 initialize_objfile_symbol (storage
);
13375 storage
->concrete_type
= containing_type
;
13376 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13380 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13381 struct attribute
*abstract_origin
13382 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13383 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13384 if (res
== NULL
&& loc
&& abstract_origin
)
13386 /* We have a variable without a name, but with a location and an abstract
13387 origin. This may be a concrete instance of an abstract variable
13388 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13390 struct dwarf2_cu
*origin_cu
= cu
;
13391 struct die_info
*origin_die
13392 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13393 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13394 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13398 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13399 reading .debug_rnglists.
13400 Callback's type should be:
13401 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13402 Return true if the attributes are present and valid, otherwise,
13405 template <typename Callback
>
13407 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13408 Callback
&&callback
)
13410 struct dwarf2_per_objfile
*dwarf2_per_objfile
13411 = cu
->per_cu
->dwarf2_per_objfile
;
13412 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13413 bfd
*obfd
= objfile
->obfd
;
13414 /* Base address selection entry. */
13415 gdb::optional
<CORE_ADDR
> base
;
13416 const gdb_byte
*buffer
;
13417 CORE_ADDR baseaddr
;
13418 bool overflow
= false;
13420 base
= cu
->base_address
;
13422 dwarf2_per_objfile
->rnglists
.read (objfile
);
13423 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13425 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13429 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13431 baseaddr
= objfile
->text_section_offset ();
13435 /* Initialize it due to a false compiler warning. */
13436 CORE_ADDR range_beginning
= 0, range_end
= 0;
13437 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13438 + dwarf2_per_objfile
->rnglists
.size
);
13439 unsigned int bytes_read
;
13441 if (buffer
== buf_end
)
13446 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13449 case DW_RLE_end_of_list
:
13451 case DW_RLE_base_address
:
13452 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13457 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13458 buffer
+= bytes_read
;
13460 case DW_RLE_start_length
:
13461 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13466 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13468 buffer
+= bytes_read
;
13469 range_end
= (range_beginning
13470 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13471 buffer
+= bytes_read
;
13472 if (buffer
> buf_end
)
13478 case DW_RLE_offset_pair
:
13479 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13480 buffer
+= bytes_read
;
13481 if (buffer
> buf_end
)
13486 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13487 buffer
+= bytes_read
;
13488 if (buffer
> buf_end
)
13494 case DW_RLE_start_end
:
13495 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13500 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13502 buffer
+= bytes_read
;
13503 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13504 buffer
+= bytes_read
;
13507 complaint (_("Invalid .debug_rnglists data (no base address)"));
13510 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13512 if (rlet
== DW_RLE_base_address
)
13515 if (!base
.has_value ())
13517 /* We have no valid base address for the ranges
13519 complaint (_("Invalid .debug_rnglists data (no base address)"));
13523 if (range_beginning
> range_end
)
13525 /* Inverted range entries are invalid. */
13526 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13530 /* Empty range entries have no effect. */
13531 if (range_beginning
== range_end
)
13534 range_beginning
+= *base
;
13535 range_end
+= *base
;
13537 /* A not-uncommon case of bad debug info.
13538 Don't pollute the addrmap with bad data. */
13539 if (range_beginning
+ baseaddr
== 0
13540 && !dwarf2_per_objfile
->has_section_at_zero
)
13542 complaint (_(".debug_rnglists entry has start address of zero"
13543 " [in module %s]"), objfile_name (objfile
));
13547 callback (range_beginning
, range_end
);
13552 complaint (_("Offset %d is not terminated "
13553 "for DW_AT_ranges attribute"),
13561 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13562 Callback's type should be:
13563 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13564 Return 1 if the attributes are present and valid, otherwise, return 0. */
13566 template <typename Callback
>
13568 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13569 Callback
&&callback
)
13571 struct dwarf2_per_objfile
*dwarf2_per_objfile
13572 = cu
->per_cu
->dwarf2_per_objfile
;
13573 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13574 struct comp_unit_head
*cu_header
= &cu
->header
;
13575 bfd
*obfd
= objfile
->obfd
;
13576 unsigned int addr_size
= cu_header
->addr_size
;
13577 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13578 /* Base address selection entry. */
13579 gdb::optional
<CORE_ADDR
> base
;
13580 unsigned int dummy
;
13581 const gdb_byte
*buffer
;
13582 CORE_ADDR baseaddr
;
13584 if (cu_header
->version
>= 5)
13585 return dwarf2_rnglists_process (offset
, cu
, callback
);
13587 base
= cu
->base_address
;
13589 dwarf2_per_objfile
->ranges
.read (objfile
);
13590 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13592 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13596 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13598 baseaddr
= objfile
->text_section_offset ();
13602 CORE_ADDR range_beginning
, range_end
;
13604 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13605 buffer
+= addr_size
;
13606 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13607 buffer
+= addr_size
;
13608 offset
+= 2 * addr_size
;
13610 /* An end of list marker is a pair of zero addresses. */
13611 if (range_beginning
== 0 && range_end
== 0)
13612 /* Found the end of list entry. */
13615 /* Each base address selection entry is a pair of 2 values.
13616 The first is the largest possible address, the second is
13617 the base address. Check for a base address here. */
13618 if ((range_beginning
& mask
) == mask
)
13620 /* If we found the largest possible address, then we already
13621 have the base address in range_end. */
13626 if (!base
.has_value ())
13628 /* We have no valid base address for the ranges
13630 complaint (_("Invalid .debug_ranges data (no base address)"));
13634 if (range_beginning
> range_end
)
13636 /* Inverted range entries are invalid. */
13637 complaint (_("Invalid .debug_ranges data (inverted range)"));
13641 /* Empty range entries have no effect. */
13642 if (range_beginning
== range_end
)
13645 range_beginning
+= *base
;
13646 range_end
+= *base
;
13648 /* A not-uncommon case of bad debug info.
13649 Don't pollute the addrmap with bad data. */
13650 if (range_beginning
+ baseaddr
== 0
13651 && !dwarf2_per_objfile
->has_section_at_zero
)
13653 complaint (_(".debug_ranges entry has start address of zero"
13654 " [in module %s]"), objfile_name (objfile
));
13658 callback (range_beginning
, range_end
);
13664 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13665 Return 1 if the attributes are present and valid, otherwise, return 0.
13666 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13669 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13670 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13671 dwarf2_psymtab
*ranges_pst
)
13673 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13674 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13675 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13678 CORE_ADDR high
= 0;
13681 retval
= dwarf2_ranges_process (offset
, cu
,
13682 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13684 if (ranges_pst
!= NULL
)
13689 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13690 range_beginning
+ baseaddr
)
13692 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13693 range_end
+ baseaddr
)
13695 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13696 lowpc
, highpc
- 1, ranges_pst
);
13699 /* FIXME: This is recording everything as a low-high
13700 segment of consecutive addresses. We should have a
13701 data structure for discontiguous block ranges
13705 low
= range_beginning
;
13711 if (range_beginning
< low
)
13712 low
= range_beginning
;
13713 if (range_end
> high
)
13721 /* If the first entry is an end-of-list marker, the range
13722 describes an empty scope, i.e. no instructions. */
13728 *high_return
= high
;
13732 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13733 definition for the return value. *LOWPC and *HIGHPC are set iff
13734 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13736 static enum pc_bounds_kind
13737 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13738 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13739 dwarf2_psymtab
*pst
)
13741 struct dwarf2_per_objfile
*dwarf2_per_objfile
13742 = cu
->per_cu
->dwarf2_per_objfile
;
13743 struct attribute
*attr
;
13744 struct attribute
*attr_high
;
13746 CORE_ADDR high
= 0;
13747 enum pc_bounds_kind ret
;
13749 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13752 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13753 if (attr
!= nullptr)
13755 low
= attr
->value_as_address ();
13756 high
= attr_high
->value_as_address ();
13757 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13761 /* Found high w/o low attribute. */
13762 return PC_BOUNDS_INVALID
;
13764 /* Found consecutive range of addresses. */
13765 ret
= PC_BOUNDS_HIGH_LOW
;
13769 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13772 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13773 We take advantage of the fact that DW_AT_ranges does not appear
13774 in DW_TAG_compile_unit of DWO files. */
13775 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13776 unsigned int ranges_offset
= (DW_UNSND (attr
)
13777 + (need_ranges_base
13781 /* Value of the DW_AT_ranges attribute is the offset in the
13782 .debug_ranges section. */
13783 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13784 return PC_BOUNDS_INVALID
;
13785 /* Found discontinuous range of addresses. */
13786 ret
= PC_BOUNDS_RANGES
;
13789 return PC_BOUNDS_NOT_PRESENT
;
13792 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13794 return PC_BOUNDS_INVALID
;
13796 /* When using the GNU linker, .gnu.linkonce. sections are used to
13797 eliminate duplicate copies of functions and vtables and such.
13798 The linker will arbitrarily choose one and discard the others.
13799 The AT_*_pc values for such functions refer to local labels in
13800 these sections. If the section from that file was discarded, the
13801 labels are not in the output, so the relocs get a value of 0.
13802 If this is a discarded function, mark the pc bounds as invalid,
13803 so that GDB will ignore it. */
13804 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13805 return PC_BOUNDS_INVALID
;
13813 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13814 its low and high PC addresses. Do nothing if these addresses could not
13815 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13816 and HIGHPC to the high address if greater than HIGHPC. */
13819 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13820 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13821 struct dwarf2_cu
*cu
)
13823 CORE_ADDR low
, high
;
13824 struct die_info
*child
= die
->child
;
13826 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13828 *lowpc
= std::min (*lowpc
, low
);
13829 *highpc
= std::max (*highpc
, high
);
13832 /* If the language does not allow nested subprograms (either inside
13833 subprograms or lexical blocks), we're done. */
13834 if (cu
->language
!= language_ada
)
13837 /* Check all the children of the given DIE. If it contains nested
13838 subprograms, then check their pc bounds. Likewise, we need to
13839 check lexical blocks as well, as they may also contain subprogram
13841 while (child
&& child
->tag
)
13843 if (child
->tag
== DW_TAG_subprogram
13844 || child
->tag
== DW_TAG_lexical_block
)
13845 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13846 child
= child
->sibling
;
13850 /* Get the low and high pc's represented by the scope DIE, and store
13851 them in *LOWPC and *HIGHPC. If the correct values can't be
13852 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13855 get_scope_pc_bounds (struct die_info
*die
,
13856 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13857 struct dwarf2_cu
*cu
)
13859 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13860 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13861 CORE_ADDR current_low
, current_high
;
13863 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13864 >= PC_BOUNDS_RANGES
)
13866 best_low
= current_low
;
13867 best_high
= current_high
;
13871 struct die_info
*child
= die
->child
;
13873 while (child
&& child
->tag
)
13875 switch (child
->tag
) {
13876 case DW_TAG_subprogram
:
13877 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13879 case DW_TAG_namespace
:
13880 case DW_TAG_module
:
13881 /* FIXME: carlton/2004-01-16: Should we do this for
13882 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13883 that current GCC's always emit the DIEs corresponding
13884 to definitions of methods of classes as children of a
13885 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13886 the DIEs giving the declarations, which could be
13887 anywhere). But I don't see any reason why the
13888 standards says that they have to be there. */
13889 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13891 if (current_low
!= ((CORE_ADDR
) -1))
13893 best_low
= std::min (best_low
, current_low
);
13894 best_high
= std::max (best_high
, current_high
);
13902 child
= child
->sibling
;
13907 *highpc
= best_high
;
13910 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13914 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13915 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13917 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13918 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13919 struct attribute
*attr
;
13920 struct attribute
*attr_high
;
13922 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13925 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13926 if (attr
!= nullptr)
13928 CORE_ADDR low
= attr
->value_as_address ();
13929 CORE_ADDR high
= attr_high
->value_as_address ();
13931 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13934 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13935 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13936 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13940 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13941 if (attr
!= nullptr)
13943 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13944 We take advantage of the fact that DW_AT_ranges does not appear
13945 in DW_TAG_compile_unit of DWO files. */
13946 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13948 /* The value of the DW_AT_ranges attribute is the offset of the
13949 address range list in the .debug_ranges section. */
13950 unsigned long offset
= (DW_UNSND (attr
)
13951 + (need_ranges_base
? cu
->ranges_base
: 0));
13953 std::vector
<blockrange
> blockvec
;
13954 dwarf2_ranges_process (offset
, cu
,
13955 [&] (CORE_ADDR start
, CORE_ADDR end
)
13959 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13960 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13961 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13962 blockvec
.emplace_back (start
, end
);
13965 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13969 /* Check whether the producer field indicates either of GCC < 4.6, or the
13970 Intel C/C++ compiler, and cache the result in CU. */
13973 check_producer (struct dwarf2_cu
*cu
)
13977 if (cu
->producer
== NULL
)
13979 /* For unknown compilers expect their behavior is DWARF version
13982 GCC started to support .debug_types sections by -gdwarf-4 since
13983 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13984 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13985 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13986 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13988 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13990 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13991 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13993 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13995 cu
->producer_is_icc
= true;
13996 cu
->producer_is_icc_lt_14
= major
< 14;
13998 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13999 cu
->producer_is_codewarrior
= true;
14002 /* For other non-GCC compilers, expect their behavior is DWARF version
14006 cu
->checked_producer
= true;
14009 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14010 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14011 during 4.6.0 experimental. */
14014 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14016 if (!cu
->checked_producer
)
14017 check_producer (cu
);
14019 return cu
->producer_is_gxx_lt_4_6
;
14023 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14024 with incorrect is_stmt attributes. */
14027 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14029 if (!cu
->checked_producer
)
14030 check_producer (cu
);
14032 return cu
->producer_is_codewarrior
;
14035 /* Return the default accessibility type if it is not overridden by
14036 DW_AT_accessibility. */
14038 static enum dwarf_access_attribute
14039 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14041 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14043 /* The default DWARF 2 accessibility for members is public, the default
14044 accessibility for inheritance is private. */
14046 if (die
->tag
!= DW_TAG_inheritance
)
14047 return DW_ACCESS_public
;
14049 return DW_ACCESS_private
;
14053 /* DWARF 3+ defines the default accessibility a different way. The same
14054 rules apply now for DW_TAG_inheritance as for the members and it only
14055 depends on the container kind. */
14057 if (die
->parent
->tag
== DW_TAG_class_type
)
14058 return DW_ACCESS_private
;
14060 return DW_ACCESS_public
;
14064 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14065 offset. If the attribute was not found return 0, otherwise return
14066 1. If it was found but could not properly be handled, set *OFFSET
14070 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14073 struct attribute
*attr
;
14075 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14080 /* Note that we do not check for a section offset first here.
14081 This is because DW_AT_data_member_location is new in DWARF 4,
14082 so if we see it, we can assume that a constant form is really
14083 a constant and not a section offset. */
14084 if (attr
->form_is_constant ())
14085 *offset
= attr
->constant_value (0);
14086 else if (attr
->form_is_section_offset ())
14087 dwarf2_complex_location_expr_complaint ();
14088 else if (attr
->form_is_block ())
14089 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14091 dwarf2_complex_location_expr_complaint ();
14099 /* Add an aggregate field to the field list. */
14102 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14103 struct dwarf2_cu
*cu
)
14105 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14106 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14107 struct nextfield
*new_field
;
14108 struct attribute
*attr
;
14110 const char *fieldname
= "";
14112 if (die
->tag
== DW_TAG_inheritance
)
14114 fip
->baseclasses
.emplace_back ();
14115 new_field
= &fip
->baseclasses
.back ();
14119 fip
->fields
.emplace_back ();
14120 new_field
= &fip
->fields
.back ();
14123 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14124 if (attr
!= nullptr)
14125 new_field
->accessibility
= DW_UNSND (attr
);
14127 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14128 if (new_field
->accessibility
!= DW_ACCESS_public
)
14129 fip
->non_public_fields
= 1;
14131 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14132 if (attr
!= nullptr)
14133 new_field
->virtuality
= DW_UNSND (attr
);
14135 new_field
->virtuality
= DW_VIRTUALITY_none
;
14137 fp
= &new_field
->field
;
14139 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14143 /* Data member other than a C++ static data member. */
14145 /* Get type of field. */
14146 fp
->type
= die_type (die
, cu
);
14148 SET_FIELD_BITPOS (*fp
, 0);
14150 /* Get bit size of field (zero if none). */
14151 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14152 if (attr
!= nullptr)
14154 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14158 FIELD_BITSIZE (*fp
) = 0;
14161 /* Get bit offset of field. */
14162 if (handle_data_member_location (die
, cu
, &offset
))
14163 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14164 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14165 if (attr
!= nullptr)
14167 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14169 /* For big endian bits, the DW_AT_bit_offset gives the
14170 additional bit offset from the MSB of the containing
14171 anonymous object to the MSB of the field. We don't
14172 have to do anything special since we don't need to
14173 know the size of the anonymous object. */
14174 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14178 /* For little endian bits, compute the bit offset to the
14179 MSB of the anonymous object, subtract off the number of
14180 bits from the MSB of the field to the MSB of the
14181 object, and then subtract off the number of bits of
14182 the field itself. The result is the bit offset of
14183 the LSB of the field. */
14184 int anonymous_size
;
14185 int bit_offset
= DW_UNSND (attr
);
14187 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14188 if (attr
!= nullptr)
14190 /* The size of the anonymous object containing
14191 the bit field is explicit, so use the
14192 indicated size (in bytes). */
14193 anonymous_size
= DW_UNSND (attr
);
14197 /* The size of the anonymous object containing
14198 the bit field must be inferred from the type
14199 attribute of the data member containing the
14201 anonymous_size
= TYPE_LENGTH (fp
->type
);
14203 SET_FIELD_BITPOS (*fp
,
14204 (FIELD_BITPOS (*fp
)
14205 + anonymous_size
* bits_per_byte
14206 - bit_offset
- FIELD_BITSIZE (*fp
)));
14209 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14211 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14212 + attr
->constant_value (0)));
14214 /* Get name of field. */
14215 fieldname
= dwarf2_name (die
, cu
);
14216 if (fieldname
== NULL
)
14219 /* The name is already allocated along with this objfile, so we don't
14220 need to duplicate it for the type. */
14221 fp
->name
= fieldname
;
14223 /* Change accessibility for artificial fields (e.g. virtual table
14224 pointer or virtual base class pointer) to private. */
14225 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14227 FIELD_ARTIFICIAL (*fp
) = 1;
14228 new_field
->accessibility
= DW_ACCESS_private
;
14229 fip
->non_public_fields
= 1;
14232 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14234 /* C++ static member. */
14236 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14237 is a declaration, but all versions of G++ as of this writing
14238 (so through at least 3.2.1) incorrectly generate
14239 DW_TAG_variable tags. */
14241 const char *physname
;
14243 /* Get name of field. */
14244 fieldname
= dwarf2_name (die
, cu
);
14245 if (fieldname
== NULL
)
14248 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14250 /* Only create a symbol if this is an external value.
14251 new_symbol checks this and puts the value in the global symbol
14252 table, which we want. If it is not external, new_symbol
14253 will try to put the value in cu->list_in_scope which is wrong. */
14254 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14256 /* A static const member, not much different than an enum as far as
14257 we're concerned, except that we can support more types. */
14258 new_symbol (die
, NULL
, cu
);
14261 /* Get physical name. */
14262 physname
= dwarf2_physname (fieldname
, die
, cu
);
14264 /* The name is already allocated along with this objfile, so we don't
14265 need to duplicate it for the type. */
14266 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14267 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14268 FIELD_NAME (*fp
) = fieldname
;
14270 else if (die
->tag
== DW_TAG_inheritance
)
14274 /* C++ base class field. */
14275 if (handle_data_member_location (die
, cu
, &offset
))
14276 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14277 FIELD_BITSIZE (*fp
) = 0;
14278 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14279 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14281 else if (die
->tag
== DW_TAG_variant_part
)
14283 /* process_structure_scope will treat this DIE as a union. */
14284 process_structure_scope (die
, cu
);
14286 /* The variant part is relative to the start of the enclosing
14288 SET_FIELD_BITPOS (*fp
, 0);
14289 fp
->type
= get_die_type (die
, cu
);
14290 fp
->artificial
= 1;
14291 fp
->name
= "<<variant>>";
14293 /* Normally a DW_TAG_variant_part won't have a size, but our
14294 representation requires one, so set it to the maximum of the
14295 child sizes, being sure to account for the offset at which
14296 each child is seen. */
14297 if (TYPE_LENGTH (fp
->type
) == 0)
14300 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14302 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14303 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14307 TYPE_LENGTH (fp
->type
) = max
;
14311 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14314 /* Can the type given by DIE define another type? */
14317 type_can_define_types (const struct die_info
*die
)
14321 case DW_TAG_typedef
:
14322 case DW_TAG_class_type
:
14323 case DW_TAG_structure_type
:
14324 case DW_TAG_union_type
:
14325 case DW_TAG_enumeration_type
:
14333 /* Add a type definition defined in the scope of the FIP's class. */
14336 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14337 struct dwarf2_cu
*cu
)
14339 struct decl_field fp
;
14340 memset (&fp
, 0, sizeof (fp
));
14342 gdb_assert (type_can_define_types (die
));
14344 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14345 fp
.name
= dwarf2_name (die
, cu
);
14346 fp
.type
= read_type_die (die
, cu
);
14348 /* Save accessibility. */
14349 enum dwarf_access_attribute accessibility
;
14350 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14352 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14354 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14355 switch (accessibility
)
14357 case DW_ACCESS_public
:
14358 /* The assumed value if neither private nor protected. */
14360 case DW_ACCESS_private
:
14363 case DW_ACCESS_protected
:
14364 fp
.is_protected
= 1;
14367 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14370 if (die
->tag
== DW_TAG_typedef
)
14371 fip
->typedef_field_list
.push_back (fp
);
14373 fip
->nested_types_list
.push_back (fp
);
14376 /* Create the vector of fields, and attach it to the type. */
14379 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14380 struct dwarf2_cu
*cu
)
14382 int nfields
= fip
->nfields ();
14384 /* Record the field count, allocate space for the array of fields,
14385 and create blank accessibility bitfields if necessary. */
14386 TYPE_NFIELDS (type
) = nfields
;
14387 TYPE_FIELDS (type
) = (struct field
*)
14388 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14390 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14392 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14394 TYPE_FIELD_PRIVATE_BITS (type
) =
14395 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14396 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14398 TYPE_FIELD_PROTECTED_BITS (type
) =
14399 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14400 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14402 TYPE_FIELD_IGNORE_BITS (type
) =
14403 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14404 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14407 /* If the type has baseclasses, allocate and clear a bit vector for
14408 TYPE_FIELD_VIRTUAL_BITS. */
14409 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14411 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14412 unsigned char *pointer
;
14414 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14415 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14416 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14417 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14418 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14421 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14423 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14425 for (int index
= 0; index
< nfields
; ++index
)
14427 struct nextfield
&field
= fip
->fields
[index
];
14429 if (field
.variant
.is_discriminant
)
14430 di
->discriminant_index
= index
;
14431 else if (field
.variant
.default_branch
)
14432 di
->default_index
= index
;
14434 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14438 /* Copy the saved-up fields into the field vector. */
14439 for (int i
= 0; i
< nfields
; ++i
)
14441 struct nextfield
&field
14442 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14443 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14445 TYPE_FIELD (type
, i
) = field
.field
;
14446 switch (field
.accessibility
)
14448 case DW_ACCESS_private
:
14449 if (cu
->language
!= language_ada
)
14450 SET_TYPE_FIELD_PRIVATE (type
, i
);
14453 case DW_ACCESS_protected
:
14454 if (cu
->language
!= language_ada
)
14455 SET_TYPE_FIELD_PROTECTED (type
, i
);
14458 case DW_ACCESS_public
:
14462 /* Unknown accessibility. Complain and treat it as public. */
14464 complaint (_("unsupported accessibility %d"),
14465 field
.accessibility
);
14469 if (i
< fip
->baseclasses
.size ())
14471 switch (field
.virtuality
)
14473 case DW_VIRTUALITY_virtual
:
14474 case DW_VIRTUALITY_pure_virtual
:
14475 if (cu
->language
== language_ada
)
14476 error (_("unexpected virtuality in component of Ada type"));
14477 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14484 /* Return true if this member function is a constructor, false
14488 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14490 const char *fieldname
;
14491 const char *type_name
;
14494 if (die
->parent
== NULL
)
14497 if (die
->parent
->tag
!= DW_TAG_structure_type
14498 && die
->parent
->tag
!= DW_TAG_union_type
14499 && die
->parent
->tag
!= DW_TAG_class_type
)
14502 fieldname
= dwarf2_name (die
, cu
);
14503 type_name
= dwarf2_name (die
->parent
, cu
);
14504 if (fieldname
== NULL
|| type_name
== NULL
)
14507 len
= strlen (fieldname
);
14508 return (strncmp (fieldname
, type_name
, len
) == 0
14509 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14512 /* Check if the given VALUE is a recognized enum
14513 dwarf_defaulted_attribute constant according to DWARF5 spec,
14517 is_valid_DW_AT_defaulted (ULONGEST value
)
14521 case DW_DEFAULTED_no
:
14522 case DW_DEFAULTED_in_class
:
14523 case DW_DEFAULTED_out_of_class
:
14527 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14531 /* Add a member function to the proper fieldlist. */
14534 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14535 struct type
*type
, struct dwarf2_cu
*cu
)
14537 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14538 struct attribute
*attr
;
14540 struct fnfieldlist
*flp
= nullptr;
14541 struct fn_field
*fnp
;
14542 const char *fieldname
;
14543 struct type
*this_type
;
14544 enum dwarf_access_attribute accessibility
;
14546 if (cu
->language
== language_ada
)
14547 error (_("unexpected member function in Ada type"));
14549 /* Get name of member function. */
14550 fieldname
= dwarf2_name (die
, cu
);
14551 if (fieldname
== NULL
)
14554 /* Look up member function name in fieldlist. */
14555 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14557 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14559 flp
= &fip
->fnfieldlists
[i
];
14564 /* Create a new fnfieldlist if necessary. */
14565 if (flp
== nullptr)
14567 fip
->fnfieldlists
.emplace_back ();
14568 flp
= &fip
->fnfieldlists
.back ();
14569 flp
->name
= fieldname
;
14570 i
= fip
->fnfieldlists
.size () - 1;
14573 /* Create a new member function field and add it to the vector of
14575 flp
->fnfields
.emplace_back ();
14576 fnp
= &flp
->fnfields
.back ();
14578 /* Delay processing of the physname until later. */
14579 if (cu
->language
== language_cplus
)
14580 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14584 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14585 fnp
->physname
= physname
? physname
: "";
14588 fnp
->type
= alloc_type (objfile
);
14589 this_type
= read_type_die (die
, cu
);
14590 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14592 int nparams
= TYPE_NFIELDS (this_type
);
14594 /* TYPE is the domain of this method, and THIS_TYPE is the type
14595 of the method itself (TYPE_CODE_METHOD). */
14596 smash_to_method_type (fnp
->type
, type
,
14597 TYPE_TARGET_TYPE (this_type
),
14598 TYPE_FIELDS (this_type
),
14599 TYPE_NFIELDS (this_type
),
14600 TYPE_VARARGS (this_type
));
14602 /* Handle static member functions.
14603 Dwarf2 has no clean way to discern C++ static and non-static
14604 member functions. G++ helps GDB by marking the first
14605 parameter for non-static member functions (which is the this
14606 pointer) as artificial. We obtain this information from
14607 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14608 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14609 fnp
->voffset
= VOFFSET_STATIC
;
14612 complaint (_("member function type missing for '%s'"),
14613 dwarf2_full_name (fieldname
, die
, cu
));
14615 /* Get fcontext from DW_AT_containing_type if present. */
14616 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14617 fnp
->fcontext
= die_containing_type (die
, cu
);
14619 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14620 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14622 /* Get accessibility. */
14623 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14624 if (attr
!= nullptr)
14625 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14627 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14628 switch (accessibility
)
14630 case DW_ACCESS_private
:
14631 fnp
->is_private
= 1;
14633 case DW_ACCESS_protected
:
14634 fnp
->is_protected
= 1;
14638 /* Check for artificial methods. */
14639 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14640 if (attr
&& DW_UNSND (attr
) != 0)
14641 fnp
->is_artificial
= 1;
14643 /* Check for defaulted methods. */
14644 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14645 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14646 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14648 /* Check for deleted methods. */
14649 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14650 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14651 fnp
->is_deleted
= 1;
14653 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14655 /* Get index in virtual function table if it is a virtual member
14656 function. For older versions of GCC, this is an offset in the
14657 appropriate virtual table, as specified by DW_AT_containing_type.
14658 For everyone else, it is an expression to be evaluated relative
14659 to the object address. */
14661 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14662 if (attr
!= nullptr)
14664 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14666 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14668 /* Old-style GCC. */
14669 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14671 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14672 || (DW_BLOCK (attr
)->size
> 1
14673 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14674 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14676 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14677 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14678 dwarf2_complex_location_expr_complaint ();
14680 fnp
->voffset
/= cu
->header
.addr_size
;
14684 dwarf2_complex_location_expr_complaint ();
14686 if (!fnp
->fcontext
)
14688 /* If there is no `this' field and no DW_AT_containing_type,
14689 we cannot actually find a base class context for the
14691 if (TYPE_NFIELDS (this_type
) == 0
14692 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14694 complaint (_("cannot determine context for virtual member "
14695 "function \"%s\" (offset %s)"),
14696 fieldname
, sect_offset_str (die
->sect_off
));
14701 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14705 else if (attr
->form_is_section_offset ())
14707 dwarf2_complex_location_expr_complaint ();
14711 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14717 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14718 if (attr
&& DW_UNSND (attr
))
14720 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14721 complaint (_("Member function \"%s\" (offset %s) is virtual "
14722 "but the vtable offset is not specified"),
14723 fieldname
, sect_offset_str (die
->sect_off
));
14724 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14725 TYPE_CPLUS_DYNAMIC (type
) = 1;
14730 /* Create the vector of member function fields, and attach it to the type. */
14733 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14734 struct dwarf2_cu
*cu
)
14736 if (cu
->language
== language_ada
)
14737 error (_("unexpected member functions in Ada type"));
14739 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14740 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14742 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14744 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14746 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14747 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14749 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14750 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14751 fn_flp
->fn_fields
= (struct fn_field
*)
14752 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14754 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14755 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14758 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14761 /* Returns non-zero if NAME is the name of a vtable member in CU's
14762 language, zero otherwise. */
14764 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14766 static const char vptr
[] = "_vptr";
14768 /* Look for the C++ form of the vtable. */
14769 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14775 /* GCC outputs unnamed structures that are really pointers to member
14776 functions, with the ABI-specified layout. If TYPE describes
14777 such a structure, smash it into a member function type.
14779 GCC shouldn't do this; it should just output pointer to member DIEs.
14780 This is GCC PR debug/28767. */
14783 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14785 struct type
*pfn_type
, *self_type
, *new_type
;
14787 /* Check for a structure with no name and two children. */
14788 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14791 /* Check for __pfn and __delta members. */
14792 if (TYPE_FIELD_NAME (type
, 0) == NULL
14793 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14794 || TYPE_FIELD_NAME (type
, 1) == NULL
14795 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14798 /* Find the type of the method. */
14799 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14800 if (pfn_type
== NULL
14801 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14802 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14805 /* Look for the "this" argument. */
14806 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14807 if (TYPE_NFIELDS (pfn_type
) == 0
14808 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14809 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14812 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14813 new_type
= alloc_type (objfile
);
14814 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14815 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14816 TYPE_VARARGS (pfn_type
));
14817 smash_to_methodptr_type (type
, new_type
);
14820 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14821 appropriate error checking and issuing complaints if there is a
14825 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14827 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14829 if (attr
== nullptr)
14832 if (!attr
->form_is_constant ())
14834 complaint (_("DW_AT_alignment must have constant form"
14835 " - DIE at %s [in module %s]"),
14836 sect_offset_str (die
->sect_off
),
14837 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14842 if (attr
->form
== DW_FORM_sdata
)
14844 LONGEST val
= DW_SND (attr
);
14847 complaint (_("DW_AT_alignment value must not be negative"
14848 " - DIE at %s [in module %s]"),
14849 sect_offset_str (die
->sect_off
),
14850 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14856 align
= DW_UNSND (attr
);
14860 complaint (_("DW_AT_alignment value must not be zero"
14861 " - DIE at %s [in module %s]"),
14862 sect_offset_str (die
->sect_off
),
14863 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14866 if ((align
& (align
- 1)) != 0)
14868 complaint (_("DW_AT_alignment value must be a power of 2"
14869 " - DIE at %s [in module %s]"),
14870 sect_offset_str (die
->sect_off
),
14871 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14878 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14879 the alignment for TYPE. */
14882 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14885 if (!set_type_align (type
, get_alignment (cu
, die
)))
14886 complaint (_("DW_AT_alignment value too large"
14887 " - DIE at %s [in module %s]"),
14888 sect_offset_str (die
->sect_off
),
14889 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14892 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14893 constant for a type, according to DWARF5 spec, Table 5.5. */
14896 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14901 case DW_CC_pass_by_reference
:
14902 case DW_CC_pass_by_value
:
14906 complaint (_("unrecognized DW_AT_calling_convention value "
14907 "(%s) for a type"), pulongest (value
));
14912 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14913 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14914 also according to GNU-specific values (see include/dwarf2.h). */
14917 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14922 case DW_CC_program
:
14926 case DW_CC_GNU_renesas_sh
:
14927 case DW_CC_GNU_borland_fastcall_i386
:
14928 case DW_CC_GDB_IBM_OpenCL
:
14932 complaint (_("unrecognized DW_AT_calling_convention value "
14933 "(%s) for a subroutine"), pulongest (value
));
14938 /* Called when we find the DIE that starts a structure or union scope
14939 (definition) to create a type for the structure or union. Fill in
14940 the type's name and general properties; the members will not be
14941 processed until process_structure_scope. A symbol table entry for
14942 the type will also not be done until process_structure_scope (assuming
14943 the type has a name).
14945 NOTE: we need to call these functions regardless of whether or not the
14946 DIE has a DW_AT_name attribute, since it might be an anonymous
14947 structure or union. This gets the type entered into our set of
14948 user defined types. */
14950 static struct type
*
14951 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14953 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14955 struct attribute
*attr
;
14958 /* If the definition of this type lives in .debug_types, read that type.
14959 Don't follow DW_AT_specification though, that will take us back up
14960 the chain and we want to go down. */
14961 attr
= die
->attr (DW_AT_signature
);
14962 if (attr
!= nullptr)
14964 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14966 /* The type's CU may not be the same as CU.
14967 Ensure TYPE is recorded with CU in die_type_hash. */
14968 return set_die_type (die
, type
, cu
);
14971 type
= alloc_type (objfile
);
14972 INIT_CPLUS_SPECIFIC (type
);
14974 name
= dwarf2_name (die
, cu
);
14977 if (cu
->language
== language_cplus
14978 || cu
->language
== language_d
14979 || cu
->language
== language_rust
)
14981 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14983 /* dwarf2_full_name might have already finished building the DIE's
14984 type. If so, there is no need to continue. */
14985 if (get_die_type (die
, cu
) != NULL
)
14986 return get_die_type (die
, cu
);
14988 TYPE_NAME (type
) = full_name
;
14992 /* The name is already allocated along with this objfile, so
14993 we don't need to duplicate it for the type. */
14994 TYPE_NAME (type
) = name
;
14998 if (die
->tag
== DW_TAG_structure_type
)
15000 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15002 else if (die
->tag
== DW_TAG_union_type
)
15004 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15006 else if (die
->tag
== DW_TAG_variant_part
)
15008 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15009 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15013 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15016 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15017 TYPE_DECLARED_CLASS (type
) = 1;
15019 /* Store the calling convention in the type if it's available in
15020 the die. Otherwise the calling convention remains set to
15021 the default value DW_CC_normal. */
15022 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15023 if (attr
!= nullptr
15024 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15026 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15027 TYPE_CPLUS_CALLING_CONVENTION (type
)
15028 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15031 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15032 if (attr
!= nullptr)
15034 if (attr
->form_is_constant ())
15035 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15038 /* For the moment, dynamic type sizes are not supported
15039 by GDB's struct type. The actual size is determined
15040 on-demand when resolving the type of a given object,
15041 so set the type's length to zero for now. Otherwise,
15042 we record an expression as the length, and that expression
15043 could lead to a very large value, which could eventually
15044 lead to us trying to allocate that much memory when creating
15045 a value of that type. */
15046 TYPE_LENGTH (type
) = 0;
15051 TYPE_LENGTH (type
) = 0;
15054 maybe_set_alignment (cu
, die
, type
);
15056 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15058 /* ICC<14 does not output the required DW_AT_declaration on
15059 incomplete types, but gives them a size of zero. */
15060 TYPE_STUB (type
) = 1;
15063 TYPE_STUB_SUPPORTED (type
) = 1;
15065 if (die_is_declaration (die
, cu
))
15066 TYPE_STUB (type
) = 1;
15067 else if (attr
== NULL
&& die
->child
== NULL
15068 && producer_is_realview (cu
->producer
))
15069 /* RealView does not output the required DW_AT_declaration
15070 on incomplete types. */
15071 TYPE_STUB (type
) = 1;
15073 /* We need to add the type field to the die immediately so we don't
15074 infinitely recurse when dealing with pointers to the structure
15075 type within the structure itself. */
15076 set_die_type (die
, type
, cu
);
15078 /* set_die_type should be already done. */
15079 set_descriptive_type (type
, die
, cu
);
15084 /* A helper for process_structure_scope that handles a single member
15088 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15089 struct field_info
*fi
,
15090 std::vector
<struct symbol
*> *template_args
,
15091 struct dwarf2_cu
*cu
)
15093 if (child_die
->tag
== DW_TAG_member
15094 || child_die
->tag
== DW_TAG_variable
15095 || child_die
->tag
== DW_TAG_variant_part
)
15097 /* NOTE: carlton/2002-11-05: A C++ static data member
15098 should be a DW_TAG_member that is a declaration, but
15099 all versions of G++ as of this writing (so through at
15100 least 3.2.1) incorrectly generate DW_TAG_variable
15101 tags for them instead. */
15102 dwarf2_add_field (fi
, child_die
, cu
);
15104 else if (child_die
->tag
== DW_TAG_subprogram
)
15106 /* Rust doesn't have member functions in the C++ sense.
15107 However, it does emit ordinary functions as children
15108 of a struct DIE. */
15109 if (cu
->language
== language_rust
)
15110 read_func_scope (child_die
, cu
);
15113 /* C++ member function. */
15114 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15117 else if (child_die
->tag
== DW_TAG_inheritance
)
15119 /* C++ base class field. */
15120 dwarf2_add_field (fi
, child_die
, cu
);
15122 else if (type_can_define_types (child_die
))
15123 dwarf2_add_type_defn (fi
, child_die
, cu
);
15124 else if (child_die
->tag
== DW_TAG_template_type_param
15125 || child_die
->tag
== DW_TAG_template_value_param
)
15127 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15130 template_args
->push_back (arg
);
15132 else if (child_die
->tag
== DW_TAG_variant
)
15134 /* In a variant we want to get the discriminant and also add a
15135 field for our sole member child. */
15136 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15138 for (die_info
*variant_child
= child_die
->child
;
15139 variant_child
!= NULL
;
15140 variant_child
= variant_child
->sibling
)
15142 if (variant_child
->tag
== DW_TAG_member
)
15144 handle_struct_member_die (variant_child
, type
, fi
,
15145 template_args
, cu
);
15146 /* Only handle the one. */
15151 /* We don't handle this but we might as well report it if we see
15153 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15154 complaint (_("DW_AT_discr_list is not supported yet"
15155 " - DIE at %s [in module %s]"),
15156 sect_offset_str (child_die
->sect_off
),
15157 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15159 /* The first field was just added, so we can stash the
15160 discriminant there. */
15161 gdb_assert (!fi
->fields
.empty ());
15163 fi
->fields
.back ().variant
.default_branch
= true;
15165 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15169 /* Finish creating a structure or union type, including filling in
15170 its members and creating a symbol for it. */
15173 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15175 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15176 struct die_info
*child_die
;
15179 type
= get_die_type (die
, cu
);
15181 type
= read_structure_type (die
, cu
);
15183 /* When reading a DW_TAG_variant_part, we need to notice when we
15184 read the discriminant member, so we can record it later in the
15185 discriminant_info. */
15186 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15187 sect_offset discr_offset
{};
15188 bool has_template_parameters
= false;
15190 if (is_variant_part
)
15192 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15195 /* Maybe it's a univariant form, an extension we support.
15196 In this case arrange not to check the offset. */
15197 is_variant_part
= false;
15199 else if (discr
->form_is_ref ())
15201 struct dwarf2_cu
*target_cu
= cu
;
15202 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15204 discr_offset
= target_die
->sect_off
;
15208 complaint (_("DW_AT_discr does not have DIE reference form"
15209 " - DIE at %s [in module %s]"),
15210 sect_offset_str (die
->sect_off
),
15211 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15212 is_variant_part
= false;
15216 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15218 struct field_info fi
;
15219 std::vector
<struct symbol
*> template_args
;
15221 child_die
= die
->child
;
15223 while (child_die
&& child_die
->tag
)
15225 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15227 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15228 fi
.fields
.back ().variant
.is_discriminant
= true;
15230 child_die
= child_die
->sibling
;
15233 /* Attach template arguments to type. */
15234 if (!template_args
.empty ())
15236 has_template_parameters
= true;
15237 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15238 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15239 TYPE_TEMPLATE_ARGUMENTS (type
)
15240 = XOBNEWVEC (&objfile
->objfile_obstack
,
15242 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15243 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15244 template_args
.data (),
15245 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15246 * sizeof (struct symbol
*)));
15249 /* Attach fields and member functions to the type. */
15250 if (fi
.nfields () > 0)
15251 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15252 if (!fi
.fnfieldlists
.empty ())
15254 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15256 /* Get the type which refers to the base class (possibly this
15257 class itself) which contains the vtable pointer for the current
15258 class from the DW_AT_containing_type attribute. This use of
15259 DW_AT_containing_type is a GNU extension. */
15261 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15263 struct type
*t
= die_containing_type (die
, cu
);
15265 set_type_vptr_basetype (type
, t
);
15270 /* Our own class provides vtbl ptr. */
15271 for (i
= TYPE_NFIELDS (t
) - 1;
15272 i
>= TYPE_N_BASECLASSES (t
);
15275 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15277 if (is_vtable_name (fieldname
, cu
))
15279 set_type_vptr_fieldno (type
, i
);
15284 /* Complain if virtual function table field not found. */
15285 if (i
< TYPE_N_BASECLASSES (t
))
15286 complaint (_("virtual function table pointer "
15287 "not found when defining class '%s'"),
15288 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15292 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15295 else if (cu
->producer
15296 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15298 /* The IBM XLC compiler does not provide direct indication
15299 of the containing type, but the vtable pointer is
15300 always named __vfp. */
15304 for (i
= TYPE_NFIELDS (type
) - 1;
15305 i
>= TYPE_N_BASECLASSES (type
);
15308 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15310 set_type_vptr_fieldno (type
, i
);
15311 set_type_vptr_basetype (type
, type
);
15318 /* Copy fi.typedef_field_list linked list elements content into the
15319 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15320 if (!fi
.typedef_field_list
.empty ())
15322 int count
= fi
.typedef_field_list
.size ();
15324 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15325 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15326 = ((struct decl_field
*)
15328 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15329 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15331 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15332 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15335 /* Copy fi.nested_types_list linked list elements content into the
15336 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15337 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15339 int count
= fi
.nested_types_list
.size ();
15341 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15342 TYPE_NESTED_TYPES_ARRAY (type
)
15343 = ((struct decl_field
*)
15344 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15345 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15347 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15348 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15352 quirk_gcc_member_function_pointer (type
, objfile
);
15353 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15354 cu
->rust_unions
.push_back (type
);
15356 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15357 snapshots) has been known to create a die giving a declaration
15358 for a class that has, as a child, a die giving a definition for a
15359 nested class. So we have to process our children even if the
15360 current die is a declaration. Normally, of course, a declaration
15361 won't have any children at all. */
15363 child_die
= die
->child
;
15365 while (child_die
!= NULL
&& child_die
->tag
)
15367 if (child_die
->tag
== DW_TAG_member
15368 || child_die
->tag
== DW_TAG_variable
15369 || child_die
->tag
== DW_TAG_inheritance
15370 || child_die
->tag
== DW_TAG_template_value_param
15371 || child_die
->tag
== DW_TAG_template_type_param
)
15376 process_die (child_die
, cu
);
15378 child_die
= child_die
->sibling
;
15381 /* Do not consider external references. According to the DWARF standard,
15382 these DIEs are identified by the fact that they have no byte_size
15383 attribute, and a declaration attribute. */
15384 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15385 || !die_is_declaration (die
, cu
))
15387 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15389 if (has_template_parameters
)
15391 struct symtab
*symtab
;
15392 if (sym
!= nullptr)
15393 symtab
= symbol_symtab (sym
);
15394 else if (cu
->line_header
!= nullptr)
15396 /* Any related symtab will do. */
15398 = cu
->line_header
->file_names ()[0].symtab
;
15403 complaint (_("could not find suitable "
15404 "symtab for template parameter"
15405 " - DIE at %s [in module %s]"),
15406 sect_offset_str (die
->sect_off
),
15407 objfile_name (objfile
));
15410 if (symtab
!= nullptr)
15412 /* Make sure that the symtab is set on the new symbols.
15413 Even though they don't appear in this symtab directly,
15414 other parts of gdb assume that symbols do, and this is
15415 reasonably true. */
15416 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15417 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15423 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15424 update TYPE using some information only available in DIE's children. */
15427 update_enumeration_type_from_children (struct die_info
*die
,
15429 struct dwarf2_cu
*cu
)
15431 struct die_info
*child_die
;
15432 int unsigned_enum
= 1;
15435 auto_obstack obstack
;
15437 for (child_die
= die
->child
;
15438 child_die
!= NULL
&& child_die
->tag
;
15439 child_die
= child_die
->sibling
)
15441 struct attribute
*attr
;
15443 const gdb_byte
*bytes
;
15444 struct dwarf2_locexpr_baton
*baton
;
15447 if (child_die
->tag
!= DW_TAG_enumerator
)
15450 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15454 name
= dwarf2_name (child_die
, cu
);
15456 name
= "<anonymous enumerator>";
15458 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15459 &value
, &bytes
, &baton
);
15467 if (count_one_bits_ll (value
) >= 2)
15471 /* If we already know that the enum type is neither unsigned, nor
15472 a flag type, no need to look at the rest of the enumerates. */
15473 if (!unsigned_enum
&& !flag_enum
)
15478 TYPE_UNSIGNED (type
) = 1;
15480 TYPE_FLAG_ENUM (type
) = 1;
15483 /* Given a DW_AT_enumeration_type die, set its type. We do not
15484 complete the type's fields yet, or create any symbols. */
15486 static struct type
*
15487 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15489 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15491 struct attribute
*attr
;
15494 /* If the definition of this type lives in .debug_types, read that type.
15495 Don't follow DW_AT_specification though, that will take us back up
15496 the chain and we want to go down. */
15497 attr
= die
->attr (DW_AT_signature
);
15498 if (attr
!= nullptr)
15500 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15502 /* The type's CU may not be the same as CU.
15503 Ensure TYPE is recorded with CU in die_type_hash. */
15504 return set_die_type (die
, type
, cu
);
15507 type
= alloc_type (objfile
);
15509 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15510 name
= dwarf2_full_name (NULL
, die
, cu
);
15512 TYPE_NAME (type
) = name
;
15514 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15517 struct type
*underlying_type
= die_type (die
, cu
);
15519 TYPE_TARGET_TYPE (type
) = underlying_type
;
15522 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15523 if (attr
!= nullptr)
15525 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15529 TYPE_LENGTH (type
) = 0;
15532 maybe_set_alignment (cu
, die
, type
);
15534 /* The enumeration DIE can be incomplete. In Ada, any type can be
15535 declared as private in the package spec, and then defined only
15536 inside the package body. Such types are known as Taft Amendment
15537 Types. When another package uses such a type, an incomplete DIE
15538 may be generated by the compiler. */
15539 if (die_is_declaration (die
, cu
))
15540 TYPE_STUB (type
) = 1;
15542 /* Finish the creation of this type by using the enum's children.
15543 We must call this even when the underlying type has been provided
15544 so that we can determine if we're looking at a "flag" enum. */
15545 update_enumeration_type_from_children (die
, type
, cu
);
15547 /* If this type has an underlying type that is not a stub, then we
15548 may use its attributes. We always use the "unsigned" attribute
15549 in this situation, because ordinarily we guess whether the type
15550 is unsigned -- but the guess can be wrong and the underlying type
15551 can tell us the reality. However, we defer to a local size
15552 attribute if one exists, because this lets the compiler override
15553 the underlying type if needed. */
15554 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15556 struct type
*underlying_type
= TYPE_TARGET_TYPE (type
);
15557 underlying_type
= check_typedef (underlying_type
);
15558 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (underlying_type
);
15559 if (TYPE_LENGTH (type
) == 0)
15560 TYPE_LENGTH (type
) = TYPE_LENGTH (underlying_type
);
15561 if (TYPE_RAW_ALIGN (type
) == 0
15562 && TYPE_RAW_ALIGN (underlying_type
) != 0)
15563 set_type_align (type
, TYPE_RAW_ALIGN (underlying_type
));
15566 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15568 return set_die_type (die
, type
, cu
);
15571 /* Given a pointer to a die which begins an enumeration, process all
15572 the dies that define the members of the enumeration, and create the
15573 symbol for the enumeration type.
15575 NOTE: We reverse the order of the element list. */
15578 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15580 struct type
*this_type
;
15582 this_type
= get_die_type (die
, cu
);
15583 if (this_type
== NULL
)
15584 this_type
= read_enumeration_type (die
, cu
);
15586 if (die
->child
!= NULL
)
15588 struct die_info
*child_die
;
15589 struct symbol
*sym
;
15590 std::vector
<struct field
> fields
;
15593 child_die
= die
->child
;
15594 while (child_die
&& child_die
->tag
)
15596 if (child_die
->tag
!= DW_TAG_enumerator
)
15598 process_die (child_die
, cu
);
15602 name
= dwarf2_name (child_die
, cu
);
15605 sym
= new_symbol (child_die
, this_type
, cu
);
15607 fields
.emplace_back ();
15608 struct field
&field
= fields
.back ();
15610 FIELD_NAME (field
) = sym
->linkage_name ();
15611 FIELD_TYPE (field
) = NULL
;
15612 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15613 FIELD_BITSIZE (field
) = 0;
15617 child_die
= child_die
->sibling
;
15620 if (!fields
.empty ())
15622 TYPE_NFIELDS (this_type
) = fields
.size ();
15623 TYPE_FIELDS (this_type
) = (struct field
*)
15624 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15625 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15626 sizeof (struct field
) * fields
.size ());
15630 /* If we are reading an enum from a .debug_types unit, and the enum
15631 is a declaration, and the enum is not the signatured type in the
15632 unit, then we do not want to add a symbol for it. Adding a
15633 symbol would in some cases obscure the true definition of the
15634 enum, giving users an incomplete type when the definition is
15635 actually available. Note that we do not want to do this for all
15636 enums which are just declarations, because C++0x allows forward
15637 enum declarations. */
15638 if (cu
->per_cu
->is_debug_types
15639 && die_is_declaration (die
, cu
))
15641 struct signatured_type
*sig_type
;
15643 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15644 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15645 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15649 new_symbol (die
, this_type
, cu
);
15652 /* Extract all information from a DW_TAG_array_type DIE and put it in
15653 the DIE's type field. For now, this only handles one dimensional
15656 static struct type
*
15657 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15660 struct die_info
*child_die
;
15662 struct type
*element_type
, *range_type
, *index_type
;
15663 struct attribute
*attr
;
15665 struct dynamic_prop
*byte_stride_prop
= NULL
;
15666 unsigned int bit_stride
= 0;
15668 element_type
= die_type (die
, cu
);
15670 /* The die_type call above may have already set the type for this DIE. */
15671 type
= get_die_type (die
, cu
);
15675 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15679 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15682 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15683 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15687 complaint (_("unable to read array DW_AT_byte_stride "
15688 " - DIE at %s [in module %s]"),
15689 sect_offset_str (die
->sect_off
),
15690 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15691 /* Ignore this attribute. We will likely not be able to print
15692 arrays of this type correctly, but there is little we can do
15693 to help if we cannot read the attribute's value. */
15694 byte_stride_prop
= NULL
;
15698 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15700 bit_stride
= DW_UNSND (attr
);
15702 /* Irix 6.2 native cc creates array types without children for
15703 arrays with unspecified length. */
15704 if (die
->child
== NULL
)
15706 index_type
= objfile_type (objfile
)->builtin_int
;
15707 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15708 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15709 byte_stride_prop
, bit_stride
);
15710 return set_die_type (die
, type
, cu
);
15713 std::vector
<struct type
*> range_types
;
15714 child_die
= die
->child
;
15715 while (child_die
&& child_die
->tag
)
15717 if (child_die
->tag
== DW_TAG_subrange_type
)
15719 struct type
*child_type
= read_type_die (child_die
, cu
);
15721 if (child_type
!= NULL
)
15723 /* The range type was succesfully read. Save it for the
15724 array type creation. */
15725 range_types
.push_back (child_type
);
15728 child_die
= child_die
->sibling
;
15731 /* Dwarf2 dimensions are output from left to right, create the
15732 necessary array types in backwards order. */
15734 type
= element_type
;
15736 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15740 while (i
< range_types
.size ())
15741 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15742 byte_stride_prop
, bit_stride
);
15746 size_t ndim
= range_types
.size ();
15748 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15749 byte_stride_prop
, bit_stride
);
15752 /* Understand Dwarf2 support for vector types (like they occur on
15753 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15754 array type. This is not part of the Dwarf2/3 standard yet, but a
15755 custom vendor extension. The main difference between a regular
15756 array and the vector variant is that vectors are passed by value
15758 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15759 if (attr
!= nullptr)
15760 make_vector_type (type
);
15762 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15763 implementation may choose to implement triple vectors using this
15765 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15766 if (attr
!= nullptr)
15768 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15769 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15771 complaint (_("DW_AT_byte_size for array type smaller "
15772 "than the total size of elements"));
15775 name
= dwarf2_name (die
, cu
);
15777 TYPE_NAME (type
) = name
;
15779 maybe_set_alignment (cu
, die
, type
);
15781 /* Install the type in the die. */
15782 set_die_type (die
, type
, cu
);
15784 /* set_die_type should be already done. */
15785 set_descriptive_type (type
, die
, cu
);
15790 static enum dwarf_array_dim_ordering
15791 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15793 struct attribute
*attr
;
15795 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15797 if (attr
!= nullptr)
15798 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15800 /* GNU F77 is a special case, as at 08/2004 array type info is the
15801 opposite order to the dwarf2 specification, but data is still
15802 laid out as per normal fortran.
15804 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15805 version checking. */
15807 if (cu
->language
== language_fortran
15808 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15810 return DW_ORD_row_major
;
15813 switch (cu
->language_defn
->la_array_ordering
)
15815 case array_column_major
:
15816 return DW_ORD_col_major
;
15817 case array_row_major
:
15819 return DW_ORD_row_major
;
15823 /* Extract all information from a DW_TAG_set_type DIE and put it in
15824 the DIE's type field. */
15826 static struct type
*
15827 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15829 struct type
*domain_type
, *set_type
;
15830 struct attribute
*attr
;
15832 domain_type
= die_type (die
, cu
);
15834 /* The die_type call above may have already set the type for this DIE. */
15835 set_type
= get_die_type (die
, cu
);
15839 set_type
= create_set_type (NULL
, domain_type
);
15841 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15842 if (attr
!= nullptr)
15843 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15845 maybe_set_alignment (cu
, die
, set_type
);
15847 return set_die_type (die
, set_type
, cu
);
15850 /* A helper for read_common_block that creates a locexpr baton.
15851 SYM is the symbol which we are marking as computed.
15852 COMMON_DIE is the DIE for the common block.
15853 COMMON_LOC is the location expression attribute for the common
15855 MEMBER_LOC is the location expression attribute for the particular
15856 member of the common block that we are processing.
15857 CU is the CU from which the above come. */
15860 mark_common_block_symbol_computed (struct symbol
*sym
,
15861 struct die_info
*common_die
,
15862 struct attribute
*common_loc
,
15863 struct attribute
*member_loc
,
15864 struct dwarf2_cu
*cu
)
15866 struct dwarf2_per_objfile
*dwarf2_per_objfile
15867 = cu
->per_cu
->dwarf2_per_objfile
;
15868 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15869 struct dwarf2_locexpr_baton
*baton
;
15871 unsigned int cu_off
;
15872 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15873 LONGEST offset
= 0;
15875 gdb_assert (common_loc
&& member_loc
);
15876 gdb_assert (common_loc
->form_is_block ());
15877 gdb_assert (member_loc
->form_is_block ()
15878 || member_loc
->form_is_constant ());
15880 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15881 baton
->per_cu
= cu
->per_cu
;
15882 gdb_assert (baton
->per_cu
);
15884 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15886 if (member_loc
->form_is_constant ())
15888 offset
= member_loc
->constant_value (0);
15889 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15892 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15894 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15897 *ptr
++ = DW_OP_call4
;
15898 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15899 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15902 if (member_loc
->form_is_constant ())
15904 *ptr
++ = DW_OP_addr
;
15905 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15906 ptr
+= cu
->header
.addr_size
;
15910 /* We have to copy the data here, because DW_OP_call4 will only
15911 use a DW_AT_location attribute. */
15912 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15913 ptr
+= DW_BLOCK (member_loc
)->size
;
15916 *ptr
++ = DW_OP_plus
;
15917 gdb_assert (ptr
- baton
->data
== baton
->size
);
15919 SYMBOL_LOCATION_BATON (sym
) = baton
;
15920 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15923 /* Create appropriate locally-scoped variables for all the
15924 DW_TAG_common_block entries. Also create a struct common_block
15925 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15926 is used to separate the common blocks name namespace from regular
15930 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15932 struct attribute
*attr
;
15934 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15935 if (attr
!= nullptr)
15937 /* Support the .debug_loc offsets. */
15938 if (attr
->form_is_block ())
15942 else if (attr
->form_is_section_offset ())
15944 dwarf2_complex_location_expr_complaint ();
15949 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15950 "common block member");
15955 if (die
->child
!= NULL
)
15957 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15958 struct die_info
*child_die
;
15959 size_t n_entries
= 0, size
;
15960 struct common_block
*common_block
;
15961 struct symbol
*sym
;
15963 for (child_die
= die
->child
;
15964 child_die
&& child_die
->tag
;
15965 child_die
= child_die
->sibling
)
15968 size
= (sizeof (struct common_block
)
15969 + (n_entries
- 1) * sizeof (struct symbol
*));
15971 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15973 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15974 common_block
->n_entries
= 0;
15976 for (child_die
= die
->child
;
15977 child_die
&& child_die
->tag
;
15978 child_die
= child_die
->sibling
)
15980 /* Create the symbol in the DW_TAG_common_block block in the current
15982 sym
= new_symbol (child_die
, NULL
, cu
);
15985 struct attribute
*member_loc
;
15987 common_block
->contents
[common_block
->n_entries
++] = sym
;
15989 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15993 /* GDB has handled this for a long time, but it is
15994 not specified by DWARF. It seems to have been
15995 emitted by gfortran at least as recently as:
15996 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15997 complaint (_("Variable in common block has "
15998 "DW_AT_data_member_location "
15999 "- DIE at %s [in module %s]"),
16000 sect_offset_str (child_die
->sect_off
),
16001 objfile_name (objfile
));
16003 if (member_loc
->form_is_section_offset ())
16004 dwarf2_complex_location_expr_complaint ();
16005 else if (member_loc
->form_is_constant ()
16006 || member_loc
->form_is_block ())
16008 if (attr
!= nullptr)
16009 mark_common_block_symbol_computed (sym
, die
, attr
,
16013 dwarf2_complex_location_expr_complaint ();
16018 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16019 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16023 /* Create a type for a C++ namespace. */
16025 static struct type
*
16026 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16028 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16029 const char *previous_prefix
, *name
;
16033 /* For extensions, reuse the type of the original namespace. */
16034 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16036 struct die_info
*ext_die
;
16037 struct dwarf2_cu
*ext_cu
= cu
;
16039 ext_die
= dwarf2_extension (die
, &ext_cu
);
16040 type
= read_type_die (ext_die
, ext_cu
);
16042 /* EXT_CU may not be the same as CU.
16043 Ensure TYPE is recorded with CU in die_type_hash. */
16044 return set_die_type (die
, type
, cu
);
16047 name
= namespace_name (die
, &is_anonymous
, cu
);
16049 /* Now build the name of the current namespace. */
16051 previous_prefix
= determine_prefix (die
, cu
);
16052 if (previous_prefix
[0] != '\0')
16053 name
= typename_concat (&objfile
->objfile_obstack
,
16054 previous_prefix
, name
, 0, cu
);
16056 /* Create the type. */
16057 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16059 return set_die_type (die
, type
, cu
);
16062 /* Read a namespace scope. */
16065 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16067 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16070 /* Add a symbol associated to this if we haven't seen the namespace
16071 before. Also, add a using directive if it's an anonymous
16074 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16078 type
= read_type_die (die
, cu
);
16079 new_symbol (die
, type
, cu
);
16081 namespace_name (die
, &is_anonymous
, cu
);
16084 const char *previous_prefix
= determine_prefix (die
, cu
);
16086 std::vector
<const char *> excludes
;
16087 add_using_directive (using_directives (cu
),
16088 previous_prefix
, TYPE_NAME (type
), NULL
,
16089 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16093 if (die
->child
!= NULL
)
16095 struct die_info
*child_die
= die
->child
;
16097 while (child_die
&& child_die
->tag
)
16099 process_die (child_die
, cu
);
16100 child_die
= child_die
->sibling
;
16105 /* Read a Fortran module as type. This DIE can be only a declaration used for
16106 imported module. Still we need that type as local Fortran "use ... only"
16107 declaration imports depend on the created type in determine_prefix. */
16109 static struct type
*
16110 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16112 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16113 const char *module_name
;
16116 module_name
= dwarf2_name (die
, cu
);
16117 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16119 return set_die_type (die
, type
, cu
);
16122 /* Read a Fortran module. */
16125 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16127 struct die_info
*child_die
= die
->child
;
16130 type
= read_type_die (die
, cu
);
16131 new_symbol (die
, type
, cu
);
16133 while (child_die
&& child_die
->tag
)
16135 process_die (child_die
, cu
);
16136 child_die
= child_die
->sibling
;
16140 /* Return the name of the namespace represented by DIE. Set
16141 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16144 static const char *
16145 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16147 struct die_info
*current_die
;
16148 const char *name
= NULL
;
16150 /* Loop through the extensions until we find a name. */
16152 for (current_die
= die
;
16153 current_die
!= NULL
;
16154 current_die
= dwarf2_extension (die
, &cu
))
16156 /* We don't use dwarf2_name here so that we can detect the absence
16157 of a name -> anonymous namespace. */
16158 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16164 /* Is it an anonymous namespace? */
16166 *is_anonymous
= (name
== NULL
);
16168 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16173 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16174 the user defined type vector. */
16176 static struct type
*
16177 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16179 struct gdbarch
*gdbarch
16180 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16181 struct comp_unit_head
*cu_header
= &cu
->header
;
16183 struct attribute
*attr_byte_size
;
16184 struct attribute
*attr_address_class
;
16185 int byte_size
, addr_class
;
16186 struct type
*target_type
;
16188 target_type
= die_type (die
, cu
);
16190 /* The die_type call above may have already set the type for this DIE. */
16191 type
= get_die_type (die
, cu
);
16195 type
= lookup_pointer_type (target_type
);
16197 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16198 if (attr_byte_size
)
16199 byte_size
= DW_UNSND (attr_byte_size
);
16201 byte_size
= cu_header
->addr_size
;
16203 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16204 if (attr_address_class
)
16205 addr_class
= DW_UNSND (attr_address_class
);
16207 addr_class
= DW_ADDR_none
;
16209 ULONGEST alignment
= get_alignment (cu
, die
);
16211 /* If the pointer size, alignment, or address class is different
16212 than the default, create a type variant marked as such and set
16213 the length accordingly. */
16214 if (TYPE_LENGTH (type
) != byte_size
16215 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16216 && alignment
!= TYPE_RAW_ALIGN (type
))
16217 || addr_class
!= DW_ADDR_none
)
16219 if (gdbarch_address_class_type_flags_p (gdbarch
))
16223 type_flags
= gdbarch_address_class_type_flags
16224 (gdbarch
, byte_size
, addr_class
);
16225 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16227 type
= make_type_with_address_space (type
, type_flags
);
16229 else if (TYPE_LENGTH (type
) != byte_size
)
16231 complaint (_("invalid pointer size %d"), byte_size
);
16233 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16235 complaint (_("Invalid DW_AT_alignment"
16236 " - DIE at %s [in module %s]"),
16237 sect_offset_str (die
->sect_off
),
16238 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16242 /* Should we also complain about unhandled address classes? */
16246 TYPE_LENGTH (type
) = byte_size
;
16247 set_type_align (type
, alignment
);
16248 return set_die_type (die
, type
, cu
);
16251 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16252 the user defined type vector. */
16254 static struct type
*
16255 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16258 struct type
*to_type
;
16259 struct type
*domain
;
16261 to_type
= die_type (die
, cu
);
16262 domain
= die_containing_type (die
, cu
);
16264 /* The calls above may have already set the type for this DIE. */
16265 type
= get_die_type (die
, cu
);
16269 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16270 type
= lookup_methodptr_type (to_type
);
16271 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16273 struct type
*new_type
16274 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16276 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16277 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16278 TYPE_VARARGS (to_type
));
16279 type
= lookup_methodptr_type (new_type
);
16282 type
= lookup_memberptr_type (to_type
, domain
);
16284 return set_die_type (die
, type
, cu
);
16287 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16288 the user defined type vector. */
16290 static struct type
*
16291 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16292 enum type_code refcode
)
16294 struct comp_unit_head
*cu_header
= &cu
->header
;
16295 struct type
*type
, *target_type
;
16296 struct attribute
*attr
;
16298 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16300 target_type
= die_type (die
, cu
);
16302 /* The die_type call above may have already set the type for this DIE. */
16303 type
= get_die_type (die
, cu
);
16307 type
= lookup_reference_type (target_type
, refcode
);
16308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16309 if (attr
!= nullptr)
16311 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16315 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16317 maybe_set_alignment (cu
, die
, type
);
16318 return set_die_type (die
, type
, cu
);
16321 /* Add the given cv-qualifiers to the element type of the array. GCC
16322 outputs DWARF type qualifiers that apply to an array, not the
16323 element type. But GDB relies on the array element type to carry
16324 the cv-qualifiers. This mimics section 6.7.3 of the C99
16327 static struct type
*
16328 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16329 struct type
*base_type
, int cnst
, int voltl
)
16331 struct type
*el_type
, *inner_array
;
16333 base_type
= copy_type (base_type
);
16334 inner_array
= base_type
;
16336 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16338 TYPE_TARGET_TYPE (inner_array
) =
16339 copy_type (TYPE_TARGET_TYPE (inner_array
));
16340 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16343 el_type
= TYPE_TARGET_TYPE (inner_array
);
16344 cnst
|= TYPE_CONST (el_type
);
16345 voltl
|= TYPE_VOLATILE (el_type
);
16346 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16348 return set_die_type (die
, base_type
, cu
);
16351 static struct type
*
16352 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16354 struct type
*base_type
, *cv_type
;
16356 base_type
= die_type (die
, cu
);
16358 /* The die_type call above may have already set the type for this DIE. */
16359 cv_type
= get_die_type (die
, cu
);
16363 /* In case the const qualifier is applied to an array type, the element type
16364 is so qualified, not the array type (section 6.7.3 of C99). */
16365 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16366 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16368 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16369 return set_die_type (die
, cv_type
, cu
);
16372 static struct type
*
16373 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16375 struct type
*base_type
, *cv_type
;
16377 base_type
= die_type (die
, cu
);
16379 /* The die_type call above may have already set the type for this DIE. */
16380 cv_type
= get_die_type (die
, cu
);
16384 /* In case the volatile qualifier is applied to an array type, the
16385 element type is so qualified, not the array type (section 6.7.3
16387 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16388 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16390 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16391 return set_die_type (die
, cv_type
, cu
);
16394 /* Handle DW_TAG_restrict_type. */
16396 static struct type
*
16397 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16399 struct type
*base_type
, *cv_type
;
16401 base_type
= die_type (die
, cu
);
16403 /* The die_type call above may have already set the type for this DIE. */
16404 cv_type
= get_die_type (die
, cu
);
16408 cv_type
= make_restrict_type (base_type
);
16409 return set_die_type (die
, cv_type
, cu
);
16412 /* Handle DW_TAG_atomic_type. */
16414 static struct type
*
16415 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16417 struct type
*base_type
, *cv_type
;
16419 base_type
= die_type (die
, cu
);
16421 /* The die_type call above may have already set the type for this DIE. */
16422 cv_type
= get_die_type (die
, cu
);
16426 cv_type
= make_atomic_type (base_type
);
16427 return set_die_type (die
, cv_type
, cu
);
16430 /* Extract all information from a DW_TAG_string_type DIE and add to
16431 the user defined type vector. It isn't really a user defined type,
16432 but it behaves like one, with other DIE's using an AT_user_def_type
16433 attribute to reference it. */
16435 static struct type
*
16436 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16438 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16439 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16440 struct type
*type
, *range_type
, *index_type
, *char_type
;
16441 struct attribute
*attr
;
16442 struct dynamic_prop prop
;
16443 bool length_is_constant
= true;
16446 /* There are a couple of places where bit sizes might be made use of
16447 when parsing a DW_TAG_string_type, however, no producer that we know
16448 of make use of these. Handling bit sizes that are a multiple of the
16449 byte size is easy enough, but what about other bit sizes? Lets deal
16450 with that problem when we have to. Warn about these attributes being
16451 unsupported, then parse the type and ignore them like we always
16453 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16454 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16456 static bool warning_printed
= false;
16457 if (!warning_printed
)
16459 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16460 "currently supported on DW_TAG_string_type."));
16461 warning_printed
= true;
16465 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16466 if (attr
!= nullptr && !attr
->form_is_constant ())
16468 /* The string length describes the location at which the length of
16469 the string can be found. The size of the length field can be
16470 specified with one of the attributes below. */
16471 struct type
*prop_type
;
16472 struct attribute
*len
16473 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16474 if (len
== nullptr)
16475 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16476 if (len
!= nullptr && len
->form_is_constant ())
16478 /* Pass 0 as the default as we know this attribute is constant
16479 and the default value will not be returned. */
16480 LONGEST sz
= len
->constant_value (0);
16481 prop_type
= cu
->per_cu
->int_type (sz
, true);
16485 /* If the size is not specified then we assume it is the size of
16486 an address on this target. */
16487 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16490 /* Convert the attribute into a dynamic property. */
16491 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16494 length_is_constant
= false;
16496 else if (attr
!= nullptr)
16498 /* This DW_AT_string_length just contains the length with no
16499 indirection. There's no need to create a dynamic property in this
16500 case. Pass 0 for the default value as we know it will not be
16501 returned in this case. */
16502 length
= attr
->constant_value (0);
16504 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16506 /* We don't currently support non-constant byte sizes for strings. */
16507 length
= attr
->constant_value (1);
16511 /* Use 1 as a fallback length if we have nothing else. */
16515 index_type
= objfile_type (objfile
)->builtin_int
;
16516 if (length_is_constant
)
16517 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16520 struct dynamic_prop low_bound
;
16522 low_bound
.kind
= PROP_CONST
;
16523 low_bound
.data
.const_val
= 1;
16524 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16526 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16527 type
= create_string_type (NULL
, char_type
, range_type
);
16529 return set_die_type (die
, type
, cu
);
16532 /* Assuming that DIE corresponds to a function, returns nonzero
16533 if the function is prototyped. */
16536 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16538 struct attribute
*attr
;
16540 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16541 if (attr
&& (DW_UNSND (attr
) != 0))
16544 /* The DWARF standard implies that the DW_AT_prototyped attribute
16545 is only meaningful for C, but the concept also extends to other
16546 languages that allow unprototyped functions (Eg: Objective C).
16547 For all other languages, assume that functions are always
16549 if (cu
->language
!= language_c
16550 && cu
->language
!= language_objc
16551 && cu
->language
!= language_opencl
)
16554 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16555 prototyped and unprototyped functions; default to prototyped,
16556 since that is more common in modern code (and RealView warns
16557 about unprototyped functions). */
16558 if (producer_is_realview (cu
->producer
))
16564 /* Handle DIES due to C code like:
16568 int (*funcp)(int a, long l);
16572 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16574 static struct type
*
16575 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16577 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16578 struct type
*type
; /* Type that this function returns. */
16579 struct type
*ftype
; /* Function that returns above type. */
16580 struct attribute
*attr
;
16582 type
= die_type (die
, cu
);
16584 /* The die_type call above may have already set the type for this DIE. */
16585 ftype
= get_die_type (die
, cu
);
16589 ftype
= lookup_function_type (type
);
16591 if (prototyped_function_p (die
, cu
))
16592 TYPE_PROTOTYPED (ftype
) = 1;
16594 /* Store the calling convention in the type if it's available in
16595 the subroutine die. Otherwise set the calling convention to
16596 the default value DW_CC_normal. */
16597 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16598 if (attr
!= nullptr
16599 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16600 TYPE_CALLING_CONVENTION (ftype
)
16601 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16602 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16603 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16605 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16607 /* Record whether the function returns normally to its caller or not
16608 if the DWARF producer set that information. */
16609 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16610 if (attr
&& (DW_UNSND (attr
) != 0))
16611 TYPE_NO_RETURN (ftype
) = 1;
16613 /* We need to add the subroutine type to the die immediately so
16614 we don't infinitely recurse when dealing with parameters
16615 declared as the same subroutine type. */
16616 set_die_type (die
, ftype
, cu
);
16618 if (die
->child
!= NULL
)
16620 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16621 struct die_info
*child_die
;
16622 int nparams
, iparams
;
16624 /* Count the number of parameters.
16625 FIXME: GDB currently ignores vararg functions, but knows about
16626 vararg member functions. */
16628 child_die
= die
->child
;
16629 while (child_die
&& child_die
->tag
)
16631 if (child_die
->tag
== DW_TAG_formal_parameter
)
16633 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16634 TYPE_VARARGS (ftype
) = 1;
16635 child_die
= child_die
->sibling
;
16638 /* Allocate storage for parameters and fill them in. */
16639 TYPE_NFIELDS (ftype
) = nparams
;
16640 TYPE_FIELDS (ftype
) = (struct field
*)
16641 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16643 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16644 even if we error out during the parameters reading below. */
16645 for (iparams
= 0; iparams
< nparams
; iparams
++)
16646 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16649 child_die
= die
->child
;
16650 while (child_die
&& child_die
->tag
)
16652 if (child_die
->tag
== DW_TAG_formal_parameter
)
16654 struct type
*arg_type
;
16656 /* DWARF version 2 has no clean way to discern C++
16657 static and non-static member functions. G++ helps
16658 GDB by marking the first parameter for non-static
16659 member functions (which is the this pointer) as
16660 artificial. We pass this information to
16661 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16663 DWARF version 3 added DW_AT_object_pointer, which GCC
16664 4.5 does not yet generate. */
16665 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16666 if (attr
!= nullptr)
16667 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16669 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16670 arg_type
= die_type (child_die
, cu
);
16672 /* RealView does not mark THIS as const, which the testsuite
16673 expects. GCC marks THIS as const in method definitions,
16674 but not in the class specifications (GCC PR 43053). */
16675 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16676 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16679 struct dwarf2_cu
*arg_cu
= cu
;
16680 const char *name
= dwarf2_name (child_die
, cu
);
16682 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16683 if (attr
!= nullptr)
16685 /* If the compiler emits this, use it. */
16686 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16689 else if (name
&& strcmp (name
, "this") == 0)
16690 /* Function definitions will have the argument names. */
16692 else if (name
== NULL
&& iparams
== 0)
16693 /* Declarations may not have the names, so like
16694 elsewhere in GDB, assume an artificial first
16695 argument is "this". */
16699 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16703 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16706 child_die
= child_die
->sibling
;
16713 static struct type
*
16714 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16716 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16717 const char *name
= NULL
;
16718 struct type
*this_type
, *target_type
;
16720 name
= dwarf2_full_name (NULL
, die
, cu
);
16721 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16722 TYPE_TARGET_STUB (this_type
) = 1;
16723 set_die_type (die
, this_type
, cu
);
16724 target_type
= die_type (die
, cu
);
16725 if (target_type
!= this_type
)
16726 TYPE_TARGET_TYPE (this_type
) = target_type
;
16729 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16730 spec and cause infinite loops in GDB. */
16731 complaint (_("Self-referential DW_TAG_typedef "
16732 "- DIE at %s [in module %s]"),
16733 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16734 TYPE_TARGET_TYPE (this_type
) = NULL
;
16738 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16739 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16740 Handle these by just returning the target type, rather than
16741 constructing an anonymous typedef type and trying to handle this
16743 set_die_type (die
, target_type
, cu
);
16744 return target_type
;
16749 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16750 (which may be different from NAME) to the architecture back-end to allow
16751 it to guess the correct format if necessary. */
16753 static struct type
*
16754 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16755 const char *name_hint
, enum bfd_endian byte_order
)
16757 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16758 const struct floatformat
**format
;
16761 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16763 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16765 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16770 /* Allocate an integer type of size BITS and name NAME. */
16772 static struct type
*
16773 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16774 int bits
, int unsigned_p
, const char *name
)
16778 /* Versions of Intel's C Compiler generate an integer type called "void"
16779 instead of using DW_TAG_unspecified_type. This has been seen on
16780 at least versions 14, 17, and 18. */
16781 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16782 && strcmp (name
, "void") == 0)
16783 type
= objfile_type (objfile
)->builtin_void
;
16785 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16790 /* Initialise and return a floating point type of size BITS suitable for
16791 use as a component of a complex number. The NAME_HINT is passed through
16792 when initialising the floating point type and is the name of the complex
16795 As DWARF doesn't currently provide an explicit name for the components
16796 of a complex number, but it can be helpful to have these components
16797 named, we try to select a suitable name based on the size of the
16799 static struct type
*
16800 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16801 struct objfile
*objfile
,
16802 int bits
, const char *name_hint
,
16803 enum bfd_endian byte_order
)
16805 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16806 struct type
*tt
= nullptr;
16808 /* Try to find a suitable floating point builtin type of size BITS.
16809 We're going to use the name of this type as the name for the complex
16810 target type that we are about to create. */
16811 switch (cu
->language
)
16813 case language_fortran
:
16817 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16820 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16822 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16824 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16832 tt
= builtin_type (gdbarch
)->builtin_float
;
16835 tt
= builtin_type (gdbarch
)->builtin_double
;
16837 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16839 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16845 /* If the type we found doesn't match the size we were looking for, then
16846 pretend we didn't find a type at all, the complex target type we
16847 create will then be nameless. */
16848 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16851 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16852 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16855 /* Find a representation of a given base type and install
16856 it in the TYPE field of the die. */
16858 static struct type
*
16859 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16861 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16863 struct attribute
*attr
;
16864 int encoding
= 0, bits
= 0;
16868 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16869 if (attr
!= nullptr)
16870 encoding
= DW_UNSND (attr
);
16871 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16872 if (attr
!= nullptr)
16873 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16874 name
= dwarf2_name (die
, cu
);
16876 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16878 arch
= get_objfile_arch (objfile
);
16879 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16881 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16884 int endianity
= DW_UNSND (attr
);
16889 byte_order
= BFD_ENDIAN_BIG
;
16891 case DW_END_little
:
16892 byte_order
= BFD_ENDIAN_LITTLE
;
16895 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16902 case DW_ATE_address
:
16903 /* Turn DW_ATE_address into a void * pointer. */
16904 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16905 type
= init_pointer_type (objfile
, bits
, name
, type
);
16907 case DW_ATE_boolean
:
16908 type
= init_boolean_type (objfile
, bits
, 1, name
);
16910 case DW_ATE_complex_float
:
16911 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16913 if (TYPE_CODE (type
) == TYPE_CODE_ERROR
)
16915 if (name
== nullptr)
16917 struct obstack
*obstack
16918 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16919 name
= obconcat (obstack
, "_Complex ", TYPE_NAME (type
),
16922 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16925 type
= init_complex_type (name
, type
);
16927 case DW_ATE_decimal_float
:
16928 type
= init_decfloat_type (objfile
, bits
, name
);
16931 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16933 case DW_ATE_signed
:
16934 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16936 case DW_ATE_unsigned
:
16937 if (cu
->language
== language_fortran
16939 && startswith (name
, "character("))
16940 type
= init_character_type (objfile
, bits
, 1, name
);
16942 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16944 case DW_ATE_signed_char
:
16945 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16946 || cu
->language
== language_pascal
16947 || cu
->language
== language_fortran
)
16948 type
= init_character_type (objfile
, bits
, 0, name
);
16950 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16952 case DW_ATE_unsigned_char
:
16953 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16954 || cu
->language
== language_pascal
16955 || cu
->language
== language_fortran
16956 || cu
->language
== language_rust
)
16957 type
= init_character_type (objfile
, bits
, 1, name
);
16959 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16964 type
= builtin_type (arch
)->builtin_char16
;
16965 else if (bits
== 32)
16966 type
= builtin_type (arch
)->builtin_char32
;
16969 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16971 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16973 return set_die_type (die
, type
, cu
);
16978 complaint (_("unsupported DW_AT_encoding: '%s'"),
16979 dwarf_type_encoding_name (encoding
));
16980 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16984 if (name
&& strcmp (name
, "char") == 0)
16985 TYPE_NOSIGN (type
) = 1;
16987 maybe_set_alignment (cu
, die
, type
);
16989 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16991 return set_die_type (die
, type
, cu
);
16994 /* Parse dwarf attribute if it's a block, reference or constant and put the
16995 resulting value of the attribute into struct bound_prop.
16996 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
16999 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17000 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17001 struct type
*default_type
)
17003 struct dwarf2_property_baton
*baton
;
17004 struct obstack
*obstack
17005 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17007 gdb_assert (default_type
!= NULL
);
17009 if (attr
== NULL
|| prop
== NULL
)
17012 if (attr
->form_is_block ())
17014 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17015 baton
->property_type
= default_type
;
17016 baton
->locexpr
.per_cu
= cu
->per_cu
;
17017 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17018 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17019 switch (attr
->name
)
17021 case DW_AT_string_length
:
17022 baton
->locexpr
.is_reference
= true;
17025 baton
->locexpr
.is_reference
= false;
17028 prop
->data
.baton
= baton
;
17029 prop
->kind
= PROP_LOCEXPR
;
17030 gdb_assert (prop
->data
.baton
!= NULL
);
17032 else if (attr
->form_is_ref ())
17034 struct dwarf2_cu
*target_cu
= cu
;
17035 struct die_info
*target_die
;
17036 struct attribute
*target_attr
;
17038 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17039 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17040 if (target_attr
== NULL
)
17041 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17043 if (target_attr
== NULL
)
17046 switch (target_attr
->name
)
17048 case DW_AT_location
:
17049 if (target_attr
->form_is_section_offset ())
17051 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17052 baton
->property_type
= die_type (target_die
, target_cu
);
17053 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17054 prop
->data
.baton
= baton
;
17055 prop
->kind
= PROP_LOCLIST
;
17056 gdb_assert (prop
->data
.baton
!= NULL
);
17058 else if (target_attr
->form_is_block ())
17060 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17061 baton
->property_type
= die_type (target_die
, target_cu
);
17062 baton
->locexpr
.per_cu
= cu
->per_cu
;
17063 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17064 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17065 baton
->locexpr
.is_reference
= true;
17066 prop
->data
.baton
= baton
;
17067 prop
->kind
= PROP_LOCEXPR
;
17068 gdb_assert (prop
->data
.baton
!= NULL
);
17072 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17073 "dynamic property");
17077 case DW_AT_data_member_location
:
17081 if (!handle_data_member_location (target_die
, target_cu
,
17085 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17086 baton
->property_type
= read_type_die (target_die
->parent
,
17088 baton
->offset_info
.offset
= offset
;
17089 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17090 prop
->data
.baton
= baton
;
17091 prop
->kind
= PROP_ADDR_OFFSET
;
17096 else if (attr
->form_is_constant ())
17098 prop
->data
.const_val
= attr
->constant_value (0);
17099 prop
->kind
= PROP_CONST
;
17103 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17104 dwarf2_name (die
, cu
));
17114 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17116 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17117 struct type
*int_type
;
17119 /* Helper macro to examine the various builtin types. */
17120 #define TRY_TYPE(F) \
17121 int_type = (unsigned_p \
17122 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17123 : objfile_type (objfile)->builtin_ ## F); \
17124 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17131 TRY_TYPE (long_long
);
17135 gdb_assert_not_reached ("unable to find suitable integer type");
17141 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17143 int addr_size
= this->addr_size ();
17144 return int_type (addr_size
, unsigned_p
);
17147 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17148 present (which is valid) then compute the default type based on the
17149 compilation units address size. */
17151 static struct type
*
17152 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17154 struct type
*index_type
= die_type (die
, cu
);
17156 /* Dwarf-2 specifications explicitly allows to create subrange types
17157 without specifying a base type.
17158 In that case, the base type must be set to the type of
17159 the lower bound, upper bound or count, in that order, if any of these
17160 three attributes references an object that has a type.
17161 If no base type is found, the Dwarf-2 specifications say that
17162 a signed integer type of size equal to the size of an address should
17164 For the following C code: `extern char gdb_int [];'
17165 GCC produces an empty range DIE.
17166 FIXME: muller/2010-05-28: Possible references to object for low bound,
17167 high bound or count are not yet handled by this code. */
17168 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17169 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17174 /* Read the given DW_AT_subrange DIE. */
17176 static struct type
*
17177 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17179 struct type
*base_type
, *orig_base_type
;
17180 struct type
*range_type
;
17181 struct attribute
*attr
;
17182 struct dynamic_prop low
, high
;
17183 int low_default_is_valid
;
17184 int high_bound_is_count
= 0;
17186 ULONGEST negative_mask
;
17188 orig_base_type
= read_subrange_index_type (die
, cu
);
17190 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17191 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17192 creating the range type, but we use the result of check_typedef
17193 when examining properties of the type. */
17194 base_type
= check_typedef (orig_base_type
);
17196 /* The die_type call above may have already set the type for this DIE. */
17197 range_type
= get_die_type (die
, cu
);
17201 low
.kind
= PROP_CONST
;
17202 high
.kind
= PROP_CONST
;
17203 high
.data
.const_val
= 0;
17205 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17206 omitting DW_AT_lower_bound. */
17207 switch (cu
->language
)
17210 case language_cplus
:
17211 low
.data
.const_val
= 0;
17212 low_default_is_valid
= 1;
17214 case language_fortran
:
17215 low
.data
.const_val
= 1;
17216 low_default_is_valid
= 1;
17219 case language_objc
:
17220 case language_rust
:
17221 low
.data
.const_val
= 0;
17222 low_default_is_valid
= (cu
->header
.version
>= 4);
17226 case language_pascal
:
17227 low
.data
.const_val
= 1;
17228 low_default_is_valid
= (cu
->header
.version
>= 4);
17231 low
.data
.const_val
= 0;
17232 low_default_is_valid
= 0;
17236 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17237 if (attr
!= nullptr)
17238 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17239 else if (!low_default_is_valid
)
17240 complaint (_("Missing DW_AT_lower_bound "
17241 "- DIE at %s [in module %s]"),
17242 sect_offset_str (die
->sect_off
),
17243 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17245 struct attribute
*attr_ub
, *attr_count
;
17246 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17247 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17249 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17250 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17252 /* If bounds are constant do the final calculation here. */
17253 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17254 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17256 high_bound_is_count
= 1;
17260 if (attr_ub
!= NULL
)
17261 complaint (_("Unresolved DW_AT_upper_bound "
17262 "- DIE at %s [in module %s]"),
17263 sect_offset_str (die
->sect_off
),
17264 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17265 if (attr_count
!= NULL
)
17266 complaint (_("Unresolved DW_AT_count "
17267 "- DIE at %s [in module %s]"),
17268 sect_offset_str (die
->sect_off
),
17269 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17274 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17275 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17276 bias
= bias_attr
->constant_value (0);
17278 /* Normally, the DWARF producers are expected to use a signed
17279 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17280 But this is unfortunately not always the case, as witnessed
17281 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17282 is used instead. To work around that ambiguity, we treat
17283 the bounds as signed, and thus sign-extend their values, when
17284 the base type is signed. */
17286 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17287 if (low
.kind
== PROP_CONST
17288 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17289 low
.data
.const_val
|= negative_mask
;
17290 if (high
.kind
== PROP_CONST
17291 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17292 high
.data
.const_val
|= negative_mask
;
17294 /* Check for bit and byte strides. */
17295 struct dynamic_prop byte_stride_prop
;
17296 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17297 if (attr_byte_stride
!= nullptr)
17299 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17300 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17304 struct dynamic_prop bit_stride_prop
;
17305 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17306 if (attr_bit_stride
!= nullptr)
17308 /* It only makes sense to have either a bit or byte stride. */
17309 if (attr_byte_stride
!= nullptr)
17311 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17312 "- DIE at %s [in module %s]"),
17313 sect_offset_str (die
->sect_off
),
17314 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17315 attr_bit_stride
= nullptr;
17319 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17320 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17325 if (attr_byte_stride
!= nullptr
17326 || attr_bit_stride
!= nullptr)
17328 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17329 struct dynamic_prop
*stride
17330 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17333 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17334 &high
, bias
, stride
, byte_stride_p
);
17337 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17339 if (high_bound_is_count
)
17340 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17342 /* Ada expects an empty array on no boundary attributes. */
17343 if (attr
== NULL
&& cu
->language
!= language_ada
)
17344 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17346 name
= dwarf2_name (die
, cu
);
17348 TYPE_NAME (range_type
) = name
;
17350 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17351 if (attr
!= nullptr)
17352 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17354 maybe_set_alignment (cu
, die
, range_type
);
17356 set_die_type (die
, range_type
, cu
);
17358 /* set_die_type should be already done. */
17359 set_descriptive_type (range_type
, die
, cu
);
17364 static struct type
*
17365 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17369 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17371 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17373 /* In Ada, an unspecified type is typically used when the description
17374 of the type is deferred to a different unit. When encountering
17375 such a type, we treat it as a stub, and try to resolve it later on,
17377 if (cu
->language
== language_ada
)
17378 TYPE_STUB (type
) = 1;
17380 return set_die_type (die
, type
, cu
);
17383 /* Read a single die and all its descendents. Set the die's sibling
17384 field to NULL; set other fields in the die correctly, and set all
17385 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17386 location of the info_ptr after reading all of those dies. PARENT
17387 is the parent of the die in question. */
17389 static struct die_info
*
17390 read_die_and_children (const struct die_reader_specs
*reader
,
17391 const gdb_byte
*info_ptr
,
17392 const gdb_byte
**new_info_ptr
,
17393 struct die_info
*parent
)
17395 struct die_info
*die
;
17396 const gdb_byte
*cur_ptr
;
17398 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17401 *new_info_ptr
= cur_ptr
;
17404 store_in_ref_table (die
, reader
->cu
);
17406 if (die
->has_children
)
17407 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17411 *new_info_ptr
= cur_ptr
;
17414 die
->sibling
= NULL
;
17415 die
->parent
= parent
;
17419 /* Read a die, all of its descendents, and all of its siblings; set
17420 all of the fields of all of the dies correctly. Arguments are as
17421 in read_die_and_children. */
17423 static struct die_info
*
17424 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17425 const gdb_byte
*info_ptr
,
17426 const gdb_byte
**new_info_ptr
,
17427 struct die_info
*parent
)
17429 struct die_info
*first_die
, *last_sibling
;
17430 const gdb_byte
*cur_ptr
;
17432 cur_ptr
= info_ptr
;
17433 first_die
= last_sibling
= NULL
;
17437 struct die_info
*die
17438 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17442 *new_info_ptr
= cur_ptr
;
17449 last_sibling
->sibling
= die
;
17451 last_sibling
= die
;
17455 /* Read a die, all of its descendents, and all of its siblings; set
17456 all of the fields of all of the dies correctly. Arguments are as
17457 in read_die_and_children.
17458 This the main entry point for reading a DIE and all its children. */
17460 static struct die_info
*
17461 read_die_and_siblings (const struct die_reader_specs
*reader
,
17462 const gdb_byte
*info_ptr
,
17463 const gdb_byte
**new_info_ptr
,
17464 struct die_info
*parent
)
17466 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17467 new_info_ptr
, parent
);
17469 if (dwarf_die_debug
)
17471 fprintf_unfiltered (gdb_stdlog
,
17472 "Read die from %s@0x%x of %s:\n",
17473 reader
->die_section
->get_name (),
17474 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17475 bfd_get_filename (reader
->abfd
));
17476 dump_die (die
, dwarf_die_debug
);
17482 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17484 The caller is responsible for filling in the extra attributes
17485 and updating (*DIEP)->num_attrs.
17486 Set DIEP to point to a newly allocated die with its information,
17487 except for its child, sibling, and parent fields. */
17489 static const gdb_byte
*
17490 read_full_die_1 (const struct die_reader_specs
*reader
,
17491 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17492 int num_extra_attrs
)
17494 unsigned int abbrev_number
, bytes_read
, i
;
17495 struct abbrev_info
*abbrev
;
17496 struct die_info
*die
;
17497 struct dwarf2_cu
*cu
= reader
->cu
;
17498 bfd
*abfd
= reader
->abfd
;
17500 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17501 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17502 info_ptr
+= bytes_read
;
17503 if (!abbrev_number
)
17509 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17511 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17513 bfd_get_filename (abfd
));
17515 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17516 die
->sect_off
= sect_off
;
17517 die
->tag
= abbrev
->tag
;
17518 die
->abbrev
= abbrev_number
;
17519 die
->has_children
= abbrev
->has_children
;
17521 /* Make the result usable.
17522 The caller needs to update num_attrs after adding the extra
17524 die
->num_attrs
= abbrev
->num_attrs
;
17526 std::vector
<int> indexes_that_need_reprocess
;
17527 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17529 bool need_reprocess
;
17531 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17532 info_ptr
, &need_reprocess
);
17533 if (need_reprocess
)
17534 indexes_that_need_reprocess
.push_back (i
);
17537 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17538 if (attr
!= nullptr)
17539 cu
->str_offsets_base
= DW_UNSND (attr
);
17541 auto maybe_addr_base
= die
->addr_base ();
17542 if (maybe_addr_base
.has_value ())
17543 cu
->addr_base
= *maybe_addr_base
;
17544 for (int index
: indexes_that_need_reprocess
)
17545 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17550 /* Read a die and all its attributes.
17551 Set DIEP to point to a newly allocated die with its information,
17552 except for its child, sibling, and parent fields. */
17554 static const gdb_byte
*
17555 read_full_die (const struct die_reader_specs
*reader
,
17556 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17558 const gdb_byte
*result
;
17560 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17562 if (dwarf_die_debug
)
17564 fprintf_unfiltered (gdb_stdlog
,
17565 "Read die from %s@0x%x of %s:\n",
17566 reader
->die_section
->get_name (),
17567 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17568 bfd_get_filename (reader
->abfd
));
17569 dump_die (*diep
, dwarf_die_debug
);
17576 /* Returns nonzero if TAG represents a type that we might generate a partial
17580 is_type_tag_for_partial (int tag
)
17585 /* Some types that would be reasonable to generate partial symbols for,
17586 that we don't at present. */
17587 case DW_TAG_array_type
:
17588 case DW_TAG_file_type
:
17589 case DW_TAG_ptr_to_member_type
:
17590 case DW_TAG_set_type
:
17591 case DW_TAG_string_type
:
17592 case DW_TAG_subroutine_type
:
17594 case DW_TAG_base_type
:
17595 case DW_TAG_class_type
:
17596 case DW_TAG_interface_type
:
17597 case DW_TAG_enumeration_type
:
17598 case DW_TAG_structure_type
:
17599 case DW_TAG_subrange_type
:
17600 case DW_TAG_typedef
:
17601 case DW_TAG_union_type
:
17608 /* Load all DIEs that are interesting for partial symbols into memory. */
17610 static struct partial_die_info
*
17611 load_partial_dies (const struct die_reader_specs
*reader
,
17612 const gdb_byte
*info_ptr
, int building_psymtab
)
17614 struct dwarf2_cu
*cu
= reader
->cu
;
17615 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17616 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17617 unsigned int bytes_read
;
17618 unsigned int load_all
= 0;
17619 int nesting_level
= 1;
17624 gdb_assert (cu
->per_cu
!= NULL
);
17625 if (cu
->per_cu
->load_all_dies
)
17629 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17633 &cu
->comp_unit_obstack
,
17634 hashtab_obstack_allocate
,
17635 dummy_obstack_deallocate
);
17639 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17641 /* A NULL abbrev means the end of a series of children. */
17642 if (abbrev
== NULL
)
17644 if (--nesting_level
== 0)
17647 info_ptr
+= bytes_read
;
17648 last_die
= parent_die
;
17649 parent_die
= parent_die
->die_parent
;
17653 /* Check for template arguments. We never save these; if
17654 they're seen, we just mark the parent, and go on our way. */
17655 if (parent_die
!= NULL
17656 && cu
->language
== language_cplus
17657 && (abbrev
->tag
== DW_TAG_template_type_param
17658 || abbrev
->tag
== DW_TAG_template_value_param
))
17660 parent_die
->has_template_arguments
= 1;
17664 /* We don't need a partial DIE for the template argument. */
17665 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17670 /* We only recurse into c++ subprograms looking for template arguments.
17671 Skip their other children. */
17673 && cu
->language
== language_cplus
17674 && parent_die
!= NULL
17675 && parent_die
->tag
== DW_TAG_subprogram
)
17677 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17681 /* Check whether this DIE is interesting enough to save. Normally
17682 we would not be interested in members here, but there may be
17683 later variables referencing them via DW_AT_specification (for
17684 static members). */
17686 && !is_type_tag_for_partial (abbrev
->tag
)
17687 && abbrev
->tag
!= DW_TAG_constant
17688 && abbrev
->tag
!= DW_TAG_enumerator
17689 && abbrev
->tag
!= DW_TAG_subprogram
17690 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17691 && abbrev
->tag
!= DW_TAG_lexical_block
17692 && abbrev
->tag
!= DW_TAG_variable
17693 && abbrev
->tag
!= DW_TAG_namespace
17694 && abbrev
->tag
!= DW_TAG_module
17695 && abbrev
->tag
!= DW_TAG_member
17696 && abbrev
->tag
!= DW_TAG_imported_unit
17697 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17699 /* Otherwise we skip to the next sibling, if any. */
17700 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17704 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17707 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17709 /* This two-pass algorithm for processing partial symbols has a
17710 high cost in cache pressure. Thus, handle some simple cases
17711 here which cover the majority of C partial symbols. DIEs
17712 which neither have specification tags in them, nor could have
17713 specification tags elsewhere pointing at them, can simply be
17714 processed and discarded.
17716 This segment is also optional; scan_partial_symbols and
17717 add_partial_symbol will handle these DIEs if we chain
17718 them in normally. When compilers which do not emit large
17719 quantities of duplicate debug information are more common,
17720 this code can probably be removed. */
17722 /* Any complete simple types at the top level (pretty much all
17723 of them, for a language without namespaces), can be processed
17725 if (parent_die
== NULL
17726 && pdi
.has_specification
== 0
17727 && pdi
.is_declaration
== 0
17728 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17729 || pdi
.tag
== DW_TAG_base_type
17730 || pdi
.tag
== DW_TAG_subrange_type
))
17732 if (building_psymtab
&& pdi
.name
!= NULL
)
17733 add_psymbol_to_list (pdi
.name
, false,
17734 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17735 psymbol_placement::STATIC
,
17736 0, cu
->language
, objfile
);
17737 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17741 /* The exception for DW_TAG_typedef with has_children above is
17742 a workaround of GCC PR debug/47510. In the case of this complaint
17743 type_name_or_error will error on such types later.
17745 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17746 it could not find the child DIEs referenced later, this is checked
17747 above. In correct DWARF DW_TAG_typedef should have no children. */
17749 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17750 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17751 "- DIE at %s [in module %s]"),
17752 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17754 /* If we're at the second level, and we're an enumerator, and
17755 our parent has no specification (meaning possibly lives in a
17756 namespace elsewhere), then we can add the partial symbol now
17757 instead of queueing it. */
17758 if (pdi
.tag
== DW_TAG_enumerator
17759 && parent_die
!= NULL
17760 && parent_die
->die_parent
== NULL
17761 && parent_die
->tag
== DW_TAG_enumeration_type
17762 && parent_die
->has_specification
== 0)
17764 if (pdi
.name
== NULL
)
17765 complaint (_("malformed enumerator DIE ignored"));
17766 else if (building_psymtab
)
17767 add_psymbol_to_list (pdi
.name
, false,
17768 VAR_DOMAIN
, LOC_CONST
, -1,
17769 cu
->language
== language_cplus
17770 ? psymbol_placement::GLOBAL
17771 : psymbol_placement::STATIC
,
17772 0, cu
->language
, objfile
);
17774 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17778 struct partial_die_info
*part_die
17779 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17781 /* We'll save this DIE so link it in. */
17782 part_die
->die_parent
= parent_die
;
17783 part_die
->die_sibling
= NULL
;
17784 part_die
->die_child
= NULL
;
17786 if (last_die
&& last_die
== parent_die
)
17787 last_die
->die_child
= part_die
;
17789 last_die
->die_sibling
= part_die
;
17791 last_die
= part_die
;
17793 if (first_die
== NULL
)
17794 first_die
= part_die
;
17796 /* Maybe add the DIE to the hash table. Not all DIEs that we
17797 find interesting need to be in the hash table, because we
17798 also have the parent/sibling/child chains; only those that we
17799 might refer to by offset later during partial symbol reading.
17801 For now this means things that might have be the target of a
17802 DW_AT_specification, DW_AT_abstract_origin, or
17803 DW_AT_extension. DW_AT_extension will refer only to
17804 namespaces; DW_AT_abstract_origin refers to functions (and
17805 many things under the function DIE, but we do not recurse
17806 into function DIEs during partial symbol reading) and
17807 possibly variables as well; DW_AT_specification refers to
17808 declarations. Declarations ought to have the DW_AT_declaration
17809 flag. It happens that GCC forgets to put it in sometimes, but
17810 only for functions, not for types.
17812 Adding more things than necessary to the hash table is harmless
17813 except for the performance cost. Adding too few will result in
17814 wasted time in find_partial_die, when we reread the compilation
17815 unit with load_all_dies set. */
17818 || abbrev
->tag
== DW_TAG_constant
17819 || abbrev
->tag
== DW_TAG_subprogram
17820 || abbrev
->tag
== DW_TAG_variable
17821 || abbrev
->tag
== DW_TAG_namespace
17822 || part_die
->is_declaration
)
17826 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17827 to_underlying (part_die
->sect_off
),
17832 /* For some DIEs we want to follow their children (if any). For C
17833 we have no reason to follow the children of structures; for other
17834 languages we have to, so that we can get at method physnames
17835 to infer fully qualified class names, for DW_AT_specification,
17836 and for C++ template arguments. For C++, we also look one level
17837 inside functions to find template arguments (if the name of the
17838 function does not already contain the template arguments).
17840 For Ada and Fortran, we need to scan the children of subprograms
17841 and lexical blocks as well because these languages allow the
17842 definition of nested entities that could be interesting for the
17843 debugger, such as nested subprograms for instance. */
17844 if (last_die
->has_children
17846 || last_die
->tag
== DW_TAG_namespace
17847 || last_die
->tag
== DW_TAG_module
17848 || last_die
->tag
== DW_TAG_enumeration_type
17849 || (cu
->language
== language_cplus
17850 && last_die
->tag
== DW_TAG_subprogram
17851 && (last_die
->name
== NULL
17852 || strchr (last_die
->name
, '<') == NULL
))
17853 || (cu
->language
!= language_c
17854 && (last_die
->tag
== DW_TAG_class_type
17855 || last_die
->tag
== DW_TAG_interface_type
17856 || last_die
->tag
== DW_TAG_structure_type
17857 || last_die
->tag
== DW_TAG_union_type
))
17858 || ((cu
->language
== language_ada
17859 || cu
->language
== language_fortran
)
17860 && (last_die
->tag
== DW_TAG_subprogram
17861 || last_die
->tag
== DW_TAG_lexical_block
))))
17864 parent_die
= last_die
;
17868 /* Otherwise we skip to the next sibling, if any. */
17869 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17871 /* Back to the top, do it again. */
17875 partial_die_info::partial_die_info (sect_offset sect_off_
,
17876 struct abbrev_info
*abbrev
)
17877 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17881 /* Read a minimal amount of information into the minimal die structure.
17882 INFO_PTR should point just after the initial uleb128 of a DIE. */
17885 partial_die_info::read (const struct die_reader_specs
*reader
,
17886 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17888 struct dwarf2_cu
*cu
= reader
->cu
;
17889 struct dwarf2_per_objfile
*dwarf2_per_objfile
17890 = cu
->per_cu
->dwarf2_per_objfile
;
17892 int has_low_pc_attr
= 0;
17893 int has_high_pc_attr
= 0;
17894 int high_pc_relative
= 0;
17896 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17899 bool need_reprocess
;
17900 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
],
17901 info_ptr
, &need_reprocess
);
17902 /* String and address offsets that need to do the reprocessing have
17903 already been read at this point, so there is no need to wait until
17904 the loop terminates to do the reprocessing. */
17905 if (need_reprocess
)
17906 read_attribute_reprocess (reader
, &attr
);
17907 /* Store the data if it is of an attribute we want to keep in a
17908 partial symbol table. */
17914 case DW_TAG_compile_unit
:
17915 case DW_TAG_partial_unit
:
17916 case DW_TAG_type_unit
:
17917 /* Compilation units have a DW_AT_name that is a filename, not
17918 a source language identifier. */
17919 case DW_TAG_enumeration_type
:
17920 case DW_TAG_enumerator
:
17921 /* These tags always have simple identifiers already; no need
17922 to canonicalize them. */
17923 name
= DW_STRING (&attr
);
17927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17930 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17935 case DW_AT_linkage_name
:
17936 case DW_AT_MIPS_linkage_name
:
17937 /* Note that both forms of linkage name might appear. We
17938 assume they will be the same, and we only store the last
17940 linkage_name
= DW_STRING (&attr
);
17943 has_low_pc_attr
= 1;
17944 lowpc
= attr
.value_as_address ();
17946 case DW_AT_high_pc
:
17947 has_high_pc_attr
= 1;
17948 highpc
= attr
.value_as_address ();
17949 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17950 high_pc_relative
= 1;
17952 case DW_AT_location
:
17953 /* Support the .debug_loc offsets. */
17954 if (attr
.form_is_block ())
17956 d
.locdesc
= DW_BLOCK (&attr
);
17958 else if (attr
.form_is_section_offset ())
17960 dwarf2_complex_location_expr_complaint ();
17964 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17965 "partial symbol information");
17968 case DW_AT_external
:
17969 is_external
= DW_UNSND (&attr
);
17971 case DW_AT_declaration
:
17972 is_declaration
= DW_UNSND (&attr
);
17977 case DW_AT_abstract_origin
:
17978 case DW_AT_specification
:
17979 case DW_AT_extension
:
17980 has_specification
= 1;
17981 spec_offset
= attr
.get_ref_die_offset ();
17982 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17983 || cu
->per_cu
->is_dwz
);
17985 case DW_AT_sibling
:
17986 /* Ignore absolute siblings, they might point outside of
17987 the current compile unit. */
17988 if (attr
.form
== DW_FORM_ref_addr
)
17989 complaint (_("ignoring absolute DW_AT_sibling"));
17992 const gdb_byte
*buffer
= reader
->buffer
;
17993 sect_offset off
= attr
.get_ref_die_offset ();
17994 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17996 if (sibling_ptr
< info_ptr
)
17997 complaint (_("DW_AT_sibling points backwards"));
17998 else if (sibling_ptr
> reader
->buffer_end
)
17999 reader
->die_section
->overflow_complaint ();
18001 sibling
= sibling_ptr
;
18004 case DW_AT_byte_size
:
18007 case DW_AT_const_value
:
18008 has_const_value
= 1;
18010 case DW_AT_calling_convention
:
18011 /* DWARF doesn't provide a way to identify a program's source-level
18012 entry point. DW_AT_calling_convention attributes are only meant
18013 to describe functions' calling conventions.
18015 However, because it's a necessary piece of information in
18016 Fortran, and before DWARF 4 DW_CC_program was the only
18017 piece of debugging information whose definition refers to
18018 a 'main program' at all, several compilers marked Fortran
18019 main programs with DW_CC_program --- even when those
18020 functions use the standard calling conventions.
18022 Although DWARF now specifies a way to provide this
18023 information, we support this practice for backward
18025 if (DW_UNSND (&attr
) == DW_CC_program
18026 && cu
->language
== language_fortran
)
18027 main_subprogram
= 1;
18030 if (DW_UNSND (&attr
) == DW_INL_inlined
18031 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18032 may_be_inlined
= 1;
18036 if (tag
== DW_TAG_imported_unit
)
18038 d
.sect_off
= attr
.get_ref_die_offset ();
18039 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18040 || cu
->per_cu
->is_dwz
);
18044 case DW_AT_main_subprogram
:
18045 main_subprogram
= DW_UNSND (&attr
);
18050 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18051 but that requires a full DIE, so instead we just
18053 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18054 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18055 + (need_ranges_base
18059 /* Value of the DW_AT_ranges attribute is the offset in the
18060 .debug_ranges section. */
18061 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18072 /* For Ada, if both the name and the linkage name appear, we prefer
18073 the latter. This lets "catch exception" work better, regardless
18074 of the order in which the name and linkage name were emitted.
18075 Really, though, this is just a workaround for the fact that gdb
18076 doesn't store both the name and the linkage name. */
18077 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18078 name
= linkage_name
;
18080 if (high_pc_relative
)
18083 if (has_low_pc_attr
&& has_high_pc_attr
)
18085 /* When using the GNU linker, .gnu.linkonce. sections are used to
18086 eliminate duplicate copies of functions and vtables and such.
18087 The linker will arbitrarily choose one and discard the others.
18088 The AT_*_pc values for such functions refer to local labels in
18089 these sections. If the section from that file was discarded, the
18090 labels are not in the output, so the relocs get a value of 0.
18091 If this is a discarded function, mark the pc bounds as invalid,
18092 so that GDB will ignore it. */
18093 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18096 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18098 complaint (_("DW_AT_low_pc %s is zero "
18099 "for DIE at %s [in module %s]"),
18100 paddress (gdbarch
, lowpc
),
18101 sect_offset_str (sect_off
),
18102 objfile_name (objfile
));
18104 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18105 else if (lowpc
>= highpc
)
18107 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18108 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18110 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18111 "for DIE at %s [in module %s]"),
18112 paddress (gdbarch
, lowpc
),
18113 paddress (gdbarch
, highpc
),
18114 sect_offset_str (sect_off
),
18115 objfile_name (objfile
));
18124 /* Find a cached partial DIE at OFFSET in CU. */
18126 struct partial_die_info
*
18127 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18129 struct partial_die_info
*lookup_die
= NULL
;
18130 struct partial_die_info
part_die (sect_off
);
18132 lookup_die
= ((struct partial_die_info
*)
18133 htab_find_with_hash (partial_dies
, &part_die
,
18134 to_underlying (sect_off
)));
18139 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18140 except in the case of .debug_types DIEs which do not reference
18141 outside their CU (they do however referencing other types via
18142 DW_FORM_ref_sig8). */
18144 static const struct cu_partial_die_info
18145 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18147 struct dwarf2_per_objfile
*dwarf2_per_objfile
18148 = cu
->per_cu
->dwarf2_per_objfile
;
18149 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18150 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18151 struct partial_die_info
*pd
= NULL
;
18153 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18154 && cu
->header
.offset_in_cu_p (sect_off
))
18156 pd
= cu
->find_partial_die (sect_off
);
18159 /* We missed recording what we needed.
18160 Load all dies and try again. */
18161 per_cu
= cu
->per_cu
;
18165 /* TUs don't reference other CUs/TUs (except via type signatures). */
18166 if (cu
->per_cu
->is_debug_types
)
18168 error (_("Dwarf Error: Type Unit at offset %s contains"
18169 " external reference to offset %s [in module %s].\n"),
18170 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18171 bfd_get_filename (objfile
->obfd
));
18173 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18174 dwarf2_per_objfile
);
18176 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18177 load_partial_comp_unit (per_cu
);
18179 per_cu
->cu
->last_used
= 0;
18180 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18183 /* If we didn't find it, and not all dies have been loaded,
18184 load them all and try again. */
18186 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18188 per_cu
->load_all_dies
= 1;
18190 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18191 THIS_CU->cu may already be in use. So we can't just free it and
18192 replace its DIEs with the ones we read in. Instead, we leave those
18193 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18194 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18196 load_partial_comp_unit (per_cu
);
18198 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18202 internal_error (__FILE__
, __LINE__
,
18203 _("could not find partial DIE %s "
18204 "in cache [from module %s]\n"),
18205 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18206 return { per_cu
->cu
, pd
};
18209 /* See if we can figure out if the class lives in a namespace. We do
18210 this by looking for a member function; its demangled name will
18211 contain namespace info, if there is any. */
18214 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18215 struct dwarf2_cu
*cu
)
18217 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18218 what template types look like, because the demangler
18219 frequently doesn't give the same name as the debug info. We
18220 could fix this by only using the demangled name to get the
18221 prefix (but see comment in read_structure_type). */
18223 struct partial_die_info
*real_pdi
;
18224 struct partial_die_info
*child_pdi
;
18226 /* If this DIE (this DIE's specification, if any) has a parent, then
18227 we should not do this. We'll prepend the parent's fully qualified
18228 name when we create the partial symbol. */
18230 real_pdi
= struct_pdi
;
18231 while (real_pdi
->has_specification
)
18233 auto res
= find_partial_die (real_pdi
->spec_offset
,
18234 real_pdi
->spec_is_dwz
, cu
);
18235 real_pdi
= res
.pdi
;
18239 if (real_pdi
->die_parent
!= NULL
)
18242 for (child_pdi
= struct_pdi
->die_child
;
18244 child_pdi
= child_pdi
->die_sibling
)
18246 if (child_pdi
->tag
== DW_TAG_subprogram
18247 && child_pdi
->linkage_name
!= NULL
)
18249 gdb::unique_xmalloc_ptr
<char> actual_class_name
18250 (language_class_name_from_physname (cu
->language_defn
,
18251 child_pdi
->linkage_name
));
18252 if (actual_class_name
!= NULL
)
18254 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18255 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18262 /* Return true if a DIE with TAG may have the DW_AT_const_value
18266 can_have_DW_AT_const_value_p (enum dwarf_tag tag
)
18270 case DW_TAG_constant
:
18271 case DW_TAG_enumerator
:
18272 case DW_TAG_formal_parameter
:
18273 case DW_TAG_template_value_param
:
18274 case DW_TAG_variable
:
18282 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18284 /* Once we've fixed up a die, there's no point in doing so again.
18285 This also avoids a memory leak if we were to call
18286 guess_partial_die_structure_name multiple times. */
18290 /* If we found a reference attribute and the DIE has no name, try
18291 to find a name in the referred to DIE. */
18293 if (name
== NULL
&& has_specification
)
18295 struct partial_die_info
*spec_die
;
18297 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18298 spec_die
= res
.pdi
;
18301 spec_die
->fixup (cu
);
18303 if (spec_die
->name
)
18305 name
= spec_die
->name
;
18307 /* Copy DW_AT_external attribute if it is set. */
18308 if (spec_die
->is_external
)
18309 is_external
= spec_die
->is_external
;
18313 if (!has_const_value
&& has_specification
18314 && can_have_DW_AT_const_value_p (tag
))
18316 struct partial_die_info
*spec_die
;
18318 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18319 spec_die
= res
.pdi
;
18322 spec_die
->fixup (cu
);
18324 if (spec_die
->has_const_value
)
18326 /* Copy DW_AT_const_value attribute if it is set. */
18327 has_const_value
= spec_die
->has_const_value
;
18331 /* Set default names for some unnamed DIEs. */
18333 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18334 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18336 /* If there is no parent die to provide a namespace, and there are
18337 children, see if we can determine the namespace from their linkage
18339 if (cu
->language
== language_cplus
18340 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18341 && die_parent
== NULL
18343 && (tag
== DW_TAG_class_type
18344 || tag
== DW_TAG_structure_type
18345 || tag
== DW_TAG_union_type
))
18346 guess_partial_die_structure_name (this, cu
);
18348 /* GCC might emit a nameless struct or union that has a linkage
18349 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18351 && (tag
== DW_TAG_class_type
18352 || tag
== DW_TAG_interface_type
18353 || tag
== DW_TAG_structure_type
18354 || tag
== DW_TAG_union_type
)
18355 && linkage_name
!= NULL
)
18357 gdb::unique_xmalloc_ptr
<char> demangled
18358 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18359 if (demangled
!= nullptr)
18363 /* Strip any leading namespaces/classes, keep only the base name.
18364 DW_AT_name for named DIEs does not contain the prefixes. */
18365 base
= strrchr (demangled
.get (), ':');
18366 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18369 base
= demangled
.get ();
18371 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18372 name
= objfile
->intern (base
);
18379 /* Process the attributes that had to be skipped in the first round. These
18380 attributes are the ones that need str_offsets_base or addr_base attributes.
18381 They could not have been processed in the first round, because at the time
18382 the values of str_offsets_base or addr_base may not have been known. */
18384 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18385 struct attribute
*attr
)
18387 struct dwarf2_cu
*cu
= reader
->cu
;
18388 switch (attr
->form
)
18390 case DW_FORM_addrx
:
18391 case DW_FORM_GNU_addr_index
:
18392 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18395 case DW_FORM_strx1
:
18396 case DW_FORM_strx2
:
18397 case DW_FORM_strx3
:
18398 case DW_FORM_strx4
:
18399 case DW_FORM_GNU_str_index
:
18401 unsigned int str_index
= DW_UNSND (attr
);
18402 if (reader
->dwo_file
!= NULL
)
18404 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18405 DW_STRING_IS_CANONICAL (attr
) = 0;
18409 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18410 DW_STRING_IS_CANONICAL (attr
) = 0;
18415 gdb_assert_not_reached (_("Unexpected DWARF form."));
18419 /* Read an attribute value described by an attribute form. */
18421 static const gdb_byte
*
18422 read_attribute_value (const struct die_reader_specs
*reader
,
18423 struct attribute
*attr
, unsigned form
,
18424 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18425 bool *need_reprocess
)
18427 struct dwarf2_cu
*cu
= reader
->cu
;
18428 struct dwarf2_per_objfile
*dwarf2_per_objfile
18429 = cu
->per_cu
->dwarf2_per_objfile
;
18430 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18431 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18432 bfd
*abfd
= reader
->abfd
;
18433 struct comp_unit_head
*cu_header
= &cu
->header
;
18434 unsigned int bytes_read
;
18435 struct dwarf_block
*blk
;
18436 *need_reprocess
= false;
18438 attr
->form
= (enum dwarf_form
) form
;
18441 case DW_FORM_ref_addr
:
18442 if (cu
->header
.version
== 2)
18443 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18446 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18448 info_ptr
+= bytes_read
;
18450 case DW_FORM_GNU_ref_alt
:
18451 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18452 info_ptr
+= bytes_read
;
18455 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18456 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18457 info_ptr
+= bytes_read
;
18459 case DW_FORM_block2
:
18460 blk
= dwarf_alloc_block (cu
);
18461 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18463 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18464 info_ptr
+= blk
->size
;
18465 DW_BLOCK (attr
) = blk
;
18467 case DW_FORM_block4
:
18468 blk
= dwarf_alloc_block (cu
);
18469 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18471 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18472 info_ptr
+= blk
->size
;
18473 DW_BLOCK (attr
) = blk
;
18475 case DW_FORM_data2
:
18476 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18479 case DW_FORM_data4
:
18480 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18483 case DW_FORM_data8
:
18484 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18487 case DW_FORM_data16
:
18488 blk
= dwarf_alloc_block (cu
);
18490 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18492 DW_BLOCK (attr
) = blk
;
18494 case DW_FORM_sec_offset
:
18495 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18496 info_ptr
+= bytes_read
;
18498 case DW_FORM_string
:
18499 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18500 DW_STRING_IS_CANONICAL (attr
) = 0;
18501 info_ptr
+= bytes_read
;
18504 if (!cu
->per_cu
->is_dwz
)
18506 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18507 abfd
, info_ptr
, cu_header
,
18509 DW_STRING_IS_CANONICAL (attr
) = 0;
18510 info_ptr
+= bytes_read
;
18514 case DW_FORM_line_strp
:
18515 if (!cu
->per_cu
->is_dwz
)
18518 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18520 DW_STRING_IS_CANONICAL (attr
) = 0;
18521 info_ptr
+= bytes_read
;
18525 case DW_FORM_GNU_strp_alt
:
18527 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18528 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18531 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18532 DW_STRING_IS_CANONICAL (attr
) = 0;
18533 info_ptr
+= bytes_read
;
18536 case DW_FORM_exprloc
:
18537 case DW_FORM_block
:
18538 blk
= dwarf_alloc_block (cu
);
18539 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18540 info_ptr
+= bytes_read
;
18541 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18542 info_ptr
+= blk
->size
;
18543 DW_BLOCK (attr
) = blk
;
18545 case DW_FORM_block1
:
18546 blk
= dwarf_alloc_block (cu
);
18547 blk
->size
= read_1_byte (abfd
, info_ptr
);
18549 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18550 info_ptr
+= blk
->size
;
18551 DW_BLOCK (attr
) = blk
;
18553 case DW_FORM_data1
:
18554 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18558 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18561 case DW_FORM_flag_present
:
18562 DW_UNSND (attr
) = 1;
18564 case DW_FORM_sdata
:
18565 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18566 info_ptr
+= bytes_read
;
18568 case DW_FORM_udata
:
18569 case DW_FORM_rnglistx
:
18570 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18571 info_ptr
+= bytes_read
;
18574 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18575 + read_1_byte (abfd
, info_ptr
));
18579 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18580 + read_2_bytes (abfd
, info_ptr
));
18584 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18585 + read_4_bytes (abfd
, info_ptr
));
18589 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18590 + read_8_bytes (abfd
, info_ptr
));
18593 case DW_FORM_ref_sig8
:
18594 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18597 case DW_FORM_ref_udata
:
18598 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18599 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18600 info_ptr
+= bytes_read
;
18602 case DW_FORM_indirect
:
18603 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18604 info_ptr
+= bytes_read
;
18605 if (form
== DW_FORM_implicit_const
)
18607 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18608 info_ptr
+= bytes_read
;
18610 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18611 info_ptr
, need_reprocess
);
18613 case DW_FORM_implicit_const
:
18614 DW_SND (attr
) = implicit_const
;
18616 case DW_FORM_addrx
:
18617 case DW_FORM_GNU_addr_index
:
18618 *need_reprocess
= true;
18619 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18620 info_ptr
+= bytes_read
;
18623 case DW_FORM_strx1
:
18624 case DW_FORM_strx2
:
18625 case DW_FORM_strx3
:
18626 case DW_FORM_strx4
:
18627 case DW_FORM_GNU_str_index
:
18629 ULONGEST str_index
;
18630 if (form
== DW_FORM_strx1
)
18632 str_index
= read_1_byte (abfd
, info_ptr
);
18635 else if (form
== DW_FORM_strx2
)
18637 str_index
= read_2_bytes (abfd
, info_ptr
);
18640 else if (form
== DW_FORM_strx3
)
18642 str_index
= read_3_bytes (abfd
, info_ptr
);
18645 else if (form
== DW_FORM_strx4
)
18647 str_index
= read_4_bytes (abfd
, info_ptr
);
18652 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18653 info_ptr
+= bytes_read
;
18655 *need_reprocess
= true;
18656 DW_UNSND (attr
) = str_index
;
18660 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18661 dwarf_form_name (form
),
18662 bfd_get_filename (abfd
));
18666 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18667 attr
->form
= DW_FORM_GNU_ref_alt
;
18669 /* We have seen instances where the compiler tried to emit a byte
18670 size attribute of -1 which ended up being encoded as an unsigned
18671 0xffffffff. Although 0xffffffff is technically a valid size value,
18672 an object of this size seems pretty unlikely so we can relatively
18673 safely treat these cases as if the size attribute was invalid and
18674 treat them as zero by default. */
18675 if (attr
->name
== DW_AT_byte_size
18676 && form
== DW_FORM_data4
18677 && DW_UNSND (attr
) >= 0xffffffff)
18680 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18681 hex_string (DW_UNSND (attr
)));
18682 DW_UNSND (attr
) = 0;
18688 /* Read an attribute described by an abbreviated attribute. */
18690 static const gdb_byte
*
18691 read_attribute (const struct die_reader_specs
*reader
,
18692 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18693 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18695 attr
->name
= abbrev
->name
;
18696 return read_attribute_value (reader
, attr
, abbrev
->form
,
18697 abbrev
->implicit_const
, info_ptr
,
18701 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18703 static const char *
18704 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18705 LONGEST str_offset
)
18707 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18708 str_offset
, "DW_FORM_strp");
18711 /* Return pointer to string at .debug_str offset as read from BUF.
18712 BUF is assumed to be in a compilation unit described by CU_HEADER.
18713 Return *BYTES_READ_PTR count of bytes read from BUF. */
18715 static const char *
18716 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18717 const gdb_byte
*buf
,
18718 const struct comp_unit_head
*cu_header
,
18719 unsigned int *bytes_read_ptr
)
18721 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18723 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18729 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18730 const struct comp_unit_head
*cu_header
,
18731 unsigned int *bytes_read_ptr
)
18733 bfd
*abfd
= objfile
->obfd
;
18734 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18736 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18739 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18740 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18741 ADDR_SIZE is the size of addresses from the CU header. */
18744 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18745 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18748 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18749 bfd
*abfd
= objfile
->obfd
;
18750 const gdb_byte
*info_ptr
;
18751 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18753 dwarf2_per_objfile
->addr
.read (objfile
);
18754 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18755 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18756 objfile_name (objfile
));
18757 if (addr_base_or_zero
+ addr_index
* addr_size
18758 >= dwarf2_per_objfile
->addr
.size
)
18759 error (_("DW_FORM_addr_index pointing outside of "
18760 ".debug_addr section [in module %s]"),
18761 objfile_name (objfile
));
18762 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18763 + addr_base_or_zero
+ addr_index
* addr_size
);
18764 if (addr_size
== 4)
18765 return bfd_get_32 (abfd
, info_ptr
);
18767 return bfd_get_64 (abfd
, info_ptr
);
18770 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18773 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18775 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18776 cu
->addr_base
, cu
->header
.addr_size
);
18779 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18782 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18783 unsigned int *bytes_read
)
18785 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18786 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18788 return read_addr_index (cu
, addr_index
);
18794 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18796 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18797 struct dwarf2_cu
*cu
= per_cu
->cu
;
18798 gdb::optional
<ULONGEST
> addr_base
;
18801 /* We need addr_base and addr_size.
18802 If we don't have PER_CU->cu, we have to get it.
18803 Nasty, but the alternative is storing the needed info in PER_CU,
18804 which at this point doesn't seem justified: it's not clear how frequently
18805 it would get used and it would increase the size of every PER_CU.
18806 Entry points like dwarf2_per_cu_addr_size do a similar thing
18807 so we're not in uncharted territory here.
18808 Alas we need to be a bit more complicated as addr_base is contained
18811 We don't need to read the entire CU(/TU).
18812 We just need the header and top level die.
18814 IWBN to use the aging mechanism to let us lazily later discard the CU.
18815 For now we skip this optimization. */
18819 addr_base
= cu
->addr_base
;
18820 addr_size
= cu
->header
.addr_size
;
18824 cutu_reader
reader (per_cu
, NULL
, 0, false);
18825 addr_base
= reader
.cu
->addr_base
;
18826 addr_size
= reader
.cu
->header
.addr_size
;
18829 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18833 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18834 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18837 static const char *
18838 read_str_index (struct dwarf2_cu
*cu
,
18839 struct dwarf2_section_info
*str_section
,
18840 struct dwarf2_section_info
*str_offsets_section
,
18841 ULONGEST str_offsets_base
, ULONGEST str_index
)
18843 struct dwarf2_per_objfile
*dwarf2_per_objfile
18844 = cu
->per_cu
->dwarf2_per_objfile
;
18845 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18846 const char *objf_name
= objfile_name (objfile
);
18847 bfd
*abfd
= objfile
->obfd
;
18848 const gdb_byte
*info_ptr
;
18849 ULONGEST str_offset
;
18850 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18852 str_section
->read (objfile
);
18853 str_offsets_section
->read (objfile
);
18854 if (str_section
->buffer
== NULL
)
18855 error (_("%s used without %s section"
18856 " in CU at offset %s [in module %s]"),
18857 form_name
, str_section
->get_name (),
18858 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18859 if (str_offsets_section
->buffer
== NULL
)
18860 error (_("%s used without %s section"
18861 " in CU at offset %s [in module %s]"),
18862 form_name
, str_section
->get_name (),
18863 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18864 info_ptr
= (str_offsets_section
->buffer
18866 + str_index
* cu
->header
.offset_size
);
18867 if (cu
->header
.offset_size
== 4)
18868 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18870 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18871 if (str_offset
>= str_section
->size
)
18872 error (_("Offset from %s pointing outside of"
18873 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18874 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18875 return (const char *) (str_section
->buffer
+ str_offset
);
18878 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18880 static const char *
18881 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18883 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18884 ? reader
->cu
->header
.addr_size
: 0;
18885 return read_str_index (reader
->cu
,
18886 &reader
->dwo_file
->sections
.str
,
18887 &reader
->dwo_file
->sections
.str_offsets
,
18888 str_offsets_base
, str_index
);
18891 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18893 static const char *
18894 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18896 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18897 const char *objf_name
= objfile_name (objfile
);
18898 static const char form_name
[] = "DW_FORM_GNU_str_index";
18899 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18901 if (!cu
->str_offsets_base
.has_value ())
18902 error (_("%s used in Fission stub without %s"
18903 " in CU at offset 0x%lx [in module %s]"),
18904 form_name
, str_offsets_attr_name
,
18905 (long) cu
->header
.offset_size
, objf_name
);
18907 return read_str_index (cu
,
18908 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18909 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18910 *cu
->str_offsets_base
, str_index
);
18913 /* Return the length of an LEB128 number in BUF. */
18916 leb128_size (const gdb_byte
*buf
)
18918 const gdb_byte
*begin
= buf
;
18924 if ((byte
& 128) == 0)
18925 return buf
- begin
;
18930 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18939 cu
->language
= language_c
;
18942 case DW_LANG_C_plus_plus
:
18943 case DW_LANG_C_plus_plus_11
:
18944 case DW_LANG_C_plus_plus_14
:
18945 cu
->language
= language_cplus
;
18948 cu
->language
= language_d
;
18950 case DW_LANG_Fortran77
:
18951 case DW_LANG_Fortran90
:
18952 case DW_LANG_Fortran95
:
18953 case DW_LANG_Fortran03
:
18954 case DW_LANG_Fortran08
:
18955 cu
->language
= language_fortran
;
18958 cu
->language
= language_go
;
18960 case DW_LANG_Mips_Assembler
:
18961 cu
->language
= language_asm
;
18963 case DW_LANG_Ada83
:
18964 case DW_LANG_Ada95
:
18965 cu
->language
= language_ada
;
18967 case DW_LANG_Modula2
:
18968 cu
->language
= language_m2
;
18970 case DW_LANG_Pascal83
:
18971 cu
->language
= language_pascal
;
18974 cu
->language
= language_objc
;
18977 case DW_LANG_Rust_old
:
18978 cu
->language
= language_rust
;
18980 case DW_LANG_Cobol74
:
18981 case DW_LANG_Cobol85
:
18983 cu
->language
= language_minimal
;
18986 cu
->language_defn
= language_def (cu
->language
);
18989 /* Return the named attribute or NULL if not there. */
18991 static struct attribute
*
18992 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18997 struct attribute
*spec
= NULL
;
18999 for (i
= 0; i
< die
->num_attrs
; ++i
)
19001 if (die
->attrs
[i
].name
== name
)
19002 return &die
->attrs
[i
];
19003 if (die
->attrs
[i
].name
== DW_AT_specification
19004 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19005 spec
= &die
->attrs
[i
];
19011 die
= follow_die_ref (die
, spec
, &cu
);
19017 /* Return the string associated with a string-typed attribute, or NULL if it
19018 is either not found or is of an incorrect type. */
19020 static const char *
19021 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19023 struct attribute
*attr
;
19024 const char *str
= NULL
;
19026 attr
= dwarf2_attr (die
, name
, cu
);
19030 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19031 || attr
->form
== DW_FORM_string
19032 || attr
->form
== DW_FORM_strx
19033 || attr
->form
== DW_FORM_strx1
19034 || attr
->form
== DW_FORM_strx2
19035 || attr
->form
== DW_FORM_strx3
19036 || attr
->form
== DW_FORM_strx4
19037 || attr
->form
== DW_FORM_GNU_str_index
19038 || attr
->form
== DW_FORM_GNU_strp_alt
)
19039 str
= DW_STRING (attr
);
19041 complaint (_("string type expected for attribute %s for "
19042 "DIE at %s in module %s"),
19043 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19044 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19050 /* Return the dwo name or NULL if not present. If present, it is in either
19051 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19052 static const char *
19053 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19055 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19056 if (dwo_name
== nullptr)
19057 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19061 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19062 and holds a non-zero value. This function should only be used for
19063 DW_FORM_flag or DW_FORM_flag_present attributes. */
19066 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19068 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19070 return (attr
&& DW_UNSND (attr
));
19074 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19076 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19077 which value is non-zero. However, we have to be careful with
19078 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19079 (via dwarf2_flag_true_p) follows this attribute. So we may
19080 end up accidently finding a declaration attribute that belongs
19081 to a different DIE referenced by the specification attribute,
19082 even though the given DIE does not have a declaration attribute. */
19083 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19084 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19087 /* Return the die giving the specification for DIE, if there is
19088 one. *SPEC_CU is the CU containing DIE on input, and the CU
19089 containing the return value on output. If there is no
19090 specification, but there is an abstract origin, that is
19093 static struct die_info
*
19094 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19096 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19099 if (spec_attr
== NULL
)
19100 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19102 if (spec_attr
== NULL
)
19105 return follow_die_ref (die
, spec_attr
, spec_cu
);
19108 /* Stub for free_line_header to match void * callback types. */
19111 free_line_header_voidp (void *arg
)
19113 struct line_header
*lh
= (struct line_header
*) arg
;
19118 /* A convenience function to find the proper .debug_line section for a CU. */
19120 static struct dwarf2_section_info
*
19121 get_debug_line_section (struct dwarf2_cu
*cu
)
19123 struct dwarf2_section_info
*section
;
19124 struct dwarf2_per_objfile
*dwarf2_per_objfile
19125 = cu
->per_cu
->dwarf2_per_objfile
;
19127 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19129 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19130 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19131 else if (cu
->per_cu
->is_dwz
)
19133 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19135 section
= &dwz
->line
;
19138 section
= &dwarf2_per_objfile
->line
;
19143 /* Read the statement program header starting at OFFSET in
19144 .debug_line, or .debug_line.dwo. Return a pointer
19145 to a struct line_header, allocated using xmalloc.
19146 Returns NULL if there is a problem reading the header, e.g., if it
19147 has a version we don't understand.
19149 NOTE: the strings in the include directory and file name tables of
19150 the returned object point into the dwarf line section buffer,
19151 and must not be freed. */
19153 static line_header_up
19154 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19156 struct dwarf2_section_info
*section
;
19157 struct dwarf2_per_objfile
*dwarf2_per_objfile
19158 = cu
->per_cu
->dwarf2_per_objfile
;
19160 section
= get_debug_line_section (cu
);
19161 section
->read (dwarf2_per_objfile
->objfile
);
19162 if (section
->buffer
== NULL
)
19164 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19165 complaint (_("missing .debug_line.dwo section"));
19167 complaint (_("missing .debug_line section"));
19171 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19172 dwarf2_per_objfile
, section
,
19176 /* Subroutine of dwarf_decode_lines to simplify it.
19177 Return the file name of the psymtab for the given file_entry.
19178 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19179 If space for the result is malloc'd, *NAME_HOLDER will be set.
19180 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19182 static const char *
19183 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19184 const dwarf2_psymtab
*pst
,
19185 const char *comp_dir
,
19186 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19188 const char *include_name
= fe
.name
;
19189 const char *include_name_to_compare
= include_name
;
19190 const char *pst_filename
;
19193 const char *dir_name
= fe
.include_dir (lh
);
19195 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19196 if (!IS_ABSOLUTE_PATH (include_name
)
19197 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19199 /* Avoid creating a duplicate psymtab for PST.
19200 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19201 Before we do the comparison, however, we need to account
19202 for DIR_NAME and COMP_DIR.
19203 First prepend dir_name (if non-NULL). If we still don't
19204 have an absolute path prepend comp_dir (if non-NULL).
19205 However, the directory we record in the include-file's
19206 psymtab does not contain COMP_DIR (to match the
19207 corresponding symtab(s)).
19212 bash$ gcc -g ./hello.c
19213 include_name = "hello.c"
19215 DW_AT_comp_dir = comp_dir = "/tmp"
19216 DW_AT_name = "./hello.c"
19220 if (dir_name
!= NULL
)
19222 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19223 include_name
, (char *) NULL
));
19224 include_name
= name_holder
->get ();
19225 include_name_to_compare
= include_name
;
19227 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19229 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19230 include_name
, (char *) NULL
));
19231 include_name_to_compare
= hold_compare
.get ();
19235 pst_filename
= pst
->filename
;
19236 gdb::unique_xmalloc_ptr
<char> copied_name
;
19237 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19239 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19240 pst_filename
, (char *) NULL
));
19241 pst_filename
= copied_name
.get ();
19244 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19248 return include_name
;
19251 /* State machine to track the state of the line number program. */
19253 class lnp_state_machine
19256 /* Initialize a machine state for the start of a line number
19258 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19259 bool record_lines_p
);
19261 file_entry
*current_file ()
19263 /* lh->file_names is 0-based, but the file name numbers in the
19264 statement program are 1-based. */
19265 return m_line_header
->file_name_at (m_file
);
19268 /* Record the line in the state machine. END_SEQUENCE is true if
19269 we're processing the end of a sequence. */
19270 void record_line (bool end_sequence
);
19272 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19273 nop-out rest of the lines in this sequence. */
19274 void check_line_address (struct dwarf2_cu
*cu
,
19275 const gdb_byte
*line_ptr
,
19276 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19278 void handle_set_discriminator (unsigned int discriminator
)
19280 m_discriminator
= discriminator
;
19281 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19284 /* Handle DW_LNE_set_address. */
19285 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19288 address
+= baseaddr
;
19289 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19292 /* Handle DW_LNS_advance_pc. */
19293 void handle_advance_pc (CORE_ADDR adjust
);
19295 /* Handle a special opcode. */
19296 void handle_special_opcode (unsigned char op_code
);
19298 /* Handle DW_LNS_advance_line. */
19299 void handle_advance_line (int line_delta
)
19301 advance_line (line_delta
);
19304 /* Handle DW_LNS_set_file. */
19305 void handle_set_file (file_name_index file
);
19307 /* Handle DW_LNS_negate_stmt. */
19308 void handle_negate_stmt ()
19310 m_is_stmt
= !m_is_stmt
;
19313 /* Handle DW_LNS_const_add_pc. */
19314 void handle_const_add_pc ();
19316 /* Handle DW_LNS_fixed_advance_pc. */
19317 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19319 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19323 /* Handle DW_LNS_copy. */
19324 void handle_copy ()
19326 record_line (false);
19327 m_discriminator
= 0;
19330 /* Handle DW_LNE_end_sequence. */
19331 void handle_end_sequence ()
19333 m_currently_recording_lines
= true;
19337 /* Advance the line by LINE_DELTA. */
19338 void advance_line (int line_delta
)
19340 m_line
+= line_delta
;
19342 if (line_delta
!= 0)
19343 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19346 struct dwarf2_cu
*m_cu
;
19348 gdbarch
*m_gdbarch
;
19350 /* True if we're recording lines.
19351 Otherwise we're building partial symtabs and are just interested in
19352 finding include files mentioned by the line number program. */
19353 bool m_record_lines_p
;
19355 /* The line number header. */
19356 line_header
*m_line_header
;
19358 /* These are part of the standard DWARF line number state machine,
19359 and initialized according to the DWARF spec. */
19361 unsigned char m_op_index
= 0;
19362 /* The line table index of the current file. */
19363 file_name_index m_file
= 1;
19364 unsigned int m_line
= 1;
19366 /* These are initialized in the constructor. */
19368 CORE_ADDR m_address
;
19370 unsigned int m_discriminator
;
19372 /* Additional bits of state we need to track. */
19374 /* The last file that we called dwarf2_start_subfile for.
19375 This is only used for TLLs. */
19376 unsigned int m_last_file
= 0;
19377 /* The last file a line number was recorded for. */
19378 struct subfile
*m_last_subfile
= NULL
;
19380 /* When true, record the lines we decode. */
19381 bool m_currently_recording_lines
= false;
19383 /* The last line number that was recorded, used to coalesce
19384 consecutive entries for the same line. This can happen, for
19385 example, when discriminators are present. PR 17276. */
19386 unsigned int m_last_line
= 0;
19387 bool m_line_has_non_zero_discriminator
= false;
19391 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19393 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19394 / m_line_header
->maximum_ops_per_instruction
)
19395 * m_line_header
->minimum_instruction_length
);
19396 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19397 m_op_index
= ((m_op_index
+ adjust
)
19398 % m_line_header
->maximum_ops_per_instruction
);
19402 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19404 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19405 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19406 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19407 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19408 / m_line_header
->maximum_ops_per_instruction
)
19409 * m_line_header
->minimum_instruction_length
);
19410 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19411 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19412 % m_line_header
->maximum_ops_per_instruction
);
19414 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19415 advance_line (line_delta
);
19416 record_line (false);
19417 m_discriminator
= 0;
19421 lnp_state_machine::handle_set_file (file_name_index file
)
19425 const file_entry
*fe
= current_file ();
19427 dwarf2_debug_line_missing_file_complaint ();
19428 else if (m_record_lines_p
)
19430 const char *dir
= fe
->include_dir (m_line_header
);
19432 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19433 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19434 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19439 lnp_state_machine::handle_const_add_pc ()
19442 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19445 = (((m_op_index
+ adjust
)
19446 / m_line_header
->maximum_ops_per_instruction
)
19447 * m_line_header
->minimum_instruction_length
);
19449 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19450 m_op_index
= ((m_op_index
+ adjust
)
19451 % m_line_header
->maximum_ops_per_instruction
);
19454 /* Return non-zero if we should add LINE to the line number table.
19455 LINE is the line to add, LAST_LINE is the last line that was added,
19456 LAST_SUBFILE is the subfile for LAST_LINE.
19457 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19458 had a non-zero discriminator.
19460 We have to be careful in the presence of discriminators.
19461 E.g., for this line:
19463 for (i = 0; i < 100000; i++);
19465 clang can emit four line number entries for that one line,
19466 each with a different discriminator.
19467 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19469 However, we want gdb to coalesce all four entries into one.
19470 Otherwise the user could stepi into the middle of the line and
19471 gdb would get confused about whether the pc really was in the
19472 middle of the line.
19474 Things are further complicated by the fact that two consecutive
19475 line number entries for the same line is a heuristic used by gcc
19476 to denote the end of the prologue. So we can't just discard duplicate
19477 entries, we have to be selective about it. The heuristic we use is
19478 that we only collapse consecutive entries for the same line if at least
19479 one of those entries has a non-zero discriminator. PR 17276.
19481 Note: Addresses in the line number state machine can never go backwards
19482 within one sequence, thus this coalescing is ok. */
19485 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19486 unsigned int line
, unsigned int last_line
,
19487 int line_has_non_zero_discriminator
,
19488 struct subfile
*last_subfile
)
19490 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19492 if (line
!= last_line
)
19494 /* Same line for the same file that we've seen already.
19495 As a last check, for pr 17276, only record the line if the line
19496 has never had a non-zero discriminator. */
19497 if (!line_has_non_zero_discriminator
)
19502 /* Use the CU's builder to record line number LINE beginning at
19503 address ADDRESS in the line table of subfile SUBFILE. */
19506 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19507 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19508 struct dwarf2_cu
*cu
)
19510 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19512 if (dwarf_line_debug
)
19514 fprintf_unfiltered (gdb_stdlog
,
19515 "Recording line %u, file %s, address %s\n",
19516 line
, lbasename (subfile
->name
),
19517 paddress (gdbarch
, address
));
19521 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19524 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19525 Mark the end of a set of line number records.
19526 The arguments are the same as for dwarf_record_line_1.
19527 If SUBFILE is NULL the request is ignored. */
19530 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19531 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19533 if (subfile
== NULL
)
19536 if (dwarf_line_debug
)
19538 fprintf_unfiltered (gdb_stdlog
,
19539 "Finishing current line, file %s, address %s\n",
19540 lbasename (subfile
->name
),
19541 paddress (gdbarch
, address
));
19544 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19548 lnp_state_machine::record_line (bool end_sequence
)
19550 if (dwarf_line_debug
)
19552 fprintf_unfiltered (gdb_stdlog
,
19553 "Processing actual line %u: file %u,"
19554 " address %s, is_stmt %u, discrim %u%s\n",
19556 paddress (m_gdbarch
, m_address
),
19557 m_is_stmt
, m_discriminator
,
19558 (end_sequence
? "\t(end sequence)" : ""));
19561 file_entry
*fe
= current_file ();
19564 dwarf2_debug_line_missing_file_complaint ();
19565 /* For now we ignore lines not starting on an instruction boundary.
19566 But not when processing end_sequence for compatibility with the
19567 previous version of the code. */
19568 else if (m_op_index
== 0 || end_sequence
)
19570 fe
->included_p
= 1;
19571 if (m_record_lines_p
)
19573 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19576 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19577 m_currently_recording_lines
? m_cu
: nullptr);
19582 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19584 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19585 m_line_has_non_zero_discriminator
,
19588 buildsym_compunit
*builder
= m_cu
->get_builder ();
19589 dwarf_record_line_1 (m_gdbarch
,
19590 builder
->get_current_subfile (),
19591 m_line
, m_address
, is_stmt
,
19592 m_currently_recording_lines
? m_cu
: nullptr);
19594 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19595 m_last_line
= m_line
;
19601 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19602 line_header
*lh
, bool record_lines_p
)
19606 m_record_lines_p
= record_lines_p
;
19607 m_line_header
= lh
;
19609 m_currently_recording_lines
= true;
19611 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19612 was a line entry for it so that the backend has a chance to adjust it
19613 and also record it in case it needs it. This is currently used by MIPS
19614 code, cf. `mips_adjust_dwarf2_line'. */
19615 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19616 m_is_stmt
= lh
->default_is_stmt
;
19617 m_discriminator
= 0;
19621 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19622 const gdb_byte
*line_ptr
,
19623 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19625 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19626 the pc range of the CU. However, we restrict the test to only ADDRESS
19627 values of zero to preserve GDB's previous behaviour which is to handle
19628 the specific case of a function being GC'd by the linker. */
19630 if (address
== 0 && address
< unrelocated_lowpc
)
19632 /* This line table is for a function which has been
19633 GCd by the linker. Ignore it. PR gdb/12528 */
19635 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19636 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19638 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19639 line_offset
, objfile_name (objfile
));
19640 m_currently_recording_lines
= false;
19641 /* Note: m_currently_recording_lines is left as false until we see
19642 DW_LNE_end_sequence. */
19646 /* Subroutine of dwarf_decode_lines to simplify it.
19647 Process the line number information in LH.
19648 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19649 program in order to set included_p for every referenced header. */
19652 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19653 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19655 const gdb_byte
*line_ptr
, *extended_end
;
19656 const gdb_byte
*line_end
;
19657 unsigned int bytes_read
, extended_len
;
19658 unsigned char op_code
, extended_op
;
19659 CORE_ADDR baseaddr
;
19660 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19661 bfd
*abfd
= objfile
->obfd
;
19662 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19663 /* True if we're recording line info (as opposed to building partial
19664 symtabs and just interested in finding include files mentioned by
19665 the line number program). */
19666 bool record_lines_p
= !decode_for_pst_p
;
19668 baseaddr
= objfile
->text_section_offset ();
19670 line_ptr
= lh
->statement_program_start
;
19671 line_end
= lh
->statement_program_end
;
19673 /* Read the statement sequences until there's nothing left. */
19674 while (line_ptr
< line_end
)
19676 /* The DWARF line number program state machine. Reset the state
19677 machine at the start of each sequence. */
19678 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19679 bool end_sequence
= false;
19681 if (record_lines_p
)
19683 /* Start a subfile for the current file of the state
19685 const file_entry
*fe
= state_machine
.current_file ();
19688 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19691 /* Decode the table. */
19692 while (line_ptr
< line_end
&& !end_sequence
)
19694 op_code
= read_1_byte (abfd
, line_ptr
);
19697 if (op_code
>= lh
->opcode_base
)
19699 /* Special opcode. */
19700 state_machine
.handle_special_opcode (op_code
);
19702 else switch (op_code
)
19704 case DW_LNS_extended_op
:
19705 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19707 line_ptr
+= bytes_read
;
19708 extended_end
= line_ptr
+ extended_len
;
19709 extended_op
= read_1_byte (abfd
, line_ptr
);
19711 switch (extended_op
)
19713 case DW_LNE_end_sequence
:
19714 state_machine
.handle_end_sequence ();
19715 end_sequence
= true;
19717 case DW_LNE_set_address
:
19720 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19721 line_ptr
+= bytes_read
;
19723 state_machine
.check_line_address (cu
, line_ptr
,
19724 lowpc
- baseaddr
, address
);
19725 state_machine
.handle_set_address (baseaddr
, address
);
19728 case DW_LNE_define_file
:
19730 const char *cur_file
;
19731 unsigned int mod_time
, length
;
19734 cur_file
= read_direct_string (abfd
, line_ptr
,
19736 line_ptr
+= bytes_read
;
19737 dindex
= (dir_index
)
19738 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19739 line_ptr
+= bytes_read
;
19741 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19742 line_ptr
+= bytes_read
;
19744 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19745 line_ptr
+= bytes_read
;
19746 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19749 case DW_LNE_set_discriminator
:
19751 /* The discriminator is not interesting to the
19752 debugger; just ignore it. We still need to
19753 check its value though:
19754 if there are consecutive entries for the same
19755 (non-prologue) line we want to coalesce them.
19758 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19759 line_ptr
+= bytes_read
;
19761 state_machine
.handle_set_discriminator (discr
);
19765 complaint (_("mangled .debug_line section"));
19768 /* Make sure that we parsed the extended op correctly. If e.g.
19769 we expected a different address size than the producer used,
19770 we may have read the wrong number of bytes. */
19771 if (line_ptr
!= extended_end
)
19773 complaint (_("mangled .debug_line section"));
19778 state_machine
.handle_copy ();
19780 case DW_LNS_advance_pc
:
19783 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19784 line_ptr
+= bytes_read
;
19786 state_machine
.handle_advance_pc (adjust
);
19789 case DW_LNS_advance_line
:
19792 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19793 line_ptr
+= bytes_read
;
19795 state_machine
.handle_advance_line (line_delta
);
19798 case DW_LNS_set_file
:
19800 file_name_index file
19801 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19803 line_ptr
+= bytes_read
;
19805 state_machine
.handle_set_file (file
);
19808 case DW_LNS_set_column
:
19809 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19810 line_ptr
+= bytes_read
;
19812 case DW_LNS_negate_stmt
:
19813 state_machine
.handle_negate_stmt ();
19815 case DW_LNS_set_basic_block
:
19817 /* Add to the address register of the state machine the
19818 address increment value corresponding to special opcode
19819 255. I.e., this value is scaled by the minimum
19820 instruction length since special opcode 255 would have
19821 scaled the increment. */
19822 case DW_LNS_const_add_pc
:
19823 state_machine
.handle_const_add_pc ();
19825 case DW_LNS_fixed_advance_pc
:
19827 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19830 state_machine
.handle_fixed_advance_pc (addr_adj
);
19835 /* Unknown standard opcode, ignore it. */
19838 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19840 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19841 line_ptr
+= bytes_read
;
19848 dwarf2_debug_line_missing_end_sequence_complaint ();
19850 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19851 in which case we still finish recording the last line). */
19852 state_machine
.record_line (true);
19856 /* Decode the Line Number Program (LNP) for the given line_header
19857 structure and CU. The actual information extracted and the type
19858 of structures created from the LNP depends on the value of PST.
19860 1. If PST is NULL, then this procedure uses the data from the program
19861 to create all necessary symbol tables, and their linetables.
19863 2. If PST is not NULL, this procedure reads the program to determine
19864 the list of files included by the unit represented by PST, and
19865 builds all the associated partial symbol tables.
19867 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19868 It is used for relative paths in the line table.
19869 NOTE: When processing partial symtabs (pst != NULL),
19870 comp_dir == pst->dirname.
19872 NOTE: It is important that psymtabs have the same file name (via strcmp)
19873 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19874 symtab we don't use it in the name of the psymtabs we create.
19875 E.g. expand_line_sal requires this when finding psymtabs to expand.
19876 A good testcase for this is mb-inline.exp.
19878 LOWPC is the lowest address in CU (or 0 if not known).
19880 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19881 for its PC<->lines mapping information. Otherwise only the filename
19882 table is read in. */
19885 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19886 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19887 CORE_ADDR lowpc
, int decode_mapping
)
19889 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19890 const int decode_for_pst_p
= (pst
!= NULL
);
19892 if (decode_mapping
)
19893 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19895 if (decode_for_pst_p
)
19897 /* Now that we're done scanning the Line Header Program, we can
19898 create the psymtab of each included file. */
19899 for (auto &file_entry
: lh
->file_names ())
19900 if (file_entry
.included_p
== 1)
19902 gdb::unique_xmalloc_ptr
<char> name_holder
;
19903 const char *include_name
=
19904 psymtab_include_file_name (lh
, file_entry
, pst
,
19905 comp_dir
, &name_holder
);
19906 if (include_name
!= NULL
)
19907 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19912 /* Make sure a symtab is created for every file, even files
19913 which contain only variables (i.e. no code with associated
19915 buildsym_compunit
*builder
= cu
->get_builder ();
19916 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19918 for (auto &fe
: lh
->file_names ())
19920 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19921 if (builder
->get_current_subfile ()->symtab
== NULL
)
19923 builder
->get_current_subfile ()->symtab
19924 = allocate_symtab (cust
,
19925 builder
->get_current_subfile ()->name
);
19927 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19932 /* Start a subfile for DWARF. FILENAME is the name of the file and
19933 DIRNAME the name of the source directory which contains FILENAME
19934 or NULL if not known.
19935 This routine tries to keep line numbers from identical absolute and
19936 relative file names in a common subfile.
19938 Using the `list' example from the GDB testsuite, which resides in
19939 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19940 of /srcdir/list0.c yields the following debugging information for list0.c:
19942 DW_AT_name: /srcdir/list0.c
19943 DW_AT_comp_dir: /compdir
19944 files.files[0].name: list0.h
19945 files.files[0].dir: /srcdir
19946 files.files[1].name: list0.c
19947 files.files[1].dir: /srcdir
19949 The line number information for list0.c has to end up in a single
19950 subfile, so that `break /srcdir/list0.c:1' works as expected.
19951 start_subfile will ensure that this happens provided that we pass the
19952 concatenation of files.files[1].dir and files.files[1].name as the
19956 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19957 const char *dirname
)
19959 gdb::unique_xmalloc_ptr
<char> copy
;
19961 /* In order not to lose the line information directory,
19962 we concatenate it to the filename when it makes sense.
19963 Note that the Dwarf3 standard says (speaking of filenames in line
19964 information): ``The directory index is ignored for file names
19965 that represent full path names''. Thus ignoring dirname in the
19966 `else' branch below isn't an issue. */
19968 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19970 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19971 filename
= copy
.get ();
19974 cu
->get_builder ()->start_subfile (filename
);
19977 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19978 buildsym_compunit constructor. */
19980 struct compunit_symtab
*
19981 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19984 gdb_assert (m_builder
== nullptr);
19986 m_builder
.reset (new struct buildsym_compunit
19987 (per_cu
->dwarf2_per_objfile
->objfile
,
19988 name
, comp_dir
, language
, low_pc
));
19990 list_in_scope
= get_builder ()->get_file_symbols ();
19992 get_builder ()->record_debugformat ("DWARF 2");
19993 get_builder ()->record_producer (producer
);
19995 processing_has_namespace_info
= false;
19997 return get_builder ()->get_compunit_symtab ();
20001 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
20002 struct dwarf2_cu
*cu
)
20004 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20005 struct comp_unit_head
*cu_header
= &cu
->header
;
20007 /* NOTE drow/2003-01-30: There used to be a comment and some special
20008 code here to turn a symbol with DW_AT_external and a
20009 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
20010 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
20011 with some versions of binutils) where shared libraries could have
20012 relocations against symbols in their debug information - the
20013 minimal symbol would have the right address, but the debug info
20014 would not. It's no longer necessary, because we will explicitly
20015 apply relocations when we read in the debug information now. */
20017 /* A DW_AT_location attribute with no contents indicates that a
20018 variable has been optimized away. */
20019 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
20021 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20025 /* Handle one degenerate form of location expression specially, to
20026 preserve GDB's previous behavior when section offsets are
20027 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
20028 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
20030 if (attr
->form_is_block ()
20031 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
20032 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
20033 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
20034 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
20035 && (DW_BLOCK (attr
)->size
20036 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
20038 unsigned int dummy
;
20040 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
20041 SET_SYMBOL_VALUE_ADDRESS
20042 (sym
, cu
->header
.read_address (objfile
->obfd
,
20043 DW_BLOCK (attr
)->data
+ 1,
20046 SET_SYMBOL_VALUE_ADDRESS
20047 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
20049 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
20050 fixup_symbol_section (sym
, objfile
);
20051 SET_SYMBOL_VALUE_ADDRESS
20053 SYMBOL_VALUE_ADDRESS (sym
)
20054 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
20058 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
20059 expression evaluator, and use LOC_COMPUTED only when necessary
20060 (i.e. when the value of a register or memory location is
20061 referenced, or a thread-local block, etc.). Then again, it might
20062 not be worthwhile. I'm assuming that it isn't unless performance
20063 or memory numbers show me otherwise. */
20065 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
20067 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
20068 cu
->has_loclist
= true;
20071 /* Given a pointer to a DWARF information entry, figure out if we need
20072 to make a symbol table entry for it, and if so, create a new entry
20073 and return a pointer to it.
20074 If TYPE is NULL, determine symbol type from the die, otherwise
20075 used the passed type.
20076 If SPACE is not NULL, use it to hold the new symbol. If it is
20077 NULL, allocate a new symbol on the objfile's obstack. */
20079 static struct symbol
*
20080 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20081 struct symbol
*space
)
20083 struct dwarf2_per_objfile
*dwarf2_per_objfile
20084 = cu
->per_cu
->dwarf2_per_objfile
;
20085 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20086 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20087 struct symbol
*sym
= NULL
;
20089 struct attribute
*attr
= NULL
;
20090 struct attribute
*attr2
= NULL
;
20091 CORE_ADDR baseaddr
;
20092 struct pending
**list_to_add
= NULL
;
20094 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20096 baseaddr
= objfile
->text_section_offset ();
20098 name
= dwarf2_name (die
, cu
);
20101 const char *linkagename
;
20102 int suppress_add
= 0;
20107 sym
= allocate_symbol (objfile
);
20108 OBJSTAT (objfile
, n_syms
++);
20110 /* Cache this symbol's name and the name's demangled form (if any). */
20111 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20112 linkagename
= dwarf2_physname (name
, die
, cu
);
20113 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20115 /* Fortran does not have mangling standard and the mangling does differ
20116 between gfortran, iFort etc. */
20117 if (cu
->language
== language_fortran
20118 && symbol_get_demangled_name (sym
) == NULL
)
20119 symbol_set_demangled_name (sym
,
20120 dwarf2_full_name (name
, die
, cu
),
20123 /* Default assumptions.
20124 Use the passed type or decode it from the die. */
20125 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20126 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20128 SYMBOL_TYPE (sym
) = type
;
20130 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20131 attr
= dwarf2_attr (die
,
20132 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20134 if (attr
!= nullptr)
20136 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20139 attr
= dwarf2_attr (die
,
20140 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20142 if (attr
!= nullptr)
20144 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20145 struct file_entry
*fe
;
20147 if (cu
->line_header
!= NULL
)
20148 fe
= cu
->line_header
->file_name_at (file_index
);
20153 complaint (_("file index out of range"));
20155 symbol_set_symtab (sym
, fe
->symtab
);
20161 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20162 if (attr
!= nullptr)
20166 addr
= attr
->value_as_address ();
20167 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20168 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20170 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20171 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20172 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20173 add_symbol_to_list (sym
, cu
->list_in_scope
);
20175 case DW_TAG_subprogram
:
20176 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20178 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20179 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20180 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20181 || cu
->language
== language_ada
20182 || cu
->language
== language_fortran
)
20184 /* Subprograms marked external are stored as a global symbol.
20185 Ada and Fortran subprograms, whether marked external or
20186 not, are always stored as a global symbol, because we want
20187 to be able to access them globally. For instance, we want
20188 to be able to break on a nested subprogram without having
20189 to specify the context. */
20190 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20194 list_to_add
= cu
->list_in_scope
;
20197 case DW_TAG_inlined_subroutine
:
20198 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20200 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20201 SYMBOL_INLINED (sym
) = 1;
20202 list_to_add
= cu
->list_in_scope
;
20204 case DW_TAG_template_value_param
:
20206 /* Fall through. */
20207 case DW_TAG_constant
:
20208 case DW_TAG_variable
:
20209 case DW_TAG_member
:
20210 /* Compilation with minimal debug info may result in
20211 variables with missing type entries. Change the
20212 misleading `void' type to something sensible. */
20213 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20214 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20216 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20217 /* In the case of DW_TAG_member, we should only be called for
20218 static const members. */
20219 if (die
->tag
== DW_TAG_member
)
20221 /* dwarf2_add_field uses die_is_declaration,
20222 so we do the same. */
20223 gdb_assert (die_is_declaration (die
, cu
));
20226 if (attr
!= nullptr)
20228 dwarf2_const_value (attr
, sym
, cu
);
20229 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20232 if (attr2
&& (DW_UNSND (attr2
) != 0))
20233 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20235 list_to_add
= cu
->list_in_scope
;
20239 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20240 if (attr
!= nullptr)
20242 var_decode_location (attr
, sym
, cu
);
20243 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20245 /* Fortran explicitly imports any global symbols to the local
20246 scope by DW_TAG_common_block. */
20247 if (cu
->language
== language_fortran
&& die
->parent
20248 && die
->parent
->tag
== DW_TAG_common_block
)
20251 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20252 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20253 && !dwarf2_per_objfile
->has_section_at_zero
)
20255 /* When a static variable is eliminated by the linker,
20256 the corresponding debug information is not stripped
20257 out, but the variable address is set to null;
20258 do not add such variables into symbol table. */
20260 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20262 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20263 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20264 && dwarf2_per_objfile
->can_copy
)
20266 /* A global static variable might be subject to
20267 copy relocation. We first check for a local
20268 minsym, though, because maybe the symbol was
20269 marked hidden, in which case this would not
20271 bound_minimal_symbol found
20272 = (lookup_minimal_symbol_linkage
20273 (sym
->linkage_name (), objfile
));
20274 if (found
.minsym
!= nullptr)
20275 sym
->maybe_copied
= 1;
20278 /* A variable with DW_AT_external is never static,
20279 but it may be block-scoped. */
20281 = ((cu
->list_in_scope
20282 == cu
->get_builder ()->get_file_symbols ())
20283 ? cu
->get_builder ()->get_global_symbols ()
20284 : cu
->list_in_scope
);
20287 list_to_add
= cu
->list_in_scope
;
20291 /* We do not know the address of this symbol.
20292 If it is an external symbol and we have type information
20293 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20294 The address of the variable will then be determined from
20295 the minimal symbol table whenever the variable is
20297 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20299 /* Fortran explicitly imports any global symbols to the local
20300 scope by DW_TAG_common_block. */
20301 if (cu
->language
== language_fortran
&& die
->parent
20302 && die
->parent
->tag
== DW_TAG_common_block
)
20304 /* SYMBOL_CLASS doesn't matter here because
20305 read_common_block is going to reset it. */
20307 list_to_add
= cu
->list_in_scope
;
20309 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20310 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20312 /* A variable with DW_AT_external is never static, but it
20313 may be block-scoped. */
20315 = ((cu
->list_in_scope
20316 == cu
->get_builder ()->get_file_symbols ())
20317 ? cu
->get_builder ()->get_global_symbols ()
20318 : cu
->list_in_scope
);
20320 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20322 else if (!die_is_declaration (die
, cu
))
20324 /* Use the default LOC_OPTIMIZED_OUT class. */
20325 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20327 list_to_add
= cu
->list_in_scope
;
20331 case DW_TAG_formal_parameter
:
20333 /* If we are inside a function, mark this as an argument. If
20334 not, we might be looking at an argument to an inlined function
20335 when we do not have enough information to show inlined frames;
20336 pretend it's a local variable in that case so that the user can
20338 struct context_stack
*curr
20339 = cu
->get_builder ()->get_current_context_stack ();
20340 if (curr
!= nullptr && curr
->name
!= nullptr)
20341 SYMBOL_IS_ARGUMENT (sym
) = 1;
20342 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20343 if (attr
!= nullptr)
20345 var_decode_location (attr
, sym
, cu
);
20347 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20348 if (attr
!= nullptr)
20350 dwarf2_const_value (attr
, sym
, cu
);
20353 list_to_add
= cu
->list_in_scope
;
20356 case DW_TAG_unspecified_parameters
:
20357 /* From varargs functions; gdb doesn't seem to have any
20358 interest in this information, so just ignore it for now.
20361 case DW_TAG_template_type_param
:
20363 /* Fall through. */
20364 case DW_TAG_class_type
:
20365 case DW_TAG_interface_type
:
20366 case DW_TAG_structure_type
:
20367 case DW_TAG_union_type
:
20368 case DW_TAG_set_type
:
20369 case DW_TAG_enumeration_type
:
20370 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20371 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20374 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20375 really ever be static objects: otherwise, if you try
20376 to, say, break of a class's method and you're in a file
20377 which doesn't mention that class, it won't work unless
20378 the check for all static symbols in lookup_symbol_aux
20379 saves you. See the OtherFileClass tests in
20380 gdb.c++/namespace.exp. */
20384 buildsym_compunit
*builder
= cu
->get_builder ();
20386 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20387 && cu
->language
== language_cplus
20388 ? builder
->get_global_symbols ()
20389 : cu
->list_in_scope
);
20391 /* The semantics of C++ state that "struct foo {
20392 ... }" also defines a typedef for "foo". */
20393 if (cu
->language
== language_cplus
20394 || cu
->language
== language_ada
20395 || cu
->language
== language_d
20396 || cu
->language
== language_rust
)
20398 /* The symbol's name is already allocated along
20399 with this objfile, so we don't need to
20400 duplicate it for the type. */
20401 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20402 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20407 case DW_TAG_typedef
:
20408 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20409 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20410 list_to_add
= cu
->list_in_scope
;
20412 case DW_TAG_base_type
:
20413 case DW_TAG_subrange_type
:
20414 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20415 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20416 list_to_add
= cu
->list_in_scope
;
20418 case DW_TAG_enumerator
:
20419 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20420 if (attr
!= nullptr)
20422 dwarf2_const_value (attr
, sym
, cu
);
20425 /* NOTE: carlton/2003-11-10: See comment above in the
20426 DW_TAG_class_type, etc. block. */
20429 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20430 && cu
->language
== language_cplus
20431 ? cu
->get_builder ()->get_global_symbols ()
20432 : cu
->list_in_scope
);
20435 case DW_TAG_imported_declaration
:
20436 case DW_TAG_namespace
:
20437 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20438 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20440 case DW_TAG_module
:
20441 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20442 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20443 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20445 case DW_TAG_common_block
:
20446 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20447 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20448 add_symbol_to_list (sym
, cu
->list_in_scope
);
20451 /* Not a tag we recognize. Hopefully we aren't processing
20452 trash data, but since we must specifically ignore things
20453 we don't recognize, there is nothing else we should do at
20455 complaint (_("unsupported tag: '%s'"),
20456 dwarf_tag_name (die
->tag
));
20462 sym
->hash_next
= objfile
->template_symbols
;
20463 objfile
->template_symbols
= sym
;
20464 list_to_add
= NULL
;
20467 if (list_to_add
!= NULL
)
20468 add_symbol_to_list (sym
, list_to_add
);
20470 /* For the benefit of old versions of GCC, check for anonymous
20471 namespaces based on the demangled name. */
20472 if (!cu
->processing_has_namespace_info
20473 && cu
->language
== language_cplus
)
20474 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20479 /* Given an attr with a DW_FORM_dataN value in host byte order,
20480 zero-extend it as appropriate for the symbol's type. The DWARF
20481 standard (v4) is not entirely clear about the meaning of using
20482 DW_FORM_dataN for a constant with a signed type, where the type is
20483 wider than the data. The conclusion of a discussion on the DWARF
20484 list was that this is unspecified. We choose to always zero-extend
20485 because that is the interpretation long in use by GCC. */
20488 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20489 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20491 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20492 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20493 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20494 LONGEST l
= DW_UNSND (attr
);
20496 if (bits
< sizeof (*value
) * 8)
20498 l
&= ((LONGEST
) 1 << bits
) - 1;
20501 else if (bits
== sizeof (*value
) * 8)
20505 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20506 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20513 /* Read a constant value from an attribute. Either set *VALUE, or if
20514 the value does not fit in *VALUE, set *BYTES - either already
20515 allocated on the objfile obstack, or newly allocated on OBSTACK,
20516 or, set *BATON, if we translated the constant to a location
20520 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20521 const char *name
, struct obstack
*obstack
,
20522 struct dwarf2_cu
*cu
,
20523 LONGEST
*value
, const gdb_byte
**bytes
,
20524 struct dwarf2_locexpr_baton
**baton
)
20526 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20527 struct comp_unit_head
*cu_header
= &cu
->header
;
20528 struct dwarf_block
*blk
;
20529 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20530 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20536 switch (attr
->form
)
20539 case DW_FORM_addrx
:
20540 case DW_FORM_GNU_addr_index
:
20544 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20545 dwarf2_const_value_length_mismatch_complaint (name
,
20546 cu_header
->addr_size
,
20547 TYPE_LENGTH (type
));
20548 /* Symbols of this form are reasonably rare, so we just
20549 piggyback on the existing location code rather than writing
20550 a new implementation of symbol_computed_ops. */
20551 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20552 (*baton
)->per_cu
= cu
->per_cu
;
20553 gdb_assert ((*baton
)->per_cu
);
20555 (*baton
)->size
= 2 + cu_header
->addr_size
;
20556 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20557 (*baton
)->data
= data
;
20559 data
[0] = DW_OP_addr
;
20560 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20561 byte_order
, DW_ADDR (attr
));
20562 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20565 case DW_FORM_string
:
20568 case DW_FORM_GNU_str_index
:
20569 case DW_FORM_GNU_strp_alt
:
20570 /* DW_STRING is already allocated on the objfile obstack, point
20572 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20574 case DW_FORM_block1
:
20575 case DW_FORM_block2
:
20576 case DW_FORM_block4
:
20577 case DW_FORM_block
:
20578 case DW_FORM_exprloc
:
20579 case DW_FORM_data16
:
20580 blk
= DW_BLOCK (attr
);
20581 if (TYPE_LENGTH (type
) != blk
->size
)
20582 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20583 TYPE_LENGTH (type
));
20584 *bytes
= blk
->data
;
20587 /* The DW_AT_const_value attributes are supposed to carry the
20588 symbol's value "represented as it would be on the target
20589 architecture." By the time we get here, it's already been
20590 converted to host endianness, so we just need to sign- or
20591 zero-extend it as appropriate. */
20592 case DW_FORM_data1
:
20593 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20595 case DW_FORM_data2
:
20596 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20598 case DW_FORM_data4
:
20599 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20601 case DW_FORM_data8
:
20602 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20605 case DW_FORM_sdata
:
20606 case DW_FORM_implicit_const
:
20607 *value
= DW_SND (attr
);
20610 case DW_FORM_udata
:
20611 *value
= DW_UNSND (attr
);
20615 complaint (_("unsupported const value attribute form: '%s'"),
20616 dwarf_form_name (attr
->form
));
20623 /* Copy constant value from an attribute to a symbol. */
20626 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20627 struct dwarf2_cu
*cu
)
20629 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20631 const gdb_byte
*bytes
;
20632 struct dwarf2_locexpr_baton
*baton
;
20634 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20635 sym
->print_name (),
20636 &objfile
->objfile_obstack
, cu
,
20637 &value
, &bytes
, &baton
);
20641 SYMBOL_LOCATION_BATON (sym
) = baton
;
20642 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20644 else if (bytes
!= NULL
)
20646 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20647 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20651 SYMBOL_VALUE (sym
) = value
;
20652 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20656 /* Return the type of the die in question using its DW_AT_type attribute. */
20658 static struct type
*
20659 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20661 struct attribute
*type_attr
;
20663 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20666 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20667 /* A missing DW_AT_type represents a void type. */
20668 return objfile_type (objfile
)->builtin_void
;
20671 return lookup_die_type (die
, type_attr
, cu
);
20674 /* True iff CU's producer generates GNAT Ada auxiliary information
20675 that allows to find parallel types through that information instead
20676 of having to do expensive parallel lookups by type name. */
20679 need_gnat_info (struct dwarf2_cu
*cu
)
20681 /* Assume that the Ada compiler was GNAT, which always produces
20682 the auxiliary information. */
20683 return (cu
->language
== language_ada
);
20686 /* Return the auxiliary type of the die in question using its
20687 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20688 attribute is not present. */
20690 static struct type
*
20691 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20693 struct attribute
*type_attr
;
20695 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20699 return lookup_die_type (die
, type_attr
, cu
);
20702 /* If DIE has a descriptive_type attribute, then set the TYPE's
20703 descriptive type accordingly. */
20706 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20707 struct dwarf2_cu
*cu
)
20709 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20711 if (descriptive_type
)
20713 ALLOCATE_GNAT_AUX_TYPE (type
);
20714 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20718 /* Return the containing type of the die in question using its
20719 DW_AT_containing_type attribute. */
20721 static struct type
*
20722 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20724 struct attribute
*type_attr
;
20725 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20727 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20729 error (_("Dwarf Error: Problem turning containing type into gdb type "
20730 "[in module %s]"), objfile_name (objfile
));
20732 return lookup_die_type (die
, type_attr
, cu
);
20735 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20737 static struct type
*
20738 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20740 struct dwarf2_per_objfile
*dwarf2_per_objfile
20741 = cu
->per_cu
->dwarf2_per_objfile
;
20742 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20745 std::string message
20746 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20747 objfile_name (objfile
),
20748 sect_offset_str (cu
->header
.sect_off
),
20749 sect_offset_str (die
->sect_off
));
20750 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20752 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20755 /* Look up the type of DIE in CU using its type attribute ATTR.
20756 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20757 DW_AT_containing_type.
20758 If there is no type substitute an error marker. */
20760 static struct type
*
20761 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20762 struct dwarf2_cu
*cu
)
20764 struct dwarf2_per_objfile
*dwarf2_per_objfile
20765 = cu
->per_cu
->dwarf2_per_objfile
;
20766 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20767 struct type
*this_type
;
20769 gdb_assert (attr
->name
== DW_AT_type
20770 || attr
->name
== DW_AT_GNAT_descriptive_type
20771 || attr
->name
== DW_AT_containing_type
);
20773 /* First see if we have it cached. */
20775 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20777 struct dwarf2_per_cu_data
*per_cu
;
20778 sect_offset sect_off
= attr
->get_ref_die_offset ();
20780 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20781 dwarf2_per_objfile
);
20782 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20784 else if (attr
->form_is_ref ())
20786 sect_offset sect_off
= attr
->get_ref_die_offset ();
20788 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20790 else if (attr
->form
== DW_FORM_ref_sig8
)
20792 ULONGEST signature
= DW_SIGNATURE (attr
);
20794 return get_signatured_type (die
, signature
, cu
);
20798 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20799 " at %s [in module %s]"),
20800 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20801 objfile_name (objfile
));
20802 return build_error_marker_type (cu
, die
);
20805 /* If not cached we need to read it in. */
20807 if (this_type
== NULL
)
20809 struct die_info
*type_die
= NULL
;
20810 struct dwarf2_cu
*type_cu
= cu
;
20812 if (attr
->form_is_ref ())
20813 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20814 if (type_die
== NULL
)
20815 return build_error_marker_type (cu
, die
);
20816 /* If we find the type now, it's probably because the type came
20817 from an inter-CU reference and the type's CU got expanded before
20819 this_type
= read_type_die (type_die
, type_cu
);
20822 /* If we still don't have a type use an error marker. */
20824 if (this_type
== NULL
)
20825 return build_error_marker_type (cu
, die
);
20830 /* Return the type in DIE, CU.
20831 Returns NULL for invalid types.
20833 This first does a lookup in die_type_hash,
20834 and only reads the die in if necessary.
20836 NOTE: This can be called when reading in partial or full symbols. */
20838 static struct type
*
20839 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20841 struct type
*this_type
;
20843 this_type
= get_die_type (die
, cu
);
20847 return read_type_die_1 (die
, cu
);
20850 /* Read the type in DIE, CU.
20851 Returns NULL for invalid types. */
20853 static struct type
*
20854 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20856 struct type
*this_type
= NULL
;
20860 case DW_TAG_class_type
:
20861 case DW_TAG_interface_type
:
20862 case DW_TAG_structure_type
:
20863 case DW_TAG_union_type
:
20864 this_type
= read_structure_type (die
, cu
);
20866 case DW_TAG_enumeration_type
:
20867 this_type
= read_enumeration_type (die
, cu
);
20869 case DW_TAG_subprogram
:
20870 case DW_TAG_subroutine_type
:
20871 case DW_TAG_inlined_subroutine
:
20872 this_type
= read_subroutine_type (die
, cu
);
20874 case DW_TAG_array_type
:
20875 this_type
= read_array_type (die
, cu
);
20877 case DW_TAG_set_type
:
20878 this_type
= read_set_type (die
, cu
);
20880 case DW_TAG_pointer_type
:
20881 this_type
= read_tag_pointer_type (die
, cu
);
20883 case DW_TAG_ptr_to_member_type
:
20884 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20886 case DW_TAG_reference_type
:
20887 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20889 case DW_TAG_rvalue_reference_type
:
20890 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20892 case DW_TAG_const_type
:
20893 this_type
= read_tag_const_type (die
, cu
);
20895 case DW_TAG_volatile_type
:
20896 this_type
= read_tag_volatile_type (die
, cu
);
20898 case DW_TAG_restrict_type
:
20899 this_type
= read_tag_restrict_type (die
, cu
);
20901 case DW_TAG_string_type
:
20902 this_type
= read_tag_string_type (die
, cu
);
20904 case DW_TAG_typedef
:
20905 this_type
= read_typedef (die
, cu
);
20907 case DW_TAG_subrange_type
:
20908 this_type
= read_subrange_type (die
, cu
);
20910 case DW_TAG_base_type
:
20911 this_type
= read_base_type (die
, cu
);
20913 case DW_TAG_unspecified_type
:
20914 this_type
= read_unspecified_type (die
, cu
);
20916 case DW_TAG_namespace
:
20917 this_type
= read_namespace_type (die
, cu
);
20919 case DW_TAG_module
:
20920 this_type
= read_module_type (die
, cu
);
20922 case DW_TAG_atomic_type
:
20923 this_type
= read_tag_atomic_type (die
, cu
);
20926 complaint (_("unexpected tag in read_type_die: '%s'"),
20927 dwarf_tag_name (die
->tag
));
20934 /* See if we can figure out if the class lives in a namespace. We do
20935 this by looking for a member function; its demangled name will
20936 contain namespace info, if there is any.
20937 Return the computed name or NULL.
20938 Space for the result is allocated on the objfile's obstack.
20939 This is the full-die version of guess_partial_die_structure_name.
20940 In this case we know DIE has no useful parent. */
20942 static const char *
20943 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20945 struct die_info
*spec_die
;
20946 struct dwarf2_cu
*spec_cu
;
20947 struct die_info
*child
;
20948 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20951 spec_die
= die_specification (die
, &spec_cu
);
20952 if (spec_die
!= NULL
)
20958 for (child
= die
->child
;
20960 child
= child
->sibling
)
20962 if (child
->tag
== DW_TAG_subprogram
)
20964 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20966 if (linkage_name
!= NULL
)
20968 gdb::unique_xmalloc_ptr
<char> actual_name
20969 (language_class_name_from_physname (cu
->language_defn
,
20971 const char *name
= NULL
;
20973 if (actual_name
!= NULL
)
20975 const char *die_name
= dwarf2_name (die
, cu
);
20977 if (die_name
!= NULL
20978 && strcmp (die_name
, actual_name
.get ()) != 0)
20980 /* Strip off the class name from the full name.
20981 We want the prefix. */
20982 int die_name_len
= strlen (die_name
);
20983 int actual_name_len
= strlen (actual_name
.get ());
20984 const char *ptr
= actual_name
.get ();
20986 /* Test for '::' as a sanity check. */
20987 if (actual_name_len
> die_name_len
+ 2
20988 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20989 name
= obstack_strndup (
20990 &objfile
->per_bfd
->storage_obstack
,
20991 ptr
, actual_name_len
- die_name_len
- 2);
21002 /* GCC might emit a nameless typedef that has a linkage name. Determine the
21003 prefix part in such case. See
21004 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21006 static const char *
21007 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21009 struct attribute
*attr
;
21012 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
21013 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
21016 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
21019 attr
= dw2_linkage_name_attr (die
, cu
);
21020 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21023 /* dwarf2_name had to be already called. */
21024 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
21026 /* Strip the base name, keep any leading namespaces/classes. */
21027 base
= strrchr (DW_STRING (attr
), ':');
21028 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
21031 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21032 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
21034 &base
[-1] - DW_STRING (attr
));
21037 /* Return the name of the namespace/class that DIE is defined within,
21038 or "" if we can't tell. The caller should not xfree the result.
21040 For example, if we're within the method foo() in the following
21050 then determine_prefix on foo's die will return "N::C". */
21052 static const char *
21053 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
21055 struct dwarf2_per_objfile
*dwarf2_per_objfile
21056 = cu
->per_cu
->dwarf2_per_objfile
;
21057 struct die_info
*parent
, *spec_die
;
21058 struct dwarf2_cu
*spec_cu
;
21059 struct type
*parent_type
;
21060 const char *retval
;
21062 if (cu
->language
!= language_cplus
21063 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
21064 && cu
->language
!= language_rust
)
21067 retval
= anonymous_struct_prefix (die
, cu
);
21071 /* We have to be careful in the presence of DW_AT_specification.
21072 For example, with GCC 3.4, given the code
21076 // Definition of N::foo.
21080 then we'll have a tree of DIEs like this:
21082 1: DW_TAG_compile_unit
21083 2: DW_TAG_namespace // N
21084 3: DW_TAG_subprogram // declaration of N::foo
21085 4: DW_TAG_subprogram // definition of N::foo
21086 DW_AT_specification // refers to die #3
21088 Thus, when processing die #4, we have to pretend that we're in
21089 the context of its DW_AT_specification, namely the contex of die
21092 spec_die
= die_specification (die
, &spec_cu
);
21093 if (spec_die
== NULL
)
21094 parent
= die
->parent
;
21097 parent
= spec_die
->parent
;
21101 if (parent
== NULL
)
21103 else if (parent
->building_fullname
)
21106 const char *parent_name
;
21108 /* It has been seen on RealView 2.2 built binaries,
21109 DW_TAG_template_type_param types actually _defined_ as
21110 children of the parent class:
21113 template class <class Enum> Class{};
21114 Class<enum E> class_e;
21116 1: DW_TAG_class_type (Class)
21117 2: DW_TAG_enumeration_type (E)
21118 3: DW_TAG_enumerator (enum1:0)
21119 3: DW_TAG_enumerator (enum2:1)
21121 2: DW_TAG_template_type_param
21122 DW_AT_type DW_FORM_ref_udata (E)
21124 Besides being broken debug info, it can put GDB into an
21125 infinite loop. Consider:
21127 When we're building the full name for Class<E>, we'll start
21128 at Class, and go look over its template type parameters,
21129 finding E. We'll then try to build the full name of E, and
21130 reach here. We're now trying to build the full name of E,
21131 and look over the parent DIE for containing scope. In the
21132 broken case, if we followed the parent DIE of E, we'd again
21133 find Class, and once again go look at its template type
21134 arguments, etc., etc. Simply don't consider such parent die
21135 as source-level parent of this die (it can't be, the language
21136 doesn't allow it), and break the loop here. */
21137 name
= dwarf2_name (die
, cu
);
21138 parent_name
= dwarf2_name (parent
, cu
);
21139 complaint (_("template param type '%s' defined within parent '%s'"),
21140 name
? name
: "<unknown>",
21141 parent_name
? parent_name
: "<unknown>");
21145 switch (parent
->tag
)
21147 case DW_TAG_namespace
:
21148 parent_type
= read_type_die (parent
, cu
);
21149 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21150 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21151 Work around this problem here. */
21152 if (cu
->language
== language_cplus
21153 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21155 /* We give a name to even anonymous namespaces. */
21156 return TYPE_NAME (parent_type
);
21157 case DW_TAG_class_type
:
21158 case DW_TAG_interface_type
:
21159 case DW_TAG_structure_type
:
21160 case DW_TAG_union_type
:
21161 case DW_TAG_module
:
21162 parent_type
= read_type_die (parent
, cu
);
21163 if (TYPE_NAME (parent_type
) != NULL
)
21164 return TYPE_NAME (parent_type
);
21166 /* An anonymous structure is only allowed non-static data
21167 members; no typedefs, no member functions, et cetera.
21168 So it does not need a prefix. */
21170 case DW_TAG_compile_unit
:
21171 case DW_TAG_partial_unit
:
21172 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21173 if (cu
->language
== language_cplus
21174 && !dwarf2_per_objfile
->types
.empty ()
21175 && die
->child
!= NULL
21176 && (die
->tag
== DW_TAG_class_type
21177 || die
->tag
== DW_TAG_structure_type
21178 || die
->tag
== DW_TAG_union_type
))
21180 const char *name
= guess_full_die_structure_name (die
, cu
);
21185 case DW_TAG_subprogram
:
21186 /* Nested subroutines in Fortran get a prefix with the name
21187 of the parent's subroutine. */
21188 if (cu
->language
== language_fortran
)
21190 if ((die
->tag
== DW_TAG_subprogram
)
21191 && (dwarf2_name (parent
, cu
) != NULL
))
21192 return dwarf2_name (parent
, cu
);
21194 return determine_prefix (parent
, cu
);
21195 case DW_TAG_enumeration_type
:
21196 parent_type
= read_type_die (parent
, cu
);
21197 if (TYPE_DECLARED_CLASS (parent_type
))
21199 if (TYPE_NAME (parent_type
) != NULL
)
21200 return TYPE_NAME (parent_type
);
21203 /* Fall through. */
21205 return determine_prefix (parent
, cu
);
21209 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21210 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21211 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21212 an obconcat, otherwise allocate storage for the result. The CU argument is
21213 used to determine the language and hence, the appropriate separator. */
21215 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21218 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21219 int physname
, struct dwarf2_cu
*cu
)
21221 const char *lead
= "";
21224 if (suffix
== NULL
|| suffix
[0] == '\0'
21225 || prefix
== NULL
|| prefix
[0] == '\0')
21227 else if (cu
->language
== language_d
)
21229 /* For D, the 'main' function could be defined in any module, but it
21230 should never be prefixed. */
21231 if (strcmp (suffix
, "D main") == 0)
21239 else if (cu
->language
== language_fortran
&& physname
)
21241 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21242 DW_AT_MIPS_linkage_name is preferred and used instead. */
21250 if (prefix
== NULL
)
21252 if (suffix
== NULL
)
21259 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21261 strcpy (retval
, lead
);
21262 strcat (retval
, prefix
);
21263 strcat (retval
, sep
);
21264 strcat (retval
, suffix
);
21269 /* We have an obstack. */
21270 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21274 /* Get name of a die, return NULL if not found. */
21276 static const char *
21277 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21278 struct objfile
*objfile
)
21280 if (name
&& cu
->language
== language_cplus
)
21282 std::string canon_name
= cp_canonicalize_string (name
);
21284 if (!canon_name
.empty ())
21286 if (canon_name
!= name
)
21287 name
= objfile
->intern (canon_name
);
21294 /* Get name of a die, return NULL if not found.
21295 Anonymous namespaces are converted to their magic string. */
21297 static const char *
21298 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21300 struct attribute
*attr
;
21301 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21303 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21304 if ((!attr
|| !DW_STRING (attr
))
21305 && die
->tag
!= DW_TAG_namespace
21306 && die
->tag
!= DW_TAG_class_type
21307 && die
->tag
!= DW_TAG_interface_type
21308 && die
->tag
!= DW_TAG_structure_type
21309 && die
->tag
!= DW_TAG_union_type
)
21314 case DW_TAG_compile_unit
:
21315 case DW_TAG_partial_unit
:
21316 /* Compilation units have a DW_AT_name that is a filename, not
21317 a source language identifier. */
21318 case DW_TAG_enumeration_type
:
21319 case DW_TAG_enumerator
:
21320 /* These tags always have simple identifiers already; no need
21321 to canonicalize them. */
21322 return DW_STRING (attr
);
21324 case DW_TAG_namespace
:
21325 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21326 return DW_STRING (attr
);
21327 return CP_ANONYMOUS_NAMESPACE_STR
;
21329 case DW_TAG_class_type
:
21330 case DW_TAG_interface_type
:
21331 case DW_TAG_structure_type
:
21332 case DW_TAG_union_type
:
21333 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21334 structures or unions. These were of the form "._%d" in GCC 4.1,
21335 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21336 and GCC 4.4. We work around this problem by ignoring these. */
21337 if (attr
&& DW_STRING (attr
)
21338 && (startswith (DW_STRING (attr
), "._")
21339 || startswith (DW_STRING (attr
), "<anonymous")))
21342 /* GCC might emit a nameless typedef that has a linkage name. See
21343 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21344 if (!attr
|| DW_STRING (attr
) == NULL
)
21346 attr
= dw2_linkage_name_attr (die
, cu
);
21347 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21350 /* Avoid demangling DW_STRING (attr) the second time on a second
21351 call for the same DIE. */
21352 if (!DW_STRING_IS_CANONICAL (attr
))
21354 gdb::unique_xmalloc_ptr
<char> demangled
21355 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21356 if (demangled
== nullptr)
21359 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21360 DW_STRING_IS_CANONICAL (attr
) = 1;
21363 /* Strip any leading namespaces/classes, keep only the base name.
21364 DW_AT_name for named DIEs does not contain the prefixes. */
21365 const char *base
= strrchr (DW_STRING (attr
), ':');
21366 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21369 return DW_STRING (attr
);
21377 if (!DW_STRING_IS_CANONICAL (attr
))
21379 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21381 DW_STRING_IS_CANONICAL (attr
) = 1;
21383 return DW_STRING (attr
);
21386 /* Return the die that this die in an extension of, or NULL if there
21387 is none. *EXT_CU is the CU containing DIE on input, and the CU
21388 containing the return value on output. */
21390 static struct die_info
*
21391 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21393 struct attribute
*attr
;
21395 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21399 return follow_die_ref (die
, attr
, ext_cu
);
21403 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21407 print_spaces (indent
, f
);
21408 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21409 dwarf_tag_name (die
->tag
), die
->abbrev
,
21410 sect_offset_str (die
->sect_off
));
21412 if (die
->parent
!= NULL
)
21414 print_spaces (indent
, f
);
21415 fprintf_unfiltered (f
, " parent at offset: %s\n",
21416 sect_offset_str (die
->parent
->sect_off
));
21419 print_spaces (indent
, f
);
21420 fprintf_unfiltered (f
, " has children: %s\n",
21421 dwarf_bool_name (die
->child
!= NULL
));
21423 print_spaces (indent
, f
);
21424 fprintf_unfiltered (f
, " attributes:\n");
21426 for (i
= 0; i
< die
->num_attrs
; ++i
)
21428 print_spaces (indent
, f
);
21429 fprintf_unfiltered (f
, " %s (%s) ",
21430 dwarf_attr_name (die
->attrs
[i
].name
),
21431 dwarf_form_name (die
->attrs
[i
].form
));
21433 switch (die
->attrs
[i
].form
)
21436 case DW_FORM_addrx
:
21437 case DW_FORM_GNU_addr_index
:
21438 fprintf_unfiltered (f
, "address: ");
21439 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21441 case DW_FORM_block2
:
21442 case DW_FORM_block4
:
21443 case DW_FORM_block
:
21444 case DW_FORM_block1
:
21445 fprintf_unfiltered (f
, "block: size %s",
21446 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21448 case DW_FORM_exprloc
:
21449 fprintf_unfiltered (f
, "expression: size %s",
21450 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21452 case DW_FORM_data16
:
21453 fprintf_unfiltered (f
, "constant of 16 bytes");
21455 case DW_FORM_ref_addr
:
21456 fprintf_unfiltered (f
, "ref address: ");
21457 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21459 case DW_FORM_GNU_ref_alt
:
21460 fprintf_unfiltered (f
, "alt ref address: ");
21461 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21467 case DW_FORM_ref_udata
:
21468 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21469 (long) (DW_UNSND (&die
->attrs
[i
])));
21471 case DW_FORM_data1
:
21472 case DW_FORM_data2
:
21473 case DW_FORM_data4
:
21474 case DW_FORM_data8
:
21475 case DW_FORM_udata
:
21476 case DW_FORM_sdata
:
21477 fprintf_unfiltered (f
, "constant: %s",
21478 pulongest (DW_UNSND (&die
->attrs
[i
])));
21480 case DW_FORM_sec_offset
:
21481 fprintf_unfiltered (f
, "section offset: %s",
21482 pulongest (DW_UNSND (&die
->attrs
[i
])));
21484 case DW_FORM_ref_sig8
:
21485 fprintf_unfiltered (f
, "signature: %s",
21486 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21488 case DW_FORM_string
:
21490 case DW_FORM_line_strp
:
21492 case DW_FORM_GNU_str_index
:
21493 case DW_FORM_GNU_strp_alt
:
21494 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21495 DW_STRING (&die
->attrs
[i
])
21496 ? DW_STRING (&die
->attrs
[i
]) : "",
21497 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21500 if (DW_UNSND (&die
->attrs
[i
]))
21501 fprintf_unfiltered (f
, "flag: TRUE");
21503 fprintf_unfiltered (f
, "flag: FALSE");
21505 case DW_FORM_flag_present
:
21506 fprintf_unfiltered (f
, "flag: TRUE");
21508 case DW_FORM_indirect
:
21509 /* The reader will have reduced the indirect form to
21510 the "base form" so this form should not occur. */
21511 fprintf_unfiltered (f
,
21512 "unexpected attribute form: DW_FORM_indirect");
21514 case DW_FORM_implicit_const
:
21515 fprintf_unfiltered (f
, "constant: %s",
21516 plongest (DW_SND (&die
->attrs
[i
])));
21519 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21520 die
->attrs
[i
].form
);
21523 fprintf_unfiltered (f
, "\n");
21528 dump_die_for_error (struct die_info
*die
)
21530 dump_die_shallow (gdb_stderr
, 0, die
);
21534 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21536 int indent
= level
* 4;
21538 gdb_assert (die
!= NULL
);
21540 if (level
>= max_level
)
21543 dump_die_shallow (f
, indent
, die
);
21545 if (die
->child
!= NULL
)
21547 print_spaces (indent
, f
);
21548 fprintf_unfiltered (f
, " Children:");
21549 if (level
+ 1 < max_level
)
21551 fprintf_unfiltered (f
, "\n");
21552 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21556 fprintf_unfiltered (f
,
21557 " [not printed, max nesting level reached]\n");
21561 if (die
->sibling
!= NULL
&& level
> 0)
21563 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21567 /* This is called from the pdie macro in gdbinit.in.
21568 It's not static so gcc will keep a copy callable from gdb. */
21571 dump_die (struct die_info
*die
, int max_level
)
21573 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21577 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21581 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21582 to_underlying (die
->sect_off
),
21588 /* Follow reference or signature attribute ATTR of SRC_DIE.
21589 On entry *REF_CU is the CU of SRC_DIE.
21590 On exit *REF_CU is the CU of the result. */
21592 static struct die_info
*
21593 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21594 struct dwarf2_cu
**ref_cu
)
21596 struct die_info
*die
;
21598 if (attr
->form_is_ref ())
21599 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21600 else if (attr
->form
== DW_FORM_ref_sig8
)
21601 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21604 dump_die_for_error (src_die
);
21605 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21606 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21612 /* Follow reference OFFSET.
21613 On entry *REF_CU is the CU of the source die referencing OFFSET.
21614 On exit *REF_CU is the CU of the result.
21615 Returns NULL if OFFSET is invalid. */
21617 static struct die_info
*
21618 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21619 struct dwarf2_cu
**ref_cu
)
21621 struct die_info temp_die
;
21622 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21623 struct dwarf2_per_objfile
*dwarf2_per_objfile
21624 = cu
->per_cu
->dwarf2_per_objfile
;
21626 gdb_assert (cu
->per_cu
!= NULL
);
21630 if (cu
->per_cu
->is_debug_types
)
21632 /* .debug_types CUs cannot reference anything outside their CU.
21633 If they need to, they have to reference a signatured type via
21634 DW_FORM_ref_sig8. */
21635 if (!cu
->header
.offset_in_cu_p (sect_off
))
21638 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21639 || !cu
->header
.offset_in_cu_p (sect_off
))
21641 struct dwarf2_per_cu_data
*per_cu
;
21643 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21644 dwarf2_per_objfile
);
21646 /* If necessary, add it to the queue and load its DIEs. */
21647 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21648 load_full_comp_unit (per_cu
, false, cu
->language
);
21650 target_cu
= per_cu
->cu
;
21652 else if (cu
->dies
== NULL
)
21654 /* We're loading full DIEs during partial symbol reading. */
21655 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21656 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21659 *ref_cu
= target_cu
;
21660 temp_die
.sect_off
= sect_off
;
21662 if (target_cu
!= cu
)
21663 target_cu
->ancestor
= cu
;
21665 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21667 to_underlying (sect_off
));
21670 /* Follow reference attribute ATTR of SRC_DIE.
21671 On entry *REF_CU is the CU of SRC_DIE.
21672 On exit *REF_CU is the CU of the result. */
21674 static struct die_info
*
21675 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21676 struct dwarf2_cu
**ref_cu
)
21678 sect_offset sect_off
= attr
->get_ref_die_offset ();
21679 struct dwarf2_cu
*cu
= *ref_cu
;
21680 struct die_info
*die
;
21682 die
= follow_die_offset (sect_off
,
21683 (attr
->form
== DW_FORM_GNU_ref_alt
21684 || cu
->per_cu
->is_dwz
),
21687 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21688 "at %s [in module %s]"),
21689 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21690 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21697 struct dwarf2_locexpr_baton
21698 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21699 dwarf2_per_cu_data
*per_cu
,
21700 CORE_ADDR (*get_frame_pc
) (void *baton
),
21701 void *baton
, bool resolve_abstract_p
)
21703 struct dwarf2_cu
*cu
;
21704 struct die_info
*die
;
21705 struct attribute
*attr
;
21706 struct dwarf2_locexpr_baton retval
;
21707 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21708 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21710 if (per_cu
->cu
== NULL
)
21711 load_cu (per_cu
, false);
21715 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21716 Instead just throw an error, not much else we can do. */
21717 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21718 sect_offset_str (sect_off
), objfile_name (objfile
));
21721 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21723 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21724 sect_offset_str (sect_off
), objfile_name (objfile
));
21726 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21727 if (!attr
&& resolve_abstract_p
21728 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21729 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21731 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21732 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21733 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21735 for (const auto &cand_off
21736 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21738 struct dwarf2_cu
*cand_cu
= cu
;
21739 struct die_info
*cand
21740 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21743 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21746 CORE_ADDR pc_low
, pc_high
;
21747 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21748 if (pc_low
== ((CORE_ADDR
) -1))
21750 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21751 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21752 if (!(pc_low
<= pc
&& pc
< pc_high
))
21756 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21763 /* DWARF: "If there is no such attribute, then there is no effect.".
21764 DATA is ignored if SIZE is 0. */
21766 retval
.data
= NULL
;
21769 else if (attr
->form_is_section_offset ())
21771 struct dwarf2_loclist_baton loclist_baton
;
21772 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21775 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21777 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21779 retval
.size
= size
;
21783 if (!attr
->form_is_block ())
21784 error (_("Dwarf Error: DIE at %s referenced in module %s "
21785 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21786 sect_offset_str (sect_off
), objfile_name (objfile
));
21788 retval
.data
= DW_BLOCK (attr
)->data
;
21789 retval
.size
= DW_BLOCK (attr
)->size
;
21791 retval
.per_cu
= cu
->per_cu
;
21793 age_cached_comp_units (dwarf2_per_objfile
);
21800 struct dwarf2_locexpr_baton
21801 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21802 dwarf2_per_cu_data
*per_cu
,
21803 CORE_ADDR (*get_frame_pc
) (void *baton
),
21806 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21808 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21811 /* Write a constant of a given type as target-ordered bytes into
21814 static const gdb_byte
*
21815 write_constant_as_bytes (struct obstack
*obstack
,
21816 enum bfd_endian byte_order
,
21823 *len
= TYPE_LENGTH (type
);
21824 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21825 store_unsigned_integer (result
, *len
, byte_order
, value
);
21833 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21834 dwarf2_per_cu_data
*per_cu
,
21838 struct dwarf2_cu
*cu
;
21839 struct die_info
*die
;
21840 struct attribute
*attr
;
21841 const gdb_byte
*result
= NULL
;
21844 enum bfd_endian byte_order
;
21845 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21847 if (per_cu
->cu
== NULL
)
21848 load_cu (per_cu
, false);
21852 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21853 Instead just throw an error, not much else we can do. */
21854 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21855 sect_offset_str (sect_off
), objfile_name (objfile
));
21858 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21860 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21861 sect_offset_str (sect_off
), objfile_name (objfile
));
21863 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21867 byte_order
= (bfd_big_endian (objfile
->obfd
)
21868 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21870 switch (attr
->form
)
21873 case DW_FORM_addrx
:
21874 case DW_FORM_GNU_addr_index
:
21878 *len
= cu
->header
.addr_size
;
21879 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21880 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21884 case DW_FORM_string
:
21887 case DW_FORM_GNU_str_index
:
21888 case DW_FORM_GNU_strp_alt
:
21889 /* DW_STRING is already allocated on the objfile obstack, point
21891 result
= (const gdb_byte
*) DW_STRING (attr
);
21892 *len
= strlen (DW_STRING (attr
));
21894 case DW_FORM_block1
:
21895 case DW_FORM_block2
:
21896 case DW_FORM_block4
:
21897 case DW_FORM_block
:
21898 case DW_FORM_exprloc
:
21899 case DW_FORM_data16
:
21900 result
= DW_BLOCK (attr
)->data
;
21901 *len
= DW_BLOCK (attr
)->size
;
21904 /* The DW_AT_const_value attributes are supposed to carry the
21905 symbol's value "represented as it would be on the target
21906 architecture." By the time we get here, it's already been
21907 converted to host endianness, so we just need to sign- or
21908 zero-extend it as appropriate. */
21909 case DW_FORM_data1
:
21910 type
= die_type (die
, cu
);
21911 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21912 if (result
== NULL
)
21913 result
= write_constant_as_bytes (obstack
, byte_order
,
21916 case DW_FORM_data2
:
21917 type
= die_type (die
, cu
);
21918 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21919 if (result
== NULL
)
21920 result
= write_constant_as_bytes (obstack
, byte_order
,
21923 case DW_FORM_data4
:
21924 type
= die_type (die
, cu
);
21925 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21926 if (result
== NULL
)
21927 result
= write_constant_as_bytes (obstack
, byte_order
,
21930 case DW_FORM_data8
:
21931 type
= die_type (die
, cu
);
21932 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21933 if (result
== NULL
)
21934 result
= write_constant_as_bytes (obstack
, byte_order
,
21938 case DW_FORM_sdata
:
21939 case DW_FORM_implicit_const
:
21940 type
= die_type (die
, cu
);
21941 result
= write_constant_as_bytes (obstack
, byte_order
,
21942 type
, DW_SND (attr
), len
);
21945 case DW_FORM_udata
:
21946 type
= die_type (die
, cu
);
21947 result
= write_constant_as_bytes (obstack
, byte_order
,
21948 type
, DW_UNSND (attr
), len
);
21952 complaint (_("unsupported const value attribute form: '%s'"),
21953 dwarf_form_name (attr
->form
));
21963 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21964 dwarf2_per_cu_data
*per_cu
)
21966 struct dwarf2_cu
*cu
;
21967 struct die_info
*die
;
21969 if (per_cu
->cu
== NULL
)
21970 load_cu (per_cu
, false);
21975 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21979 return die_type (die
, cu
);
21985 dwarf2_get_die_type (cu_offset die_offset
,
21986 struct dwarf2_per_cu_data
*per_cu
)
21988 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21989 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21992 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21993 On entry *REF_CU is the CU of SRC_DIE.
21994 On exit *REF_CU is the CU of the result.
21995 Returns NULL if the referenced DIE isn't found. */
21997 static struct die_info
*
21998 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21999 struct dwarf2_cu
**ref_cu
)
22001 struct die_info temp_die
;
22002 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
22003 struct die_info
*die
;
22005 /* While it might be nice to assert sig_type->type == NULL here,
22006 we can get here for DW_AT_imported_declaration where we need
22007 the DIE not the type. */
22009 /* If necessary, add it to the queue and load its DIEs. */
22011 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
22012 read_signatured_type (sig_type
);
22014 sig_cu
= sig_type
->per_cu
.cu
;
22015 gdb_assert (sig_cu
!= NULL
);
22016 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
22017 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
22018 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
22019 to_underlying (temp_die
.sect_off
));
22022 struct dwarf2_per_objfile
*dwarf2_per_objfile
22023 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
22025 /* For .gdb_index version 7 keep track of included TUs.
22026 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
22027 if (dwarf2_per_objfile
->index_table
!= NULL
22028 && dwarf2_per_objfile
->index_table
->version
<= 7)
22030 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
22035 sig_cu
->ancestor
= cu
;
22043 /* Follow signatured type referenced by ATTR in SRC_DIE.
22044 On entry *REF_CU is the CU of SRC_DIE.
22045 On exit *REF_CU is the CU of the result.
22046 The result is the DIE of the type.
22047 If the referenced type cannot be found an error is thrown. */
22049 static struct die_info
*
22050 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22051 struct dwarf2_cu
**ref_cu
)
22053 ULONGEST signature
= DW_SIGNATURE (attr
);
22054 struct signatured_type
*sig_type
;
22055 struct die_info
*die
;
22057 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
22059 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
22060 /* sig_type will be NULL if the signatured type is missing from
22062 if (sig_type
== NULL
)
22064 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22065 " from DIE at %s [in module %s]"),
22066 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22067 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22070 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
22073 dump_die_for_error (src_die
);
22074 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22075 " from DIE at %s [in module %s]"),
22076 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22077 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22083 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22084 reading in and processing the type unit if necessary. */
22086 static struct type
*
22087 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22088 struct dwarf2_cu
*cu
)
22090 struct dwarf2_per_objfile
*dwarf2_per_objfile
22091 = cu
->per_cu
->dwarf2_per_objfile
;
22092 struct signatured_type
*sig_type
;
22093 struct dwarf2_cu
*type_cu
;
22094 struct die_info
*type_die
;
22097 sig_type
= lookup_signatured_type (cu
, signature
);
22098 /* sig_type will be NULL if the signatured type is missing from
22100 if (sig_type
== NULL
)
22102 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22103 " from DIE at %s [in module %s]"),
22104 hex_string (signature
), sect_offset_str (die
->sect_off
),
22105 objfile_name (dwarf2_per_objfile
->objfile
));
22106 return build_error_marker_type (cu
, die
);
22109 /* If we already know the type we're done. */
22110 if (sig_type
->type
!= NULL
)
22111 return sig_type
->type
;
22114 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22115 if (type_die
!= NULL
)
22117 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22118 is created. This is important, for example, because for c++ classes
22119 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22120 type
= read_type_die (type_die
, type_cu
);
22123 complaint (_("Dwarf Error: Cannot build signatured type %s"
22124 " referenced from DIE at %s [in module %s]"),
22125 hex_string (signature
), sect_offset_str (die
->sect_off
),
22126 objfile_name (dwarf2_per_objfile
->objfile
));
22127 type
= build_error_marker_type (cu
, die
);
22132 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22133 " from DIE at %s [in module %s]"),
22134 hex_string (signature
), sect_offset_str (die
->sect_off
),
22135 objfile_name (dwarf2_per_objfile
->objfile
));
22136 type
= build_error_marker_type (cu
, die
);
22138 sig_type
->type
= type
;
22143 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22144 reading in and processing the type unit if necessary. */
22146 static struct type
*
22147 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22148 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22150 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22151 if (attr
->form_is_ref ())
22153 struct dwarf2_cu
*type_cu
= cu
;
22154 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22156 return read_type_die (type_die
, type_cu
);
22158 else if (attr
->form
== DW_FORM_ref_sig8
)
22160 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22164 struct dwarf2_per_objfile
*dwarf2_per_objfile
22165 = cu
->per_cu
->dwarf2_per_objfile
;
22167 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22168 " at %s [in module %s]"),
22169 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22170 objfile_name (dwarf2_per_objfile
->objfile
));
22171 return build_error_marker_type (cu
, die
);
22175 /* Load the DIEs associated with type unit PER_CU into memory. */
22178 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22180 struct signatured_type
*sig_type
;
22182 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22183 gdb_assert (! per_cu
->type_unit_group_p ());
22185 /* We have the per_cu, but we need the signatured_type.
22186 Fortunately this is an easy translation. */
22187 gdb_assert (per_cu
->is_debug_types
);
22188 sig_type
= (struct signatured_type
*) per_cu
;
22190 gdb_assert (per_cu
->cu
== NULL
);
22192 read_signatured_type (sig_type
);
22194 gdb_assert (per_cu
->cu
!= NULL
);
22197 /* Read in a signatured type and build its CU and DIEs.
22198 If the type is a stub for the real type in a DWO file,
22199 read in the real type from the DWO file as well. */
22202 read_signatured_type (struct signatured_type
*sig_type
)
22204 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22206 gdb_assert (per_cu
->is_debug_types
);
22207 gdb_assert (per_cu
->cu
== NULL
);
22209 cutu_reader
reader (per_cu
, NULL
, 0, false);
22211 if (!reader
.dummy_p
)
22213 struct dwarf2_cu
*cu
= reader
.cu
;
22214 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22216 gdb_assert (cu
->die_hash
== NULL
);
22218 htab_create_alloc_ex (cu
->header
.length
/ 12,
22222 &cu
->comp_unit_obstack
,
22223 hashtab_obstack_allocate
,
22224 dummy_obstack_deallocate
);
22226 if (reader
.comp_unit_die
->has_children
)
22227 reader
.comp_unit_die
->child
22228 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22229 reader
.comp_unit_die
);
22230 cu
->dies
= reader
.comp_unit_die
;
22231 /* comp_unit_die is not stored in die_hash, no need. */
22233 /* We try not to read any attributes in this function, because
22234 not all CUs needed for references have been loaded yet, and
22235 symbol table processing isn't initialized. But we have to
22236 set the CU language, or we won't be able to build types
22237 correctly. Similarly, if we do not read the producer, we can
22238 not apply producer-specific interpretation. */
22239 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22244 sig_type
->per_cu
.tu_read
= 1;
22247 /* Decode simple location descriptions.
22248 Given a pointer to a dwarf block that defines a location, compute
22249 the location and return the value.
22251 NOTE drow/2003-11-18: This function is called in two situations
22252 now: for the address of static or global variables (partial symbols
22253 only) and for offsets into structures which are expected to be
22254 (more or less) constant. The partial symbol case should go away,
22255 and only the constant case should remain. That will let this
22256 function complain more accurately. A few special modes are allowed
22257 without complaint for global variables (for instance, global
22258 register values and thread-local values).
22260 A location description containing no operations indicates that the
22261 object is optimized out. The return value is 0 for that case.
22262 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22263 callers will only want a very basic result and this can become a
22266 Note that stack[0] is unused except as a default error return. */
22269 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22271 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22273 size_t size
= blk
->size
;
22274 const gdb_byte
*data
= blk
->data
;
22275 CORE_ADDR stack
[64];
22277 unsigned int bytes_read
, unsnd
;
22283 stack
[++stacki
] = 0;
22322 stack
[++stacki
] = op
- DW_OP_lit0
;
22357 stack
[++stacki
] = op
- DW_OP_reg0
;
22359 dwarf2_complex_location_expr_complaint ();
22363 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22365 stack
[++stacki
] = unsnd
;
22367 dwarf2_complex_location_expr_complaint ();
22371 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22376 case DW_OP_const1u
:
22377 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22381 case DW_OP_const1s
:
22382 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22386 case DW_OP_const2u
:
22387 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22391 case DW_OP_const2s
:
22392 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22396 case DW_OP_const4u
:
22397 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22401 case DW_OP_const4s
:
22402 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22406 case DW_OP_const8u
:
22407 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22412 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22418 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22423 stack
[stacki
+ 1] = stack
[stacki
];
22428 stack
[stacki
- 1] += stack
[stacki
];
22432 case DW_OP_plus_uconst
:
22433 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22439 stack
[stacki
- 1] -= stack
[stacki
];
22444 /* If we're not the last op, then we definitely can't encode
22445 this using GDB's address_class enum. This is valid for partial
22446 global symbols, although the variable's address will be bogus
22449 dwarf2_complex_location_expr_complaint ();
22452 case DW_OP_GNU_push_tls_address
:
22453 case DW_OP_form_tls_address
:
22454 /* The top of the stack has the offset from the beginning
22455 of the thread control block at which the variable is located. */
22456 /* Nothing should follow this operator, so the top of stack would
22458 /* This is valid for partial global symbols, but the variable's
22459 address will be bogus in the psymtab. Make it always at least
22460 non-zero to not look as a variable garbage collected by linker
22461 which have DW_OP_addr 0. */
22463 dwarf2_complex_location_expr_complaint ();
22467 case DW_OP_GNU_uninit
:
22471 case DW_OP_GNU_addr_index
:
22472 case DW_OP_GNU_const_index
:
22473 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22480 const char *name
= get_DW_OP_name (op
);
22483 complaint (_("unsupported stack op: '%s'"),
22486 complaint (_("unsupported stack op: '%02x'"),
22490 return (stack
[stacki
]);
22493 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22494 outside of the allocated space. Also enforce minimum>0. */
22495 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22497 complaint (_("location description stack overflow"));
22503 complaint (_("location description stack underflow"));
22507 return (stack
[stacki
]);
22510 /* memory allocation interface */
22512 static struct dwarf_block
*
22513 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22515 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22518 static struct die_info
*
22519 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22521 struct die_info
*die
;
22522 size_t size
= sizeof (struct die_info
);
22525 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22527 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22528 memset (die
, 0, sizeof (struct die_info
));
22534 /* Macro support. */
22536 /* An overload of dwarf_decode_macros that finds the correct section
22537 and ensures it is read in before calling the other overload. */
22540 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22541 int section_is_gnu
)
22543 struct dwarf2_per_objfile
*dwarf2_per_objfile
22544 = cu
->per_cu
->dwarf2_per_objfile
;
22545 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22546 const struct line_header
*lh
= cu
->line_header
;
22547 unsigned int offset_size
= cu
->header
.offset_size
;
22548 struct dwarf2_section_info
*section
;
22549 const char *section_name
;
22551 if (cu
->dwo_unit
!= nullptr)
22553 if (section_is_gnu
)
22555 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22556 section_name
= ".debug_macro.dwo";
22560 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22561 section_name
= ".debug_macinfo.dwo";
22566 if (section_is_gnu
)
22568 section
= &dwarf2_per_objfile
->macro
;
22569 section_name
= ".debug_macro";
22573 section
= &dwarf2_per_objfile
->macinfo
;
22574 section_name
= ".debug_macinfo";
22578 section
->read (objfile
);
22579 if (section
->buffer
== nullptr)
22581 complaint (_("missing %s section"), section_name
);
22585 buildsym_compunit
*builder
= cu
->get_builder ();
22587 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22588 offset_size
, offset
, section_is_gnu
);
22591 /* Return the .debug_loc section to use for CU.
22592 For DWO files use .debug_loc.dwo. */
22594 static struct dwarf2_section_info
*
22595 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22597 struct dwarf2_per_objfile
*dwarf2_per_objfile
22598 = cu
->per_cu
->dwarf2_per_objfile
;
22602 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22604 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22606 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22607 : &dwarf2_per_objfile
->loc
);
22610 /* A helper function that fills in a dwarf2_loclist_baton. */
22613 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22614 struct dwarf2_loclist_baton
*baton
,
22615 const struct attribute
*attr
)
22617 struct dwarf2_per_objfile
*dwarf2_per_objfile
22618 = cu
->per_cu
->dwarf2_per_objfile
;
22619 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22621 section
->read (dwarf2_per_objfile
->objfile
);
22623 baton
->per_cu
= cu
->per_cu
;
22624 gdb_assert (baton
->per_cu
);
22625 /* We don't know how long the location list is, but make sure we
22626 don't run off the edge of the section. */
22627 baton
->size
= section
->size
- DW_UNSND (attr
);
22628 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22629 if (cu
->base_address
.has_value ())
22630 baton
->base_address
= *cu
->base_address
;
22632 baton
->base_address
= 0;
22633 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22637 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22638 struct dwarf2_cu
*cu
, int is_block
)
22640 struct dwarf2_per_objfile
*dwarf2_per_objfile
22641 = cu
->per_cu
->dwarf2_per_objfile
;
22642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22643 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22645 if (attr
->form_is_section_offset ()
22646 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22647 the section. If so, fall through to the complaint in the
22649 && DW_UNSND (attr
) < section
->get_size (objfile
))
22651 struct dwarf2_loclist_baton
*baton
;
22653 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22655 fill_in_loclist_baton (cu
, baton
, attr
);
22657 if (!cu
->base_address
.has_value ())
22658 complaint (_("Location list used without "
22659 "specifying the CU base address."));
22661 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22662 ? dwarf2_loclist_block_index
22663 : dwarf2_loclist_index
);
22664 SYMBOL_LOCATION_BATON (sym
) = baton
;
22668 struct dwarf2_locexpr_baton
*baton
;
22670 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22671 baton
->per_cu
= cu
->per_cu
;
22672 gdb_assert (baton
->per_cu
);
22674 if (attr
->form_is_block ())
22676 /* Note that we're just copying the block's data pointer
22677 here, not the actual data. We're still pointing into the
22678 info_buffer for SYM's objfile; right now we never release
22679 that buffer, but when we do clean up properly this may
22681 baton
->size
= DW_BLOCK (attr
)->size
;
22682 baton
->data
= DW_BLOCK (attr
)->data
;
22686 dwarf2_invalid_attrib_class_complaint ("location description",
22687 sym
->natural_name ());
22691 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22692 ? dwarf2_locexpr_block_index
22693 : dwarf2_locexpr_index
);
22694 SYMBOL_LOCATION_BATON (sym
) = baton
;
22701 dwarf2_per_cu_data::objfile () const
22703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22705 /* Return the master objfile, so that we can report and look up the
22706 correct file containing this variable. */
22707 if (objfile
->separate_debug_objfile_backlink
)
22708 objfile
= objfile
->separate_debug_objfile_backlink
;
22713 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22714 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22715 CU_HEADERP first. */
22717 static const struct comp_unit_head
*
22718 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22719 const struct dwarf2_per_cu_data
*per_cu
)
22721 const gdb_byte
*info_ptr
;
22724 return &per_cu
->cu
->header
;
22726 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22728 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22729 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22730 rcuh_kind::COMPILE
);
22738 dwarf2_per_cu_data::addr_size () const
22740 struct comp_unit_head cu_header_local
;
22741 const struct comp_unit_head
*cu_headerp
;
22743 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22745 return cu_headerp
->addr_size
;
22751 dwarf2_per_cu_data::offset_size () const
22753 struct comp_unit_head cu_header_local
;
22754 const struct comp_unit_head
*cu_headerp
;
22756 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22758 return cu_headerp
->offset_size
;
22764 dwarf2_per_cu_data::ref_addr_size () const
22766 struct comp_unit_head cu_header_local
;
22767 const struct comp_unit_head
*cu_headerp
;
22769 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22771 if (cu_headerp
->version
== 2)
22772 return cu_headerp
->addr_size
;
22774 return cu_headerp
->offset_size
;
22780 dwarf2_per_cu_data::text_offset () const
22782 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22784 return objfile
->text_section_offset ();
22790 dwarf2_per_cu_data::addr_type () const
22792 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22793 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22794 struct type
*addr_type
= lookup_pointer_type (void_type
);
22795 int addr_size
= this->addr_size ();
22797 if (TYPE_LENGTH (addr_type
) == addr_size
)
22800 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22804 /* A helper function for dwarf2_find_containing_comp_unit that returns
22805 the index of the result, and that searches a vector. It will
22806 return a result even if the offset in question does not actually
22807 occur in any CU. This is separate so that it can be unit
22811 dwarf2_find_containing_comp_unit
22812 (sect_offset sect_off
,
22813 unsigned int offset_in_dwz
,
22814 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22819 high
= all_comp_units
.size () - 1;
22822 struct dwarf2_per_cu_data
*mid_cu
;
22823 int mid
= low
+ (high
- low
) / 2;
22825 mid_cu
= all_comp_units
[mid
];
22826 if (mid_cu
->is_dwz
> offset_in_dwz
22827 || (mid_cu
->is_dwz
== offset_in_dwz
22828 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22833 gdb_assert (low
== high
);
22837 /* Locate the .debug_info compilation unit from CU's objfile which contains
22838 the DIE at OFFSET. Raises an error on failure. */
22840 static struct dwarf2_per_cu_data
*
22841 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22842 unsigned int offset_in_dwz
,
22843 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22846 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22847 dwarf2_per_objfile
->all_comp_units
);
22848 struct dwarf2_per_cu_data
*this_cu
22849 = dwarf2_per_objfile
->all_comp_units
[low
];
22851 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22853 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22854 error (_("Dwarf Error: could not find partial DIE containing "
22855 "offset %s [in module %s]"),
22856 sect_offset_str (sect_off
),
22857 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22859 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22861 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22865 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22866 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22867 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22868 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22875 namespace selftests
{
22876 namespace find_containing_comp_unit
{
22881 struct dwarf2_per_cu_data one
{};
22882 struct dwarf2_per_cu_data two
{};
22883 struct dwarf2_per_cu_data three
{};
22884 struct dwarf2_per_cu_data four
{};
22887 two
.sect_off
= sect_offset (one
.length
);
22892 four
.sect_off
= sect_offset (three
.length
);
22896 std::vector
<dwarf2_per_cu_data
*> units
;
22897 units
.push_back (&one
);
22898 units
.push_back (&two
);
22899 units
.push_back (&three
);
22900 units
.push_back (&four
);
22904 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22905 SELF_CHECK (units
[result
] == &one
);
22906 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
22907 SELF_CHECK (units
[result
] == &one
);
22908 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
22909 SELF_CHECK (units
[result
] == &two
);
22911 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
22912 SELF_CHECK (units
[result
] == &three
);
22913 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
22914 SELF_CHECK (units
[result
] == &three
);
22915 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
22916 SELF_CHECK (units
[result
] == &four
);
22922 #endif /* GDB_SELF_TEST */
22924 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22926 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
22927 : per_cu (per_cu_
),
22929 has_loclist (false),
22930 checked_producer (false),
22931 producer_is_gxx_lt_4_6 (false),
22932 producer_is_gcc_lt_4_3 (false),
22933 producer_is_icc (false),
22934 producer_is_icc_lt_14 (false),
22935 producer_is_codewarrior (false),
22936 processing_has_namespace_info (false)
22941 /* Destroy a dwarf2_cu. */
22943 dwarf2_cu::~dwarf2_cu ()
22948 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22951 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22952 enum language pretend_language
)
22954 struct attribute
*attr
;
22956 /* Set the language we're debugging. */
22957 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22958 if (attr
!= nullptr)
22959 set_cu_language (DW_UNSND (attr
), cu
);
22962 cu
->language
= pretend_language
;
22963 cu
->language_defn
= language_def (cu
->language
);
22966 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22969 /* Increase the age counter on each cached compilation unit, and free
22970 any that are too old. */
22973 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22975 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22977 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22978 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22979 while (per_cu
!= NULL
)
22981 per_cu
->cu
->last_used
++;
22982 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22983 dwarf2_mark (per_cu
->cu
);
22984 per_cu
= per_cu
->cu
->read_in_chain
;
22987 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22988 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22989 while (per_cu
!= NULL
)
22991 struct dwarf2_per_cu_data
*next_cu
;
22993 next_cu
= per_cu
->cu
->read_in_chain
;
22995 if (!per_cu
->cu
->mark
)
22998 *last_chain
= next_cu
;
23001 last_chain
= &per_cu
->cu
->read_in_chain
;
23007 /* Remove a single compilation unit from the cache. */
23010 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
23012 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
23013 struct dwarf2_per_objfile
*dwarf2_per_objfile
23014 = target_per_cu
->dwarf2_per_objfile
;
23016 per_cu
= dwarf2_per_objfile
->read_in_chain
;
23017 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
23018 while (per_cu
!= NULL
)
23020 struct dwarf2_per_cu_data
*next_cu
;
23022 next_cu
= per_cu
->cu
->read_in_chain
;
23024 if (per_cu
== target_per_cu
)
23028 *last_chain
= next_cu
;
23032 last_chain
= &per_cu
->cu
->read_in_chain
;
23038 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
23039 We store these in a hash table separate from the DIEs, and preserve them
23040 when the DIEs are flushed out of cache.
23042 The CU "per_cu" pointer is needed because offset alone is not enough to
23043 uniquely identify the type. A file may have multiple .debug_types sections,
23044 or the type may come from a DWO file. Furthermore, while it's more logical
23045 to use per_cu->section+offset, with Fission the section with the data is in
23046 the DWO file but we don't know that section at the point we need it.
23047 We have to use something in dwarf2_per_cu_data (or the pointer to it)
23048 because we can enter the lookup routine, get_die_type_at_offset, from
23049 outside this file, and thus won't necessarily have PER_CU->cu.
23050 Fortunately, PER_CU is stable for the life of the objfile. */
23052 struct dwarf2_per_cu_offset_and_type
23054 const struct dwarf2_per_cu_data
*per_cu
;
23055 sect_offset sect_off
;
23059 /* Hash function for a dwarf2_per_cu_offset_and_type. */
23062 per_cu_offset_and_type_hash (const void *item
)
23064 const struct dwarf2_per_cu_offset_and_type
*ofs
23065 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
23067 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
23070 /* Equality function for a dwarf2_per_cu_offset_and_type. */
23073 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
23075 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23076 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23077 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23078 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23080 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23081 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23084 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23085 table if necessary. For convenience, return TYPE.
23087 The DIEs reading must have careful ordering to:
23088 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23089 reading current DIE.
23090 * Not trying to dereference contents of still incompletely read in types
23091 while reading in other DIEs.
23092 * Enable referencing still incompletely read in types just by a pointer to
23093 the type without accessing its fields.
23095 Therefore caller should follow these rules:
23096 * Try to fetch any prerequisite types we may need to build this DIE type
23097 before building the type and calling set_die_type.
23098 * After building type call set_die_type for current DIE as soon as
23099 possible before fetching more types to complete the current type.
23100 * Make the type as complete as possible before fetching more types. */
23102 static struct type
*
23103 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23105 struct dwarf2_per_objfile
*dwarf2_per_objfile
23106 = cu
->per_cu
->dwarf2_per_objfile
;
23107 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23109 struct attribute
*attr
;
23110 struct dynamic_prop prop
;
23112 /* For Ada types, make sure that the gnat-specific data is always
23113 initialized (if not already set). There are a few types where
23114 we should not be doing so, because the type-specific area is
23115 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23116 where the type-specific area is used to store the floatformat).
23117 But this is not a problem, because the gnat-specific information
23118 is actually not needed for these types. */
23119 if (need_gnat_info (cu
)
23120 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23121 && TYPE_CODE (type
) != TYPE_CODE_FLT
23122 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23123 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23124 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23125 && !HAVE_GNAT_AUX_INFO (type
))
23126 INIT_GNAT_SPECIFIC (type
);
23128 /* Read DW_AT_allocated and set in type. */
23129 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23130 if (attr
!= NULL
&& attr
->form_is_block ())
23132 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23133 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23134 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23136 else if (attr
!= NULL
)
23138 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23139 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23140 sect_offset_str (die
->sect_off
));
23143 /* Read DW_AT_associated and set in type. */
23144 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23145 if (attr
!= NULL
&& attr
->form_is_block ())
23147 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23148 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23149 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23151 else if (attr
!= NULL
)
23153 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23154 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23155 sect_offset_str (die
->sect_off
));
23158 /* Read DW_AT_data_location and set in type. */
23159 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23160 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23161 cu
->per_cu
->addr_type ()))
23162 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23164 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23165 dwarf2_per_objfile
->die_type_hash
23166 = htab_up (htab_create_alloc (127,
23167 per_cu_offset_and_type_hash
,
23168 per_cu_offset_and_type_eq
,
23169 NULL
, xcalloc
, xfree
));
23171 ofs
.per_cu
= cu
->per_cu
;
23172 ofs
.sect_off
= die
->sect_off
;
23174 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23175 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23177 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23178 sect_offset_str (die
->sect_off
));
23179 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23180 struct dwarf2_per_cu_offset_and_type
);
23185 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23186 or return NULL if the die does not have a saved type. */
23188 static struct type
*
23189 get_die_type_at_offset (sect_offset sect_off
,
23190 struct dwarf2_per_cu_data
*per_cu
)
23192 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23193 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23195 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23198 ofs
.per_cu
= per_cu
;
23199 ofs
.sect_off
= sect_off
;
23200 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23201 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23208 /* Look up the type for DIE in CU in die_type_hash,
23209 or return NULL if DIE does not have a saved type. */
23211 static struct type
*
23212 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23214 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23217 /* Add a dependence relationship from CU to REF_PER_CU. */
23220 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23221 struct dwarf2_per_cu_data
*ref_per_cu
)
23225 if (cu
->dependencies
== NULL
)
23227 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23228 NULL
, &cu
->comp_unit_obstack
,
23229 hashtab_obstack_allocate
,
23230 dummy_obstack_deallocate
);
23232 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23234 *slot
= ref_per_cu
;
23237 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23238 Set the mark field in every compilation unit in the
23239 cache that we must keep because we are keeping CU. */
23242 dwarf2_mark_helper (void **slot
, void *data
)
23244 struct dwarf2_per_cu_data
*per_cu
;
23246 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23248 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23249 reading of the chain. As such dependencies remain valid it is not much
23250 useful to track and undo them during QUIT cleanups. */
23251 if (per_cu
->cu
== NULL
)
23254 if (per_cu
->cu
->mark
)
23256 per_cu
->cu
->mark
= true;
23258 if (per_cu
->cu
->dependencies
!= NULL
)
23259 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23264 /* Set the mark field in CU and in every other compilation unit in the
23265 cache that we must keep because we are keeping CU. */
23268 dwarf2_mark (struct dwarf2_cu
*cu
)
23273 if (cu
->dependencies
!= NULL
)
23274 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23278 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23282 per_cu
->cu
->mark
= false;
23283 per_cu
= per_cu
->cu
->read_in_chain
;
23287 /* Trivial hash function for partial_die_info: the hash value of a DIE
23288 is its offset in .debug_info for this objfile. */
23291 partial_die_hash (const void *item
)
23293 const struct partial_die_info
*part_die
23294 = (const struct partial_die_info
*) item
;
23296 return to_underlying (part_die
->sect_off
);
23299 /* Trivial comparison function for partial_die_info structures: two DIEs
23300 are equal if they have the same offset. */
23303 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23305 const struct partial_die_info
*part_die_lhs
23306 = (const struct partial_die_info
*) item_lhs
;
23307 const struct partial_die_info
*part_die_rhs
23308 = (const struct partial_die_info
*) item_rhs
;
23310 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23313 struct cmd_list_element
*set_dwarf_cmdlist
;
23314 struct cmd_list_element
*show_dwarf_cmdlist
;
23317 set_dwarf_cmd (const char *args
, int from_tty
)
23319 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23324 show_dwarf_cmd (const char *args
, int from_tty
)
23326 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23330 show_check_physname (struct ui_file
*file
, int from_tty
,
23331 struct cmd_list_element
*c
, const char *value
)
23333 fprintf_filtered (file
,
23334 _("Whether to check \"physname\" is %s.\n"),
23338 void _initialize_dwarf2_read ();
23340 _initialize_dwarf2_read ()
23342 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23343 Set DWARF specific variables.\n\
23344 Configure DWARF variables such as the cache size."),
23345 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23346 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23348 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23349 Show DWARF specific variables.\n\
23350 Show DWARF variables such as the cache size."),
23351 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23352 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23354 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23355 &dwarf_max_cache_age
, _("\
23356 Set the upper bound on the age of cached DWARF compilation units."), _("\
23357 Show the upper bound on the age of cached DWARF compilation units."), _("\
23358 A higher limit means that cached compilation units will be stored\n\
23359 in memory longer, and more total memory will be used. Zero disables\n\
23360 caching, which can slow down startup."),
23362 show_dwarf_max_cache_age
,
23363 &set_dwarf_cmdlist
,
23364 &show_dwarf_cmdlist
);
23366 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23367 Set debugging of the DWARF reader."), _("\
23368 Show debugging of the DWARF reader."), _("\
23369 When enabled (non-zero), debugging messages are printed during DWARF\n\
23370 reading and symtab expansion. A value of 1 (one) provides basic\n\
23371 information. A value greater than 1 provides more verbose information."),
23374 &setdebuglist
, &showdebuglist
);
23376 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23377 Set debugging of the DWARF DIE reader."), _("\
23378 Show debugging of the DWARF DIE reader."), _("\
23379 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23380 The value is the maximum depth to print."),
23383 &setdebuglist
, &showdebuglist
);
23385 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23386 Set debugging of the dwarf line reader."), _("\
23387 Show debugging of the dwarf line reader."), _("\
23388 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23389 A value of 1 (one) provides basic information.\n\
23390 A value greater than 1 provides more verbose information."),
23393 &setdebuglist
, &showdebuglist
);
23395 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23396 Set cross-checking of \"physname\" code against demangler."), _("\
23397 Show cross-checking of \"physname\" code against demangler."), _("\
23398 When enabled, GDB's internal \"physname\" code is checked against\n\
23400 NULL
, show_check_physname
,
23401 &setdebuglist
, &showdebuglist
);
23403 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23404 no_class
, &use_deprecated_index_sections
, _("\
23405 Set whether to use deprecated gdb_index sections."), _("\
23406 Show whether to use deprecated gdb_index sections."), _("\
23407 When enabled, deprecated .gdb_index sections are used anyway.\n\
23408 Normally they are ignored either because of a missing feature or\n\
23409 performance issue.\n\
23410 Warning: This option must be enabled before gdb reads the file."),
23413 &setlist
, &showlist
);
23415 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23416 &dwarf2_locexpr_funcs
);
23417 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23418 &dwarf2_loclist_funcs
);
23420 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23421 &dwarf2_block_frame_base_locexpr_funcs
);
23422 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23423 &dwarf2_block_frame_base_loclist_funcs
);
23426 selftests::register_test ("dw2_expand_symtabs_matching",
23427 selftests::dw2_expand_symtabs_matching::run_test
);
23428 selftests::register_test ("dwarf2_find_containing_comp_unit",
23429 selftests::find_containing_comp_unit::run_test
);