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
).c_str ();
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
,
4713 dw2_expand_symtabs_for_function
,
4714 dw2_expand_all_symtabs
,
4715 dw2_expand_symtabs_with_fullname
,
4716 dw2_map_matching_symbols
,
4717 dw2_expand_symtabs_matching
,
4718 dw2_find_pc_sect_compunit_symtab
,
4720 dw2_map_symbol_filenames
4723 /* DWARF-5 debug_names reader. */
4725 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
4726 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
4728 /* A helper function that reads the .debug_names section in SECTION
4729 and fills in MAP. FILENAME is the name of the file containing the
4730 section; it is used for error reporting.
4732 Returns true if all went well, false otherwise. */
4735 read_debug_names_from_section (struct objfile
*objfile
,
4736 const char *filename
,
4737 struct dwarf2_section_info
*section
,
4738 mapped_debug_names
&map
)
4740 if (section
->empty ())
4743 /* Older elfutils strip versions could keep the section in the main
4744 executable while splitting it for the separate debug info file. */
4745 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
4748 section
->read (objfile
);
4750 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
4752 const gdb_byte
*addr
= section
->buffer
;
4754 bfd
*const abfd
= section
->get_bfd_owner ();
4756 unsigned int bytes_read
;
4757 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
4760 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
4761 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
4762 if (bytes_read
+ length
!= section
->size
)
4764 /* There may be multiple per-CU indices. */
4765 warning (_("Section .debug_names in %s length %s does not match "
4766 "section length %s, ignoring .debug_names."),
4767 filename
, plongest (bytes_read
+ length
),
4768 pulongest (section
->size
));
4772 /* The version number. */
4773 uint16_t version
= read_2_bytes (abfd
, addr
);
4777 warning (_("Section .debug_names in %s has unsupported version %d, "
4778 "ignoring .debug_names."),
4784 uint16_t padding
= read_2_bytes (abfd
, addr
);
4788 warning (_("Section .debug_names in %s has unsupported padding %d, "
4789 "ignoring .debug_names."),
4794 /* comp_unit_count - The number of CUs in the CU list. */
4795 map
.cu_count
= read_4_bytes (abfd
, addr
);
4798 /* local_type_unit_count - The number of TUs in the local TU
4800 map
.tu_count
= read_4_bytes (abfd
, addr
);
4803 /* foreign_type_unit_count - The number of TUs in the foreign TU
4805 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
4807 if (foreign_tu_count
!= 0)
4809 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
4810 "ignoring .debug_names."),
4811 filename
, static_cast<unsigned long> (foreign_tu_count
));
4815 /* bucket_count - The number of hash buckets in the hash lookup
4817 map
.bucket_count
= read_4_bytes (abfd
, addr
);
4820 /* name_count - The number of unique names in the index. */
4821 map
.name_count
= read_4_bytes (abfd
, addr
);
4824 /* abbrev_table_size - The size in bytes of the abbreviations
4826 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
4829 /* augmentation_string_size - The size in bytes of the augmentation
4830 string. This value is rounded up to a multiple of 4. */
4831 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
4833 map
.augmentation_is_gdb
= ((augmentation_string_size
4834 == sizeof (dwarf5_augmentation
))
4835 && memcmp (addr
, dwarf5_augmentation
,
4836 sizeof (dwarf5_augmentation
)) == 0);
4837 augmentation_string_size
+= (-augmentation_string_size
) & 3;
4838 addr
+= augmentation_string_size
;
4841 map
.cu_table_reordered
= addr
;
4842 addr
+= map
.cu_count
* map
.offset_size
;
4844 /* List of Local TUs */
4845 map
.tu_table_reordered
= addr
;
4846 addr
+= map
.tu_count
* map
.offset_size
;
4848 /* Hash Lookup Table */
4849 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4850 addr
+= map
.bucket_count
* 4;
4851 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
4852 addr
+= map
.name_count
* 4;
4855 map
.name_table_string_offs_reordered
= addr
;
4856 addr
+= map
.name_count
* map
.offset_size
;
4857 map
.name_table_entry_offs_reordered
= addr
;
4858 addr
+= map
.name_count
* map
.offset_size
;
4860 const gdb_byte
*abbrev_table_start
= addr
;
4863 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4868 const auto insertpair
4869 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
4870 if (!insertpair
.second
)
4872 warning (_("Section .debug_names in %s has duplicate index %s, "
4873 "ignoring .debug_names."),
4874 filename
, pulongest (index_num
));
4877 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
4878 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4883 mapped_debug_names::index_val::attr attr
;
4884 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4886 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
4888 if (attr
.form
== DW_FORM_implicit_const
)
4890 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
4894 if (attr
.dw_idx
== 0 && attr
.form
== 0)
4896 indexval
.attr_vec
.push_back (std::move (attr
));
4899 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
4901 warning (_("Section .debug_names in %s has abbreviation_table "
4902 "of size %s vs. written as %u, ignoring .debug_names."),
4903 filename
, plongest (addr
- abbrev_table_start
),
4907 map
.entry_pool
= addr
;
4912 /* A helper for create_cus_from_debug_names that handles the MAP's CU
4916 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4917 const mapped_debug_names
&map
,
4918 dwarf2_section_info
§ion
,
4921 sect_offset sect_off_prev
;
4922 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
4924 sect_offset sect_off_next
;
4925 if (i
< map
.cu_count
)
4928 = (sect_offset
) (extract_unsigned_integer
4929 (map
.cu_table_reordered
+ i
* map
.offset_size
,
4931 map
.dwarf5_byte_order
));
4934 sect_off_next
= (sect_offset
) section
.size
;
4937 const ULONGEST length
= sect_off_next
- sect_off_prev
;
4938 dwarf2_per_cu_data
*per_cu
4939 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
4940 sect_off_prev
, length
);
4941 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
4943 sect_off_prev
= sect_off_next
;
4947 /* Read the CU list from the mapped index, and use it to create all
4948 the CU objects for this dwarf2_per_objfile. */
4951 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4952 const mapped_debug_names
&map
,
4953 const mapped_debug_names
&dwz_map
)
4955 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
4956 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
4958 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
4959 dwarf2_per_objfile
->info
,
4960 false /* is_dwz */);
4962 if (dwz_map
.cu_count
== 0)
4965 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4966 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
4970 /* Read .debug_names. If everything went ok, initialize the "quick"
4971 elements of all the CUs and return true. Otherwise, return false. */
4974 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
4976 std::unique_ptr
<mapped_debug_names
> map
4977 (new mapped_debug_names (dwarf2_per_objfile
));
4978 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
4979 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
4981 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
4982 &dwarf2_per_objfile
->debug_names
,
4986 /* Don't use the index if it's empty. */
4987 if (map
->name_count
== 0)
4990 /* If there is a .dwz file, read it so we can get its CU list as
4992 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
4995 if (!read_debug_names_from_section (objfile
,
4996 bfd_get_filename (dwz
->dwz_bfd
.get ()),
4997 &dwz
->debug_names
, dwz_map
))
4999 warning (_("could not read '.debug_names' section from %s; skipping"),
5000 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5005 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5007 if (map
->tu_count
!= 0)
5009 /* We can only handle a single .debug_types when we have an
5011 if (dwarf2_per_objfile
->types
.size () != 1)
5014 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5016 create_signatured_type_table_from_debug_names
5017 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5020 create_addrmap_from_aranges (dwarf2_per_objfile
,
5021 &dwarf2_per_objfile
->debug_aranges
);
5023 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5024 dwarf2_per_objfile
->using_index
= 1;
5025 dwarf2_per_objfile
->quick_file_names_table
=
5026 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5031 /* Type used to manage iterating over all CUs looking for a symbol for
5034 class dw2_debug_names_iterator
5037 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5038 gdb::optional
<block_enum
> block_index
,
5041 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5042 m_addr (find_vec_in_debug_names (map
, name
))
5045 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5046 search_domain search
, uint32_t namei
)
5049 m_addr (find_vec_in_debug_names (map
, namei
))
5052 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5053 block_enum block_index
, domain_enum domain
,
5055 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5056 m_addr (find_vec_in_debug_names (map
, namei
))
5059 /* Return the next matching CU or NULL if there are no more. */
5060 dwarf2_per_cu_data
*next ();
5063 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5065 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5068 /* The internalized form of .debug_names. */
5069 const mapped_debug_names
&m_map
;
5071 /* If set, only look for symbols that match that block. Valid values are
5072 GLOBAL_BLOCK and STATIC_BLOCK. */
5073 const gdb::optional
<block_enum
> m_block_index
;
5075 /* The kind of symbol we're looking for. */
5076 const domain_enum m_domain
= UNDEF_DOMAIN
;
5077 const search_domain m_search
= ALL_DOMAIN
;
5079 /* The list of CUs from the index entry of the symbol, or NULL if
5081 const gdb_byte
*m_addr
;
5085 mapped_debug_names::namei_to_name (uint32_t namei
) const
5087 const ULONGEST namei_string_offs
5088 = extract_unsigned_integer ((name_table_string_offs_reordered
5089 + namei
* offset_size
),
5092 return read_indirect_string_at_offset (dwarf2_per_objfile
,
5096 /* Find a slot in .debug_names for the object named NAME. If NAME is
5097 found, return pointer to its pool data. If NAME cannot be found,
5101 dw2_debug_names_iterator::find_vec_in_debug_names
5102 (const mapped_debug_names
&map
, const char *name
)
5104 int (*cmp
) (const char *, const char *);
5106 gdb::unique_xmalloc_ptr
<char> without_params
;
5107 if (current_language
->la_language
== language_cplus
5108 || current_language
->la_language
== language_fortran
5109 || current_language
->la_language
== language_d
)
5111 /* NAME is already canonical. Drop any qualifiers as
5112 .debug_names does not contain any. */
5114 if (strchr (name
, '(') != NULL
)
5116 without_params
= cp_remove_params (name
);
5117 if (without_params
!= NULL
)
5118 name
= without_params
.get ();
5122 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5124 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5126 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5127 (map
.bucket_table_reordered
5128 + (full_hash
% map
.bucket_count
)), 4,
5129 map
.dwarf5_byte_order
);
5133 if (namei
>= map
.name_count
)
5135 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5137 namei
, map
.name_count
,
5138 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5144 const uint32_t namei_full_hash
5145 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5146 (map
.hash_table_reordered
+ namei
), 4,
5147 map
.dwarf5_byte_order
);
5148 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5151 if (full_hash
== namei_full_hash
)
5153 const char *const namei_string
= map
.namei_to_name (namei
);
5155 #if 0 /* An expensive sanity check. */
5156 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5158 complaint (_("Wrong .debug_names hash for string at index %u "
5160 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5165 if (cmp (namei_string
, name
) == 0)
5167 const ULONGEST namei_entry_offs
5168 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5169 + namei
* map
.offset_size
),
5170 map
.offset_size
, map
.dwarf5_byte_order
);
5171 return map
.entry_pool
+ namei_entry_offs
;
5176 if (namei
>= map
.name_count
)
5182 dw2_debug_names_iterator::find_vec_in_debug_names
5183 (const mapped_debug_names
&map
, uint32_t namei
)
5185 if (namei
>= map
.name_count
)
5187 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5189 namei
, map
.name_count
,
5190 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5194 const ULONGEST namei_entry_offs
5195 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5196 + namei
* map
.offset_size
),
5197 map
.offset_size
, map
.dwarf5_byte_order
);
5198 return map
.entry_pool
+ namei_entry_offs
;
5201 /* See dw2_debug_names_iterator. */
5203 dwarf2_per_cu_data
*
5204 dw2_debug_names_iterator::next ()
5209 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5210 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5211 bfd
*const abfd
= objfile
->obfd
;
5215 unsigned int bytes_read
;
5216 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5217 m_addr
+= bytes_read
;
5221 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5222 if (indexval_it
== m_map
.abbrev_map
.cend ())
5224 complaint (_("Wrong .debug_names undefined abbrev code %s "
5226 pulongest (abbrev
), objfile_name (objfile
));
5229 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5230 enum class symbol_linkage
{
5234 } symbol_linkage_
= symbol_linkage::unknown
;
5235 dwarf2_per_cu_data
*per_cu
= NULL
;
5236 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5241 case DW_FORM_implicit_const
:
5242 ull
= attr
.implicit_const
;
5244 case DW_FORM_flag_present
:
5248 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5249 m_addr
+= bytes_read
;
5252 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5253 dwarf_form_name (attr
.form
),
5254 objfile_name (objfile
));
5257 switch (attr
.dw_idx
)
5259 case DW_IDX_compile_unit
:
5260 /* Don't crash on bad data. */
5261 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5263 complaint (_(".debug_names entry has bad CU index %s"
5266 objfile_name (dwarf2_per_objfile
->objfile
));
5269 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5271 case DW_IDX_type_unit
:
5272 /* Don't crash on bad data. */
5273 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5275 complaint (_(".debug_names entry has bad TU index %s"
5278 objfile_name (dwarf2_per_objfile
->objfile
));
5281 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5283 case DW_IDX_GNU_internal
:
5284 if (!m_map
.augmentation_is_gdb
)
5286 symbol_linkage_
= symbol_linkage::static_
;
5288 case DW_IDX_GNU_external
:
5289 if (!m_map
.augmentation_is_gdb
)
5291 symbol_linkage_
= symbol_linkage::extern_
;
5296 /* Skip if already read in. */
5297 if (per_cu
->v
.quick
->compunit_symtab
)
5300 /* Check static vs global. */
5301 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5303 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5304 const bool symbol_is_static
=
5305 symbol_linkage_
== symbol_linkage::static_
;
5306 if (want_static
!= symbol_is_static
)
5310 /* Match dw2_symtab_iter_next, symbol_kind
5311 and debug_names::psymbol_tag. */
5315 switch (indexval
.dwarf_tag
)
5317 case DW_TAG_variable
:
5318 case DW_TAG_subprogram
:
5319 /* Some types are also in VAR_DOMAIN. */
5320 case DW_TAG_typedef
:
5321 case DW_TAG_structure_type
:
5328 switch (indexval
.dwarf_tag
)
5330 case DW_TAG_typedef
:
5331 case DW_TAG_structure_type
:
5338 switch (indexval
.dwarf_tag
)
5341 case DW_TAG_variable
:
5348 switch (indexval
.dwarf_tag
)
5360 /* Match dw2_expand_symtabs_matching, symbol_kind and
5361 debug_names::psymbol_tag. */
5364 case VARIABLES_DOMAIN
:
5365 switch (indexval
.dwarf_tag
)
5367 case DW_TAG_variable
:
5373 case FUNCTIONS_DOMAIN
:
5374 switch (indexval
.dwarf_tag
)
5376 case DW_TAG_subprogram
:
5383 switch (indexval
.dwarf_tag
)
5385 case DW_TAG_typedef
:
5386 case DW_TAG_structure_type
:
5392 case MODULES_DOMAIN
:
5393 switch (indexval
.dwarf_tag
)
5407 static struct compunit_symtab
*
5408 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5409 const char *name
, domain_enum domain
)
5411 struct dwarf2_per_objfile
*dwarf2_per_objfile
5412 = get_dwarf2_per_objfile (objfile
);
5414 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5417 /* index is NULL if OBJF_READNOW. */
5420 const auto &map
= *mapp
;
5422 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5424 struct compunit_symtab
*stab_best
= NULL
;
5425 struct dwarf2_per_cu_data
*per_cu
;
5426 while ((per_cu
= iter
.next ()) != NULL
)
5428 struct symbol
*sym
, *with_opaque
= NULL
;
5429 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5430 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5431 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5433 sym
= block_find_symbol (block
, name
, domain
,
5434 block_find_non_opaque_type_preferred
,
5437 /* Some caution must be observed with overloaded functions and
5438 methods, since the index will not contain any overload
5439 information (but NAME might contain it). */
5442 && strcmp_iw (sym
->search_name (), name
) == 0)
5444 if (with_opaque
!= NULL
5445 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5448 /* Keep looking through other CUs. */
5454 /* This dumps minimal information about .debug_names. It is called
5455 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5456 uses this to verify that .debug_names has been loaded. */
5459 dw2_debug_names_dump (struct objfile
*objfile
)
5461 struct dwarf2_per_objfile
*dwarf2_per_objfile
5462 = get_dwarf2_per_objfile (objfile
);
5464 gdb_assert (dwarf2_per_objfile
->using_index
);
5465 printf_filtered (".debug_names:");
5466 if (dwarf2_per_objfile
->debug_names_table
)
5467 printf_filtered (" exists\n");
5469 printf_filtered (" faked for \"readnow\"\n");
5470 printf_filtered ("\n");
5474 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5475 const char *func_name
)
5477 struct dwarf2_per_objfile
*dwarf2_per_objfile
5478 = get_dwarf2_per_objfile (objfile
);
5480 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5481 if (dwarf2_per_objfile
->debug_names_table
)
5483 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5485 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5487 struct dwarf2_per_cu_data
*per_cu
;
5488 while ((per_cu
= iter
.next ()) != NULL
)
5489 dw2_instantiate_symtab (per_cu
, false);
5494 dw2_debug_names_map_matching_symbols
5495 (struct objfile
*objfile
,
5496 const lookup_name_info
&name
, domain_enum domain
,
5498 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5499 symbol_compare_ftype
*ordered_compare
)
5501 struct dwarf2_per_objfile
*dwarf2_per_objfile
5502 = get_dwarf2_per_objfile (objfile
);
5504 /* debug_names_table is NULL if OBJF_READNOW. */
5505 if (!dwarf2_per_objfile
->debug_names_table
)
5508 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5509 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5511 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5512 auto matcher
= [&] (const char *symname
)
5514 if (ordered_compare
== nullptr)
5516 return ordered_compare (symname
, match_name
) == 0;
5519 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5520 [&] (offset_type namei
)
5522 /* The name was matched, now expand corresponding CUs that were
5524 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5526 struct dwarf2_per_cu_data
*per_cu
;
5527 while ((per_cu
= iter
.next ()) != NULL
)
5528 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5532 /* It's a shame we couldn't do this inside the
5533 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5534 that have already been expanded. Instead, this loop matches what
5535 the psymtab code does. */
5536 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5538 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5539 if (cust
!= nullptr)
5541 const struct block
*block
5542 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5543 if (!iterate_over_symbols_terminated (block
, name
,
5551 dw2_debug_names_expand_symtabs_matching
5552 (struct objfile
*objfile
,
5553 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5554 const lookup_name_info
&lookup_name
,
5555 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5556 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5557 enum search_domain kind
)
5559 struct dwarf2_per_objfile
*dwarf2_per_objfile
5560 = get_dwarf2_per_objfile (objfile
);
5562 /* debug_names_table is NULL if OBJF_READNOW. */
5563 if (!dwarf2_per_objfile
->debug_names_table
)
5566 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5568 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5570 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5572 kind
, [&] (offset_type namei
)
5574 /* The name was matched, now expand corresponding CUs that were
5576 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5578 struct dwarf2_per_cu_data
*per_cu
;
5579 while ((per_cu
= iter
.next ()) != NULL
)
5580 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5586 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5589 dw2_find_last_source_symtab
,
5590 dw2_forget_cached_source_info
,
5591 dw2_map_symtabs_matching_filename
,
5592 dw2_debug_names_lookup_symbol
,
5594 dw2_debug_names_dump
,
5595 dw2_debug_names_expand_symtabs_for_function
,
5596 dw2_expand_all_symtabs
,
5597 dw2_expand_symtabs_with_fullname
,
5598 dw2_debug_names_map_matching_symbols
,
5599 dw2_debug_names_expand_symtabs_matching
,
5600 dw2_find_pc_sect_compunit_symtab
,
5602 dw2_map_symbol_filenames
5605 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
5606 to either a dwarf2_per_objfile or dwz_file object. */
5608 template <typename T
>
5609 static gdb::array_view
<const gdb_byte
>
5610 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
5612 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
5614 if (section
->empty ())
5617 /* Older elfutils strip versions could keep the section in the main
5618 executable while splitting it for the separate debug info file. */
5619 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5622 section
->read (obj
);
5624 /* dwarf2_section_info::size is a bfd_size_type, while
5625 gdb::array_view works with size_t. On 32-bit hosts, with
5626 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
5627 is 32-bit. So we need an explicit narrowing conversion here.
5628 This is fine, because it's impossible to allocate or mmap an
5629 array/buffer larger than what size_t can represent. */
5630 return gdb::make_array_view (section
->buffer
, section
->size
);
5633 /* Lookup the index cache for the contents of the index associated to
5636 static gdb::array_view
<const gdb_byte
>
5637 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
5639 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
5640 if (build_id
== nullptr)
5643 return global_index_cache
.lookup_gdb_index (build_id
,
5644 &dwarf2_obj
->index_cache_res
);
5647 /* Same as the above, but for DWZ. */
5649 static gdb::array_view
<const gdb_byte
>
5650 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
5652 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
5653 if (build_id
== nullptr)
5656 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
5659 /* See symfile.h. */
5662 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
5664 struct dwarf2_per_objfile
*dwarf2_per_objfile
5665 = get_dwarf2_per_objfile (objfile
);
5667 /* If we're about to read full symbols, don't bother with the
5668 indices. In this case we also don't care if some other debug
5669 format is making psymtabs, because they are all about to be
5671 if ((objfile
->flags
& OBJF_READNOW
))
5673 dwarf2_per_objfile
->using_index
= 1;
5674 create_all_comp_units (dwarf2_per_objfile
);
5675 create_all_type_units (dwarf2_per_objfile
);
5676 dwarf2_per_objfile
->quick_file_names_table
5677 = create_quick_file_names_table
5678 (dwarf2_per_objfile
->all_comp_units
.size ());
5680 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
5681 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
5683 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
5685 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5686 struct dwarf2_per_cu_quick_data
);
5689 /* Return 1 so that gdb sees the "quick" functions. However,
5690 these functions will be no-ops because we will have expanded
5692 *index_kind
= dw_index_kind::GDB_INDEX
;
5696 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
5698 *index_kind
= dw_index_kind::DEBUG_NAMES
;
5702 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5703 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
5704 get_gdb_index_contents_from_section
<dwz_file
>))
5706 *index_kind
= dw_index_kind::GDB_INDEX
;
5710 /* ... otherwise, try to find the index in the index cache. */
5711 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
5712 get_gdb_index_contents_from_cache
,
5713 get_gdb_index_contents_from_cache_dwz
))
5715 global_index_cache
.hit ();
5716 *index_kind
= dw_index_kind::GDB_INDEX
;
5720 global_index_cache
.miss ();
5726 /* Build a partial symbol table. */
5729 dwarf2_build_psymtabs (struct objfile
*objfile
)
5731 struct dwarf2_per_objfile
*dwarf2_per_objfile
5732 = get_dwarf2_per_objfile (objfile
);
5734 init_psymbol_list (objfile
, 1024);
5738 /* This isn't really ideal: all the data we allocate on the
5739 objfile's obstack is still uselessly kept around. However,
5740 freeing it seems unsafe. */
5741 psymtab_discarder
psymtabs (objfile
);
5742 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
5745 /* (maybe) store an index in the cache. */
5746 global_index_cache
.store (dwarf2_per_objfile
);
5748 catch (const gdb_exception_error
&except
)
5750 exception_print (gdb_stderr
, except
);
5754 /* Find the base address of the compilation unit for range lists and
5755 location lists. It will normally be specified by DW_AT_low_pc.
5756 In DWARF-3 draft 4, the base address could be overridden by
5757 DW_AT_entry_pc. It's been removed, but GCC still uses this for
5758 compilation units with discontinuous ranges. */
5761 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
5763 struct attribute
*attr
;
5765 cu
->base_address
.reset ();
5767 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
5768 if (attr
!= nullptr)
5769 cu
->base_address
= attr
->value_as_address ();
5772 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5773 if (attr
!= nullptr)
5774 cu
->base_address
= attr
->value_as_address ();
5778 /* Helper function that returns the proper abbrev section for
5781 static struct dwarf2_section_info
*
5782 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
5784 struct dwarf2_section_info
*abbrev
;
5785 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
5787 if (this_cu
->is_dwz
)
5788 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
5790 abbrev
= &dwarf2_per_objfile
->abbrev
;
5795 /* Fetch the abbreviation table offset from a comp or type unit header. */
5798 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5799 struct dwarf2_section_info
*section
,
5800 sect_offset sect_off
)
5802 bfd
*abfd
= section
->get_bfd_owner ();
5803 const gdb_byte
*info_ptr
;
5804 unsigned int initial_length_size
, offset_size
;
5807 section
->read (dwarf2_per_objfile
->objfile
);
5808 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
5809 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
5810 offset_size
= initial_length_size
== 4 ? 4 : 8;
5811 info_ptr
+= initial_length_size
;
5813 version
= read_2_bytes (abfd
, info_ptr
);
5817 /* Skip unit type and address size. */
5821 return (sect_offset
) read_offset (abfd
, info_ptr
, offset_size
);
5824 /* A partial symtab that is used only for include files. */
5825 struct dwarf2_include_psymtab
: public partial_symtab
5827 dwarf2_include_psymtab (const char *filename
, struct objfile
*objfile
)
5828 : partial_symtab (filename
, objfile
)
5832 void read_symtab (struct objfile
*objfile
) override
5834 expand_psymtab (objfile
);
5837 void expand_psymtab (struct objfile
*objfile
) override
5841 /* It's an include file, no symbols to read for it.
5842 Everything is in the parent symtab. */
5843 expand_dependencies (objfile
);
5847 bool readin_p () const override
5852 struct compunit_symtab
*get_compunit_symtab () const override
5859 bool m_readin
= false;
5862 /* Allocate a new partial symtab for file named NAME and mark this new
5863 partial symtab as being an include of PST. */
5866 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
5867 struct objfile
*objfile
)
5869 dwarf2_include_psymtab
*subpst
= new dwarf2_include_psymtab (name
, objfile
);
5871 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
5873 /* It shares objfile->objfile_obstack. */
5874 subpst
->dirname
= pst
->dirname
;
5877 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
5878 subpst
->dependencies
[0] = pst
;
5879 subpst
->number_of_dependencies
= 1;
5882 /* Read the Line Number Program data and extract the list of files
5883 included by the source file represented by PST. Build an include
5884 partial symtab for each of these included files. */
5887 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
5888 struct die_info
*die
,
5889 dwarf2_psymtab
*pst
)
5892 struct attribute
*attr
;
5894 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5895 if (attr
!= nullptr)
5896 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
5898 return; /* No linetable, so no includes. */
5900 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
5901 that we pass in the raw text_low here; that is ok because we're
5902 only decoding the line table to make include partial symtabs, and
5903 so the addresses aren't really used. */
5904 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
5905 pst
->raw_text_low (), 1);
5909 hash_signatured_type (const void *item
)
5911 const struct signatured_type
*sig_type
5912 = (const struct signatured_type
*) item
;
5914 /* This drops the top 32 bits of the signature, but is ok for a hash. */
5915 return sig_type
->signature
;
5919 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
5921 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
5922 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
5924 return lhs
->signature
== rhs
->signature
;
5927 /* Allocate a hash table for signatured types. */
5930 allocate_signatured_type_table ()
5932 return htab_up (htab_create_alloc (41,
5933 hash_signatured_type
,
5935 NULL
, xcalloc
, xfree
));
5938 /* A helper function to add a signatured type CU to a table. */
5941 add_signatured_type_cu_to_table (void **slot
, void *datum
)
5943 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
5944 std::vector
<signatured_type
*> *all_type_units
5945 = (std::vector
<signatured_type
*> *) datum
;
5947 all_type_units
->push_back (sigt
);
5952 /* A helper for create_debug_types_hash_table. Read types from SECTION
5953 and fill them into TYPES_HTAB. It will process only type units,
5954 therefore DW_UT_type. */
5957 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5958 struct dwo_file
*dwo_file
,
5959 dwarf2_section_info
*section
, htab_up
&types_htab
,
5960 rcuh_kind section_kind
)
5962 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5963 struct dwarf2_section_info
*abbrev_section
;
5965 const gdb_byte
*info_ptr
, *end_ptr
;
5967 abbrev_section
= (dwo_file
!= NULL
5968 ? &dwo_file
->sections
.abbrev
5969 : &dwarf2_per_objfile
->abbrev
);
5971 if (dwarf_read_debug
)
5972 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
5973 section
->get_name (),
5974 abbrev_section
->get_file_name ());
5976 section
->read (objfile
);
5977 info_ptr
= section
->buffer
;
5979 if (info_ptr
== NULL
)
5982 /* We can't set abfd until now because the section may be empty or
5983 not present, in which case the bfd is unknown. */
5984 abfd
= section
->get_bfd_owner ();
5986 /* We don't use cutu_reader here because we don't need to read
5987 any dies: the signature is in the header. */
5989 end_ptr
= info_ptr
+ section
->size
;
5990 while (info_ptr
< end_ptr
)
5992 struct signatured_type
*sig_type
;
5993 struct dwo_unit
*dwo_tu
;
5995 const gdb_byte
*ptr
= info_ptr
;
5996 struct comp_unit_head header
;
5997 unsigned int length
;
5999 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6001 /* Initialize it due to a false compiler warning. */
6002 header
.signature
= -1;
6003 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6005 /* We need to read the type's signature in order to build the hash
6006 table, but we don't need anything else just yet. */
6008 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6009 abbrev_section
, ptr
, section_kind
);
6011 length
= header
.get_length ();
6013 /* Skip dummy type units. */
6014 if (ptr
>= info_ptr
+ length
6015 || peek_abbrev_code (abfd
, ptr
) == 0
6016 || header
.unit_type
!= DW_UT_type
)
6022 if (types_htab
== NULL
)
6025 types_htab
= allocate_dwo_unit_table ();
6027 types_htab
= allocate_signatured_type_table ();
6033 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6035 dwo_tu
->dwo_file
= dwo_file
;
6036 dwo_tu
->signature
= header
.signature
;
6037 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6038 dwo_tu
->section
= section
;
6039 dwo_tu
->sect_off
= sect_off
;
6040 dwo_tu
->length
= length
;
6044 /* N.B.: type_offset is not usable if this type uses a DWO file.
6045 The real type_offset is in the DWO file. */
6047 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6048 struct signatured_type
);
6049 sig_type
->signature
= header
.signature
;
6050 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6051 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6052 sig_type
->per_cu
.is_debug_types
= 1;
6053 sig_type
->per_cu
.section
= section
;
6054 sig_type
->per_cu
.sect_off
= sect_off
;
6055 sig_type
->per_cu
.length
= length
;
6058 slot
= htab_find_slot (types_htab
.get (),
6059 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6061 gdb_assert (slot
!= NULL
);
6064 sect_offset dup_sect_off
;
6068 const struct dwo_unit
*dup_tu
6069 = (const struct dwo_unit
*) *slot
;
6071 dup_sect_off
= dup_tu
->sect_off
;
6075 const struct signatured_type
*dup_tu
6076 = (const struct signatured_type
*) *slot
;
6078 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6081 complaint (_("debug type entry at offset %s is duplicate to"
6082 " the entry at offset %s, signature %s"),
6083 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6084 hex_string (header
.signature
));
6086 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6088 if (dwarf_read_debug
> 1)
6089 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6090 sect_offset_str (sect_off
),
6091 hex_string (header
.signature
));
6097 /* Create the hash table of all entries in the .debug_types
6098 (or .debug_types.dwo) section(s).
6099 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6100 otherwise it is NULL.
6102 The result is a pointer to the hash table or NULL if there are no types.
6104 Note: This function processes DWO files only, not DWP files. */
6107 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6108 struct dwo_file
*dwo_file
,
6109 gdb::array_view
<dwarf2_section_info
> type_sections
,
6110 htab_up
&types_htab
)
6112 for (dwarf2_section_info
§ion
: type_sections
)
6113 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6114 types_htab
, rcuh_kind::TYPE
);
6117 /* Create the hash table of all entries in the .debug_types section,
6118 and initialize all_type_units.
6119 The result is zero if there is an error (e.g. missing .debug_types section),
6120 otherwise non-zero. */
6123 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6127 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6128 &dwarf2_per_objfile
->info
, types_htab
,
6129 rcuh_kind::COMPILE
);
6130 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6131 dwarf2_per_objfile
->types
, types_htab
);
6132 if (types_htab
== NULL
)
6134 dwarf2_per_objfile
->signatured_types
= NULL
;
6138 dwarf2_per_objfile
->signatured_types
= std::move (types_htab
);
6140 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6141 dwarf2_per_objfile
->all_type_units
.reserve
6142 (htab_elements (dwarf2_per_objfile
->signatured_types
.get ()));
6144 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
.get (),
6145 add_signatured_type_cu_to_table
,
6146 &dwarf2_per_objfile
->all_type_units
);
6151 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6152 If SLOT is non-NULL, it is the entry to use in the hash table.
6153 Otherwise we find one. */
6155 static struct signatured_type
*
6156 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6159 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6161 if (dwarf2_per_objfile
->all_type_units
.size ()
6162 == dwarf2_per_objfile
->all_type_units
.capacity ())
6163 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6165 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6166 struct signatured_type
);
6168 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6169 sig_type
->signature
= sig
;
6170 sig_type
->per_cu
.is_debug_types
= 1;
6171 if (dwarf2_per_objfile
->using_index
)
6173 sig_type
->per_cu
.v
.quick
=
6174 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6175 struct dwarf2_per_cu_quick_data
);
6180 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6183 gdb_assert (*slot
== NULL
);
6185 /* The rest of sig_type must be filled in by the caller. */
6189 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6190 Fill in SIG_ENTRY with DWO_ENTRY. */
6193 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6194 struct signatured_type
*sig_entry
,
6195 struct dwo_unit
*dwo_entry
)
6197 /* Make sure we're not clobbering something we don't expect to. */
6198 gdb_assert (! sig_entry
->per_cu
.queued
);
6199 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6200 if (dwarf2_per_objfile
->using_index
)
6202 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6203 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6206 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6207 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6208 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6209 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6210 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6212 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6213 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6214 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6215 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6216 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6217 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6218 sig_entry
->dwo_unit
= dwo_entry
;
6221 /* Subroutine of lookup_signatured_type.
6222 If we haven't read the TU yet, create the signatured_type data structure
6223 for a TU to be read in directly from a DWO file, bypassing the stub.
6224 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6225 using .gdb_index, then when reading a CU we want to stay in the DWO file
6226 containing that CU. Otherwise we could end up reading several other DWO
6227 files (due to comdat folding) to process the transitive closure of all the
6228 mentioned TUs, and that can be slow. The current DWO file will have every
6229 type signature that it needs.
6230 We only do this for .gdb_index because in the psymtab case we already have
6231 to read all the DWOs to build the type unit groups. */
6233 static struct signatured_type
*
6234 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6236 struct dwarf2_per_objfile
*dwarf2_per_objfile
6237 = cu
->per_cu
->dwarf2_per_objfile
;
6238 struct dwo_file
*dwo_file
;
6239 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6240 struct signatured_type find_sig_entry
, *sig_entry
;
6243 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6245 /* If TU skeletons have been removed then we may not have read in any
6247 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6248 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6250 /* We only ever need to read in one copy of a signatured type.
6251 Use the global signatured_types array to do our own comdat-folding
6252 of types. If this is the first time we're reading this TU, and
6253 the TU has an entry in .gdb_index, replace the recorded data from
6254 .gdb_index with this TU. */
6256 find_sig_entry
.signature
= sig
;
6257 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6258 &find_sig_entry
, INSERT
);
6259 sig_entry
= (struct signatured_type
*) *slot
;
6261 /* We can get here with the TU already read, *or* in the process of being
6262 read. Don't reassign the global entry to point to this DWO if that's
6263 the case. Also note that if the TU is already being read, it may not
6264 have come from a DWO, the program may be a mix of Fission-compiled
6265 code and non-Fission-compiled code. */
6267 /* Have we already tried to read this TU?
6268 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6269 needn't exist in the global table yet). */
6270 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6273 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6274 dwo_unit of the TU itself. */
6275 dwo_file
= cu
->dwo_unit
->dwo_file
;
6277 /* Ok, this is the first time we're reading this TU. */
6278 if (dwo_file
->tus
== NULL
)
6280 find_dwo_entry
.signature
= sig
;
6281 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
6283 if (dwo_entry
== NULL
)
6286 /* If the global table doesn't have an entry for this TU, add one. */
6287 if (sig_entry
== NULL
)
6288 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6290 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6291 sig_entry
->per_cu
.tu_read
= 1;
6295 /* Subroutine of lookup_signatured_type.
6296 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6297 then try the DWP file. If the TU stub (skeleton) has been removed then
6298 it won't be in .gdb_index. */
6300 static struct signatured_type
*
6301 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6303 struct dwarf2_per_objfile
*dwarf2_per_objfile
6304 = cu
->per_cu
->dwarf2_per_objfile
;
6305 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6306 struct dwo_unit
*dwo_entry
;
6307 struct signatured_type find_sig_entry
, *sig_entry
;
6310 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6311 gdb_assert (dwp_file
!= NULL
);
6313 /* If TU skeletons have been removed then we may not have read in any
6315 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6316 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
6318 find_sig_entry
.signature
= sig
;
6319 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
6320 &find_sig_entry
, INSERT
);
6321 sig_entry
= (struct signatured_type
*) *slot
;
6323 /* Have we already tried to read this TU?
6324 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6325 needn't exist in the global table yet). */
6326 if (sig_entry
!= NULL
)
6329 if (dwp_file
->tus
== NULL
)
6331 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6332 sig
, 1 /* is_debug_types */);
6333 if (dwo_entry
== NULL
)
6336 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6337 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6342 /* Lookup a signature based type for DW_FORM_ref_sig8.
6343 Returns NULL if signature SIG is not present in the table.
6344 It is up to the caller to complain about this. */
6346 static struct signatured_type
*
6347 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6349 struct dwarf2_per_objfile
*dwarf2_per_objfile
6350 = cu
->per_cu
->dwarf2_per_objfile
;
6353 && dwarf2_per_objfile
->using_index
)
6355 /* We're in a DWO/DWP file, and we're using .gdb_index.
6356 These cases require special processing. */
6357 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6358 return lookup_dwo_signatured_type (cu
, sig
);
6360 return lookup_dwp_signatured_type (cu
, sig
);
6364 struct signatured_type find_entry
, *entry
;
6366 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6368 find_entry
.signature
= sig
;
6369 entry
= ((struct signatured_type
*)
6370 htab_find (dwarf2_per_objfile
->signatured_types
.get (),
6376 /* Low level DIE reading support. */
6378 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6381 init_cu_die_reader (struct die_reader_specs
*reader
,
6382 struct dwarf2_cu
*cu
,
6383 struct dwarf2_section_info
*section
,
6384 struct dwo_file
*dwo_file
,
6385 struct abbrev_table
*abbrev_table
)
6387 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6388 reader
->abfd
= section
->get_bfd_owner ();
6390 reader
->dwo_file
= dwo_file
;
6391 reader
->die_section
= section
;
6392 reader
->buffer
= section
->buffer
;
6393 reader
->buffer_end
= section
->buffer
+ section
->size
;
6394 reader
->abbrev_table
= abbrev_table
;
6397 /* Subroutine of cutu_reader to simplify it.
6398 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
6399 There's just a lot of work to do, and cutu_reader is big enough
6402 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
6403 from it to the DIE in the DWO. If NULL we are skipping the stub.
6404 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
6405 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
6406 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
6407 STUB_COMP_DIR may be non-NULL.
6408 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
6409 are filled in with the info of the DIE from the DWO file.
6410 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
6411 from the dwo. Since *RESULT_READER references this abbrev table, it must be
6412 kept around for at least as long as *RESULT_READER.
6414 The result is non-zero if a valid (non-dummy) DIE was found. */
6417 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
6418 struct dwo_unit
*dwo_unit
,
6419 struct die_info
*stub_comp_unit_die
,
6420 const char *stub_comp_dir
,
6421 struct die_reader_specs
*result_reader
,
6422 const gdb_byte
**result_info_ptr
,
6423 struct die_info
**result_comp_unit_die
,
6424 abbrev_table_up
*result_dwo_abbrev_table
)
6426 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6427 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6428 struct dwarf2_cu
*cu
= this_cu
->cu
;
6430 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6431 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
6432 int i
,num_extra_attrs
;
6433 struct dwarf2_section_info
*dwo_abbrev_section
;
6434 struct die_info
*comp_unit_die
;
6436 /* At most one of these may be provided. */
6437 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
6439 /* These attributes aren't processed until later:
6440 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
6441 DW_AT_comp_dir is used now, to find the DWO file, but it is also
6442 referenced later. However, these attributes are found in the stub
6443 which we won't have later. In order to not impose this complication
6444 on the rest of the code, we read them here and copy them to the
6453 if (stub_comp_unit_die
!= NULL
)
6455 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
6457 if (! this_cu
->is_debug_types
)
6458 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
6459 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
6460 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
6461 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
6462 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
6464 cu
->addr_base
= stub_comp_unit_die
->addr_base ();
6466 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
6467 here (if needed). We need the value before we can process
6469 cu
->ranges_base
= stub_comp_unit_die
->ranges_base ();
6471 else if (stub_comp_dir
!= NULL
)
6473 /* Reconstruct the comp_dir attribute to simplify the code below. */
6474 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
6475 comp_dir
->name
= DW_AT_comp_dir
;
6476 comp_dir
->form
= DW_FORM_string
;
6477 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
6478 DW_STRING (comp_dir
) = stub_comp_dir
;
6481 /* Set up for reading the DWO CU/TU. */
6482 cu
->dwo_unit
= dwo_unit
;
6483 dwarf2_section_info
*section
= dwo_unit
->section
;
6484 section
->read (objfile
);
6485 abfd
= section
->get_bfd_owner ();
6486 begin_info_ptr
= info_ptr
= (section
->buffer
6487 + to_underlying (dwo_unit
->sect_off
));
6488 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
6490 if (this_cu
->is_debug_types
)
6492 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
6494 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6495 &cu
->header
, section
,
6497 info_ptr
, rcuh_kind::TYPE
);
6498 /* This is not an assert because it can be caused by bad debug info. */
6499 if (sig_type
->signature
!= cu
->header
.signature
)
6501 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
6502 " TU at offset %s [in module %s]"),
6503 hex_string (sig_type
->signature
),
6504 hex_string (cu
->header
.signature
),
6505 sect_offset_str (dwo_unit
->sect_off
),
6506 bfd_get_filename (abfd
));
6508 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6509 /* For DWOs coming from DWP files, we don't know the CU length
6510 nor the type's offset in the TU until now. */
6511 dwo_unit
->length
= cu
->header
.get_length ();
6512 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
6514 /* Establish the type offset that can be used to lookup the type.
6515 For DWO files, we don't know it until now. */
6516 sig_type
->type_offset_in_section
6517 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
6521 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6522 &cu
->header
, section
,
6524 info_ptr
, rcuh_kind::COMPILE
);
6525 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
6526 /* For DWOs coming from DWP files, we don't know the CU length
6528 dwo_unit
->length
= cu
->header
.get_length ();
6531 *result_dwo_abbrev_table
6532 = abbrev_table::read (objfile
, dwo_abbrev_section
,
6533 cu
->header
.abbrev_sect_off
);
6534 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
6535 result_dwo_abbrev_table
->get ());
6537 /* Read in the die, but leave space to copy over the attributes
6538 from the stub. This has the benefit of simplifying the rest of
6539 the code - all the work to maintain the illusion of a single
6540 DW_TAG_{compile,type}_unit DIE is done here. */
6541 num_extra_attrs
= ((stmt_list
!= NULL
)
6545 + (comp_dir
!= NULL
));
6546 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
6549 /* Copy over the attributes from the stub to the DIE we just read in. */
6550 comp_unit_die
= *result_comp_unit_die
;
6551 i
= comp_unit_die
->num_attrs
;
6552 if (stmt_list
!= NULL
)
6553 comp_unit_die
->attrs
[i
++] = *stmt_list
;
6555 comp_unit_die
->attrs
[i
++] = *low_pc
;
6556 if (high_pc
!= NULL
)
6557 comp_unit_die
->attrs
[i
++] = *high_pc
;
6559 comp_unit_die
->attrs
[i
++] = *ranges
;
6560 if (comp_dir
!= NULL
)
6561 comp_unit_die
->attrs
[i
++] = *comp_dir
;
6562 comp_unit_die
->num_attrs
+= num_extra_attrs
;
6564 if (dwarf_die_debug
)
6566 fprintf_unfiltered (gdb_stdlog
,
6567 "Read die from %s@0x%x of %s:\n",
6568 section
->get_name (),
6569 (unsigned) (begin_info_ptr
- section
->buffer
),
6570 bfd_get_filename (abfd
));
6571 dump_die (comp_unit_die
, dwarf_die_debug
);
6574 /* Skip dummy compilation units. */
6575 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
6576 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6579 *result_info_ptr
= info_ptr
;
6583 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
6584 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
6585 signature is part of the header. */
6586 static gdb::optional
<ULONGEST
>
6587 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
6589 if (cu
->header
.version
>= 5)
6590 return cu
->header
.signature
;
6591 struct attribute
*attr
;
6592 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
6593 if (attr
== nullptr)
6594 return gdb::optional
<ULONGEST
> ();
6595 return DW_UNSND (attr
);
6598 /* Subroutine of cutu_reader to simplify it.
6599 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
6600 Returns NULL if the specified DWO unit cannot be found. */
6602 static struct dwo_unit
*
6603 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
6604 struct die_info
*comp_unit_die
,
6605 const char *dwo_name
)
6607 struct dwarf2_cu
*cu
= this_cu
->cu
;
6608 struct dwo_unit
*dwo_unit
;
6609 const char *comp_dir
;
6611 gdb_assert (cu
!= NULL
);
6613 /* Yeah, we look dwo_name up again, but it simplifies the code. */
6614 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6615 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
6617 if (this_cu
->is_debug_types
)
6619 struct signatured_type
*sig_type
;
6621 /* Since this_cu is the first member of struct signatured_type,
6622 we can go from a pointer to one to a pointer to the other. */
6623 sig_type
= (struct signatured_type
*) this_cu
;
6624 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
6628 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
6629 if (!signature
.has_value ())
6630 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
6632 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
6633 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
6640 /* Subroutine of cutu_reader to simplify it.
6641 See it for a description of the parameters.
6642 Read a TU directly from a DWO file, bypassing the stub. */
6645 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
6646 int use_existing_cu
)
6648 struct signatured_type
*sig_type
;
6650 /* Verify we can do the following downcast, and that we have the
6652 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
6653 sig_type
= (struct signatured_type
*) this_cu
;
6654 gdb_assert (sig_type
->dwo_unit
!= NULL
);
6656 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6658 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
6659 /* There's no need to do the rereading_dwo_cu handling that
6660 cutu_reader does since we don't read the stub. */
6664 /* If !use_existing_cu, this_cu->cu must be NULL. */
6665 gdb_assert (this_cu
->cu
== NULL
);
6666 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6669 /* A future optimization, if needed, would be to use an existing
6670 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
6671 could share abbrev tables. */
6673 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
6674 NULL
/* stub_comp_unit_die */,
6675 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
6678 &m_dwo_abbrev_table
) == 0)
6685 /* Initialize a CU (or TU) and read its DIEs.
6686 If the CU defers to a DWO file, read the DWO file as well.
6688 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
6689 Otherwise the table specified in the comp unit header is read in and used.
6690 This is an optimization for when we already have the abbrev table.
6692 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
6693 Otherwise, a new CU is allocated with xmalloc. */
6695 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6696 struct abbrev_table
*abbrev_table
,
6697 int use_existing_cu
,
6699 : die_reader_specs
{},
6702 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6703 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6704 struct dwarf2_section_info
*section
= this_cu
->section
;
6705 bfd
*abfd
= section
->get_bfd_owner ();
6706 struct dwarf2_cu
*cu
;
6707 const gdb_byte
*begin_info_ptr
;
6708 struct signatured_type
*sig_type
= NULL
;
6709 struct dwarf2_section_info
*abbrev_section
;
6710 /* Non-zero if CU currently points to a DWO file and we need to
6711 reread it. When this happens we need to reread the skeleton die
6712 before we can reread the DWO file (this only applies to CUs, not TUs). */
6713 int rereading_dwo_cu
= 0;
6715 if (dwarf_die_debug
)
6716 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6717 this_cu
->is_debug_types
? "type" : "comp",
6718 sect_offset_str (this_cu
->sect_off
));
6720 /* If we're reading a TU directly from a DWO file, including a virtual DWO
6721 file (instead of going through the stub), short-circuit all of this. */
6722 if (this_cu
->reading_dwo_directly
)
6724 /* Narrow down the scope of possibilities to have to understand. */
6725 gdb_assert (this_cu
->is_debug_types
);
6726 gdb_assert (abbrev_table
== NULL
);
6727 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
);
6731 /* This is cheap if the section is already read in. */
6732 section
->read (objfile
);
6734 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6736 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
6738 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
6741 /* If this CU is from a DWO file we need to start over, we need to
6742 refetch the attributes from the skeleton CU.
6743 This could be optimized by retrieving those attributes from when we
6744 were here the first time: the previous comp_unit_die was stored in
6745 comp_unit_obstack. But there's no data yet that we need this
6747 if (cu
->dwo_unit
!= NULL
)
6748 rereading_dwo_cu
= 1;
6752 /* If !use_existing_cu, this_cu->cu must be NULL. */
6753 gdb_assert (this_cu
->cu
== NULL
);
6754 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6755 cu
= m_new_cu
.get ();
6758 /* Get the header. */
6759 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
6761 /* We already have the header, there's no need to read it in again. */
6762 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
6766 if (this_cu
->is_debug_types
)
6768 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6769 &cu
->header
, section
,
6770 abbrev_section
, info_ptr
,
6773 /* Since per_cu is the first member of struct signatured_type,
6774 we can go from a pointer to one to a pointer to the other. */
6775 sig_type
= (struct signatured_type
*) this_cu
;
6776 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
6777 gdb_assert (sig_type
->type_offset_in_tu
6778 == cu
->header
.type_cu_offset_in_tu
);
6779 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6781 /* LENGTH has not been set yet for type units if we're
6782 using .gdb_index. */
6783 this_cu
->length
= cu
->header
.get_length ();
6785 /* Establish the type offset that can be used to lookup the type. */
6786 sig_type
->type_offset_in_section
=
6787 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
6789 this_cu
->dwarf_version
= cu
->header
.version
;
6793 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6794 &cu
->header
, section
,
6797 rcuh_kind::COMPILE
);
6799 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
6800 gdb_assert (this_cu
->length
== cu
->header
.get_length ());
6801 this_cu
->dwarf_version
= cu
->header
.version
;
6805 /* Skip dummy compilation units. */
6806 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6807 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6813 /* If we don't have them yet, read the abbrevs for this compilation unit.
6814 And if we need to read them now, make sure they're freed when we're
6816 if (abbrev_table
!= NULL
)
6817 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
6820 m_abbrev_table_holder
6821 = abbrev_table::read (objfile
, abbrev_section
,
6822 cu
->header
.abbrev_sect_off
);
6823 abbrev_table
= m_abbrev_table_holder
.get ();
6826 /* Read the top level CU/TU die. */
6827 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
6828 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6830 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
6836 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
6837 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
6838 table from the DWO file and pass the ownership over to us. It will be
6839 referenced from READER, so we must make sure to free it after we're done
6842 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
6843 DWO CU, that this test will fail (the attribute will not be present). */
6844 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
6845 if (dwo_name
!= nullptr)
6847 struct dwo_unit
*dwo_unit
;
6848 struct die_info
*dwo_comp_unit_die
;
6850 if (comp_unit_die
->has_children
)
6852 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
6853 " has children (offset %s) [in module %s]"),
6854 sect_offset_str (this_cu
->sect_off
),
6855 bfd_get_filename (abfd
));
6857 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
6858 if (dwo_unit
!= NULL
)
6860 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
6861 comp_unit_die
, NULL
,
6864 &m_dwo_abbrev_table
) == 0)
6870 comp_unit_die
= dwo_comp_unit_die
;
6874 /* Yikes, we couldn't find the rest of the DIE, we only have
6875 the stub. A complaint has already been logged. There's
6876 not much more we can do except pass on the stub DIE to
6877 die_reader_func. We don't want to throw an error on bad
6884 cutu_reader::keep ()
6886 /* Done, clean up. */
6887 gdb_assert (!dummy_p
);
6888 if (m_new_cu
!= NULL
)
6890 struct dwarf2_per_objfile
*dwarf2_per_objfile
6891 = m_this_cu
->dwarf2_per_objfile
;
6892 /* Link this CU into read_in_chain. */
6893 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6894 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
6895 /* The chain owns it now. */
6896 m_new_cu
.release ();
6900 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
6901 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
6902 assumed to have already done the lookup to find the DWO file).
6904 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
6905 THIS_CU->is_debug_types, but nothing else.
6907 We fill in THIS_CU->length.
6909 THIS_CU->cu is always freed when done.
6910 This is done in order to not leave THIS_CU->cu in a state where we have
6911 to care whether it refers to the "main" CU or the DWO CU.
6913 When parent_cu is passed, it is used to provide a default value for
6914 str_offsets_base and addr_base from the parent. */
6916 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
6917 struct dwarf2_cu
*parent_cu
,
6918 struct dwo_file
*dwo_file
)
6919 : die_reader_specs
{},
6922 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6923 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6924 struct dwarf2_section_info
*section
= this_cu
->section
;
6925 bfd
*abfd
= section
->get_bfd_owner ();
6926 struct dwarf2_section_info
*abbrev_section
;
6927 const gdb_byte
*begin_info_ptr
, *info_ptr
;
6929 if (dwarf_die_debug
)
6930 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
6931 this_cu
->is_debug_types
? "type" : "comp",
6932 sect_offset_str (this_cu
->sect_off
));
6934 gdb_assert (this_cu
->cu
== NULL
);
6936 abbrev_section
= (dwo_file
!= NULL
6937 ? &dwo_file
->sections
.abbrev
6938 : get_abbrev_section_for_cu (this_cu
));
6940 /* This is cheap if the section is already read in. */
6941 section
->read (objfile
);
6943 m_new_cu
.reset (new dwarf2_cu (this_cu
));
6945 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
6946 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
6947 &m_new_cu
->header
, section
,
6948 abbrev_section
, info_ptr
,
6949 (this_cu
->is_debug_types
6951 : rcuh_kind::COMPILE
));
6953 if (parent_cu
!= nullptr)
6955 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
6956 m_new_cu
->addr_base
= parent_cu
->addr_base
;
6958 this_cu
->length
= m_new_cu
->header
.get_length ();
6960 /* Skip dummy compilation units. */
6961 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
6962 || peek_abbrev_code (abfd
, info_ptr
) == 0)
6968 m_abbrev_table_holder
6969 = abbrev_table::read (objfile
, abbrev_section
,
6970 m_new_cu
->header
.abbrev_sect_off
);
6972 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
6973 m_abbrev_table_holder
.get ());
6974 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
);
6978 /* Type Unit Groups.
6980 Type Unit Groups are a way to collapse the set of all TUs (type units) into
6981 a more manageable set. The grouping is done by DW_AT_stmt_list entry
6982 so that all types coming from the same compilation (.o file) are grouped
6983 together. A future step could be to put the types in the same symtab as
6984 the CU the types ultimately came from. */
6987 hash_type_unit_group (const void *item
)
6989 const struct type_unit_group
*tu_group
6990 = (const struct type_unit_group
*) item
;
6992 return hash_stmt_list_entry (&tu_group
->hash
);
6996 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
6998 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
6999 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7001 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7004 /* Allocate a hash table for type unit groups. */
7007 allocate_type_unit_groups_table ()
7009 return htab_up (htab_create_alloc (3,
7010 hash_type_unit_group
,
7012 NULL
, xcalloc
, xfree
));
7015 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7016 partial symtabs. We combine several TUs per psymtab to not let the size
7017 of any one psymtab grow too big. */
7018 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7019 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7021 /* Helper routine for get_type_unit_group.
7022 Create the type_unit_group object used to hold one or more TUs. */
7024 static struct type_unit_group
*
7025 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7027 struct dwarf2_per_objfile
*dwarf2_per_objfile
7028 = cu
->per_cu
->dwarf2_per_objfile
;
7029 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7030 struct dwarf2_per_cu_data
*per_cu
;
7031 struct type_unit_group
*tu_group
;
7033 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7034 struct type_unit_group
);
7035 per_cu
= &tu_group
->per_cu
;
7036 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7038 if (dwarf2_per_objfile
->using_index
)
7040 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7041 struct dwarf2_per_cu_quick_data
);
7045 unsigned int line_offset
= to_underlying (line_offset_struct
);
7046 dwarf2_psymtab
*pst
;
7049 /* Give the symtab a useful name for debug purposes. */
7050 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7051 name
= string_printf ("<type_units_%d>",
7052 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7054 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7056 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7057 pst
->anonymous
= true;
7060 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7061 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7066 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7067 STMT_LIST is a DW_AT_stmt_list attribute. */
7069 static struct type_unit_group
*
7070 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7072 struct dwarf2_per_objfile
*dwarf2_per_objfile
7073 = cu
->per_cu
->dwarf2_per_objfile
;
7074 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7075 struct type_unit_group
*tu_group
;
7077 unsigned int line_offset
;
7078 struct type_unit_group type_unit_group_for_lookup
;
7080 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7081 dwarf2_per_objfile
->type_unit_groups
= allocate_type_unit_groups_table ();
7083 /* Do we need to create a new group, or can we use an existing one? */
7087 line_offset
= DW_UNSND (stmt_list
);
7088 ++tu_stats
->nr_symtab_sharers
;
7092 /* Ugh, no stmt_list. Rare, but we have to handle it.
7093 We can do various things here like create one group per TU or
7094 spread them over multiple groups to split up the expansion work.
7095 To avoid worst case scenarios (too many groups or too large groups)
7096 we, umm, group them in bunches. */
7097 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7098 | (tu_stats
->nr_stmt_less_type_units
7099 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7100 ++tu_stats
->nr_stmt_less_type_units
;
7103 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7104 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7105 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
.get (),
7106 &type_unit_group_for_lookup
, INSERT
);
7109 tu_group
= (struct type_unit_group
*) *slot
;
7110 gdb_assert (tu_group
!= NULL
);
7114 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7115 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7117 ++tu_stats
->nr_symtabs
;
7123 /* Partial symbol tables. */
7125 /* Create a psymtab named NAME and assign it to PER_CU.
7127 The caller must fill in the following details:
7128 dirname, textlow, texthigh. */
7130 static dwarf2_psymtab
*
7131 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7133 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7134 dwarf2_psymtab
*pst
;
7136 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7138 pst
->psymtabs_addrmap_supported
= true;
7140 /* This is the glue that links PST into GDB's symbol API. */
7141 pst
->per_cu_data
= per_cu
;
7142 per_cu
->v
.psymtab
= pst
;
7147 /* DIE reader function for process_psymtab_comp_unit. */
7150 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7151 const gdb_byte
*info_ptr
,
7152 struct die_info
*comp_unit_die
,
7153 enum language pretend_language
)
7155 struct dwarf2_cu
*cu
= reader
->cu
;
7156 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7157 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7158 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7160 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7161 dwarf2_psymtab
*pst
;
7162 enum pc_bounds_kind cu_bounds_kind
;
7163 const char *filename
;
7165 gdb_assert (! per_cu
->is_debug_types
);
7167 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7169 /* Allocate a new partial symbol table structure. */
7170 gdb::unique_xmalloc_ptr
<char> debug_filename
;
7171 static const char artificial
[] = "<artificial>";
7172 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7173 if (filename
== NULL
)
7175 else if (strcmp (filename
, artificial
) == 0)
7177 debug_filename
.reset (concat (artificial
, "@",
7178 sect_offset_str (per_cu
->sect_off
),
7180 filename
= debug_filename
.get ();
7183 pst
= create_partial_symtab (per_cu
, filename
);
7185 /* This must be done before calling dwarf2_build_include_psymtabs. */
7186 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7188 baseaddr
= objfile
->text_section_offset ();
7190 dwarf2_find_base_address (comp_unit_die
, cu
);
7192 /* Possibly set the default values of LOWPC and HIGHPC from
7194 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7195 &best_highpc
, cu
, pst
);
7196 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7199 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7202 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7204 /* Store the contiguous range if it is not empty; it can be
7205 empty for CUs with no code. */
7206 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7210 /* Check if comp unit has_children.
7211 If so, read the rest of the partial symbols from this comp unit.
7212 If not, there's no more debug_info for this comp unit. */
7213 if (comp_unit_die
->has_children
)
7215 struct partial_die_info
*first_die
;
7216 CORE_ADDR lowpc
, highpc
;
7218 lowpc
= ((CORE_ADDR
) -1);
7219 highpc
= ((CORE_ADDR
) 0);
7221 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7223 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7224 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7226 /* If we didn't find a lowpc, set it to highpc to avoid
7227 complaints from `maint check'. */
7228 if (lowpc
== ((CORE_ADDR
) -1))
7231 /* If the compilation unit didn't have an explicit address range,
7232 then use the information extracted from its child dies. */
7233 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7236 best_highpc
= highpc
;
7239 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7240 best_lowpc
+ baseaddr
)
7242 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7243 best_highpc
+ baseaddr
)
7246 end_psymtab_common (objfile
, pst
);
7248 if (!cu
->per_cu
->imported_symtabs_empty ())
7251 int len
= cu
->per_cu
->imported_symtabs_size ();
7253 /* Fill in 'dependencies' here; we fill in 'users' in a
7255 pst
->number_of_dependencies
= len
;
7257 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7258 for (i
= 0; i
< len
; ++i
)
7260 pst
->dependencies
[i
]
7261 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7264 cu
->per_cu
->imported_symtabs_free ();
7267 /* Get the list of files included in the current compilation unit,
7268 and build a psymtab for each of them. */
7269 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7271 if (dwarf_read_debug
)
7272 fprintf_unfiltered (gdb_stdlog
,
7273 "Psymtab for %s unit @%s: %s - %s"
7274 ", %d global, %d static syms\n",
7275 per_cu
->is_debug_types
? "type" : "comp",
7276 sect_offset_str (per_cu
->sect_off
),
7277 paddress (gdbarch
, pst
->text_low (objfile
)),
7278 paddress (gdbarch
, pst
->text_high (objfile
)),
7279 pst
->n_global_syms
, pst
->n_static_syms
);
7282 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7283 Process compilation unit THIS_CU for a psymtab. */
7286 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7287 bool want_partial_unit
,
7288 enum language pretend_language
)
7290 /* If this compilation unit was already read in, free the
7291 cached copy in order to read it in again. This is
7292 necessary because we skipped some symbols when we first
7293 read in the compilation unit (see load_partial_dies).
7294 This problem could be avoided, but the benefit is unclear. */
7295 if (this_cu
->cu
!= NULL
)
7296 free_one_cached_comp_unit (this_cu
);
7298 cutu_reader
reader (this_cu
, NULL
, 0, false);
7300 switch (reader
.comp_unit_die
->tag
)
7302 case DW_TAG_compile_unit
:
7303 this_cu
->unit_type
= DW_UT_compile
;
7305 case DW_TAG_partial_unit
:
7306 this_cu
->unit_type
= DW_UT_partial
;
7316 else if (this_cu
->is_debug_types
)
7317 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7318 reader
.comp_unit_die
);
7319 else if (want_partial_unit
7320 || reader
.comp_unit_die
->tag
!= DW_TAG_partial_unit
)
7321 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7322 reader
.comp_unit_die
,
7325 this_cu
->lang
= this_cu
->cu
->language
;
7327 /* Age out any secondary CUs. */
7328 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7331 /* Reader function for build_type_psymtabs. */
7334 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7335 const gdb_byte
*info_ptr
,
7336 struct die_info
*type_unit_die
)
7338 struct dwarf2_per_objfile
*dwarf2_per_objfile
7339 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7340 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7341 struct dwarf2_cu
*cu
= reader
->cu
;
7342 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7343 struct signatured_type
*sig_type
;
7344 struct type_unit_group
*tu_group
;
7345 struct attribute
*attr
;
7346 struct partial_die_info
*first_die
;
7347 CORE_ADDR lowpc
, highpc
;
7348 dwarf2_psymtab
*pst
;
7350 gdb_assert (per_cu
->is_debug_types
);
7351 sig_type
= (struct signatured_type
*) per_cu
;
7353 if (! type_unit_die
->has_children
)
7356 attr
= type_unit_die
->attr (DW_AT_stmt_list
);
7357 tu_group
= get_type_unit_group (cu
, attr
);
7359 if (tu_group
->tus
== nullptr)
7360 tu_group
->tus
= new std::vector
<signatured_type
*>;
7361 tu_group
->tus
->push_back (sig_type
);
7363 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7364 pst
= create_partial_symtab (per_cu
, "");
7365 pst
->anonymous
= true;
7367 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7369 lowpc
= (CORE_ADDR
) -1;
7370 highpc
= (CORE_ADDR
) 0;
7371 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7373 end_psymtab_common (objfile
, pst
);
7376 /* Struct used to sort TUs by their abbreviation table offset. */
7378 struct tu_abbrev_offset
7380 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7381 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7384 signatured_type
*sig_type
;
7385 sect_offset abbrev_offset
;
7388 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
7391 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
7392 const struct tu_abbrev_offset
&b
)
7394 return a
.abbrev_offset
< b
.abbrev_offset
;
7397 /* Efficiently read all the type units.
7398 This does the bulk of the work for build_type_psymtabs.
7400 The efficiency is because we sort TUs by the abbrev table they use and
7401 only read each abbrev table once. In one program there are 200K TUs
7402 sharing 8K abbrev tables.
7404 The main purpose of this function is to support building the
7405 dwarf2_per_objfile->type_unit_groups table.
7406 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
7407 can collapse the search space by grouping them by stmt_list.
7408 The savings can be significant, in the same program from above the 200K TUs
7409 share 8K stmt_list tables.
7411 FUNC is expected to call get_type_unit_group, which will create the
7412 struct type_unit_group if necessary and add it to
7413 dwarf2_per_objfile->type_unit_groups. */
7416 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7418 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7419 abbrev_table_up abbrev_table
;
7420 sect_offset abbrev_offset
;
7422 /* It's up to the caller to not call us multiple times. */
7423 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
7425 if (dwarf2_per_objfile
->all_type_units
.empty ())
7428 /* TUs typically share abbrev tables, and there can be way more TUs than
7429 abbrev tables. Sort by abbrev table to reduce the number of times we
7430 read each abbrev table in.
7431 Alternatives are to punt or to maintain a cache of abbrev tables.
7432 This is simpler and efficient enough for now.
7434 Later we group TUs by their DW_AT_stmt_list value (as this defines the
7435 symtab to use). Typically TUs with the same abbrev offset have the same
7436 stmt_list value too so in practice this should work well.
7438 The basic algorithm here is:
7440 sort TUs by abbrev table
7441 for each TU with same abbrev table:
7442 read abbrev table if first user
7443 read TU top level DIE
7444 [IWBN if DWO skeletons had DW_AT_stmt_list]
7447 if (dwarf_read_debug
)
7448 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
7450 /* Sort in a separate table to maintain the order of all_type_units
7451 for .gdb_index: TU indices directly index all_type_units. */
7452 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
7453 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
7455 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
7456 sorted_by_abbrev
.emplace_back
7457 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
7458 sig_type
->per_cu
.section
,
7459 sig_type
->per_cu
.sect_off
));
7461 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
7462 sort_tu_by_abbrev_offset
);
7464 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
7466 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
7468 /* Switch to the next abbrev table if necessary. */
7469 if (abbrev_table
== NULL
7470 || tu
.abbrev_offset
!= abbrev_offset
)
7472 abbrev_offset
= tu
.abbrev_offset
;
7474 abbrev_table::read (dwarf2_per_objfile
->objfile
,
7475 &dwarf2_per_objfile
->abbrev
,
7477 ++tu_stats
->nr_uniq_abbrev_tables
;
7480 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
7482 if (!reader
.dummy_p
)
7483 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7484 reader
.comp_unit_die
);
7488 /* Print collected type unit statistics. */
7491 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7493 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7495 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
7496 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
7497 dwarf2_per_objfile
->all_type_units
.size ());
7498 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
7499 tu_stats
->nr_uniq_abbrev_tables
);
7500 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
7501 tu_stats
->nr_symtabs
);
7502 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
7503 tu_stats
->nr_symtab_sharers
);
7504 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
7505 tu_stats
->nr_stmt_less_type_units
);
7506 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
7507 tu_stats
->nr_all_type_units_reallocs
);
7510 /* Traversal function for build_type_psymtabs. */
7513 build_type_psymtab_dependencies (void **slot
, void *info
)
7515 struct dwarf2_per_objfile
*dwarf2_per_objfile
7516 = (struct dwarf2_per_objfile
*) info
;
7517 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7518 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
7519 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
7520 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7521 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
7524 gdb_assert (len
> 0);
7525 gdb_assert (per_cu
->type_unit_group_p ());
7527 pst
->number_of_dependencies
= len
;
7528 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
7529 for (i
= 0; i
< len
; ++i
)
7531 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
7532 gdb_assert (iter
->per_cu
.is_debug_types
);
7533 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
7534 iter
->type_unit_group
= tu_group
;
7537 delete tu_group
->tus
;
7538 tu_group
->tus
= nullptr;
7543 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7544 Build partial symbol tables for the .debug_types comp-units. */
7547 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7549 if (! create_all_type_units (dwarf2_per_objfile
))
7552 build_type_psymtabs_1 (dwarf2_per_objfile
);
7555 /* Traversal function for process_skeletonless_type_unit.
7556 Read a TU in a DWO file and build partial symbols for it. */
7559 process_skeletonless_type_unit (void **slot
, void *info
)
7561 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
7562 struct dwarf2_per_objfile
*dwarf2_per_objfile
7563 = (struct dwarf2_per_objfile
*) info
;
7564 struct signatured_type find_entry
, *entry
;
7566 /* If this TU doesn't exist in the global table, add it and read it in. */
7568 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7569 dwarf2_per_objfile
->signatured_types
= allocate_signatured_type_table ();
7571 find_entry
.signature
= dwo_unit
->signature
;
7572 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
.get (),
7573 &find_entry
, INSERT
);
7574 /* If we've already seen this type there's nothing to do. What's happening
7575 is we're doing our own version of comdat-folding here. */
7579 /* This does the job that create_all_type_units would have done for
7581 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
7582 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
7585 /* This does the job that build_type_psymtabs_1 would have done. */
7586 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, false);
7587 if (!reader
.dummy_p
)
7588 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
7589 reader
.comp_unit_die
);
7594 /* Traversal function for process_skeletonless_type_units. */
7597 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
7599 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
7601 if (dwo_file
->tus
!= NULL
)
7602 htab_traverse_noresize (dwo_file
->tus
.get (),
7603 process_skeletonless_type_unit
, info
);
7608 /* Scan all TUs of DWO files, verifying we've processed them.
7609 This is needed in case a TU was emitted without its skeleton.
7610 Note: This can't be done until we know what all the DWO files are. */
7613 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7615 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
7616 if (get_dwp_file (dwarf2_per_objfile
) == NULL
7617 && dwarf2_per_objfile
->dwo_files
!= NULL
)
7619 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
7620 process_dwo_file_for_skeletonless_type_units
,
7621 dwarf2_per_objfile
);
7625 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
7628 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7630 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7632 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
7637 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
7639 /* Set the 'user' field only if it is not already set. */
7640 if (pst
->dependencies
[j
]->user
== NULL
)
7641 pst
->dependencies
[j
]->user
= pst
;
7646 /* Build the partial symbol table by doing a quick pass through the
7647 .debug_info and .debug_abbrev sections. */
7650 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7652 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7654 if (dwarf_read_debug
)
7656 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
7657 objfile_name (objfile
));
7660 scoped_restore restore_reading_psyms
7661 = make_scoped_restore (&dwarf2_per_objfile
->reading_partial_symbols
,
7664 dwarf2_per_objfile
->info
.read (objfile
);
7666 /* Any cached compilation units will be linked by the per-objfile
7667 read_in_chain. Make sure to free them when we're done. */
7668 free_cached_comp_units
freer (dwarf2_per_objfile
);
7670 build_type_psymtabs (dwarf2_per_objfile
);
7672 create_all_comp_units (dwarf2_per_objfile
);
7674 /* Create a temporary address map on a temporary obstack. We later
7675 copy this to the final obstack. */
7676 auto_obstack temp_obstack
;
7678 scoped_restore save_psymtabs_addrmap
7679 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
7680 addrmap_create_mutable (&temp_obstack
));
7682 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
7683 process_psymtab_comp_unit (per_cu
, false, language_minimal
);
7685 /* This has to wait until we read the CUs, we need the list of DWOs. */
7686 process_skeletonless_type_units (dwarf2_per_objfile
);
7688 /* Now that all TUs have been processed we can fill in the dependencies. */
7689 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
7691 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
.get (),
7692 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
7695 if (dwarf_read_debug
)
7696 print_tu_stats (dwarf2_per_objfile
);
7698 set_partial_user (dwarf2_per_objfile
);
7700 objfile
->partial_symtabs
->psymtabs_addrmap
7701 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
7702 objfile
->partial_symtabs
->obstack ());
7703 /* At this point we want to keep the address map. */
7704 save_psymtabs_addrmap
.release ();
7706 if (dwarf_read_debug
)
7707 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
7708 objfile_name (objfile
));
7711 /* Load the partial DIEs for a secondary CU into memory.
7712 This is also used when rereading a primary CU with load_all_dies. */
7715 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
7717 cutu_reader
reader (this_cu
, NULL
, 1, false);
7719 if (!reader
.dummy_p
)
7721 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
7724 /* Check if comp unit has_children.
7725 If so, read the rest of the partial symbols from this comp unit.
7726 If not, there's no more debug_info for this comp unit. */
7727 if (reader
.comp_unit_die
->has_children
)
7728 load_partial_dies (&reader
, reader
.info_ptr
, 0);
7735 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7736 struct dwarf2_section_info
*section
,
7737 struct dwarf2_section_info
*abbrev_section
,
7738 unsigned int is_dwz
)
7740 const gdb_byte
*info_ptr
;
7741 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7743 if (dwarf_read_debug
)
7744 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
7745 section
->get_name (),
7746 section
->get_file_name ());
7748 section
->read (objfile
);
7750 info_ptr
= section
->buffer
;
7752 while (info_ptr
< section
->buffer
+ section
->size
)
7754 struct dwarf2_per_cu_data
*this_cu
;
7756 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
7758 comp_unit_head cu_header
;
7759 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
7760 abbrev_section
, info_ptr
,
7761 rcuh_kind::COMPILE
);
7763 /* Save the compilation unit for later lookup. */
7764 if (cu_header
.unit_type
!= DW_UT_type
)
7766 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
7767 struct dwarf2_per_cu_data
);
7768 memset (this_cu
, 0, sizeof (*this_cu
));
7772 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
7773 struct signatured_type
);
7774 memset (sig_type
, 0, sizeof (*sig_type
));
7775 sig_type
->signature
= cu_header
.signature
;
7776 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
7777 this_cu
= &sig_type
->per_cu
;
7779 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
7780 this_cu
->sect_off
= sect_off
;
7781 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
7782 this_cu
->is_dwz
= is_dwz
;
7783 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7784 this_cu
->section
= section
;
7786 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
7788 info_ptr
= info_ptr
+ this_cu
->length
;
7792 /* Create a list of all compilation units in OBJFILE.
7793 This is only done for -readnow and building partial symtabs. */
7796 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
7798 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
7799 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
7800 &dwarf2_per_objfile
->abbrev
, 0);
7802 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
7804 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
7808 /* Process all loaded DIEs for compilation unit CU, starting at
7809 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
7810 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
7811 DW_AT_ranges). See the comments of add_partial_subprogram on how
7812 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
7815 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
7816 CORE_ADDR
*highpc
, int set_addrmap
,
7817 struct dwarf2_cu
*cu
)
7819 struct partial_die_info
*pdi
;
7821 /* Now, march along the PDI's, descending into ones which have
7822 interesting children but skipping the children of the other ones,
7823 until we reach the end of the compilation unit. */
7831 /* Anonymous namespaces or modules have no name but have interesting
7832 children, so we need to look at them. Ditto for anonymous
7835 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
7836 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
7837 || pdi
->tag
== DW_TAG_imported_unit
7838 || pdi
->tag
== DW_TAG_inlined_subroutine
)
7842 case DW_TAG_subprogram
:
7843 case DW_TAG_inlined_subroutine
:
7844 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7846 case DW_TAG_constant
:
7847 case DW_TAG_variable
:
7848 case DW_TAG_typedef
:
7849 case DW_TAG_union_type
:
7850 if (!pdi
->is_declaration
)
7852 add_partial_symbol (pdi
, cu
);
7855 case DW_TAG_class_type
:
7856 case DW_TAG_interface_type
:
7857 case DW_TAG_structure_type
:
7858 if (!pdi
->is_declaration
)
7860 add_partial_symbol (pdi
, cu
);
7862 if ((cu
->language
== language_rust
7863 || cu
->language
== language_cplus
) && pdi
->has_children
)
7864 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
7867 case DW_TAG_enumeration_type
:
7868 if (!pdi
->is_declaration
)
7869 add_partial_enumeration (pdi
, cu
);
7871 case DW_TAG_base_type
:
7872 case DW_TAG_subrange_type
:
7873 /* File scope base type definitions are added to the partial
7875 add_partial_symbol (pdi
, cu
);
7877 case DW_TAG_namespace
:
7878 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7881 if (!pdi
->is_declaration
)
7882 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
7884 case DW_TAG_imported_unit
:
7886 struct dwarf2_per_cu_data
*per_cu
;
7888 /* For now we don't handle imported units in type units. */
7889 if (cu
->per_cu
->is_debug_types
)
7891 error (_("Dwarf Error: DW_TAG_imported_unit is not"
7892 " supported in type units [in module %s]"),
7893 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
7896 per_cu
= dwarf2_find_containing_comp_unit
7897 (pdi
->d
.sect_off
, pdi
->is_dwz
,
7898 cu
->per_cu
->dwarf2_per_objfile
);
7900 /* Go read the partial unit, if needed. */
7901 if (per_cu
->v
.psymtab
== NULL
)
7902 process_psymtab_comp_unit (per_cu
, true, cu
->language
);
7904 cu
->per_cu
->imported_symtabs_push (per_cu
);
7907 case DW_TAG_imported_declaration
:
7908 add_partial_symbol (pdi
, cu
);
7915 /* If the die has a sibling, skip to the sibling. */
7917 pdi
= pdi
->die_sibling
;
7921 /* Functions used to compute the fully scoped name of a partial DIE.
7923 Normally, this is simple. For C++, the parent DIE's fully scoped
7924 name is concatenated with "::" and the partial DIE's name.
7925 Enumerators are an exception; they use the scope of their parent
7926 enumeration type, i.e. the name of the enumeration type is not
7927 prepended to the enumerator.
7929 There are two complexities. One is DW_AT_specification; in this
7930 case "parent" means the parent of the target of the specification,
7931 instead of the direct parent of the DIE. The other is compilers
7932 which do not emit DW_TAG_namespace; in this case we try to guess
7933 the fully qualified name of structure types from their members'
7934 linkage names. This must be done using the DIE's children rather
7935 than the children of any DW_AT_specification target. We only need
7936 to do this for structures at the top level, i.e. if the target of
7937 any DW_AT_specification (if any; otherwise the DIE itself) does not
7940 /* Compute the scope prefix associated with PDI's parent, in
7941 compilation unit CU. The result will be allocated on CU's
7942 comp_unit_obstack, or a copy of the already allocated PDI->NAME
7943 field. NULL is returned if no prefix is necessary. */
7945 partial_die_parent_scope (struct partial_die_info
*pdi
,
7946 struct dwarf2_cu
*cu
)
7948 const char *grandparent_scope
;
7949 struct partial_die_info
*parent
, *real_pdi
;
7951 /* We need to look at our parent DIE; if we have a DW_AT_specification,
7952 then this means the parent of the specification DIE. */
7955 while (real_pdi
->has_specification
)
7957 auto res
= find_partial_die (real_pdi
->spec_offset
,
7958 real_pdi
->spec_is_dwz
, cu
);
7963 parent
= real_pdi
->die_parent
;
7967 if (parent
->scope_set
)
7968 return parent
->scope
;
7972 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
7974 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
7975 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
7976 Work around this problem here. */
7977 if (cu
->language
== language_cplus
7978 && parent
->tag
== DW_TAG_namespace
7979 && strcmp (parent
->name
, "::") == 0
7980 && grandparent_scope
== NULL
)
7982 parent
->scope
= NULL
;
7983 parent
->scope_set
= 1;
7987 /* Nested subroutines in Fortran get a prefix. */
7988 if (pdi
->tag
== DW_TAG_enumerator
)
7989 /* Enumerators should not get the name of the enumeration as a prefix. */
7990 parent
->scope
= grandparent_scope
;
7991 else if (parent
->tag
== DW_TAG_namespace
7992 || parent
->tag
== DW_TAG_module
7993 || parent
->tag
== DW_TAG_structure_type
7994 || parent
->tag
== DW_TAG_class_type
7995 || parent
->tag
== DW_TAG_interface_type
7996 || parent
->tag
== DW_TAG_union_type
7997 || parent
->tag
== DW_TAG_enumeration_type
7998 || (cu
->language
== language_fortran
7999 && parent
->tag
== DW_TAG_subprogram
8000 && pdi
->tag
== DW_TAG_subprogram
))
8002 if (grandparent_scope
== NULL
)
8003 parent
->scope
= parent
->name
;
8005 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8007 parent
->name
, 0, cu
);
8011 /* FIXME drow/2004-04-01: What should we be doing with
8012 function-local names? For partial symbols, we should probably be
8014 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8015 dwarf_tag_name (parent
->tag
),
8016 sect_offset_str (pdi
->sect_off
));
8017 parent
->scope
= grandparent_scope
;
8020 parent
->scope_set
= 1;
8021 return parent
->scope
;
8024 /* Return the fully scoped name associated with PDI, from compilation unit
8025 CU. The result will be allocated with malloc. */
8027 static gdb::unique_xmalloc_ptr
<char>
8028 partial_die_full_name (struct partial_die_info
*pdi
,
8029 struct dwarf2_cu
*cu
)
8031 const char *parent_scope
;
8033 /* If this is a template instantiation, we can not work out the
8034 template arguments from partial DIEs. So, unfortunately, we have
8035 to go through the full DIEs. At least any work we do building
8036 types here will be reused if full symbols are loaded later. */
8037 if (pdi
->has_template_arguments
)
8041 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8043 struct die_info
*die
;
8044 struct attribute attr
;
8045 struct dwarf2_cu
*ref_cu
= cu
;
8047 /* DW_FORM_ref_addr is using section offset. */
8048 attr
.name
= (enum dwarf_attribute
) 0;
8049 attr
.form
= DW_FORM_ref_addr
;
8050 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8051 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8053 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8057 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8058 if (parent_scope
== NULL
)
8061 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8066 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8068 struct dwarf2_per_objfile
*dwarf2_per_objfile
8069 = cu
->per_cu
->dwarf2_per_objfile
;
8070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8071 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8073 const char *actual_name
= NULL
;
8076 baseaddr
= objfile
->text_section_offset ();
8078 gdb::unique_xmalloc_ptr
<char> built_actual_name
8079 = partial_die_full_name (pdi
, cu
);
8080 if (built_actual_name
!= NULL
)
8081 actual_name
= built_actual_name
.get ();
8083 if (actual_name
== NULL
)
8084 actual_name
= pdi
->name
;
8088 case DW_TAG_inlined_subroutine
:
8089 case DW_TAG_subprogram
:
8090 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8092 if (pdi
->is_external
8093 || cu
->language
== language_ada
8094 || (cu
->language
== language_fortran
8095 && pdi
->die_parent
!= NULL
8096 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8098 /* Normally, only "external" DIEs are part of the global scope.
8099 But in Ada and Fortran, we want to be able to access nested
8100 procedures globally. So all Ada and Fortran subprograms are
8101 stored in the global scope. */
8102 add_psymbol_to_list (actual_name
,
8103 built_actual_name
!= NULL
,
8104 VAR_DOMAIN
, LOC_BLOCK
,
8105 SECT_OFF_TEXT (objfile
),
8106 psymbol_placement::GLOBAL
,
8108 cu
->language
, objfile
);
8112 add_psymbol_to_list (actual_name
,
8113 built_actual_name
!= NULL
,
8114 VAR_DOMAIN
, LOC_BLOCK
,
8115 SECT_OFF_TEXT (objfile
),
8116 psymbol_placement::STATIC
,
8117 addr
, cu
->language
, objfile
);
8120 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8121 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8123 case DW_TAG_constant
:
8124 add_psymbol_to_list (actual_name
,
8125 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8126 -1, (pdi
->is_external
8127 ? psymbol_placement::GLOBAL
8128 : psymbol_placement::STATIC
),
8129 0, cu
->language
, objfile
);
8131 case DW_TAG_variable
:
8133 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8137 && !dwarf2_per_objfile
->has_section_at_zero
)
8139 /* A global or static variable may also have been stripped
8140 out by the linker if unused, in which case its address
8141 will be nullified; do not add such variables into partial
8142 symbol table then. */
8144 else if (pdi
->is_external
)
8147 Don't enter into the minimal symbol tables as there is
8148 a minimal symbol table entry from the ELF symbols already.
8149 Enter into partial symbol table if it has a location
8150 descriptor or a type.
8151 If the location descriptor is missing, new_symbol will create
8152 a LOC_UNRESOLVED symbol, the address of the variable will then
8153 be determined from the minimal symbol table whenever the variable
8155 The address for the partial symbol table entry is not
8156 used by GDB, but it comes in handy for debugging partial symbol
8159 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8160 add_psymbol_to_list (actual_name
,
8161 built_actual_name
!= NULL
,
8162 VAR_DOMAIN
, LOC_STATIC
,
8163 SECT_OFF_TEXT (objfile
),
8164 psymbol_placement::GLOBAL
,
8165 addr
, cu
->language
, objfile
);
8169 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8171 /* Static Variable. Skip symbols whose value we cannot know (those
8172 without location descriptors or constant values). */
8173 if (!has_loc
&& !pdi
->has_const_value
)
8176 add_psymbol_to_list (actual_name
,
8177 built_actual_name
!= NULL
,
8178 VAR_DOMAIN
, LOC_STATIC
,
8179 SECT_OFF_TEXT (objfile
),
8180 psymbol_placement::STATIC
,
8182 cu
->language
, objfile
);
8185 case DW_TAG_typedef
:
8186 case DW_TAG_base_type
:
8187 case DW_TAG_subrange_type
:
8188 add_psymbol_to_list (actual_name
,
8189 built_actual_name
!= NULL
,
8190 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8191 psymbol_placement::STATIC
,
8192 0, cu
->language
, objfile
);
8194 case DW_TAG_imported_declaration
:
8195 case DW_TAG_namespace
:
8196 add_psymbol_to_list (actual_name
,
8197 built_actual_name
!= NULL
,
8198 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8199 psymbol_placement::GLOBAL
,
8200 0, cu
->language
, objfile
);
8203 /* With Fortran 77 there might be a "BLOCK DATA" module
8204 available without any name. If so, we skip the module as it
8205 doesn't bring any value. */
8206 if (actual_name
!= nullptr)
8207 add_psymbol_to_list (actual_name
,
8208 built_actual_name
!= NULL
,
8209 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8210 psymbol_placement::GLOBAL
,
8211 0, cu
->language
, objfile
);
8213 case DW_TAG_class_type
:
8214 case DW_TAG_interface_type
:
8215 case DW_TAG_structure_type
:
8216 case DW_TAG_union_type
:
8217 case DW_TAG_enumeration_type
:
8218 /* Skip external references. The DWARF standard says in the section
8219 about "Structure, Union, and Class Type Entries": "An incomplete
8220 structure, union or class type is represented by a structure,
8221 union or class entry that does not have a byte size attribute
8222 and that has a DW_AT_declaration attribute." */
8223 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8226 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8227 static vs. global. */
8228 add_psymbol_to_list (actual_name
,
8229 built_actual_name
!= NULL
,
8230 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8231 cu
->language
== language_cplus
8232 ? psymbol_placement::GLOBAL
8233 : psymbol_placement::STATIC
,
8234 0, cu
->language
, objfile
);
8237 case DW_TAG_enumerator
:
8238 add_psymbol_to_list (actual_name
,
8239 built_actual_name
!= NULL
,
8240 VAR_DOMAIN
, LOC_CONST
, -1,
8241 cu
->language
== language_cplus
8242 ? psymbol_placement::GLOBAL
8243 : psymbol_placement::STATIC
,
8244 0, cu
->language
, objfile
);
8251 /* Read a partial die corresponding to a namespace; also, add a symbol
8252 corresponding to that namespace to the symbol table. NAMESPACE is
8253 the name of the enclosing namespace. */
8256 add_partial_namespace (struct partial_die_info
*pdi
,
8257 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8258 int set_addrmap
, struct dwarf2_cu
*cu
)
8260 /* Add a symbol for the namespace. */
8262 add_partial_symbol (pdi
, cu
);
8264 /* Now scan partial symbols in that namespace. */
8266 if (pdi
->has_children
)
8267 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8270 /* Read a partial die corresponding to a Fortran module. */
8273 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8274 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8276 /* Add a symbol for the namespace. */
8278 add_partial_symbol (pdi
, cu
);
8280 /* Now scan partial symbols in that module. */
8282 if (pdi
->has_children
)
8283 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8286 /* Read a partial die corresponding to a subprogram or an inlined
8287 subprogram and create a partial symbol for that subprogram.
8288 When the CU language allows it, this routine also defines a partial
8289 symbol for each nested subprogram that this subprogram contains.
8290 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8291 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8293 PDI may also be a lexical block, in which case we simply search
8294 recursively for subprograms defined inside that lexical block.
8295 Again, this is only performed when the CU language allows this
8296 type of definitions. */
8299 add_partial_subprogram (struct partial_die_info
*pdi
,
8300 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8301 int set_addrmap
, struct dwarf2_cu
*cu
)
8303 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8305 if (pdi
->has_pc_info
)
8307 if (pdi
->lowpc
< *lowpc
)
8308 *lowpc
= pdi
->lowpc
;
8309 if (pdi
->highpc
> *highpc
)
8310 *highpc
= pdi
->highpc
;
8313 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8314 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8316 CORE_ADDR this_highpc
;
8317 CORE_ADDR this_lowpc
;
8319 baseaddr
= objfile
->text_section_offset ();
8321 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8322 pdi
->lowpc
+ baseaddr
)
8325 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8326 pdi
->highpc
+ baseaddr
)
8328 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8329 this_lowpc
, this_highpc
- 1,
8330 cu
->per_cu
->v
.psymtab
);
8334 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8336 if (!pdi
->is_declaration
)
8337 /* Ignore subprogram DIEs that do not have a name, they are
8338 illegal. Do not emit a complaint at this point, we will
8339 do so when we convert this psymtab into a symtab. */
8341 add_partial_symbol (pdi
, cu
);
8345 if (! pdi
->has_children
)
8348 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8350 pdi
= pdi
->die_child
;
8354 if (pdi
->tag
== DW_TAG_subprogram
8355 || pdi
->tag
== DW_TAG_inlined_subroutine
8356 || pdi
->tag
== DW_TAG_lexical_block
)
8357 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8358 pdi
= pdi
->die_sibling
;
8363 /* Read a partial die corresponding to an enumeration type. */
8366 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8367 struct dwarf2_cu
*cu
)
8369 struct partial_die_info
*pdi
;
8371 if (enum_pdi
->name
!= NULL
)
8372 add_partial_symbol (enum_pdi
, cu
);
8374 pdi
= enum_pdi
->die_child
;
8377 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8378 complaint (_("malformed enumerator DIE ignored"));
8380 add_partial_symbol (pdi
, cu
);
8381 pdi
= pdi
->die_sibling
;
8385 /* Return the initial uleb128 in the die at INFO_PTR. */
8388 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
8390 unsigned int bytes_read
;
8392 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8395 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
8396 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
8398 Return the corresponding abbrev, or NULL if the number is zero (indicating
8399 an empty DIE). In either case *BYTES_READ will be set to the length of
8400 the initial number. */
8402 static struct abbrev_info
*
8403 peek_die_abbrev (const die_reader_specs
&reader
,
8404 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
8406 dwarf2_cu
*cu
= reader
.cu
;
8407 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
8408 unsigned int abbrev_number
8409 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
8411 if (abbrev_number
== 0)
8414 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
8417 error (_("Dwarf Error: Could not find abbrev number %d in %s"
8418 " at offset %s [in module %s]"),
8419 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
8420 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
8426 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8427 Returns a pointer to the end of a series of DIEs, terminated by an empty
8428 DIE. Any children of the skipped DIEs will also be skipped. */
8430 static const gdb_byte
*
8431 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
8435 unsigned int bytes_read
;
8436 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
8439 return info_ptr
+ bytes_read
;
8441 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
8445 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
8446 INFO_PTR should point just after the initial uleb128 of a DIE, and the
8447 abbrev corresponding to that skipped uleb128 should be passed in
8448 ABBREV. Returns a pointer to this DIE's sibling, skipping any
8451 static const gdb_byte
*
8452 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
8453 struct abbrev_info
*abbrev
)
8455 unsigned int bytes_read
;
8456 struct attribute attr
;
8457 bfd
*abfd
= reader
->abfd
;
8458 struct dwarf2_cu
*cu
= reader
->cu
;
8459 const gdb_byte
*buffer
= reader
->buffer
;
8460 const gdb_byte
*buffer_end
= reader
->buffer_end
;
8461 unsigned int form
, i
;
8463 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
8465 /* The only abbrev we care about is DW_AT_sibling. */
8466 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
8469 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
8471 if (attr
.form
== DW_FORM_ref_addr
)
8472 complaint (_("ignoring absolute DW_AT_sibling"));
8475 sect_offset off
= attr
.get_ref_die_offset ();
8476 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
8478 if (sibling_ptr
< info_ptr
)
8479 complaint (_("DW_AT_sibling points backwards"));
8480 else if (sibling_ptr
> reader
->buffer_end
)
8481 reader
->die_section
->overflow_complaint ();
8487 /* If it isn't DW_AT_sibling, skip this attribute. */
8488 form
= abbrev
->attrs
[i
].form
;
8492 case DW_FORM_ref_addr
:
8493 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
8494 and later it is offset sized. */
8495 if (cu
->header
.version
== 2)
8496 info_ptr
+= cu
->header
.addr_size
;
8498 info_ptr
+= cu
->header
.offset_size
;
8500 case DW_FORM_GNU_ref_alt
:
8501 info_ptr
+= cu
->header
.offset_size
;
8504 info_ptr
+= cu
->header
.addr_size
;
8512 case DW_FORM_flag_present
:
8513 case DW_FORM_implicit_const
:
8530 case DW_FORM_ref_sig8
:
8533 case DW_FORM_data16
:
8536 case DW_FORM_string
:
8537 read_direct_string (abfd
, info_ptr
, &bytes_read
);
8538 info_ptr
+= bytes_read
;
8540 case DW_FORM_sec_offset
:
8542 case DW_FORM_GNU_strp_alt
:
8543 info_ptr
+= cu
->header
.offset_size
;
8545 case DW_FORM_exprloc
:
8547 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8548 info_ptr
+= bytes_read
;
8550 case DW_FORM_block1
:
8551 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
8553 case DW_FORM_block2
:
8554 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
8556 case DW_FORM_block4
:
8557 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
8563 case DW_FORM_ref_udata
:
8564 case DW_FORM_GNU_addr_index
:
8565 case DW_FORM_GNU_str_index
:
8566 case DW_FORM_rnglistx
:
8567 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
8569 case DW_FORM_indirect
:
8570 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8571 info_ptr
+= bytes_read
;
8572 /* We need to continue parsing from here, so just go back to
8574 goto skip_attribute
;
8577 error (_("Dwarf Error: Cannot handle %s "
8578 "in DWARF reader [in module %s]"),
8579 dwarf_form_name (form
),
8580 bfd_get_filename (abfd
));
8584 if (abbrev
->has_children
)
8585 return skip_children (reader
, info_ptr
);
8590 /* Locate ORIG_PDI's sibling.
8591 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
8593 static const gdb_byte
*
8594 locate_pdi_sibling (const struct die_reader_specs
*reader
,
8595 struct partial_die_info
*orig_pdi
,
8596 const gdb_byte
*info_ptr
)
8598 /* Do we know the sibling already? */
8600 if (orig_pdi
->sibling
)
8601 return orig_pdi
->sibling
;
8603 /* Are there any children to deal with? */
8605 if (!orig_pdi
->has_children
)
8608 /* Skip the children the long way. */
8610 return skip_children (reader
, info_ptr
);
8613 /* Expand this partial symbol table into a full symbol table. SELF is
8617 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
8619 struct dwarf2_per_objfile
*dwarf2_per_objfile
8620 = get_dwarf2_per_objfile (objfile
);
8622 gdb_assert (!readin
);
8623 /* If this psymtab is constructed from a debug-only objfile, the
8624 has_section_at_zero flag will not necessarily be correct. We
8625 can get the correct value for this flag by looking at the data
8626 associated with the (presumably stripped) associated objfile. */
8627 if (objfile
->separate_debug_objfile_backlink
)
8629 struct dwarf2_per_objfile
*dpo_backlink
8630 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
8632 dwarf2_per_objfile
->has_section_at_zero
8633 = dpo_backlink
->has_section_at_zero
;
8636 expand_psymtab (objfile
);
8638 process_cu_includes (dwarf2_per_objfile
);
8641 /* Reading in full CUs. */
8643 /* Add PER_CU to the queue. */
8646 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
8647 enum language pretend_language
)
8650 per_cu
->dwarf2_per_objfile
->queue
.emplace (per_cu
, pretend_language
);
8653 /* If PER_CU is not yet queued, add it to the queue.
8654 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
8656 The result is non-zero if PER_CU was queued, otherwise the result is zero
8657 meaning either PER_CU is already queued or it is already loaded.
8659 N.B. There is an invariant here that if a CU is queued then it is loaded.
8660 The caller is required to load PER_CU if we return non-zero. */
8663 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
8664 struct dwarf2_per_cu_data
*per_cu
,
8665 enum language pretend_language
)
8667 /* We may arrive here during partial symbol reading, if we need full
8668 DIEs to process an unusual case (e.g. template arguments). Do
8669 not queue PER_CU, just tell our caller to load its DIEs. */
8670 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
8672 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
8677 /* Mark the dependence relation so that we don't flush PER_CU
8679 if (dependent_cu
!= NULL
)
8680 dwarf2_add_dependence (dependent_cu
, per_cu
);
8682 /* If it's already on the queue, we have nothing to do. */
8686 /* If the compilation unit is already loaded, just mark it as
8688 if (per_cu
->cu
!= NULL
)
8690 per_cu
->cu
->last_used
= 0;
8694 /* Add it to the queue. */
8695 queue_comp_unit (per_cu
, pretend_language
);
8700 /* Process the queue. */
8703 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8705 if (dwarf_read_debug
)
8707 fprintf_unfiltered (gdb_stdlog
,
8708 "Expanding one or more symtabs of objfile %s ...\n",
8709 objfile_name (dwarf2_per_objfile
->objfile
));
8712 /* The queue starts out with one item, but following a DIE reference
8713 may load a new CU, adding it to the end of the queue. */
8714 while (!dwarf2_per_objfile
->queue
.empty ())
8716 dwarf2_queue_item
&item
= dwarf2_per_objfile
->queue
.front ();
8718 if ((dwarf2_per_objfile
->using_index
8719 ? !item
.per_cu
->v
.quick
->compunit_symtab
8720 : (item
.per_cu
->v
.psymtab
&& !item
.per_cu
->v
.psymtab
->readin
))
8721 /* Skip dummy CUs. */
8722 && item
.per_cu
->cu
!= NULL
)
8724 struct dwarf2_per_cu_data
*per_cu
= item
.per_cu
;
8725 unsigned int debug_print_threshold
;
8728 if (per_cu
->is_debug_types
)
8730 struct signatured_type
*sig_type
=
8731 (struct signatured_type
*) per_cu
;
8733 sprintf (buf
, "TU %s at offset %s",
8734 hex_string (sig_type
->signature
),
8735 sect_offset_str (per_cu
->sect_off
));
8736 /* There can be 100s of TUs.
8737 Only print them in verbose mode. */
8738 debug_print_threshold
= 2;
8742 sprintf (buf
, "CU at offset %s",
8743 sect_offset_str (per_cu
->sect_off
));
8744 debug_print_threshold
= 1;
8747 if (dwarf_read_debug
>= debug_print_threshold
)
8748 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
8750 if (per_cu
->is_debug_types
)
8751 process_full_type_unit (per_cu
, item
.pretend_language
);
8753 process_full_comp_unit (per_cu
, item
.pretend_language
);
8755 if (dwarf_read_debug
>= debug_print_threshold
)
8756 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
8759 item
.per_cu
->queued
= 0;
8760 dwarf2_per_objfile
->queue
.pop ();
8763 if (dwarf_read_debug
)
8765 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
8766 objfile_name (dwarf2_per_objfile
->objfile
));
8770 /* Read in full symbols for PST, and anything it depends on. */
8773 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
8778 expand_dependencies (objfile
);
8780 dw2_do_instantiate_symtab (per_cu_data
, false);
8781 gdb_assert (get_compunit_symtab () != nullptr);
8784 /* Trivial hash function for die_info: the hash value of a DIE
8785 is its offset in .debug_info for this objfile. */
8788 die_hash (const void *item
)
8790 const struct die_info
*die
= (const struct die_info
*) item
;
8792 return to_underlying (die
->sect_off
);
8795 /* Trivial comparison function for die_info structures: two DIEs
8796 are equal if they have the same offset. */
8799 die_eq (const void *item_lhs
, const void *item_rhs
)
8801 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
8802 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
8804 return die_lhs
->sect_off
== die_rhs
->sect_off
;
8807 /* Load the DIEs associated with PER_CU into memory. */
8810 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8812 enum language pretend_language
)
8814 gdb_assert (! this_cu
->is_debug_types
);
8816 cutu_reader
reader (this_cu
, NULL
, 1, skip_partial
);
8820 struct dwarf2_cu
*cu
= reader
.cu
;
8821 const gdb_byte
*info_ptr
= reader
.info_ptr
;
8823 gdb_assert (cu
->die_hash
== NULL
);
8825 htab_create_alloc_ex (cu
->header
.length
/ 12,
8829 &cu
->comp_unit_obstack
,
8830 hashtab_obstack_allocate
,
8831 dummy_obstack_deallocate
);
8833 if (reader
.comp_unit_die
->has_children
)
8834 reader
.comp_unit_die
->child
8835 = read_die_and_siblings (&reader
, reader
.info_ptr
,
8836 &info_ptr
, reader
.comp_unit_die
);
8837 cu
->dies
= reader
.comp_unit_die
;
8838 /* comp_unit_die is not stored in die_hash, no need. */
8840 /* We try not to read any attributes in this function, because not
8841 all CUs needed for references have been loaded yet, and symbol
8842 table processing isn't initialized. But we have to set the CU language,
8843 or we won't be able to build types correctly.
8844 Similarly, if we do not read the producer, we can not apply
8845 producer-specific interpretation. */
8846 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
8851 /* Add a DIE to the delayed physname list. */
8854 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
8855 const char *name
, struct die_info
*die
,
8856 struct dwarf2_cu
*cu
)
8858 struct delayed_method_info mi
;
8860 mi
.fnfield_index
= fnfield_index
;
8864 cu
->method_list
.push_back (mi
);
8867 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
8868 "const" / "volatile". If so, decrements LEN by the length of the
8869 modifier and return true. Otherwise return false. */
8873 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
8875 size_t mod_len
= sizeof (mod
) - 1;
8876 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
8884 /* Compute the physnames of any methods on the CU's method list.
8886 The computation of method physnames is delayed in order to avoid the
8887 (bad) condition that one of the method's formal parameters is of an as yet
8891 compute_delayed_physnames (struct dwarf2_cu
*cu
)
8893 /* Only C++ delays computing physnames. */
8894 if (cu
->method_list
.empty ())
8896 gdb_assert (cu
->language
== language_cplus
);
8898 for (const delayed_method_info
&mi
: cu
->method_list
)
8900 const char *physname
;
8901 struct fn_fieldlist
*fn_flp
8902 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
8903 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
8904 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
8905 = physname
? physname
: "";
8907 /* Since there's no tag to indicate whether a method is a
8908 const/volatile overload, extract that information out of the
8910 if (physname
!= NULL
)
8912 size_t len
= strlen (physname
);
8916 if (physname
[len
] == ')') /* shortcut */
8918 else if (check_modifier (physname
, len
, " const"))
8919 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
8920 else if (check_modifier (physname
, len
, " volatile"))
8921 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
8928 /* The list is no longer needed. */
8929 cu
->method_list
.clear ();
8932 /* Go objects should be embedded in a DW_TAG_module DIE,
8933 and it's not clear if/how imported objects will appear.
8934 To keep Go support simple until that's worked out,
8935 go back through what we've read and create something usable.
8936 We could do this while processing each DIE, and feels kinda cleaner,
8937 but that way is more invasive.
8938 This is to, for example, allow the user to type "p var" or "b main"
8939 without having to specify the package name, and allow lookups
8940 of module.object to work in contexts that use the expression
8944 fixup_go_packaging (struct dwarf2_cu
*cu
)
8946 gdb::unique_xmalloc_ptr
<char> package_name
;
8947 struct pending
*list
;
8950 for (list
= *cu
->get_builder ()->get_global_symbols ();
8954 for (i
= 0; i
< list
->nsyms
; ++i
)
8956 struct symbol
*sym
= list
->symbol
[i
];
8958 if (sym
->language () == language_go
8959 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
8961 gdb::unique_xmalloc_ptr
<char> this_package_name
8962 (go_symbol_package_name (sym
));
8964 if (this_package_name
== NULL
)
8966 if (package_name
== NULL
)
8967 package_name
= std::move (this_package_name
);
8970 struct objfile
*objfile
8971 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8972 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
8973 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
8974 (symbol_symtab (sym
) != NULL
8975 ? symtab_to_filename_for_display
8976 (symbol_symtab (sym
))
8977 : objfile_name (objfile
)),
8978 this_package_name
.get (), package_name
.get ());
8984 if (package_name
!= NULL
)
8986 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8987 const char *saved_package_name
= objfile
->intern (package_name
.get ());
8988 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
8989 saved_package_name
);
8992 sym
= allocate_symbol (objfile
);
8993 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
8994 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
8995 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
8996 e.g., "main" finds the "main" module and not C's main(). */
8997 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8998 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
8999 SYMBOL_TYPE (sym
) = type
;
9001 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9005 /* Allocate a fully-qualified name consisting of the two parts on the
9009 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9011 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9014 /* A helper that allocates a struct discriminant_info to attach to a
9017 static struct discriminant_info
*
9018 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9021 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9022 gdb_assert (discriminant_index
== -1
9023 || (discriminant_index
>= 0
9024 && discriminant_index
< TYPE_NFIELDS (type
)));
9025 gdb_assert (default_index
== -1
9026 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9028 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9030 struct discriminant_info
*disc
9031 = ((struct discriminant_info
*)
9033 offsetof (struct discriminant_info
, discriminants
)
9034 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9035 disc
->default_index
= default_index
;
9036 disc
->discriminant_index
= discriminant_index
;
9038 struct dynamic_prop prop
;
9039 prop
.kind
= PROP_UNDEFINED
;
9040 prop
.data
.baton
= disc
;
9042 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9047 /* Some versions of rustc emitted enums in an unusual way.
9049 Ordinary enums were emitted as unions. The first element of each
9050 structure in the union was named "RUST$ENUM$DISR". This element
9051 held the discriminant.
9053 These versions of Rust also implemented the "non-zero"
9054 optimization. When the enum had two values, and one is empty and
9055 the other holds a pointer that cannot be zero, the pointer is used
9056 as the discriminant, with a zero value meaning the empty variant.
9057 Here, the union's first member is of the form
9058 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9059 where the fieldnos are the indices of the fields that should be
9060 traversed in order to find the field (which may be several fields deep)
9061 and the variantname is the name of the variant of the case when the
9064 This function recognizes whether TYPE is of one of these forms,
9065 and, if so, smashes it to be a variant type. */
9068 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9070 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9072 /* We don't need to deal with empty enums. */
9073 if (TYPE_NFIELDS (type
) == 0)
9076 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9077 if (TYPE_NFIELDS (type
) == 1
9078 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9080 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9082 /* Decode the field name to find the offset of the
9084 ULONGEST bit_offset
= 0;
9085 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9086 while (name
[0] >= '0' && name
[0] <= '9')
9089 unsigned long index
= strtoul (name
, &tail
, 10);
9092 || index
>= TYPE_NFIELDS (field_type
)
9093 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9094 != FIELD_LOC_KIND_BITPOS
))
9096 complaint (_("Could not parse Rust enum encoding string \"%s\""
9098 TYPE_FIELD_NAME (type
, 0),
9099 objfile_name (objfile
));
9104 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9105 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9108 /* Make a union to hold the variants. */
9109 struct type
*union_type
= alloc_type (objfile
);
9110 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9111 TYPE_NFIELDS (union_type
) = 3;
9112 TYPE_FIELDS (union_type
)
9113 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9114 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9115 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9117 /* Put the discriminant must at index 0. */
9118 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9119 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9120 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9121 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9123 /* The order of fields doesn't really matter, so put the real
9124 field at index 1 and the data-less field at index 2. */
9125 struct discriminant_info
*disc
9126 = alloc_discriminant_info (union_type
, 0, 1);
9127 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9128 TYPE_FIELD_NAME (union_type
, 1)
9129 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9130 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9131 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9132 TYPE_FIELD_NAME (union_type
, 1));
9134 const char *dataless_name
9135 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9137 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9139 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9140 /* NAME points into the original discriminant name, which
9141 already has the correct lifetime. */
9142 TYPE_FIELD_NAME (union_type
, 2) = name
;
9143 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9144 disc
->discriminants
[2] = 0;
9146 /* Smash this type to be a structure type. We have to do this
9147 because the type has already been recorded. */
9148 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9149 TYPE_NFIELDS (type
) = 1;
9151 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9153 /* Install the variant part. */
9154 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9155 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9156 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9158 /* A union with a single anonymous field is probably an old-style
9160 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9162 /* Smash this type to be a structure type. We have to do this
9163 because the type has already been recorded. */
9164 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9166 /* Make a union to hold the variants. */
9167 struct type
*union_type
= alloc_type (objfile
);
9168 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9169 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9170 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9171 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9172 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9174 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9175 const char *variant_name
9176 = rust_last_path_segment (TYPE_NAME (field_type
));
9177 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9178 TYPE_NAME (field_type
)
9179 = rust_fully_qualify (&objfile
->objfile_obstack
,
9180 TYPE_NAME (type
), variant_name
);
9182 /* Install the union in the outer struct type. */
9183 TYPE_NFIELDS (type
) = 1;
9185 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9186 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9187 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9188 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9190 alloc_discriminant_info (union_type
, -1, 0);
9194 struct type
*disr_type
= nullptr;
9195 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9197 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9199 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9201 /* All fields of a true enum will be structs. */
9204 else if (TYPE_NFIELDS (disr_type
) == 0)
9206 /* Could be data-less variant, so keep going. */
9207 disr_type
= nullptr;
9209 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9210 "RUST$ENUM$DISR") != 0)
9212 /* Not a Rust enum. */
9222 /* If we got here without a discriminant, then it's probably
9224 if (disr_type
== nullptr)
9227 /* Smash this type to be a structure type. We have to do this
9228 because the type has already been recorded. */
9229 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9231 /* Make a union to hold the variants. */
9232 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9233 struct type
*union_type
= alloc_type (objfile
);
9234 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9235 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9236 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9237 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9238 TYPE_FIELDS (union_type
)
9239 = (struct field
*) TYPE_ZALLOC (union_type
,
9240 (TYPE_NFIELDS (union_type
)
9241 * sizeof (struct field
)));
9243 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9244 TYPE_NFIELDS (type
) * sizeof (struct field
));
9246 /* Install the discriminant at index 0 in the union. */
9247 TYPE_FIELD (union_type
, 0) = *disr_field
;
9248 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9249 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9251 /* Install the union in the outer struct type. */
9252 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9253 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9254 TYPE_NFIELDS (type
) = 1;
9256 /* Set the size and offset of the union type. */
9257 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9259 /* We need a way to find the correct discriminant given a
9260 variant name. For convenience we build a map here. */
9261 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9262 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9263 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9265 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9268 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9269 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9273 int n_fields
= TYPE_NFIELDS (union_type
);
9274 struct discriminant_info
*disc
9275 = alloc_discriminant_info (union_type
, 0, -1);
9276 /* Skip the discriminant here. */
9277 for (int i
= 1; i
< n_fields
; ++i
)
9279 /* Find the final word in the name of this variant's type.
9280 That name can be used to look up the correct
9282 const char *variant_name
9283 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9286 auto iter
= discriminant_map
.find (variant_name
);
9287 if (iter
!= discriminant_map
.end ())
9288 disc
->discriminants
[i
] = iter
->second
;
9290 /* Remove the discriminant field, if it exists. */
9291 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9292 if (TYPE_NFIELDS (sub_type
) > 0)
9294 --TYPE_NFIELDS (sub_type
);
9295 ++TYPE_FIELDS (sub_type
);
9297 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9298 TYPE_NAME (sub_type
)
9299 = rust_fully_qualify (&objfile
->objfile_obstack
,
9300 TYPE_NAME (type
), variant_name
);
9305 /* Rewrite some Rust unions to be structures with variants parts. */
9308 rust_union_quirks (struct dwarf2_cu
*cu
)
9310 gdb_assert (cu
->language
== language_rust
);
9311 for (type
*type_
: cu
->rust_unions
)
9312 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9313 /* We don't need this any more. */
9314 cu
->rust_unions
.clear ();
9317 /* Return the symtab for PER_CU. This works properly regardless of
9318 whether we're using the index or psymtabs. */
9320 static struct compunit_symtab
*
9321 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9323 return (per_cu
->dwarf2_per_objfile
->using_index
9324 ? per_cu
->v
.quick
->compunit_symtab
9325 : per_cu
->v
.psymtab
->compunit_symtab
);
9328 /* A helper function for computing the list of all symbol tables
9329 included by PER_CU. */
9332 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9333 htab_t all_children
, htab_t all_type_symtabs
,
9334 struct dwarf2_per_cu_data
*per_cu
,
9335 struct compunit_symtab
*immediate_parent
)
9338 struct compunit_symtab
*cust
;
9340 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9343 /* This inclusion and its children have been processed. */
9348 /* Only add a CU if it has a symbol table. */
9349 cust
= get_compunit_symtab (per_cu
);
9352 /* If this is a type unit only add its symbol table if we haven't
9353 seen it yet (type unit per_cu's can share symtabs). */
9354 if (per_cu
->is_debug_types
)
9356 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9360 result
->push_back (cust
);
9361 if (cust
->user
== NULL
)
9362 cust
->user
= immediate_parent
;
9367 result
->push_back (cust
);
9368 if (cust
->user
== NULL
)
9369 cust
->user
= immediate_parent
;
9373 if (!per_cu
->imported_symtabs_empty ())
9374 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9376 recursively_compute_inclusions (result
, all_children
,
9377 all_type_symtabs
, ptr
, cust
);
9381 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
9385 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
9387 gdb_assert (! per_cu
->is_debug_types
);
9389 if (!per_cu
->imported_symtabs_empty ())
9392 std::vector
<compunit_symtab
*> result_symtabs
;
9393 htab_t all_children
, all_type_symtabs
;
9394 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
9396 /* If we don't have a symtab, we can just skip this case. */
9400 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9401 NULL
, xcalloc
, xfree
);
9402 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
9403 NULL
, xcalloc
, xfree
);
9405 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
9407 recursively_compute_inclusions (&result_symtabs
, all_children
,
9408 all_type_symtabs
, ptr
, cust
);
9411 /* Now we have a transitive closure of all the included symtabs. */
9412 len
= result_symtabs
.size ();
9414 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
9415 struct compunit_symtab
*, len
+ 1);
9416 memcpy (cust
->includes
, result_symtabs
.data (),
9417 len
* sizeof (compunit_symtab
*));
9418 cust
->includes
[len
] = NULL
;
9420 htab_delete (all_children
);
9421 htab_delete (all_type_symtabs
);
9425 /* Compute the 'includes' field for the symtabs of all the CUs we just
9429 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9431 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
9433 if (! iter
->is_debug_types
)
9434 compute_compunit_symtab_includes (iter
);
9437 dwarf2_per_objfile
->just_read_cus
.clear ();
9440 /* Generate full symbol information for PER_CU, whose DIEs have
9441 already been loaded into memory. */
9444 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9445 enum language pretend_language
)
9447 struct dwarf2_cu
*cu
= per_cu
->cu
;
9448 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9449 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9450 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9451 CORE_ADDR lowpc
, highpc
;
9452 struct compunit_symtab
*cust
;
9454 struct block
*static_block
;
9457 baseaddr
= objfile
->text_section_offset ();
9459 /* Clear the list here in case something was left over. */
9460 cu
->method_list
.clear ();
9462 cu
->language
= pretend_language
;
9463 cu
->language_defn
= language_def (cu
->language
);
9465 /* Do line number decoding in read_file_scope () */
9466 process_die (cu
->dies
, cu
);
9468 /* For now fudge the Go package. */
9469 if (cu
->language
== language_go
)
9470 fixup_go_packaging (cu
);
9472 /* Now that we have processed all the DIEs in the CU, all the types
9473 should be complete, and it should now be safe to compute all of the
9475 compute_delayed_physnames (cu
);
9477 if (cu
->language
== language_rust
)
9478 rust_union_quirks (cu
);
9480 /* Some compilers don't define a DW_AT_high_pc attribute for the
9481 compilation unit. If the DW_AT_high_pc is missing, synthesize
9482 it, by scanning the DIE's below the compilation unit. */
9483 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
9485 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
9486 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
9488 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
9489 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
9490 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
9491 addrmap to help ensure it has an accurate map of pc values belonging to
9493 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
9495 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
9496 SECT_OFF_TEXT (objfile
),
9501 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
9503 /* Set symtab language to language from DW_AT_language. If the
9504 compilation is from a C file generated by language preprocessors, do
9505 not set the language if it was already deduced by start_subfile. */
9506 if (!(cu
->language
== language_c
9507 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
9508 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9510 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
9511 produce DW_AT_location with location lists but it can be possibly
9512 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
9513 there were bugs in prologue debug info, fixed later in GCC-4.5
9514 by "unwind info for epilogues" patch (which is not directly related).
9516 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
9517 needed, it would be wrong due to missing DW_AT_producer there.
9519 Still one can confuse GDB by using non-standard GCC compilation
9520 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
9522 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
9523 cust
->locations_valid
= 1;
9525 if (gcc_4_minor
>= 5)
9526 cust
->epilogue_unwind_valid
= 1;
9528 cust
->call_site_htab
= cu
->call_site_htab
;
9531 if (dwarf2_per_objfile
->using_index
)
9532 per_cu
->v
.quick
->compunit_symtab
= cust
;
9535 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9536 pst
->compunit_symtab
= cust
;
9540 /* Push it for inclusion processing later. */
9541 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
9543 /* Not needed any more. */
9544 cu
->reset_builder ();
9547 /* Generate full symbol information for type unit PER_CU, whose DIEs have
9548 already been loaded into memory. */
9551 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
9552 enum language pretend_language
)
9554 struct dwarf2_cu
*cu
= per_cu
->cu
;
9555 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
9556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
9557 struct compunit_symtab
*cust
;
9558 struct signatured_type
*sig_type
;
9560 gdb_assert (per_cu
->is_debug_types
);
9561 sig_type
= (struct signatured_type
*) per_cu
;
9563 /* Clear the list here in case something was left over. */
9564 cu
->method_list
.clear ();
9566 cu
->language
= pretend_language
;
9567 cu
->language_defn
= language_def (cu
->language
);
9569 /* The symbol tables are set up in read_type_unit_scope. */
9570 process_die (cu
->dies
, cu
);
9572 /* For now fudge the Go package. */
9573 if (cu
->language
== language_go
)
9574 fixup_go_packaging (cu
);
9576 /* Now that we have processed all the DIEs in the CU, all the types
9577 should be complete, and it should now be safe to compute all of the
9579 compute_delayed_physnames (cu
);
9581 if (cu
->language
== language_rust
)
9582 rust_union_quirks (cu
);
9584 /* TUs share symbol tables.
9585 If this is the first TU to use this symtab, complete the construction
9586 of it with end_expandable_symtab. Otherwise, complete the addition of
9587 this TU's symbols to the existing symtab. */
9588 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
9590 buildsym_compunit
*builder
= cu
->get_builder ();
9591 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
9592 sig_type
->type_unit_group
->compunit_symtab
= cust
;
9596 /* Set symtab language to language from DW_AT_language. If the
9597 compilation is from a C file generated by language preprocessors,
9598 do not set the language if it was already deduced by
9600 if (!(cu
->language
== language_c
9601 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
9602 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
9607 cu
->get_builder ()->augment_type_symtab ();
9608 cust
= sig_type
->type_unit_group
->compunit_symtab
;
9611 if (dwarf2_per_objfile
->using_index
)
9612 per_cu
->v
.quick
->compunit_symtab
= cust
;
9615 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
9616 pst
->compunit_symtab
= cust
;
9620 /* Not needed any more. */
9621 cu
->reset_builder ();
9624 /* Process an imported unit DIE. */
9627 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9629 struct attribute
*attr
;
9631 /* For now we don't handle imported units in type units. */
9632 if (cu
->per_cu
->is_debug_types
)
9634 error (_("Dwarf Error: DW_TAG_imported_unit is not"
9635 " supported in type units [in module %s]"),
9636 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
9639 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
9642 sect_offset sect_off
= attr
->get_ref_die_offset ();
9643 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
9644 dwarf2_per_cu_data
*per_cu
9645 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
9646 cu
->per_cu
->dwarf2_per_objfile
);
9648 /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
9649 into another compilation unit, at root level. Regard this as a hint,
9651 if (die
->parent
&& die
->parent
->parent
== NULL
9652 && per_cu
->unit_type
== DW_UT_compile
9653 && per_cu
->lang
== language_cplus
)
9656 /* If necessary, add it to the queue and load its DIEs. */
9657 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
9658 load_full_comp_unit (per_cu
, false, cu
->language
);
9660 cu
->per_cu
->imported_symtabs_push (per_cu
);
9664 /* RAII object that represents a process_die scope: i.e.,
9665 starts/finishes processing a DIE. */
9666 class process_die_scope
9669 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
9670 : m_die (die
), m_cu (cu
)
9672 /* We should only be processing DIEs not already in process. */
9673 gdb_assert (!m_die
->in_process
);
9674 m_die
->in_process
= true;
9677 ~process_die_scope ()
9679 m_die
->in_process
= false;
9681 /* If we're done processing the DIE for the CU that owns the line
9682 header, we don't need the line header anymore. */
9683 if (m_cu
->line_header_die_owner
== m_die
)
9685 delete m_cu
->line_header
;
9686 m_cu
->line_header
= NULL
;
9687 m_cu
->line_header_die_owner
= NULL
;
9696 /* Process a die and its children. */
9699 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9701 process_die_scope
scope (die
, cu
);
9705 case DW_TAG_padding
:
9707 case DW_TAG_compile_unit
:
9708 case DW_TAG_partial_unit
:
9709 read_file_scope (die
, cu
);
9711 case DW_TAG_type_unit
:
9712 read_type_unit_scope (die
, cu
);
9714 case DW_TAG_subprogram
:
9715 /* Nested subprograms in Fortran get a prefix. */
9716 if (cu
->language
== language_fortran
9717 && die
->parent
!= NULL
9718 && die
->parent
->tag
== DW_TAG_subprogram
)
9719 cu
->processing_has_namespace_info
= true;
9721 case DW_TAG_inlined_subroutine
:
9722 read_func_scope (die
, cu
);
9724 case DW_TAG_lexical_block
:
9725 case DW_TAG_try_block
:
9726 case DW_TAG_catch_block
:
9727 read_lexical_block_scope (die
, cu
);
9729 case DW_TAG_call_site
:
9730 case DW_TAG_GNU_call_site
:
9731 read_call_site_scope (die
, cu
);
9733 case DW_TAG_class_type
:
9734 case DW_TAG_interface_type
:
9735 case DW_TAG_structure_type
:
9736 case DW_TAG_union_type
:
9737 process_structure_scope (die
, cu
);
9739 case DW_TAG_enumeration_type
:
9740 process_enumeration_scope (die
, cu
);
9743 /* These dies have a type, but processing them does not create
9744 a symbol or recurse to process the children. Therefore we can
9745 read them on-demand through read_type_die. */
9746 case DW_TAG_subroutine_type
:
9747 case DW_TAG_set_type
:
9748 case DW_TAG_array_type
:
9749 case DW_TAG_pointer_type
:
9750 case DW_TAG_ptr_to_member_type
:
9751 case DW_TAG_reference_type
:
9752 case DW_TAG_rvalue_reference_type
:
9753 case DW_TAG_string_type
:
9756 case DW_TAG_base_type
:
9757 case DW_TAG_subrange_type
:
9758 case DW_TAG_typedef
:
9759 /* Add a typedef symbol for the type definition, if it has a
9761 new_symbol (die
, read_type_die (die
, cu
), cu
);
9763 case DW_TAG_common_block
:
9764 read_common_block (die
, cu
);
9766 case DW_TAG_common_inclusion
:
9768 case DW_TAG_namespace
:
9769 cu
->processing_has_namespace_info
= true;
9770 read_namespace (die
, cu
);
9773 cu
->processing_has_namespace_info
= true;
9774 read_module (die
, cu
);
9776 case DW_TAG_imported_declaration
:
9777 cu
->processing_has_namespace_info
= true;
9778 if (read_namespace_alias (die
, cu
))
9780 /* The declaration is not a global namespace alias. */
9782 case DW_TAG_imported_module
:
9783 cu
->processing_has_namespace_info
= true;
9784 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
9785 || cu
->language
!= language_fortran
))
9786 complaint (_("Tag '%s' has unexpected children"),
9787 dwarf_tag_name (die
->tag
));
9788 read_import_statement (die
, cu
);
9791 case DW_TAG_imported_unit
:
9792 process_imported_unit_die (die
, cu
);
9795 case DW_TAG_variable
:
9796 read_variable (die
, cu
);
9800 new_symbol (die
, NULL
, cu
);
9805 /* DWARF name computation. */
9807 /* A helper function for dwarf2_compute_name which determines whether DIE
9808 needs to have the name of the scope prepended to the name listed in the
9812 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
9814 struct attribute
*attr
;
9818 case DW_TAG_namespace
:
9819 case DW_TAG_typedef
:
9820 case DW_TAG_class_type
:
9821 case DW_TAG_interface_type
:
9822 case DW_TAG_structure_type
:
9823 case DW_TAG_union_type
:
9824 case DW_TAG_enumeration_type
:
9825 case DW_TAG_enumerator
:
9826 case DW_TAG_subprogram
:
9827 case DW_TAG_inlined_subroutine
:
9829 case DW_TAG_imported_declaration
:
9832 case DW_TAG_variable
:
9833 case DW_TAG_constant
:
9834 /* We only need to prefix "globally" visible variables. These include
9835 any variable marked with DW_AT_external or any variable that
9836 lives in a namespace. [Variables in anonymous namespaces
9837 require prefixing, but they are not DW_AT_external.] */
9839 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
9841 struct dwarf2_cu
*spec_cu
= cu
;
9843 return die_needs_namespace (die_specification (die
, &spec_cu
),
9847 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
9848 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
9849 && die
->parent
->tag
!= DW_TAG_module
)
9851 /* A variable in a lexical block of some kind does not need a
9852 namespace, even though in C++ such variables may be external
9853 and have a mangled name. */
9854 if (die
->parent
->tag
== DW_TAG_lexical_block
9855 || die
->parent
->tag
== DW_TAG_try_block
9856 || die
->parent
->tag
== DW_TAG_catch_block
9857 || die
->parent
->tag
== DW_TAG_subprogram
)
9866 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
9867 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9868 defined for the given DIE. */
9870 static struct attribute
*
9871 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
9873 struct attribute
*attr
;
9875 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
9877 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9882 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
9883 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
9884 defined for the given DIE. */
9887 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9889 const char *linkage_name
;
9891 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
9892 if (linkage_name
== NULL
)
9893 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
9895 return linkage_name
;
9898 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
9899 compute the physname for the object, which include a method's:
9900 - formal parameters (C++),
9901 - receiver type (Go),
9903 The term "physname" is a bit confusing.
9904 For C++, for example, it is the demangled name.
9905 For Go, for example, it's the mangled name.
9907 For Ada, return the DIE's linkage name rather than the fully qualified
9908 name. PHYSNAME is ignored..
9910 The result is allocated on the objfile_obstack and canonicalized. */
9913 dwarf2_compute_name (const char *name
,
9914 struct die_info
*die
, struct dwarf2_cu
*cu
,
9917 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9920 name
= dwarf2_name (die
, cu
);
9922 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
9923 but otherwise compute it by typename_concat inside GDB.
9924 FIXME: Actually this is not really true, or at least not always true.
9925 It's all very confusing. compute_and_set_names doesn't try to demangle
9926 Fortran names because there is no mangling standard. So new_symbol
9927 will set the demangled name to the result of dwarf2_full_name, and it is
9928 the demangled name that GDB uses if it exists. */
9929 if (cu
->language
== language_ada
9930 || (cu
->language
== language_fortran
&& physname
))
9932 /* For Ada unit, we prefer the linkage name over the name, as
9933 the former contains the exported name, which the user expects
9934 to be able to reference. Ideally, we want the user to be able
9935 to reference this entity using either natural or linkage name,
9936 but we haven't started looking at this enhancement yet. */
9937 const char *linkage_name
= dw2_linkage_name (die
, cu
);
9939 if (linkage_name
!= NULL
)
9940 return linkage_name
;
9943 /* These are the only languages we know how to qualify names in. */
9945 && (cu
->language
== language_cplus
9946 || cu
->language
== language_fortran
|| cu
->language
== language_d
9947 || cu
->language
== language_rust
))
9949 if (die_needs_namespace (die
, cu
))
9952 const char *canonical_name
= NULL
;
9956 prefix
= determine_prefix (die
, cu
);
9957 if (*prefix
!= '\0')
9959 gdb::unique_xmalloc_ptr
<char> prefixed_name
9960 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
9962 buf
.puts (prefixed_name
.get ());
9967 /* Template parameters may be specified in the DIE's DW_AT_name, or
9968 as children with DW_TAG_template_type_param or
9969 DW_TAG_value_type_param. If the latter, add them to the name
9970 here. If the name already has template parameters, then
9971 skip this step; some versions of GCC emit both, and
9972 it is more efficient to use the pre-computed name.
9974 Something to keep in mind about this process: it is very
9975 unlikely, or in some cases downright impossible, to produce
9976 something that will match the mangled name of a function.
9977 If the definition of the function has the same debug info,
9978 we should be able to match up with it anyway. But fallbacks
9979 using the minimal symbol, for instance to find a method
9980 implemented in a stripped copy of libstdc++, will not work.
9981 If we do not have debug info for the definition, we will have to
9982 match them up some other way.
9984 When we do name matching there is a related problem with function
9985 templates; two instantiated function templates are allowed to
9986 differ only by their return types, which we do not add here. */
9988 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
9990 struct attribute
*attr
;
9991 struct die_info
*child
;
9994 die
->building_fullname
= 1;
9996 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10000 const gdb_byte
*bytes
;
10001 struct dwarf2_locexpr_baton
*baton
;
10004 if (child
->tag
!= DW_TAG_template_type_param
10005 && child
->tag
!= DW_TAG_template_value_param
)
10016 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10019 complaint (_("template parameter missing DW_AT_type"));
10020 buf
.puts ("UNKNOWN_TYPE");
10023 type
= die_type (child
, cu
);
10025 if (child
->tag
== DW_TAG_template_type_param
)
10027 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10028 &type_print_raw_options
);
10032 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10035 complaint (_("template parameter missing "
10036 "DW_AT_const_value"));
10037 buf
.puts ("UNKNOWN_VALUE");
10041 dwarf2_const_value_attr (attr
, type
, name
,
10042 &cu
->comp_unit_obstack
, cu
,
10043 &value
, &bytes
, &baton
);
10045 if (TYPE_NOSIGN (type
))
10046 /* GDB prints characters as NUMBER 'CHAR'. If that's
10047 changed, this can use value_print instead. */
10048 c_printchar (value
, type
, &buf
);
10051 struct value_print_options opts
;
10054 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10058 else if (bytes
!= NULL
)
10060 v
= allocate_value (type
);
10061 memcpy (value_contents_writeable (v
), bytes
,
10062 TYPE_LENGTH (type
));
10065 v
= value_from_longest (type
, value
);
10067 /* Specify decimal so that we do not depend on
10069 get_formatted_print_options (&opts
, 'd');
10071 value_print (v
, &buf
, &opts
);
10076 die
->building_fullname
= 0;
10080 /* Close the argument list, with a space if necessary
10081 (nested templates). */
10082 if (!buf
.empty () && buf
.string ().back () == '>')
10089 /* For C++ methods, append formal parameter type
10090 information, if PHYSNAME. */
10092 if (physname
&& die
->tag
== DW_TAG_subprogram
10093 && cu
->language
== language_cplus
)
10095 struct type
*type
= read_type_die (die
, cu
);
10097 c_type_print_args (type
, &buf
, 1, cu
->language
,
10098 &type_print_raw_options
);
10100 if (cu
->language
== language_cplus
)
10102 /* Assume that an artificial first parameter is
10103 "this", but do not crash if it is not. RealView
10104 marks unnamed (and thus unused) parameters as
10105 artificial; there is no way to differentiate
10107 if (TYPE_NFIELDS (type
) > 0
10108 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10109 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10110 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10112 buf
.puts (" const");
10116 const std::string
&intermediate_name
= buf
.string ();
10118 if (cu
->language
== language_cplus
)
10120 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10123 /* If we only computed INTERMEDIATE_NAME, or if
10124 INTERMEDIATE_NAME is already canonical, then we need to
10126 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10127 name
= objfile
->intern (intermediate_name
);
10129 name
= canonical_name
;
10136 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10137 If scope qualifiers are appropriate they will be added. The result
10138 will be allocated on the storage_obstack, or NULL if the DIE does
10139 not have a name. NAME may either be from a previous call to
10140 dwarf2_name or NULL.
10142 The output string will be canonicalized (if C++). */
10144 static const char *
10145 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10147 return dwarf2_compute_name (name
, die
, cu
, 0);
10150 /* Construct a physname for the given DIE in CU. NAME may either be
10151 from a previous call to dwarf2_name or NULL. The result will be
10152 allocated on the objfile_objstack or NULL if the DIE does not have a
10155 The output string will be canonicalized (if C++). */
10157 static const char *
10158 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10160 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10161 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10164 /* In this case dwarf2_compute_name is just a shortcut not building anything
10166 if (!die_needs_namespace (die
, cu
))
10167 return dwarf2_compute_name (name
, die
, cu
, 1);
10169 mangled
= dw2_linkage_name (die
, cu
);
10171 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10172 See https://github.com/rust-lang/rust/issues/32925. */
10173 if (cu
->language
== language_rust
&& mangled
!= NULL
10174 && strchr (mangled
, '{') != NULL
)
10177 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10179 gdb::unique_xmalloc_ptr
<char> demangled
;
10180 if (mangled
!= NULL
)
10183 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10185 /* Do nothing (do not demangle the symbol name). */
10187 else if (cu
->language
== language_go
)
10189 /* This is a lie, but we already lie to the caller new_symbol.
10190 new_symbol assumes we return the mangled name.
10191 This just undoes that lie until things are cleaned up. */
10195 /* Use DMGL_RET_DROP for C++ template functions to suppress
10196 their return type. It is easier for GDB users to search
10197 for such functions as `name(params)' than `long name(params)'.
10198 In such case the minimal symbol names do not match the full
10199 symbol names but for template functions there is never a need
10200 to look up their definition from their declaration so
10201 the only disadvantage remains the minimal symbol variant
10202 `long name(params)' does not have the proper inferior type. */
10203 demangled
.reset (gdb_demangle (mangled
,
10204 (DMGL_PARAMS
| DMGL_ANSI
10205 | DMGL_RET_DROP
)));
10208 canon
= demangled
.get ();
10216 if (canon
== NULL
|| check_physname
)
10218 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10220 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10222 /* It may not mean a bug in GDB. The compiler could also
10223 compute DW_AT_linkage_name incorrectly. But in such case
10224 GDB would need to be bug-to-bug compatible. */
10226 complaint (_("Computed physname <%s> does not match demangled <%s> "
10227 "(from linkage <%s>) - DIE at %s [in module %s]"),
10228 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10229 objfile_name (objfile
));
10231 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10232 is available here - over computed PHYSNAME. It is safer
10233 against both buggy GDB and buggy compilers. */
10247 retval
= objfile
->intern (retval
);
10252 /* Inspect DIE in CU for a namespace alias. If one exists, record
10253 a new symbol for it.
10255 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10258 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10260 struct attribute
*attr
;
10262 /* If the die does not have a name, this is not a namespace
10264 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10268 struct die_info
*d
= die
;
10269 struct dwarf2_cu
*imported_cu
= cu
;
10271 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10272 keep inspecting DIEs until we hit the underlying import. */
10273 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10274 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10276 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10280 d
= follow_die_ref (d
, attr
, &imported_cu
);
10281 if (d
->tag
!= DW_TAG_imported_declaration
)
10285 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10287 complaint (_("DIE at %s has too many recursively imported "
10288 "declarations"), sect_offset_str (d
->sect_off
));
10295 sect_offset sect_off
= attr
->get_ref_die_offset ();
10297 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10298 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10300 /* This declaration is a global namespace alias. Add
10301 a symbol for it whose type is the aliased namespace. */
10302 new_symbol (die
, type
, cu
);
10311 /* Return the using directives repository (global or local?) to use in the
10312 current context for CU.
10314 For Ada, imported declarations can materialize renamings, which *may* be
10315 global. However it is impossible (for now?) in DWARF to distinguish
10316 "external" imported declarations and "static" ones. As all imported
10317 declarations seem to be static in all other languages, make them all CU-wide
10318 global only in Ada. */
10320 static struct using_direct
**
10321 using_directives (struct dwarf2_cu
*cu
)
10323 if (cu
->language
== language_ada
10324 && cu
->get_builder ()->outermost_context_p ())
10325 return cu
->get_builder ()->get_global_using_directives ();
10327 return cu
->get_builder ()->get_local_using_directives ();
10330 /* Read the import statement specified by the given die and record it. */
10333 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10335 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10336 struct attribute
*import_attr
;
10337 struct die_info
*imported_die
, *child_die
;
10338 struct dwarf2_cu
*imported_cu
;
10339 const char *imported_name
;
10340 const char *imported_name_prefix
;
10341 const char *canonical_name
;
10342 const char *import_alias
;
10343 const char *imported_declaration
= NULL
;
10344 const char *import_prefix
;
10345 std::vector
<const char *> excludes
;
10347 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10348 if (import_attr
== NULL
)
10350 complaint (_("Tag '%s' has no DW_AT_import"),
10351 dwarf_tag_name (die
->tag
));
10356 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10357 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10358 if (imported_name
== NULL
)
10360 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10362 The import in the following code:
10376 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
10377 <52> DW_AT_decl_file : 1
10378 <53> DW_AT_decl_line : 6
10379 <54> DW_AT_import : <0x75>
10380 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
10381 <59> DW_AT_name : B
10382 <5b> DW_AT_decl_file : 1
10383 <5c> DW_AT_decl_line : 2
10384 <5d> DW_AT_type : <0x6e>
10386 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
10387 <76> DW_AT_byte_size : 4
10388 <77> DW_AT_encoding : 5 (signed)
10390 imports the wrong die ( 0x75 instead of 0x58 ).
10391 This case will be ignored until the gcc bug is fixed. */
10395 /* Figure out the local name after import. */
10396 import_alias
= dwarf2_name (die
, cu
);
10398 /* Figure out where the statement is being imported to. */
10399 import_prefix
= determine_prefix (die
, cu
);
10401 /* Figure out what the scope of the imported die is and prepend it
10402 to the name of the imported die. */
10403 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
10405 if (imported_die
->tag
!= DW_TAG_namespace
10406 && imported_die
->tag
!= DW_TAG_module
)
10408 imported_declaration
= imported_name
;
10409 canonical_name
= imported_name_prefix
;
10411 else if (strlen (imported_name_prefix
) > 0)
10412 canonical_name
= obconcat (&objfile
->objfile_obstack
,
10413 imported_name_prefix
,
10414 (cu
->language
== language_d
? "." : "::"),
10415 imported_name
, (char *) NULL
);
10417 canonical_name
= imported_name
;
10419 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
10420 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
10421 child_die
= child_die
->sibling
)
10423 /* DWARF-4: A Fortran use statement with a “rename list” may be
10424 represented by an imported module entry with an import attribute
10425 referring to the module and owned entries corresponding to those
10426 entities that are renamed as part of being imported. */
10428 if (child_die
->tag
!= DW_TAG_imported_declaration
)
10430 complaint (_("child DW_TAG_imported_declaration expected "
10431 "- DIE at %s [in module %s]"),
10432 sect_offset_str (child_die
->sect_off
),
10433 objfile_name (objfile
));
10437 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
10438 if (import_attr
== NULL
)
10440 complaint (_("Tag '%s' has no DW_AT_import"),
10441 dwarf_tag_name (child_die
->tag
));
10446 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
10448 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10449 if (imported_name
== NULL
)
10451 complaint (_("child DW_TAG_imported_declaration has unknown "
10452 "imported name - DIE at %s [in module %s]"),
10453 sect_offset_str (child_die
->sect_off
),
10454 objfile_name (objfile
));
10458 excludes
.push_back (imported_name
);
10460 process_die (child_die
, cu
);
10463 add_using_directive (using_directives (cu
),
10467 imported_declaration
,
10470 &objfile
->objfile_obstack
);
10473 /* ICC<14 does not output the required DW_AT_declaration on incomplete
10474 types, but gives them a size of zero. Starting with version 14,
10475 ICC is compatible with GCC. */
10478 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
10480 if (!cu
->checked_producer
)
10481 check_producer (cu
);
10483 return cu
->producer_is_icc_lt_14
;
10486 /* ICC generates a DW_AT_type for C void functions. This was observed on
10487 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
10488 which says that void functions should not have a DW_AT_type. */
10491 producer_is_icc (struct dwarf2_cu
*cu
)
10493 if (!cu
->checked_producer
)
10494 check_producer (cu
);
10496 return cu
->producer_is_icc
;
10499 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
10500 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
10501 this, it was first present in GCC release 4.3.0. */
10504 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
10506 if (!cu
->checked_producer
)
10507 check_producer (cu
);
10509 return cu
->producer_is_gcc_lt_4_3
;
10512 static file_and_directory
10513 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
10515 file_and_directory res
;
10517 /* Find the filename. Do not use dwarf2_name here, since the filename
10518 is not a source language identifier. */
10519 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
10520 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
10522 if (res
.comp_dir
== NULL
10523 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
10524 && IS_ABSOLUTE_PATH (res
.name
))
10526 res
.comp_dir_storage
= ldirname (res
.name
);
10527 if (!res
.comp_dir_storage
.empty ())
10528 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
10530 if (res
.comp_dir
!= NULL
)
10532 /* Irix 6.2 native cc prepends <machine>.: to the compilation
10533 directory, get rid of it. */
10534 const char *cp
= strchr (res
.comp_dir
, ':');
10536 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
10537 res
.comp_dir
= cp
+ 1;
10540 if (res
.name
== NULL
)
10541 res
.name
= "<unknown>";
10546 /* Handle DW_AT_stmt_list for a compilation unit.
10547 DIE is the DW_TAG_compile_unit die for CU.
10548 COMP_DIR is the compilation directory. LOWPC is passed to
10549 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
10552 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
10553 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
10555 struct dwarf2_per_objfile
*dwarf2_per_objfile
10556 = cu
->per_cu
->dwarf2_per_objfile
;
10557 struct attribute
*attr
;
10558 struct line_header line_header_local
;
10559 hashval_t line_header_local_hash
;
10561 int decode_mapping
;
10563 gdb_assert (! cu
->per_cu
->is_debug_types
);
10565 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
10569 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10571 /* The line header hash table is only created if needed (it exists to
10572 prevent redundant reading of the line table for partial_units).
10573 If we're given a partial_unit, we'll need it. If we're given a
10574 compile_unit, then use the line header hash table if it's already
10575 created, but don't create one just yet. */
10577 if (dwarf2_per_objfile
->line_header_hash
== NULL
10578 && die
->tag
== DW_TAG_partial_unit
)
10580 dwarf2_per_objfile
->line_header_hash
10581 .reset (htab_create_alloc (127, line_header_hash_voidp
,
10582 line_header_eq_voidp
,
10583 free_line_header_voidp
,
10587 line_header_local
.sect_off
= line_offset
;
10588 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
10589 line_header_local_hash
= line_header_hash (&line_header_local
);
10590 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
10592 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10593 &line_header_local
,
10594 line_header_local_hash
, NO_INSERT
);
10596 /* For DW_TAG_compile_unit we need info like symtab::linetable which
10597 is not present in *SLOT (since if there is something in *SLOT then
10598 it will be for a partial_unit). */
10599 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
10601 gdb_assert (*slot
!= NULL
);
10602 cu
->line_header
= (struct line_header
*) *slot
;
10607 /* dwarf_decode_line_header does not yet provide sufficient information.
10608 We always have to call also dwarf_decode_lines for it. */
10609 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
10613 cu
->line_header
= lh
.release ();
10614 cu
->line_header_die_owner
= die
;
10616 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
10620 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
.get (),
10621 &line_header_local
,
10622 line_header_local_hash
, INSERT
);
10623 gdb_assert (slot
!= NULL
);
10625 if (slot
!= NULL
&& *slot
== NULL
)
10627 /* This newly decoded line number information unit will be owned
10628 by line_header_hash hash table. */
10629 *slot
= cu
->line_header
;
10630 cu
->line_header_die_owner
= NULL
;
10634 /* We cannot free any current entry in (*slot) as that struct line_header
10635 may be already used by multiple CUs. Create only temporary decoded
10636 line_header for this CU - it may happen at most once for each line
10637 number information unit. And if we're not using line_header_hash
10638 then this is what we want as well. */
10639 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
10641 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
10642 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
10647 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
10650 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10652 struct dwarf2_per_objfile
*dwarf2_per_objfile
10653 = cu
->per_cu
->dwarf2_per_objfile
;
10654 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10655 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10656 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
10657 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
10658 struct attribute
*attr
;
10659 struct die_info
*child_die
;
10660 CORE_ADDR baseaddr
;
10662 prepare_one_comp_unit (cu
, die
, cu
->language
);
10663 baseaddr
= objfile
->text_section_offset ();
10665 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
10667 /* If we didn't find a lowpc, set it to highpc to avoid complaints
10668 from finish_block. */
10669 if (lowpc
== ((CORE_ADDR
) -1))
10671 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
10673 file_and_directory fnd
= find_file_and_directory (die
, cu
);
10675 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
10676 standardised yet. As a workaround for the language detection we fall
10677 back to the DW_AT_producer string. */
10678 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
10679 cu
->language
= language_opencl
;
10681 /* Similar hack for Go. */
10682 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
10683 set_cu_language (DW_LANG_Go
, cu
);
10685 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
10687 /* Decode line number information if present. We do this before
10688 processing child DIEs, so that the line header table is available
10689 for DW_AT_decl_file. */
10690 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
10692 /* Process all dies in compilation unit. */
10693 if (die
->child
!= NULL
)
10695 child_die
= die
->child
;
10696 while (child_die
&& child_die
->tag
)
10698 process_die (child_die
, cu
);
10699 child_die
= child_die
->sibling
;
10703 /* Decode macro information, if present. Dwarf 2 macro information
10704 refers to information in the line number info statement program
10705 header, so we can only read it if we've read the header
10707 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
10709 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
10710 if (attr
&& cu
->line_header
)
10712 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
10713 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
10715 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
10719 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
10720 if (attr
&& cu
->line_header
)
10722 unsigned int macro_offset
= DW_UNSND (attr
);
10724 dwarf_decode_macros (cu
, macro_offset
, 0);
10730 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
10732 struct type_unit_group
*tu_group
;
10734 struct attribute
*attr
;
10736 struct signatured_type
*sig_type
;
10738 gdb_assert (per_cu
->is_debug_types
);
10739 sig_type
= (struct signatured_type
*) per_cu
;
10741 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
10743 /* If we're using .gdb_index (includes -readnow) then
10744 per_cu->type_unit_group may not have been set up yet. */
10745 if (sig_type
->type_unit_group
== NULL
)
10746 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
10747 tu_group
= sig_type
->type_unit_group
;
10749 /* If we've already processed this stmt_list there's no real need to
10750 do it again, we could fake it and just recreate the part we need
10751 (file name,index -> symtab mapping). If data shows this optimization
10752 is useful we can do it then. */
10753 first_time
= tu_group
->compunit_symtab
== NULL
;
10755 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
10760 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
10761 lh
= dwarf_decode_line_header (line_offset
, this);
10766 start_symtab ("", NULL
, 0);
10769 gdb_assert (tu_group
->symtabs
== NULL
);
10770 gdb_assert (m_builder
== nullptr);
10771 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10772 m_builder
.reset (new struct buildsym_compunit
10773 (COMPUNIT_OBJFILE (cust
), "",
10774 COMPUNIT_DIRNAME (cust
),
10775 compunit_language (cust
),
10781 line_header
= lh
.release ();
10782 line_header_die_owner
= die
;
10786 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
10788 /* Note: We don't assign tu_group->compunit_symtab yet because we're
10789 still initializing it, and our caller (a few levels up)
10790 process_full_type_unit still needs to know if this is the first
10794 = XOBNEWVEC (&COMPUNIT_OBJFILE (cust
)->objfile_obstack
,
10795 struct symtab
*, line_header
->file_names_size ());
10797 auto &file_names
= line_header
->file_names ();
10798 for (i
= 0; i
< file_names
.size (); ++i
)
10800 file_entry
&fe
= file_names
[i
];
10801 dwarf2_start_subfile (this, fe
.name
,
10802 fe
.include_dir (line_header
));
10803 buildsym_compunit
*b
= get_builder ();
10804 if (b
->get_current_subfile ()->symtab
== NULL
)
10806 /* NOTE: start_subfile will recognize when it's been
10807 passed a file it has already seen. So we can't
10808 assume there's a simple mapping from
10809 cu->line_header->file_names to subfiles, plus
10810 cu->line_header->file_names may contain dups. */
10811 b
->get_current_subfile ()->symtab
10812 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
10815 fe
.symtab
= b
->get_current_subfile ()->symtab
;
10816 tu_group
->symtabs
[i
] = fe
.symtab
;
10821 gdb_assert (m_builder
== nullptr);
10822 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
10823 m_builder
.reset (new struct buildsym_compunit
10824 (COMPUNIT_OBJFILE (cust
), "",
10825 COMPUNIT_DIRNAME (cust
),
10826 compunit_language (cust
),
10829 auto &file_names
= line_header
->file_names ();
10830 for (i
= 0; i
< file_names
.size (); ++i
)
10832 file_entry
&fe
= file_names
[i
];
10833 fe
.symtab
= tu_group
->symtabs
[i
];
10837 /* The main symtab is allocated last. Type units don't have DW_AT_name
10838 so they don't have a "real" (so to speak) symtab anyway.
10839 There is later code that will assign the main symtab to all symbols
10840 that don't have one. We need to handle the case of a symbol with a
10841 missing symtab (DW_AT_decl_file) anyway. */
10844 /* Process DW_TAG_type_unit.
10845 For TUs we want to skip the first top level sibling if it's not the
10846 actual type being defined by this TU. In this case the first top
10847 level sibling is there to provide context only. */
10850 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
10852 struct die_info
*child_die
;
10854 prepare_one_comp_unit (cu
, die
, language_minimal
);
10856 /* Initialize (or reinitialize) the machinery for building symtabs.
10857 We do this before processing child DIEs, so that the line header table
10858 is available for DW_AT_decl_file. */
10859 cu
->setup_type_unit_groups (die
);
10861 if (die
->child
!= NULL
)
10863 child_die
= die
->child
;
10864 while (child_die
&& child_die
->tag
)
10866 process_die (child_die
, cu
);
10867 child_die
= child_die
->sibling
;
10874 http://gcc.gnu.org/wiki/DebugFission
10875 http://gcc.gnu.org/wiki/DebugFissionDWP
10877 To simplify handling of both DWO files ("object" files with the DWARF info)
10878 and DWP files (a file with the DWOs packaged up into one file), we treat
10879 DWP files as having a collection of virtual DWO files. */
10882 hash_dwo_file (const void *item
)
10884 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
10887 hash
= htab_hash_string (dwo_file
->dwo_name
);
10888 if (dwo_file
->comp_dir
!= NULL
)
10889 hash
+= htab_hash_string (dwo_file
->comp_dir
);
10894 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
10896 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
10897 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
10899 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
10901 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
10902 return lhs
->comp_dir
== rhs
->comp_dir
;
10903 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
10906 /* Allocate a hash table for DWO files. */
10909 allocate_dwo_file_hash_table ()
10911 auto delete_dwo_file
= [] (void *item
)
10913 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
10918 return htab_up (htab_create_alloc (41,
10925 /* Lookup DWO file DWO_NAME. */
10928 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
10929 const char *dwo_name
,
10930 const char *comp_dir
)
10932 struct dwo_file find_entry
;
10935 if (dwarf2_per_objfile
->dwo_files
== NULL
)
10936 dwarf2_per_objfile
->dwo_files
= allocate_dwo_file_hash_table ();
10938 find_entry
.dwo_name
= dwo_name
;
10939 find_entry
.comp_dir
= comp_dir
;
10940 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
10947 hash_dwo_unit (const void *item
)
10949 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
10951 /* This drops the top 32 bits of the id, but is ok for a hash. */
10952 return dwo_unit
->signature
;
10956 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
10958 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
10959 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
10961 /* The signature is assumed to be unique within the DWO file.
10962 So while object file CU dwo_id's always have the value zero,
10963 that's OK, assuming each object file DWO file has only one CU,
10964 and that's the rule for now. */
10965 return lhs
->signature
== rhs
->signature
;
10968 /* Allocate a hash table for DWO CUs,TUs.
10969 There is one of these tables for each of CUs,TUs for each DWO file. */
10972 allocate_dwo_unit_table ()
10974 /* Start out with a pretty small number.
10975 Generally DWO files contain only one CU and maybe some TUs. */
10976 return htab_up (htab_create_alloc (3,
10979 NULL
, xcalloc
, xfree
));
10982 /* die_reader_func for create_dwo_cu. */
10985 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
10986 const gdb_byte
*info_ptr
,
10987 struct die_info
*comp_unit_die
,
10988 struct dwo_file
*dwo_file
,
10989 struct dwo_unit
*dwo_unit
)
10991 struct dwarf2_cu
*cu
= reader
->cu
;
10992 sect_offset sect_off
= cu
->per_cu
->sect_off
;
10993 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
10995 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
10996 if (!signature
.has_value ())
10998 complaint (_("Dwarf Error: debug entry at offset %s is missing"
10999 " its dwo_id [in module %s]"),
11000 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11004 dwo_unit
->dwo_file
= dwo_file
;
11005 dwo_unit
->signature
= *signature
;
11006 dwo_unit
->section
= section
;
11007 dwo_unit
->sect_off
= sect_off
;
11008 dwo_unit
->length
= cu
->per_cu
->length
;
11010 if (dwarf_read_debug
)
11011 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11012 sect_offset_str (sect_off
),
11013 hex_string (dwo_unit
->signature
));
11016 /* Create the dwo_units for the CUs in a DWO_FILE.
11017 Note: This function processes DWO files only, not DWP files. */
11020 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11021 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11022 dwarf2_section_info
§ion
, htab_up
&cus_htab
)
11024 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11025 const gdb_byte
*info_ptr
, *end_ptr
;
11027 section
.read (objfile
);
11028 info_ptr
= section
.buffer
;
11030 if (info_ptr
== NULL
)
11033 if (dwarf_read_debug
)
11035 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11036 section
.get_name (),
11037 section
.get_file_name ());
11040 end_ptr
= info_ptr
+ section
.size
;
11041 while (info_ptr
< end_ptr
)
11043 struct dwarf2_per_cu_data per_cu
;
11044 struct dwo_unit read_unit
{};
11045 struct dwo_unit
*dwo_unit
;
11047 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11049 memset (&per_cu
, 0, sizeof (per_cu
));
11050 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11051 per_cu
.is_debug_types
= 0;
11052 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11053 per_cu
.section
= §ion
;
11055 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11056 if (!reader
.dummy_p
)
11057 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11058 &dwo_file
, &read_unit
);
11059 info_ptr
+= per_cu
.length
;
11061 // If the unit could not be parsed, skip it.
11062 if (read_unit
.dwo_file
== NULL
)
11065 if (cus_htab
== NULL
)
11066 cus_htab
= allocate_dwo_unit_table ();
11068 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11069 *dwo_unit
= read_unit
;
11070 slot
= htab_find_slot (cus_htab
.get (), dwo_unit
, INSERT
);
11071 gdb_assert (slot
!= NULL
);
11074 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11075 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11077 complaint (_("debug cu entry at offset %s is duplicate to"
11078 " the entry at offset %s, signature %s"),
11079 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11080 hex_string (dwo_unit
->signature
));
11082 *slot
= (void *)dwo_unit
;
11086 /* DWP file .debug_{cu,tu}_index section format:
11087 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11091 Both index sections have the same format, and serve to map a 64-bit
11092 signature to a set of section numbers. Each section begins with a header,
11093 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11094 indexes, and a pool of 32-bit section numbers. The index sections will be
11095 aligned at 8-byte boundaries in the file.
11097 The index section header consists of:
11099 V, 32 bit version number
11101 N, 32 bit number of compilation units or type units in the index
11102 M, 32 bit number of slots in the hash table
11104 Numbers are recorded using the byte order of the application binary.
11106 The hash table begins at offset 16 in the section, and consists of an array
11107 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11108 order of the application binary). Unused slots in the hash table are 0.
11109 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11111 The parallel table begins immediately after the hash table
11112 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11113 array of 32-bit indexes (using the byte order of the application binary),
11114 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11115 table contains a 32-bit index into the pool of section numbers. For unused
11116 hash table slots, the corresponding entry in the parallel table will be 0.
11118 The pool of section numbers begins immediately following the hash table
11119 (at offset 16 + 12 * M from the beginning of the section). The pool of
11120 section numbers consists of an array of 32-bit words (using the byte order
11121 of the application binary). Each item in the array is indexed starting
11122 from 0. The hash table entry provides the index of the first section
11123 number in the set. Additional section numbers in the set follow, and the
11124 set is terminated by a 0 entry (section number 0 is not used in ELF).
11126 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11127 section must be the first entry in the set, and the .debug_abbrev.dwo must
11128 be the second entry. Other members of the set may follow in any order.
11134 DWP Version 2 combines all the .debug_info, etc. sections into one,
11135 and the entries in the index tables are now offsets into these sections.
11136 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11139 Index Section Contents:
11141 Hash Table of Signatures dwp_hash_table.hash_table
11142 Parallel Table of Indices dwp_hash_table.unit_table
11143 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11144 Table of Section Sizes dwp_hash_table.v2.sizes
11146 The index section header consists of:
11148 V, 32 bit version number
11149 L, 32 bit number of columns in the table of section offsets
11150 N, 32 bit number of compilation units or type units in the index
11151 M, 32 bit number of slots in the hash table
11153 Numbers are recorded using the byte order of the application binary.
11155 The hash table has the same format as version 1.
11156 The parallel table of indices has the same format as version 1,
11157 except that the entries are origin-1 indices into the table of sections
11158 offsets and the table of section sizes.
11160 The table of offsets begins immediately following the parallel table
11161 (at offset 16 + 12 * M from the beginning of the section). The table is
11162 a two-dimensional array of 32-bit words (using the byte order of the
11163 application binary), with L columns and N+1 rows, in row-major order.
11164 Each row in the array is indexed starting from 0. The first row provides
11165 a key to the remaining rows: each column in this row provides an identifier
11166 for a debug section, and the offsets in the same column of subsequent rows
11167 refer to that section. The section identifiers are:
11169 DW_SECT_INFO 1 .debug_info.dwo
11170 DW_SECT_TYPES 2 .debug_types.dwo
11171 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11172 DW_SECT_LINE 4 .debug_line.dwo
11173 DW_SECT_LOC 5 .debug_loc.dwo
11174 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11175 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11176 DW_SECT_MACRO 8 .debug_macro.dwo
11178 The offsets provided by the CU and TU index sections are the base offsets
11179 for the contributions made by each CU or TU to the corresponding section
11180 in the package file. Each CU and TU header contains an abbrev_offset
11181 field, used to find the abbreviations table for that CU or TU within the
11182 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11183 be interpreted as relative to the base offset given in the index section.
11184 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11185 should be interpreted as relative to the base offset for .debug_line.dwo,
11186 and offsets into other debug sections obtained from DWARF attributes should
11187 also be interpreted as relative to the corresponding base offset.
11189 The table of sizes begins immediately following the table of offsets.
11190 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11191 with L columns and N rows, in row-major order. Each row in the array is
11192 indexed starting from 1 (row 0 is shared by the two tables).
11196 Hash table lookup is handled the same in version 1 and 2:
11198 We assume that N and M will not exceed 2^32 - 1.
11199 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11201 Given a 64-bit compilation unit signature or a type signature S, an entry
11202 in the hash table is located as follows:
11204 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11205 the low-order k bits all set to 1.
11207 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11209 3) If the hash table entry at index H matches the signature, use that
11210 entry. If the hash table entry at index H is unused (all zeroes),
11211 terminate the search: the signature is not present in the table.
11213 4) Let H = (H + H') modulo M. Repeat at Step 3.
11215 Because M > N and H' and M are relatively prime, the search is guaranteed
11216 to stop at an unused slot or find the match. */
11218 /* Create a hash table to map DWO IDs to their CU/TU entry in
11219 .debug_{info,types}.dwo in DWP_FILE.
11220 Returns NULL if there isn't one.
11221 Note: This function processes DWP files only, not DWO files. */
11223 static struct dwp_hash_table
*
11224 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11225 struct dwp_file
*dwp_file
, int is_debug_types
)
11227 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11228 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11229 const gdb_byte
*index_ptr
, *index_end
;
11230 struct dwarf2_section_info
*index
;
11231 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11232 struct dwp_hash_table
*htab
;
11234 if (is_debug_types
)
11235 index
= &dwp_file
->sections
.tu_index
;
11237 index
= &dwp_file
->sections
.cu_index
;
11239 if (index
->empty ())
11241 index
->read (objfile
);
11243 index_ptr
= index
->buffer
;
11244 index_end
= index_ptr
+ index
->size
;
11246 version
= read_4_bytes (dbfd
, index_ptr
);
11249 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11253 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11255 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11258 if (version
!= 1 && version
!= 2)
11260 error (_("Dwarf Error: unsupported DWP file version (%s)"
11261 " [in module %s]"),
11262 pulongest (version
), dwp_file
->name
);
11264 if (nr_slots
!= (nr_slots
& -nr_slots
))
11266 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11267 " is not power of 2 [in module %s]"),
11268 pulongest (nr_slots
), dwp_file
->name
);
11271 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11272 htab
->version
= version
;
11273 htab
->nr_columns
= nr_columns
;
11274 htab
->nr_units
= nr_units
;
11275 htab
->nr_slots
= nr_slots
;
11276 htab
->hash_table
= index_ptr
;
11277 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11279 /* Exit early if the table is empty. */
11280 if (nr_slots
== 0 || nr_units
== 0
11281 || (version
== 2 && nr_columns
== 0))
11283 /* All must be zero. */
11284 if (nr_slots
!= 0 || nr_units
!= 0
11285 || (version
== 2 && nr_columns
!= 0))
11287 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11288 " all zero [in modules %s]"),
11296 htab
->section_pool
.v1
.indices
=
11297 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11298 /* It's harder to decide whether the section is too small in v1.
11299 V1 is deprecated anyway so we punt. */
11303 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11304 int *ids
= htab
->section_pool
.v2
.section_ids
;
11305 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11306 /* Reverse map for error checking. */
11307 int ids_seen
[DW_SECT_MAX
+ 1];
11310 if (nr_columns
< 2)
11312 error (_("Dwarf Error: bad DWP hash table, too few columns"
11313 " in section table [in module %s]"),
11316 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11318 error (_("Dwarf Error: bad DWP hash table, too many columns"
11319 " in section table [in module %s]"),
11322 memset (ids
, 255, sizeof_ids
);
11323 memset (ids_seen
, 255, sizeof (ids_seen
));
11324 for (i
= 0; i
< nr_columns
; ++i
)
11326 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11328 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11330 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11331 " in section table [in module %s]"),
11332 id
, dwp_file
->name
);
11334 if (ids_seen
[id
] != -1)
11336 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11337 " id %d in section table [in module %s]"),
11338 id
, dwp_file
->name
);
11343 /* Must have exactly one info or types section. */
11344 if (((ids_seen
[DW_SECT_INFO
] != -1)
11345 + (ids_seen
[DW_SECT_TYPES
] != -1))
11348 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11349 " DWO info/types section [in module %s]"),
11352 /* Must have an abbrev section. */
11353 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11355 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11356 " section [in module %s]"),
11359 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
11360 htab
->section_pool
.v2
.sizes
=
11361 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
11362 * nr_units
* nr_columns
);
11363 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
11364 * nr_units
* nr_columns
))
11367 error (_("Dwarf Error: DWP index section is corrupt (too small)"
11368 " [in module %s]"),
11376 /* Update SECTIONS with the data from SECTP.
11378 This function is like the other "locate" section routines that are
11379 passed to bfd_map_over_sections, but in this context the sections to
11380 read comes from the DWP V1 hash table, not the full ELF section table.
11382 The result is non-zero for success, or zero if an error was found. */
11385 locate_v1_virtual_dwo_sections (asection
*sectp
,
11386 struct virtual_v1_dwo_sections
*sections
)
11388 const struct dwop_section_names
*names
= &dwop_section_names
;
11390 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
11392 /* There can be only one. */
11393 if (sections
->abbrev
.s
.section
!= NULL
)
11395 sections
->abbrev
.s
.section
= sectp
;
11396 sections
->abbrev
.size
= bfd_section_size (sectp
);
11398 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
11399 || section_is_p (sectp
->name
, &names
->types_dwo
))
11401 /* There can be only one. */
11402 if (sections
->info_or_types
.s
.section
!= NULL
)
11404 sections
->info_or_types
.s
.section
= sectp
;
11405 sections
->info_or_types
.size
= bfd_section_size (sectp
);
11407 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
11409 /* There can be only one. */
11410 if (sections
->line
.s
.section
!= NULL
)
11412 sections
->line
.s
.section
= sectp
;
11413 sections
->line
.size
= bfd_section_size (sectp
);
11415 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
11417 /* There can be only one. */
11418 if (sections
->loc
.s
.section
!= NULL
)
11420 sections
->loc
.s
.section
= sectp
;
11421 sections
->loc
.size
= bfd_section_size (sectp
);
11423 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
11425 /* There can be only one. */
11426 if (sections
->macinfo
.s
.section
!= NULL
)
11428 sections
->macinfo
.s
.section
= sectp
;
11429 sections
->macinfo
.size
= bfd_section_size (sectp
);
11431 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
11433 /* There can be only one. */
11434 if (sections
->macro
.s
.section
!= NULL
)
11436 sections
->macro
.s
.section
= sectp
;
11437 sections
->macro
.size
= bfd_section_size (sectp
);
11439 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
11441 /* There can be only one. */
11442 if (sections
->str_offsets
.s
.section
!= NULL
)
11444 sections
->str_offsets
.s
.section
= sectp
;
11445 sections
->str_offsets
.size
= bfd_section_size (sectp
);
11449 /* No other kind of section is valid. */
11456 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11457 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11458 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11459 This is for DWP version 1 files. */
11461 static struct dwo_unit
*
11462 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11463 struct dwp_file
*dwp_file
,
11464 uint32_t unit_index
,
11465 const char *comp_dir
,
11466 ULONGEST signature
, int is_debug_types
)
11468 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11469 const struct dwp_hash_table
*dwp_htab
=
11470 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11471 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11472 const char *kind
= is_debug_types
? "TU" : "CU";
11473 struct dwo_file
*dwo_file
;
11474 struct dwo_unit
*dwo_unit
;
11475 struct virtual_v1_dwo_sections sections
;
11476 void **dwo_file_slot
;
11479 gdb_assert (dwp_file
->version
== 1);
11481 if (dwarf_read_debug
)
11483 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
11485 pulongest (unit_index
), hex_string (signature
),
11489 /* Fetch the sections of this DWO unit.
11490 Put a limit on the number of sections we look for so that bad data
11491 doesn't cause us to loop forever. */
11493 #define MAX_NR_V1_DWO_SECTIONS \
11494 (1 /* .debug_info or .debug_types */ \
11495 + 1 /* .debug_abbrev */ \
11496 + 1 /* .debug_line */ \
11497 + 1 /* .debug_loc */ \
11498 + 1 /* .debug_str_offsets */ \
11499 + 1 /* .debug_macro or .debug_macinfo */ \
11500 + 1 /* trailing zero */)
11502 memset (§ions
, 0, sizeof (sections
));
11504 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
11507 uint32_t section_nr
=
11508 read_4_bytes (dbfd
,
11509 dwp_htab
->section_pool
.v1
.indices
11510 + (unit_index
+ i
) * sizeof (uint32_t));
11512 if (section_nr
== 0)
11514 if (section_nr
>= dwp_file
->num_sections
)
11516 error (_("Dwarf Error: bad DWP hash table, section number too large"
11517 " [in module %s]"),
11521 sectp
= dwp_file
->elf_sections
[section_nr
];
11522 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
11524 error (_("Dwarf Error: bad DWP hash table, invalid section found"
11525 " [in module %s]"),
11531 || sections
.info_or_types
.empty ()
11532 || sections
.abbrev
.empty ())
11534 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
11535 " [in module %s]"),
11538 if (i
== MAX_NR_V1_DWO_SECTIONS
)
11540 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
11541 " [in module %s]"),
11545 /* It's easier for the rest of the code if we fake a struct dwo_file and
11546 have dwo_unit "live" in that. At least for now.
11548 The DWP file can be made up of a random collection of CUs and TUs.
11549 However, for each CU + set of TUs that came from the same original DWO
11550 file, we can combine them back into a virtual DWO file to save space
11551 (fewer struct dwo_file objects to allocate). Remember that for really
11552 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11554 std::string virtual_dwo_name
=
11555 string_printf ("virtual-dwo/%d-%d-%d-%d",
11556 sections
.abbrev
.get_id (),
11557 sections
.line
.get_id (),
11558 sections
.loc
.get_id (),
11559 sections
.str_offsets
.get_id ());
11560 /* Can we use an existing virtual DWO file? */
11561 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11562 virtual_dwo_name
.c_str (),
11564 /* Create one if necessary. */
11565 if (*dwo_file_slot
== NULL
)
11567 if (dwarf_read_debug
)
11569 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11570 virtual_dwo_name
.c_str ());
11572 dwo_file
= new struct dwo_file
;
11573 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11574 dwo_file
->comp_dir
= comp_dir
;
11575 dwo_file
->sections
.abbrev
= sections
.abbrev
;
11576 dwo_file
->sections
.line
= sections
.line
;
11577 dwo_file
->sections
.loc
= sections
.loc
;
11578 dwo_file
->sections
.macinfo
= sections
.macinfo
;
11579 dwo_file
->sections
.macro
= sections
.macro
;
11580 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
11581 /* The "str" section is global to the entire DWP file. */
11582 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11583 /* The info or types section is assigned below to dwo_unit,
11584 there's no need to record it in dwo_file.
11585 Also, we can't simply record type sections in dwo_file because
11586 we record a pointer into the vector in dwo_unit. As we collect more
11587 types we'll grow the vector and eventually have to reallocate space
11588 for it, invalidating all copies of pointers into the previous
11590 *dwo_file_slot
= dwo_file
;
11594 if (dwarf_read_debug
)
11596 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11597 virtual_dwo_name
.c_str ());
11599 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11602 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11603 dwo_unit
->dwo_file
= dwo_file
;
11604 dwo_unit
->signature
= signature
;
11605 dwo_unit
->section
=
11606 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11607 *dwo_unit
->section
= sections
.info_or_types
;
11608 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11613 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
11614 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
11615 piece within that section used by a TU/CU, return a virtual section
11616 of just that piece. */
11618 static struct dwarf2_section_info
11619 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11620 struct dwarf2_section_info
*section
,
11621 bfd_size_type offset
, bfd_size_type size
)
11623 struct dwarf2_section_info result
;
11626 gdb_assert (section
!= NULL
);
11627 gdb_assert (!section
->is_virtual
);
11629 memset (&result
, 0, sizeof (result
));
11630 result
.s
.containing_section
= section
;
11631 result
.is_virtual
= true;
11636 sectp
= section
->get_bfd_section ();
11638 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
11639 bounds of the real section. This is a pretty-rare event, so just
11640 flag an error (easier) instead of a warning and trying to cope. */
11642 || offset
+ size
> bfd_section_size (sectp
))
11644 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
11645 " in section %s [in module %s]"),
11646 sectp
? bfd_section_name (sectp
) : "<unknown>",
11647 objfile_name (dwarf2_per_objfile
->objfile
));
11650 result
.virtual_offset
= offset
;
11651 result
.size
= size
;
11655 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
11656 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
11657 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
11658 This is for DWP version 2 files. */
11660 static struct dwo_unit
*
11661 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11662 struct dwp_file
*dwp_file
,
11663 uint32_t unit_index
,
11664 const char *comp_dir
,
11665 ULONGEST signature
, int is_debug_types
)
11667 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11668 const struct dwp_hash_table
*dwp_htab
=
11669 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11670 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11671 const char *kind
= is_debug_types
? "TU" : "CU";
11672 struct dwo_file
*dwo_file
;
11673 struct dwo_unit
*dwo_unit
;
11674 struct virtual_v2_dwo_sections sections
;
11675 void **dwo_file_slot
;
11678 gdb_assert (dwp_file
->version
== 2);
11680 if (dwarf_read_debug
)
11682 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
11684 pulongest (unit_index
), hex_string (signature
),
11688 /* Fetch the section offsets of this DWO unit. */
11690 memset (§ions
, 0, sizeof (sections
));
11692 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
11694 uint32_t offset
= read_4_bytes (dbfd
,
11695 dwp_htab
->section_pool
.v2
.offsets
11696 + (((unit_index
- 1) * dwp_htab
->nr_columns
11698 * sizeof (uint32_t)));
11699 uint32_t size
= read_4_bytes (dbfd
,
11700 dwp_htab
->section_pool
.v2
.sizes
11701 + (((unit_index
- 1) * dwp_htab
->nr_columns
11703 * sizeof (uint32_t)));
11705 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
11708 case DW_SECT_TYPES
:
11709 sections
.info_or_types_offset
= offset
;
11710 sections
.info_or_types_size
= size
;
11712 case DW_SECT_ABBREV
:
11713 sections
.abbrev_offset
= offset
;
11714 sections
.abbrev_size
= size
;
11717 sections
.line_offset
= offset
;
11718 sections
.line_size
= size
;
11721 sections
.loc_offset
= offset
;
11722 sections
.loc_size
= size
;
11724 case DW_SECT_STR_OFFSETS
:
11725 sections
.str_offsets_offset
= offset
;
11726 sections
.str_offsets_size
= size
;
11728 case DW_SECT_MACINFO
:
11729 sections
.macinfo_offset
= offset
;
11730 sections
.macinfo_size
= size
;
11732 case DW_SECT_MACRO
:
11733 sections
.macro_offset
= offset
;
11734 sections
.macro_size
= size
;
11739 /* It's easier for the rest of the code if we fake a struct dwo_file and
11740 have dwo_unit "live" in that. At least for now.
11742 The DWP file can be made up of a random collection of CUs and TUs.
11743 However, for each CU + set of TUs that came from the same original DWO
11744 file, we can combine them back into a virtual DWO file to save space
11745 (fewer struct dwo_file objects to allocate). Remember that for really
11746 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
11748 std::string virtual_dwo_name
=
11749 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
11750 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
11751 (long) (sections
.line_size
? sections
.line_offset
: 0),
11752 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
11753 (long) (sections
.str_offsets_size
11754 ? sections
.str_offsets_offset
: 0));
11755 /* Can we use an existing virtual DWO file? */
11756 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
11757 virtual_dwo_name
.c_str (),
11759 /* Create one if necessary. */
11760 if (*dwo_file_slot
== NULL
)
11762 if (dwarf_read_debug
)
11764 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
11765 virtual_dwo_name
.c_str ());
11767 dwo_file
= new struct dwo_file
;
11768 dwo_file
->dwo_name
= objfile
->intern (virtual_dwo_name
);
11769 dwo_file
->comp_dir
= comp_dir
;
11770 dwo_file
->sections
.abbrev
=
11771 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
11772 sections
.abbrev_offset
, sections
.abbrev_size
);
11773 dwo_file
->sections
.line
=
11774 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
11775 sections
.line_offset
, sections
.line_size
);
11776 dwo_file
->sections
.loc
=
11777 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
11778 sections
.loc_offset
, sections
.loc_size
);
11779 dwo_file
->sections
.macinfo
=
11780 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
11781 sections
.macinfo_offset
, sections
.macinfo_size
);
11782 dwo_file
->sections
.macro
=
11783 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
11784 sections
.macro_offset
, sections
.macro_size
);
11785 dwo_file
->sections
.str_offsets
=
11786 create_dwp_v2_section (dwarf2_per_objfile
,
11787 &dwp_file
->sections
.str_offsets
,
11788 sections
.str_offsets_offset
,
11789 sections
.str_offsets_size
);
11790 /* The "str" section is global to the entire DWP file. */
11791 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
11792 /* The info or types section is assigned below to dwo_unit,
11793 there's no need to record it in dwo_file.
11794 Also, we can't simply record type sections in dwo_file because
11795 we record a pointer into the vector in dwo_unit. As we collect more
11796 types we'll grow the vector and eventually have to reallocate space
11797 for it, invalidating all copies of pointers into the previous
11799 *dwo_file_slot
= dwo_file
;
11803 if (dwarf_read_debug
)
11805 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
11806 virtual_dwo_name
.c_str ());
11808 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
11811 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11812 dwo_unit
->dwo_file
= dwo_file
;
11813 dwo_unit
->signature
= signature
;
11814 dwo_unit
->section
=
11815 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
11816 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
11818 ? &dwp_file
->sections
.types
11819 : &dwp_file
->sections
.info
,
11820 sections
.info_or_types_offset
,
11821 sections
.info_or_types_size
);
11822 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
11827 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
11828 Returns NULL if the signature isn't found. */
11830 static struct dwo_unit
*
11831 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11832 struct dwp_file
*dwp_file
, const char *comp_dir
,
11833 ULONGEST signature
, int is_debug_types
)
11835 const struct dwp_hash_table
*dwp_htab
=
11836 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
11837 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11838 uint32_t mask
= dwp_htab
->nr_slots
- 1;
11839 uint32_t hash
= signature
& mask
;
11840 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
11843 struct dwo_unit find_dwo_cu
;
11845 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
11846 find_dwo_cu
.signature
= signature
;
11847 slot
= htab_find_slot (is_debug_types
11848 ? dwp_file
->loaded_tus
.get ()
11849 : dwp_file
->loaded_cus
.get (),
11850 &find_dwo_cu
, INSERT
);
11853 return (struct dwo_unit
*) *slot
;
11855 /* Use a for loop so that we don't loop forever on bad debug info. */
11856 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
11858 ULONGEST signature_in_table
;
11860 signature_in_table
=
11861 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
11862 if (signature_in_table
== signature
)
11864 uint32_t unit_index
=
11865 read_4_bytes (dbfd
,
11866 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
11868 if (dwp_file
->version
== 1)
11870 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
11871 dwp_file
, unit_index
,
11872 comp_dir
, signature
,
11877 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
11878 dwp_file
, unit_index
,
11879 comp_dir
, signature
,
11882 return (struct dwo_unit
*) *slot
;
11884 if (signature_in_table
== 0)
11886 hash
= (hash
+ hash2
) & mask
;
11889 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
11890 " [in module %s]"),
11894 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
11895 Open the file specified by FILE_NAME and hand it off to BFD for
11896 preliminary analysis. Return a newly initialized bfd *, which
11897 includes a canonicalized copy of FILE_NAME.
11898 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
11899 SEARCH_CWD is true if the current directory is to be searched.
11900 It will be searched before debug-file-directory.
11901 If successful, the file is added to the bfd include table of the
11902 objfile's bfd (see gdb_bfd_record_inclusion).
11903 If unable to find/open the file, return NULL.
11904 NOTE: This function is derived from symfile_bfd_open. */
11906 static gdb_bfd_ref_ptr
11907 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11908 const char *file_name
, int is_dwp
, int search_cwd
)
11911 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
11912 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
11913 to debug_file_directory. */
11914 const char *search_path
;
11915 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
11917 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
11920 if (*debug_file_directory
!= '\0')
11922 search_path_holder
.reset (concat (".", dirname_separator_string
,
11923 debug_file_directory
,
11925 search_path
= search_path_holder
.get ();
11931 search_path
= debug_file_directory
;
11933 openp_flags flags
= OPF_RETURN_REALPATH
;
11935 flags
|= OPF_SEARCH_IN_PATH
;
11937 gdb::unique_xmalloc_ptr
<char> absolute_name
;
11938 desc
= openp (search_path
, flags
, file_name
,
11939 O_RDONLY
| O_BINARY
, &absolute_name
);
11943 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
11945 if (sym_bfd
== NULL
)
11947 bfd_set_cacheable (sym_bfd
.get (), 1);
11949 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
11952 /* Success. Record the bfd as having been included by the objfile's bfd.
11953 This is important because things like demangled_names_hash lives in the
11954 objfile's per_bfd space and may have references to things like symbol
11955 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
11956 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
11961 /* Try to open DWO file FILE_NAME.
11962 COMP_DIR is the DW_AT_comp_dir attribute.
11963 The result is the bfd handle of the file.
11964 If there is a problem finding or opening the file, return NULL.
11965 Upon success, the canonicalized path of the file is stored in the bfd,
11966 same as symfile_bfd_open. */
11968 static gdb_bfd_ref_ptr
11969 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11970 const char *file_name
, const char *comp_dir
)
11972 if (IS_ABSOLUTE_PATH (file_name
))
11973 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
11974 0 /*is_dwp*/, 0 /*search_cwd*/);
11976 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
11978 if (comp_dir
!= NULL
)
11980 gdb::unique_xmalloc_ptr
<char> path_to_try
11981 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
11983 /* NOTE: If comp_dir is a relative path, this will also try the
11984 search path, which seems useful. */
11985 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
11986 path_to_try
.get (),
11988 1 /*search_cwd*/));
11993 /* That didn't work, try debug-file-directory, which, despite its name,
11994 is a list of paths. */
11996 if (*debug_file_directory
== '\0')
11999 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12000 0 /*is_dwp*/, 1 /*search_cwd*/);
12003 /* This function is mapped across the sections and remembers the offset and
12004 size of each of the DWO debugging sections we are interested in. */
12007 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12009 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12010 const struct dwop_section_names
*names
= &dwop_section_names
;
12012 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12014 dwo_sections
->abbrev
.s
.section
= sectp
;
12015 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12017 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12019 dwo_sections
->info
.s
.section
= sectp
;
12020 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12022 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12024 dwo_sections
->line
.s
.section
= sectp
;
12025 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12027 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12029 dwo_sections
->loc
.s
.section
= sectp
;
12030 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12032 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12034 dwo_sections
->macinfo
.s
.section
= sectp
;
12035 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12037 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12039 dwo_sections
->macro
.s
.section
= sectp
;
12040 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12042 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12044 dwo_sections
->str
.s
.section
= sectp
;
12045 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12047 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12049 dwo_sections
->str_offsets
.s
.section
= sectp
;
12050 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12052 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12054 struct dwarf2_section_info type_section
;
12056 memset (&type_section
, 0, sizeof (type_section
));
12057 type_section
.s
.section
= sectp
;
12058 type_section
.size
= bfd_section_size (sectp
);
12059 dwo_sections
->types
.push_back (type_section
);
12063 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12064 by PER_CU. This is for the non-DWP case.
12065 The result is NULL if DWO_NAME can't be found. */
12067 static struct dwo_file
*
12068 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12069 const char *dwo_name
, const char *comp_dir
)
12071 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12073 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12076 if (dwarf_read_debug
)
12077 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12081 dwo_file_up
dwo_file (new struct dwo_file
);
12082 dwo_file
->dwo_name
= dwo_name
;
12083 dwo_file
->comp_dir
= comp_dir
;
12084 dwo_file
->dbfd
= std::move (dbfd
);
12086 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12087 &dwo_file
->sections
);
12089 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12090 dwo_file
->sections
.info
, dwo_file
->cus
);
12092 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12093 dwo_file
->sections
.types
, dwo_file
->tus
);
12095 if (dwarf_read_debug
)
12096 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12098 return dwo_file
.release ();
12101 /* This function is mapped across the sections and remembers the offset and
12102 size of each of the DWP debugging sections common to version 1 and 2 that
12103 we are interested in. */
12106 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12107 void *dwp_file_ptr
)
12109 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12110 const struct dwop_section_names
*names
= &dwop_section_names
;
12111 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12113 /* Record the ELF section number for later lookup: this is what the
12114 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12115 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12116 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12118 /* Look for specific sections that we need. */
12119 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12121 dwp_file
->sections
.str
.s
.section
= sectp
;
12122 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12124 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12126 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12127 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12129 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12131 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12132 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12136 /* This function is mapped across the sections and remembers the offset and
12137 size of each of the DWP version 2 debugging sections that we are interested
12138 in. This is split into a separate function because we don't know if we
12139 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12142 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12144 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12145 const struct dwop_section_names
*names
= &dwop_section_names
;
12146 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12148 /* Record the ELF section number for later lookup: this is what the
12149 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12150 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12151 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12153 /* Look for specific sections that we need. */
12154 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12156 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12157 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12159 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12161 dwp_file
->sections
.info
.s
.section
= sectp
;
12162 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12164 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12166 dwp_file
->sections
.line
.s
.section
= sectp
;
12167 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12169 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12171 dwp_file
->sections
.loc
.s
.section
= sectp
;
12172 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12174 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12176 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12177 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12179 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12181 dwp_file
->sections
.macro
.s
.section
= sectp
;
12182 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12184 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12186 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12187 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12189 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12191 dwp_file
->sections
.types
.s
.section
= sectp
;
12192 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12196 /* Hash function for dwp_file loaded CUs/TUs. */
12199 hash_dwp_loaded_cutus (const void *item
)
12201 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12203 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12204 return dwo_unit
->signature
;
12207 /* Equality function for dwp_file loaded CUs/TUs. */
12210 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12212 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12213 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12215 return dua
->signature
== dub
->signature
;
12218 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12221 allocate_dwp_loaded_cutus_table ()
12223 return htab_up (htab_create_alloc (3,
12224 hash_dwp_loaded_cutus
,
12225 eq_dwp_loaded_cutus
,
12226 NULL
, xcalloc
, xfree
));
12229 /* Try to open DWP file FILE_NAME.
12230 The result is the bfd handle of the file.
12231 If there is a problem finding or opening the file, return NULL.
12232 Upon success, the canonicalized path of the file is stored in the bfd,
12233 same as symfile_bfd_open. */
12235 static gdb_bfd_ref_ptr
12236 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12237 const char *file_name
)
12239 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12241 1 /*search_cwd*/));
12245 /* Work around upstream bug 15652.
12246 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12247 [Whether that's a "bug" is debatable, but it is getting in our way.]
12248 We have no real idea where the dwp file is, because gdb's realpath-ing
12249 of the executable's path may have discarded the needed info.
12250 [IWBN if the dwp file name was recorded in the executable, akin to
12251 .gnu_debuglink, but that doesn't exist yet.]
12252 Strip the directory from FILE_NAME and search again. */
12253 if (*debug_file_directory
!= '\0')
12255 /* Don't implicitly search the current directory here.
12256 If the user wants to search "." to handle this case,
12257 it must be added to debug-file-directory. */
12258 return try_open_dwop_file (dwarf2_per_objfile
,
12259 lbasename (file_name
), 1 /*is_dwp*/,
12266 /* Initialize the use of the DWP file for the current objfile.
12267 By convention the name of the DWP file is ${objfile}.dwp.
12268 The result is NULL if it can't be found. */
12270 static std::unique_ptr
<struct dwp_file
>
12271 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12273 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12275 /* Try to find first .dwp for the binary file before any symbolic links
12278 /* If the objfile is a debug file, find the name of the real binary
12279 file and get the name of dwp file from there. */
12280 std::string dwp_name
;
12281 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12283 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12284 const char *backlink_basename
= lbasename (backlink
->original_name
);
12286 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12289 dwp_name
= objfile
->original_name
;
12291 dwp_name
+= ".dwp";
12293 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12295 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12297 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12298 dwp_name
= objfile_name (objfile
);
12299 dwp_name
+= ".dwp";
12300 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12305 if (dwarf_read_debug
)
12306 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12307 return std::unique_ptr
<dwp_file
> ();
12310 const char *name
= bfd_get_filename (dbfd
.get ());
12311 std::unique_ptr
<struct dwp_file
> dwp_file
12312 (new struct dwp_file (name
, std::move (dbfd
)));
12314 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12315 dwp_file
->elf_sections
=
12316 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12317 dwp_file
->num_sections
, asection
*);
12319 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12320 dwarf2_locate_common_dwp_sections
,
12323 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12326 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12329 /* The DWP file version is stored in the hash table. Oh well. */
12330 if (dwp_file
->cus
&& dwp_file
->tus
12331 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12333 /* Technically speaking, we should try to limp along, but this is
12334 pretty bizarre. We use pulongest here because that's the established
12335 portability solution (e.g, we cannot use %u for uint32_t). */
12336 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12337 " TU version %s [in DWP file %s]"),
12338 pulongest (dwp_file
->cus
->version
),
12339 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12343 dwp_file
->version
= dwp_file
->cus
->version
;
12344 else if (dwp_file
->tus
)
12345 dwp_file
->version
= dwp_file
->tus
->version
;
12347 dwp_file
->version
= 2;
12349 if (dwp_file
->version
== 2)
12350 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12351 dwarf2_locate_v2_dwp_sections
,
12354 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table ();
12355 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table ();
12357 if (dwarf_read_debug
)
12359 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
12360 fprintf_unfiltered (gdb_stdlog
,
12361 " %s CUs, %s TUs\n",
12362 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
12363 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
12369 /* Wrapper around open_and_init_dwp_file, only open it once. */
12371 static struct dwp_file
*
12372 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12374 if (! dwarf2_per_objfile
->dwp_checked
)
12376 dwarf2_per_objfile
->dwp_file
12377 = open_and_init_dwp_file (dwarf2_per_objfile
);
12378 dwarf2_per_objfile
->dwp_checked
= 1;
12380 return dwarf2_per_objfile
->dwp_file
.get ();
12383 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
12384 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
12385 or in the DWP file for the objfile, referenced by THIS_UNIT.
12386 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
12387 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
12389 This is called, for example, when wanting to read a variable with a
12390 complex location. Therefore we don't want to do file i/o for every call.
12391 Therefore we don't want to look for a DWO file on every call.
12392 Therefore we first see if we've already seen SIGNATURE in a DWP file,
12393 then we check if we've already seen DWO_NAME, and only THEN do we check
12396 The result is a pointer to the dwo_unit object or NULL if we didn't find it
12397 (dwo_id mismatch or couldn't find the DWO/DWP file). */
12399 static struct dwo_unit
*
12400 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
12401 const char *dwo_name
, const char *comp_dir
,
12402 ULONGEST signature
, int is_debug_types
)
12404 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
12405 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12406 const char *kind
= is_debug_types
? "TU" : "CU";
12407 void **dwo_file_slot
;
12408 struct dwo_file
*dwo_file
;
12409 struct dwp_file
*dwp_file
;
12411 /* First see if there's a DWP file.
12412 If we have a DWP file but didn't find the DWO inside it, don't
12413 look for the original DWO file. It makes gdb behave differently
12414 depending on whether one is debugging in the build tree. */
12416 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
12417 if (dwp_file
!= NULL
)
12419 const struct dwp_hash_table
*dwp_htab
=
12420 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12422 if (dwp_htab
!= NULL
)
12424 struct dwo_unit
*dwo_cutu
=
12425 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
12426 signature
, is_debug_types
);
12428 if (dwo_cutu
!= NULL
)
12430 if (dwarf_read_debug
)
12432 fprintf_unfiltered (gdb_stdlog
,
12433 "Virtual DWO %s %s found: @%s\n",
12434 kind
, hex_string (signature
),
12435 host_address_to_string (dwo_cutu
));
12443 /* No DWP file, look for the DWO file. */
12445 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12446 dwo_name
, comp_dir
);
12447 if (*dwo_file_slot
== NULL
)
12449 /* Read in the file and build a table of the CUs/TUs it contains. */
12450 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
12452 /* NOTE: This will be NULL if unable to open the file. */
12453 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12455 if (dwo_file
!= NULL
)
12457 struct dwo_unit
*dwo_cutu
= NULL
;
12459 if (is_debug_types
&& dwo_file
->tus
)
12461 struct dwo_unit find_dwo_cutu
;
12463 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12464 find_dwo_cutu
.signature
= signature
;
12466 = (struct dwo_unit
*) htab_find (dwo_file
->tus
.get (),
12469 else if (!is_debug_types
&& dwo_file
->cus
)
12471 struct dwo_unit find_dwo_cutu
;
12473 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
12474 find_dwo_cutu
.signature
= signature
;
12475 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
.get (),
12479 if (dwo_cutu
!= NULL
)
12481 if (dwarf_read_debug
)
12483 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
12484 kind
, dwo_name
, hex_string (signature
),
12485 host_address_to_string (dwo_cutu
));
12492 /* We didn't find it. This could mean a dwo_id mismatch, or
12493 someone deleted the DWO/DWP file, or the search path isn't set up
12494 correctly to find the file. */
12496 if (dwarf_read_debug
)
12498 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
12499 kind
, dwo_name
, hex_string (signature
));
12502 /* This is a warning and not a complaint because it can be caused by
12503 pilot error (e.g., user accidentally deleting the DWO). */
12505 /* Print the name of the DWP file if we looked there, helps the user
12506 better diagnose the problem. */
12507 std::string dwp_text
;
12509 if (dwp_file
!= NULL
)
12510 dwp_text
= string_printf (" [in DWP file %s]",
12511 lbasename (dwp_file
->name
));
12513 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
12514 " [in module %s]"),
12515 kind
, dwo_name
, hex_string (signature
),
12517 this_unit
->is_debug_types
? "TU" : "CU",
12518 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
12523 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
12524 See lookup_dwo_cutu_unit for details. */
12526 static struct dwo_unit
*
12527 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
12528 const char *dwo_name
, const char *comp_dir
,
12529 ULONGEST signature
)
12531 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
12534 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
12535 See lookup_dwo_cutu_unit for details. */
12537 static struct dwo_unit
*
12538 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
12539 const char *dwo_name
, const char *comp_dir
)
12541 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
12544 /* Traversal function for queue_and_load_all_dwo_tus. */
12547 queue_and_load_dwo_tu (void **slot
, void *info
)
12549 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
12550 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
12551 ULONGEST signature
= dwo_unit
->signature
;
12552 struct signatured_type
*sig_type
=
12553 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
12555 if (sig_type
!= NULL
)
12557 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
12559 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
12560 a real dependency of PER_CU on SIG_TYPE. That is detected later
12561 while processing PER_CU. */
12562 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
12563 load_full_type_unit (sig_cu
);
12564 per_cu
->imported_symtabs_push (sig_cu
);
12570 /* Queue all TUs contained in the DWO of PER_CU to be read in.
12571 The DWO may have the only definition of the type, though it may not be
12572 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
12573 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
12576 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
12578 struct dwo_unit
*dwo_unit
;
12579 struct dwo_file
*dwo_file
;
12581 gdb_assert (!per_cu
->is_debug_types
);
12582 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
12583 gdb_assert (per_cu
->cu
!= NULL
);
12585 dwo_unit
= per_cu
->cu
->dwo_unit
;
12586 gdb_assert (dwo_unit
!= NULL
);
12588 dwo_file
= dwo_unit
->dwo_file
;
12589 if (dwo_file
->tus
!= NULL
)
12590 htab_traverse_noresize (dwo_file
->tus
.get (), queue_and_load_dwo_tu
,
12594 /* Read in various DIEs. */
12596 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
12597 Inherit only the children of the DW_AT_abstract_origin DIE not being
12598 already referenced by DW_AT_abstract_origin from the children of the
12602 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
12604 struct die_info
*child_die
;
12605 sect_offset
*offsetp
;
12606 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
12607 struct die_info
*origin_die
;
12608 /* Iterator of the ORIGIN_DIE children. */
12609 struct die_info
*origin_child_die
;
12610 struct attribute
*attr
;
12611 struct dwarf2_cu
*origin_cu
;
12612 struct pending
**origin_previous_list_in_scope
;
12614 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
12618 /* Note that following die references may follow to a die in a
12622 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
12624 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
12626 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
12627 origin_cu
->list_in_scope
= cu
->list_in_scope
;
12629 if (die
->tag
!= origin_die
->tag
12630 && !(die
->tag
== DW_TAG_inlined_subroutine
12631 && origin_die
->tag
== DW_TAG_subprogram
))
12632 complaint (_("DIE %s and its abstract origin %s have different tags"),
12633 sect_offset_str (die
->sect_off
),
12634 sect_offset_str (origin_die
->sect_off
));
12636 std::vector
<sect_offset
> offsets
;
12638 for (child_die
= die
->child
;
12639 child_die
&& child_die
->tag
;
12640 child_die
= child_die
->sibling
)
12642 struct die_info
*child_origin_die
;
12643 struct dwarf2_cu
*child_origin_cu
;
12645 /* We are trying to process concrete instance entries:
12646 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
12647 it's not relevant to our analysis here. i.e. detecting DIEs that are
12648 present in the abstract instance but not referenced in the concrete
12650 if (child_die
->tag
== DW_TAG_call_site
12651 || child_die
->tag
== DW_TAG_GNU_call_site
)
12654 /* For each CHILD_DIE, find the corresponding child of
12655 ORIGIN_DIE. If there is more than one layer of
12656 DW_AT_abstract_origin, follow them all; there shouldn't be,
12657 but GCC versions at least through 4.4 generate this (GCC PR
12659 child_origin_die
= child_die
;
12660 child_origin_cu
= cu
;
12663 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
12667 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
12671 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
12672 counterpart may exist. */
12673 if (child_origin_die
!= child_die
)
12675 if (child_die
->tag
!= child_origin_die
->tag
12676 && !(child_die
->tag
== DW_TAG_inlined_subroutine
12677 && child_origin_die
->tag
== DW_TAG_subprogram
))
12678 complaint (_("Child DIE %s and its abstract origin %s have "
12680 sect_offset_str (child_die
->sect_off
),
12681 sect_offset_str (child_origin_die
->sect_off
));
12682 if (child_origin_die
->parent
!= origin_die
)
12683 complaint (_("Child DIE %s and its abstract origin %s have "
12684 "different parents"),
12685 sect_offset_str (child_die
->sect_off
),
12686 sect_offset_str (child_origin_die
->sect_off
));
12688 offsets
.push_back (child_origin_die
->sect_off
);
12691 std::sort (offsets
.begin (), offsets
.end ());
12692 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
12693 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
12694 if (offsetp
[-1] == *offsetp
)
12695 complaint (_("Multiple children of DIE %s refer "
12696 "to DIE %s as their abstract origin"),
12697 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
12699 offsetp
= offsets
.data ();
12700 origin_child_die
= origin_die
->child
;
12701 while (origin_child_die
&& origin_child_die
->tag
)
12703 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
12704 while (offsetp
< offsets_end
12705 && *offsetp
< origin_child_die
->sect_off
)
12707 if (offsetp
>= offsets_end
12708 || *offsetp
> origin_child_die
->sect_off
)
12710 /* Found that ORIGIN_CHILD_DIE is really not referenced.
12711 Check whether we're already processing ORIGIN_CHILD_DIE.
12712 This can happen with mutually referenced abstract_origins.
12714 if (!origin_child_die
->in_process
)
12715 process_die (origin_child_die
, origin_cu
);
12717 origin_child_die
= origin_child_die
->sibling
;
12719 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
12721 if (cu
!= origin_cu
)
12722 compute_delayed_physnames (origin_cu
);
12726 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12728 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12729 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12730 struct context_stack
*newobj
;
12733 struct die_info
*child_die
;
12734 struct attribute
*attr
, *call_line
, *call_file
;
12736 CORE_ADDR baseaddr
;
12737 struct block
*block
;
12738 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
12739 std::vector
<struct symbol
*> template_args
;
12740 struct template_symbol
*templ_func
= NULL
;
12744 /* If we do not have call site information, we can't show the
12745 caller of this inlined function. That's too confusing, so
12746 only use the scope for local variables. */
12747 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
12748 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
12749 if (call_line
== NULL
|| call_file
== NULL
)
12751 read_lexical_block_scope (die
, cu
);
12756 baseaddr
= objfile
->text_section_offset ();
12758 name
= dwarf2_name (die
, cu
);
12760 /* Ignore functions with missing or empty names. These are actually
12761 illegal according to the DWARF standard. */
12764 complaint (_("missing name for subprogram DIE at %s"),
12765 sect_offset_str (die
->sect_off
));
12769 /* Ignore functions with missing or invalid low and high pc attributes. */
12770 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
12771 <= PC_BOUNDS_INVALID
)
12773 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
12774 if (!attr
|| !DW_UNSND (attr
))
12775 complaint (_("cannot get low and high bounds "
12776 "for subprogram DIE at %s"),
12777 sect_offset_str (die
->sect_off
));
12781 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12782 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12784 /* If we have any template arguments, then we must allocate a
12785 different sort of symbol. */
12786 for (child_die
= die
->child
; child_die
; child_die
= child_die
->sibling
)
12788 if (child_die
->tag
== DW_TAG_template_type_param
12789 || child_die
->tag
== DW_TAG_template_value_param
)
12791 templ_func
= allocate_template_symbol (objfile
);
12792 templ_func
->subclass
= SYMBOL_TEMPLATE
;
12797 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
12798 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
12799 (struct symbol
*) templ_func
);
12801 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
12802 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
12805 /* If there is a location expression for DW_AT_frame_base, record
12807 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
12808 if (attr
!= nullptr)
12809 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
12811 /* If there is a location for the static link, record it. */
12812 newobj
->static_link
= NULL
;
12813 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
12814 if (attr
!= nullptr)
12816 newobj
->static_link
12817 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
12818 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
12819 cu
->per_cu
->addr_type ());
12822 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
12824 if (die
->child
!= NULL
)
12826 child_die
= die
->child
;
12827 while (child_die
&& child_die
->tag
)
12829 if (child_die
->tag
== DW_TAG_template_type_param
12830 || child_die
->tag
== DW_TAG_template_value_param
)
12832 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
12835 template_args
.push_back (arg
);
12838 process_die (child_die
, cu
);
12839 child_die
= child_die
->sibling
;
12843 inherit_abstract_dies (die
, cu
);
12845 /* If we have a DW_AT_specification, we might need to import using
12846 directives from the context of the specification DIE. See the
12847 comment in determine_prefix. */
12848 if (cu
->language
== language_cplus
12849 && dwarf2_attr (die
, DW_AT_specification
, cu
))
12851 struct dwarf2_cu
*spec_cu
= cu
;
12852 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
12856 child_die
= spec_die
->child
;
12857 while (child_die
&& child_die
->tag
)
12859 if (child_die
->tag
== DW_TAG_imported_module
)
12860 process_die (child_die
, spec_cu
);
12861 child_die
= child_die
->sibling
;
12864 /* In some cases, GCC generates specification DIEs that
12865 themselves contain DW_AT_specification attributes. */
12866 spec_die
= die_specification (spec_die
, &spec_cu
);
12870 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12871 /* Make a block for the local symbols within. */
12872 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
12873 cstk
.static_link
, lowpc
, highpc
);
12875 /* For C++, set the block's scope. */
12876 if ((cu
->language
== language_cplus
12877 || cu
->language
== language_fortran
12878 || cu
->language
== language_d
12879 || cu
->language
== language_rust
)
12880 && cu
->processing_has_namespace_info
)
12881 block_set_scope (block
, determine_prefix (die
, cu
),
12882 &objfile
->objfile_obstack
);
12884 /* If we have address ranges, record them. */
12885 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12887 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
12889 /* Attach template arguments to function. */
12890 if (!template_args
.empty ())
12892 gdb_assert (templ_func
!= NULL
);
12894 templ_func
->n_template_arguments
= template_args
.size ();
12895 templ_func
->template_arguments
12896 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
12897 templ_func
->n_template_arguments
);
12898 memcpy (templ_func
->template_arguments
,
12899 template_args
.data (),
12900 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
12902 /* Make sure that the symtab is set on the new symbols. Even
12903 though they don't appear in this symtab directly, other parts
12904 of gdb assume that symbols do, and this is reasonably
12906 for (symbol
*sym
: template_args
)
12907 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
12910 /* In C++, we can have functions nested inside functions (e.g., when
12911 a function declares a class that has methods). This means that
12912 when we finish processing a function scope, we may need to go
12913 back to building a containing block's symbol lists. */
12914 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12915 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12917 /* If we've finished processing a top-level function, subsequent
12918 symbols go in the file symbol list. */
12919 if (cu
->get_builder ()->outermost_context_p ())
12920 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
12923 /* Process all the DIES contained within a lexical block scope. Start
12924 a new scope, process the dies, and then close the scope. */
12927 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
12929 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
12930 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
12931 CORE_ADDR lowpc
, highpc
;
12932 struct die_info
*child_die
;
12933 CORE_ADDR baseaddr
;
12935 baseaddr
= objfile
->text_section_offset ();
12937 /* Ignore blocks with missing or invalid low and high pc attributes. */
12938 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
12939 as multiple lexical blocks? Handling children in a sane way would
12940 be nasty. Might be easier to properly extend generic blocks to
12941 describe ranges. */
12942 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
12944 case PC_BOUNDS_NOT_PRESENT
:
12945 /* DW_TAG_lexical_block has no attributes, process its children as if
12946 there was no wrapping by that DW_TAG_lexical_block.
12947 GCC does no longer produces such DWARF since GCC r224161. */
12948 for (child_die
= die
->child
;
12949 child_die
!= NULL
&& child_die
->tag
;
12950 child_die
= child_die
->sibling
)
12951 process_die (child_die
, cu
);
12953 case PC_BOUNDS_INVALID
:
12956 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
12957 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
12959 cu
->get_builder ()->push_context (0, lowpc
);
12960 if (die
->child
!= NULL
)
12962 child_die
= die
->child
;
12963 while (child_die
&& child_die
->tag
)
12965 process_die (child_die
, cu
);
12966 child_die
= child_die
->sibling
;
12969 inherit_abstract_dies (die
, cu
);
12970 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
12972 if (*cu
->get_builder ()->get_local_symbols () != NULL
12973 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
12975 struct block
*block
12976 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
12977 cstk
.start_addr
, highpc
);
12979 /* Note that recording ranges after traversing children, as we
12980 do here, means that recording a parent's ranges entails
12981 walking across all its children's ranges as they appear in
12982 the address map, which is quadratic behavior.
12984 It would be nicer to record the parent's ranges before
12985 traversing its children, simply overriding whatever you find
12986 there. But since we don't even decide whether to create a
12987 block until after we've traversed its children, that's hard
12989 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
12991 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
12992 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
12995 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
12998 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13000 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13001 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13002 CORE_ADDR pc
, baseaddr
;
13003 struct attribute
*attr
;
13004 struct call_site
*call_site
, call_site_local
;
13007 struct die_info
*child_die
;
13009 baseaddr
= objfile
->text_section_offset ();
13011 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13014 /* This was a pre-DWARF-5 GNU extension alias
13015 for DW_AT_call_return_pc. */
13016 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13020 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13021 "DIE %s [in module %s]"),
13022 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13025 pc
= attr
->value_as_address () + baseaddr
;
13026 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13028 if (cu
->call_site_htab
== NULL
)
13029 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13030 NULL
, &objfile
->objfile_obstack
,
13031 hashtab_obstack_allocate
, NULL
);
13032 call_site_local
.pc
= pc
;
13033 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13036 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13037 "DIE %s [in module %s]"),
13038 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13039 objfile_name (objfile
));
13043 /* Count parameters at the caller. */
13046 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13047 child_die
= child_die
->sibling
)
13049 if (child_die
->tag
!= DW_TAG_call_site_parameter
13050 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13052 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13053 "DW_TAG_call_site child DIE %s [in module %s]"),
13054 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13055 objfile_name (objfile
));
13063 = ((struct call_site
*)
13064 obstack_alloc (&objfile
->objfile_obstack
,
13065 sizeof (*call_site
)
13066 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13068 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13069 call_site
->pc
= pc
;
13071 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13072 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13074 struct die_info
*func_die
;
13076 /* Skip also over DW_TAG_inlined_subroutine. */
13077 for (func_die
= die
->parent
;
13078 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13079 && func_die
->tag
!= DW_TAG_subroutine_type
;
13080 func_die
= func_die
->parent
);
13082 /* DW_AT_call_all_calls is a superset
13083 of DW_AT_call_all_tail_calls. */
13085 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13086 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13087 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13088 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13090 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13091 not complete. But keep CALL_SITE for look ups via call_site_htab,
13092 both the initial caller containing the real return address PC and
13093 the final callee containing the current PC of a chain of tail
13094 calls do not need to have the tail call list complete. But any
13095 function candidate for a virtual tail call frame searched via
13096 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13097 determined unambiguously. */
13101 struct type
*func_type
= NULL
;
13104 func_type
= get_die_type (func_die
, cu
);
13105 if (func_type
!= NULL
)
13107 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13109 /* Enlist this call site to the function. */
13110 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13111 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13114 complaint (_("Cannot find function owning DW_TAG_call_site "
13115 "DIE %s [in module %s]"),
13116 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13120 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13122 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13124 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13127 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13128 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13130 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13131 if (!attr
|| (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0))
13132 /* Keep NULL DWARF_BLOCK. */;
13133 else if (attr
->form_is_block ())
13135 struct dwarf2_locexpr_baton
*dlbaton
;
13137 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13138 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13139 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13140 dlbaton
->per_cu
= cu
->per_cu
;
13142 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13144 else if (attr
->form_is_ref ())
13146 struct dwarf2_cu
*target_cu
= cu
;
13147 struct die_info
*target_die
;
13149 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13150 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13151 if (die_is_declaration (target_die
, target_cu
))
13153 const char *target_physname
;
13155 /* Prefer the mangled name; otherwise compute the demangled one. */
13156 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13157 if (target_physname
== NULL
)
13158 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13159 if (target_physname
== NULL
)
13160 complaint (_("DW_AT_call_target target DIE has invalid "
13161 "physname, for referencing DIE %s [in module %s]"),
13162 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13164 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13170 /* DW_AT_entry_pc should be preferred. */
13171 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13172 <= PC_BOUNDS_INVALID
)
13173 complaint (_("DW_AT_call_target target DIE has invalid "
13174 "low pc, for referencing DIE %s [in module %s]"),
13175 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13178 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13179 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13184 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13185 "block nor reference, for DIE %s [in module %s]"),
13186 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13188 call_site
->per_cu
= cu
->per_cu
;
13190 for (child_die
= die
->child
;
13191 child_die
&& child_die
->tag
;
13192 child_die
= child_die
->sibling
)
13194 struct call_site_parameter
*parameter
;
13195 struct attribute
*loc
, *origin
;
13197 if (child_die
->tag
!= DW_TAG_call_site_parameter
13198 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13200 /* Already printed the complaint above. */
13204 gdb_assert (call_site
->parameter_count
< nparams
);
13205 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13207 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13208 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13209 register is contained in DW_AT_call_value. */
13211 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13212 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13213 if (origin
== NULL
)
13215 /* This was a pre-DWARF-5 GNU extension alias
13216 for DW_AT_call_parameter. */
13217 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13219 if (loc
== NULL
&& origin
!= NULL
&& origin
->form_is_ref ())
13221 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13223 sect_offset sect_off
= origin
->get_ref_die_offset ();
13224 if (!cu
->header
.offset_in_cu_p (sect_off
))
13226 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13227 binding can be done only inside one CU. Such referenced DIE
13228 therefore cannot be even moved to DW_TAG_partial_unit. */
13229 complaint (_("DW_AT_call_parameter offset is not in CU for "
13230 "DW_TAG_call_site child DIE %s [in module %s]"),
13231 sect_offset_str (child_die
->sect_off
),
13232 objfile_name (objfile
));
13235 parameter
->u
.param_cu_off
13236 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13238 else if (loc
== NULL
|| origin
!= NULL
|| !loc
->form_is_block ())
13240 complaint (_("No DW_FORM_block* DW_AT_location for "
13241 "DW_TAG_call_site child DIE %s [in module %s]"),
13242 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13247 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13248 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13249 if (parameter
->u
.dwarf_reg
!= -1)
13250 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13251 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13252 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13253 ¶meter
->u
.fb_offset
))
13254 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13257 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13258 "for DW_FORM_block* DW_AT_location is supported for "
13259 "DW_TAG_call_site child DIE %s "
13261 sect_offset_str (child_die
->sect_off
),
13262 objfile_name (objfile
));
13267 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13269 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13270 if (attr
== NULL
|| !attr
->form_is_block ())
13272 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13273 "DW_TAG_call_site child DIE %s [in module %s]"),
13274 sect_offset_str (child_die
->sect_off
),
13275 objfile_name (objfile
));
13278 parameter
->value
= DW_BLOCK (attr
)->data
;
13279 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13281 /* Parameters are not pre-cleared by memset above. */
13282 parameter
->data_value
= NULL
;
13283 parameter
->data_value_size
= 0;
13284 call_site
->parameter_count
++;
13286 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13288 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13289 if (attr
!= nullptr)
13291 if (!attr
->form_is_block ())
13292 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13293 "DW_TAG_call_site child DIE %s [in module %s]"),
13294 sect_offset_str (child_die
->sect_off
),
13295 objfile_name (objfile
));
13298 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13299 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13305 /* Helper function for read_variable. If DIE represents a virtual
13306 table, then return the type of the concrete object that is
13307 associated with the virtual table. Otherwise, return NULL. */
13309 static struct type
*
13310 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13312 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13316 /* Find the type DIE. */
13317 struct die_info
*type_die
= NULL
;
13318 struct dwarf2_cu
*type_cu
= cu
;
13320 if (attr
->form_is_ref ())
13321 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13322 if (type_die
== NULL
)
13325 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13327 return die_containing_type (type_die
, type_cu
);
13330 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13333 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13335 struct rust_vtable_symbol
*storage
= NULL
;
13337 if (cu
->language
== language_rust
)
13339 struct type
*containing_type
= rust_containing_type (die
, cu
);
13341 if (containing_type
!= NULL
)
13343 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13345 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13346 initialize_objfile_symbol (storage
);
13347 storage
->concrete_type
= containing_type
;
13348 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13352 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13353 struct attribute
*abstract_origin
13354 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13355 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
13356 if (res
== NULL
&& loc
&& abstract_origin
)
13358 /* We have a variable without a name, but with a location and an abstract
13359 origin. This may be a concrete instance of an abstract variable
13360 referenced from an DW_OP_GNU_variable_value, so save it to find it back
13362 struct dwarf2_cu
*origin_cu
= cu
;
13363 struct die_info
*origin_die
13364 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
13365 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
13366 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
13370 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
13371 reading .debug_rnglists.
13372 Callback's type should be:
13373 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13374 Return true if the attributes are present and valid, otherwise,
13377 template <typename Callback
>
13379 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
13380 Callback
&&callback
)
13382 struct dwarf2_per_objfile
*dwarf2_per_objfile
13383 = cu
->per_cu
->dwarf2_per_objfile
;
13384 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13385 bfd
*obfd
= objfile
->obfd
;
13386 /* Base address selection entry. */
13387 gdb::optional
<CORE_ADDR
> base
;
13388 const gdb_byte
*buffer
;
13389 CORE_ADDR baseaddr
;
13390 bool overflow
= false;
13392 base
= cu
->base_address
;
13394 dwarf2_per_objfile
->rnglists
.read (objfile
);
13395 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
13397 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13401 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
13403 baseaddr
= objfile
->text_section_offset ();
13407 /* Initialize it due to a false compiler warning. */
13408 CORE_ADDR range_beginning
= 0, range_end
= 0;
13409 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
13410 + dwarf2_per_objfile
->rnglists
.size
);
13411 unsigned int bytes_read
;
13413 if (buffer
== buf_end
)
13418 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
13421 case DW_RLE_end_of_list
:
13423 case DW_RLE_base_address
:
13424 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13429 base
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13430 buffer
+= bytes_read
;
13432 case DW_RLE_start_length
:
13433 if (buffer
+ cu
->header
.addr_size
> buf_end
)
13438 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13440 buffer
+= bytes_read
;
13441 range_end
= (range_beginning
13442 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
13443 buffer
+= bytes_read
;
13444 if (buffer
> buf_end
)
13450 case DW_RLE_offset_pair
:
13451 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13452 buffer
+= bytes_read
;
13453 if (buffer
> buf_end
)
13458 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
13459 buffer
+= bytes_read
;
13460 if (buffer
> buf_end
)
13466 case DW_RLE_start_end
:
13467 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
13472 range_beginning
= cu
->header
.read_address (obfd
, buffer
,
13474 buffer
+= bytes_read
;
13475 range_end
= cu
->header
.read_address (obfd
, buffer
, &bytes_read
);
13476 buffer
+= bytes_read
;
13479 complaint (_("Invalid .debug_rnglists data (no base address)"));
13482 if (rlet
== DW_RLE_end_of_list
|| overflow
)
13484 if (rlet
== DW_RLE_base_address
)
13487 if (!base
.has_value ())
13489 /* We have no valid base address for the ranges
13491 complaint (_("Invalid .debug_rnglists data (no base address)"));
13495 if (range_beginning
> range_end
)
13497 /* Inverted range entries are invalid. */
13498 complaint (_("Invalid .debug_rnglists data (inverted range)"));
13502 /* Empty range entries have no effect. */
13503 if (range_beginning
== range_end
)
13506 range_beginning
+= *base
;
13507 range_end
+= *base
;
13509 /* A not-uncommon case of bad debug info.
13510 Don't pollute the addrmap with bad data. */
13511 if (range_beginning
+ baseaddr
== 0
13512 && !dwarf2_per_objfile
->has_section_at_zero
)
13514 complaint (_(".debug_rnglists entry has start address of zero"
13515 " [in module %s]"), objfile_name (objfile
));
13519 callback (range_beginning
, range_end
);
13524 complaint (_("Offset %d is not terminated "
13525 "for DW_AT_ranges attribute"),
13533 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
13534 Callback's type should be:
13535 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
13536 Return 1 if the attributes are present and valid, otherwise, return 0. */
13538 template <typename Callback
>
13540 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
13541 Callback
&&callback
)
13543 struct dwarf2_per_objfile
*dwarf2_per_objfile
13544 = cu
->per_cu
->dwarf2_per_objfile
;
13545 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13546 struct comp_unit_head
*cu_header
= &cu
->header
;
13547 bfd
*obfd
= objfile
->obfd
;
13548 unsigned int addr_size
= cu_header
->addr_size
;
13549 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
13550 /* Base address selection entry. */
13551 gdb::optional
<CORE_ADDR
> base
;
13552 unsigned int dummy
;
13553 const gdb_byte
*buffer
;
13554 CORE_ADDR baseaddr
;
13556 if (cu_header
->version
>= 5)
13557 return dwarf2_rnglists_process (offset
, cu
, callback
);
13559 base
= cu
->base_address
;
13561 dwarf2_per_objfile
->ranges
.read (objfile
);
13562 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
13564 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
13568 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
13570 baseaddr
= objfile
->text_section_offset ();
13574 CORE_ADDR range_beginning
, range_end
;
13576 range_beginning
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13577 buffer
+= addr_size
;
13578 range_end
= cu
->header
.read_address (obfd
, buffer
, &dummy
);
13579 buffer
+= addr_size
;
13580 offset
+= 2 * addr_size
;
13582 /* An end of list marker is a pair of zero addresses. */
13583 if (range_beginning
== 0 && range_end
== 0)
13584 /* Found the end of list entry. */
13587 /* Each base address selection entry is a pair of 2 values.
13588 The first is the largest possible address, the second is
13589 the base address. Check for a base address here. */
13590 if ((range_beginning
& mask
) == mask
)
13592 /* If we found the largest possible address, then we already
13593 have the base address in range_end. */
13598 if (!base
.has_value ())
13600 /* We have no valid base address for the ranges
13602 complaint (_("Invalid .debug_ranges data (no base address)"));
13606 if (range_beginning
> range_end
)
13608 /* Inverted range entries are invalid. */
13609 complaint (_("Invalid .debug_ranges data (inverted range)"));
13613 /* Empty range entries have no effect. */
13614 if (range_beginning
== range_end
)
13617 range_beginning
+= *base
;
13618 range_end
+= *base
;
13620 /* A not-uncommon case of bad debug info.
13621 Don't pollute the addrmap with bad data. */
13622 if (range_beginning
+ baseaddr
== 0
13623 && !dwarf2_per_objfile
->has_section_at_zero
)
13625 complaint (_(".debug_ranges entry has start address of zero"
13626 " [in module %s]"), objfile_name (objfile
));
13630 callback (range_beginning
, range_end
);
13636 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
13637 Return 1 if the attributes are present and valid, otherwise, return 0.
13638 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
13641 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
13642 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
13643 dwarf2_psymtab
*ranges_pst
)
13645 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13646 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13647 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
13650 CORE_ADDR high
= 0;
13653 retval
= dwarf2_ranges_process (offset
, cu
,
13654 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
13656 if (ranges_pst
!= NULL
)
13661 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13662 range_beginning
+ baseaddr
)
13664 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
13665 range_end
+ baseaddr
)
13667 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
13668 lowpc
, highpc
- 1, ranges_pst
);
13671 /* FIXME: This is recording everything as a low-high
13672 segment of consecutive addresses. We should have a
13673 data structure for discontiguous block ranges
13677 low
= range_beginning
;
13683 if (range_beginning
< low
)
13684 low
= range_beginning
;
13685 if (range_end
> high
)
13693 /* If the first entry is an end-of-list marker, the range
13694 describes an empty scope, i.e. no instructions. */
13700 *high_return
= high
;
13704 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
13705 definition for the return value. *LOWPC and *HIGHPC are set iff
13706 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
13708 static enum pc_bounds_kind
13709 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
13710 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
13711 dwarf2_psymtab
*pst
)
13713 struct dwarf2_per_objfile
*dwarf2_per_objfile
13714 = cu
->per_cu
->dwarf2_per_objfile
;
13715 struct attribute
*attr
;
13716 struct attribute
*attr_high
;
13718 CORE_ADDR high
= 0;
13719 enum pc_bounds_kind ret
;
13721 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13724 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13725 if (attr
!= nullptr)
13727 low
= attr
->value_as_address ();
13728 high
= attr_high
->value_as_address ();
13729 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13733 /* Found high w/o low attribute. */
13734 return PC_BOUNDS_INVALID
;
13736 /* Found consecutive range of addresses. */
13737 ret
= PC_BOUNDS_HIGH_LOW
;
13741 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13744 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13745 We take advantage of the fact that DW_AT_ranges does not appear
13746 in DW_TAG_compile_unit of DWO files. */
13747 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13748 unsigned int ranges_offset
= (DW_UNSND (attr
)
13749 + (need_ranges_base
13753 /* Value of the DW_AT_ranges attribute is the offset in the
13754 .debug_ranges section. */
13755 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
13756 return PC_BOUNDS_INVALID
;
13757 /* Found discontinuous range of addresses. */
13758 ret
= PC_BOUNDS_RANGES
;
13761 return PC_BOUNDS_NOT_PRESENT
;
13764 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
13766 return PC_BOUNDS_INVALID
;
13768 /* When using the GNU linker, .gnu.linkonce. sections are used to
13769 eliminate duplicate copies of functions and vtables and such.
13770 The linker will arbitrarily choose one and discard the others.
13771 The AT_*_pc values for such functions refer to local labels in
13772 these sections. If the section from that file was discarded, the
13773 labels are not in the output, so the relocs get a value of 0.
13774 If this is a discarded function, mark the pc bounds as invalid,
13775 so that GDB will ignore it. */
13776 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
13777 return PC_BOUNDS_INVALID
;
13785 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
13786 its low and high PC addresses. Do nothing if these addresses could not
13787 be determined. Otherwise, set LOWPC to the low address if it is smaller,
13788 and HIGHPC to the high address if greater than HIGHPC. */
13791 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
13792 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13793 struct dwarf2_cu
*cu
)
13795 CORE_ADDR low
, high
;
13796 struct die_info
*child
= die
->child
;
13798 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
13800 *lowpc
= std::min (*lowpc
, low
);
13801 *highpc
= std::max (*highpc
, high
);
13804 /* If the language does not allow nested subprograms (either inside
13805 subprograms or lexical blocks), we're done. */
13806 if (cu
->language
!= language_ada
)
13809 /* Check all the children of the given DIE. If it contains nested
13810 subprograms, then check their pc bounds. Likewise, we need to
13811 check lexical blocks as well, as they may also contain subprogram
13813 while (child
&& child
->tag
)
13815 if (child
->tag
== DW_TAG_subprogram
13816 || child
->tag
== DW_TAG_lexical_block
)
13817 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
13818 child
= child
->sibling
;
13822 /* Get the low and high pc's represented by the scope DIE, and store
13823 them in *LOWPC and *HIGHPC. If the correct values can't be
13824 determined, set *LOWPC to -1 and *HIGHPC to 0. */
13827 get_scope_pc_bounds (struct die_info
*die
,
13828 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
13829 struct dwarf2_cu
*cu
)
13831 CORE_ADDR best_low
= (CORE_ADDR
) -1;
13832 CORE_ADDR best_high
= (CORE_ADDR
) 0;
13833 CORE_ADDR current_low
, current_high
;
13835 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
13836 >= PC_BOUNDS_RANGES
)
13838 best_low
= current_low
;
13839 best_high
= current_high
;
13843 struct die_info
*child
= die
->child
;
13845 while (child
&& child
->tag
)
13847 switch (child
->tag
) {
13848 case DW_TAG_subprogram
:
13849 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
13851 case DW_TAG_namespace
:
13852 case DW_TAG_module
:
13853 /* FIXME: carlton/2004-01-16: Should we do this for
13854 DW_TAG_class_type/DW_TAG_structure_type, too? I think
13855 that current GCC's always emit the DIEs corresponding
13856 to definitions of methods of classes as children of a
13857 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
13858 the DIEs giving the declarations, which could be
13859 anywhere). But I don't see any reason why the
13860 standards says that they have to be there. */
13861 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
13863 if (current_low
!= ((CORE_ADDR
) -1))
13865 best_low
= std::min (best_low
, current_low
);
13866 best_high
= std::max (best_high
, current_high
);
13874 child
= child
->sibling
;
13879 *highpc
= best_high
;
13882 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
13886 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
13887 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
13889 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13890 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13891 struct attribute
*attr
;
13892 struct attribute
*attr_high
;
13894 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
13897 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13898 if (attr
!= nullptr)
13900 CORE_ADDR low
= attr
->value_as_address ();
13901 CORE_ADDR high
= attr_high
->value_as_address ();
13903 if (cu
->header
.version
>= 4 && attr_high
->form_is_constant ())
13906 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
13907 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
13908 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
13912 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
13913 if (attr
!= nullptr)
13915 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
13916 We take advantage of the fact that DW_AT_ranges does not appear
13917 in DW_TAG_compile_unit of DWO files. */
13918 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
13920 /* The value of the DW_AT_ranges attribute is the offset of the
13921 address range list in the .debug_ranges section. */
13922 unsigned long offset
= (DW_UNSND (attr
)
13923 + (need_ranges_base
? cu
->ranges_base
: 0));
13925 std::vector
<blockrange
> blockvec
;
13926 dwarf2_ranges_process (offset
, cu
,
13927 [&] (CORE_ADDR start
, CORE_ADDR end
)
13931 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
13932 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
13933 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
13934 blockvec
.emplace_back (start
, end
);
13937 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
13941 /* Check whether the producer field indicates either of GCC < 4.6, or the
13942 Intel C/C++ compiler, and cache the result in CU. */
13945 check_producer (struct dwarf2_cu
*cu
)
13949 if (cu
->producer
== NULL
)
13951 /* For unknown compilers expect their behavior is DWARF version
13954 GCC started to support .debug_types sections by -gdwarf-4 since
13955 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
13956 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
13957 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
13958 interpreted incorrectly by GDB now - GCC PR debug/48229. */
13960 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
13962 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
13963 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
13965 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
13967 cu
->producer_is_icc
= true;
13968 cu
->producer_is_icc_lt_14
= major
< 14;
13970 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
13971 cu
->producer_is_codewarrior
= true;
13974 /* For other non-GCC compilers, expect their behavior is DWARF version
13978 cu
->checked_producer
= true;
13981 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
13982 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
13983 during 4.6.0 experimental. */
13986 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
13988 if (!cu
->checked_producer
)
13989 check_producer (cu
);
13991 return cu
->producer_is_gxx_lt_4_6
;
13995 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
13996 with incorrect is_stmt attributes. */
13999 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14001 if (!cu
->checked_producer
)
14002 check_producer (cu
);
14004 return cu
->producer_is_codewarrior
;
14007 /* Return the default accessibility type if it is not overridden by
14008 DW_AT_accessibility. */
14010 static enum dwarf_access_attribute
14011 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14013 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14015 /* The default DWARF 2 accessibility for members is public, the default
14016 accessibility for inheritance is private. */
14018 if (die
->tag
!= DW_TAG_inheritance
)
14019 return DW_ACCESS_public
;
14021 return DW_ACCESS_private
;
14025 /* DWARF 3+ defines the default accessibility a different way. The same
14026 rules apply now for DW_TAG_inheritance as for the members and it only
14027 depends on the container kind. */
14029 if (die
->parent
->tag
== DW_TAG_class_type
)
14030 return DW_ACCESS_private
;
14032 return DW_ACCESS_public
;
14036 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14037 offset. If the attribute was not found return 0, otherwise return
14038 1. If it was found but could not properly be handled, set *OFFSET
14042 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14045 struct attribute
*attr
;
14047 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14052 /* Note that we do not check for a section offset first here.
14053 This is because DW_AT_data_member_location is new in DWARF 4,
14054 so if we see it, we can assume that a constant form is really
14055 a constant and not a section offset. */
14056 if (attr
->form_is_constant ())
14057 *offset
= attr
->constant_value (0);
14058 else if (attr
->form_is_section_offset ())
14059 dwarf2_complex_location_expr_complaint ();
14060 else if (attr
->form_is_block ())
14061 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14063 dwarf2_complex_location_expr_complaint ();
14071 /* Add an aggregate field to the field list. */
14074 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14075 struct dwarf2_cu
*cu
)
14077 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14078 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14079 struct nextfield
*new_field
;
14080 struct attribute
*attr
;
14082 const char *fieldname
= "";
14084 if (die
->tag
== DW_TAG_inheritance
)
14086 fip
->baseclasses
.emplace_back ();
14087 new_field
= &fip
->baseclasses
.back ();
14091 fip
->fields
.emplace_back ();
14092 new_field
= &fip
->fields
.back ();
14095 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14096 if (attr
!= nullptr)
14097 new_field
->accessibility
= DW_UNSND (attr
);
14099 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14100 if (new_field
->accessibility
!= DW_ACCESS_public
)
14101 fip
->non_public_fields
= 1;
14103 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14104 if (attr
!= nullptr)
14105 new_field
->virtuality
= DW_UNSND (attr
);
14107 new_field
->virtuality
= DW_VIRTUALITY_none
;
14109 fp
= &new_field
->field
;
14111 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14115 /* Data member other than a C++ static data member. */
14117 /* Get type of field. */
14118 fp
->type
= die_type (die
, cu
);
14120 SET_FIELD_BITPOS (*fp
, 0);
14122 /* Get bit size of field (zero if none). */
14123 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14124 if (attr
!= nullptr)
14126 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14130 FIELD_BITSIZE (*fp
) = 0;
14133 /* Get bit offset of field. */
14134 if (handle_data_member_location (die
, cu
, &offset
))
14135 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14136 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14137 if (attr
!= nullptr)
14139 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14141 /* For big endian bits, the DW_AT_bit_offset gives the
14142 additional bit offset from the MSB of the containing
14143 anonymous object to the MSB of the field. We don't
14144 have to do anything special since we don't need to
14145 know the size of the anonymous object. */
14146 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14150 /* For little endian bits, compute the bit offset to the
14151 MSB of the anonymous object, subtract off the number of
14152 bits from the MSB of the field to the MSB of the
14153 object, and then subtract off the number of bits of
14154 the field itself. The result is the bit offset of
14155 the LSB of the field. */
14156 int anonymous_size
;
14157 int bit_offset
= DW_UNSND (attr
);
14159 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14160 if (attr
!= nullptr)
14162 /* The size of the anonymous object containing
14163 the bit field is explicit, so use the
14164 indicated size (in bytes). */
14165 anonymous_size
= DW_UNSND (attr
);
14169 /* The size of the anonymous object containing
14170 the bit field must be inferred from the type
14171 attribute of the data member containing the
14173 anonymous_size
= TYPE_LENGTH (fp
->type
);
14175 SET_FIELD_BITPOS (*fp
,
14176 (FIELD_BITPOS (*fp
)
14177 + anonymous_size
* bits_per_byte
14178 - bit_offset
- FIELD_BITSIZE (*fp
)));
14181 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14183 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14184 + attr
->constant_value (0)));
14186 /* Get name of field. */
14187 fieldname
= dwarf2_name (die
, cu
);
14188 if (fieldname
== NULL
)
14191 /* The name is already allocated along with this objfile, so we don't
14192 need to duplicate it for the type. */
14193 fp
->name
= fieldname
;
14195 /* Change accessibility for artificial fields (e.g. virtual table
14196 pointer or virtual base class pointer) to private. */
14197 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14199 FIELD_ARTIFICIAL (*fp
) = 1;
14200 new_field
->accessibility
= DW_ACCESS_private
;
14201 fip
->non_public_fields
= 1;
14204 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14206 /* C++ static member. */
14208 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14209 is a declaration, but all versions of G++ as of this writing
14210 (so through at least 3.2.1) incorrectly generate
14211 DW_TAG_variable tags. */
14213 const char *physname
;
14215 /* Get name of field. */
14216 fieldname
= dwarf2_name (die
, cu
);
14217 if (fieldname
== NULL
)
14220 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14222 /* Only create a symbol if this is an external value.
14223 new_symbol checks this and puts the value in the global symbol
14224 table, which we want. If it is not external, new_symbol
14225 will try to put the value in cu->list_in_scope which is wrong. */
14226 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14228 /* A static const member, not much different than an enum as far as
14229 we're concerned, except that we can support more types. */
14230 new_symbol (die
, NULL
, cu
);
14233 /* Get physical name. */
14234 physname
= dwarf2_physname (fieldname
, die
, cu
);
14236 /* The name is already allocated along with this objfile, so we don't
14237 need to duplicate it for the type. */
14238 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14239 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14240 FIELD_NAME (*fp
) = fieldname
;
14242 else if (die
->tag
== DW_TAG_inheritance
)
14246 /* C++ base class field. */
14247 if (handle_data_member_location (die
, cu
, &offset
))
14248 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14249 FIELD_BITSIZE (*fp
) = 0;
14250 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14251 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14253 else if (die
->tag
== DW_TAG_variant_part
)
14255 /* process_structure_scope will treat this DIE as a union. */
14256 process_structure_scope (die
, cu
);
14258 /* The variant part is relative to the start of the enclosing
14260 SET_FIELD_BITPOS (*fp
, 0);
14261 fp
->type
= get_die_type (die
, cu
);
14262 fp
->artificial
= 1;
14263 fp
->name
= "<<variant>>";
14265 /* Normally a DW_TAG_variant_part won't have a size, but our
14266 representation requires one, so set it to the maximum of the
14267 child sizes, being sure to account for the offset at which
14268 each child is seen. */
14269 if (TYPE_LENGTH (fp
->type
) == 0)
14272 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14274 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14275 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14279 TYPE_LENGTH (fp
->type
) = max
;
14283 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14286 /* Can the type given by DIE define another type? */
14289 type_can_define_types (const struct die_info
*die
)
14293 case DW_TAG_typedef
:
14294 case DW_TAG_class_type
:
14295 case DW_TAG_structure_type
:
14296 case DW_TAG_union_type
:
14297 case DW_TAG_enumeration_type
:
14305 /* Add a type definition defined in the scope of the FIP's class. */
14308 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14309 struct dwarf2_cu
*cu
)
14311 struct decl_field fp
;
14312 memset (&fp
, 0, sizeof (fp
));
14314 gdb_assert (type_can_define_types (die
));
14316 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14317 fp
.name
= dwarf2_name (die
, cu
);
14318 fp
.type
= read_type_die (die
, cu
);
14320 /* Save accessibility. */
14321 enum dwarf_access_attribute accessibility
;
14322 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14324 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14326 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14327 switch (accessibility
)
14329 case DW_ACCESS_public
:
14330 /* The assumed value if neither private nor protected. */
14332 case DW_ACCESS_private
:
14335 case DW_ACCESS_protected
:
14336 fp
.is_protected
= 1;
14339 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14342 if (die
->tag
== DW_TAG_typedef
)
14343 fip
->typedef_field_list
.push_back (fp
);
14345 fip
->nested_types_list
.push_back (fp
);
14348 /* Create the vector of fields, and attach it to the type. */
14351 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
14352 struct dwarf2_cu
*cu
)
14354 int nfields
= fip
->nfields ();
14356 /* Record the field count, allocate space for the array of fields,
14357 and create blank accessibility bitfields if necessary. */
14358 TYPE_NFIELDS (type
) = nfields
;
14359 TYPE_FIELDS (type
) = (struct field
*)
14360 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
14362 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
14364 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14366 TYPE_FIELD_PRIVATE_BITS (type
) =
14367 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14368 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
14370 TYPE_FIELD_PROTECTED_BITS (type
) =
14371 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14372 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
14374 TYPE_FIELD_IGNORE_BITS (type
) =
14375 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
14376 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
14379 /* If the type has baseclasses, allocate and clear a bit vector for
14380 TYPE_FIELD_VIRTUAL_BITS. */
14381 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
14383 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
14384 unsigned char *pointer
;
14386 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14387 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
14388 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
14389 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
14390 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
14393 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
14395 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
14397 for (int index
= 0; index
< nfields
; ++index
)
14399 struct nextfield
&field
= fip
->fields
[index
];
14401 if (field
.variant
.is_discriminant
)
14402 di
->discriminant_index
= index
;
14403 else if (field
.variant
.default_branch
)
14404 di
->default_index
= index
;
14406 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
14410 /* Copy the saved-up fields into the field vector. */
14411 for (int i
= 0; i
< nfields
; ++i
)
14413 struct nextfield
&field
14414 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
14415 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
14417 TYPE_FIELD (type
, i
) = field
.field
;
14418 switch (field
.accessibility
)
14420 case DW_ACCESS_private
:
14421 if (cu
->language
!= language_ada
)
14422 SET_TYPE_FIELD_PRIVATE (type
, i
);
14425 case DW_ACCESS_protected
:
14426 if (cu
->language
!= language_ada
)
14427 SET_TYPE_FIELD_PROTECTED (type
, i
);
14430 case DW_ACCESS_public
:
14434 /* Unknown accessibility. Complain and treat it as public. */
14436 complaint (_("unsupported accessibility %d"),
14437 field
.accessibility
);
14441 if (i
< fip
->baseclasses
.size ())
14443 switch (field
.virtuality
)
14445 case DW_VIRTUALITY_virtual
:
14446 case DW_VIRTUALITY_pure_virtual
:
14447 if (cu
->language
== language_ada
)
14448 error (_("unexpected virtuality in component of Ada type"));
14449 SET_TYPE_FIELD_VIRTUAL (type
, i
);
14456 /* Return true if this member function is a constructor, false
14460 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
14462 const char *fieldname
;
14463 const char *type_name
;
14466 if (die
->parent
== NULL
)
14469 if (die
->parent
->tag
!= DW_TAG_structure_type
14470 && die
->parent
->tag
!= DW_TAG_union_type
14471 && die
->parent
->tag
!= DW_TAG_class_type
)
14474 fieldname
= dwarf2_name (die
, cu
);
14475 type_name
= dwarf2_name (die
->parent
, cu
);
14476 if (fieldname
== NULL
|| type_name
== NULL
)
14479 len
= strlen (fieldname
);
14480 return (strncmp (fieldname
, type_name
, len
) == 0
14481 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
14484 /* Check if the given VALUE is a recognized enum
14485 dwarf_defaulted_attribute constant according to DWARF5 spec,
14489 is_valid_DW_AT_defaulted (ULONGEST value
)
14493 case DW_DEFAULTED_no
:
14494 case DW_DEFAULTED_in_class
:
14495 case DW_DEFAULTED_out_of_class
:
14499 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
14503 /* Add a member function to the proper fieldlist. */
14506 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
14507 struct type
*type
, struct dwarf2_cu
*cu
)
14509 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14510 struct attribute
*attr
;
14512 struct fnfieldlist
*flp
= nullptr;
14513 struct fn_field
*fnp
;
14514 const char *fieldname
;
14515 struct type
*this_type
;
14516 enum dwarf_access_attribute accessibility
;
14518 if (cu
->language
== language_ada
)
14519 error (_("unexpected member function in Ada type"));
14521 /* Get name of member function. */
14522 fieldname
= dwarf2_name (die
, cu
);
14523 if (fieldname
== NULL
)
14526 /* Look up member function name in fieldlist. */
14527 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14529 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
14531 flp
= &fip
->fnfieldlists
[i
];
14536 /* Create a new fnfieldlist if necessary. */
14537 if (flp
== nullptr)
14539 fip
->fnfieldlists
.emplace_back ();
14540 flp
= &fip
->fnfieldlists
.back ();
14541 flp
->name
= fieldname
;
14542 i
= fip
->fnfieldlists
.size () - 1;
14545 /* Create a new member function field and add it to the vector of
14547 flp
->fnfields
.emplace_back ();
14548 fnp
= &flp
->fnfields
.back ();
14550 /* Delay processing of the physname until later. */
14551 if (cu
->language
== language_cplus
)
14552 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
14556 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
14557 fnp
->physname
= physname
? physname
: "";
14560 fnp
->type
= alloc_type (objfile
);
14561 this_type
= read_type_die (die
, cu
);
14562 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
14564 int nparams
= TYPE_NFIELDS (this_type
);
14566 /* TYPE is the domain of this method, and THIS_TYPE is the type
14567 of the method itself (TYPE_CODE_METHOD). */
14568 smash_to_method_type (fnp
->type
, type
,
14569 TYPE_TARGET_TYPE (this_type
),
14570 TYPE_FIELDS (this_type
),
14571 TYPE_NFIELDS (this_type
),
14572 TYPE_VARARGS (this_type
));
14574 /* Handle static member functions.
14575 Dwarf2 has no clean way to discern C++ static and non-static
14576 member functions. G++ helps GDB by marking the first
14577 parameter for non-static member functions (which is the this
14578 pointer) as artificial. We obtain this information from
14579 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
14580 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
14581 fnp
->voffset
= VOFFSET_STATIC
;
14584 complaint (_("member function type missing for '%s'"),
14585 dwarf2_full_name (fieldname
, die
, cu
));
14587 /* Get fcontext from DW_AT_containing_type if present. */
14588 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
14589 fnp
->fcontext
= die_containing_type (die
, cu
);
14591 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
14592 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
14594 /* Get accessibility. */
14595 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14596 if (attr
!= nullptr)
14597 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14599 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14600 switch (accessibility
)
14602 case DW_ACCESS_private
:
14603 fnp
->is_private
= 1;
14605 case DW_ACCESS_protected
:
14606 fnp
->is_protected
= 1;
14610 /* Check for artificial methods. */
14611 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
14612 if (attr
&& DW_UNSND (attr
) != 0)
14613 fnp
->is_artificial
= 1;
14615 /* Check for defaulted methods. */
14616 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
14617 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
14618 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
14620 /* Check for deleted methods. */
14621 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
14622 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
14623 fnp
->is_deleted
= 1;
14625 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
14627 /* Get index in virtual function table if it is a virtual member
14628 function. For older versions of GCC, this is an offset in the
14629 appropriate virtual table, as specified by DW_AT_containing_type.
14630 For everyone else, it is an expression to be evaluated relative
14631 to the object address. */
14633 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
14634 if (attr
!= nullptr)
14636 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
> 0)
14638 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
14640 /* Old-style GCC. */
14641 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
14643 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
14644 || (DW_BLOCK (attr
)->size
> 1
14645 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
14646 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
14648 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14649 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
14650 dwarf2_complex_location_expr_complaint ();
14652 fnp
->voffset
/= cu
->header
.addr_size
;
14656 dwarf2_complex_location_expr_complaint ();
14658 if (!fnp
->fcontext
)
14660 /* If there is no `this' field and no DW_AT_containing_type,
14661 we cannot actually find a base class context for the
14663 if (TYPE_NFIELDS (this_type
) == 0
14664 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
14666 complaint (_("cannot determine context for virtual member "
14667 "function \"%s\" (offset %s)"),
14668 fieldname
, sect_offset_str (die
->sect_off
));
14673 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
14677 else if (attr
->form_is_section_offset ())
14679 dwarf2_complex_location_expr_complaint ();
14683 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
14689 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14690 if (attr
&& DW_UNSND (attr
))
14692 /* GCC does this, as of 2008-08-25; PR debug/37237. */
14693 complaint (_("Member function \"%s\" (offset %s) is virtual "
14694 "but the vtable offset is not specified"),
14695 fieldname
, sect_offset_str (die
->sect_off
));
14696 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14697 TYPE_CPLUS_DYNAMIC (type
) = 1;
14702 /* Create the vector of member function fields, and attach it to the type. */
14705 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
14706 struct dwarf2_cu
*cu
)
14708 if (cu
->language
== language_ada
)
14709 error (_("unexpected member functions in Ada type"));
14711 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14712 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
14714 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
14716 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
14718 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
14719 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
14721 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
14722 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
14723 fn_flp
->fn_fields
= (struct fn_field
*)
14724 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
14726 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
14727 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
14730 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
14733 /* Returns non-zero if NAME is the name of a vtable member in CU's
14734 language, zero otherwise. */
14736 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
14738 static const char vptr
[] = "_vptr";
14740 /* Look for the C++ form of the vtable. */
14741 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
14747 /* GCC outputs unnamed structures that are really pointers to member
14748 functions, with the ABI-specified layout. If TYPE describes
14749 such a structure, smash it into a member function type.
14751 GCC shouldn't do this; it should just output pointer to member DIEs.
14752 This is GCC PR debug/28767. */
14755 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
14757 struct type
*pfn_type
, *self_type
, *new_type
;
14759 /* Check for a structure with no name and two children. */
14760 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
14763 /* Check for __pfn and __delta members. */
14764 if (TYPE_FIELD_NAME (type
, 0) == NULL
14765 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
14766 || TYPE_FIELD_NAME (type
, 1) == NULL
14767 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
14770 /* Find the type of the method. */
14771 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
14772 if (pfn_type
== NULL
14773 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
14774 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
14777 /* Look for the "this" argument. */
14778 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
14779 if (TYPE_NFIELDS (pfn_type
) == 0
14780 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
14781 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
14784 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
14785 new_type
= alloc_type (objfile
);
14786 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
14787 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
14788 TYPE_VARARGS (pfn_type
));
14789 smash_to_methodptr_type (type
, new_type
);
14792 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
14793 appropriate error checking and issuing complaints if there is a
14797 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
14799 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
14801 if (attr
== nullptr)
14804 if (!attr
->form_is_constant ())
14806 complaint (_("DW_AT_alignment must have constant form"
14807 " - DIE at %s [in module %s]"),
14808 sect_offset_str (die
->sect_off
),
14809 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14814 if (attr
->form
== DW_FORM_sdata
)
14816 LONGEST val
= DW_SND (attr
);
14819 complaint (_("DW_AT_alignment value must not be negative"
14820 " - DIE at %s [in module %s]"),
14821 sect_offset_str (die
->sect_off
),
14822 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14828 align
= DW_UNSND (attr
);
14832 complaint (_("DW_AT_alignment value must not be zero"
14833 " - DIE at %s [in module %s]"),
14834 sect_offset_str (die
->sect_off
),
14835 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14838 if ((align
& (align
- 1)) != 0)
14840 complaint (_("DW_AT_alignment value must be a power of 2"
14841 " - DIE at %s [in module %s]"),
14842 sect_offset_str (die
->sect_off
),
14843 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14850 /* If the DIE has a DW_AT_alignment attribute, use its value to set
14851 the alignment for TYPE. */
14854 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
14857 if (!set_type_align (type
, get_alignment (cu
, die
)))
14858 complaint (_("DW_AT_alignment value too large"
14859 " - DIE at %s [in module %s]"),
14860 sect_offset_str (die
->sect_off
),
14861 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
14864 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14865 constant for a type, according to DWARF5 spec, Table 5.5. */
14868 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
14873 case DW_CC_pass_by_reference
:
14874 case DW_CC_pass_by_value
:
14878 complaint (_("unrecognized DW_AT_calling_convention value "
14879 "(%s) for a type"), pulongest (value
));
14884 /* Check if the given VALUE is a valid enum dwarf_calling_convention
14885 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
14886 also according to GNU-specific values (see include/dwarf2.h). */
14889 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
14894 case DW_CC_program
:
14898 case DW_CC_GNU_renesas_sh
:
14899 case DW_CC_GNU_borland_fastcall_i386
:
14900 case DW_CC_GDB_IBM_OpenCL
:
14904 complaint (_("unrecognized DW_AT_calling_convention value "
14905 "(%s) for a subroutine"), pulongest (value
));
14910 /* Called when we find the DIE that starts a structure or union scope
14911 (definition) to create a type for the structure or union. Fill in
14912 the type's name and general properties; the members will not be
14913 processed until process_structure_scope. A symbol table entry for
14914 the type will also not be done until process_structure_scope (assuming
14915 the type has a name).
14917 NOTE: we need to call these functions regardless of whether or not the
14918 DIE has a DW_AT_name attribute, since it might be an anonymous
14919 structure or union. This gets the type entered into our set of
14920 user defined types. */
14922 static struct type
*
14923 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14925 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14927 struct attribute
*attr
;
14930 /* If the definition of this type lives in .debug_types, read that type.
14931 Don't follow DW_AT_specification though, that will take us back up
14932 the chain and we want to go down. */
14933 attr
= die
->attr (DW_AT_signature
);
14934 if (attr
!= nullptr)
14936 type
= get_DW_AT_signature_type (die
, attr
, cu
);
14938 /* The type's CU may not be the same as CU.
14939 Ensure TYPE is recorded with CU in die_type_hash. */
14940 return set_die_type (die
, type
, cu
);
14943 type
= alloc_type (objfile
);
14944 INIT_CPLUS_SPECIFIC (type
);
14946 name
= dwarf2_name (die
, cu
);
14949 if (cu
->language
== language_cplus
14950 || cu
->language
== language_d
14951 || cu
->language
== language_rust
)
14953 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
14955 /* dwarf2_full_name might have already finished building the DIE's
14956 type. If so, there is no need to continue. */
14957 if (get_die_type (die
, cu
) != NULL
)
14958 return get_die_type (die
, cu
);
14960 TYPE_NAME (type
) = full_name
;
14964 /* The name is already allocated along with this objfile, so
14965 we don't need to duplicate it for the type. */
14966 TYPE_NAME (type
) = name
;
14970 if (die
->tag
== DW_TAG_structure_type
)
14972 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14974 else if (die
->tag
== DW_TAG_union_type
)
14976 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14978 else if (die
->tag
== DW_TAG_variant_part
)
14980 TYPE_CODE (type
) = TYPE_CODE_UNION
;
14981 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
14985 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
14988 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
14989 TYPE_DECLARED_CLASS (type
) = 1;
14991 /* Store the calling convention in the type if it's available in
14992 the die. Otherwise the calling convention remains set to
14993 the default value DW_CC_normal. */
14994 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
14995 if (attr
!= nullptr
14996 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
14998 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
14999 TYPE_CPLUS_CALLING_CONVENTION (type
)
15000 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15003 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15004 if (attr
!= nullptr)
15006 if (attr
->form_is_constant ())
15007 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15010 /* For the moment, dynamic type sizes are not supported
15011 by GDB's struct type. The actual size is determined
15012 on-demand when resolving the type of a given object,
15013 so set the type's length to zero for now. Otherwise,
15014 we record an expression as the length, and that expression
15015 could lead to a very large value, which could eventually
15016 lead to us trying to allocate that much memory when creating
15017 a value of that type. */
15018 TYPE_LENGTH (type
) = 0;
15023 TYPE_LENGTH (type
) = 0;
15026 maybe_set_alignment (cu
, die
, type
);
15028 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15030 /* ICC<14 does not output the required DW_AT_declaration on
15031 incomplete types, but gives them a size of zero. */
15032 TYPE_STUB (type
) = 1;
15035 TYPE_STUB_SUPPORTED (type
) = 1;
15037 if (die_is_declaration (die
, cu
))
15038 TYPE_STUB (type
) = 1;
15039 else if (attr
== NULL
&& die
->child
== NULL
15040 && producer_is_realview (cu
->producer
))
15041 /* RealView does not output the required DW_AT_declaration
15042 on incomplete types. */
15043 TYPE_STUB (type
) = 1;
15045 /* We need to add the type field to the die immediately so we don't
15046 infinitely recurse when dealing with pointers to the structure
15047 type within the structure itself. */
15048 set_die_type (die
, type
, cu
);
15050 /* set_die_type should be already done. */
15051 set_descriptive_type (type
, die
, cu
);
15056 /* A helper for process_structure_scope that handles a single member
15060 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15061 struct field_info
*fi
,
15062 std::vector
<struct symbol
*> *template_args
,
15063 struct dwarf2_cu
*cu
)
15065 if (child_die
->tag
== DW_TAG_member
15066 || child_die
->tag
== DW_TAG_variable
15067 || child_die
->tag
== DW_TAG_variant_part
)
15069 /* NOTE: carlton/2002-11-05: A C++ static data member
15070 should be a DW_TAG_member that is a declaration, but
15071 all versions of G++ as of this writing (so through at
15072 least 3.2.1) incorrectly generate DW_TAG_variable
15073 tags for them instead. */
15074 dwarf2_add_field (fi
, child_die
, cu
);
15076 else if (child_die
->tag
== DW_TAG_subprogram
)
15078 /* Rust doesn't have member functions in the C++ sense.
15079 However, it does emit ordinary functions as children
15080 of a struct DIE. */
15081 if (cu
->language
== language_rust
)
15082 read_func_scope (child_die
, cu
);
15085 /* C++ member function. */
15086 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15089 else if (child_die
->tag
== DW_TAG_inheritance
)
15091 /* C++ base class field. */
15092 dwarf2_add_field (fi
, child_die
, cu
);
15094 else if (type_can_define_types (child_die
))
15095 dwarf2_add_type_defn (fi
, child_die
, cu
);
15096 else if (child_die
->tag
== DW_TAG_template_type_param
15097 || child_die
->tag
== DW_TAG_template_value_param
)
15099 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15102 template_args
->push_back (arg
);
15104 else if (child_die
->tag
== DW_TAG_variant
)
15106 /* In a variant we want to get the discriminant and also add a
15107 field for our sole member child. */
15108 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15110 for (die_info
*variant_child
= child_die
->child
;
15111 variant_child
!= NULL
;
15112 variant_child
= variant_child
->sibling
)
15114 if (variant_child
->tag
== DW_TAG_member
)
15116 handle_struct_member_die (variant_child
, type
, fi
,
15117 template_args
, cu
);
15118 /* Only handle the one. */
15123 /* We don't handle this but we might as well report it if we see
15125 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15126 complaint (_("DW_AT_discr_list is not supported yet"
15127 " - DIE at %s [in module %s]"),
15128 sect_offset_str (child_die
->sect_off
),
15129 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15131 /* The first field was just added, so we can stash the
15132 discriminant there. */
15133 gdb_assert (!fi
->fields
.empty ());
15135 fi
->fields
.back ().variant
.default_branch
= true;
15137 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15141 /* Finish creating a structure or union type, including filling in
15142 its members and creating a symbol for it. */
15145 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15147 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15148 struct die_info
*child_die
;
15151 type
= get_die_type (die
, cu
);
15153 type
= read_structure_type (die
, cu
);
15155 /* When reading a DW_TAG_variant_part, we need to notice when we
15156 read the discriminant member, so we can record it later in the
15157 discriminant_info. */
15158 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15159 sect_offset discr_offset
{};
15160 bool has_template_parameters
= false;
15162 if (is_variant_part
)
15164 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15167 /* Maybe it's a univariant form, an extension we support.
15168 In this case arrange not to check the offset. */
15169 is_variant_part
= false;
15171 else if (discr
->form_is_ref ())
15173 struct dwarf2_cu
*target_cu
= cu
;
15174 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15176 discr_offset
= target_die
->sect_off
;
15180 complaint (_("DW_AT_discr does not have DIE reference form"
15181 " - DIE at %s [in module %s]"),
15182 sect_offset_str (die
->sect_off
),
15183 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15184 is_variant_part
= false;
15188 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15190 struct field_info fi
;
15191 std::vector
<struct symbol
*> template_args
;
15193 child_die
= die
->child
;
15195 while (child_die
&& child_die
->tag
)
15197 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15199 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15200 fi
.fields
.back ().variant
.is_discriminant
= true;
15202 child_die
= child_die
->sibling
;
15205 /* Attach template arguments to type. */
15206 if (!template_args
.empty ())
15208 has_template_parameters
= true;
15209 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15210 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15211 TYPE_TEMPLATE_ARGUMENTS (type
)
15212 = XOBNEWVEC (&objfile
->objfile_obstack
,
15214 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15215 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15216 template_args
.data (),
15217 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15218 * sizeof (struct symbol
*)));
15221 /* Attach fields and member functions to the type. */
15222 if (fi
.nfields () > 0)
15223 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15224 if (!fi
.fnfieldlists
.empty ())
15226 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15228 /* Get the type which refers to the base class (possibly this
15229 class itself) which contains the vtable pointer for the current
15230 class from the DW_AT_containing_type attribute. This use of
15231 DW_AT_containing_type is a GNU extension. */
15233 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15235 struct type
*t
= die_containing_type (die
, cu
);
15237 set_type_vptr_basetype (type
, t
);
15242 /* Our own class provides vtbl ptr. */
15243 for (i
= TYPE_NFIELDS (t
) - 1;
15244 i
>= TYPE_N_BASECLASSES (t
);
15247 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15249 if (is_vtable_name (fieldname
, cu
))
15251 set_type_vptr_fieldno (type
, i
);
15256 /* Complain if virtual function table field not found. */
15257 if (i
< TYPE_N_BASECLASSES (t
))
15258 complaint (_("virtual function table pointer "
15259 "not found when defining class '%s'"),
15260 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15264 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15267 else if (cu
->producer
15268 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15270 /* The IBM XLC compiler does not provide direct indication
15271 of the containing type, but the vtable pointer is
15272 always named __vfp. */
15276 for (i
= TYPE_NFIELDS (type
) - 1;
15277 i
>= TYPE_N_BASECLASSES (type
);
15280 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15282 set_type_vptr_fieldno (type
, i
);
15283 set_type_vptr_basetype (type
, type
);
15290 /* Copy fi.typedef_field_list linked list elements content into the
15291 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15292 if (!fi
.typedef_field_list
.empty ())
15294 int count
= fi
.typedef_field_list
.size ();
15296 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15297 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15298 = ((struct decl_field
*)
15300 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15301 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15303 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15304 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15307 /* Copy fi.nested_types_list linked list elements content into the
15308 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15309 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15311 int count
= fi
.nested_types_list
.size ();
15313 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15314 TYPE_NESTED_TYPES_ARRAY (type
)
15315 = ((struct decl_field
*)
15316 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15317 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15319 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15320 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15324 quirk_gcc_member_function_pointer (type
, objfile
);
15325 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15326 cu
->rust_unions
.push_back (type
);
15328 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15329 snapshots) has been known to create a die giving a declaration
15330 for a class that has, as a child, a die giving a definition for a
15331 nested class. So we have to process our children even if the
15332 current die is a declaration. Normally, of course, a declaration
15333 won't have any children at all. */
15335 child_die
= die
->child
;
15337 while (child_die
!= NULL
&& child_die
->tag
)
15339 if (child_die
->tag
== DW_TAG_member
15340 || child_die
->tag
== DW_TAG_variable
15341 || child_die
->tag
== DW_TAG_inheritance
15342 || child_die
->tag
== DW_TAG_template_value_param
15343 || child_die
->tag
== DW_TAG_template_type_param
)
15348 process_die (child_die
, cu
);
15350 child_die
= child_die
->sibling
;
15353 /* Do not consider external references. According to the DWARF standard,
15354 these DIEs are identified by the fact that they have no byte_size
15355 attribute, and a declaration attribute. */
15356 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
15357 || !die_is_declaration (die
, cu
))
15359 struct symbol
*sym
= new_symbol (die
, type
, cu
);
15361 if (has_template_parameters
)
15363 struct symtab
*symtab
;
15364 if (sym
!= nullptr)
15365 symtab
= symbol_symtab (sym
);
15366 else if (cu
->line_header
!= nullptr)
15368 /* Any related symtab will do. */
15370 = cu
->line_header
->file_names ()[0].symtab
;
15375 complaint (_("could not find suitable "
15376 "symtab for template parameter"
15377 " - DIE at %s [in module %s]"),
15378 sect_offset_str (die
->sect_off
),
15379 objfile_name (objfile
));
15382 if (symtab
!= nullptr)
15384 /* Make sure that the symtab is set on the new symbols.
15385 Even though they don't appear in this symtab directly,
15386 other parts of gdb assume that symbols do, and this is
15387 reasonably true. */
15388 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
15389 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
15395 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
15396 update TYPE using some information only available in DIE's children. */
15399 update_enumeration_type_from_children (struct die_info
*die
,
15401 struct dwarf2_cu
*cu
)
15403 struct die_info
*child_die
;
15404 int unsigned_enum
= 1;
15407 auto_obstack obstack
;
15409 for (child_die
= die
->child
;
15410 child_die
!= NULL
&& child_die
->tag
;
15411 child_die
= child_die
->sibling
)
15413 struct attribute
*attr
;
15415 const gdb_byte
*bytes
;
15416 struct dwarf2_locexpr_baton
*baton
;
15419 if (child_die
->tag
!= DW_TAG_enumerator
)
15422 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
15426 name
= dwarf2_name (child_die
, cu
);
15428 name
= "<anonymous enumerator>";
15430 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
15431 &value
, &bytes
, &baton
);
15439 if (count_one_bits_ll (value
) >= 2)
15443 /* If we already know that the enum type is neither unsigned, nor
15444 a flag type, no need to look at the rest of the enumerates. */
15445 if (!unsigned_enum
&& !flag_enum
)
15450 TYPE_UNSIGNED (type
) = 1;
15452 TYPE_FLAG_ENUM (type
) = 1;
15455 /* Given a DW_AT_enumeration_type die, set its type. We do not
15456 complete the type's fields yet, or create any symbols. */
15458 static struct type
*
15459 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15461 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15463 struct attribute
*attr
;
15466 /* If the definition of this type lives in .debug_types, read that type.
15467 Don't follow DW_AT_specification though, that will take us back up
15468 the chain and we want to go down. */
15469 attr
= die
->attr (DW_AT_signature
);
15470 if (attr
!= nullptr)
15472 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15474 /* The type's CU may not be the same as CU.
15475 Ensure TYPE is recorded with CU in die_type_hash. */
15476 return set_die_type (die
, type
, cu
);
15479 type
= alloc_type (objfile
);
15481 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
15482 name
= dwarf2_full_name (NULL
, die
, cu
);
15484 TYPE_NAME (type
) = name
;
15486 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
15489 struct type
*underlying_type
= die_type (die
, cu
);
15491 TYPE_TARGET_TYPE (type
) = underlying_type
;
15494 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15495 if (attr
!= nullptr)
15497 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15501 TYPE_LENGTH (type
) = 0;
15504 maybe_set_alignment (cu
, die
, type
);
15506 /* The enumeration DIE can be incomplete. In Ada, any type can be
15507 declared as private in the package spec, and then defined only
15508 inside the package body. Such types are known as Taft Amendment
15509 Types. When another package uses such a type, an incomplete DIE
15510 may be generated by the compiler. */
15511 if (die_is_declaration (die
, cu
))
15512 TYPE_STUB (type
) = 1;
15514 /* Finish the creation of this type by using the enum's children.
15515 We must call this even when the underlying type has been provided
15516 so that we can determine if we're looking at a "flag" enum. */
15517 update_enumeration_type_from_children (die
, type
, cu
);
15519 /* If this type has an underlying type that is not a stub, then we
15520 may use its attributes. We always use the "unsigned" attribute
15521 in this situation, because ordinarily we guess whether the type
15522 is unsigned -- but the guess can be wrong and the underlying type
15523 can tell us the reality. However, we defer to a local size
15524 attribute if one exists, because this lets the compiler override
15525 the underlying type if needed. */
15526 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
15528 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
15529 if (TYPE_LENGTH (type
) == 0)
15530 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
15531 if (TYPE_RAW_ALIGN (type
) == 0
15532 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
15533 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
15536 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
15538 return set_die_type (die
, type
, cu
);
15541 /* Given a pointer to a die which begins an enumeration, process all
15542 the dies that define the members of the enumeration, and create the
15543 symbol for the enumeration type.
15545 NOTE: We reverse the order of the element list. */
15548 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15550 struct type
*this_type
;
15552 this_type
= get_die_type (die
, cu
);
15553 if (this_type
== NULL
)
15554 this_type
= read_enumeration_type (die
, cu
);
15556 if (die
->child
!= NULL
)
15558 struct die_info
*child_die
;
15559 struct symbol
*sym
;
15560 std::vector
<struct field
> fields
;
15563 child_die
= die
->child
;
15564 while (child_die
&& child_die
->tag
)
15566 if (child_die
->tag
!= DW_TAG_enumerator
)
15568 process_die (child_die
, cu
);
15572 name
= dwarf2_name (child_die
, cu
);
15575 sym
= new_symbol (child_die
, this_type
, cu
);
15577 fields
.emplace_back ();
15578 struct field
&field
= fields
.back ();
15580 FIELD_NAME (field
) = sym
->linkage_name ();
15581 FIELD_TYPE (field
) = NULL
;
15582 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
15583 FIELD_BITSIZE (field
) = 0;
15587 child_die
= child_die
->sibling
;
15590 if (!fields
.empty ())
15592 TYPE_NFIELDS (this_type
) = fields
.size ();
15593 TYPE_FIELDS (this_type
) = (struct field
*)
15594 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
15595 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
15596 sizeof (struct field
) * fields
.size ());
15600 /* If we are reading an enum from a .debug_types unit, and the enum
15601 is a declaration, and the enum is not the signatured type in the
15602 unit, then we do not want to add a symbol for it. Adding a
15603 symbol would in some cases obscure the true definition of the
15604 enum, giving users an incomplete type when the definition is
15605 actually available. Note that we do not want to do this for all
15606 enums which are just declarations, because C++0x allows forward
15607 enum declarations. */
15608 if (cu
->per_cu
->is_debug_types
15609 && die_is_declaration (die
, cu
))
15611 struct signatured_type
*sig_type
;
15613 sig_type
= (struct signatured_type
*) cu
->per_cu
;
15614 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
15615 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
15619 new_symbol (die
, this_type
, cu
);
15622 /* Extract all information from a DW_TAG_array_type DIE and put it in
15623 the DIE's type field. For now, this only handles one dimensional
15626 static struct type
*
15627 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15629 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15630 struct die_info
*child_die
;
15632 struct type
*element_type
, *range_type
, *index_type
;
15633 struct attribute
*attr
;
15635 struct dynamic_prop
*byte_stride_prop
= NULL
;
15636 unsigned int bit_stride
= 0;
15638 element_type
= die_type (die
, cu
);
15640 /* The die_type call above may have already set the type for this DIE. */
15641 type
= get_die_type (die
, cu
);
15645 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
15649 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
15652 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
15653 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
15657 complaint (_("unable to read array DW_AT_byte_stride "
15658 " - DIE at %s [in module %s]"),
15659 sect_offset_str (die
->sect_off
),
15660 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15661 /* Ignore this attribute. We will likely not be able to print
15662 arrays of this type correctly, but there is little we can do
15663 to help if we cannot read the attribute's value. */
15664 byte_stride_prop
= NULL
;
15668 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
15670 bit_stride
= DW_UNSND (attr
);
15672 /* Irix 6.2 native cc creates array types without children for
15673 arrays with unspecified length. */
15674 if (die
->child
== NULL
)
15676 index_type
= objfile_type (objfile
)->builtin_int
;
15677 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
15678 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
15679 byte_stride_prop
, bit_stride
);
15680 return set_die_type (die
, type
, cu
);
15683 std::vector
<struct type
*> range_types
;
15684 child_die
= die
->child
;
15685 while (child_die
&& child_die
->tag
)
15687 if (child_die
->tag
== DW_TAG_subrange_type
)
15689 struct type
*child_type
= read_type_die (child_die
, cu
);
15691 if (child_type
!= NULL
)
15693 /* The range type was succesfully read. Save it for the
15694 array type creation. */
15695 range_types
.push_back (child_type
);
15698 child_die
= child_die
->sibling
;
15701 /* Dwarf2 dimensions are output from left to right, create the
15702 necessary array types in backwards order. */
15704 type
= element_type
;
15706 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
15710 while (i
< range_types
.size ())
15711 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
15712 byte_stride_prop
, bit_stride
);
15716 size_t ndim
= range_types
.size ();
15718 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
15719 byte_stride_prop
, bit_stride
);
15722 /* Understand Dwarf2 support for vector types (like they occur on
15723 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
15724 array type. This is not part of the Dwarf2/3 standard yet, but a
15725 custom vendor extension. The main difference between a regular
15726 array and the vector variant is that vectors are passed by value
15728 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
15729 if (attr
!= nullptr)
15730 make_vector_type (type
);
15732 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
15733 implementation may choose to implement triple vectors using this
15735 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15736 if (attr
!= nullptr)
15738 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
15739 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15741 complaint (_("DW_AT_byte_size for array type smaller "
15742 "than the total size of elements"));
15745 name
= dwarf2_name (die
, cu
);
15747 TYPE_NAME (type
) = name
;
15749 maybe_set_alignment (cu
, die
, type
);
15751 /* Install the type in the die. */
15752 set_die_type (die
, type
, cu
);
15754 /* set_die_type should be already done. */
15755 set_descriptive_type (type
, die
, cu
);
15760 static enum dwarf_array_dim_ordering
15761 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
15763 struct attribute
*attr
;
15765 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
15767 if (attr
!= nullptr)
15768 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
15770 /* GNU F77 is a special case, as at 08/2004 array type info is the
15771 opposite order to the dwarf2 specification, but data is still
15772 laid out as per normal fortran.
15774 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
15775 version checking. */
15777 if (cu
->language
== language_fortran
15778 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
15780 return DW_ORD_row_major
;
15783 switch (cu
->language_defn
->la_array_ordering
)
15785 case array_column_major
:
15786 return DW_ORD_col_major
;
15787 case array_row_major
:
15789 return DW_ORD_row_major
;
15793 /* Extract all information from a DW_TAG_set_type DIE and put it in
15794 the DIE's type field. */
15796 static struct type
*
15797 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15799 struct type
*domain_type
, *set_type
;
15800 struct attribute
*attr
;
15802 domain_type
= die_type (die
, cu
);
15804 /* The die_type call above may have already set the type for this DIE. */
15805 set_type
= get_die_type (die
, cu
);
15809 set_type
= create_set_type (NULL
, domain_type
);
15811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15812 if (attr
!= nullptr)
15813 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
15815 maybe_set_alignment (cu
, die
, set_type
);
15817 return set_die_type (die
, set_type
, cu
);
15820 /* A helper for read_common_block that creates a locexpr baton.
15821 SYM is the symbol which we are marking as computed.
15822 COMMON_DIE is the DIE for the common block.
15823 COMMON_LOC is the location expression attribute for the common
15825 MEMBER_LOC is the location expression attribute for the particular
15826 member of the common block that we are processing.
15827 CU is the CU from which the above come. */
15830 mark_common_block_symbol_computed (struct symbol
*sym
,
15831 struct die_info
*common_die
,
15832 struct attribute
*common_loc
,
15833 struct attribute
*member_loc
,
15834 struct dwarf2_cu
*cu
)
15836 struct dwarf2_per_objfile
*dwarf2_per_objfile
15837 = cu
->per_cu
->dwarf2_per_objfile
;
15838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
15839 struct dwarf2_locexpr_baton
*baton
;
15841 unsigned int cu_off
;
15842 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
15843 LONGEST offset
= 0;
15845 gdb_assert (common_loc
&& member_loc
);
15846 gdb_assert (common_loc
->form_is_block ());
15847 gdb_assert (member_loc
->form_is_block ()
15848 || member_loc
->form_is_constant ());
15850 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
15851 baton
->per_cu
= cu
->per_cu
;
15852 gdb_assert (baton
->per_cu
);
15854 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
15856 if (member_loc
->form_is_constant ())
15858 offset
= member_loc
->constant_value (0);
15859 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
15862 baton
->size
+= DW_BLOCK (member_loc
)->size
;
15864 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
15867 *ptr
++ = DW_OP_call4
;
15868 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
15869 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
15872 if (member_loc
->form_is_constant ())
15874 *ptr
++ = DW_OP_addr
;
15875 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
15876 ptr
+= cu
->header
.addr_size
;
15880 /* We have to copy the data here, because DW_OP_call4 will only
15881 use a DW_AT_location attribute. */
15882 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
15883 ptr
+= DW_BLOCK (member_loc
)->size
;
15886 *ptr
++ = DW_OP_plus
;
15887 gdb_assert (ptr
- baton
->data
== baton
->size
);
15889 SYMBOL_LOCATION_BATON (sym
) = baton
;
15890 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
15893 /* Create appropriate locally-scoped variables for all the
15894 DW_TAG_common_block entries. Also create a struct common_block
15895 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
15896 is used to separate the common blocks name namespace from regular
15900 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
15902 struct attribute
*attr
;
15904 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
15905 if (attr
!= nullptr)
15907 /* Support the .debug_loc offsets. */
15908 if (attr
->form_is_block ())
15912 else if (attr
->form_is_section_offset ())
15914 dwarf2_complex_location_expr_complaint ();
15919 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
15920 "common block member");
15925 if (die
->child
!= NULL
)
15927 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15928 struct die_info
*child_die
;
15929 size_t n_entries
= 0, size
;
15930 struct common_block
*common_block
;
15931 struct symbol
*sym
;
15933 for (child_die
= die
->child
;
15934 child_die
&& child_die
->tag
;
15935 child_die
= child_die
->sibling
)
15938 size
= (sizeof (struct common_block
)
15939 + (n_entries
- 1) * sizeof (struct symbol
*));
15941 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
15943 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
15944 common_block
->n_entries
= 0;
15946 for (child_die
= die
->child
;
15947 child_die
&& child_die
->tag
;
15948 child_die
= child_die
->sibling
)
15950 /* Create the symbol in the DW_TAG_common_block block in the current
15952 sym
= new_symbol (child_die
, NULL
, cu
);
15955 struct attribute
*member_loc
;
15957 common_block
->contents
[common_block
->n_entries
++] = sym
;
15959 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
15963 /* GDB has handled this for a long time, but it is
15964 not specified by DWARF. It seems to have been
15965 emitted by gfortran at least as recently as:
15966 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
15967 complaint (_("Variable in common block has "
15968 "DW_AT_data_member_location "
15969 "- DIE at %s [in module %s]"),
15970 sect_offset_str (child_die
->sect_off
),
15971 objfile_name (objfile
));
15973 if (member_loc
->form_is_section_offset ())
15974 dwarf2_complex_location_expr_complaint ();
15975 else if (member_loc
->form_is_constant ()
15976 || member_loc
->form_is_block ())
15978 if (attr
!= nullptr)
15979 mark_common_block_symbol_computed (sym
, die
, attr
,
15983 dwarf2_complex_location_expr_complaint ();
15988 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
15989 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
15993 /* Create a type for a C++ namespace. */
15995 static struct type
*
15996 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15998 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15999 const char *previous_prefix
, *name
;
16003 /* For extensions, reuse the type of the original namespace. */
16004 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16006 struct die_info
*ext_die
;
16007 struct dwarf2_cu
*ext_cu
= cu
;
16009 ext_die
= dwarf2_extension (die
, &ext_cu
);
16010 type
= read_type_die (ext_die
, ext_cu
);
16012 /* EXT_CU may not be the same as CU.
16013 Ensure TYPE is recorded with CU in die_type_hash. */
16014 return set_die_type (die
, type
, cu
);
16017 name
= namespace_name (die
, &is_anonymous
, cu
);
16019 /* Now build the name of the current namespace. */
16021 previous_prefix
= determine_prefix (die
, cu
);
16022 if (previous_prefix
[0] != '\0')
16023 name
= typename_concat (&objfile
->objfile_obstack
,
16024 previous_prefix
, name
, 0, cu
);
16026 /* Create the type. */
16027 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16029 return set_die_type (die
, type
, cu
);
16032 /* Read a namespace scope. */
16035 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16037 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16040 /* Add a symbol associated to this if we haven't seen the namespace
16041 before. Also, add a using directive if it's an anonymous
16044 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16048 type
= read_type_die (die
, cu
);
16049 new_symbol (die
, type
, cu
);
16051 namespace_name (die
, &is_anonymous
, cu
);
16054 const char *previous_prefix
= determine_prefix (die
, cu
);
16056 std::vector
<const char *> excludes
;
16057 add_using_directive (using_directives (cu
),
16058 previous_prefix
, TYPE_NAME (type
), NULL
,
16059 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16063 if (die
->child
!= NULL
)
16065 struct die_info
*child_die
= die
->child
;
16067 while (child_die
&& child_die
->tag
)
16069 process_die (child_die
, cu
);
16070 child_die
= child_die
->sibling
;
16075 /* Read a Fortran module as type. This DIE can be only a declaration used for
16076 imported module. Still we need that type as local Fortran "use ... only"
16077 declaration imports depend on the created type in determine_prefix. */
16079 static struct type
*
16080 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16082 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16083 const char *module_name
;
16086 module_name
= dwarf2_name (die
, cu
);
16087 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16089 return set_die_type (die
, type
, cu
);
16092 /* Read a Fortran module. */
16095 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16097 struct die_info
*child_die
= die
->child
;
16100 type
= read_type_die (die
, cu
);
16101 new_symbol (die
, type
, cu
);
16103 while (child_die
&& child_die
->tag
)
16105 process_die (child_die
, cu
);
16106 child_die
= child_die
->sibling
;
16110 /* Return the name of the namespace represented by DIE. Set
16111 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16114 static const char *
16115 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16117 struct die_info
*current_die
;
16118 const char *name
= NULL
;
16120 /* Loop through the extensions until we find a name. */
16122 for (current_die
= die
;
16123 current_die
!= NULL
;
16124 current_die
= dwarf2_extension (die
, &cu
))
16126 /* We don't use dwarf2_name here so that we can detect the absence
16127 of a name -> anonymous namespace. */
16128 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16134 /* Is it an anonymous namespace? */
16136 *is_anonymous
= (name
== NULL
);
16138 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16143 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16144 the user defined type vector. */
16146 static struct type
*
16147 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16149 struct gdbarch
*gdbarch
16150 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16151 struct comp_unit_head
*cu_header
= &cu
->header
;
16153 struct attribute
*attr_byte_size
;
16154 struct attribute
*attr_address_class
;
16155 int byte_size
, addr_class
;
16156 struct type
*target_type
;
16158 target_type
= die_type (die
, cu
);
16160 /* The die_type call above may have already set the type for this DIE. */
16161 type
= get_die_type (die
, cu
);
16165 type
= lookup_pointer_type (target_type
);
16167 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16168 if (attr_byte_size
)
16169 byte_size
= DW_UNSND (attr_byte_size
);
16171 byte_size
= cu_header
->addr_size
;
16173 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16174 if (attr_address_class
)
16175 addr_class
= DW_UNSND (attr_address_class
);
16177 addr_class
= DW_ADDR_none
;
16179 ULONGEST alignment
= get_alignment (cu
, die
);
16181 /* If the pointer size, alignment, or address class is different
16182 than the default, create a type variant marked as such and set
16183 the length accordingly. */
16184 if (TYPE_LENGTH (type
) != byte_size
16185 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16186 && alignment
!= TYPE_RAW_ALIGN (type
))
16187 || addr_class
!= DW_ADDR_none
)
16189 if (gdbarch_address_class_type_flags_p (gdbarch
))
16193 type_flags
= gdbarch_address_class_type_flags
16194 (gdbarch
, byte_size
, addr_class
);
16195 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16197 type
= make_type_with_address_space (type
, type_flags
);
16199 else if (TYPE_LENGTH (type
) != byte_size
)
16201 complaint (_("invalid pointer size %d"), byte_size
);
16203 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16205 complaint (_("Invalid DW_AT_alignment"
16206 " - DIE at %s [in module %s]"),
16207 sect_offset_str (die
->sect_off
),
16208 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16212 /* Should we also complain about unhandled address classes? */
16216 TYPE_LENGTH (type
) = byte_size
;
16217 set_type_align (type
, alignment
);
16218 return set_die_type (die
, type
, cu
);
16221 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16222 the user defined type vector. */
16224 static struct type
*
16225 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16228 struct type
*to_type
;
16229 struct type
*domain
;
16231 to_type
= die_type (die
, cu
);
16232 domain
= die_containing_type (die
, cu
);
16234 /* The calls above may have already set the type for this DIE. */
16235 type
= get_die_type (die
, cu
);
16239 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16240 type
= lookup_methodptr_type (to_type
);
16241 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16243 struct type
*new_type
16244 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16246 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16247 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16248 TYPE_VARARGS (to_type
));
16249 type
= lookup_methodptr_type (new_type
);
16252 type
= lookup_memberptr_type (to_type
, domain
);
16254 return set_die_type (die
, type
, cu
);
16257 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16258 the user defined type vector. */
16260 static struct type
*
16261 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16262 enum type_code refcode
)
16264 struct comp_unit_head
*cu_header
= &cu
->header
;
16265 struct type
*type
, *target_type
;
16266 struct attribute
*attr
;
16268 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16270 target_type
= die_type (die
, cu
);
16272 /* The die_type call above may have already set the type for this DIE. */
16273 type
= get_die_type (die
, cu
);
16277 type
= lookup_reference_type (target_type
, refcode
);
16278 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16279 if (attr
!= nullptr)
16281 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16285 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16287 maybe_set_alignment (cu
, die
, type
);
16288 return set_die_type (die
, type
, cu
);
16291 /* Add the given cv-qualifiers to the element type of the array. GCC
16292 outputs DWARF type qualifiers that apply to an array, not the
16293 element type. But GDB relies on the array element type to carry
16294 the cv-qualifiers. This mimics section 6.7.3 of the C99
16297 static struct type
*
16298 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16299 struct type
*base_type
, int cnst
, int voltl
)
16301 struct type
*el_type
, *inner_array
;
16303 base_type
= copy_type (base_type
);
16304 inner_array
= base_type
;
16306 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16308 TYPE_TARGET_TYPE (inner_array
) =
16309 copy_type (TYPE_TARGET_TYPE (inner_array
));
16310 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16313 el_type
= TYPE_TARGET_TYPE (inner_array
);
16314 cnst
|= TYPE_CONST (el_type
);
16315 voltl
|= TYPE_VOLATILE (el_type
);
16316 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16318 return set_die_type (die
, base_type
, cu
);
16321 static struct type
*
16322 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16324 struct type
*base_type
, *cv_type
;
16326 base_type
= die_type (die
, cu
);
16328 /* The die_type call above may have already set the type for this DIE. */
16329 cv_type
= get_die_type (die
, cu
);
16333 /* In case the const qualifier is applied to an array type, the element type
16334 is so qualified, not the array type (section 6.7.3 of C99). */
16335 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16336 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16338 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16339 return set_die_type (die
, cv_type
, cu
);
16342 static struct type
*
16343 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16345 struct type
*base_type
, *cv_type
;
16347 base_type
= die_type (die
, cu
);
16349 /* The die_type call above may have already set the type for this DIE. */
16350 cv_type
= get_die_type (die
, cu
);
16354 /* In case the volatile qualifier is applied to an array type, the
16355 element type is so qualified, not the array type (section 6.7.3
16357 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16358 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
16360 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
16361 return set_die_type (die
, cv_type
, cu
);
16364 /* Handle DW_TAG_restrict_type. */
16366 static struct type
*
16367 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16369 struct type
*base_type
, *cv_type
;
16371 base_type
= die_type (die
, cu
);
16373 /* The die_type call above may have already set the type for this DIE. */
16374 cv_type
= get_die_type (die
, cu
);
16378 cv_type
= make_restrict_type (base_type
);
16379 return set_die_type (die
, cv_type
, cu
);
16382 /* Handle DW_TAG_atomic_type. */
16384 static struct type
*
16385 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16387 struct type
*base_type
, *cv_type
;
16389 base_type
= die_type (die
, cu
);
16391 /* The die_type call above may have already set the type for this DIE. */
16392 cv_type
= get_die_type (die
, cu
);
16396 cv_type
= make_atomic_type (base_type
);
16397 return set_die_type (die
, cv_type
, cu
);
16400 /* Extract all information from a DW_TAG_string_type DIE and add to
16401 the user defined type vector. It isn't really a user defined type,
16402 but it behaves like one, with other DIE's using an AT_user_def_type
16403 attribute to reference it. */
16405 static struct type
*
16406 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16408 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16409 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16410 struct type
*type
, *range_type
, *index_type
, *char_type
;
16411 struct attribute
*attr
;
16412 struct dynamic_prop prop
;
16413 bool length_is_constant
= true;
16416 /* There are a couple of places where bit sizes might be made use of
16417 when parsing a DW_TAG_string_type, however, no producer that we know
16418 of make use of these. Handling bit sizes that are a multiple of the
16419 byte size is easy enough, but what about other bit sizes? Lets deal
16420 with that problem when we have to. Warn about these attributes being
16421 unsupported, then parse the type and ignore them like we always
16423 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
16424 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
16426 static bool warning_printed
= false;
16427 if (!warning_printed
)
16429 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
16430 "currently supported on DW_TAG_string_type."));
16431 warning_printed
= true;
16435 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
16436 if (attr
!= nullptr && !attr
->form_is_constant ())
16438 /* The string length describes the location at which the length of
16439 the string can be found. The size of the length field can be
16440 specified with one of the attributes below. */
16441 struct type
*prop_type
;
16442 struct attribute
*len
16443 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
16444 if (len
== nullptr)
16445 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16446 if (len
!= nullptr && len
->form_is_constant ())
16448 /* Pass 0 as the default as we know this attribute is constant
16449 and the default value will not be returned. */
16450 LONGEST sz
= len
->constant_value (0);
16451 prop_type
= cu
->per_cu
->int_type (sz
, true);
16455 /* If the size is not specified then we assume it is the size of
16456 an address on this target. */
16457 prop_type
= cu
->per_cu
->addr_sized_int_type (true);
16460 /* Convert the attribute into a dynamic property. */
16461 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
16464 length_is_constant
= false;
16466 else if (attr
!= nullptr)
16468 /* This DW_AT_string_length just contains the length with no
16469 indirection. There's no need to create a dynamic property in this
16470 case. Pass 0 for the default value as we know it will not be
16471 returned in this case. */
16472 length
= attr
->constant_value (0);
16474 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
16476 /* We don't currently support non-constant byte sizes for strings. */
16477 length
= attr
->constant_value (1);
16481 /* Use 1 as a fallback length if we have nothing else. */
16485 index_type
= objfile_type (objfile
)->builtin_int
;
16486 if (length_is_constant
)
16487 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
16490 struct dynamic_prop low_bound
;
16492 low_bound
.kind
= PROP_CONST
;
16493 low_bound
.data
.const_val
= 1;
16494 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
16496 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
16497 type
= create_string_type (NULL
, char_type
, range_type
);
16499 return set_die_type (die
, type
, cu
);
16502 /* Assuming that DIE corresponds to a function, returns nonzero
16503 if the function is prototyped. */
16506 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
16508 struct attribute
*attr
;
16510 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
16511 if (attr
&& (DW_UNSND (attr
) != 0))
16514 /* The DWARF standard implies that the DW_AT_prototyped attribute
16515 is only meaningful for C, but the concept also extends to other
16516 languages that allow unprototyped functions (Eg: Objective C).
16517 For all other languages, assume that functions are always
16519 if (cu
->language
!= language_c
16520 && cu
->language
!= language_objc
16521 && cu
->language
!= language_opencl
)
16524 /* RealView does not emit DW_AT_prototyped. We can not distinguish
16525 prototyped and unprototyped functions; default to prototyped,
16526 since that is more common in modern code (and RealView warns
16527 about unprototyped functions). */
16528 if (producer_is_realview (cu
->producer
))
16534 /* Handle DIES due to C code like:
16538 int (*funcp)(int a, long l);
16542 ('funcp' generates a DW_TAG_subroutine_type DIE). */
16544 static struct type
*
16545 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16547 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16548 struct type
*type
; /* Type that this function returns. */
16549 struct type
*ftype
; /* Function that returns above type. */
16550 struct attribute
*attr
;
16552 type
= die_type (die
, cu
);
16554 /* The die_type call above may have already set the type for this DIE. */
16555 ftype
= get_die_type (die
, cu
);
16559 ftype
= lookup_function_type (type
);
16561 if (prototyped_function_p (die
, cu
))
16562 TYPE_PROTOTYPED (ftype
) = 1;
16564 /* Store the calling convention in the type if it's available in
16565 the subroutine die. Otherwise set the calling convention to
16566 the default value DW_CC_normal. */
16567 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16568 if (attr
!= nullptr
16569 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
16570 TYPE_CALLING_CONVENTION (ftype
)
16571 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16572 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
16573 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
16575 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
16577 /* Record whether the function returns normally to its caller or not
16578 if the DWARF producer set that information. */
16579 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
16580 if (attr
&& (DW_UNSND (attr
) != 0))
16581 TYPE_NO_RETURN (ftype
) = 1;
16583 /* We need to add the subroutine type to the die immediately so
16584 we don't infinitely recurse when dealing with parameters
16585 declared as the same subroutine type. */
16586 set_die_type (die
, ftype
, cu
);
16588 if (die
->child
!= NULL
)
16590 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
16591 struct die_info
*child_die
;
16592 int nparams
, iparams
;
16594 /* Count the number of parameters.
16595 FIXME: GDB currently ignores vararg functions, but knows about
16596 vararg member functions. */
16598 child_die
= die
->child
;
16599 while (child_die
&& child_die
->tag
)
16601 if (child_die
->tag
== DW_TAG_formal_parameter
)
16603 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
16604 TYPE_VARARGS (ftype
) = 1;
16605 child_die
= child_die
->sibling
;
16608 /* Allocate storage for parameters and fill them in. */
16609 TYPE_NFIELDS (ftype
) = nparams
;
16610 TYPE_FIELDS (ftype
) = (struct field
*)
16611 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
16613 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
16614 even if we error out during the parameters reading below. */
16615 for (iparams
= 0; iparams
< nparams
; iparams
++)
16616 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
16619 child_die
= die
->child
;
16620 while (child_die
&& child_die
->tag
)
16622 if (child_die
->tag
== DW_TAG_formal_parameter
)
16624 struct type
*arg_type
;
16626 /* DWARF version 2 has no clean way to discern C++
16627 static and non-static member functions. G++ helps
16628 GDB by marking the first parameter for non-static
16629 member functions (which is the this pointer) as
16630 artificial. We pass this information to
16631 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
16633 DWARF version 3 added DW_AT_object_pointer, which GCC
16634 4.5 does not yet generate. */
16635 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
16636 if (attr
!= nullptr)
16637 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
16639 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
16640 arg_type
= die_type (child_die
, cu
);
16642 /* RealView does not mark THIS as const, which the testsuite
16643 expects. GCC marks THIS as const in method definitions,
16644 but not in the class specifications (GCC PR 43053). */
16645 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
16646 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
16649 struct dwarf2_cu
*arg_cu
= cu
;
16650 const char *name
= dwarf2_name (child_die
, cu
);
16652 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
16653 if (attr
!= nullptr)
16655 /* If the compiler emits this, use it. */
16656 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
16659 else if (name
&& strcmp (name
, "this") == 0)
16660 /* Function definitions will have the argument names. */
16662 else if (name
== NULL
&& iparams
== 0)
16663 /* Declarations may not have the names, so like
16664 elsewhere in GDB, assume an artificial first
16665 argument is "this". */
16669 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
16673 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
16676 child_die
= child_die
->sibling
;
16683 static struct type
*
16684 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
16686 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16687 const char *name
= NULL
;
16688 struct type
*this_type
, *target_type
;
16690 name
= dwarf2_full_name (NULL
, die
, cu
);
16691 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
16692 TYPE_TARGET_STUB (this_type
) = 1;
16693 set_die_type (die
, this_type
, cu
);
16694 target_type
= die_type (die
, cu
);
16695 if (target_type
!= this_type
)
16696 TYPE_TARGET_TYPE (this_type
) = target_type
;
16699 /* Self-referential typedefs are, it seems, not allowed by the DWARF
16700 spec and cause infinite loops in GDB. */
16701 complaint (_("Self-referential DW_TAG_typedef "
16702 "- DIE at %s [in module %s]"),
16703 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
16704 TYPE_TARGET_TYPE (this_type
) = NULL
;
16708 /* Gcc-7 and before supports -feliminate-dwarf2-dups, which generates
16709 anonymous typedefs, which is, strictly speaking, invalid DWARF.
16710 Handle these by just returning the target type, rather than
16711 constructing an anonymous typedef type and trying to handle this
16713 set_die_type (die
, target_type
, cu
);
16714 return target_type
;
16719 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
16720 (which may be different from NAME) to the architecture back-end to allow
16721 it to guess the correct format if necessary. */
16723 static struct type
*
16724 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
16725 const char *name_hint
, enum bfd_endian byte_order
)
16727 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16728 const struct floatformat
**format
;
16731 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
16733 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
16735 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16740 /* Allocate an integer type of size BITS and name NAME. */
16742 static struct type
*
16743 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
16744 int bits
, int unsigned_p
, const char *name
)
16748 /* Versions of Intel's C Compiler generate an integer type called "void"
16749 instead of using DW_TAG_unspecified_type. This has been seen on
16750 at least versions 14, 17, and 18. */
16751 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
16752 && strcmp (name
, "void") == 0)
16753 type
= objfile_type (objfile
)->builtin_void
;
16755 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
16760 /* Initialise and return a floating point type of size BITS suitable for
16761 use as a component of a complex number. The NAME_HINT is passed through
16762 when initialising the floating point type and is the name of the complex
16765 As DWARF doesn't currently provide an explicit name for the components
16766 of a complex number, but it can be helpful to have these components
16767 named, we try to select a suitable name based on the size of the
16769 static struct type
*
16770 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
16771 struct objfile
*objfile
,
16772 int bits
, const char *name_hint
,
16773 enum bfd_endian byte_order
)
16775 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
16776 struct type
*tt
= nullptr;
16778 /* Try to find a suitable floating point builtin type of size BITS.
16779 We're going to use the name of this type as the name for the complex
16780 target type that we are about to create. */
16781 switch (cu
->language
)
16783 case language_fortran
:
16787 tt
= builtin_f_type (gdbarch
)->builtin_real
;
16790 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
16792 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16794 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
16802 tt
= builtin_type (gdbarch
)->builtin_float
;
16805 tt
= builtin_type (gdbarch
)->builtin_double
;
16807 case 96: /* The x86-32 ABI specifies 96-bit long double. */
16809 tt
= builtin_type (gdbarch
)->builtin_long_double
;
16815 /* If the type we found doesn't match the size we were looking for, then
16816 pretend we didn't find a type at all, the complex target type we
16817 create will then be nameless. */
16818 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
16821 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
16822 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
16825 /* Find a representation of a given base type and install
16826 it in the TYPE field of the die. */
16828 static struct type
*
16829 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16831 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16833 struct attribute
*attr
;
16834 int encoding
= 0, bits
= 0;
16838 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
16839 if (attr
!= nullptr)
16840 encoding
= DW_UNSND (attr
);
16841 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16842 if (attr
!= nullptr)
16843 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
16844 name
= dwarf2_name (die
, cu
);
16846 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
16848 arch
= get_objfile_arch (objfile
);
16849 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
16851 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
16854 int endianity
= DW_UNSND (attr
);
16859 byte_order
= BFD_ENDIAN_BIG
;
16861 case DW_END_little
:
16862 byte_order
= BFD_ENDIAN_LITTLE
;
16865 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
16872 case DW_ATE_address
:
16873 /* Turn DW_ATE_address into a void * pointer. */
16874 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
16875 type
= init_pointer_type (objfile
, bits
, name
, type
);
16877 case DW_ATE_boolean
:
16878 type
= init_boolean_type (objfile
, bits
, 1, name
);
16880 case DW_ATE_complex_float
:
16881 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
16883 type
= init_complex_type (objfile
, name
, type
);
16885 case DW_ATE_decimal_float
:
16886 type
= init_decfloat_type (objfile
, bits
, name
);
16889 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
16891 case DW_ATE_signed
:
16892 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16894 case DW_ATE_unsigned
:
16895 if (cu
->language
== language_fortran
16897 && startswith (name
, "character("))
16898 type
= init_character_type (objfile
, bits
, 1, name
);
16900 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16902 case DW_ATE_signed_char
:
16903 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16904 || cu
->language
== language_pascal
16905 || cu
->language
== language_fortran
)
16906 type
= init_character_type (objfile
, bits
, 0, name
);
16908 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
16910 case DW_ATE_unsigned_char
:
16911 if (cu
->language
== language_ada
|| cu
->language
== language_m2
16912 || cu
->language
== language_pascal
16913 || cu
->language
== language_fortran
16914 || cu
->language
== language_rust
)
16915 type
= init_character_type (objfile
, bits
, 1, name
);
16917 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16922 type
= builtin_type (arch
)->builtin_char16
;
16923 else if (bits
== 32)
16924 type
= builtin_type (arch
)->builtin_char32
;
16927 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
16929 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
16931 return set_die_type (die
, type
, cu
);
16936 complaint (_("unsupported DW_AT_encoding: '%s'"),
16937 dwarf_type_encoding_name (encoding
));
16938 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
16942 if (name
&& strcmp (name
, "char") == 0)
16943 TYPE_NOSIGN (type
) = 1;
16945 maybe_set_alignment (cu
, die
, type
);
16947 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
16949 return set_die_type (die
, type
, cu
);
16952 /* Parse dwarf attribute if it's a block, reference or constant and put the
16953 resulting value of the attribute into struct bound_prop.
16954 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
16957 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
16958 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
16959 struct type
*default_type
)
16961 struct dwarf2_property_baton
*baton
;
16962 struct obstack
*obstack
16963 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
16965 gdb_assert (default_type
!= NULL
);
16967 if (attr
== NULL
|| prop
== NULL
)
16970 if (attr
->form_is_block ())
16972 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
16973 baton
->property_type
= default_type
;
16974 baton
->locexpr
.per_cu
= cu
->per_cu
;
16975 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
16976 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
16977 switch (attr
->name
)
16979 case DW_AT_string_length
:
16980 baton
->locexpr
.is_reference
= true;
16983 baton
->locexpr
.is_reference
= false;
16986 prop
->data
.baton
= baton
;
16987 prop
->kind
= PROP_LOCEXPR
;
16988 gdb_assert (prop
->data
.baton
!= NULL
);
16990 else if (attr
->form_is_ref ())
16992 struct dwarf2_cu
*target_cu
= cu
;
16993 struct die_info
*target_die
;
16994 struct attribute
*target_attr
;
16996 target_die
= follow_die_ref (die
, attr
, &target_cu
);
16997 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
16998 if (target_attr
== NULL
)
16999 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17001 if (target_attr
== NULL
)
17004 switch (target_attr
->name
)
17006 case DW_AT_location
:
17007 if (target_attr
->form_is_section_offset ())
17009 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17010 baton
->property_type
= die_type (target_die
, target_cu
);
17011 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17012 prop
->data
.baton
= baton
;
17013 prop
->kind
= PROP_LOCLIST
;
17014 gdb_assert (prop
->data
.baton
!= NULL
);
17016 else if (target_attr
->form_is_block ())
17018 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17019 baton
->property_type
= die_type (target_die
, target_cu
);
17020 baton
->locexpr
.per_cu
= cu
->per_cu
;
17021 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17022 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17023 baton
->locexpr
.is_reference
= true;
17024 prop
->data
.baton
= baton
;
17025 prop
->kind
= PROP_LOCEXPR
;
17026 gdb_assert (prop
->data
.baton
!= NULL
);
17030 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17031 "dynamic property");
17035 case DW_AT_data_member_location
:
17039 if (!handle_data_member_location (target_die
, target_cu
,
17043 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17044 baton
->property_type
= read_type_die (target_die
->parent
,
17046 baton
->offset_info
.offset
= offset
;
17047 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17048 prop
->data
.baton
= baton
;
17049 prop
->kind
= PROP_ADDR_OFFSET
;
17054 else if (attr
->form_is_constant ())
17056 prop
->data
.const_val
= attr
->constant_value (0);
17057 prop
->kind
= PROP_CONST
;
17061 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17062 dwarf2_name (die
, cu
));
17072 dwarf2_per_cu_data::int_type (int size_in_bytes
, bool unsigned_p
) const
17074 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17075 struct type
*int_type
;
17077 /* Helper macro to examine the various builtin types. */
17078 #define TRY_TYPE(F) \
17079 int_type = (unsigned_p \
17080 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17081 : objfile_type (objfile)->builtin_ ## F); \
17082 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17089 TRY_TYPE (long_long
);
17093 gdb_assert_not_reached ("unable to find suitable integer type");
17099 dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p
) const
17101 int addr_size
= this->addr_size ();
17102 return int_type (addr_size
, unsigned_p
);
17105 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17106 present (which is valid) then compute the default type based on the
17107 compilation units address size. */
17109 static struct type
*
17110 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17112 struct type
*index_type
= die_type (die
, cu
);
17114 /* Dwarf-2 specifications explicitly allows to create subrange types
17115 without specifying a base type.
17116 In that case, the base type must be set to the type of
17117 the lower bound, upper bound or count, in that order, if any of these
17118 three attributes references an object that has a type.
17119 If no base type is found, the Dwarf-2 specifications say that
17120 a signed integer type of size equal to the size of an address should
17122 For the following C code: `extern char gdb_int [];'
17123 GCC produces an empty range DIE.
17124 FIXME: muller/2010-05-28: Possible references to object for low bound,
17125 high bound or count are not yet handled by this code. */
17126 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17127 index_type
= cu
->per_cu
->addr_sized_int_type (false);
17132 /* Read the given DW_AT_subrange DIE. */
17134 static struct type
*
17135 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17137 struct type
*base_type
, *orig_base_type
;
17138 struct type
*range_type
;
17139 struct attribute
*attr
;
17140 struct dynamic_prop low
, high
;
17141 int low_default_is_valid
;
17142 int high_bound_is_count
= 0;
17144 ULONGEST negative_mask
;
17146 orig_base_type
= read_subrange_index_type (die
, cu
);
17148 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17149 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17150 creating the range type, but we use the result of check_typedef
17151 when examining properties of the type. */
17152 base_type
= check_typedef (orig_base_type
);
17154 /* The die_type call above may have already set the type for this DIE. */
17155 range_type
= get_die_type (die
, cu
);
17159 low
.kind
= PROP_CONST
;
17160 high
.kind
= PROP_CONST
;
17161 high
.data
.const_val
= 0;
17163 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17164 omitting DW_AT_lower_bound. */
17165 switch (cu
->language
)
17168 case language_cplus
:
17169 low
.data
.const_val
= 0;
17170 low_default_is_valid
= 1;
17172 case language_fortran
:
17173 low
.data
.const_val
= 1;
17174 low_default_is_valid
= 1;
17177 case language_objc
:
17178 case language_rust
:
17179 low
.data
.const_val
= 0;
17180 low_default_is_valid
= (cu
->header
.version
>= 4);
17184 case language_pascal
:
17185 low
.data
.const_val
= 1;
17186 low_default_is_valid
= (cu
->header
.version
>= 4);
17189 low
.data
.const_val
= 0;
17190 low_default_is_valid
= 0;
17194 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17195 if (attr
!= nullptr)
17196 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17197 else if (!low_default_is_valid
)
17198 complaint (_("Missing DW_AT_lower_bound "
17199 "- DIE at %s [in module %s]"),
17200 sect_offset_str (die
->sect_off
),
17201 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17203 struct attribute
*attr_ub
, *attr_count
;
17204 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17205 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17207 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17208 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17210 /* If bounds are constant do the final calculation here. */
17211 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17212 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17214 high_bound_is_count
= 1;
17218 if (attr_ub
!= NULL
)
17219 complaint (_("Unresolved DW_AT_upper_bound "
17220 "- DIE at %s [in module %s]"),
17221 sect_offset_str (die
->sect_off
),
17222 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17223 if (attr_count
!= NULL
)
17224 complaint (_("Unresolved DW_AT_count "
17225 "- DIE at %s [in module %s]"),
17226 sect_offset_str (die
->sect_off
),
17227 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17232 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17233 if (bias_attr
!= nullptr && bias_attr
->form_is_constant ())
17234 bias
= bias_attr
->constant_value (0);
17236 /* Normally, the DWARF producers are expected to use a signed
17237 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17238 But this is unfortunately not always the case, as witnessed
17239 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17240 is used instead. To work around that ambiguity, we treat
17241 the bounds as signed, and thus sign-extend their values, when
17242 the base type is signed. */
17244 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17245 if (low
.kind
== PROP_CONST
17246 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17247 low
.data
.const_val
|= negative_mask
;
17248 if (high
.kind
== PROP_CONST
17249 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17250 high
.data
.const_val
|= negative_mask
;
17252 /* Check for bit and byte strides. */
17253 struct dynamic_prop byte_stride_prop
;
17254 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17255 if (attr_byte_stride
!= nullptr)
17257 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17258 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17262 struct dynamic_prop bit_stride_prop
;
17263 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17264 if (attr_bit_stride
!= nullptr)
17266 /* It only makes sense to have either a bit or byte stride. */
17267 if (attr_byte_stride
!= nullptr)
17269 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17270 "- DIE at %s [in module %s]"),
17271 sect_offset_str (die
->sect_off
),
17272 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17273 attr_bit_stride
= nullptr;
17277 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
17278 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17283 if (attr_byte_stride
!= nullptr
17284 || attr_bit_stride
!= nullptr)
17286 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17287 struct dynamic_prop
*stride
17288 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17291 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17292 &high
, bias
, stride
, byte_stride_p
);
17295 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17297 if (high_bound_is_count
)
17298 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17300 /* Ada expects an empty array on no boundary attributes. */
17301 if (attr
== NULL
&& cu
->language
!= language_ada
)
17302 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17304 name
= dwarf2_name (die
, cu
);
17306 TYPE_NAME (range_type
) = name
;
17308 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17309 if (attr
!= nullptr)
17310 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17312 maybe_set_alignment (cu
, die
, range_type
);
17314 set_die_type (die
, range_type
, cu
);
17316 /* set_die_type should be already done. */
17317 set_descriptive_type (range_type
, die
, cu
);
17322 static struct type
*
17323 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17327 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17329 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17331 /* In Ada, an unspecified type is typically used when the description
17332 of the type is deferred to a different unit. When encountering
17333 such a type, we treat it as a stub, and try to resolve it later on,
17335 if (cu
->language
== language_ada
)
17336 TYPE_STUB (type
) = 1;
17338 return set_die_type (die
, type
, cu
);
17341 /* Read a single die and all its descendents. Set the die's sibling
17342 field to NULL; set other fields in the die correctly, and set all
17343 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17344 location of the info_ptr after reading all of those dies. PARENT
17345 is the parent of the die in question. */
17347 static struct die_info
*
17348 read_die_and_children (const struct die_reader_specs
*reader
,
17349 const gdb_byte
*info_ptr
,
17350 const gdb_byte
**new_info_ptr
,
17351 struct die_info
*parent
)
17353 struct die_info
*die
;
17354 const gdb_byte
*cur_ptr
;
17356 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, 0);
17359 *new_info_ptr
= cur_ptr
;
17362 store_in_ref_table (die
, reader
->cu
);
17364 if (die
->has_children
)
17365 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
17369 *new_info_ptr
= cur_ptr
;
17372 die
->sibling
= NULL
;
17373 die
->parent
= parent
;
17377 /* Read a die, all of its descendents, and all of its siblings; set
17378 all of the fields of all of the dies correctly. Arguments are as
17379 in read_die_and_children. */
17381 static struct die_info
*
17382 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
17383 const gdb_byte
*info_ptr
,
17384 const gdb_byte
**new_info_ptr
,
17385 struct die_info
*parent
)
17387 struct die_info
*first_die
, *last_sibling
;
17388 const gdb_byte
*cur_ptr
;
17390 cur_ptr
= info_ptr
;
17391 first_die
= last_sibling
= NULL
;
17395 struct die_info
*die
17396 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
17400 *new_info_ptr
= cur_ptr
;
17407 last_sibling
->sibling
= die
;
17409 last_sibling
= die
;
17413 /* Read a die, all of its descendents, and all of its siblings; set
17414 all of the fields of all of the dies correctly. Arguments are as
17415 in read_die_and_children.
17416 This the main entry point for reading a DIE and all its children. */
17418 static struct die_info
*
17419 read_die_and_siblings (const struct die_reader_specs
*reader
,
17420 const gdb_byte
*info_ptr
,
17421 const gdb_byte
**new_info_ptr
,
17422 struct die_info
*parent
)
17424 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
17425 new_info_ptr
, parent
);
17427 if (dwarf_die_debug
)
17429 fprintf_unfiltered (gdb_stdlog
,
17430 "Read die from %s@0x%x of %s:\n",
17431 reader
->die_section
->get_name (),
17432 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17433 bfd_get_filename (reader
->abfd
));
17434 dump_die (die
, dwarf_die_debug
);
17440 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
17442 The caller is responsible for filling in the extra attributes
17443 and updating (*DIEP)->num_attrs.
17444 Set DIEP to point to a newly allocated die with its information,
17445 except for its child, sibling, and parent fields. */
17447 static const gdb_byte
*
17448 read_full_die_1 (const struct die_reader_specs
*reader
,
17449 struct die_info
**diep
, const gdb_byte
*info_ptr
,
17450 int num_extra_attrs
)
17452 unsigned int abbrev_number
, bytes_read
, i
;
17453 struct abbrev_info
*abbrev
;
17454 struct die_info
*die
;
17455 struct dwarf2_cu
*cu
= reader
->cu
;
17456 bfd
*abfd
= reader
->abfd
;
17458 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
17459 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
17460 info_ptr
+= bytes_read
;
17461 if (!abbrev_number
)
17467 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
17469 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
17471 bfd_get_filename (abfd
));
17473 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
17474 die
->sect_off
= sect_off
;
17475 die
->tag
= abbrev
->tag
;
17476 die
->abbrev
= abbrev_number
;
17477 die
->has_children
= abbrev
->has_children
;
17479 /* Make the result usable.
17480 The caller needs to update num_attrs after adding the extra
17482 die
->num_attrs
= abbrev
->num_attrs
;
17484 std::vector
<int> indexes_that_need_reprocess
;
17485 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
17487 bool need_reprocess
;
17489 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
17490 info_ptr
, &need_reprocess
);
17491 if (need_reprocess
)
17492 indexes_that_need_reprocess
.push_back (i
);
17495 struct attribute
*attr
= die
->attr (DW_AT_str_offsets_base
);
17496 if (attr
!= nullptr)
17497 cu
->str_offsets_base
= DW_UNSND (attr
);
17499 auto maybe_addr_base
= die
->addr_base ();
17500 if (maybe_addr_base
.has_value ())
17501 cu
->addr_base
= *maybe_addr_base
;
17502 for (int index
: indexes_that_need_reprocess
)
17503 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
17508 /* Read a die and all its attributes.
17509 Set DIEP to point to a newly allocated die with its information,
17510 except for its child, sibling, and parent fields. */
17512 static const gdb_byte
*
17513 read_full_die (const struct die_reader_specs
*reader
,
17514 struct die_info
**diep
, const gdb_byte
*info_ptr
)
17516 const gdb_byte
*result
;
17518 result
= read_full_die_1 (reader
, diep
, info_ptr
, 0);
17520 if (dwarf_die_debug
)
17522 fprintf_unfiltered (gdb_stdlog
,
17523 "Read die from %s@0x%x of %s:\n",
17524 reader
->die_section
->get_name (),
17525 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
17526 bfd_get_filename (reader
->abfd
));
17527 dump_die (*diep
, dwarf_die_debug
);
17534 /* Returns nonzero if TAG represents a type that we might generate a partial
17538 is_type_tag_for_partial (int tag
)
17543 /* Some types that would be reasonable to generate partial symbols for,
17544 that we don't at present. */
17545 case DW_TAG_array_type
:
17546 case DW_TAG_file_type
:
17547 case DW_TAG_ptr_to_member_type
:
17548 case DW_TAG_set_type
:
17549 case DW_TAG_string_type
:
17550 case DW_TAG_subroutine_type
:
17552 case DW_TAG_base_type
:
17553 case DW_TAG_class_type
:
17554 case DW_TAG_interface_type
:
17555 case DW_TAG_enumeration_type
:
17556 case DW_TAG_structure_type
:
17557 case DW_TAG_subrange_type
:
17558 case DW_TAG_typedef
:
17559 case DW_TAG_union_type
:
17566 /* Load all DIEs that are interesting for partial symbols into memory. */
17568 static struct partial_die_info
*
17569 load_partial_dies (const struct die_reader_specs
*reader
,
17570 const gdb_byte
*info_ptr
, int building_psymtab
)
17572 struct dwarf2_cu
*cu
= reader
->cu
;
17573 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17574 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
17575 unsigned int bytes_read
;
17576 unsigned int load_all
= 0;
17577 int nesting_level
= 1;
17582 gdb_assert (cu
->per_cu
!= NULL
);
17583 if (cu
->per_cu
->load_all_dies
)
17587 = htab_create_alloc_ex (cu
->header
.length
/ 12,
17591 &cu
->comp_unit_obstack
,
17592 hashtab_obstack_allocate
,
17593 dummy_obstack_deallocate
);
17597 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
17599 /* A NULL abbrev means the end of a series of children. */
17600 if (abbrev
== NULL
)
17602 if (--nesting_level
== 0)
17605 info_ptr
+= bytes_read
;
17606 last_die
= parent_die
;
17607 parent_die
= parent_die
->die_parent
;
17611 /* Check for template arguments. We never save these; if
17612 they're seen, we just mark the parent, and go on our way. */
17613 if (parent_die
!= NULL
17614 && cu
->language
== language_cplus
17615 && (abbrev
->tag
== DW_TAG_template_type_param
17616 || abbrev
->tag
== DW_TAG_template_value_param
))
17618 parent_die
->has_template_arguments
= 1;
17622 /* We don't need a partial DIE for the template argument. */
17623 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17628 /* We only recurse into c++ subprograms looking for template arguments.
17629 Skip their other children. */
17631 && cu
->language
== language_cplus
17632 && parent_die
!= NULL
17633 && parent_die
->tag
== DW_TAG_subprogram
)
17635 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17639 /* Check whether this DIE is interesting enough to save. Normally
17640 we would not be interested in members here, but there may be
17641 later variables referencing them via DW_AT_specification (for
17642 static members). */
17644 && !is_type_tag_for_partial (abbrev
->tag
)
17645 && abbrev
->tag
!= DW_TAG_constant
17646 && abbrev
->tag
!= DW_TAG_enumerator
17647 && abbrev
->tag
!= DW_TAG_subprogram
17648 && abbrev
->tag
!= DW_TAG_inlined_subroutine
17649 && abbrev
->tag
!= DW_TAG_lexical_block
17650 && abbrev
->tag
!= DW_TAG_variable
17651 && abbrev
->tag
!= DW_TAG_namespace
17652 && abbrev
->tag
!= DW_TAG_module
17653 && abbrev
->tag
!= DW_TAG_member
17654 && abbrev
->tag
!= DW_TAG_imported_unit
17655 && abbrev
->tag
!= DW_TAG_imported_declaration
)
17657 /* Otherwise we skip to the next sibling, if any. */
17658 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
17662 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
17665 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
17667 /* This two-pass algorithm for processing partial symbols has a
17668 high cost in cache pressure. Thus, handle some simple cases
17669 here which cover the majority of C partial symbols. DIEs
17670 which neither have specification tags in them, nor could have
17671 specification tags elsewhere pointing at them, can simply be
17672 processed and discarded.
17674 This segment is also optional; scan_partial_symbols and
17675 add_partial_symbol will handle these DIEs if we chain
17676 them in normally. When compilers which do not emit large
17677 quantities of duplicate debug information are more common,
17678 this code can probably be removed. */
17680 /* Any complete simple types at the top level (pretty much all
17681 of them, for a language without namespaces), can be processed
17683 if (parent_die
== NULL
17684 && pdi
.has_specification
== 0
17685 && pdi
.is_declaration
== 0
17686 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
17687 || pdi
.tag
== DW_TAG_base_type
17688 || pdi
.tag
== DW_TAG_subrange_type
))
17690 if (building_psymtab
&& pdi
.name
!= NULL
)
17691 add_psymbol_to_list (pdi
.name
, false,
17692 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
17693 psymbol_placement::STATIC
,
17694 0, cu
->language
, objfile
);
17695 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17699 /* The exception for DW_TAG_typedef with has_children above is
17700 a workaround of GCC PR debug/47510. In the case of this complaint
17701 type_name_or_error will error on such types later.
17703 GDB skipped children of DW_TAG_typedef by the shortcut above and then
17704 it could not find the child DIEs referenced later, this is checked
17705 above. In correct DWARF DW_TAG_typedef should have no children. */
17707 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
17708 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
17709 "- DIE at %s [in module %s]"),
17710 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
17712 /* If we're at the second level, and we're an enumerator, and
17713 our parent has no specification (meaning possibly lives in a
17714 namespace elsewhere), then we can add the partial symbol now
17715 instead of queueing it. */
17716 if (pdi
.tag
== DW_TAG_enumerator
17717 && parent_die
!= NULL
17718 && parent_die
->die_parent
== NULL
17719 && parent_die
->tag
== DW_TAG_enumeration_type
17720 && parent_die
->has_specification
== 0)
17722 if (pdi
.name
== NULL
)
17723 complaint (_("malformed enumerator DIE ignored"));
17724 else if (building_psymtab
)
17725 add_psymbol_to_list (pdi
.name
, false,
17726 VAR_DOMAIN
, LOC_CONST
, -1,
17727 cu
->language
== language_cplus
17728 ? psymbol_placement::GLOBAL
17729 : psymbol_placement::STATIC
,
17730 0, cu
->language
, objfile
);
17732 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
17736 struct partial_die_info
*part_die
17737 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
17739 /* We'll save this DIE so link it in. */
17740 part_die
->die_parent
= parent_die
;
17741 part_die
->die_sibling
= NULL
;
17742 part_die
->die_child
= NULL
;
17744 if (last_die
&& last_die
== parent_die
)
17745 last_die
->die_child
= part_die
;
17747 last_die
->die_sibling
= part_die
;
17749 last_die
= part_die
;
17751 if (first_die
== NULL
)
17752 first_die
= part_die
;
17754 /* Maybe add the DIE to the hash table. Not all DIEs that we
17755 find interesting need to be in the hash table, because we
17756 also have the parent/sibling/child chains; only those that we
17757 might refer to by offset later during partial symbol reading.
17759 For now this means things that might have be the target of a
17760 DW_AT_specification, DW_AT_abstract_origin, or
17761 DW_AT_extension. DW_AT_extension will refer only to
17762 namespaces; DW_AT_abstract_origin refers to functions (and
17763 many things under the function DIE, but we do not recurse
17764 into function DIEs during partial symbol reading) and
17765 possibly variables as well; DW_AT_specification refers to
17766 declarations. Declarations ought to have the DW_AT_declaration
17767 flag. It happens that GCC forgets to put it in sometimes, but
17768 only for functions, not for types.
17770 Adding more things than necessary to the hash table is harmless
17771 except for the performance cost. Adding too few will result in
17772 wasted time in find_partial_die, when we reread the compilation
17773 unit with load_all_dies set. */
17776 || abbrev
->tag
== DW_TAG_constant
17777 || abbrev
->tag
== DW_TAG_subprogram
17778 || abbrev
->tag
== DW_TAG_variable
17779 || abbrev
->tag
== DW_TAG_namespace
17780 || part_die
->is_declaration
)
17784 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
17785 to_underlying (part_die
->sect_off
),
17790 /* For some DIEs we want to follow their children (if any). For C
17791 we have no reason to follow the children of structures; for other
17792 languages we have to, so that we can get at method physnames
17793 to infer fully qualified class names, for DW_AT_specification,
17794 and for C++ template arguments. For C++, we also look one level
17795 inside functions to find template arguments (if the name of the
17796 function does not already contain the template arguments).
17798 For Ada and Fortran, we need to scan the children of subprograms
17799 and lexical blocks as well because these languages allow the
17800 definition of nested entities that could be interesting for the
17801 debugger, such as nested subprograms for instance. */
17802 if (last_die
->has_children
17804 || last_die
->tag
== DW_TAG_namespace
17805 || last_die
->tag
== DW_TAG_module
17806 || last_die
->tag
== DW_TAG_enumeration_type
17807 || (cu
->language
== language_cplus
17808 && last_die
->tag
== DW_TAG_subprogram
17809 && (last_die
->name
== NULL
17810 || strchr (last_die
->name
, '<') == NULL
))
17811 || (cu
->language
!= language_c
17812 && (last_die
->tag
== DW_TAG_class_type
17813 || last_die
->tag
== DW_TAG_interface_type
17814 || last_die
->tag
== DW_TAG_structure_type
17815 || last_die
->tag
== DW_TAG_union_type
))
17816 || ((cu
->language
== language_ada
17817 || cu
->language
== language_fortran
)
17818 && (last_die
->tag
== DW_TAG_subprogram
17819 || last_die
->tag
== DW_TAG_lexical_block
))))
17822 parent_die
= last_die
;
17826 /* Otherwise we skip to the next sibling, if any. */
17827 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
17829 /* Back to the top, do it again. */
17833 partial_die_info::partial_die_info (sect_offset sect_off_
,
17834 struct abbrev_info
*abbrev
)
17835 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
17839 /* Read a minimal amount of information into the minimal die structure.
17840 INFO_PTR should point just after the initial uleb128 of a DIE. */
17843 partial_die_info::read (const struct die_reader_specs
*reader
,
17844 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
17846 struct dwarf2_cu
*cu
= reader
->cu
;
17847 struct dwarf2_per_objfile
*dwarf2_per_objfile
17848 = cu
->per_cu
->dwarf2_per_objfile
;
17850 int has_low_pc_attr
= 0;
17851 int has_high_pc_attr
= 0;
17852 int high_pc_relative
= 0;
17854 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
17855 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
17857 bool need_reprocess
;
17858 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
17859 info_ptr
, &need_reprocess
);
17860 /* String and address offsets that need to do the reprocessing have
17861 already been read at this point, so there is no need to wait until
17862 the loop terminates to do the reprocessing. */
17863 if (need_reprocess
)
17864 read_attribute_reprocess (reader
, &attr_vec
[i
]);
17865 attribute
&attr
= attr_vec
[i
];
17866 /* Store the data if it is of an attribute we want to keep in a
17867 partial symbol table. */
17873 case DW_TAG_compile_unit
:
17874 case DW_TAG_partial_unit
:
17875 case DW_TAG_type_unit
:
17876 /* Compilation units have a DW_AT_name that is a filename, not
17877 a source language identifier. */
17878 case DW_TAG_enumeration_type
:
17879 case DW_TAG_enumerator
:
17880 /* These tags always have simple identifiers already; no need
17881 to canonicalize them. */
17882 name
= DW_STRING (&attr
);
17886 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
17889 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
, objfile
);
17894 case DW_AT_linkage_name
:
17895 case DW_AT_MIPS_linkage_name
:
17896 /* Note that both forms of linkage name might appear. We
17897 assume they will be the same, and we only store the last
17899 linkage_name
= DW_STRING (&attr
);
17902 has_low_pc_attr
= 1;
17903 lowpc
= attr
.value_as_address ();
17905 case DW_AT_high_pc
:
17906 has_high_pc_attr
= 1;
17907 highpc
= attr
.value_as_address ();
17908 if (cu
->header
.version
>= 4 && attr
.form_is_constant ())
17909 high_pc_relative
= 1;
17911 case DW_AT_location
:
17912 /* Support the .debug_loc offsets. */
17913 if (attr
.form_is_block ())
17915 d
.locdesc
= DW_BLOCK (&attr
);
17917 else if (attr
.form_is_section_offset ())
17919 dwarf2_complex_location_expr_complaint ();
17923 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17924 "partial symbol information");
17927 case DW_AT_external
:
17928 is_external
= DW_UNSND (&attr
);
17930 case DW_AT_declaration
:
17931 is_declaration
= DW_UNSND (&attr
);
17936 case DW_AT_abstract_origin
:
17937 case DW_AT_specification
:
17938 case DW_AT_extension
:
17939 has_specification
= 1;
17940 spec_offset
= attr
.get_ref_die_offset ();
17941 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17942 || cu
->per_cu
->is_dwz
);
17944 case DW_AT_sibling
:
17945 /* Ignore absolute siblings, they might point outside of
17946 the current compile unit. */
17947 if (attr
.form
== DW_FORM_ref_addr
)
17948 complaint (_("ignoring absolute DW_AT_sibling"));
17951 const gdb_byte
*buffer
= reader
->buffer
;
17952 sect_offset off
= attr
.get_ref_die_offset ();
17953 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
17955 if (sibling_ptr
< info_ptr
)
17956 complaint (_("DW_AT_sibling points backwards"));
17957 else if (sibling_ptr
> reader
->buffer_end
)
17958 reader
->die_section
->overflow_complaint ();
17960 sibling
= sibling_ptr
;
17963 case DW_AT_byte_size
:
17966 case DW_AT_const_value
:
17967 has_const_value
= 1;
17969 case DW_AT_calling_convention
:
17970 /* DWARF doesn't provide a way to identify a program's source-level
17971 entry point. DW_AT_calling_convention attributes are only meant
17972 to describe functions' calling conventions.
17974 However, because it's a necessary piece of information in
17975 Fortran, and before DWARF 4 DW_CC_program was the only
17976 piece of debugging information whose definition refers to
17977 a 'main program' at all, several compilers marked Fortran
17978 main programs with DW_CC_program --- even when those
17979 functions use the standard calling conventions.
17981 Although DWARF now specifies a way to provide this
17982 information, we support this practice for backward
17984 if (DW_UNSND (&attr
) == DW_CC_program
17985 && cu
->language
== language_fortran
)
17986 main_subprogram
= 1;
17989 if (DW_UNSND (&attr
) == DW_INL_inlined
17990 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
17991 may_be_inlined
= 1;
17995 if (tag
== DW_TAG_imported_unit
)
17997 d
.sect_off
= attr
.get_ref_die_offset ();
17998 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
17999 || cu
->per_cu
->is_dwz
);
18003 case DW_AT_main_subprogram
:
18004 main_subprogram
= DW_UNSND (&attr
);
18009 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18010 but that requires a full DIE, so instead we just
18012 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18013 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18014 + (need_ranges_base
18018 /* Value of the DW_AT_ranges attribute is the offset in the
18019 .debug_ranges section. */
18020 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18031 /* For Ada, if both the name and the linkage name appear, we prefer
18032 the latter. This lets "catch exception" work better, regardless
18033 of the order in which the name and linkage name were emitted.
18034 Really, though, this is just a workaround for the fact that gdb
18035 doesn't store both the name and the linkage name. */
18036 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18037 name
= linkage_name
;
18039 if (high_pc_relative
)
18042 if (has_low_pc_attr
&& has_high_pc_attr
)
18044 /* When using the GNU linker, .gnu.linkonce. sections are used to
18045 eliminate duplicate copies of functions and vtables and such.
18046 The linker will arbitrarily choose one and discard the others.
18047 The AT_*_pc values for such functions refer to local labels in
18048 these sections. If the section from that file was discarded, the
18049 labels are not in the output, so the relocs get a value of 0.
18050 If this is a discarded function, mark the pc bounds as invalid,
18051 so that GDB will ignore it. */
18052 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18054 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18055 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18057 complaint (_("DW_AT_low_pc %s is zero "
18058 "for DIE at %s [in module %s]"),
18059 paddress (gdbarch
, lowpc
),
18060 sect_offset_str (sect_off
),
18061 objfile_name (objfile
));
18063 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18064 else if (lowpc
>= highpc
)
18066 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18067 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18069 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18070 "for DIE at %s [in module %s]"),
18071 paddress (gdbarch
, lowpc
),
18072 paddress (gdbarch
, highpc
),
18073 sect_offset_str (sect_off
),
18074 objfile_name (objfile
));
18083 /* Find a cached partial DIE at OFFSET in CU. */
18085 struct partial_die_info
*
18086 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18088 struct partial_die_info
*lookup_die
= NULL
;
18089 struct partial_die_info
part_die (sect_off
);
18091 lookup_die
= ((struct partial_die_info
*)
18092 htab_find_with_hash (partial_dies
, &part_die
,
18093 to_underlying (sect_off
)));
18098 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18099 except in the case of .debug_types DIEs which do not reference
18100 outside their CU (they do however referencing other types via
18101 DW_FORM_ref_sig8). */
18103 static const struct cu_partial_die_info
18104 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18106 struct dwarf2_per_objfile
*dwarf2_per_objfile
18107 = cu
->per_cu
->dwarf2_per_objfile
;
18108 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18109 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18110 struct partial_die_info
*pd
= NULL
;
18112 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18113 && cu
->header
.offset_in_cu_p (sect_off
))
18115 pd
= cu
->find_partial_die (sect_off
);
18118 /* We missed recording what we needed.
18119 Load all dies and try again. */
18120 per_cu
= cu
->per_cu
;
18124 /* TUs don't reference other CUs/TUs (except via type signatures). */
18125 if (cu
->per_cu
->is_debug_types
)
18127 error (_("Dwarf Error: Type Unit at offset %s contains"
18128 " external reference to offset %s [in module %s].\n"),
18129 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18130 bfd_get_filename (objfile
->obfd
));
18132 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18133 dwarf2_per_objfile
);
18135 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18136 load_partial_comp_unit (per_cu
);
18138 per_cu
->cu
->last_used
= 0;
18139 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18142 /* If we didn't find it, and not all dies have been loaded,
18143 load them all and try again. */
18145 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18147 per_cu
->load_all_dies
= 1;
18149 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18150 THIS_CU->cu may already be in use. So we can't just free it and
18151 replace its DIEs with the ones we read in. Instead, we leave those
18152 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18153 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18155 load_partial_comp_unit (per_cu
);
18157 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18161 internal_error (__FILE__
, __LINE__
,
18162 _("could not find partial DIE %s "
18163 "in cache [from module %s]\n"),
18164 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18165 return { per_cu
->cu
, pd
};
18168 /* See if we can figure out if the class lives in a namespace. We do
18169 this by looking for a member function; its demangled name will
18170 contain namespace info, if there is any. */
18173 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18174 struct dwarf2_cu
*cu
)
18176 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18177 what template types look like, because the demangler
18178 frequently doesn't give the same name as the debug info. We
18179 could fix this by only using the demangled name to get the
18180 prefix (but see comment in read_structure_type). */
18182 struct partial_die_info
*real_pdi
;
18183 struct partial_die_info
*child_pdi
;
18185 /* If this DIE (this DIE's specification, if any) has a parent, then
18186 we should not do this. We'll prepend the parent's fully qualified
18187 name when we create the partial symbol. */
18189 real_pdi
= struct_pdi
;
18190 while (real_pdi
->has_specification
)
18192 auto res
= find_partial_die (real_pdi
->spec_offset
,
18193 real_pdi
->spec_is_dwz
, cu
);
18194 real_pdi
= res
.pdi
;
18198 if (real_pdi
->die_parent
!= NULL
)
18201 for (child_pdi
= struct_pdi
->die_child
;
18203 child_pdi
= child_pdi
->die_sibling
)
18205 if (child_pdi
->tag
== DW_TAG_subprogram
18206 && child_pdi
->linkage_name
!= NULL
)
18208 gdb::unique_xmalloc_ptr
<char> actual_class_name
18209 (language_class_name_from_physname (cu
->language_defn
,
18210 child_pdi
->linkage_name
));
18211 if (actual_class_name
!= NULL
)
18213 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18214 struct_pdi
->name
= objfile
->intern (actual_class_name
.get ());
18222 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18224 /* Once we've fixed up a die, there's no point in doing so again.
18225 This also avoids a memory leak if we were to call
18226 guess_partial_die_structure_name multiple times. */
18230 /* If we found a reference attribute and the DIE has no name, try
18231 to find a name in the referred to DIE. */
18233 if (name
== NULL
&& has_specification
)
18235 struct partial_die_info
*spec_die
;
18237 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18238 spec_die
= res
.pdi
;
18241 spec_die
->fixup (cu
);
18243 if (spec_die
->name
)
18245 name
= spec_die
->name
;
18247 /* Copy DW_AT_external attribute if it is set. */
18248 if (spec_die
->is_external
)
18249 is_external
= spec_die
->is_external
;
18253 /* Set default names for some unnamed DIEs. */
18255 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18256 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18258 /* If there is no parent die to provide a namespace, and there are
18259 children, see if we can determine the namespace from their linkage
18261 if (cu
->language
== language_cplus
18262 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18263 && die_parent
== NULL
18265 && (tag
== DW_TAG_class_type
18266 || tag
== DW_TAG_structure_type
18267 || tag
== DW_TAG_union_type
))
18268 guess_partial_die_structure_name (this, cu
);
18270 /* GCC might emit a nameless struct or union that has a linkage
18271 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18273 && (tag
== DW_TAG_class_type
18274 || tag
== DW_TAG_interface_type
18275 || tag
== DW_TAG_structure_type
18276 || tag
== DW_TAG_union_type
)
18277 && linkage_name
!= NULL
)
18279 gdb::unique_xmalloc_ptr
<char> demangled
18280 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18281 if (demangled
!= nullptr)
18285 /* Strip any leading namespaces/classes, keep only the base name.
18286 DW_AT_name for named DIEs does not contain the prefixes. */
18287 base
= strrchr (demangled
.get (), ':');
18288 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18291 base
= demangled
.get ();
18293 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18294 name
= objfile
->intern (base
);
18301 /* Process the attributes that had to be skipped in the first round. These
18302 attributes are the ones that need str_offsets_base or addr_base attributes.
18303 They could not have been processed in the first round, because at the time
18304 the values of str_offsets_base or addr_base may not have been known. */
18306 read_attribute_reprocess (const struct die_reader_specs
*reader
,
18307 struct attribute
*attr
)
18309 struct dwarf2_cu
*cu
= reader
->cu
;
18310 switch (attr
->form
)
18312 case DW_FORM_addrx
:
18313 case DW_FORM_GNU_addr_index
:
18314 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18317 case DW_FORM_strx1
:
18318 case DW_FORM_strx2
:
18319 case DW_FORM_strx3
:
18320 case DW_FORM_strx4
:
18321 case DW_FORM_GNU_str_index
:
18323 unsigned int str_index
= DW_UNSND (attr
);
18324 if (reader
->dwo_file
!= NULL
)
18326 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18327 DW_STRING_IS_CANONICAL (attr
) = 0;
18331 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18332 DW_STRING_IS_CANONICAL (attr
) = 0;
18337 gdb_assert_not_reached (_("Unexpected DWARF form."));
18341 /* Read an attribute value described by an attribute form. */
18343 static const gdb_byte
*
18344 read_attribute_value (const struct die_reader_specs
*reader
,
18345 struct attribute
*attr
, unsigned form
,
18346 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
18347 bool *need_reprocess
)
18349 struct dwarf2_cu
*cu
= reader
->cu
;
18350 struct dwarf2_per_objfile
*dwarf2_per_objfile
18351 = cu
->per_cu
->dwarf2_per_objfile
;
18352 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18353 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18354 bfd
*abfd
= reader
->abfd
;
18355 struct comp_unit_head
*cu_header
= &cu
->header
;
18356 unsigned int bytes_read
;
18357 struct dwarf_block
*blk
;
18358 *need_reprocess
= false;
18360 attr
->form
= (enum dwarf_form
) form
;
18363 case DW_FORM_ref_addr
:
18364 if (cu
->header
.version
== 2)
18365 DW_UNSND (attr
) = cu
->header
.read_address (abfd
, info_ptr
,
18368 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
,
18370 info_ptr
+= bytes_read
;
18372 case DW_FORM_GNU_ref_alt
:
18373 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18374 info_ptr
+= bytes_read
;
18377 DW_ADDR (attr
) = cu
->header
.read_address (abfd
, info_ptr
, &bytes_read
);
18378 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
18379 info_ptr
+= bytes_read
;
18381 case DW_FORM_block2
:
18382 blk
= dwarf_alloc_block (cu
);
18383 blk
->size
= read_2_bytes (abfd
, info_ptr
);
18385 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18386 info_ptr
+= blk
->size
;
18387 DW_BLOCK (attr
) = blk
;
18389 case DW_FORM_block4
:
18390 blk
= dwarf_alloc_block (cu
);
18391 blk
->size
= read_4_bytes (abfd
, info_ptr
);
18393 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18394 info_ptr
+= blk
->size
;
18395 DW_BLOCK (attr
) = blk
;
18397 case DW_FORM_data2
:
18398 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
18401 case DW_FORM_data4
:
18402 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
18405 case DW_FORM_data8
:
18406 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
18409 case DW_FORM_data16
:
18410 blk
= dwarf_alloc_block (cu
);
18412 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
18414 DW_BLOCK (attr
) = blk
;
18416 case DW_FORM_sec_offset
:
18417 DW_UNSND (attr
) = cu
->header
.read_offset (abfd
, info_ptr
, &bytes_read
);
18418 info_ptr
+= bytes_read
;
18420 case DW_FORM_string
:
18421 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
18422 DW_STRING_IS_CANONICAL (attr
) = 0;
18423 info_ptr
+= bytes_read
;
18426 if (!cu
->per_cu
->is_dwz
)
18428 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
18429 abfd
, info_ptr
, cu_header
,
18431 DW_STRING_IS_CANONICAL (attr
) = 0;
18432 info_ptr
+= bytes_read
;
18436 case DW_FORM_line_strp
:
18437 if (!cu
->per_cu
->is_dwz
)
18440 = dwarf2_per_objfile
->read_line_string (info_ptr
, cu_header
,
18442 DW_STRING_IS_CANONICAL (attr
) = 0;
18443 info_ptr
+= bytes_read
;
18447 case DW_FORM_GNU_strp_alt
:
18449 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
18450 LONGEST str_offset
= cu_header
->read_offset (abfd
, info_ptr
,
18453 DW_STRING (attr
) = dwz
->read_string (objfile
, str_offset
);
18454 DW_STRING_IS_CANONICAL (attr
) = 0;
18455 info_ptr
+= bytes_read
;
18458 case DW_FORM_exprloc
:
18459 case DW_FORM_block
:
18460 blk
= dwarf_alloc_block (cu
);
18461 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18462 info_ptr
+= bytes_read
;
18463 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18464 info_ptr
+= blk
->size
;
18465 DW_BLOCK (attr
) = blk
;
18467 case DW_FORM_block1
:
18468 blk
= dwarf_alloc_block (cu
);
18469 blk
->size
= read_1_byte (abfd
, info_ptr
);
18471 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
18472 info_ptr
+= blk
->size
;
18473 DW_BLOCK (attr
) = blk
;
18475 case DW_FORM_data1
:
18476 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18480 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
18483 case DW_FORM_flag_present
:
18484 DW_UNSND (attr
) = 1;
18486 case DW_FORM_sdata
:
18487 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18488 info_ptr
+= bytes_read
;
18490 case DW_FORM_udata
:
18491 case DW_FORM_rnglistx
:
18492 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18493 info_ptr
+= bytes_read
;
18496 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18497 + read_1_byte (abfd
, info_ptr
));
18501 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18502 + read_2_bytes (abfd
, info_ptr
));
18506 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18507 + read_4_bytes (abfd
, info_ptr
));
18511 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18512 + read_8_bytes (abfd
, info_ptr
));
18515 case DW_FORM_ref_sig8
:
18516 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
18519 case DW_FORM_ref_udata
:
18520 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
18521 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
18522 info_ptr
+= bytes_read
;
18524 case DW_FORM_indirect
:
18525 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18526 info_ptr
+= bytes_read
;
18527 if (form
== DW_FORM_implicit_const
)
18529 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
18530 info_ptr
+= bytes_read
;
18532 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
18533 info_ptr
, need_reprocess
);
18535 case DW_FORM_implicit_const
:
18536 DW_SND (attr
) = implicit_const
;
18538 case DW_FORM_addrx
:
18539 case DW_FORM_GNU_addr_index
:
18540 *need_reprocess
= true;
18541 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18542 info_ptr
+= bytes_read
;
18545 case DW_FORM_strx1
:
18546 case DW_FORM_strx2
:
18547 case DW_FORM_strx3
:
18548 case DW_FORM_strx4
:
18549 case DW_FORM_GNU_str_index
:
18551 ULONGEST str_index
;
18552 if (form
== DW_FORM_strx1
)
18554 str_index
= read_1_byte (abfd
, info_ptr
);
18557 else if (form
== DW_FORM_strx2
)
18559 str_index
= read_2_bytes (abfd
, info_ptr
);
18562 else if (form
== DW_FORM_strx3
)
18564 str_index
= read_3_bytes (abfd
, info_ptr
);
18567 else if (form
== DW_FORM_strx4
)
18569 str_index
= read_4_bytes (abfd
, info_ptr
);
18574 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18575 info_ptr
+= bytes_read
;
18577 *need_reprocess
= true;
18578 DW_UNSND (attr
) = str_index
;
18582 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
18583 dwarf_form_name (form
),
18584 bfd_get_filename (abfd
));
18588 if (cu
->per_cu
->is_dwz
&& attr
->form_is_ref ())
18589 attr
->form
= DW_FORM_GNU_ref_alt
;
18591 /* We have seen instances where the compiler tried to emit a byte
18592 size attribute of -1 which ended up being encoded as an unsigned
18593 0xffffffff. Although 0xffffffff is technically a valid size value,
18594 an object of this size seems pretty unlikely so we can relatively
18595 safely treat these cases as if the size attribute was invalid and
18596 treat them as zero by default. */
18597 if (attr
->name
== DW_AT_byte_size
18598 && form
== DW_FORM_data4
18599 && DW_UNSND (attr
) >= 0xffffffff)
18602 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
18603 hex_string (DW_UNSND (attr
)));
18604 DW_UNSND (attr
) = 0;
18610 /* Read an attribute described by an abbreviated attribute. */
18612 static const gdb_byte
*
18613 read_attribute (const struct die_reader_specs
*reader
,
18614 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
18615 const gdb_byte
*info_ptr
, bool *need_reprocess
)
18617 attr
->name
= abbrev
->name
;
18618 return read_attribute_value (reader
, attr
, abbrev
->form
,
18619 abbrev
->implicit_const
, info_ptr
,
18623 /* Return pointer to string at .debug_str offset STR_OFFSET. */
18625 static const char *
18626 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18627 LONGEST str_offset
)
18629 return dwarf2_per_objfile
->str
.read_string (dwarf2_per_objfile
->objfile
,
18630 str_offset
, "DW_FORM_strp");
18633 /* Return pointer to string at .debug_str offset as read from BUF.
18634 BUF is assumed to be in a compilation unit described by CU_HEADER.
18635 Return *BYTES_READ_PTR count of bytes read from BUF. */
18637 static const char *
18638 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
18639 const gdb_byte
*buf
,
18640 const struct comp_unit_head
*cu_header
,
18641 unsigned int *bytes_read_ptr
)
18643 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18645 return read_indirect_string_at_offset (dwarf2_per_objfile
, str_offset
);
18651 dwarf2_per_objfile::read_line_string (const gdb_byte
*buf
,
18652 const struct comp_unit_head
*cu_header
,
18653 unsigned int *bytes_read_ptr
)
18655 bfd
*abfd
= objfile
->obfd
;
18656 LONGEST str_offset
= cu_header
->read_offset (abfd
, buf
, bytes_read_ptr
);
18658 return line_str
.read_string (objfile
, str_offset
, "DW_FORM_line_strp");
18661 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
18662 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
18663 ADDR_SIZE is the size of addresses from the CU header. */
18666 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18667 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
18670 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18671 bfd
*abfd
= objfile
->obfd
;
18672 const gdb_byte
*info_ptr
;
18673 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
18675 dwarf2_per_objfile
->addr
.read (objfile
);
18676 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
18677 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
18678 objfile_name (objfile
));
18679 if (addr_base_or_zero
+ addr_index
* addr_size
18680 >= dwarf2_per_objfile
->addr
.size
)
18681 error (_("DW_FORM_addr_index pointing outside of "
18682 ".debug_addr section [in module %s]"),
18683 objfile_name (objfile
));
18684 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
18685 + addr_base_or_zero
+ addr_index
* addr_size
);
18686 if (addr_size
== 4)
18687 return bfd_get_32 (abfd
, info_ptr
);
18689 return bfd_get_64 (abfd
, info_ptr
);
18692 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
18695 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
18697 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
18698 cu
->addr_base
, cu
->header
.addr_size
);
18701 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
18704 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
18705 unsigned int *bytes_read
)
18707 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
18708 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
18710 return read_addr_index (cu
, addr_index
);
18716 dwarf2_read_addr_index (dwarf2_per_cu_data
*per_cu
, unsigned int addr_index
)
18718 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
18719 struct dwarf2_cu
*cu
= per_cu
->cu
;
18720 gdb::optional
<ULONGEST
> addr_base
;
18723 /* We need addr_base and addr_size.
18724 If we don't have PER_CU->cu, we have to get it.
18725 Nasty, but the alternative is storing the needed info in PER_CU,
18726 which at this point doesn't seem justified: it's not clear how frequently
18727 it would get used and it would increase the size of every PER_CU.
18728 Entry points like dwarf2_per_cu_addr_size do a similar thing
18729 so we're not in uncharted territory here.
18730 Alas we need to be a bit more complicated as addr_base is contained
18733 We don't need to read the entire CU(/TU).
18734 We just need the header and top level die.
18736 IWBN to use the aging mechanism to let us lazily later discard the CU.
18737 For now we skip this optimization. */
18741 addr_base
= cu
->addr_base
;
18742 addr_size
= cu
->header
.addr_size
;
18746 cutu_reader
reader (per_cu
, NULL
, 0, false);
18747 addr_base
= reader
.cu
->addr_base
;
18748 addr_size
= reader
.cu
->header
.addr_size
;
18751 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
18755 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
18756 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
18759 static const char *
18760 read_str_index (struct dwarf2_cu
*cu
,
18761 struct dwarf2_section_info
*str_section
,
18762 struct dwarf2_section_info
*str_offsets_section
,
18763 ULONGEST str_offsets_base
, ULONGEST str_index
)
18765 struct dwarf2_per_objfile
*dwarf2_per_objfile
18766 = cu
->per_cu
->dwarf2_per_objfile
;
18767 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18768 const char *objf_name
= objfile_name (objfile
);
18769 bfd
*abfd
= objfile
->obfd
;
18770 const gdb_byte
*info_ptr
;
18771 ULONGEST str_offset
;
18772 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
18774 str_section
->read (objfile
);
18775 str_offsets_section
->read (objfile
);
18776 if (str_section
->buffer
== NULL
)
18777 error (_("%s used without %s section"
18778 " in CU at offset %s [in module %s]"),
18779 form_name
, str_section
->get_name (),
18780 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18781 if (str_offsets_section
->buffer
== NULL
)
18782 error (_("%s used without %s section"
18783 " in CU at offset %s [in module %s]"),
18784 form_name
, str_section
->get_name (),
18785 sect_offset_str (cu
->header
.sect_off
), objf_name
);
18786 info_ptr
= (str_offsets_section
->buffer
18788 + str_index
* cu
->header
.offset_size
);
18789 if (cu
->header
.offset_size
== 4)
18790 str_offset
= bfd_get_32 (abfd
, info_ptr
);
18792 str_offset
= bfd_get_64 (abfd
, info_ptr
);
18793 if (str_offset
>= str_section
->size
)
18794 error (_("Offset from %s pointing outside of"
18795 " .debug_str.dwo section in CU at offset %s [in module %s]"),
18796 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
18797 return (const char *) (str_section
->buffer
+ str_offset
);
18800 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
18802 static const char *
18803 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
18805 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
18806 ? reader
->cu
->header
.addr_size
: 0;
18807 return read_str_index (reader
->cu
,
18808 &reader
->dwo_file
->sections
.str
,
18809 &reader
->dwo_file
->sections
.str_offsets
,
18810 str_offsets_base
, str_index
);
18813 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
18815 static const char *
18816 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
18818 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18819 const char *objf_name
= objfile_name (objfile
);
18820 static const char form_name
[] = "DW_FORM_GNU_str_index";
18821 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
18823 if (!cu
->str_offsets_base
.has_value ())
18824 error (_("%s used in Fission stub without %s"
18825 " in CU at offset 0x%lx [in module %s]"),
18826 form_name
, str_offsets_attr_name
,
18827 (long) cu
->header
.offset_size
, objf_name
);
18829 return read_str_index (cu
,
18830 &cu
->per_cu
->dwarf2_per_objfile
->str
,
18831 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
18832 *cu
->str_offsets_base
, str_index
);
18835 /* Return the length of an LEB128 number in BUF. */
18838 leb128_size (const gdb_byte
*buf
)
18840 const gdb_byte
*begin
= buf
;
18846 if ((byte
& 128) == 0)
18847 return buf
- begin
;
18852 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
18861 cu
->language
= language_c
;
18864 case DW_LANG_C_plus_plus
:
18865 case DW_LANG_C_plus_plus_11
:
18866 case DW_LANG_C_plus_plus_14
:
18867 cu
->language
= language_cplus
;
18870 cu
->language
= language_d
;
18872 case DW_LANG_Fortran77
:
18873 case DW_LANG_Fortran90
:
18874 case DW_LANG_Fortran95
:
18875 case DW_LANG_Fortran03
:
18876 case DW_LANG_Fortran08
:
18877 cu
->language
= language_fortran
;
18880 cu
->language
= language_go
;
18882 case DW_LANG_Mips_Assembler
:
18883 cu
->language
= language_asm
;
18885 case DW_LANG_Ada83
:
18886 case DW_LANG_Ada95
:
18887 cu
->language
= language_ada
;
18889 case DW_LANG_Modula2
:
18890 cu
->language
= language_m2
;
18892 case DW_LANG_Pascal83
:
18893 cu
->language
= language_pascal
;
18896 cu
->language
= language_objc
;
18899 case DW_LANG_Rust_old
:
18900 cu
->language
= language_rust
;
18902 case DW_LANG_Cobol74
:
18903 case DW_LANG_Cobol85
:
18905 cu
->language
= language_minimal
;
18908 cu
->language_defn
= language_def (cu
->language
);
18911 /* Return the named attribute or NULL if not there. */
18913 static struct attribute
*
18914 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18919 struct attribute
*spec
= NULL
;
18921 for (i
= 0; i
< die
->num_attrs
; ++i
)
18923 if (die
->attrs
[i
].name
== name
)
18924 return &die
->attrs
[i
];
18925 if (die
->attrs
[i
].name
== DW_AT_specification
18926 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
18927 spec
= &die
->attrs
[i
];
18933 die
= follow_die_ref (die
, spec
, &cu
);
18939 /* Return the string associated with a string-typed attribute, or NULL if it
18940 is either not found or is of an incorrect type. */
18942 static const char *
18943 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
18945 struct attribute
*attr
;
18946 const char *str
= NULL
;
18948 attr
= dwarf2_attr (die
, name
, cu
);
18952 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
18953 || attr
->form
== DW_FORM_string
18954 || attr
->form
== DW_FORM_strx
18955 || attr
->form
== DW_FORM_strx1
18956 || attr
->form
== DW_FORM_strx2
18957 || attr
->form
== DW_FORM_strx3
18958 || attr
->form
== DW_FORM_strx4
18959 || attr
->form
== DW_FORM_GNU_str_index
18960 || attr
->form
== DW_FORM_GNU_strp_alt
)
18961 str
= DW_STRING (attr
);
18963 complaint (_("string type expected for attribute %s for "
18964 "DIE at %s in module %s"),
18965 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
18966 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18972 /* Return the dwo name or NULL if not present. If present, it is in either
18973 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
18974 static const char *
18975 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
18977 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
18978 if (dwo_name
== nullptr)
18979 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
18983 /* Return non-zero iff the attribute NAME is defined for the given DIE,
18984 and holds a non-zero value. This function should only be used for
18985 DW_FORM_flag or DW_FORM_flag_present attributes. */
18988 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
18990 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
18992 return (attr
&& DW_UNSND (attr
));
18996 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
18998 /* A DIE is a declaration if it has a DW_AT_declaration attribute
18999 which value is non-zero. However, we have to be careful with
19000 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19001 (via dwarf2_flag_true_p) follows this attribute. So we may
19002 end up accidently finding a declaration attribute that belongs
19003 to a different DIE referenced by the specification attribute,
19004 even though the given DIE does not have a declaration attribute. */
19005 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19006 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19009 /* Return the die giving the specification for DIE, if there is
19010 one. *SPEC_CU is the CU containing DIE on input, and the CU
19011 containing the return value on output. If there is no
19012 specification, but there is an abstract origin, that is
19015 static struct die_info
*
19016 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19018 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19021 if (spec_attr
== NULL
)
19022 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19024 if (spec_attr
== NULL
)
19027 return follow_die_ref (die
, spec_attr
, spec_cu
);
19030 /* Stub for free_line_header to match void * callback types. */
19033 free_line_header_voidp (void *arg
)
19035 struct line_header
*lh
= (struct line_header
*) arg
;
19040 /* A convenience function to find the proper .debug_line section for a CU. */
19042 static struct dwarf2_section_info
*
19043 get_debug_line_section (struct dwarf2_cu
*cu
)
19045 struct dwarf2_section_info
*section
;
19046 struct dwarf2_per_objfile
*dwarf2_per_objfile
19047 = cu
->per_cu
->dwarf2_per_objfile
;
19049 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
19051 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19052 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
19053 else if (cu
->per_cu
->is_dwz
)
19055 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19057 section
= &dwz
->line
;
19060 section
= &dwarf2_per_objfile
->line
;
19065 /* Read the statement program header starting at OFFSET in
19066 .debug_line, or .debug_line.dwo. Return a pointer
19067 to a struct line_header, allocated using xmalloc.
19068 Returns NULL if there is a problem reading the header, e.g., if it
19069 has a version we don't understand.
19071 NOTE: the strings in the include directory and file name tables of
19072 the returned object point into the dwarf line section buffer,
19073 and must not be freed. */
19075 static line_header_up
19076 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
19078 struct dwarf2_section_info
*section
;
19079 struct dwarf2_per_objfile
*dwarf2_per_objfile
19080 = cu
->per_cu
->dwarf2_per_objfile
;
19082 section
= get_debug_line_section (cu
);
19083 section
->read (dwarf2_per_objfile
->objfile
);
19084 if (section
->buffer
== NULL
)
19086 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
19087 complaint (_("missing .debug_line.dwo section"));
19089 complaint (_("missing .debug_line section"));
19093 return dwarf_decode_line_header (sect_off
, cu
->per_cu
->is_dwz
,
19094 dwarf2_per_objfile
, section
,
19098 /* Subroutine of dwarf_decode_lines to simplify it.
19099 Return the file name of the psymtab for the given file_entry.
19100 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19101 If space for the result is malloc'd, *NAME_HOLDER will be set.
19102 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
19104 static const char *
19105 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
19106 const dwarf2_psymtab
*pst
,
19107 const char *comp_dir
,
19108 gdb::unique_xmalloc_ptr
<char> *name_holder
)
19110 const char *include_name
= fe
.name
;
19111 const char *include_name_to_compare
= include_name
;
19112 const char *pst_filename
;
19115 const char *dir_name
= fe
.include_dir (lh
);
19117 gdb::unique_xmalloc_ptr
<char> hold_compare
;
19118 if (!IS_ABSOLUTE_PATH (include_name
)
19119 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
19121 /* Avoid creating a duplicate psymtab for PST.
19122 We do this by comparing INCLUDE_NAME and PST_FILENAME.
19123 Before we do the comparison, however, we need to account
19124 for DIR_NAME and COMP_DIR.
19125 First prepend dir_name (if non-NULL). If we still don't
19126 have an absolute path prepend comp_dir (if non-NULL).
19127 However, the directory we record in the include-file's
19128 psymtab does not contain COMP_DIR (to match the
19129 corresponding symtab(s)).
19134 bash$ gcc -g ./hello.c
19135 include_name = "hello.c"
19137 DW_AT_comp_dir = comp_dir = "/tmp"
19138 DW_AT_name = "./hello.c"
19142 if (dir_name
!= NULL
)
19144 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
19145 include_name
, (char *) NULL
));
19146 include_name
= name_holder
->get ();
19147 include_name_to_compare
= include_name
;
19149 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
19151 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
19152 include_name
, (char *) NULL
));
19153 include_name_to_compare
= hold_compare
.get ();
19157 pst_filename
= pst
->filename
;
19158 gdb::unique_xmalloc_ptr
<char> copied_name
;
19159 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
19161 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
19162 pst_filename
, (char *) NULL
));
19163 pst_filename
= copied_name
.get ();
19166 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
19170 return include_name
;
19173 /* State machine to track the state of the line number program. */
19175 class lnp_state_machine
19178 /* Initialize a machine state for the start of a line number
19180 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
19181 bool record_lines_p
);
19183 file_entry
*current_file ()
19185 /* lh->file_names is 0-based, but the file name numbers in the
19186 statement program are 1-based. */
19187 return m_line_header
->file_name_at (m_file
);
19190 /* Record the line in the state machine. END_SEQUENCE is true if
19191 we're processing the end of a sequence. */
19192 void record_line (bool end_sequence
);
19194 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
19195 nop-out rest of the lines in this sequence. */
19196 void check_line_address (struct dwarf2_cu
*cu
,
19197 const gdb_byte
*line_ptr
,
19198 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
19200 void handle_set_discriminator (unsigned int discriminator
)
19202 m_discriminator
= discriminator
;
19203 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
19206 /* Handle DW_LNE_set_address. */
19207 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
19210 address
+= baseaddr
;
19211 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
19214 /* Handle DW_LNS_advance_pc. */
19215 void handle_advance_pc (CORE_ADDR adjust
);
19217 /* Handle a special opcode. */
19218 void handle_special_opcode (unsigned char op_code
);
19220 /* Handle DW_LNS_advance_line. */
19221 void handle_advance_line (int line_delta
)
19223 advance_line (line_delta
);
19226 /* Handle DW_LNS_set_file. */
19227 void handle_set_file (file_name_index file
);
19229 /* Handle DW_LNS_negate_stmt. */
19230 void handle_negate_stmt ()
19232 m_is_stmt
= !m_is_stmt
;
19235 /* Handle DW_LNS_const_add_pc. */
19236 void handle_const_add_pc ();
19238 /* Handle DW_LNS_fixed_advance_pc. */
19239 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
19241 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19245 /* Handle DW_LNS_copy. */
19246 void handle_copy ()
19248 record_line (false);
19249 m_discriminator
= 0;
19252 /* Handle DW_LNE_end_sequence. */
19253 void handle_end_sequence ()
19255 m_currently_recording_lines
= true;
19259 /* Advance the line by LINE_DELTA. */
19260 void advance_line (int line_delta
)
19262 m_line
+= line_delta
;
19264 if (line_delta
!= 0)
19265 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19268 struct dwarf2_cu
*m_cu
;
19270 gdbarch
*m_gdbarch
;
19272 /* True if we're recording lines.
19273 Otherwise we're building partial symtabs and are just interested in
19274 finding include files mentioned by the line number program. */
19275 bool m_record_lines_p
;
19277 /* The line number header. */
19278 line_header
*m_line_header
;
19280 /* These are part of the standard DWARF line number state machine,
19281 and initialized according to the DWARF spec. */
19283 unsigned char m_op_index
= 0;
19284 /* The line table index of the current file. */
19285 file_name_index m_file
= 1;
19286 unsigned int m_line
= 1;
19288 /* These are initialized in the constructor. */
19290 CORE_ADDR m_address
;
19292 unsigned int m_discriminator
;
19294 /* Additional bits of state we need to track. */
19296 /* The last file that we called dwarf2_start_subfile for.
19297 This is only used for TLLs. */
19298 unsigned int m_last_file
= 0;
19299 /* The last file a line number was recorded for. */
19300 struct subfile
*m_last_subfile
= NULL
;
19302 /* When true, record the lines we decode. */
19303 bool m_currently_recording_lines
= false;
19305 /* The last line number that was recorded, used to coalesce
19306 consecutive entries for the same line. This can happen, for
19307 example, when discriminators are present. PR 17276. */
19308 unsigned int m_last_line
= 0;
19309 bool m_line_has_non_zero_discriminator
= false;
19313 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
19315 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
19316 / m_line_header
->maximum_ops_per_instruction
)
19317 * m_line_header
->minimum_instruction_length
);
19318 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19319 m_op_index
= ((m_op_index
+ adjust
)
19320 % m_line_header
->maximum_ops_per_instruction
);
19324 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
19326 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
19327 unsigned char adj_opcode_d
= adj_opcode
/ m_line_header
->line_range
;
19328 unsigned char adj_opcode_r
= adj_opcode
% m_line_header
->line_range
;
19329 CORE_ADDR addr_adj
= (((m_op_index
+ adj_opcode_d
)
19330 / m_line_header
->maximum_ops_per_instruction
)
19331 * m_line_header
->minimum_instruction_length
);
19332 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19333 m_op_index
= ((m_op_index
+ adj_opcode_d
)
19334 % m_line_header
->maximum_ops_per_instruction
);
19336 int line_delta
= m_line_header
->line_base
+ adj_opcode_r
;
19337 advance_line (line_delta
);
19338 record_line (false);
19339 m_discriminator
= 0;
19343 lnp_state_machine::handle_set_file (file_name_index file
)
19347 const file_entry
*fe
= current_file ();
19349 dwarf2_debug_line_missing_file_complaint ();
19350 else if (m_record_lines_p
)
19352 const char *dir
= fe
->include_dir (m_line_header
);
19354 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19355 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
19356 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
19361 lnp_state_machine::handle_const_add_pc ()
19364 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
19367 = (((m_op_index
+ adjust
)
19368 / m_line_header
->maximum_ops_per_instruction
)
19369 * m_line_header
->minimum_instruction_length
);
19371 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
19372 m_op_index
= ((m_op_index
+ adjust
)
19373 % m_line_header
->maximum_ops_per_instruction
);
19376 /* Return non-zero if we should add LINE to the line number table.
19377 LINE is the line to add, LAST_LINE is the last line that was added,
19378 LAST_SUBFILE is the subfile for LAST_LINE.
19379 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
19380 had a non-zero discriminator.
19382 We have to be careful in the presence of discriminators.
19383 E.g., for this line:
19385 for (i = 0; i < 100000; i++);
19387 clang can emit four line number entries for that one line,
19388 each with a different discriminator.
19389 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
19391 However, we want gdb to coalesce all four entries into one.
19392 Otherwise the user could stepi into the middle of the line and
19393 gdb would get confused about whether the pc really was in the
19394 middle of the line.
19396 Things are further complicated by the fact that two consecutive
19397 line number entries for the same line is a heuristic used by gcc
19398 to denote the end of the prologue. So we can't just discard duplicate
19399 entries, we have to be selective about it. The heuristic we use is
19400 that we only collapse consecutive entries for the same line if at least
19401 one of those entries has a non-zero discriminator. PR 17276.
19403 Note: Addresses in the line number state machine can never go backwards
19404 within one sequence, thus this coalescing is ok. */
19407 dwarf_record_line_p (struct dwarf2_cu
*cu
,
19408 unsigned int line
, unsigned int last_line
,
19409 int line_has_non_zero_discriminator
,
19410 struct subfile
*last_subfile
)
19412 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
19414 if (line
!= last_line
)
19416 /* Same line for the same file that we've seen already.
19417 As a last check, for pr 17276, only record the line if the line
19418 has never had a non-zero discriminator. */
19419 if (!line_has_non_zero_discriminator
)
19424 /* Use the CU's builder to record line number LINE beginning at
19425 address ADDRESS in the line table of subfile SUBFILE. */
19428 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19429 unsigned int line
, CORE_ADDR address
, bool is_stmt
,
19430 struct dwarf2_cu
*cu
)
19432 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
19434 if (dwarf_line_debug
)
19436 fprintf_unfiltered (gdb_stdlog
,
19437 "Recording line %u, file %s, address %s\n",
19438 line
, lbasename (subfile
->name
),
19439 paddress (gdbarch
, address
));
19443 cu
->get_builder ()->record_line (subfile
, line
, addr
, is_stmt
);
19446 /* Subroutine of dwarf_decode_lines_1 to simplify it.
19447 Mark the end of a set of line number records.
19448 The arguments are the same as for dwarf_record_line_1.
19449 If SUBFILE is NULL the request is ignored. */
19452 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
19453 CORE_ADDR address
, struct dwarf2_cu
*cu
)
19455 if (subfile
== NULL
)
19458 if (dwarf_line_debug
)
19460 fprintf_unfiltered (gdb_stdlog
,
19461 "Finishing current line, file %s, address %s\n",
19462 lbasename (subfile
->name
),
19463 paddress (gdbarch
, address
));
19466 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, true, cu
);
19470 lnp_state_machine::record_line (bool end_sequence
)
19472 if (dwarf_line_debug
)
19474 fprintf_unfiltered (gdb_stdlog
,
19475 "Processing actual line %u: file %u,"
19476 " address %s, is_stmt %u, discrim %u%s\n",
19478 paddress (m_gdbarch
, m_address
),
19479 m_is_stmt
, m_discriminator
,
19480 (end_sequence
? "\t(end sequence)" : ""));
19483 file_entry
*fe
= current_file ();
19486 dwarf2_debug_line_missing_file_complaint ();
19487 /* For now we ignore lines not starting on an instruction boundary.
19488 But not when processing end_sequence for compatibility with the
19489 previous version of the code. */
19490 else if (m_op_index
== 0 || end_sequence
)
19492 fe
->included_p
= 1;
19493 if (m_record_lines_p
)
19495 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
19498 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
19499 m_currently_recording_lines
? m_cu
: nullptr);
19504 bool is_stmt
= producer_is_codewarrior (m_cu
) || m_is_stmt
;
19506 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
19507 m_line_has_non_zero_discriminator
,
19510 buildsym_compunit
*builder
= m_cu
->get_builder ();
19511 dwarf_record_line_1 (m_gdbarch
,
19512 builder
->get_current_subfile (),
19513 m_line
, m_address
, is_stmt
,
19514 m_currently_recording_lines
? m_cu
: nullptr);
19516 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
19517 m_last_line
= m_line
;
19523 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
19524 line_header
*lh
, bool record_lines_p
)
19528 m_record_lines_p
= record_lines_p
;
19529 m_line_header
= lh
;
19531 m_currently_recording_lines
= true;
19533 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
19534 was a line entry for it so that the backend has a chance to adjust it
19535 and also record it in case it needs it. This is currently used by MIPS
19536 code, cf. `mips_adjust_dwarf2_line'. */
19537 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
19538 m_is_stmt
= lh
->default_is_stmt
;
19539 m_discriminator
= 0;
19543 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
19544 const gdb_byte
*line_ptr
,
19545 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
19547 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
19548 the pc range of the CU. However, we restrict the test to only ADDRESS
19549 values of zero to preserve GDB's previous behaviour which is to handle
19550 the specific case of a function being GC'd by the linker. */
19552 if (address
== 0 && address
< unrelocated_lowpc
)
19554 /* This line table is for a function which has been
19555 GCd by the linker. Ignore it. PR gdb/12528 */
19557 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19558 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
19560 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
19561 line_offset
, objfile_name (objfile
));
19562 m_currently_recording_lines
= false;
19563 /* Note: m_currently_recording_lines is left as false until we see
19564 DW_LNE_end_sequence. */
19568 /* Subroutine of dwarf_decode_lines to simplify it.
19569 Process the line number information in LH.
19570 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
19571 program in order to set included_p for every referenced header. */
19574 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
19575 const int decode_for_pst_p
, CORE_ADDR lowpc
)
19577 const gdb_byte
*line_ptr
, *extended_end
;
19578 const gdb_byte
*line_end
;
19579 unsigned int bytes_read
, extended_len
;
19580 unsigned char op_code
, extended_op
;
19581 CORE_ADDR baseaddr
;
19582 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19583 bfd
*abfd
= objfile
->obfd
;
19584 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19585 /* True if we're recording line info (as opposed to building partial
19586 symtabs and just interested in finding include files mentioned by
19587 the line number program). */
19588 bool record_lines_p
= !decode_for_pst_p
;
19590 baseaddr
= objfile
->text_section_offset ();
19592 line_ptr
= lh
->statement_program_start
;
19593 line_end
= lh
->statement_program_end
;
19595 /* Read the statement sequences until there's nothing left. */
19596 while (line_ptr
< line_end
)
19598 /* The DWARF line number program state machine. Reset the state
19599 machine at the start of each sequence. */
19600 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
19601 bool end_sequence
= false;
19603 if (record_lines_p
)
19605 /* Start a subfile for the current file of the state
19607 const file_entry
*fe
= state_machine
.current_file ();
19610 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
19613 /* Decode the table. */
19614 while (line_ptr
< line_end
&& !end_sequence
)
19616 op_code
= read_1_byte (abfd
, line_ptr
);
19619 if (op_code
>= lh
->opcode_base
)
19621 /* Special opcode. */
19622 state_machine
.handle_special_opcode (op_code
);
19624 else switch (op_code
)
19626 case DW_LNS_extended_op
:
19627 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
19629 line_ptr
+= bytes_read
;
19630 extended_end
= line_ptr
+ extended_len
;
19631 extended_op
= read_1_byte (abfd
, line_ptr
);
19633 switch (extended_op
)
19635 case DW_LNE_end_sequence
:
19636 state_machine
.handle_end_sequence ();
19637 end_sequence
= true;
19639 case DW_LNE_set_address
:
19642 = cu
->header
.read_address (abfd
, line_ptr
, &bytes_read
);
19643 line_ptr
+= bytes_read
;
19645 state_machine
.check_line_address (cu
, line_ptr
,
19646 lowpc
- baseaddr
, address
);
19647 state_machine
.handle_set_address (baseaddr
, address
);
19650 case DW_LNE_define_file
:
19652 const char *cur_file
;
19653 unsigned int mod_time
, length
;
19656 cur_file
= read_direct_string (abfd
, line_ptr
,
19658 line_ptr
+= bytes_read
;
19659 dindex
= (dir_index
)
19660 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19661 line_ptr
+= bytes_read
;
19663 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19664 line_ptr
+= bytes_read
;
19666 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19667 line_ptr
+= bytes_read
;
19668 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
19671 case DW_LNE_set_discriminator
:
19673 /* The discriminator is not interesting to the
19674 debugger; just ignore it. We still need to
19675 check its value though:
19676 if there are consecutive entries for the same
19677 (non-prologue) line we want to coalesce them.
19680 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19681 line_ptr
+= bytes_read
;
19683 state_machine
.handle_set_discriminator (discr
);
19687 complaint (_("mangled .debug_line section"));
19690 /* Make sure that we parsed the extended op correctly. If e.g.
19691 we expected a different address size than the producer used,
19692 we may have read the wrong number of bytes. */
19693 if (line_ptr
!= extended_end
)
19695 complaint (_("mangled .debug_line section"));
19700 state_machine
.handle_copy ();
19702 case DW_LNS_advance_pc
:
19705 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19706 line_ptr
+= bytes_read
;
19708 state_machine
.handle_advance_pc (adjust
);
19711 case DW_LNS_advance_line
:
19714 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
19715 line_ptr
+= bytes_read
;
19717 state_machine
.handle_advance_line (line_delta
);
19720 case DW_LNS_set_file
:
19722 file_name_index file
19723 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
19725 line_ptr
+= bytes_read
;
19727 state_machine
.handle_set_file (file
);
19730 case DW_LNS_set_column
:
19731 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19732 line_ptr
+= bytes_read
;
19734 case DW_LNS_negate_stmt
:
19735 state_machine
.handle_negate_stmt ();
19737 case DW_LNS_set_basic_block
:
19739 /* Add to the address register of the state machine the
19740 address increment value corresponding to special opcode
19741 255. I.e., this value is scaled by the minimum
19742 instruction length since special opcode 255 would have
19743 scaled the increment. */
19744 case DW_LNS_const_add_pc
:
19745 state_machine
.handle_const_add_pc ();
19747 case DW_LNS_fixed_advance_pc
:
19749 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
19752 state_machine
.handle_fixed_advance_pc (addr_adj
);
19757 /* Unknown standard opcode, ignore it. */
19760 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
19762 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
19763 line_ptr
+= bytes_read
;
19770 dwarf2_debug_line_missing_end_sequence_complaint ();
19772 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
19773 in which case we still finish recording the last line). */
19774 state_machine
.record_line (true);
19778 /* Decode the Line Number Program (LNP) for the given line_header
19779 structure and CU. The actual information extracted and the type
19780 of structures created from the LNP depends on the value of PST.
19782 1. If PST is NULL, then this procedure uses the data from the program
19783 to create all necessary symbol tables, and their linetables.
19785 2. If PST is not NULL, this procedure reads the program to determine
19786 the list of files included by the unit represented by PST, and
19787 builds all the associated partial symbol tables.
19789 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
19790 It is used for relative paths in the line table.
19791 NOTE: When processing partial symtabs (pst != NULL),
19792 comp_dir == pst->dirname.
19794 NOTE: It is important that psymtabs have the same file name (via strcmp)
19795 as the corresponding symtab. Since COMP_DIR is not used in the name of the
19796 symtab we don't use it in the name of the psymtabs we create.
19797 E.g. expand_line_sal requires this when finding psymtabs to expand.
19798 A good testcase for this is mb-inline.exp.
19800 LOWPC is the lowest address in CU (or 0 if not known).
19802 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
19803 for its PC<->lines mapping information. Otherwise only the filename
19804 table is read in. */
19807 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
19808 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
19809 CORE_ADDR lowpc
, int decode_mapping
)
19811 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19812 const int decode_for_pst_p
= (pst
!= NULL
);
19814 if (decode_mapping
)
19815 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
19817 if (decode_for_pst_p
)
19819 /* Now that we're done scanning the Line Header Program, we can
19820 create the psymtab of each included file. */
19821 for (auto &file_entry
: lh
->file_names ())
19822 if (file_entry
.included_p
== 1)
19824 gdb::unique_xmalloc_ptr
<char> name_holder
;
19825 const char *include_name
=
19826 psymtab_include_file_name (lh
, file_entry
, pst
,
19827 comp_dir
, &name_holder
);
19828 if (include_name
!= NULL
)
19829 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
19834 /* Make sure a symtab is created for every file, even files
19835 which contain only variables (i.e. no code with associated
19837 buildsym_compunit
*builder
= cu
->get_builder ();
19838 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
19840 for (auto &fe
: lh
->file_names ())
19842 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
19843 if (builder
->get_current_subfile ()->symtab
== NULL
)
19845 builder
->get_current_subfile ()->symtab
19846 = allocate_symtab (cust
,
19847 builder
->get_current_subfile ()->name
);
19849 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
19854 /* Start a subfile for DWARF. FILENAME is the name of the file and
19855 DIRNAME the name of the source directory which contains FILENAME
19856 or NULL if not known.
19857 This routine tries to keep line numbers from identical absolute and
19858 relative file names in a common subfile.
19860 Using the `list' example from the GDB testsuite, which resides in
19861 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
19862 of /srcdir/list0.c yields the following debugging information for list0.c:
19864 DW_AT_name: /srcdir/list0.c
19865 DW_AT_comp_dir: /compdir
19866 files.files[0].name: list0.h
19867 files.files[0].dir: /srcdir
19868 files.files[1].name: list0.c
19869 files.files[1].dir: /srcdir
19871 The line number information for list0.c has to end up in a single
19872 subfile, so that `break /srcdir/list0.c:1' works as expected.
19873 start_subfile will ensure that this happens provided that we pass the
19874 concatenation of files.files[1].dir and files.files[1].name as the
19878 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
19879 const char *dirname
)
19881 gdb::unique_xmalloc_ptr
<char> copy
;
19883 /* In order not to lose the line information directory,
19884 we concatenate it to the filename when it makes sense.
19885 Note that the Dwarf3 standard says (speaking of filenames in line
19886 information): ``The directory index is ignored for file names
19887 that represent full path names''. Thus ignoring dirname in the
19888 `else' branch below isn't an issue. */
19890 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
19892 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
19893 filename
= copy
.get ();
19896 cu
->get_builder ()->start_subfile (filename
);
19899 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
19900 buildsym_compunit constructor. */
19902 struct compunit_symtab
*
19903 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
19906 gdb_assert (m_builder
== nullptr);
19908 m_builder
.reset (new struct buildsym_compunit
19909 (per_cu
->dwarf2_per_objfile
->objfile
,
19910 name
, comp_dir
, language
, low_pc
));
19912 list_in_scope
= get_builder ()->get_file_symbols ();
19914 get_builder ()->record_debugformat ("DWARF 2");
19915 get_builder ()->record_producer (producer
);
19917 processing_has_namespace_info
= false;
19919 return get_builder ()->get_compunit_symtab ();
19923 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
19924 struct dwarf2_cu
*cu
)
19926 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19927 struct comp_unit_head
*cu_header
= &cu
->header
;
19929 /* NOTE drow/2003-01-30: There used to be a comment and some special
19930 code here to turn a symbol with DW_AT_external and a
19931 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
19932 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
19933 with some versions of binutils) where shared libraries could have
19934 relocations against symbols in their debug information - the
19935 minimal symbol would have the right address, but the debug info
19936 would not. It's no longer necessary, because we will explicitly
19937 apply relocations when we read in the debug information now. */
19939 /* A DW_AT_location attribute with no contents indicates that a
19940 variable has been optimized away. */
19941 if (attr
->form_is_block () && DW_BLOCK (attr
)->size
== 0)
19943 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
19947 /* Handle one degenerate form of location expression specially, to
19948 preserve GDB's previous behavior when section offsets are
19949 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
19950 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
19952 if (attr
->form_is_block ()
19953 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
19954 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
19955 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
19956 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
19957 && (DW_BLOCK (attr
)->size
19958 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
19960 unsigned int dummy
;
19962 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
19963 SET_SYMBOL_VALUE_ADDRESS
19964 (sym
, cu
->header
.read_address (objfile
->obfd
,
19965 DW_BLOCK (attr
)->data
+ 1,
19968 SET_SYMBOL_VALUE_ADDRESS
19969 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
19971 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
19972 fixup_symbol_section (sym
, objfile
);
19973 SET_SYMBOL_VALUE_ADDRESS
19975 SYMBOL_VALUE_ADDRESS (sym
)
19976 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
19980 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
19981 expression evaluator, and use LOC_COMPUTED only when necessary
19982 (i.e. when the value of a register or memory location is
19983 referenced, or a thread-local block, etc.). Then again, it might
19984 not be worthwhile. I'm assuming that it isn't unless performance
19985 or memory numbers show me otherwise. */
19987 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
19989 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
19990 cu
->has_loclist
= true;
19993 /* Given a pointer to a DWARF information entry, figure out if we need
19994 to make a symbol table entry for it, and if so, create a new entry
19995 and return a pointer to it.
19996 If TYPE is NULL, determine symbol type from the die, otherwise
19997 used the passed type.
19998 If SPACE is not NULL, use it to hold the new symbol. If it is
19999 NULL, allocate a new symbol on the objfile's obstack. */
20001 static struct symbol
*
20002 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
20003 struct symbol
*space
)
20005 struct dwarf2_per_objfile
*dwarf2_per_objfile
20006 = cu
->per_cu
->dwarf2_per_objfile
;
20007 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20008 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20009 struct symbol
*sym
= NULL
;
20011 struct attribute
*attr
= NULL
;
20012 struct attribute
*attr2
= NULL
;
20013 CORE_ADDR baseaddr
;
20014 struct pending
**list_to_add
= NULL
;
20016 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
20018 baseaddr
= objfile
->text_section_offset ();
20020 name
= dwarf2_name (die
, cu
);
20023 const char *linkagename
;
20024 int suppress_add
= 0;
20029 sym
= allocate_symbol (objfile
);
20030 OBJSTAT (objfile
, n_syms
++);
20032 /* Cache this symbol's name and the name's demangled form (if any). */
20033 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
20034 linkagename
= dwarf2_physname (name
, die
, cu
);
20035 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
20037 /* Fortran does not have mangling standard and the mangling does differ
20038 between gfortran, iFort etc. */
20039 if (cu
->language
== language_fortran
20040 && symbol_get_demangled_name (sym
) == NULL
)
20041 symbol_set_demangled_name (sym
,
20042 dwarf2_full_name (name
, die
, cu
),
20045 /* Default assumptions.
20046 Use the passed type or decode it from the die. */
20047 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20048 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
20050 SYMBOL_TYPE (sym
) = type
;
20052 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
20053 attr
= dwarf2_attr (die
,
20054 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
20056 if (attr
!= nullptr)
20058 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
20061 attr
= dwarf2_attr (die
,
20062 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
20064 if (attr
!= nullptr)
20066 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
20067 struct file_entry
*fe
;
20069 if (cu
->line_header
!= NULL
)
20070 fe
= cu
->line_header
->file_name_at (file_index
);
20075 complaint (_("file index out of range"));
20077 symbol_set_symtab (sym
, fe
->symtab
);
20083 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
20084 if (attr
!= nullptr)
20088 addr
= attr
->value_as_address ();
20089 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
20090 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
20092 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
20093 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
20094 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
20095 add_symbol_to_list (sym
, cu
->list_in_scope
);
20097 case DW_TAG_subprogram
:
20098 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20100 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20101 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20102 if ((attr2
&& (DW_UNSND (attr2
) != 0))
20103 || cu
->language
== language_ada
20104 || cu
->language
== language_fortran
)
20106 /* Subprograms marked external are stored as a global symbol.
20107 Ada and Fortran subprograms, whether marked external or
20108 not, are always stored as a global symbol, because we want
20109 to be able to access them globally. For instance, we want
20110 to be able to break on a nested subprogram without having
20111 to specify the context. */
20112 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20116 list_to_add
= cu
->list_in_scope
;
20119 case DW_TAG_inlined_subroutine
:
20120 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
20122 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
20123 SYMBOL_INLINED (sym
) = 1;
20124 list_to_add
= cu
->list_in_scope
;
20126 case DW_TAG_template_value_param
:
20128 /* Fall through. */
20129 case DW_TAG_constant
:
20130 case DW_TAG_variable
:
20131 case DW_TAG_member
:
20132 /* Compilation with minimal debug info may result in
20133 variables with missing type entries. Change the
20134 misleading `void' type to something sensible. */
20135 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
20136 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
20138 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20139 /* In the case of DW_TAG_member, we should only be called for
20140 static const members. */
20141 if (die
->tag
== DW_TAG_member
)
20143 /* dwarf2_add_field uses die_is_declaration,
20144 so we do the same. */
20145 gdb_assert (die_is_declaration (die
, cu
));
20148 if (attr
!= nullptr)
20150 dwarf2_const_value (attr
, sym
, cu
);
20151 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20154 if (attr2
&& (DW_UNSND (attr2
) != 0))
20155 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20157 list_to_add
= cu
->list_in_scope
;
20161 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20162 if (attr
!= nullptr)
20164 var_decode_location (attr
, sym
, cu
);
20165 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20167 /* Fortran explicitly imports any global symbols to the local
20168 scope by DW_TAG_common_block. */
20169 if (cu
->language
== language_fortran
&& die
->parent
20170 && die
->parent
->tag
== DW_TAG_common_block
)
20173 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20174 && SYMBOL_VALUE_ADDRESS (sym
) == 0
20175 && !dwarf2_per_objfile
->has_section_at_zero
)
20177 /* When a static variable is eliminated by the linker,
20178 the corresponding debug information is not stripped
20179 out, but the variable address is set to null;
20180 do not add such variables into symbol table. */
20182 else if (attr2
&& (DW_UNSND (attr2
) != 0))
20184 if (SYMBOL_CLASS (sym
) == LOC_STATIC
20185 && (objfile
->flags
& OBJF_MAINLINE
) == 0
20186 && dwarf2_per_objfile
->can_copy
)
20188 /* A global static variable might be subject to
20189 copy relocation. We first check for a local
20190 minsym, though, because maybe the symbol was
20191 marked hidden, in which case this would not
20193 bound_minimal_symbol found
20194 = (lookup_minimal_symbol_linkage
20195 (sym
->linkage_name (), objfile
));
20196 if (found
.minsym
!= nullptr)
20197 sym
->maybe_copied
= 1;
20200 /* A variable with DW_AT_external is never static,
20201 but it may be block-scoped. */
20203 = ((cu
->list_in_scope
20204 == cu
->get_builder ()->get_file_symbols ())
20205 ? cu
->get_builder ()->get_global_symbols ()
20206 : cu
->list_in_scope
);
20209 list_to_add
= cu
->list_in_scope
;
20213 /* We do not know the address of this symbol.
20214 If it is an external symbol and we have type information
20215 for it, enter the symbol as a LOC_UNRESOLVED symbol.
20216 The address of the variable will then be determined from
20217 the minimal symbol table whenever the variable is
20219 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
20221 /* Fortran explicitly imports any global symbols to the local
20222 scope by DW_TAG_common_block. */
20223 if (cu
->language
== language_fortran
&& die
->parent
20224 && die
->parent
->tag
== DW_TAG_common_block
)
20226 /* SYMBOL_CLASS doesn't matter here because
20227 read_common_block is going to reset it. */
20229 list_to_add
= cu
->list_in_scope
;
20231 else if (attr2
&& (DW_UNSND (attr2
) != 0)
20232 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
20234 /* A variable with DW_AT_external is never static, but it
20235 may be block-scoped. */
20237 = ((cu
->list_in_scope
20238 == cu
->get_builder ()->get_file_symbols ())
20239 ? cu
->get_builder ()->get_global_symbols ()
20240 : cu
->list_in_scope
);
20242 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
20244 else if (!die_is_declaration (die
, cu
))
20246 /* Use the default LOC_OPTIMIZED_OUT class. */
20247 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
20249 list_to_add
= cu
->list_in_scope
;
20253 case DW_TAG_formal_parameter
:
20255 /* If we are inside a function, mark this as an argument. If
20256 not, we might be looking at an argument to an inlined function
20257 when we do not have enough information to show inlined frames;
20258 pretend it's a local variable in that case so that the user can
20260 struct context_stack
*curr
20261 = cu
->get_builder ()->get_current_context_stack ();
20262 if (curr
!= nullptr && curr
->name
!= nullptr)
20263 SYMBOL_IS_ARGUMENT (sym
) = 1;
20264 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
20265 if (attr
!= nullptr)
20267 var_decode_location (attr
, sym
, cu
);
20269 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20270 if (attr
!= nullptr)
20272 dwarf2_const_value (attr
, sym
, cu
);
20275 list_to_add
= cu
->list_in_scope
;
20278 case DW_TAG_unspecified_parameters
:
20279 /* From varargs functions; gdb doesn't seem to have any
20280 interest in this information, so just ignore it for now.
20283 case DW_TAG_template_type_param
:
20285 /* Fall through. */
20286 case DW_TAG_class_type
:
20287 case DW_TAG_interface_type
:
20288 case DW_TAG_structure_type
:
20289 case DW_TAG_union_type
:
20290 case DW_TAG_set_type
:
20291 case DW_TAG_enumeration_type
:
20292 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20293 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
20296 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
20297 really ever be static objects: otherwise, if you try
20298 to, say, break of a class's method and you're in a file
20299 which doesn't mention that class, it won't work unless
20300 the check for all static symbols in lookup_symbol_aux
20301 saves you. See the OtherFileClass tests in
20302 gdb.c++/namespace.exp. */
20306 buildsym_compunit
*builder
= cu
->get_builder ();
20308 = (cu
->list_in_scope
== builder
->get_file_symbols ()
20309 && cu
->language
== language_cplus
20310 ? builder
->get_global_symbols ()
20311 : cu
->list_in_scope
);
20313 /* The semantics of C++ state that "struct foo {
20314 ... }" also defines a typedef for "foo". */
20315 if (cu
->language
== language_cplus
20316 || cu
->language
== language_ada
20317 || cu
->language
== language_d
20318 || cu
->language
== language_rust
)
20320 /* The symbol's name is already allocated along
20321 with this objfile, so we don't need to
20322 duplicate it for the type. */
20323 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
20324 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
20329 case DW_TAG_typedef
:
20330 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20331 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20332 list_to_add
= cu
->list_in_scope
;
20334 case DW_TAG_base_type
:
20335 case DW_TAG_subrange_type
:
20336 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20337 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
20338 list_to_add
= cu
->list_in_scope
;
20340 case DW_TAG_enumerator
:
20341 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
20342 if (attr
!= nullptr)
20344 dwarf2_const_value (attr
, sym
, cu
);
20347 /* NOTE: carlton/2003-11-10: See comment above in the
20348 DW_TAG_class_type, etc. block. */
20351 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
20352 && cu
->language
== language_cplus
20353 ? cu
->get_builder ()->get_global_symbols ()
20354 : cu
->list_in_scope
);
20357 case DW_TAG_imported_declaration
:
20358 case DW_TAG_namespace
:
20359 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20360 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20362 case DW_TAG_module
:
20363 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
20364 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
20365 list_to_add
= cu
->get_builder ()->get_global_symbols ();
20367 case DW_TAG_common_block
:
20368 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
20369 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
20370 add_symbol_to_list (sym
, cu
->list_in_scope
);
20373 /* Not a tag we recognize. Hopefully we aren't processing
20374 trash data, but since we must specifically ignore things
20375 we don't recognize, there is nothing else we should do at
20377 complaint (_("unsupported tag: '%s'"),
20378 dwarf_tag_name (die
->tag
));
20384 sym
->hash_next
= objfile
->template_symbols
;
20385 objfile
->template_symbols
= sym
;
20386 list_to_add
= NULL
;
20389 if (list_to_add
!= NULL
)
20390 add_symbol_to_list (sym
, list_to_add
);
20392 /* For the benefit of old versions of GCC, check for anonymous
20393 namespaces based on the demangled name. */
20394 if (!cu
->processing_has_namespace_info
20395 && cu
->language
== language_cplus
)
20396 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
20401 /* Given an attr with a DW_FORM_dataN value in host byte order,
20402 zero-extend it as appropriate for the symbol's type. The DWARF
20403 standard (v4) is not entirely clear about the meaning of using
20404 DW_FORM_dataN for a constant with a signed type, where the type is
20405 wider than the data. The conclusion of a discussion on the DWARF
20406 list was that this is unspecified. We choose to always zero-extend
20407 because that is the interpretation long in use by GCC. */
20410 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
20411 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
20413 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20414 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
20415 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
20416 LONGEST l
= DW_UNSND (attr
);
20418 if (bits
< sizeof (*value
) * 8)
20420 l
&= ((LONGEST
) 1 << bits
) - 1;
20423 else if (bits
== sizeof (*value
) * 8)
20427 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
20428 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
20435 /* Read a constant value from an attribute. Either set *VALUE, or if
20436 the value does not fit in *VALUE, set *BYTES - either already
20437 allocated on the objfile obstack, or newly allocated on OBSTACK,
20438 or, set *BATON, if we translated the constant to a location
20442 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
20443 const char *name
, struct obstack
*obstack
,
20444 struct dwarf2_cu
*cu
,
20445 LONGEST
*value
, const gdb_byte
**bytes
,
20446 struct dwarf2_locexpr_baton
**baton
)
20448 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20449 struct comp_unit_head
*cu_header
= &cu
->header
;
20450 struct dwarf_block
*blk
;
20451 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
20452 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
20458 switch (attr
->form
)
20461 case DW_FORM_addrx
:
20462 case DW_FORM_GNU_addr_index
:
20466 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
20467 dwarf2_const_value_length_mismatch_complaint (name
,
20468 cu_header
->addr_size
,
20469 TYPE_LENGTH (type
));
20470 /* Symbols of this form are reasonably rare, so we just
20471 piggyback on the existing location code rather than writing
20472 a new implementation of symbol_computed_ops. */
20473 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
20474 (*baton
)->per_cu
= cu
->per_cu
;
20475 gdb_assert ((*baton
)->per_cu
);
20477 (*baton
)->size
= 2 + cu_header
->addr_size
;
20478 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
20479 (*baton
)->data
= data
;
20481 data
[0] = DW_OP_addr
;
20482 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
20483 byte_order
, DW_ADDR (attr
));
20484 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
20487 case DW_FORM_string
:
20490 case DW_FORM_GNU_str_index
:
20491 case DW_FORM_GNU_strp_alt
:
20492 /* DW_STRING is already allocated on the objfile obstack, point
20494 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
20496 case DW_FORM_block1
:
20497 case DW_FORM_block2
:
20498 case DW_FORM_block4
:
20499 case DW_FORM_block
:
20500 case DW_FORM_exprloc
:
20501 case DW_FORM_data16
:
20502 blk
= DW_BLOCK (attr
);
20503 if (TYPE_LENGTH (type
) != blk
->size
)
20504 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
20505 TYPE_LENGTH (type
));
20506 *bytes
= blk
->data
;
20509 /* The DW_AT_const_value attributes are supposed to carry the
20510 symbol's value "represented as it would be on the target
20511 architecture." By the time we get here, it's already been
20512 converted to host endianness, so we just need to sign- or
20513 zero-extend it as appropriate. */
20514 case DW_FORM_data1
:
20515 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
20517 case DW_FORM_data2
:
20518 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
20520 case DW_FORM_data4
:
20521 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
20523 case DW_FORM_data8
:
20524 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
20527 case DW_FORM_sdata
:
20528 case DW_FORM_implicit_const
:
20529 *value
= DW_SND (attr
);
20532 case DW_FORM_udata
:
20533 *value
= DW_UNSND (attr
);
20537 complaint (_("unsupported const value attribute form: '%s'"),
20538 dwarf_form_name (attr
->form
));
20545 /* Copy constant value from an attribute to a symbol. */
20548 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
20549 struct dwarf2_cu
*cu
)
20551 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20553 const gdb_byte
*bytes
;
20554 struct dwarf2_locexpr_baton
*baton
;
20556 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
20557 sym
->print_name (),
20558 &objfile
->objfile_obstack
, cu
,
20559 &value
, &bytes
, &baton
);
20563 SYMBOL_LOCATION_BATON (sym
) = baton
;
20564 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
20566 else if (bytes
!= NULL
)
20568 SYMBOL_VALUE_BYTES (sym
) = bytes
;
20569 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
20573 SYMBOL_VALUE (sym
) = value
;
20574 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
20578 /* Return the type of the die in question using its DW_AT_type attribute. */
20580 static struct type
*
20581 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20583 struct attribute
*type_attr
;
20585 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
20588 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20589 /* A missing DW_AT_type represents a void type. */
20590 return objfile_type (objfile
)->builtin_void
;
20593 return lookup_die_type (die
, type_attr
, cu
);
20596 /* True iff CU's producer generates GNAT Ada auxiliary information
20597 that allows to find parallel types through that information instead
20598 of having to do expensive parallel lookups by type name. */
20601 need_gnat_info (struct dwarf2_cu
*cu
)
20603 /* Assume that the Ada compiler was GNAT, which always produces
20604 the auxiliary information. */
20605 return (cu
->language
== language_ada
);
20608 /* Return the auxiliary type of the die in question using its
20609 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
20610 attribute is not present. */
20612 static struct type
*
20613 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20615 struct attribute
*type_attr
;
20617 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
20621 return lookup_die_type (die
, type_attr
, cu
);
20624 /* If DIE has a descriptive_type attribute, then set the TYPE's
20625 descriptive type accordingly. */
20628 set_descriptive_type (struct type
*type
, struct die_info
*die
,
20629 struct dwarf2_cu
*cu
)
20631 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
20633 if (descriptive_type
)
20635 ALLOCATE_GNAT_AUX_TYPE (type
);
20636 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
20640 /* Return the containing type of the die in question using its
20641 DW_AT_containing_type attribute. */
20643 static struct type
*
20644 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
20646 struct attribute
*type_attr
;
20647 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20649 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
20651 error (_("Dwarf Error: Problem turning containing type into gdb type "
20652 "[in module %s]"), objfile_name (objfile
));
20654 return lookup_die_type (die
, type_attr
, cu
);
20657 /* Return an error marker type to use for the ill formed type in DIE/CU. */
20659 static struct type
*
20660 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
20662 struct dwarf2_per_objfile
*dwarf2_per_objfile
20663 = cu
->per_cu
->dwarf2_per_objfile
;
20664 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20667 std::string message
20668 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
20669 objfile_name (objfile
),
20670 sect_offset_str (cu
->header
.sect_off
),
20671 sect_offset_str (die
->sect_off
));
20672 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
20674 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
20677 /* Look up the type of DIE in CU using its type attribute ATTR.
20678 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
20679 DW_AT_containing_type.
20680 If there is no type substitute an error marker. */
20682 static struct type
*
20683 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
20684 struct dwarf2_cu
*cu
)
20686 struct dwarf2_per_objfile
*dwarf2_per_objfile
20687 = cu
->per_cu
->dwarf2_per_objfile
;
20688 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20689 struct type
*this_type
;
20691 gdb_assert (attr
->name
== DW_AT_type
20692 || attr
->name
== DW_AT_GNAT_descriptive_type
20693 || attr
->name
== DW_AT_containing_type
);
20695 /* First see if we have it cached. */
20697 if (attr
->form
== DW_FORM_GNU_ref_alt
)
20699 struct dwarf2_per_cu_data
*per_cu
;
20700 sect_offset sect_off
= attr
->get_ref_die_offset ();
20702 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
20703 dwarf2_per_objfile
);
20704 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
20706 else if (attr
->form_is_ref ())
20708 sect_offset sect_off
= attr
->get_ref_die_offset ();
20710 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
20712 else if (attr
->form
== DW_FORM_ref_sig8
)
20714 ULONGEST signature
= DW_SIGNATURE (attr
);
20716 return get_signatured_type (die
, signature
, cu
);
20720 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
20721 " at %s [in module %s]"),
20722 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
20723 objfile_name (objfile
));
20724 return build_error_marker_type (cu
, die
);
20727 /* If not cached we need to read it in. */
20729 if (this_type
== NULL
)
20731 struct die_info
*type_die
= NULL
;
20732 struct dwarf2_cu
*type_cu
= cu
;
20734 if (attr
->form_is_ref ())
20735 type_die
= follow_die_ref (die
, attr
, &type_cu
);
20736 if (type_die
== NULL
)
20737 return build_error_marker_type (cu
, die
);
20738 /* If we find the type now, it's probably because the type came
20739 from an inter-CU reference and the type's CU got expanded before
20741 this_type
= read_type_die (type_die
, type_cu
);
20744 /* If we still don't have a type use an error marker. */
20746 if (this_type
== NULL
)
20747 return build_error_marker_type (cu
, die
);
20752 /* Return the type in DIE, CU.
20753 Returns NULL for invalid types.
20755 This first does a lookup in die_type_hash,
20756 and only reads the die in if necessary.
20758 NOTE: This can be called when reading in partial or full symbols. */
20760 static struct type
*
20761 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
20763 struct type
*this_type
;
20765 this_type
= get_die_type (die
, cu
);
20769 return read_type_die_1 (die
, cu
);
20772 /* Read the type in DIE, CU.
20773 Returns NULL for invalid types. */
20775 static struct type
*
20776 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
20778 struct type
*this_type
= NULL
;
20782 case DW_TAG_class_type
:
20783 case DW_TAG_interface_type
:
20784 case DW_TAG_structure_type
:
20785 case DW_TAG_union_type
:
20786 this_type
= read_structure_type (die
, cu
);
20788 case DW_TAG_enumeration_type
:
20789 this_type
= read_enumeration_type (die
, cu
);
20791 case DW_TAG_subprogram
:
20792 case DW_TAG_subroutine_type
:
20793 case DW_TAG_inlined_subroutine
:
20794 this_type
= read_subroutine_type (die
, cu
);
20796 case DW_TAG_array_type
:
20797 this_type
= read_array_type (die
, cu
);
20799 case DW_TAG_set_type
:
20800 this_type
= read_set_type (die
, cu
);
20802 case DW_TAG_pointer_type
:
20803 this_type
= read_tag_pointer_type (die
, cu
);
20805 case DW_TAG_ptr_to_member_type
:
20806 this_type
= read_tag_ptr_to_member_type (die
, cu
);
20808 case DW_TAG_reference_type
:
20809 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
20811 case DW_TAG_rvalue_reference_type
:
20812 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
20814 case DW_TAG_const_type
:
20815 this_type
= read_tag_const_type (die
, cu
);
20817 case DW_TAG_volatile_type
:
20818 this_type
= read_tag_volatile_type (die
, cu
);
20820 case DW_TAG_restrict_type
:
20821 this_type
= read_tag_restrict_type (die
, cu
);
20823 case DW_TAG_string_type
:
20824 this_type
= read_tag_string_type (die
, cu
);
20826 case DW_TAG_typedef
:
20827 this_type
= read_typedef (die
, cu
);
20829 case DW_TAG_subrange_type
:
20830 this_type
= read_subrange_type (die
, cu
);
20832 case DW_TAG_base_type
:
20833 this_type
= read_base_type (die
, cu
);
20835 case DW_TAG_unspecified_type
:
20836 this_type
= read_unspecified_type (die
, cu
);
20838 case DW_TAG_namespace
:
20839 this_type
= read_namespace_type (die
, cu
);
20841 case DW_TAG_module
:
20842 this_type
= read_module_type (die
, cu
);
20844 case DW_TAG_atomic_type
:
20845 this_type
= read_tag_atomic_type (die
, cu
);
20848 complaint (_("unexpected tag in read_type_die: '%s'"),
20849 dwarf_tag_name (die
->tag
));
20856 /* See if we can figure out if the class lives in a namespace. We do
20857 this by looking for a member function; its demangled name will
20858 contain namespace info, if there is any.
20859 Return the computed name or NULL.
20860 Space for the result is allocated on the objfile's obstack.
20861 This is the full-die version of guess_partial_die_structure_name.
20862 In this case we know DIE has no useful parent. */
20864 static const char *
20865 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20867 struct die_info
*spec_die
;
20868 struct dwarf2_cu
*spec_cu
;
20869 struct die_info
*child
;
20870 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20873 spec_die
= die_specification (die
, &spec_cu
);
20874 if (spec_die
!= NULL
)
20880 for (child
= die
->child
;
20882 child
= child
->sibling
)
20884 if (child
->tag
== DW_TAG_subprogram
)
20886 const char *linkage_name
= dw2_linkage_name (child
, cu
);
20888 if (linkage_name
!= NULL
)
20890 gdb::unique_xmalloc_ptr
<char> actual_name
20891 (language_class_name_from_physname (cu
->language_defn
,
20893 const char *name
= NULL
;
20895 if (actual_name
!= NULL
)
20897 const char *die_name
= dwarf2_name (die
, cu
);
20899 if (die_name
!= NULL
20900 && strcmp (die_name
, actual_name
.get ()) != 0)
20902 /* Strip off the class name from the full name.
20903 We want the prefix. */
20904 int die_name_len
= strlen (die_name
);
20905 int actual_name_len
= strlen (actual_name
.get ());
20906 const char *ptr
= actual_name
.get ();
20908 /* Test for '::' as a sanity check. */
20909 if (actual_name_len
> die_name_len
+ 2
20910 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
20911 name
= obstack_strndup (
20912 &objfile
->per_bfd
->storage_obstack
,
20913 ptr
, actual_name_len
- die_name_len
- 2);
20924 /* GCC might emit a nameless typedef that has a linkage name. Determine the
20925 prefix part in such case. See
20926 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
20928 static const char *
20929 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20931 struct attribute
*attr
;
20934 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
20935 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
20938 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
20941 attr
= dw2_linkage_name_attr (die
, cu
);
20942 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
20945 /* dwarf2_name had to be already called. */
20946 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
20948 /* Strip the base name, keep any leading namespaces/classes. */
20949 base
= strrchr (DW_STRING (attr
), ':');
20950 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
20953 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20954 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
20956 &base
[-1] - DW_STRING (attr
));
20959 /* Return the name of the namespace/class that DIE is defined within,
20960 or "" if we can't tell. The caller should not xfree the result.
20962 For example, if we're within the method foo() in the following
20972 then determine_prefix on foo's die will return "N::C". */
20974 static const char *
20975 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
20977 struct dwarf2_per_objfile
*dwarf2_per_objfile
20978 = cu
->per_cu
->dwarf2_per_objfile
;
20979 struct die_info
*parent
, *spec_die
;
20980 struct dwarf2_cu
*spec_cu
;
20981 struct type
*parent_type
;
20982 const char *retval
;
20984 if (cu
->language
!= language_cplus
20985 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
20986 && cu
->language
!= language_rust
)
20989 retval
= anonymous_struct_prefix (die
, cu
);
20993 /* We have to be careful in the presence of DW_AT_specification.
20994 For example, with GCC 3.4, given the code
20998 // Definition of N::foo.
21002 then we'll have a tree of DIEs like this:
21004 1: DW_TAG_compile_unit
21005 2: DW_TAG_namespace // N
21006 3: DW_TAG_subprogram // declaration of N::foo
21007 4: DW_TAG_subprogram // definition of N::foo
21008 DW_AT_specification // refers to die #3
21010 Thus, when processing die #4, we have to pretend that we're in
21011 the context of its DW_AT_specification, namely the contex of die
21014 spec_die
= die_specification (die
, &spec_cu
);
21015 if (spec_die
== NULL
)
21016 parent
= die
->parent
;
21019 parent
= spec_die
->parent
;
21023 if (parent
== NULL
)
21025 else if (parent
->building_fullname
)
21028 const char *parent_name
;
21030 /* It has been seen on RealView 2.2 built binaries,
21031 DW_TAG_template_type_param types actually _defined_ as
21032 children of the parent class:
21035 template class <class Enum> Class{};
21036 Class<enum E> class_e;
21038 1: DW_TAG_class_type (Class)
21039 2: DW_TAG_enumeration_type (E)
21040 3: DW_TAG_enumerator (enum1:0)
21041 3: DW_TAG_enumerator (enum2:1)
21043 2: DW_TAG_template_type_param
21044 DW_AT_type DW_FORM_ref_udata (E)
21046 Besides being broken debug info, it can put GDB into an
21047 infinite loop. Consider:
21049 When we're building the full name for Class<E>, we'll start
21050 at Class, and go look over its template type parameters,
21051 finding E. We'll then try to build the full name of E, and
21052 reach here. We're now trying to build the full name of E,
21053 and look over the parent DIE for containing scope. In the
21054 broken case, if we followed the parent DIE of E, we'd again
21055 find Class, and once again go look at its template type
21056 arguments, etc., etc. Simply don't consider such parent die
21057 as source-level parent of this die (it can't be, the language
21058 doesn't allow it), and break the loop here. */
21059 name
= dwarf2_name (die
, cu
);
21060 parent_name
= dwarf2_name (parent
, cu
);
21061 complaint (_("template param type '%s' defined within parent '%s'"),
21062 name
? name
: "<unknown>",
21063 parent_name
? parent_name
: "<unknown>");
21067 switch (parent
->tag
)
21069 case DW_TAG_namespace
:
21070 parent_type
= read_type_die (parent
, cu
);
21071 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
21072 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
21073 Work around this problem here. */
21074 if (cu
->language
== language_cplus
21075 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
21077 /* We give a name to even anonymous namespaces. */
21078 return TYPE_NAME (parent_type
);
21079 case DW_TAG_class_type
:
21080 case DW_TAG_interface_type
:
21081 case DW_TAG_structure_type
:
21082 case DW_TAG_union_type
:
21083 case DW_TAG_module
:
21084 parent_type
= read_type_die (parent
, cu
);
21085 if (TYPE_NAME (parent_type
) != NULL
)
21086 return TYPE_NAME (parent_type
);
21088 /* An anonymous structure is only allowed non-static data
21089 members; no typedefs, no member functions, et cetera.
21090 So it does not need a prefix. */
21092 case DW_TAG_compile_unit
:
21093 case DW_TAG_partial_unit
:
21094 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
21095 if (cu
->language
== language_cplus
21096 && !dwarf2_per_objfile
->types
.empty ()
21097 && die
->child
!= NULL
21098 && (die
->tag
== DW_TAG_class_type
21099 || die
->tag
== DW_TAG_structure_type
21100 || die
->tag
== DW_TAG_union_type
))
21102 const char *name
= guess_full_die_structure_name (die
, cu
);
21107 case DW_TAG_subprogram
:
21108 /* Nested subroutines in Fortran get a prefix with the name
21109 of the parent's subroutine. */
21110 if (cu
->language
== language_fortran
)
21112 if ((die
->tag
== DW_TAG_subprogram
)
21113 && (dwarf2_name (parent
, cu
) != NULL
))
21114 return dwarf2_name (parent
, cu
);
21116 return determine_prefix (parent
, cu
);
21117 case DW_TAG_enumeration_type
:
21118 parent_type
= read_type_die (parent
, cu
);
21119 if (TYPE_DECLARED_CLASS (parent_type
))
21121 if (TYPE_NAME (parent_type
) != NULL
)
21122 return TYPE_NAME (parent_type
);
21125 /* Fall through. */
21127 return determine_prefix (parent
, cu
);
21131 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
21132 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
21133 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
21134 an obconcat, otherwise allocate storage for the result. The CU argument is
21135 used to determine the language and hence, the appropriate separator. */
21137 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
21140 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
21141 int physname
, struct dwarf2_cu
*cu
)
21143 const char *lead
= "";
21146 if (suffix
== NULL
|| suffix
[0] == '\0'
21147 || prefix
== NULL
|| prefix
[0] == '\0')
21149 else if (cu
->language
== language_d
)
21151 /* For D, the 'main' function could be defined in any module, but it
21152 should never be prefixed. */
21153 if (strcmp (suffix
, "D main") == 0)
21161 else if (cu
->language
== language_fortran
&& physname
)
21163 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
21164 DW_AT_MIPS_linkage_name is preferred and used instead. */
21172 if (prefix
== NULL
)
21174 if (suffix
== NULL
)
21181 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
21183 strcpy (retval
, lead
);
21184 strcat (retval
, prefix
);
21185 strcat (retval
, sep
);
21186 strcat (retval
, suffix
);
21191 /* We have an obstack. */
21192 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
21196 /* Get name of a die, return NULL if not found. */
21198 static const char *
21199 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
21200 struct objfile
*objfile
)
21202 if (name
&& cu
->language
== language_cplus
)
21204 std::string canon_name
= cp_canonicalize_string (name
);
21206 if (!canon_name
.empty ())
21208 if (canon_name
!= name
)
21209 name
= objfile
->intern (canon_name
);
21216 /* Get name of a die, return NULL if not found.
21217 Anonymous namespaces are converted to their magic string. */
21219 static const char *
21220 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
21222 struct attribute
*attr
;
21223 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21225 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
21226 if ((!attr
|| !DW_STRING (attr
))
21227 && die
->tag
!= DW_TAG_namespace
21228 && die
->tag
!= DW_TAG_class_type
21229 && die
->tag
!= DW_TAG_interface_type
21230 && die
->tag
!= DW_TAG_structure_type
21231 && die
->tag
!= DW_TAG_union_type
)
21236 case DW_TAG_compile_unit
:
21237 case DW_TAG_partial_unit
:
21238 /* Compilation units have a DW_AT_name that is a filename, not
21239 a source language identifier. */
21240 case DW_TAG_enumeration_type
:
21241 case DW_TAG_enumerator
:
21242 /* These tags always have simple identifiers already; no need
21243 to canonicalize them. */
21244 return DW_STRING (attr
);
21246 case DW_TAG_namespace
:
21247 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
21248 return DW_STRING (attr
);
21249 return CP_ANONYMOUS_NAMESPACE_STR
;
21251 case DW_TAG_class_type
:
21252 case DW_TAG_interface_type
:
21253 case DW_TAG_structure_type
:
21254 case DW_TAG_union_type
:
21255 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
21256 structures or unions. These were of the form "._%d" in GCC 4.1,
21257 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
21258 and GCC 4.4. We work around this problem by ignoring these. */
21259 if (attr
&& DW_STRING (attr
)
21260 && (startswith (DW_STRING (attr
), "._")
21261 || startswith (DW_STRING (attr
), "<anonymous")))
21264 /* GCC might emit a nameless typedef that has a linkage name. See
21265 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
21266 if (!attr
|| DW_STRING (attr
) == NULL
)
21268 attr
= dw2_linkage_name_attr (die
, cu
);
21269 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
21272 /* Avoid demangling DW_STRING (attr) the second time on a second
21273 call for the same DIE. */
21274 if (!DW_STRING_IS_CANONICAL (attr
))
21276 gdb::unique_xmalloc_ptr
<char> demangled
21277 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
21278 if (demangled
== nullptr)
21281 DW_STRING (attr
) = objfile
->intern (demangled
.get ());
21282 DW_STRING_IS_CANONICAL (attr
) = 1;
21285 /* Strip any leading namespaces/classes, keep only the base name.
21286 DW_AT_name for named DIEs does not contain the prefixes. */
21287 const char *base
= strrchr (DW_STRING (attr
), ':');
21288 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
21291 return DW_STRING (attr
);
21299 if (!DW_STRING_IS_CANONICAL (attr
))
21301 DW_STRING (attr
) = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
21303 DW_STRING_IS_CANONICAL (attr
) = 1;
21305 return DW_STRING (attr
);
21308 /* Return the die that this die in an extension of, or NULL if there
21309 is none. *EXT_CU is the CU containing DIE on input, and the CU
21310 containing the return value on output. */
21312 static struct die_info
*
21313 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
21315 struct attribute
*attr
;
21317 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
21321 return follow_die_ref (die
, attr
, ext_cu
);
21325 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
21329 print_spaces (indent
, f
);
21330 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
21331 dwarf_tag_name (die
->tag
), die
->abbrev
,
21332 sect_offset_str (die
->sect_off
));
21334 if (die
->parent
!= NULL
)
21336 print_spaces (indent
, f
);
21337 fprintf_unfiltered (f
, " parent at offset: %s\n",
21338 sect_offset_str (die
->parent
->sect_off
));
21341 print_spaces (indent
, f
);
21342 fprintf_unfiltered (f
, " has children: %s\n",
21343 dwarf_bool_name (die
->child
!= NULL
));
21345 print_spaces (indent
, f
);
21346 fprintf_unfiltered (f
, " attributes:\n");
21348 for (i
= 0; i
< die
->num_attrs
; ++i
)
21350 print_spaces (indent
, f
);
21351 fprintf_unfiltered (f
, " %s (%s) ",
21352 dwarf_attr_name (die
->attrs
[i
].name
),
21353 dwarf_form_name (die
->attrs
[i
].form
));
21355 switch (die
->attrs
[i
].form
)
21358 case DW_FORM_addrx
:
21359 case DW_FORM_GNU_addr_index
:
21360 fprintf_unfiltered (f
, "address: ");
21361 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
21363 case DW_FORM_block2
:
21364 case DW_FORM_block4
:
21365 case DW_FORM_block
:
21366 case DW_FORM_block1
:
21367 fprintf_unfiltered (f
, "block: size %s",
21368 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21370 case DW_FORM_exprloc
:
21371 fprintf_unfiltered (f
, "expression: size %s",
21372 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
21374 case DW_FORM_data16
:
21375 fprintf_unfiltered (f
, "constant of 16 bytes");
21377 case DW_FORM_ref_addr
:
21378 fprintf_unfiltered (f
, "ref address: ");
21379 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21381 case DW_FORM_GNU_ref_alt
:
21382 fprintf_unfiltered (f
, "alt ref address: ");
21383 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
21389 case DW_FORM_ref_udata
:
21390 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
21391 (long) (DW_UNSND (&die
->attrs
[i
])));
21393 case DW_FORM_data1
:
21394 case DW_FORM_data2
:
21395 case DW_FORM_data4
:
21396 case DW_FORM_data8
:
21397 case DW_FORM_udata
:
21398 case DW_FORM_sdata
:
21399 fprintf_unfiltered (f
, "constant: %s",
21400 pulongest (DW_UNSND (&die
->attrs
[i
])));
21402 case DW_FORM_sec_offset
:
21403 fprintf_unfiltered (f
, "section offset: %s",
21404 pulongest (DW_UNSND (&die
->attrs
[i
])));
21406 case DW_FORM_ref_sig8
:
21407 fprintf_unfiltered (f
, "signature: %s",
21408 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
21410 case DW_FORM_string
:
21412 case DW_FORM_line_strp
:
21414 case DW_FORM_GNU_str_index
:
21415 case DW_FORM_GNU_strp_alt
:
21416 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
21417 DW_STRING (&die
->attrs
[i
])
21418 ? DW_STRING (&die
->attrs
[i
]) : "",
21419 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
21422 if (DW_UNSND (&die
->attrs
[i
]))
21423 fprintf_unfiltered (f
, "flag: TRUE");
21425 fprintf_unfiltered (f
, "flag: FALSE");
21427 case DW_FORM_flag_present
:
21428 fprintf_unfiltered (f
, "flag: TRUE");
21430 case DW_FORM_indirect
:
21431 /* The reader will have reduced the indirect form to
21432 the "base form" so this form should not occur. */
21433 fprintf_unfiltered (f
,
21434 "unexpected attribute form: DW_FORM_indirect");
21436 case DW_FORM_implicit_const
:
21437 fprintf_unfiltered (f
, "constant: %s",
21438 plongest (DW_SND (&die
->attrs
[i
])));
21441 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
21442 die
->attrs
[i
].form
);
21445 fprintf_unfiltered (f
, "\n");
21450 dump_die_for_error (struct die_info
*die
)
21452 dump_die_shallow (gdb_stderr
, 0, die
);
21456 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
21458 int indent
= level
* 4;
21460 gdb_assert (die
!= NULL
);
21462 if (level
>= max_level
)
21465 dump_die_shallow (f
, indent
, die
);
21467 if (die
->child
!= NULL
)
21469 print_spaces (indent
, f
);
21470 fprintf_unfiltered (f
, " Children:");
21471 if (level
+ 1 < max_level
)
21473 fprintf_unfiltered (f
, "\n");
21474 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
21478 fprintf_unfiltered (f
,
21479 " [not printed, max nesting level reached]\n");
21483 if (die
->sibling
!= NULL
&& level
> 0)
21485 dump_die_1 (f
, level
, max_level
, die
->sibling
);
21489 /* This is called from the pdie macro in gdbinit.in.
21490 It's not static so gcc will keep a copy callable from gdb. */
21493 dump_die (struct die_info
*die
, int max_level
)
21495 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
21499 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
21503 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
21504 to_underlying (die
->sect_off
),
21510 /* Follow reference or signature attribute ATTR of SRC_DIE.
21511 On entry *REF_CU is the CU of SRC_DIE.
21512 On exit *REF_CU is the CU of the result. */
21514 static struct die_info
*
21515 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21516 struct dwarf2_cu
**ref_cu
)
21518 struct die_info
*die
;
21520 if (attr
->form_is_ref ())
21521 die
= follow_die_ref (src_die
, attr
, ref_cu
);
21522 else if (attr
->form
== DW_FORM_ref_sig8
)
21523 die
= follow_die_sig (src_die
, attr
, ref_cu
);
21526 dump_die_for_error (src_die
);
21527 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
21528 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21534 /* Follow reference OFFSET.
21535 On entry *REF_CU is the CU of the source die referencing OFFSET.
21536 On exit *REF_CU is the CU of the result.
21537 Returns NULL if OFFSET is invalid. */
21539 static struct die_info
*
21540 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
21541 struct dwarf2_cu
**ref_cu
)
21543 struct die_info temp_die
;
21544 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
21545 struct dwarf2_per_objfile
*dwarf2_per_objfile
21546 = cu
->per_cu
->dwarf2_per_objfile
;
21548 gdb_assert (cu
->per_cu
!= NULL
);
21552 if (cu
->per_cu
->is_debug_types
)
21554 /* .debug_types CUs cannot reference anything outside their CU.
21555 If they need to, they have to reference a signatured type via
21556 DW_FORM_ref_sig8. */
21557 if (!cu
->header
.offset_in_cu_p (sect_off
))
21560 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
21561 || !cu
->header
.offset_in_cu_p (sect_off
))
21563 struct dwarf2_per_cu_data
*per_cu
;
21565 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
21566 dwarf2_per_objfile
);
21568 /* If necessary, add it to the queue and load its DIEs. */
21569 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
21570 load_full_comp_unit (per_cu
, false, cu
->language
);
21572 target_cu
= per_cu
->cu
;
21574 else if (cu
->dies
== NULL
)
21576 /* We're loading full DIEs during partial symbol reading. */
21577 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
21578 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
21581 *ref_cu
= target_cu
;
21582 temp_die
.sect_off
= sect_off
;
21584 if (target_cu
!= cu
)
21585 target_cu
->ancestor
= cu
;
21587 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
21589 to_underlying (sect_off
));
21592 /* Follow reference attribute ATTR of SRC_DIE.
21593 On entry *REF_CU is the CU of SRC_DIE.
21594 On exit *REF_CU is the CU of the result. */
21596 static struct die_info
*
21597 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
21598 struct dwarf2_cu
**ref_cu
)
21600 sect_offset sect_off
= attr
->get_ref_die_offset ();
21601 struct dwarf2_cu
*cu
= *ref_cu
;
21602 struct die_info
*die
;
21604 die
= follow_die_offset (sect_off
,
21605 (attr
->form
== DW_FORM_GNU_ref_alt
21606 || cu
->per_cu
->is_dwz
),
21609 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
21610 "at %s [in module %s]"),
21611 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
21612 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
21619 struct dwarf2_locexpr_baton
21620 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
21621 dwarf2_per_cu_data
*per_cu
,
21622 CORE_ADDR (*get_frame_pc
) (void *baton
),
21623 void *baton
, bool resolve_abstract_p
)
21625 struct dwarf2_cu
*cu
;
21626 struct die_info
*die
;
21627 struct attribute
*attr
;
21628 struct dwarf2_locexpr_baton retval
;
21629 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
21630 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21632 if (per_cu
->cu
== NULL
)
21633 load_cu (per_cu
, false);
21637 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21638 Instead just throw an error, not much else we can do. */
21639 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21640 sect_offset_str (sect_off
), objfile_name (objfile
));
21643 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21645 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21646 sect_offset_str (sect_off
), objfile_name (objfile
));
21648 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21649 if (!attr
&& resolve_abstract_p
21650 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
21651 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
21653 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21654 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
21655 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21657 for (const auto &cand_off
21658 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
21660 struct dwarf2_cu
*cand_cu
= cu
;
21661 struct die_info
*cand
21662 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
21665 || cand
->parent
->tag
!= DW_TAG_subprogram
)
21668 CORE_ADDR pc_low
, pc_high
;
21669 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
21670 if (pc_low
== ((CORE_ADDR
) -1))
21672 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
21673 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
21674 if (!(pc_low
<= pc
&& pc
< pc_high
))
21678 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21685 /* DWARF: "If there is no such attribute, then there is no effect.".
21686 DATA is ignored if SIZE is 0. */
21688 retval
.data
= NULL
;
21691 else if (attr
->form_is_section_offset ())
21693 struct dwarf2_loclist_baton loclist_baton
;
21694 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
21697 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
21699 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
21701 retval
.size
= size
;
21705 if (!attr
->form_is_block ())
21706 error (_("Dwarf Error: DIE at %s referenced in module %s "
21707 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
21708 sect_offset_str (sect_off
), objfile_name (objfile
));
21710 retval
.data
= DW_BLOCK (attr
)->data
;
21711 retval
.size
= DW_BLOCK (attr
)->size
;
21713 retval
.per_cu
= cu
->per_cu
;
21715 age_cached_comp_units (dwarf2_per_objfile
);
21722 struct dwarf2_locexpr_baton
21723 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
21724 dwarf2_per_cu_data
*per_cu
,
21725 CORE_ADDR (*get_frame_pc
) (void *baton
),
21728 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
21730 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
21733 /* Write a constant of a given type as target-ordered bytes into
21736 static const gdb_byte
*
21737 write_constant_as_bytes (struct obstack
*obstack
,
21738 enum bfd_endian byte_order
,
21745 *len
= TYPE_LENGTH (type
);
21746 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21747 store_unsigned_integer (result
, *len
, byte_order
, value
);
21755 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
21756 dwarf2_per_cu_data
*per_cu
,
21760 struct dwarf2_cu
*cu
;
21761 struct die_info
*die
;
21762 struct attribute
*attr
;
21763 const gdb_byte
*result
= NULL
;
21766 enum bfd_endian byte_order
;
21767 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
21769 if (per_cu
->cu
== NULL
)
21770 load_cu (per_cu
, false);
21774 /* We shouldn't get here for a dummy CU, but don't crash on the user.
21775 Instead just throw an error, not much else we can do. */
21776 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
21777 sect_offset_str (sect_off
), objfile_name (objfile
));
21780 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21782 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
21783 sect_offset_str (sect_off
), objfile_name (objfile
));
21785 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21789 byte_order
= (bfd_big_endian (objfile
->obfd
)
21790 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21792 switch (attr
->form
)
21795 case DW_FORM_addrx
:
21796 case DW_FORM_GNU_addr_index
:
21800 *len
= cu
->header
.addr_size
;
21801 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
21802 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
21806 case DW_FORM_string
:
21809 case DW_FORM_GNU_str_index
:
21810 case DW_FORM_GNU_strp_alt
:
21811 /* DW_STRING is already allocated on the objfile obstack, point
21813 result
= (const gdb_byte
*) DW_STRING (attr
);
21814 *len
= strlen (DW_STRING (attr
));
21816 case DW_FORM_block1
:
21817 case DW_FORM_block2
:
21818 case DW_FORM_block4
:
21819 case DW_FORM_block
:
21820 case DW_FORM_exprloc
:
21821 case DW_FORM_data16
:
21822 result
= DW_BLOCK (attr
)->data
;
21823 *len
= DW_BLOCK (attr
)->size
;
21826 /* The DW_AT_const_value attributes are supposed to carry the
21827 symbol's value "represented as it would be on the target
21828 architecture." By the time we get here, it's already been
21829 converted to host endianness, so we just need to sign- or
21830 zero-extend it as appropriate. */
21831 case DW_FORM_data1
:
21832 type
= die_type (die
, cu
);
21833 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
21834 if (result
== NULL
)
21835 result
= write_constant_as_bytes (obstack
, byte_order
,
21838 case DW_FORM_data2
:
21839 type
= die_type (die
, cu
);
21840 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
21841 if (result
== NULL
)
21842 result
= write_constant_as_bytes (obstack
, byte_order
,
21845 case DW_FORM_data4
:
21846 type
= die_type (die
, cu
);
21847 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
21848 if (result
== NULL
)
21849 result
= write_constant_as_bytes (obstack
, byte_order
,
21852 case DW_FORM_data8
:
21853 type
= die_type (die
, cu
);
21854 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
21855 if (result
== NULL
)
21856 result
= write_constant_as_bytes (obstack
, byte_order
,
21860 case DW_FORM_sdata
:
21861 case DW_FORM_implicit_const
:
21862 type
= die_type (die
, cu
);
21863 result
= write_constant_as_bytes (obstack
, byte_order
,
21864 type
, DW_SND (attr
), len
);
21867 case DW_FORM_udata
:
21868 type
= die_type (die
, cu
);
21869 result
= write_constant_as_bytes (obstack
, byte_order
,
21870 type
, DW_UNSND (attr
), len
);
21874 complaint (_("unsupported const value attribute form: '%s'"),
21875 dwarf_form_name (attr
->form
));
21885 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
21886 dwarf2_per_cu_data
*per_cu
)
21888 struct dwarf2_cu
*cu
;
21889 struct die_info
*die
;
21891 if (per_cu
->cu
== NULL
)
21892 load_cu (per_cu
, false);
21897 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
21901 return die_type (die
, cu
);
21907 dwarf2_get_die_type (cu_offset die_offset
,
21908 struct dwarf2_per_cu_data
*per_cu
)
21910 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
21911 return get_die_type_at_offset (die_offset_sect
, per_cu
);
21914 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
21915 On entry *REF_CU is the CU of SRC_DIE.
21916 On exit *REF_CU is the CU of the result.
21917 Returns NULL if the referenced DIE isn't found. */
21919 static struct die_info
*
21920 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
21921 struct dwarf2_cu
**ref_cu
)
21923 struct die_info temp_die
;
21924 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
21925 struct die_info
*die
;
21927 /* While it might be nice to assert sig_type->type == NULL here,
21928 we can get here for DW_AT_imported_declaration where we need
21929 the DIE not the type. */
21931 /* If necessary, add it to the queue and load its DIEs. */
21933 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
21934 read_signatured_type (sig_type
);
21936 sig_cu
= sig_type
->per_cu
.cu
;
21937 gdb_assert (sig_cu
!= NULL
);
21938 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
21939 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
21940 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
21941 to_underlying (temp_die
.sect_off
));
21944 struct dwarf2_per_objfile
*dwarf2_per_objfile
21945 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
21947 /* For .gdb_index version 7 keep track of included TUs.
21948 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
21949 if (dwarf2_per_objfile
->index_table
!= NULL
21950 && dwarf2_per_objfile
->index_table
->version
<= 7)
21952 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
21957 sig_cu
->ancestor
= cu
;
21965 /* Follow signatured type referenced by ATTR in SRC_DIE.
21966 On entry *REF_CU is the CU of SRC_DIE.
21967 On exit *REF_CU is the CU of the result.
21968 The result is the DIE of the type.
21969 If the referenced type cannot be found an error is thrown. */
21971 static struct die_info
*
21972 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
21973 struct dwarf2_cu
**ref_cu
)
21975 ULONGEST signature
= DW_SIGNATURE (attr
);
21976 struct signatured_type
*sig_type
;
21977 struct die_info
*die
;
21979 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
21981 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
21982 /* sig_type will be NULL if the signatured type is missing from
21984 if (sig_type
== NULL
)
21986 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
21987 " from DIE at %s [in module %s]"),
21988 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
21989 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
21992 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
21995 dump_die_for_error (src_die
);
21996 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
21997 " from DIE at %s [in module %s]"),
21998 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
21999 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22005 /* Get the type specified by SIGNATURE referenced in DIE/CU,
22006 reading in and processing the type unit if necessary. */
22008 static struct type
*
22009 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
22010 struct dwarf2_cu
*cu
)
22012 struct dwarf2_per_objfile
*dwarf2_per_objfile
22013 = cu
->per_cu
->dwarf2_per_objfile
;
22014 struct signatured_type
*sig_type
;
22015 struct dwarf2_cu
*type_cu
;
22016 struct die_info
*type_die
;
22019 sig_type
= lookup_signatured_type (cu
, signature
);
22020 /* sig_type will be NULL if the signatured type is missing from
22022 if (sig_type
== NULL
)
22024 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
22025 " from DIE at %s [in module %s]"),
22026 hex_string (signature
), sect_offset_str (die
->sect_off
),
22027 objfile_name (dwarf2_per_objfile
->objfile
));
22028 return build_error_marker_type (cu
, die
);
22031 /* If we already know the type we're done. */
22032 if (sig_type
->type
!= NULL
)
22033 return sig_type
->type
;
22036 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
22037 if (type_die
!= NULL
)
22039 /* N.B. We need to call get_die_type to ensure only one type for this DIE
22040 is created. This is important, for example, because for c++ classes
22041 we need TYPE_NAME set which is only done by new_symbol. Blech. */
22042 type
= read_type_die (type_die
, type_cu
);
22045 complaint (_("Dwarf Error: Cannot build signatured type %s"
22046 " referenced from DIE at %s [in module %s]"),
22047 hex_string (signature
), sect_offset_str (die
->sect_off
),
22048 objfile_name (dwarf2_per_objfile
->objfile
));
22049 type
= build_error_marker_type (cu
, die
);
22054 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
22055 " from DIE at %s [in module %s]"),
22056 hex_string (signature
), sect_offset_str (die
->sect_off
),
22057 objfile_name (dwarf2_per_objfile
->objfile
));
22058 type
= build_error_marker_type (cu
, die
);
22060 sig_type
->type
= type
;
22065 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
22066 reading in and processing the type unit if necessary. */
22068 static struct type
*
22069 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
22070 struct dwarf2_cu
*cu
) /* ARI: editCase function */
22072 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
22073 if (attr
->form_is_ref ())
22075 struct dwarf2_cu
*type_cu
= cu
;
22076 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
22078 return read_type_die (type_die
, type_cu
);
22080 else if (attr
->form
== DW_FORM_ref_sig8
)
22082 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
22086 struct dwarf2_per_objfile
*dwarf2_per_objfile
22087 = cu
->per_cu
->dwarf2_per_objfile
;
22089 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
22090 " at %s [in module %s]"),
22091 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
22092 objfile_name (dwarf2_per_objfile
->objfile
));
22093 return build_error_marker_type (cu
, die
);
22097 /* Load the DIEs associated with type unit PER_CU into memory. */
22100 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
22102 struct signatured_type
*sig_type
;
22104 /* Caller is responsible for ensuring type_unit_groups don't get here. */
22105 gdb_assert (! per_cu
->type_unit_group_p ());
22107 /* We have the per_cu, but we need the signatured_type.
22108 Fortunately this is an easy translation. */
22109 gdb_assert (per_cu
->is_debug_types
);
22110 sig_type
= (struct signatured_type
*) per_cu
;
22112 gdb_assert (per_cu
->cu
== NULL
);
22114 read_signatured_type (sig_type
);
22116 gdb_assert (per_cu
->cu
!= NULL
);
22119 /* Read in a signatured type and build its CU and DIEs.
22120 If the type is a stub for the real type in a DWO file,
22121 read in the real type from the DWO file as well. */
22124 read_signatured_type (struct signatured_type
*sig_type
)
22126 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
22128 gdb_assert (per_cu
->is_debug_types
);
22129 gdb_assert (per_cu
->cu
== NULL
);
22131 cutu_reader
reader (per_cu
, NULL
, 0, false);
22133 if (!reader
.dummy_p
)
22135 struct dwarf2_cu
*cu
= reader
.cu
;
22136 const gdb_byte
*info_ptr
= reader
.info_ptr
;
22138 gdb_assert (cu
->die_hash
== NULL
);
22140 htab_create_alloc_ex (cu
->header
.length
/ 12,
22144 &cu
->comp_unit_obstack
,
22145 hashtab_obstack_allocate
,
22146 dummy_obstack_deallocate
);
22148 if (reader
.comp_unit_die
->has_children
)
22149 reader
.comp_unit_die
->child
22150 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
22151 reader
.comp_unit_die
);
22152 cu
->dies
= reader
.comp_unit_die
;
22153 /* comp_unit_die is not stored in die_hash, no need. */
22155 /* We try not to read any attributes in this function, because
22156 not all CUs needed for references have been loaded yet, and
22157 symbol table processing isn't initialized. But we have to
22158 set the CU language, or we won't be able to build types
22159 correctly. Similarly, if we do not read the producer, we can
22160 not apply producer-specific interpretation. */
22161 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
22166 sig_type
->per_cu
.tu_read
= 1;
22169 /* Decode simple location descriptions.
22170 Given a pointer to a dwarf block that defines a location, compute
22171 the location and return the value.
22173 NOTE drow/2003-11-18: This function is called in two situations
22174 now: for the address of static or global variables (partial symbols
22175 only) and for offsets into structures which are expected to be
22176 (more or less) constant. The partial symbol case should go away,
22177 and only the constant case should remain. That will let this
22178 function complain more accurately. A few special modes are allowed
22179 without complaint for global variables (for instance, global
22180 register values and thread-local values).
22182 A location description containing no operations indicates that the
22183 object is optimized out. The return value is 0 for that case.
22184 FIXME drow/2003-11-16: No callers check for this case any more; soon all
22185 callers will only want a very basic result and this can become a
22188 Note that stack[0] is unused except as a default error return. */
22191 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
22193 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22195 size_t size
= blk
->size
;
22196 const gdb_byte
*data
= blk
->data
;
22197 CORE_ADDR stack
[64];
22199 unsigned int bytes_read
, unsnd
;
22205 stack
[++stacki
] = 0;
22244 stack
[++stacki
] = op
- DW_OP_lit0
;
22279 stack
[++stacki
] = op
- DW_OP_reg0
;
22281 dwarf2_complex_location_expr_complaint ();
22285 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
22287 stack
[++stacki
] = unsnd
;
22289 dwarf2_complex_location_expr_complaint ();
22293 stack
[++stacki
] = cu
->header
.read_address (objfile
->obfd
, &data
[i
],
22298 case DW_OP_const1u
:
22299 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
22303 case DW_OP_const1s
:
22304 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
22308 case DW_OP_const2u
:
22309 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
22313 case DW_OP_const2s
:
22314 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
22318 case DW_OP_const4u
:
22319 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
22323 case DW_OP_const4s
:
22324 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
22328 case DW_OP_const8u
:
22329 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
22334 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
22340 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
22345 stack
[stacki
+ 1] = stack
[stacki
];
22350 stack
[stacki
- 1] += stack
[stacki
];
22354 case DW_OP_plus_uconst
:
22355 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
22361 stack
[stacki
- 1] -= stack
[stacki
];
22366 /* If we're not the last op, then we definitely can't encode
22367 this using GDB's address_class enum. This is valid for partial
22368 global symbols, although the variable's address will be bogus
22371 dwarf2_complex_location_expr_complaint ();
22374 case DW_OP_GNU_push_tls_address
:
22375 case DW_OP_form_tls_address
:
22376 /* The top of the stack has the offset from the beginning
22377 of the thread control block at which the variable is located. */
22378 /* Nothing should follow this operator, so the top of stack would
22380 /* This is valid for partial global symbols, but the variable's
22381 address will be bogus in the psymtab. Make it always at least
22382 non-zero to not look as a variable garbage collected by linker
22383 which have DW_OP_addr 0. */
22385 dwarf2_complex_location_expr_complaint ();
22389 case DW_OP_GNU_uninit
:
22393 case DW_OP_GNU_addr_index
:
22394 case DW_OP_GNU_const_index
:
22395 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
22402 const char *name
= get_DW_OP_name (op
);
22405 complaint (_("unsupported stack op: '%s'"),
22408 complaint (_("unsupported stack op: '%02x'"),
22412 return (stack
[stacki
]);
22415 /* Enforce maximum stack depth of SIZE-1 to avoid writing
22416 outside of the allocated space. Also enforce minimum>0. */
22417 if (stacki
>= ARRAY_SIZE (stack
) - 1)
22419 complaint (_("location description stack overflow"));
22425 complaint (_("location description stack underflow"));
22429 return (stack
[stacki
]);
22432 /* memory allocation interface */
22434 static struct dwarf_block
*
22435 dwarf_alloc_block (struct dwarf2_cu
*cu
)
22437 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
22440 static struct die_info
*
22441 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
22443 struct die_info
*die
;
22444 size_t size
= sizeof (struct die_info
);
22447 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
22449 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
22450 memset (die
, 0, sizeof (struct die_info
));
22456 /* Macro support. */
22458 /* An overload of dwarf_decode_macros that finds the correct section
22459 and ensures it is read in before calling the other overload. */
22462 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
22463 int section_is_gnu
)
22465 struct dwarf2_per_objfile
*dwarf2_per_objfile
22466 = cu
->per_cu
->dwarf2_per_objfile
;
22467 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22468 const struct line_header
*lh
= cu
->line_header
;
22469 unsigned int offset_size
= cu
->header
.offset_size
;
22470 struct dwarf2_section_info
*section
;
22471 const char *section_name
;
22473 if (cu
->dwo_unit
!= nullptr)
22475 if (section_is_gnu
)
22477 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
22478 section_name
= ".debug_macro.dwo";
22482 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
22483 section_name
= ".debug_macinfo.dwo";
22488 if (section_is_gnu
)
22490 section
= &dwarf2_per_objfile
->macro
;
22491 section_name
= ".debug_macro";
22495 section
= &dwarf2_per_objfile
->macinfo
;
22496 section_name
= ".debug_macinfo";
22500 section
->read (objfile
);
22501 if (section
->buffer
== nullptr)
22503 complaint (_("missing %s section"), section_name
);
22507 buildsym_compunit
*builder
= cu
->get_builder ();
22509 dwarf_decode_macros (dwarf2_per_objfile
, builder
, section
, lh
,
22510 offset_size
, offset
, section_is_gnu
);
22513 /* Return the .debug_loc section to use for CU.
22514 For DWO files use .debug_loc.dwo. */
22516 static struct dwarf2_section_info
*
22517 cu_debug_loc_section (struct dwarf2_cu
*cu
)
22519 struct dwarf2_per_objfile
*dwarf2_per_objfile
22520 = cu
->per_cu
->dwarf2_per_objfile
;
22524 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
22526 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
22528 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
22529 : &dwarf2_per_objfile
->loc
);
22532 /* A helper function that fills in a dwarf2_loclist_baton. */
22535 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
22536 struct dwarf2_loclist_baton
*baton
,
22537 const struct attribute
*attr
)
22539 struct dwarf2_per_objfile
*dwarf2_per_objfile
22540 = cu
->per_cu
->dwarf2_per_objfile
;
22541 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22543 section
->read (dwarf2_per_objfile
->objfile
);
22545 baton
->per_cu
= cu
->per_cu
;
22546 gdb_assert (baton
->per_cu
);
22547 /* We don't know how long the location list is, but make sure we
22548 don't run off the edge of the section. */
22549 baton
->size
= section
->size
- DW_UNSND (attr
);
22550 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
22551 if (cu
->base_address
.has_value ())
22552 baton
->base_address
= *cu
->base_address
;
22554 baton
->base_address
= 0;
22555 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
22559 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
22560 struct dwarf2_cu
*cu
, int is_block
)
22562 struct dwarf2_per_objfile
*dwarf2_per_objfile
22563 = cu
->per_cu
->dwarf2_per_objfile
;
22564 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22565 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
22567 if (attr
->form_is_section_offset ()
22568 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
22569 the section. If so, fall through to the complaint in the
22571 && DW_UNSND (attr
) < section
->get_size (objfile
))
22573 struct dwarf2_loclist_baton
*baton
;
22575 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
22577 fill_in_loclist_baton (cu
, baton
, attr
);
22579 if (!cu
->base_address
.has_value ())
22580 complaint (_("Location list used without "
22581 "specifying the CU base address."));
22583 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22584 ? dwarf2_loclist_block_index
22585 : dwarf2_loclist_index
);
22586 SYMBOL_LOCATION_BATON (sym
) = baton
;
22590 struct dwarf2_locexpr_baton
*baton
;
22592 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
22593 baton
->per_cu
= cu
->per_cu
;
22594 gdb_assert (baton
->per_cu
);
22596 if (attr
->form_is_block ())
22598 /* Note that we're just copying the block's data pointer
22599 here, not the actual data. We're still pointing into the
22600 info_buffer for SYM's objfile; right now we never release
22601 that buffer, but when we do clean up properly this may
22603 baton
->size
= DW_BLOCK (attr
)->size
;
22604 baton
->data
= DW_BLOCK (attr
)->data
;
22608 dwarf2_invalid_attrib_class_complaint ("location description",
22609 sym
->natural_name ());
22613 SYMBOL_ACLASS_INDEX (sym
) = (is_block
22614 ? dwarf2_locexpr_block_index
22615 : dwarf2_locexpr_index
);
22616 SYMBOL_LOCATION_BATON (sym
) = baton
;
22623 dwarf2_per_cu_data::objfile () const
22625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22627 /* Return the master objfile, so that we can report and look up the
22628 correct file containing this variable. */
22629 if (objfile
->separate_debug_objfile_backlink
)
22630 objfile
= objfile
->separate_debug_objfile_backlink
;
22635 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
22636 (CU_HEADERP is unused in such case) or prepare a temporary copy at
22637 CU_HEADERP first. */
22639 static const struct comp_unit_head
*
22640 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
22641 const struct dwarf2_per_cu_data
*per_cu
)
22643 const gdb_byte
*info_ptr
;
22646 return &per_cu
->cu
->header
;
22648 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
22650 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
22651 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
22652 rcuh_kind::COMPILE
);
22660 dwarf2_per_cu_data::addr_size () const
22662 struct comp_unit_head cu_header_local
;
22663 const struct comp_unit_head
*cu_headerp
;
22665 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22667 return cu_headerp
->addr_size
;
22673 dwarf2_per_cu_data::offset_size () const
22675 struct comp_unit_head cu_header_local
;
22676 const struct comp_unit_head
*cu_headerp
;
22678 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22680 return cu_headerp
->offset_size
;
22686 dwarf2_per_cu_data::ref_addr_size () const
22688 struct comp_unit_head cu_header_local
;
22689 const struct comp_unit_head
*cu_headerp
;
22691 cu_headerp
= per_cu_header_read_in (&cu_header_local
, this);
22693 if (cu_headerp
->version
== 2)
22694 return cu_headerp
->addr_size
;
22696 return cu_headerp
->offset_size
;
22702 dwarf2_per_cu_data::text_offset () const
22704 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22706 return objfile
->text_section_offset ();
22712 dwarf2_per_cu_data::addr_type () const
22714 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22715 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
22716 struct type
*addr_type
= lookup_pointer_type (void_type
);
22717 int addr_size
= this->addr_size ();
22719 if (TYPE_LENGTH (addr_type
) == addr_size
)
22722 addr_type
= addr_sized_int_type (TYPE_UNSIGNED (addr_type
));
22726 /* A helper function for dwarf2_find_containing_comp_unit that returns
22727 the index of the result, and that searches a vector. It will
22728 return a result even if the offset in question does not actually
22729 occur in any CU. This is separate so that it can be unit
22733 dwarf2_find_containing_comp_unit
22734 (sect_offset sect_off
,
22735 unsigned int offset_in_dwz
,
22736 const std::vector
<dwarf2_per_cu_data
*> &all_comp_units
)
22741 high
= all_comp_units
.size () - 1;
22744 struct dwarf2_per_cu_data
*mid_cu
;
22745 int mid
= low
+ (high
- low
) / 2;
22747 mid_cu
= all_comp_units
[mid
];
22748 if (mid_cu
->is_dwz
> offset_in_dwz
22749 || (mid_cu
->is_dwz
== offset_in_dwz
22750 && mid_cu
->sect_off
+ mid_cu
->length
> sect_off
))
22755 gdb_assert (low
== high
);
22759 /* Locate the .debug_info compilation unit from CU's objfile which contains
22760 the DIE at OFFSET. Raises an error on failure. */
22762 static struct dwarf2_per_cu_data
*
22763 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
22764 unsigned int offset_in_dwz
,
22765 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22768 = dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22769 dwarf2_per_objfile
->all_comp_units
);
22770 struct dwarf2_per_cu_data
*this_cu
22771 = dwarf2_per_objfile
->all_comp_units
[low
];
22773 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
22775 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
22776 error (_("Dwarf Error: could not find partial DIE containing "
22777 "offset %s [in module %s]"),
22778 sect_offset_str (sect_off
),
22779 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
22781 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
22783 return dwarf2_per_objfile
->all_comp_units
[low
-1];
22787 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
22788 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
22789 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
22790 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
22797 namespace selftests
{
22798 namespace find_containing_comp_unit
{
22803 struct dwarf2_per_cu_data one
{};
22804 struct dwarf2_per_cu_data two
{};
22805 struct dwarf2_per_cu_data three
{};
22806 struct dwarf2_per_cu_data four
{};
22809 two
.sect_off
= sect_offset (one
.length
);
22814 four
.sect_off
= sect_offset (three
.length
);
22818 std::vector
<dwarf2_per_cu_data
*> units
;
22819 units
.push_back (&one
);
22820 units
.push_back (&two
);
22821 units
.push_back (&three
);
22822 units
.push_back (&four
);
22826 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 0, units
);
22827 SELF_CHECK (units
[result
] == &one
);
22828 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 0, units
);
22829 SELF_CHECK (units
[result
] == &one
);
22830 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 0, units
);
22831 SELF_CHECK (units
[result
] == &two
);
22833 result
= dwarf2_find_containing_comp_unit (sect_offset (0), 1, units
);
22834 SELF_CHECK (units
[result
] == &three
);
22835 result
= dwarf2_find_containing_comp_unit (sect_offset (3), 1, units
);
22836 SELF_CHECK (units
[result
] == &three
);
22837 result
= dwarf2_find_containing_comp_unit (sect_offset (5), 1, units
);
22838 SELF_CHECK (units
[result
] == &four
);
22844 #endif /* GDB_SELF_TEST */
22846 /* Initialize dwarf2_cu CU, owned by PER_CU. */
22848 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
22849 : per_cu (per_cu_
),
22851 has_loclist (false),
22852 checked_producer (false),
22853 producer_is_gxx_lt_4_6 (false),
22854 producer_is_gcc_lt_4_3 (false),
22855 producer_is_icc (false),
22856 producer_is_icc_lt_14 (false),
22857 producer_is_codewarrior (false),
22858 processing_has_namespace_info (false)
22863 /* Destroy a dwarf2_cu. */
22865 dwarf2_cu::~dwarf2_cu ()
22870 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
22873 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
22874 enum language pretend_language
)
22876 struct attribute
*attr
;
22878 /* Set the language we're debugging. */
22879 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
22880 if (attr
!= nullptr)
22881 set_cu_language (DW_UNSND (attr
), cu
);
22884 cu
->language
= pretend_language
;
22885 cu
->language_defn
= language_def (cu
->language
);
22888 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
22891 /* Increase the age counter on each cached compilation unit, and free
22892 any that are too old. */
22895 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
22897 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22899 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
22900 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22901 while (per_cu
!= NULL
)
22903 per_cu
->cu
->last_used
++;
22904 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
22905 dwarf2_mark (per_cu
->cu
);
22906 per_cu
= per_cu
->cu
->read_in_chain
;
22909 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22910 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22911 while (per_cu
!= NULL
)
22913 struct dwarf2_per_cu_data
*next_cu
;
22915 next_cu
= per_cu
->cu
->read_in_chain
;
22917 if (!per_cu
->cu
->mark
)
22920 *last_chain
= next_cu
;
22923 last_chain
= &per_cu
->cu
->read_in_chain
;
22929 /* Remove a single compilation unit from the cache. */
22932 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
22934 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
22935 struct dwarf2_per_objfile
*dwarf2_per_objfile
22936 = target_per_cu
->dwarf2_per_objfile
;
22938 per_cu
= dwarf2_per_objfile
->read_in_chain
;
22939 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
22940 while (per_cu
!= NULL
)
22942 struct dwarf2_per_cu_data
*next_cu
;
22944 next_cu
= per_cu
->cu
->read_in_chain
;
22946 if (per_cu
== target_per_cu
)
22950 *last_chain
= next_cu
;
22954 last_chain
= &per_cu
->cu
->read_in_chain
;
22960 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
22961 We store these in a hash table separate from the DIEs, and preserve them
22962 when the DIEs are flushed out of cache.
22964 The CU "per_cu" pointer is needed because offset alone is not enough to
22965 uniquely identify the type. A file may have multiple .debug_types sections,
22966 or the type may come from a DWO file. Furthermore, while it's more logical
22967 to use per_cu->section+offset, with Fission the section with the data is in
22968 the DWO file but we don't know that section at the point we need it.
22969 We have to use something in dwarf2_per_cu_data (or the pointer to it)
22970 because we can enter the lookup routine, get_die_type_at_offset, from
22971 outside this file, and thus won't necessarily have PER_CU->cu.
22972 Fortunately, PER_CU is stable for the life of the objfile. */
22974 struct dwarf2_per_cu_offset_and_type
22976 const struct dwarf2_per_cu_data
*per_cu
;
22977 sect_offset sect_off
;
22981 /* Hash function for a dwarf2_per_cu_offset_and_type. */
22984 per_cu_offset_and_type_hash (const void *item
)
22986 const struct dwarf2_per_cu_offset_and_type
*ofs
22987 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
22989 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
22992 /* Equality function for a dwarf2_per_cu_offset_and_type. */
22995 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
22997 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
22998 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
22999 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
23000 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
23002 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
23003 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
23006 /* Set the type associated with DIE to TYPE. Save it in CU's hash
23007 table if necessary. For convenience, return TYPE.
23009 The DIEs reading must have careful ordering to:
23010 * Not cause infinite loops trying to read in DIEs as a prerequisite for
23011 reading current DIE.
23012 * Not trying to dereference contents of still incompletely read in types
23013 while reading in other DIEs.
23014 * Enable referencing still incompletely read in types just by a pointer to
23015 the type without accessing its fields.
23017 Therefore caller should follow these rules:
23018 * Try to fetch any prerequisite types we may need to build this DIE type
23019 before building the type and calling set_die_type.
23020 * After building type call set_die_type for current DIE as soon as
23021 possible before fetching more types to complete the current type.
23022 * Make the type as complete as possible before fetching more types. */
23024 static struct type
*
23025 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
23027 struct dwarf2_per_objfile
*dwarf2_per_objfile
23028 = cu
->per_cu
->dwarf2_per_objfile
;
23029 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
23030 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23031 struct attribute
*attr
;
23032 struct dynamic_prop prop
;
23034 /* For Ada types, make sure that the gnat-specific data is always
23035 initialized (if not already set). There are a few types where
23036 we should not be doing so, because the type-specific area is
23037 already used to hold some other piece of info (eg: TYPE_CODE_FLT
23038 where the type-specific area is used to store the floatformat).
23039 But this is not a problem, because the gnat-specific information
23040 is actually not needed for these types. */
23041 if (need_gnat_info (cu
)
23042 && TYPE_CODE (type
) != TYPE_CODE_FUNC
23043 && TYPE_CODE (type
) != TYPE_CODE_FLT
23044 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
23045 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
23046 && TYPE_CODE (type
) != TYPE_CODE_METHOD
23047 && !HAVE_GNAT_AUX_INFO (type
))
23048 INIT_GNAT_SPECIFIC (type
);
23050 /* Read DW_AT_allocated and set in type. */
23051 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
23052 if (attr
!= NULL
&& attr
->form_is_block ())
23054 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23055 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23056 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
23058 else if (attr
!= NULL
)
23060 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
23061 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23062 sect_offset_str (die
->sect_off
));
23065 /* Read DW_AT_associated and set in type. */
23066 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
23067 if (attr
!= NULL
&& attr
->form_is_block ())
23069 struct type
*prop_type
= cu
->per_cu
->addr_sized_int_type (false);
23070 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
23071 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
23073 else if (attr
!= NULL
)
23075 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
23076 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
23077 sect_offset_str (die
->sect_off
));
23080 /* Read DW_AT_data_location and set in type. */
23081 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
23082 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
23083 cu
->per_cu
->addr_type ()))
23084 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
23086 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23087 dwarf2_per_objfile
->die_type_hash
23088 = htab_up (htab_create_alloc (127,
23089 per_cu_offset_and_type_hash
,
23090 per_cu_offset_and_type_eq
,
23091 NULL
, xcalloc
, xfree
));
23093 ofs
.per_cu
= cu
->per_cu
;
23094 ofs
.sect_off
= die
->sect_off
;
23096 slot
= (struct dwarf2_per_cu_offset_and_type
**)
23097 htab_find_slot (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
, INSERT
);
23099 complaint (_("A problem internal to GDB: DIE %s has type already set"),
23100 sect_offset_str (die
->sect_off
));
23101 *slot
= XOBNEW (&objfile
->objfile_obstack
,
23102 struct dwarf2_per_cu_offset_and_type
);
23107 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
23108 or return NULL if the die does not have a saved type. */
23110 static struct type
*
23111 get_die_type_at_offset (sect_offset sect_off
,
23112 struct dwarf2_per_cu_data
*per_cu
)
23114 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
23115 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23117 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
23120 ofs
.per_cu
= per_cu
;
23121 ofs
.sect_off
= sect_off
;
23122 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
23123 htab_find (dwarf2_per_objfile
->die_type_hash
.get (), &ofs
));
23130 /* Look up the type for DIE in CU in die_type_hash,
23131 or return NULL if DIE does not have a saved type. */
23133 static struct type
*
23134 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
23136 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
23139 /* Add a dependence relationship from CU to REF_PER_CU. */
23142 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
23143 struct dwarf2_per_cu_data
*ref_per_cu
)
23147 if (cu
->dependencies
== NULL
)
23149 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
23150 NULL
, &cu
->comp_unit_obstack
,
23151 hashtab_obstack_allocate
,
23152 dummy_obstack_deallocate
);
23154 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
23156 *slot
= ref_per_cu
;
23159 /* Subroutine of dwarf2_mark to pass to htab_traverse.
23160 Set the mark field in every compilation unit in the
23161 cache that we must keep because we are keeping CU. */
23164 dwarf2_mark_helper (void **slot
, void *data
)
23166 struct dwarf2_per_cu_data
*per_cu
;
23168 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
23170 /* cu->dependencies references may not yet have been ever read if QUIT aborts
23171 reading of the chain. As such dependencies remain valid it is not much
23172 useful to track and undo them during QUIT cleanups. */
23173 if (per_cu
->cu
== NULL
)
23176 if (per_cu
->cu
->mark
)
23178 per_cu
->cu
->mark
= true;
23180 if (per_cu
->cu
->dependencies
!= NULL
)
23181 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23186 /* Set the mark field in CU and in every other compilation unit in the
23187 cache that we must keep because we are keeping CU. */
23190 dwarf2_mark (struct dwarf2_cu
*cu
)
23195 if (cu
->dependencies
!= NULL
)
23196 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
23200 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
23204 per_cu
->cu
->mark
= false;
23205 per_cu
= per_cu
->cu
->read_in_chain
;
23209 /* Trivial hash function for partial_die_info: the hash value of a DIE
23210 is its offset in .debug_info for this objfile. */
23213 partial_die_hash (const void *item
)
23215 const struct partial_die_info
*part_die
23216 = (const struct partial_die_info
*) item
;
23218 return to_underlying (part_die
->sect_off
);
23221 /* Trivial comparison function for partial_die_info structures: two DIEs
23222 are equal if they have the same offset. */
23225 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
23227 const struct partial_die_info
*part_die_lhs
23228 = (const struct partial_die_info
*) item_lhs
;
23229 const struct partial_die_info
*part_die_rhs
23230 = (const struct partial_die_info
*) item_rhs
;
23232 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
23235 struct cmd_list_element
*set_dwarf_cmdlist
;
23236 struct cmd_list_element
*show_dwarf_cmdlist
;
23239 set_dwarf_cmd (const char *args
, int from_tty
)
23241 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
23246 show_dwarf_cmd (const char *args
, int from_tty
)
23248 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
23252 show_check_physname (struct ui_file
*file
, int from_tty
,
23253 struct cmd_list_element
*c
, const char *value
)
23255 fprintf_filtered (file
,
23256 _("Whether to check \"physname\" is %s.\n"),
23260 void _initialize_dwarf2_read ();
23262 _initialize_dwarf2_read ()
23264 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
23265 Set DWARF specific variables.\n\
23266 Configure DWARF variables such as the cache size."),
23267 &set_dwarf_cmdlist
, "maintenance set dwarf ",
23268 0/*allow-unknown*/, &maintenance_set_cmdlist
);
23270 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
23271 Show DWARF specific variables.\n\
23272 Show DWARF variables such as the cache size."),
23273 &show_dwarf_cmdlist
, "maintenance show dwarf ",
23274 0/*allow-unknown*/, &maintenance_show_cmdlist
);
23276 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
23277 &dwarf_max_cache_age
, _("\
23278 Set the upper bound on the age of cached DWARF compilation units."), _("\
23279 Show the upper bound on the age of cached DWARF compilation units."), _("\
23280 A higher limit means that cached compilation units will be stored\n\
23281 in memory longer, and more total memory will be used. Zero disables\n\
23282 caching, which can slow down startup."),
23284 show_dwarf_max_cache_age
,
23285 &set_dwarf_cmdlist
,
23286 &show_dwarf_cmdlist
);
23288 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
23289 Set debugging of the DWARF reader."), _("\
23290 Show debugging of the DWARF reader."), _("\
23291 When enabled (non-zero), debugging messages are printed during DWARF\n\
23292 reading and symtab expansion. A value of 1 (one) provides basic\n\
23293 information. A value greater than 1 provides more verbose information."),
23296 &setdebuglist
, &showdebuglist
);
23298 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
23299 Set debugging of the DWARF DIE reader."), _("\
23300 Show debugging of the DWARF DIE reader."), _("\
23301 When enabled (non-zero), DIEs are dumped after they are read in.\n\
23302 The value is the maximum depth to print."),
23305 &setdebuglist
, &showdebuglist
);
23307 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
23308 Set debugging of the dwarf line reader."), _("\
23309 Show debugging of the dwarf line reader."), _("\
23310 When enabled (non-zero), line number entries are dumped as they are read in.\n\
23311 A value of 1 (one) provides basic information.\n\
23312 A value greater than 1 provides more verbose information."),
23315 &setdebuglist
, &showdebuglist
);
23317 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
23318 Set cross-checking of \"physname\" code against demangler."), _("\
23319 Show cross-checking of \"physname\" code against demangler."), _("\
23320 When enabled, GDB's internal \"physname\" code is checked against\n\
23322 NULL
, show_check_physname
,
23323 &setdebuglist
, &showdebuglist
);
23325 add_setshow_boolean_cmd ("use-deprecated-index-sections",
23326 no_class
, &use_deprecated_index_sections
, _("\
23327 Set whether to use deprecated gdb_index sections."), _("\
23328 Show whether to use deprecated gdb_index sections."), _("\
23329 When enabled, deprecated .gdb_index sections are used anyway.\n\
23330 Normally they are ignored either because of a missing feature or\n\
23331 performance issue.\n\
23332 Warning: This option must be enabled before gdb reads the file."),
23335 &setlist
, &showlist
);
23337 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23338 &dwarf2_locexpr_funcs
);
23339 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
23340 &dwarf2_loclist_funcs
);
23342 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23343 &dwarf2_block_frame_base_locexpr_funcs
);
23344 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
23345 &dwarf2_block_frame_base_loclist_funcs
);
23348 selftests::register_test ("dw2_expand_symtabs_matching",
23349 selftests::dw2_expand_symtabs_matching::run_test
);
23350 selftests::register_test ("dwarf2_find_containing_comp_unit",
23351 selftests::find_containing_comp_unit::run_test
);