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
)
3595 /* Currently unimplemented; used for Ada. The function can be called if the
3596 current language is Ada for a non-Ada objfile using GNU index. As Ada
3597 does not look for non-Ada symbols this function should just return. */
3600 /* Starting from a search name, return the string that finds the upper
3601 bound of all strings that start with SEARCH_NAME in a sorted name
3602 list. Returns the empty string to indicate that the upper bound is
3603 the end of the list. */
3606 make_sort_after_prefix_name (const char *search_name
)
3608 /* When looking to complete "func", we find the upper bound of all
3609 symbols that start with "func" by looking for where we'd insert
3610 the closest string that would follow "func" in lexicographical
3611 order. Usually, that's "func"-with-last-character-incremented,
3612 i.e. "fund". Mind non-ASCII characters, though. Usually those
3613 will be UTF-8 multi-byte sequences, but we can't be certain.
3614 Especially mind the 0xff character, which is a valid character in
3615 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
3616 rule out compilers allowing it in identifiers. Note that
3617 conveniently, strcmp/strcasecmp are specified to compare
3618 characters interpreted as unsigned char. So what we do is treat
3619 the whole string as a base 256 number composed of a sequence of
3620 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
3621 to 0, and carries 1 to the following more-significant position.
3622 If the very first character in SEARCH_NAME ends up incremented
3623 and carries/overflows, then the upper bound is the end of the
3624 list. The string after the empty string is also the empty
3627 Some examples of this operation:
3629 SEARCH_NAME => "+1" RESULT
3633 "\xff" "a" "\xff" => "\xff" "b"
3638 Then, with these symbols for example:
3644 completing "func" looks for symbols between "func" and
3645 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
3646 which finds "func" and "func1", but not "fund".
3650 funcÿ (Latin1 'ÿ' [0xff])
3654 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
3655 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
3659 ÿÿ (Latin1 'ÿ' [0xff])
3662 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
3663 the end of the list.
3665 std::string after
= search_name
;
3666 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
3668 if (!after
.empty ())
3669 after
.back () = (unsigned char) after
.back () + 1;
3673 /* See declaration. */
3675 std::pair
<std::vector
<name_component
>::const_iterator
,
3676 std::vector
<name_component
>::const_iterator
>
3677 mapped_index_base::find_name_components_bounds
3678 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
3681 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3683 const char *lang_name
3684 = lookup_name_without_params
.language_lookup_name (lang
);
3686 /* Comparison function object for lower_bound that matches against a
3687 given symbol name. */
3688 auto lookup_compare_lower
= [&] (const name_component
&elem
,
3691 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3692 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3693 return name_cmp (elem_name
, name
) < 0;
3696 /* Comparison function object for upper_bound that matches against a
3697 given symbol name. */
3698 auto lookup_compare_upper
= [&] (const char *name
,
3699 const name_component
&elem
)
3701 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
3702 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
3703 return name_cmp (name
, elem_name
) < 0;
3706 auto begin
= this->name_components
.begin ();
3707 auto end
= this->name_components
.end ();
3709 /* Find the lower bound. */
3712 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
3715 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
3718 /* Find the upper bound. */
3721 if (lookup_name_without_params
.completion_mode ())
3723 /* In completion mode, we want UPPER to point past all
3724 symbols names that have the same prefix. I.e., with
3725 these symbols, and completing "func":
3727 function << lower bound
3729 other_function << upper bound
3731 We find the upper bound by looking for the insertion
3732 point of "func"-with-last-character-incremented,
3734 std::string after
= make_sort_after_prefix_name (lang_name
);
3737 return std::lower_bound (lower
, end
, after
.c_str (),
3738 lookup_compare_lower
);
3741 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
3744 return {lower
, upper
};
3747 /* See declaration. */
3750 mapped_index_base::build_name_components ()
3752 if (!this->name_components
.empty ())
3755 this->name_components_casing
= case_sensitivity
;
3757 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
3759 /* The code below only knows how to break apart components of C++
3760 symbol names (and other languages that use '::' as
3761 namespace/module separator) and Ada symbol names. */
3762 auto count
= this->symbol_name_count ();
3763 for (offset_type idx
= 0; idx
< count
; idx
++)
3765 if (this->symbol_name_slot_invalid (idx
))
3768 const char *name
= this->symbol_name_at (idx
);
3770 /* Add each name component to the name component table. */
3771 unsigned int previous_len
= 0;
3773 if (strstr (name
, "::") != nullptr)
3775 for (unsigned int current_len
= cp_find_first_component (name
);
3776 name
[current_len
] != '\0';
3777 current_len
+= cp_find_first_component (name
+ current_len
))
3779 gdb_assert (name
[current_len
] == ':');
3780 this->name_components
.push_back ({previous_len
, idx
});
3781 /* Skip the '::'. */
3783 previous_len
= current_len
;
3788 /* Handle the Ada encoded (aka mangled) form here. */
3789 for (const char *iter
= strstr (name
, "__");
3791 iter
= strstr (iter
, "__"))
3793 this->name_components
.push_back ({previous_len
, idx
});
3795 previous_len
= iter
- name
;
3799 this->name_components
.push_back ({previous_len
, idx
});
3802 /* Sort name_components elements by name. */
3803 auto name_comp_compare
= [&] (const name_component
&left
,
3804 const name_component
&right
)
3806 const char *left_qualified
= this->symbol_name_at (left
.idx
);
3807 const char *right_qualified
= this->symbol_name_at (right
.idx
);
3809 const char *left_name
= left_qualified
+ left
.name_offset
;
3810 const char *right_name
= right_qualified
+ right
.name_offset
;
3812 return name_cmp (left_name
, right_name
) < 0;
3815 std::sort (this->name_components
.begin (),
3816 this->name_components
.end (),
3820 /* Helper for dw2_expand_symtabs_matching that works with a
3821 mapped_index_base instead of the containing objfile. This is split
3822 to a separate function in order to be able to unit test the
3823 name_components matching using a mock mapped_index_base. For each
3824 symbol name that matches, calls MATCH_CALLBACK, passing it the
3825 symbol's index in the mapped_index_base symbol table. */
3828 dw2_expand_symtabs_matching_symbol
3829 (mapped_index_base
&index
,
3830 const lookup_name_info
&lookup_name_in
,
3831 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
3832 enum search_domain kind
,
3833 gdb::function_view
<bool (offset_type
)> match_callback
)
3835 lookup_name_info lookup_name_without_params
3836 = lookup_name_in
.make_ignore_params ();
3838 /* Build the symbol name component sorted vector, if we haven't
3840 index
.build_name_components ();
3842 /* The same symbol may appear more than once in the range though.
3843 E.g., if we're looking for symbols that complete "w", and we have
3844 a symbol named "w1::w2", we'll find the two name components for
3845 that same symbol in the range. To be sure we only call the
3846 callback once per symbol, we first collect the symbol name
3847 indexes that matched in a temporary vector and ignore
3849 std::vector
<offset_type
> matches
;
3851 struct name_and_matcher
3853 symbol_name_matcher_ftype
*matcher
;
3854 const std::string
&name
;
3856 bool operator== (const name_and_matcher
&other
) const
3858 return matcher
== other
.matcher
&& name
== other
.name
;
3862 /* A vector holding all the different symbol name matchers, for all
3864 std::vector
<name_and_matcher
> matchers
;
3866 for (int i
= 0; i
< nr_languages
; i
++)
3868 enum language lang_e
= (enum language
) i
;
3870 const language_defn
*lang
= language_def (lang_e
);
3871 symbol_name_matcher_ftype
*name_matcher
3872 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
3874 name_and_matcher key
{
3876 lookup_name_without_params
.language_lookup_name (lang_e
)
3879 /* Don't insert the same comparison routine more than once.
3880 Note that we do this linear walk. This is not a problem in
3881 practice because the number of supported languages is
3883 if (std::find (matchers
.begin (), matchers
.end (), key
)
3886 matchers
.push_back (std::move (key
));
3889 = index
.find_name_components_bounds (lookup_name_without_params
,
3892 /* Now for each symbol name in range, check to see if we have a name
3893 match, and if so, call the MATCH_CALLBACK callback. */
3895 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
3897 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
3899 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
3900 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
3903 matches
.push_back (bounds
.first
->idx
);
3907 std::sort (matches
.begin (), matches
.end ());
3909 /* Finally call the callback, once per match. */
3911 for (offset_type idx
: matches
)
3915 if (!match_callback (idx
))
3921 /* Above we use a type wider than idx's for 'prev', since 0 and
3922 (offset_type)-1 are both possible values. */
3923 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
3928 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
3930 /* A mock .gdb_index/.debug_names-like name index table, enough to
3931 exercise dw2_expand_symtabs_matching_symbol, which works with the
3932 mapped_index_base interface. Builds an index from the symbol list
3933 passed as parameter to the constructor. */
3934 class mock_mapped_index
: public mapped_index_base
3937 mock_mapped_index (gdb::array_view
<const char *> symbols
)
3938 : m_symbol_table (symbols
)
3941 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
3943 /* Return the number of names in the symbol table. */
3944 size_t symbol_name_count () const override
3946 return m_symbol_table
.size ();
3949 /* Get the name of the symbol at IDX in the symbol table. */
3950 const char *symbol_name_at (offset_type idx
) const override
3952 return m_symbol_table
[idx
];
3956 gdb::array_view
<const char *> m_symbol_table
;
3959 /* Convenience function that converts a NULL pointer to a "<null>"
3960 string, to pass to print routines. */
3963 string_or_null (const char *str
)
3965 return str
!= NULL
? str
: "<null>";
3968 /* Check if a lookup_name_info built from
3969 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
3970 index. EXPECTED_LIST is the list of expected matches, in expected
3971 matching order. If no match expected, then an empty list is
3972 specified. Returns true on success. On failure prints a warning
3973 indicating the file:line that failed, and returns false. */
3976 check_match (const char *file
, int line
,
3977 mock_mapped_index
&mock_index
,
3978 const char *name
, symbol_name_match_type match_type
,
3979 bool completion_mode
,
3980 std::initializer_list
<const char *> expected_list
)
3982 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
3984 bool matched
= true;
3986 auto mismatch
= [&] (const char *expected_str
,
3989 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
3990 "expected=\"%s\", got=\"%s\"\n"),
3992 (match_type
== symbol_name_match_type::FULL
3994 name
, string_or_null (expected_str
), string_or_null (got
));
3998 auto expected_it
= expected_list
.begin ();
3999 auto expected_end
= expected_list
.end ();
4001 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4003 [&] (offset_type idx
)
4005 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4006 const char *expected_str
4007 = expected_it
== expected_end
? NULL
: *expected_it
++;
4009 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4010 mismatch (expected_str
, matched_name
);
4014 const char *expected_str
4015 = expected_it
== expected_end
? NULL
: *expected_it
++;
4016 if (expected_str
!= NULL
)
4017 mismatch (expected_str
, NULL
);
4022 /* The symbols added to the mock mapped_index for testing (in
4024 static const char *test_symbols
[] = {
4033 "ns2::tmpl<int>::foo2",
4034 "(anonymous namespace)::A::B::C",
4036 /* These are used to check that the increment-last-char in the
4037 matching algorithm for completion doesn't match "t1_fund" when
4038 completing "t1_func". */
4044 /* A UTF-8 name with multi-byte sequences to make sure that
4045 cp-name-parser understands this as a single identifier ("função"
4046 is "function" in PT). */
4049 /* \377 (0xff) is Latin1 'ÿ'. */
4052 /* \377 (0xff) is Latin1 'ÿ'. */
4056 /* A name with all sorts of complications. Starts with "z" to make
4057 it easier for the completion tests below. */
4058 #define Z_SYM_NAME \
4059 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4060 "::tuple<(anonymous namespace)::ui*, " \
4061 "std::default_delete<(anonymous namespace)::ui>, void>"
4066 /* Returns true if the mapped_index_base::find_name_component_bounds
4067 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4068 in completion mode. */
4071 check_find_bounds_finds (mapped_index_base
&index
,
4072 const char *search_name
,
4073 gdb::array_view
<const char *> expected_syms
)
4075 lookup_name_info
lookup_name (search_name
,
4076 symbol_name_match_type::FULL
, true);
4078 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4081 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4082 if (distance
!= expected_syms
.size ())
4085 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4087 auto nc_elem
= bounds
.first
+ exp_elem
;
4088 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4089 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4096 /* Test the lower-level mapped_index::find_name_component_bounds
4100 test_mapped_index_find_name_component_bounds ()
4102 mock_mapped_index
mock_index (test_symbols
);
4104 mock_index
.build_name_components ();
4106 /* Test the lower-level mapped_index::find_name_component_bounds
4107 method in completion mode. */
4109 static const char *expected_syms
[] = {
4114 SELF_CHECK (check_find_bounds_finds (mock_index
,
4115 "t1_func", expected_syms
));
4118 /* Check that the increment-last-char in the name matching algorithm
4119 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4121 static const char *expected_syms1
[] = {
4125 SELF_CHECK (check_find_bounds_finds (mock_index
,
4126 "\377", expected_syms1
));
4128 static const char *expected_syms2
[] = {
4131 SELF_CHECK (check_find_bounds_finds (mock_index
,
4132 "\377\377", expected_syms2
));
4136 /* Test dw2_expand_symtabs_matching_symbol. */
4139 test_dw2_expand_symtabs_matching_symbol ()
4141 mock_mapped_index
mock_index (test_symbols
);
4143 /* We let all tests run until the end even if some fails, for debug
4145 bool any_mismatch
= false;
4147 /* Create the expected symbols list (an initializer_list). Needed
4148 because lists have commas, and we need to pass them to CHECK,
4149 which is a macro. */
4150 #define EXPECT(...) { __VA_ARGS__ }
4152 /* Wrapper for check_match that passes down the current
4153 __FILE__/__LINE__. */
4154 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4155 any_mismatch |= !check_match (__FILE__, __LINE__, \
4157 NAME, MATCH_TYPE, COMPLETION_MODE, \
4160 /* Identity checks. */
4161 for (const char *sym
: test_symbols
)
4163 /* Should be able to match all existing symbols. */
4164 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4167 /* Should be able to match all existing symbols with
4169 std::string with_params
= std::string (sym
) + "(int)";
4170 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4173 /* Should be able to match all existing symbols with
4174 parameters and qualifiers. */
4175 with_params
= std::string (sym
) + " ( int ) const";
4176 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4179 /* This should really find sym, but cp-name-parser.y doesn't
4180 know about lvalue/rvalue qualifiers yet. */
4181 with_params
= std::string (sym
) + " ( int ) &&";
4182 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4186 /* Check that the name matching algorithm for completion doesn't get
4187 confused with Latin1 'ÿ' / 0xff. */
4189 static const char str
[] = "\377";
4190 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4191 EXPECT ("\377", "\377\377123"));
4194 /* Check that the increment-last-char in the matching algorithm for
4195 completion doesn't match "t1_fund" when completing "t1_func". */
4197 static const char str
[] = "t1_func";
4198 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4199 EXPECT ("t1_func", "t1_func1"));
4202 /* Check that completion mode works at each prefix of the expected
4205 static const char str
[] = "function(int)";
4206 size_t len
= strlen (str
);
4209 for (size_t i
= 1; i
< len
; i
++)
4211 lookup
.assign (str
, i
);
4212 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4213 EXPECT ("function"));
4217 /* While "w" is a prefix of both components, the match function
4218 should still only be called once. */
4220 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4222 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4226 /* Same, with a "complicated" symbol. */
4228 static const char str
[] = Z_SYM_NAME
;
4229 size_t len
= strlen (str
);
4232 for (size_t i
= 1; i
< len
; i
++)
4234 lookup
.assign (str
, i
);
4235 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4236 EXPECT (Z_SYM_NAME
));
4240 /* In FULL mode, an incomplete symbol doesn't match. */
4242 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4246 /* A complete symbol with parameters matches any overload, since the
4247 index has no overload info. */
4249 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4250 EXPECT ("std::zfunction", "std::zfunction2"));
4251 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4252 EXPECT ("std::zfunction", "std::zfunction2"));
4253 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4254 EXPECT ("std::zfunction", "std::zfunction2"));
4257 /* Check that whitespace is ignored appropriately. A symbol with a
4258 template argument list. */
4260 static const char expected
[] = "ns::foo<int>";
4261 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4263 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4267 /* Check that whitespace is ignored appropriately. A symbol with a
4268 template argument list that includes a pointer. */
4270 static const char expected
[] = "ns::foo<char*>";
4271 /* Try both completion and non-completion modes. */
4272 static const bool completion_mode
[2] = {false, true};
4273 for (size_t i
= 0; i
< 2; i
++)
4275 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4276 completion_mode
[i
], EXPECT (expected
));
4277 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4278 completion_mode
[i
], EXPECT (expected
));
4280 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4281 completion_mode
[i
], EXPECT (expected
));
4282 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4283 completion_mode
[i
], EXPECT (expected
));
4288 /* Check method qualifiers are ignored. */
4289 static const char expected
[] = "ns::foo<char*>";
4290 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4291 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4292 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4293 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4294 CHECK_MATCH ("foo < char * > ( int ) const",
4295 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4296 CHECK_MATCH ("foo < char * > ( int ) &&",
4297 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4300 /* Test lookup names that don't match anything. */
4302 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4305 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4309 /* Some wild matching tests, exercising "(anonymous namespace)",
4310 which should not be confused with a parameter list. */
4312 static const char *syms
[] = {
4316 "A :: B :: C ( int )",
4321 for (const char *s
: syms
)
4323 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4324 EXPECT ("(anonymous namespace)::A::B::C"));
4329 static const char expected
[] = "ns2::tmpl<int>::foo2";
4330 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4332 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4336 SELF_CHECK (!any_mismatch
);
4345 test_mapped_index_find_name_component_bounds ();
4346 test_dw2_expand_symtabs_matching_symbol ();
4349 }} // namespace selftests::dw2_expand_symtabs_matching
4351 #endif /* GDB_SELF_TEST */
4353 /* If FILE_MATCHER is NULL or if PER_CU has
4354 dwarf2_per_cu_quick_data::MARK set (see
4355 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4356 EXPANSION_NOTIFY on it. */
4359 dw2_expand_symtabs_matching_one
4360 (struct dwarf2_per_cu_data
*per_cu
,
4361 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4362 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4364 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4366 bool symtab_was_null
4367 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4369 dw2_instantiate_symtab (per_cu
, false);
4371 if (expansion_notify
!= NULL
4373 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4374 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4378 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4379 matched, to expand corresponding CUs that were marked. IDX is the
4380 index of the symbol name that matched. */
4383 dw2_expand_marked_cus
4384 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4385 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4386 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4389 offset_type
*vec
, vec_len
, vec_idx
;
4390 bool global_seen
= false;
4391 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4393 vec
= (offset_type
*) (index
.constant_pool
4394 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4395 vec_len
= MAYBE_SWAP (vec
[0]);
4396 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4398 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4399 /* This value is only valid for index versions >= 7. */
4400 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4401 gdb_index_symbol_kind symbol_kind
=
4402 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4403 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4404 /* Only check the symbol attributes if they're present.
4405 Indices prior to version 7 don't record them,
4406 and indices >= 7 may elide them for certain symbols
4407 (gold does this). */
4410 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4412 /* Work around gold/15646. */
4415 if (!is_static
&& global_seen
)
4421 /* Only check the symbol's kind if it has one. */
4426 case VARIABLES_DOMAIN
:
4427 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4430 case FUNCTIONS_DOMAIN
:
4431 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4435 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4438 case MODULES_DOMAIN
:
4439 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4447 /* Don't crash on bad data. */
4448 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4449 + dwarf2_per_objfile
->all_type_units
.size ()))
4451 complaint (_(".gdb_index entry has bad CU index"
4453 objfile_name (dwarf2_per_objfile
->objfile
));
4457 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4458 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4463 /* If FILE_MATCHER is non-NULL, set all the
4464 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4465 that match FILE_MATCHER. */
4468 dw_expand_symtabs_matching_file_matcher
4469 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4470 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4472 if (file_matcher
== NULL
)
4475 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4477 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4479 NULL
, xcalloc
, xfree
));
4480 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4482 NULL
, xcalloc
, xfree
));
4484 /* The rule is CUs specify all the files, including those used by
4485 any TU, so there's no need to scan TUs here. */
4487 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4491 per_cu
->v
.quick
->mark
= 0;
4493 /* We only need to look at symtabs not already expanded. */
4494 if (per_cu
->v
.quick
->compunit_symtab
)
4497 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4498 if (file_data
== NULL
)
4501 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4503 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4505 per_cu
->v
.quick
->mark
= 1;
4509 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4511 const char *this_real_name
;
4513 if (file_matcher (file_data
->file_names
[j
], false))
4515 per_cu
->v
.quick
->mark
= 1;
4519 /* Before we invoke realpath, which can get expensive when many
4520 files are involved, do a quick comparison of the basenames. */
4521 if (!basenames_may_differ
4522 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4526 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4527 if (file_matcher (this_real_name
, false))
4529 per_cu
->v
.quick
->mark
= 1;
4534 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4535 ? visited_found
.get ()
4536 : visited_not_found
.get (),
4543 dw2_expand_symtabs_matching
4544 (struct objfile
*objfile
,
4545 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4546 const lookup_name_info
&lookup_name
,
4547 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4548 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4549 enum search_domain kind
)
4551 struct dwarf2_per_objfile
*dwarf2_per_objfile
4552 = get_dwarf2_per_objfile (objfile
);
4554 /* index_table is NULL if OBJF_READNOW. */
4555 if (!dwarf2_per_objfile
->index_table
)
4558 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4560 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4562 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4564 kind
, [&] (offset_type idx
)
4566 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4567 expansion_notify
, kind
);
4572 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4575 static struct compunit_symtab
*
4576 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4581 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4582 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4585 if (cust
->includes
== NULL
)
4588 for (i
= 0; cust
->includes
[i
]; ++i
)
4590 struct compunit_symtab
*s
= cust
->includes
[i
];
4592 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
4600 static struct compunit_symtab
*
4601 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
4602 struct bound_minimal_symbol msymbol
,
4604 struct obj_section
*section
,
4607 struct dwarf2_per_cu_data
*data
;
4608 struct compunit_symtab
*result
;
4610 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
4613 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
4614 data
= (struct dwarf2_per_cu_data
*) addrmap_find
4615 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
4619 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
4620 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
4621 paddress (get_objfile_arch (objfile
), pc
));
4624 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
4627 gdb_assert (result
!= NULL
);
4632 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
4633 void *data
, int need_fullname
)
4635 struct dwarf2_per_objfile
*dwarf2_per_objfile
4636 = get_dwarf2_per_objfile (objfile
);
4638 if (!dwarf2_per_objfile
->filenames_cache
)
4640 dwarf2_per_objfile
->filenames_cache
.emplace ();
4642 htab_up
visited (htab_create_alloc (10,
4643 htab_hash_pointer
, htab_eq_pointer
,
4644 NULL
, xcalloc
, xfree
));
4646 /* The rule is CUs specify all the files, including those used
4647 by any TU, so there's no need to scan TUs here. We can
4648 ignore file names coming from already-expanded CUs. */
4650 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4652 if (per_cu
->v
.quick
->compunit_symtab
)
4654 void **slot
= htab_find_slot (visited
.get (),
4655 per_cu
->v
.quick
->file_names
,
4658 *slot
= per_cu
->v
.quick
->file_names
;
4662 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4664 /* We only need to look at symtabs not already expanded. */
4665 if (per_cu
->v
.quick
->compunit_symtab
)
4668 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4669 if (file_data
== NULL
)
4672 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
4675 /* Already visited. */
4680 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4682 const char *filename
= file_data
->file_names
[j
];
4683 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
4688 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
4690 gdb::unique_xmalloc_ptr
<char> this_real_name
;
4693 this_real_name
= gdb_realpath (filename
);
4694 (*fun
) (filename
, this_real_name
.get (), data
);
4699 dw2_has_symbols (struct objfile
*objfile
)
4704 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
4707 dw2_find_last_source_symtab
,
4708 dw2_forget_cached_source_info
,
4709 dw2_map_symtabs_matching_filename
,
4714 dw2_expand_symtabs_for_function
,
4715 dw2_expand_all_symtabs
,
4716 dw2_expand_symtabs_with_fullname
,
4717 dw2_map_matching_symbols
,
4718 dw2_expand_symtabs_matching
,
4719 dw2_find_pc_sect_compunit_symtab
,
4721 dw2_map_symbol_filenames
4724 /* DWARF-5 debug_names reader. */
4726 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4727 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4729 /* A helper function that reads the .debug_names section in SECTION
4730 and fills in MAP. FILENAME is the name of the file containing the
4731 section; it is used for error reporting.
4733 Returns true if all went well, false otherwise. */
4736 read_debug_names_from_section (struct objfile
*objfile
,
4737 const char *filename
,
4738 struct dwarf2_section_info
*section
,
4739 mapped_debug_names
&map
)
4741 if (section
->empty ())
4744 /* Older elfutils strip versions could keep the section in the main
4745 executable while splitting it for the separate debug info file. */
4746 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4749 section
->read (objfile
);
4751 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4753 const gdb_byte
*addr
= section
->buffer
;
4755 bfd
*const abfd
= section
->get_bfd_owner ();
4757 unsigned int bytes_read
;
4758 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4761 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4762 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4763 if (bytes_read
+ length
!= section
->size
)
4765 /* There may be multiple per-CU indices. */
4766 warning (_("Section .debug_names in %s length %s does not match "
4767 "section length %s, ignoring .debug_names."),
4768 filename
, plongest (bytes_read
+ length
),
4769 pulongest (section
->size
));
4773 /* The version number. */
4774 uint16_t version
= read_2_bytes (abfd
, addr
);
4778 warning (_("Section .debug_names in %s has unsupported version %d, "
4779 "ignoring .debug_names."),
4785 uint16_t padding
= read_2_bytes (abfd
, addr
);
4789 warning (_("Section .debug_names in %s has unsupported padding %d, "
4790 "ignoring .debug_names."),
4795 /* comp_unit_count - The number of CUs in the CU list. */
4796 map
.cu_count
= read_4_bytes (abfd
, addr
);
4799 /* local_type_unit_count - The number of TUs in the local TU
4801 map
.tu_count
= read_4_bytes (abfd
, addr
);
4804 /* foreign_type_unit_count - The number of TUs in the foreign TU
4806 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4808 if (foreign_tu_count
!= 0)
4810 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4811 "ignoring .debug_names."),
4812 filename
, static_cast<unsigned long> (foreign_tu_count
));
4816 /* bucket_count - The number of hash buckets in the hash lookup
4818 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4821 /* name_count - The number of unique names in the index. */
4822 map
.name_count
= read_4_bytes (abfd
, addr
);
4825 /* abbrev_table_size - The size in bytes of the abbreviations
4827 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4830 /* augmentation_string_size - The size in bytes of the augmentation
4831 string. This value is rounded up to a multiple of 4. */
4832 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4834 map
.augmentation_is_gdb
= ((augmentation_string_size
4835 == sizeof (dwarf5_augmentation
))
4836 && memcmp (addr
, dwarf5_augmentation
,
4837 sizeof (dwarf5_augmentation
)) == 0);
4838 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4839 addr
+= augmentation_string_size
;
4842 map
.cu_table_reordered
= addr
;
4843 addr
+= map
.cu_count
* map
.offset_size
;
4845 /* List of Local TUs */
4846 map
.tu_table_reordered
= addr
;
4847 addr
+= map
.tu_count
* map
.offset_size
;
4849 /* Hash Lookup Table */
4850 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4851 addr
+= map
.bucket_count
* 4;
4852 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4853 addr
+= map
.name_count
* 4;
4856 map
.name_table_string_offs_reordered
= addr
;
4857 addr
+= map
.name_count
* map
.offset_size
;
4858 map
.name_table_entry_offs_reordered
= addr
;
4859 addr
+= map
.name_count
* map
.offset_size
;
4861 const gdb_byte
*abbrev_table_start
= addr
;
4864 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4869 const auto insertpair
4870 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4871 if (!insertpair
.second
)
4873 warning (_("Section .debug_names in %s has duplicate index %s, "
4874 "ignoring .debug_names."),
4875 filename
, pulongest (index_num
));
4878 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4879 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4884 mapped_debug_names::index_val::attr attr
;
4885 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4887 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4889 if (attr
.form
== DW_FORM_implicit_const
)
4891 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4895 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4897 indexval
.attr_vec
.push_back (std::move (attr
));
4900 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4902 warning (_("Section .debug_names in %s has abbreviation_table "
4903 "of size %s vs. written as %u, ignoring .debug_names."),
4904 filename
, plongest (addr
- abbrev_table_start
),
4908 map
.entry_pool
= addr
;
4913 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4917 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4918 const mapped_debug_names
&map
,
4919 dwarf2_section_info
§ion
,
4922 sect_offset sect_off_prev
;
4923 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4925 sect_offset sect_off_next
;
4926 if (i
< map
.cu_count
)
4929 = (sect_offset
) (extract_unsigned_integer
4930 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4932 map
.dwarf5_byte_order
));
4935 sect_off_next
= (sect_offset
) section
.size
;
4938 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4939 dwarf2_per_cu_data
*per_cu
4940 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4941 sect_off_prev
, length
);
4942 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4944 sect_off_prev
= sect_off_next
;
4948 /* Read the CU list from the mapped index, and use it to create all
4949 the CU objects for this dwarf2_per_objfile. */
4952 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4953 const mapped_debug_names
&map
,
4954 const mapped_debug_names
&dwz_map
)
4956 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4957 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4959 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4960 dwarf2_per_objfile
->info
,
4961 false /* is_dwz */);
4963 if (dwz_map
.cu_count
== 0)
4966 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4967 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4971 /* Read .debug_names. If everything went ok, initialize the "quick"
4972 elements of all the CUs and return true. Otherwise, return false. */
4975 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
4977 std::unique_ptr
<mapped_debug_names
> map
4978 (new mapped_debug_names (dwarf2_per_objfile
));
4979 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
4980 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4982 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4983 &dwarf2_per_objfile
->debug_names
,
4987 /* Don't use the index if it's empty. */
4988 if (map
->name_count
== 0)
4991 /* If there is a .dwz file, read it so we can get its CU list as
4993 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4996 if (!read_debug_names_from_section (objfile
,
4997 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4998 &dwz
->debug_names
, dwz_map
))
5000 warning (_("could not read '.debug_names' section from %s; skipping"),
5001 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5006 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5008 if (map
->tu_count
!= 0)
5010 /* We can only handle a single .debug_types when we have an
5012 if (dwarf2_per_objfile
->types
.size () != 1)
5015 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5017 create_signatured_type_table_from_debug_names
5018 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5021 create_addrmap_from_aranges (dwarf2_per_objfile
,
5022 &dwarf2_per_objfile
->debug_aranges
);
5024 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5025 dwarf2_per_objfile
->using_index
= 1;
5026 dwarf2_per_objfile
->quick_file_names_table
=
5027 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5032 /* Type used to manage iterating over all CUs looking for a symbol for
5035 class dw2_debug_names_iterator
5038 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5039 gdb::optional
<block_enum
> block_index
,
5042 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5043 m_addr (find_vec_in_debug_names (map
, name
))
5046 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5047 search_domain search
, uint32_t namei
)
5050 m_addr (find_vec_in_debug_names (map
, namei
))
5053 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5054 block_enum block_index
, domain_enum domain
,
5056 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5057 m_addr (find_vec_in_debug_names (map
, namei
))
5060 /* Return the next matching CU or NULL if there are no more. */
5061 dwarf2_per_cu_data
*next ();
5064 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5066 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5069 /* The internalized form of .debug_names. */
5070 const mapped_debug_names
&m_map
;
5072 /* If set, only look for symbols that match that block. Valid values are
5073 GLOBAL_BLOCK and STATIC_BLOCK. */
5074 const gdb::optional
<block_enum
> m_block_index
;
5076 /* The kind of symbol we're looking for. */
5077 const domain_enum m_domain
= UNDEF_DOMAIN
;
5078 const search_domain m_search
= ALL_DOMAIN
;
5080 /* The list of CUs from the index entry of the symbol, or NULL if
5082 const gdb_byte
*m_addr
;
5086 mapped_debug_names::namei_to_name (uint32_t namei
) const
5088 const ULONGEST namei_string_offs
5089 = extract_unsigned_integer ((name_table_string_offs_reordered
5090 + namei
* offset_size
),
5093 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5097 /* Find a slot in .debug_names for the object named NAME. If NAME is
5098 found, return pointer to its pool data. If NAME cannot be found,
5102 dw2_debug_names_iterator::find_vec_in_debug_names
5103 (const mapped_debug_names
&map
, const char *name
)
5105 int (*cmp
) (const char *, const char *);
5107 gdb::unique_xmalloc_ptr
<char> without_params
;
5108 if (current_language
->la_language
== language_cplus
5109 || current_language
->la_language
== language_fortran
5110 || current_language
->la_language
== language_d
)
5112 /* NAME is already canonical. Drop any qualifiers as
5113 .debug_names does not contain any. */
5115 if (strchr (name
, '(') != NULL
)
5117 without_params
= cp_remove_params (name
);
5118 if (without_params
!= NULL
)
5119 name
= without_params
.get ();
5123 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5125 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5127 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5128 (map
.bucket_table_reordered
5129 + (full_hash
% map
.bucket_count
)), 4,
5130 map
.dwarf5_byte_order
);
5134 if (namei
>= map
.name_count
)
5136 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5138 namei
, map
.name_count
,
5139 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5145 const uint32_t namei_full_hash
5146 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5147 (map
.hash_table_reordered
+ namei
), 4,
5148 map
.dwarf5_byte_order
);
5149 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5152 if (full_hash
== namei_full_hash
)
5154 const char *const namei_string
= map
.namei_to_name (namei
);
5156 #if 0 /* An expensive sanity check. */
5157 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5159 complaint (_("Wrong .debug_names hash for string at index %u "
5161 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5166 if (cmp (namei_string
, name
) == 0)
5168 const ULONGEST namei_entry_offs
5169 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5170 + namei
* map
.offset_size
),
5171 map
.offset_size
, map
.dwarf5_byte_order
);
5172 return map
.entry_pool
+ namei_entry_offs
;
5177 if (namei
>= map
.name_count
)
5183 dw2_debug_names_iterator::find_vec_in_debug_names
5184 (const mapped_debug_names
&map
, uint32_t namei
)
5186 if (namei
>= map
.name_count
)
5188 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5190 namei
, map
.name_count
,
5191 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5195 const ULONGEST namei_entry_offs
5196 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5197 + namei
* map
.offset_size
),
5198 map
.offset_size
, map
.dwarf5_byte_order
);
5199 return map
.entry_pool
+ namei_entry_offs
;
5202 /* See dw2_debug_names_iterator. */
5204 dwarf2_per_cu_data
*
5205 dw2_debug_names_iterator::next ()
5210 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5211 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5212 bfd
*const abfd
= objfile
->obfd
;
5216 unsigned int bytes_read
;
5217 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5218 m_addr
+= bytes_read
;
5222 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5223 if (indexval_it
== m_map
.abbrev_map
.cend ())
5225 complaint (_("Wrong .debug_names undefined abbrev code %s "
5227 pulongest (abbrev
), objfile_name (objfile
));
5230 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5231 enum class symbol_linkage
{
5235 } symbol_linkage_
= symbol_linkage::unknown
;
5236 dwarf2_per_cu_data
*per_cu
= NULL
;
5237 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5242 case DW_FORM_implicit_const
:
5243 ull
= attr
.implicit_const
;
5245 case DW_FORM_flag_present
:
5249 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5250 m_addr
+= bytes_read
;
5253 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5254 dwarf_form_name (attr
.form
),
5255 objfile_name (objfile
));
5258 switch (attr
.dw_idx
)
5260 case DW_IDX_compile_unit
:
5261 /* Don't crash on bad data. */
5262 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5264 complaint (_(".debug_names entry has bad CU index %s"
5267 objfile_name (dwarf2_per_objfile
->objfile
));
5270 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5272 case DW_IDX_type_unit
:
5273 /* Don't crash on bad data. */
5274 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5276 complaint (_(".debug_names entry has bad TU index %s"
5279 objfile_name (dwarf2_per_objfile
->objfile
));
5282 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5284 case DW_IDX_GNU_internal
:
5285 if (!m_map
.augmentation_is_gdb
)
5287 symbol_linkage_
= symbol_linkage::static_
;
5289 case DW_IDX_GNU_external
:
5290 if (!m_map
.augmentation_is_gdb
)
5292 symbol_linkage_
= symbol_linkage::extern_
;
5297 /* Skip if already read in. */
5298 if (per_cu
->v
.quick
->compunit_symtab
)
5301 /* Check static vs global. */
5302 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5304 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5305 const bool symbol_is_static
=
5306 symbol_linkage_
== symbol_linkage::static_
;
5307 if (want_static
!= symbol_is_static
)
5311 /* Match dw2_symtab_iter_next, symbol_kind
5312 and debug_names::psymbol_tag. */
5316 switch (indexval
.dwarf_tag
)
5318 case DW_TAG_variable
:
5319 case DW_TAG_subprogram
:
5320 /* Some types are also in VAR_DOMAIN. */
5321 case DW_TAG_typedef
:
5322 case DW_TAG_structure_type
:
5329 switch (indexval
.dwarf_tag
)
5331 case DW_TAG_typedef
:
5332 case DW_TAG_structure_type
:
5339 switch (indexval
.dwarf_tag
)
5342 case DW_TAG_variable
:
5349 switch (indexval
.dwarf_tag
)
5361 /* Match dw2_expand_symtabs_matching, symbol_kind and
5362 debug_names::psymbol_tag. */
5365 case VARIABLES_DOMAIN
:
5366 switch (indexval
.dwarf_tag
)
5368 case DW_TAG_variable
:
5374 case FUNCTIONS_DOMAIN
:
5375 switch (indexval
.dwarf_tag
)
5377 case DW_TAG_subprogram
:
5384 switch (indexval
.dwarf_tag
)
5386 case DW_TAG_typedef
:
5387 case DW_TAG_structure_type
:
5393 case MODULES_DOMAIN
:
5394 switch (indexval
.dwarf_tag
)
5408 static struct compunit_symtab
*
5409 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5410 const char *name
, domain_enum domain
)
5412 struct dwarf2_per_objfile
*dwarf2_per_objfile
5413 = get_dwarf2_per_objfile (objfile
);
5415 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5418 /* index is NULL if OBJF_READNOW. */
5421 const auto &map
= *mapp
;
5423 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5425 struct compunit_symtab
*stab_best
= NULL
;
5426 struct dwarf2_per_cu_data
*per_cu
;
5427 while ((per_cu
= iter
.next ()) != NULL
)
5429 struct symbol
*sym
, *with_opaque
= NULL
;
5430 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5431 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5432 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5434 sym
= block_find_symbol (block
, name
, domain
,
5435 block_find_non_opaque_type_preferred
,
5438 /* Some caution must be observed with overloaded functions and
5439 methods, since the index will not contain any overload
5440 information (but NAME might contain it). */
5443 && strcmp_iw (sym
->search_name (), name
) == 0)
5445 if (with_opaque
!= NULL
5446 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5449 /* Keep looking through other CUs. */
5455 /* This dumps minimal information about .debug_names. It is called
5456 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5457 uses this to verify that .debug_names has been loaded. */
5460 dw2_debug_names_dump (struct objfile
*objfile
)
5462 struct dwarf2_per_objfile
*dwarf2_per_objfile
5463 = get_dwarf2_per_objfile (objfile
);
5465 gdb_assert (dwarf2_per_objfile
->using_index
);
5466 printf_filtered (".debug_names:");
5467 if (dwarf2_per_objfile
->debug_names_table
)
5468 printf_filtered (" exists\n");
5470 printf_filtered (" faked for \"readnow\"\n");
5471 printf_filtered ("\n");
5475 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5476 const char *func_name
)
5478 struct dwarf2_per_objfile
*dwarf2_per_objfile
5479 = get_dwarf2_per_objfile (objfile
);
5481 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5482 if (dwarf2_per_objfile
->debug_names_table
)
5484 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5486 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5488 struct dwarf2_per_cu_data
*per_cu
;
5489 while ((per_cu
= iter
.next ()) != NULL
)
5490 dw2_instantiate_symtab (per_cu
, false);
5495 dw2_debug_names_map_matching_symbols
5496 (struct objfile
*objfile
,
5497 const lookup_name_info
&name
, domain_enum domain
,
5499 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5500 symbol_compare_ftype
*ordered_compare
)
5502 struct dwarf2_per_objfile
*dwarf2_per_objfile
5503 = get_dwarf2_per_objfile (objfile
);
5505 /* debug_names_table is NULL if OBJF_READNOW. */
5506 if (!dwarf2_per_objfile
->debug_names_table
)
5509 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5510 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5512 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5513 auto matcher
= [&] (const char *symname
)
5515 if (ordered_compare
== nullptr)
5517 return ordered_compare (symname
, match_name
) == 0;
5520 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5521 [&] (offset_type namei
)
5523 /* The name was matched, now expand corresponding CUs that were
5525 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5527 struct dwarf2_per_cu_data
*per_cu
;
5528 while ((per_cu
= iter
.next ()) != NULL
)
5529 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5533 /* It's a shame we couldn't do this inside the
5534 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5535 that have already been expanded. Instead, this loop matches what
5536 the psymtab code does. */
5537 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5539 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5540 if (cust
!= nullptr)
5542 const struct block
*block
5543 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5544 if (!iterate_over_symbols_terminated (block
, name
,
5552 dw2_debug_names_expand_symtabs_matching
5553 (struct objfile
*objfile
,
5554 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5555 const lookup_name_info
&lookup_name
,
5556 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5557 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5558 enum search_domain kind
)
5560 struct dwarf2_per_objfile
*dwarf2_per_objfile
5561 = get_dwarf2_per_objfile (objfile
);
5563 /* debug_names_table is NULL if OBJF_READNOW. */
5564 if (!dwarf2_per_objfile
->debug_names_table
)
5567 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5569 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5571 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5573 kind
, [&] (offset_type namei
)
5575 /* The name was matched, now expand corresponding CUs that were
5577 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5579 struct dwarf2_per_cu_data
*per_cu
;
5580 while ((per_cu
= iter
.next ()) != NULL
)
5581 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5587 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5590 dw2_find_last_source_symtab
,
5591 dw2_forget_cached_source_info
,
5592 dw2_map_symtabs_matching_filename
,
5593 dw2_debug_names_lookup_symbol
,
5596 dw2_debug_names_dump
,
5597 dw2_debug_names_expand_symtabs_for_function
,
5598 dw2_expand_all_symtabs
,
5599 dw2_expand_symtabs_with_fullname
,
5600 dw2_debug_names_map_matching_symbols
,
5601 dw2_debug_names_expand_symtabs_matching
,
5602 dw2_find_pc_sect_compunit_symtab
,
5604 dw2_map_symbol_filenames
5607 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5608 to either a dwarf2_per_objfile or dwz_file object. */
5610 template <typename T
>
5611 static gdb::array_view
<const gdb_byte
>
5612 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5614 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5616 if (section
->empty ())
5619 /* Older elfutils strip versions could keep the section in the main
5620 executable while splitting it for the separate debug info file. */
5621 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5624 section
->read (obj
);
5626 /* dwarf2_section_info::size is a bfd_size_type, while
5627 gdb::array_view works with size_t. On 32-bit hosts, with
5628 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5629 is 32-bit. So we need an explicit narrowing conversion here.
5630 This is fine, because it's impossible to allocate or mmap an
5631 array/buffer larger than what size_t can represent. */
5632 return gdb::make_array_view (section
->buffer
, section
->size
);
5635 /* Lookup the index cache for the contents of the index associated to
5638 static gdb::array_view
<const gdb_byte
>
5639 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5641 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5642 if (build_id
== nullptr)
5645 return global_index_cache
.lookup_gdb_index (build_id
,
5646 &dwarf2_obj
->index_cache_res
);
5649 /* Same as the above, but for DWZ. */
5651 static gdb::array_view
<const gdb_byte
>
5652 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5654 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5655 if (build_id
== nullptr)
5658 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5661 /* See symfile.h. */
5664 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5666 struct dwarf2_per_objfile
*dwarf2_per_objfile
5667 = get_dwarf2_per_objfile (objfile
);
5669 /* If we're about to read full symbols, don't bother with the
5670 indices. In this case we also don't care if some other debug
5671 format is making psymtabs, because they are all about to be
5673 if ((objfile
->flags
& OBJF_READNOW
))
5675 dwarf2_per_objfile
->using_index
= 1;
5676 create_all_comp_units (dwarf2_per_objfile
);
5677 create_all_type_units (dwarf2_per_objfile
);
5678 dwarf2_per_objfile
->quick_file_names_table
5679 = create_quick_file_names_table
5680 (dwarf2_per_objfile
->all_comp_units
.size ());
5682 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5683 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5685 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5687 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5688 struct dwarf2_per_cu_quick_data
);
5691 /* Return 1 so that gdb sees the "quick" functions. However,
5692 these functions will be no-ops because we will have expanded
5694 *index_kind
= dw_index_kind::GDB_INDEX
;
5698 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5700 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5704 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5705 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5706 get_gdb_index_contents_from_section
<dwz_file
>))
5708 *index_kind
= dw_index_kind::GDB_INDEX
;
5712 /* ... otherwise, try to find the index in the index cache. */
5713 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5714 get_gdb_index_contents_from_cache
,
5715 get_gdb_index_contents_from_cache_dwz
))
5717 global_index_cache
.hit ();
5718 *index_kind
= dw_index_kind::GDB_INDEX
;
5722 global_index_cache
.miss ();
5728 /* Build a partial symbol table. */
5731 dwarf2_build_psymtabs (struct objfile
*objfile
)
5733 struct dwarf2_per_objfile
*dwarf2_per_objfile
5734 = get_dwarf2_per_objfile (objfile
);
5736 init_psymbol_list (objfile
, 1024);
5740 /* This isn't really ideal: all the data we allocate on the
5741 objfile's obstack is still uselessly kept around. However,
5742 freeing it seems unsafe. */
5743 psymtab_discarder
psymtabs (objfile
);
5744 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5747 /* (maybe) store an index in the cache. */
5748 global_index_cache
.store (dwarf2_per_objfile
);
5750 catch (const gdb_exception_error
&except
)
5752 exception_print (gdb_stderr
, except
);
5756 /* Find the base address of the compilation unit for range lists and
5757 location lists. It will normally be specified by DW_AT_low_pc.
5758 In DWARF-3 draft 4, the base address could be overridden by
5759 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5760 compilation units with discontinuous ranges. */
5763 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5765 struct attribute
*attr
;
5767 cu
->base_address
.reset ();
5769 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5770 if (attr
!= nullptr)
5771 cu
->base_address
= attr
->value_as_address ();
5774 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5775 if (attr
!= nullptr)
5776 cu
->base_address
= attr
->value_as_address ();
5780 /* Helper function that returns the proper abbrev section for
5783 static struct dwarf2_section_info
*
5784 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5786 struct dwarf2_section_info
*abbrev
;
5787 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5789 if (this_cu
->is_dwz
)
5790 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5792 abbrev
= &dwarf2_per_objfile
->abbrev
;
5797 /* Fetch the abbreviation table offset from a comp or type unit header. */
5800 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5801 struct dwarf2_section_info
*section
,
5802 sect_offset sect_off
)
5804 bfd
*abfd
= section
->get_bfd_owner ();
5805 const gdb_byte
*info_ptr
;
5806 unsigned int initial_length_size
, offset_size
;
5809 section
->read (dwarf2_per_objfile
->objfile
);
5810 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5811 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5812 offset_size
= initial_length_size
== 4 ? 4 : 8;
5813 info_ptr
+= initial_length_size
;
5815 version
= read_2_bytes (abfd
, info_ptr
);
5819 /* Skip unit type and address size. */
5823 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5826 /* A partial symtab that is used only for include files. */
5827 struct dwarf2_include_psymtab
: public partial_symtab
5829 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5830 : partial_symtab (filename
, objfile
)
5834 void read_symtab (struct objfile
*objfile
) override
5836 expand_psymtab (objfile
);
5839 void expand_psymtab (struct objfile
*objfile
) override
5843 /* It's an include file, no symbols to read for it.
5844 Everything is in the parent symtab. */
5845 expand_dependencies (objfile
);
5849 bool readin_p () const override
5854 struct compunit_symtab
*get_compunit_symtab () const override
5861 bool m_readin
= false;
5864 /* Allocate a new partial symtab for file named NAME and mark this new
5865 partial symtab as being an include of PST. */
5868 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5869 struct objfile
*objfile
)
5871 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5873 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5875 /* It shares objfile->objfile_obstack. */
5876 subpst
->dirname
= pst
->dirname
;
5879 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5880 subpst
->dependencies
[0] = pst
;
5881 subpst
->number_of_dependencies
= 1;
5884 /* Read the Line Number Program data and extract the list of files
5885 included by the source file represented by PST. Build an include
5886 partial symtab for each of these included files. */
5889 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5890 struct die_info
*die
,
5891 dwarf2_psymtab
*pst
)
5894 struct attribute
*attr
;
5896 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5897 if (attr
!= nullptr)
5898 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5900 return; /* No linetable, so no includes. */
5902 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5903 that we pass in the raw text_low here; that is ok because we're
5904 only decoding the line table to make include partial symtabs, and
5905 so the addresses aren't really used. */
5906 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5907 pst
->raw_text_low (), 1);
5911 hash_signatured_type (const void *item
)
5913 const struct signatured_type
*sig_type
5914 = (const struct signatured_type
*) item
;
5916 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5917 return sig_type
->signature
;
5921 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5923 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5924 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5926 return lhs
->signature
== rhs
->signature
;
5929 /* Allocate a hash table for signatured types. */
5932 allocate_signatured_type_table ()
5934 return htab_up (htab_create_alloc (41,
5935 hash_signatured_type
,
5937 NULL
, xcalloc
, xfree
));
5940 /* A helper function to add a signatured type CU to a table. */
5943 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5945 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5946 std::vector
<signatured_type
*> *all_type_units
5947 = (std::vector
<signatured_type
*> *) datum
;
5949 all_type_units
->push_back (sigt
);
5954 /* A helper for create_debug_types_hash_table. Read types from SECTION
5955 and fill them into TYPES_HTAB. It will process only type units,
5956 therefore DW_UT_type. */
5959 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5960 struct dwo_file
*dwo_file
,
5961 dwarf2_section_info
*section
, htab_up
&types_htab
,
5962 rcuh_kind section_kind
)
5964 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5965 struct dwarf2_section_info
*abbrev_section
;
5967 const gdb_byte
*info_ptr
, *end_ptr
;
5969 abbrev_section
= (dwo_file
!= NULL
5970 ? &dwo_file
->sections
.abbrev
5971 : &dwarf2_per_objfile
->abbrev
);
5973 if (dwarf_read_debug
)
5974 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5975 section
->get_name (),
5976 abbrev_section
->get_file_name ());
5978 section
->read (objfile
);
5979 info_ptr
= section
->buffer
;
5981 if (info_ptr
== NULL
)
5984 /* We can't set abfd until now because the section may be empty or
5985 not present, in which case the bfd is unknown. */
5986 abfd
= section
->get_bfd_owner ();
5988 /* We don't use cutu_reader here because we don't need to read
5989 any dies: the signature is in the header. */
5991 end_ptr
= info_ptr
+ section
->size
;
5992 while (info_ptr
< end_ptr
)
5994 struct signatured_type
*sig_type
;
5995 struct dwo_unit
*dwo_tu
;
5997 const gdb_byte
*ptr
= info_ptr
;
5998 struct comp_unit_head header
;
5999 unsigned int length
;
6001 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6003 /* Initialize it due to a false compiler warning. */
6004 header
.signature
= -1;
6005 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6007 /* We need to read the type's signature in order to build the hash
6008 table, but we don't need anything else just yet. */
6010 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6011 abbrev_section
, ptr
, section_kind
);
6013 length
= header
.get_length ();
6015 /* Skip dummy type units. */
6016 if (ptr
>= info_ptr
+ length
6017 || peek_abbrev_code (abfd
, ptr
) == 0
6018 || header
.unit_type
!= DW_UT_type
)
6024 if (types_htab
== NULL
)
6027 types_htab
= allocate_dwo_unit_table ();
6029 types_htab
= allocate_signatured_type_table ();
6035 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6037 dwo_tu
->dwo_file
= dwo_file
;
6038 dwo_tu
->signature
= header
.signature
;
6039 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6040 dwo_tu
->section
= section
;
6041 dwo_tu
->sect_off
= sect_off
;
6042 dwo_tu
->length
= length
;
6046 /* N.B.: type_offset is not usable if this type uses a DWO file.
6047 The real type_offset is in the DWO file. */
6049 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6050 struct signatured_type
);
6051 sig_type
->signature
= header
.signature
;
6052 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6053 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6054 sig_type
->per_cu
.is_debug_types
= 1;
6055 sig_type
->per_cu
.section
= section
;
6056 sig_type
->per_cu
.sect_off
= sect_off
;
6057 sig_type
->per_cu
.length
= length
;
6060 slot
= htab_find_slot (types_htab
.get (),
6061 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6063 gdb_assert (slot
!= NULL
);
6066 sect_offset dup_sect_off
;
6070 const struct dwo_unit
*dup_tu
6071 = (const struct dwo_unit
*) *slot
;
6073 dup_sect_off
= dup_tu
->sect_off
;
6077 const struct signatured_type
*dup_tu
6078 = (const struct signatured_type
*) *slot
;
6080 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6083 complaint (_("debug type entry at offset %s is duplicate to"
6084 " the entry at offset %s, signature %s"),
6085 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6086 hex_string (header
.signature
));
6088 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6090 if (dwarf_read_debug
> 1)
6091 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6092 sect_offset_str (sect_off
),
6093 hex_string (header
.signature
));
6099 /* Create the hash table of all entries in the .debug_types
6100 (or .debug_types.dwo) section(s).
6101 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6102 otherwise it is NULL.
6104 The result is a pointer to the hash table or NULL if there are no types.
6106 Note: This function processes DWO files only, not DWP files. */
6109 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6110 struct dwo_file
*dwo_file
,
6111 gdb::array_view
<dwarf2_section_info
> type_sections
,
6112 htab_up
&types_htab
)
6114 for (dwarf2_section_info
§ion
: type_sections
)
6115 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6116 types_htab
, rcuh_kind::TYPE
);
6119 /* Create the hash table of all entries in the .debug_types section,
6120 and initialize all_type_units.
6121 The result is zero if there is an error (e.g. missing .debug_types section),
6122 otherwise non-zero. */
6125 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6129 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6130 &dwarf2_per_objfile
->info
, types_htab
,
6131 rcuh_kind::COMPILE
);
6132 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6133 dwarf2_per_objfile
->types
, types_htab
);
6134 if (types_htab
== NULL
)
6136 dwarf2_per_objfile
->signatured_types
= NULL
;
6140 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6142 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6143 dwarf2_per_objfile
->all_type_units
.reserve
6144 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6146 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6147 add_signatured_type_cu_to_table
,
6148 &dwarf2_per_objfile
->all_type_units
);
6153 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6154 If SLOT is non-NULL, it is the entry to use in the hash table.
6155 Otherwise we find one. */
6157 static struct signatured_type
*
6158 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6161 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6163 if (dwarf2_per_objfile
->all_type_units
.size ()
6164 == dwarf2_per_objfile
->all_type_units
.capacity ())
6165 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6167 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6168 struct signatured_type
);
6170 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6171 sig_type
->signature
= sig
;
6172 sig_type
->per_cu
.is_debug_types
= 1;
6173 if (dwarf2_per_objfile
->using_index
)
6175 sig_type
->per_cu
.v
.quick
=
6176 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6177 struct dwarf2_per_cu_quick_data
);
6182 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6185 gdb_assert (*slot
== NULL
);
6187 /* The rest of sig_type must be filled in by the caller. */
6191 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6192 Fill in SIG_ENTRY with DWO_ENTRY. */
6195 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6196 struct signatured_type
*sig_entry
,
6197 struct dwo_unit
*dwo_entry
)
6199 /* Make sure we're not clobbering something we don't expect to. */
6200 gdb_assert (! sig_entry
->per_cu
.queued
);
6201 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6202 if (dwarf2_per_objfile
->using_index
)
6204 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6205 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6208 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6209 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6210 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6211 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6212 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6214 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6215 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6216 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6217 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6218 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6219 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6220 sig_entry
->dwo_unit
= dwo_entry
;
6223 /* Subroutine of lookup_signatured_type.
6224 If we haven't read the TU yet, create the signatured_type data structure
6225 for a TU to be read in directly from a DWO file, bypassing the stub.
6226 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6227 using .gdb_index, then when reading a CU we want to stay in the DWO file
6228 containing that CU. Otherwise we could end up reading several other DWO
6229 files (due to comdat folding) to process the transitive closure of all the
6230 mentioned TUs, and that can be slow. The current DWO file will have every
6231 type signature that it needs.
6232 We only do this for .gdb_index because in the psymtab case we already have
6233 to read all the DWOs to build the type unit groups. */
6235 static struct signatured_type
*
6236 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6238 struct dwarf2_per_objfile
*dwarf2_per_objfile
6239 = cu
->per_cu
->dwarf2_per_objfile
;
6240 struct dwo_file
*dwo_file
;
6241 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6242 struct signatured_type find_sig_entry
, *sig_entry
;
6245 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6247 /* If TU skeletons have been removed then we may not have read in any
6249 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6250 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6252 /* We only ever need to read in one copy of a signatured type.
6253 Use the global signatured_types array to do our own comdat-folding
6254 of types. If this is the first time we're reading this TU, and
6255 the TU has an entry in .gdb_index, replace the recorded data from
6256 .gdb_index with this TU. */
6258 find_sig_entry
.signature
= sig
;
6259 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6260 &find_sig_entry
, INSERT
);
6261 sig_entry
= (struct signatured_type
*) *slot
;
6263 /* We can get here with the TU already read, *or* in the process of being
6264 read. Don't reassign the global entry to point to this DWO if that's
6265 the case. Also note that if the TU is already being read, it may not
6266 have come from a DWO, the program may be a mix of Fission-compiled
6267 code and non-Fission-compiled code. */
6269 /* Have we already tried to read this TU?
6270 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6271 needn't exist in the global table yet). */
6272 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6275 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6276 dwo_unit of the TU itself. */
6277 dwo_file
= cu
->dwo_unit
->dwo_file
;
6279 /* Ok, this is the first time we're reading this TU. */
6280 if (dwo_file
->tus
== NULL
)
6282 find_dwo_entry
.signature
= sig
;
6283 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6285 if (dwo_entry
== NULL
)
6288 /* If the global table doesn't have an entry for this TU, add one. */
6289 if (sig_entry
== NULL
)
6290 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6292 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6293 sig_entry
->per_cu
.tu_read
= 1;
6297 /* Subroutine of lookup_signatured_type.
6298 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6299 then try the DWP file. If the TU stub (skeleton) has been removed then
6300 it won't be in .gdb_index. */
6302 static struct signatured_type
*
6303 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6305 struct dwarf2_per_objfile
*dwarf2_per_objfile
6306 = cu
->per_cu
->dwarf2_per_objfile
;
6307 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6308 struct dwo_unit
*dwo_entry
;
6309 struct signatured_type find_sig_entry
, *sig_entry
;
6312 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6313 gdb_assert (dwp_file
!= NULL
);
6315 /* If TU skeletons have been removed then we may not have read in any
6317 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6318 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6320 find_sig_entry
.signature
= sig
;
6321 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6322 &find_sig_entry
, INSERT
);
6323 sig_entry
= (struct signatured_type
*) *slot
;
6325 /* Have we already tried to read this TU?
6326 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6327 needn't exist in the global table yet). */
6328 if (sig_entry
!= NULL
)
6331 if (dwp_file
->tus
== NULL
)
6333 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6334 sig
, 1 /* is_debug_types */);
6335 if (dwo_entry
== NULL
)
6338 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6339 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6344 /* Lookup a signature based type for DW_FORM_ref_sig8.
6345 Returns NULL if signature SIG is not present in the table.
6346 It is up to the caller to complain about this. */
6348 static struct signatured_type
*
6349 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6351 struct dwarf2_per_objfile
*dwarf2_per_objfile
6352 = cu
->per_cu
->dwarf2_per_objfile
;
6355 && dwarf2_per_objfile
->using_index
)
6357 /* We're in a DWO/DWP file, and we're using .gdb_index.
6358 These cases require special processing. */
6359 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6360 return lookup_dwo_signatured_type (cu
, sig
);
6362 return lookup_dwp_signatured_type (cu
, sig
);
6366 struct signatured_type find_entry
, *entry
;
6368 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6370 find_entry
.signature
= sig
;
6371 entry
= ((struct signatured_type
*)
6372 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6378 /* Low level DIE reading support. */
6380 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6383 init_cu_die_reader (struct die_reader_specs
*reader
,
6384 struct dwarf2_cu
*cu
,
6385 struct dwarf2_section_info
*section
,
6386 struct dwo_file
*dwo_file
,
6387 struct abbrev_table
*abbrev_table
)
6389 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6390 reader
->abfd
= section
->get_bfd_owner ();
6392 reader
->dwo_file
= dwo_file
;
6393 reader
->die_section
= section
;
6394 reader
->buffer
= section
->buffer
;
6395 reader
->buffer_end
= section
->buffer
+ section
->size
;
6396 reader
->abbrev_table
= abbrev_table
;
6399 /* Subroutine of cutu_reader to simplify it.
6400 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6401 There's just a lot of work to do, and cutu_reader is big enough
6404 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6405 from it to the DIE in the DWO. If NULL we are skipping the stub.
6406 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6407 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6408 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6409 STUB_COMP_DIR may be non-NULL.
6410 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6411 are filled in with the info of the DIE from the DWO file.
6412 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6413 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6414 kept around for at least as long as *RESULT_READER.
6416 The result is non-zero if a valid (non-dummy) DIE was found. */
6419 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6420 struct dwo_unit
*dwo_unit
,
6421 struct die_info
*stub_comp_unit_die
,
6422 const char *stub_comp_dir
,
6423 struct die_reader_specs
*result_reader
,
6424 const gdb_byte
**result_info_ptr
,
6425 struct die_info
**result_comp_unit_die
,
6426 abbrev_table_up
*result_dwo_abbrev_table
)
6428 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6429 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6430 struct dwarf2_cu
*cu
= this_cu
->cu
;
6432 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6433 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6434 int i
,num_extra_attrs
;
6435 struct dwarf2_section_info
*dwo_abbrev_section
;
6436 struct die_info
*comp_unit_die
;
6438 /* At most one of these may be provided. */
6439 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6441 /* These attributes aren't processed until later:
6442 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6443 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6444 referenced later. However, these attributes are found in the stub
6445 which we won't have later. In order to not impose this complication
6446 on the rest of the code, we read them here and copy them to the
6455 if (stub_comp_unit_die
!= NULL
)
6457 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6459 if (! this_cu
->is_debug_types
)
6460 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6461 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6462 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6463 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6464 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6466 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6468 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6469 here (if needed). We need the value before we can process
6471 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6473 else if (stub_comp_dir
!= NULL
)
6475 /* Reconstruct the comp_dir attribute to simplify the code below. */
6476 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6477 comp_dir
->name
= DW_AT_comp_dir
;
6478 comp_dir
->form
= DW_FORM_string
;
6479 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6480 DW_STRING (comp_dir
) = stub_comp_dir
;
6483 /* Set up for reading the DWO CU/TU. */
6484 cu
->dwo_unit
= dwo_unit
;
6485 dwarf2_section_info
*section
= dwo_unit
->section
;
6486 section
->read (objfile
);
6487 abfd
= section
->get_bfd_owner ();
6488 begin_info_ptr
= info_ptr
= (section
->buffer
6489 + to_underlying (dwo_unit
->sect_off
));
6490 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6492 if (this_cu
->is_debug_types
)
6494 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6496 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6497 &cu
->header
, section
,
6499 info_ptr
, rcuh_kind::TYPE
);
6500 /* This is not an assert because it can be caused by bad debug info. */
6501 if (sig_type
->signature
!= cu
->header
.signature
)
6503 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6504 " TU at offset %s [in module %s]"),
6505 hex_string (sig_type
->signature
),
6506 hex_string (cu
->header
.signature
),
6507 sect_offset_str (dwo_unit
->sect_off
),
6508 bfd_get_filename (abfd
));
6510 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6511 /* For DWOs coming from DWP files, we don't know the CU length
6512 nor the type's offset in the TU until now. */
6513 dwo_unit
->length
= cu
->header
.get_length ();
6514 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6516 /* Establish the type offset that can be used to lookup the type.
6517 For DWO files, we don't know it until now. */
6518 sig_type
->type_offset_in_section
6519 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6523 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6524 &cu
->header
, section
,
6526 info_ptr
, rcuh_kind::COMPILE
);
6527 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6528 /* For DWOs coming from DWP files, we don't know the CU length
6530 dwo_unit
->length
= cu
->header
.get_length ();
6533 *result_dwo_abbrev_table
6534 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6535 cu
->header
.abbrev_sect_off
);
6536 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6537 result_dwo_abbrev_table
->get ());
6539 /* Read in the die, but leave space to copy over the attributes
6540 from the stub. This has the benefit of simplifying the rest of
6541 the code - all the work to maintain the illusion of a single
6542 DW_TAG_{compile,type}_unit DIE is done here. */
6543 num_extra_attrs
= ((stmt_list
!= NULL
)
6547 + (comp_dir
!= NULL
));
6548 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6551 /* Copy over the attributes from the stub to the DIE we just read in. */
6552 comp_unit_die
= *result_comp_unit_die
;
6553 i
= comp_unit_die
->num_attrs
;
6554 if (stmt_list
!= NULL
)
6555 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6557 comp_unit_die
->attrs
[i
++] = *low_pc
;
6558 if (high_pc
!= NULL
)
6559 comp_unit_die
->attrs
[i
++] = *high_pc
;
6561 comp_unit_die
->attrs
[i
++] = *ranges
;
6562 if (comp_dir
!= NULL
)
6563 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6564 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6566 if (dwarf_die_debug
)
6568 fprintf_unfiltered (gdb_stdlog
,
6569 "Read die from %s@0x%x of %s:\n",
6570 section
->get_name (),
6571 (unsigned) (begin_info_ptr
- section
->buffer
),
6572 bfd_get_filename (abfd
));
6573 dump_die (comp_unit_die
, dwarf_die_debug
);
6576 /* Skip dummy compilation units. */
6577 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6578 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6581 *result_info_ptr
= info_ptr
;
6585 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6586 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6587 signature is part of the header. */
6588 static gdb::optional
<ULONGEST
>
6589 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6591 if (cu
->header
.version
>= 5)
6592 return cu
->header
.signature
;
6593 struct attribute
*attr
;
6594 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6595 if (attr
== nullptr)
6596 return gdb::optional
<ULONGEST
> ();
6597 return DW_UNSND (attr
);
6600 /* Subroutine of cutu_reader to simplify it.
6601 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6602 Returns NULL if the specified DWO unit cannot be found. */
6604 static struct dwo_unit
*
6605 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6606 struct die_info
*comp_unit_die
,
6607 const char *dwo_name
)
6609 struct dwarf2_cu
*cu
= this_cu
->cu
;
6610 struct dwo_unit
*dwo_unit
;
6611 const char *comp_dir
;
6613 gdb_assert (cu
!= NULL
);
6615 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6616 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6617 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6619 if (this_cu
->is_debug_types
)
6621 struct signatured_type
*sig_type
;
6623 /* Since this_cu is the first member of struct signatured_type,
6624 we can go from a pointer to one to a pointer to the other. */
6625 sig_type
= (struct signatured_type
*) this_cu
;
6626 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6630 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6631 if (!signature
.has_value ())
6632 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6634 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6635 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6642 /* Subroutine of cutu_reader to simplify it.
6643 See it for a description of the parameters.
6644 Read a TU directly from a DWO file, bypassing the stub. */
6647 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6648 int use_existing_cu
)
6650 struct signatured_type
*sig_type
;
6652 /* Verify we can do the following downcast, and that we have the
6654 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6655 sig_type
= (struct signatured_type
*) this_cu
;
6656 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6658 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6660 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6661 /* There's no need to do the rereading_dwo_cu handling that
6662 cutu_reader does since we don't read the stub. */
6666 /* If !use_existing_cu, this_cu->cu must be NULL. */
6667 gdb_assert (this_cu
->cu
== NULL
);
6668 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6671 /* A future optimization, if needed, would be to use an existing
6672 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6673 could share abbrev tables. */
6675 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6676 NULL
/* stub_comp_unit_die */,
6677 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6680 &m_dwo_abbrev_table
) == 0)
6687 /* Initialize a CU (or TU) and read its DIEs.
6688 If the CU defers to a DWO file, read the DWO file as well.
6690 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6691 Otherwise the table specified in the comp unit header is read in and used.
6692 This is an optimization for when we already have the abbrev table.
6694 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6695 Otherwise, a new CU is allocated with xmalloc. */
6697 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6698 struct abbrev_table
*abbrev_table
,
6699 int use_existing_cu
,
6701 : die_reader_specs
{},
6704 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6705 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6706 struct dwarf2_section_info
*section
= this_cu
->section
;
6707 bfd
*abfd
= section
->get_bfd_owner ();
6708 struct dwarf2_cu
*cu
;
6709 const gdb_byte
*begin_info_ptr
;
6710 struct signatured_type
*sig_type
= NULL
;
6711 struct dwarf2_section_info
*abbrev_section
;
6712 /* Non-zero if CU currently points to a DWO file and we need to
6713 reread it. When this happens we need to reread the skeleton die
6714 before we can reread the DWO file (this only applies to CUs, not TUs). */
6715 int rereading_dwo_cu
= 0;
6717 if (dwarf_die_debug
)
6718 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6719 this_cu
->is_debug_types
? "type" : "comp",
6720 sect_offset_str (this_cu
->sect_off
));
6722 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6723 file (instead of going through the stub), short-circuit all of this. */
6724 if (this_cu
->reading_dwo_directly
)
6726 /* Narrow down the scope of possibilities to have to understand. */
6727 gdb_assert (this_cu
->is_debug_types
);
6728 gdb_assert (abbrev_table
== NULL
);
6729 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6733 /* This is cheap if the section is already read in. */
6734 section
->read (objfile
);
6736 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6738 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6740 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6743 /* If this CU is from a DWO file we need to start over, we need to
6744 refetch the attributes from the skeleton CU.
6745 This could be optimized by retrieving those attributes from when we
6746 were here the first time: the previous comp_unit_die was stored in
6747 comp_unit_obstack. But there's no data yet that we need this
6749 if (cu
->dwo_unit
!= NULL
)
6750 rereading_dwo_cu
= 1;
6754 /* If !use_existing_cu, this_cu->cu must be NULL. */
6755 gdb_assert (this_cu
->cu
== NULL
);
6756 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6757 cu
= m_new_cu
.get ();
6760 /* Get the header. */
6761 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6763 /* We already have the header, there's no need to read it in again. */
6764 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6768 if (this_cu
->is_debug_types
)
6770 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6771 &cu
->header
, section
,
6772 abbrev_section
, info_ptr
,
6775 /* Since per_cu is the first member of struct signatured_type,
6776 we can go from a pointer to one to a pointer to the other. */
6777 sig_type
= (struct signatured_type
*) this_cu
;
6778 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6779 gdb_assert (sig_type
->type_offset_in_tu
6780 == cu
->header
.type_cu_offset_in_tu
);
6781 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6783 /* LENGTH has not been set yet for type units if we're
6784 using .gdb_index. */
6785 this_cu
->length
= cu
->header
.get_length ();
6787 /* Establish the type offset that can be used to lookup the type. */
6788 sig_type
->type_offset_in_section
=
6789 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6791 this_cu
->dwarf_version
= cu
->header
.version
;
6795 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6796 &cu
->header
, section
,
6799 rcuh_kind::COMPILE
);
6801 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6802 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6803 this_cu
->dwarf_version
= cu
->header
.version
;
6807 /* Skip dummy compilation units. */
6808 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6809 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6815 /* If we don't have them yet, read the abbrevs for this compilation unit.
6816 And if we need to read them now, make sure they're freed when we're
6818 if (abbrev_table
!= NULL
)
6819 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6822 m_abbrev_table_holder
6823 = abbrev_table::read (objfile
, abbrev_section
,
6824 cu
->header
.abbrev_sect_off
);
6825 abbrev_table
= m_abbrev_table_holder
.get ();
6828 /* Read the top level CU/TU die. */
6829 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6830 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6832 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6838 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6839 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6840 table from the DWO file and pass the ownership over to us. It will be
6841 referenced from READER, so we must make sure to free it after we're done
6844 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6845 DWO CU, that this test will fail (the attribute will not be present). */
6846 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6847 if (dwo_name
!= nullptr)
6849 struct dwo_unit
*dwo_unit
;
6850 struct die_info
*dwo_comp_unit_die
;
6852 if (comp_unit_die
->has_children
)
6854 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6855 " has children (offset %s) [in module %s]"),
6856 sect_offset_str (this_cu
->sect_off
),
6857 bfd_get_filename (abfd
));
6859 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6860 if (dwo_unit
!= NULL
)
6862 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6863 comp_unit_die
, NULL
,
6866 &m_dwo_abbrev_table
) == 0)
6872 comp_unit_die
= dwo_comp_unit_die
;
6876 /* Yikes, we couldn't find the rest of the DIE, we only have
6877 the stub. A complaint has already been logged. There's
6878 not much more we can do except pass on the stub DIE to
6879 die_reader_func. We don't want to throw an error on bad
6886 cutu_reader::keep ()
6888 /* Done, clean up. */
6889 gdb_assert (!dummy_p
);
6890 if (m_new_cu
!= NULL
)
6892 struct dwarf2_per_objfile
*dwarf2_per_objfile
6893 = m_this_cu
->dwarf2_per_objfile
;
6894 /* Link this CU into read_in_chain. */
6895 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6896 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6897 /* The chain owns it now. */
6898 m_new_cu
.release ();
6902 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6903 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6904 assumed to have already done the lookup to find the DWO file).
6906 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6907 THIS_CU->is_debug_types, but nothing else.
6909 We fill in THIS_CU->length.
6911 THIS_CU->cu is always freed when done.
6912 This is done in order to not leave THIS_CU->cu in a state where we have
6913 to care whether it refers to the "main" CU or the DWO CU.
6915 When parent_cu is passed, it is used to provide a default value for
6916 str_offsets_base and addr_base from the parent. */
6918 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6919 struct dwarf2_cu
*parent_cu
,
6920 struct dwo_file
*dwo_file
)
6921 : die_reader_specs
{},
6924 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6925 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6926 struct dwarf2_section_info
*section
= this_cu
->section
;
6927 bfd
*abfd
= section
->get_bfd_owner ();
6928 struct dwarf2_section_info
*abbrev_section
;
6929 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6931 if (dwarf_die_debug
)
6932 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6933 this_cu
->is_debug_types
? "type" : "comp",
6934 sect_offset_str (this_cu
->sect_off
));
6936 gdb_assert (this_cu
->cu
== NULL
);
6938 abbrev_section
= (dwo_file
!= NULL
6939 ? &dwo_file
->sections
.abbrev
6940 : get_abbrev_section_for_cu (this_cu
));
6942 /* This is cheap if the section is already read in. */
6943 section
->read (objfile
);
6945 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6947 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6948 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6949 &m_new_cu
->header
, section
,
6950 abbrev_section
, info_ptr
,
6951 (this_cu
->is_debug_types
6953 : rcuh_kind::COMPILE
));
6955 if (parent_cu
!= nullptr)
6957 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6958 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6960 this_cu
->length
= m_new_cu
->header
.get_length ();
6962 /* Skip dummy compilation units. */
6963 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6964 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6970 m_abbrev_table_holder
6971 = abbrev_table::read (objfile
, abbrev_section
,
6972 m_new_cu
->header
.abbrev_sect_off
);
6974 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6975 m_abbrev_table_holder
.get ());
6976 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6980 /* Type Unit Groups.
6982 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6983 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6984 so that all types coming from the same compilation (.o file) are grouped
6985 together. A future step could be to put the types in the same symtab as
6986 the CU the types ultimately came from. */
6989 hash_type_unit_group (const void *item
)
6991 const struct type_unit_group
*tu_group
6992 = (const struct type_unit_group
*) item
;
6994 return hash_stmt_list_entry (&tu_group
->hash
);
6998 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7000 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7001 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7003 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7006 /* Allocate a hash table for type unit groups. */
7009 allocate_type_unit_groups_table ()
7011 return htab_up (htab_create_alloc (3,
7012 hash_type_unit_group
,
7014 NULL
, xcalloc
, xfree
));
7017 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7018 partial symtabs. We combine several TUs per psymtab to not let the size
7019 of any one psymtab grow too big. */
7020 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7021 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7023 /* Helper routine for get_type_unit_group.
7024 Create the type_unit_group object used to hold one or more TUs. */
7026 static struct type_unit_group
*
7027 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7029 struct dwarf2_per_objfile
*dwarf2_per_objfile
7030 = cu
->per_cu
->dwarf2_per_objfile
;
7031 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7032 struct dwarf2_per_cu_data
*per_cu
;
7033 struct type_unit_group
*tu_group
;
7035 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7036 struct type_unit_group
);
7037 per_cu
= &tu_group
->per_cu
;
7038 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7040 if (dwarf2_per_objfile
->using_index
)
7042 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7043 struct dwarf2_per_cu_quick_data
);
7047 unsigned int line_offset
= to_underlying (line_offset_struct
);
7048 dwarf2_psymtab
*pst
;
7051 /* Give the symtab a useful name for debug purposes. */
7052 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7053 name
= string_printf ("<type_units_%d>",
7054 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7056 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7058 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7059 pst
->anonymous
= true;
7062 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7063 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7068 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7069 STMT_LIST is a DW_AT_stmt_list attribute. */
7071 static struct type_unit_group
*
7072 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7074 struct dwarf2_per_objfile
*dwarf2_per_objfile
7075 = cu
->per_cu
->dwarf2_per_objfile
;
7076 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7077 struct type_unit_group
*tu_group
;
7079 unsigned int line_offset
;
7080 struct type_unit_group type_unit_group_for_lookup
;
7082 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7083 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7085 /* Do we need to create a new group, or can we use an existing one? */
7089 line_offset
= DW_UNSND (stmt_list
);
7090 ++tu_stats
->nr_symtab_sharers
;
7094 /* Ugh, no stmt_list. Rare, but we have to handle it.
7095 We can do various things here like create one group per TU or
7096 spread them over multiple groups to split up the expansion work.
7097 To avoid worst case scenarios (too many groups or too large groups)
7098 we, umm, group them in bunches. */
7099 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7100 | (tu_stats
->nr_stmt_less_type_units
7101 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7102 ++tu_stats
->nr_stmt_less_type_units
;
7105 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7106 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7107 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7108 &type_unit_group_for_lookup
, INSERT
);
7111 tu_group
= (struct type_unit_group
*) *slot
;
7112 gdb_assert (tu_group
!= NULL
);
7116 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7117 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7119 ++tu_stats
->nr_symtabs
;
7125 /* Partial symbol tables. */
7127 /* Create a psymtab named NAME and assign it to PER_CU.
7129 The caller must fill in the following details:
7130 dirname, textlow, texthigh. */
7132 static dwarf2_psymtab
*
7133 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7135 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7136 dwarf2_psymtab
*pst
;
7138 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7140 pst
->psymtabs_addrmap_supported
= true;
7142 /* This is the glue that links PST into GDB's symbol API. */
7143 pst
->per_cu_data
= per_cu
;
7144 per_cu
->v
.psymtab
= pst
;
7149 /* DIE reader function for process_psymtab_comp_unit. */
7152 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7153 const gdb_byte
*info_ptr
,
7154 struct die_info
*comp_unit_die
,
7155 enum language pretend_language
)
7157 struct dwarf2_cu
*cu
= reader
->cu
;
7158 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7159 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7160 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7162 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7163 dwarf2_psymtab
*pst
;
7164 enum pc_bounds_kind cu_bounds_kind
;
7165 const char *filename
;
7167 gdb_assert (! per_cu
->is_debug_types
);
7169 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7171 /* Allocate a new partial symbol table structure. */
7172 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7173 static const char artificial
[] = "<artificial>";
7174 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7175 if (filename
== NULL
)
7177 else if (strcmp (filename
, artificial
) == 0)
7179 debug_filename
.reset (concat (artificial
, "@",
7180 sect_offset_str (per_cu
->sect_off
),
7182 filename
= debug_filename
.get ();
7185 pst
= create_partial_symtab (per_cu
, filename
);
7187 /* This must be done before calling dwarf2_build_include_psymtabs. */
7188 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7190 baseaddr
= objfile
->text_section_offset ();
7192 dwarf2_find_base_address (comp_unit_die
, cu
);
7194 /* Possibly set the default values of LOWPC and HIGHPC from
7196 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7197 &best_highpc
, cu
, pst
);
7198 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7201 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7204 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7206 /* Store the contiguous range if it is not empty; it can be
7207 empty for CUs with no code. */
7208 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7212 /* Check if comp unit has_children.
7213 If so, read the rest of the partial symbols from this comp unit.
7214 If not, there's no more debug_info for this comp unit. */
7215 if (comp_unit_die
->has_children
)
7217 struct partial_die_info
*first_die
;
7218 CORE_ADDR lowpc
, highpc
;
7220 lowpc
= ((CORE_ADDR
) -1);
7221 highpc
= ((CORE_ADDR
) 0);
7223 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7225 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7226 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7228 /* If we didn't find a lowpc, set it to highpc to avoid
7229 complaints from `maint check'. */
7230 if (lowpc
== ((CORE_ADDR
) -1))
7233 /* If the compilation unit didn't have an explicit address range,
7234 then use the information extracted from its child dies. */
7235 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7238 best_highpc
= highpc
;
7241 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7242 best_lowpc
+ baseaddr
)
7244 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7245 best_highpc
+ baseaddr
)
7248 end_psymtab_common (objfile
, pst
);
7250 if (!cu
->per_cu
->imported_symtabs_empty ())
7253 int len
= cu
->per_cu
->imported_symtabs_size ();
7255 /* Fill in 'dependencies' here; we fill in 'users' in a
7257 pst
->number_of_dependencies
= len
;
7259 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7260 for (i
= 0; i
< len
; ++i
)
7262 pst
->dependencies
[i
]
7263 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7266 cu
->per_cu
->imported_symtabs_free ();
7269 /* Get the list of files included in the current compilation unit,
7270 and build a psymtab for each of them. */
7271 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7273 if (dwarf_read_debug
)
7274 fprintf_unfiltered (gdb_stdlog
,
7275 "Psymtab for %s unit @%s: %s - %s"
7276 ", %d global, %d static syms\n",
7277 per_cu
->is_debug_types
? "type" : "comp",
7278 sect_offset_str (per_cu
->sect_off
),
7279 paddress (gdbarch
, pst
->text_low (objfile
)),
7280 paddress (gdbarch
, pst
->text_high (objfile
)),
7281 pst
->n_global_syms
, pst
->n_static_syms
);
7284 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7285 Process compilation unit THIS_CU for a psymtab. */
7288 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7289 bool want_partial_unit
,
7290 enum language pretend_language
)
7292 /* If this compilation unit was already read in, free the
7293 cached copy in order to read it in again. This is
7294 necessary because we skipped some symbols when we first
7295 read in the compilation unit (see load_partial_dies).
7296 This problem could be avoided, but the benefit is unclear. */
7297 if (this_cu
->cu
!= NULL
)
7298 free_one_cached_comp_unit (this_cu
);
7300 cutu_reader
reader (this_cu
, NULL
, 0, false);
7302 switch (reader
.comp_unit_die
->tag
)
7304 case DW_TAG_compile_unit
:
7305 this_cu
->unit_type
= DW_UT_compile
;
7307 case DW_TAG_partial_unit
:
7308 this_cu
->unit_type
= DW_UT_partial
;
7318 else if (this_cu
->is_debug_types
)
7319 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7320 reader
.comp_unit_die
);
7321 else if (want_partial_unit
7322 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7323 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7324 reader
.comp_unit_die
,
7327 this_cu
->lang
= this_cu
->cu
->language
;
7329 /* Age out any secondary CUs. */
7330 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7333 /* Reader function for build_type_psymtabs. */
7336 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7337 const gdb_byte
*info_ptr
,
7338 struct die_info
*type_unit_die
)
7340 struct dwarf2_per_objfile
*dwarf2_per_objfile
7341 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7342 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7343 struct dwarf2_cu
*cu
= reader
->cu
;
7344 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7345 struct signatured_type
*sig_type
;
7346 struct type_unit_group
*tu_group
;
7347 struct attribute
*attr
;
7348 struct partial_die_info
*first_die
;
7349 CORE_ADDR lowpc
, highpc
;
7350 dwarf2_psymtab
*pst
;
7352 gdb_assert (per_cu
->is_debug_types
);
7353 sig_type
= (struct signatured_type
*) per_cu
;
7355 if (! type_unit_die
->has_children
)
7358 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7359 tu_group
= get_type_unit_group (cu
, attr
);
7361 if (tu_group
->tus
== nullptr)
7362 tu_group
->tus
= new std::vector
<signatured_type
*>;
7363 tu_group
->tus
->push_back (sig_type
);
7365 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7366 pst
= create_partial_symtab (per_cu
, "");
7367 pst
->anonymous
= true;
7369 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7371 lowpc
= (CORE_ADDR
) -1;
7372 highpc
= (CORE_ADDR
) 0;
7373 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7375 end_psymtab_common (objfile
, pst
);
7378 /* Struct used to sort TUs by their abbreviation table offset. */
7380 struct tu_abbrev_offset
7382 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7383 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7386 signatured_type
*sig_type
;
7387 sect_offset abbrev_offset
;
7390 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7393 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7394 const struct tu_abbrev_offset
&b
)
7396 return a
.abbrev_offset
< b
.abbrev_offset
;
7399 /* Efficiently read all the type units.
7400 This does the bulk of the work for build_type_psymtabs.
7402 The efficiency is because we sort TUs by the abbrev table they use and
7403 only read each abbrev table once. In one program there are 200K TUs
7404 sharing 8K abbrev tables.
7406 The main purpose of this function is to support building the
7407 dwarf2_per_objfile->type_unit_groups table.
7408 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7409 can collapse the search space by grouping them by stmt_list.
7410 The savings can be significant, in the same program from above the 200K TUs
7411 share 8K stmt_list tables.
7413 FUNC is expected to call get_type_unit_group, which will create the
7414 struct type_unit_group if necessary and add it to
7415 dwarf2_per_objfile->type_unit_groups. */
7418 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7420 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7421 abbrev_table_up abbrev_table
;
7422 sect_offset abbrev_offset
;
7424 /* It's up to the caller to not call us multiple times. */
7425 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7427 if (dwarf2_per_objfile
->all_type_units
.empty ())
7430 /* TUs typically share abbrev tables, and there can be way more TUs than
7431 abbrev tables. Sort by abbrev table to reduce the number of times we
7432 read each abbrev table in.
7433 Alternatives are to punt or to maintain a cache of abbrev tables.
7434 This is simpler and efficient enough for now.
7436 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7437 symtab to use). Typically TUs with the same abbrev offset have the same
7438 stmt_list value too so in practice this should work well.
7440 The basic algorithm here is:
7442 sort TUs by abbrev table
7443 for each TU with same abbrev table:
7444 read abbrev table if first user
7445 read TU top level DIE
7446 [IWBN if DWO skeletons had DW_AT_stmt_list]
7449 if (dwarf_read_debug
)
7450 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7452 /* Sort in a separate table to maintain the order of all_type_units
7453 for .gdb_index: TU indices directly index all_type_units. */
7454 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7455 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7457 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7458 sorted_by_abbrev
.emplace_back
7459 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7460 sig_type
->per_cu
.section
,
7461 sig_type
->per_cu
.sect_off
));
7463 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7464 sort_tu_by_abbrev_offset
);
7466 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7468 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7470 /* Switch to the next abbrev table if necessary. */
7471 if (abbrev_table
== NULL
7472 || tu
.abbrev_offset
!= abbrev_offset
)
7474 abbrev_offset
= tu
.abbrev_offset
;
7476 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7477 &dwarf2_per_objfile
->abbrev
,
7479 ++tu_stats
->nr_uniq_abbrev_tables
;
7482 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7484 if (!reader
.dummy_p
)
7485 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7486 reader
.comp_unit_die
);
7490 /* Print collected type unit statistics. */
7493 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7495 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7497 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7498 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7499 dwarf2_per_objfile
->all_type_units
.size ());
7500 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7501 tu_stats
->nr_uniq_abbrev_tables
);
7502 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7503 tu_stats
->nr_symtabs
);
7504 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7505 tu_stats
->nr_symtab_sharers
);
7506 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7507 tu_stats
->nr_stmt_less_type_units
);
7508 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7509 tu_stats
->nr_all_type_units_reallocs
);
7512 /* Traversal function for build_type_psymtabs. */
7515 build_type_psymtab_dependencies (void **slot
, void *info
)
7517 struct dwarf2_per_objfile
*dwarf2_per_objfile
7518 = (struct dwarf2_per_objfile
*) info
;
7519 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7520 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7521 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7522 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7523 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7526 gdb_assert (len
> 0);
7527 gdb_assert (per_cu
->type_unit_group_p ());
7529 pst
->number_of_dependencies
= len
;
7530 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7531 for (i
= 0; i
< len
; ++i
)
7533 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7534 gdb_assert (iter
->per_cu
.is_debug_types
);
7535 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7536 iter
->type_unit_group
= tu_group
;
7539 delete tu_group
->tus
;
7540 tu_group
->tus
= nullptr;
7545 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7546 Build partial symbol tables for the .debug_types comp-units. */
7549 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7551 if (! create_all_type_units (dwarf2_per_objfile
))
7554 build_type_psymtabs_1 (dwarf2_per_objfile
);
7557 /* Traversal function for process_skeletonless_type_unit.
7558 Read a TU in a DWO file and build partial symbols for it. */
7561 process_skeletonless_type_unit (void **slot
, void *info
)
7563 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7564 struct dwarf2_per_objfile
*dwarf2_per_objfile
7565 = (struct dwarf2_per_objfile
*) info
;
7566 struct signatured_type find_entry
, *entry
;
7568 /* If this TU doesn't exist in the global table, add it and read it in. */
7570 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7571 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7573 find_entry
.signature
= dwo_unit
->signature
;
7574 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7575 &find_entry
, INSERT
);
7576 /* If we've already seen this type there's nothing to do. What's happening
7577 is we're doing our own version of comdat-folding here. */
7581 /* This does the job that create_all_type_units would have done for
7583 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7584 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7587 /* This does the job that build_type_psymtabs_1 would have done. */
7588 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7589 if (!reader
.dummy_p
)
7590 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7591 reader
.comp_unit_die
);
7596 /* Traversal function for process_skeletonless_type_units. */
7599 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7601 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7603 if (dwo_file
->tus
!= NULL
)
7604 htab_traverse_noresize (dwo_file
->tus
.get (),
7605 process_skeletonless_type_unit
, info
);
7610 /* Scan all TUs of DWO files, verifying we've processed them.
7611 This is needed in case a TU was emitted without its skeleton.
7612 Note: This can't be done until we know what all the DWO files are. */
7615 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7617 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7618 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7619 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7621 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7622 process_dwo_file_for_skeletonless_type_units
,
7623 dwarf2_per_objfile
);
7627 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7630 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7632 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7634 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7639 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7641 /* Set the 'user' field only if it is not already set. */
7642 if (pst
->dependencies
[j
]->user
== NULL
)
7643 pst
->dependencies
[j
]->user
= pst
;
7648 /* Build the partial symbol table by doing a quick pass through the
7649 .debug_info and .debug_abbrev sections. */
7652 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7656 if (dwarf_read_debug
)
7658 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7659 objfile_name (objfile
));
7662 scoped_restore restore_reading_psyms
7663 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7666 dwarf2_per_objfile
->info
.read (objfile
);
7668 /* Any cached compilation units will be linked by the per-objfile
7669 read_in_chain. Make sure to free them when we're done. */
7670 free_cached_comp_units
freer (dwarf2_per_objfile
);
7672 build_type_psymtabs (dwarf2_per_objfile
);
7674 create_all_comp_units (dwarf2_per_objfile
);
7676 /* Create a temporary address map on a temporary obstack. We later
7677 copy this to the final obstack. */
7678 auto_obstack temp_obstack
;
7680 scoped_restore save_psymtabs_addrmap
7681 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7682 addrmap_create_mutable (&temp_obstack
));
7684 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7685 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7687 /* This has to wait until we read the CUs, we need the list of DWOs. */
7688 process_skeletonless_type_units (dwarf2_per_objfile
);
7690 /* Now that all TUs have been processed we can fill in the dependencies. */
7691 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7693 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7694 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7697 if (dwarf_read_debug
)
7698 print_tu_stats (dwarf2_per_objfile
);
7700 set_partial_user (dwarf2_per_objfile
);
7702 objfile
->partial_symtabs
->psymtabs_addrmap
7703 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7704 objfile
->partial_symtabs
->obstack ());
7705 /* At this point we want to keep the address map. */
7706 save_psymtabs_addrmap
.release ();
7708 if (dwarf_read_debug
)
7709 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7710 objfile_name (objfile
));
7713 /* Load the partial DIEs for a secondary CU into memory.
7714 This is also used when rereading a primary CU with load_all_dies. */
7717 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7719 cutu_reader
reader (this_cu
, NULL
, 1, false);
7721 if (!reader
.dummy_p
)
7723 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7726 /* Check if comp unit has_children.
7727 If so, read the rest of the partial symbols from this comp unit.
7728 If not, there's no more debug_info for this comp unit. */
7729 if (reader
.comp_unit_die
->has_children
)
7730 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7737 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7738 struct dwarf2_section_info
*section
,
7739 struct dwarf2_section_info
*abbrev_section
,
7740 unsigned int is_dwz
)
7742 const gdb_byte
*info_ptr
;
7743 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7745 if (dwarf_read_debug
)
7746 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7747 section
->get_name (),
7748 section
->get_file_name ());
7750 section
->read (objfile
);
7752 info_ptr
= section
->buffer
;
7754 while (info_ptr
< section
->buffer
+ section
->size
)
7756 struct dwarf2_per_cu_data
*this_cu
;
7758 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7760 comp_unit_head cu_header
;
7761 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7762 abbrev_section
, info_ptr
,
7763 rcuh_kind::COMPILE
);
7765 /* Save the compilation unit for later lookup. */
7766 if (cu_header
.unit_type
!= DW_UT_type
)
7768 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7769 struct dwarf2_per_cu_data
);
7770 memset (this_cu
, 0, sizeof (*this_cu
));
7774 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7775 struct signatured_type
);
7776 memset (sig_type
, 0, sizeof (*sig_type
));
7777 sig_type
->signature
= cu_header
.signature
;
7778 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7779 this_cu
= &sig_type
->per_cu
;
7781 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7782 this_cu
->sect_off
= sect_off
;
7783 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7784 this_cu
->is_dwz
= is_dwz
;
7785 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7786 this_cu
->section
= section
;
7788 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7790 info_ptr
= info_ptr
+ this_cu
->length
;
7794 /* Create a list of all compilation units in OBJFILE.
7795 This is only done for -readnow and building partial symtabs. */
7798 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7800 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7801 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7802 &dwarf2_per_objfile
->abbrev
, 0);
7804 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7806 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7810 /* Process all loaded DIEs for compilation unit CU, starting at
7811 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7812 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7813 DW_AT_ranges). See the comments of add_partial_subprogram on how
7814 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7817 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7818 CORE_ADDR
*highpc
, int set_addrmap
,
7819 struct dwarf2_cu
*cu
)
7821 struct partial_die_info
*pdi
;
7823 /* Now, march along the PDI's, descending into ones which have
7824 interesting children but skipping the children of the other ones,
7825 until we reach the end of the compilation unit. */
7833 /* Anonymous namespaces or modules have no name but have interesting
7834 children, so we need to look at them. Ditto for anonymous
7837 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7838 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7839 || pdi
->tag
== DW_TAG_imported_unit
7840 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7844 case DW_TAG_subprogram
:
7845 case DW_TAG_inlined_subroutine
:
7846 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7848 case DW_TAG_constant
:
7849 case DW_TAG_variable
:
7850 case DW_TAG_typedef
:
7851 case DW_TAG_union_type
:
7852 if (!pdi
->is_declaration
)
7854 add_partial_symbol (pdi
, cu
);
7857 case DW_TAG_class_type
:
7858 case DW_TAG_interface_type
:
7859 case DW_TAG_structure_type
:
7860 if (!pdi
->is_declaration
)
7862 add_partial_symbol (pdi
, cu
);
7864 if ((cu
->language
== language_rust
7865 || cu
->language
== language_cplus
) && pdi
->has_children
)
7866 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7869 case DW_TAG_enumeration_type
:
7870 if (!pdi
->is_declaration
)
7871 add_partial_enumeration (pdi
, cu
);
7873 case DW_TAG_base_type
:
7874 case DW_TAG_subrange_type
:
7875 /* File scope base type definitions are added to the partial
7877 add_partial_symbol (pdi
, cu
);
7879 case DW_TAG_namespace
:
7880 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7883 if (!pdi
->is_declaration
)
7884 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7886 case DW_TAG_imported_unit
:
7888 struct dwarf2_per_cu_data
*per_cu
;
7890 /* For now we don't handle imported units in type units. */
7891 if (cu
->per_cu
->is_debug_types
)
7893 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7894 " supported in type units [in module %s]"),
7895 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7898 per_cu
= dwarf2_find_containing_comp_unit
7899 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7900 cu
->per_cu
->dwarf2_per_objfile
);
7902 /* Go read the partial unit, if needed. */
7903 if (per_cu
->v
.psymtab
== NULL
)
7904 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7906 cu
->per_cu
->imported_symtabs_push (per_cu
);
7909 case DW_TAG_imported_declaration
:
7910 add_partial_symbol (pdi
, cu
);
7917 /* If the die has a sibling, skip to the sibling. */
7919 pdi
= pdi
->die_sibling
;
7923 /* Functions used to compute the fully scoped name of a partial DIE.
7925 Normally, this is simple. For C++, the parent DIE's fully scoped
7926 name is concatenated with "::" and the partial DIE's name.
7927 Enumerators are an exception; they use the scope of their parent
7928 enumeration type, i.e. the name of the enumeration type is not
7929 prepended to the enumerator.
7931 There are two complexities. One is DW_AT_specification; in this
7932 case "parent" means the parent of the target of the specification,
7933 instead of the direct parent of the DIE. The other is compilers
7934 which do not emit DW_TAG_namespace; in this case we try to guess
7935 the fully qualified name of structure types from their members'
7936 linkage names. This must be done using the DIE's children rather
7937 than the children of any DW_AT_specification target. We only need
7938 to do this for structures at the top level, i.e. if the target of
7939 any DW_AT_specification (if any; otherwise the DIE itself) does not
7942 /* Compute the scope prefix associated with PDI's parent, in
7943 compilation unit CU. The result will be allocated on CU's
7944 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7945 field. NULL is returned if no prefix is necessary. */
7947 partial_die_parent_scope (struct partial_die_info
*pdi
,
7948 struct dwarf2_cu
*cu
)
7950 const char *grandparent_scope
;
7951 struct partial_die_info
*parent
, *real_pdi
;
7953 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7954 then this means the parent of the specification DIE. */
7957 while (real_pdi
->has_specification
)
7959 auto res
= find_partial_die (real_pdi
->spec_offset
,
7960 real_pdi
->spec_is_dwz
, cu
);
7965 parent
= real_pdi
->die_parent
;
7969 if (parent
->scope_set
)
7970 return parent
->scope
;
7974 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7976 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7977 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7978 Work around this problem here. */
7979 if (cu
->language
== language_cplus
7980 && parent
->tag
== DW_TAG_namespace
7981 && strcmp (parent
->name
, "::") == 0
7982 && grandparent_scope
== NULL
)
7984 parent
->scope
= NULL
;
7985 parent
->scope_set
= 1;
7989 /* Nested subroutines in Fortran get a prefix. */
7990 if (pdi
->tag
== DW_TAG_enumerator
)
7991 /* Enumerators should not get the name of the enumeration as a prefix. */
7992 parent
->scope
= grandparent_scope
;
7993 else if (parent
->tag
== DW_TAG_namespace
7994 || parent
->tag
== DW_TAG_module
7995 || parent
->tag
== DW_TAG_structure_type
7996 || parent
->tag
== DW_TAG_class_type
7997 || parent
->tag
== DW_TAG_interface_type
7998 || parent
->tag
== DW_TAG_union_type
7999 || parent
->tag
== DW_TAG_enumeration_type
8000 || (cu
->language
== language_fortran
8001 && parent
->tag
== DW_TAG_subprogram
8002 && pdi
->tag
== DW_TAG_subprogram
))
8004 if (grandparent_scope
== NULL
)
8005 parent
->scope
= parent
->name
;
8007 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8009 parent
->name
, 0, cu
);
8013 /* FIXME drow/2004-04-01: What should we be doing with
8014 function-local names? For partial symbols, we should probably be
8016 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8017 dwarf_tag_name (parent
->tag
),
8018 sect_offset_str (pdi
->sect_off
));
8019 parent
->scope
= grandparent_scope
;
8022 parent
->scope_set
= 1;
8023 return parent
->scope
;
8026 /* Return the fully scoped name associated with PDI, from compilation unit
8027 CU. The result will be allocated with malloc. */
8029 static gdb::unique_xmalloc_ptr
<char>
8030 partial_die_full_name (struct partial_die_info
*pdi
,
8031 struct dwarf2_cu
*cu
)
8033 const char *parent_scope
;
8035 /* If this is a template instantiation, we can not work out the
8036 template arguments from partial DIEs. So, unfortunately, we have
8037 to go through the full DIEs. At least any work we do building
8038 types here will be reused if full symbols are loaded later. */
8039 if (pdi
->has_template_arguments
)
8043 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8045 struct die_info
*die
;
8046 struct attribute attr
;
8047 struct dwarf2_cu
*ref_cu
= cu
;
8049 /* DW_FORM_ref_addr is using section offset. */
8050 attr
.name
= (enum dwarf_attribute
) 0;
8051 attr
.form
= DW_FORM_ref_addr
;
8052 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8053 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8055 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8059 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8060 if (parent_scope
== NULL
)
8063 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8068 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8070 struct dwarf2_per_objfile
*dwarf2_per_objfile
8071 = cu
->per_cu
->dwarf2_per_objfile
;
8072 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8073 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8075 const char *actual_name
= NULL
;
8078 baseaddr
= objfile
->text_section_offset ();
8080 gdb::unique_xmalloc_ptr
<char> built_actual_name
8081 = partial_die_full_name (pdi
, cu
);
8082 if (built_actual_name
!= NULL
)
8083 actual_name
= built_actual_name
.get ();
8085 if (actual_name
== NULL
)
8086 actual_name
= pdi
->name
;
8090 case DW_TAG_inlined_subroutine
:
8091 case DW_TAG_subprogram
:
8092 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8094 if (pdi
->is_external
8095 || cu
->language
== language_ada
8096 || (cu
->language
== language_fortran
8097 && pdi
->die_parent
!= NULL
8098 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8100 /* Normally, only "external" DIEs are part of the global scope.
8101 But in Ada and Fortran, we want to be able to access nested
8102 procedures globally. So all Ada and Fortran subprograms are
8103 stored in the global scope. */
8104 add_psymbol_to_list (actual_name
,
8105 built_actual_name
!= NULL
,
8106 VAR_DOMAIN
, LOC_BLOCK
,
8107 SECT_OFF_TEXT (objfile
),
8108 psymbol_placement::GLOBAL
,
8110 cu
->language
, objfile
);
8114 add_psymbol_to_list (actual_name
,
8115 built_actual_name
!= NULL
,
8116 VAR_DOMAIN
, LOC_BLOCK
,
8117 SECT_OFF_TEXT (objfile
),
8118 psymbol_placement::STATIC
,
8119 addr
, cu
->language
, objfile
);
8122 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8123 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8125 case DW_TAG_constant
:
8126 add_psymbol_to_list (actual_name
,
8127 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8128 -1, (pdi
->is_external
8129 ? psymbol_placement::GLOBAL
8130 : psymbol_placement::STATIC
),
8131 0, cu
->language
, objfile
);
8133 case DW_TAG_variable
:
8135 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8139 && !dwarf2_per_objfile
->has_section_at_zero
)
8141 /* A global or static variable may also have been stripped
8142 out by the linker if unused, in which case its address
8143 will be nullified; do not add such variables into partial
8144 symbol table then. */
8146 else if (pdi
->is_external
)
8149 Don't enter into the minimal symbol tables as there is
8150 a minimal symbol table entry from the ELF symbols already.
8151 Enter into partial symbol table if it has a location
8152 descriptor or a type.
8153 If the location descriptor is missing, new_symbol will create
8154 a LOC_UNRESOLVED symbol, the address of the variable will then
8155 be determined from the minimal symbol table whenever the variable
8157 The address for the partial symbol table entry is not
8158 used by GDB, but it comes in handy for debugging partial symbol
8161 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8162 add_psymbol_to_list (actual_name
,
8163 built_actual_name
!= NULL
,
8164 VAR_DOMAIN
, LOC_STATIC
,
8165 SECT_OFF_TEXT (objfile
),
8166 psymbol_placement::GLOBAL
,
8167 addr
, cu
->language
, objfile
);
8171 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8173 /* Static Variable. Skip symbols whose value we cannot know (those
8174 without location descriptors or constant values). */
8175 if (!has_loc
&& !pdi
->has_const_value
)
8178 add_psymbol_to_list (actual_name
,
8179 built_actual_name
!= NULL
,
8180 VAR_DOMAIN
, LOC_STATIC
,
8181 SECT_OFF_TEXT (objfile
),
8182 psymbol_placement::STATIC
,
8184 cu
->language
, objfile
);
8187 case DW_TAG_typedef
:
8188 case DW_TAG_base_type
:
8189 case DW_TAG_subrange_type
:
8190 add_psymbol_to_list (actual_name
,
8191 built_actual_name
!= NULL
,
8192 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8193 psymbol_placement::STATIC
,
8194 0, cu
->language
, objfile
);
8196 case DW_TAG_imported_declaration
:
8197 case DW_TAG_namespace
:
8198 add_psymbol_to_list (actual_name
,
8199 built_actual_name
!= NULL
,
8200 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8201 psymbol_placement::GLOBAL
,
8202 0, cu
->language
, objfile
);
8205 /* With Fortran 77 there might be a "BLOCK DATA" module
8206 available without any name. If so, we skip the module as it
8207 doesn't bring any value. */
8208 if (actual_name
!= nullptr)
8209 add_psymbol_to_list (actual_name
,
8210 built_actual_name
!= NULL
,
8211 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8212 psymbol_placement::GLOBAL
,
8213 0, cu
->language
, objfile
);
8215 case DW_TAG_class_type
:
8216 case DW_TAG_interface_type
:
8217 case DW_TAG_structure_type
:
8218 case DW_TAG_union_type
:
8219 case DW_TAG_enumeration_type
:
8220 /* Skip external references. The DWARF standard says in the section
8221 about "Structure, Union, and Class Type Entries": "An incomplete
8222 structure, union or class type is represented by a structure,
8223 union or class entry that does not have a byte size attribute
8224 and that has a DW_AT_declaration attribute." */
8225 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8228 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8229 static vs. global. */
8230 add_psymbol_to_list (actual_name
,
8231 built_actual_name
!= NULL
,
8232 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8233 cu
->language
== language_cplus
8234 ? psymbol_placement::GLOBAL
8235 : psymbol_placement::STATIC
,
8236 0, cu
->language
, objfile
);
8239 case DW_TAG_enumerator
:
8240 add_psymbol_to_list (actual_name
,
8241 built_actual_name
!= NULL
,
8242 VAR_DOMAIN
, LOC_CONST
, -1,
8243 cu
->language
== language_cplus
8244 ? psymbol_placement::GLOBAL
8245 : psymbol_placement::STATIC
,
8246 0, cu
->language
, objfile
);
8253 /* Read a partial die corresponding to a namespace; also, add a symbol
8254 corresponding to that namespace to the symbol table. NAMESPACE is
8255 the name of the enclosing namespace. */
8258 add_partial_namespace (struct partial_die_info
*pdi
,
8259 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8260 int set_addrmap
, struct dwarf2_cu
*cu
)
8262 /* Add a symbol for the namespace. */
8264 add_partial_symbol (pdi
, cu
);
8266 /* Now scan partial symbols in that namespace. */
8268 if (pdi
->has_children
)
8269 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8272 /* Read a partial die corresponding to a Fortran module. */
8275 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8276 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8278 /* Add a symbol for the namespace. */
8280 add_partial_symbol (pdi
, cu
);
8282 /* Now scan partial symbols in that module. */
8284 if (pdi
->has_children
)
8285 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8288 /* Read a partial die corresponding to a subprogram or an inlined
8289 subprogram and create a partial symbol for that subprogram.
8290 When the CU language allows it, this routine also defines a partial
8291 symbol for each nested subprogram that this subprogram contains.
8292 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8293 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8295 PDI may also be a lexical block, in which case we simply search
8296 recursively for subprograms defined inside that lexical block.
8297 Again, this is only performed when the CU language allows this
8298 type of definitions. */
8301 add_partial_subprogram (struct partial_die_info
*pdi
,
8302 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8303 int set_addrmap
, struct dwarf2_cu
*cu
)
8305 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8307 if (pdi
->has_pc_info
)
8309 if (pdi
->lowpc
< *lowpc
)
8310 *lowpc
= pdi
->lowpc
;
8311 if (pdi
->highpc
> *highpc
)
8312 *highpc
= pdi
->highpc
;
8315 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8316 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8318 CORE_ADDR this_highpc
;
8319 CORE_ADDR this_lowpc
;
8321 baseaddr
= objfile
->text_section_offset ();
8323 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8324 pdi
->lowpc
+ baseaddr
)
8327 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8328 pdi
->highpc
+ baseaddr
)
8330 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8331 this_lowpc
, this_highpc
- 1,
8332 cu
->per_cu
->v
.psymtab
);
8336 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8338 if (!pdi
->is_declaration
)
8339 /* Ignore subprogram DIEs that do not have a name, they are
8340 illegal. Do not emit a complaint at this point, we will
8341 do so when we convert this psymtab into a symtab. */
8343 add_partial_symbol (pdi
, cu
);
8347 if (! pdi
->has_children
)
8350 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8352 pdi
= pdi
->die_child
;
8356 if (pdi
->tag
== DW_TAG_subprogram
8357 || pdi
->tag
== DW_TAG_inlined_subroutine
8358 || pdi
->tag
== DW_TAG_lexical_block
)
8359 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8360 pdi
= pdi
->die_sibling
;
8365 /* Read a partial die corresponding to an enumeration type. */
8368 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8369 struct dwarf2_cu
*cu
)
8371 struct partial_die_info
*pdi
;
8373 if (enum_pdi
->name
!= NULL
)
8374 add_partial_symbol (enum_pdi
, cu
);
8376 pdi
= enum_pdi
->die_child
;
8379 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8380 complaint (_("malformed enumerator DIE ignored"));
8382 add_partial_symbol (pdi
, cu
);
8383 pdi
= pdi
->die_sibling
;
8387 /* Return the initial uleb128 in the die at INFO_PTR. */
8390 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8392 unsigned int bytes_read
;
8394 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8397 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8398 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8400 Return the corresponding abbrev, or NULL if the number is zero (indicating
8401 an empty DIE). In either case *BYTES_READ will be set to the length of
8402 the initial number. */
8404 static struct abbrev_info
*
8405 peek_die_abbrev (const die_reader_specs
&reader
,
8406 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8408 dwarf2_cu
*cu
= reader
.cu
;
8409 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8410 unsigned int abbrev_number
8411 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8413 if (abbrev_number
== 0)
8416 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8419 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8420 " at offset %s [in module %s]"),
8421 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8422 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8428 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8429 Returns a pointer to the end of a series of DIEs, terminated by an empty
8430 DIE. Any children of the skipped DIEs will also be skipped. */
8432 static const gdb_byte
*
8433 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8437 unsigned int bytes_read
;
8438 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8441 return info_ptr
+ bytes_read
;
8443 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8447 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8448 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8449 abbrev corresponding to that skipped uleb128 should be passed in
8450 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8453 static const gdb_byte
*
8454 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8455 struct abbrev_info
*abbrev
)
8457 unsigned int bytes_read
;
8458 struct attribute attr
;
8459 bfd
*abfd
= reader
->abfd
;
8460 struct dwarf2_cu
*cu
= reader
->cu
;
8461 const gdb_byte
*buffer
= reader
->buffer
;
8462 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8463 unsigned int form
, i
;
8465 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8467 /* The only abbrev we care about is DW_AT_sibling. */
8468 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8471 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8473 if (attr
.form
== DW_FORM_ref_addr
)
8474 complaint (_("ignoring absolute DW_AT_sibling"));
8477 sect_offset off
= attr
.get_ref_die_offset ();
8478 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8480 if (sibling_ptr
< info_ptr
)
8481 complaint (_("DW_AT_sibling points backwards"));
8482 else if (sibling_ptr
> reader
->buffer_end
)
8483 reader
->die_section
->overflow_complaint ();
8489 /* If it isn't DW_AT_sibling, skip this attribute. */
8490 form
= abbrev
->attrs
[i
].form
;
8494 case DW_FORM_ref_addr
:
8495 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8496 and later it is offset sized. */
8497 if (cu
->header
.version
== 2)
8498 info_ptr
+= cu
->header
.addr_size
;
8500 info_ptr
+= cu
->header
.offset_size
;
8502 case DW_FORM_GNU_ref_alt
:
8503 info_ptr
+= cu
->header
.offset_size
;
8506 info_ptr
+= cu
->header
.addr_size
;
8514 case DW_FORM_flag_present
:
8515 case DW_FORM_implicit_const
:
8532 case DW_FORM_ref_sig8
:
8535 case DW_FORM_data16
:
8538 case DW_FORM_string
:
8539 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8540 info_ptr
+= bytes_read
;
8542 case DW_FORM_sec_offset
:
8544 case DW_FORM_GNU_strp_alt
:
8545 info_ptr
+= cu
->header
.offset_size
;
8547 case DW_FORM_exprloc
:
8549 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8550 info_ptr
+= bytes_read
;
8552 case DW_FORM_block1
:
8553 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8555 case DW_FORM_block2
:
8556 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8558 case DW_FORM_block4
:
8559 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8565 case DW_FORM_ref_udata
:
8566 case DW_FORM_GNU_addr_index
:
8567 case DW_FORM_GNU_str_index
:
8568 case DW_FORM_rnglistx
:
8569 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8571 case DW_FORM_indirect
:
8572 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8573 info_ptr
+= bytes_read
;
8574 /* We need to continue parsing from here, so just go back to
8576 goto skip_attribute
;
8579 error (_("Dwarf Error: Cannot handle %s "
8580 "in DWARF reader [in module %s]"),
8581 dwarf_form_name (form
),
8582 bfd_get_filename (abfd
));
8586 if (abbrev
->has_children
)
8587 return skip_children (reader
, info_ptr
);
8592 /* Locate ORIG_PDI's sibling.
8593 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8595 static const gdb_byte
*
8596 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8597 struct partial_die_info
*orig_pdi
,
8598 const gdb_byte
*info_ptr
)
8600 /* Do we know the sibling already? */
8602 if (orig_pdi
->sibling
)
8603 return orig_pdi
->sibling
;
8605 /* Are there any children to deal with? */
8607 if (!orig_pdi
->has_children
)
8610 /* Skip the children the long way. */
8612 return skip_children (reader
, info_ptr
);
8615 /* Expand this partial symbol table into a full symbol table. SELF is
8619 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8621 struct dwarf2_per_objfile
*dwarf2_per_objfile
8622 = get_dwarf2_per_objfile (objfile
);
8624 gdb_assert (!readin
);
8625 /* If this psymtab is constructed from a debug-only objfile, the
8626 has_section_at_zero flag will not necessarily be correct. We
8627 can get the correct value for this flag by looking at the data
8628 associated with the (presumably stripped) associated objfile. */
8629 if (objfile
->separate_debug_objfile_backlink
)
8631 struct dwarf2_per_objfile
*dpo_backlink
8632 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8634 dwarf2_per_objfile
->has_section_at_zero
8635 = dpo_backlink
->has_section_at_zero
;
8638 expand_psymtab (objfile
);
8640 process_cu_includes (dwarf2_per_objfile
);
8643 /* Reading in full CUs. */
8645 /* Add PER_CU to the queue. */
8648 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8649 enum language pretend_language
)
8652 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8655 /* If PER_CU is not yet queued, add it to the queue.
8656 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8658 The result is non-zero if PER_CU was queued, otherwise the result is zero
8659 meaning either PER_CU is already queued or it is already loaded.
8661 N.B. There is an invariant here that if a CU is queued then it is loaded.
8662 The caller is required to load PER_CU if we return non-zero. */
8665 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8666 struct dwarf2_per_cu_data
*per_cu
,
8667 enum language pretend_language
)
8669 /* We may arrive here during partial symbol reading, if we need full
8670 DIEs to process an unusual case (e.g. template arguments). Do
8671 not queue PER_CU, just tell our caller to load its DIEs. */
8672 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8674 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8679 /* Mark the dependence relation so that we don't flush PER_CU
8681 if (dependent_cu
!= NULL
)
8682 dwarf2_add_dependence (dependent_cu
, per_cu
);
8684 /* If it's already on the queue, we have nothing to do. */
8688 /* If the compilation unit is already loaded, just mark it as
8690 if (per_cu
->cu
!= NULL
)
8692 per_cu
->cu
->last_used
= 0;
8696 /* Add it to the queue. */
8697 queue_comp_unit (per_cu
, pretend_language
);
8702 /* Process the queue. */
8705 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8707 if (dwarf_read_debug
)
8709 fprintf_unfiltered (gdb_stdlog
,
8710 "Expanding one or more symtabs of objfile %s ...\n",
8711 objfile_name (dwarf2_per_objfile
->objfile
));
8714 /* The queue starts out with one item, but following a DIE reference
8715 may load a new CU, adding it to the end of the queue. */
8716 while (!dwarf2_per_objfile
->queue
.empty ())
8718 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8720 if ((dwarf2_per_objfile
->using_index
8721 ? !item
.per_cu
->v
.quick
->compunit_symtab
8722 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8723 /* Skip dummy CUs. */
8724 && item
.per_cu
->cu
!= NULL
)
8726 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8727 unsigned int debug_print_threshold
;
8730 if (per_cu
->is_debug_types
)
8732 struct signatured_type
*sig_type
=
8733 (struct signatured_type
*) per_cu
;
8735 sprintf (buf
, "TU %s at offset %s",
8736 hex_string (sig_type
->signature
),
8737 sect_offset_str (per_cu
->sect_off
));
8738 /* There can be 100s of TUs.
8739 Only print them in verbose mode. */
8740 debug_print_threshold
= 2;
8744 sprintf (buf
, "CU at offset %s",
8745 sect_offset_str (per_cu
->sect_off
));
8746 debug_print_threshold
= 1;
8749 if (dwarf_read_debug
>= debug_print_threshold
)
8750 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8752 if (per_cu
->is_debug_types
)
8753 process_full_type_unit (per_cu
, item
.pretend_language
);
8755 process_full_comp_unit (per_cu
, item
.pretend_language
);
8757 if (dwarf_read_debug
>= debug_print_threshold
)
8758 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8761 item
.per_cu
->queued
= 0;
8762 dwarf2_per_objfile
->queue
.pop ();
8765 if (dwarf_read_debug
)
8767 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8768 objfile_name (dwarf2_per_objfile
->objfile
));
8772 /* Read in full symbols for PST, and anything it depends on. */
8775 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8780 expand_dependencies (objfile
);
8782 dw2_do_instantiate_symtab (per_cu_data
, false);
8783 gdb_assert (get_compunit_symtab () != nullptr);
8786 /* Trivial hash function for die_info: the hash value of a DIE
8787 is its offset in .debug_info for this objfile. */
8790 die_hash (const void *item
)
8792 const struct die_info
*die
= (const struct die_info
*) item
;
8794 return to_underlying (die
->sect_off
);
8797 /* Trivial comparison function for die_info structures: two DIEs
8798 are equal if they have the same offset. */
8801 die_eq (const void *item_lhs
, const void *item_rhs
)
8803 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8804 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8806 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8809 /* Load the DIEs associated with PER_CU into memory. */
8812 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8814 enum language pretend_language
)
8816 gdb_assert (! this_cu
->is_debug_types
);
8818 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8822 struct dwarf2_cu
*cu
= reader
.cu
;
8823 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8825 gdb_assert (cu
->die_hash
== NULL
);
8827 htab_create_alloc_ex (cu
->header
.length
/ 12,
8831 &cu
->comp_unit_obstack
,
8832 hashtab_obstack_allocate
,
8833 dummy_obstack_deallocate
);
8835 if (reader
.comp_unit_die
->has_children
)
8836 reader
.comp_unit_die
->child
8837 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8838 &info_ptr
, reader
.comp_unit_die
);
8839 cu
->dies
= reader
.comp_unit_die
;
8840 /* comp_unit_die is not stored in die_hash, no need. */
8842 /* We try not to read any attributes in this function, because not
8843 all CUs needed for references have been loaded yet, and symbol
8844 table processing isn't initialized. But we have to set the CU language,
8845 or we won't be able to build types correctly.
8846 Similarly, if we do not read the producer, we can not apply
8847 producer-specific interpretation. */
8848 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8853 /* Add a DIE to the delayed physname list. */
8856 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8857 const char *name
, struct die_info
*die
,
8858 struct dwarf2_cu
*cu
)
8860 struct delayed_method_info mi
;
8862 mi
.fnfield_index
= fnfield_index
;
8866 cu
->method_list
.push_back (mi
);
8869 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8870 "const" / "volatile". If so, decrements LEN by the length of the
8871 modifier and return true. Otherwise return false. */
8875 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8877 size_t mod_len
= sizeof (mod
) - 1;
8878 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8886 /* Compute the physnames of any methods on the CU's method list.
8888 The computation of method physnames is delayed in order to avoid the
8889 (bad) condition that one of the method's formal parameters is of an as yet
8893 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8895 /* Only C++ delays computing physnames. */
8896 if (cu
->method_list
.empty ())
8898 gdb_assert (cu
->language
== language_cplus
);
8900 for (const delayed_method_info
&mi
: cu
->method_list
)
8902 const char *physname
;
8903 struct fn_fieldlist
*fn_flp
8904 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8905 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8906 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8907 = physname
? physname
: "";
8909 /* Since there's no tag to indicate whether a method is a
8910 const/volatile overload, extract that information out of the
8912 if (physname
!= NULL
)
8914 size_t len
= strlen (physname
);
8918 if (physname
[len
] == ')') /* shortcut */
8920 else if (check_modifier (physname
, len
, " const"))
8921 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8922 else if (check_modifier (physname
, len
, " volatile"))
8923 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8930 /* The list is no longer needed. */
8931 cu
->method_list
.clear ();
8934 /* Go objects should be embedded in a DW_TAG_module DIE,
8935 and it's not clear if/how imported objects will appear.
8936 To keep Go support simple until that's worked out,
8937 go back through what we've read and create something usable.
8938 We could do this while processing each DIE, and feels kinda cleaner,
8939 but that way is more invasive.
8940 This is to, for example, allow the user to type "p var" or "b main"
8941 without having to specify the package name, and allow lookups
8942 of module.object to work in contexts that use the expression
8946 fixup_go_packaging (struct dwarf2_cu
*cu
)
8948 gdb::unique_xmalloc_ptr
<char> package_name
;
8949 struct pending
*list
;
8952 for (list
= *cu
->get_builder ()->get_global_symbols ();
8956 for (i
= 0; i
< list
->nsyms
; ++i
)
8958 struct symbol
*sym
= list
->symbol
[i
];
8960 if (sym
->language () == language_go
8961 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8963 gdb::unique_xmalloc_ptr
<char> this_package_name
8964 (go_symbol_package_name (sym
));
8966 if (this_package_name
== NULL
)
8968 if (package_name
== NULL
)
8969 package_name
= std::move (this_package_name
);
8972 struct objfile
*objfile
8973 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8974 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8975 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8976 (symbol_symtab (sym
) != NULL
8977 ? symtab_to_filename_for_display
8978 (symbol_symtab (sym
))
8979 : objfile_name (objfile
)),
8980 this_package_name
.get (), package_name
.get ());
8986 if (package_name
!= NULL
)
8988 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8989 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8990 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8991 saved_package_name
);
8994 sym
= allocate_symbol (objfile
);
8995 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8996 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8997 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8998 e.g., "main" finds the "main" module and not C's main(). */
8999 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9000 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9001 SYMBOL_TYPE (sym
) = type
;
9003 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9007 /* Allocate a fully-qualified name consisting of the two parts on the
9011 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9013 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9016 /* A helper that allocates a struct discriminant_info to attach to a
9019 static struct discriminant_info
*
9020 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9023 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9024 gdb_assert (discriminant_index
== -1
9025 || (discriminant_index
>= 0
9026 && discriminant_index
< TYPE_NFIELDS (type
)));
9027 gdb_assert (default_index
== -1
9028 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9030 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9032 struct discriminant_info
*disc
9033 = ((struct discriminant_info
*)
9035 offsetof (struct discriminant_info
, discriminants
)
9036 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9037 disc
->default_index
= default_index
;
9038 disc
->discriminant_index
= discriminant_index
;
9040 struct dynamic_prop prop
;
9041 prop
.kind
= PROP_UNDEFINED
;
9042 prop
.data
.baton
= disc
;
9044 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9049 /* Some versions of rustc emitted enums in an unusual way.
9051 Ordinary enums were emitted as unions. The first element of each
9052 structure in the union was named "RUST$ENUM$DISR". This element
9053 held the discriminant.
9055 These versions of Rust also implemented the "non-zero"
9056 optimization. When the enum had two values, and one is empty and
9057 the other holds a pointer that cannot be zero, the pointer is used
9058 as the discriminant, with a zero value meaning the empty variant.
9059 Here, the union's first member is of the form
9060 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9061 where the fieldnos are the indices of the fields that should be
9062 traversed in order to find the field (which may be several fields deep)
9063 and the variantname is the name of the variant of the case when the
9066 This function recognizes whether TYPE is of one of these forms,
9067 and, if so, smashes it to be a variant type. */
9070 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9072 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9074 /* We don't need to deal with empty enums. */
9075 if (TYPE_NFIELDS (type
) == 0)
9078 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9079 if (TYPE_NFIELDS (type
) == 1
9080 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9082 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9084 /* Decode the field name to find the offset of the
9086 ULONGEST bit_offset
= 0;
9087 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9088 while (name
[0] >= '0' && name
[0] <= '9')
9091 unsigned long index
= strtoul (name
, &tail
, 10);
9094 || index
>= TYPE_NFIELDS (field_type
)
9095 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9096 != FIELD_LOC_KIND_BITPOS
))
9098 complaint (_("Could not parse Rust enum encoding string \"%s\""
9100 TYPE_FIELD_NAME (type
, 0),
9101 objfile_name (objfile
));
9106 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9107 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9110 /* Make a union to hold the variants. */
9111 struct type
*union_type
= alloc_type (objfile
);
9112 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9113 TYPE_NFIELDS (union_type
) = 3;
9114 TYPE_FIELDS (union_type
)
9115 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9116 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9117 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9119 /* Put the discriminant must at index 0. */
9120 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9121 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9122 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9123 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9125 /* The order of fields doesn't really matter, so put the real
9126 field at index 1 and the data-less field at index 2. */
9127 struct discriminant_info
*disc
9128 = alloc_discriminant_info (union_type
, 0, 1);
9129 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9130 TYPE_FIELD_NAME (union_type
, 1)
9131 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9132 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9133 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9134 TYPE_FIELD_NAME (union_type
, 1));
9136 const char *dataless_name
9137 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9139 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9141 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9142 /* NAME points into the original discriminant name, which
9143 already has the correct lifetime. */
9144 TYPE_FIELD_NAME (union_type
, 2) = name
;
9145 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9146 disc
->discriminants
[2] = 0;
9148 /* Smash this type to be a structure type. We have to do this
9149 because the type has already been recorded. */
9150 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9151 TYPE_NFIELDS (type
) = 1;
9153 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9155 /* Install the variant part. */
9156 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9157 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9158 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9160 /* A union with a single anonymous field is probably an old-style
9162 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9164 /* Smash this type to be a structure type. We have to do this
9165 because the type has already been recorded. */
9166 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9168 /* Make a union to hold the variants. */
9169 struct type
*union_type
= alloc_type (objfile
);
9170 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9171 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9172 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9173 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9174 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9176 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9177 const char *variant_name
9178 = rust_last_path_segment (TYPE_NAME (field_type
));
9179 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9180 TYPE_NAME (field_type
)
9181 = rust_fully_qualify (&objfile
->objfile_obstack
,
9182 TYPE_NAME (type
), variant_name
);
9184 /* Install the union in the outer struct type. */
9185 TYPE_NFIELDS (type
) = 1;
9187 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9188 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9189 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9190 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9192 alloc_discriminant_info (union_type
, -1, 0);
9196 struct type
*disr_type
= nullptr;
9197 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9199 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9201 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9203 /* All fields of a true enum will be structs. */
9206 else if (TYPE_NFIELDS (disr_type
) == 0)
9208 /* Could be data-less variant, so keep going. */
9209 disr_type
= nullptr;
9211 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9212 "RUST$ENUM$DISR") != 0)
9214 /* Not a Rust enum. */
9224 /* If we got here without a discriminant, then it's probably
9226 if (disr_type
== nullptr)
9229 /* Smash this type to be a structure type. We have to do this
9230 because the type has already been recorded. */
9231 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9233 /* Make a union to hold the variants. */
9234 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9235 struct type
*union_type
= alloc_type (objfile
);
9236 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9237 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9238 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9239 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9240 TYPE_FIELDS (union_type
)
9241 = (struct field
*) TYPE_ZALLOC (union_type
,
9242 (TYPE_NFIELDS (union_type
)
9243 * sizeof (struct field
)));
9245 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9246 TYPE_NFIELDS (type
) * sizeof (struct field
));
9248 /* Install the discriminant at index 0 in the union. */
9249 TYPE_FIELD (union_type
, 0) = *disr_field
;
9250 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9251 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9253 /* Install the union in the outer struct type. */
9254 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9255 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9256 TYPE_NFIELDS (type
) = 1;
9258 /* Set the size and offset of the union type. */
9259 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9261 /* We need a way to find the correct discriminant given a
9262 variant name. For convenience we build a map here. */
9263 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9264 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9265 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9267 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9270 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9271 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9275 int n_fields
= TYPE_NFIELDS (union_type
);
9276 struct discriminant_info
*disc
9277 = alloc_discriminant_info (union_type
, 0, -1);
9278 /* Skip the discriminant here. */
9279 for (int i
= 1; i
< n_fields
; ++i
)
9281 /* Find the final word in the name of this variant's type.
9282 That name can be used to look up the correct
9284 const char *variant_name
9285 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9288 auto iter
= discriminant_map
.find (variant_name
);
9289 if (iter
!= discriminant_map
.end ())
9290 disc
->discriminants
[i
] = iter
->second
;
9292 /* Remove the discriminant field, if it exists. */
9293 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9294 if (TYPE_NFIELDS (sub_type
) > 0)
9296 --TYPE_NFIELDS (sub_type
);
9297 ++TYPE_FIELDS (sub_type
);
9299 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9300 TYPE_NAME (sub_type
)
9301 = rust_fully_qualify (&objfile
->objfile_obstack
,
9302 TYPE_NAME (type
), variant_name
);
9307 /* Rewrite some Rust unions to be structures with variants parts. */
9310 rust_union_quirks (struct dwarf2_cu
*cu
)
9312 gdb_assert (cu
->language
== language_rust
);
9313 for (type
*type_
: cu
->rust_unions
)
9314 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9315 /* We don't need this any more. */
9316 cu
->rust_unions
.clear ();
9319 /* Return the symtab for PER_CU. This works properly regardless of
9320 whether we're using the index or psymtabs. */
9322 static struct compunit_symtab
*
9323 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9325 return (per_cu
->dwarf2_per_objfile
->using_index
9326 ? per_cu
->v
.quick
->compunit_symtab
9327 : per_cu
->v
.psymtab
->compunit_symtab
);
9330 /* A helper function for computing the list of all symbol tables
9331 included by PER_CU. */
9334 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9335 htab_t all_children
, htab_t all_type_symtabs
,
9336 struct dwarf2_per_cu_data
*per_cu
,
9337 struct compunit_symtab
*immediate_parent
)
9340 struct compunit_symtab
*cust
;
9342 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9345 /* This inclusion and its children have been processed. */
9350 /* Only add a CU if it has a symbol table. */
9351 cust
= get_compunit_symtab (per_cu
);
9354 /* If this is a type unit only add its symbol table if we haven't
9355 seen it yet (type unit per_cu's can share symtabs). */
9356 if (per_cu
->is_debug_types
)
9358 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9362 result
->push_back (cust
);
9363 if (cust
->user
== NULL
)
9364 cust
->user
= immediate_parent
;
9369 result
->push_back (cust
);
9370 if (cust
->user
== NULL
)
9371 cust
->user
= immediate_parent
;
9375 if (!per_cu
->imported_symtabs_empty ())
9376 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9378 recursively_compute_inclusions (result
, all_children
,
9379 all_type_symtabs
, ptr
, cust
);
9383 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9387 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9389 gdb_assert (! per_cu
->is_debug_types
);
9391 if (!per_cu
->imported_symtabs_empty ())
9394 std::vector
<compunit_symtab
*> result_symtabs
;
9395 htab_t all_children
, all_type_symtabs
;
9396 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9398 /* If we don't have a symtab, we can just skip this case. */
9402 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9403 NULL
, xcalloc
, xfree
);
9404 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9405 NULL
, xcalloc
, xfree
);
9407 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9409 recursively_compute_inclusions (&result_symtabs
, all_children
,
9410 all_type_symtabs
, ptr
, cust
);
9413 /* Now we have a transitive closure of all the included symtabs. */
9414 len
= result_symtabs
.size ();
9416 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9417 struct compunit_symtab
*, len
+ 1);
9418 memcpy (cust
->includes
, result_symtabs
.data (),
9419 len
* sizeof (compunit_symtab
*));
9420 cust
->includes
[len
] = NULL
;
9422 htab_delete (all_children
);
9423 htab_delete (all_type_symtabs
);
9427 /* Compute the 'includes' field for the symtabs of all the CUs we just
9431 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9433 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9435 if (! iter
->is_debug_types
)
9436 compute_compunit_symtab_includes (iter
);
9439 dwarf2_per_objfile
->just_read_cus
.clear ();
9442 /* Generate full symbol information for PER_CU, whose DIEs have
9443 already been loaded into memory. */
9446 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9447 enum language pretend_language
)
9449 struct dwarf2_cu
*cu
= per_cu
->cu
;
9450 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9451 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9452 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9453 CORE_ADDR lowpc
, highpc
;
9454 struct compunit_symtab
*cust
;
9456 struct block
*static_block
;
9459 baseaddr
= objfile
->text_section_offset ();
9461 /* Clear the list here in case something was left over. */
9462 cu
->method_list
.clear ();
9464 cu
->language
= pretend_language
;
9465 cu
->language_defn
= language_def (cu
->language
);
9467 /* Do line number decoding in read_file_scope () */
9468 process_die (cu
->dies
, cu
);
9470 /* For now fudge the Go package. */
9471 if (cu
->language
== language_go
)
9472 fixup_go_packaging (cu
);
9474 /* Now that we have processed all the DIEs in the CU, all the types
9475 should be complete, and it should now be safe to compute all of the
9477 compute_delayed_physnames (cu
);
9479 if (cu
->language
== language_rust
)
9480 rust_union_quirks (cu
);
9482 /* Some compilers don't define a DW_AT_high_pc attribute for the
9483 compilation unit. If the DW_AT_high_pc is missing, synthesize
9484 it, by scanning the DIE's below the compilation unit. */
9485 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9487 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9488 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9490 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9491 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9492 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9493 addrmap to help ensure it has an accurate map of pc values belonging to
9495 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9497 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9498 SECT_OFF_TEXT (objfile
),
9503 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9505 /* Set symtab language to language from DW_AT_language. If the
9506 compilation is from a C file generated by language preprocessors, do
9507 not set the language if it was already deduced by start_subfile. */
9508 if (!(cu
->language
== language_c
9509 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9510 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9512 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9513 produce DW_AT_location with location lists but it can be possibly
9514 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9515 there were bugs in prologue debug info, fixed later in GCC-4.5
9516 by "unwind info for epilogues" patch (which is not directly related).
9518 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9519 needed, it would be wrong due to missing DW_AT_producer there.
9521 Still one can confuse GDB by using non-standard GCC compilation
9522 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9524 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9525 cust
->locations_valid
= 1;
9527 if (gcc_4_minor
>= 5)
9528 cust
->epilogue_unwind_valid
= 1;
9530 cust
->call_site_htab
= cu
->call_site_htab
;
9533 if (dwarf2_per_objfile
->using_index
)
9534 per_cu
->v
.quick
->compunit_symtab
= cust
;
9537 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9538 pst
->compunit_symtab
= cust
;
9542 /* Push it for inclusion processing later. */
9543 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9545 /* Not needed any more. */
9546 cu
->reset_builder ();
9549 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9550 already been loaded into memory. */
9553 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9554 enum language pretend_language
)
9556 struct dwarf2_cu
*cu
= per_cu
->cu
;
9557 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9558 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9559 struct compunit_symtab
*cust
;
9560 struct signatured_type
*sig_type
;
9562 gdb_assert (per_cu
->is_debug_types
);
9563 sig_type
= (struct signatured_type
*) per_cu
;
9565 /* Clear the list here in case something was left over. */
9566 cu
->method_list
.clear ();
9568 cu
->language
= pretend_language
;
9569 cu
->language_defn
= language_def (cu
->language
);
9571 /* The symbol tables are set up in read_type_unit_scope. */
9572 process_die (cu
->dies
, cu
);
9574 /* For now fudge the Go package. */
9575 if (cu
->language
== language_go
)
9576 fixup_go_packaging (cu
);
9578 /* Now that we have processed all the DIEs in the CU, all the types
9579 should be complete, and it should now be safe to compute all of the
9581 compute_delayed_physnames (cu
);
9583 if (cu
->language
== language_rust
)
9584 rust_union_quirks (cu
);
9586 /* TUs share symbol tables.
9587 If this is the first TU to use this symtab, complete the construction
9588 of it with end_expandable_symtab. Otherwise, complete the addition of
9589 this TU's symbols to the existing symtab. */
9590 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9592 buildsym_compunit
*builder
= cu
->get_builder ();
9593 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9594 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9598 /* Set symtab language to language from DW_AT_language. If the
9599 compilation is from a C file generated by language preprocessors,
9600 do not set the language if it was already deduced by
9602 if (!(cu
->language
== language_c
9603 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9604 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9609 cu
->get_builder ()->augment_type_symtab ();
9610 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9613 if (dwarf2_per_objfile
->using_index
)
9614 per_cu
->v
.quick
->compunit_symtab
= cust
;
9617 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9618 pst
->compunit_symtab
= cust
;
9622 /* Not needed any more. */
9623 cu
->reset_builder ();
9626 /* Process an imported unit DIE. */
9629 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9631 struct attribute
*attr
;
9633 /* For now we don't handle imported units in type units. */
9634 if (cu
->per_cu
->is_debug_types
)
9636 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9637 " supported in type units [in module %s]"),
9638 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9641 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9644 sect_offset sect_off
= attr
->get_ref_die_offset ();
9645 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9646 dwarf2_per_cu_data
*per_cu
9647 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9648 cu
->per_cu
->dwarf2_per_objfile
);
9650 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9651 into another compilation unit, at root level. Regard this as a hint,
9653 if (die
->parent
&& die
->parent
->parent
== NULL
9654 && per_cu
->unit_type
== DW_UT_compile
9655 && per_cu
->lang
== language_cplus
)
9658 /* If necessary, add it to the queue and load its DIEs. */
9659 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9660 load_full_comp_unit (per_cu
, false, cu
->language
);
9662 cu
->per_cu
->imported_symtabs_push (per_cu
);
9666 /* RAII object that represents a process_die scope: i.e.,
9667 starts/finishes processing a DIE. */
9668 class process_die_scope
9671 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9672 : m_die (die
), m_cu (cu
)
9674 /* We should only be processing DIEs not already in process. */
9675 gdb_assert (!m_die
->in_process
);
9676 m_die
->in_process
= true;
9679 ~process_die_scope ()
9681 m_die
->in_process
= false;
9683 /* If we're done processing the DIE for the CU that owns the line
9684 header, we don't need the line header anymore. */
9685 if (m_cu
->line_header_die_owner
== m_die
)
9687 delete m_cu
->line_header
;
9688 m_cu
->line_header
= NULL
;
9689 m_cu
->line_header_die_owner
= NULL
;
9698 /* Process a die and its children. */
9701 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9703 process_die_scope
scope (die
, cu
);
9707 case DW_TAG_padding
:
9709 case DW_TAG_compile_unit
:
9710 case DW_TAG_partial_unit
:
9711 read_file_scope (die
, cu
);
9713 case DW_TAG_type_unit
:
9714 read_type_unit_scope (die
, cu
);
9716 case DW_TAG_subprogram
:
9717 /* Nested subprograms in Fortran get a prefix. */
9718 if (cu
->language
== language_fortran
9719 && die
->parent
!= NULL
9720 && die
->parent
->tag
== DW_TAG_subprogram
)
9721 cu
->processing_has_namespace_info
= true;
9723 case DW_TAG_inlined_subroutine
:
9724 read_func_scope (die
, cu
);
9726 case DW_TAG_lexical_block
:
9727 case DW_TAG_try_block
:
9728 case DW_TAG_catch_block
:
9729 read_lexical_block_scope (die
, cu
);
9731 case DW_TAG_call_site
:
9732 case DW_TAG_GNU_call_site
:
9733 read_call_site_scope (die
, cu
);
9735 case DW_TAG_class_type
:
9736 case DW_TAG_interface_type
:
9737 case DW_TAG_structure_type
:
9738 case DW_TAG_union_type
:
9739 process_structure_scope (die
, cu
);
9741 case DW_TAG_enumeration_type
:
9742 process_enumeration_scope (die
, cu
);
9745 /* These dies have a type, but processing them does not create
9746 a symbol or recurse to process the children. Therefore we can
9747 read them on-demand through read_type_die. */
9748 case DW_TAG_subroutine_type
:
9749 case DW_TAG_set_type
:
9750 case DW_TAG_array_type
:
9751 case DW_TAG_pointer_type
:
9752 case DW_TAG_ptr_to_member_type
:
9753 case DW_TAG_reference_type
:
9754 case DW_TAG_rvalue_reference_type
:
9755 case DW_TAG_string_type
:
9758 case DW_TAG_base_type
:
9759 case DW_TAG_subrange_type
:
9760 case DW_TAG_typedef
:
9761 /* Add a typedef symbol for the type definition, if it has a
9763 new_symbol (die
, read_type_die (die
, cu
), cu
);
9765 case DW_TAG_common_block
:
9766 read_common_block (die
, cu
);
9768 case DW_TAG_common_inclusion
:
9770 case DW_TAG_namespace
:
9771 cu
->processing_has_namespace_info
= true;
9772 read_namespace (die
, cu
);
9775 cu
->processing_has_namespace_info
= true;
9776 read_module (die
, cu
);
9778 case DW_TAG_imported_declaration
:
9779 cu
->processing_has_namespace_info
= true;
9780 if (read_namespace_alias (die
, cu
))
9782 /* The declaration is not a global namespace alias. */
9784 case DW_TAG_imported_module
:
9785 cu
->processing_has_namespace_info
= true;
9786 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9787 || cu
->language
!= language_fortran
))
9788 complaint (_("Tag '%s' has unexpected children"),
9789 dwarf_tag_name (die
->tag
));
9790 read_import_statement (die
, cu
);
9793 case DW_TAG_imported_unit
:
9794 process_imported_unit_die (die
, cu
);
9797 case DW_TAG_variable
:
9798 read_variable (die
, cu
);
9802 new_symbol (die
, NULL
, cu
);
9807 /* DWARF name computation. */
9809 /* A helper function for dwarf2_compute_name which determines whether DIE
9810 needs to have the name of the scope prepended to the name listed in the
9814 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9816 struct attribute
*attr
;
9820 case DW_TAG_namespace
:
9821 case DW_TAG_typedef
:
9822 case DW_TAG_class_type
:
9823 case DW_TAG_interface_type
:
9824 case DW_TAG_structure_type
:
9825 case DW_TAG_union_type
:
9826 case DW_TAG_enumeration_type
:
9827 case DW_TAG_enumerator
:
9828 case DW_TAG_subprogram
:
9829 case DW_TAG_inlined_subroutine
:
9831 case DW_TAG_imported_declaration
:
9834 case DW_TAG_variable
:
9835 case DW_TAG_constant
:
9836 /* We only need to prefix "globally" visible variables. These include
9837 any variable marked with DW_AT_external or any variable that
9838 lives in a namespace. [Variables in anonymous namespaces
9839 require prefixing, but they are not DW_AT_external.] */
9841 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9843 struct dwarf2_cu
*spec_cu
= cu
;
9845 return die_needs_namespace (die_specification (die
, &spec_cu
),
9849 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9850 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9851 && die
->parent
->tag
!= DW_TAG_module
)
9853 /* A variable in a lexical block of some kind does not need a
9854 namespace, even though in C++ such variables may be external
9855 and have a mangled name. */
9856 if (die
->parent
->tag
== DW_TAG_lexical_block
9857 || die
->parent
->tag
== DW_TAG_try_block
9858 || die
->parent
->tag
== DW_TAG_catch_block
9859 || die
->parent
->tag
== DW_TAG_subprogram
)
9868 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9869 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9870 defined for the given DIE. */
9872 static struct attribute
*
9873 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9875 struct attribute
*attr
;
9877 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9879 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9884 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9885 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9886 defined for the given DIE. */
9889 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9891 const char *linkage_name
;
9893 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9894 if (linkage_name
== NULL
)
9895 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9897 return linkage_name
;
9900 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9901 compute the physname for the object, which include a method's:
9902 - formal parameters (C++),
9903 - receiver type (Go),
9905 The term "physname" is a bit confusing.
9906 For C++, for example, it is the demangled name.
9907 For Go, for example, it's the mangled name.
9909 For Ada, return the DIE's linkage name rather than the fully qualified
9910 name. PHYSNAME is ignored..
9912 The result is allocated on the objfile_obstack and canonicalized. */
9915 dwarf2_compute_name (const char *name
,
9916 struct die_info
*die
, struct dwarf2_cu
*cu
,
9919 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9922 name
= dwarf2_name (die
, cu
);
9924 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9925 but otherwise compute it by typename_concat inside GDB.
9926 FIXME: Actually this is not really true, or at least not always true.
9927 It's all very confusing. compute_and_set_names doesn't try to demangle
9928 Fortran names because there is no mangling standard. So new_symbol
9929 will set the demangled name to the result of dwarf2_full_name, and it is
9930 the demangled name that GDB uses if it exists. */
9931 if (cu
->language
== language_ada
9932 || (cu
->language
== language_fortran
&& physname
))
9934 /* For Ada unit, we prefer the linkage name over the name, as
9935 the former contains the exported name, which the user expects
9936 to be able to reference. Ideally, we want the user to be able
9937 to reference this entity using either natural or linkage name,
9938 but we haven't started looking at this enhancement yet. */
9939 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9941 if (linkage_name
!= NULL
)
9942 return linkage_name
;
9945 /* These are the only languages we know how to qualify names in. */
9947 && (cu
->language
== language_cplus
9948 || cu
->language
== language_fortran
|| cu
->language
== language_d
9949 || cu
->language
== language_rust
))
9951 if (die_needs_namespace (die
, cu
))
9954 const char *canonical_name
= NULL
;
9958 prefix
= determine_prefix (die
, cu
);
9959 if (*prefix
!= '\0')
9961 gdb::unique_xmalloc_ptr
<char> prefixed_name
9962 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9964 buf
.puts (prefixed_name
.get ());
9969 /* Template parameters may be specified in the DIE's DW_AT_name, or
9970 as children with DW_TAG_template_type_param or
9971 DW_TAG_value_type_param. If the latter, add them to the name
9972 here. If the name already has template parameters, then
9973 skip this step; some versions of GCC emit both, and
9974 it is more efficient to use the pre-computed name.
9976 Something to keep in mind about this process: it is very
9977 unlikely, or in some cases downright impossible, to produce
9978 something that will match the mangled name of a function.
9979 If the definition of the function has the same debug info,
9980 we should be able to match up with it anyway. But fallbacks
9981 using the minimal symbol, for instance to find a method
9982 implemented in a stripped copy of libstdc++, will not work.
9983 If we do not have debug info for the definition, we will have to
9984 match them up some other way.
9986 When we do name matching there is a related problem with function
9987 templates; two instantiated function templates are allowed to
9988 differ only by their return types, which we do not add here. */
9990 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9992 struct attribute
*attr
;
9993 struct die_info
*child
;
9996 die
->building_fullname
= 1;
9998 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10002 const gdb_byte
*bytes
;
10003 struct dwarf2_locexpr_baton
*baton
;
10006 if (child
->tag
!= DW_TAG_template_type_param
10007 && child
->tag
!= DW_TAG_template_value_param
)
10018 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10021 complaint (_("template parameter missing DW_AT_type"));
10022 buf
.puts ("UNKNOWN_TYPE");
10025 type
= die_type (child
, cu
);
10027 if (child
->tag
== DW_TAG_template_type_param
)
10029 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10030 &type_print_raw_options
);
10034 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10037 complaint (_("template parameter missing "
10038 "DW_AT_const_value"));
10039 buf
.puts ("UNKNOWN_VALUE");
10043 dwarf2_const_value_attr (attr
, type
, name
,
10044 &cu
->comp_unit_obstack
, cu
,
10045 &value
, &bytes
, &baton
);
10047 if (TYPE_NOSIGN (type
))
10048 /* GDB prints characters as NUMBER 'CHAR'. If that's
10049 changed, this can use value_print instead. */
10050 c_printchar (value
, type
, &buf
);
10053 struct value_print_options opts
;
10056 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10060 else if (bytes
!= NULL
)
10062 v
= allocate_value (type
);
10063 memcpy (value_contents_writeable (v
), bytes
,
10064 TYPE_LENGTH (type
));
10067 v
= value_from_longest (type
, value
);
10069 /* Specify decimal so that we do not depend on
10071 get_formatted_print_options (&opts
, 'd');
10073 value_print (v
, &buf
, &opts
);
10078 die
->building_fullname
= 0;
10082 /* Close the argument list, with a space if necessary
10083 (nested templates). */
10084 if (!buf
.empty () && buf
.string ().back () == '>')
10091 /* For C++ methods, append formal parameter type
10092 information, if PHYSNAME. */
10094 if (physname
&& die
->tag
== DW_TAG_subprogram
10095 && cu
->language
== language_cplus
)
10097 struct type
*type
= read_type_die (die
, cu
);
10099 c_type_print_args (type
, &buf
, 1, cu
->language
,
10100 &type_print_raw_options
);
10102 if (cu
->language
== language_cplus
)
10104 /* Assume that an artificial first parameter is
10105 "this", but do not crash if it is not. RealView
10106 marks unnamed (and thus unused) parameters as
10107 artificial; there is no way to differentiate
10109 if (TYPE_NFIELDS (type
) > 0
10110 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10111 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10112 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10114 buf
.puts (" const");
10118 const std::string
&intermediate_name
= buf
.string ();
10120 if (cu
->language
== language_cplus
)
10122 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10125 /* If we only computed INTERMEDIATE_NAME, or if
10126 INTERMEDIATE_NAME is already canonical, then we need to
10128 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10129 name
= objfile
->intern (intermediate_name
);
10131 name
= canonical_name
;
10138 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10139 If scope qualifiers are appropriate they will be added. The result
10140 will be allocated on the storage_obstack, or NULL if the DIE does
10141 not have a name. NAME may either be from a previous call to
10142 dwarf2_name or NULL.
10144 The output string will be canonicalized (if C++). */
10146 static const char *
10147 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10149 return dwarf2_compute_name (name
, die
, cu
, 0);
10152 /* Construct a physname for the given DIE in CU. NAME may either be
10153 from a previous call to dwarf2_name or NULL. The result will be
10154 allocated on the objfile_objstack or NULL if the DIE does not have a
10157 The output string will be canonicalized (if C++). */
10159 static const char *
10160 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10162 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10163 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10166 /* In this case dwarf2_compute_name is just a shortcut not building anything
10168 if (!die_needs_namespace (die
, cu
))
10169 return dwarf2_compute_name (name
, die
, cu
, 1);
10171 mangled
= dw2_linkage_name (die
, cu
);
10173 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10174 See https://github.com/rust-lang/rust/issues/32925. */
10175 if (cu
->language
== language_rust
&& mangled
!= NULL
10176 && strchr (mangled
, '{') != NULL
)
10179 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10181 gdb::unique_xmalloc_ptr
<char> demangled
;
10182 if (mangled
!= NULL
)
10185 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10187 /* Do nothing (do not demangle the symbol name). */
10189 else if (cu
->language
== language_go
)
10191 /* This is a lie, but we already lie to the caller new_symbol.
10192 new_symbol assumes we return the mangled name.
10193 This just undoes that lie until things are cleaned up. */
10197 /* Use DMGL_RET_DROP for C++ template functions to suppress
10198 their return type. It is easier for GDB users to search
10199 for such functions as `name(params)' than `long name(params)'.
10200 In such case the minimal symbol names do not match the full
10201 symbol names but for template functions there is never a need
10202 to look up their definition from their declaration so
10203 the only disadvantage remains the minimal symbol variant
10204 `long name(params)' does not have the proper inferior type. */
10205 demangled
.reset (gdb_demangle (mangled
,
10206 (DMGL_PARAMS
| DMGL_ANSI
10207 | DMGL_RET_DROP
)));
10210 canon
= demangled
.get ();
10218 if (canon
== NULL
|| check_physname
)
10220 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10222 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10224 /* It may not mean a bug in GDB. The compiler could also
10225 compute DW_AT_linkage_name incorrectly. But in such case
10226 GDB would need to be bug-to-bug compatible. */
10228 complaint (_("Computed physname <%s> does not match demangled <%s> "
10229 "(from linkage <%s>) - DIE at %s [in module %s]"),
10230 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10231 objfile_name (objfile
));
10233 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10234 is available here - over computed PHYSNAME. It is safer
10235 against both buggy GDB and buggy compilers. */
10249 retval
= objfile
->intern (retval
);
10254 /* Inspect DIE in CU for a namespace alias. If one exists, record
10255 a new symbol for it.
10257 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10260 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10262 struct attribute
*attr
;
10264 /* If the die does not have a name, this is not a namespace
10266 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10270 struct die_info
*d
= die
;
10271 struct dwarf2_cu
*imported_cu
= cu
;
10273 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10274 keep inspecting DIEs until we hit the underlying import. */
10275 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10276 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10278 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10282 d
= follow_die_ref (d
, attr
, &imported_cu
);
10283 if (d
->tag
!= DW_TAG_imported_declaration
)
10287 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10289 complaint (_("DIE at %s has too many recursively imported "
10290 "declarations"), sect_offset_str (d
->sect_off
));
10297 sect_offset sect_off
= attr
->get_ref_die_offset ();
10299 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10300 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10302 /* This declaration is a global namespace alias. Add
10303 a symbol for it whose type is the aliased namespace. */
10304 new_symbol (die
, type
, cu
);
10313 /* Return the using directives repository (global or local?) to use in the
10314 current context for CU.
10316 For Ada, imported declarations can materialize renamings, which *may* be
10317 global. However it is impossible (for now?) in DWARF to distinguish
10318 "external" imported declarations and "static" ones. As all imported
10319 declarations seem to be static in all other languages, make them all CU-wide
10320 global only in Ada. */
10322 static struct using_direct
**
10323 using_directives (struct dwarf2_cu
*cu
)
10325 if (cu
->language
== language_ada
10326 && cu
->get_builder ()->outermost_context_p ())
10327 return cu
->get_builder ()->get_global_using_directives ();
10329 return cu
->get_builder ()->get_local_using_directives ();
10332 /* Read the import statement specified by the given die and record it. */
10335 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10337 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10338 struct attribute
*import_attr
;
10339 struct die_info
*imported_die
, *child_die
;
10340 struct dwarf2_cu
*imported_cu
;
10341 const char *imported_name
;
10342 const char *imported_name_prefix
;
10343 const char *canonical_name
;
10344 const char *import_alias
;
10345 const char *imported_declaration
= NULL
;
10346 const char *import_prefix
;
10347 std::vector
<const char *> excludes
;
10349 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10350 if (import_attr
== NULL
)
10352 complaint (_("Tag '%s' has no DW_AT_import"),
10353 dwarf_tag_name (die
->tag
));
10358 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10359 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10360 if (imported_name
== NULL
)
10362 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10364 The import in the following code:
10378 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10379 <52> DW_AT_decl_file : 1
10380 <53> DW_AT_decl_line : 6
10381 <54> DW_AT_import : <0x75>
10382 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10383 <59> DW_AT_name : B
10384 <5b> DW_AT_decl_file : 1
10385 <5c> DW_AT_decl_line : 2
10386 <5d> DW_AT_type : <0x6e>
10388 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10389 <76> DW_AT_byte_size : 4
10390 <77> DW_AT_encoding : 5 (signed)
10392 imports the wrong die ( 0x75 instead of 0x58 ).
10393 This case will be ignored until the gcc bug is fixed. */
10397 /* Figure out the local name after import. */
10398 import_alias
= dwarf2_name (die
, cu
);
10400 /* Figure out where the statement is being imported to. */
10401 import_prefix
= determine_prefix (die
, cu
);
10403 /* Figure out what the scope of the imported die is and prepend it
10404 to the name of the imported die. */
10405 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10407 if (imported_die
->tag
!= DW_TAG_namespace
10408 && imported_die
->tag
!= DW_TAG_module
)
10410 imported_declaration
= imported_name
;
10411 canonical_name
= imported_name_prefix
;
10413 else if (strlen (imported_name_prefix
) > 0)
10414 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10415 imported_name_prefix
,
10416 (cu
->language
== language_d
? "." : "::"),
10417 imported_name
, (char *) NULL
);
10419 canonical_name
= imported_name
;
10421 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10422 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10423 child_die
= child_die
->sibling
)
10425 /* DWARF-4: A Fortran use statement with a “rename list” may be
10426 represented by an imported module entry with an import attribute
10427 referring to the module and owned entries corresponding to those
10428 entities that are renamed as part of being imported. */
10430 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10432 complaint (_("child DW_TAG_imported_declaration expected "
10433 "- DIE at %s [in module %s]"),
10434 sect_offset_str (child_die
->sect_off
),
10435 objfile_name (objfile
));
10439 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10440 if (import_attr
== NULL
)
10442 complaint (_("Tag '%s' has no DW_AT_import"),
10443 dwarf_tag_name (child_die
->tag
));
10448 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10450 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10451 if (imported_name
== NULL
)
10453 complaint (_("child DW_TAG_imported_declaration has unknown "
10454 "imported name - DIE at %s [in module %s]"),
10455 sect_offset_str (child_die
->sect_off
),
10456 objfile_name (objfile
));
10460 excludes
.push_back (imported_name
);
10462 process_die (child_die
, cu
);
10465 add_using_directive (using_directives (cu
),
10469 imported_declaration
,
10472 &objfile
->objfile_obstack
);
10475 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10476 types, but gives them a size of zero. Starting with version 14,
10477 ICC is compatible with GCC. */
10480 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10482 if (!cu
->checked_producer
)
10483 check_producer (cu
);
10485 return cu
->producer_is_icc_lt_14
;
10488 /* ICC generates a DW_AT_type for C void functions. This was observed on
10489 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10490 which says that void functions should not have a DW_AT_type. */
10493 producer_is_icc (struct dwarf2_cu
*cu
)
10495 if (!cu
->checked_producer
)
10496 check_producer (cu
);
10498 return cu
->producer_is_icc
;
10501 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10502 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10503 this, it was first present in GCC release 4.3.0. */
10506 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10508 if (!cu
->checked_producer
)
10509 check_producer (cu
);
10511 return cu
->producer_is_gcc_lt_4_3
;
10514 static file_and_directory
10515 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10517 file_and_directory res
;
10519 /* Find the filename. Do not use dwarf2_name here, since the filename
10520 is not a source language identifier. */
10521 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10522 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10524 if (res
.comp_dir
== NULL
10525 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10526 && IS_ABSOLUTE_PATH (res
.name
))
10528 res
.comp_dir_storage
= ldirname (res
.name
);
10529 if (!res
.comp_dir_storage
.empty ())
10530 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10532 if (res
.comp_dir
!= NULL
)
10534 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10535 directory, get rid of it. */
10536 const char *cp
= strchr (res
.comp_dir
, ':');
10538 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10539 res
.comp_dir
= cp
+ 1;
10542 if (res
.name
== NULL
)
10543 res
.name
= "<unknown>";
10548 /* Handle DW_AT_stmt_list for a compilation unit.
10549 DIE is the DW_TAG_compile_unit die for CU.
10550 COMP_DIR is the compilation directory. LOWPC is passed to
10551 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10554 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10555 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10557 struct dwarf2_per_objfile
*dwarf2_per_objfile
10558 = cu
->per_cu
->dwarf2_per_objfile
;
10559 struct attribute
*attr
;
10560 struct line_header line_header_local
;
10561 hashval_t line_header_local_hash
;
10563 int decode_mapping
;
10565 gdb_assert (! cu
->per_cu
->is_debug_types
);
10567 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10571 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10573 /* The line header hash table is only created if needed (it exists to
10574 prevent redundant reading of the line table for partial_units).
10575 If we're given a partial_unit, we'll need it. If we're given a
10576 compile_unit, then use the line header hash table if it's already
10577 created, but don't create one just yet. */
10579 if (dwarf2_per_objfile
->line_header_hash
== NULL
10580 && die
->tag
== DW_TAG_partial_unit
)
10582 dwarf2_per_objfile
->line_header_hash
10583 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10584 line_header_eq_voidp
,
10585 free_line_header_voidp
,
10589 line_header_local
.sect_off
= line_offset
;
10590 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10591 line_header_local_hash
= line_header_hash (&line_header_local
);
10592 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10594 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10595 &line_header_local
,
10596 line_header_local_hash
, NO_INSERT
);
10598 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10599 is not present in *SLOT (since if there is something in *SLOT then
10600 it will be for a partial_unit). */
10601 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10603 gdb_assert (*slot
!= NULL
);
10604 cu
->line_header
= (struct line_header
*) *slot
;
10609 /* dwarf_decode_line_header does not yet provide sufficient information.
10610 We always have to call also dwarf_decode_lines for it. */
10611 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10615 cu
->line_header
= lh
.release ();
10616 cu
->line_header_die_owner
= die
;
10618 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10622 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10623 &line_header_local
,
10624 line_header_local_hash
, INSERT
);
10625 gdb_assert (slot
!= NULL
);
10627 if (slot
!= NULL
&& *slot
== NULL
)
10629 /* This newly decoded line number information unit will be owned
10630 by line_header_hash hash table. */
10631 *slot
= cu
->line_header
;
10632 cu
->line_header_die_owner
= NULL
;
10636 /* We cannot free any current entry in (*slot) as that struct line_header
10637 may be already used by multiple CUs. Create only temporary decoded
10638 line_header for this CU - it may happen at most once for each line
10639 number information unit. And if we're not using line_header_hash
10640 then this is what we want as well. */
10641 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10643 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10644 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10649 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10652 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10654 struct dwarf2_per_objfile
*dwarf2_per_objfile
10655 = cu
->per_cu
->dwarf2_per_objfile
;
10656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10658 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10659 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10660 struct attribute
*attr
;
10661 struct die_info
*child_die
;
10662 CORE_ADDR baseaddr
;
10664 prepare_one_comp_unit (cu
, die
, cu
->language
);
10665 baseaddr
= objfile
->text_section_offset ();
10667 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10669 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10670 from finish_block. */
10671 if (lowpc
== ((CORE_ADDR
) -1))
10673 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10675 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10677 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10678 standardised yet. As a workaround for the language detection we fall
10679 back to the DW_AT_producer string. */
10680 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10681 cu
->language
= language_opencl
;
10683 /* Similar hack for Go. */
10684 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10685 set_cu_language (DW_LANG_Go
, cu
);
10687 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10689 /* Decode line number information if present. We do this before
10690 processing child DIEs, so that the line header table is available
10691 for DW_AT_decl_file. */
10692 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10694 /* Process all dies in compilation unit. */
10695 if (die
->child
!= NULL
)
10697 child_die
= die
->child
;
10698 while (child_die
&& child_die
->tag
)
10700 process_die (child_die
, cu
);
10701 child_die
= child_die
->sibling
;
10705 /* Decode macro information, if present. Dwarf 2 macro information
10706 refers to information in the line number info statement program
10707 header, so we can only read it if we've read the header
10709 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10711 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10712 if (attr
&& cu
->line_header
)
10714 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10715 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10717 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10721 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10722 if (attr
&& cu
->line_header
)
10724 unsigned int macro_offset
= DW_UNSND (attr
);
10726 dwarf_decode_macros (cu
, macro_offset
, 0);
10732 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10734 struct type_unit_group
*tu_group
;
10736 struct attribute
*attr
;
10738 struct signatured_type
*sig_type
;
10740 gdb_assert (per_cu
->is_debug_types
);
10741 sig_type
= (struct signatured_type
*) per_cu
;
10743 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10745 /* If we're using .gdb_index (includes -readnow) then
10746 per_cu->type_unit_group may not have been set up yet. */
10747 if (sig_type
->type_unit_group
== NULL
)
10748 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10749 tu_group
= sig_type
->type_unit_group
;
10751 /* If we've already processed this stmt_list there's no real need to
10752 do it again, we could fake it and just recreate the part we need
10753 (file name,index -> symtab mapping). If data shows this optimization
10754 is useful we can do it then. */
10755 first_time
= tu_group
->compunit_symtab
== NULL
;
10757 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10762 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10763 lh
= dwarf_decode_line_header (line_offset
, this);
10768 start_symtab ("", NULL
, 0);
10771 gdb_assert (tu_group
->symtabs
== NULL
);
10772 gdb_assert (m_builder
== nullptr);
10773 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10774 m_builder
.reset (new struct buildsym_compunit
10775 (COMPUNIT_OBJFILE (cust
), "",
10776 COMPUNIT_DIRNAME (cust
),
10777 compunit_language (cust
),
10783 line_header
= lh
.release ();
10784 line_header_die_owner
= die
;
10788 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10790 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10791 still initializing it, and our caller (a few levels up)
10792 process_full_type_unit still needs to know if this is the first
10796 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10797 struct symtab
*, line_header
->file_names_size ());
10799 auto &file_names
= line_header
->file_names ();
10800 for (i
= 0; i
< file_names
.size (); ++i
)
10802 file_entry
&fe
= file_names
[i
];
10803 dwarf2_start_subfile (this, fe
.name
,
10804 fe
.include_dir (line_header
));
10805 buildsym_compunit
*b
= get_builder ();
10806 if (b
->get_current_subfile ()->symtab
== NULL
)
10808 /* NOTE: start_subfile will recognize when it's been
10809 passed a file it has already seen. So we can't
10810 assume there's a simple mapping from
10811 cu->line_header->file_names to subfiles, plus
10812 cu->line_header->file_names may contain dups. */
10813 b
->get_current_subfile ()->symtab
10814 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10817 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10818 tu_group
->symtabs
[i
] = fe
.symtab
;
10823 gdb_assert (m_builder
== nullptr);
10824 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10825 m_builder
.reset (new struct buildsym_compunit
10826 (COMPUNIT_OBJFILE (cust
), "",
10827 COMPUNIT_DIRNAME (cust
),
10828 compunit_language (cust
),
10831 auto &file_names
= line_header
->file_names ();
10832 for (i
= 0; i
< file_names
.size (); ++i
)
10834 file_entry
&fe
= file_names
[i
];
10835 fe
.symtab
= tu_group
->symtabs
[i
];
10839 /* The main symtab is allocated last. Type units don't have DW_AT_name
10840 so they don't have a "real" (so to speak) symtab anyway.
10841 There is later code that will assign the main symtab to all symbols
10842 that don't have one. We need to handle the case of a symbol with a
10843 missing symtab (DW_AT_decl_file) anyway. */
10846 /* Process DW_TAG_type_unit.
10847 For TUs we want to skip the first top level sibling if it's not the
10848 actual type being defined by this TU. In this case the first top
10849 level sibling is there to provide context only. */
10852 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10854 struct die_info
*child_die
;
10856 prepare_one_comp_unit (cu
, die
, language_minimal
);
10858 /* Initialize (or reinitialize) the machinery for building symtabs.
10859 We do this before processing child DIEs, so that the line header table
10860 is available for DW_AT_decl_file. */
10861 cu
->setup_type_unit_groups (die
);
10863 if (die
->child
!= NULL
)
10865 child_die
= die
->child
;
10866 while (child_die
&& child_die
->tag
)
10868 process_die (child_die
, cu
);
10869 child_die
= child_die
->sibling
;
10876 http://gcc.gnu.org/wiki/DebugFission
10877 http://gcc.gnu.org/wiki/DebugFissionDWP
10879 To simplify handling of both DWO files ("object" files with the DWARF info)
10880 and DWP files (a file with the DWOs packaged up into one file), we treat
10881 DWP files as having a collection of virtual DWO files. */
10884 hash_dwo_file (const void *item
)
10886 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10889 hash
= htab_hash_string (dwo_file
->dwo_name
);
10890 if (dwo_file
->comp_dir
!= NULL
)
10891 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10896 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10898 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10899 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10901 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10903 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10904 return lhs
->comp_dir
== rhs
->comp_dir
;
10905 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10908 /* Allocate a hash table for DWO files. */
10911 allocate_dwo_file_hash_table ()
10913 auto delete_dwo_file
= [] (void *item
)
10915 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10920 return htab_up (htab_create_alloc (41,
10927 /* Lookup DWO file DWO_NAME. */
10930 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10931 const char *dwo_name
,
10932 const char *comp_dir
)
10934 struct dwo_file find_entry
;
10937 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10938 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10940 find_entry
.dwo_name
= dwo_name
;
10941 find_entry
.comp_dir
= comp_dir
;
10942 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10949 hash_dwo_unit (const void *item
)
10951 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10953 /* This drops the top 32 bits of the id, but is ok for a hash. */
10954 return dwo_unit
->signature
;
10958 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10960 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10961 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10963 /* The signature is assumed to be unique within the DWO file.
10964 So while object file CU dwo_id's always have the value zero,
10965 that's OK, assuming each object file DWO file has only one CU,
10966 and that's the rule for now. */
10967 return lhs
->signature
== rhs
->signature
;
10970 /* Allocate a hash table for DWO CUs,TUs.
10971 There is one of these tables for each of CUs,TUs for each DWO file. */
10974 allocate_dwo_unit_table ()
10976 /* Start out with a pretty small number.
10977 Generally DWO files contain only one CU and maybe some TUs. */
10978 return htab_up (htab_create_alloc (3,
10981 NULL
, xcalloc
, xfree
));
10984 /* die_reader_func for create_dwo_cu. */
10987 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10988 const gdb_byte
*info_ptr
,
10989 struct die_info
*comp_unit_die
,
10990 struct dwo_file
*dwo_file
,
10991 struct dwo_unit
*dwo_unit
)
10993 struct dwarf2_cu
*cu
= reader
->cu
;
10994 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10995 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10997 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10998 if (!signature
.has_value ())
11000 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11001 " its dwo_id [in module %s]"),
11002 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11006 dwo_unit
->dwo_file
= dwo_file
;
11007 dwo_unit
->signature
= *signature
;
11008 dwo_unit
->section
= section
;
11009 dwo_unit
->sect_off
= sect_off
;
11010 dwo_unit
->length
= cu
->per_cu
->length
;
11012 if (dwarf_read_debug
)
11013 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11014 sect_offset_str (sect_off
),
11015 hex_string (dwo_unit
->signature
));
11018 /* Create the dwo_units for the CUs in a DWO_FILE.
11019 Note: This function processes DWO files only, not DWP files. */
11022 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11023 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11024 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11026 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11027 const gdb_byte
*info_ptr
, *end_ptr
;
11029 section
.read (objfile
);
11030 info_ptr
= section
.buffer
;
11032 if (info_ptr
== NULL
)
11035 if (dwarf_read_debug
)
11037 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11038 section
.get_name (),
11039 section
.get_file_name ());
11042 end_ptr
= info_ptr
+ section
.size
;
11043 while (info_ptr
< end_ptr
)
11045 struct dwarf2_per_cu_data per_cu
;
11046 struct dwo_unit read_unit
{};
11047 struct dwo_unit
*dwo_unit
;
11049 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11051 memset (&per_cu
, 0, sizeof (per_cu
));
11052 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11053 per_cu
.is_debug_types
= 0;
11054 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11055 per_cu
.section
= §ion
;
11057 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11058 if (!reader
.dummy_p
)
11059 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11060 &dwo_file
, &read_unit
);
11061 info_ptr
+= per_cu
.length
;
11063 // If the unit could not be parsed, skip it.
11064 if (read_unit
.dwo_file
== NULL
)
11067 if (cus_htab
== NULL
)
11068 cus_htab
= allocate_dwo_unit_table ();
11070 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11071 *dwo_unit
= read_unit
;
11072 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11073 gdb_assert (slot
!= NULL
);
11076 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11077 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11079 complaint (_("debug cu entry at offset %s is duplicate to"
11080 " the entry at offset %s, signature %s"),
11081 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11082 hex_string (dwo_unit
->signature
));
11084 *slot
= (void *)dwo_unit
;
11088 /* DWP file .debug_{cu,tu}_index section format:
11089 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11093 Both index sections have the same format, and serve to map a 64-bit
11094 signature to a set of section numbers. Each section begins with a header,
11095 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11096 indexes, and a pool of 32-bit section numbers. The index sections will be
11097 aligned at 8-byte boundaries in the file.
11099 The index section header consists of:
11101 V, 32 bit version number
11103 N, 32 bit number of compilation units or type units in the index
11104 M, 32 bit number of slots in the hash table
11106 Numbers are recorded using the byte order of the application binary.
11108 The hash table begins at offset 16 in the section, and consists of an array
11109 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11110 order of the application binary). Unused slots in the hash table are 0.
11111 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11113 The parallel table begins immediately after the hash table
11114 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11115 array of 32-bit indexes (using the byte order of the application binary),
11116 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11117 table contains a 32-bit index into the pool of section numbers. For unused
11118 hash table slots, the corresponding entry in the parallel table will be 0.
11120 The pool of section numbers begins immediately following the hash table
11121 (at offset 16 + 12 * M from the beginning of the section). The pool of
11122 section numbers consists of an array of 32-bit words (using the byte order
11123 of the application binary). Each item in the array is indexed starting
11124 from 0. The hash table entry provides the index of the first section
11125 number in the set. Additional section numbers in the set follow, and the
11126 set is terminated by a 0 entry (section number 0 is not used in ELF).
11128 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11129 section must be the first entry in the set, and the .debug_abbrev.dwo must
11130 be the second entry. Other members of the set may follow in any order.
11136 DWP Version 2 combines all the .debug_info, etc. sections into one,
11137 and the entries in the index tables are now offsets into these sections.
11138 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11141 Index Section Contents:
11143 Hash Table of Signatures dwp_hash_table.hash_table
11144 Parallel Table of Indices dwp_hash_table.unit_table
11145 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11146 Table of Section Sizes dwp_hash_table.v2.sizes
11148 The index section header consists of:
11150 V, 32 bit version number
11151 L, 32 bit number of columns in the table of section offsets
11152 N, 32 bit number of compilation units or type units in the index
11153 M, 32 bit number of slots in the hash table
11155 Numbers are recorded using the byte order of the application binary.
11157 The hash table has the same format as version 1.
11158 The parallel table of indices has the same format as version 1,
11159 except that the entries are origin-1 indices into the table of sections
11160 offsets and the table of section sizes.
11162 The table of offsets begins immediately following the parallel table
11163 (at offset 16 + 12 * M from the beginning of the section). The table is
11164 a two-dimensional array of 32-bit words (using the byte order of the
11165 application binary), with L columns and N+1 rows, in row-major order.
11166 Each row in the array is indexed starting from 0. The first row provides
11167 a key to the remaining rows: each column in this row provides an identifier
11168 for a debug section, and the offsets in the same column of subsequent rows
11169 refer to that section. The section identifiers are:
11171 DW_SECT_INFO 1 .debug_info.dwo
11172 DW_SECT_TYPES 2 .debug_types.dwo
11173 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11174 DW_SECT_LINE 4 .debug_line.dwo
11175 DW_SECT_LOC 5 .debug_loc.dwo
11176 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11177 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11178 DW_SECT_MACRO 8 .debug_macro.dwo
11180 The offsets provided by the CU and TU index sections are the base offsets
11181 for the contributions made by each CU or TU to the corresponding section
11182 in the package file. Each CU and TU header contains an abbrev_offset
11183 field, used to find the abbreviations table for that CU or TU within the
11184 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11185 be interpreted as relative to the base offset given in the index section.
11186 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11187 should be interpreted as relative to the base offset for .debug_line.dwo,
11188 and offsets into other debug sections obtained from DWARF attributes should
11189 also be interpreted as relative to the corresponding base offset.
11191 The table of sizes begins immediately following the table of offsets.
11192 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11193 with L columns and N rows, in row-major order. Each row in the array is
11194 indexed starting from 1 (row 0 is shared by the two tables).
11198 Hash table lookup is handled the same in version 1 and 2:
11200 We assume that N and M will not exceed 2^32 - 1.
11201 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11203 Given a 64-bit compilation unit signature or a type signature S, an entry
11204 in the hash table is located as follows:
11206 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11207 the low-order k bits all set to 1.
11209 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11211 3) If the hash table entry at index H matches the signature, use that
11212 entry. If the hash table entry at index H is unused (all zeroes),
11213 terminate the search: the signature is not present in the table.
11215 4) Let H = (H + H') modulo M. Repeat at Step 3.
11217 Because M > N and H' and M are relatively prime, the search is guaranteed
11218 to stop at an unused slot or find the match. */
11220 /* Create a hash table to map DWO IDs to their CU/TU entry in
11221 .debug_{info,types}.dwo in DWP_FILE.
11222 Returns NULL if there isn't one.
11223 Note: This function processes DWP files only, not DWO files. */
11225 static struct dwp_hash_table
*
11226 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11227 struct dwp_file
*dwp_file
, int is_debug_types
)
11229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11230 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11231 const gdb_byte
*index_ptr
, *index_end
;
11232 struct dwarf2_section_info
*index
;
11233 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11234 struct dwp_hash_table
*htab
;
11236 if (is_debug_types
)
11237 index
= &dwp_file
->sections
.tu_index
;
11239 index
= &dwp_file
->sections
.cu_index
;
11241 if (index
->empty ())
11243 index
->read (objfile
);
11245 index_ptr
= index
->buffer
;
11246 index_end
= index_ptr
+ index
->size
;
11248 version
= read_4_bytes (dbfd
, index_ptr
);
11251 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11255 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11257 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11260 if (version
!= 1 && version
!= 2)
11262 error (_("Dwarf Error: unsupported DWP file version (%s)"
11263 " [in module %s]"),
11264 pulongest (version
), dwp_file
->name
);
11266 if (nr_slots
!= (nr_slots
& -nr_slots
))
11268 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11269 " is not power of 2 [in module %s]"),
11270 pulongest (nr_slots
), dwp_file
->name
);
11273 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11274 htab
->version
= version
;
11275 htab
->nr_columns
= nr_columns
;
11276 htab
->nr_units
= nr_units
;
11277 htab
->nr_slots
= nr_slots
;
11278 htab
->hash_table
= index_ptr
;
11279 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11281 /* Exit early if the table is empty. */
11282 if (nr_slots
== 0 || nr_units
== 0
11283 || (version
== 2 && nr_columns
== 0))
11285 /* All must be zero. */
11286 if (nr_slots
!= 0 || nr_units
!= 0
11287 || (version
== 2 && nr_columns
!= 0))
11289 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11290 " all zero [in modules %s]"),
11298 htab
->section_pool
.v1
.indices
=
11299 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11300 /* It's harder to decide whether the section is too small in v1.
11301 V1 is deprecated anyway so we punt. */
11305 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11306 int *ids
= htab
->section_pool
.v2
.section_ids
;
11307 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11308 /* Reverse map for error checking. */
11309 int ids_seen
[DW_SECT_MAX
+ 1];
11312 if (nr_columns
< 2)
11314 error (_("Dwarf Error: bad DWP hash table, too few columns"
11315 " in section table [in module %s]"),
11318 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11320 error (_("Dwarf Error: bad DWP hash table, too many columns"
11321 " in section table [in module %s]"),
11324 memset (ids
, 255, sizeof_ids
);
11325 memset (ids_seen
, 255, sizeof (ids_seen
));
11326 for (i
= 0; i
< nr_columns
; ++i
)
11328 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11330 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11332 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11333 " in section table [in module %s]"),
11334 id
, dwp_file
->name
);
11336 if (ids_seen
[id
] != -1)
11338 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11339 " id %d in section table [in module %s]"),
11340 id
, dwp_file
->name
);
11345 /* Must have exactly one info or types section. */
11346 if (((ids_seen
[DW_SECT_INFO
] != -1)
11347 + (ids_seen
[DW_SECT_TYPES
] != -1))
11350 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11351 " DWO info/types section [in module %s]"),
11354 /* Must have an abbrev section. */
11355 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11357 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11358 " section [in module %s]"),
11361 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11362 htab
->section_pool
.v2
.sizes
=
11363 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11364 * nr_units
* nr_columns
);
11365 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11366 * nr_units
* nr_columns
))
11369 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11370 " [in module %s]"),
11378 /* Update SECTIONS with the data from SECTP.
11380 This function is like the other "locate" section routines that are
11381 passed to bfd_map_over_sections, but in this context the sections to
11382 read comes from the DWP V1 hash table, not the full ELF section table.
11384 The result is non-zero for success, or zero if an error was found. */
11387 locate_v1_virtual_dwo_sections (asection
*sectp
,
11388 struct virtual_v1_dwo_sections
*sections
)
11390 const struct dwop_section_names
*names
= &dwop_section_names
;
11392 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11394 /* There can be only one. */
11395 if (sections
->abbrev
.s
.section
!= NULL
)
11397 sections
->abbrev
.s
.section
= sectp
;
11398 sections
->abbrev
.size
= bfd_section_size (sectp
);
11400 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11401 || section_is_p (sectp
->name
, &names
->types_dwo
))
11403 /* There can be only one. */
11404 if (sections
->info_or_types
.s
.section
!= NULL
)
11406 sections
->info_or_types
.s
.section
= sectp
;
11407 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11409 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11411 /* There can be only one. */
11412 if (sections
->line
.s
.section
!= NULL
)
11414 sections
->line
.s
.section
= sectp
;
11415 sections
->line
.size
= bfd_section_size (sectp
);
11417 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11419 /* There can be only one. */
11420 if (sections
->loc
.s
.section
!= NULL
)
11422 sections
->loc
.s
.section
= sectp
;
11423 sections
->loc
.size
= bfd_section_size (sectp
);
11425 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11427 /* There can be only one. */
11428 if (sections
->macinfo
.s
.section
!= NULL
)
11430 sections
->macinfo
.s
.section
= sectp
;
11431 sections
->macinfo
.size
= bfd_section_size (sectp
);
11433 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11435 /* There can be only one. */
11436 if (sections
->macro
.s
.section
!= NULL
)
11438 sections
->macro
.s
.section
= sectp
;
11439 sections
->macro
.size
= bfd_section_size (sectp
);
11441 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11443 /* There can be only one. */
11444 if (sections
->str_offsets
.s
.section
!= NULL
)
11446 sections
->str_offsets
.s
.section
= sectp
;
11447 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11451 /* No other kind of section is valid. */
11458 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11459 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11460 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11461 This is for DWP version 1 files. */
11463 static struct dwo_unit
*
11464 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11465 struct dwp_file
*dwp_file
,
11466 uint32_t unit_index
,
11467 const char *comp_dir
,
11468 ULONGEST signature
, int is_debug_types
)
11470 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11471 const struct dwp_hash_table
*dwp_htab
=
11472 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11473 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11474 const char *kind
= is_debug_types
? "TU" : "CU";
11475 struct dwo_file
*dwo_file
;
11476 struct dwo_unit
*dwo_unit
;
11477 struct virtual_v1_dwo_sections sections
;
11478 void **dwo_file_slot
;
11481 gdb_assert (dwp_file
->version
== 1);
11483 if (dwarf_read_debug
)
11485 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11487 pulongest (unit_index
), hex_string (signature
),
11491 /* Fetch the sections of this DWO unit.
11492 Put a limit on the number of sections we look for so that bad data
11493 doesn't cause us to loop forever. */
11495 #define MAX_NR_V1_DWO_SECTIONS \
11496 (1 /* .debug_info or .debug_types */ \
11497 + 1 /* .debug_abbrev */ \
11498 + 1 /* .debug_line */ \
11499 + 1 /* .debug_loc */ \
11500 + 1 /* .debug_str_offsets */ \
11501 + 1 /* .debug_macro or .debug_macinfo */ \
11502 + 1 /* trailing zero */)
11504 memset (§ions
, 0, sizeof (sections
));
11506 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11509 uint32_t section_nr
=
11510 read_4_bytes (dbfd
,
11511 dwp_htab
->section_pool
.v1
.indices
11512 + (unit_index
+ i
) * sizeof (uint32_t));
11514 if (section_nr
== 0)
11516 if (section_nr
>= dwp_file
->num_sections
)
11518 error (_("Dwarf Error: bad DWP hash table, section number too large"
11519 " [in module %s]"),
11523 sectp
= dwp_file
->elf_sections
[section_nr
];
11524 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11526 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11527 " [in module %s]"),
11533 || sections
.info_or_types
.empty ()
11534 || sections
.abbrev
.empty ())
11536 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11537 " [in module %s]"),
11540 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11542 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11543 " [in module %s]"),
11547 /* It's easier for the rest of the code if we fake a struct dwo_file and
11548 have dwo_unit "live" in that. At least for now.
11550 The DWP file can be made up of a random collection of CUs and TUs.
11551 However, for each CU + set of TUs that came from the same original DWO
11552 file, we can combine them back into a virtual DWO file to save space
11553 (fewer struct dwo_file objects to allocate). Remember that for really
11554 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11556 std::string virtual_dwo_name
=
11557 string_printf ("virtual-dwo/%d-%d-%d-%d",
11558 sections
.abbrev
.get_id (),
11559 sections
.line
.get_id (),
11560 sections
.loc
.get_id (),
11561 sections
.str_offsets
.get_id ());
11562 /* Can we use an existing virtual DWO file? */
11563 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11564 virtual_dwo_name
.c_str (),
11566 /* Create one if necessary. */
11567 if (*dwo_file_slot
== NULL
)
11569 if (dwarf_read_debug
)
11571 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11572 virtual_dwo_name
.c_str ());
11574 dwo_file
= new struct dwo_file
;
11575 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11576 dwo_file
->comp_dir
= comp_dir
;
11577 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11578 dwo_file
->sections
.line
= sections
.line
;
11579 dwo_file
->sections
.loc
= sections
.loc
;
11580 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11581 dwo_file
->sections
.macro
= sections
.macro
;
11582 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11583 /* The "str" section is global to the entire DWP file. */
11584 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11585 /* The info or types section is assigned below to dwo_unit,
11586 there's no need to record it in dwo_file.
11587 Also, we can't simply record type sections in dwo_file because
11588 we record a pointer into the vector in dwo_unit. As we collect more
11589 types we'll grow the vector and eventually have to reallocate space
11590 for it, invalidating all copies of pointers into the previous
11592 *dwo_file_slot
= dwo_file
;
11596 if (dwarf_read_debug
)
11598 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11599 virtual_dwo_name
.c_str ());
11601 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11604 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11605 dwo_unit
->dwo_file
= dwo_file
;
11606 dwo_unit
->signature
= signature
;
11607 dwo_unit
->section
=
11608 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11609 *dwo_unit
->section
= sections
.info_or_types
;
11610 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11615 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11616 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11617 piece within that section used by a TU/CU, return a virtual section
11618 of just that piece. */
11620 static struct dwarf2_section_info
11621 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11622 struct dwarf2_section_info
*section
,
11623 bfd_size_type offset
, bfd_size_type size
)
11625 struct dwarf2_section_info result
;
11628 gdb_assert (section
!= NULL
);
11629 gdb_assert (!section
->is_virtual
);
11631 memset (&result
, 0, sizeof (result
));
11632 result
.s
.containing_section
= section
;
11633 result
.is_virtual
= true;
11638 sectp
= section
->get_bfd_section ();
11640 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11641 bounds of the real section. This is a pretty-rare event, so just
11642 flag an error (easier) instead of a warning and trying to cope. */
11644 || offset
+ size
> bfd_section_size (sectp
))
11646 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11647 " in section %s [in module %s]"),
11648 sectp
? bfd_section_name (sectp
) : "<unknown>",
11649 objfile_name (dwarf2_per_objfile
->objfile
));
11652 result
.virtual_offset
= offset
;
11653 result
.size
= size
;
11657 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11658 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11659 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11660 This is for DWP version 2 files. */
11662 static struct dwo_unit
*
11663 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11664 struct dwp_file
*dwp_file
,
11665 uint32_t unit_index
,
11666 const char *comp_dir
,
11667 ULONGEST signature
, int is_debug_types
)
11669 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11670 const struct dwp_hash_table
*dwp_htab
=
11671 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11672 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11673 const char *kind
= is_debug_types
? "TU" : "CU";
11674 struct dwo_file
*dwo_file
;
11675 struct dwo_unit
*dwo_unit
;
11676 struct virtual_v2_dwo_sections sections
;
11677 void **dwo_file_slot
;
11680 gdb_assert (dwp_file
->version
== 2);
11682 if (dwarf_read_debug
)
11684 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11686 pulongest (unit_index
), hex_string (signature
),
11690 /* Fetch the section offsets of this DWO unit. */
11692 memset (§ions
, 0, sizeof (sections
));
11694 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11696 uint32_t offset
= read_4_bytes (dbfd
,
11697 dwp_htab
->section_pool
.v2
.offsets
11698 + (((unit_index
- 1) * dwp_htab
->nr_columns
11700 * sizeof (uint32_t)));
11701 uint32_t size
= read_4_bytes (dbfd
,
11702 dwp_htab
->section_pool
.v2
.sizes
11703 + (((unit_index
- 1) * dwp_htab
->nr_columns
11705 * sizeof (uint32_t)));
11707 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11710 case DW_SECT_TYPES
:
11711 sections
.info_or_types_offset
= offset
;
11712 sections
.info_or_types_size
= size
;
11714 case DW_SECT_ABBREV
:
11715 sections
.abbrev_offset
= offset
;
11716 sections
.abbrev_size
= size
;
11719 sections
.line_offset
= offset
;
11720 sections
.line_size
= size
;
11723 sections
.loc_offset
= offset
;
11724 sections
.loc_size
= size
;
11726 case DW_SECT_STR_OFFSETS
:
11727 sections
.str_offsets_offset
= offset
;
11728 sections
.str_offsets_size
= size
;
11730 case DW_SECT_MACINFO
:
11731 sections
.macinfo_offset
= offset
;
11732 sections
.macinfo_size
= size
;
11734 case DW_SECT_MACRO
:
11735 sections
.macro_offset
= offset
;
11736 sections
.macro_size
= size
;
11741 /* It's easier for the rest of the code if we fake a struct dwo_file and
11742 have dwo_unit "live" in that. At least for now.
11744 The DWP file can be made up of a random collection of CUs and TUs.
11745 However, for each CU + set of TUs that came from the same original DWO
11746 file, we can combine them back into a virtual DWO file to save space
11747 (fewer struct dwo_file objects to allocate). Remember that for really
11748 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11750 std::string virtual_dwo_name
=
11751 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11752 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11753 (long) (sections
.line_size
? sections
.line_offset
: 0),
11754 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11755 (long) (sections
.str_offsets_size
11756 ? sections
.str_offsets_offset
: 0));
11757 /* Can we use an existing virtual DWO file? */
11758 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11759 virtual_dwo_name
.c_str (),
11761 /* Create one if necessary. */
11762 if (*dwo_file_slot
== NULL
)
11764 if (dwarf_read_debug
)
11766 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11767 virtual_dwo_name
.c_str ());
11769 dwo_file
= new struct dwo_file
;
11770 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11771 dwo_file
->comp_dir
= comp_dir
;
11772 dwo_file
->sections
.abbrev
=
11773 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11774 sections
.abbrev_offset
, sections
.abbrev_size
);
11775 dwo_file
->sections
.line
=
11776 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11777 sections
.line_offset
, sections
.line_size
);
11778 dwo_file
->sections
.loc
=
11779 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11780 sections
.loc_offset
, sections
.loc_size
);
11781 dwo_file
->sections
.macinfo
=
11782 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11783 sections
.macinfo_offset
, sections
.macinfo_size
);
11784 dwo_file
->sections
.macro
=
11785 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11786 sections
.macro_offset
, sections
.macro_size
);
11787 dwo_file
->sections
.str_offsets
=
11788 create_dwp_v2_section (dwarf2_per_objfile
,
11789 &dwp_file
->sections
.str_offsets
,
11790 sections
.str_offsets_offset
,
11791 sections
.str_offsets_size
);
11792 /* The "str" section is global to the entire DWP file. */
11793 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11794 /* The info or types section is assigned below to dwo_unit,
11795 there's no need to record it in dwo_file.
11796 Also, we can't simply record type sections in dwo_file because
11797 we record a pointer into the vector in dwo_unit. As we collect more
11798 types we'll grow the vector and eventually have to reallocate space
11799 for it, invalidating all copies of pointers into the previous
11801 *dwo_file_slot
= dwo_file
;
11805 if (dwarf_read_debug
)
11807 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11808 virtual_dwo_name
.c_str ());
11810 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11813 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11814 dwo_unit
->dwo_file
= dwo_file
;
11815 dwo_unit
->signature
= signature
;
11816 dwo_unit
->section
=
11817 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11818 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11820 ? &dwp_file
->sections
.types
11821 : &dwp_file
->sections
.info
,
11822 sections
.info_or_types_offset
,
11823 sections
.info_or_types_size
);
11824 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11829 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11830 Returns NULL if the signature isn't found. */
11832 static struct dwo_unit
*
11833 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11834 struct dwp_file
*dwp_file
, const char *comp_dir
,
11835 ULONGEST signature
, int is_debug_types
)
11837 const struct dwp_hash_table
*dwp_htab
=
11838 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11839 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11840 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11841 uint32_t hash
= signature
& mask
;
11842 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11845 struct dwo_unit find_dwo_cu
;
11847 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11848 find_dwo_cu
.signature
= signature
;
11849 slot
= htab_find_slot (is_debug_types
11850 ? dwp_file
->loaded_tus
.get ()
11851 : dwp_file
->loaded_cus
.get (),
11852 &find_dwo_cu
, INSERT
);
11855 return (struct dwo_unit
*) *slot
;
11857 /* Use a for loop so that we don't loop forever on bad debug info. */
11858 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11860 ULONGEST signature_in_table
;
11862 signature_in_table
=
11863 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11864 if (signature_in_table
== signature
)
11866 uint32_t unit_index
=
11867 read_4_bytes (dbfd
,
11868 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11870 if (dwp_file
->version
== 1)
11872 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11873 dwp_file
, unit_index
,
11874 comp_dir
, signature
,
11879 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11880 dwp_file
, unit_index
,
11881 comp_dir
, signature
,
11884 return (struct dwo_unit
*) *slot
;
11886 if (signature_in_table
== 0)
11888 hash
= (hash
+ hash2
) & mask
;
11891 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11892 " [in module %s]"),
11896 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11897 Open the file specified by FILE_NAME and hand it off to BFD for
11898 preliminary analysis. Return a newly initialized bfd *, which
11899 includes a canonicalized copy of FILE_NAME.
11900 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11901 SEARCH_CWD is true if the current directory is to be searched.
11902 It will be searched before debug-file-directory.
11903 If successful, the file is added to the bfd include table of the
11904 objfile's bfd (see gdb_bfd_record_inclusion).
11905 If unable to find/open the file, return NULL.
11906 NOTE: This function is derived from symfile_bfd_open. */
11908 static gdb_bfd_ref_ptr
11909 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11910 const char *file_name
, int is_dwp
, int search_cwd
)
11913 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11914 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11915 to debug_file_directory. */
11916 const char *search_path
;
11917 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11919 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11922 if (*debug_file_directory
!= '\0')
11924 search_path_holder
.reset (concat (".", dirname_separator_string
,
11925 debug_file_directory
,
11927 search_path
= search_path_holder
.get ();
11933 search_path
= debug_file_directory
;
11935 openp_flags flags
= OPF_RETURN_REALPATH
;
11937 flags
|= OPF_SEARCH_IN_PATH
;
11939 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11940 desc
= openp (search_path
, flags
, file_name
,
11941 O_RDONLY
| O_BINARY
, &absolute_name
);
11945 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11947 if (sym_bfd
== NULL
)
11949 bfd_set_cacheable (sym_bfd
.get (), 1);
11951 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11954 /* Success. Record the bfd as having been included by the objfile's bfd.
11955 This is important because things like demangled_names_hash lives in the
11956 objfile's per_bfd space and may have references to things like symbol
11957 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11958 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11963 /* Try to open DWO file FILE_NAME.
11964 COMP_DIR is the DW_AT_comp_dir attribute.
11965 The result is the bfd handle of the file.
11966 If there is a problem finding or opening the file, return NULL.
11967 Upon success, the canonicalized path of the file is stored in the bfd,
11968 same as symfile_bfd_open. */
11970 static gdb_bfd_ref_ptr
11971 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11972 const char *file_name
, const char *comp_dir
)
11974 if (IS_ABSOLUTE_PATH (file_name
))
11975 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
11976 0 /*is_dwp*/, 0 /*search_cwd*/);
11978 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11980 if (comp_dir
!= NULL
)
11982 gdb::unique_xmalloc_ptr
<char> path_to_try
11983 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
11985 /* NOTE: If comp_dir is a relative path, this will also try the
11986 search path, which seems useful. */
11987 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
11988 path_to_try
.get (),
11990 1 /*search_cwd*/));
11995 /* That didn't work, try debug-file-directory, which, despite its name,
11996 is a list of paths. */
11998 if (*debug_file_directory
== '\0')
12001 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12002 0 /*is_dwp*/, 1 /*search_cwd*/);
12005 /* This function is mapped across the sections and remembers the offset and
12006 size of each of the DWO debugging sections we are interested in. */
12009 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12011 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12012 const struct dwop_section_names
*names
= &dwop_section_names
;
12014 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12016 dwo_sections
->abbrev
.s
.section
= sectp
;
12017 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12019 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12021 dwo_sections
->info
.s
.section
= sectp
;
12022 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12024 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12026 dwo_sections
->line
.s
.section
= sectp
;
12027 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12029 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12031 dwo_sections
->loc
.s
.section
= sectp
;
12032 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12034 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12036 dwo_sections
->macinfo
.s
.section
= sectp
;
12037 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12039 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12041 dwo_sections
->macro
.s
.section
= sectp
;
12042 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12044 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12046 dwo_sections
->str
.s
.section
= sectp
;
12047 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12049 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12051 dwo_sections
->str_offsets
.s
.section
= sectp
;
12052 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12054 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12056 struct dwarf2_section_info type_section
;
12058 memset (&type_section
, 0, sizeof (type_section
));
12059 type_section
.s
.section
= sectp
;
12060 type_section
.size
= bfd_section_size (sectp
);
12061 dwo_sections
->types
.push_back (type_section
);
12065 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12066 by PER_CU. This is for the non-DWP case.
12067 The result is NULL if DWO_NAME can't be found. */
12069 static struct dwo_file
*
12070 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12071 const char *dwo_name
, const char *comp_dir
)
12073 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12075 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12078 if (dwarf_read_debug
)
12079 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12083 dwo_file_up
dwo_file (new struct dwo_file
);
12084 dwo_file
->dwo_name
= dwo_name
;
12085 dwo_file
->comp_dir
= comp_dir
;
12086 dwo_file
->dbfd
= std::move (dbfd
);
12088 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12089 &dwo_file
->sections
);
12091 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12092 dwo_file
->sections
.info
, dwo_file
->cus
);
12094 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12095 dwo_file
->sections
.types
, dwo_file
->tus
);
12097 if (dwarf_read_debug
)
12098 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12100 return dwo_file
.release ();
12103 /* This function is mapped across the sections and remembers the offset and
12104 size of each of the DWP debugging sections common to version 1 and 2 that
12105 we are interested in. */
12108 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12109 void *dwp_file_ptr
)
12111 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12112 const struct dwop_section_names
*names
= &dwop_section_names
;
12113 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12115 /* Record the ELF section number for later lookup: this is what the
12116 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12117 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12118 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12120 /* Look for specific sections that we need. */
12121 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12123 dwp_file
->sections
.str
.s
.section
= sectp
;
12124 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12126 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12128 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12129 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12131 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12133 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12134 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12138 /* This function is mapped across the sections and remembers the offset and
12139 size of each of the DWP version 2 debugging sections that we are interested
12140 in. This is split into a separate function because we don't know if we
12141 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12144 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12146 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12147 const struct dwop_section_names
*names
= &dwop_section_names
;
12148 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12150 /* Record the ELF section number for later lookup: this is what the
12151 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12152 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12153 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12155 /* Look for specific sections that we need. */
12156 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12158 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12159 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12161 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12163 dwp_file
->sections
.info
.s
.section
= sectp
;
12164 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12166 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12168 dwp_file
->sections
.line
.s
.section
= sectp
;
12169 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12171 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12173 dwp_file
->sections
.loc
.s
.section
= sectp
;
12174 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12176 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12178 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12179 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12181 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12183 dwp_file
->sections
.macro
.s
.section
= sectp
;
12184 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12186 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12188 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12189 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12191 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12193 dwp_file
->sections
.types
.s
.section
= sectp
;
12194 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12198 /* Hash function for dwp_file loaded CUs/TUs. */
12201 hash_dwp_loaded_cutus (const void *item
)
12203 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12205 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12206 return dwo_unit
->signature
;
12209 /* Equality function for dwp_file loaded CUs/TUs. */
12212 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12214 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12215 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12217 return dua
->signature
== dub
->signature
;
12220 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12223 allocate_dwp_loaded_cutus_table ()
12225 return htab_up (htab_create_alloc (3,
12226 hash_dwp_loaded_cutus
,
12227 eq_dwp_loaded_cutus
,
12228 NULL
, xcalloc
, xfree
));
12231 /* Try to open DWP file FILE_NAME.
12232 The result is the bfd handle of the file.
12233 If there is a problem finding or opening the file, return NULL.
12234 Upon success, the canonicalized path of the file is stored in the bfd,
12235 same as symfile_bfd_open. */
12237 static gdb_bfd_ref_ptr
12238 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12239 const char *file_name
)
12241 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12243 1 /*search_cwd*/));
12247 /* Work around upstream bug 15652.
12248 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12249 [Whether that's a "bug" is debatable, but it is getting in our way.]
12250 We have no real idea where the dwp file is, because gdb's realpath-ing
12251 of the executable's path may have discarded the needed info.
12252 [IWBN if the dwp file name was recorded in the executable, akin to
12253 .gnu_debuglink, but that doesn't exist yet.]
12254 Strip the directory from FILE_NAME and search again. */
12255 if (*debug_file_directory
!= '\0')
12257 /* Don't implicitly search the current directory here.
12258 If the user wants to search "." to handle this case,
12259 it must be added to debug-file-directory. */
12260 return try_open_dwop_file (dwarf2_per_objfile
,
12261 lbasename (file_name
), 1 /*is_dwp*/,
12268 /* Initialize the use of the DWP file for the current objfile.
12269 By convention the name of the DWP file is ${objfile}.dwp.
12270 The result is NULL if it can't be found. */
12272 static std::unique_ptr
<struct dwp_file
>
12273 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12277 /* Try to find first .dwp for the binary file before any symbolic links
12280 /* If the objfile is a debug file, find the name of the real binary
12281 file and get the name of dwp file from there. */
12282 std::string dwp_name
;
12283 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12285 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12286 const char *backlink_basename
= lbasename (backlink
->original_name
);
12288 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12291 dwp_name
= objfile
->original_name
;
12293 dwp_name
+= ".dwp";
12295 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12297 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12299 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12300 dwp_name
= objfile_name (objfile
);
12301 dwp_name
+= ".dwp";
12302 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12307 if (dwarf_read_debug
)
12308 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12309 return std::unique_ptr
<dwp_file
> ();
12312 const char *name
= bfd_get_filename (dbfd
.get ());
12313 std::unique_ptr
<struct dwp_file
> dwp_file
12314 (new struct dwp_file (name
, std::move (dbfd
)));
12316 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12317 dwp_file
->elf_sections
=
12318 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12319 dwp_file
->num_sections
, asection
*);
12321 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12322 dwarf2_locate_common_dwp_sections
,
12325 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12328 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12331 /* The DWP file version is stored in the hash table. Oh well. */
12332 if (dwp_file
->cus
&& dwp_file
->tus
12333 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12335 /* Technically speaking, we should try to limp along, but this is
12336 pretty bizarre. We use pulongest here because that's the established
12337 portability solution (e.g, we cannot use %u for uint32_t). */
12338 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12339 " TU version %s [in DWP file %s]"),
12340 pulongest (dwp_file
->cus
->version
),
12341 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12345 dwp_file
->version
= dwp_file
->cus
->version
;
12346 else if (dwp_file
->tus
)
12347 dwp_file
->version
= dwp_file
->tus
->version
;
12349 dwp_file
->version
= 2;
12351 if (dwp_file
->version
== 2)
12352 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12353 dwarf2_locate_v2_dwp_sections
,
12356 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12357 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12359 if (dwarf_read_debug
)
12361 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12362 fprintf_unfiltered (gdb_stdlog
,
12363 " %s CUs, %s TUs\n",
12364 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12365 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12371 /* Wrapper around open_and_init_dwp_file, only open it once. */
12373 static struct dwp_file
*
12374 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12376 if (! dwarf2_per_objfile
->dwp_checked
)
12378 dwarf2_per_objfile
->dwp_file
12379 = open_and_init_dwp_file (dwarf2_per_objfile
);
12380 dwarf2_per_objfile
->dwp_checked
= 1;
12382 return dwarf2_per_objfile
->dwp_file
.get ();
12385 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12386 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12387 or in the DWP file for the objfile, referenced by THIS_UNIT.
12388 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12389 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12391 This is called, for example, when wanting to read a variable with a
12392 complex location. Therefore we don't want to do file i/o for every call.
12393 Therefore we don't want to look for a DWO file on every call.
12394 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12395 then we check if we've already seen DWO_NAME, and only THEN do we check
12398 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12399 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12401 static struct dwo_unit
*
12402 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12403 const char *dwo_name
, const char *comp_dir
,
12404 ULONGEST signature
, int is_debug_types
)
12406 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12407 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12408 const char *kind
= is_debug_types
? "TU" : "CU";
12409 void **dwo_file_slot
;
12410 struct dwo_file
*dwo_file
;
12411 struct dwp_file
*dwp_file
;
12413 /* First see if there's a DWP file.
12414 If we have a DWP file but didn't find the DWO inside it, don't
12415 look for the original DWO file. It makes gdb behave differently
12416 depending on whether one is debugging in the build tree. */
12418 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12419 if (dwp_file
!= NULL
)
12421 const struct dwp_hash_table
*dwp_htab
=
12422 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12424 if (dwp_htab
!= NULL
)
12426 struct dwo_unit
*dwo_cutu
=
12427 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12428 signature
, is_debug_types
);
12430 if (dwo_cutu
!= NULL
)
12432 if (dwarf_read_debug
)
12434 fprintf_unfiltered (gdb_stdlog
,
12435 "Virtual DWO %s %s found: @%s\n",
12436 kind
, hex_string (signature
),
12437 host_address_to_string (dwo_cutu
));
12445 /* No DWP file, look for the DWO file. */
12447 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12448 dwo_name
, comp_dir
);
12449 if (*dwo_file_slot
== NULL
)
12451 /* Read in the file and build a table of the CUs/TUs it contains. */
12452 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12454 /* NOTE: This will be NULL if unable to open the file. */
12455 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12457 if (dwo_file
!= NULL
)
12459 struct dwo_unit
*dwo_cutu
= NULL
;
12461 if (is_debug_types
&& dwo_file
->tus
)
12463 struct dwo_unit find_dwo_cutu
;
12465 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12466 find_dwo_cutu
.signature
= signature
;
12468 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12471 else if (!is_debug_types
&& dwo_file
->cus
)
12473 struct dwo_unit find_dwo_cutu
;
12475 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12476 find_dwo_cutu
.signature
= signature
;
12477 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12481 if (dwo_cutu
!= NULL
)
12483 if (dwarf_read_debug
)
12485 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12486 kind
, dwo_name
, hex_string (signature
),
12487 host_address_to_string (dwo_cutu
));
12494 /* We didn't find it. This could mean a dwo_id mismatch, or
12495 someone deleted the DWO/DWP file, or the search path isn't set up
12496 correctly to find the file. */
12498 if (dwarf_read_debug
)
12500 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12501 kind
, dwo_name
, hex_string (signature
));
12504 /* This is a warning and not a complaint because it can be caused by
12505 pilot error (e.g., user accidentally deleting the DWO). */
12507 /* Print the name of the DWP file if we looked there, helps the user
12508 better diagnose the problem. */
12509 std::string dwp_text
;
12511 if (dwp_file
!= NULL
)
12512 dwp_text
= string_printf (" [in DWP file %s]",
12513 lbasename (dwp_file
->name
));
12515 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12516 " [in module %s]"),
12517 kind
, dwo_name
, hex_string (signature
),
12519 this_unit
->is_debug_types
? "TU" : "CU",
12520 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12525 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12526 See lookup_dwo_cutu_unit for details. */
12528 static struct dwo_unit
*
12529 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12530 const char *dwo_name
, const char *comp_dir
,
12531 ULONGEST signature
)
12533 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12536 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12537 See lookup_dwo_cutu_unit for details. */
12539 static struct dwo_unit
*
12540 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12541 const char *dwo_name
, const char *comp_dir
)
12543 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12546 /* Traversal function for queue_and_load_all_dwo_tus. */
12549 queue_and_load_dwo_tu (void **slot
, void *info
)
12551 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12552 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12553 ULONGEST signature
= dwo_unit
->signature
;
12554 struct signatured_type
*sig_type
=
12555 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12557 if (sig_type
!= NULL
)
12559 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12561 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12562 a real dependency of PER_CU on SIG_TYPE. That is detected later
12563 while processing PER_CU. */
12564 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12565 load_full_type_unit (sig_cu
);
12566 per_cu
->imported_symtabs_push (sig_cu
);
12572 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12573 The DWO may have the only definition of the type, though it may not be
12574 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12575 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12578 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12580 struct dwo_unit
*dwo_unit
;
12581 struct dwo_file
*dwo_file
;
12583 gdb_assert (!per_cu
->is_debug_types
);
12584 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12585 gdb_assert (per_cu
->cu
!= NULL
);
12587 dwo_unit
= per_cu
->cu
->dwo_unit
;
12588 gdb_assert (dwo_unit
!= NULL
);
12590 dwo_file
= dwo_unit
->dwo_file
;
12591 if (dwo_file
->tus
!= NULL
)
12592 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12596 /* Read in various DIEs. */
12598 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12599 Inherit only the children of the DW_AT_abstract_origin DIE not being
12600 already referenced by DW_AT_abstract_origin from the children of the
12604 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12606 struct die_info
*child_die
;
12607 sect_offset
*offsetp
;
12608 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12609 struct die_info
*origin_die
;
12610 /* Iterator of the ORIGIN_DIE children. */
12611 struct die_info
*origin_child_die
;
12612 struct attribute
*attr
;
12613 struct dwarf2_cu
*origin_cu
;
12614 struct pending
**origin_previous_list_in_scope
;
12616 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12620 /* Note that following die references may follow to a die in a
12624 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12626 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12628 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12629 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12631 if (die
->tag
!= origin_die
->tag
12632 && !(die
->tag
== DW_TAG_inlined_subroutine
12633 && origin_die
->tag
== DW_TAG_subprogram
))
12634 complaint (_("DIE %s and its abstract origin %s have different tags"),
12635 sect_offset_str (die
->sect_off
),
12636 sect_offset_str (origin_die
->sect_off
));
12638 std::vector
<sect_offset
> offsets
;
12640 for (child_die
= die
->child
;
12641 child_die
&& child_die
->tag
;
12642 child_die
= child_die
->sibling
)
12644 struct die_info
*child_origin_die
;
12645 struct dwarf2_cu
*child_origin_cu
;
12647 /* We are trying to process concrete instance entries:
12648 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12649 it's not relevant to our analysis here. i.e. detecting DIEs that are
12650 present in the abstract instance but not referenced in the concrete
12652 if (child_die
->tag
== DW_TAG_call_site
12653 || child_die
->tag
== DW_TAG_GNU_call_site
)
12656 /* For each CHILD_DIE, find the corresponding child of
12657 ORIGIN_DIE. If there is more than one layer of
12658 DW_AT_abstract_origin, follow them all; there shouldn't be,
12659 but GCC versions at least through 4.4 generate this (GCC PR
12661 child_origin_die
= child_die
;
12662 child_origin_cu
= cu
;
12665 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12669 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12673 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12674 counterpart may exist. */
12675 if (child_origin_die
!= child_die
)
12677 if (child_die
->tag
!= child_origin_die
->tag
12678 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12679 && child_origin_die
->tag
== DW_TAG_subprogram
))
12680 complaint (_("Child DIE %s and its abstract origin %s have "
12682 sect_offset_str (child_die
->sect_off
),
12683 sect_offset_str (child_origin_die
->sect_off
));
12684 if (child_origin_die
->parent
!= origin_die
)
12685 complaint (_("Child DIE %s and its abstract origin %s have "
12686 "different parents"),
12687 sect_offset_str (child_die
->sect_off
),
12688 sect_offset_str (child_origin_die
->sect_off
));
12690 offsets
.push_back (child_origin_die
->sect_off
);
12693 std::sort (offsets
.begin (), offsets
.end ());
12694 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12695 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12696 if (offsetp
[-1] == *offsetp
)
12697 complaint (_("Multiple children of DIE %s refer "
12698 "to DIE %s as their abstract origin"),
12699 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12701 offsetp
= offsets
.data ();
12702 origin_child_die
= origin_die
->child
;
12703 while (origin_child_die
&& origin_child_die
->tag
)
12705 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12706 while (offsetp
< offsets_end
12707 && *offsetp
< origin_child_die
->sect_off
)
12709 if (offsetp
>= offsets_end
12710 || *offsetp
> origin_child_die
->sect_off
)
12712 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12713 Check whether we're already processing ORIGIN_CHILD_DIE.
12714 This can happen with mutually referenced abstract_origins.
12716 if (!origin_child_die
->in_process
)
12717 process_die (origin_child_die
, origin_cu
);
12719 origin_child_die
= origin_child_die
->sibling
;
12721 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12723 if (cu
!= origin_cu
)
12724 compute_delayed_physnames (origin_cu
);
12728 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12730 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12731 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12732 struct context_stack
*newobj
;
12735 struct die_info
*child_die
;
12736 struct attribute
*attr
, *call_line
, *call_file
;
12738 CORE_ADDR baseaddr
;
12739 struct block
*block
;
12740 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12741 std::vector
<struct symbol
*> template_args
;
12742 struct template_symbol
*templ_func
= NULL
;
12746 /* If we do not have call site information, we can't show the
12747 caller of this inlined function. That's too confusing, so
12748 only use the scope for local variables. */
12749 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12750 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12751 if (call_line
== NULL
|| call_file
== NULL
)
12753 read_lexical_block_scope (die
, cu
);
12758 baseaddr
= objfile
->text_section_offset ();
12760 name
= dwarf2_name (die
, cu
);
12762 /* Ignore functions with missing or empty names. These are actually
12763 illegal according to the DWARF standard. */
12766 complaint (_("missing name for subprogram DIE at %s"),
12767 sect_offset_str (die
->sect_off
));
12771 /* Ignore functions with missing or invalid low and high pc attributes. */
12772 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12773 <= PC_BOUNDS_INVALID
)
12775 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12776 if (!attr
|| !DW_UNSND (attr
))
12777 complaint (_("cannot get low and high bounds "
12778 "for subprogram DIE at %s"),
12779 sect_offset_str (die
->sect_off
));
12783 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12784 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12786 /* If we have any template arguments, then we must allocate a
12787 different sort of symbol. */
12788 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12790 if (child_die
->tag
== DW_TAG_template_type_param
12791 || child_die
->tag
== DW_TAG_template_value_param
)
12793 templ_func
= allocate_template_symbol (objfile
);
12794 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12799 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12800 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12801 (struct symbol
*) templ_func
);
12803 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12804 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12807 /* If there is a location expression for DW_AT_frame_base, record
12809 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12810 if (attr
!= nullptr)
12811 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12813 /* If there is a location for the static link, record it. */
12814 newobj
->static_link
= NULL
;
12815 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12816 if (attr
!= nullptr)
12818 newobj
->static_link
12819 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12820 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12821 cu
->per_cu
->addr_type ());
12824 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12826 if (die
->child
!= NULL
)
12828 child_die
= die
->child
;
12829 while (child_die
&& child_die
->tag
)
12831 if (child_die
->tag
== DW_TAG_template_type_param
12832 || child_die
->tag
== DW_TAG_template_value_param
)
12834 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12837 template_args
.push_back (arg
);
12840 process_die (child_die
, cu
);
12841 child_die
= child_die
->sibling
;
12845 inherit_abstract_dies (die
, cu
);
12847 /* If we have a DW_AT_specification, we might need to import using
12848 directives from the context of the specification DIE. See the
12849 comment in determine_prefix. */
12850 if (cu
->language
== language_cplus
12851 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12853 struct dwarf2_cu
*spec_cu
= cu
;
12854 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12858 child_die
= spec_die
->child
;
12859 while (child_die
&& child_die
->tag
)
12861 if (child_die
->tag
== DW_TAG_imported_module
)
12862 process_die (child_die
, spec_cu
);
12863 child_die
= child_die
->sibling
;
12866 /* In some cases, GCC generates specification DIEs that
12867 themselves contain DW_AT_specification attributes. */
12868 spec_die
= die_specification (spec_die
, &spec_cu
);
12872 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12873 /* Make a block for the local symbols within. */
12874 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12875 cstk
.static_link
, lowpc
, highpc
);
12877 /* For C++, set the block's scope. */
12878 if ((cu
->language
== language_cplus
12879 || cu
->language
== language_fortran
12880 || cu
->language
== language_d
12881 || cu
->language
== language_rust
)
12882 && cu
->processing_has_namespace_info
)
12883 block_set_scope (block
, determine_prefix (die
, cu
),
12884 &objfile
->objfile_obstack
);
12886 /* If we have address ranges, record them. */
12887 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12889 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12891 /* Attach template arguments to function. */
12892 if (!template_args
.empty ())
12894 gdb_assert (templ_func
!= NULL
);
12896 templ_func
->n_template_arguments
= template_args
.size ();
12897 templ_func
->template_arguments
12898 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12899 templ_func
->n_template_arguments
);
12900 memcpy (templ_func
->template_arguments
,
12901 template_args
.data (),
12902 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12904 /* Make sure that the symtab is set on the new symbols. Even
12905 though they don't appear in this symtab directly, other parts
12906 of gdb assume that symbols do, and this is reasonably
12908 for (symbol
*sym
: template_args
)
12909 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12912 /* In C++, we can have functions nested inside functions (e.g., when
12913 a function declares a class that has methods). This means that
12914 when we finish processing a function scope, we may need to go
12915 back to building a containing block's symbol lists. */
12916 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12917 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12919 /* If we've finished processing a top-level function, subsequent
12920 symbols go in the file symbol list. */
12921 if (cu
->get_builder ()->outermost_context_p ())
12922 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12925 /* Process all the DIES contained within a lexical block scope. Start
12926 a new scope, process the dies, and then close the scope. */
12929 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12932 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12933 CORE_ADDR lowpc
, highpc
;
12934 struct die_info
*child_die
;
12935 CORE_ADDR baseaddr
;
12937 baseaddr
= objfile
->text_section_offset ();
12939 /* Ignore blocks with missing or invalid low and high pc attributes. */
12940 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12941 as multiple lexical blocks? Handling children in a sane way would
12942 be nasty. Might be easier to properly extend generic blocks to
12943 describe ranges. */
12944 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12946 case PC_BOUNDS_NOT_PRESENT
:
12947 /* DW_TAG_lexical_block has no attributes, process its children as if
12948 there was no wrapping by that DW_TAG_lexical_block.
12949 GCC does no longer produces such DWARF since GCC r224161. */
12950 for (child_die
= die
->child
;
12951 child_die
!= NULL
&& child_die
->tag
;
12952 child_die
= child_die
->sibling
)
12953 process_die (child_die
, cu
);
12955 case PC_BOUNDS_INVALID
:
12958 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12959 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12961 cu
->get_builder ()->push_context (0, lowpc
);
12962 if (die
->child
!= NULL
)
12964 child_die
= die
->child
;
12965 while (child_die
&& child_die
->tag
)
12967 process_die (child_die
, cu
);
12968 child_die
= child_die
->sibling
;
12971 inherit_abstract_dies (die
, cu
);
12972 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12974 if (*cu
->get_builder ()->get_local_symbols () != NULL
12975 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
12977 struct block
*block
12978 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
12979 cstk
.start_addr
, highpc
);
12981 /* Note that recording ranges after traversing children, as we
12982 do here, means that recording a parent's ranges entails
12983 walking across all its children's ranges as they appear in
12984 the address map, which is quadratic behavior.
12986 It would be nicer to record the parent's ranges before
12987 traversing its children, simply overriding whatever you find
12988 there. But since we don't even decide whether to create a
12989 block until after we've traversed its children, that's hard
12991 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12993 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12994 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12997 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13000 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13002 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13003 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13004 CORE_ADDR pc
, baseaddr
;
13005 struct attribute
*attr
;
13006 struct call_site
*call_site
, call_site_local
;
13009 struct die_info
*child_die
;
13011 baseaddr
= objfile
->text_section_offset ();
13013 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13016 /* This was a pre-DWARF-5 GNU extension alias
13017 for DW_AT_call_return_pc. */
13018 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13022 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13023 "DIE %s [in module %s]"),
13024 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13027 pc
= attr
->value_as_address () + baseaddr
;
13028 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13030 if (cu
->call_site_htab
== NULL
)
13031 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13032 NULL
, &objfile
->objfile_obstack
,
13033 hashtab_obstack_allocate
, NULL
);
13034 call_site_local
.pc
= pc
;
13035 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13038 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13039 "DIE %s [in module %s]"),
13040 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13041 objfile_name (objfile
));
13045 /* Count parameters at the caller. */
13048 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13049 child_die
= child_die
->sibling
)
13051 if (child_die
->tag
!= DW_TAG_call_site_parameter
13052 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13054 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13055 "DW_TAG_call_site child DIE %s [in module %s]"),
13056 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13057 objfile_name (objfile
));
13065 = ((struct call_site
*)
13066 obstack_alloc (&objfile
->objfile_obstack
,
13067 sizeof (*call_site
)
13068 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13070 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13071 call_site
->pc
= pc
;
13073 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13074 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13076 struct die_info
*func_die
;
13078 /* Skip also over DW_TAG_inlined_subroutine. */
13079 for (func_die
= die
->parent
;
13080 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13081 && func_die
->tag
!= DW_TAG_subroutine_type
;
13082 func_die
= func_die
->parent
);
13084 /* DW_AT_call_all_calls is a superset
13085 of DW_AT_call_all_tail_calls. */
13087 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13088 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13089 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13090 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13092 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13093 not complete. But keep CALL_SITE for look ups via call_site_htab,
13094 both the initial caller containing the real return address PC and
13095 the final callee containing the current PC of a chain of tail
13096 calls do not need to have the tail call list complete. But any
13097 function candidate for a virtual tail call frame searched via
13098 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13099 determined unambiguously. */
13103 struct type
*func_type
= NULL
;
13106 func_type
= get_die_type (func_die
, cu
);
13107 if (func_type
!= NULL
)
13109 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13111 /* Enlist this call site to the function. */
13112 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13113 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13116 complaint (_("Cannot find function owning DW_TAG_call_site "
13117 "DIE %s [in module %s]"),
13118 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13122 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13124 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13126 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13129 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13130 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13132 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13133 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13134 /* Keep NULL DWARF_BLOCK. */;
13135 else if (attr
->form_is_block ())
13137 struct dwarf2_locexpr_baton
*dlbaton
;
13139 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13140 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13141 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13142 dlbaton
->per_cu
= cu
->per_cu
;
13144 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13146 else if (attr
->form_is_ref ())
13148 struct dwarf2_cu
*target_cu
= cu
;
13149 struct die_info
*target_die
;
13151 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13152 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13153 if (die_is_declaration (target_die
, target_cu
))
13155 const char *target_physname
;
13157 /* Prefer the mangled name; otherwise compute the demangled one. */
13158 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13159 if (target_physname
== NULL
)
13160 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13161 if (target_physname
== NULL
)
13162 complaint (_("DW_AT_call_target target DIE has invalid "
13163 "physname, for referencing DIE %s [in module %s]"),
13164 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13166 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13172 /* DW_AT_entry_pc should be preferred. */
13173 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13174 <= PC_BOUNDS_INVALID
)
13175 complaint (_("DW_AT_call_target target DIE has invalid "
13176 "low pc, for referencing DIE %s [in module %s]"),
13177 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13180 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13181 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13186 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13187 "block nor reference, for DIE %s [in module %s]"),
13188 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13190 call_site
->per_cu
= cu
->per_cu
;
13192 for (child_die
= die
->child
;
13193 child_die
&& child_die
->tag
;
13194 child_die
= child_die
->sibling
)
13196 struct call_site_parameter
*parameter
;
13197 struct attribute
*loc
, *origin
;
13199 if (child_die
->tag
!= DW_TAG_call_site_parameter
13200 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13202 /* Already printed the complaint above. */
13206 gdb_assert (call_site
->parameter_count
< nparams
);
13207 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13209 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13210 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13211 register is contained in DW_AT_call_value. */
13213 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13214 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13215 if (origin
== NULL
)
13217 /* This was a pre-DWARF-5 GNU extension alias
13218 for DW_AT_call_parameter. */
13219 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13221 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13223 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13225 sect_offset sect_off
= origin
->get_ref_die_offset ();
13226 if (!cu
->header
.offset_in_cu_p (sect_off
))
13228 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13229 binding can be done only inside one CU. Such referenced DIE
13230 therefore cannot be even moved to DW_TAG_partial_unit. */
13231 complaint (_("DW_AT_call_parameter offset is not in CU for "
13232 "DW_TAG_call_site child DIE %s [in module %s]"),
13233 sect_offset_str (child_die
->sect_off
),
13234 objfile_name (objfile
));
13237 parameter
->u
.param_cu_off
13238 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13240 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13242 complaint (_("No DW_FORM_block* DW_AT_location for "
13243 "DW_TAG_call_site child DIE %s [in module %s]"),
13244 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13249 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13250 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13251 if (parameter
->u
.dwarf_reg
!= -1)
13252 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13253 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13254 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13255 ¶meter
->u
.fb_offset
))
13256 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13259 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13260 "for DW_FORM_block* DW_AT_location is supported for "
13261 "DW_TAG_call_site child DIE %s "
13263 sect_offset_str (child_die
->sect_off
),
13264 objfile_name (objfile
));
13269 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13271 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13272 if (attr
== NULL
|| !attr
->form_is_block ())
13274 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13275 "DW_TAG_call_site child DIE %s [in module %s]"),
13276 sect_offset_str (child_die
->sect_off
),
13277 objfile_name (objfile
));
13280 parameter
->value
= DW_BLOCK (attr
)->data
;
13281 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13283 /* Parameters are not pre-cleared by memset above. */
13284 parameter
->data_value
= NULL
;
13285 parameter
->data_value_size
= 0;
13286 call_site
->parameter_count
++;
13288 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13290 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13291 if (attr
!= nullptr)
13293 if (!attr
->form_is_block ())
13294 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13295 "DW_TAG_call_site child DIE %s [in module %s]"),
13296 sect_offset_str (child_die
->sect_off
),
13297 objfile_name (objfile
));
13300 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13301 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13307 /* Helper function for read_variable. If DIE represents a virtual
13308 table, then return the type of the concrete object that is
13309 associated with the virtual table. Otherwise, return NULL. */
13311 static struct type
*
13312 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13314 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13318 /* Find the type DIE. */
13319 struct die_info
*type_die
= NULL
;
13320 struct dwarf2_cu
*type_cu
= cu
;
13322 if (attr
->form_is_ref ())
13323 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13324 if (type_die
== NULL
)
13327 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13329 return die_containing_type (type_die
, type_cu
);
13332 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13335 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13337 struct rust_vtable_symbol
*storage
= NULL
;
13339 if (cu
->language
== language_rust
)
13341 struct type
*containing_type
= rust_containing_type (die
, cu
);
13343 if (containing_type
!= NULL
)
13345 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13347 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13348 initialize_objfile_symbol (storage
);
13349 storage
->concrete_type
= containing_type
;
13350 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13354 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13355 struct attribute
*abstract_origin
13356 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13357 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13358 if (res
== NULL
&& loc
&& abstract_origin
)
13360 /* We have a variable without a name, but with a location and an abstract
13361 origin. This may be a concrete instance of an abstract variable
13362 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13364 struct dwarf2_cu
*origin_cu
= cu
;
13365 struct die_info
*origin_die
13366 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13367 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13368 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13372 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13373 reading .debug_rnglists.
13374 Callback's type should be:
13375 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13376 Return true if the attributes are present and valid, otherwise,
13379 template <typename Callback
>
13381 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13382 Callback
&&callback
)
13384 struct dwarf2_per_objfile
*dwarf2_per_objfile
13385 = cu
->per_cu
->dwarf2_per_objfile
;
13386 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13387 bfd
*obfd
= objfile
->obfd
;
13388 /* Base address selection entry. */
13389 gdb::optional
<CORE_ADDR
> base
;
13390 const gdb_byte
*buffer
;
13391 CORE_ADDR baseaddr
;
13392 bool overflow
= false;
13394 base
= cu
->base_address
;
13396 dwarf2_per_objfile
->rnglists
.read (objfile
);
13397 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13399 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13403 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13405 baseaddr
= objfile
->text_section_offset ();
13409 /* Initialize it due to a false compiler warning. */
13410 CORE_ADDR range_beginning
= 0, range_end
= 0;
13411 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13412 + dwarf2_per_objfile
->rnglists
.size
);
13413 unsigned int bytes_read
;
13415 if (buffer
== buf_end
)
13420 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13423 case DW_RLE_end_of_list
:
13425 case DW_RLE_base_address
:
13426 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13431 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13432 buffer
+= bytes_read
;
13434 case DW_RLE_start_length
:
13435 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13440 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13442 buffer
+= bytes_read
;
13443 range_end
= (range_beginning
13444 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13445 buffer
+= bytes_read
;
13446 if (buffer
> buf_end
)
13452 case DW_RLE_offset_pair
:
13453 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13454 buffer
+= bytes_read
;
13455 if (buffer
> buf_end
)
13460 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13461 buffer
+= bytes_read
;
13462 if (buffer
> buf_end
)
13468 case DW_RLE_start_end
:
13469 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13474 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13476 buffer
+= bytes_read
;
13477 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13478 buffer
+= bytes_read
;
13481 complaint (_("Invalid .debug_rnglists data (no base address)"));
13484 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13486 if (rlet
== DW_RLE_base_address
)
13489 if (!base
.has_value ())
13491 /* We have no valid base address for the ranges
13493 complaint (_("Invalid .debug_rnglists data (no base address)"));
13497 if (range_beginning
> range_end
)
13499 /* Inverted range entries are invalid. */
13500 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13504 /* Empty range entries have no effect. */
13505 if (range_beginning
== range_end
)
13508 range_beginning
+= *base
;
13509 range_end
+= *base
;
13511 /* A not-uncommon case of bad debug info.
13512 Don't pollute the addrmap with bad data. */
13513 if (range_beginning
+ baseaddr
== 0
13514 && !dwarf2_per_objfile
->has_section_at_zero
)
13516 complaint (_(".debug_rnglists entry has start address of zero"
13517 " [in module %s]"), objfile_name (objfile
));
13521 callback (range_beginning
, range_end
);
13526 complaint (_("Offset %d is not terminated "
13527 "for DW_AT_ranges attribute"),
13535 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13536 Callback's type should be:
13537 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13538 Return 1 if the attributes are present and valid, otherwise, return 0. */
13540 template <typename Callback
>
13542 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13543 Callback
&&callback
)
13545 struct dwarf2_per_objfile
*dwarf2_per_objfile
13546 = cu
->per_cu
->dwarf2_per_objfile
;
13547 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13548 struct comp_unit_head
*cu_header
= &cu
->header
;
13549 bfd
*obfd
= objfile
->obfd
;
13550 unsigned int addr_size
= cu_header
->addr_size
;
13551 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13552 /* Base address selection entry. */
13553 gdb::optional
<CORE_ADDR
> base
;
13554 unsigned int dummy
;
13555 const gdb_byte
*buffer
;
13556 CORE_ADDR baseaddr
;
13558 if (cu_header
->version
>= 5)
13559 return dwarf2_rnglists_process (offset
, cu
, callback
);
13561 base
= cu
->base_address
;
13563 dwarf2_per_objfile
->ranges
.read (objfile
);
13564 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13566 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13570 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13572 baseaddr
= objfile
->text_section_offset ();
13576 CORE_ADDR range_beginning
, range_end
;
13578 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13579 buffer
+= addr_size
;
13580 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13581 buffer
+= addr_size
;
13582 offset
+= 2 * addr_size
;
13584 /* An end of list marker is a pair of zero addresses. */
13585 if (range_beginning
== 0 && range_end
== 0)
13586 /* Found the end of list entry. */
13589 /* Each base address selection entry is a pair of 2 values.
13590 The first is the largest possible address, the second is
13591 the base address. Check for a base address here. */
13592 if ((range_beginning
& mask
) == mask
)
13594 /* If we found the largest possible address, then we already
13595 have the base address in range_end. */
13600 if (!base
.has_value ())
13602 /* We have no valid base address for the ranges
13604 complaint (_("Invalid .debug_ranges data (no base address)"));
13608 if (range_beginning
> range_end
)
13610 /* Inverted range entries are invalid. */
13611 complaint (_("Invalid .debug_ranges data (inverted range)"));
13615 /* Empty range entries have no effect. */
13616 if (range_beginning
== range_end
)
13619 range_beginning
+= *base
;
13620 range_end
+= *base
;
13622 /* A not-uncommon case of bad debug info.
13623 Don't pollute the addrmap with bad data. */
13624 if (range_beginning
+ baseaddr
== 0
13625 && !dwarf2_per_objfile
->has_section_at_zero
)
13627 complaint (_(".debug_ranges entry has start address of zero"
13628 " [in module %s]"), objfile_name (objfile
));
13632 callback (range_beginning
, range_end
);
13638 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13639 Return 1 if the attributes are present and valid, otherwise, return 0.
13640 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13643 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13644 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13645 dwarf2_psymtab
*ranges_pst
)
13647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13648 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13649 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13652 CORE_ADDR high
= 0;
13655 retval
= dwarf2_ranges_process (offset
, cu
,
13656 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13658 if (ranges_pst
!= NULL
)
13663 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13664 range_beginning
+ baseaddr
)
13666 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13667 range_end
+ baseaddr
)
13669 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13670 lowpc
, highpc
- 1, ranges_pst
);
13673 /* FIXME: This is recording everything as a low-high
13674 segment of consecutive addresses. We should have a
13675 data structure for discontiguous block ranges
13679 low
= range_beginning
;
13685 if (range_beginning
< low
)
13686 low
= range_beginning
;
13687 if (range_end
> high
)
13695 /* If the first entry is an end-of-list marker, the range
13696 describes an empty scope, i.e. no instructions. */
13702 *high_return
= high
;
13706 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13707 definition for the return value. *LOWPC and *HIGHPC are set iff
13708 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13710 static enum pc_bounds_kind
13711 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13712 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13713 dwarf2_psymtab
*pst
)
13715 struct dwarf2_per_objfile
*dwarf2_per_objfile
13716 = cu
->per_cu
->dwarf2_per_objfile
;
13717 struct attribute
*attr
;
13718 struct attribute
*attr_high
;
13720 CORE_ADDR high
= 0;
13721 enum pc_bounds_kind ret
;
13723 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13726 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13727 if (attr
!= nullptr)
13729 low
= attr
->value_as_address ();
13730 high
= attr_high
->value_as_address ();
13731 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13735 /* Found high w/o low attribute. */
13736 return PC_BOUNDS_INVALID
;
13738 /* Found consecutive range of addresses. */
13739 ret
= PC_BOUNDS_HIGH_LOW
;
13743 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13746 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13747 We take advantage of the fact that DW_AT_ranges does not appear
13748 in DW_TAG_compile_unit of DWO files. */
13749 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13750 unsigned int ranges_offset
= (DW_UNSND (attr
)
13751 + (need_ranges_base
13755 /* Value of the DW_AT_ranges attribute is the offset in the
13756 .debug_ranges section. */
13757 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13758 return PC_BOUNDS_INVALID
;
13759 /* Found discontinuous range of addresses. */
13760 ret
= PC_BOUNDS_RANGES
;
13763 return PC_BOUNDS_NOT_PRESENT
;
13766 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13768 return PC_BOUNDS_INVALID
;
13770 /* When using the GNU linker, .gnu.linkonce. sections are used to
13771 eliminate duplicate copies of functions and vtables and such.
13772 The linker will arbitrarily choose one and discard the others.
13773 The AT_*_pc values for such functions refer to local labels in
13774 these sections. If the section from that file was discarded, the
13775 labels are not in the output, so the relocs get a value of 0.
13776 If this is a discarded function, mark the pc bounds as invalid,
13777 so that GDB will ignore it. */
13778 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13779 return PC_BOUNDS_INVALID
;
13787 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13788 its low and high PC addresses. Do nothing if these addresses could not
13789 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13790 and HIGHPC to the high address if greater than HIGHPC. */
13793 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13794 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13795 struct dwarf2_cu
*cu
)
13797 CORE_ADDR low
, high
;
13798 struct die_info
*child
= die
->child
;
13800 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13802 *lowpc
= std::min (*lowpc
, low
);
13803 *highpc
= std::max (*highpc
, high
);
13806 /* If the language does not allow nested subprograms (either inside
13807 subprograms or lexical blocks), we're done. */
13808 if (cu
->language
!= language_ada
)
13811 /* Check all the children of the given DIE. If it contains nested
13812 subprograms, then check their pc bounds. Likewise, we need to
13813 check lexical blocks as well, as they may also contain subprogram
13815 while (child
&& child
->tag
)
13817 if (child
->tag
== DW_TAG_subprogram
13818 || child
->tag
== DW_TAG_lexical_block
)
13819 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13820 child
= child
->sibling
;
13824 /* Get the low and high pc's represented by the scope DIE, and store
13825 them in *LOWPC and *HIGHPC. If the correct values can't be
13826 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13829 get_scope_pc_bounds (struct die_info
*die
,
13830 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13831 struct dwarf2_cu
*cu
)
13833 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13834 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13835 CORE_ADDR current_low
, current_high
;
13837 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13838 >= PC_BOUNDS_RANGES
)
13840 best_low
= current_low
;
13841 best_high
= current_high
;
13845 struct die_info
*child
= die
->child
;
13847 while (child
&& child
->tag
)
13849 switch (child
->tag
) {
13850 case DW_TAG_subprogram
:
13851 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13853 case DW_TAG_namespace
:
13854 case DW_TAG_module
:
13855 /* FIXME: carlton/2004-01-16: Should we do this for
13856 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13857 that current GCC's always emit the DIEs corresponding
13858 to definitions of methods of classes as children of a
13859 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13860 the DIEs giving the declarations, which could be
13861 anywhere). But I don't see any reason why the
13862 standards says that they have to be there. */
13863 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13865 if (current_low
!= ((CORE_ADDR
) -1))
13867 best_low
= std::min (best_low
, current_low
);
13868 best_high
= std::max (best_high
, current_high
);
13876 child
= child
->sibling
;
13881 *highpc
= best_high
;
13884 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13888 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13889 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13891 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13892 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13893 struct attribute
*attr
;
13894 struct attribute
*attr_high
;
13896 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13899 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13900 if (attr
!= nullptr)
13902 CORE_ADDR low
= attr
->value_as_address ();
13903 CORE_ADDR high
= attr_high
->value_as_address ();
13905 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13908 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13909 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13910 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13914 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13915 if (attr
!= nullptr)
13917 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13918 We take advantage of the fact that DW_AT_ranges does not appear
13919 in DW_TAG_compile_unit of DWO files. */
13920 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13922 /* The value of the DW_AT_ranges attribute is the offset of the
13923 address range list in the .debug_ranges section. */
13924 unsigned long offset
= (DW_UNSND (attr
)
13925 + (need_ranges_base
? cu
->ranges_base
: 0));
13927 std::vector
<blockrange
> blockvec
;
13928 dwarf2_ranges_process (offset
, cu
,
13929 [&] (CORE_ADDR start
, CORE_ADDR end
)
13933 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13934 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13935 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13936 blockvec
.emplace_back (start
, end
);
13939 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13943 /* Check whether the producer field indicates either of GCC < 4.6, or the
13944 Intel C/C++ compiler, and cache the result in CU. */
13947 check_producer (struct dwarf2_cu
*cu
)
13951 if (cu
->producer
== NULL
)
13953 /* For unknown compilers expect their behavior is DWARF version
13956 GCC started to support .debug_types sections by -gdwarf-4 since
13957 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13958 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13959 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13960 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13962 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13964 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13965 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13967 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13969 cu
->producer_is_icc
= true;
13970 cu
->producer_is_icc_lt_14
= major
< 14;
13972 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13973 cu
->producer_is_codewarrior
= true;
13976 /* For other non-GCC compilers, expect their behavior is DWARF version
13980 cu
->checked_producer
= true;
13983 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13984 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13985 during 4.6.0 experimental. */
13988 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
13990 if (!cu
->checked_producer
)
13991 check_producer (cu
);
13993 return cu
->producer_is_gxx_lt_4_6
;
13997 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
13998 with incorrect is_stmt attributes. */
14001 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14003 if (!cu
->checked_producer
)
14004 check_producer (cu
);
14006 return cu
->producer_is_codewarrior
;
14009 /* Return the default accessibility type if it is not overridden by
14010 DW_AT_accessibility. */
14012 static enum dwarf_access_attribute
14013 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14015 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14017 /* The default DWARF 2 accessibility for members is public, the default
14018 accessibility for inheritance is private. */
14020 if (die
->tag
!= DW_TAG_inheritance
)
14021 return DW_ACCESS_public
;
14023 return DW_ACCESS_private
;
14027 /* DWARF 3+ defines the default accessibility a different way. The same
14028 rules apply now for DW_TAG_inheritance as for the members and it only
14029 depends on the container kind. */
14031 if (die
->parent
->tag
== DW_TAG_class_type
)
14032 return DW_ACCESS_private
;
14034 return DW_ACCESS_public
;
14038 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14039 offset. If the attribute was not found return 0, otherwise return
14040 1. If it was found but could not properly be handled, set *OFFSET
14044 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14047 struct attribute
*attr
;
14049 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14054 /* Note that we do not check for a section offset first here.
14055 This is because DW_AT_data_member_location is new in DWARF 4,
14056 so if we see it, we can assume that a constant form is really
14057 a constant and not a section offset. */
14058 if (attr
->form_is_constant ())
14059 *offset
= attr
->constant_value (0);
14060 else if (attr
->form_is_section_offset ())
14061 dwarf2_complex_location_expr_complaint ();
14062 else if (attr
->form_is_block ())
14063 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14065 dwarf2_complex_location_expr_complaint ();
14073 /* Add an aggregate field to the field list. */
14076 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14077 struct dwarf2_cu
*cu
)
14079 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14080 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14081 struct nextfield
*new_field
;
14082 struct attribute
*attr
;
14084 const char *fieldname
= "";
14086 if (die
->tag
== DW_TAG_inheritance
)
14088 fip
->baseclasses
.emplace_back ();
14089 new_field
= &fip
->baseclasses
.back ();
14093 fip
->fields
.emplace_back ();
14094 new_field
= &fip
->fields
.back ();
14097 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14098 if (attr
!= nullptr)
14099 new_field
->accessibility
= DW_UNSND (attr
);
14101 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14102 if (new_field
->accessibility
!= DW_ACCESS_public
)
14103 fip
->non_public_fields
= 1;
14105 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14106 if (attr
!= nullptr)
14107 new_field
->virtuality
= DW_UNSND (attr
);
14109 new_field
->virtuality
= DW_VIRTUALITY_none
;
14111 fp
= &new_field
->field
;
14113 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14117 /* Data member other than a C++ static data member. */
14119 /* Get type of field. */
14120 fp
->type
= die_type (die
, cu
);
14122 SET_FIELD_BITPOS (*fp
, 0);
14124 /* Get bit size of field (zero if none). */
14125 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14126 if (attr
!= nullptr)
14128 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14132 FIELD_BITSIZE (*fp
) = 0;
14135 /* Get bit offset of field. */
14136 if (handle_data_member_location (die
, cu
, &offset
))
14137 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14138 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14139 if (attr
!= nullptr)
14141 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14143 /* For big endian bits, the DW_AT_bit_offset gives the
14144 additional bit offset from the MSB of the containing
14145 anonymous object to the MSB of the field. We don't
14146 have to do anything special since we don't need to
14147 know the size of the anonymous object. */
14148 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14152 /* For little endian bits, compute the bit offset to the
14153 MSB of the anonymous object, subtract off the number of
14154 bits from the MSB of the field to the MSB of the
14155 object, and then subtract off the number of bits of
14156 the field itself. The result is the bit offset of
14157 the LSB of the field. */
14158 int anonymous_size
;
14159 int bit_offset
= DW_UNSND (attr
);
14161 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14162 if (attr
!= nullptr)
14164 /* The size of the anonymous object containing
14165 the bit field is explicit, so use the
14166 indicated size (in bytes). */
14167 anonymous_size
= DW_UNSND (attr
);
14171 /* The size of the anonymous object containing
14172 the bit field must be inferred from the type
14173 attribute of the data member containing the
14175 anonymous_size
= TYPE_LENGTH (fp
->type
);
14177 SET_FIELD_BITPOS (*fp
,
14178 (FIELD_BITPOS (*fp
)
14179 + anonymous_size
* bits_per_byte
14180 - bit_offset
- FIELD_BITSIZE (*fp
)));
14183 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14185 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14186 + attr
->constant_value (0)));
14188 /* Get name of field. */
14189 fieldname
= dwarf2_name (die
, cu
);
14190 if (fieldname
== NULL
)
14193 /* The name is already allocated along with this objfile, so we don't
14194 need to duplicate it for the type. */
14195 fp
->name
= fieldname
;
14197 /* Change accessibility for artificial fields (e.g. virtual table
14198 pointer or virtual base class pointer) to private. */
14199 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14201 FIELD_ARTIFICIAL (*fp
) = 1;
14202 new_field
->accessibility
= DW_ACCESS_private
;
14203 fip
->non_public_fields
= 1;
14206 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14208 /* C++ static member. */
14210 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14211 is a declaration, but all versions of G++ as of this writing
14212 (so through at least 3.2.1) incorrectly generate
14213 DW_TAG_variable tags. */
14215 const char *physname
;
14217 /* Get name of field. */
14218 fieldname
= dwarf2_name (die
, cu
);
14219 if (fieldname
== NULL
)
14222 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14224 /* Only create a symbol if this is an external value.
14225 new_symbol checks this and puts the value in the global symbol
14226 table, which we want. If it is not external, new_symbol
14227 will try to put the value in cu->list_in_scope which is wrong. */
14228 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14230 /* A static const member, not much different than an enum as far as
14231 we're concerned, except that we can support more types. */
14232 new_symbol (die
, NULL
, cu
);
14235 /* Get physical name. */
14236 physname
= dwarf2_physname (fieldname
, die
, cu
);
14238 /* The name is already allocated along with this objfile, so we don't
14239 need to duplicate it for the type. */
14240 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14241 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14242 FIELD_NAME (*fp
) = fieldname
;
14244 else if (die
->tag
== DW_TAG_inheritance
)
14248 /* C++ base class field. */
14249 if (handle_data_member_location (die
, cu
, &offset
))
14250 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14251 FIELD_BITSIZE (*fp
) = 0;
14252 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14253 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14255 else if (die
->tag
== DW_TAG_variant_part
)
14257 /* process_structure_scope will treat this DIE as a union. */
14258 process_structure_scope (die
, cu
);
14260 /* The variant part is relative to the start of the enclosing
14262 SET_FIELD_BITPOS (*fp
, 0);
14263 fp
->type
= get_die_type (die
, cu
);
14264 fp
->artificial
= 1;
14265 fp
->name
= "<<variant>>";
14267 /* Normally a DW_TAG_variant_part won't have a size, but our
14268 representation requires one, so set it to the maximum of the
14269 child sizes, being sure to account for the offset at which
14270 each child is seen. */
14271 if (TYPE_LENGTH (fp
->type
) == 0)
14274 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14276 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14277 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14281 TYPE_LENGTH (fp
->type
) = max
;
14285 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14288 /* Can the type given by DIE define another type? */
14291 type_can_define_types (const struct die_info
*die
)
14295 case DW_TAG_typedef
:
14296 case DW_TAG_class_type
:
14297 case DW_TAG_structure_type
:
14298 case DW_TAG_union_type
:
14299 case DW_TAG_enumeration_type
:
14307 /* Add a type definition defined in the scope of the FIP's class. */
14310 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14311 struct dwarf2_cu
*cu
)
14313 struct decl_field fp
;
14314 memset (&fp
, 0, sizeof (fp
));
14316 gdb_assert (type_can_define_types (die
));
14318 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14319 fp
.name
= dwarf2_name (die
, cu
);
14320 fp
.type
= read_type_die (die
, cu
);
14322 /* Save accessibility. */
14323 enum dwarf_access_attribute accessibility
;
14324 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14326 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14328 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14329 switch (accessibility
)
14331 case DW_ACCESS_public
:
14332 /* The assumed value if neither private nor protected. */
14334 case DW_ACCESS_private
:
14337 case DW_ACCESS_protected
:
14338 fp
.is_protected
= 1;
14341 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14344 if (die
->tag
== DW_TAG_typedef
)
14345 fip
->typedef_field_list
.push_back (fp
);
14347 fip
->nested_types_list
.push_back (fp
);
14350 /* Create the vector of fields, and attach it to the type. */
14353 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14354 struct dwarf2_cu
*cu
)
14356 int nfields
= fip
->nfields ();
14358 /* Record the field count, allocate space for the array of fields,
14359 and create blank accessibility bitfields if necessary. */
14360 TYPE_NFIELDS (type
) = nfields
;
14361 TYPE_FIELDS (type
) = (struct field
*)
14362 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14364 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14366 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14368 TYPE_FIELD_PRIVATE_BITS (type
) =
14369 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14370 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14372 TYPE_FIELD_PROTECTED_BITS (type
) =
14373 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14374 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14376 TYPE_FIELD_IGNORE_BITS (type
) =
14377 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14378 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14381 /* If the type has baseclasses, allocate and clear a bit vector for
14382 TYPE_FIELD_VIRTUAL_BITS. */
14383 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14385 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14386 unsigned char *pointer
;
14388 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14389 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14390 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14391 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14392 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14395 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14397 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14399 for (int index
= 0; index
< nfields
; ++index
)
14401 struct nextfield
&field
= fip
->fields
[index
];
14403 if (field
.variant
.is_discriminant
)
14404 di
->discriminant_index
= index
;
14405 else if (field
.variant
.default_branch
)
14406 di
->default_index
= index
;
14408 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14412 /* Copy the saved-up fields into the field vector. */
14413 for (int i
= 0; i
< nfields
; ++i
)
14415 struct nextfield
&field
14416 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14417 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14419 TYPE_FIELD (type
, i
) = field
.field
;
14420 switch (field
.accessibility
)
14422 case DW_ACCESS_private
:
14423 if (cu
->language
!= language_ada
)
14424 SET_TYPE_FIELD_PRIVATE (type
, i
);
14427 case DW_ACCESS_protected
:
14428 if (cu
->language
!= language_ada
)
14429 SET_TYPE_FIELD_PROTECTED (type
, i
);
14432 case DW_ACCESS_public
:
14436 /* Unknown accessibility. Complain and treat it as public. */
14438 complaint (_("unsupported accessibility %d"),
14439 field
.accessibility
);
14443 if (i
< fip
->baseclasses
.size ())
14445 switch (field
.virtuality
)
14447 case DW_VIRTUALITY_virtual
:
14448 case DW_VIRTUALITY_pure_virtual
:
14449 if (cu
->language
== language_ada
)
14450 error (_("unexpected virtuality in component of Ada type"));
14451 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14458 /* Return true if this member function is a constructor, false
14462 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14464 const char *fieldname
;
14465 const char *type_name
;
14468 if (die
->parent
== NULL
)
14471 if (die
->parent
->tag
!= DW_TAG_structure_type
14472 && die
->parent
->tag
!= DW_TAG_union_type
14473 && die
->parent
->tag
!= DW_TAG_class_type
)
14476 fieldname
= dwarf2_name (die
, cu
);
14477 type_name
= dwarf2_name (die
->parent
, cu
);
14478 if (fieldname
== NULL
|| type_name
== NULL
)
14481 len
= strlen (fieldname
);
14482 return (strncmp (fieldname
, type_name
, len
) == 0
14483 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14486 /* Check if the given VALUE is a recognized enum
14487 dwarf_defaulted_attribute constant according to DWARF5 spec,
14491 is_valid_DW_AT_defaulted (ULONGEST value
)
14495 case DW_DEFAULTED_no
:
14496 case DW_DEFAULTED_in_class
:
14497 case DW_DEFAULTED_out_of_class
:
14501 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14505 /* Add a member function to the proper fieldlist. */
14508 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14509 struct type
*type
, struct dwarf2_cu
*cu
)
14511 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14512 struct attribute
*attr
;
14514 struct fnfieldlist
*flp
= nullptr;
14515 struct fn_field
*fnp
;
14516 const char *fieldname
;
14517 struct type
*this_type
;
14518 enum dwarf_access_attribute accessibility
;
14520 if (cu
->language
== language_ada
)
14521 error (_("unexpected member function in Ada type"));
14523 /* Get name of member function. */
14524 fieldname
= dwarf2_name (die
, cu
);
14525 if (fieldname
== NULL
)
14528 /* Look up member function name in fieldlist. */
14529 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14531 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14533 flp
= &fip
->fnfieldlists
[i
];
14538 /* Create a new fnfieldlist if necessary. */
14539 if (flp
== nullptr)
14541 fip
->fnfieldlists
.emplace_back ();
14542 flp
= &fip
->fnfieldlists
.back ();
14543 flp
->name
= fieldname
;
14544 i
= fip
->fnfieldlists
.size () - 1;
14547 /* Create a new member function field and add it to the vector of
14549 flp
->fnfields
.emplace_back ();
14550 fnp
= &flp
->fnfields
.back ();
14552 /* Delay processing of the physname until later. */
14553 if (cu
->language
== language_cplus
)
14554 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14558 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14559 fnp
->physname
= physname
? physname
: "";
14562 fnp
->type
= alloc_type (objfile
);
14563 this_type
= read_type_die (die
, cu
);
14564 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14566 int nparams
= TYPE_NFIELDS (this_type
);
14568 /* TYPE is the domain of this method, and THIS_TYPE is the type
14569 of the method itself (TYPE_CODE_METHOD). */
14570 smash_to_method_type (fnp
->type
, type
,
14571 TYPE_TARGET_TYPE (this_type
),
14572 TYPE_FIELDS (this_type
),
14573 TYPE_NFIELDS (this_type
),
14574 TYPE_VARARGS (this_type
));
14576 /* Handle static member functions.
14577 Dwarf2 has no clean way to discern C++ static and non-static
14578 member functions. G++ helps GDB by marking the first
14579 parameter for non-static member functions (which is the this
14580 pointer) as artificial. We obtain this information from
14581 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14582 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14583 fnp
->voffset
= VOFFSET_STATIC
;
14586 complaint (_("member function type missing for '%s'"),
14587 dwarf2_full_name (fieldname
, die
, cu
));
14589 /* Get fcontext from DW_AT_containing_type if present. */
14590 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14591 fnp
->fcontext
= die_containing_type (die
, cu
);
14593 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14594 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14596 /* Get accessibility. */
14597 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14598 if (attr
!= nullptr)
14599 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14601 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14602 switch (accessibility
)
14604 case DW_ACCESS_private
:
14605 fnp
->is_private
= 1;
14607 case DW_ACCESS_protected
:
14608 fnp
->is_protected
= 1;
14612 /* Check for artificial methods. */
14613 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14614 if (attr
&& DW_UNSND (attr
) != 0)
14615 fnp
->is_artificial
= 1;
14617 /* Check for defaulted methods. */
14618 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14619 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14620 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14622 /* Check for deleted methods. */
14623 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14624 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14625 fnp
->is_deleted
= 1;
14627 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14629 /* Get index in virtual function table if it is a virtual member
14630 function. For older versions of GCC, this is an offset in the
14631 appropriate virtual table, as specified by DW_AT_containing_type.
14632 For everyone else, it is an expression to be evaluated relative
14633 to the object address. */
14635 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14636 if (attr
!= nullptr)
14638 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14640 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14642 /* Old-style GCC. */
14643 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14645 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14646 || (DW_BLOCK (attr
)->size
> 1
14647 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14648 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14650 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14651 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14652 dwarf2_complex_location_expr_complaint ();
14654 fnp
->voffset
/= cu
->header
.addr_size
;
14658 dwarf2_complex_location_expr_complaint ();
14660 if (!fnp
->fcontext
)
14662 /* If there is no `this' field and no DW_AT_containing_type,
14663 we cannot actually find a base class context for the
14665 if (TYPE_NFIELDS (this_type
) == 0
14666 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14668 complaint (_("cannot determine context for virtual member "
14669 "function \"%s\" (offset %s)"),
14670 fieldname
, sect_offset_str (die
->sect_off
));
14675 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14679 else if (attr
->form_is_section_offset ())
14681 dwarf2_complex_location_expr_complaint ();
14685 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14691 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14692 if (attr
&& DW_UNSND (attr
))
14694 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14695 complaint (_("Member function \"%s\" (offset %s) is virtual "
14696 "but the vtable offset is not specified"),
14697 fieldname
, sect_offset_str (die
->sect_off
));
14698 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14699 TYPE_CPLUS_DYNAMIC (type
) = 1;
14704 /* Create the vector of member function fields, and attach it to the type. */
14707 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14708 struct dwarf2_cu
*cu
)
14710 if (cu
->language
== language_ada
)
14711 error (_("unexpected member functions in Ada type"));
14713 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14714 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14716 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14718 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14720 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14721 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14723 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14724 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14725 fn_flp
->fn_fields
= (struct fn_field
*)
14726 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14728 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14729 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14732 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14735 /* Returns non-zero if NAME is the name of a vtable member in CU's
14736 language, zero otherwise. */
14738 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14740 static const char vptr
[] = "_vptr";
14742 /* Look for the C++ form of the vtable. */
14743 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14749 /* GCC outputs unnamed structures that are really pointers to member
14750 functions, with the ABI-specified layout. If TYPE describes
14751 such a structure, smash it into a member function type.
14753 GCC shouldn't do this; it should just output pointer to member DIEs.
14754 This is GCC PR debug/28767. */
14757 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14759 struct type
*pfn_type
, *self_type
, *new_type
;
14761 /* Check for a structure with no name and two children. */
14762 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14765 /* Check for __pfn and __delta members. */
14766 if (TYPE_FIELD_NAME (type
, 0) == NULL
14767 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14768 || TYPE_FIELD_NAME (type
, 1) == NULL
14769 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14772 /* Find the type of the method. */
14773 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14774 if (pfn_type
== NULL
14775 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14776 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14779 /* Look for the "this" argument. */
14780 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14781 if (TYPE_NFIELDS (pfn_type
) == 0
14782 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14783 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14786 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14787 new_type
= alloc_type (objfile
);
14788 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14789 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14790 TYPE_VARARGS (pfn_type
));
14791 smash_to_methodptr_type (type
, new_type
);
14794 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14795 appropriate error checking and issuing complaints if there is a
14799 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14801 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14803 if (attr
== nullptr)
14806 if (!attr
->form_is_constant ())
14808 complaint (_("DW_AT_alignment must have constant form"
14809 " - DIE at %s [in module %s]"),
14810 sect_offset_str (die
->sect_off
),
14811 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14816 if (attr
->form
== DW_FORM_sdata
)
14818 LONGEST val
= DW_SND (attr
);
14821 complaint (_("DW_AT_alignment value must not be negative"
14822 " - DIE at %s [in module %s]"),
14823 sect_offset_str (die
->sect_off
),
14824 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14830 align
= DW_UNSND (attr
);
14834 complaint (_("DW_AT_alignment value must not be zero"
14835 " - DIE at %s [in module %s]"),
14836 sect_offset_str (die
->sect_off
),
14837 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14840 if ((align
& (align
- 1)) != 0)
14842 complaint (_("DW_AT_alignment value must be a power of 2"
14843 " - DIE at %s [in module %s]"),
14844 sect_offset_str (die
->sect_off
),
14845 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14852 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14853 the alignment for TYPE. */
14856 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14859 if (!set_type_align (type
, get_alignment (cu
, die
)))
14860 complaint (_("DW_AT_alignment value too large"
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 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14867 constant for a type, according to DWARF5 spec, Table 5.5. */
14870 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14875 case DW_CC_pass_by_reference
:
14876 case DW_CC_pass_by_value
:
14880 complaint (_("unrecognized DW_AT_calling_convention value "
14881 "(%s) for a type"), pulongest (value
));
14886 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14887 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14888 also according to GNU-specific values (see include/dwarf2.h). */
14891 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14896 case DW_CC_program
:
14900 case DW_CC_GNU_renesas_sh
:
14901 case DW_CC_GNU_borland_fastcall_i386
:
14902 case DW_CC_GDB_IBM_OpenCL
:
14906 complaint (_("unrecognized DW_AT_calling_convention value "
14907 "(%s) for a subroutine"), pulongest (value
));
14912 /* Called when we find the DIE that starts a structure or union scope
14913 (definition) to create a type for the structure or union. Fill in
14914 the type's name and general properties; the members will not be
14915 processed until process_structure_scope. A symbol table entry for
14916 the type will also not be done until process_structure_scope (assuming
14917 the type has a name).
14919 NOTE: we need to call these functions regardless of whether or not the
14920 DIE has a DW_AT_name attribute, since it might be an anonymous
14921 structure or union. This gets the type entered into our set of
14922 user defined types. */
14924 static struct type
*
14925 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14927 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14929 struct attribute
*attr
;
14932 /* If the definition of this type lives in .debug_types, read that type.
14933 Don't follow DW_AT_specification though, that will take us back up
14934 the chain and we want to go down. */
14935 attr
= die
->attr (DW_AT_signature
);
14936 if (attr
!= nullptr)
14938 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14940 /* The type's CU may not be the same as CU.
14941 Ensure TYPE is recorded with CU in die_type_hash. */
14942 return set_die_type (die
, type
, cu
);
14945 type
= alloc_type (objfile
);
14946 INIT_CPLUS_SPECIFIC (type
);
14948 name
= dwarf2_name (die
, cu
);
14951 if (cu
->language
== language_cplus
14952 || cu
->language
== language_d
14953 || cu
->language
== language_rust
)
14955 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14957 /* dwarf2_full_name might have already finished building the DIE's
14958 type. If so, there is no need to continue. */
14959 if (get_die_type (die
, cu
) != NULL
)
14960 return get_die_type (die
, cu
);
14962 TYPE_NAME (type
) = full_name
;
14966 /* The name is already allocated along with this objfile, so
14967 we don't need to duplicate it for the type. */
14968 TYPE_NAME (type
) = name
;
14972 if (die
->tag
== DW_TAG_structure_type
)
14974 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14976 else if (die
->tag
== DW_TAG_union_type
)
14978 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14980 else if (die
->tag
== DW_TAG_variant_part
)
14982 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14983 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
14987 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14990 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
14991 TYPE_DECLARED_CLASS (type
) = 1;
14993 /* Store the calling convention in the type if it's available in
14994 the die. Otherwise the calling convention remains set to
14995 the default value DW_CC_normal. */
14996 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14997 if (attr
!= nullptr
14998 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15000 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15001 TYPE_CPLUS_CALLING_CONVENTION (type
)
15002 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15005 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15006 if (attr
!= nullptr)
15008 if (attr
->form_is_constant ())
15009 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15012 /* For the moment, dynamic type sizes are not supported
15013 by GDB's struct type. The actual size is determined
15014 on-demand when resolving the type of a given object,
15015 so set the type's length to zero for now. Otherwise,
15016 we record an expression as the length, and that expression
15017 could lead to a very large value, which could eventually
15018 lead to us trying to allocate that much memory when creating
15019 a value of that type. */
15020 TYPE_LENGTH (type
) = 0;
15025 TYPE_LENGTH (type
) = 0;
15028 maybe_set_alignment (cu
, die
, type
);
15030 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15032 /* ICC<14 does not output the required DW_AT_declaration on
15033 incomplete types, but gives them a size of zero. */
15034 TYPE_STUB (type
) = 1;
15037 TYPE_STUB_SUPPORTED (type
) = 1;
15039 if (die_is_declaration (die
, cu
))
15040 TYPE_STUB (type
) = 1;
15041 else if (attr
== NULL
&& die
->child
== NULL
15042 && producer_is_realview (cu
->producer
))
15043 /* RealView does not output the required DW_AT_declaration
15044 on incomplete types. */
15045 TYPE_STUB (type
) = 1;
15047 /* We need to add the type field to the die immediately so we don't
15048 infinitely recurse when dealing with pointers to the structure
15049 type within the structure itself. */
15050 set_die_type (die
, type
, cu
);
15052 /* set_die_type should be already done. */
15053 set_descriptive_type (type
, die
, cu
);
15058 /* A helper for process_structure_scope that handles a single member
15062 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15063 struct field_info
*fi
,
15064 std::vector
<struct symbol
*> *template_args
,
15065 struct dwarf2_cu
*cu
)
15067 if (child_die
->tag
== DW_TAG_member
15068 || child_die
->tag
== DW_TAG_variable
15069 || child_die
->tag
== DW_TAG_variant_part
)
15071 /* NOTE: carlton/2002-11-05: A C++ static data member
15072 should be a DW_TAG_member that is a declaration, but
15073 all versions of G++ as of this writing (so through at
15074 least 3.2.1) incorrectly generate DW_TAG_variable
15075 tags for them instead. */
15076 dwarf2_add_field (fi
, child_die
, cu
);
15078 else if (child_die
->tag
== DW_TAG_subprogram
)
15080 /* Rust doesn't have member functions in the C++ sense.
15081 However, it does emit ordinary functions as children
15082 of a struct DIE. */
15083 if (cu
->language
== language_rust
)
15084 read_func_scope (child_die
, cu
);
15087 /* C++ member function. */
15088 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15091 else if (child_die
->tag
== DW_TAG_inheritance
)
15093 /* C++ base class field. */
15094 dwarf2_add_field (fi
, child_die
, cu
);
15096 else if (type_can_define_types (child_die
))
15097 dwarf2_add_type_defn (fi
, child_die
, cu
);
15098 else if (child_die
->tag
== DW_TAG_template_type_param
15099 || child_die
->tag
== DW_TAG_template_value_param
)
15101 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15104 template_args
->push_back (arg
);
15106 else if (child_die
->tag
== DW_TAG_variant
)
15108 /* In a variant we want to get the discriminant and also add a
15109 field for our sole member child. */
15110 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15112 for (die_info
*variant_child
= child_die
->child
;
15113 variant_child
!= NULL
;
15114 variant_child
= variant_child
->sibling
)
15116 if (variant_child
->tag
== DW_TAG_member
)
15118 handle_struct_member_die (variant_child
, type
, fi
,
15119 template_args
, cu
);
15120 /* Only handle the one. */
15125 /* We don't handle this but we might as well report it if we see
15127 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15128 complaint (_("DW_AT_discr_list is not supported yet"
15129 " - DIE at %s [in module %s]"),
15130 sect_offset_str (child_die
->sect_off
),
15131 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15133 /* The first field was just added, so we can stash the
15134 discriminant there. */
15135 gdb_assert (!fi
->fields
.empty ());
15137 fi
->fields
.back ().variant
.default_branch
= true;
15139 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15143 /* Finish creating a structure or union type, including filling in
15144 its members and creating a symbol for it. */
15147 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15149 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15150 struct die_info
*child_die
;
15153 type
= get_die_type (die
, cu
);
15155 type
= read_structure_type (die
, cu
);
15157 /* When reading a DW_TAG_variant_part, we need to notice when we
15158 read the discriminant member, so we can record it later in the
15159 discriminant_info. */
15160 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15161 sect_offset discr_offset
{};
15162 bool has_template_parameters
= false;
15164 if (is_variant_part
)
15166 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15169 /* Maybe it's a univariant form, an extension we support.
15170 In this case arrange not to check the offset. */
15171 is_variant_part
= false;
15173 else if (discr
->form_is_ref ())
15175 struct dwarf2_cu
*target_cu
= cu
;
15176 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15178 discr_offset
= target_die
->sect_off
;
15182 complaint (_("DW_AT_discr does not have DIE reference form"
15183 " - DIE at %s [in module %s]"),
15184 sect_offset_str (die
->sect_off
),
15185 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15186 is_variant_part
= false;
15190 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15192 struct field_info fi
;
15193 std::vector
<struct symbol
*> template_args
;
15195 child_die
= die
->child
;
15197 while (child_die
&& child_die
->tag
)
15199 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15201 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15202 fi
.fields
.back ().variant
.is_discriminant
= true;
15204 child_die
= child_die
->sibling
;
15207 /* Attach template arguments to type. */
15208 if (!template_args
.empty ())
15210 has_template_parameters
= true;
15211 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15212 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15213 TYPE_TEMPLATE_ARGUMENTS (type
)
15214 = XOBNEWVEC (&objfile
->objfile_obstack
,
15216 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15217 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15218 template_args
.data (),
15219 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15220 * sizeof (struct symbol
*)));
15223 /* Attach fields and member functions to the type. */
15224 if (fi
.nfields () > 0)
15225 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15226 if (!fi
.fnfieldlists
.empty ())
15228 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15230 /* Get the type which refers to the base class (possibly this
15231 class itself) which contains the vtable pointer for the current
15232 class from the DW_AT_containing_type attribute. This use of
15233 DW_AT_containing_type is a GNU extension. */
15235 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15237 struct type
*t
= die_containing_type (die
, cu
);
15239 set_type_vptr_basetype (type
, t
);
15244 /* Our own class provides vtbl ptr. */
15245 for (i
= TYPE_NFIELDS (t
) - 1;
15246 i
>= TYPE_N_BASECLASSES (t
);
15249 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15251 if (is_vtable_name (fieldname
, cu
))
15253 set_type_vptr_fieldno (type
, i
);
15258 /* Complain if virtual function table field not found. */
15259 if (i
< TYPE_N_BASECLASSES (t
))
15260 complaint (_("virtual function table pointer "
15261 "not found when defining class '%s'"),
15262 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15266 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15269 else if (cu
->producer
15270 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15272 /* The IBM XLC compiler does not provide direct indication
15273 of the containing type, but the vtable pointer is
15274 always named __vfp. */
15278 for (i
= TYPE_NFIELDS (type
) - 1;
15279 i
>= TYPE_N_BASECLASSES (type
);
15282 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15284 set_type_vptr_fieldno (type
, i
);
15285 set_type_vptr_basetype (type
, type
);
15292 /* Copy fi.typedef_field_list linked list elements content into the
15293 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15294 if (!fi
.typedef_field_list
.empty ())
15296 int count
= fi
.typedef_field_list
.size ();
15298 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15299 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15300 = ((struct decl_field
*)
15302 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15303 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15305 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15306 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15309 /* Copy fi.nested_types_list linked list elements content into the
15310 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15311 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15313 int count
= fi
.nested_types_list
.size ();
15315 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15316 TYPE_NESTED_TYPES_ARRAY (type
)
15317 = ((struct decl_field
*)
15318 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15319 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15321 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15322 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15326 quirk_gcc_member_function_pointer (type
, objfile
);
15327 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15328 cu
->rust_unions
.push_back (type
);
15330 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15331 snapshots) has been known to create a die giving a declaration
15332 for a class that has, as a child, a die giving a definition for a
15333 nested class. So we have to process our children even if the
15334 current die is a declaration. Normally, of course, a declaration
15335 won't have any children at all. */
15337 child_die
= die
->child
;
15339 while (child_die
!= NULL
&& child_die
->tag
)
15341 if (child_die
->tag
== DW_TAG_member
15342 || child_die
->tag
== DW_TAG_variable
15343 || child_die
->tag
== DW_TAG_inheritance
15344 || child_die
->tag
== DW_TAG_template_value_param
15345 || child_die
->tag
== DW_TAG_template_type_param
)
15350 process_die (child_die
, cu
);
15352 child_die
= child_die
->sibling
;
15355 /* Do not consider external references. According to the DWARF standard,
15356 these DIEs are identified by the fact that they have no byte_size
15357 attribute, and a declaration attribute. */
15358 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15359 || !die_is_declaration (die
, cu
))
15361 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15363 if (has_template_parameters
)
15365 struct symtab
*symtab
;
15366 if (sym
!= nullptr)
15367 symtab
= symbol_symtab (sym
);
15368 else if (cu
->line_header
!= nullptr)
15370 /* Any related symtab will do. */
15372 = cu
->line_header
->file_names ()[0].symtab
;
15377 complaint (_("could not find suitable "
15378 "symtab for template parameter"
15379 " - DIE at %s [in module %s]"),
15380 sect_offset_str (die
->sect_off
),
15381 objfile_name (objfile
));
15384 if (symtab
!= nullptr)
15386 /* Make sure that the symtab is set on the new symbols.
15387 Even though they don't appear in this symtab directly,
15388 other parts of gdb assume that symbols do, and this is
15389 reasonably true. */
15390 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15391 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15397 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15398 update TYPE using some information only available in DIE's children. */
15401 update_enumeration_type_from_children (struct die_info
*die
,
15403 struct dwarf2_cu
*cu
)
15405 struct die_info
*child_die
;
15406 int unsigned_enum
= 1;
15409 auto_obstack obstack
;
15411 for (child_die
= die
->child
;
15412 child_die
!= NULL
&& child_die
->tag
;
15413 child_die
= child_die
->sibling
)
15415 struct attribute
*attr
;
15417 const gdb_byte
*bytes
;
15418 struct dwarf2_locexpr_baton
*baton
;
15421 if (child_die
->tag
!= DW_TAG_enumerator
)
15424 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15428 name
= dwarf2_name (child_die
, cu
);
15430 name
= "<anonymous enumerator>";
15432 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15433 &value
, &bytes
, &baton
);
15441 if (count_one_bits_ll (value
) >= 2)
15445 /* If we already know that the enum type is neither unsigned, nor
15446 a flag type, no need to look at the rest of the enumerates. */
15447 if (!unsigned_enum
&& !flag_enum
)
15452 TYPE_UNSIGNED (type
) = 1;
15454 TYPE_FLAG_ENUM (type
) = 1;
15457 /* Given a DW_AT_enumeration_type die, set its type. We do not
15458 complete the type's fields yet, or create any symbols. */
15460 static struct type
*
15461 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15463 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15465 struct attribute
*attr
;
15468 /* If the definition of this type lives in .debug_types, read that type.
15469 Don't follow DW_AT_specification though, that will take us back up
15470 the chain and we want to go down. */
15471 attr
= die
->attr (DW_AT_signature
);
15472 if (attr
!= nullptr)
15474 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15476 /* The type's CU may not be the same as CU.
15477 Ensure TYPE is recorded with CU in die_type_hash. */
15478 return set_die_type (die
, type
, cu
);
15481 type
= alloc_type (objfile
);
15483 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15484 name
= dwarf2_full_name (NULL
, die
, cu
);
15486 TYPE_NAME (type
) = name
;
15488 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15491 struct type
*underlying_type
= die_type (die
, cu
);
15493 TYPE_TARGET_TYPE (type
) = underlying_type
;
15496 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15497 if (attr
!= nullptr)
15499 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15503 TYPE_LENGTH (type
) = 0;
15506 maybe_set_alignment (cu
, die
, type
);
15508 /* The enumeration DIE can be incomplete. In Ada, any type can be
15509 declared as private in the package spec, and then defined only
15510 inside the package body. Such types are known as Taft Amendment
15511 Types. When another package uses such a type, an incomplete DIE
15512 may be generated by the compiler. */
15513 if (die_is_declaration (die
, cu
))
15514 TYPE_STUB (type
) = 1;
15516 /* Finish the creation of this type by using the enum's children.
15517 We must call this even when the underlying type has been provided
15518 so that we can determine if we're looking at a "flag" enum. */
15519 update_enumeration_type_from_children (die
, type
, cu
);
15521 /* If this type has an underlying type that is not a stub, then we
15522 may use its attributes. We always use the "unsigned" attribute
15523 in this situation, because ordinarily we guess whether the type
15524 is unsigned -- but the guess can be wrong and the underlying type
15525 can tell us the reality. However, we defer to a local size
15526 attribute if one exists, because this lets the compiler override
15527 the underlying type if needed. */
15528 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15530 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15531 if (TYPE_LENGTH (type
) == 0)
15532 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15533 if (TYPE_RAW_ALIGN (type
) == 0
15534 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15535 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15538 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15540 return set_die_type (die
, type
, cu
);
15543 /* Given a pointer to a die which begins an enumeration, process all
15544 the dies that define the members of the enumeration, and create the
15545 symbol for the enumeration type.
15547 NOTE: We reverse the order of the element list. */
15550 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15552 struct type
*this_type
;
15554 this_type
= get_die_type (die
, cu
);
15555 if (this_type
== NULL
)
15556 this_type
= read_enumeration_type (die
, cu
);
15558 if (die
->child
!= NULL
)
15560 struct die_info
*child_die
;
15561 struct symbol
*sym
;
15562 std::vector
<struct field
> fields
;
15565 child_die
= die
->child
;
15566 while (child_die
&& child_die
->tag
)
15568 if (child_die
->tag
!= DW_TAG_enumerator
)
15570 process_die (child_die
, cu
);
15574 name
= dwarf2_name (child_die
, cu
);
15577 sym
= new_symbol (child_die
, this_type
, cu
);
15579 fields
.emplace_back ();
15580 struct field
&field
= fields
.back ();
15582 FIELD_NAME (field
) = sym
->linkage_name ();
15583 FIELD_TYPE (field
) = NULL
;
15584 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15585 FIELD_BITSIZE (field
) = 0;
15589 child_die
= child_die
->sibling
;
15592 if (!fields
.empty ())
15594 TYPE_NFIELDS (this_type
) = fields
.size ();
15595 TYPE_FIELDS (this_type
) = (struct field
*)
15596 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15597 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15598 sizeof (struct field
) * fields
.size ());
15602 /* If we are reading an enum from a .debug_types unit, and the enum
15603 is a declaration, and the enum is not the signatured type in the
15604 unit, then we do not want to add a symbol for it. Adding a
15605 symbol would in some cases obscure the true definition of the
15606 enum, giving users an incomplete type when the definition is
15607 actually available. Note that we do not want to do this for all
15608 enums which are just declarations, because C++0x allows forward
15609 enum declarations. */
15610 if (cu
->per_cu
->is_debug_types
15611 && die_is_declaration (die
, cu
))
15613 struct signatured_type
*sig_type
;
15615 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15616 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15617 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15621 new_symbol (die
, this_type
, cu
);
15624 /* Extract all information from a DW_TAG_array_type DIE and put it in
15625 the DIE's type field. For now, this only handles one dimensional
15628 static struct type
*
15629 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15631 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15632 struct die_info
*child_die
;
15634 struct type
*element_type
, *range_type
, *index_type
;
15635 struct attribute
*attr
;
15637 struct dynamic_prop
*byte_stride_prop
= NULL
;
15638 unsigned int bit_stride
= 0;
15640 element_type
= die_type (die
, cu
);
15642 /* The die_type call above may have already set the type for this DIE. */
15643 type
= get_die_type (die
, cu
);
15647 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15651 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15654 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15655 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15659 complaint (_("unable to read array DW_AT_byte_stride "
15660 " - DIE at %s [in module %s]"),
15661 sect_offset_str (die
->sect_off
),
15662 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15663 /* Ignore this attribute. We will likely not be able to print
15664 arrays of this type correctly, but there is little we can do
15665 to help if we cannot read the attribute's value. */
15666 byte_stride_prop
= NULL
;
15670 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15672 bit_stride
= DW_UNSND (attr
);
15674 /* Irix 6.2 native cc creates array types without children for
15675 arrays with unspecified length. */
15676 if (die
->child
== NULL
)
15678 index_type
= objfile_type (objfile
)->builtin_int
;
15679 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15680 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15681 byte_stride_prop
, bit_stride
);
15682 return set_die_type (die
, type
, cu
);
15685 std::vector
<struct type
*> range_types
;
15686 child_die
= die
->child
;
15687 while (child_die
&& child_die
->tag
)
15689 if (child_die
->tag
== DW_TAG_subrange_type
)
15691 struct type
*child_type
= read_type_die (child_die
, cu
);
15693 if (child_type
!= NULL
)
15695 /* The range type was succesfully read. Save it for the
15696 array type creation. */
15697 range_types
.push_back (child_type
);
15700 child_die
= child_die
->sibling
;
15703 /* Dwarf2 dimensions are output from left to right, create the
15704 necessary array types in backwards order. */
15706 type
= element_type
;
15708 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15712 while (i
< range_types
.size ())
15713 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15714 byte_stride_prop
, bit_stride
);
15718 size_t ndim
= range_types
.size ();
15720 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15721 byte_stride_prop
, bit_stride
);
15724 /* Understand Dwarf2 support for vector types (like they occur on
15725 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15726 array type. This is not part of the Dwarf2/3 standard yet, but a
15727 custom vendor extension. The main difference between a regular
15728 array and the vector variant is that vectors are passed by value
15730 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15731 if (attr
!= nullptr)
15732 make_vector_type (type
);
15734 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15735 implementation may choose to implement triple vectors using this
15737 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15738 if (attr
!= nullptr)
15740 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15741 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15743 complaint (_("DW_AT_byte_size for array type smaller "
15744 "than the total size of elements"));
15747 name
= dwarf2_name (die
, cu
);
15749 TYPE_NAME (type
) = name
;
15751 maybe_set_alignment (cu
, die
, type
);
15753 /* Install the type in the die. */
15754 set_die_type (die
, type
, cu
);
15756 /* set_die_type should be already done. */
15757 set_descriptive_type (type
, die
, cu
);
15762 static enum dwarf_array_dim_ordering
15763 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15765 struct attribute
*attr
;
15767 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15769 if (attr
!= nullptr)
15770 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15772 /* GNU F77 is a special case, as at 08/2004 array type info is the
15773 opposite order to the dwarf2 specification, but data is still
15774 laid out as per normal fortran.
15776 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15777 version checking. */
15779 if (cu
->language
== language_fortran
15780 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15782 return DW_ORD_row_major
;
15785 switch (cu
->language_defn
->la_array_ordering
)
15787 case array_column_major
:
15788 return DW_ORD_col_major
;
15789 case array_row_major
:
15791 return DW_ORD_row_major
;
15795 /* Extract all information from a DW_TAG_set_type DIE and put it in
15796 the DIE's type field. */
15798 static struct type
*
15799 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15801 struct type
*domain_type
, *set_type
;
15802 struct attribute
*attr
;
15804 domain_type
= die_type (die
, cu
);
15806 /* The die_type call above may have already set the type for this DIE. */
15807 set_type
= get_die_type (die
, cu
);
15811 set_type
= create_set_type (NULL
, domain_type
);
15813 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15814 if (attr
!= nullptr)
15815 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15817 maybe_set_alignment (cu
, die
, set_type
);
15819 return set_die_type (die
, set_type
, cu
);
15822 /* A helper for read_common_block that creates a locexpr baton.
15823 SYM is the symbol which we are marking as computed.
15824 COMMON_DIE is the DIE for the common block.
15825 COMMON_LOC is the location expression attribute for the common
15827 MEMBER_LOC is the location expression attribute for the particular
15828 member of the common block that we are processing.
15829 CU is the CU from which the above come. */
15832 mark_common_block_symbol_computed (struct symbol
*sym
,
15833 struct die_info
*common_die
,
15834 struct attribute
*common_loc
,
15835 struct attribute
*member_loc
,
15836 struct dwarf2_cu
*cu
)
15838 struct dwarf2_per_objfile
*dwarf2_per_objfile
15839 = cu
->per_cu
->dwarf2_per_objfile
;
15840 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15841 struct dwarf2_locexpr_baton
*baton
;
15843 unsigned int cu_off
;
15844 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15845 LONGEST offset
= 0;
15847 gdb_assert (common_loc
&& member_loc
);
15848 gdb_assert (common_loc
->form_is_block ());
15849 gdb_assert (member_loc
->form_is_block ()
15850 || member_loc
->form_is_constant ());
15852 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15853 baton
->per_cu
= cu
->per_cu
;
15854 gdb_assert (baton
->per_cu
);
15856 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15858 if (member_loc
->form_is_constant ())
15860 offset
= member_loc
->constant_value (0);
15861 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15864 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15866 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15869 *ptr
++ = DW_OP_call4
;
15870 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15871 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15874 if (member_loc
->form_is_constant ())
15876 *ptr
++ = DW_OP_addr
;
15877 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15878 ptr
+= cu
->header
.addr_size
;
15882 /* We have to copy the data here, because DW_OP_call4 will only
15883 use a DW_AT_location attribute. */
15884 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15885 ptr
+= DW_BLOCK (member_loc
)->size
;
15888 *ptr
++ = DW_OP_plus
;
15889 gdb_assert (ptr
- baton
->data
== baton
->size
);
15891 SYMBOL_LOCATION_BATON (sym
) = baton
;
15892 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15895 /* Create appropriate locally-scoped variables for all the
15896 DW_TAG_common_block entries. Also create a struct common_block
15897 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15898 is used to separate the common blocks name namespace from regular
15902 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15904 struct attribute
*attr
;
15906 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15907 if (attr
!= nullptr)
15909 /* Support the .debug_loc offsets. */
15910 if (attr
->form_is_block ())
15914 else if (attr
->form_is_section_offset ())
15916 dwarf2_complex_location_expr_complaint ();
15921 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15922 "common block member");
15927 if (die
->child
!= NULL
)
15929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15930 struct die_info
*child_die
;
15931 size_t n_entries
= 0, size
;
15932 struct common_block
*common_block
;
15933 struct symbol
*sym
;
15935 for (child_die
= die
->child
;
15936 child_die
&& child_die
->tag
;
15937 child_die
= child_die
->sibling
)
15940 size
= (sizeof (struct common_block
)
15941 + (n_entries
- 1) * sizeof (struct symbol
*));
15943 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15945 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15946 common_block
->n_entries
= 0;
15948 for (child_die
= die
->child
;
15949 child_die
&& child_die
->tag
;
15950 child_die
= child_die
->sibling
)
15952 /* Create the symbol in the DW_TAG_common_block block in the current
15954 sym
= new_symbol (child_die
, NULL
, cu
);
15957 struct attribute
*member_loc
;
15959 common_block
->contents
[common_block
->n_entries
++] = sym
;
15961 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15965 /* GDB has handled this for a long time, but it is
15966 not specified by DWARF. It seems to have been
15967 emitted by gfortran at least as recently as:
15968 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15969 complaint (_("Variable in common block has "
15970 "DW_AT_data_member_location "
15971 "- DIE at %s [in module %s]"),
15972 sect_offset_str (child_die
->sect_off
),
15973 objfile_name (objfile
));
15975 if (member_loc
->form_is_section_offset ())
15976 dwarf2_complex_location_expr_complaint ();
15977 else if (member_loc
->form_is_constant ()
15978 || member_loc
->form_is_block ())
15980 if (attr
!= nullptr)
15981 mark_common_block_symbol_computed (sym
, die
, attr
,
15985 dwarf2_complex_location_expr_complaint ();
15990 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
15991 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
15995 /* Create a type for a C++ namespace. */
15997 static struct type
*
15998 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16000 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16001 const char *previous_prefix
, *name
;
16005 /* For extensions, reuse the type of the original namespace. */
16006 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16008 struct die_info
*ext_die
;
16009 struct dwarf2_cu
*ext_cu
= cu
;
16011 ext_die
= dwarf2_extension (die
, &ext_cu
);
16012 type
= read_type_die (ext_die
, ext_cu
);
16014 /* EXT_CU may not be the same as CU.
16015 Ensure TYPE is recorded with CU in die_type_hash. */
16016 return set_die_type (die
, type
, cu
);
16019 name
= namespace_name (die
, &is_anonymous
, cu
);
16021 /* Now build the name of the current namespace. */
16023 previous_prefix
= determine_prefix (die
, cu
);
16024 if (previous_prefix
[0] != '\0')
16025 name
= typename_concat (&objfile
->objfile_obstack
,
16026 previous_prefix
, name
, 0, cu
);
16028 /* Create the type. */
16029 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16031 return set_die_type (die
, type
, cu
);
16034 /* Read a namespace scope. */
16037 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16039 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16042 /* Add a symbol associated to this if we haven't seen the namespace
16043 before. Also, add a using directive if it's an anonymous
16046 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16050 type
= read_type_die (die
, cu
);
16051 new_symbol (die
, type
, cu
);
16053 namespace_name (die
, &is_anonymous
, cu
);
16056 const char *previous_prefix
= determine_prefix (die
, cu
);
16058 std::vector
<const char *> excludes
;
16059 add_using_directive (using_directives (cu
),
16060 previous_prefix
, TYPE_NAME (type
), NULL
,
16061 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16065 if (die
->child
!= NULL
)
16067 struct die_info
*child_die
= die
->child
;
16069 while (child_die
&& child_die
->tag
)
16071 process_die (child_die
, cu
);
16072 child_die
= child_die
->sibling
;
16077 /* Read a Fortran module as type. This DIE can be only a declaration used for
16078 imported module. Still we need that type as local Fortran "use ... only"
16079 declaration imports depend on the created type in determine_prefix. */
16081 static struct type
*
16082 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16085 const char *module_name
;
16088 module_name
= dwarf2_name (die
, cu
);
16089 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16091 return set_die_type (die
, type
, cu
);
16094 /* Read a Fortran module. */
16097 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16099 struct die_info
*child_die
= die
->child
;
16102 type
= read_type_die (die
, cu
);
16103 new_symbol (die
, type
, cu
);
16105 while (child_die
&& child_die
->tag
)
16107 process_die (child_die
, cu
);
16108 child_die
= child_die
->sibling
;
16112 /* Return the name of the namespace represented by DIE. Set
16113 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16116 static const char *
16117 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16119 struct die_info
*current_die
;
16120 const char *name
= NULL
;
16122 /* Loop through the extensions until we find a name. */
16124 for (current_die
= die
;
16125 current_die
!= NULL
;
16126 current_die
= dwarf2_extension (die
, &cu
))
16128 /* We don't use dwarf2_name here so that we can detect the absence
16129 of a name -> anonymous namespace. */
16130 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16136 /* Is it an anonymous namespace? */
16138 *is_anonymous
= (name
== NULL
);
16140 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16145 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16146 the user defined type vector. */
16148 static struct type
*
16149 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16151 struct gdbarch
*gdbarch
16152 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16153 struct comp_unit_head
*cu_header
= &cu
->header
;
16155 struct attribute
*attr_byte_size
;
16156 struct attribute
*attr_address_class
;
16157 int byte_size
, addr_class
;
16158 struct type
*target_type
;
16160 target_type
= die_type (die
, cu
);
16162 /* The die_type call above may have already set the type for this DIE. */
16163 type
= get_die_type (die
, cu
);
16167 type
= lookup_pointer_type (target_type
);
16169 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16170 if (attr_byte_size
)
16171 byte_size
= DW_UNSND (attr_byte_size
);
16173 byte_size
= cu_header
->addr_size
;
16175 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16176 if (attr_address_class
)
16177 addr_class
= DW_UNSND (attr_address_class
);
16179 addr_class
= DW_ADDR_none
;
16181 ULONGEST alignment
= get_alignment (cu
, die
);
16183 /* If the pointer size, alignment, or address class is different
16184 than the default, create a type variant marked as such and set
16185 the length accordingly. */
16186 if (TYPE_LENGTH (type
) != byte_size
16187 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16188 && alignment
!= TYPE_RAW_ALIGN (type
))
16189 || addr_class
!= DW_ADDR_none
)
16191 if (gdbarch_address_class_type_flags_p (gdbarch
))
16195 type_flags
= gdbarch_address_class_type_flags
16196 (gdbarch
, byte_size
, addr_class
);
16197 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16199 type
= make_type_with_address_space (type
, type_flags
);
16201 else if (TYPE_LENGTH (type
) != byte_size
)
16203 complaint (_("invalid pointer size %d"), byte_size
);
16205 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16207 complaint (_("Invalid DW_AT_alignment"
16208 " - DIE at %s [in module %s]"),
16209 sect_offset_str (die
->sect_off
),
16210 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16214 /* Should we also complain about unhandled address classes? */
16218 TYPE_LENGTH (type
) = byte_size
;
16219 set_type_align (type
, alignment
);
16220 return set_die_type (die
, type
, cu
);
16223 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16224 the user defined type vector. */
16226 static struct type
*
16227 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16230 struct type
*to_type
;
16231 struct type
*domain
;
16233 to_type
= die_type (die
, cu
);
16234 domain
= die_containing_type (die
, cu
);
16236 /* The calls above may have already set the type for this DIE. */
16237 type
= get_die_type (die
, cu
);
16241 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16242 type
= lookup_methodptr_type (to_type
);
16243 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16245 struct type
*new_type
16246 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16248 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16249 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16250 TYPE_VARARGS (to_type
));
16251 type
= lookup_methodptr_type (new_type
);
16254 type
= lookup_memberptr_type (to_type
, domain
);
16256 return set_die_type (die
, type
, cu
);
16259 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16260 the user defined type vector. */
16262 static struct type
*
16263 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16264 enum type_code refcode
)
16266 struct comp_unit_head
*cu_header
= &cu
->header
;
16267 struct type
*type
, *target_type
;
16268 struct attribute
*attr
;
16270 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16272 target_type
= die_type (die
, cu
);
16274 /* The die_type call above may have already set the type for this DIE. */
16275 type
= get_die_type (die
, cu
);
16279 type
= lookup_reference_type (target_type
, refcode
);
16280 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16281 if (attr
!= nullptr)
16283 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16287 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16289 maybe_set_alignment (cu
, die
, type
);
16290 return set_die_type (die
, type
, cu
);
16293 /* Add the given cv-qualifiers to the element type of the array. GCC
16294 outputs DWARF type qualifiers that apply to an array, not the
16295 element type. But GDB relies on the array element type to carry
16296 the cv-qualifiers. This mimics section 6.7.3 of the C99
16299 static struct type
*
16300 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16301 struct type
*base_type
, int cnst
, int voltl
)
16303 struct type
*el_type
, *inner_array
;
16305 base_type
= copy_type (base_type
);
16306 inner_array
= base_type
;
16308 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16310 TYPE_TARGET_TYPE (inner_array
) =
16311 copy_type (TYPE_TARGET_TYPE (inner_array
));
16312 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16315 el_type
= TYPE_TARGET_TYPE (inner_array
);
16316 cnst
|= TYPE_CONST (el_type
);
16317 voltl
|= TYPE_VOLATILE (el_type
);
16318 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16320 return set_die_type (die
, base_type
, cu
);
16323 static struct type
*
16324 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16326 struct type
*base_type
, *cv_type
;
16328 base_type
= die_type (die
, cu
);
16330 /* The die_type call above may have already set the type for this DIE. */
16331 cv_type
= get_die_type (die
, cu
);
16335 /* In case the const qualifier is applied to an array type, the element type
16336 is so qualified, not the array type (section 6.7.3 of C99). */
16337 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16338 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16340 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16341 return set_die_type (die
, cv_type
, cu
);
16344 static struct type
*
16345 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16347 struct type
*base_type
, *cv_type
;
16349 base_type
= die_type (die
, cu
);
16351 /* The die_type call above may have already set the type for this DIE. */
16352 cv_type
= get_die_type (die
, cu
);
16356 /* In case the volatile qualifier is applied to an array type, the
16357 element type is so qualified, not the array type (section 6.7.3
16359 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16360 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16362 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16363 return set_die_type (die
, cv_type
, cu
);
16366 /* Handle DW_TAG_restrict_type. */
16368 static struct type
*
16369 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16371 struct type
*base_type
, *cv_type
;
16373 base_type
= die_type (die
, cu
);
16375 /* The die_type call above may have already set the type for this DIE. */
16376 cv_type
= get_die_type (die
, cu
);
16380 cv_type
= make_restrict_type (base_type
);
16381 return set_die_type (die
, cv_type
, cu
);
16384 /* Handle DW_TAG_atomic_type. */
16386 static struct type
*
16387 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16389 struct type
*base_type
, *cv_type
;
16391 base_type
= die_type (die
, cu
);
16393 /* The die_type call above may have already set the type for this DIE. */
16394 cv_type
= get_die_type (die
, cu
);
16398 cv_type
= make_atomic_type (base_type
);
16399 return set_die_type (die
, cv_type
, cu
);
16402 /* Extract all information from a DW_TAG_string_type DIE and add to
16403 the user defined type vector. It isn't really a user defined type,
16404 but it behaves like one, with other DIE's using an AT_user_def_type
16405 attribute to reference it. */
16407 static struct type
*
16408 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16410 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16411 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16412 struct type
*type
, *range_type
, *index_type
, *char_type
;
16413 struct attribute
*attr
;
16414 struct dynamic_prop prop
;
16415 bool length_is_constant
= true;
16418 /* There are a couple of places where bit sizes might be made use of
16419 when parsing a DW_TAG_string_type, however, no producer that we know
16420 of make use of these. Handling bit sizes that are a multiple of the
16421 byte size is easy enough, but what about other bit sizes? Lets deal
16422 with that problem when we have to. Warn about these attributes being
16423 unsupported, then parse the type and ignore them like we always
16425 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16426 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16428 static bool warning_printed
= false;
16429 if (!warning_printed
)
16431 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16432 "currently supported on DW_TAG_string_type."));
16433 warning_printed
= true;
16437 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16438 if (attr
!= nullptr && !attr
->form_is_constant ())
16440 /* The string length describes the location at which the length of
16441 the string can be found. The size of the length field can be
16442 specified with one of the attributes below. */
16443 struct type
*prop_type
;
16444 struct attribute
*len
16445 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16446 if (len
== nullptr)
16447 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16448 if (len
!= nullptr && len
->form_is_constant ())
16450 /* Pass 0 as the default as we know this attribute is constant
16451 and the default value will not be returned. */
16452 LONGEST sz
= len
->constant_value (0);
16453 prop_type
= cu
->per_cu
->int_type (sz
, true);
16457 /* If the size is not specified then we assume it is the size of
16458 an address on this target. */
16459 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16462 /* Convert the attribute into a dynamic property. */
16463 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16466 length_is_constant
= false;
16468 else if (attr
!= nullptr)
16470 /* This DW_AT_string_length just contains the length with no
16471 indirection. There's no need to create a dynamic property in this
16472 case. Pass 0 for the default value as we know it will not be
16473 returned in this case. */
16474 length
= attr
->constant_value (0);
16476 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16478 /* We don't currently support non-constant byte sizes for strings. */
16479 length
= attr
->constant_value (1);
16483 /* Use 1 as a fallback length if we have nothing else. */
16487 index_type
= objfile_type (objfile
)->builtin_int
;
16488 if (length_is_constant
)
16489 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16492 struct dynamic_prop low_bound
;
16494 low_bound
.kind
= PROP_CONST
;
16495 low_bound
.data
.const_val
= 1;
16496 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16498 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16499 type
= create_string_type (NULL
, char_type
, range_type
);
16501 return set_die_type (die
, type
, cu
);
16504 /* Assuming that DIE corresponds to a function, returns nonzero
16505 if the function is prototyped. */
16508 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16510 struct attribute
*attr
;
16512 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16513 if (attr
&& (DW_UNSND (attr
) != 0))
16516 /* The DWARF standard implies that the DW_AT_prototyped attribute
16517 is only meaningful for C, but the concept also extends to other
16518 languages that allow unprototyped functions (Eg: Objective C).
16519 For all other languages, assume that functions are always
16521 if (cu
->language
!= language_c
16522 && cu
->language
!= language_objc
16523 && cu
->language
!= language_opencl
)
16526 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16527 prototyped and unprototyped functions; default to prototyped,
16528 since that is more common in modern code (and RealView warns
16529 about unprototyped functions). */
16530 if (producer_is_realview (cu
->producer
))
16536 /* Handle DIES due to C code like:
16540 int (*funcp)(int a, long l);
16544 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16546 static struct type
*
16547 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16549 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16550 struct type
*type
; /* Type that this function returns. */
16551 struct type
*ftype
; /* Function that returns above type. */
16552 struct attribute
*attr
;
16554 type
= die_type (die
, cu
);
16556 /* The die_type call above may have already set the type for this DIE. */
16557 ftype
= get_die_type (die
, cu
);
16561 ftype
= lookup_function_type (type
);
16563 if (prototyped_function_p (die
, cu
))
16564 TYPE_PROTOTYPED (ftype
) = 1;
16566 /* Store the calling convention in the type if it's available in
16567 the subroutine die. Otherwise set the calling convention to
16568 the default value DW_CC_normal. */
16569 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16570 if (attr
!= nullptr
16571 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16572 TYPE_CALLING_CONVENTION (ftype
)
16573 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16574 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16575 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16577 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16579 /* Record whether the function returns normally to its caller or not
16580 if the DWARF producer set that information. */
16581 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16582 if (attr
&& (DW_UNSND (attr
) != 0))
16583 TYPE_NO_RETURN (ftype
) = 1;
16585 /* We need to add the subroutine type to the die immediately so
16586 we don't infinitely recurse when dealing with parameters
16587 declared as the same subroutine type. */
16588 set_die_type (die
, ftype
, cu
);
16590 if (die
->child
!= NULL
)
16592 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16593 struct die_info
*child_die
;
16594 int nparams
, iparams
;
16596 /* Count the number of parameters.
16597 FIXME: GDB currently ignores vararg functions, but knows about
16598 vararg member functions. */
16600 child_die
= die
->child
;
16601 while (child_die
&& child_die
->tag
)
16603 if (child_die
->tag
== DW_TAG_formal_parameter
)
16605 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16606 TYPE_VARARGS (ftype
) = 1;
16607 child_die
= child_die
->sibling
;
16610 /* Allocate storage for parameters and fill them in. */
16611 TYPE_NFIELDS (ftype
) = nparams
;
16612 TYPE_FIELDS (ftype
) = (struct field
*)
16613 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16615 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16616 even if we error out during the parameters reading below. */
16617 for (iparams
= 0; iparams
< nparams
; iparams
++)
16618 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16621 child_die
= die
->child
;
16622 while (child_die
&& child_die
->tag
)
16624 if (child_die
->tag
== DW_TAG_formal_parameter
)
16626 struct type
*arg_type
;
16628 /* DWARF version 2 has no clean way to discern C++
16629 static and non-static member functions. G++ helps
16630 GDB by marking the first parameter for non-static
16631 member functions (which is the this pointer) as
16632 artificial. We pass this information to
16633 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16635 DWARF version 3 added DW_AT_object_pointer, which GCC
16636 4.5 does not yet generate. */
16637 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16638 if (attr
!= nullptr)
16639 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16641 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16642 arg_type
= die_type (child_die
, cu
);
16644 /* RealView does not mark THIS as const, which the testsuite
16645 expects. GCC marks THIS as const in method definitions,
16646 but not in the class specifications (GCC PR 43053). */
16647 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16648 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16651 struct dwarf2_cu
*arg_cu
= cu
;
16652 const char *name
= dwarf2_name (child_die
, cu
);
16654 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16655 if (attr
!= nullptr)
16657 /* If the compiler emits this, use it. */
16658 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16661 else if (name
&& strcmp (name
, "this") == 0)
16662 /* Function definitions will have the argument names. */
16664 else if (name
== NULL
&& iparams
== 0)
16665 /* Declarations may not have the names, so like
16666 elsewhere in GDB, assume an artificial first
16667 argument is "this". */
16671 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16675 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16678 child_die
= child_die
->sibling
;
16685 static struct type
*
16686 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16688 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16689 const char *name
= NULL
;
16690 struct type
*this_type
, *target_type
;
16692 name
= dwarf2_full_name (NULL
, die
, cu
);
16693 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16694 TYPE_TARGET_STUB (this_type
) = 1;
16695 set_die_type (die
, this_type
, cu
);
16696 target_type
= die_type (die
, cu
);
16697 if (target_type
!= this_type
)
16698 TYPE_TARGET_TYPE (this_type
) = target_type
;
16701 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16702 spec and cause infinite loops in GDB. */
16703 complaint (_("Self-referential DW_TAG_typedef "
16704 "- DIE at %s [in module %s]"),
16705 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16706 TYPE_TARGET_TYPE (this_type
) = NULL
;
16710 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16711 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16712 Handle these by just returning the target type, rather than
16713 constructing an anonymous typedef type and trying to handle this
16715 set_die_type (die
, target_type
, cu
);
16716 return target_type
;
16721 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16722 (which may be different from NAME) to the architecture back-end to allow
16723 it to guess the correct format if necessary. */
16725 static struct type
*
16726 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16727 const char *name_hint
, enum bfd_endian byte_order
)
16729 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16730 const struct floatformat
**format
;
16733 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16735 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16737 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16742 /* Allocate an integer type of size BITS and name NAME. */
16744 static struct type
*
16745 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16746 int bits
, int unsigned_p
, const char *name
)
16750 /* Versions of Intel's C Compiler generate an integer type called "void"
16751 instead of using DW_TAG_unspecified_type. This has been seen on
16752 at least versions 14, 17, and 18. */
16753 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16754 && strcmp (name
, "void") == 0)
16755 type
= objfile_type (objfile
)->builtin_void
;
16757 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16762 /* Initialise and return a floating point type of size BITS suitable for
16763 use as a component of a complex number. The NAME_HINT is passed through
16764 when initialising the floating point type and is the name of the complex
16767 As DWARF doesn't currently provide an explicit name for the components
16768 of a complex number, but it can be helpful to have these components
16769 named, we try to select a suitable name based on the size of the
16771 static struct type
*
16772 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16773 struct objfile
*objfile
,
16774 int bits
, const char *name_hint
,
16775 enum bfd_endian byte_order
)
16777 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16778 struct type
*tt
= nullptr;
16780 /* Try to find a suitable floating point builtin type of size BITS.
16781 We're going to use the name of this type as the name for the complex
16782 target type that we are about to create. */
16783 switch (cu
->language
)
16785 case language_fortran
:
16789 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16792 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16794 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16796 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16804 tt
= builtin_type (gdbarch
)->builtin_float
;
16807 tt
= builtin_type (gdbarch
)->builtin_double
;
16809 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16811 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16817 /* If the type we found doesn't match the size we were looking for, then
16818 pretend we didn't find a type at all, the complex target type we
16819 create will then be nameless. */
16820 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16823 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16824 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16827 /* Find a representation of a given base type and install
16828 it in the TYPE field of the die. */
16830 static struct type
*
16831 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16833 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16835 struct attribute
*attr
;
16836 int encoding
= 0, bits
= 0;
16840 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16841 if (attr
!= nullptr)
16842 encoding
= DW_UNSND (attr
);
16843 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16844 if (attr
!= nullptr)
16845 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16846 name
= dwarf2_name (die
, cu
);
16848 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16850 arch
= get_objfile_arch (objfile
);
16851 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16853 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16856 int endianity
= DW_UNSND (attr
);
16861 byte_order
= BFD_ENDIAN_BIG
;
16863 case DW_END_little
:
16864 byte_order
= BFD_ENDIAN_LITTLE
;
16867 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16874 case DW_ATE_address
:
16875 /* Turn DW_ATE_address into a void * pointer. */
16876 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16877 type
= init_pointer_type (objfile
, bits
, name
, type
);
16879 case DW_ATE_boolean
:
16880 type
= init_boolean_type (objfile
, bits
, 1, name
);
16882 case DW_ATE_complex_float
:
16883 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16885 type
= init_complex_type (name
, type
);
16887 case DW_ATE_decimal_float
:
16888 type
= init_decfloat_type (objfile
, bits
, name
);
16891 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16893 case DW_ATE_signed
:
16894 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16896 case DW_ATE_unsigned
:
16897 if (cu
->language
== language_fortran
16899 && startswith (name
, "character("))
16900 type
= init_character_type (objfile
, bits
, 1, name
);
16902 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16904 case DW_ATE_signed_char
:
16905 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16906 || cu
->language
== language_pascal
16907 || cu
->language
== language_fortran
)
16908 type
= init_character_type (objfile
, bits
, 0, name
);
16910 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16912 case DW_ATE_unsigned_char
:
16913 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16914 || cu
->language
== language_pascal
16915 || cu
->language
== language_fortran
16916 || cu
->language
== language_rust
)
16917 type
= init_character_type (objfile
, bits
, 1, name
);
16919 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16924 type
= builtin_type (arch
)->builtin_char16
;
16925 else if (bits
== 32)
16926 type
= builtin_type (arch
)->builtin_char32
;
16929 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16931 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16933 return set_die_type (die
, type
, cu
);
16938 complaint (_("unsupported DW_AT_encoding: '%s'"),
16939 dwarf_type_encoding_name (encoding
));
16940 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16944 if (name
&& strcmp (name
, "char") == 0)
16945 TYPE_NOSIGN (type
) = 1;
16947 maybe_set_alignment (cu
, die
, type
);
16949 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16951 return set_die_type (die
, type
, cu
);
16954 /* Parse dwarf attribute if it's a block, reference or constant and put the
16955 resulting value of the attribute into struct bound_prop.
16956 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
16959 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
16960 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
16961 struct type
*default_type
)
16963 struct dwarf2_property_baton
*baton
;
16964 struct obstack
*obstack
16965 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16967 gdb_assert (default_type
!= NULL
);
16969 if (attr
== NULL
|| prop
== NULL
)
16972 if (attr
->form_is_block ())
16974 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
16975 baton
->property_type
= default_type
;
16976 baton
->locexpr
.per_cu
= cu
->per_cu
;
16977 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
16978 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
16979 switch (attr
->name
)
16981 case DW_AT_string_length
:
16982 baton
->locexpr
.is_reference
= true;
16985 baton
->locexpr
.is_reference
= false;
16988 prop
->data
.baton
= baton
;
16989 prop
->kind
= PROP_LOCEXPR
;
16990 gdb_assert (prop
->data
.baton
!= NULL
);
16992 else if (attr
->form_is_ref ())
16994 struct dwarf2_cu
*target_cu
= cu
;
16995 struct die_info
*target_die
;
16996 struct attribute
*target_attr
;
16998 target_die
= follow_die_ref (die
, attr
, &target_cu
);
16999 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17000 if (target_attr
== NULL
)
17001 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17003 if (target_attr
== NULL
)
17006 switch (target_attr
->name
)
17008 case DW_AT_location
:
17009 if (target_attr
->form_is_section_offset ())
17011 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17012 baton
->property_type
= die_type (target_die
, target_cu
);
17013 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17014 prop
->data
.baton
= baton
;
17015 prop
->kind
= PROP_LOCLIST
;
17016 gdb_assert (prop
->data
.baton
!= NULL
);
17018 else if (target_attr
->form_is_block ())
17020 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17021 baton
->property_type
= die_type (target_die
, target_cu
);
17022 baton
->locexpr
.per_cu
= cu
->per_cu
;
17023 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17024 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17025 baton
->locexpr
.is_reference
= true;
17026 prop
->data
.baton
= baton
;
17027 prop
->kind
= PROP_LOCEXPR
;
17028 gdb_assert (prop
->data
.baton
!= NULL
);
17032 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17033 "dynamic property");
17037 case DW_AT_data_member_location
:
17041 if (!handle_data_member_location (target_die
, target_cu
,
17045 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17046 baton
->property_type
= read_type_die (target_die
->parent
,
17048 baton
->offset_info
.offset
= offset
;
17049 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17050 prop
->data
.baton
= baton
;
17051 prop
->kind
= PROP_ADDR_OFFSET
;
17056 else if (attr
->form_is_constant ())
17058 prop
->data
.const_val
= attr
->constant_value (0);
17059 prop
->kind
= PROP_CONST
;
17063 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17064 dwarf2_name (die
, cu
));
17074 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17076 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17077 struct type
*int_type
;
17079 /* Helper macro to examine the various builtin types. */
17080 #define TRY_TYPE(F) \
17081 int_type = (unsigned_p \
17082 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17083 : objfile_type (objfile)->builtin_ ## F); \
17084 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17091 TRY_TYPE (long_long
);
17095 gdb_assert_not_reached ("unable to find suitable integer type");
17101 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17103 int addr_size
= this->addr_size ();
17104 return int_type (addr_size
, unsigned_p
);
17107 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17108 present (which is valid) then compute the default type based on the
17109 compilation units address size. */
17111 static struct type
*
17112 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17114 struct type
*index_type
= die_type (die
, cu
);
17116 /* Dwarf-2 specifications explicitly allows to create subrange types
17117 without specifying a base type.
17118 In that case, the base type must be set to the type of
17119 the lower bound, upper bound or count, in that order, if any of these
17120 three attributes references an object that has a type.
17121 If no base type is found, the Dwarf-2 specifications say that
17122 a signed integer type of size equal to the size of an address should
17124 For the following C code: `extern char gdb_int [];'
17125 GCC produces an empty range DIE.
17126 FIXME: muller/2010-05-28: Possible references to object for low bound,
17127 high bound or count are not yet handled by this code. */
17128 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17129 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17134 /* Read the given DW_AT_subrange DIE. */
17136 static struct type
*
17137 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17139 struct type
*base_type
, *orig_base_type
;
17140 struct type
*range_type
;
17141 struct attribute
*attr
;
17142 struct dynamic_prop low
, high
;
17143 int low_default_is_valid
;
17144 int high_bound_is_count
= 0;
17146 ULONGEST negative_mask
;
17148 orig_base_type
= read_subrange_index_type (die
, cu
);
17150 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17151 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17152 creating the range type, but we use the result of check_typedef
17153 when examining properties of the type. */
17154 base_type
= check_typedef (orig_base_type
);
17156 /* The die_type call above may have already set the type for this DIE. */
17157 range_type
= get_die_type (die
, cu
);
17161 low
.kind
= PROP_CONST
;
17162 high
.kind
= PROP_CONST
;
17163 high
.data
.const_val
= 0;
17165 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17166 omitting DW_AT_lower_bound. */
17167 switch (cu
->language
)
17170 case language_cplus
:
17171 low
.data
.const_val
= 0;
17172 low_default_is_valid
= 1;
17174 case language_fortran
:
17175 low
.data
.const_val
= 1;
17176 low_default_is_valid
= 1;
17179 case language_objc
:
17180 case language_rust
:
17181 low
.data
.const_val
= 0;
17182 low_default_is_valid
= (cu
->header
.version
>= 4);
17186 case language_pascal
:
17187 low
.data
.const_val
= 1;
17188 low_default_is_valid
= (cu
->header
.version
>= 4);
17191 low
.data
.const_val
= 0;
17192 low_default_is_valid
= 0;
17196 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17197 if (attr
!= nullptr)
17198 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17199 else if (!low_default_is_valid
)
17200 complaint (_("Missing DW_AT_lower_bound "
17201 "- DIE at %s [in module %s]"),
17202 sect_offset_str (die
->sect_off
),
17203 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17205 struct attribute
*attr_ub
, *attr_count
;
17206 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17207 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17209 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17210 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17212 /* If bounds are constant do the final calculation here. */
17213 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17214 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17216 high_bound_is_count
= 1;
17220 if (attr_ub
!= NULL
)
17221 complaint (_("Unresolved DW_AT_upper_bound "
17222 "- DIE at %s [in module %s]"),
17223 sect_offset_str (die
->sect_off
),
17224 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17225 if (attr_count
!= NULL
)
17226 complaint (_("Unresolved DW_AT_count "
17227 "- DIE at %s [in module %s]"),
17228 sect_offset_str (die
->sect_off
),
17229 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17234 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17235 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17236 bias
= bias_attr
->constant_value (0);
17238 /* Normally, the DWARF producers are expected to use a signed
17239 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17240 But this is unfortunately not always the case, as witnessed
17241 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17242 is used instead. To work around that ambiguity, we treat
17243 the bounds as signed, and thus sign-extend their values, when
17244 the base type is signed. */
17246 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17247 if (low
.kind
== PROP_CONST
17248 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17249 low
.data
.const_val
|= negative_mask
;
17250 if (high
.kind
== PROP_CONST
17251 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17252 high
.data
.const_val
|= negative_mask
;
17254 /* Check for bit and byte strides. */
17255 struct dynamic_prop byte_stride_prop
;
17256 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17257 if (attr_byte_stride
!= nullptr)
17259 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17260 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17264 struct dynamic_prop bit_stride_prop
;
17265 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17266 if (attr_bit_stride
!= nullptr)
17268 /* It only makes sense to have either a bit or byte stride. */
17269 if (attr_byte_stride
!= nullptr)
17271 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17272 "- DIE at %s [in module %s]"),
17273 sect_offset_str (die
->sect_off
),
17274 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17275 attr_bit_stride
= nullptr;
17279 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17280 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17285 if (attr_byte_stride
!= nullptr
17286 || attr_bit_stride
!= nullptr)
17288 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17289 struct dynamic_prop
*stride
17290 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17293 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17294 &high
, bias
, stride
, byte_stride_p
);
17297 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17299 if (high_bound_is_count
)
17300 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17302 /* Ada expects an empty array on no boundary attributes. */
17303 if (attr
== NULL
&& cu
->language
!= language_ada
)
17304 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17306 name
= dwarf2_name (die
, cu
);
17308 TYPE_NAME (range_type
) = name
;
17310 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17311 if (attr
!= nullptr)
17312 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17314 maybe_set_alignment (cu
, die
, range_type
);
17316 set_die_type (die
, range_type
, cu
);
17318 /* set_die_type should be already done. */
17319 set_descriptive_type (range_type
, die
, cu
);
17324 static struct type
*
17325 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17329 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17331 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17333 /* In Ada, an unspecified type is typically used when the description
17334 of the type is deferred to a different unit. When encountering
17335 such a type, we treat it as a stub, and try to resolve it later on,
17337 if (cu
->language
== language_ada
)
17338 TYPE_STUB (type
) = 1;
17340 return set_die_type (die
, type
, cu
);
17343 /* Read a single die and all its descendents. Set the die's sibling
17344 field to NULL; set other fields in the die correctly, and set all
17345 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17346 location of the info_ptr after reading all of those dies. PARENT
17347 is the parent of the die in question. */
17349 static struct die_info
*
17350 read_die_and_children (const struct die_reader_specs
*reader
,
17351 const gdb_byte
*info_ptr
,
17352 const gdb_byte
**new_info_ptr
,
17353 struct die_info
*parent
)
17355 struct die_info
*die
;
17356 const gdb_byte
*cur_ptr
;
17358 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17361 *new_info_ptr
= cur_ptr
;
17364 store_in_ref_table (die
, reader
->cu
);
17366 if (die
->has_children
)
17367 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17371 *new_info_ptr
= cur_ptr
;
17374 die
->sibling
= NULL
;
17375 die
->parent
= parent
;
17379 /* Read a die, all of its descendents, and all of its siblings; set
17380 all of the fields of all of the dies correctly. Arguments are as
17381 in read_die_and_children. */
17383 static struct die_info
*
17384 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17385 const gdb_byte
*info_ptr
,
17386 const gdb_byte
**new_info_ptr
,
17387 struct die_info
*parent
)
17389 struct die_info
*first_die
, *last_sibling
;
17390 const gdb_byte
*cur_ptr
;
17392 cur_ptr
= info_ptr
;
17393 first_die
= last_sibling
= NULL
;
17397 struct die_info
*die
17398 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17402 *new_info_ptr
= cur_ptr
;
17409 last_sibling
->sibling
= die
;
17411 last_sibling
= die
;
17415 /* Read a die, all of its descendents, and all of its siblings; set
17416 all of the fields of all of the dies correctly. Arguments are as
17417 in read_die_and_children.
17418 This the main entry point for reading a DIE and all its children. */
17420 static struct die_info
*
17421 read_die_and_siblings (const struct die_reader_specs
*reader
,
17422 const gdb_byte
*info_ptr
,
17423 const gdb_byte
**new_info_ptr
,
17424 struct die_info
*parent
)
17426 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17427 new_info_ptr
, parent
);
17429 if (dwarf_die_debug
)
17431 fprintf_unfiltered (gdb_stdlog
,
17432 "Read die from %s@0x%x of %s:\n",
17433 reader
->die_section
->get_name (),
17434 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17435 bfd_get_filename (reader
->abfd
));
17436 dump_die (die
, dwarf_die_debug
);
17442 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17444 The caller is responsible for filling in the extra attributes
17445 and updating (*DIEP)->num_attrs.
17446 Set DIEP to point to a newly allocated die with its information,
17447 except for its child, sibling, and parent fields. */
17449 static const gdb_byte
*
17450 read_full_die_1 (const struct die_reader_specs
*reader
,
17451 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17452 int num_extra_attrs
)
17454 unsigned int abbrev_number
, bytes_read
, i
;
17455 struct abbrev_info
*abbrev
;
17456 struct die_info
*die
;
17457 struct dwarf2_cu
*cu
= reader
->cu
;
17458 bfd
*abfd
= reader
->abfd
;
17460 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17461 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17462 info_ptr
+= bytes_read
;
17463 if (!abbrev_number
)
17469 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17471 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17473 bfd_get_filename (abfd
));
17475 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17476 die
->sect_off
= sect_off
;
17477 die
->tag
= abbrev
->tag
;
17478 die
->abbrev
= abbrev_number
;
17479 die
->has_children
= abbrev
->has_children
;
17481 /* Make the result usable.
17482 The caller needs to update num_attrs after adding the extra
17484 die
->num_attrs
= abbrev
->num_attrs
;
17486 std::vector
<int> indexes_that_need_reprocess
;
17487 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17489 bool need_reprocess
;
17491 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17492 info_ptr
, &need_reprocess
);
17493 if (need_reprocess
)
17494 indexes_that_need_reprocess
.push_back (i
);
17497 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17498 if (attr
!= nullptr)
17499 cu
->str_offsets_base
= DW_UNSND (attr
);
17501 auto maybe_addr_base
= die
->addr_base ();
17502 if (maybe_addr_base
.has_value ())
17503 cu
->addr_base
= *maybe_addr_base
;
17504 for (int index
: indexes_that_need_reprocess
)
17505 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17510 /* Read a die and all its attributes.
17511 Set DIEP to point to a newly allocated die with its information,
17512 except for its child, sibling, and parent fields. */
17514 static const gdb_byte
*
17515 read_full_die (const struct die_reader_specs
*reader
,
17516 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17518 const gdb_byte
*result
;
17520 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17522 if (dwarf_die_debug
)
17524 fprintf_unfiltered (gdb_stdlog
,
17525 "Read die from %s@0x%x of %s:\n",
17526 reader
->die_section
->get_name (),
17527 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17528 bfd_get_filename (reader
->abfd
));
17529 dump_die (*diep
, dwarf_die_debug
);
17536 /* Returns nonzero if TAG represents a type that we might generate a partial
17540 is_type_tag_for_partial (int tag
)
17545 /* Some types that would be reasonable to generate partial symbols for,
17546 that we don't at present. */
17547 case DW_TAG_array_type
:
17548 case DW_TAG_file_type
:
17549 case DW_TAG_ptr_to_member_type
:
17550 case DW_TAG_set_type
:
17551 case DW_TAG_string_type
:
17552 case DW_TAG_subroutine_type
:
17554 case DW_TAG_base_type
:
17555 case DW_TAG_class_type
:
17556 case DW_TAG_interface_type
:
17557 case DW_TAG_enumeration_type
:
17558 case DW_TAG_structure_type
:
17559 case DW_TAG_subrange_type
:
17560 case DW_TAG_typedef
:
17561 case DW_TAG_union_type
:
17568 /* Load all DIEs that are interesting for partial symbols into memory. */
17570 static struct partial_die_info
*
17571 load_partial_dies (const struct die_reader_specs
*reader
,
17572 const gdb_byte
*info_ptr
, int building_psymtab
)
17574 struct dwarf2_cu
*cu
= reader
->cu
;
17575 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17576 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17577 unsigned int bytes_read
;
17578 unsigned int load_all
= 0;
17579 int nesting_level
= 1;
17584 gdb_assert (cu
->per_cu
!= NULL
);
17585 if (cu
->per_cu
->load_all_dies
)
17589 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17593 &cu
->comp_unit_obstack
,
17594 hashtab_obstack_allocate
,
17595 dummy_obstack_deallocate
);
17599 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17601 /* A NULL abbrev means the end of a series of children. */
17602 if (abbrev
== NULL
)
17604 if (--nesting_level
== 0)
17607 info_ptr
+= bytes_read
;
17608 last_die
= parent_die
;
17609 parent_die
= parent_die
->die_parent
;
17613 /* Check for template arguments. We never save these; if
17614 they're seen, we just mark the parent, and go on our way. */
17615 if (parent_die
!= NULL
17616 && cu
->language
== language_cplus
17617 && (abbrev
->tag
== DW_TAG_template_type_param
17618 || abbrev
->tag
== DW_TAG_template_value_param
))
17620 parent_die
->has_template_arguments
= 1;
17624 /* We don't need a partial DIE for the template argument. */
17625 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17630 /* We only recurse into c++ subprograms looking for template arguments.
17631 Skip their other children. */
17633 && cu
->language
== language_cplus
17634 && parent_die
!= NULL
17635 && parent_die
->tag
== DW_TAG_subprogram
)
17637 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17641 /* Check whether this DIE is interesting enough to save. Normally
17642 we would not be interested in members here, but there may be
17643 later variables referencing them via DW_AT_specification (for
17644 static members). */
17646 && !is_type_tag_for_partial (abbrev
->tag
)
17647 && abbrev
->tag
!= DW_TAG_constant
17648 && abbrev
->tag
!= DW_TAG_enumerator
17649 && abbrev
->tag
!= DW_TAG_subprogram
17650 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17651 && abbrev
->tag
!= DW_TAG_lexical_block
17652 && abbrev
->tag
!= DW_TAG_variable
17653 && abbrev
->tag
!= DW_TAG_namespace
17654 && abbrev
->tag
!= DW_TAG_module
17655 && abbrev
->tag
!= DW_TAG_member
17656 && abbrev
->tag
!= DW_TAG_imported_unit
17657 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17659 /* Otherwise we skip to the next sibling, if any. */
17660 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17664 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17667 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17669 /* This two-pass algorithm for processing partial symbols has a
17670 high cost in cache pressure. Thus, handle some simple cases
17671 here which cover the majority of C partial symbols. DIEs
17672 which neither have specification tags in them, nor could have
17673 specification tags elsewhere pointing at them, can simply be
17674 processed and discarded.
17676 This segment is also optional; scan_partial_symbols and
17677 add_partial_symbol will handle these DIEs if we chain
17678 them in normally. When compilers which do not emit large
17679 quantities of duplicate debug information are more common,
17680 this code can probably be removed. */
17682 /* Any complete simple types at the top level (pretty much all
17683 of them, for a language without namespaces), can be processed
17685 if (parent_die
== NULL
17686 && pdi
.has_specification
== 0
17687 && pdi
.is_declaration
== 0
17688 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17689 || pdi
.tag
== DW_TAG_base_type
17690 || pdi
.tag
== DW_TAG_subrange_type
))
17692 if (building_psymtab
&& pdi
.name
!= NULL
)
17693 add_psymbol_to_list (pdi
.name
, false,
17694 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17695 psymbol_placement::STATIC
,
17696 0, cu
->language
, objfile
);
17697 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17701 /* The exception for DW_TAG_typedef with has_children above is
17702 a workaround of GCC PR debug/47510. In the case of this complaint
17703 type_name_or_error will error on such types later.
17705 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17706 it could not find the child DIEs referenced later, this is checked
17707 above. In correct DWARF DW_TAG_typedef should have no children. */
17709 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17710 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17711 "- DIE at %s [in module %s]"),
17712 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17714 /* If we're at the second level, and we're an enumerator, and
17715 our parent has no specification (meaning possibly lives in a
17716 namespace elsewhere), then we can add the partial symbol now
17717 instead of queueing it. */
17718 if (pdi
.tag
== DW_TAG_enumerator
17719 && parent_die
!= NULL
17720 && parent_die
->die_parent
== NULL
17721 && parent_die
->tag
== DW_TAG_enumeration_type
17722 && parent_die
->has_specification
== 0)
17724 if (pdi
.name
== NULL
)
17725 complaint (_("malformed enumerator DIE ignored"));
17726 else if (building_psymtab
)
17727 add_psymbol_to_list (pdi
.name
, false,
17728 VAR_DOMAIN
, LOC_CONST
, -1,
17729 cu
->language
== language_cplus
17730 ? psymbol_placement::GLOBAL
17731 : psymbol_placement::STATIC
,
17732 0, cu
->language
, objfile
);
17734 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17738 struct partial_die_info
*part_die
17739 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17741 /* We'll save this DIE so link it in. */
17742 part_die
->die_parent
= parent_die
;
17743 part_die
->die_sibling
= NULL
;
17744 part_die
->die_child
= NULL
;
17746 if (last_die
&& last_die
== parent_die
)
17747 last_die
->die_child
= part_die
;
17749 last_die
->die_sibling
= part_die
;
17751 last_die
= part_die
;
17753 if (first_die
== NULL
)
17754 first_die
= part_die
;
17756 /* Maybe add the DIE to the hash table. Not all DIEs that we
17757 find interesting need to be in the hash table, because we
17758 also have the parent/sibling/child chains; only those that we
17759 might refer to by offset later during partial symbol reading.
17761 For now this means things that might have be the target of a
17762 DW_AT_specification, DW_AT_abstract_origin, or
17763 DW_AT_extension. DW_AT_extension will refer only to
17764 namespaces; DW_AT_abstract_origin refers to functions (and
17765 many things under the function DIE, but we do not recurse
17766 into function DIEs during partial symbol reading) and
17767 possibly variables as well; DW_AT_specification refers to
17768 declarations. Declarations ought to have the DW_AT_declaration
17769 flag. It happens that GCC forgets to put it in sometimes, but
17770 only for functions, not for types.
17772 Adding more things than necessary to the hash table is harmless
17773 except for the performance cost. Adding too few will result in
17774 wasted time in find_partial_die, when we reread the compilation
17775 unit with load_all_dies set. */
17778 || abbrev
->tag
== DW_TAG_constant
17779 || abbrev
->tag
== DW_TAG_subprogram
17780 || abbrev
->tag
== DW_TAG_variable
17781 || abbrev
->tag
== DW_TAG_namespace
17782 || part_die
->is_declaration
)
17786 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17787 to_underlying (part_die
->sect_off
),
17792 /* For some DIEs we want to follow their children (if any). For C
17793 we have no reason to follow the children of structures; for other
17794 languages we have to, so that we can get at method physnames
17795 to infer fully qualified class names, for DW_AT_specification,
17796 and for C++ template arguments. For C++, we also look one level
17797 inside functions to find template arguments (if the name of the
17798 function does not already contain the template arguments).
17800 For Ada and Fortran, we need to scan the children of subprograms
17801 and lexical blocks as well because these languages allow the
17802 definition of nested entities that could be interesting for the
17803 debugger, such as nested subprograms for instance. */
17804 if (last_die
->has_children
17806 || last_die
->tag
== DW_TAG_namespace
17807 || last_die
->tag
== DW_TAG_module
17808 || last_die
->tag
== DW_TAG_enumeration_type
17809 || (cu
->language
== language_cplus
17810 && last_die
->tag
== DW_TAG_subprogram
17811 && (last_die
->name
== NULL
17812 || strchr (last_die
->name
, '<') == NULL
))
17813 || (cu
->language
!= language_c
17814 && (last_die
->tag
== DW_TAG_class_type
17815 || last_die
->tag
== DW_TAG_interface_type
17816 || last_die
->tag
== DW_TAG_structure_type
17817 || last_die
->tag
== DW_TAG_union_type
))
17818 || ((cu
->language
== language_ada
17819 || cu
->language
== language_fortran
)
17820 && (last_die
->tag
== DW_TAG_subprogram
17821 || last_die
->tag
== DW_TAG_lexical_block
))))
17824 parent_die
= last_die
;
17828 /* Otherwise we skip to the next sibling, if any. */
17829 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17831 /* Back to the top, do it again. */
17835 partial_die_info::partial_die_info (sect_offset sect_off_
,
17836 struct abbrev_info
*abbrev
)
17837 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17841 /* Read a minimal amount of information into the minimal die structure.
17842 INFO_PTR should point just after the initial uleb128 of a DIE. */
17845 partial_die_info::read (const struct die_reader_specs
*reader
,
17846 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17848 struct dwarf2_cu
*cu
= reader
->cu
;
17849 struct dwarf2_per_objfile
*dwarf2_per_objfile
17850 = cu
->per_cu
->dwarf2_per_objfile
;
17852 int has_low_pc_attr
= 0;
17853 int has_high_pc_attr
= 0;
17854 int high_pc_relative
= 0;
17856 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17857 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17859 bool need_reprocess
;
17860 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17861 info_ptr
, &need_reprocess
);
17862 /* String and address offsets that need to do the reprocessing have
17863 already been read at this point, so there is no need to wait until
17864 the loop terminates to do the reprocessing. */
17865 if (need_reprocess
)
17866 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17867 attribute
&attr
= attr_vec
[i
];
17868 /* Store the data if it is of an attribute we want to keep in a
17869 partial symbol table. */
17875 case DW_TAG_compile_unit
:
17876 case DW_TAG_partial_unit
:
17877 case DW_TAG_type_unit
:
17878 /* Compilation units have a DW_AT_name that is a filename, not
17879 a source language identifier. */
17880 case DW_TAG_enumeration_type
:
17881 case DW_TAG_enumerator
:
17882 /* These tags always have simple identifiers already; no need
17883 to canonicalize them. */
17884 name
= DW_STRING (&attr
);
17888 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17891 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17896 case DW_AT_linkage_name
:
17897 case DW_AT_MIPS_linkage_name
:
17898 /* Note that both forms of linkage name might appear. We
17899 assume they will be the same, and we only store the last
17901 linkage_name
= DW_STRING (&attr
);
17904 has_low_pc_attr
= 1;
17905 lowpc
= attr
.value_as_address ();
17907 case DW_AT_high_pc
:
17908 has_high_pc_attr
= 1;
17909 highpc
= attr
.value_as_address ();
17910 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17911 high_pc_relative
= 1;
17913 case DW_AT_location
:
17914 /* Support the .debug_loc offsets. */
17915 if (attr
.form_is_block ())
17917 d
.locdesc
= DW_BLOCK (&attr
);
17919 else if (attr
.form_is_section_offset ())
17921 dwarf2_complex_location_expr_complaint ();
17925 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17926 "partial symbol information");
17929 case DW_AT_external
:
17930 is_external
= DW_UNSND (&attr
);
17932 case DW_AT_declaration
:
17933 is_declaration
= DW_UNSND (&attr
);
17938 case DW_AT_abstract_origin
:
17939 case DW_AT_specification
:
17940 case DW_AT_extension
:
17941 has_specification
= 1;
17942 spec_offset
= attr
.get_ref_die_offset ();
17943 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17944 || cu
->per_cu
->is_dwz
);
17946 case DW_AT_sibling
:
17947 /* Ignore absolute siblings, they might point outside of
17948 the current compile unit. */
17949 if (attr
.form
== DW_FORM_ref_addr
)
17950 complaint (_("ignoring absolute DW_AT_sibling"));
17953 const gdb_byte
*buffer
= reader
->buffer
;
17954 sect_offset off
= attr
.get_ref_die_offset ();
17955 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17957 if (sibling_ptr
< info_ptr
)
17958 complaint (_("DW_AT_sibling points backwards"));
17959 else if (sibling_ptr
> reader
->buffer_end
)
17960 reader
->die_section
->overflow_complaint ();
17962 sibling
= sibling_ptr
;
17965 case DW_AT_byte_size
:
17968 case DW_AT_const_value
:
17969 has_const_value
= 1;
17971 case DW_AT_calling_convention
:
17972 /* DWARF doesn't provide a way to identify a program's source-level
17973 entry point. DW_AT_calling_convention attributes are only meant
17974 to describe functions' calling conventions.
17976 However, because it's a necessary piece of information in
17977 Fortran, and before DWARF 4 DW_CC_program was the only
17978 piece of debugging information whose definition refers to
17979 a 'main program' at all, several compilers marked Fortran
17980 main programs with DW_CC_program --- even when those
17981 functions use the standard calling conventions.
17983 Although DWARF now specifies a way to provide this
17984 information, we support this practice for backward
17986 if (DW_UNSND (&attr
) == DW_CC_program
17987 && cu
->language
== language_fortran
)
17988 main_subprogram
= 1;
17991 if (DW_UNSND (&attr
) == DW_INL_inlined
17992 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
17993 may_be_inlined
= 1;
17997 if (tag
== DW_TAG_imported_unit
)
17999 d
.sect_off
= attr
.get_ref_die_offset ();
18000 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18001 || cu
->per_cu
->is_dwz
);
18005 case DW_AT_main_subprogram
:
18006 main_subprogram
= DW_UNSND (&attr
);
18011 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18012 but that requires a full DIE, so instead we just
18014 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18015 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18016 + (need_ranges_base
18020 /* Value of the DW_AT_ranges attribute is the offset in the
18021 .debug_ranges section. */
18022 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18033 /* For Ada, if both the name and the linkage name appear, we prefer
18034 the latter. This lets "catch exception" work better, regardless
18035 of the order in which the name and linkage name were emitted.
18036 Really, though, this is just a workaround for the fact that gdb
18037 doesn't store both the name and the linkage name. */
18038 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18039 name
= linkage_name
;
18041 if (high_pc_relative
)
18044 if (has_low_pc_attr
&& has_high_pc_attr
)
18046 /* When using the GNU linker, .gnu.linkonce. sections are used to
18047 eliminate duplicate copies of functions and vtables and such.
18048 The linker will arbitrarily choose one and discard the others.
18049 The AT_*_pc values for such functions refer to local labels in
18050 these sections. If the section from that file was discarded, the
18051 labels are not in the output, so the relocs get a value of 0.
18052 If this is a discarded function, mark the pc bounds as invalid,
18053 so that GDB will ignore it. */
18054 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18056 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18057 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18059 complaint (_("DW_AT_low_pc %s is zero "
18060 "for DIE at %s [in module %s]"),
18061 paddress (gdbarch
, lowpc
),
18062 sect_offset_str (sect_off
),
18063 objfile_name (objfile
));
18065 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18066 else if (lowpc
>= highpc
)
18068 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18069 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18071 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18072 "for DIE at %s [in module %s]"),
18073 paddress (gdbarch
, lowpc
),
18074 paddress (gdbarch
, highpc
),
18075 sect_offset_str (sect_off
),
18076 objfile_name (objfile
));
18085 /* Find a cached partial DIE at OFFSET in CU. */
18087 struct partial_die_info
*
18088 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18090 struct partial_die_info
*lookup_die
= NULL
;
18091 struct partial_die_info
part_die (sect_off
);
18093 lookup_die
= ((struct partial_die_info
*)
18094 htab_find_with_hash (partial_dies
, &part_die
,
18095 to_underlying (sect_off
)));
18100 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18101 except in the case of .debug_types DIEs which do not reference
18102 outside their CU (they do however referencing other types via
18103 DW_FORM_ref_sig8). */
18105 static const struct cu_partial_die_info
18106 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18108 struct dwarf2_per_objfile
*dwarf2_per_objfile
18109 = cu
->per_cu
->dwarf2_per_objfile
;
18110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18111 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18112 struct partial_die_info
*pd
= NULL
;
18114 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18115 && cu
->header
.offset_in_cu_p (sect_off
))
18117 pd
= cu
->find_partial_die (sect_off
);
18120 /* We missed recording what we needed.
18121 Load all dies and try again. */
18122 per_cu
= cu
->per_cu
;
18126 /* TUs don't reference other CUs/TUs (except via type signatures). */
18127 if (cu
->per_cu
->is_debug_types
)
18129 error (_("Dwarf Error: Type Unit at offset %s contains"
18130 " external reference to offset %s [in module %s].\n"),
18131 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18132 bfd_get_filename (objfile
->obfd
));
18134 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18135 dwarf2_per_objfile
);
18137 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18138 load_partial_comp_unit (per_cu
);
18140 per_cu
->cu
->last_used
= 0;
18141 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18144 /* If we didn't find it, and not all dies have been loaded,
18145 load them all and try again. */
18147 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18149 per_cu
->load_all_dies
= 1;
18151 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18152 THIS_CU->cu may already be in use. So we can't just free it and
18153 replace its DIEs with the ones we read in. Instead, we leave those
18154 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18155 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18157 load_partial_comp_unit (per_cu
);
18159 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18163 internal_error (__FILE__
, __LINE__
,
18164 _("could not find partial DIE %s "
18165 "in cache [from module %s]\n"),
18166 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18167 return { per_cu
->cu
, pd
};
18170 /* See if we can figure out if the class lives in a namespace. We do
18171 this by looking for a member function; its demangled name will
18172 contain namespace info, if there is any. */
18175 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18176 struct dwarf2_cu
*cu
)
18178 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18179 what template types look like, because the demangler
18180 frequently doesn't give the same name as the debug info. We
18181 could fix this by only using the demangled name to get the
18182 prefix (but see comment in read_structure_type). */
18184 struct partial_die_info
*real_pdi
;
18185 struct partial_die_info
*child_pdi
;
18187 /* If this DIE (this DIE's specification, if any) has a parent, then
18188 we should not do this. We'll prepend the parent's fully qualified
18189 name when we create the partial symbol. */
18191 real_pdi
= struct_pdi
;
18192 while (real_pdi
->has_specification
)
18194 auto res
= find_partial_die (real_pdi
->spec_offset
,
18195 real_pdi
->spec_is_dwz
, cu
);
18196 real_pdi
= res
.pdi
;
18200 if (real_pdi
->die_parent
!= NULL
)
18203 for (child_pdi
= struct_pdi
->die_child
;
18205 child_pdi
= child_pdi
->die_sibling
)
18207 if (child_pdi
->tag
== DW_TAG_subprogram
18208 && child_pdi
->linkage_name
!= NULL
)
18210 gdb::unique_xmalloc_ptr
<char> actual_class_name
18211 (language_class_name_from_physname (cu
->language_defn
,
18212 child_pdi
->linkage_name
));
18213 if (actual_class_name
!= NULL
)
18215 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18216 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18224 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18226 /* Once we've fixed up a die, there's no point in doing so again.
18227 This also avoids a memory leak if we were to call
18228 guess_partial_die_structure_name multiple times. */
18232 /* If we found a reference attribute and the DIE has no name, try
18233 to find a name in the referred to DIE. */
18235 if (name
== NULL
&& has_specification
)
18237 struct partial_die_info
*spec_die
;
18239 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18240 spec_die
= res
.pdi
;
18243 spec_die
->fixup (cu
);
18245 if (spec_die
->name
)
18247 name
= spec_die
->name
;
18249 /* Copy DW_AT_external attribute if it is set. */
18250 if (spec_die
->is_external
)
18251 is_external
= spec_die
->is_external
;
18255 /* Set default names for some unnamed DIEs. */
18257 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18258 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18260 /* If there is no parent die to provide a namespace, and there are
18261 children, see if we can determine the namespace from their linkage
18263 if (cu
->language
== language_cplus
18264 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18265 && die_parent
== NULL
18267 && (tag
== DW_TAG_class_type
18268 || tag
== DW_TAG_structure_type
18269 || tag
== DW_TAG_union_type
))
18270 guess_partial_die_structure_name (this, cu
);
18272 /* GCC might emit a nameless struct or union that has a linkage
18273 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18275 && (tag
== DW_TAG_class_type
18276 || tag
== DW_TAG_interface_type
18277 || tag
== DW_TAG_structure_type
18278 || tag
== DW_TAG_union_type
)
18279 && linkage_name
!= NULL
)
18281 gdb::unique_xmalloc_ptr
<char> demangled
18282 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18283 if (demangled
!= nullptr)
18287 /* Strip any leading namespaces/classes, keep only the base name.
18288 DW_AT_name for named DIEs does not contain the prefixes. */
18289 base
= strrchr (demangled
.get (), ':');
18290 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18293 base
= demangled
.get ();
18295 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18296 name
= objfile
->intern (base
);
18303 /* Process the attributes that had to be skipped in the first round. These
18304 attributes are the ones that need str_offsets_base or addr_base attributes.
18305 They could not have been processed in the first round, because at the time
18306 the values of str_offsets_base or addr_base may not have been known. */
18308 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18309 struct attribute
*attr
)
18311 struct dwarf2_cu
*cu
= reader
->cu
;
18312 switch (attr
->form
)
18314 case DW_FORM_addrx
:
18315 case DW_FORM_GNU_addr_index
:
18316 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18319 case DW_FORM_strx1
:
18320 case DW_FORM_strx2
:
18321 case DW_FORM_strx3
:
18322 case DW_FORM_strx4
:
18323 case DW_FORM_GNU_str_index
:
18325 unsigned int str_index
= DW_UNSND (attr
);
18326 if (reader
->dwo_file
!= NULL
)
18328 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18329 DW_STRING_IS_CANONICAL (attr
) = 0;
18333 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18334 DW_STRING_IS_CANONICAL (attr
) = 0;
18339 gdb_assert_not_reached (_("Unexpected DWARF form."));
18343 /* Read an attribute value described by an attribute form. */
18345 static const gdb_byte
*
18346 read_attribute_value (const struct die_reader_specs
*reader
,
18347 struct attribute
*attr
, unsigned form
,
18348 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18349 bool *need_reprocess
)
18351 struct dwarf2_cu
*cu
= reader
->cu
;
18352 struct dwarf2_per_objfile
*dwarf2_per_objfile
18353 = cu
->per_cu
->dwarf2_per_objfile
;
18354 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18355 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18356 bfd
*abfd
= reader
->abfd
;
18357 struct comp_unit_head
*cu_header
= &cu
->header
;
18358 unsigned int bytes_read
;
18359 struct dwarf_block
*blk
;
18360 *need_reprocess
= false;
18362 attr
->form
= (enum dwarf_form
) form
;
18365 case DW_FORM_ref_addr
:
18366 if (cu
->header
.version
== 2)
18367 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18370 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18372 info_ptr
+= bytes_read
;
18374 case DW_FORM_GNU_ref_alt
:
18375 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18376 info_ptr
+= bytes_read
;
18379 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18380 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18381 info_ptr
+= bytes_read
;
18383 case DW_FORM_block2
:
18384 blk
= dwarf_alloc_block (cu
);
18385 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18387 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18388 info_ptr
+= blk
->size
;
18389 DW_BLOCK (attr
) = blk
;
18391 case DW_FORM_block4
:
18392 blk
= dwarf_alloc_block (cu
);
18393 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18395 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18396 info_ptr
+= blk
->size
;
18397 DW_BLOCK (attr
) = blk
;
18399 case DW_FORM_data2
:
18400 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18403 case DW_FORM_data4
:
18404 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18407 case DW_FORM_data8
:
18408 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18411 case DW_FORM_data16
:
18412 blk
= dwarf_alloc_block (cu
);
18414 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18416 DW_BLOCK (attr
) = blk
;
18418 case DW_FORM_sec_offset
:
18419 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18420 info_ptr
+= bytes_read
;
18422 case DW_FORM_string
:
18423 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18424 DW_STRING_IS_CANONICAL (attr
) = 0;
18425 info_ptr
+= bytes_read
;
18428 if (!cu
->per_cu
->is_dwz
)
18430 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18431 abfd
, info_ptr
, cu_header
,
18433 DW_STRING_IS_CANONICAL (attr
) = 0;
18434 info_ptr
+= bytes_read
;
18438 case DW_FORM_line_strp
:
18439 if (!cu
->per_cu
->is_dwz
)
18442 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18444 DW_STRING_IS_CANONICAL (attr
) = 0;
18445 info_ptr
+= bytes_read
;
18449 case DW_FORM_GNU_strp_alt
:
18451 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18452 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18455 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18456 DW_STRING_IS_CANONICAL (attr
) = 0;
18457 info_ptr
+= bytes_read
;
18460 case DW_FORM_exprloc
:
18461 case DW_FORM_block
:
18462 blk
= dwarf_alloc_block (cu
);
18463 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18464 info_ptr
+= bytes_read
;
18465 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18466 info_ptr
+= blk
->size
;
18467 DW_BLOCK (attr
) = blk
;
18469 case DW_FORM_block1
:
18470 blk
= dwarf_alloc_block (cu
);
18471 blk
->size
= read_1_byte (abfd
, info_ptr
);
18473 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18474 info_ptr
+= blk
->size
;
18475 DW_BLOCK (attr
) = blk
;
18477 case DW_FORM_data1
:
18478 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18482 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18485 case DW_FORM_flag_present
:
18486 DW_UNSND (attr
) = 1;
18488 case DW_FORM_sdata
:
18489 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18490 info_ptr
+= bytes_read
;
18492 case DW_FORM_udata
:
18493 case DW_FORM_rnglistx
:
18494 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18495 info_ptr
+= bytes_read
;
18498 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18499 + read_1_byte (abfd
, info_ptr
));
18503 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18504 + read_2_bytes (abfd
, info_ptr
));
18508 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18509 + read_4_bytes (abfd
, info_ptr
));
18513 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18514 + read_8_bytes (abfd
, info_ptr
));
18517 case DW_FORM_ref_sig8
:
18518 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18521 case DW_FORM_ref_udata
:
18522 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18523 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18524 info_ptr
+= bytes_read
;
18526 case DW_FORM_indirect
:
18527 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18528 info_ptr
+= bytes_read
;
18529 if (form
== DW_FORM_implicit_const
)
18531 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18532 info_ptr
+= bytes_read
;
18534 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18535 info_ptr
, need_reprocess
);
18537 case DW_FORM_implicit_const
:
18538 DW_SND (attr
) = implicit_const
;
18540 case DW_FORM_addrx
:
18541 case DW_FORM_GNU_addr_index
:
18542 *need_reprocess
= true;
18543 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18544 info_ptr
+= bytes_read
;
18547 case DW_FORM_strx1
:
18548 case DW_FORM_strx2
:
18549 case DW_FORM_strx3
:
18550 case DW_FORM_strx4
:
18551 case DW_FORM_GNU_str_index
:
18553 ULONGEST str_index
;
18554 if (form
== DW_FORM_strx1
)
18556 str_index
= read_1_byte (abfd
, info_ptr
);
18559 else if (form
== DW_FORM_strx2
)
18561 str_index
= read_2_bytes (abfd
, info_ptr
);
18564 else if (form
== DW_FORM_strx3
)
18566 str_index
= read_3_bytes (abfd
, info_ptr
);
18569 else if (form
== DW_FORM_strx4
)
18571 str_index
= read_4_bytes (abfd
, info_ptr
);
18576 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18577 info_ptr
+= bytes_read
;
18579 *need_reprocess
= true;
18580 DW_UNSND (attr
) = str_index
;
18584 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18585 dwarf_form_name (form
),
18586 bfd_get_filename (abfd
));
18590 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18591 attr
->form
= DW_FORM_GNU_ref_alt
;
18593 /* We have seen instances where the compiler tried to emit a byte
18594 size attribute of -1 which ended up being encoded as an unsigned
18595 0xffffffff. Although 0xffffffff is technically a valid size value,
18596 an object of this size seems pretty unlikely so we can relatively
18597 safely treat these cases as if the size attribute was invalid and
18598 treat them as zero by default. */
18599 if (attr
->name
== DW_AT_byte_size
18600 && form
== DW_FORM_data4
18601 && DW_UNSND (attr
) >= 0xffffffff)
18604 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18605 hex_string (DW_UNSND (attr
)));
18606 DW_UNSND (attr
) = 0;
18612 /* Read an attribute described by an abbreviated attribute. */
18614 static const gdb_byte
*
18615 read_attribute (const struct die_reader_specs
*reader
,
18616 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18617 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18619 attr
->name
= abbrev
->name
;
18620 return read_attribute_value (reader
, attr
, abbrev
->form
,
18621 abbrev
->implicit_const
, info_ptr
,
18625 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18627 static const char *
18628 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18629 LONGEST str_offset
)
18631 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18632 str_offset
, "DW_FORM_strp");
18635 /* Return pointer to string at .debug_str offset as read from BUF.
18636 BUF is assumed to be in a compilation unit described by CU_HEADER.
18637 Return *BYTES_READ_PTR count of bytes read from BUF. */
18639 static const char *
18640 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18641 const gdb_byte
*buf
,
18642 const struct comp_unit_head
*cu_header
,
18643 unsigned int *bytes_read_ptr
)
18645 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18647 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18653 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18654 const struct comp_unit_head
*cu_header
,
18655 unsigned int *bytes_read_ptr
)
18657 bfd
*abfd
= objfile
->obfd
;
18658 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18660 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18663 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18664 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18665 ADDR_SIZE is the size of addresses from the CU header. */
18668 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18669 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18672 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18673 bfd
*abfd
= objfile
->obfd
;
18674 const gdb_byte
*info_ptr
;
18675 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18677 dwarf2_per_objfile
->addr
.read (objfile
);
18678 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18679 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18680 objfile_name (objfile
));
18681 if (addr_base_or_zero
+ addr_index
* addr_size
18682 >= dwarf2_per_objfile
->addr
.size
)
18683 error (_("DW_FORM_addr_index pointing outside of "
18684 ".debug_addr section [in module %s]"),
18685 objfile_name (objfile
));
18686 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18687 + addr_base_or_zero
+ addr_index
* addr_size
);
18688 if (addr_size
== 4)
18689 return bfd_get_32 (abfd
, info_ptr
);
18691 return bfd_get_64 (abfd
, info_ptr
);
18694 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18697 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18699 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18700 cu
->addr_base
, cu
->header
.addr_size
);
18703 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18706 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18707 unsigned int *bytes_read
)
18709 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18710 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18712 return read_addr_index (cu
, addr_index
);
18718 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18720 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18721 struct dwarf2_cu
*cu
= per_cu
->cu
;
18722 gdb::optional
<ULONGEST
> addr_base
;
18725 /* We need addr_base and addr_size.
18726 If we don't have PER_CU->cu, we have to get it.
18727 Nasty, but the alternative is storing the needed info in PER_CU,
18728 which at this point doesn't seem justified: it's not clear how frequently
18729 it would get used and it would increase the size of every PER_CU.
18730 Entry points like dwarf2_per_cu_addr_size do a similar thing
18731 so we're not in uncharted territory here.
18732 Alas we need to be a bit more complicated as addr_base is contained
18735 We don't need to read the entire CU(/TU).
18736 We just need the header and top level die.
18738 IWBN to use the aging mechanism to let us lazily later discard the CU.
18739 For now we skip this optimization. */
18743 addr_base
= cu
->addr_base
;
18744 addr_size
= cu
->header
.addr_size
;
18748 cutu_reader
reader (per_cu
, NULL
, 0, false);
18749 addr_base
= reader
.cu
->addr_base
;
18750 addr_size
= reader
.cu
->header
.addr_size
;
18753 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18757 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18758 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18761 static const char *
18762 read_str_index (struct dwarf2_cu
*cu
,
18763 struct dwarf2_section_info
*str_section
,
18764 struct dwarf2_section_info
*str_offsets_section
,
18765 ULONGEST str_offsets_base
, ULONGEST str_index
)
18767 struct dwarf2_per_objfile
*dwarf2_per_objfile
18768 = cu
->per_cu
->dwarf2_per_objfile
;
18769 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18770 const char *objf_name
= objfile_name (objfile
);
18771 bfd
*abfd
= objfile
->obfd
;
18772 const gdb_byte
*info_ptr
;
18773 ULONGEST str_offset
;
18774 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18776 str_section
->read (objfile
);
18777 str_offsets_section
->read (objfile
);
18778 if (str_section
->buffer
== NULL
)
18779 error (_("%s used without %s section"
18780 " in CU at offset %s [in module %s]"),
18781 form_name
, str_section
->get_name (),
18782 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18783 if (str_offsets_section
->buffer
== NULL
)
18784 error (_("%s used without %s section"
18785 " in CU at offset %s [in module %s]"),
18786 form_name
, str_section
->get_name (),
18787 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18788 info_ptr
= (str_offsets_section
->buffer
18790 + str_index
* cu
->header
.offset_size
);
18791 if (cu
->header
.offset_size
== 4)
18792 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18794 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18795 if (str_offset
>= str_section
->size
)
18796 error (_("Offset from %s pointing outside of"
18797 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18798 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18799 return (const char *) (str_section
->buffer
+ str_offset
);
18802 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18804 static const char *
18805 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18807 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18808 ? reader
->cu
->header
.addr_size
: 0;
18809 return read_str_index (reader
->cu
,
18810 &reader
->dwo_file
->sections
.str
,
18811 &reader
->dwo_file
->sections
.str_offsets
,
18812 str_offsets_base
, str_index
);
18815 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18817 static const char *
18818 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18820 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18821 const char *objf_name
= objfile_name (objfile
);
18822 static const char form_name
[] = "DW_FORM_GNU_str_index";
18823 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18825 if (!cu
->str_offsets_base
.has_value ())
18826 error (_("%s used in Fission stub without %s"
18827 " in CU at offset 0x%lx [in module %s]"),
18828 form_name
, str_offsets_attr_name
,
18829 (long) cu
->header
.offset_size
, objf_name
);
18831 return read_str_index (cu
,
18832 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18833 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18834 *cu
->str_offsets_base
, str_index
);
18837 /* Return the length of an LEB128 number in BUF. */
18840 leb128_size (const gdb_byte
*buf
)
18842 const gdb_byte
*begin
= buf
;
18848 if ((byte
& 128) == 0)
18849 return buf
- begin
;
18854 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18863 cu
->language
= language_c
;
18866 case DW_LANG_C_plus_plus
:
18867 case DW_LANG_C_plus_plus_11
:
18868 case DW_LANG_C_plus_plus_14
:
18869 cu
->language
= language_cplus
;
18872 cu
->language
= language_d
;
18874 case DW_LANG_Fortran77
:
18875 case DW_LANG_Fortran90
:
18876 case DW_LANG_Fortran95
:
18877 case DW_LANG_Fortran03
:
18878 case DW_LANG_Fortran08
:
18879 cu
->language
= language_fortran
;
18882 cu
->language
= language_go
;
18884 case DW_LANG_Mips_Assembler
:
18885 cu
->language
= language_asm
;
18887 case DW_LANG_Ada83
:
18888 case DW_LANG_Ada95
:
18889 cu
->language
= language_ada
;
18891 case DW_LANG_Modula2
:
18892 cu
->language
= language_m2
;
18894 case DW_LANG_Pascal83
:
18895 cu
->language
= language_pascal
;
18898 cu
->language
= language_objc
;
18901 case DW_LANG_Rust_old
:
18902 cu
->language
= language_rust
;
18904 case DW_LANG_Cobol74
:
18905 case DW_LANG_Cobol85
:
18907 cu
->language
= language_minimal
;
18910 cu
->language_defn
= language_def (cu
->language
);
18913 /* Return the named attribute or NULL if not there. */
18915 static struct attribute
*
18916 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18921 struct attribute
*spec
= NULL
;
18923 for (i
= 0; i
< die
->num_attrs
; ++i
)
18925 if (die
->attrs
[i
].name
== name
)
18926 return &die
->attrs
[i
];
18927 if (die
->attrs
[i
].name
== DW_AT_specification
18928 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18929 spec
= &die
->attrs
[i
];
18935 die
= follow_die_ref (die
, spec
, &cu
);
18941 /* Return the string associated with a string-typed attribute, or NULL if it
18942 is either not found or is of an incorrect type. */
18944 static const char *
18945 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18947 struct attribute
*attr
;
18948 const char *str
= NULL
;
18950 attr
= dwarf2_attr (die
, name
, cu
);
18954 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18955 || attr
->form
== DW_FORM_string
18956 || attr
->form
== DW_FORM_strx
18957 || attr
->form
== DW_FORM_strx1
18958 || attr
->form
== DW_FORM_strx2
18959 || attr
->form
== DW_FORM_strx3
18960 || attr
->form
== DW_FORM_strx4
18961 || attr
->form
== DW_FORM_GNU_str_index
18962 || attr
->form
== DW_FORM_GNU_strp_alt
)
18963 str
= DW_STRING (attr
);
18965 complaint (_("string type expected for attribute %s for "
18966 "DIE at %s in module %s"),
18967 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
18968 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18974 /* Return the dwo name or NULL if not present. If present, it is in either
18975 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
18976 static const char *
18977 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18979 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
18980 if (dwo_name
== nullptr)
18981 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
18985 /* Return non-zero iff the attribute NAME is defined for the given DIE,
18986 and holds a non-zero value. This function should only be used for
18987 DW_FORM_flag or DW_FORM_flag_present attributes. */
18990 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
18992 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
18994 return (attr
&& DW_UNSND (attr
));
18998 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19000 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19001 which value is non-zero. However, we have to be careful with
19002 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19003 (via dwarf2_flag_true_p) follows this attribute. So we may
19004 end up accidently finding a declaration attribute that belongs
19005 to a different DIE referenced by the specification attribute,
19006 even though the given DIE does not have a declaration attribute. */
19007 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19008 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19011 /* Return the die giving the specification for DIE, if there is
19012 one. *SPEC_CU is the CU containing DIE on input, and the CU
19013 containing the return value on output. If there is no
19014 specification, but there is an abstract origin, that is
19017 static struct die_info
*
19018 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19020 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19023 if (spec_attr
== NULL
)
19024 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19026 if (spec_attr
== NULL
)
19029 return follow_die_ref (die
, spec_attr
, spec_cu
);
19032 /* Stub for free_line_header to match void * callback types. */
19035 free_line_header_voidp (void *arg
)
19037 struct line_header
*lh
= (struct line_header
*) arg
;
19042 /* A convenience function to find the proper .debug_line section for a CU. */
19044 static struct dwarf2_section_info
*
19045 get_debug_line_section (struct dwarf2_cu
*cu
)
19047 struct dwarf2_section_info
*section
;
19048 struct dwarf2_per_objfile
*dwarf2_per_objfile
19049 = cu
->per_cu
->dwarf2_per_objfile
;
19051 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19053 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19054 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19055 else if (cu
->per_cu
->is_dwz
)
19057 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19059 section
= &dwz
->line
;
19062 section
= &dwarf2_per_objfile
->line
;
19067 /* Read the statement program header starting at OFFSET in
19068 .debug_line, or .debug_line.dwo. Return a pointer
19069 to a struct line_header, allocated using xmalloc.
19070 Returns NULL if there is a problem reading the header, e.g., if it
19071 has a version we don't understand.
19073 NOTE: the strings in the include directory and file name tables of
19074 the returned object point into the dwarf line section buffer,
19075 and must not be freed. */
19077 static line_header_up
19078 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19080 struct dwarf2_section_info
*section
;
19081 struct dwarf2_per_objfile
*dwarf2_per_objfile
19082 = cu
->per_cu
->dwarf2_per_objfile
;
19084 section
= get_debug_line_section (cu
);
19085 section
->read (dwarf2_per_objfile
->objfile
);
19086 if (section
->buffer
== NULL
)
19088 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19089 complaint (_("missing .debug_line.dwo section"));
19091 complaint (_("missing .debug_line section"));
19095 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19096 dwarf2_per_objfile
, section
,
19100 /* Subroutine of dwarf_decode_lines to simplify it.
19101 Return the file name of the psymtab for the given file_entry.
19102 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19103 If space for the result is malloc'd, *NAME_HOLDER will be set.
19104 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19106 static const char *
19107 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19108 const dwarf2_psymtab
*pst
,
19109 const char *comp_dir
,
19110 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19112 const char *include_name
= fe
.name
;
19113 const char *include_name_to_compare
= include_name
;
19114 const char *pst_filename
;
19117 const char *dir_name
= fe
.include_dir (lh
);
19119 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19120 if (!IS_ABSOLUTE_PATH (include_name
)
19121 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19123 /* Avoid creating a duplicate psymtab for PST.
19124 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19125 Before we do the comparison, however, we need to account
19126 for DIR_NAME and COMP_DIR.
19127 First prepend dir_name (if non-NULL). If we still don't
19128 have an absolute path prepend comp_dir (if non-NULL).
19129 However, the directory we record in the include-file's
19130 psymtab does not contain COMP_DIR (to match the
19131 corresponding symtab(s)).
19136 bash$ gcc -g ./hello.c
19137 include_name = "hello.c"
19139 DW_AT_comp_dir = comp_dir = "/tmp"
19140 DW_AT_name = "./hello.c"
19144 if (dir_name
!= NULL
)
19146 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19147 include_name
, (char *) NULL
));
19148 include_name
= name_holder
->get ();
19149 include_name_to_compare
= include_name
;
19151 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19153 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19154 include_name
, (char *) NULL
));
19155 include_name_to_compare
= hold_compare
.get ();
19159 pst_filename
= pst
->filename
;
19160 gdb::unique_xmalloc_ptr
<char> copied_name
;
19161 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19163 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19164 pst_filename
, (char *) NULL
));
19165 pst_filename
= copied_name
.get ();
19168 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19172 return include_name
;
19175 /* State machine to track the state of the line number program. */
19177 class lnp_state_machine
19180 /* Initialize a machine state for the start of a line number
19182 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19183 bool record_lines_p
);
19185 file_entry
*current_file ()
19187 /* lh->file_names is 0-based, but the file name numbers in the
19188 statement program are 1-based. */
19189 return m_line_header
->file_name_at (m_file
);
19192 /* Record the line in the state machine. END_SEQUENCE is true if
19193 we're processing the end of a sequence. */
19194 void record_line (bool end_sequence
);
19196 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19197 nop-out rest of the lines in this sequence. */
19198 void check_line_address (struct dwarf2_cu
*cu
,
19199 const gdb_byte
*line_ptr
,
19200 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19202 void handle_set_discriminator (unsigned int discriminator
)
19204 m_discriminator
= discriminator
;
19205 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19208 /* Handle DW_LNE_set_address. */
19209 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19212 address
+= baseaddr
;
19213 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19216 /* Handle DW_LNS_advance_pc. */
19217 void handle_advance_pc (CORE_ADDR adjust
);
19219 /* Handle a special opcode. */
19220 void handle_special_opcode (unsigned char op_code
);
19222 /* Handle DW_LNS_advance_line. */
19223 void handle_advance_line (int line_delta
)
19225 advance_line (line_delta
);
19228 /* Handle DW_LNS_set_file. */
19229 void handle_set_file (file_name_index file
);
19231 /* Handle DW_LNS_negate_stmt. */
19232 void handle_negate_stmt ()
19234 m_is_stmt
= !m_is_stmt
;
19237 /* Handle DW_LNS_const_add_pc. */
19238 void handle_const_add_pc ();
19240 /* Handle DW_LNS_fixed_advance_pc. */
19241 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19243 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19247 /* Handle DW_LNS_copy. */
19248 void handle_copy ()
19250 record_line (false);
19251 m_discriminator
= 0;
19254 /* Handle DW_LNE_end_sequence. */
19255 void handle_end_sequence ()
19257 m_currently_recording_lines
= true;
19261 /* Advance the line by LINE_DELTA. */
19262 void advance_line (int line_delta
)
19264 m_line
+= line_delta
;
19266 if (line_delta
!= 0)
19267 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19270 struct dwarf2_cu
*m_cu
;
19272 gdbarch
*m_gdbarch
;
19274 /* True if we're recording lines.
19275 Otherwise we're building partial symtabs and are just interested in
19276 finding include files mentioned by the line number program. */
19277 bool m_record_lines_p
;
19279 /* The line number header. */
19280 line_header
*m_line_header
;
19282 /* These are part of the standard DWARF line number state machine,
19283 and initialized according to the DWARF spec. */
19285 unsigned char m_op_index
= 0;
19286 /* The line table index of the current file. */
19287 file_name_index m_file
= 1;
19288 unsigned int m_line
= 1;
19290 /* These are initialized in the constructor. */
19292 CORE_ADDR m_address
;
19294 unsigned int m_discriminator
;
19296 /* Additional bits of state we need to track. */
19298 /* The last file that we called dwarf2_start_subfile for.
19299 This is only used for TLLs. */
19300 unsigned int m_last_file
= 0;
19301 /* The last file a line number was recorded for. */
19302 struct subfile
*m_last_subfile
= NULL
;
19304 /* When true, record the lines we decode. */
19305 bool m_currently_recording_lines
= false;
19307 /* The last line number that was recorded, used to coalesce
19308 consecutive entries for the same line. This can happen, for
19309 example, when discriminators are present. PR 17276. */
19310 unsigned int m_last_line
= 0;
19311 bool m_line_has_non_zero_discriminator
= false;
19315 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19317 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19318 / m_line_header
->maximum_ops_per_instruction
)
19319 * m_line_header
->minimum_instruction_length
);
19320 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19321 m_op_index
= ((m_op_index
+ adjust
)
19322 % m_line_header
->maximum_ops_per_instruction
);
19326 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19328 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19329 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19330 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19331 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19332 / m_line_header
->maximum_ops_per_instruction
)
19333 * m_line_header
->minimum_instruction_length
);
19334 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19335 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19336 % m_line_header
->maximum_ops_per_instruction
);
19338 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19339 advance_line (line_delta
);
19340 record_line (false);
19341 m_discriminator
= 0;
19345 lnp_state_machine::handle_set_file (file_name_index file
)
19349 const file_entry
*fe
= current_file ();
19351 dwarf2_debug_line_missing_file_complaint ();
19352 else if (m_record_lines_p
)
19354 const char *dir
= fe
->include_dir (m_line_header
);
19356 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19357 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19358 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19363 lnp_state_machine::handle_const_add_pc ()
19366 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19369 = (((m_op_index
+ adjust
)
19370 / m_line_header
->maximum_ops_per_instruction
)
19371 * m_line_header
->minimum_instruction_length
);
19373 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19374 m_op_index
= ((m_op_index
+ adjust
)
19375 % m_line_header
->maximum_ops_per_instruction
);
19378 /* Return non-zero if we should add LINE to the line number table.
19379 LINE is the line to add, LAST_LINE is the last line that was added,
19380 LAST_SUBFILE is the subfile for LAST_LINE.
19381 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19382 had a non-zero discriminator.
19384 We have to be careful in the presence of discriminators.
19385 E.g., for this line:
19387 for (i = 0; i < 100000; i++);
19389 clang can emit four line number entries for that one line,
19390 each with a different discriminator.
19391 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19393 However, we want gdb to coalesce all four entries into one.
19394 Otherwise the user could stepi into the middle of the line and
19395 gdb would get confused about whether the pc really was in the
19396 middle of the line.
19398 Things are further complicated by the fact that two consecutive
19399 line number entries for the same line is a heuristic used by gcc
19400 to denote the end of the prologue. So we can't just discard duplicate
19401 entries, we have to be selective about it. The heuristic we use is
19402 that we only collapse consecutive entries for the same line if at least
19403 one of those entries has a non-zero discriminator. PR 17276.
19405 Note: Addresses in the line number state machine can never go backwards
19406 within one sequence, thus this coalescing is ok. */
19409 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19410 unsigned int line
, unsigned int last_line
,
19411 int line_has_non_zero_discriminator
,
19412 struct subfile
*last_subfile
)
19414 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19416 if (line
!= last_line
)
19418 /* Same line for the same file that we've seen already.
19419 As a last check, for pr 17276, only record the line if the line
19420 has never had a non-zero discriminator. */
19421 if (!line_has_non_zero_discriminator
)
19426 /* Use the CU's builder to record line number LINE beginning at
19427 address ADDRESS in the line table of subfile SUBFILE. */
19430 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19431 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19432 struct dwarf2_cu
*cu
)
19434 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19436 if (dwarf_line_debug
)
19438 fprintf_unfiltered (gdb_stdlog
,
19439 "Recording line %u, file %s, address %s\n",
19440 line
, lbasename (subfile
->name
),
19441 paddress (gdbarch
, address
));
19445 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19448 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19449 Mark the end of a set of line number records.
19450 The arguments are the same as for dwarf_record_line_1.
19451 If SUBFILE is NULL the request is ignored. */
19454 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19455 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19457 if (subfile
== NULL
)
19460 if (dwarf_line_debug
)
19462 fprintf_unfiltered (gdb_stdlog
,
19463 "Finishing current line, file %s, address %s\n",
19464 lbasename (subfile
->name
),
19465 paddress (gdbarch
, address
));
19468 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19472 lnp_state_machine::record_line (bool end_sequence
)
19474 if (dwarf_line_debug
)
19476 fprintf_unfiltered (gdb_stdlog
,
19477 "Processing actual line %u: file %u,"
19478 " address %s, is_stmt %u, discrim %u%s\n",
19480 paddress (m_gdbarch
, m_address
),
19481 m_is_stmt
, m_discriminator
,
19482 (end_sequence
? "\t(end sequence)" : ""));
19485 file_entry
*fe
= current_file ();
19488 dwarf2_debug_line_missing_file_complaint ();
19489 /* For now we ignore lines not starting on an instruction boundary.
19490 But not when processing end_sequence for compatibility with the
19491 previous version of the code. */
19492 else if (m_op_index
== 0 || end_sequence
)
19494 fe
->included_p
= 1;
19495 if (m_record_lines_p
)
19497 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19500 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19501 m_currently_recording_lines
? m_cu
: nullptr);
19506 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19508 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19509 m_line_has_non_zero_discriminator
,
19512 buildsym_compunit
*builder
= m_cu
->get_builder ();
19513 dwarf_record_line_1 (m_gdbarch
,
19514 builder
->get_current_subfile (),
19515 m_line
, m_address
, is_stmt
,
19516 m_currently_recording_lines
? m_cu
: nullptr);
19518 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19519 m_last_line
= m_line
;
19525 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19526 line_header
*lh
, bool record_lines_p
)
19530 m_record_lines_p
= record_lines_p
;
19531 m_line_header
= lh
;
19533 m_currently_recording_lines
= true;
19535 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19536 was a line entry for it so that the backend has a chance to adjust it
19537 and also record it in case it needs it. This is currently used by MIPS
19538 code, cf. `mips_adjust_dwarf2_line'. */
19539 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19540 m_is_stmt
= lh
->default_is_stmt
;
19541 m_discriminator
= 0;
19545 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19546 const gdb_byte
*line_ptr
,
19547 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19549 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19550 the pc range of the CU. However, we restrict the test to only ADDRESS
19551 values of zero to preserve GDB's previous behaviour which is to handle
19552 the specific case of a function being GC'd by the linker. */
19554 if (address
== 0 && address
< unrelocated_lowpc
)
19556 /* This line table is for a function which has been
19557 GCd by the linker. Ignore it. PR gdb/12528 */
19559 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19560 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19562 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19563 line_offset
, objfile_name (objfile
));
19564 m_currently_recording_lines
= false;
19565 /* Note: m_currently_recording_lines is left as false until we see
19566 DW_LNE_end_sequence. */
19570 /* Subroutine of dwarf_decode_lines to simplify it.
19571 Process the line number information in LH.
19572 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19573 program in order to set included_p for every referenced header. */
19576 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19577 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19579 const gdb_byte
*line_ptr
, *extended_end
;
19580 const gdb_byte
*line_end
;
19581 unsigned int bytes_read
, extended_len
;
19582 unsigned char op_code
, extended_op
;
19583 CORE_ADDR baseaddr
;
19584 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19585 bfd
*abfd
= objfile
->obfd
;
19586 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19587 /* True if we're recording line info (as opposed to building partial
19588 symtabs and just interested in finding include files mentioned by
19589 the line number program). */
19590 bool record_lines_p
= !decode_for_pst_p
;
19592 baseaddr
= objfile
->text_section_offset ();
19594 line_ptr
= lh
->statement_program_start
;
19595 line_end
= lh
->statement_program_end
;
19597 /* Read the statement sequences until there's nothing left. */
19598 while (line_ptr
< line_end
)
19600 /* The DWARF line number program state machine. Reset the state
19601 machine at the start of each sequence. */
19602 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19603 bool end_sequence
= false;
19605 if (record_lines_p
)
19607 /* Start a subfile for the current file of the state
19609 const file_entry
*fe
= state_machine
.current_file ();
19612 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19615 /* Decode the table. */
19616 while (line_ptr
< line_end
&& !end_sequence
)
19618 op_code
= read_1_byte (abfd
, line_ptr
);
19621 if (op_code
>= lh
->opcode_base
)
19623 /* Special opcode. */
19624 state_machine
.handle_special_opcode (op_code
);
19626 else switch (op_code
)
19628 case DW_LNS_extended_op
:
19629 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19631 line_ptr
+= bytes_read
;
19632 extended_end
= line_ptr
+ extended_len
;
19633 extended_op
= read_1_byte (abfd
, line_ptr
);
19635 switch (extended_op
)
19637 case DW_LNE_end_sequence
:
19638 state_machine
.handle_end_sequence ();
19639 end_sequence
= true;
19641 case DW_LNE_set_address
:
19644 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19645 line_ptr
+= bytes_read
;
19647 state_machine
.check_line_address (cu
, line_ptr
,
19648 lowpc
- baseaddr
, address
);
19649 state_machine
.handle_set_address (baseaddr
, address
);
19652 case DW_LNE_define_file
:
19654 const char *cur_file
;
19655 unsigned int mod_time
, length
;
19658 cur_file
= read_direct_string (abfd
, line_ptr
,
19660 line_ptr
+= bytes_read
;
19661 dindex
= (dir_index
)
19662 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19663 line_ptr
+= bytes_read
;
19665 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19666 line_ptr
+= bytes_read
;
19668 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19669 line_ptr
+= bytes_read
;
19670 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19673 case DW_LNE_set_discriminator
:
19675 /* The discriminator is not interesting to the
19676 debugger; just ignore it. We still need to
19677 check its value though:
19678 if there are consecutive entries for the same
19679 (non-prologue) line we want to coalesce them.
19682 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19683 line_ptr
+= bytes_read
;
19685 state_machine
.handle_set_discriminator (discr
);
19689 complaint (_("mangled .debug_line section"));
19692 /* Make sure that we parsed the extended op correctly. If e.g.
19693 we expected a different address size than the producer used,
19694 we may have read the wrong number of bytes. */
19695 if (line_ptr
!= extended_end
)
19697 complaint (_("mangled .debug_line section"));
19702 state_machine
.handle_copy ();
19704 case DW_LNS_advance_pc
:
19707 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19708 line_ptr
+= bytes_read
;
19710 state_machine
.handle_advance_pc (adjust
);
19713 case DW_LNS_advance_line
:
19716 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19717 line_ptr
+= bytes_read
;
19719 state_machine
.handle_advance_line (line_delta
);
19722 case DW_LNS_set_file
:
19724 file_name_index file
19725 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19727 line_ptr
+= bytes_read
;
19729 state_machine
.handle_set_file (file
);
19732 case DW_LNS_set_column
:
19733 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19734 line_ptr
+= bytes_read
;
19736 case DW_LNS_negate_stmt
:
19737 state_machine
.handle_negate_stmt ();
19739 case DW_LNS_set_basic_block
:
19741 /* Add to the address register of the state machine the
19742 address increment value corresponding to special opcode
19743 255. I.e., this value is scaled by the minimum
19744 instruction length since special opcode 255 would have
19745 scaled the increment. */
19746 case DW_LNS_const_add_pc
:
19747 state_machine
.handle_const_add_pc ();
19749 case DW_LNS_fixed_advance_pc
:
19751 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19754 state_machine
.handle_fixed_advance_pc (addr_adj
);
19759 /* Unknown standard opcode, ignore it. */
19762 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19764 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19765 line_ptr
+= bytes_read
;
19772 dwarf2_debug_line_missing_end_sequence_complaint ();
19774 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19775 in which case we still finish recording the last line). */
19776 state_machine
.record_line (true);
19780 /* Decode the Line Number Program (LNP) for the given line_header
19781 structure and CU. The actual information extracted and the type
19782 of structures created from the LNP depends on the value of PST.
19784 1. If PST is NULL, then this procedure uses the data from the program
19785 to create all necessary symbol tables, and their linetables.
19787 2. If PST is not NULL, this procedure reads the program to determine
19788 the list of files included by the unit represented by PST, and
19789 builds all the associated partial symbol tables.
19791 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19792 It is used for relative paths in the line table.
19793 NOTE: When processing partial symtabs (pst != NULL),
19794 comp_dir == pst->dirname.
19796 NOTE: It is important that psymtabs have the same file name (via strcmp)
19797 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19798 symtab we don't use it in the name of the psymtabs we create.
19799 E.g. expand_line_sal requires this when finding psymtabs to expand.
19800 A good testcase for this is mb-inline.exp.
19802 LOWPC is the lowest address in CU (or 0 if not known).
19804 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19805 for its PC<->lines mapping information. Otherwise only the filename
19806 table is read in. */
19809 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19810 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19811 CORE_ADDR lowpc
, int decode_mapping
)
19813 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19814 const int decode_for_pst_p
= (pst
!= NULL
);
19816 if (decode_mapping
)
19817 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19819 if (decode_for_pst_p
)
19821 /* Now that we're done scanning the Line Header Program, we can
19822 create the psymtab of each included file. */
19823 for (auto &file_entry
: lh
->file_names ())
19824 if (file_entry
.included_p
== 1)
19826 gdb::unique_xmalloc_ptr
<char> name_holder
;
19827 const char *include_name
=
19828 psymtab_include_file_name (lh
, file_entry
, pst
,
19829 comp_dir
, &name_holder
);
19830 if (include_name
!= NULL
)
19831 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19836 /* Make sure a symtab is created for every file, even files
19837 which contain only variables (i.e. no code with associated
19839 buildsym_compunit
*builder
= cu
->get_builder ();
19840 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19842 for (auto &fe
: lh
->file_names ())
19844 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19845 if (builder
->get_current_subfile ()->symtab
== NULL
)
19847 builder
->get_current_subfile ()->symtab
19848 = allocate_symtab (cust
,
19849 builder
->get_current_subfile ()->name
);
19851 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19856 /* Start a subfile for DWARF. FILENAME is the name of the file and
19857 DIRNAME the name of the source directory which contains FILENAME
19858 or NULL if not known.
19859 This routine tries to keep line numbers from identical absolute and
19860 relative file names in a common subfile.
19862 Using the `list' example from the GDB testsuite, which resides in
19863 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19864 of /srcdir/list0.c yields the following debugging information for list0.c:
19866 DW_AT_name: /srcdir/list0.c
19867 DW_AT_comp_dir: /compdir
19868 files.files[0].name: list0.h
19869 files.files[0].dir: /srcdir
19870 files.files[1].name: list0.c
19871 files.files[1].dir: /srcdir
19873 The line number information for list0.c has to end up in a single
19874 subfile, so that `break /srcdir/list0.c:1' works as expected.
19875 start_subfile will ensure that this happens provided that we pass the
19876 concatenation of files.files[1].dir and files.files[1].name as the
19880 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19881 const char *dirname
)
19883 gdb::unique_xmalloc_ptr
<char> copy
;
19885 /* In order not to lose the line information directory,
19886 we concatenate it to the filename when it makes sense.
19887 Note that the Dwarf3 standard says (speaking of filenames in line
19888 information): ``The directory index is ignored for file names
19889 that represent full path names''. Thus ignoring dirname in the
19890 `else' branch below isn't an issue. */
19892 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19894 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19895 filename
= copy
.get ();
19898 cu
->get_builder ()->start_subfile (filename
);
19901 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19902 buildsym_compunit constructor. */
19904 struct compunit_symtab
*
19905 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19908 gdb_assert (m_builder
== nullptr);
19910 m_builder
.reset (new struct buildsym_compunit
19911 (per_cu
->dwarf2_per_objfile
->objfile
,
19912 name
, comp_dir
, language
, low_pc
));
19914 list_in_scope
= get_builder ()->get_file_symbols ();
19916 get_builder ()->record_debugformat ("DWARF 2");
19917 get_builder ()->record_producer (producer
);
19919 processing_has_namespace_info
= false;
19921 return get_builder ()->get_compunit_symtab ();
19925 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19926 struct dwarf2_cu
*cu
)
19928 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19929 struct comp_unit_head
*cu_header
= &cu
->header
;
19931 /* NOTE drow/2003-01-30: There used to be a comment and some special
19932 code here to turn a symbol with DW_AT_external and a
19933 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19934 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19935 with some versions of binutils) where shared libraries could have
19936 relocations against symbols in their debug information - the
19937 minimal symbol would have the right address, but the debug info
19938 would not. It's no longer necessary, because we will explicitly
19939 apply relocations when we read in the debug information now. */
19941 /* A DW_AT_location attribute with no contents indicates that a
19942 variable has been optimized away. */
19943 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
19945 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19949 /* Handle one degenerate form of location expression specially, to
19950 preserve GDB's previous behavior when section offsets are
19951 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
19952 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
19954 if (attr
->form_is_block ()
19955 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19956 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19957 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19958 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
19959 && (DW_BLOCK (attr
)->size
19960 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
19962 unsigned int dummy
;
19964 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
19965 SET_SYMBOL_VALUE_ADDRESS
19966 (sym
, cu
->header
.read_address (objfile
->obfd
,
19967 DW_BLOCK (attr
)->data
+ 1,
19970 SET_SYMBOL_VALUE_ADDRESS
19971 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
19973 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
19974 fixup_symbol_section (sym
, objfile
);
19975 SET_SYMBOL_VALUE_ADDRESS
19977 SYMBOL_VALUE_ADDRESS (sym
)
19978 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
19982 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
19983 expression evaluator, and use LOC_COMPUTED only when necessary
19984 (i.e. when the value of a register or memory location is
19985 referenced, or a thread-local block, etc.). Then again, it might
19986 not be worthwhile. I'm assuming that it isn't unless performance
19987 or memory numbers show me otherwise. */
19989 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
19991 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
19992 cu
->has_loclist
= true;
19995 /* Given a pointer to a DWARF information entry, figure out if we need
19996 to make a symbol table entry for it, and if so, create a new entry
19997 and return a pointer to it.
19998 If TYPE is NULL, determine symbol type from the die, otherwise
19999 used the passed type.
20000 If SPACE is not NULL, use it to hold the new symbol. If it is
20001 NULL, allocate a new symbol on the objfile's obstack. */
20003 static struct symbol
*
20004 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20005 struct symbol
*space
)
20007 struct dwarf2_per_objfile
*dwarf2_per_objfile
20008 = cu
->per_cu
->dwarf2_per_objfile
;
20009 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20010 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20011 struct symbol
*sym
= NULL
;
20013 struct attribute
*attr
= NULL
;
20014 struct attribute
*attr2
= NULL
;
20015 CORE_ADDR baseaddr
;
20016 struct pending
**list_to_add
= NULL
;
20018 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20020 baseaddr
= objfile
->text_section_offset ();
20022 name
= dwarf2_name (die
, cu
);
20025 const char *linkagename
;
20026 int suppress_add
= 0;
20031 sym
= allocate_symbol (objfile
);
20032 OBJSTAT (objfile
, n_syms
++);
20034 /* Cache this symbol's name and the name's demangled form (if any). */
20035 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20036 linkagename
= dwarf2_physname (name
, die
, cu
);
20037 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20039 /* Fortran does not have mangling standard and the mangling does differ
20040 between gfortran, iFort etc. */
20041 if (cu
->language
== language_fortran
20042 && symbol_get_demangled_name (sym
) == NULL
)
20043 symbol_set_demangled_name (sym
,
20044 dwarf2_full_name (name
, die
, cu
),
20047 /* Default assumptions.
20048 Use the passed type or decode it from the die. */
20049 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20050 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20052 SYMBOL_TYPE (sym
) = type
;
20054 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20055 attr
= dwarf2_attr (die
,
20056 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20058 if (attr
!= nullptr)
20060 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20063 attr
= dwarf2_attr (die
,
20064 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20066 if (attr
!= nullptr)
20068 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20069 struct file_entry
*fe
;
20071 if (cu
->line_header
!= NULL
)
20072 fe
= cu
->line_header
->file_name_at (file_index
);
20077 complaint (_("file index out of range"));
20079 symbol_set_symtab (sym
, fe
->symtab
);
20085 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20086 if (attr
!= nullptr)
20090 addr
= attr
->value_as_address ();
20091 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20092 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20094 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20095 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20096 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20097 add_symbol_to_list (sym
, cu
->list_in_scope
);
20099 case DW_TAG_subprogram
:
20100 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20102 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20103 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20104 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20105 || cu
->language
== language_ada
20106 || cu
->language
== language_fortran
)
20108 /* Subprograms marked external are stored as a global symbol.
20109 Ada and Fortran subprograms, whether marked external or
20110 not, are always stored as a global symbol, because we want
20111 to be able to access them globally. For instance, we want
20112 to be able to break on a nested subprogram without having
20113 to specify the context. */
20114 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20118 list_to_add
= cu
->list_in_scope
;
20121 case DW_TAG_inlined_subroutine
:
20122 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20124 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20125 SYMBOL_INLINED (sym
) = 1;
20126 list_to_add
= cu
->list_in_scope
;
20128 case DW_TAG_template_value_param
:
20130 /* Fall through. */
20131 case DW_TAG_constant
:
20132 case DW_TAG_variable
:
20133 case DW_TAG_member
:
20134 /* Compilation with minimal debug info may result in
20135 variables with missing type entries. Change the
20136 misleading `void' type to something sensible. */
20137 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20138 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20140 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20141 /* In the case of DW_TAG_member, we should only be called for
20142 static const members. */
20143 if (die
->tag
== DW_TAG_member
)
20145 /* dwarf2_add_field uses die_is_declaration,
20146 so we do the same. */
20147 gdb_assert (die_is_declaration (die
, cu
));
20150 if (attr
!= nullptr)
20152 dwarf2_const_value (attr
, sym
, cu
);
20153 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20156 if (attr2
&& (DW_UNSND (attr2
) != 0))
20157 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20159 list_to_add
= cu
->list_in_scope
;
20163 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20164 if (attr
!= nullptr)
20166 var_decode_location (attr
, sym
, cu
);
20167 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20169 /* Fortran explicitly imports any global symbols to the local
20170 scope by DW_TAG_common_block. */
20171 if (cu
->language
== language_fortran
&& die
->parent
20172 && die
->parent
->tag
== DW_TAG_common_block
)
20175 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20176 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20177 && !dwarf2_per_objfile
->has_section_at_zero
)
20179 /* When a static variable is eliminated by the linker,
20180 the corresponding debug information is not stripped
20181 out, but the variable address is set to null;
20182 do not add such variables into symbol table. */
20184 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20186 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20187 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20188 && dwarf2_per_objfile
->can_copy
)
20190 /* A global static variable might be subject to
20191 copy relocation. We first check for a local
20192 minsym, though, because maybe the symbol was
20193 marked hidden, in which case this would not
20195 bound_minimal_symbol found
20196 = (lookup_minimal_symbol_linkage
20197 (sym
->linkage_name (), objfile
));
20198 if (found
.minsym
!= nullptr)
20199 sym
->maybe_copied
= 1;
20202 /* A variable with DW_AT_external is never static,
20203 but it may be block-scoped. */
20205 = ((cu
->list_in_scope
20206 == cu
->get_builder ()->get_file_symbols ())
20207 ? cu
->get_builder ()->get_global_symbols ()
20208 : cu
->list_in_scope
);
20211 list_to_add
= cu
->list_in_scope
;
20215 /* We do not know the address of this symbol.
20216 If it is an external symbol and we have type information
20217 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20218 The address of the variable will then be determined from
20219 the minimal symbol table whenever the variable is
20221 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20223 /* Fortran explicitly imports any global symbols to the local
20224 scope by DW_TAG_common_block. */
20225 if (cu
->language
== language_fortran
&& die
->parent
20226 && die
->parent
->tag
== DW_TAG_common_block
)
20228 /* SYMBOL_CLASS doesn't matter here because
20229 read_common_block is going to reset it. */
20231 list_to_add
= cu
->list_in_scope
;
20233 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20234 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20236 /* A variable with DW_AT_external is never static, but it
20237 may be block-scoped. */
20239 = ((cu
->list_in_scope
20240 == cu
->get_builder ()->get_file_symbols ())
20241 ? cu
->get_builder ()->get_global_symbols ()
20242 : cu
->list_in_scope
);
20244 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20246 else if (!die_is_declaration (die
, cu
))
20248 /* Use the default LOC_OPTIMIZED_OUT class. */
20249 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20251 list_to_add
= cu
->list_in_scope
;
20255 case DW_TAG_formal_parameter
:
20257 /* If we are inside a function, mark this as an argument. If
20258 not, we might be looking at an argument to an inlined function
20259 when we do not have enough information to show inlined frames;
20260 pretend it's a local variable in that case so that the user can
20262 struct context_stack
*curr
20263 = cu
->get_builder ()->get_current_context_stack ();
20264 if (curr
!= nullptr && curr
->name
!= nullptr)
20265 SYMBOL_IS_ARGUMENT (sym
) = 1;
20266 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20267 if (attr
!= nullptr)
20269 var_decode_location (attr
, sym
, cu
);
20271 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20272 if (attr
!= nullptr)
20274 dwarf2_const_value (attr
, sym
, cu
);
20277 list_to_add
= cu
->list_in_scope
;
20280 case DW_TAG_unspecified_parameters
:
20281 /* From varargs functions; gdb doesn't seem to have any
20282 interest in this information, so just ignore it for now.
20285 case DW_TAG_template_type_param
:
20287 /* Fall through. */
20288 case DW_TAG_class_type
:
20289 case DW_TAG_interface_type
:
20290 case DW_TAG_structure_type
:
20291 case DW_TAG_union_type
:
20292 case DW_TAG_set_type
:
20293 case DW_TAG_enumeration_type
:
20294 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20295 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20298 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20299 really ever be static objects: otherwise, if you try
20300 to, say, break of a class's method and you're in a file
20301 which doesn't mention that class, it won't work unless
20302 the check for all static symbols in lookup_symbol_aux
20303 saves you. See the OtherFileClass tests in
20304 gdb.c++/namespace.exp. */
20308 buildsym_compunit
*builder
= cu
->get_builder ();
20310 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20311 && cu
->language
== language_cplus
20312 ? builder
->get_global_symbols ()
20313 : cu
->list_in_scope
);
20315 /* The semantics of C++ state that "struct foo {
20316 ... }" also defines a typedef for "foo". */
20317 if (cu
->language
== language_cplus
20318 || cu
->language
== language_ada
20319 || cu
->language
== language_d
20320 || cu
->language
== language_rust
)
20322 /* The symbol's name is already allocated along
20323 with this objfile, so we don't need to
20324 duplicate it for the type. */
20325 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20326 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20331 case DW_TAG_typedef
:
20332 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20333 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20334 list_to_add
= cu
->list_in_scope
;
20336 case DW_TAG_base_type
:
20337 case DW_TAG_subrange_type
:
20338 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20339 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20340 list_to_add
= cu
->list_in_scope
;
20342 case DW_TAG_enumerator
:
20343 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20344 if (attr
!= nullptr)
20346 dwarf2_const_value (attr
, sym
, cu
);
20349 /* NOTE: carlton/2003-11-10: See comment above in the
20350 DW_TAG_class_type, etc. block. */
20353 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20354 && cu
->language
== language_cplus
20355 ? cu
->get_builder ()->get_global_symbols ()
20356 : cu
->list_in_scope
);
20359 case DW_TAG_imported_declaration
:
20360 case DW_TAG_namespace
:
20361 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20362 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20364 case DW_TAG_module
:
20365 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20366 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20367 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20369 case DW_TAG_common_block
:
20370 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20371 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20372 add_symbol_to_list (sym
, cu
->list_in_scope
);
20375 /* Not a tag we recognize. Hopefully we aren't processing
20376 trash data, but since we must specifically ignore things
20377 we don't recognize, there is nothing else we should do at
20379 complaint (_("unsupported tag: '%s'"),
20380 dwarf_tag_name (die
->tag
));
20386 sym
->hash_next
= objfile
->template_symbols
;
20387 objfile
->template_symbols
= sym
;
20388 list_to_add
= NULL
;
20391 if (list_to_add
!= NULL
)
20392 add_symbol_to_list (sym
, list_to_add
);
20394 /* For the benefit of old versions of GCC, check for anonymous
20395 namespaces based on the demangled name. */
20396 if (!cu
->processing_has_namespace_info
20397 && cu
->language
== language_cplus
)
20398 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20403 /* Given an attr with a DW_FORM_dataN value in host byte order,
20404 zero-extend it as appropriate for the symbol's type. The DWARF
20405 standard (v4) is not entirely clear about the meaning of using
20406 DW_FORM_dataN for a constant with a signed type, where the type is
20407 wider than the data. The conclusion of a discussion on the DWARF
20408 list was that this is unspecified. We choose to always zero-extend
20409 because that is the interpretation long in use by GCC. */
20412 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20413 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20415 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20416 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20417 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20418 LONGEST l
= DW_UNSND (attr
);
20420 if (bits
< sizeof (*value
) * 8)
20422 l
&= ((LONGEST
) 1 << bits
) - 1;
20425 else if (bits
== sizeof (*value
) * 8)
20429 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20430 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20437 /* Read a constant value from an attribute. Either set *VALUE, or if
20438 the value does not fit in *VALUE, set *BYTES - either already
20439 allocated on the objfile obstack, or newly allocated on OBSTACK,
20440 or, set *BATON, if we translated the constant to a location
20444 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20445 const char *name
, struct obstack
*obstack
,
20446 struct dwarf2_cu
*cu
,
20447 LONGEST
*value
, const gdb_byte
**bytes
,
20448 struct dwarf2_locexpr_baton
**baton
)
20450 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20451 struct comp_unit_head
*cu_header
= &cu
->header
;
20452 struct dwarf_block
*blk
;
20453 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20454 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20460 switch (attr
->form
)
20463 case DW_FORM_addrx
:
20464 case DW_FORM_GNU_addr_index
:
20468 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20469 dwarf2_const_value_length_mismatch_complaint (name
,
20470 cu_header
->addr_size
,
20471 TYPE_LENGTH (type
));
20472 /* Symbols of this form are reasonably rare, so we just
20473 piggyback on the existing location code rather than writing
20474 a new implementation of symbol_computed_ops. */
20475 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20476 (*baton
)->per_cu
= cu
->per_cu
;
20477 gdb_assert ((*baton
)->per_cu
);
20479 (*baton
)->size
= 2 + cu_header
->addr_size
;
20480 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20481 (*baton
)->data
= data
;
20483 data
[0] = DW_OP_addr
;
20484 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20485 byte_order
, DW_ADDR (attr
));
20486 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20489 case DW_FORM_string
:
20492 case DW_FORM_GNU_str_index
:
20493 case DW_FORM_GNU_strp_alt
:
20494 /* DW_STRING is already allocated on the objfile obstack, point
20496 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20498 case DW_FORM_block1
:
20499 case DW_FORM_block2
:
20500 case DW_FORM_block4
:
20501 case DW_FORM_block
:
20502 case DW_FORM_exprloc
:
20503 case DW_FORM_data16
:
20504 blk
= DW_BLOCK (attr
);
20505 if (TYPE_LENGTH (type
) != blk
->size
)
20506 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20507 TYPE_LENGTH (type
));
20508 *bytes
= blk
->data
;
20511 /* The DW_AT_const_value attributes are supposed to carry the
20512 symbol's value "represented as it would be on the target
20513 architecture." By the time we get here, it's already been
20514 converted to host endianness, so we just need to sign- or
20515 zero-extend it as appropriate. */
20516 case DW_FORM_data1
:
20517 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20519 case DW_FORM_data2
:
20520 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20522 case DW_FORM_data4
:
20523 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20525 case DW_FORM_data8
:
20526 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20529 case DW_FORM_sdata
:
20530 case DW_FORM_implicit_const
:
20531 *value
= DW_SND (attr
);
20534 case DW_FORM_udata
:
20535 *value
= DW_UNSND (attr
);
20539 complaint (_("unsupported const value attribute form: '%s'"),
20540 dwarf_form_name (attr
->form
));
20547 /* Copy constant value from an attribute to a symbol. */
20550 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20551 struct dwarf2_cu
*cu
)
20553 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20555 const gdb_byte
*bytes
;
20556 struct dwarf2_locexpr_baton
*baton
;
20558 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20559 sym
->print_name (),
20560 &objfile
->objfile_obstack
, cu
,
20561 &value
, &bytes
, &baton
);
20565 SYMBOL_LOCATION_BATON (sym
) = baton
;
20566 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20568 else if (bytes
!= NULL
)
20570 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20571 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20575 SYMBOL_VALUE (sym
) = value
;
20576 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20580 /* Return the type of the die in question using its DW_AT_type attribute. */
20582 static struct type
*
20583 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20585 struct attribute
*type_attr
;
20587 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20590 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20591 /* A missing DW_AT_type represents a void type. */
20592 return objfile_type (objfile
)->builtin_void
;
20595 return lookup_die_type (die
, type_attr
, cu
);
20598 /* True iff CU's producer generates GNAT Ada auxiliary information
20599 that allows to find parallel types through that information instead
20600 of having to do expensive parallel lookups by type name. */
20603 need_gnat_info (struct dwarf2_cu
*cu
)
20605 /* Assume that the Ada compiler was GNAT, which always produces
20606 the auxiliary information. */
20607 return (cu
->language
== language_ada
);
20610 /* Return the auxiliary type of the die in question using its
20611 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20612 attribute is not present. */
20614 static struct type
*
20615 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20617 struct attribute
*type_attr
;
20619 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20623 return lookup_die_type (die
, type_attr
, cu
);
20626 /* If DIE has a descriptive_type attribute, then set the TYPE's
20627 descriptive type accordingly. */
20630 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20631 struct dwarf2_cu
*cu
)
20633 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20635 if (descriptive_type
)
20637 ALLOCATE_GNAT_AUX_TYPE (type
);
20638 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20642 /* Return the containing type of the die in question using its
20643 DW_AT_containing_type attribute. */
20645 static struct type
*
20646 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20648 struct attribute
*type_attr
;
20649 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20651 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20653 error (_("Dwarf Error: Problem turning containing type into gdb type "
20654 "[in module %s]"), objfile_name (objfile
));
20656 return lookup_die_type (die
, type_attr
, cu
);
20659 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20661 static struct type
*
20662 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20664 struct dwarf2_per_objfile
*dwarf2_per_objfile
20665 = cu
->per_cu
->dwarf2_per_objfile
;
20666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20669 std::string message
20670 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20671 objfile_name (objfile
),
20672 sect_offset_str (cu
->header
.sect_off
),
20673 sect_offset_str (die
->sect_off
));
20674 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20676 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20679 /* Look up the type of DIE in CU using its type attribute ATTR.
20680 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20681 DW_AT_containing_type.
20682 If there is no type substitute an error marker. */
20684 static struct type
*
20685 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20686 struct dwarf2_cu
*cu
)
20688 struct dwarf2_per_objfile
*dwarf2_per_objfile
20689 = cu
->per_cu
->dwarf2_per_objfile
;
20690 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20691 struct type
*this_type
;
20693 gdb_assert (attr
->name
== DW_AT_type
20694 || attr
->name
== DW_AT_GNAT_descriptive_type
20695 || attr
->name
== DW_AT_containing_type
);
20697 /* First see if we have it cached. */
20699 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20701 struct dwarf2_per_cu_data
*per_cu
;
20702 sect_offset sect_off
= attr
->get_ref_die_offset ();
20704 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20705 dwarf2_per_objfile
);
20706 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20708 else if (attr
->form_is_ref ())
20710 sect_offset sect_off
= attr
->get_ref_die_offset ();
20712 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20714 else if (attr
->form
== DW_FORM_ref_sig8
)
20716 ULONGEST signature
= DW_SIGNATURE (attr
);
20718 return get_signatured_type (die
, signature
, cu
);
20722 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20723 " at %s [in module %s]"),
20724 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20725 objfile_name (objfile
));
20726 return build_error_marker_type (cu
, die
);
20729 /* If not cached we need to read it in. */
20731 if (this_type
== NULL
)
20733 struct die_info
*type_die
= NULL
;
20734 struct dwarf2_cu
*type_cu
= cu
;
20736 if (attr
->form_is_ref ())
20737 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20738 if (type_die
== NULL
)
20739 return build_error_marker_type (cu
, die
);
20740 /* If we find the type now, it's probably because the type came
20741 from an inter-CU reference and the type's CU got expanded before
20743 this_type
= read_type_die (type_die
, type_cu
);
20746 /* If we still don't have a type use an error marker. */
20748 if (this_type
== NULL
)
20749 return build_error_marker_type (cu
, die
);
20754 /* Return the type in DIE, CU.
20755 Returns NULL for invalid types.
20757 This first does a lookup in die_type_hash,
20758 and only reads the die in if necessary.
20760 NOTE: This can be called when reading in partial or full symbols. */
20762 static struct type
*
20763 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20765 struct type
*this_type
;
20767 this_type
= get_die_type (die
, cu
);
20771 return read_type_die_1 (die
, cu
);
20774 /* Read the type in DIE, CU.
20775 Returns NULL for invalid types. */
20777 static struct type
*
20778 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20780 struct type
*this_type
= NULL
;
20784 case DW_TAG_class_type
:
20785 case DW_TAG_interface_type
:
20786 case DW_TAG_structure_type
:
20787 case DW_TAG_union_type
:
20788 this_type
= read_structure_type (die
, cu
);
20790 case DW_TAG_enumeration_type
:
20791 this_type
= read_enumeration_type (die
, cu
);
20793 case DW_TAG_subprogram
:
20794 case DW_TAG_subroutine_type
:
20795 case DW_TAG_inlined_subroutine
:
20796 this_type
= read_subroutine_type (die
, cu
);
20798 case DW_TAG_array_type
:
20799 this_type
= read_array_type (die
, cu
);
20801 case DW_TAG_set_type
:
20802 this_type
= read_set_type (die
, cu
);
20804 case DW_TAG_pointer_type
:
20805 this_type
= read_tag_pointer_type (die
, cu
);
20807 case DW_TAG_ptr_to_member_type
:
20808 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20810 case DW_TAG_reference_type
:
20811 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20813 case DW_TAG_rvalue_reference_type
:
20814 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20816 case DW_TAG_const_type
:
20817 this_type
= read_tag_const_type (die
, cu
);
20819 case DW_TAG_volatile_type
:
20820 this_type
= read_tag_volatile_type (die
, cu
);
20822 case DW_TAG_restrict_type
:
20823 this_type
= read_tag_restrict_type (die
, cu
);
20825 case DW_TAG_string_type
:
20826 this_type
= read_tag_string_type (die
, cu
);
20828 case DW_TAG_typedef
:
20829 this_type
= read_typedef (die
, cu
);
20831 case DW_TAG_subrange_type
:
20832 this_type
= read_subrange_type (die
, cu
);
20834 case DW_TAG_base_type
:
20835 this_type
= read_base_type (die
, cu
);
20837 case DW_TAG_unspecified_type
:
20838 this_type
= read_unspecified_type (die
, cu
);
20840 case DW_TAG_namespace
:
20841 this_type
= read_namespace_type (die
, cu
);
20843 case DW_TAG_module
:
20844 this_type
= read_module_type (die
, cu
);
20846 case DW_TAG_atomic_type
:
20847 this_type
= read_tag_atomic_type (die
, cu
);
20850 complaint (_("unexpected tag in read_type_die: '%s'"),
20851 dwarf_tag_name (die
->tag
));
20858 /* See if we can figure out if the class lives in a namespace. We do
20859 this by looking for a member function; its demangled name will
20860 contain namespace info, if there is any.
20861 Return the computed name or NULL.
20862 Space for the result is allocated on the objfile's obstack.
20863 This is the full-die version of guess_partial_die_structure_name.
20864 In this case we know DIE has no useful parent. */
20866 static const char *
20867 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20869 struct die_info
*spec_die
;
20870 struct dwarf2_cu
*spec_cu
;
20871 struct die_info
*child
;
20872 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20875 spec_die
= die_specification (die
, &spec_cu
);
20876 if (spec_die
!= NULL
)
20882 for (child
= die
->child
;
20884 child
= child
->sibling
)
20886 if (child
->tag
== DW_TAG_subprogram
)
20888 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20890 if (linkage_name
!= NULL
)
20892 gdb::unique_xmalloc_ptr
<char> actual_name
20893 (language_class_name_from_physname (cu
->language_defn
,
20895 const char *name
= NULL
;
20897 if (actual_name
!= NULL
)
20899 const char *die_name
= dwarf2_name (die
, cu
);
20901 if (die_name
!= NULL
20902 && strcmp (die_name
, actual_name
.get ()) != 0)
20904 /* Strip off the class name from the full name.
20905 We want the prefix. */
20906 int die_name_len
= strlen (die_name
);
20907 int actual_name_len
= strlen (actual_name
.get ());
20908 const char *ptr
= actual_name
.get ();
20910 /* Test for '::' as a sanity check. */
20911 if (actual_name_len
> die_name_len
+ 2
20912 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20913 name
= obstack_strndup (
20914 &objfile
->per_bfd
->storage_obstack
,
20915 ptr
, actual_name_len
- die_name_len
- 2);
20926 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20927 prefix part in such case. See
20928 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20930 static const char *
20931 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20933 struct attribute
*attr
;
20936 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20937 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20940 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20943 attr
= dw2_linkage_name_attr (die
, cu
);
20944 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20947 /* dwarf2_name had to be already called. */
20948 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20950 /* Strip the base name, keep any leading namespaces/classes. */
20951 base
= strrchr (DW_STRING (attr
), ':');
20952 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20955 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20956 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
20958 &base
[-1] - DW_STRING (attr
));
20961 /* Return the name of the namespace/class that DIE is defined within,
20962 or "" if we can't tell. The caller should not xfree the result.
20964 For example, if we're within the method foo() in the following
20974 then determine_prefix on foo's die will return "N::C". */
20976 static const char *
20977 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20979 struct dwarf2_per_objfile
*dwarf2_per_objfile
20980 = cu
->per_cu
->dwarf2_per_objfile
;
20981 struct die_info
*parent
, *spec_die
;
20982 struct dwarf2_cu
*spec_cu
;
20983 struct type
*parent_type
;
20984 const char *retval
;
20986 if (cu
->language
!= language_cplus
20987 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
20988 && cu
->language
!= language_rust
)
20991 retval
= anonymous_struct_prefix (die
, cu
);
20995 /* We have to be careful in the presence of DW_AT_specification.
20996 For example, with GCC 3.4, given the code
21000 // Definition of N::foo.
21004 then we'll have a tree of DIEs like this:
21006 1: DW_TAG_compile_unit
21007 2: DW_TAG_namespace // N
21008 3: DW_TAG_subprogram // declaration of N::foo
21009 4: DW_TAG_subprogram // definition of N::foo
21010 DW_AT_specification // refers to die #3
21012 Thus, when processing die #4, we have to pretend that we're in
21013 the context of its DW_AT_specification, namely the contex of die
21016 spec_die
= die_specification (die
, &spec_cu
);
21017 if (spec_die
== NULL
)
21018 parent
= die
->parent
;
21021 parent
= spec_die
->parent
;
21025 if (parent
== NULL
)
21027 else if (parent
->building_fullname
)
21030 const char *parent_name
;
21032 /* It has been seen on RealView 2.2 built binaries,
21033 DW_TAG_template_type_param types actually _defined_ as
21034 children of the parent class:
21037 template class <class Enum> Class{};
21038 Class<enum E> class_e;
21040 1: DW_TAG_class_type (Class)
21041 2: DW_TAG_enumeration_type (E)
21042 3: DW_TAG_enumerator (enum1:0)
21043 3: DW_TAG_enumerator (enum2:1)
21045 2: DW_TAG_template_type_param
21046 DW_AT_type DW_FORM_ref_udata (E)
21048 Besides being broken debug info, it can put GDB into an
21049 infinite loop. Consider:
21051 When we're building the full name for Class<E>, we'll start
21052 at Class, and go look over its template type parameters,
21053 finding E. We'll then try to build the full name of E, and
21054 reach here. We're now trying to build the full name of E,
21055 and look over the parent DIE for containing scope. In the
21056 broken case, if we followed the parent DIE of E, we'd again
21057 find Class, and once again go look at its template type
21058 arguments, etc., etc. Simply don't consider such parent die
21059 as source-level parent of this die (it can't be, the language
21060 doesn't allow it), and break the loop here. */
21061 name
= dwarf2_name (die
, cu
);
21062 parent_name
= dwarf2_name (parent
, cu
);
21063 complaint (_("template param type '%s' defined within parent '%s'"),
21064 name
? name
: "<unknown>",
21065 parent_name
? parent_name
: "<unknown>");
21069 switch (parent
->tag
)
21071 case DW_TAG_namespace
:
21072 parent_type
= read_type_die (parent
, cu
);
21073 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21074 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21075 Work around this problem here. */
21076 if (cu
->language
== language_cplus
21077 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21079 /* We give a name to even anonymous namespaces. */
21080 return TYPE_NAME (parent_type
);
21081 case DW_TAG_class_type
:
21082 case DW_TAG_interface_type
:
21083 case DW_TAG_structure_type
:
21084 case DW_TAG_union_type
:
21085 case DW_TAG_module
:
21086 parent_type
= read_type_die (parent
, cu
);
21087 if (TYPE_NAME (parent_type
) != NULL
)
21088 return TYPE_NAME (parent_type
);
21090 /* An anonymous structure is only allowed non-static data
21091 members; no typedefs, no member functions, et cetera.
21092 So it does not need a prefix. */
21094 case DW_TAG_compile_unit
:
21095 case DW_TAG_partial_unit
:
21096 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21097 if (cu
->language
== language_cplus
21098 && !dwarf2_per_objfile
->types
.empty ()
21099 && die
->child
!= NULL
21100 && (die
->tag
== DW_TAG_class_type
21101 || die
->tag
== DW_TAG_structure_type
21102 || die
->tag
== DW_TAG_union_type
))
21104 const char *name
= guess_full_die_structure_name (die
, cu
);
21109 case DW_TAG_subprogram
:
21110 /* Nested subroutines in Fortran get a prefix with the name
21111 of the parent's subroutine. */
21112 if (cu
->language
== language_fortran
)
21114 if ((die
->tag
== DW_TAG_subprogram
)
21115 && (dwarf2_name (parent
, cu
) != NULL
))
21116 return dwarf2_name (parent
, cu
);
21118 return determine_prefix (parent
, cu
);
21119 case DW_TAG_enumeration_type
:
21120 parent_type
= read_type_die (parent
, cu
);
21121 if (TYPE_DECLARED_CLASS (parent_type
))
21123 if (TYPE_NAME (parent_type
) != NULL
)
21124 return TYPE_NAME (parent_type
);
21127 /* Fall through. */
21129 return determine_prefix (parent
, cu
);
21133 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21134 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21135 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21136 an obconcat, otherwise allocate storage for the result. The CU argument is
21137 used to determine the language and hence, the appropriate separator. */
21139 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21142 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21143 int physname
, struct dwarf2_cu
*cu
)
21145 const char *lead
= "";
21148 if (suffix
== NULL
|| suffix
[0] == '\0'
21149 || prefix
== NULL
|| prefix
[0] == '\0')
21151 else if (cu
->language
== language_d
)
21153 /* For D, the 'main' function could be defined in any module, but it
21154 should never be prefixed. */
21155 if (strcmp (suffix
, "D main") == 0)
21163 else if (cu
->language
== language_fortran
&& physname
)
21165 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21166 DW_AT_MIPS_linkage_name is preferred and used instead. */
21174 if (prefix
== NULL
)
21176 if (suffix
== NULL
)
21183 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21185 strcpy (retval
, lead
);
21186 strcat (retval
, prefix
);
21187 strcat (retval
, sep
);
21188 strcat (retval
, suffix
);
21193 /* We have an obstack. */
21194 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21198 /* Get name of a die, return NULL if not found. */
21200 static const char *
21201 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21202 struct objfile
*objfile
)
21204 if (name
&& cu
->language
== language_cplus
)
21206 std::string canon_name
= cp_canonicalize_string (name
);
21208 if (!canon_name
.empty ())
21210 if (canon_name
!= name
)
21211 name
= objfile
->intern (canon_name
);
21218 /* Get name of a die, return NULL if not found.
21219 Anonymous namespaces are converted to their magic string. */
21221 static const char *
21222 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21224 struct attribute
*attr
;
21225 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21227 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21228 if ((!attr
|| !DW_STRING (attr
))
21229 && die
->tag
!= DW_TAG_namespace
21230 && die
->tag
!= DW_TAG_class_type
21231 && die
->tag
!= DW_TAG_interface_type
21232 && die
->tag
!= DW_TAG_structure_type
21233 && die
->tag
!= DW_TAG_union_type
)
21238 case DW_TAG_compile_unit
:
21239 case DW_TAG_partial_unit
:
21240 /* Compilation units have a DW_AT_name that is a filename, not
21241 a source language identifier. */
21242 case DW_TAG_enumeration_type
:
21243 case DW_TAG_enumerator
:
21244 /* These tags always have simple identifiers already; no need
21245 to canonicalize them. */
21246 return DW_STRING (attr
);
21248 case DW_TAG_namespace
:
21249 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21250 return DW_STRING (attr
);
21251 return CP_ANONYMOUS_NAMESPACE_STR
;
21253 case DW_TAG_class_type
:
21254 case DW_TAG_interface_type
:
21255 case DW_TAG_structure_type
:
21256 case DW_TAG_union_type
:
21257 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21258 structures or unions. These were of the form "._%d" in GCC 4.1,
21259 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21260 and GCC 4.4. We work around this problem by ignoring these. */
21261 if (attr
&& DW_STRING (attr
)
21262 && (startswith (DW_STRING (attr
), "._")
21263 || startswith (DW_STRING (attr
), "<anonymous")))
21266 /* GCC might emit a nameless typedef that has a linkage name. See
21267 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21268 if (!attr
|| DW_STRING (attr
) == NULL
)
21270 attr
= dw2_linkage_name_attr (die
, cu
);
21271 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21274 /* Avoid demangling DW_STRING (attr) the second time on a second
21275 call for the same DIE. */
21276 if (!DW_STRING_IS_CANONICAL (attr
))
21278 gdb::unique_xmalloc_ptr
<char> demangled
21279 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21280 if (demangled
== nullptr)
21283 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21284 DW_STRING_IS_CANONICAL (attr
) = 1;
21287 /* Strip any leading namespaces/classes, keep only the base name.
21288 DW_AT_name for named DIEs does not contain the prefixes. */
21289 const char *base
= strrchr (DW_STRING (attr
), ':');
21290 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21293 return DW_STRING (attr
);
21301 if (!DW_STRING_IS_CANONICAL (attr
))
21303 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21305 DW_STRING_IS_CANONICAL (attr
) = 1;
21307 return DW_STRING (attr
);
21310 /* Return the die that this die in an extension of, or NULL if there
21311 is none. *EXT_CU is the CU containing DIE on input, and the CU
21312 containing the return value on output. */
21314 static struct die_info
*
21315 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21317 struct attribute
*attr
;
21319 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21323 return follow_die_ref (die
, attr
, ext_cu
);
21327 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21331 print_spaces (indent
, f
);
21332 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21333 dwarf_tag_name (die
->tag
), die
->abbrev
,
21334 sect_offset_str (die
->sect_off
));
21336 if (die
->parent
!= NULL
)
21338 print_spaces (indent
, f
);
21339 fprintf_unfiltered (f
, " parent at offset: %s\n",
21340 sect_offset_str (die
->parent
->sect_off
));
21343 print_spaces (indent
, f
);
21344 fprintf_unfiltered (f
, " has children: %s\n",
21345 dwarf_bool_name (die
->child
!= NULL
));
21347 print_spaces (indent
, f
);
21348 fprintf_unfiltered (f
, " attributes:\n");
21350 for (i
= 0; i
< die
->num_attrs
; ++i
)
21352 print_spaces (indent
, f
);
21353 fprintf_unfiltered (f
, " %s (%s) ",
21354 dwarf_attr_name (die
->attrs
[i
].name
),
21355 dwarf_form_name (die
->attrs
[i
].form
));
21357 switch (die
->attrs
[i
].form
)
21360 case DW_FORM_addrx
:
21361 case DW_FORM_GNU_addr_index
:
21362 fprintf_unfiltered (f
, "address: ");
21363 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21365 case DW_FORM_block2
:
21366 case DW_FORM_block4
:
21367 case DW_FORM_block
:
21368 case DW_FORM_block1
:
21369 fprintf_unfiltered (f
, "block: size %s",
21370 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21372 case DW_FORM_exprloc
:
21373 fprintf_unfiltered (f
, "expression: size %s",
21374 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21376 case DW_FORM_data16
:
21377 fprintf_unfiltered (f
, "constant of 16 bytes");
21379 case DW_FORM_ref_addr
:
21380 fprintf_unfiltered (f
, "ref address: ");
21381 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21383 case DW_FORM_GNU_ref_alt
:
21384 fprintf_unfiltered (f
, "alt ref address: ");
21385 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21391 case DW_FORM_ref_udata
:
21392 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21393 (long) (DW_UNSND (&die
->attrs
[i
])));
21395 case DW_FORM_data1
:
21396 case DW_FORM_data2
:
21397 case DW_FORM_data4
:
21398 case DW_FORM_data8
:
21399 case DW_FORM_udata
:
21400 case DW_FORM_sdata
:
21401 fprintf_unfiltered (f
, "constant: %s",
21402 pulongest (DW_UNSND (&die
->attrs
[i
])));
21404 case DW_FORM_sec_offset
:
21405 fprintf_unfiltered (f
, "section offset: %s",
21406 pulongest (DW_UNSND (&die
->attrs
[i
])));
21408 case DW_FORM_ref_sig8
:
21409 fprintf_unfiltered (f
, "signature: %s",
21410 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21412 case DW_FORM_string
:
21414 case DW_FORM_line_strp
:
21416 case DW_FORM_GNU_str_index
:
21417 case DW_FORM_GNU_strp_alt
:
21418 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21419 DW_STRING (&die
->attrs
[i
])
21420 ? DW_STRING (&die
->attrs
[i
]) : "",
21421 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21424 if (DW_UNSND (&die
->attrs
[i
]))
21425 fprintf_unfiltered (f
, "flag: TRUE");
21427 fprintf_unfiltered (f
, "flag: FALSE");
21429 case DW_FORM_flag_present
:
21430 fprintf_unfiltered (f
, "flag: TRUE");
21432 case DW_FORM_indirect
:
21433 /* The reader will have reduced the indirect form to
21434 the "base form" so this form should not occur. */
21435 fprintf_unfiltered (f
,
21436 "unexpected attribute form: DW_FORM_indirect");
21438 case DW_FORM_implicit_const
:
21439 fprintf_unfiltered (f
, "constant: %s",
21440 plongest (DW_SND (&die
->attrs
[i
])));
21443 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21444 die
->attrs
[i
].form
);
21447 fprintf_unfiltered (f
, "\n");
21452 dump_die_for_error (struct die_info
*die
)
21454 dump_die_shallow (gdb_stderr
, 0, die
);
21458 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21460 int indent
= level
* 4;
21462 gdb_assert (die
!= NULL
);
21464 if (level
>= max_level
)
21467 dump_die_shallow (f
, indent
, die
);
21469 if (die
->child
!= NULL
)
21471 print_spaces (indent
, f
);
21472 fprintf_unfiltered (f
, " Children:");
21473 if (level
+ 1 < max_level
)
21475 fprintf_unfiltered (f
, "\n");
21476 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21480 fprintf_unfiltered (f
,
21481 " [not printed, max nesting level reached]\n");
21485 if (die
->sibling
!= NULL
&& level
> 0)
21487 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21491 /* This is called from the pdie macro in gdbinit.in.
21492 It's not static so gcc will keep a copy callable from gdb. */
21495 dump_die (struct die_info
*die
, int max_level
)
21497 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21501 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21505 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21506 to_underlying (die
->sect_off
),
21512 /* Follow reference or signature attribute ATTR of SRC_DIE.
21513 On entry *REF_CU is the CU of SRC_DIE.
21514 On exit *REF_CU is the CU of the result. */
21516 static struct die_info
*
21517 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21518 struct dwarf2_cu
**ref_cu
)
21520 struct die_info
*die
;
21522 if (attr
->form_is_ref ())
21523 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21524 else if (attr
->form
== DW_FORM_ref_sig8
)
21525 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21528 dump_die_for_error (src_die
);
21529 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21530 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21536 /* Follow reference OFFSET.
21537 On entry *REF_CU is the CU of the source die referencing OFFSET.
21538 On exit *REF_CU is the CU of the result.
21539 Returns NULL if OFFSET is invalid. */
21541 static struct die_info
*
21542 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21543 struct dwarf2_cu
**ref_cu
)
21545 struct die_info temp_die
;
21546 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21547 struct dwarf2_per_objfile
*dwarf2_per_objfile
21548 = cu
->per_cu
->dwarf2_per_objfile
;
21550 gdb_assert (cu
->per_cu
!= NULL
);
21554 if (cu
->per_cu
->is_debug_types
)
21556 /* .debug_types CUs cannot reference anything outside their CU.
21557 If they need to, they have to reference a signatured type via
21558 DW_FORM_ref_sig8. */
21559 if (!cu
->header
.offset_in_cu_p (sect_off
))
21562 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21563 || !cu
->header
.offset_in_cu_p (sect_off
))
21565 struct dwarf2_per_cu_data
*per_cu
;
21567 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21568 dwarf2_per_objfile
);
21570 /* If necessary, add it to the queue and load its DIEs. */
21571 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21572 load_full_comp_unit (per_cu
, false, cu
->language
);
21574 target_cu
= per_cu
->cu
;
21576 else if (cu
->dies
== NULL
)
21578 /* We're loading full DIEs during partial symbol reading. */
21579 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21580 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21583 *ref_cu
= target_cu
;
21584 temp_die
.sect_off
= sect_off
;
21586 if (target_cu
!= cu
)
21587 target_cu
->ancestor
= cu
;
21589 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21591 to_underlying (sect_off
));
21594 /* Follow reference attribute ATTR of SRC_DIE.
21595 On entry *REF_CU is the CU of SRC_DIE.
21596 On exit *REF_CU is the CU of the result. */
21598 static struct die_info
*
21599 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21600 struct dwarf2_cu
**ref_cu
)
21602 sect_offset sect_off
= attr
->get_ref_die_offset ();
21603 struct dwarf2_cu
*cu
= *ref_cu
;
21604 struct die_info
*die
;
21606 die
= follow_die_offset (sect_off
,
21607 (attr
->form
== DW_FORM_GNU_ref_alt
21608 || cu
->per_cu
->is_dwz
),
21611 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21612 "at %s [in module %s]"),
21613 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21614 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21621 struct dwarf2_locexpr_baton
21622 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21623 dwarf2_per_cu_data
*per_cu
,
21624 CORE_ADDR (*get_frame_pc
) (void *baton
),
21625 void *baton
, bool resolve_abstract_p
)
21627 struct dwarf2_cu
*cu
;
21628 struct die_info
*die
;
21629 struct attribute
*attr
;
21630 struct dwarf2_locexpr_baton retval
;
21631 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21632 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21634 if (per_cu
->cu
== NULL
)
21635 load_cu (per_cu
, false);
21639 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21640 Instead just throw an error, not much else we can do. */
21641 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21642 sect_offset_str (sect_off
), objfile_name (objfile
));
21645 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21647 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21648 sect_offset_str (sect_off
), objfile_name (objfile
));
21650 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21651 if (!attr
&& resolve_abstract_p
21652 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21653 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21655 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21656 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21659 for (const auto &cand_off
21660 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21662 struct dwarf2_cu
*cand_cu
= cu
;
21663 struct die_info
*cand
21664 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21667 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21670 CORE_ADDR pc_low
, pc_high
;
21671 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21672 if (pc_low
== ((CORE_ADDR
) -1))
21674 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21675 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21676 if (!(pc_low
<= pc
&& pc
< pc_high
))
21680 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21687 /* DWARF: "If there is no such attribute, then there is no effect.".
21688 DATA is ignored if SIZE is 0. */
21690 retval
.data
= NULL
;
21693 else if (attr
->form_is_section_offset ())
21695 struct dwarf2_loclist_baton loclist_baton
;
21696 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21699 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21701 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21703 retval
.size
= size
;
21707 if (!attr
->form_is_block ())
21708 error (_("Dwarf Error: DIE at %s referenced in module %s "
21709 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21710 sect_offset_str (sect_off
), objfile_name (objfile
));
21712 retval
.data
= DW_BLOCK (attr
)->data
;
21713 retval
.size
= DW_BLOCK (attr
)->size
;
21715 retval
.per_cu
= cu
->per_cu
;
21717 age_cached_comp_units (dwarf2_per_objfile
);
21724 struct dwarf2_locexpr_baton
21725 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21726 dwarf2_per_cu_data
*per_cu
,
21727 CORE_ADDR (*get_frame_pc
) (void *baton
),
21730 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21732 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21735 /* Write a constant of a given type as target-ordered bytes into
21738 static const gdb_byte
*
21739 write_constant_as_bytes (struct obstack
*obstack
,
21740 enum bfd_endian byte_order
,
21747 *len
= TYPE_LENGTH (type
);
21748 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21749 store_unsigned_integer (result
, *len
, byte_order
, value
);
21757 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21758 dwarf2_per_cu_data
*per_cu
,
21762 struct dwarf2_cu
*cu
;
21763 struct die_info
*die
;
21764 struct attribute
*attr
;
21765 const gdb_byte
*result
= NULL
;
21768 enum bfd_endian byte_order
;
21769 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21771 if (per_cu
->cu
== NULL
)
21772 load_cu (per_cu
, false);
21776 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21777 Instead just throw an error, not much else we can do. */
21778 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21779 sect_offset_str (sect_off
), objfile_name (objfile
));
21782 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21784 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21785 sect_offset_str (sect_off
), objfile_name (objfile
));
21787 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21791 byte_order
= (bfd_big_endian (objfile
->obfd
)
21792 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21794 switch (attr
->form
)
21797 case DW_FORM_addrx
:
21798 case DW_FORM_GNU_addr_index
:
21802 *len
= cu
->header
.addr_size
;
21803 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21804 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21808 case DW_FORM_string
:
21811 case DW_FORM_GNU_str_index
:
21812 case DW_FORM_GNU_strp_alt
:
21813 /* DW_STRING is already allocated on the objfile obstack, point
21815 result
= (const gdb_byte
*) DW_STRING (attr
);
21816 *len
= strlen (DW_STRING (attr
));
21818 case DW_FORM_block1
:
21819 case DW_FORM_block2
:
21820 case DW_FORM_block4
:
21821 case DW_FORM_block
:
21822 case DW_FORM_exprloc
:
21823 case DW_FORM_data16
:
21824 result
= DW_BLOCK (attr
)->data
;
21825 *len
= DW_BLOCK (attr
)->size
;
21828 /* The DW_AT_const_value attributes are supposed to carry the
21829 symbol's value "represented as it would be on the target
21830 architecture." By the time we get here, it's already been
21831 converted to host endianness, so we just need to sign- or
21832 zero-extend it as appropriate. */
21833 case DW_FORM_data1
:
21834 type
= die_type (die
, cu
);
21835 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21836 if (result
== NULL
)
21837 result
= write_constant_as_bytes (obstack
, byte_order
,
21840 case DW_FORM_data2
:
21841 type
= die_type (die
, cu
);
21842 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21843 if (result
== NULL
)
21844 result
= write_constant_as_bytes (obstack
, byte_order
,
21847 case DW_FORM_data4
:
21848 type
= die_type (die
, cu
);
21849 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21850 if (result
== NULL
)
21851 result
= write_constant_as_bytes (obstack
, byte_order
,
21854 case DW_FORM_data8
:
21855 type
= die_type (die
, cu
);
21856 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21857 if (result
== NULL
)
21858 result
= write_constant_as_bytes (obstack
, byte_order
,
21862 case DW_FORM_sdata
:
21863 case DW_FORM_implicit_const
:
21864 type
= die_type (die
, cu
);
21865 result
= write_constant_as_bytes (obstack
, byte_order
,
21866 type
, DW_SND (attr
), len
);
21869 case DW_FORM_udata
:
21870 type
= die_type (die
, cu
);
21871 result
= write_constant_as_bytes (obstack
, byte_order
,
21872 type
, DW_UNSND (attr
), len
);
21876 complaint (_("unsupported const value attribute form: '%s'"),
21877 dwarf_form_name (attr
->form
));
21887 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21888 dwarf2_per_cu_data
*per_cu
)
21890 struct dwarf2_cu
*cu
;
21891 struct die_info
*die
;
21893 if (per_cu
->cu
== NULL
)
21894 load_cu (per_cu
, false);
21899 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21903 return die_type (die
, cu
);
21909 dwarf2_get_die_type (cu_offset die_offset
,
21910 struct dwarf2_per_cu_data
*per_cu
)
21912 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21913 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21916 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21917 On entry *REF_CU is the CU of SRC_DIE.
21918 On exit *REF_CU is the CU of the result.
21919 Returns NULL if the referenced DIE isn't found. */
21921 static struct die_info
*
21922 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21923 struct dwarf2_cu
**ref_cu
)
21925 struct die_info temp_die
;
21926 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
21927 struct die_info
*die
;
21929 /* While it might be nice to assert sig_type->type == NULL here,
21930 we can get here for DW_AT_imported_declaration where we need
21931 the DIE not the type. */
21933 /* If necessary, add it to the queue and load its DIEs. */
21935 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
21936 read_signatured_type (sig_type
);
21938 sig_cu
= sig_type
->per_cu
.cu
;
21939 gdb_assert (sig_cu
!= NULL
);
21940 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
21941 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
21942 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
21943 to_underlying (temp_die
.sect_off
));
21946 struct dwarf2_per_objfile
*dwarf2_per_objfile
21947 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
21949 /* For .gdb_index version 7 keep track of included TUs.
21950 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
21951 if (dwarf2_per_objfile
->index_table
!= NULL
21952 && dwarf2_per_objfile
->index_table
->version
<= 7)
21954 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
21959 sig_cu
->ancestor
= cu
;
21967 /* Follow signatured type referenced by ATTR in SRC_DIE.
21968 On entry *REF_CU is the CU of SRC_DIE.
21969 On exit *REF_CU is the CU of the result.
21970 The result is the DIE of the type.
21971 If the referenced type cannot be found an error is thrown. */
21973 static struct die_info
*
21974 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21975 struct dwarf2_cu
**ref_cu
)
21977 ULONGEST signature
= DW_SIGNATURE (attr
);
21978 struct signatured_type
*sig_type
;
21979 struct die_info
*die
;
21981 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
21983 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
21984 /* sig_type will be NULL if the signatured type is missing from
21986 if (sig_type
== NULL
)
21988 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
21989 " from DIE at %s [in module %s]"),
21990 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
21991 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21994 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
21997 dump_die_for_error (src_die
);
21998 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21999 " from DIE at %s [in module %s]"),
22000 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
22001 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22007 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22008 reading in and processing the type unit if necessary. */
22010 static struct type
*
22011 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22012 struct dwarf2_cu
*cu
)
22014 struct dwarf2_per_objfile
*dwarf2_per_objfile
22015 = cu
->per_cu
->dwarf2_per_objfile
;
22016 struct signatured_type
*sig_type
;
22017 struct dwarf2_cu
*type_cu
;
22018 struct die_info
*type_die
;
22021 sig_type
= lookup_signatured_type (cu
, signature
);
22022 /* sig_type will be NULL if the signatured type is missing from
22024 if (sig_type
== NULL
)
22026 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22027 " from DIE at %s [in module %s]"),
22028 hex_string (signature
), sect_offset_str (die
->sect_off
),
22029 objfile_name (dwarf2_per_objfile
->objfile
));
22030 return build_error_marker_type (cu
, die
);
22033 /* If we already know the type we're done. */
22034 if (sig_type
->type
!= NULL
)
22035 return sig_type
->type
;
22038 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22039 if (type_die
!= NULL
)
22041 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22042 is created. This is important, for example, because for c++ classes
22043 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22044 type
= read_type_die (type_die
, type_cu
);
22047 complaint (_("Dwarf Error: Cannot build signatured type %s"
22048 " referenced from DIE at %s [in module %s]"),
22049 hex_string (signature
), sect_offset_str (die
->sect_off
),
22050 objfile_name (dwarf2_per_objfile
->objfile
));
22051 type
= build_error_marker_type (cu
, die
);
22056 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22057 " from DIE at %s [in module %s]"),
22058 hex_string (signature
), sect_offset_str (die
->sect_off
),
22059 objfile_name (dwarf2_per_objfile
->objfile
));
22060 type
= build_error_marker_type (cu
, die
);
22062 sig_type
->type
= type
;
22067 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22068 reading in and processing the type unit if necessary. */
22070 static struct type
*
22071 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22072 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22074 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22075 if (attr
->form_is_ref ())
22077 struct dwarf2_cu
*type_cu
= cu
;
22078 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22080 return read_type_die (type_die
, type_cu
);
22082 else if (attr
->form
== DW_FORM_ref_sig8
)
22084 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22088 struct dwarf2_per_objfile
*dwarf2_per_objfile
22089 = cu
->per_cu
->dwarf2_per_objfile
;
22091 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22092 " at %s [in module %s]"),
22093 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22094 objfile_name (dwarf2_per_objfile
->objfile
));
22095 return build_error_marker_type (cu
, die
);
22099 /* Load the DIEs associated with type unit PER_CU into memory. */
22102 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22104 struct signatured_type
*sig_type
;
22106 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22107 gdb_assert (! per_cu
->type_unit_group_p ());
22109 /* We have the per_cu, but we need the signatured_type.
22110 Fortunately this is an easy translation. */
22111 gdb_assert (per_cu
->is_debug_types
);
22112 sig_type
= (struct signatured_type
*) per_cu
;
22114 gdb_assert (per_cu
->cu
== NULL
);
22116 read_signatured_type (sig_type
);
22118 gdb_assert (per_cu
->cu
!= NULL
);
22121 /* Read in a signatured type and build its CU and DIEs.
22122 If the type is a stub for the real type in a DWO file,
22123 read in the real type from the DWO file as well. */
22126 read_signatured_type (struct signatured_type
*sig_type
)
22128 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22130 gdb_assert (per_cu
->is_debug_types
);
22131 gdb_assert (per_cu
->cu
== NULL
);
22133 cutu_reader
reader (per_cu
, NULL
, 0, false);
22135 if (!reader
.dummy_p
)
22137 struct dwarf2_cu
*cu
= reader
.cu
;
22138 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22140 gdb_assert (cu
->die_hash
== NULL
);
22142 htab_create_alloc_ex (cu
->header
.length
/ 12,
22146 &cu
->comp_unit_obstack
,
22147 hashtab_obstack_allocate
,
22148 dummy_obstack_deallocate
);
22150 if (reader
.comp_unit_die
->has_children
)
22151 reader
.comp_unit_die
->child
22152 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22153 reader
.comp_unit_die
);
22154 cu
->dies
= reader
.comp_unit_die
;
22155 /* comp_unit_die is not stored in die_hash, no need. */
22157 /* We try not to read any attributes in this function, because
22158 not all CUs needed for references have been loaded yet, and
22159 symbol table processing isn't initialized. But we have to
22160 set the CU language, or we won't be able to build types
22161 correctly. Similarly, if we do not read the producer, we can
22162 not apply producer-specific interpretation. */
22163 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22168 sig_type
->per_cu
.tu_read
= 1;
22171 /* Decode simple location descriptions.
22172 Given a pointer to a dwarf block that defines a location, compute
22173 the location and return the value.
22175 NOTE drow/2003-11-18: This function is called in two situations
22176 now: for the address of static or global variables (partial symbols
22177 only) and for offsets into structures which are expected to be
22178 (more or less) constant. The partial symbol case should go away,
22179 and only the constant case should remain. That will let this
22180 function complain more accurately. A few special modes are allowed
22181 without complaint for global variables (for instance, global
22182 register values and thread-local values).
22184 A location description containing no operations indicates that the
22185 object is optimized out. The return value is 0 for that case.
22186 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22187 callers will only want a very basic result and this can become a
22190 Note that stack[0] is unused except as a default error return. */
22193 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22195 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22197 size_t size
= blk
->size
;
22198 const gdb_byte
*data
= blk
->data
;
22199 CORE_ADDR stack
[64];
22201 unsigned int bytes_read
, unsnd
;
22207 stack
[++stacki
] = 0;
22246 stack
[++stacki
] = op
- DW_OP_lit0
;
22281 stack
[++stacki
] = op
- DW_OP_reg0
;
22283 dwarf2_complex_location_expr_complaint ();
22287 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22289 stack
[++stacki
] = unsnd
;
22291 dwarf2_complex_location_expr_complaint ();
22295 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22300 case DW_OP_const1u
:
22301 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22305 case DW_OP_const1s
:
22306 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22310 case DW_OP_const2u
:
22311 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22315 case DW_OP_const2s
:
22316 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22320 case DW_OP_const4u
:
22321 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22325 case DW_OP_const4s
:
22326 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22330 case DW_OP_const8u
:
22331 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22336 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22342 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22347 stack
[stacki
+ 1] = stack
[stacki
];
22352 stack
[stacki
- 1] += stack
[stacki
];
22356 case DW_OP_plus_uconst
:
22357 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22363 stack
[stacki
- 1] -= stack
[stacki
];
22368 /* If we're not the last op, then we definitely can't encode
22369 this using GDB's address_class enum. This is valid for partial
22370 global symbols, although the variable's address will be bogus
22373 dwarf2_complex_location_expr_complaint ();
22376 case DW_OP_GNU_push_tls_address
:
22377 case DW_OP_form_tls_address
:
22378 /* The top of the stack has the offset from the beginning
22379 of the thread control block at which the variable is located. */
22380 /* Nothing should follow this operator, so the top of stack would
22382 /* This is valid for partial global symbols, but the variable's
22383 address will be bogus in the psymtab. Make it always at least
22384 non-zero to not look as a variable garbage collected by linker
22385 which have DW_OP_addr 0. */
22387 dwarf2_complex_location_expr_complaint ();
22391 case DW_OP_GNU_uninit
:
22395 case DW_OP_GNU_addr_index
:
22396 case DW_OP_GNU_const_index
:
22397 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22404 const char *name
= get_DW_OP_name (op
);
22407 complaint (_("unsupported stack op: '%s'"),
22410 complaint (_("unsupported stack op: '%02x'"),
22414 return (stack
[stacki
]);
22417 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22418 outside of the allocated space. Also enforce minimum>0. */
22419 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22421 complaint (_("location description stack overflow"));
22427 complaint (_("location description stack underflow"));
22431 return (stack
[stacki
]);
22434 /* memory allocation interface */
22436 static struct dwarf_block
*
22437 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22439 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22442 static struct die_info
*
22443 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22445 struct die_info
*die
;
22446 size_t size
= sizeof (struct die_info
);
22449 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22451 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22452 memset (die
, 0, sizeof (struct die_info
));
22458 /* Macro support. */
22460 /* An overload of dwarf_decode_macros that finds the correct section
22461 and ensures it is read in before calling the other overload. */
22464 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22465 int section_is_gnu
)
22467 struct dwarf2_per_objfile
*dwarf2_per_objfile
22468 = cu
->per_cu
->dwarf2_per_objfile
;
22469 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22470 const struct line_header
*lh
= cu
->line_header
;
22471 unsigned int offset_size
= cu
->header
.offset_size
;
22472 struct dwarf2_section_info
*section
;
22473 const char *section_name
;
22475 if (cu
->dwo_unit
!= nullptr)
22477 if (section_is_gnu
)
22479 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22480 section_name
= ".debug_macro.dwo";
22484 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22485 section_name
= ".debug_macinfo.dwo";
22490 if (section_is_gnu
)
22492 section
= &dwarf2_per_objfile
->macro
;
22493 section_name
= ".debug_macro";
22497 section
= &dwarf2_per_objfile
->macinfo
;
22498 section_name
= ".debug_macinfo";
22502 section
->read (objfile
);
22503 if (section
->buffer
== nullptr)
22505 complaint (_("missing %s section"), section_name
);
22509 buildsym_compunit
*builder
= cu
->get_builder ();
22511 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22512 offset_size
, offset
, section_is_gnu
);
22515 /* Return the .debug_loc section to use for CU.
22516 For DWO files use .debug_loc.dwo. */
22518 static struct dwarf2_section_info
*
22519 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22521 struct dwarf2_per_objfile
*dwarf2_per_objfile
22522 = cu
->per_cu
->dwarf2_per_objfile
;
22526 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22528 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22530 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22531 : &dwarf2_per_objfile
->loc
);
22534 /* A helper function that fills in a dwarf2_loclist_baton. */
22537 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22538 struct dwarf2_loclist_baton
*baton
,
22539 const struct attribute
*attr
)
22541 struct dwarf2_per_objfile
*dwarf2_per_objfile
22542 = cu
->per_cu
->dwarf2_per_objfile
;
22543 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22545 section
->read (dwarf2_per_objfile
->objfile
);
22547 baton
->per_cu
= cu
->per_cu
;
22548 gdb_assert (baton
->per_cu
);
22549 /* We don't know how long the location list is, but make sure we
22550 don't run off the edge of the section. */
22551 baton
->size
= section
->size
- DW_UNSND (attr
);
22552 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22553 if (cu
->base_address
.has_value ())
22554 baton
->base_address
= *cu
->base_address
;
22556 baton
->base_address
= 0;
22557 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22561 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22562 struct dwarf2_cu
*cu
, int is_block
)
22564 struct dwarf2_per_objfile
*dwarf2_per_objfile
22565 = cu
->per_cu
->dwarf2_per_objfile
;
22566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22567 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22569 if (attr
->form_is_section_offset ()
22570 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22571 the section. If so, fall through to the complaint in the
22573 && DW_UNSND (attr
) < section
->get_size (objfile
))
22575 struct dwarf2_loclist_baton
*baton
;
22577 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22579 fill_in_loclist_baton (cu
, baton
, attr
);
22581 if (!cu
->base_address
.has_value ())
22582 complaint (_("Location list used without "
22583 "specifying the CU base address."));
22585 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22586 ? dwarf2_loclist_block_index
22587 : dwarf2_loclist_index
);
22588 SYMBOL_LOCATION_BATON (sym
) = baton
;
22592 struct dwarf2_locexpr_baton
*baton
;
22594 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22595 baton
->per_cu
= cu
->per_cu
;
22596 gdb_assert (baton
->per_cu
);
22598 if (attr
->form_is_block ())
22600 /* Note that we're just copying the block's data pointer
22601 here, not the actual data. We're still pointing into the
22602 info_buffer for SYM's objfile; right now we never release
22603 that buffer, but when we do clean up properly this may
22605 baton
->size
= DW_BLOCK (attr
)->size
;
22606 baton
->data
= DW_BLOCK (attr
)->data
;
22610 dwarf2_invalid_attrib_class_complaint ("location description",
22611 sym
->natural_name ());
22615 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22616 ? dwarf2_locexpr_block_index
22617 : dwarf2_locexpr_index
);
22618 SYMBOL_LOCATION_BATON (sym
) = baton
;
22625 dwarf2_per_cu_data::objfile () const
22627 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22629 /* Return the master objfile, so that we can report and look up the
22630 correct file containing this variable. */
22631 if (objfile
->separate_debug_objfile_backlink
)
22632 objfile
= objfile
->separate_debug_objfile_backlink
;
22637 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22638 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22639 CU_HEADERP first. */
22641 static const struct comp_unit_head
*
22642 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22643 const struct dwarf2_per_cu_data
*per_cu
)
22645 const gdb_byte
*info_ptr
;
22648 return &per_cu
->cu
->header
;
22650 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22652 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22653 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22654 rcuh_kind::COMPILE
);
22662 dwarf2_per_cu_data::addr_size () const
22664 struct comp_unit_head cu_header_local
;
22665 const struct comp_unit_head
*cu_headerp
;
22667 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22669 return cu_headerp
->addr_size
;
22675 dwarf2_per_cu_data::offset_size () const
22677 struct comp_unit_head cu_header_local
;
22678 const struct comp_unit_head
*cu_headerp
;
22680 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22682 return cu_headerp
->offset_size
;
22688 dwarf2_per_cu_data::ref_addr_size () const
22690 struct comp_unit_head cu_header_local
;
22691 const struct comp_unit_head
*cu_headerp
;
22693 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22695 if (cu_headerp
->version
== 2)
22696 return cu_headerp
->addr_size
;
22698 return cu_headerp
->offset_size
;
22704 dwarf2_per_cu_data::text_offset () const
22706 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22708 return objfile
->text_section_offset ();
22714 dwarf2_per_cu_data::addr_type () const
22716 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22717 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22718 struct type
*addr_type
= lookup_pointer_type (void_type
);
22719 int addr_size
= this->addr_size ();
22721 if (TYPE_LENGTH (addr_type
) == addr_size
)
22724 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22728 /* A helper function for dwarf2_find_containing_comp_unit that returns
22729 the index of the result, and that searches a vector. It will
22730 return a result even if the offset in question does not actually
22731 occur in any CU. This is separate so that it can be unit
22735 dwarf2_find_containing_comp_unit
22736 (sect_offset sect_off
,
22737 unsigned int offset_in_dwz
,
22738 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22743 high
= all_comp_units
.size () - 1;
22746 struct dwarf2_per_cu_data
*mid_cu
;
22747 int mid
= low
+ (high
- low
) / 2;
22749 mid_cu
= all_comp_units
[mid
];
22750 if (mid_cu
->is_dwz
> offset_in_dwz
22751 || (mid_cu
->is_dwz
== offset_in_dwz
22752 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22757 gdb_assert (low
== high
);
22761 /* Locate the .debug_info compilation unit from CU's objfile which contains
22762 the DIE at OFFSET. Raises an error on failure. */
22764 static struct dwarf2_per_cu_data
*
22765 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22766 unsigned int offset_in_dwz
,
22767 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22770 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22771 dwarf2_per_objfile
->all_comp_units
);
22772 struct dwarf2_per_cu_data
*this_cu
22773 = dwarf2_per_objfile
->all_comp_units
[low
];
22775 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22777 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22778 error (_("Dwarf Error: could not find partial DIE containing "
22779 "offset %s [in module %s]"),
22780 sect_offset_str (sect_off
),
22781 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22783 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22785 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22789 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22790 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22791 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22792 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22799 namespace selftests
{
22800 namespace find_containing_comp_unit
{
22805 struct dwarf2_per_cu_data one
{};
22806 struct dwarf2_per_cu_data two
{};
22807 struct dwarf2_per_cu_data three
{};
22808 struct dwarf2_per_cu_data four
{};
22811 two
.sect_off
= sect_offset (one
.length
);
22816 four
.sect_off
= sect_offset (three
.length
);
22820 std::vector
<dwarf2_per_cu_data
*> units
;
22821 units
.push_back (&one
);
22822 units
.push_back (&two
);
22823 units
.push_back (&three
);
22824 units
.push_back (&four
);
22828 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22829 SELF_CHECK (units
[result
] == &one
);
22830 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
22831 SELF_CHECK (units
[result
] == &one
);
22832 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
22833 SELF_CHECK (units
[result
] == &two
);
22835 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
22836 SELF_CHECK (units
[result
] == &three
);
22837 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
22838 SELF_CHECK (units
[result
] == &three
);
22839 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
22840 SELF_CHECK (units
[result
] == &four
);
22846 #endif /* GDB_SELF_TEST */
22848 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22850 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
22851 : per_cu (per_cu_
),
22853 has_loclist (false),
22854 checked_producer (false),
22855 producer_is_gxx_lt_4_6 (false),
22856 producer_is_gcc_lt_4_3 (false),
22857 producer_is_icc (false),
22858 producer_is_icc_lt_14 (false),
22859 producer_is_codewarrior (false),
22860 processing_has_namespace_info (false)
22865 /* Destroy a dwarf2_cu. */
22867 dwarf2_cu::~dwarf2_cu ()
22872 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22875 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22876 enum language pretend_language
)
22878 struct attribute
*attr
;
22880 /* Set the language we're debugging. */
22881 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22882 if (attr
!= nullptr)
22883 set_cu_language (DW_UNSND (attr
), cu
);
22886 cu
->language
= pretend_language
;
22887 cu
->language_defn
= language_def (cu
->language
);
22890 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22893 /* Increase the age counter on each cached compilation unit, and free
22894 any that are too old. */
22897 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22899 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22901 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22902 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22903 while (per_cu
!= NULL
)
22905 per_cu
->cu
->last_used
++;
22906 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22907 dwarf2_mark (per_cu
->cu
);
22908 per_cu
= per_cu
->cu
->read_in_chain
;
22911 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22912 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22913 while (per_cu
!= NULL
)
22915 struct dwarf2_per_cu_data
*next_cu
;
22917 next_cu
= per_cu
->cu
->read_in_chain
;
22919 if (!per_cu
->cu
->mark
)
22922 *last_chain
= next_cu
;
22925 last_chain
= &per_cu
->cu
->read_in_chain
;
22931 /* Remove a single compilation unit from the cache. */
22934 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22936 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22937 struct dwarf2_per_objfile
*dwarf2_per_objfile
22938 = target_per_cu
->dwarf2_per_objfile
;
22940 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22941 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22942 while (per_cu
!= NULL
)
22944 struct dwarf2_per_cu_data
*next_cu
;
22946 next_cu
= per_cu
->cu
->read_in_chain
;
22948 if (per_cu
== target_per_cu
)
22952 *last_chain
= next_cu
;
22956 last_chain
= &per_cu
->cu
->read_in_chain
;
22962 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22963 We store these in a hash table separate from the DIEs, and preserve them
22964 when the DIEs are flushed out of cache.
22966 The CU "per_cu" pointer is needed because offset alone is not enough to
22967 uniquely identify the type. A file may have multiple .debug_types sections,
22968 or the type may come from a DWO file. Furthermore, while it's more logical
22969 to use per_cu->section+offset, with Fission the section with the data is in
22970 the DWO file but we don't know that section at the point we need it.
22971 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22972 because we can enter the lookup routine, get_die_type_at_offset, from
22973 outside this file, and thus won't necessarily have PER_CU->cu.
22974 Fortunately, PER_CU is stable for the life of the objfile. */
22976 struct dwarf2_per_cu_offset_and_type
22978 const struct dwarf2_per_cu_data
*per_cu
;
22979 sect_offset sect_off
;
22983 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22986 per_cu_offset_and_type_hash (const void *item
)
22988 const struct dwarf2_per_cu_offset_and_type
*ofs
22989 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22991 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
22994 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22997 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22999 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
23000 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
23001 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23002 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23004 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23005 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23008 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23009 table if necessary. For convenience, return TYPE.
23011 The DIEs reading must have careful ordering to:
23012 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23013 reading current DIE.
23014 * Not trying to dereference contents of still incompletely read in types
23015 while reading in other DIEs.
23016 * Enable referencing still incompletely read in types just by a pointer to
23017 the type without accessing its fields.
23019 Therefore caller should follow these rules:
23020 * Try to fetch any prerequisite types we may need to build this DIE type
23021 before building the type and calling set_die_type.
23022 * After building type call set_die_type for current DIE as soon as
23023 possible before fetching more types to complete the current type.
23024 * Make the type as complete as possible before fetching more types. */
23026 static struct type
*
23027 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23029 struct dwarf2_per_objfile
*dwarf2_per_objfile
23030 = cu
->per_cu
->dwarf2_per_objfile
;
23031 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23033 struct attribute
*attr
;
23034 struct dynamic_prop prop
;
23036 /* For Ada types, make sure that the gnat-specific data is always
23037 initialized (if not already set). There are a few types where
23038 we should not be doing so, because the type-specific area is
23039 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23040 where the type-specific area is used to store the floatformat).
23041 But this is not a problem, because the gnat-specific information
23042 is actually not needed for these types. */
23043 if (need_gnat_info (cu
)
23044 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23045 && TYPE_CODE (type
) != TYPE_CODE_FLT
23046 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23047 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23048 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23049 && !HAVE_GNAT_AUX_INFO (type
))
23050 INIT_GNAT_SPECIFIC (type
);
23052 /* Read DW_AT_allocated and set in type. */
23053 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23054 if (attr
!= NULL
&& attr
->form_is_block ())
23056 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23057 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23058 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23060 else if (attr
!= NULL
)
23062 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23063 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23064 sect_offset_str (die
->sect_off
));
23067 /* Read DW_AT_associated and set in type. */
23068 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23069 if (attr
!= NULL
&& attr
->form_is_block ())
23071 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23072 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23073 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23075 else if (attr
!= NULL
)
23077 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23078 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23079 sect_offset_str (die
->sect_off
));
23082 /* Read DW_AT_data_location and set in type. */
23083 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23084 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23085 cu
->per_cu
->addr_type ()))
23086 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23088 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23089 dwarf2_per_objfile
->die_type_hash
23090 = htab_up (htab_create_alloc (127,
23091 per_cu_offset_and_type_hash
,
23092 per_cu_offset_and_type_eq
,
23093 NULL
, xcalloc
, xfree
));
23095 ofs
.per_cu
= cu
->per_cu
;
23096 ofs
.sect_off
= die
->sect_off
;
23098 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23099 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23101 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23102 sect_offset_str (die
->sect_off
));
23103 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23104 struct dwarf2_per_cu_offset_and_type
);
23109 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23110 or return NULL if the die does not have a saved type. */
23112 static struct type
*
23113 get_die_type_at_offset (sect_offset sect_off
,
23114 struct dwarf2_per_cu_data
*per_cu
)
23116 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23117 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23119 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23122 ofs
.per_cu
= per_cu
;
23123 ofs
.sect_off
= sect_off
;
23124 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23125 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23132 /* Look up the type for DIE in CU in die_type_hash,
23133 or return NULL if DIE does not have a saved type. */
23135 static struct type
*
23136 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23138 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23141 /* Add a dependence relationship from CU to REF_PER_CU. */
23144 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23145 struct dwarf2_per_cu_data
*ref_per_cu
)
23149 if (cu
->dependencies
== NULL
)
23151 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23152 NULL
, &cu
->comp_unit_obstack
,
23153 hashtab_obstack_allocate
,
23154 dummy_obstack_deallocate
);
23156 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23158 *slot
= ref_per_cu
;
23161 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23162 Set the mark field in every compilation unit in the
23163 cache that we must keep because we are keeping CU. */
23166 dwarf2_mark_helper (void **slot
, void *data
)
23168 struct dwarf2_per_cu_data
*per_cu
;
23170 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23172 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23173 reading of the chain. As such dependencies remain valid it is not much
23174 useful to track and undo them during QUIT cleanups. */
23175 if (per_cu
->cu
== NULL
)
23178 if (per_cu
->cu
->mark
)
23180 per_cu
->cu
->mark
= true;
23182 if (per_cu
->cu
->dependencies
!= NULL
)
23183 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23188 /* Set the mark field in CU and in every other compilation unit in the
23189 cache that we must keep because we are keeping CU. */
23192 dwarf2_mark (struct dwarf2_cu
*cu
)
23197 if (cu
->dependencies
!= NULL
)
23198 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23202 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23206 per_cu
->cu
->mark
= false;
23207 per_cu
= per_cu
->cu
->read_in_chain
;
23211 /* Trivial hash function for partial_die_info: the hash value of a DIE
23212 is its offset in .debug_info for this objfile. */
23215 partial_die_hash (const void *item
)
23217 const struct partial_die_info
*part_die
23218 = (const struct partial_die_info
*) item
;
23220 return to_underlying (part_die
->sect_off
);
23223 /* Trivial comparison function for partial_die_info structures: two DIEs
23224 are equal if they have the same offset. */
23227 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23229 const struct partial_die_info
*part_die_lhs
23230 = (const struct partial_die_info
*) item_lhs
;
23231 const struct partial_die_info
*part_die_rhs
23232 = (const struct partial_die_info
*) item_rhs
;
23234 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23237 struct cmd_list_element
*set_dwarf_cmdlist
;
23238 struct cmd_list_element
*show_dwarf_cmdlist
;
23241 set_dwarf_cmd (const char *args
, int from_tty
)
23243 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23248 show_dwarf_cmd (const char *args
, int from_tty
)
23250 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23254 show_check_physname (struct ui_file
*file
, int from_tty
,
23255 struct cmd_list_element
*c
, const char *value
)
23257 fprintf_filtered (file
,
23258 _("Whether to check \"physname\" is %s.\n"),
23262 void _initialize_dwarf2_read ();
23264 _initialize_dwarf2_read ()
23266 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23267 Set DWARF specific variables.\n\
23268 Configure DWARF variables such as the cache size."),
23269 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23270 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23272 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23273 Show DWARF specific variables.\n\
23274 Show DWARF variables such as the cache size."),
23275 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23276 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23278 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23279 &dwarf_max_cache_age
, _("\
23280 Set the upper bound on the age of cached DWARF compilation units."), _("\
23281 Show the upper bound on the age of cached DWARF compilation units."), _("\
23282 A higher limit means that cached compilation units will be stored\n\
23283 in memory longer, and more total memory will be used. Zero disables\n\
23284 caching, which can slow down startup."),
23286 show_dwarf_max_cache_age
,
23287 &set_dwarf_cmdlist
,
23288 &show_dwarf_cmdlist
);
23290 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23291 Set debugging of the DWARF reader."), _("\
23292 Show debugging of the DWARF reader."), _("\
23293 When enabled (non-zero), debugging messages are printed during DWARF\n\
23294 reading and symtab expansion. A value of 1 (one) provides basic\n\
23295 information. A value greater than 1 provides more verbose information."),
23298 &setdebuglist
, &showdebuglist
);
23300 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23301 Set debugging of the DWARF DIE reader."), _("\
23302 Show debugging of the DWARF DIE reader."), _("\
23303 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23304 The value is the maximum depth to print."),
23307 &setdebuglist
, &showdebuglist
);
23309 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23310 Set debugging of the dwarf line reader."), _("\
23311 Show debugging of the dwarf line reader."), _("\
23312 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23313 A value of 1 (one) provides basic information.\n\
23314 A value greater than 1 provides more verbose information."),
23317 &setdebuglist
, &showdebuglist
);
23319 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23320 Set cross-checking of \"physname\" code against demangler."), _("\
23321 Show cross-checking of \"physname\" code against demangler."), _("\
23322 When enabled, GDB's internal \"physname\" code is checked against\n\
23324 NULL
, show_check_physname
,
23325 &setdebuglist
, &showdebuglist
);
23327 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23328 no_class
, &use_deprecated_index_sections
, _("\
23329 Set whether to use deprecated gdb_index sections."), _("\
23330 Show whether to use deprecated gdb_index sections."), _("\
23331 When enabled, deprecated .gdb_index sections are used anyway.\n\
23332 Normally they are ignored either because of a missing feature or\n\
23333 performance issue.\n\
23334 Warning: This option must be enabled before gdb reads the file."),
23337 &setlist
, &showlist
);
23339 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23340 &dwarf2_locexpr_funcs
);
23341 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23342 &dwarf2_loclist_funcs
);
23344 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23345 &dwarf2_block_frame_base_locexpr_funcs
);
23346 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23347 &dwarf2_block_frame_base_loclist_funcs
);
23350 selftests::register_test ("dw2_expand_symtabs_matching",
23351 selftests::dw2_expand_symtabs_matching::run_test
);
23352 selftests::register_test ("dwarf2_find_containing_comp_unit",
23353 selftests::find_containing_comp_unit::run_test
);