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 "dwarf2read.h"
33 #include "dwarf2/abbrev.h"
34 #include "dwarf-index-cache.h"
35 #include "dwarf-index-common.h"
36 #include "dwarf2/leb.h"
45 #include "gdb-demangle.h"
46 #include "filenames.h" /* for DOSish file names */
49 #include "complaints.h"
50 #include "dwarf2expr.h"
51 #include "dwarf2loc.h"
52 #include "cp-support.h"
58 #include "typeprint.h"
63 #include "gdbcore.h" /* for gnutarget */
64 #include "gdb/gdb-index.h"
69 #include "namespace.h"
70 #include "gdbsupport/function-view.h"
71 #include "gdbsupport/gdb_optional.h"
72 #include "gdbsupport/underlying.h"
73 #include "gdbsupport/hash_enum.h"
74 #include "filename-seen-cache.h"
78 #include <unordered_map>
79 #include "gdbsupport/selftest.h"
80 #include "rust-lang.h"
81 #include "gdbsupport/pathstuff.h"
83 /* When == 1, print basic high level tracing messages.
84 When > 1, be more verbose.
85 This is in contrast to the low level DIE reading of dwarf_die_debug. */
86 static unsigned int dwarf_read_debug
= 0;
88 /* When non-zero, dump DIEs after they are read in. */
89 static unsigned int dwarf_die_debug
= 0;
91 /* When non-zero, dump line number entries as they are read in. */
92 static unsigned int dwarf_line_debug
= 0;
94 /* When true, cross-check physname against demangler. */
95 static bool check_physname
= false;
97 /* When true, do not reject deprecated .gdb_index sections. */
98 static bool use_deprecated_index_sections
= false;
100 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
102 /* The "aclass" indices for various kinds of computed DWARF symbols. */
104 static int dwarf2_locexpr_index
;
105 static int dwarf2_loclist_index
;
106 static int dwarf2_locexpr_block_index
;
107 static int dwarf2_loclist_block_index
;
109 /* An index into a (C++) symbol name component in a symbol name as
110 recorded in the mapped_index's symbol table. For each C++ symbol
111 in the symbol table, we record one entry for the start of each
112 component in the symbol in a table of name components, and then
113 sort the table, in order to be able to binary search symbol names,
114 ignoring leading namespaces, both completion and regular look up.
115 For example, for symbol "A::B::C", we'll have an entry that points
116 to "A::B::C", another that points to "B::C", and another for "C".
117 Note that function symbols in GDB index have no parameter
118 information, just the function/method names. You can convert a
119 name_component to a "const char *" using the
120 'mapped_index::symbol_name_at(offset_type)' method. */
122 struct name_component
124 /* Offset in the symbol name where the component starts. Stored as
125 a (32-bit) offset instead of a pointer to save memory and improve
126 locality on 64-bit architectures. */
127 offset_type name_offset
;
129 /* The symbol's index in the symbol and constant pool tables of a
134 /* Base class containing bits shared by both .gdb_index and
135 .debug_name indexes. */
137 struct mapped_index_base
139 mapped_index_base () = default;
140 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
142 /* The name_component table (a sorted vector). See name_component's
143 description above. */
144 std::vector
<name_component
> name_components
;
146 /* How NAME_COMPONENTS is sorted. */
147 enum case_sensitivity name_components_casing
;
149 /* Return the number of names in the symbol table. */
150 virtual size_t symbol_name_count () const = 0;
152 /* Get the name of the symbol at IDX in the symbol table. */
153 virtual const char *symbol_name_at (offset_type idx
) const = 0;
155 /* Return whether the name at IDX in the symbol table should be
157 virtual bool symbol_name_slot_invalid (offset_type idx
) const
162 /* Build the symbol name component sorted vector, if we haven't
164 void build_name_components ();
166 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
167 possible matches for LN_NO_PARAMS in the name component
169 std::pair
<std::vector
<name_component
>::const_iterator
,
170 std::vector
<name_component
>::const_iterator
>
171 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
172 enum language lang
) const;
174 /* Prevent deleting/destroying via a base class pointer. */
176 ~mapped_index_base() = default;
179 /* A description of the mapped index. The file format is described in
180 a comment by the code that writes the index. */
181 struct mapped_index final
: public mapped_index_base
183 /* A slot/bucket in the symbol table hash. */
184 struct symbol_table_slot
186 const offset_type name
;
187 const offset_type vec
;
190 /* Index data format version. */
193 /* The address table data. */
194 gdb::array_view
<const gdb_byte
> address_table
;
196 /* The symbol table, implemented as a hash table. */
197 gdb::array_view
<symbol_table_slot
> symbol_table
;
199 /* A pointer to the constant pool. */
200 const char *constant_pool
= nullptr;
202 bool symbol_name_slot_invalid (offset_type idx
) const override
204 const auto &bucket
= this->symbol_table
[idx
];
205 return bucket
.name
== 0 && bucket
.vec
== 0;
208 /* Convenience method to get at the name of the symbol at IDX in the
210 const char *symbol_name_at (offset_type idx
) const override
211 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
213 size_t symbol_name_count () const override
214 { return this->symbol_table
.size (); }
217 /* A description of the mapped .debug_names.
218 Uninitialized map has CU_COUNT 0. */
219 struct mapped_debug_names final
: public mapped_index_base
221 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
222 : dwarf2_per_objfile (dwarf2_per_objfile_
)
225 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
226 bfd_endian dwarf5_byte_order
;
227 bool dwarf5_is_dwarf64
;
228 bool augmentation_is_gdb
;
230 uint32_t cu_count
= 0;
231 uint32_t tu_count
, bucket_count
, name_count
;
232 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
233 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
234 const gdb_byte
*name_table_string_offs_reordered
;
235 const gdb_byte
*name_table_entry_offs_reordered
;
236 const gdb_byte
*entry_pool
;
243 /* Attribute name DW_IDX_*. */
246 /* Attribute form DW_FORM_*. */
249 /* Value if FORM is DW_FORM_implicit_const. */
250 LONGEST implicit_const
;
252 std::vector
<attr
> attr_vec
;
255 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
257 const char *namei_to_name (uint32_t namei
) const;
259 /* Implementation of the mapped_index_base virtual interface, for
260 the name_components cache. */
262 const char *symbol_name_at (offset_type idx
) const override
263 { return namei_to_name (idx
); }
265 size_t symbol_name_count () const override
266 { return this->name_count
; }
269 /* See dwarf2read.h. */
272 get_dwarf2_per_objfile (struct objfile
*objfile
)
274 return dwarf2_objfile_data_key
.get (objfile
);
277 /* Default names of the debugging sections. */
279 /* Note that if the debugging section has been compressed, it might
280 have a name like .zdebug_info. */
282 static const struct dwarf2_debug_sections dwarf2_elf_names
=
284 { ".debug_info", ".zdebug_info" },
285 { ".debug_abbrev", ".zdebug_abbrev" },
286 { ".debug_line", ".zdebug_line" },
287 { ".debug_loc", ".zdebug_loc" },
288 { ".debug_loclists", ".zdebug_loclists" },
289 { ".debug_macinfo", ".zdebug_macinfo" },
290 { ".debug_macro", ".zdebug_macro" },
291 { ".debug_str", ".zdebug_str" },
292 { ".debug_str_offsets", ".zdebug_str_offsets" },
293 { ".debug_line_str", ".zdebug_line_str" },
294 { ".debug_ranges", ".zdebug_ranges" },
295 { ".debug_rnglists", ".zdebug_rnglists" },
296 { ".debug_types", ".zdebug_types" },
297 { ".debug_addr", ".zdebug_addr" },
298 { ".debug_frame", ".zdebug_frame" },
299 { ".eh_frame", NULL
},
300 { ".gdb_index", ".zgdb_index" },
301 { ".debug_names", ".zdebug_names" },
302 { ".debug_aranges", ".zdebug_aranges" },
306 /* List of DWO/DWP sections. */
308 static const struct dwop_section_names
310 struct dwarf2_section_names abbrev_dwo
;
311 struct dwarf2_section_names info_dwo
;
312 struct dwarf2_section_names line_dwo
;
313 struct dwarf2_section_names loc_dwo
;
314 struct dwarf2_section_names loclists_dwo
;
315 struct dwarf2_section_names macinfo_dwo
;
316 struct dwarf2_section_names macro_dwo
;
317 struct dwarf2_section_names str_dwo
;
318 struct dwarf2_section_names str_offsets_dwo
;
319 struct dwarf2_section_names types_dwo
;
320 struct dwarf2_section_names cu_index
;
321 struct dwarf2_section_names tu_index
;
325 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
326 { ".debug_info.dwo", ".zdebug_info.dwo" },
327 { ".debug_line.dwo", ".zdebug_line.dwo" },
328 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
329 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
330 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
331 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
332 { ".debug_str.dwo", ".zdebug_str.dwo" },
333 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
334 { ".debug_types.dwo", ".zdebug_types.dwo" },
335 { ".debug_cu_index", ".zdebug_cu_index" },
336 { ".debug_tu_index", ".zdebug_tu_index" },
339 /* local data types */
341 /* The data in a compilation unit header, after target2host
342 translation, looks like this. */
343 struct comp_unit_head
347 unsigned char addr_size
;
348 unsigned char signed_addr_p
;
349 sect_offset abbrev_sect_off
;
351 /* Size of file offsets; either 4 or 8. */
352 unsigned int offset_size
;
354 /* Size of the length field; either 4 or 12. */
355 unsigned int initial_length_size
;
357 enum dwarf_unit_type unit_type
;
359 /* Offset to the first byte of this compilation unit header in the
360 .debug_info section, for resolving relative reference dies. */
361 sect_offset sect_off
;
363 /* Offset to first die in this cu from the start of the cu.
364 This will be the first byte following the compilation unit header. */
365 cu_offset first_die_cu_offset
;
368 /* 64-bit signature of this unit. For type units, it denotes the signature of
369 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
370 Also used in DWARF 5, to denote the dwo id when the unit type is
371 DW_UT_skeleton or DW_UT_split_compile. */
374 /* For types, offset in the type's DIE of the type defined by this TU. */
375 cu_offset type_cu_offset_in_tu
;
378 /* Type used for delaying computation of method physnames.
379 See comments for compute_delayed_physnames. */
380 struct delayed_method_info
382 /* The type to which the method is attached, i.e., its parent class. */
385 /* The index of the method in the type's function fieldlists. */
388 /* The index of the method in the fieldlist. */
391 /* The name of the DIE. */
394 /* The DIE associated with this method. */
395 struct die_info
*die
;
398 /* Internal state when decoding a particular compilation unit. */
401 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
404 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
406 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
407 Create the set of symtabs used by this TU, or if this TU is sharing
408 symtabs with another TU and the symtabs have already been created
409 then restore those symtabs in the line header.
410 We don't need the pc/line-number mapping for type units. */
411 void setup_type_unit_groups (struct die_info
*die
);
413 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
414 buildsym_compunit constructor. */
415 struct compunit_symtab
*start_symtab (const char *name
,
416 const char *comp_dir
,
419 /* Reset the builder. */
420 void reset_builder () { m_builder
.reset (); }
422 /* The header of the compilation unit. */
423 struct comp_unit_head header
{};
425 /* Base address of this compilation unit. */
426 CORE_ADDR base_address
= 0;
428 /* Non-zero if base_address has been set. */
431 /* The language we are debugging. */
432 enum language language
= language_unknown
;
433 const struct language_defn
*language_defn
= nullptr;
435 const char *producer
= nullptr;
438 /* The symtab builder for this CU. This is only non-NULL when full
439 symbols are being read. */
440 std::unique_ptr
<buildsym_compunit
> m_builder
;
443 /* The generic symbol table building routines have separate lists for
444 file scope symbols and all all other scopes (local scopes). So
445 we need to select the right one to pass to add_symbol_to_list().
446 We do it by keeping a pointer to the correct list in list_in_scope.
448 FIXME: The original dwarf code just treated the file scope as the
449 first local scope, and all other local scopes as nested local
450 scopes, and worked fine. Check to see if we really need to
451 distinguish these in buildsym.c. */
452 struct pending
**list_in_scope
= nullptr;
454 /* Hash table holding all the loaded partial DIEs
455 with partial_die->offset.SECT_OFF as hash. */
456 htab_t partial_dies
= nullptr;
458 /* Storage for things with the same lifetime as this read-in compilation
459 unit, including partial DIEs. */
460 auto_obstack comp_unit_obstack
;
462 /* When multiple dwarf2_cu structures are living in memory, this field
463 chains them all together, so that they can be released efficiently.
464 We will probably also want a generation counter so that most-recently-used
465 compilation units are cached... */
466 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
468 /* Backlink to our per_cu entry. */
469 struct dwarf2_per_cu_data
*per_cu
;
471 /* How many compilation units ago was this CU last referenced? */
474 /* A hash table of DIE cu_offset for following references with
475 die_info->offset.sect_off as hash. */
476 htab_t die_hash
= nullptr;
478 /* Full DIEs if read in. */
479 struct die_info
*dies
= nullptr;
481 /* A set of pointers to dwarf2_per_cu_data objects for compilation
482 units referenced by this one. Only set during full symbol processing;
483 partial symbol tables do not have dependencies. */
484 htab_t dependencies
= nullptr;
486 /* Header data from the line table, during full symbol processing. */
487 struct line_header
*line_header
= nullptr;
488 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
489 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
490 this is the DW_TAG_compile_unit die for this CU. We'll hold on
491 to the line header as long as this DIE is being processed. See
492 process_die_scope. */
493 die_info
*line_header_die_owner
= nullptr;
495 /* A list of methods which need to have physnames computed
496 after all type information has been read. */
497 std::vector
<delayed_method_info
> method_list
;
499 /* To be copied to symtab->call_site_htab. */
500 htab_t call_site_htab
= nullptr;
502 /* Non-NULL if this CU came from a DWO file.
503 There is an invariant here that is important to remember:
504 Except for attributes copied from the top level DIE in the "main"
505 (or "stub") file in preparation for reading the DWO file
506 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
507 Either there isn't a DWO file (in which case this is NULL and the point
508 is moot), or there is and either we're not going to read it (in which
509 case this is NULL) or there is and we are reading it (in which case this
511 struct dwo_unit
*dwo_unit
= nullptr;
513 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
514 Note this value comes from the Fission stub CU/TU's DIE. */
515 gdb::optional
<ULONGEST
> addr_base
;
517 /* The DW_AT_rnglists_base attribute if present.
518 Note this value comes from the Fission stub CU/TU's DIE.
519 Also note that the value is zero in the non-DWO case so this value can
520 be used without needing to know whether DWO files are in use or not.
521 N.B. This does not apply to DW_AT_ranges appearing in
522 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
523 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
524 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
525 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
526 ULONGEST ranges_base
= 0;
528 /* When reading debug info generated by older versions of rustc, we
529 have to rewrite some union types to be struct types with a
530 variant part. This rewriting must be done after the CU is fully
531 read in, because otherwise at the point of rewriting some struct
532 type might not have been fully processed. So, we keep a list of
533 all such types here and process them after expansion. */
534 std::vector
<struct type
*> rust_unions
;
536 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
537 files, the value is implicitly zero. For DWARF 5 version DWO files, the
538 value is often implicit and is the size of the header of
539 .debug_str_offsets section (8 or 4, depending on the address size). */
540 gdb::optional
<ULONGEST
> str_offsets_base
;
542 /* Mark used when releasing cached dies. */
545 /* This CU references .debug_loc. See the symtab->locations_valid field.
546 This test is imperfect as there may exist optimized debug code not using
547 any location list and still facing inlining issues if handled as
548 unoptimized code. For a future better test see GCC PR other/32998. */
549 bool has_loclist
: 1;
551 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
552 if all the producer_is_* fields are valid. This information is cached
553 because profiling CU expansion showed excessive time spent in
554 producer_is_gxx_lt_4_6. */
555 bool checked_producer
: 1;
556 bool producer_is_gxx_lt_4_6
: 1;
557 bool producer_is_gcc_lt_4_3
: 1;
558 bool producer_is_icc
: 1;
559 bool producer_is_icc_lt_14
: 1;
560 bool producer_is_codewarrior
: 1;
562 /* When true, the file that we're processing is known to have
563 debugging info for C++ namespaces. GCC 3.3.x did not produce
564 this information, but later versions do. */
566 bool processing_has_namespace_info
: 1;
568 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
570 /* If this CU was inherited by another CU (via specification,
571 abstract_origin, etc), this is the ancestor CU. */
574 /* Get the buildsym_compunit for this CU. */
575 buildsym_compunit
*get_builder ()
577 /* If this CU has a builder associated with it, use that. */
578 if (m_builder
!= nullptr)
579 return m_builder
.get ();
581 /* Otherwise, search ancestors for a valid builder. */
582 if (ancestor
!= nullptr)
583 return ancestor
->get_builder ();
589 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
590 This includes type_unit_group and quick_file_names. */
592 struct stmt_list_hash
594 /* The DWO unit this table is from or NULL if there is none. */
595 struct dwo_unit
*dwo_unit
;
597 /* Offset in .debug_line or .debug_line.dwo. */
598 sect_offset line_sect_off
;
601 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
602 an object of this type. */
604 struct type_unit_group
606 /* dwarf2read.c's main "handle" on a TU symtab.
607 To simplify things we create an artificial CU that "includes" all the
608 type units using this stmt_list so that the rest of the code still has
609 a "per_cu" handle on the symtab.
610 This PER_CU is recognized by having no section. */
611 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
612 struct dwarf2_per_cu_data per_cu
;
614 /* The TUs that share this DW_AT_stmt_list entry.
615 This is added to while parsing type units to build partial symtabs,
616 and is deleted afterwards and not used again. */
617 std::vector
<signatured_type
*> *tus
;
619 /* The compunit symtab.
620 Type units in a group needn't all be defined in the same source file,
621 so we create an essentially anonymous symtab as the compunit symtab. */
622 struct compunit_symtab
*compunit_symtab
;
624 /* The data used to construct the hash key. */
625 struct stmt_list_hash hash
;
627 /* The number of symtabs from the line header.
628 The value here must match line_header.num_file_names. */
629 unsigned int num_symtabs
;
631 /* The symbol tables for this TU (obtained from the files listed in
633 WARNING: The order of entries here must match the order of entries
634 in the line header. After the first TU using this type_unit_group, the
635 line header for the subsequent TUs is recreated from this. This is done
636 because we need to use the same symtabs for each TU using the same
637 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
638 there's no guarantee the line header doesn't have duplicate entries. */
639 struct symtab
**symtabs
;
642 /* These sections are what may appear in a (real or virtual) DWO file. */
646 struct dwarf2_section_info abbrev
;
647 struct dwarf2_section_info line
;
648 struct dwarf2_section_info loc
;
649 struct dwarf2_section_info loclists
;
650 struct dwarf2_section_info macinfo
;
651 struct dwarf2_section_info macro
;
652 struct dwarf2_section_info str
;
653 struct dwarf2_section_info str_offsets
;
654 /* In the case of a virtual DWO file, these two are unused. */
655 struct dwarf2_section_info info
;
656 std::vector
<dwarf2_section_info
> types
;
659 /* CUs/TUs in DWP/DWO files. */
663 /* Backlink to the containing struct dwo_file. */
664 struct dwo_file
*dwo_file
;
666 /* The "id" that distinguishes this CU/TU.
667 .debug_info calls this "dwo_id", .debug_types calls this "signature".
668 Since signatures came first, we stick with it for consistency. */
671 /* The section this CU/TU lives in, in the DWO file. */
672 struct dwarf2_section_info
*section
;
674 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
675 sect_offset sect_off
;
678 /* For types, offset in the type's DIE of the type defined by this TU. */
679 cu_offset type_offset_in_tu
;
682 /* include/dwarf2.h defines the DWP section codes.
683 It defines a max value but it doesn't define a min value, which we
684 use for error checking, so provide one. */
686 enum dwp_v2_section_ids
691 /* Data for one DWO file.
693 This includes virtual DWO files (a virtual DWO file is a DWO file as it
694 appears in a DWP file). DWP files don't really have DWO files per se -
695 comdat folding of types "loses" the DWO file they came from, and from
696 a high level view DWP files appear to contain a mass of random types.
697 However, to maintain consistency with the non-DWP case we pretend DWP
698 files contain virtual DWO files, and we assign each TU with one virtual
699 DWO file (generally based on the line and abbrev section offsets -
700 a heuristic that seems to work in practice). */
704 dwo_file () = default;
705 DISABLE_COPY_AND_ASSIGN (dwo_file
);
707 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
708 For virtual DWO files the name is constructed from the section offsets
709 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
710 from related CU+TUs. */
711 const char *dwo_name
= nullptr;
713 /* The DW_AT_comp_dir attribute. */
714 const char *comp_dir
= nullptr;
716 /* The bfd, when the file is open. Otherwise this is NULL.
717 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
718 gdb_bfd_ref_ptr dbfd
;
720 /* The sections that make up this DWO file.
721 Remember that for virtual DWO files in DWP V2, these are virtual
722 sections (for lack of a better name). */
723 struct dwo_sections sections
{};
725 /* The CUs in the file.
726 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
727 an extension to handle LLVM's Link Time Optimization output (where
728 multiple source files may be compiled into a single object/dwo pair). */
731 /* Table of TUs in the file.
732 Each element is a struct dwo_unit. */
736 /* These sections are what may appear in a DWP file. */
740 /* These are used by both DWP version 1 and 2. */
741 struct dwarf2_section_info str
;
742 struct dwarf2_section_info cu_index
;
743 struct dwarf2_section_info tu_index
;
745 /* These are only used by DWP version 2 files.
746 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
747 sections are referenced by section number, and are not recorded here.
748 In DWP version 2 there is at most one copy of all these sections, each
749 section being (effectively) comprised of the concatenation of all of the
750 individual sections that exist in the version 1 format.
751 To keep the code simple we treat each of these concatenated pieces as a
752 section itself (a virtual section?). */
753 struct dwarf2_section_info abbrev
;
754 struct dwarf2_section_info info
;
755 struct dwarf2_section_info line
;
756 struct dwarf2_section_info loc
;
757 struct dwarf2_section_info macinfo
;
758 struct dwarf2_section_info macro
;
759 struct dwarf2_section_info str_offsets
;
760 struct dwarf2_section_info types
;
763 /* These sections are what may appear in a virtual DWO file in DWP version 1.
764 A virtual DWO file is a DWO file as it appears in a DWP file. */
766 struct virtual_v1_dwo_sections
768 struct dwarf2_section_info abbrev
;
769 struct dwarf2_section_info line
;
770 struct dwarf2_section_info loc
;
771 struct dwarf2_section_info macinfo
;
772 struct dwarf2_section_info macro
;
773 struct dwarf2_section_info str_offsets
;
774 /* Each DWP hash table entry records one CU or one TU.
775 That is recorded here, and copied to dwo_unit.section. */
776 struct dwarf2_section_info info_or_types
;
779 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
780 In version 2, the sections of the DWO files are concatenated together
781 and stored in one section of that name. Thus each ELF section contains
782 several "virtual" sections. */
784 struct virtual_v2_dwo_sections
786 bfd_size_type abbrev_offset
;
787 bfd_size_type abbrev_size
;
789 bfd_size_type line_offset
;
790 bfd_size_type line_size
;
792 bfd_size_type loc_offset
;
793 bfd_size_type loc_size
;
795 bfd_size_type macinfo_offset
;
796 bfd_size_type macinfo_size
;
798 bfd_size_type macro_offset
;
799 bfd_size_type macro_size
;
801 bfd_size_type str_offsets_offset
;
802 bfd_size_type str_offsets_size
;
804 /* Each DWP hash table entry records one CU or one TU.
805 That is recorded here, and copied to dwo_unit.section. */
806 bfd_size_type info_or_types_offset
;
807 bfd_size_type info_or_types_size
;
810 /* Contents of DWP hash tables. */
812 struct dwp_hash_table
814 uint32_t version
, nr_columns
;
815 uint32_t nr_units
, nr_slots
;
816 const gdb_byte
*hash_table
, *unit_table
;
821 const gdb_byte
*indices
;
825 /* This is indexed by column number and gives the id of the section
827 #define MAX_NR_V2_DWO_SECTIONS \
828 (1 /* .debug_info or .debug_types */ \
829 + 1 /* .debug_abbrev */ \
830 + 1 /* .debug_line */ \
831 + 1 /* .debug_loc */ \
832 + 1 /* .debug_str_offsets */ \
833 + 1 /* .debug_macro or .debug_macinfo */)
834 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
835 const gdb_byte
*offsets
;
836 const gdb_byte
*sizes
;
841 /* Data for one DWP file. */
845 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
847 dbfd (std::move (abfd
))
851 /* Name of the file. */
854 /* File format version. */
858 gdb_bfd_ref_ptr dbfd
;
860 /* Section info for this file. */
861 struct dwp_sections sections
{};
863 /* Table of CUs in the file. */
864 const struct dwp_hash_table
*cus
= nullptr;
866 /* Table of TUs in the file. */
867 const struct dwp_hash_table
*tus
= nullptr;
869 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
870 htab_t loaded_cus
{};
871 htab_t loaded_tus
{};
873 /* Table to map ELF section numbers to their sections.
874 This is only needed for the DWP V1 file format. */
875 unsigned int num_sections
= 0;
876 asection
**elf_sections
= nullptr;
879 /* Struct used to pass misc. parameters to read_die_and_children, et
880 al. which are used for both .debug_info and .debug_types dies.
881 All parameters here are unchanging for the life of the call. This
882 struct exists to abstract away the constant parameters of die reading. */
884 struct die_reader_specs
886 /* The bfd of die_section. */
889 /* The CU of the DIE we are parsing. */
890 struct dwarf2_cu
*cu
;
892 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
893 struct dwo_file
*dwo_file
;
895 /* The section the die comes from.
896 This is either .debug_info or .debug_types, or the .dwo variants. */
897 struct dwarf2_section_info
*die_section
;
899 /* die_section->buffer. */
900 const gdb_byte
*buffer
;
902 /* The end of the buffer. */
903 const gdb_byte
*buffer_end
;
905 /* The value of the DW_AT_comp_dir attribute. */
906 const char *comp_dir
;
908 /* The abbreviation table to use when reading the DIEs. */
909 struct abbrev_table
*abbrev_table
;
912 /* A subclass of die_reader_specs that holds storage and has complex
913 constructor and destructor behavior. */
915 class cutu_reader
: public die_reader_specs
919 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
920 struct abbrev_table
*abbrev_table
,
921 int use_existing_cu
, int keep
,
924 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
925 struct dwarf2_cu
*parent_cu
= nullptr,
926 struct dwo_file
*dwo_file
= nullptr);
930 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
932 const gdb_byte
*info_ptr
= nullptr;
933 struct die_info
*comp_unit_die
= nullptr;
934 int has_children
= 0;
935 bool dummy_p
= false;
938 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
939 int use_existing_cu
, int keep
);
941 struct dwarf2_per_cu_data
*m_this_cu
;
943 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
945 /* The ordinary abbreviation table. */
946 abbrev_table_up m_abbrev_table_holder
;
948 /* The DWO abbreviation table. */
949 abbrev_table_up m_dwo_abbrev_table
;
952 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
954 typedef int dir_index
;
956 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
958 typedef int file_name_index
;
962 file_entry () = default;
964 file_entry (const char *name_
, dir_index d_index_
,
965 unsigned int mod_time_
, unsigned int length_
)
968 mod_time (mod_time_
),
972 /* Return the include directory at D_INDEX stored in LH. Returns
973 NULL if D_INDEX is out of bounds. */
974 const char *include_dir (const line_header
*lh
) const;
976 /* The file name. Note this is an observing pointer. The memory is
977 owned by debug_line_buffer. */
980 /* The directory index (1-based). */
981 dir_index d_index
{};
983 unsigned int mod_time
{};
985 unsigned int length
{};
987 /* True if referenced by the Line Number Program. */
990 /* The associated symbol table, if any. */
991 struct symtab
*symtab
{};
994 /* The line number information for a compilation unit (found in the
995 .debug_line section) begins with a "statement program header",
996 which contains the following information. */
1003 /* Add an entry to the include directory table. */
1004 void add_include_dir (const char *include_dir
);
1006 /* Add an entry to the file name table. */
1007 void add_file_name (const char *name
, dir_index d_index
,
1008 unsigned int mod_time
, unsigned int length
);
1010 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1011 Returns NULL if INDEX is out of bounds. */
1012 const char *include_dir_at (dir_index index
) const
1018 vec_index
= index
- 1;
1019 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1021 return m_include_dirs
[vec_index
];
1024 bool is_valid_file_index (int file_index
)
1027 return 0 <= file_index
&& file_index
< file_names_size ();
1028 return 1 <= file_index
&& file_index
<= file_names_size ();
1031 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1032 Returns NULL if INDEX is out of bounds. */
1033 file_entry
*file_name_at (file_name_index index
)
1039 vec_index
= index
- 1;
1040 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1042 return &m_file_names
[vec_index
];
1045 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1046 this method should only be used to iterate through all file entries in an
1047 index-agnostic manner. */
1048 std::vector
<file_entry
> &file_names ()
1049 { return m_file_names
; }
1051 /* Offset of line number information in .debug_line section. */
1052 sect_offset sect_off
{};
1054 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1055 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1057 unsigned int total_length
{};
1058 unsigned short version
{};
1059 unsigned int header_length
{};
1060 unsigned char minimum_instruction_length
{};
1061 unsigned char maximum_ops_per_instruction
{};
1062 unsigned char default_is_stmt
{};
1064 unsigned char line_range
{};
1065 unsigned char opcode_base
{};
1067 /* standard_opcode_lengths[i] is the number of operands for the
1068 standard opcode whose value is i. This means that
1069 standard_opcode_lengths[0] is unused, and the last meaningful
1070 element is standard_opcode_lengths[opcode_base - 1]. */
1071 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1073 int file_names_size ()
1074 { return m_file_names
.size(); }
1076 /* The start and end of the statement program following this
1077 header. These point into dwarf2_per_objfile->line_buffer. */
1078 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1081 /* The include_directories table. Note these are observing
1082 pointers. The memory is owned by debug_line_buffer. */
1083 std::vector
<const char *> m_include_dirs
;
1085 /* The file_names table. This is private because the meaning of indexes
1086 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1087 before, and is 0 in DWARF 5 and later). So the client should use
1088 file_name_at method for access. */
1089 std::vector
<file_entry
> m_file_names
;
1092 typedef std::unique_ptr
<line_header
> line_header_up
;
1095 file_entry::include_dir (const line_header
*lh
) const
1097 return lh
->include_dir_at (d_index
);
1100 /* When we construct a partial symbol table entry we only
1101 need this much information. */
1102 struct partial_die_info
: public allocate_on_obstack
1104 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1106 /* Disable assign but still keep copy ctor, which is needed
1107 load_partial_dies. */
1108 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1110 /* Adjust the partial die before generating a symbol for it. This
1111 function may set the is_external flag or change the DIE's
1113 void fixup (struct dwarf2_cu
*cu
);
1115 /* Read a minimal amount of information into the minimal die
1117 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1118 const struct abbrev_info
&abbrev
,
1119 const gdb_byte
*info_ptr
);
1121 /* Offset of this DIE. */
1122 const sect_offset sect_off
;
1124 /* DWARF-2 tag for this DIE. */
1125 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1127 /* Assorted flags describing the data found in this DIE. */
1128 const unsigned int has_children
: 1;
1130 unsigned int is_external
: 1;
1131 unsigned int is_declaration
: 1;
1132 unsigned int has_type
: 1;
1133 unsigned int has_specification
: 1;
1134 unsigned int has_pc_info
: 1;
1135 unsigned int may_be_inlined
: 1;
1137 /* This DIE has been marked DW_AT_main_subprogram. */
1138 unsigned int main_subprogram
: 1;
1140 /* Flag set if the SCOPE field of this structure has been
1142 unsigned int scope_set
: 1;
1144 /* Flag set if the DIE has a byte_size attribute. */
1145 unsigned int has_byte_size
: 1;
1147 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1148 unsigned int has_const_value
: 1;
1150 /* Flag set if any of the DIE's children are template arguments. */
1151 unsigned int has_template_arguments
: 1;
1153 /* Flag set if fixup has been called on this die. */
1154 unsigned int fixup_called
: 1;
1156 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1157 unsigned int is_dwz
: 1;
1159 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1160 unsigned int spec_is_dwz
: 1;
1162 /* The name of this DIE. Normally the value of DW_AT_name, but
1163 sometimes a default name for unnamed DIEs. */
1164 const char *name
= nullptr;
1166 /* The linkage name, if present. */
1167 const char *linkage_name
= nullptr;
1169 /* The scope to prepend to our children. This is generally
1170 allocated on the comp_unit_obstack, so will disappear
1171 when this compilation unit leaves the cache. */
1172 const char *scope
= nullptr;
1174 /* Some data associated with the partial DIE. The tag determines
1175 which field is live. */
1178 /* The location description associated with this DIE, if any. */
1179 struct dwarf_block
*locdesc
;
1180 /* The offset of an import, for DW_TAG_imported_unit. */
1181 sect_offset sect_off
;
1184 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1185 CORE_ADDR lowpc
= 0;
1186 CORE_ADDR highpc
= 0;
1188 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1189 DW_AT_sibling, if any. */
1190 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1191 could return DW_AT_sibling values to its caller load_partial_dies. */
1192 const gdb_byte
*sibling
= nullptr;
1194 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1195 DW_AT_specification (or DW_AT_abstract_origin or
1196 DW_AT_extension). */
1197 sect_offset spec_offset
{};
1199 /* Pointers to this DIE's parent, first child, and next sibling,
1201 struct partial_die_info
*die_parent
= nullptr;
1202 struct partial_die_info
*die_child
= nullptr;
1203 struct partial_die_info
*die_sibling
= nullptr;
1205 friend struct partial_die_info
*
1206 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1209 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1210 partial_die_info (sect_offset sect_off
)
1211 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1215 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1217 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1222 has_specification
= 0;
1225 main_subprogram
= 0;
1228 has_const_value
= 0;
1229 has_template_arguments
= 0;
1236 /* Attributes have a name and a value. */
1239 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1240 ENUM_BITFIELD(dwarf_form
) form
: 15;
1242 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1243 field should be in u.str (existing only for DW_STRING) but it is kept
1244 here for better struct attribute alignment. */
1245 unsigned int string_is_canonical
: 1;
1250 struct dwarf_block
*blk
;
1259 /* This data structure holds a complete die structure. */
1262 /* DWARF-2 tag for this DIE. */
1263 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1265 /* Number of attributes */
1266 unsigned char num_attrs
;
1268 /* True if we're presently building the full type name for the
1269 type derived from this DIE. */
1270 unsigned char building_fullname
: 1;
1272 /* True if this die is in process. PR 16581. */
1273 unsigned char in_process
: 1;
1276 unsigned int abbrev
;
1278 /* Offset in .debug_info or .debug_types section. */
1279 sect_offset sect_off
;
1281 /* The dies in a compilation unit form an n-ary tree. PARENT
1282 points to this die's parent; CHILD points to the first child of
1283 this node; and all the children of a given node are chained
1284 together via their SIBLING fields. */
1285 struct die_info
*child
; /* Its first child, if any. */
1286 struct die_info
*sibling
; /* Its next sibling, if any. */
1287 struct die_info
*parent
; /* Its parent, if any. */
1289 /* An array of attributes, with NUM_ATTRS elements. There may be
1290 zero, but it's not common and zero-sized arrays are not
1291 sufficiently portable C. */
1292 struct attribute attrs
[1];
1295 /* Get at parts of an attribute structure. */
1297 #define DW_STRING(attr) ((attr)->u.str)
1298 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1299 #define DW_UNSND(attr) ((attr)->u.unsnd)
1300 #define DW_BLOCK(attr) ((attr)->u.blk)
1301 #define DW_SND(attr) ((attr)->u.snd)
1302 #define DW_ADDR(attr) ((attr)->u.addr)
1303 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1305 /* Blocks are a bunch of untyped bytes. */
1310 /* Valid only if SIZE is not zero. */
1311 const gdb_byte
*data
;
1314 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1315 but this would require a corresponding change in unpack_field_as_long
1317 static int bits_per_byte
= 8;
1319 /* When reading a variant or variant part, we track a bit more
1320 information about the field, and store it in an object of this
1323 struct variant_field
1325 /* If we see a DW_TAG_variant, then this will be the discriminant
1327 ULONGEST discriminant_value
;
1328 /* If we see a DW_TAG_variant, then this will be set if this is the
1330 bool default_branch
;
1331 /* While reading a DW_TAG_variant_part, this will be set if this
1332 field is the discriminant. */
1333 bool is_discriminant
;
1338 int accessibility
= 0;
1340 /* Extra information to describe a variant or variant part. */
1341 struct variant_field variant
{};
1342 struct field field
{};
1347 const char *name
= nullptr;
1348 std::vector
<struct fn_field
> fnfields
;
1351 /* The routines that read and process dies for a C struct or C++ class
1352 pass lists of data member fields and lists of member function fields
1353 in an instance of a field_info structure, as defined below. */
1356 /* List of data member and baseclasses fields. */
1357 std::vector
<struct nextfield
> fields
;
1358 std::vector
<struct nextfield
> baseclasses
;
1360 /* Number of fields (including baseclasses). */
1363 /* Set if the accessibility of one of the fields is not public. */
1364 int non_public_fields
= 0;
1366 /* Member function fieldlist array, contains name of possibly overloaded
1367 member function, number of overloaded member functions and a pointer
1368 to the head of the member function field chain. */
1369 std::vector
<struct fnfieldlist
> fnfieldlists
;
1371 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1372 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1373 std::vector
<struct decl_field
> typedef_field_list
;
1375 /* Nested types defined by this class and the number of elements in this
1377 std::vector
<struct decl_field
> nested_types_list
;
1380 /* One item on the queue of compilation units to read in full symbols
1382 struct dwarf2_queue_item
1384 struct dwarf2_per_cu_data
*per_cu
;
1385 enum language pretend_language
;
1386 struct dwarf2_queue_item
*next
;
1389 /* The current queue. */
1390 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1392 /* Loaded secondary compilation units are kept in memory until they
1393 have not been referenced for the processing of this many
1394 compilation units. Set this to zero to disable caching. Cache
1395 sizes of up to at least twenty will improve startup time for
1396 typical inter-CU-reference binaries, at an obvious memory cost. */
1397 static int dwarf_max_cache_age
= 5;
1399 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1400 struct cmd_list_element
*c
, const char *value
)
1402 fprintf_filtered (file
, _("The upper bound on the age of cached "
1403 "DWARF compilation units is %s.\n"),
1407 /* local function prototypes */
1409 static void dwarf2_find_base_address (struct die_info
*die
,
1410 struct dwarf2_cu
*cu
);
1412 static dwarf2_psymtab
*create_partial_symtab
1413 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1415 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1416 const gdb_byte
*info_ptr
,
1417 struct die_info
*type_unit_die
,
1420 static void dwarf2_build_psymtabs_hard
1421 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1423 static void scan_partial_symbols (struct partial_die_info
*,
1424 CORE_ADDR
*, CORE_ADDR
*,
1425 int, struct dwarf2_cu
*);
1427 static void add_partial_symbol (struct partial_die_info
*,
1428 struct dwarf2_cu
*);
1430 static void add_partial_namespace (struct partial_die_info
*pdi
,
1431 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1432 int set_addrmap
, struct dwarf2_cu
*cu
);
1434 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1435 CORE_ADDR
*highpc
, int set_addrmap
,
1436 struct dwarf2_cu
*cu
);
1438 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1439 struct dwarf2_cu
*cu
);
1441 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1442 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1443 int need_pc
, struct dwarf2_cu
*cu
);
1445 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1447 static struct partial_die_info
*load_partial_dies
1448 (const struct die_reader_specs
*, const gdb_byte
*, int);
1450 /* A pair of partial_die_info and compilation unit. */
1451 struct cu_partial_die_info
1453 /* The compilation unit of the partial_die_info. */
1454 struct dwarf2_cu
*cu
;
1455 /* A partial_die_info. */
1456 struct partial_die_info
*pdi
;
1458 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1464 cu_partial_die_info () = delete;
1467 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1468 struct dwarf2_cu
*);
1470 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1471 struct attribute
*, struct attr_abbrev
*,
1472 const gdb_byte
*, bool *need_reprocess
);
1474 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1475 struct attribute
*attr
);
1477 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1479 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1482 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1484 static LONGEST read_checked_initial_length_and_offset
1485 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1486 unsigned int *, unsigned int *);
1488 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1489 const struct comp_unit_head
*,
1492 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1494 static sect_offset read_abbrev_offset
1495 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1496 struct dwarf2_section_info
*, sect_offset
);
1498 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1500 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1502 static const char *read_indirect_string
1503 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1504 const struct comp_unit_head
*, unsigned int *);
1506 static const char *read_indirect_line_string
1507 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1508 const struct comp_unit_head
*, unsigned int *);
1510 static const char *read_indirect_string_at_offset
1511 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1512 LONGEST str_offset
);
1514 static const char *read_indirect_string_from_dwz
1515 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1517 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1521 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1522 ULONGEST str_index
);
1524 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1525 ULONGEST str_index
);
1527 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1529 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1530 struct dwarf2_cu
*);
1532 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1535 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1536 struct dwarf2_cu
*cu
);
1538 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1540 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1541 struct dwarf2_cu
*cu
);
1543 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1545 static struct die_info
*die_specification (struct die_info
*die
,
1546 struct dwarf2_cu
**);
1548 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1549 struct dwarf2_cu
*cu
);
1551 static void dwarf_decode_lines (struct line_header
*, const char *,
1552 struct dwarf2_cu
*, dwarf2_psymtab
*,
1553 CORE_ADDR
, int decode_mapping
);
1555 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1558 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1559 struct dwarf2_cu
*, struct symbol
* = NULL
);
1561 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1562 struct dwarf2_cu
*);
1564 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1567 struct obstack
*obstack
,
1568 struct dwarf2_cu
*cu
, LONGEST
*value
,
1569 const gdb_byte
**bytes
,
1570 struct dwarf2_locexpr_baton
**baton
);
1572 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1574 static int need_gnat_info (struct dwarf2_cu
*);
1576 static struct type
*die_descriptive_type (struct die_info
*,
1577 struct dwarf2_cu
*);
1579 static void set_descriptive_type (struct type
*, struct die_info
*,
1580 struct dwarf2_cu
*);
1582 static struct type
*die_containing_type (struct die_info
*,
1583 struct dwarf2_cu
*);
1585 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1586 struct dwarf2_cu
*);
1588 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1590 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1592 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1594 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1595 const char *suffix
, int physname
,
1596 struct dwarf2_cu
*cu
);
1598 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1600 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1602 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1604 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1606 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1608 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1610 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1611 struct dwarf2_cu
*, dwarf2_psymtab
*);
1613 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1614 values. Keep the items ordered with increasing constraints compliance. */
1617 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1618 PC_BOUNDS_NOT_PRESENT
,
1620 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1621 were present but they do not form a valid range of PC addresses. */
1624 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1627 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1631 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1632 CORE_ADDR
*, CORE_ADDR
*,
1636 static void get_scope_pc_bounds (struct die_info
*,
1637 CORE_ADDR
*, CORE_ADDR
*,
1638 struct dwarf2_cu
*);
1640 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1641 CORE_ADDR
, struct dwarf2_cu
*);
1643 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1644 struct dwarf2_cu
*);
1646 static void dwarf2_attach_fields_to_type (struct field_info
*,
1647 struct type
*, struct dwarf2_cu
*);
1649 static void dwarf2_add_member_fn (struct field_info
*,
1650 struct die_info
*, struct type
*,
1651 struct dwarf2_cu
*);
1653 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1655 struct dwarf2_cu
*);
1657 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1659 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1661 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1663 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1665 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1667 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1669 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1671 static struct type
*read_module_type (struct die_info
*die
,
1672 struct dwarf2_cu
*cu
);
1674 static const char *namespace_name (struct die_info
*die
,
1675 int *is_anonymous
, struct dwarf2_cu
*);
1677 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1679 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1681 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1682 struct dwarf2_cu
*);
1684 static struct die_info
*read_die_and_siblings_1
1685 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1688 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1689 const gdb_byte
*info_ptr
,
1690 const gdb_byte
**new_info_ptr
,
1691 struct die_info
*parent
);
1693 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1694 struct die_info
**, const gdb_byte
*,
1697 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1698 struct die_info
**, const gdb_byte
*,
1701 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1703 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1706 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1708 static const char *dwarf2_full_name (const char *name
,
1709 struct die_info
*die
,
1710 struct dwarf2_cu
*cu
);
1712 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1713 struct dwarf2_cu
*cu
);
1715 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1716 struct dwarf2_cu
**);
1718 static const char *dwarf_tag_name (unsigned int);
1720 static const char *dwarf_attr_name (unsigned int);
1722 static const char *dwarf_unit_type_name (int unit_type
);
1724 static const char *dwarf_form_name (unsigned int);
1726 static const char *dwarf_bool_name (unsigned int);
1728 static const char *dwarf_type_encoding_name (unsigned int);
1730 static struct die_info
*sibling_die (struct die_info
*);
1732 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1734 static void dump_die_for_error (struct die_info
*);
1736 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1739 /*static*/ void dump_die (struct die_info
*, int max_level
);
1741 static void store_in_ref_table (struct die_info
*,
1742 struct dwarf2_cu
*);
1744 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1746 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1748 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1749 const struct attribute
*,
1750 struct dwarf2_cu
**);
1752 static struct die_info
*follow_die_ref (struct die_info
*,
1753 const struct attribute
*,
1754 struct dwarf2_cu
**);
1756 static struct die_info
*follow_die_sig (struct die_info
*,
1757 const struct attribute
*,
1758 struct dwarf2_cu
**);
1760 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1761 struct dwarf2_cu
*);
1763 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1764 const struct attribute
*,
1765 struct dwarf2_cu
*);
1767 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1769 static void read_signatured_type (struct signatured_type
*);
1771 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1772 struct die_info
*die
, struct dwarf2_cu
*cu
,
1773 struct dynamic_prop
*prop
, struct type
*type
);
1775 /* memory allocation interface */
1777 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1779 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1781 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1783 static int attr_form_is_block (const struct attribute
*);
1785 static int attr_form_is_section_offset (const struct attribute
*);
1787 static int attr_form_is_constant (const struct attribute
*);
1789 static int attr_form_is_ref (const struct attribute
*);
1791 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1792 struct dwarf2_loclist_baton
*baton
,
1793 const struct attribute
*attr
);
1795 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1797 struct dwarf2_cu
*cu
,
1800 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1801 const gdb_byte
*info_ptr
,
1802 struct abbrev_info
*abbrev
);
1804 static hashval_t
partial_die_hash (const void *item
);
1806 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1808 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1809 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1810 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1812 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1813 struct die_info
*comp_unit_die
,
1814 enum language pretend_language
);
1816 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1818 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1820 static struct type
*set_die_type (struct die_info
*, struct type
*,
1821 struct dwarf2_cu
*);
1823 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1825 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1827 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1830 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1833 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1836 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1837 struct dwarf2_per_cu_data
*);
1839 static void dwarf2_mark (struct dwarf2_cu
*);
1841 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1843 static struct type
*get_die_type_at_offset (sect_offset
,
1844 struct dwarf2_per_cu_data
*);
1846 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1848 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1849 enum language pretend_language
);
1851 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1853 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1854 static struct type
*dwarf2_per_cu_addr_sized_int_type
1855 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1856 static struct type
*dwarf2_per_cu_int_type
1857 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1860 /* Class, the destructor of which frees all allocated queue entries. This
1861 will only have work to do if an error was thrown while processing the
1862 dwarf. If no error was thrown then the queue entries should have all
1863 been processed, and freed, as we went along. */
1865 class dwarf2_queue_guard
1868 dwarf2_queue_guard () = default;
1870 /* Free any entries remaining on the queue. There should only be
1871 entries left if we hit an error while processing the dwarf. */
1872 ~dwarf2_queue_guard ()
1874 struct dwarf2_queue_item
*item
, *last
;
1876 item
= dwarf2_queue
;
1879 /* Anything still marked queued is likely to be in an
1880 inconsistent state, so discard it. */
1881 if (item
->per_cu
->queued
)
1883 if (item
->per_cu
->cu
!= NULL
)
1884 free_one_cached_comp_unit (item
->per_cu
);
1885 item
->per_cu
->queued
= 0;
1893 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1897 /* The return type of find_file_and_directory. Note, the enclosed
1898 string pointers are only valid while this object is valid. */
1900 struct file_and_directory
1902 /* The filename. This is never NULL. */
1905 /* The compilation directory. NULL if not known. If we needed to
1906 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1907 points directly to the DW_AT_comp_dir string attribute owned by
1908 the obstack that owns the DIE. */
1909 const char *comp_dir
;
1911 /* If we needed to build a new string for comp_dir, this is what
1912 owns the storage. */
1913 std::string comp_dir_storage
;
1916 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1917 struct dwarf2_cu
*cu
);
1919 static char *file_full_name (int file
, struct line_header
*lh
,
1920 const char *comp_dir
);
1922 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1923 enum class rcuh_kind
{ COMPILE
, TYPE
};
1925 static const gdb_byte
*read_and_check_comp_unit_head
1926 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1927 struct comp_unit_head
*header
,
1928 struct dwarf2_section_info
*section
,
1929 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1930 rcuh_kind section_kind
);
1932 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1934 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1936 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1937 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1938 struct dwp_file
*dwp_file
, const char *comp_dir
,
1939 ULONGEST signature
, int is_debug_types
);
1941 static struct dwp_file
*get_dwp_file
1942 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1944 static struct dwo_unit
*lookup_dwo_comp_unit
1945 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1947 static struct dwo_unit
*lookup_dwo_type_unit
1948 (struct signatured_type
*, const char *, const char *);
1950 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1952 /* A unique pointer to a dwo_file. */
1954 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1956 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1958 static void check_producer (struct dwarf2_cu
*cu
);
1960 static void free_line_header_voidp (void *arg
);
1962 /* Various complaints about symbol reading that don't abort the process. */
1965 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
1967 complaint (_("statement list doesn't fit in .debug_line section"));
1971 dwarf2_debug_line_missing_file_complaint (void)
1973 complaint (_(".debug_line section has line data without a file"));
1977 dwarf2_debug_line_missing_end_sequence_complaint (void)
1979 complaint (_(".debug_line section has line "
1980 "program sequence without an end"));
1984 dwarf2_complex_location_expr_complaint (void)
1986 complaint (_("location expression too complex"));
1990 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
1993 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
1998 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2000 complaint (_("debug info runs off end of %s section"
2002 section
->get_name (),
2003 section
->get_file_name ());
2007 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2009 complaint (_("macro debug info contains a "
2010 "malformed macro definition:\n`%s'"),
2015 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2017 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2021 /* Hash function for line_header_hash. */
2024 line_header_hash (const struct line_header
*ofs
)
2026 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2029 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2032 line_header_hash_voidp (const void *item
)
2034 const struct line_header
*ofs
= (const struct line_header
*) item
;
2036 return line_header_hash (ofs
);
2039 /* Equality function for line_header_hash. */
2042 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2044 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2045 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2047 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2048 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2053 /* Read the given attribute value as an address, taking the attribute's
2054 form into account. */
2057 attr_value_as_address (struct attribute
*attr
)
2061 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2062 && attr
->form
!= DW_FORM_GNU_addr_index
)
2064 /* Aside from a few clearly defined exceptions, attributes that
2065 contain an address must always be in DW_FORM_addr form.
2066 Unfortunately, some compilers happen to be violating this
2067 requirement by encoding addresses using other forms, such
2068 as DW_FORM_data4 for example. For those broken compilers,
2069 we try to do our best, without any guarantee of success,
2070 to interpret the address correctly. It would also be nice
2071 to generate a complaint, but that would require us to maintain
2072 a list of legitimate cases where a non-address form is allowed,
2073 as well as update callers to pass in at least the CU's DWARF
2074 version. This is more overhead than what we're willing to
2075 expand for a pretty rare case. */
2076 addr
= DW_UNSND (attr
);
2079 addr
= DW_ADDR (attr
);
2084 /* See declaration. */
2086 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2087 const dwarf2_debug_sections
*names
,
2089 : objfile (objfile_
),
2090 can_copy (can_copy_
)
2093 names
= &dwarf2_elf_names
;
2095 bfd
*obfd
= objfile
->obfd
;
2097 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2098 locate_sections (obfd
, sec
, *names
);
2101 dwarf2_per_objfile::~dwarf2_per_objfile ()
2103 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2104 free_cached_comp_units ();
2106 if (quick_file_names_table
)
2107 htab_delete (quick_file_names_table
);
2109 if (line_header_hash
)
2110 htab_delete (line_header_hash
);
2112 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2113 per_cu
->imported_symtabs_free ();
2115 for (signatured_type
*sig_type
: all_type_units
)
2116 sig_type
->per_cu
.imported_symtabs_free ();
2118 /* Everything else should be on the objfile obstack. */
2121 /* See declaration. */
2124 dwarf2_per_objfile::free_cached_comp_units ()
2126 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2127 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2128 while (per_cu
!= NULL
)
2130 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2133 *last_chain
= next_cu
;
2138 /* A helper class that calls free_cached_comp_units on
2141 class free_cached_comp_units
2145 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2146 : m_per_objfile (per_objfile
)
2150 ~free_cached_comp_units ()
2152 m_per_objfile
->free_cached_comp_units ();
2155 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2159 dwarf2_per_objfile
*m_per_objfile
;
2162 /* Try to locate the sections we need for DWARF 2 debugging
2163 information and return true if we have enough to do something.
2164 NAMES points to the dwarf2 section names, or is NULL if the standard
2165 ELF names are used. CAN_COPY is true for formats where symbol
2166 interposition is possible and so symbol values must follow copy
2167 relocation rules. */
2170 dwarf2_has_info (struct objfile
*objfile
,
2171 const struct dwarf2_debug_sections
*names
,
2174 if (objfile
->flags
& OBJF_READNEVER
)
2177 struct dwarf2_per_objfile
*dwarf2_per_objfile
2178 = get_dwarf2_per_objfile (objfile
);
2180 if (dwarf2_per_objfile
== NULL
)
2181 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2185 return (!dwarf2_per_objfile
->info
.is_virtual
2186 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2187 && !dwarf2_per_objfile
->abbrev
.is_virtual
2188 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2191 /* When loading sections, we look either for uncompressed section or for
2192 compressed section names. */
2195 section_is_p (const char *section_name
,
2196 const struct dwarf2_section_names
*names
)
2198 if (names
->normal
!= NULL
2199 && strcmp (section_name
, names
->normal
) == 0)
2201 if (names
->compressed
!= NULL
2202 && strcmp (section_name
, names
->compressed
) == 0)
2207 /* See declaration. */
2210 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2211 const dwarf2_debug_sections
&names
)
2213 flagword aflag
= bfd_section_flags (sectp
);
2215 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2218 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2219 > bfd_get_file_size (abfd
))
2221 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2222 warning (_("Discarding section %s which has a section size (%s"
2223 ") larger than the file size [in module %s]"),
2224 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2225 bfd_get_filename (abfd
));
2227 else if (section_is_p (sectp
->name
, &names
.info
))
2229 this->info
.s
.section
= sectp
;
2230 this->info
.size
= bfd_section_size (sectp
);
2232 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2234 this->abbrev
.s
.section
= sectp
;
2235 this->abbrev
.size
= bfd_section_size (sectp
);
2237 else if (section_is_p (sectp
->name
, &names
.line
))
2239 this->line
.s
.section
= sectp
;
2240 this->line
.size
= bfd_section_size (sectp
);
2242 else if (section_is_p (sectp
->name
, &names
.loc
))
2244 this->loc
.s
.section
= sectp
;
2245 this->loc
.size
= bfd_section_size (sectp
);
2247 else if (section_is_p (sectp
->name
, &names
.loclists
))
2249 this->loclists
.s
.section
= sectp
;
2250 this->loclists
.size
= bfd_section_size (sectp
);
2252 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2254 this->macinfo
.s
.section
= sectp
;
2255 this->macinfo
.size
= bfd_section_size (sectp
);
2257 else if (section_is_p (sectp
->name
, &names
.macro
))
2259 this->macro
.s
.section
= sectp
;
2260 this->macro
.size
= bfd_section_size (sectp
);
2262 else if (section_is_p (sectp
->name
, &names
.str
))
2264 this->str
.s
.section
= sectp
;
2265 this->str
.size
= bfd_section_size (sectp
);
2267 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2269 this->str_offsets
.s
.section
= sectp
;
2270 this->str_offsets
.size
= bfd_section_size (sectp
);
2272 else if (section_is_p (sectp
->name
, &names
.line_str
))
2274 this->line_str
.s
.section
= sectp
;
2275 this->line_str
.size
= bfd_section_size (sectp
);
2277 else if (section_is_p (sectp
->name
, &names
.addr
))
2279 this->addr
.s
.section
= sectp
;
2280 this->addr
.size
= bfd_section_size (sectp
);
2282 else if (section_is_p (sectp
->name
, &names
.frame
))
2284 this->frame
.s
.section
= sectp
;
2285 this->frame
.size
= bfd_section_size (sectp
);
2287 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2289 this->eh_frame
.s
.section
= sectp
;
2290 this->eh_frame
.size
= bfd_section_size (sectp
);
2292 else if (section_is_p (sectp
->name
, &names
.ranges
))
2294 this->ranges
.s
.section
= sectp
;
2295 this->ranges
.size
= bfd_section_size (sectp
);
2297 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2299 this->rnglists
.s
.section
= sectp
;
2300 this->rnglists
.size
= bfd_section_size (sectp
);
2302 else if (section_is_p (sectp
->name
, &names
.types
))
2304 struct dwarf2_section_info type_section
;
2306 memset (&type_section
, 0, sizeof (type_section
));
2307 type_section
.s
.section
= sectp
;
2308 type_section
.size
= bfd_section_size (sectp
);
2310 this->types
.push_back (type_section
);
2312 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2314 this->gdb_index
.s
.section
= sectp
;
2315 this->gdb_index
.size
= bfd_section_size (sectp
);
2317 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2319 this->debug_names
.s
.section
= sectp
;
2320 this->debug_names
.size
= bfd_section_size (sectp
);
2322 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2324 this->debug_aranges
.s
.section
= sectp
;
2325 this->debug_aranges
.size
= bfd_section_size (sectp
);
2328 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2329 && bfd_section_vma (sectp
) == 0)
2330 this->has_section_at_zero
= true;
2333 /* A helper function that returns the size of a section in a safe way.
2334 If you are positive that the section has been read before using the
2335 size, then it is safe to refer to the dwarf2_section_info object's
2336 "size" field directly. In other cases, you must call this
2337 function, because for compressed sections the size field is not set
2338 correctly until the section has been read. */
2340 static bfd_size_type
2341 dwarf2_section_size (struct objfile
*objfile
,
2342 struct dwarf2_section_info
*info
)
2345 info
->read (objfile
);
2349 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2353 dwarf2_get_section_info (struct objfile
*objfile
,
2354 enum dwarf2_section_enum sect
,
2355 asection
**sectp
, const gdb_byte
**bufp
,
2356 bfd_size_type
*sizep
)
2358 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2359 struct dwarf2_section_info
*info
;
2361 /* We may see an objfile without any DWARF, in which case we just
2372 case DWARF2_DEBUG_FRAME
:
2373 info
= &data
->frame
;
2375 case DWARF2_EH_FRAME
:
2376 info
= &data
->eh_frame
;
2379 gdb_assert_not_reached ("unexpected section");
2382 info
->read (objfile
);
2384 *sectp
= info
->get_bfd_section ();
2385 *bufp
= info
->buffer
;
2386 *sizep
= info
->size
;
2389 /* A helper function to find the sections for a .dwz file. */
2392 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2394 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2396 /* Note that we only support the standard ELF names, because .dwz
2397 is ELF-only (at the time of writing). */
2398 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2400 dwz_file
->abbrev
.s
.section
= sectp
;
2401 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2403 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2405 dwz_file
->info
.s
.section
= sectp
;
2406 dwz_file
->info
.size
= bfd_section_size (sectp
);
2408 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2410 dwz_file
->str
.s
.section
= sectp
;
2411 dwz_file
->str
.size
= bfd_section_size (sectp
);
2413 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2415 dwz_file
->line
.s
.section
= sectp
;
2416 dwz_file
->line
.size
= bfd_section_size (sectp
);
2418 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2420 dwz_file
->macro
.s
.section
= sectp
;
2421 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2423 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2425 dwz_file
->gdb_index
.s
.section
= sectp
;
2426 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2428 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2430 dwz_file
->debug_names
.s
.section
= sectp
;
2431 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2435 /* See dwarf2read.h. */
2438 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2440 const char *filename
;
2441 bfd_size_type buildid_len_arg
;
2445 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2446 return dwarf2_per_objfile
->dwz_file
.get ();
2448 bfd_set_error (bfd_error_no_error
);
2449 gdb::unique_xmalloc_ptr
<char> data
2450 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2451 &buildid_len_arg
, &buildid
));
2454 if (bfd_get_error () == bfd_error_no_error
)
2456 error (_("could not read '.gnu_debugaltlink' section: %s"),
2457 bfd_errmsg (bfd_get_error ()));
2460 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2462 buildid_len
= (size_t) buildid_len_arg
;
2464 filename
= data
.get ();
2466 std::string abs_storage
;
2467 if (!IS_ABSOLUTE_PATH (filename
))
2469 gdb::unique_xmalloc_ptr
<char> abs
2470 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2472 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2473 filename
= abs_storage
.c_str ();
2476 /* First try the file name given in the section. If that doesn't
2477 work, try to use the build-id instead. */
2478 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2479 if (dwz_bfd
!= NULL
)
2481 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2482 dwz_bfd
.reset (nullptr);
2485 if (dwz_bfd
== NULL
)
2486 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2488 if (dwz_bfd
== NULL
)
2489 error (_("could not find '.gnu_debugaltlink' file for %s"),
2490 objfile_name (dwarf2_per_objfile
->objfile
));
2492 std::unique_ptr
<struct dwz_file
> result
2493 (new struct dwz_file (std::move (dwz_bfd
)));
2495 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2498 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2499 result
->dwz_bfd
.get ());
2500 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2501 return dwarf2_per_objfile
->dwz_file
.get ();
2504 /* DWARF quick_symbols_functions support. */
2506 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2507 unique line tables, so we maintain a separate table of all .debug_line
2508 derived entries to support the sharing.
2509 All the quick functions need is the list of file names. We discard the
2510 line_header when we're done and don't need to record it here. */
2511 struct quick_file_names
2513 /* The data used to construct the hash key. */
2514 struct stmt_list_hash hash
;
2516 /* The number of entries in file_names, real_names. */
2517 unsigned int num_file_names
;
2519 /* The file names from the line table, after being run through
2521 const char **file_names
;
2523 /* The file names from the line table after being run through
2524 gdb_realpath. These are computed lazily. */
2525 const char **real_names
;
2528 /* When using the index (and thus not using psymtabs), each CU has an
2529 object of this type. This is used to hold information needed by
2530 the various "quick" methods. */
2531 struct dwarf2_per_cu_quick_data
2533 /* The file table. This can be NULL if there was no file table
2534 or it's currently not read in.
2535 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2536 struct quick_file_names
*file_names
;
2538 /* The corresponding symbol table. This is NULL if symbols for this
2539 CU have not yet been read. */
2540 struct compunit_symtab
*compunit_symtab
;
2542 /* A temporary mark bit used when iterating over all CUs in
2543 expand_symtabs_matching. */
2544 unsigned int mark
: 1;
2546 /* True if we've tried to read the file table and found there isn't one.
2547 There will be no point in trying to read it again next time. */
2548 unsigned int no_file_data
: 1;
2551 /* Utility hash function for a stmt_list_hash. */
2554 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2558 if (stmt_list_hash
->dwo_unit
!= NULL
)
2559 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2560 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2564 /* Utility equality function for a stmt_list_hash. */
2567 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2568 const struct stmt_list_hash
*rhs
)
2570 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2572 if (lhs
->dwo_unit
!= NULL
2573 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2576 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2579 /* Hash function for a quick_file_names. */
2582 hash_file_name_entry (const void *e
)
2584 const struct quick_file_names
*file_data
2585 = (const struct quick_file_names
*) e
;
2587 return hash_stmt_list_entry (&file_data
->hash
);
2590 /* Equality function for a quick_file_names. */
2593 eq_file_name_entry (const void *a
, const void *b
)
2595 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2596 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2598 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2601 /* Delete function for a quick_file_names. */
2604 delete_file_name_entry (void *e
)
2606 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2609 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2611 xfree ((void*) file_data
->file_names
[i
]);
2612 if (file_data
->real_names
)
2613 xfree ((void*) file_data
->real_names
[i
]);
2616 /* The space for the struct itself lives on objfile_obstack,
2617 so we don't free it here. */
2620 /* Create a quick_file_names hash table. */
2623 create_quick_file_names_table (unsigned int nr_initial_entries
)
2625 return htab_create_alloc (nr_initial_entries
,
2626 hash_file_name_entry
, eq_file_name_entry
,
2627 delete_file_name_entry
, xcalloc
, xfree
);
2630 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2631 have to be created afterwards. You should call age_cached_comp_units after
2632 processing PER_CU->CU. dw2_setup must have been already called. */
2635 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2637 if (per_cu
->is_debug_types
)
2638 load_full_type_unit (per_cu
);
2640 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2642 if (per_cu
->cu
== NULL
)
2643 return; /* Dummy CU. */
2645 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2648 /* Read in the symbols for PER_CU. */
2651 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2653 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2655 /* Skip type_unit_groups, reading the type units they contain
2656 is handled elsewhere. */
2657 if (IS_TYPE_UNIT_GROUP (per_cu
))
2660 /* The destructor of dwarf2_queue_guard frees any entries left on
2661 the queue. After this point we're guaranteed to leave this function
2662 with the dwarf queue empty. */
2663 dwarf2_queue_guard q_guard
;
2665 if (dwarf2_per_objfile
->using_index
2666 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2667 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2669 queue_comp_unit (per_cu
, language_minimal
);
2670 load_cu (per_cu
, skip_partial
);
2672 /* If we just loaded a CU from a DWO, and we're working with an index
2673 that may badly handle TUs, load all the TUs in that DWO as well.
2674 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2675 if (!per_cu
->is_debug_types
2676 && per_cu
->cu
!= NULL
2677 && per_cu
->cu
->dwo_unit
!= NULL
2678 && dwarf2_per_objfile
->index_table
!= NULL
2679 && dwarf2_per_objfile
->index_table
->version
<= 7
2680 /* DWP files aren't supported yet. */
2681 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2682 queue_and_load_all_dwo_tus (per_cu
);
2685 process_queue (dwarf2_per_objfile
);
2687 /* Age the cache, releasing compilation units that have not
2688 been used recently. */
2689 age_cached_comp_units (dwarf2_per_objfile
);
2692 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2693 the objfile from which this CU came. Returns the resulting symbol
2696 static struct compunit_symtab
*
2697 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2699 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2701 gdb_assert (dwarf2_per_objfile
->using_index
);
2702 if (!per_cu
->v
.quick
->compunit_symtab
)
2704 free_cached_comp_units
freer (dwarf2_per_objfile
);
2705 scoped_restore decrementer
= increment_reading_symtab ();
2706 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2707 process_cu_includes (dwarf2_per_objfile
);
2710 return per_cu
->v
.quick
->compunit_symtab
;
2713 /* See declaration. */
2715 dwarf2_per_cu_data
*
2716 dwarf2_per_objfile::get_cutu (int index
)
2718 if (index
>= this->all_comp_units
.size ())
2720 index
-= this->all_comp_units
.size ();
2721 gdb_assert (index
< this->all_type_units
.size ());
2722 return &this->all_type_units
[index
]->per_cu
;
2725 return this->all_comp_units
[index
];
2728 /* See declaration. */
2730 dwarf2_per_cu_data
*
2731 dwarf2_per_objfile::get_cu (int index
)
2733 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2735 return this->all_comp_units
[index
];
2738 /* See declaration. */
2741 dwarf2_per_objfile::get_tu (int index
)
2743 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2745 return this->all_type_units
[index
];
2748 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2749 objfile_obstack, and constructed with the specified field
2752 static dwarf2_per_cu_data
*
2753 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2754 struct dwarf2_section_info
*section
,
2756 sect_offset sect_off
, ULONGEST length
)
2758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2759 dwarf2_per_cu_data
*the_cu
2760 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2761 struct dwarf2_per_cu_data
);
2762 the_cu
->sect_off
= sect_off
;
2763 the_cu
->length
= length
;
2764 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2765 the_cu
->section
= section
;
2766 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2767 struct dwarf2_per_cu_quick_data
);
2768 the_cu
->is_dwz
= is_dwz
;
2772 /* A helper for create_cus_from_index that handles a given list of
2776 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2777 const gdb_byte
*cu_list
, offset_type n_elements
,
2778 struct dwarf2_section_info
*section
,
2781 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2783 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2785 sect_offset sect_off
2786 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2787 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2790 dwarf2_per_cu_data
*per_cu
2791 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
2793 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
2797 /* Read the CU list from the mapped index, and use it to create all
2798 the CU objects for this objfile. */
2801 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2802 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
2803 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
2805 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
2806 dwarf2_per_objfile
->all_comp_units
.reserve
2807 ((cu_list_elements
+ dwz_elements
) / 2);
2809 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
2810 &dwarf2_per_objfile
->info
, 0);
2812 if (dwz_elements
== 0)
2815 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
2816 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
2820 /* Create the signatured type hash table from the index. */
2823 create_signatured_type_table_from_index
2824 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2825 struct dwarf2_section_info
*section
,
2826 const gdb_byte
*bytes
,
2827 offset_type elements
)
2829 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2831 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2832 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
2834 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
2836 for (offset_type i
= 0; i
< elements
; i
+= 3)
2838 struct signatured_type
*sig_type
;
2841 cu_offset type_offset_in_tu
;
2843 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2844 sect_offset sect_off
2845 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
2847 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
2849 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
2852 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2853 struct signatured_type
);
2854 sig_type
->signature
= signature
;
2855 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
2856 sig_type
->per_cu
.is_debug_types
= 1;
2857 sig_type
->per_cu
.section
= section
;
2858 sig_type
->per_cu
.sect_off
= sect_off
;
2859 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2860 sig_type
->per_cu
.v
.quick
2861 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2862 struct dwarf2_per_cu_quick_data
);
2864 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2867 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2870 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2873 /* Create the signatured type hash table from .debug_names. */
2876 create_signatured_type_table_from_debug_names
2877 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2878 const mapped_debug_names
&map
,
2879 struct dwarf2_section_info
*section
,
2880 struct dwarf2_section_info
*abbrev_section
)
2882 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2884 section
->read (objfile
);
2885 abbrev_section
->read (objfile
);
2887 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
2888 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
2890 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
2892 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
2894 struct signatured_type
*sig_type
;
2897 sect_offset sect_off
2898 = (sect_offset
) (extract_unsigned_integer
2899 (map
.tu_table_reordered
+ i
* map
.offset_size
,
2901 map
.dwarf5_byte_order
));
2903 comp_unit_head cu_header
;
2904 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
2906 section
->buffer
+ to_underlying (sect_off
),
2909 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2910 struct signatured_type
);
2911 sig_type
->signature
= cu_header
.signature
;
2912 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
2913 sig_type
->per_cu
.is_debug_types
= 1;
2914 sig_type
->per_cu
.section
= section
;
2915 sig_type
->per_cu
.sect_off
= sect_off
;
2916 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
2917 sig_type
->per_cu
.v
.quick
2918 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2919 struct dwarf2_per_cu_quick_data
);
2921 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
2924 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
2927 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
2930 /* Read the address map data from the mapped index, and use it to
2931 populate the objfile's psymtabs_addrmap. */
2934 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2935 struct mapped_index
*index
)
2937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2938 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2939 const gdb_byte
*iter
, *end
;
2940 struct addrmap
*mutable_map
;
2943 auto_obstack temp_obstack
;
2945 mutable_map
= addrmap_create_mutable (&temp_obstack
);
2947 iter
= index
->address_table
.data ();
2948 end
= iter
+ index
->address_table
.size ();
2950 baseaddr
= objfile
->text_section_offset ();
2954 ULONGEST hi
, lo
, cu_index
;
2955 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2957 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
2959 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
2964 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
2965 hex_string (lo
), hex_string (hi
));
2969 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
2971 complaint (_(".gdb_index address table has invalid CU number %u"),
2972 (unsigned) cu_index
);
2976 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
2977 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
2978 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
2979 dwarf2_per_objfile
->get_cu (cu_index
));
2982 objfile
->partial_symtabs
->psymtabs_addrmap
2983 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
2986 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
2987 populate the objfile's psymtabs_addrmap. */
2990 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2991 struct dwarf2_section_info
*section
)
2993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2994 bfd
*abfd
= objfile
->obfd
;
2995 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2996 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
2998 auto_obstack temp_obstack
;
2999 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3001 std::unordered_map
<sect_offset
,
3002 dwarf2_per_cu_data
*,
3003 gdb::hash_enum
<sect_offset
>>
3004 debug_info_offset_to_per_cu
;
3005 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3007 const auto insertpair
3008 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3009 if (!insertpair
.second
)
3011 warning (_("Section .debug_aranges in %s has duplicate "
3012 "debug_info_offset %s, ignoring .debug_aranges."),
3013 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3018 section
->read (objfile
);
3020 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3022 const gdb_byte
*addr
= section
->buffer
;
3024 while (addr
< section
->buffer
+ section
->size
)
3026 const gdb_byte
*const entry_addr
= addr
;
3027 unsigned int bytes_read
;
3029 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3033 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3034 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3035 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3036 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3038 warning (_("Section .debug_aranges in %s entry at offset %s "
3039 "length %s exceeds section length %s, "
3040 "ignoring .debug_aranges."),
3041 objfile_name (objfile
),
3042 plongest (entry_addr
- section
->buffer
),
3043 plongest (bytes_read
+ entry_length
),
3044 pulongest (section
->size
));
3048 /* The version number. */
3049 const uint16_t version
= read_2_bytes (abfd
, addr
);
3053 warning (_("Section .debug_aranges in %s entry at offset %s "
3054 "has unsupported version %d, ignoring .debug_aranges."),
3055 objfile_name (objfile
),
3056 plongest (entry_addr
- section
->buffer
), version
);
3060 const uint64_t debug_info_offset
3061 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3062 addr
+= offset_size
;
3063 const auto per_cu_it
3064 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3065 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3067 warning (_("Section .debug_aranges in %s entry at offset %s "
3068 "debug_info_offset %s does not exists, "
3069 "ignoring .debug_aranges."),
3070 objfile_name (objfile
),
3071 plongest (entry_addr
- section
->buffer
),
3072 pulongest (debug_info_offset
));
3075 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3077 const uint8_t address_size
= *addr
++;
3078 if (address_size
< 1 || address_size
> 8)
3080 warning (_("Section .debug_aranges in %s entry at offset %s "
3081 "address_size %u is invalid, ignoring .debug_aranges."),
3082 objfile_name (objfile
),
3083 plongest (entry_addr
- section
->buffer
), address_size
);
3087 const uint8_t segment_selector_size
= *addr
++;
3088 if (segment_selector_size
!= 0)
3090 warning (_("Section .debug_aranges in %s entry at offset %s "
3091 "segment_selector_size %u is not supported, "
3092 "ignoring .debug_aranges."),
3093 objfile_name (objfile
),
3094 plongest (entry_addr
- section
->buffer
),
3095 segment_selector_size
);
3099 /* Must pad to an alignment boundary that is twice the address
3100 size. It is undocumented by the DWARF standard but GCC does
3102 for (size_t padding
= ((-(addr
- section
->buffer
))
3103 & (2 * address_size
- 1));
3104 padding
> 0; padding
--)
3107 warning (_("Section .debug_aranges in %s entry at offset %s "
3108 "padding is not zero, ignoring .debug_aranges."),
3109 objfile_name (objfile
),
3110 plongest (entry_addr
- section
->buffer
));
3116 if (addr
+ 2 * address_size
> entry_end
)
3118 warning (_("Section .debug_aranges in %s entry at offset %s "
3119 "address list is not properly terminated, "
3120 "ignoring .debug_aranges."),
3121 objfile_name (objfile
),
3122 plongest (entry_addr
- section
->buffer
));
3125 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3127 addr
+= address_size
;
3128 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3130 addr
+= address_size
;
3131 if (start
== 0 && length
== 0)
3133 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3135 /* Symbol was eliminated due to a COMDAT group. */
3138 ULONGEST end
= start
+ length
;
3139 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3141 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3143 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3147 objfile
->partial_symtabs
->psymtabs_addrmap
3148 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3151 /* Find a slot in the mapped index INDEX for the object named NAME.
3152 If NAME is found, set *VEC_OUT to point to the CU vector in the
3153 constant pool and return true. If NAME cannot be found, return
3157 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3158 offset_type
**vec_out
)
3161 offset_type slot
, step
;
3162 int (*cmp
) (const char *, const char *);
3164 gdb::unique_xmalloc_ptr
<char> without_params
;
3165 if (current_language
->la_language
== language_cplus
3166 || current_language
->la_language
== language_fortran
3167 || current_language
->la_language
== language_d
)
3169 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3172 if (strchr (name
, '(') != NULL
)
3174 without_params
= cp_remove_params (name
);
3176 if (without_params
!= NULL
)
3177 name
= without_params
.get ();
3181 /* Index version 4 did not support case insensitive searches. But the
3182 indices for case insensitive languages are built in lowercase, therefore
3183 simulate our NAME being searched is also lowercased. */
3184 hash
= mapped_index_string_hash ((index
->version
== 4
3185 && case_sensitivity
== case_sensitive_off
3186 ? 5 : index
->version
),
3189 slot
= hash
& (index
->symbol_table
.size () - 1);
3190 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3191 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3197 const auto &bucket
= index
->symbol_table
[slot
];
3198 if (bucket
.name
== 0 && bucket
.vec
== 0)
3201 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3202 if (!cmp (name
, str
))
3204 *vec_out
= (offset_type
*) (index
->constant_pool
3205 + MAYBE_SWAP (bucket
.vec
));
3209 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3213 /* A helper function that reads the .gdb_index from BUFFER and fills
3214 in MAP. FILENAME is the name of the file containing the data;
3215 it is used for error reporting. DEPRECATED_OK is true if it is
3216 ok to use deprecated sections.
3218 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3219 out parameters that are filled in with information about the CU and
3220 TU lists in the section.
3222 Returns true if all went well, false otherwise. */
3225 read_gdb_index_from_buffer (struct objfile
*objfile
,
3226 const char *filename
,
3228 gdb::array_view
<const gdb_byte
> buffer
,
3229 struct mapped_index
*map
,
3230 const gdb_byte
**cu_list
,
3231 offset_type
*cu_list_elements
,
3232 const gdb_byte
**types_list
,
3233 offset_type
*types_list_elements
)
3235 const gdb_byte
*addr
= &buffer
[0];
3237 /* Version check. */
3238 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3239 /* Versions earlier than 3 emitted every copy of a psymbol. This
3240 causes the index to behave very poorly for certain requests. Version 3
3241 contained incomplete addrmap. So, it seems better to just ignore such
3245 static int warning_printed
= 0;
3246 if (!warning_printed
)
3248 warning (_("Skipping obsolete .gdb_index section in %s."),
3250 warning_printed
= 1;
3254 /* Index version 4 uses a different hash function than index version
3257 Versions earlier than 6 did not emit psymbols for inlined
3258 functions. Using these files will cause GDB not to be able to
3259 set breakpoints on inlined functions by name, so we ignore these
3260 indices unless the user has done
3261 "set use-deprecated-index-sections on". */
3262 if (version
< 6 && !deprecated_ok
)
3264 static int warning_printed
= 0;
3265 if (!warning_printed
)
3268 Skipping deprecated .gdb_index section in %s.\n\
3269 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3270 to use the section anyway."),
3272 warning_printed
= 1;
3276 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3277 of the TU (for symbols coming from TUs),
3278 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3279 Plus gold-generated indices can have duplicate entries for global symbols,
3280 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3281 These are just performance bugs, and we can't distinguish gdb-generated
3282 indices from gold-generated ones, so issue no warning here. */
3284 /* Indexes with higher version than the one supported by GDB may be no
3285 longer backward compatible. */
3289 map
->version
= version
;
3291 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3294 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3295 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3299 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3300 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3301 - MAYBE_SWAP (metadata
[i
]))
3305 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3306 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3308 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3311 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3312 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3314 = gdb::array_view
<mapped_index::symbol_table_slot
>
3315 ((mapped_index::symbol_table_slot
*) symbol_table
,
3316 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3319 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3324 /* Callback types for dwarf2_read_gdb_index. */
3326 typedef gdb::function_view
3327 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3328 get_gdb_index_contents_ftype
;
3329 typedef gdb::function_view
3330 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3331 get_gdb_index_contents_dwz_ftype
;
3333 /* Read .gdb_index. If everything went ok, initialize the "quick"
3334 elements of all the CUs and return 1. Otherwise, return 0. */
3337 dwarf2_read_gdb_index
3338 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3339 get_gdb_index_contents_ftype get_gdb_index_contents
,
3340 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3342 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3343 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3344 struct dwz_file
*dwz
;
3345 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3347 gdb::array_view
<const gdb_byte
> main_index_contents
3348 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3350 if (main_index_contents
.empty ())
3353 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3354 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3355 use_deprecated_index_sections
,
3356 main_index_contents
, map
.get (), &cu_list
,
3357 &cu_list_elements
, &types_list
,
3358 &types_list_elements
))
3361 /* Don't use the index if it's empty. */
3362 if (map
->symbol_table
.empty ())
3365 /* If there is a .dwz file, read it so we can get its CU list as
3367 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3370 struct mapped_index dwz_map
;
3371 const gdb_byte
*dwz_types_ignore
;
3372 offset_type dwz_types_elements_ignore
;
3374 gdb::array_view
<const gdb_byte
> dwz_index_content
3375 = get_gdb_index_contents_dwz (objfile
, dwz
);
3377 if (dwz_index_content
.empty ())
3380 if (!read_gdb_index_from_buffer (objfile
,
3381 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3382 1, dwz_index_content
, &dwz_map
,
3383 &dwz_list
, &dwz_list_elements
,
3385 &dwz_types_elements_ignore
))
3387 warning (_("could not read '.gdb_index' section from %s; skipping"),
3388 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3393 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3394 dwz_list
, dwz_list_elements
);
3396 if (types_list_elements
)
3398 /* We can only handle a single .debug_types when we have an
3400 if (dwarf2_per_objfile
->types
.size () != 1)
3403 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3405 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3406 types_list
, types_list_elements
);
3409 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3411 dwarf2_per_objfile
->index_table
= std::move (map
);
3412 dwarf2_per_objfile
->using_index
= 1;
3413 dwarf2_per_objfile
->quick_file_names_table
=
3414 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3419 /* die_reader_func for dw2_get_file_names. */
3422 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3423 const gdb_byte
*info_ptr
,
3424 struct die_info
*comp_unit_die
,
3427 struct dwarf2_cu
*cu
= reader
->cu
;
3428 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3429 struct dwarf2_per_objfile
*dwarf2_per_objfile
3430 = cu
->per_cu
->dwarf2_per_objfile
;
3431 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3432 struct dwarf2_per_cu_data
*lh_cu
;
3433 struct attribute
*attr
;
3435 struct quick_file_names
*qfn
;
3437 gdb_assert (! this_cu
->is_debug_types
);
3439 /* Our callers never want to match partial units -- instead they
3440 will match the enclosing full CU. */
3441 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3443 this_cu
->v
.quick
->no_file_data
= 1;
3451 sect_offset line_offset
{};
3453 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3454 if (attr
!= nullptr)
3456 struct quick_file_names find_entry
;
3458 line_offset
= (sect_offset
) DW_UNSND (attr
);
3460 /* We may have already read in this line header (TU line header sharing).
3461 If we have we're done. */
3462 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3463 find_entry
.hash
.line_sect_off
= line_offset
;
3464 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3465 &find_entry
, INSERT
);
3468 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3472 lh
= dwarf_decode_line_header (line_offset
, cu
);
3476 lh_cu
->v
.quick
->no_file_data
= 1;
3480 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3481 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3482 qfn
->hash
.line_sect_off
= line_offset
;
3483 gdb_assert (slot
!= NULL
);
3486 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3489 if (strcmp (fnd
.name
, "<unknown>") != 0)
3492 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3494 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3496 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3497 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3498 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3499 qfn
->real_names
= NULL
;
3501 lh_cu
->v
.quick
->file_names
= qfn
;
3504 /* A helper for the "quick" functions which attempts to read the line
3505 table for THIS_CU. */
3507 static struct quick_file_names
*
3508 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3510 /* This should never be called for TUs. */
3511 gdb_assert (! this_cu
->is_debug_types
);
3512 /* Nor type unit groups. */
3513 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3515 if (this_cu
->v
.quick
->file_names
!= NULL
)
3516 return this_cu
->v
.quick
->file_names
;
3517 /* If we know there is no line data, no point in looking again. */
3518 if (this_cu
->v
.quick
->no_file_data
)
3521 cutu_reader
reader (this_cu
);
3522 if (!reader
.dummy_p
)
3523 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3524 reader
.has_children
);
3526 if (this_cu
->v
.quick
->no_file_data
)
3528 return this_cu
->v
.quick
->file_names
;
3531 /* A helper for the "quick" functions which computes and caches the
3532 real path for a given file name from the line table. */
3535 dw2_get_real_path (struct objfile
*objfile
,
3536 struct quick_file_names
*qfn
, int index
)
3538 if (qfn
->real_names
== NULL
)
3539 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3540 qfn
->num_file_names
, const char *);
3542 if (qfn
->real_names
[index
] == NULL
)
3543 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3545 return qfn
->real_names
[index
];
3548 static struct symtab
*
3549 dw2_find_last_source_symtab (struct objfile
*objfile
)
3551 struct dwarf2_per_objfile
*dwarf2_per_objfile
3552 = get_dwarf2_per_objfile (objfile
);
3553 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3554 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3559 return compunit_primary_filetab (cust
);
3562 /* Traversal function for dw2_forget_cached_source_info. */
3565 dw2_free_cached_file_names (void **slot
, void *info
)
3567 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3569 if (file_data
->real_names
)
3573 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3575 xfree ((void*) file_data
->real_names
[i
]);
3576 file_data
->real_names
[i
] = NULL
;
3584 dw2_forget_cached_source_info (struct objfile
*objfile
)
3586 struct dwarf2_per_objfile
*dwarf2_per_objfile
3587 = get_dwarf2_per_objfile (objfile
);
3589 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3590 dw2_free_cached_file_names
, NULL
);
3593 /* Helper function for dw2_map_symtabs_matching_filename that expands
3594 the symtabs and calls the iterator. */
3597 dw2_map_expand_apply (struct objfile
*objfile
,
3598 struct dwarf2_per_cu_data
*per_cu
,
3599 const char *name
, const char *real_path
,
3600 gdb::function_view
<bool (symtab
*)> callback
)
3602 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3604 /* Don't visit already-expanded CUs. */
3605 if (per_cu
->v
.quick
->compunit_symtab
)
3608 /* This may expand more than one symtab, and we want to iterate over
3610 dw2_instantiate_symtab (per_cu
, false);
3612 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3613 last_made
, callback
);
3616 /* Implementation of the map_symtabs_matching_filename method. */
3619 dw2_map_symtabs_matching_filename
3620 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3621 gdb::function_view
<bool (symtab
*)> callback
)
3623 const char *name_basename
= lbasename (name
);
3624 struct dwarf2_per_objfile
*dwarf2_per_objfile
3625 = get_dwarf2_per_objfile (objfile
);
3627 /* The rule is CUs specify all the files, including those used by
3628 any TU, so there's no need to scan TUs here. */
3630 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3632 /* We only need to look at symtabs not already expanded. */
3633 if (per_cu
->v
.quick
->compunit_symtab
)
3636 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3637 if (file_data
== NULL
)
3640 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3642 const char *this_name
= file_data
->file_names
[j
];
3643 const char *this_real_name
;
3645 if (compare_filenames_for_search (this_name
, name
))
3647 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3653 /* Before we invoke realpath, which can get expensive when many
3654 files are involved, do a quick comparison of the basenames. */
3655 if (! basenames_may_differ
3656 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3659 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3660 if (compare_filenames_for_search (this_real_name
, name
))
3662 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3668 if (real_path
!= NULL
)
3670 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3671 gdb_assert (IS_ABSOLUTE_PATH (name
));
3672 if (this_real_name
!= NULL
3673 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3675 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3687 /* Struct used to manage iterating over all CUs looking for a symbol. */
3689 struct dw2_symtab_iterator
3691 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3692 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3693 /* If set, only look for symbols that match that block. Valid values are
3694 GLOBAL_BLOCK and STATIC_BLOCK. */
3695 gdb::optional
<block_enum
> block_index
;
3696 /* The kind of symbol we're looking for. */
3698 /* The list of CUs from the index entry of the symbol,
3699 or NULL if not found. */
3701 /* The next element in VEC to look at. */
3703 /* The number of elements in VEC, or zero if there is no match. */
3705 /* Have we seen a global version of the symbol?
3706 If so we can ignore all further global instances.
3707 This is to work around gold/15646, inefficient gold-generated
3712 /* Initialize the index symtab iterator ITER. */
3715 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3716 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3717 gdb::optional
<block_enum
> block_index
,
3721 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3722 iter
->block_index
= block_index
;
3723 iter
->domain
= domain
;
3725 iter
->global_seen
= 0;
3727 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3729 /* index is NULL if OBJF_READNOW. */
3730 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3731 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3739 /* Return the next matching CU or NULL if there are no more. */
3741 static struct dwarf2_per_cu_data
*
3742 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3744 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3746 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3748 offset_type cu_index_and_attrs
=
3749 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3750 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3751 gdb_index_symbol_kind symbol_kind
=
3752 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3753 /* Only check the symbol attributes if they're present.
3754 Indices prior to version 7 don't record them,
3755 and indices >= 7 may elide them for certain symbols
3756 (gold does this). */
3758 (dwarf2_per_objfile
->index_table
->version
>= 7
3759 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3761 /* Don't crash on bad data. */
3762 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3763 + dwarf2_per_objfile
->all_type_units
.size ()))
3765 complaint (_(".gdb_index entry has bad CU index"
3767 objfile_name (dwarf2_per_objfile
->objfile
));
3771 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3773 /* Skip if already read in. */
3774 if (per_cu
->v
.quick
->compunit_symtab
)
3777 /* Check static vs global. */
3780 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3782 if (iter
->block_index
.has_value ())
3784 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3786 if (is_static
!= want_static
)
3790 /* Work around gold/15646. */
3791 if (!is_static
&& iter
->global_seen
)
3794 iter
->global_seen
= 1;
3797 /* Only check the symbol's kind if it has one. */
3800 switch (iter
->domain
)
3803 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
3804 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
3805 /* Some types are also in VAR_DOMAIN. */
3806 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3810 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
3814 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3818 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
3833 static struct compunit_symtab
*
3834 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
3835 const char *name
, domain_enum domain
)
3837 struct compunit_symtab
*stab_best
= NULL
;
3838 struct dwarf2_per_objfile
*dwarf2_per_objfile
3839 = get_dwarf2_per_objfile (objfile
);
3841 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
3843 struct dw2_symtab_iterator iter
;
3844 struct dwarf2_per_cu_data
*per_cu
;
3846 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
3848 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3850 struct symbol
*sym
, *with_opaque
= NULL
;
3851 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
3852 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
3853 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
3855 sym
= block_find_symbol (block
, name
, domain
,
3856 block_find_non_opaque_type_preferred
,
3859 /* Some caution must be observed with overloaded functions
3860 and methods, since the index will not contain any overload
3861 information (but NAME might contain it). */
3864 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
3866 if (with_opaque
!= NULL
3867 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
3870 /* Keep looking through other CUs. */
3877 dw2_print_stats (struct objfile
*objfile
)
3879 struct dwarf2_per_objfile
*dwarf2_per_objfile
3880 = get_dwarf2_per_objfile (objfile
);
3881 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
3882 + dwarf2_per_objfile
->all_type_units
.size ());
3885 for (int i
= 0; i
< total
; ++i
)
3887 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3889 if (!per_cu
->v
.quick
->compunit_symtab
)
3892 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
3893 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
3896 /* This dumps minimal information about the index.
3897 It is called via "mt print objfiles".
3898 One use is to verify .gdb_index has been loaded by the
3899 gdb.dwarf2/gdb-index.exp testcase. */
3902 dw2_dump (struct objfile
*objfile
)
3904 struct dwarf2_per_objfile
*dwarf2_per_objfile
3905 = get_dwarf2_per_objfile (objfile
);
3907 gdb_assert (dwarf2_per_objfile
->using_index
);
3908 printf_filtered (".gdb_index:");
3909 if (dwarf2_per_objfile
->index_table
!= NULL
)
3911 printf_filtered (" version %d\n",
3912 dwarf2_per_objfile
->index_table
->version
);
3915 printf_filtered (" faked for \"readnow\"\n");
3916 printf_filtered ("\n");
3920 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
3921 const char *func_name
)
3923 struct dwarf2_per_objfile
*dwarf2_per_objfile
3924 = get_dwarf2_per_objfile (objfile
);
3926 struct dw2_symtab_iterator iter
;
3927 struct dwarf2_per_cu_data
*per_cu
;
3929 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
3931 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
3932 dw2_instantiate_symtab (per_cu
, false);
3937 dw2_expand_all_symtabs (struct objfile
*objfile
)
3939 struct dwarf2_per_objfile
*dwarf2_per_objfile
3940 = get_dwarf2_per_objfile (objfile
);
3941 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
3942 + dwarf2_per_objfile
->all_type_units
.size ());
3944 for (int i
= 0; i
< total_units
; ++i
)
3946 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
3948 /* We don't want to directly expand a partial CU, because if we
3949 read it with the wrong language, then assertion failures can
3950 be triggered later on. See PR symtab/23010. So, tell
3951 dw2_instantiate_symtab to skip partial CUs -- any important
3952 partial CU will be read via DW_TAG_imported_unit anyway. */
3953 dw2_instantiate_symtab (per_cu
, true);
3958 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
3959 const char *fullname
)
3961 struct dwarf2_per_objfile
*dwarf2_per_objfile
3962 = get_dwarf2_per_objfile (objfile
);
3964 /* We don't need to consider type units here.
3965 This is only called for examining code, e.g. expand_line_sal.
3966 There can be an order of magnitude (or more) more type units
3967 than comp units, and we avoid them if we can. */
3969 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3971 /* We only need to look at symtabs not already expanded. */
3972 if (per_cu
->v
.quick
->compunit_symtab
)
3975 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3976 if (file_data
== NULL
)
3979 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3981 const char *this_fullname
= file_data
->file_names
[j
];
3983 if (filename_cmp (this_fullname
, fullname
) == 0)
3985 dw2_instantiate_symtab (per_cu
, false);
3993 dw2_map_matching_symbols
3994 (struct objfile
*objfile
,
3995 const lookup_name_info
&name
, domain_enum domain
,
3997 gdb::function_view
<symbol_found_callback_ftype
> callback
,
3998 symbol_compare_ftype
*ordered_compare
)
4000 /* Currently unimplemented; used for Ada. The function can be called if the
4001 current language is Ada for a non-Ada objfile using GNU index. As Ada
4002 does not look for non-Ada symbols this function should just return. */
4005 /* Starting from a search name, return the string that finds the upper
4006 bound of all strings that start with SEARCH_NAME in a sorted name
4007 list. Returns the empty string to indicate that the upper bound is
4008 the end of the list. */
4011 make_sort_after_prefix_name (const char *search_name
)
4013 /* When looking to complete "func", we find the upper bound of all
4014 symbols that start with "func" by looking for where we'd insert
4015 the closest string that would follow "func" in lexicographical
4016 order. Usually, that's "func"-with-last-character-incremented,
4017 i.e. "fund". Mind non-ASCII characters, though. Usually those
4018 will be UTF-8 multi-byte sequences, but we can't be certain.
4019 Especially mind the 0xff character, which is a valid character in
4020 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4021 rule out compilers allowing it in identifiers. Note that
4022 conveniently, strcmp/strcasecmp are specified to compare
4023 characters interpreted as unsigned char. So what we do is treat
4024 the whole string as a base 256 number composed of a sequence of
4025 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4026 to 0, and carries 1 to the following more-significant position.
4027 If the very first character in SEARCH_NAME ends up incremented
4028 and carries/overflows, then the upper bound is the end of the
4029 list. The string after the empty string is also the empty
4032 Some examples of this operation:
4034 SEARCH_NAME => "+1" RESULT
4038 "\xff" "a" "\xff" => "\xff" "b"
4043 Then, with these symbols for example:
4049 completing "func" looks for symbols between "func" and
4050 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4051 which finds "func" and "func1", but not "fund".
4055 funcÿ (Latin1 'ÿ' [0xff])
4059 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4060 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4064 ÿÿ (Latin1 'ÿ' [0xff])
4067 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4068 the end of the list.
4070 std::string after
= search_name
;
4071 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4073 if (!after
.empty ())
4074 after
.back () = (unsigned char) after
.back () + 1;
4078 /* See declaration. */
4080 std::pair
<std::vector
<name_component
>::const_iterator
,
4081 std::vector
<name_component
>::const_iterator
>
4082 mapped_index_base::find_name_components_bounds
4083 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4086 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4088 const char *lang_name
4089 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4091 /* Comparison function object for lower_bound that matches against a
4092 given symbol name. */
4093 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4096 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4097 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4098 return name_cmp (elem_name
, name
) < 0;
4101 /* Comparison function object for upper_bound that matches against a
4102 given symbol name. */
4103 auto lookup_compare_upper
= [&] (const char *name
,
4104 const name_component
&elem
)
4106 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4107 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4108 return name_cmp (name
, elem_name
) < 0;
4111 auto begin
= this->name_components
.begin ();
4112 auto end
= this->name_components
.end ();
4114 /* Find the lower bound. */
4117 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4120 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4123 /* Find the upper bound. */
4126 if (lookup_name_without_params
.completion_mode ())
4128 /* In completion mode, we want UPPER to point past all
4129 symbols names that have the same prefix. I.e., with
4130 these symbols, and completing "func":
4132 function << lower bound
4134 other_function << upper bound
4136 We find the upper bound by looking for the insertion
4137 point of "func"-with-last-character-incremented,
4139 std::string after
= make_sort_after_prefix_name (lang_name
);
4142 return std::lower_bound (lower
, end
, after
.c_str (),
4143 lookup_compare_lower
);
4146 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4149 return {lower
, upper
};
4152 /* See declaration. */
4155 mapped_index_base::build_name_components ()
4157 if (!this->name_components
.empty ())
4160 this->name_components_casing
= case_sensitivity
;
4162 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4164 /* The code below only knows how to break apart components of C++
4165 symbol names (and other languages that use '::' as
4166 namespace/module separator) and Ada symbol names. */
4167 auto count
= this->symbol_name_count ();
4168 for (offset_type idx
= 0; idx
< count
; idx
++)
4170 if (this->symbol_name_slot_invalid (idx
))
4173 const char *name
= this->symbol_name_at (idx
);
4175 /* Add each name component to the name component table. */
4176 unsigned int previous_len
= 0;
4178 if (strstr (name
, "::") != nullptr)
4180 for (unsigned int current_len
= cp_find_first_component (name
);
4181 name
[current_len
] != '\0';
4182 current_len
+= cp_find_first_component (name
+ current_len
))
4184 gdb_assert (name
[current_len
] == ':');
4185 this->name_components
.push_back ({previous_len
, idx
});
4186 /* Skip the '::'. */
4188 previous_len
= current_len
;
4193 /* Handle the Ada encoded (aka mangled) form here. */
4194 for (const char *iter
= strstr (name
, "__");
4196 iter
= strstr (iter
, "__"))
4198 this->name_components
.push_back ({previous_len
, idx
});
4200 previous_len
= iter
- name
;
4204 this->name_components
.push_back ({previous_len
, idx
});
4207 /* Sort name_components elements by name. */
4208 auto name_comp_compare
= [&] (const name_component
&left
,
4209 const name_component
&right
)
4211 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4212 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4214 const char *left_name
= left_qualified
+ left
.name_offset
;
4215 const char *right_name
= right_qualified
+ right
.name_offset
;
4217 return name_cmp (left_name
, right_name
) < 0;
4220 std::sort (this->name_components
.begin (),
4221 this->name_components
.end (),
4225 /* Helper for dw2_expand_symtabs_matching that works with a
4226 mapped_index_base instead of the containing objfile. This is split
4227 to a separate function in order to be able to unit test the
4228 name_components matching using a mock mapped_index_base. For each
4229 symbol name that matches, calls MATCH_CALLBACK, passing it the
4230 symbol's index in the mapped_index_base symbol table. */
4233 dw2_expand_symtabs_matching_symbol
4234 (mapped_index_base
&index
,
4235 const lookup_name_info
&lookup_name_in
,
4236 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4237 enum search_domain kind
,
4238 gdb::function_view
<bool (offset_type
)> match_callback
)
4240 lookup_name_info lookup_name_without_params
4241 = lookup_name_in
.make_ignore_params ();
4243 /* Build the symbol name component sorted vector, if we haven't
4245 index
.build_name_components ();
4247 /* The same symbol may appear more than once in the range though.
4248 E.g., if we're looking for symbols that complete "w", and we have
4249 a symbol named "w1::w2", we'll find the two name components for
4250 that same symbol in the range. To be sure we only call the
4251 callback once per symbol, we first collect the symbol name
4252 indexes that matched in a temporary vector and ignore
4254 std::vector
<offset_type
> matches
;
4256 struct name_and_matcher
4258 symbol_name_matcher_ftype
*matcher
;
4259 const std::string
&name
;
4261 bool operator== (const name_and_matcher
&other
) const
4263 return matcher
== other
.matcher
&& name
== other
.name
;
4267 /* A vector holding all the different symbol name matchers, for all
4269 std::vector
<name_and_matcher
> matchers
;
4271 for (int i
= 0; i
< nr_languages
; i
++)
4273 enum language lang_e
= (enum language
) i
;
4275 const language_defn
*lang
= language_def (lang_e
);
4276 symbol_name_matcher_ftype
*name_matcher
4277 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4279 name_and_matcher key
{
4281 lookup_name_without_params
.language_lookup_name (lang_e
)
4284 /* Don't insert the same comparison routine more than once.
4285 Note that we do this linear walk. This is not a problem in
4286 practice because the number of supported languages is
4288 if (std::find (matchers
.begin (), matchers
.end (), key
)
4291 matchers
.push_back (std::move (key
));
4294 = index
.find_name_components_bounds (lookup_name_without_params
,
4297 /* Now for each symbol name in range, check to see if we have a name
4298 match, and if so, call the MATCH_CALLBACK callback. */
4300 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4302 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4304 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4305 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4308 matches
.push_back (bounds
.first
->idx
);
4312 std::sort (matches
.begin (), matches
.end ());
4314 /* Finally call the callback, once per match. */
4316 for (offset_type idx
: matches
)
4320 if (!match_callback (idx
))
4326 /* Above we use a type wider than idx's for 'prev', since 0 and
4327 (offset_type)-1 are both possible values. */
4328 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4333 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4335 /* A mock .gdb_index/.debug_names-like name index table, enough to
4336 exercise dw2_expand_symtabs_matching_symbol, which works with the
4337 mapped_index_base interface. Builds an index from the symbol list
4338 passed as parameter to the constructor. */
4339 class mock_mapped_index
: public mapped_index_base
4342 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4343 : m_symbol_table (symbols
)
4346 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4348 /* Return the number of names in the symbol table. */
4349 size_t symbol_name_count () const override
4351 return m_symbol_table
.size ();
4354 /* Get the name of the symbol at IDX in the symbol table. */
4355 const char *symbol_name_at (offset_type idx
) const override
4357 return m_symbol_table
[idx
];
4361 gdb::array_view
<const char *> m_symbol_table
;
4364 /* Convenience function that converts a NULL pointer to a "<null>"
4365 string, to pass to print routines. */
4368 string_or_null (const char *str
)
4370 return str
!= NULL
? str
: "<null>";
4373 /* Check if a lookup_name_info built from
4374 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4375 index. EXPECTED_LIST is the list of expected matches, in expected
4376 matching order. If no match expected, then an empty list is
4377 specified. Returns true on success. On failure prints a warning
4378 indicating the file:line that failed, and returns false. */
4381 check_match (const char *file
, int line
,
4382 mock_mapped_index
&mock_index
,
4383 const char *name
, symbol_name_match_type match_type
,
4384 bool completion_mode
,
4385 std::initializer_list
<const char *> expected_list
)
4387 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4389 bool matched
= true;
4391 auto mismatch
= [&] (const char *expected_str
,
4394 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4395 "expected=\"%s\", got=\"%s\"\n"),
4397 (match_type
== symbol_name_match_type::FULL
4399 name
, string_or_null (expected_str
), string_or_null (got
));
4403 auto expected_it
= expected_list
.begin ();
4404 auto expected_end
= expected_list
.end ();
4406 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4408 [&] (offset_type idx
)
4410 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4411 const char *expected_str
4412 = expected_it
== expected_end
? NULL
: *expected_it
++;
4414 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4415 mismatch (expected_str
, matched_name
);
4419 const char *expected_str
4420 = expected_it
== expected_end
? NULL
: *expected_it
++;
4421 if (expected_str
!= NULL
)
4422 mismatch (expected_str
, NULL
);
4427 /* The symbols added to the mock mapped_index for testing (in
4429 static const char *test_symbols
[] = {
4438 "ns2::tmpl<int>::foo2",
4439 "(anonymous namespace)::A::B::C",
4441 /* These are used to check that the increment-last-char in the
4442 matching algorithm for completion doesn't match "t1_fund" when
4443 completing "t1_func". */
4449 /* A UTF-8 name with multi-byte sequences to make sure that
4450 cp-name-parser understands this as a single identifier ("função"
4451 is "function" in PT). */
4454 /* \377 (0xff) is Latin1 'ÿ'. */
4457 /* \377 (0xff) is Latin1 'ÿ'. */
4461 /* A name with all sorts of complications. Starts with "z" to make
4462 it easier for the completion tests below. */
4463 #define Z_SYM_NAME \
4464 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4465 "::tuple<(anonymous namespace)::ui*, " \
4466 "std::default_delete<(anonymous namespace)::ui>, void>"
4471 /* Returns true if the mapped_index_base::find_name_component_bounds
4472 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4473 in completion mode. */
4476 check_find_bounds_finds (mapped_index_base
&index
,
4477 const char *search_name
,
4478 gdb::array_view
<const char *> expected_syms
)
4480 lookup_name_info
lookup_name (search_name
,
4481 symbol_name_match_type::FULL
, true);
4483 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4486 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4487 if (distance
!= expected_syms
.size ())
4490 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4492 auto nc_elem
= bounds
.first
+ exp_elem
;
4493 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4494 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4501 /* Test the lower-level mapped_index::find_name_component_bounds
4505 test_mapped_index_find_name_component_bounds ()
4507 mock_mapped_index
mock_index (test_symbols
);
4509 mock_index
.build_name_components ();
4511 /* Test the lower-level mapped_index::find_name_component_bounds
4512 method in completion mode. */
4514 static const char *expected_syms
[] = {
4519 SELF_CHECK (check_find_bounds_finds (mock_index
,
4520 "t1_func", expected_syms
));
4523 /* Check that the increment-last-char in the name matching algorithm
4524 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4526 static const char *expected_syms1
[] = {
4530 SELF_CHECK (check_find_bounds_finds (mock_index
,
4531 "\377", expected_syms1
));
4533 static const char *expected_syms2
[] = {
4536 SELF_CHECK (check_find_bounds_finds (mock_index
,
4537 "\377\377", expected_syms2
));
4541 /* Test dw2_expand_symtabs_matching_symbol. */
4544 test_dw2_expand_symtabs_matching_symbol ()
4546 mock_mapped_index
mock_index (test_symbols
);
4548 /* We let all tests run until the end even if some fails, for debug
4550 bool any_mismatch
= false;
4552 /* Create the expected symbols list (an initializer_list). Needed
4553 because lists have commas, and we need to pass them to CHECK,
4554 which is a macro. */
4555 #define EXPECT(...) { __VA_ARGS__ }
4557 /* Wrapper for check_match that passes down the current
4558 __FILE__/__LINE__. */
4559 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4560 any_mismatch |= !check_match (__FILE__, __LINE__, \
4562 NAME, MATCH_TYPE, COMPLETION_MODE, \
4565 /* Identity checks. */
4566 for (const char *sym
: test_symbols
)
4568 /* Should be able to match all existing symbols. */
4569 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4572 /* Should be able to match all existing symbols with
4574 std::string with_params
= std::string (sym
) + "(int)";
4575 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4578 /* Should be able to match all existing symbols with
4579 parameters and qualifiers. */
4580 with_params
= std::string (sym
) + " ( int ) const";
4581 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4584 /* This should really find sym, but cp-name-parser.y doesn't
4585 know about lvalue/rvalue qualifiers yet. */
4586 with_params
= std::string (sym
) + " ( int ) &&";
4587 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4591 /* Check that the name matching algorithm for completion doesn't get
4592 confused with Latin1 'ÿ' / 0xff. */
4594 static const char str
[] = "\377";
4595 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4596 EXPECT ("\377", "\377\377123"));
4599 /* Check that the increment-last-char in the matching algorithm for
4600 completion doesn't match "t1_fund" when completing "t1_func". */
4602 static const char str
[] = "t1_func";
4603 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4604 EXPECT ("t1_func", "t1_func1"));
4607 /* Check that completion mode works at each prefix of the expected
4610 static const char str
[] = "function(int)";
4611 size_t len
= strlen (str
);
4614 for (size_t i
= 1; i
< len
; i
++)
4616 lookup
.assign (str
, i
);
4617 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4618 EXPECT ("function"));
4622 /* While "w" is a prefix of both components, the match function
4623 should still only be called once. */
4625 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4627 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4631 /* Same, with a "complicated" symbol. */
4633 static const char str
[] = Z_SYM_NAME
;
4634 size_t len
= strlen (str
);
4637 for (size_t i
= 1; i
< len
; i
++)
4639 lookup
.assign (str
, i
);
4640 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4641 EXPECT (Z_SYM_NAME
));
4645 /* In FULL mode, an incomplete symbol doesn't match. */
4647 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4651 /* A complete symbol with parameters matches any overload, since the
4652 index has no overload info. */
4654 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4655 EXPECT ("std::zfunction", "std::zfunction2"));
4656 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4657 EXPECT ("std::zfunction", "std::zfunction2"));
4658 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4659 EXPECT ("std::zfunction", "std::zfunction2"));
4662 /* Check that whitespace is ignored appropriately. A symbol with a
4663 template argument list. */
4665 static const char expected
[] = "ns::foo<int>";
4666 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4668 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4672 /* Check that whitespace is ignored appropriately. A symbol with a
4673 template argument list that includes a pointer. */
4675 static const char expected
[] = "ns::foo<char*>";
4676 /* Try both completion and non-completion modes. */
4677 static const bool completion_mode
[2] = {false, true};
4678 for (size_t i
= 0; i
< 2; i
++)
4680 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4681 completion_mode
[i
], EXPECT (expected
));
4682 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4683 completion_mode
[i
], EXPECT (expected
));
4685 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4686 completion_mode
[i
], EXPECT (expected
));
4687 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4688 completion_mode
[i
], EXPECT (expected
));
4693 /* Check method qualifiers are ignored. */
4694 static const char expected
[] = "ns::foo<char*>";
4695 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4696 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4697 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4698 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4699 CHECK_MATCH ("foo < char * > ( int ) const",
4700 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4701 CHECK_MATCH ("foo < char * > ( int ) &&",
4702 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4705 /* Test lookup names that don't match anything. */
4707 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4710 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4714 /* Some wild matching tests, exercising "(anonymous namespace)",
4715 which should not be confused with a parameter list. */
4717 static const char *syms
[] = {
4721 "A :: B :: C ( int )",
4726 for (const char *s
: syms
)
4728 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4729 EXPECT ("(anonymous namespace)::A::B::C"));
4734 static const char expected
[] = "ns2::tmpl<int>::foo2";
4735 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4737 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4741 SELF_CHECK (!any_mismatch
);
4750 test_mapped_index_find_name_component_bounds ();
4751 test_dw2_expand_symtabs_matching_symbol ();
4754 }} // namespace selftests::dw2_expand_symtabs_matching
4756 #endif /* GDB_SELF_TEST */
4758 /* If FILE_MATCHER is NULL or if PER_CU has
4759 dwarf2_per_cu_quick_data::MARK set (see
4760 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4761 EXPANSION_NOTIFY on it. */
4764 dw2_expand_symtabs_matching_one
4765 (struct dwarf2_per_cu_data
*per_cu
,
4766 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4767 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4769 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4771 bool symtab_was_null
4772 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4774 dw2_instantiate_symtab (per_cu
, false);
4776 if (expansion_notify
!= NULL
4778 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4779 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4783 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4784 matched, to expand corresponding CUs that were marked. IDX is the
4785 index of the symbol name that matched. */
4788 dw2_expand_marked_cus
4789 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4790 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4791 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4794 offset_type
*vec
, vec_len
, vec_idx
;
4795 bool global_seen
= false;
4796 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4798 vec
= (offset_type
*) (index
.constant_pool
4799 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
4800 vec_len
= MAYBE_SWAP (vec
[0]);
4801 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
4803 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
4804 /* This value is only valid for index versions >= 7. */
4805 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4806 gdb_index_symbol_kind symbol_kind
=
4807 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4808 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4809 /* Only check the symbol attributes if they're present.
4810 Indices prior to version 7 don't record them,
4811 and indices >= 7 may elide them for certain symbols
4812 (gold does this). */
4815 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4817 /* Work around gold/15646. */
4820 if (!is_static
&& global_seen
)
4826 /* Only check the symbol's kind if it has one. */
4831 case VARIABLES_DOMAIN
:
4832 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
4835 case FUNCTIONS_DOMAIN
:
4836 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
4840 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4843 case MODULES_DOMAIN
:
4844 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4852 /* Don't crash on bad data. */
4853 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4854 + dwarf2_per_objfile
->all_type_units
.size ()))
4856 complaint (_(".gdb_index entry has bad CU index"
4858 objfile_name (dwarf2_per_objfile
->objfile
));
4862 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4863 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
4868 /* If FILE_MATCHER is non-NULL, set all the
4869 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
4870 that match FILE_MATCHER. */
4873 dw_expand_symtabs_matching_file_matcher
4874 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
4875 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
4877 if (file_matcher
== NULL
)
4880 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
4882 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
4884 NULL
, xcalloc
, xfree
));
4885 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
4887 NULL
, xcalloc
, xfree
));
4889 /* The rule is CUs specify all the files, including those used by
4890 any TU, so there's no need to scan TUs here. */
4892 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4896 per_cu
->v
.quick
->mark
= 0;
4898 /* We only need to look at symtabs not already expanded. */
4899 if (per_cu
->v
.quick
->compunit_symtab
)
4902 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4903 if (file_data
== NULL
)
4906 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
4908 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
4910 per_cu
->v
.quick
->mark
= 1;
4914 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4916 const char *this_real_name
;
4918 if (file_matcher (file_data
->file_names
[j
], false))
4920 per_cu
->v
.quick
->mark
= 1;
4924 /* Before we invoke realpath, which can get expensive when many
4925 files are involved, do a quick comparison of the basenames. */
4926 if (!basenames_may_differ
4927 && !file_matcher (lbasename (file_data
->file_names
[j
]),
4931 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
4932 if (file_matcher (this_real_name
, false))
4934 per_cu
->v
.quick
->mark
= 1;
4939 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
4940 ? visited_found
.get ()
4941 : visited_not_found
.get (),
4948 dw2_expand_symtabs_matching
4949 (struct objfile
*objfile
,
4950 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4951 const lookup_name_info
&lookup_name
,
4952 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4953 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4954 enum search_domain kind
)
4956 struct dwarf2_per_objfile
*dwarf2_per_objfile
4957 = get_dwarf2_per_objfile (objfile
);
4959 /* index_table is NULL if OBJF_READNOW. */
4960 if (!dwarf2_per_objfile
->index_table
)
4963 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
4965 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
4967 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
4969 kind
, [&] (offset_type idx
)
4971 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
4972 expansion_notify
, kind
);
4977 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
4980 static struct compunit_symtab
*
4981 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
4986 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
4987 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
4990 if (cust
->includes
== NULL
)
4993 for (i
= 0; cust
->includes
[i
]; ++i
)
4995 struct compunit_symtab
*s
= cust
->includes
[i
];
4997 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5005 static struct compunit_symtab
*
5006 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5007 struct bound_minimal_symbol msymbol
,
5009 struct obj_section
*section
,
5012 struct dwarf2_per_cu_data
*data
;
5013 struct compunit_symtab
*result
;
5015 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5018 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5019 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5020 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5024 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5025 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5026 paddress (get_objfile_arch (objfile
), pc
));
5029 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5032 gdb_assert (result
!= NULL
);
5037 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5038 void *data
, int need_fullname
)
5040 struct dwarf2_per_objfile
*dwarf2_per_objfile
5041 = get_dwarf2_per_objfile (objfile
);
5043 if (!dwarf2_per_objfile
->filenames_cache
)
5045 dwarf2_per_objfile
->filenames_cache
.emplace ();
5047 htab_up
visited (htab_create_alloc (10,
5048 htab_hash_pointer
, htab_eq_pointer
,
5049 NULL
, xcalloc
, xfree
));
5051 /* The rule is CUs specify all the files, including those used
5052 by any TU, so there's no need to scan TUs here. We can
5053 ignore file names coming from already-expanded CUs. */
5055 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5057 if (per_cu
->v
.quick
->compunit_symtab
)
5059 void **slot
= htab_find_slot (visited
.get (),
5060 per_cu
->v
.quick
->file_names
,
5063 *slot
= per_cu
->v
.quick
->file_names
;
5067 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5069 /* We only need to look at symtabs not already expanded. */
5070 if (per_cu
->v
.quick
->compunit_symtab
)
5073 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5074 if (file_data
== NULL
)
5077 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5080 /* Already visited. */
5085 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5087 const char *filename
= file_data
->file_names
[j
];
5088 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5093 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5095 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5098 this_real_name
= gdb_realpath (filename
);
5099 (*fun
) (filename
, this_real_name
.get (), data
);
5104 dw2_has_symbols (struct objfile
*objfile
)
5109 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5112 dw2_find_last_source_symtab
,
5113 dw2_forget_cached_source_info
,
5114 dw2_map_symtabs_matching_filename
,
5118 dw2_expand_symtabs_for_function
,
5119 dw2_expand_all_symtabs
,
5120 dw2_expand_symtabs_with_fullname
,
5121 dw2_map_matching_symbols
,
5122 dw2_expand_symtabs_matching
,
5123 dw2_find_pc_sect_compunit_symtab
,
5125 dw2_map_symbol_filenames
5128 /* DWARF-5 debug_names reader. */
5130 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5131 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5133 /* A helper function that reads the .debug_names section in SECTION
5134 and fills in MAP. FILENAME is the name of the file containing the
5135 section; it is used for error reporting.
5137 Returns true if all went well, false otherwise. */
5140 read_debug_names_from_section (struct objfile
*objfile
,
5141 const char *filename
,
5142 struct dwarf2_section_info
*section
,
5143 mapped_debug_names
&map
)
5145 if (section
->empty ())
5148 /* Older elfutils strip versions could keep the section in the main
5149 executable while splitting it for the separate debug info file. */
5150 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
5153 section
->read (objfile
);
5155 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5157 const gdb_byte
*addr
= section
->buffer
;
5159 bfd
*const abfd
= section
->get_bfd_owner ();
5161 unsigned int bytes_read
;
5162 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5165 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5166 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5167 if (bytes_read
+ length
!= section
->size
)
5169 /* There may be multiple per-CU indices. */
5170 warning (_("Section .debug_names in %s length %s does not match "
5171 "section length %s, ignoring .debug_names."),
5172 filename
, plongest (bytes_read
+ length
),
5173 pulongest (section
->size
));
5177 /* The version number. */
5178 uint16_t version
= read_2_bytes (abfd
, addr
);
5182 warning (_("Section .debug_names in %s has unsupported version %d, "
5183 "ignoring .debug_names."),
5189 uint16_t padding
= read_2_bytes (abfd
, addr
);
5193 warning (_("Section .debug_names in %s has unsupported padding %d, "
5194 "ignoring .debug_names."),
5199 /* comp_unit_count - The number of CUs in the CU list. */
5200 map
.cu_count
= read_4_bytes (abfd
, addr
);
5203 /* local_type_unit_count - The number of TUs in the local TU
5205 map
.tu_count
= read_4_bytes (abfd
, addr
);
5208 /* foreign_type_unit_count - The number of TUs in the foreign TU
5210 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5212 if (foreign_tu_count
!= 0)
5214 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5215 "ignoring .debug_names."),
5216 filename
, static_cast<unsigned long> (foreign_tu_count
));
5220 /* bucket_count - The number of hash buckets in the hash lookup
5222 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5225 /* name_count - The number of unique names in the index. */
5226 map
.name_count
= read_4_bytes (abfd
, addr
);
5229 /* abbrev_table_size - The size in bytes of the abbreviations
5231 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5234 /* augmentation_string_size - The size in bytes of the augmentation
5235 string. This value is rounded up to a multiple of 4. */
5236 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5238 map
.augmentation_is_gdb
= ((augmentation_string_size
5239 == sizeof (dwarf5_augmentation
))
5240 && memcmp (addr
, dwarf5_augmentation
,
5241 sizeof (dwarf5_augmentation
)) == 0);
5242 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5243 addr
+= augmentation_string_size
;
5246 map
.cu_table_reordered
= addr
;
5247 addr
+= map
.cu_count
* map
.offset_size
;
5249 /* List of Local TUs */
5250 map
.tu_table_reordered
= addr
;
5251 addr
+= map
.tu_count
* map
.offset_size
;
5253 /* Hash Lookup Table */
5254 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5255 addr
+= map
.bucket_count
* 4;
5256 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5257 addr
+= map
.name_count
* 4;
5260 map
.name_table_string_offs_reordered
= addr
;
5261 addr
+= map
.name_count
* map
.offset_size
;
5262 map
.name_table_entry_offs_reordered
= addr
;
5263 addr
+= map
.name_count
* map
.offset_size
;
5265 const gdb_byte
*abbrev_table_start
= addr
;
5268 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5273 const auto insertpair
5274 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5275 if (!insertpair
.second
)
5277 warning (_("Section .debug_names in %s has duplicate index %s, "
5278 "ignoring .debug_names."),
5279 filename
, pulongest (index_num
));
5282 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5283 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5288 mapped_debug_names::index_val::attr attr
;
5289 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5291 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5293 if (attr
.form
== DW_FORM_implicit_const
)
5295 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5299 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5301 indexval
.attr_vec
.push_back (std::move (attr
));
5304 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5306 warning (_("Section .debug_names in %s has abbreviation_table "
5307 "of size %s vs. written as %u, ignoring .debug_names."),
5308 filename
, plongest (addr
- abbrev_table_start
),
5312 map
.entry_pool
= addr
;
5317 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5321 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5322 const mapped_debug_names
&map
,
5323 dwarf2_section_info
§ion
,
5326 sect_offset sect_off_prev
;
5327 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5329 sect_offset sect_off_next
;
5330 if (i
< map
.cu_count
)
5333 = (sect_offset
) (extract_unsigned_integer
5334 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5336 map
.dwarf5_byte_order
));
5339 sect_off_next
= (sect_offset
) section
.size
;
5342 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5343 dwarf2_per_cu_data
*per_cu
5344 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5345 sect_off_prev
, length
);
5346 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5348 sect_off_prev
= sect_off_next
;
5352 /* Read the CU list from the mapped index, and use it to create all
5353 the CU objects for this dwarf2_per_objfile. */
5356 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5357 const mapped_debug_names
&map
,
5358 const mapped_debug_names
&dwz_map
)
5360 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5361 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5363 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5364 dwarf2_per_objfile
->info
,
5365 false /* is_dwz */);
5367 if (dwz_map
.cu_count
== 0)
5370 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5371 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5375 /* Read .debug_names. If everything went ok, initialize the "quick"
5376 elements of all the CUs and return true. Otherwise, return false. */
5379 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5381 std::unique_ptr
<mapped_debug_names
> map
5382 (new mapped_debug_names (dwarf2_per_objfile
));
5383 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5384 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5386 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5387 &dwarf2_per_objfile
->debug_names
,
5391 /* Don't use the index if it's empty. */
5392 if (map
->name_count
== 0)
5395 /* If there is a .dwz file, read it so we can get its CU list as
5397 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5400 if (!read_debug_names_from_section (objfile
,
5401 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5402 &dwz
->debug_names
, dwz_map
))
5404 warning (_("could not read '.debug_names' section from %s; skipping"),
5405 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5410 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5412 if (map
->tu_count
!= 0)
5414 /* We can only handle a single .debug_types when we have an
5416 if (dwarf2_per_objfile
->types
.size () != 1)
5419 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5421 create_signatured_type_table_from_debug_names
5422 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5425 create_addrmap_from_aranges (dwarf2_per_objfile
,
5426 &dwarf2_per_objfile
->debug_aranges
);
5428 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5429 dwarf2_per_objfile
->using_index
= 1;
5430 dwarf2_per_objfile
->quick_file_names_table
=
5431 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5436 /* Type used to manage iterating over all CUs looking for a symbol for
5439 class dw2_debug_names_iterator
5442 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5443 gdb::optional
<block_enum
> block_index
,
5446 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5447 m_addr (find_vec_in_debug_names (map
, name
))
5450 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5451 search_domain search
, uint32_t namei
)
5454 m_addr (find_vec_in_debug_names (map
, namei
))
5457 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5458 block_enum block_index
, domain_enum domain
,
5460 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5461 m_addr (find_vec_in_debug_names (map
, namei
))
5464 /* Return the next matching CU or NULL if there are no more. */
5465 dwarf2_per_cu_data
*next ();
5468 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5470 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5473 /* The internalized form of .debug_names. */
5474 const mapped_debug_names
&m_map
;
5476 /* If set, only look for symbols that match that block. Valid values are
5477 GLOBAL_BLOCK and STATIC_BLOCK. */
5478 const gdb::optional
<block_enum
> m_block_index
;
5480 /* The kind of symbol we're looking for. */
5481 const domain_enum m_domain
= UNDEF_DOMAIN
;
5482 const search_domain m_search
= ALL_DOMAIN
;
5484 /* The list of CUs from the index entry of the symbol, or NULL if
5486 const gdb_byte
*m_addr
;
5490 mapped_debug_names::namei_to_name (uint32_t namei
) const
5492 const ULONGEST namei_string_offs
5493 = extract_unsigned_integer ((name_table_string_offs_reordered
5494 + namei
* offset_size
),
5497 return read_indirect_string_at_offset
5498 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5501 /* Find a slot in .debug_names for the object named NAME. If NAME is
5502 found, return pointer to its pool data. If NAME cannot be found,
5506 dw2_debug_names_iterator::find_vec_in_debug_names
5507 (const mapped_debug_names
&map
, const char *name
)
5509 int (*cmp
) (const char *, const char *);
5511 gdb::unique_xmalloc_ptr
<char> without_params
;
5512 if (current_language
->la_language
== language_cplus
5513 || current_language
->la_language
== language_fortran
5514 || current_language
->la_language
== language_d
)
5516 /* NAME is already canonical. Drop any qualifiers as
5517 .debug_names does not contain any. */
5519 if (strchr (name
, '(') != NULL
)
5521 without_params
= cp_remove_params (name
);
5522 if (without_params
!= NULL
)
5523 name
= without_params
.get ();
5527 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5529 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5531 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5532 (map
.bucket_table_reordered
5533 + (full_hash
% map
.bucket_count
)), 4,
5534 map
.dwarf5_byte_order
);
5538 if (namei
>= map
.name_count
)
5540 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5542 namei
, map
.name_count
,
5543 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5549 const uint32_t namei_full_hash
5550 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5551 (map
.hash_table_reordered
+ namei
), 4,
5552 map
.dwarf5_byte_order
);
5553 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5556 if (full_hash
== namei_full_hash
)
5558 const char *const namei_string
= map
.namei_to_name (namei
);
5560 #if 0 /* An expensive sanity check. */
5561 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5563 complaint (_("Wrong .debug_names hash for string at index %u "
5565 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5570 if (cmp (namei_string
, name
) == 0)
5572 const ULONGEST namei_entry_offs
5573 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5574 + namei
* map
.offset_size
),
5575 map
.offset_size
, map
.dwarf5_byte_order
);
5576 return map
.entry_pool
+ namei_entry_offs
;
5581 if (namei
>= map
.name_count
)
5587 dw2_debug_names_iterator::find_vec_in_debug_names
5588 (const mapped_debug_names
&map
, uint32_t namei
)
5590 if (namei
>= map
.name_count
)
5592 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5594 namei
, map
.name_count
,
5595 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5599 const ULONGEST namei_entry_offs
5600 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5601 + namei
* map
.offset_size
),
5602 map
.offset_size
, map
.dwarf5_byte_order
);
5603 return map
.entry_pool
+ namei_entry_offs
;
5606 /* See dw2_debug_names_iterator. */
5608 dwarf2_per_cu_data
*
5609 dw2_debug_names_iterator::next ()
5614 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5616 bfd
*const abfd
= objfile
->obfd
;
5620 unsigned int bytes_read
;
5621 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5622 m_addr
+= bytes_read
;
5626 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5627 if (indexval_it
== m_map
.abbrev_map
.cend ())
5629 complaint (_("Wrong .debug_names undefined abbrev code %s "
5631 pulongest (abbrev
), objfile_name (objfile
));
5634 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5635 enum class symbol_linkage
{
5639 } symbol_linkage_
= symbol_linkage::unknown
;
5640 dwarf2_per_cu_data
*per_cu
= NULL
;
5641 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5646 case DW_FORM_implicit_const
:
5647 ull
= attr
.implicit_const
;
5649 case DW_FORM_flag_present
:
5653 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5654 m_addr
+= bytes_read
;
5657 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5658 dwarf_form_name (attr
.form
),
5659 objfile_name (objfile
));
5662 switch (attr
.dw_idx
)
5664 case DW_IDX_compile_unit
:
5665 /* Don't crash on bad data. */
5666 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5668 complaint (_(".debug_names entry has bad CU index %s"
5671 objfile_name (dwarf2_per_objfile
->objfile
));
5674 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5676 case DW_IDX_type_unit
:
5677 /* Don't crash on bad data. */
5678 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5680 complaint (_(".debug_names entry has bad TU index %s"
5683 objfile_name (dwarf2_per_objfile
->objfile
));
5686 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5688 case DW_IDX_GNU_internal
:
5689 if (!m_map
.augmentation_is_gdb
)
5691 symbol_linkage_
= symbol_linkage::static_
;
5693 case DW_IDX_GNU_external
:
5694 if (!m_map
.augmentation_is_gdb
)
5696 symbol_linkage_
= symbol_linkage::extern_
;
5701 /* Skip if already read in. */
5702 if (per_cu
->v
.quick
->compunit_symtab
)
5705 /* Check static vs global. */
5706 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5708 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5709 const bool symbol_is_static
=
5710 symbol_linkage_
== symbol_linkage::static_
;
5711 if (want_static
!= symbol_is_static
)
5715 /* Match dw2_symtab_iter_next, symbol_kind
5716 and debug_names::psymbol_tag. */
5720 switch (indexval
.dwarf_tag
)
5722 case DW_TAG_variable
:
5723 case DW_TAG_subprogram
:
5724 /* Some types are also in VAR_DOMAIN. */
5725 case DW_TAG_typedef
:
5726 case DW_TAG_structure_type
:
5733 switch (indexval
.dwarf_tag
)
5735 case DW_TAG_typedef
:
5736 case DW_TAG_structure_type
:
5743 switch (indexval
.dwarf_tag
)
5746 case DW_TAG_variable
:
5753 switch (indexval
.dwarf_tag
)
5765 /* Match dw2_expand_symtabs_matching, symbol_kind and
5766 debug_names::psymbol_tag. */
5769 case VARIABLES_DOMAIN
:
5770 switch (indexval
.dwarf_tag
)
5772 case DW_TAG_variable
:
5778 case FUNCTIONS_DOMAIN
:
5779 switch (indexval
.dwarf_tag
)
5781 case DW_TAG_subprogram
:
5788 switch (indexval
.dwarf_tag
)
5790 case DW_TAG_typedef
:
5791 case DW_TAG_structure_type
:
5797 case MODULES_DOMAIN
:
5798 switch (indexval
.dwarf_tag
)
5812 static struct compunit_symtab
*
5813 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5814 const char *name
, domain_enum domain
)
5816 struct dwarf2_per_objfile
*dwarf2_per_objfile
5817 = get_dwarf2_per_objfile (objfile
);
5819 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
5822 /* index is NULL if OBJF_READNOW. */
5825 const auto &map
= *mapp
;
5827 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
5829 struct compunit_symtab
*stab_best
= NULL
;
5830 struct dwarf2_per_cu_data
*per_cu
;
5831 while ((per_cu
= iter
.next ()) != NULL
)
5833 struct symbol
*sym
, *with_opaque
= NULL
;
5834 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
5835 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
5836 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
5838 sym
= block_find_symbol (block
, name
, domain
,
5839 block_find_non_opaque_type_preferred
,
5842 /* Some caution must be observed with overloaded functions and
5843 methods, since the index will not contain any overload
5844 information (but NAME might contain it). */
5847 && strcmp_iw (sym
->search_name (), name
) == 0)
5849 if (with_opaque
!= NULL
5850 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
5853 /* Keep looking through other CUs. */
5859 /* This dumps minimal information about .debug_names. It is called
5860 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
5861 uses this to verify that .debug_names has been loaded. */
5864 dw2_debug_names_dump (struct objfile
*objfile
)
5866 struct dwarf2_per_objfile
*dwarf2_per_objfile
5867 = get_dwarf2_per_objfile (objfile
);
5869 gdb_assert (dwarf2_per_objfile
->using_index
);
5870 printf_filtered (".debug_names:");
5871 if (dwarf2_per_objfile
->debug_names_table
)
5872 printf_filtered (" exists\n");
5874 printf_filtered (" faked for \"readnow\"\n");
5875 printf_filtered ("\n");
5879 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
5880 const char *func_name
)
5882 struct dwarf2_per_objfile
*dwarf2_per_objfile
5883 = get_dwarf2_per_objfile (objfile
);
5885 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
5886 if (dwarf2_per_objfile
->debug_names_table
)
5888 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5890 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
5892 struct dwarf2_per_cu_data
*per_cu
;
5893 while ((per_cu
= iter
.next ()) != NULL
)
5894 dw2_instantiate_symtab (per_cu
, false);
5899 dw2_debug_names_map_matching_symbols
5900 (struct objfile
*objfile
,
5901 const lookup_name_info
&name
, domain_enum domain
,
5903 gdb::function_view
<symbol_found_callback_ftype
> callback
,
5904 symbol_compare_ftype
*ordered_compare
)
5906 struct dwarf2_per_objfile
*dwarf2_per_objfile
5907 = get_dwarf2_per_objfile (objfile
);
5909 /* debug_names_table is NULL if OBJF_READNOW. */
5910 if (!dwarf2_per_objfile
->debug_names_table
)
5913 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5914 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
5916 const char *match_name
= name
.ada ().lookup_name ().c_str ();
5917 auto matcher
= [&] (const char *symname
)
5919 if (ordered_compare
== nullptr)
5921 return ordered_compare (symname
, match_name
) == 0;
5924 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
5925 [&] (offset_type namei
)
5927 /* The name was matched, now expand corresponding CUs that were
5929 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
5931 struct dwarf2_per_cu_data
*per_cu
;
5932 while ((per_cu
= iter
.next ()) != NULL
)
5933 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
5937 /* It's a shame we couldn't do this inside the
5938 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
5939 that have already been expanded. Instead, this loop matches what
5940 the psymtab code does. */
5941 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5943 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
5944 if (cust
!= nullptr)
5946 const struct block
*block
5947 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
5948 if (!iterate_over_symbols_terminated (block
, name
,
5956 dw2_debug_names_expand_symtabs_matching
5957 (struct objfile
*objfile
,
5958 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5959 const lookup_name_info
&lookup_name
,
5960 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5961 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5962 enum search_domain kind
)
5964 struct dwarf2_per_objfile
*dwarf2_per_objfile
5965 = get_dwarf2_per_objfile (objfile
);
5967 /* debug_names_table is NULL if OBJF_READNOW. */
5968 if (!dwarf2_per_objfile
->debug_names_table
)
5971 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5973 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
5975 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
5977 kind
, [&] (offset_type namei
)
5979 /* The name was matched, now expand corresponding CUs that were
5981 dw2_debug_names_iterator
iter (map
, kind
, namei
);
5983 struct dwarf2_per_cu_data
*per_cu
;
5984 while ((per_cu
= iter
.next ()) != NULL
)
5985 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5991 const struct quick_symbol_functions dwarf2_debug_names_functions
=
5994 dw2_find_last_source_symtab
,
5995 dw2_forget_cached_source_info
,
5996 dw2_map_symtabs_matching_filename
,
5997 dw2_debug_names_lookup_symbol
,
5999 dw2_debug_names_dump
,
6000 dw2_debug_names_expand_symtabs_for_function
,
6001 dw2_expand_all_symtabs
,
6002 dw2_expand_symtabs_with_fullname
,
6003 dw2_debug_names_map_matching_symbols
,
6004 dw2_debug_names_expand_symtabs_matching
,
6005 dw2_find_pc_sect_compunit_symtab
,
6007 dw2_map_symbol_filenames
6010 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6011 to either a dwarf2_per_objfile or dwz_file object. */
6013 template <typename T
>
6014 static gdb::array_view
<const gdb_byte
>
6015 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6017 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6019 if (section
->empty ())
6022 /* Older elfutils strip versions could keep the section in the main
6023 executable while splitting it for the separate debug info file. */
6024 if ((section
->get_flags () & SEC_HAS_CONTENTS
) == 0)
6027 section
->read (obj
);
6029 /* dwarf2_section_info::size is a bfd_size_type, while
6030 gdb::array_view works with size_t. On 32-bit hosts, with
6031 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6032 is 32-bit. So we need an explicit narrowing conversion here.
6033 This is fine, because it's impossible to allocate or mmap an
6034 array/buffer larger than what size_t can represent. */
6035 return gdb::make_array_view (section
->buffer
, section
->size
);
6038 /* Lookup the index cache for the contents of the index associated to
6041 static gdb::array_view
<const gdb_byte
>
6042 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6044 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6045 if (build_id
== nullptr)
6048 return global_index_cache
.lookup_gdb_index (build_id
,
6049 &dwarf2_obj
->index_cache_res
);
6052 /* Same as the above, but for DWZ. */
6054 static gdb::array_view
<const gdb_byte
>
6055 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6057 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6058 if (build_id
== nullptr)
6061 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6064 /* See symfile.h. */
6067 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6069 struct dwarf2_per_objfile
*dwarf2_per_objfile
6070 = get_dwarf2_per_objfile (objfile
);
6072 /* If we're about to read full symbols, don't bother with the
6073 indices. In this case we also don't care if some other debug
6074 format is making psymtabs, because they are all about to be
6076 if ((objfile
->flags
& OBJF_READNOW
))
6078 dwarf2_per_objfile
->using_index
= 1;
6079 create_all_comp_units (dwarf2_per_objfile
);
6080 create_all_type_units (dwarf2_per_objfile
);
6081 dwarf2_per_objfile
->quick_file_names_table
6082 = create_quick_file_names_table
6083 (dwarf2_per_objfile
->all_comp_units
.size ());
6085 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6086 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6088 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6090 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6091 struct dwarf2_per_cu_quick_data
);
6094 /* Return 1 so that gdb sees the "quick" functions. However,
6095 these functions will be no-ops because we will have expanded
6097 *index_kind
= dw_index_kind::GDB_INDEX
;
6101 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6103 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6107 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6108 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6109 get_gdb_index_contents_from_section
<dwz_file
>))
6111 *index_kind
= dw_index_kind::GDB_INDEX
;
6115 /* ... otherwise, try to find the index in the index cache. */
6116 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6117 get_gdb_index_contents_from_cache
,
6118 get_gdb_index_contents_from_cache_dwz
))
6120 global_index_cache
.hit ();
6121 *index_kind
= dw_index_kind::GDB_INDEX
;
6125 global_index_cache
.miss ();
6131 /* Build a partial symbol table. */
6134 dwarf2_build_psymtabs (struct objfile
*objfile
)
6136 struct dwarf2_per_objfile
*dwarf2_per_objfile
6137 = get_dwarf2_per_objfile (objfile
);
6139 init_psymbol_list (objfile
, 1024);
6143 /* This isn't really ideal: all the data we allocate on the
6144 objfile's obstack is still uselessly kept around. However,
6145 freeing it seems unsafe. */
6146 psymtab_discarder
psymtabs (objfile
);
6147 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6150 /* (maybe) store an index in the cache. */
6151 global_index_cache
.store (dwarf2_per_objfile
);
6153 catch (const gdb_exception_error
&except
)
6155 exception_print (gdb_stderr
, except
);
6159 /* Return the total length of the CU described by HEADER. */
6162 get_cu_length (const struct comp_unit_head
*header
)
6164 return header
->initial_length_size
+ header
->length
;
6167 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6170 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6172 sect_offset bottom
= cu_header
->sect_off
;
6173 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6175 return sect_off
>= bottom
&& sect_off
< top
;
6178 /* Find the base address of the compilation unit for range lists and
6179 location lists. It will normally be specified by DW_AT_low_pc.
6180 In DWARF-3 draft 4, the base address could be overridden by
6181 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6182 compilation units with discontinuous ranges. */
6185 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6187 struct attribute
*attr
;
6190 cu
->base_address
= 0;
6192 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6193 if (attr
!= nullptr)
6195 cu
->base_address
= attr_value_as_address (attr
);
6200 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6201 if (attr
!= nullptr)
6203 cu
->base_address
= attr_value_as_address (attr
);
6209 /* Read in the comp unit header information from the debug_info at info_ptr.
6210 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6211 NOTE: This leaves members offset, first_die_offset to be filled in
6214 static const gdb_byte
*
6215 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6216 const gdb_byte
*info_ptr
,
6217 struct dwarf2_section_info
*section
,
6218 rcuh_kind section_kind
)
6221 unsigned int bytes_read
;
6222 const char *filename
= section
->get_file_name ();
6223 bfd
*abfd
= section
->get_bfd_owner ();
6225 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6226 cu_header
->initial_length_size
= bytes_read
;
6227 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6228 info_ptr
+= bytes_read
;
6229 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6230 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6231 error (_("Dwarf Error: wrong version in compilation unit header "
6232 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6233 cu_header
->version
, filename
);
6235 if (cu_header
->version
< 5)
6236 switch (section_kind
)
6238 case rcuh_kind::COMPILE
:
6239 cu_header
->unit_type
= DW_UT_compile
;
6241 case rcuh_kind::TYPE
:
6242 cu_header
->unit_type
= DW_UT_type
;
6245 internal_error (__FILE__
, __LINE__
,
6246 _("read_comp_unit_head: invalid section_kind"));
6250 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6251 (read_1_byte (abfd
, info_ptr
));
6253 switch (cu_header
->unit_type
)
6257 case DW_UT_skeleton
:
6258 case DW_UT_split_compile
:
6259 if (section_kind
!= rcuh_kind::COMPILE
)
6260 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6261 "(is %s, should be %s) [in module %s]"),
6262 dwarf_unit_type_name (cu_header
->unit_type
),
6263 dwarf_unit_type_name (DW_UT_type
), filename
);
6266 case DW_UT_split_type
:
6267 section_kind
= rcuh_kind::TYPE
;
6270 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6271 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6272 "[in module %s]"), cu_header
->unit_type
,
6273 dwarf_unit_type_name (DW_UT_compile
),
6274 dwarf_unit_type_name (DW_UT_skeleton
),
6275 dwarf_unit_type_name (DW_UT_split_compile
),
6276 dwarf_unit_type_name (DW_UT_type
),
6277 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6280 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6283 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6286 info_ptr
+= bytes_read
;
6287 if (cu_header
->version
< 5)
6289 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6292 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6293 if (signed_addr
< 0)
6294 internal_error (__FILE__
, __LINE__
,
6295 _("read_comp_unit_head: dwarf from non elf file"));
6296 cu_header
->signed_addr_p
= signed_addr
;
6298 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6299 || cu_header
->unit_type
== DW_UT_skeleton
6300 || cu_header
->unit_type
== DW_UT_split_compile
;
6302 if (header_has_signature
)
6304 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6308 if (section_kind
== rcuh_kind::TYPE
)
6310 LONGEST type_offset
;
6311 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6312 info_ptr
+= bytes_read
;
6313 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6314 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6315 error (_("Dwarf Error: Too big type_offset in compilation unit "
6316 "header (is %s) [in module %s]"), plongest (type_offset
),
6323 /* Helper function that returns the proper abbrev section for
6326 static struct dwarf2_section_info
*
6327 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6329 struct dwarf2_section_info
*abbrev
;
6330 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6332 if (this_cu
->is_dwz
)
6333 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6335 abbrev
= &dwarf2_per_objfile
->abbrev
;
6340 /* Subroutine of read_and_check_comp_unit_head and
6341 read_and_check_type_unit_head to simplify them.
6342 Perform various error checking on the header. */
6345 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6346 struct comp_unit_head
*header
,
6347 struct dwarf2_section_info
*section
,
6348 struct dwarf2_section_info
*abbrev_section
)
6350 const char *filename
= section
->get_file_name ();
6352 if (to_underlying (header
->abbrev_sect_off
)
6353 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6354 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6355 "(offset %s + 6) [in module %s]"),
6356 sect_offset_str (header
->abbrev_sect_off
),
6357 sect_offset_str (header
->sect_off
),
6360 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6361 avoid potential 32-bit overflow. */
6362 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6364 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6365 "(offset %s + 0) [in module %s]"),
6366 header
->length
, sect_offset_str (header
->sect_off
),
6370 /* Read in a CU/TU header and perform some basic error checking.
6371 The contents of the header are stored in HEADER.
6372 The result is a pointer to the start of the first DIE. */
6374 static const gdb_byte
*
6375 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6376 struct comp_unit_head
*header
,
6377 struct dwarf2_section_info
*section
,
6378 struct dwarf2_section_info
*abbrev_section
,
6379 const gdb_byte
*info_ptr
,
6380 rcuh_kind section_kind
)
6382 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6384 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6386 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6388 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6390 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6396 /* Fetch the abbreviation table offset from a comp or type unit header. */
6399 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6400 struct dwarf2_section_info
*section
,
6401 sect_offset sect_off
)
6403 bfd
*abfd
= section
->get_bfd_owner ();
6404 const gdb_byte
*info_ptr
;
6405 unsigned int initial_length_size
, offset_size
;
6408 section
->read (dwarf2_per_objfile
->objfile
);
6409 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6410 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6411 offset_size
= initial_length_size
== 4 ? 4 : 8;
6412 info_ptr
+= initial_length_size
;
6414 version
= read_2_bytes (abfd
, info_ptr
);
6418 /* Skip unit type and address size. */
6422 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6425 /* Allocate a new partial symtab for file named NAME and mark this new
6426 partial symtab as being an include of PST. */
6429 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6430 struct objfile
*objfile
)
6432 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6434 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6436 /* It shares objfile->objfile_obstack. */
6437 subpst
->dirname
= pst
->dirname
;
6440 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6441 subpst
->dependencies
[0] = pst
;
6442 subpst
->number_of_dependencies
= 1;
6444 /* No private part is necessary for include psymtabs. This property
6445 can be used to differentiate between such include psymtabs and
6446 the regular ones. */
6447 subpst
->per_cu_data
= nullptr;
6450 /* Read the Line Number Program data and extract the list of files
6451 included by the source file represented by PST. Build an include
6452 partial symtab for each of these included files. */
6455 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6456 struct die_info
*die
,
6457 dwarf2_psymtab
*pst
)
6460 struct attribute
*attr
;
6462 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6463 if (attr
!= nullptr)
6464 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6466 return; /* No linetable, so no includes. */
6468 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6469 that we pass in the raw text_low here; that is ok because we're
6470 only decoding the line table to make include partial symtabs, and
6471 so the addresses aren't really used. */
6472 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6473 pst
->raw_text_low (), 1);
6477 hash_signatured_type (const void *item
)
6479 const struct signatured_type
*sig_type
6480 = (const struct signatured_type
*) item
;
6482 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6483 return sig_type
->signature
;
6487 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6489 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6490 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6492 return lhs
->signature
== rhs
->signature
;
6495 /* Allocate a hash table for signatured types. */
6498 allocate_signatured_type_table (struct objfile
*objfile
)
6500 return htab_create_alloc_ex (41,
6501 hash_signatured_type
,
6504 &objfile
->objfile_obstack
,
6505 hashtab_obstack_allocate
,
6506 dummy_obstack_deallocate
);
6509 /* A helper function to add a signatured type CU to a table. */
6512 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6514 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6515 std::vector
<signatured_type
*> *all_type_units
6516 = (std::vector
<signatured_type
*> *) datum
;
6518 all_type_units
->push_back (sigt
);
6523 /* A helper for create_debug_types_hash_table. Read types from SECTION
6524 and fill them into TYPES_HTAB. It will process only type units,
6525 therefore DW_UT_type. */
6528 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6529 struct dwo_file
*dwo_file
,
6530 dwarf2_section_info
*section
, htab_t
&types_htab
,
6531 rcuh_kind section_kind
)
6533 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6534 struct dwarf2_section_info
*abbrev_section
;
6536 const gdb_byte
*info_ptr
, *end_ptr
;
6538 abbrev_section
= (dwo_file
!= NULL
6539 ? &dwo_file
->sections
.abbrev
6540 : &dwarf2_per_objfile
->abbrev
);
6542 if (dwarf_read_debug
)
6543 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6544 section
->get_name (),
6545 abbrev_section
->get_file_name ());
6547 section
->read (objfile
);
6548 info_ptr
= section
->buffer
;
6550 if (info_ptr
== NULL
)
6553 /* We can't set abfd until now because the section may be empty or
6554 not present, in which case the bfd is unknown. */
6555 abfd
= section
->get_bfd_owner ();
6557 /* We don't use cutu_reader here because we don't need to read
6558 any dies: the signature is in the header. */
6560 end_ptr
= info_ptr
+ section
->size
;
6561 while (info_ptr
< end_ptr
)
6563 struct signatured_type
*sig_type
;
6564 struct dwo_unit
*dwo_tu
;
6566 const gdb_byte
*ptr
= info_ptr
;
6567 struct comp_unit_head header
;
6568 unsigned int length
;
6570 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6572 /* Initialize it due to a false compiler warning. */
6573 header
.signature
= -1;
6574 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6576 /* We need to read the type's signature in order to build the hash
6577 table, but we don't need anything else just yet. */
6579 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6580 abbrev_section
, ptr
, section_kind
);
6582 length
= get_cu_length (&header
);
6584 /* Skip dummy type units. */
6585 if (ptr
>= info_ptr
+ length
6586 || peek_abbrev_code (abfd
, ptr
) == 0
6587 || header
.unit_type
!= DW_UT_type
)
6593 if (types_htab
== NULL
)
6596 types_htab
= allocate_dwo_unit_table (objfile
);
6598 types_htab
= allocate_signatured_type_table (objfile
);
6604 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6606 dwo_tu
->dwo_file
= dwo_file
;
6607 dwo_tu
->signature
= header
.signature
;
6608 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6609 dwo_tu
->section
= section
;
6610 dwo_tu
->sect_off
= sect_off
;
6611 dwo_tu
->length
= length
;
6615 /* N.B.: type_offset is not usable if this type uses a DWO file.
6616 The real type_offset is in the DWO file. */
6618 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6619 struct signatured_type
);
6620 sig_type
->signature
= header
.signature
;
6621 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6622 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6623 sig_type
->per_cu
.is_debug_types
= 1;
6624 sig_type
->per_cu
.section
= section
;
6625 sig_type
->per_cu
.sect_off
= sect_off
;
6626 sig_type
->per_cu
.length
= length
;
6629 slot
= htab_find_slot (types_htab
,
6630 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6632 gdb_assert (slot
!= NULL
);
6635 sect_offset dup_sect_off
;
6639 const struct dwo_unit
*dup_tu
6640 = (const struct dwo_unit
*) *slot
;
6642 dup_sect_off
= dup_tu
->sect_off
;
6646 const struct signatured_type
*dup_tu
6647 = (const struct signatured_type
*) *slot
;
6649 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6652 complaint (_("debug type entry at offset %s is duplicate to"
6653 " the entry at offset %s, signature %s"),
6654 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6655 hex_string (header
.signature
));
6657 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6659 if (dwarf_read_debug
> 1)
6660 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6661 sect_offset_str (sect_off
),
6662 hex_string (header
.signature
));
6668 /* Create the hash table of all entries in the .debug_types
6669 (or .debug_types.dwo) section(s).
6670 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6671 otherwise it is NULL.
6673 The result is a pointer to the hash table or NULL if there are no types.
6675 Note: This function processes DWO files only, not DWP files. */
6678 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6679 struct dwo_file
*dwo_file
,
6680 gdb::array_view
<dwarf2_section_info
> type_sections
,
6683 for (dwarf2_section_info
§ion
: type_sections
)
6684 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6685 types_htab
, rcuh_kind::TYPE
);
6688 /* Create the hash table of all entries in the .debug_types section,
6689 and initialize all_type_units.
6690 The result is zero if there is an error (e.g. missing .debug_types section),
6691 otherwise non-zero. */
6694 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6696 htab_t types_htab
= NULL
;
6698 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6699 &dwarf2_per_objfile
->info
, types_htab
,
6700 rcuh_kind::COMPILE
);
6701 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6702 dwarf2_per_objfile
->types
, types_htab
);
6703 if (types_htab
== NULL
)
6705 dwarf2_per_objfile
->signatured_types
= NULL
;
6709 dwarf2_per_objfile
->signatured_types
= types_htab
;
6711 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6712 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6714 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6715 &dwarf2_per_objfile
->all_type_units
);
6720 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6721 If SLOT is non-NULL, it is the entry to use in the hash table.
6722 Otherwise we find one. */
6724 static struct signatured_type
*
6725 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6728 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6730 if (dwarf2_per_objfile
->all_type_units
.size ()
6731 == dwarf2_per_objfile
->all_type_units
.capacity ())
6732 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6734 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6735 struct signatured_type
);
6737 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6738 sig_type
->signature
= sig
;
6739 sig_type
->per_cu
.is_debug_types
= 1;
6740 if (dwarf2_per_objfile
->using_index
)
6742 sig_type
->per_cu
.v
.quick
=
6743 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6744 struct dwarf2_per_cu_quick_data
);
6749 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6752 gdb_assert (*slot
== NULL
);
6754 /* The rest of sig_type must be filled in by the caller. */
6758 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6759 Fill in SIG_ENTRY with DWO_ENTRY. */
6762 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6763 struct signatured_type
*sig_entry
,
6764 struct dwo_unit
*dwo_entry
)
6766 /* Make sure we're not clobbering something we don't expect to. */
6767 gdb_assert (! sig_entry
->per_cu
.queued
);
6768 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6769 if (dwarf2_per_objfile
->using_index
)
6771 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6772 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6775 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6776 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6777 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6778 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6779 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6781 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6782 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6783 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6784 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6785 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6786 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6787 sig_entry
->dwo_unit
= dwo_entry
;
6790 /* Subroutine of lookup_signatured_type.
6791 If we haven't read the TU yet, create the signatured_type data structure
6792 for a TU to be read in directly from a DWO file, bypassing the stub.
6793 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6794 using .gdb_index, then when reading a CU we want to stay in the DWO file
6795 containing that CU. Otherwise we could end up reading several other DWO
6796 files (due to comdat folding) to process the transitive closure of all the
6797 mentioned TUs, and that can be slow. The current DWO file will have every
6798 type signature that it needs.
6799 We only do this for .gdb_index because in the psymtab case we already have
6800 to read all the DWOs to build the type unit groups. */
6802 static struct signatured_type
*
6803 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6805 struct dwarf2_per_objfile
*dwarf2_per_objfile
6806 = cu
->per_cu
->dwarf2_per_objfile
;
6807 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6808 struct dwo_file
*dwo_file
;
6809 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6810 struct signatured_type find_sig_entry
, *sig_entry
;
6813 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6815 /* If TU skeletons have been removed then we may not have read in any
6817 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6819 dwarf2_per_objfile
->signatured_types
6820 = allocate_signatured_type_table (objfile
);
6823 /* We only ever need to read in one copy of a signatured type.
6824 Use the global signatured_types array to do our own comdat-folding
6825 of types. If this is the first time we're reading this TU, and
6826 the TU has an entry in .gdb_index, replace the recorded data from
6827 .gdb_index with this TU. */
6829 find_sig_entry
.signature
= sig
;
6830 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6831 &find_sig_entry
, INSERT
);
6832 sig_entry
= (struct signatured_type
*) *slot
;
6834 /* We can get here with the TU already read, *or* in the process of being
6835 read. Don't reassign the global entry to point to this DWO if that's
6836 the case. Also note that if the TU is already being read, it may not
6837 have come from a DWO, the program may be a mix of Fission-compiled
6838 code and non-Fission-compiled code. */
6840 /* Have we already tried to read this TU?
6841 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6842 needn't exist in the global table yet). */
6843 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
6846 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
6847 dwo_unit of the TU itself. */
6848 dwo_file
= cu
->dwo_unit
->dwo_file
;
6850 /* Ok, this is the first time we're reading this TU. */
6851 if (dwo_file
->tus
== NULL
)
6853 find_dwo_entry
.signature
= sig
;
6854 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
6855 if (dwo_entry
== NULL
)
6858 /* If the global table doesn't have an entry for this TU, add one. */
6859 if (sig_entry
== NULL
)
6860 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6862 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6863 sig_entry
->per_cu
.tu_read
= 1;
6867 /* Subroutine of lookup_signatured_type.
6868 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
6869 then try the DWP file. If the TU stub (skeleton) has been removed then
6870 it won't be in .gdb_index. */
6872 static struct signatured_type
*
6873 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6875 struct dwarf2_per_objfile
*dwarf2_per_objfile
6876 = cu
->per_cu
->dwarf2_per_objfile
;
6877 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6878 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
6879 struct dwo_unit
*dwo_entry
;
6880 struct signatured_type find_sig_entry
, *sig_entry
;
6883 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
6884 gdb_assert (dwp_file
!= NULL
);
6886 /* If TU skeletons have been removed then we may not have read in any
6888 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6890 dwarf2_per_objfile
->signatured_types
6891 = allocate_signatured_type_table (objfile
);
6894 find_sig_entry
.signature
= sig
;
6895 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6896 &find_sig_entry
, INSERT
);
6897 sig_entry
= (struct signatured_type
*) *slot
;
6899 /* Have we already tried to read this TU?
6900 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
6901 needn't exist in the global table yet). */
6902 if (sig_entry
!= NULL
)
6905 if (dwp_file
->tus
== NULL
)
6907 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
6908 sig
, 1 /* is_debug_types */);
6909 if (dwo_entry
== NULL
)
6912 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
6913 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
6918 /* Lookup a signature based type for DW_FORM_ref_sig8.
6919 Returns NULL if signature SIG is not present in the table.
6920 It is up to the caller to complain about this. */
6922 static struct signatured_type
*
6923 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6925 struct dwarf2_per_objfile
*dwarf2_per_objfile
6926 = cu
->per_cu
->dwarf2_per_objfile
;
6929 && dwarf2_per_objfile
->using_index
)
6931 /* We're in a DWO/DWP file, and we're using .gdb_index.
6932 These cases require special processing. */
6933 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
6934 return lookup_dwo_signatured_type (cu
, sig
);
6936 return lookup_dwp_signatured_type (cu
, sig
);
6940 struct signatured_type find_entry
, *entry
;
6942 if (dwarf2_per_objfile
->signatured_types
== NULL
)
6944 find_entry
.signature
= sig
;
6945 entry
= ((struct signatured_type
*)
6946 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
6951 /* Return the address base of the compile unit, which, if exists, is stored
6952 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
6953 static gdb::optional
<ULONGEST
>
6954 lookup_addr_base (struct die_info
*comp_unit_die
)
6956 struct attribute
*attr
;
6957 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
6958 if (attr
== nullptr)
6959 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
6960 if (attr
== nullptr)
6961 return gdb::optional
<ULONGEST
> ();
6962 return DW_UNSND (attr
);
6965 /* Return range lists base of the compile unit, which, if exists, is stored
6966 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
6968 lookup_ranges_base (struct die_info
*comp_unit_die
)
6970 struct attribute
*attr
;
6971 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
6972 if (attr
== nullptr)
6973 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
6974 if (attr
== nullptr)
6976 return DW_UNSND (attr
);
6979 /* Low level DIE reading support. */
6981 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
6984 init_cu_die_reader (struct die_reader_specs
*reader
,
6985 struct dwarf2_cu
*cu
,
6986 struct dwarf2_section_info
*section
,
6987 struct dwo_file
*dwo_file
,
6988 struct abbrev_table
*abbrev_table
)
6990 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
6991 reader
->abfd
= section
->get_bfd_owner ();
6993 reader
->dwo_file
= dwo_file
;
6994 reader
->die_section
= section
;
6995 reader
->buffer
= section
->buffer
;
6996 reader
->buffer_end
= section
->buffer
+ section
->size
;
6997 reader
->comp_dir
= NULL
;
6998 reader
->abbrev_table
= abbrev_table
;
7001 /* Subroutine of cutu_reader to simplify it.
7002 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7003 There's just a lot of work to do, and cutu_reader is big enough
7006 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7007 from it to the DIE in the DWO. If NULL we are skipping the stub.
7008 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7009 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7010 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7011 STUB_COMP_DIR may be non-NULL.
7012 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7013 are filled in with the info of the DIE from the DWO file.
7014 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7015 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7016 kept around for at least as long as *RESULT_READER.
7018 The result is non-zero if a valid (non-dummy) DIE was found. */
7021 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7022 struct dwo_unit
*dwo_unit
,
7023 struct die_info
*stub_comp_unit_die
,
7024 const char *stub_comp_dir
,
7025 struct die_reader_specs
*result_reader
,
7026 const gdb_byte
**result_info_ptr
,
7027 struct die_info
**result_comp_unit_die
,
7028 int *result_has_children
,
7029 abbrev_table_up
*result_dwo_abbrev_table
)
7031 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7032 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7033 struct dwarf2_cu
*cu
= this_cu
->cu
;
7035 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7036 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7037 int i
,num_extra_attrs
;
7038 struct dwarf2_section_info
*dwo_abbrev_section
;
7039 struct die_info
*comp_unit_die
;
7041 /* At most one of these may be provided. */
7042 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7044 /* These attributes aren't processed until later:
7045 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7046 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7047 referenced later. However, these attributes are found in the stub
7048 which we won't have later. In order to not impose this complication
7049 on the rest of the code, we read them here and copy them to the
7058 if (stub_comp_unit_die
!= NULL
)
7060 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7062 if (! this_cu
->is_debug_types
)
7063 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7064 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7065 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7066 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7067 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7069 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7071 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7072 here (if needed). We need the value before we can process
7074 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7076 else if (stub_comp_dir
!= NULL
)
7078 /* Reconstruct the comp_dir attribute to simplify the code below. */
7079 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7080 comp_dir
->name
= DW_AT_comp_dir
;
7081 comp_dir
->form
= DW_FORM_string
;
7082 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7083 DW_STRING (comp_dir
) = stub_comp_dir
;
7086 /* Set up for reading the DWO CU/TU. */
7087 cu
->dwo_unit
= dwo_unit
;
7088 dwarf2_section_info
*section
= dwo_unit
->section
;
7089 section
->read (objfile
);
7090 abfd
= section
->get_bfd_owner ();
7091 begin_info_ptr
= info_ptr
= (section
->buffer
7092 + to_underlying (dwo_unit
->sect_off
));
7093 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7095 if (this_cu
->is_debug_types
)
7097 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7099 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7100 &cu
->header
, section
,
7102 info_ptr
, rcuh_kind::TYPE
);
7103 /* This is not an assert because it can be caused by bad debug info. */
7104 if (sig_type
->signature
!= cu
->header
.signature
)
7106 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7107 " TU at offset %s [in module %s]"),
7108 hex_string (sig_type
->signature
),
7109 hex_string (cu
->header
.signature
),
7110 sect_offset_str (dwo_unit
->sect_off
),
7111 bfd_get_filename (abfd
));
7113 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7114 /* For DWOs coming from DWP files, we don't know the CU length
7115 nor the type's offset in the TU until now. */
7116 dwo_unit
->length
= get_cu_length (&cu
->header
);
7117 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7119 /* Establish the type offset that can be used to lookup the type.
7120 For DWO files, we don't know it until now. */
7121 sig_type
->type_offset_in_section
7122 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7126 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7127 &cu
->header
, section
,
7129 info_ptr
, rcuh_kind::COMPILE
);
7130 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7131 /* For DWOs coming from DWP files, we don't know the CU length
7133 dwo_unit
->length
= get_cu_length (&cu
->header
);
7136 *result_dwo_abbrev_table
7137 = abbrev_table_read_table (objfile
, dwo_abbrev_section
,
7138 cu
->header
.abbrev_sect_off
);
7139 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7140 result_dwo_abbrev_table
->get ());
7142 /* Read in the die, but leave space to copy over the attributes
7143 from the stub. This has the benefit of simplifying the rest of
7144 the code - all the work to maintain the illusion of a single
7145 DW_TAG_{compile,type}_unit DIE is done here. */
7146 num_extra_attrs
= ((stmt_list
!= NULL
)
7150 + (comp_dir
!= NULL
));
7151 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7152 result_has_children
, num_extra_attrs
);
7154 /* Copy over the attributes from the stub to the DIE we just read in. */
7155 comp_unit_die
= *result_comp_unit_die
;
7156 i
= comp_unit_die
->num_attrs
;
7157 if (stmt_list
!= NULL
)
7158 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7160 comp_unit_die
->attrs
[i
++] = *low_pc
;
7161 if (high_pc
!= NULL
)
7162 comp_unit_die
->attrs
[i
++] = *high_pc
;
7164 comp_unit_die
->attrs
[i
++] = *ranges
;
7165 if (comp_dir
!= NULL
)
7166 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7167 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7169 if (dwarf_die_debug
)
7171 fprintf_unfiltered (gdb_stdlog
,
7172 "Read die from %s@0x%x of %s:\n",
7173 section
->get_name (),
7174 (unsigned) (begin_info_ptr
- section
->buffer
),
7175 bfd_get_filename (abfd
));
7176 dump_die (comp_unit_die
, dwarf_die_debug
);
7179 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7180 TUs by skipping the stub and going directly to the entry in the DWO file.
7181 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7182 to get it via circuitous means. Blech. */
7183 if (comp_dir
!= NULL
)
7184 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7186 /* Skip dummy compilation units. */
7187 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7188 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7191 *result_info_ptr
= info_ptr
;
7195 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7196 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7197 signature is part of the header. */
7198 static gdb::optional
<ULONGEST
>
7199 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7201 if (cu
->header
.version
>= 5)
7202 return cu
->header
.signature
;
7203 struct attribute
*attr
;
7204 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7205 if (attr
== nullptr)
7206 return gdb::optional
<ULONGEST
> ();
7207 return DW_UNSND (attr
);
7210 /* Subroutine of cutu_reader to simplify it.
7211 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7212 Returns NULL if the specified DWO unit cannot be found. */
7214 static struct dwo_unit
*
7215 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7216 struct die_info
*comp_unit_die
,
7217 const char *dwo_name
)
7219 struct dwarf2_cu
*cu
= this_cu
->cu
;
7220 struct dwo_unit
*dwo_unit
;
7221 const char *comp_dir
;
7223 gdb_assert (cu
!= NULL
);
7225 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7226 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7227 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7229 if (this_cu
->is_debug_types
)
7231 struct signatured_type
*sig_type
;
7233 /* Since this_cu is the first member of struct signatured_type,
7234 we can go from a pointer to one to a pointer to the other. */
7235 sig_type
= (struct signatured_type
*) this_cu
;
7236 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7240 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7241 if (!signature
.has_value ())
7242 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7244 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7245 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7252 /* Subroutine of cutu_reader to simplify it.
7253 See it for a description of the parameters.
7254 Read a TU directly from a DWO file, bypassing the stub. */
7257 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7258 int use_existing_cu
, int keep
)
7260 struct signatured_type
*sig_type
;
7261 struct die_reader_specs reader
;
7263 /* Verify we can do the following downcast, and that we have the
7265 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7266 sig_type
= (struct signatured_type
*) this_cu
;
7267 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7269 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7271 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7272 /* There's no need to do the rereading_dwo_cu handling that
7273 cutu_reader does since we don't read the stub. */
7277 /* If !use_existing_cu, this_cu->cu must be NULL. */
7278 gdb_assert (this_cu
->cu
== NULL
);
7279 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7282 /* A future optimization, if needed, would be to use an existing
7283 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7284 could share abbrev tables. */
7286 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7287 NULL
/* stub_comp_unit_die */,
7288 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7290 &comp_unit_die
, &has_children
,
7291 &m_dwo_abbrev_table
) == 0)
7298 /* Initialize a CU (or TU) and read its DIEs.
7299 If the CU defers to a DWO file, read the DWO file as well.
7301 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7302 Otherwise the table specified in the comp unit header is read in and used.
7303 This is an optimization for when we already have the abbrev table.
7305 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7306 Otherwise, a new CU is allocated with xmalloc.
7308 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7309 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7312 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7313 struct abbrev_table
*abbrev_table
,
7314 int use_existing_cu
, int keep
,
7316 : die_reader_specs
{},
7317 m_this_cu (this_cu
),
7320 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7321 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7322 struct dwarf2_section_info
*section
= this_cu
->section
;
7323 bfd
*abfd
= section
->get_bfd_owner ();
7324 struct dwarf2_cu
*cu
;
7325 const gdb_byte
*begin_info_ptr
;
7326 struct signatured_type
*sig_type
= NULL
;
7327 struct dwarf2_section_info
*abbrev_section
;
7328 /* Non-zero if CU currently points to a DWO file and we need to
7329 reread it. When this happens we need to reread the skeleton die
7330 before we can reread the DWO file (this only applies to CUs, not TUs). */
7331 int rereading_dwo_cu
= 0;
7333 if (dwarf_die_debug
)
7334 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7335 this_cu
->is_debug_types
? "type" : "comp",
7336 sect_offset_str (this_cu
->sect_off
));
7338 if (use_existing_cu
)
7341 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7342 file (instead of going through the stub), short-circuit all of this. */
7343 if (this_cu
->reading_dwo_directly
)
7345 /* Narrow down the scope of possibilities to have to understand. */
7346 gdb_assert (this_cu
->is_debug_types
);
7347 gdb_assert (abbrev_table
== NULL
);
7348 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7352 /* This is cheap if the section is already read in. */
7353 section
->read (objfile
);
7355 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7357 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7359 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7362 /* If this CU is from a DWO file we need to start over, we need to
7363 refetch the attributes from the skeleton CU.
7364 This could be optimized by retrieving those attributes from when we
7365 were here the first time: the previous comp_unit_die was stored in
7366 comp_unit_obstack. But there's no data yet that we need this
7368 if (cu
->dwo_unit
!= NULL
)
7369 rereading_dwo_cu
= 1;
7373 /* If !use_existing_cu, this_cu->cu must be NULL. */
7374 gdb_assert (this_cu
->cu
== NULL
);
7375 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7376 cu
= m_new_cu
.get ();
7379 /* Get the header. */
7380 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7382 /* We already have the header, there's no need to read it in again. */
7383 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7387 if (this_cu
->is_debug_types
)
7389 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7390 &cu
->header
, section
,
7391 abbrev_section
, info_ptr
,
7394 /* Since per_cu is the first member of struct signatured_type,
7395 we can go from a pointer to one to a pointer to the other. */
7396 sig_type
= (struct signatured_type
*) this_cu
;
7397 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7398 gdb_assert (sig_type
->type_offset_in_tu
7399 == cu
->header
.type_cu_offset_in_tu
);
7400 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7402 /* LENGTH has not been set yet for type units if we're
7403 using .gdb_index. */
7404 this_cu
->length
= get_cu_length (&cu
->header
);
7406 /* Establish the type offset that can be used to lookup the type. */
7407 sig_type
->type_offset_in_section
=
7408 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7410 this_cu
->dwarf_version
= cu
->header
.version
;
7414 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7415 &cu
->header
, section
,
7418 rcuh_kind::COMPILE
);
7420 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7421 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7422 this_cu
->dwarf_version
= cu
->header
.version
;
7426 /* Skip dummy compilation units. */
7427 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7428 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7434 /* If we don't have them yet, read the abbrevs for this compilation unit.
7435 And if we need to read them now, make sure they're freed when we're
7437 if (abbrev_table
!= NULL
)
7438 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7441 m_abbrev_table_holder
7442 = abbrev_table_read_table (objfile
, abbrev_section
,
7443 cu
->header
.abbrev_sect_off
);
7444 abbrev_table
= m_abbrev_table_holder
.get ();
7447 /* Read the top level CU/TU die. */
7448 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7449 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7451 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7457 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7458 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7459 table from the DWO file and pass the ownership over to us. It will be
7460 referenced from READER, so we must make sure to free it after we're done
7463 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7464 DWO CU, that this test will fail (the attribute will not be present). */
7465 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7466 if (dwo_name
!= nullptr)
7468 struct dwo_unit
*dwo_unit
;
7469 struct die_info
*dwo_comp_unit_die
;
7473 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7474 " has children (offset %s) [in module %s]"),
7475 sect_offset_str (this_cu
->sect_off
),
7476 bfd_get_filename (abfd
));
7478 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7479 if (dwo_unit
!= NULL
)
7481 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7482 comp_unit_die
, NULL
,
7484 &dwo_comp_unit_die
, &has_children
,
7485 &m_dwo_abbrev_table
) == 0)
7491 comp_unit_die
= dwo_comp_unit_die
;
7495 /* Yikes, we couldn't find the rest of the DIE, we only have
7496 the stub. A complaint has already been logged. There's
7497 not much more we can do except pass on the stub DIE to
7498 die_reader_func. We don't want to throw an error on bad
7504 cutu_reader::~cutu_reader ()
7506 /* Done, clean up. */
7507 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7509 struct dwarf2_per_objfile
*dwarf2_per_objfile
7510 = m_this_cu
->dwarf2_per_objfile
;
7511 /* Link this CU into read_in_chain. */
7512 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7513 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7514 /* The chain owns it now. */
7515 m_new_cu
.release ();
7519 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7520 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7521 assumed to have already done the lookup to find the DWO file).
7523 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7524 THIS_CU->is_debug_types, but nothing else.
7526 We fill in THIS_CU->length.
7528 THIS_CU->cu is always freed when done.
7529 This is done in order to not leave THIS_CU->cu in a state where we have
7530 to care whether it refers to the "main" CU or the DWO CU.
7532 When parent_cu is passed, it is used to provide a default value for
7533 str_offsets_base and addr_base from the parent. */
7535 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7536 struct dwarf2_cu
*parent_cu
,
7537 struct dwo_file
*dwo_file
)
7538 : die_reader_specs
{},
7541 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7542 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7543 struct dwarf2_section_info
*section
= this_cu
->section
;
7544 bfd
*abfd
= section
->get_bfd_owner ();
7545 struct dwarf2_section_info
*abbrev_section
;
7546 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7549 if (dwarf_die_debug
)
7550 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7551 this_cu
->is_debug_types
? "type" : "comp",
7552 sect_offset_str (this_cu
->sect_off
));
7554 gdb_assert (this_cu
->cu
== NULL
);
7556 abbrev_section
= (dwo_file
!= NULL
7557 ? &dwo_file
->sections
.abbrev
7558 : get_abbrev_section_for_cu (this_cu
));
7560 /* This is cheap if the section is already read in. */
7561 section
->read (objfile
);
7563 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7565 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7566 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7567 &m_new_cu
->header
, section
,
7568 abbrev_section
, info_ptr
,
7569 (this_cu
->is_debug_types
7571 : rcuh_kind::COMPILE
));
7573 if (parent_cu
!= nullptr)
7575 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7576 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7578 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7580 /* Skip dummy compilation units. */
7581 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7582 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7588 m_abbrev_table_holder
7589 = abbrev_table_read_table (objfile
, abbrev_section
,
7590 m_new_cu
->header
.abbrev_sect_off
);
7592 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7593 m_abbrev_table_holder
.get ());
7594 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7598 /* Type Unit Groups.
7600 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7601 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7602 so that all types coming from the same compilation (.o file) are grouped
7603 together. A future step could be to put the types in the same symtab as
7604 the CU the types ultimately came from. */
7607 hash_type_unit_group (const void *item
)
7609 const struct type_unit_group
*tu_group
7610 = (const struct type_unit_group
*) item
;
7612 return hash_stmt_list_entry (&tu_group
->hash
);
7616 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7618 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7619 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7621 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7624 /* Allocate a hash table for type unit groups. */
7627 allocate_type_unit_groups_table (struct objfile
*objfile
)
7629 return htab_create_alloc_ex (3,
7630 hash_type_unit_group
,
7633 &objfile
->objfile_obstack
,
7634 hashtab_obstack_allocate
,
7635 dummy_obstack_deallocate
);
7638 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7639 partial symtabs. We combine several TUs per psymtab to not let the size
7640 of any one psymtab grow too big. */
7641 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7642 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7644 /* Helper routine for get_type_unit_group.
7645 Create the type_unit_group object used to hold one or more TUs. */
7647 static struct type_unit_group
*
7648 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7650 struct dwarf2_per_objfile
*dwarf2_per_objfile
7651 = cu
->per_cu
->dwarf2_per_objfile
;
7652 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7653 struct dwarf2_per_cu_data
*per_cu
;
7654 struct type_unit_group
*tu_group
;
7656 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7657 struct type_unit_group
);
7658 per_cu
= &tu_group
->per_cu
;
7659 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7661 if (dwarf2_per_objfile
->using_index
)
7663 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7664 struct dwarf2_per_cu_quick_data
);
7668 unsigned int line_offset
= to_underlying (line_offset_struct
);
7669 dwarf2_psymtab
*pst
;
7672 /* Give the symtab a useful name for debug purposes. */
7673 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7674 name
= string_printf ("<type_units_%d>",
7675 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7677 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7679 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7680 pst
->anonymous
= true;
7683 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7684 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7689 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7690 STMT_LIST is a DW_AT_stmt_list attribute. */
7692 static struct type_unit_group
*
7693 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7695 struct dwarf2_per_objfile
*dwarf2_per_objfile
7696 = cu
->per_cu
->dwarf2_per_objfile
;
7697 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7698 struct type_unit_group
*tu_group
;
7700 unsigned int line_offset
;
7701 struct type_unit_group type_unit_group_for_lookup
;
7703 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7705 dwarf2_per_objfile
->type_unit_groups
=
7706 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7709 /* Do we need to create a new group, or can we use an existing one? */
7713 line_offset
= DW_UNSND (stmt_list
);
7714 ++tu_stats
->nr_symtab_sharers
;
7718 /* Ugh, no stmt_list. Rare, but we have to handle it.
7719 We can do various things here like create one group per TU or
7720 spread them over multiple groups to split up the expansion work.
7721 To avoid worst case scenarios (too many groups or too large groups)
7722 we, umm, group them in bunches. */
7723 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7724 | (tu_stats
->nr_stmt_less_type_units
7725 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7726 ++tu_stats
->nr_stmt_less_type_units
;
7729 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7730 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7731 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7732 &type_unit_group_for_lookup
, INSERT
);
7735 tu_group
= (struct type_unit_group
*) *slot
;
7736 gdb_assert (tu_group
!= NULL
);
7740 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7741 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7743 ++tu_stats
->nr_symtabs
;
7749 /* Partial symbol tables. */
7751 /* Create a psymtab named NAME and assign it to PER_CU.
7753 The caller must fill in the following details:
7754 dirname, textlow, texthigh. */
7756 static dwarf2_psymtab
*
7757 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7759 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7760 dwarf2_psymtab
*pst
;
7762 pst
= new dwarf2_psymtab (name
, objfile
, 0);
7764 pst
->psymtabs_addrmap_supported
= true;
7766 /* This is the glue that links PST into GDB's symbol API. */
7767 pst
->per_cu_data
= per_cu
;
7768 per_cu
->v
.psymtab
= pst
;
7773 /* DIE reader function for process_psymtab_comp_unit. */
7776 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7777 const gdb_byte
*info_ptr
,
7778 struct die_info
*comp_unit_die
,
7780 int want_partial_unit
,
7781 enum language pretend_language
)
7783 struct dwarf2_cu
*cu
= reader
->cu
;
7784 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
7785 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7786 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7788 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
7789 dwarf2_psymtab
*pst
;
7790 enum pc_bounds_kind cu_bounds_kind
;
7791 const char *filename
;
7793 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
7796 gdb_assert (! per_cu
->is_debug_types
);
7798 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
7800 /* Allocate a new partial symbol table structure. */
7801 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
7802 if (filename
== NULL
)
7805 pst
= create_partial_symtab (per_cu
, filename
);
7807 /* This must be done before calling dwarf2_build_include_psymtabs. */
7808 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7810 baseaddr
= objfile
->text_section_offset ();
7812 dwarf2_find_base_address (comp_unit_die
, cu
);
7814 /* Possibly set the default values of LOWPC and HIGHPC from
7816 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
7817 &best_highpc
, cu
, pst
);
7818 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
7821 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
7824 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
7826 /* Store the contiguous range if it is not empty; it can be
7827 empty for CUs with no code. */
7828 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
7832 /* Check if comp unit has_children.
7833 If so, read the rest of the partial symbols from this comp unit.
7834 If not, there's no more debug_info for this comp unit. */
7837 struct partial_die_info
*first_die
;
7838 CORE_ADDR lowpc
, highpc
;
7840 lowpc
= ((CORE_ADDR
) -1);
7841 highpc
= ((CORE_ADDR
) 0);
7843 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7845 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
7846 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
7848 /* If we didn't find a lowpc, set it to highpc to avoid
7849 complaints from `maint check'. */
7850 if (lowpc
== ((CORE_ADDR
) -1))
7853 /* If the compilation unit didn't have an explicit address range,
7854 then use the information extracted from its child dies. */
7855 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
7858 best_highpc
= highpc
;
7861 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
7862 best_lowpc
+ baseaddr
)
7864 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
7865 best_highpc
+ baseaddr
)
7868 end_psymtab_common (objfile
, pst
);
7870 if (!cu
->per_cu
->imported_symtabs_empty ())
7873 int len
= cu
->per_cu
->imported_symtabs_size ();
7875 /* Fill in 'dependencies' here; we fill in 'users' in a
7877 pst
->number_of_dependencies
= len
;
7879 = objfile
->partial_symtabs
->allocate_dependencies (len
);
7880 for (i
= 0; i
< len
; ++i
)
7882 pst
->dependencies
[i
]
7883 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
7886 cu
->per_cu
->imported_symtabs_free ();
7889 /* Get the list of files included in the current compilation unit,
7890 and build a psymtab for each of them. */
7891 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
7893 if (dwarf_read_debug
)
7894 fprintf_unfiltered (gdb_stdlog
,
7895 "Psymtab for %s unit @%s: %s - %s"
7896 ", %d global, %d static syms\n",
7897 per_cu
->is_debug_types
? "type" : "comp",
7898 sect_offset_str (per_cu
->sect_off
),
7899 paddress (gdbarch
, pst
->text_low (objfile
)),
7900 paddress (gdbarch
, pst
->text_high (objfile
)),
7901 pst
->n_global_syms
, pst
->n_static_syms
);
7904 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
7905 Process compilation unit THIS_CU for a psymtab. */
7908 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
7909 int want_partial_unit
,
7910 enum language pretend_language
)
7912 /* If this compilation unit was already read in, free the
7913 cached copy in order to read it in again. This is
7914 necessary because we skipped some symbols when we first
7915 read in the compilation unit (see load_partial_dies).
7916 This problem could be avoided, but the benefit is unclear. */
7917 if (this_cu
->cu
!= NULL
)
7918 free_one_cached_comp_unit (this_cu
);
7920 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
7926 else if (this_cu
->is_debug_types
)
7927 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
7928 reader
.has_children
);
7930 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
7931 reader
.comp_unit_die
,
7932 reader
.has_children
,
7936 /* Age out any secondary CUs. */
7937 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
7940 /* Reader function for build_type_psymtabs. */
7943 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
7944 const gdb_byte
*info_ptr
,
7945 struct die_info
*type_unit_die
,
7948 struct dwarf2_per_objfile
*dwarf2_per_objfile
7949 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
7950 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7951 struct dwarf2_cu
*cu
= reader
->cu
;
7952 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
7953 struct signatured_type
*sig_type
;
7954 struct type_unit_group
*tu_group
;
7955 struct attribute
*attr
;
7956 struct partial_die_info
*first_die
;
7957 CORE_ADDR lowpc
, highpc
;
7958 dwarf2_psymtab
*pst
;
7960 gdb_assert (per_cu
->is_debug_types
);
7961 sig_type
= (struct signatured_type
*) per_cu
;
7966 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
7967 tu_group
= get_type_unit_group (cu
, attr
);
7969 if (tu_group
->tus
== nullptr)
7970 tu_group
->tus
= new std::vector
<signatured_type
*>;
7971 tu_group
->tus
->push_back (sig_type
);
7973 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
7974 pst
= create_partial_symtab (per_cu
, "");
7975 pst
->anonymous
= true;
7977 first_die
= load_partial_dies (reader
, info_ptr
, 1);
7979 lowpc
= (CORE_ADDR
) -1;
7980 highpc
= (CORE_ADDR
) 0;
7981 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
7983 end_psymtab_common (objfile
, pst
);
7986 /* Struct used to sort TUs by their abbreviation table offset. */
7988 struct tu_abbrev_offset
7990 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
7991 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
7994 signatured_type
*sig_type
;
7995 sect_offset abbrev_offset
;
7998 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8001 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8002 const struct tu_abbrev_offset
&b
)
8004 return a
.abbrev_offset
< b
.abbrev_offset
;
8007 /* Efficiently read all the type units.
8008 This does the bulk of the work for build_type_psymtabs.
8010 The efficiency is because we sort TUs by the abbrev table they use and
8011 only read each abbrev table once. In one program there are 200K TUs
8012 sharing 8K abbrev tables.
8014 The main purpose of this function is to support building the
8015 dwarf2_per_objfile->type_unit_groups table.
8016 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8017 can collapse the search space by grouping them by stmt_list.
8018 The savings can be significant, in the same program from above the 200K TUs
8019 share 8K stmt_list tables.
8021 FUNC is expected to call get_type_unit_group, which will create the
8022 struct type_unit_group if necessary and add it to
8023 dwarf2_per_objfile->type_unit_groups. */
8026 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8028 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8029 abbrev_table_up abbrev_table
;
8030 sect_offset abbrev_offset
;
8032 /* It's up to the caller to not call us multiple times. */
8033 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8035 if (dwarf2_per_objfile
->all_type_units
.empty ())
8038 /* TUs typically share abbrev tables, and there can be way more TUs than
8039 abbrev tables. Sort by abbrev table to reduce the number of times we
8040 read each abbrev table in.
8041 Alternatives are to punt or to maintain a cache of abbrev tables.
8042 This is simpler and efficient enough for now.
8044 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8045 symtab to use). Typically TUs with the same abbrev offset have the same
8046 stmt_list value too so in practice this should work well.
8048 The basic algorithm here is:
8050 sort TUs by abbrev table
8051 for each TU with same abbrev table:
8052 read abbrev table if first user
8053 read TU top level DIE
8054 [IWBN if DWO skeletons had DW_AT_stmt_list]
8057 if (dwarf_read_debug
)
8058 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8060 /* Sort in a separate table to maintain the order of all_type_units
8061 for .gdb_index: TU indices directly index all_type_units. */
8062 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8063 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8065 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8066 sorted_by_abbrev
.emplace_back
8067 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8068 sig_type
->per_cu
.section
,
8069 sig_type
->per_cu
.sect_off
));
8071 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8072 sort_tu_by_abbrev_offset
);
8074 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8076 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8078 /* Switch to the next abbrev table if necessary. */
8079 if (abbrev_table
== NULL
8080 || tu
.abbrev_offset
!= abbrev_offset
)
8082 abbrev_offset
= tu
.abbrev_offset
;
8084 abbrev_table_read_table (dwarf2_per_objfile
->objfile
,
8085 &dwarf2_per_objfile
->abbrev
,
8087 ++tu_stats
->nr_uniq_abbrev_tables
;
8090 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8092 if (!reader
.dummy_p
)
8093 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8094 reader
.comp_unit_die
,
8095 reader
.has_children
);
8099 /* Print collected type unit statistics. */
8102 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8104 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8106 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8107 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8108 dwarf2_per_objfile
->all_type_units
.size ());
8109 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8110 tu_stats
->nr_uniq_abbrev_tables
);
8111 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8112 tu_stats
->nr_symtabs
);
8113 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8114 tu_stats
->nr_symtab_sharers
);
8115 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8116 tu_stats
->nr_stmt_less_type_units
);
8117 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8118 tu_stats
->nr_all_type_units_reallocs
);
8121 /* Traversal function for build_type_psymtabs. */
8124 build_type_psymtab_dependencies (void **slot
, void *info
)
8126 struct dwarf2_per_objfile
*dwarf2_per_objfile
8127 = (struct dwarf2_per_objfile
*) info
;
8128 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8129 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8130 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8131 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8132 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8135 gdb_assert (len
> 0);
8136 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8138 pst
->number_of_dependencies
= len
;
8139 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8140 for (i
= 0; i
< len
; ++i
)
8142 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8143 gdb_assert (iter
->per_cu
.is_debug_types
);
8144 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8145 iter
->type_unit_group
= tu_group
;
8148 delete tu_group
->tus
;
8149 tu_group
->tus
= nullptr;
8154 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8155 Build partial symbol tables for the .debug_types comp-units. */
8158 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8160 if (! create_all_type_units (dwarf2_per_objfile
))
8163 build_type_psymtabs_1 (dwarf2_per_objfile
);
8166 /* Traversal function for process_skeletonless_type_unit.
8167 Read a TU in a DWO file and build partial symbols for it. */
8170 process_skeletonless_type_unit (void **slot
, void *info
)
8172 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8173 struct dwarf2_per_objfile
*dwarf2_per_objfile
8174 = (struct dwarf2_per_objfile
*) info
;
8175 struct signatured_type find_entry
, *entry
;
8177 /* If this TU doesn't exist in the global table, add it and read it in. */
8179 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8181 dwarf2_per_objfile
->signatured_types
8182 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8185 find_entry
.signature
= dwo_unit
->signature
;
8186 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8188 /* If we've already seen this type there's nothing to do. What's happening
8189 is we're doing our own version of comdat-folding here. */
8193 /* This does the job that create_all_type_units would have done for
8195 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8196 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8199 /* This does the job that build_type_psymtabs_1 would have done. */
8200 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8201 if (!reader
.dummy_p
)
8202 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8203 reader
.comp_unit_die
, reader
.has_children
);
8208 /* Traversal function for process_skeletonless_type_units. */
8211 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8213 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8215 if (dwo_file
->tus
!= NULL
)
8217 htab_traverse_noresize (dwo_file
->tus
,
8218 process_skeletonless_type_unit
, info
);
8224 /* Scan all TUs of DWO files, verifying we've processed them.
8225 This is needed in case a TU was emitted without its skeleton.
8226 Note: This can't be done until we know what all the DWO files are. */
8229 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8231 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8232 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8233 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8235 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8236 process_dwo_file_for_skeletonless_type_units
,
8237 dwarf2_per_objfile
);
8241 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8244 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8246 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8248 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8253 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8255 /* Set the 'user' field only if it is not already set. */
8256 if (pst
->dependencies
[j
]->user
== NULL
)
8257 pst
->dependencies
[j
]->user
= pst
;
8262 /* Build the partial symbol table by doing a quick pass through the
8263 .debug_info and .debug_abbrev sections. */
8266 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8268 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8270 if (dwarf_read_debug
)
8272 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8273 objfile_name (objfile
));
8276 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8278 dwarf2_per_objfile
->info
.read (objfile
);
8280 /* Any cached compilation units will be linked by the per-objfile
8281 read_in_chain. Make sure to free them when we're done. */
8282 free_cached_comp_units
freer (dwarf2_per_objfile
);
8284 build_type_psymtabs (dwarf2_per_objfile
);
8286 create_all_comp_units (dwarf2_per_objfile
);
8288 /* Create a temporary address map on a temporary obstack. We later
8289 copy this to the final obstack. */
8290 auto_obstack temp_obstack
;
8292 scoped_restore save_psymtabs_addrmap
8293 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8294 addrmap_create_mutable (&temp_obstack
));
8296 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8297 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8299 /* This has to wait until we read the CUs, we need the list of DWOs. */
8300 process_skeletonless_type_units (dwarf2_per_objfile
);
8302 /* Now that all TUs have been processed we can fill in the dependencies. */
8303 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8305 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8306 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8309 if (dwarf_read_debug
)
8310 print_tu_stats (dwarf2_per_objfile
);
8312 set_partial_user (dwarf2_per_objfile
);
8314 objfile
->partial_symtabs
->psymtabs_addrmap
8315 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8316 objfile
->partial_symtabs
->obstack ());
8317 /* At this point we want to keep the address map. */
8318 save_psymtabs_addrmap
.release ();
8320 if (dwarf_read_debug
)
8321 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8322 objfile_name (objfile
));
8325 /* Load the partial DIEs for a secondary CU into memory.
8326 This is also used when rereading a primary CU with load_all_dies. */
8329 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8331 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8333 if (!reader
.dummy_p
)
8335 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8338 /* Check if comp unit has_children.
8339 If so, read the rest of the partial symbols from this comp unit.
8340 If not, there's no more debug_info for this comp unit. */
8341 if (reader
.has_children
)
8342 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8347 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8348 struct dwarf2_section_info
*section
,
8349 struct dwarf2_section_info
*abbrev_section
,
8350 unsigned int is_dwz
)
8352 const gdb_byte
*info_ptr
;
8353 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8355 if (dwarf_read_debug
)
8356 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8357 section
->get_name (),
8358 section
->get_file_name ());
8360 section
->read (objfile
);
8362 info_ptr
= section
->buffer
;
8364 while (info_ptr
< section
->buffer
+ section
->size
)
8366 struct dwarf2_per_cu_data
*this_cu
;
8368 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8370 comp_unit_head cu_header
;
8371 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8372 abbrev_section
, info_ptr
,
8373 rcuh_kind::COMPILE
);
8375 /* Save the compilation unit for later lookup. */
8376 if (cu_header
.unit_type
!= DW_UT_type
)
8378 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8379 struct dwarf2_per_cu_data
);
8380 memset (this_cu
, 0, sizeof (*this_cu
));
8384 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8385 struct signatured_type
);
8386 memset (sig_type
, 0, sizeof (*sig_type
));
8387 sig_type
->signature
= cu_header
.signature
;
8388 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8389 this_cu
= &sig_type
->per_cu
;
8391 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8392 this_cu
->sect_off
= sect_off
;
8393 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8394 this_cu
->is_dwz
= is_dwz
;
8395 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8396 this_cu
->section
= section
;
8398 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8400 info_ptr
= info_ptr
+ this_cu
->length
;
8404 /* Create a list of all compilation units in OBJFILE.
8405 This is only done for -readnow and building partial symtabs. */
8408 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8410 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8411 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8412 &dwarf2_per_objfile
->abbrev
, 0);
8414 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8416 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8420 /* Process all loaded DIEs for compilation unit CU, starting at
8421 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8422 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8423 DW_AT_ranges). See the comments of add_partial_subprogram on how
8424 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8427 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8428 CORE_ADDR
*highpc
, int set_addrmap
,
8429 struct dwarf2_cu
*cu
)
8431 struct partial_die_info
*pdi
;
8433 /* Now, march along the PDI's, descending into ones which have
8434 interesting children but skipping the children of the other ones,
8435 until we reach the end of the compilation unit. */
8443 /* Anonymous namespaces or modules have no name but have interesting
8444 children, so we need to look at them. Ditto for anonymous
8447 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8448 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8449 || pdi
->tag
== DW_TAG_imported_unit
8450 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8454 case DW_TAG_subprogram
:
8455 case DW_TAG_inlined_subroutine
:
8456 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8458 case DW_TAG_constant
:
8459 case DW_TAG_variable
:
8460 case DW_TAG_typedef
:
8461 case DW_TAG_union_type
:
8462 if (!pdi
->is_declaration
)
8464 add_partial_symbol (pdi
, cu
);
8467 case DW_TAG_class_type
:
8468 case DW_TAG_interface_type
:
8469 case DW_TAG_structure_type
:
8470 if (!pdi
->is_declaration
)
8472 add_partial_symbol (pdi
, cu
);
8474 if ((cu
->language
== language_rust
8475 || cu
->language
== language_cplus
) && pdi
->has_children
)
8476 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8479 case DW_TAG_enumeration_type
:
8480 if (!pdi
->is_declaration
)
8481 add_partial_enumeration (pdi
, cu
);
8483 case DW_TAG_base_type
:
8484 case DW_TAG_subrange_type
:
8485 /* File scope base type definitions are added to the partial
8487 add_partial_symbol (pdi
, cu
);
8489 case DW_TAG_namespace
:
8490 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8493 if (!pdi
->is_declaration
)
8494 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8496 case DW_TAG_imported_unit
:
8498 struct dwarf2_per_cu_data
*per_cu
;
8500 /* For now we don't handle imported units in type units. */
8501 if (cu
->per_cu
->is_debug_types
)
8503 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8504 " supported in type units [in module %s]"),
8505 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8508 per_cu
= dwarf2_find_containing_comp_unit
8509 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8510 cu
->per_cu
->dwarf2_per_objfile
);
8512 /* Go read the partial unit, if needed. */
8513 if (per_cu
->v
.psymtab
== NULL
)
8514 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8516 cu
->per_cu
->imported_symtabs_push (per_cu
);
8519 case DW_TAG_imported_declaration
:
8520 add_partial_symbol (pdi
, cu
);
8527 /* If the die has a sibling, skip to the sibling. */
8529 pdi
= pdi
->die_sibling
;
8533 /* Functions used to compute the fully scoped name of a partial DIE.
8535 Normally, this is simple. For C++, the parent DIE's fully scoped
8536 name is concatenated with "::" and the partial DIE's name.
8537 Enumerators are an exception; they use the scope of their parent
8538 enumeration type, i.e. the name of the enumeration type is not
8539 prepended to the enumerator.
8541 There are two complexities. One is DW_AT_specification; in this
8542 case "parent" means the parent of the target of the specification,
8543 instead of the direct parent of the DIE. The other is compilers
8544 which do not emit DW_TAG_namespace; in this case we try to guess
8545 the fully qualified name of structure types from their members'
8546 linkage names. This must be done using the DIE's children rather
8547 than the children of any DW_AT_specification target. We only need
8548 to do this for structures at the top level, i.e. if the target of
8549 any DW_AT_specification (if any; otherwise the DIE itself) does not
8552 /* Compute the scope prefix associated with PDI's parent, in
8553 compilation unit CU. The result will be allocated on CU's
8554 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8555 field. NULL is returned if no prefix is necessary. */
8557 partial_die_parent_scope (struct partial_die_info
*pdi
,
8558 struct dwarf2_cu
*cu
)
8560 const char *grandparent_scope
;
8561 struct partial_die_info
*parent
, *real_pdi
;
8563 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8564 then this means the parent of the specification DIE. */
8567 while (real_pdi
->has_specification
)
8569 auto res
= find_partial_die (real_pdi
->spec_offset
,
8570 real_pdi
->spec_is_dwz
, cu
);
8575 parent
= real_pdi
->die_parent
;
8579 if (parent
->scope_set
)
8580 return parent
->scope
;
8584 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8586 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8587 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8588 Work around this problem here. */
8589 if (cu
->language
== language_cplus
8590 && parent
->tag
== DW_TAG_namespace
8591 && strcmp (parent
->name
, "::") == 0
8592 && grandparent_scope
== NULL
)
8594 parent
->scope
= NULL
;
8595 parent
->scope_set
= 1;
8599 /* Nested subroutines in Fortran get a prefix. */
8600 if (pdi
->tag
== DW_TAG_enumerator
)
8601 /* Enumerators should not get the name of the enumeration as a prefix. */
8602 parent
->scope
= grandparent_scope
;
8603 else if (parent
->tag
== DW_TAG_namespace
8604 || parent
->tag
== DW_TAG_module
8605 || parent
->tag
== DW_TAG_structure_type
8606 || parent
->tag
== DW_TAG_class_type
8607 || parent
->tag
== DW_TAG_interface_type
8608 || parent
->tag
== DW_TAG_union_type
8609 || parent
->tag
== DW_TAG_enumeration_type
8610 || (cu
->language
== language_fortran
8611 && parent
->tag
== DW_TAG_subprogram
8612 && pdi
->tag
== DW_TAG_subprogram
))
8614 if (grandparent_scope
== NULL
)
8615 parent
->scope
= parent
->name
;
8617 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8619 parent
->name
, 0, cu
);
8623 /* FIXME drow/2004-04-01: What should we be doing with
8624 function-local names? For partial symbols, we should probably be
8626 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8627 dwarf_tag_name (parent
->tag
),
8628 sect_offset_str (pdi
->sect_off
));
8629 parent
->scope
= grandparent_scope
;
8632 parent
->scope_set
= 1;
8633 return parent
->scope
;
8636 /* Return the fully scoped name associated with PDI, from compilation unit
8637 CU. The result will be allocated with malloc. */
8639 static gdb::unique_xmalloc_ptr
<char>
8640 partial_die_full_name (struct partial_die_info
*pdi
,
8641 struct dwarf2_cu
*cu
)
8643 const char *parent_scope
;
8645 /* If this is a template instantiation, we can not work out the
8646 template arguments from partial DIEs. So, unfortunately, we have
8647 to go through the full DIEs. At least any work we do building
8648 types here will be reused if full symbols are loaded later. */
8649 if (pdi
->has_template_arguments
)
8653 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8655 struct die_info
*die
;
8656 struct attribute attr
;
8657 struct dwarf2_cu
*ref_cu
= cu
;
8659 /* DW_FORM_ref_addr is using section offset. */
8660 attr
.name
= (enum dwarf_attribute
) 0;
8661 attr
.form
= DW_FORM_ref_addr
;
8662 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8663 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8665 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8669 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8670 if (parent_scope
== NULL
)
8673 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8678 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8680 struct dwarf2_per_objfile
*dwarf2_per_objfile
8681 = cu
->per_cu
->dwarf2_per_objfile
;
8682 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8683 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8685 const char *actual_name
= NULL
;
8688 baseaddr
= objfile
->text_section_offset ();
8690 gdb::unique_xmalloc_ptr
<char> built_actual_name
8691 = partial_die_full_name (pdi
, cu
);
8692 if (built_actual_name
!= NULL
)
8693 actual_name
= built_actual_name
.get ();
8695 if (actual_name
== NULL
)
8696 actual_name
= pdi
->name
;
8700 case DW_TAG_inlined_subroutine
:
8701 case DW_TAG_subprogram
:
8702 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8704 if (pdi
->is_external
8705 || cu
->language
== language_ada
8706 || (cu
->language
== language_fortran
8707 && pdi
->die_parent
!= NULL
8708 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8710 /* Normally, only "external" DIEs are part of the global scope.
8711 But in Ada and Fortran, we want to be able to access nested
8712 procedures globally. So all Ada and Fortran subprograms are
8713 stored in the global scope. */
8714 add_psymbol_to_list (actual_name
,
8715 built_actual_name
!= NULL
,
8716 VAR_DOMAIN
, LOC_BLOCK
,
8717 SECT_OFF_TEXT (objfile
),
8718 psymbol_placement::GLOBAL
,
8720 cu
->language
, objfile
);
8724 add_psymbol_to_list (actual_name
,
8725 built_actual_name
!= NULL
,
8726 VAR_DOMAIN
, LOC_BLOCK
,
8727 SECT_OFF_TEXT (objfile
),
8728 psymbol_placement::STATIC
,
8729 addr
, cu
->language
, objfile
);
8732 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8733 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8735 case DW_TAG_constant
:
8736 add_psymbol_to_list (actual_name
,
8737 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8738 -1, (pdi
->is_external
8739 ? psymbol_placement::GLOBAL
8740 : psymbol_placement::STATIC
),
8741 0, cu
->language
, objfile
);
8743 case DW_TAG_variable
:
8745 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8749 && !dwarf2_per_objfile
->has_section_at_zero
)
8751 /* A global or static variable may also have been stripped
8752 out by the linker if unused, in which case its address
8753 will be nullified; do not add such variables into partial
8754 symbol table then. */
8756 else if (pdi
->is_external
)
8759 Don't enter into the minimal symbol tables as there is
8760 a minimal symbol table entry from the ELF symbols already.
8761 Enter into partial symbol table if it has a location
8762 descriptor or a type.
8763 If the location descriptor is missing, new_symbol will create
8764 a LOC_UNRESOLVED symbol, the address of the variable will then
8765 be determined from the minimal symbol table whenever the variable
8767 The address for the partial symbol table entry is not
8768 used by GDB, but it comes in handy for debugging partial symbol
8771 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8772 add_psymbol_to_list (actual_name
,
8773 built_actual_name
!= NULL
,
8774 VAR_DOMAIN
, LOC_STATIC
,
8775 SECT_OFF_TEXT (objfile
),
8776 psymbol_placement::GLOBAL
,
8777 addr
, cu
->language
, objfile
);
8781 int has_loc
= pdi
->d
.locdesc
!= NULL
;
8783 /* Static Variable. Skip symbols whose value we cannot know (those
8784 without location descriptors or constant values). */
8785 if (!has_loc
&& !pdi
->has_const_value
)
8788 add_psymbol_to_list (actual_name
,
8789 built_actual_name
!= NULL
,
8790 VAR_DOMAIN
, LOC_STATIC
,
8791 SECT_OFF_TEXT (objfile
),
8792 psymbol_placement::STATIC
,
8794 cu
->language
, objfile
);
8797 case DW_TAG_typedef
:
8798 case DW_TAG_base_type
:
8799 case DW_TAG_subrange_type
:
8800 add_psymbol_to_list (actual_name
,
8801 built_actual_name
!= NULL
,
8802 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8803 psymbol_placement::STATIC
,
8804 0, cu
->language
, objfile
);
8806 case DW_TAG_imported_declaration
:
8807 case DW_TAG_namespace
:
8808 add_psymbol_to_list (actual_name
,
8809 built_actual_name
!= NULL
,
8810 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
8811 psymbol_placement::GLOBAL
,
8812 0, cu
->language
, objfile
);
8815 /* With Fortran 77 there might be a "BLOCK DATA" module
8816 available without any name. If so, we skip the module as it
8817 doesn't bring any value. */
8818 if (actual_name
!= nullptr)
8819 add_psymbol_to_list (actual_name
,
8820 built_actual_name
!= NULL
,
8821 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
8822 psymbol_placement::GLOBAL
,
8823 0, cu
->language
, objfile
);
8825 case DW_TAG_class_type
:
8826 case DW_TAG_interface_type
:
8827 case DW_TAG_structure_type
:
8828 case DW_TAG_union_type
:
8829 case DW_TAG_enumeration_type
:
8830 /* Skip external references. The DWARF standard says in the section
8831 about "Structure, Union, and Class Type Entries": "An incomplete
8832 structure, union or class type is represented by a structure,
8833 union or class entry that does not have a byte size attribute
8834 and that has a DW_AT_declaration attribute." */
8835 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
8838 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
8839 static vs. global. */
8840 add_psymbol_to_list (actual_name
,
8841 built_actual_name
!= NULL
,
8842 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
8843 cu
->language
== language_cplus
8844 ? psymbol_placement::GLOBAL
8845 : psymbol_placement::STATIC
,
8846 0, cu
->language
, objfile
);
8849 case DW_TAG_enumerator
:
8850 add_psymbol_to_list (actual_name
,
8851 built_actual_name
!= NULL
,
8852 VAR_DOMAIN
, LOC_CONST
, -1,
8853 cu
->language
== language_cplus
8854 ? psymbol_placement::GLOBAL
8855 : psymbol_placement::STATIC
,
8856 0, cu
->language
, objfile
);
8863 /* Read a partial die corresponding to a namespace; also, add a symbol
8864 corresponding to that namespace to the symbol table. NAMESPACE is
8865 the name of the enclosing namespace. */
8868 add_partial_namespace (struct partial_die_info
*pdi
,
8869 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8870 int set_addrmap
, struct dwarf2_cu
*cu
)
8872 /* Add a symbol for the namespace. */
8874 add_partial_symbol (pdi
, cu
);
8876 /* Now scan partial symbols in that namespace. */
8878 if (pdi
->has_children
)
8879 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8882 /* Read a partial die corresponding to a Fortran module. */
8885 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
8886 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
8888 /* Add a symbol for the namespace. */
8890 add_partial_symbol (pdi
, cu
);
8892 /* Now scan partial symbols in that module. */
8894 if (pdi
->has_children
)
8895 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
8898 /* Read a partial die corresponding to a subprogram or an inlined
8899 subprogram and create a partial symbol for that subprogram.
8900 When the CU language allows it, this routine also defines a partial
8901 symbol for each nested subprogram that this subprogram contains.
8902 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
8903 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
8905 PDI may also be a lexical block, in which case we simply search
8906 recursively for subprograms defined inside that lexical block.
8907 Again, this is only performed when the CU language allows this
8908 type of definitions. */
8911 add_partial_subprogram (struct partial_die_info
*pdi
,
8912 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
8913 int set_addrmap
, struct dwarf2_cu
*cu
)
8915 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
8917 if (pdi
->has_pc_info
)
8919 if (pdi
->lowpc
< *lowpc
)
8920 *lowpc
= pdi
->lowpc
;
8921 if (pdi
->highpc
> *highpc
)
8922 *highpc
= pdi
->highpc
;
8925 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8926 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8928 CORE_ADDR this_highpc
;
8929 CORE_ADDR this_lowpc
;
8931 baseaddr
= objfile
->text_section_offset ();
8933 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8934 pdi
->lowpc
+ baseaddr
)
8937 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
8938 pdi
->highpc
+ baseaddr
)
8940 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8941 this_lowpc
, this_highpc
- 1,
8942 cu
->per_cu
->v
.psymtab
);
8946 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
8948 if (!pdi
->is_declaration
)
8949 /* Ignore subprogram DIEs that do not have a name, they are
8950 illegal. Do not emit a complaint at this point, we will
8951 do so when we convert this psymtab into a symtab. */
8953 add_partial_symbol (pdi
, cu
);
8957 if (! pdi
->has_children
)
8960 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
8962 pdi
= pdi
->die_child
;
8966 if (pdi
->tag
== DW_TAG_subprogram
8967 || pdi
->tag
== DW_TAG_inlined_subroutine
8968 || pdi
->tag
== DW_TAG_lexical_block
)
8969 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8970 pdi
= pdi
->die_sibling
;
8975 /* Read a partial die corresponding to an enumeration type. */
8978 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
8979 struct dwarf2_cu
*cu
)
8981 struct partial_die_info
*pdi
;
8983 if (enum_pdi
->name
!= NULL
)
8984 add_partial_symbol (enum_pdi
, cu
);
8986 pdi
= enum_pdi
->die_child
;
8989 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
8990 complaint (_("malformed enumerator DIE ignored"));
8992 add_partial_symbol (pdi
, cu
);
8993 pdi
= pdi
->die_sibling
;
8997 /* Return the initial uleb128 in the die at INFO_PTR. */
9000 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9002 unsigned int bytes_read
;
9004 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9007 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9008 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9010 Return the corresponding abbrev, or NULL if the number is zero (indicating
9011 an empty DIE). In either case *BYTES_READ will be set to the length of
9012 the initial number. */
9014 static struct abbrev_info
*
9015 peek_die_abbrev (const die_reader_specs
&reader
,
9016 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9018 dwarf2_cu
*cu
= reader
.cu
;
9019 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9020 unsigned int abbrev_number
9021 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9023 if (abbrev_number
== 0)
9026 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9029 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9030 " at offset %s [in module %s]"),
9031 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9032 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9038 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9039 Returns a pointer to the end of a series of DIEs, terminated by an empty
9040 DIE. Any children of the skipped DIEs will also be skipped. */
9042 static const gdb_byte
*
9043 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9047 unsigned int bytes_read
;
9048 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9051 return info_ptr
+ bytes_read
;
9053 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9057 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9058 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9059 abbrev corresponding to that skipped uleb128 should be passed in
9060 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9063 static const gdb_byte
*
9064 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9065 struct abbrev_info
*abbrev
)
9067 unsigned int bytes_read
;
9068 struct attribute attr
;
9069 bfd
*abfd
= reader
->abfd
;
9070 struct dwarf2_cu
*cu
= reader
->cu
;
9071 const gdb_byte
*buffer
= reader
->buffer
;
9072 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9073 unsigned int form
, i
;
9075 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9077 /* The only abbrev we care about is DW_AT_sibling. */
9078 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9081 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9083 if (attr
.form
== DW_FORM_ref_addr
)
9084 complaint (_("ignoring absolute DW_AT_sibling"));
9087 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9088 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9090 if (sibling_ptr
< info_ptr
)
9091 complaint (_("DW_AT_sibling points backwards"));
9092 else if (sibling_ptr
> reader
->buffer_end
)
9093 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9099 /* If it isn't DW_AT_sibling, skip this attribute. */
9100 form
= abbrev
->attrs
[i
].form
;
9104 case DW_FORM_ref_addr
:
9105 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9106 and later it is offset sized. */
9107 if (cu
->header
.version
== 2)
9108 info_ptr
+= cu
->header
.addr_size
;
9110 info_ptr
+= cu
->header
.offset_size
;
9112 case DW_FORM_GNU_ref_alt
:
9113 info_ptr
+= cu
->header
.offset_size
;
9116 info_ptr
+= cu
->header
.addr_size
;
9124 case DW_FORM_flag_present
:
9125 case DW_FORM_implicit_const
:
9142 case DW_FORM_ref_sig8
:
9145 case DW_FORM_data16
:
9148 case DW_FORM_string
:
9149 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9150 info_ptr
+= bytes_read
;
9152 case DW_FORM_sec_offset
:
9154 case DW_FORM_GNU_strp_alt
:
9155 info_ptr
+= cu
->header
.offset_size
;
9157 case DW_FORM_exprloc
:
9159 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9160 info_ptr
+= bytes_read
;
9162 case DW_FORM_block1
:
9163 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9165 case DW_FORM_block2
:
9166 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9168 case DW_FORM_block4
:
9169 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9175 case DW_FORM_ref_udata
:
9176 case DW_FORM_GNU_addr_index
:
9177 case DW_FORM_GNU_str_index
:
9178 case DW_FORM_rnglistx
:
9179 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9181 case DW_FORM_indirect
:
9182 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9183 info_ptr
+= bytes_read
;
9184 /* We need to continue parsing from here, so just go back to
9186 goto skip_attribute
;
9189 error (_("Dwarf Error: Cannot handle %s "
9190 "in DWARF reader [in module %s]"),
9191 dwarf_form_name (form
),
9192 bfd_get_filename (abfd
));
9196 if (abbrev
->has_children
)
9197 return skip_children (reader
, info_ptr
);
9202 /* Locate ORIG_PDI's sibling.
9203 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9205 static const gdb_byte
*
9206 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9207 struct partial_die_info
*orig_pdi
,
9208 const gdb_byte
*info_ptr
)
9210 /* Do we know the sibling already? */
9212 if (orig_pdi
->sibling
)
9213 return orig_pdi
->sibling
;
9215 /* Are there any children to deal with? */
9217 if (!orig_pdi
->has_children
)
9220 /* Skip the children the long way. */
9222 return skip_children (reader
, info_ptr
);
9225 /* Expand this partial symbol table into a full symbol table. SELF is
9229 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9231 struct dwarf2_per_objfile
*dwarf2_per_objfile
9232 = get_dwarf2_per_objfile (objfile
);
9234 gdb_assert (!readin
);
9235 /* If this psymtab is constructed from a debug-only objfile, the
9236 has_section_at_zero flag will not necessarily be correct. We
9237 can get the correct value for this flag by looking at the data
9238 associated with the (presumably stripped) associated objfile. */
9239 if (objfile
->separate_debug_objfile_backlink
)
9241 struct dwarf2_per_objfile
*dpo_backlink
9242 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9244 dwarf2_per_objfile
->has_section_at_zero
9245 = dpo_backlink
->has_section_at_zero
;
9248 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9250 expand_psymtab (objfile
);
9252 process_cu_includes (dwarf2_per_objfile
);
9255 /* Reading in full CUs. */
9257 /* Add PER_CU to the queue. */
9260 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9261 enum language pretend_language
)
9263 struct dwarf2_queue_item
*item
;
9266 item
= XNEW (struct dwarf2_queue_item
);
9267 item
->per_cu
= per_cu
;
9268 item
->pretend_language
= pretend_language
;
9271 if (dwarf2_queue
== NULL
)
9272 dwarf2_queue
= item
;
9274 dwarf2_queue_tail
->next
= item
;
9276 dwarf2_queue_tail
= item
;
9279 /* If PER_CU is not yet queued, add it to the queue.
9280 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9282 The result is non-zero if PER_CU was queued, otherwise the result is zero
9283 meaning either PER_CU is already queued or it is already loaded.
9285 N.B. There is an invariant here that if a CU is queued then it is loaded.
9286 The caller is required to load PER_CU if we return non-zero. */
9289 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9290 struct dwarf2_per_cu_data
*per_cu
,
9291 enum language pretend_language
)
9293 /* We may arrive here during partial symbol reading, if we need full
9294 DIEs to process an unusual case (e.g. template arguments). Do
9295 not queue PER_CU, just tell our caller to load its DIEs. */
9296 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9298 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9303 /* Mark the dependence relation so that we don't flush PER_CU
9305 if (dependent_cu
!= NULL
)
9306 dwarf2_add_dependence (dependent_cu
, per_cu
);
9308 /* If it's already on the queue, we have nothing to do. */
9312 /* If the compilation unit is already loaded, just mark it as
9314 if (per_cu
->cu
!= NULL
)
9316 per_cu
->cu
->last_used
= 0;
9320 /* Add it to the queue. */
9321 queue_comp_unit (per_cu
, pretend_language
);
9326 /* Process the queue. */
9329 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9331 struct dwarf2_queue_item
*item
, *next_item
;
9333 if (dwarf_read_debug
)
9335 fprintf_unfiltered (gdb_stdlog
,
9336 "Expanding one or more symtabs of objfile %s ...\n",
9337 objfile_name (dwarf2_per_objfile
->objfile
));
9340 /* The queue starts out with one item, but following a DIE reference
9341 may load a new CU, adding it to the end of the queue. */
9342 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9344 if ((dwarf2_per_objfile
->using_index
9345 ? !item
->per_cu
->v
.quick
->compunit_symtab
9346 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9347 /* Skip dummy CUs. */
9348 && item
->per_cu
->cu
!= NULL
)
9350 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9351 unsigned int debug_print_threshold
;
9354 if (per_cu
->is_debug_types
)
9356 struct signatured_type
*sig_type
=
9357 (struct signatured_type
*) per_cu
;
9359 sprintf (buf
, "TU %s at offset %s",
9360 hex_string (sig_type
->signature
),
9361 sect_offset_str (per_cu
->sect_off
));
9362 /* There can be 100s of TUs.
9363 Only print them in verbose mode. */
9364 debug_print_threshold
= 2;
9368 sprintf (buf
, "CU at offset %s",
9369 sect_offset_str (per_cu
->sect_off
));
9370 debug_print_threshold
= 1;
9373 if (dwarf_read_debug
>= debug_print_threshold
)
9374 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9376 if (per_cu
->is_debug_types
)
9377 process_full_type_unit (per_cu
, item
->pretend_language
);
9379 process_full_comp_unit (per_cu
, item
->pretend_language
);
9381 if (dwarf_read_debug
>= debug_print_threshold
)
9382 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9385 item
->per_cu
->queued
= 0;
9386 next_item
= item
->next
;
9390 dwarf2_queue_tail
= NULL
;
9392 if (dwarf_read_debug
)
9394 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9395 objfile_name (dwarf2_per_objfile
->objfile
));
9399 /* Read in full symbols for PST, and anything it depends on. */
9402 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9404 struct dwarf2_per_cu_data
*per_cu
;
9409 read_dependencies (objfile
);
9411 per_cu
= per_cu_data
;
9415 /* It's an include file, no symbols to read for it.
9416 Everything is in the parent symtab. */
9421 dw2_do_instantiate_symtab (per_cu
, false);
9424 /* Trivial hash function for die_info: the hash value of a DIE
9425 is its offset in .debug_info for this objfile. */
9428 die_hash (const void *item
)
9430 const struct die_info
*die
= (const struct die_info
*) item
;
9432 return to_underlying (die
->sect_off
);
9435 /* Trivial comparison function for die_info structures: two DIEs
9436 are equal if they have the same offset. */
9439 die_eq (const void *item_lhs
, const void *item_rhs
)
9441 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9442 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9444 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9447 /* Load the DIEs associated with PER_CU into memory. */
9450 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9452 enum language pretend_language
)
9454 gdb_assert (! this_cu
->is_debug_types
);
9456 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9460 struct dwarf2_cu
*cu
= reader
.cu
;
9461 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9463 gdb_assert (cu
->die_hash
== NULL
);
9465 htab_create_alloc_ex (cu
->header
.length
/ 12,
9469 &cu
->comp_unit_obstack
,
9470 hashtab_obstack_allocate
,
9471 dummy_obstack_deallocate
);
9473 if (reader
.has_children
)
9474 reader
.comp_unit_die
->child
9475 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9476 &info_ptr
, reader
.comp_unit_die
);
9477 cu
->dies
= reader
.comp_unit_die
;
9478 /* comp_unit_die is not stored in die_hash, no need. */
9480 /* We try not to read any attributes in this function, because not
9481 all CUs needed for references have been loaded yet, and symbol
9482 table processing isn't initialized. But we have to set the CU language,
9483 or we won't be able to build types correctly.
9484 Similarly, if we do not read the producer, we can not apply
9485 producer-specific interpretation. */
9486 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9489 /* Add a DIE to the delayed physname list. */
9492 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9493 const char *name
, struct die_info
*die
,
9494 struct dwarf2_cu
*cu
)
9496 struct delayed_method_info mi
;
9498 mi
.fnfield_index
= fnfield_index
;
9502 cu
->method_list
.push_back (mi
);
9505 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9506 "const" / "volatile". If so, decrements LEN by the length of the
9507 modifier and return true. Otherwise return false. */
9511 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9513 size_t mod_len
= sizeof (mod
) - 1;
9514 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9522 /* Compute the physnames of any methods on the CU's method list.
9524 The computation of method physnames is delayed in order to avoid the
9525 (bad) condition that one of the method's formal parameters is of an as yet
9529 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9531 /* Only C++ delays computing physnames. */
9532 if (cu
->method_list
.empty ())
9534 gdb_assert (cu
->language
== language_cplus
);
9536 for (const delayed_method_info
&mi
: cu
->method_list
)
9538 const char *physname
;
9539 struct fn_fieldlist
*fn_flp
9540 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9541 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9542 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9543 = physname
? physname
: "";
9545 /* Since there's no tag to indicate whether a method is a
9546 const/volatile overload, extract that information out of the
9548 if (physname
!= NULL
)
9550 size_t len
= strlen (physname
);
9554 if (physname
[len
] == ')') /* shortcut */
9556 else if (check_modifier (physname
, len
, " const"))
9557 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9558 else if (check_modifier (physname
, len
, " volatile"))
9559 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9566 /* The list is no longer needed. */
9567 cu
->method_list
.clear ();
9570 /* Go objects should be embedded in a DW_TAG_module DIE,
9571 and it's not clear if/how imported objects will appear.
9572 To keep Go support simple until that's worked out,
9573 go back through what we've read and create something usable.
9574 We could do this while processing each DIE, and feels kinda cleaner,
9575 but that way is more invasive.
9576 This is to, for example, allow the user to type "p var" or "b main"
9577 without having to specify the package name, and allow lookups
9578 of module.object to work in contexts that use the expression
9582 fixup_go_packaging (struct dwarf2_cu
*cu
)
9584 gdb::unique_xmalloc_ptr
<char> package_name
;
9585 struct pending
*list
;
9588 for (list
= *cu
->get_builder ()->get_global_symbols ();
9592 for (i
= 0; i
< list
->nsyms
; ++i
)
9594 struct symbol
*sym
= list
->symbol
[i
];
9596 if (sym
->language () == language_go
9597 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9599 gdb::unique_xmalloc_ptr
<char> this_package_name
9600 (go_symbol_package_name (sym
));
9602 if (this_package_name
== NULL
)
9604 if (package_name
== NULL
)
9605 package_name
= std::move (this_package_name
);
9608 struct objfile
*objfile
9609 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9610 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9611 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9612 (symbol_symtab (sym
) != NULL
9613 ? symtab_to_filename_for_display
9614 (symbol_symtab (sym
))
9615 : objfile_name (objfile
)),
9616 this_package_name
.get (), package_name
.get ());
9622 if (package_name
!= NULL
)
9624 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9625 const char *saved_package_name
9626 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9627 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9628 saved_package_name
);
9631 sym
= allocate_symbol (objfile
);
9632 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9633 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9634 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9635 e.g., "main" finds the "main" module and not C's main(). */
9636 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9637 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9638 SYMBOL_TYPE (sym
) = type
;
9640 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9644 /* Allocate a fully-qualified name consisting of the two parts on the
9648 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9650 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9653 /* A helper that allocates a struct discriminant_info to attach to a
9656 static struct discriminant_info
*
9657 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9660 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9661 gdb_assert (discriminant_index
== -1
9662 || (discriminant_index
>= 0
9663 && discriminant_index
< TYPE_NFIELDS (type
)));
9664 gdb_assert (default_index
== -1
9665 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9667 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9669 struct discriminant_info
*disc
9670 = ((struct discriminant_info
*)
9672 offsetof (struct discriminant_info
, discriminants
)
9673 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9674 disc
->default_index
= default_index
;
9675 disc
->discriminant_index
= discriminant_index
;
9677 struct dynamic_prop prop
;
9678 prop
.kind
= PROP_UNDEFINED
;
9679 prop
.data
.baton
= disc
;
9681 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9686 /* Some versions of rustc emitted enums in an unusual way.
9688 Ordinary enums were emitted as unions. The first element of each
9689 structure in the union was named "RUST$ENUM$DISR". This element
9690 held the discriminant.
9692 These versions of Rust also implemented the "non-zero"
9693 optimization. When the enum had two values, and one is empty and
9694 the other holds a pointer that cannot be zero, the pointer is used
9695 as the discriminant, with a zero value meaning the empty variant.
9696 Here, the union's first member is of the form
9697 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9698 where the fieldnos are the indices of the fields that should be
9699 traversed in order to find the field (which may be several fields deep)
9700 and the variantname is the name of the variant of the case when the
9703 This function recognizes whether TYPE is of one of these forms,
9704 and, if so, smashes it to be a variant type. */
9707 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9709 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9711 /* We don't need to deal with empty enums. */
9712 if (TYPE_NFIELDS (type
) == 0)
9715 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9716 if (TYPE_NFIELDS (type
) == 1
9717 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9719 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9721 /* Decode the field name to find the offset of the
9723 ULONGEST bit_offset
= 0;
9724 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
9725 while (name
[0] >= '0' && name
[0] <= '9')
9728 unsigned long index
= strtoul (name
, &tail
, 10);
9731 || index
>= TYPE_NFIELDS (field_type
)
9732 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
9733 != FIELD_LOC_KIND_BITPOS
))
9735 complaint (_("Could not parse Rust enum encoding string \"%s\""
9737 TYPE_FIELD_NAME (type
, 0),
9738 objfile_name (objfile
));
9743 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
9744 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
9747 /* Make a union to hold the variants. */
9748 struct type
*union_type
= alloc_type (objfile
);
9749 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9750 TYPE_NFIELDS (union_type
) = 3;
9751 TYPE_FIELDS (union_type
)
9752 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
9753 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9754 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9756 /* Put the discriminant must at index 0. */
9757 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
9758 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9759 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9760 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
9762 /* The order of fields doesn't really matter, so put the real
9763 field at index 1 and the data-less field at index 2. */
9764 struct discriminant_info
*disc
9765 = alloc_discriminant_info (union_type
, 0, 1);
9766 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
9767 TYPE_FIELD_NAME (union_type
, 1)
9768 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
9769 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
9770 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9771 TYPE_FIELD_NAME (union_type
, 1));
9773 const char *dataless_name
9774 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
9776 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
9778 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
9779 /* NAME points into the original discriminant name, which
9780 already has the correct lifetime. */
9781 TYPE_FIELD_NAME (union_type
, 2) = name
;
9782 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
9783 disc
->discriminants
[2] = 0;
9785 /* Smash this type to be a structure type. We have to do this
9786 because the type has already been recorded. */
9787 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9788 TYPE_NFIELDS (type
) = 1;
9790 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
9792 /* Install the variant part. */
9793 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9794 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9795 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9797 /* A union with a single anonymous field is probably an old-style
9799 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
9801 /* Smash this type to be a structure type. We have to do this
9802 because the type has already been recorded. */
9803 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9805 /* Make a union to hold the variants. */
9806 struct type
*union_type
= alloc_type (objfile
);
9807 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9808 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
9809 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9810 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9811 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
9813 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
9814 const char *variant_name
9815 = rust_last_path_segment (TYPE_NAME (field_type
));
9816 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
9817 TYPE_NAME (field_type
)
9818 = rust_fully_qualify (&objfile
->objfile_obstack
,
9819 TYPE_NAME (type
), variant_name
);
9821 /* Install the union in the outer struct type. */
9822 TYPE_NFIELDS (type
) = 1;
9824 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
9825 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9826 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9827 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9829 alloc_discriminant_info (union_type
, -1, 0);
9833 struct type
*disr_type
= nullptr;
9834 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
9836 disr_type
= TYPE_FIELD_TYPE (type
, i
);
9838 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
9840 /* All fields of a true enum will be structs. */
9843 else if (TYPE_NFIELDS (disr_type
) == 0)
9845 /* Could be data-less variant, so keep going. */
9846 disr_type
= nullptr;
9848 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
9849 "RUST$ENUM$DISR") != 0)
9851 /* Not a Rust enum. */
9861 /* If we got here without a discriminant, then it's probably
9863 if (disr_type
== nullptr)
9866 /* Smash this type to be a structure type. We have to do this
9867 because the type has already been recorded. */
9868 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
9870 /* Make a union to hold the variants. */
9871 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
9872 struct type
*union_type
= alloc_type (objfile
);
9873 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
9874 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
9875 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
9876 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
9877 TYPE_FIELDS (union_type
)
9878 = (struct field
*) TYPE_ZALLOC (union_type
,
9879 (TYPE_NFIELDS (union_type
)
9880 * sizeof (struct field
)));
9882 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
9883 TYPE_NFIELDS (type
) * sizeof (struct field
));
9885 /* Install the discriminant at index 0 in the union. */
9886 TYPE_FIELD (union_type
, 0) = *disr_field
;
9887 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
9888 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
9890 /* Install the union in the outer struct type. */
9891 TYPE_FIELD_TYPE (type
, 0) = union_type
;
9892 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
9893 TYPE_NFIELDS (type
) = 1;
9895 /* Set the size and offset of the union type. */
9896 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
9898 /* We need a way to find the correct discriminant given a
9899 variant name. For convenience we build a map here. */
9900 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
9901 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
9902 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
9904 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
9907 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
9908 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
9912 int n_fields
= TYPE_NFIELDS (union_type
);
9913 struct discriminant_info
*disc
9914 = alloc_discriminant_info (union_type
, 0, -1);
9915 /* Skip the discriminant here. */
9916 for (int i
= 1; i
< n_fields
; ++i
)
9918 /* Find the final word in the name of this variant's type.
9919 That name can be used to look up the correct
9921 const char *variant_name
9922 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
9925 auto iter
= discriminant_map
.find (variant_name
);
9926 if (iter
!= discriminant_map
.end ())
9927 disc
->discriminants
[i
] = iter
->second
;
9929 /* Remove the discriminant field, if it exists. */
9930 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
9931 if (TYPE_NFIELDS (sub_type
) > 0)
9933 --TYPE_NFIELDS (sub_type
);
9934 ++TYPE_FIELDS (sub_type
);
9936 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
9937 TYPE_NAME (sub_type
)
9938 = rust_fully_qualify (&objfile
->objfile_obstack
,
9939 TYPE_NAME (type
), variant_name
);
9944 /* Rewrite some Rust unions to be structures with variants parts. */
9947 rust_union_quirks (struct dwarf2_cu
*cu
)
9949 gdb_assert (cu
->language
== language_rust
);
9950 for (type
*type_
: cu
->rust_unions
)
9951 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
9952 /* We don't need this any more. */
9953 cu
->rust_unions
.clear ();
9956 /* Return the symtab for PER_CU. This works properly regardless of
9957 whether we're using the index or psymtabs. */
9959 static struct compunit_symtab
*
9960 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
9962 return (per_cu
->dwarf2_per_objfile
->using_index
9963 ? per_cu
->v
.quick
->compunit_symtab
9964 : per_cu
->v
.psymtab
->compunit_symtab
);
9967 /* A helper function for computing the list of all symbol tables
9968 included by PER_CU. */
9971 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
9972 htab_t all_children
, htab_t all_type_symtabs
,
9973 struct dwarf2_per_cu_data
*per_cu
,
9974 struct compunit_symtab
*immediate_parent
)
9977 struct compunit_symtab
*cust
;
9979 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
9982 /* This inclusion and its children have been processed. */
9987 /* Only add a CU if it has a symbol table. */
9988 cust
= get_compunit_symtab (per_cu
);
9991 /* If this is a type unit only add its symbol table if we haven't
9992 seen it yet (type unit per_cu's can share symtabs). */
9993 if (per_cu
->is_debug_types
)
9995 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
9999 result
->push_back (cust
);
10000 if (cust
->user
== NULL
)
10001 cust
->user
= immediate_parent
;
10006 result
->push_back (cust
);
10007 if (cust
->user
== NULL
)
10008 cust
->user
= immediate_parent
;
10012 if (!per_cu
->imported_symtabs_empty ())
10013 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10015 recursively_compute_inclusions (result
, all_children
,
10016 all_type_symtabs
, ptr
, cust
);
10020 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10024 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10026 gdb_assert (! per_cu
->is_debug_types
);
10028 if (!per_cu
->imported_symtabs_empty ())
10031 std::vector
<compunit_symtab
*> result_symtabs
;
10032 htab_t all_children
, all_type_symtabs
;
10033 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10035 /* If we don't have a symtab, we can just skip this case. */
10039 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10040 NULL
, xcalloc
, xfree
);
10041 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10042 NULL
, xcalloc
, xfree
);
10044 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10046 recursively_compute_inclusions (&result_symtabs
, all_children
,
10047 all_type_symtabs
, ptr
, cust
);
10050 /* Now we have a transitive closure of all the included symtabs. */
10051 len
= result_symtabs
.size ();
10053 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10054 struct compunit_symtab
*, len
+ 1);
10055 memcpy (cust
->includes
, result_symtabs
.data (),
10056 len
* sizeof (compunit_symtab
*));
10057 cust
->includes
[len
] = NULL
;
10059 htab_delete (all_children
);
10060 htab_delete (all_type_symtabs
);
10064 /* Compute the 'includes' field for the symtabs of all the CUs we just
10068 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10070 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10072 if (! iter
->is_debug_types
)
10073 compute_compunit_symtab_includes (iter
);
10076 dwarf2_per_objfile
->just_read_cus
.clear ();
10079 /* Generate full symbol information for PER_CU, whose DIEs have
10080 already been loaded into memory. */
10083 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10084 enum language pretend_language
)
10086 struct dwarf2_cu
*cu
= per_cu
->cu
;
10087 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10088 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10089 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10090 CORE_ADDR lowpc
, highpc
;
10091 struct compunit_symtab
*cust
;
10092 CORE_ADDR baseaddr
;
10093 struct block
*static_block
;
10096 baseaddr
= objfile
->text_section_offset ();
10098 /* Clear the list here in case something was left over. */
10099 cu
->method_list
.clear ();
10101 cu
->language
= pretend_language
;
10102 cu
->language_defn
= language_def (cu
->language
);
10104 /* Do line number decoding in read_file_scope () */
10105 process_die (cu
->dies
, cu
);
10107 /* For now fudge the Go package. */
10108 if (cu
->language
== language_go
)
10109 fixup_go_packaging (cu
);
10111 /* Now that we have processed all the DIEs in the CU, all the types
10112 should be complete, and it should now be safe to compute all of the
10114 compute_delayed_physnames (cu
);
10116 if (cu
->language
== language_rust
)
10117 rust_union_quirks (cu
);
10119 /* Some compilers don't define a DW_AT_high_pc attribute for the
10120 compilation unit. If the DW_AT_high_pc is missing, synthesize
10121 it, by scanning the DIE's below the compilation unit. */
10122 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10124 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10125 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10127 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10128 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10129 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10130 addrmap to help ensure it has an accurate map of pc values belonging to
10132 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10134 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10135 SECT_OFF_TEXT (objfile
),
10140 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10142 /* Set symtab language to language from DW_AT_language. If the
10143 compilation is from a C file generated by language preprocessors, do
10144 not set the language if it was already deduced by start_subfile. */
10145 if (!(cu
->language
== language_c
10146 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10147 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10149 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10150 produce DW_AT_location with location lists but it can be possibly
10151 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10152 there were bugs in prologue debug info, fixed later in GCC-4.5
10153 by "unwind info for epilogues" patch (which is not directly related).
10155 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10156 needed, it would be wrong due to missing DW_AT_producer there.
10158 Still one can confuse GDB by using non-standard GCC compilation
10159 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10161 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10162 cust
->locations_valid
= 1;
10164 if (gcc_4_minor
>= 5)
10165 cust
->epilogue_unwind_valid
= 1;
10167 cust
->call_site_htab
= cu
->call_site_htab
;
10170 if (dwarf2_per_objfile
->using_index
)
10171 per_cu
->v
.quick
->compunit_symtab
= cust
;
10174 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10175 pst
->compunit_symtab
= cust
;
10176 pst
->readin
= true;
10179 /* Push it for inclusion processing later. */
10180 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10182 /* Not needed any more. */
10183 cu
->reset_builder ();
10186 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10187 already been loaded into memory. */
10190 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10191 enum language pretend_language
)
10193 struct dwarf2_cu
*cu
= per_cu
->cu
;
10194 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10195 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10196 struct compunit_symtab
*cust
;
10197 struct signatured_type
*sig_type
;
10199 gdb_assert (per_cu
->is_debug_types
);
10200 sig_type
= (struct signatured_type
*) per_cu
;
10202 /* Clear the list here in case something was left over. */
10203 cu
->method_list
.clear ();
10205 cu
->language
= pretend_language
;
10206 cu
->language_defn
= language_def (cu
->language
);
10208 /* The symbol tables are set up in read_type_unit_scope. */
10209 process_die (cu
->dies
, cu
);
10211 /* For now fudge the Go package. */
10212 if (cu
->language
== language_go
)
10213 fixup_go_packaging (cu
);
10215 /* Now that we have processed all the DIEs in the CU, all the types
10216 should be complete, and it should now be safe to compute all of the
10218 compute_delayed_physnames (cu
);
10220 if (cu
->language
== language_rust
)
10221 rust_union_quirks (cu
);
10223 /* TUs share symbol tables.
10224 If this is the first TU to use this symtab, complete the construction
10225 of it with end_expandable_symtab. Otherwise, complete the addition of
10226 this TU's symbols to the existing symtab. */
10227 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10229 buildsym_compunit
*builder
= cu
->get_builder ();
10230 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10231 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10235 /* Set symtab language to language from DW_AT_language. If the
10236 compilation is from a C file generated by language preprocessors,
10237 do not set the language if it was already deduced by
10239 if (!(cu
->language
== language_c
10240 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10241 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10246 cu
->get_builder ()->augment_type_symtab ();
10247 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10250 if (dwarf2_per_objfile
->using_index
)
10251 per_cu
->v
.quick
->compunit_symtab
= cust
;
10254 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10255 pst
->compunit_symtab
= cust
;
10256 pst
->readin
= true;
10259 /* Not needed any more. */
10260 cu
->reset_builder ();
10263 /* Process an imported unit DIE. */
10266 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10268 struct attribute
*attr
;
10270 /* For now we don't handle imported units in type units. */
10271 if (cu
->per_cu
->is_debug_types
)
10273 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10274 " supported in type units [in module %s]"),
10275 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10278 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10281 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10282 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10283 dwarf2_per_cu_data
*per_cu
10284 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10285 cu
->per_cu
->dwarf2_per_objfile
);
10287 /* If necessary, add it to the queue and load its DIEs. */
10288 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10289 load_full_comp_unit (per_cu
, false, cu
->language
);
10291 cu
->per_cu
->imported_symtabs_push (per_cu
);
10295 /* RAII object that represents a process_die scope: i.e.,
10296 starts/finishes processing a DIE. */
10297 class process_die_scope
10300 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10301 : m_die (die
), m_cu (cu
)
10303 /* We should only be processing DIEs not already in process. */
10304 gdb_assert (!m_die
->in_process
);
10305 m_die
->in_process
= true;
10308 ~process_die_scope ()
10310 m_die
->in_process
= false;
10312 /* If we're done processing the DIE for the CU that owns the line
10313 header, we don't need the line header anymore. */
10314 if (m_cu
->line_header_die_owner
== m_die
)
10316 delete m_cu
->line_header
;
10317 m_cu
->line_header
= NULL
;
10318 m_cu
->line_header_die_owner
= NULL
;
10327 /* Process a die and its children. */
10330 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10332 process_die_scope
scope (die
, cu
);
10336 case DW_TAG_padding
:
10338 case DW_TAG_compile_unit
:
10339 case DW_TAG_partial_unit
:
10340 read_file_scope (die
, cu
);
10342 case DW_TAG_type_unit
:
10343 read_type_unit_scope (die
, cu
);
10345 case DW_TAG_subprogram
:
10346 /* Nested subprograms in Fortran get a prefix. */
10347 if (cu
->language
== language_fortran
10348 && die
->parent
!= NULL
10349 && die
->parent
->tag
== DW_TAG_subprogram
)
10350 cu
->processing_has_namespace_info
= true;
10351 /* Fall through. */
10352 case DW_TAG_inlined_subroutine
:
10353 read_func_scope (die
, cu
);
10355 case DW_TAG_lexical_block
:
10356 case DW_TAG_try_block
:
10357 case DW_TAG_catch_block
:
10358 read_lexical_block_scope (die
, cu
);
10360 case DW_TAG_call_site
:
10361 case DW_TAG_GNU_call_site
:
10362 read_call_site_scope (die
, cu
);
10364 case DW_TAG_class_type
:
10365 case DW_TAG_interface_type
:
10366 case DW_TAG_structure_type
:
10367 case DW_TAG_union_type
:
10368 process_structure_scope (die
, cu
);
10370 case DW_TAG_enumeration_type
:
10371 process_enumeration_scope (die
, cu
);
10374 /* These dies have a type, but processing them does not create
10375 a symbol or recurse to process the children. Therefore we can
10376 read them on-demand through read_type_die. */
10377 case DW_TAG_subroutine_type
:
10378 case DW_TAG_set_type
:
10379 case DW_TAG_array_type
:
10380 case DW_TAG_pointer_type
:
10381 case DW_TAG_ptr_to_member_type
:
10382 case DW_TAG_reference_type
:
10383 case DW_TAG_rvalue_reference_type
:
10384 case DW_TAG_string_type
:
10387 case DW_TAG_base_type
:
10388 case DW_TAG_subrange_type
:
10389 case DW_TAG_typedef
:
10390 /* Add a typedef symbol for the type definition, if it has a
10392 new_symbol (die
, read_type_die (die
, cu
), cu
);
10394 case DW_TAG_common_block
:
10395 read_common_block (die
, cu
);
10397 case DW_TAG_common_inclusion
:
10399 case DW_TAG_namespace
:
10400 cu
->processing_has_namespace_info
= true;
10401 read_namespace (die
, cu
);
10403 case DW_TAG_module
:
10404 cu
->processing_has_namespace_info
= true;
10405 read_module (die
, cu
);
10407 case DW_TAG_imported_declaration
:
10408 cu
->processing_has_namespace_info
= true;
10409 if (read_namespace_alias (die
, cu
))
10411 /* The declaration is not a global namespace alias. */
10412 /* Fall through. */
10413 case DW_TAG_imported_module
:
10414 cu
->processing_has_namespace_info
= true;
10415 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10416 || cu
->language
!= language_fortran
))
10417 complaint (_("Tag '%s' has unexpected children"),
10418 dwarf_tag_name (die
->tag
));
10419 read_import_statement (die
, cu
);
10422 case DW_TAG_imported_unit
:
10423 process_imported_unit_die (die
, cu
);
10426 case DW_TAG_variable
:
10427 read_variable (die
, cu
);
10431 new_symbol (die
, NULL
, cu
);
10436 /* DWARF name computation. */
10438 /* A helper function for dwarf2_compute_name which determines whether DIE
10439 needs to have the name of the scope prepended to the name listed in the
10443 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10445 struct attribute
*attr
;
10449 case DW_TAG_namespace
:
10450 case DW_TAG_typedef
:
10451 case DW_TAG_class_type
:
10452 case DW_TAG_interface_type
:
10453 case DW_TAG_structure_type
:
10454 case DW_TAG_union_type
:
10455 case DW_TAG_enumeration_type
:
10456 case DW_TAG_enumerator
:
10457 case DW_TAG_subprogram
:
10458 case DW_TAG_inlined_subroutine
:
10459 case DW_TAG_member
:
10460 case DW_TAG_imported_declaration
:
10463 case DW_TAG_variable
:
10464 case DW_TAG_constant
:
10465 /* We only need to prefix "globally" visible variables. These include
10466 any variable marked with DW_AT_external or any variable that
10467 lives in a namespace. [Variables in anonymous namespaces
10468 require prefixing, but they are not DW_AT_external.] */
10470 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10472 struct dwarf2_cu
*spec_cu
= cu
;
10474 return die_needs_namespace (die_specification (die
, &spec_cu
),
10478 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10479 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10480 && die
->parent
->tag
!= DW_TAG_module
)
10482 /* A variable in a lexical block of some kind does not need a
10483 namespace, even though in C++ such variables may be external
10484 and have a mangled name. */
10485 if (die
->parent
->tag
== DW_TAG_lexical_block
10486 || die
->parent
->tag
== DW_TAG_try_block
10487 || die
->parent
->tag
== DW_TAG_catch_block
10488 || die
->parent
->tag
== DW_TAG_subprogram
)
10497 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10498 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10499 defined for the given DIE. */
10501 static struct attribute
*
10502 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10504 struct attribute
*attr
;
10506 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10508 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10513 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10514 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10515 defined for the given DIE. */
10517 static const char *
10518 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10520 const char *linkage_name
;
10522 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10523 if (linkage_name
== NULL
)
10524 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10526 return linkage_name
;
10529 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10530 compute the physname for the object, which include a method's:
10531 - formal parameters (C++),
10532 - receiver type (Go),
10534 The term "physname" is a bit confusing.
10535 For C++, for example, it is the demangled name.
10536 For Go, for example, it's the mangled name.
10538 For Ada, return the DIE's linkage name rather than the fully qualified
10539 name. PHYSNAME is ignored..
10541 The result is allocated on the objfile_obstack and canonicalized. */
10543 static const char *
10544 dwarf2_compute_name (const char *name
,
10545 struct die_info
*die
, struct dwarf2_cu
*cu
,
10548 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10551 name
= dwarf2_name (die
, cu
);
10553 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10554 but otherwise compute it by typename_concat inside GDB.
10555 FIXME: Actually this is not really true, or at least not always true.
10556 It's all very confusing. compute_and_set_names doesn't try to demangle
10557 Fortran names because there is no mangling standard. So new_symbol
10558 will set the demangled name to the result of dwarf2_full_name, and it is
10559 the demangled name that GDB uses if it exists. */
10560 if (cu
->language
== language_ada
10561 || (cu
->language
== language_fortran
&& physname
))
10563 /* For Ada unit, we prefer the linkage name over the name, as
10564 the former contains the exported name, which the user expects
10565 to be able to reference. Ideally, we want the user to be able
10566 to reference this entity using either natural or linkage name,
10567 but we haven't started looking at this enhancement yet. */
10568 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10570 if (linkage_name
!= NULL
)
10571 return linkage_name
;
10574 /* These are the only languages we know how to qualify names in. */
10576 && (cu
->language
== language_cplus
10577 || cu
->language
== language_fortran
|| cu
->language
== language_d
10578 || cu
->language
== language_rust
))
10580 if (die_needs_namespace (die
, cu
))
10582 const char *prefix
;
10583 const char *canonical_name
= NULL
;
10587 prefix
= determine_prefix (die
, cu
);
10588 if (*prefix
!= '\0')
10590 gdb::unique_xmalloc_ptr
<char> prefixed_name
10591 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10593 buf
.puts (prefixed_name
.get ());
10598 /* Template parameters may be specified in the DIE's DW_AT_name, or
10599 as children with DW_TAG_template_type_param or
10600 DW_TAG_value_type_param. If the latter, add them to the name
10601 here. If the name already has template parameters, then
10602 skip this step; some versions of GCC emit both, and
10603 it is more efficient to use the pre-computed name.
10605 Something to keep in mind about this process: it is very
10606 unlikely, or in some cases downright impossible, to produce
10607 something that will match the mangled name of a function.
10608 If the definition of the function has the same debug info,
10609 we should be able to match up with it anyway. But fallbacks
10610 using the minimal symbol, for instance to find a method
10611 implemented in a stripped copy of libstdc++, will not work.
10612 If we do not have debug info for the definition, we will have to
10613 match them up some other way.
10615 When we do name matching there is a related problem with function
10616 templates; two instantiated function templates are allowed to
10617 differ only by their return types, which we do not add here. */
10619 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10621 struct attribute
*attr
;
10622 struct die_info
*child
;
10625 die
->building_fullname
= 1;
10627 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10631 const gdb_byte
*bytes
;
10632 struct dwarf2_locexpr_baton
*baton
;
10635 if (child
->tag
!= DW_TAG_template_type_param
10636 && child
->tag
!= DW_TAG_template_value_param
)
10647 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10650 complaint (_("template parameter missing DW_AT_type"));
10651 buf
.puts ("UNKNOWN_TYPE");
10654 type
= die_type (child
, cu
);
10656 if (child
->tag
== DW_TAG_template_type_param
)
10658 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10659 &type_print_raw_options
);
10663 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10666 complaint (_("template parameter missing "
10667 "DW_AT_const_value"));
10668 buf
.puts ("UNKNOWN_VALUE");
10672 dwarf2_const_value_attr (attr
, type
, name
,
10673 &cu
->comp_unit_obstack
, cu
,
10674 &value
, &bytes
, &baton
);
10676 if (TYPE_NOSIGN (type
))
10677 /* GDB prints characters as NUMBER 'CHAR'. If that's
10678 changed, this can use value_print instead. */
10679 c_printchar (value
, type
, &buf
);
10682 struct value_print_options opts
;
10685 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10689 else if (bytes
!= NULL
)
10691 v
= allocate_value (type
);
10692 memcpy (value_contents_writeable (v
), bytes
,
10693 TYPE_LENGTH (type
));
10696 v
= value_from_longest (type
, value
);
10698 /* Specify decimal so that we do not depend on
10700 get_formatted_print_options (&opts
, 'd');
10702 value_print (v
, &buf
, &opts
);
10707 die
->building_fullname
= 0;
10711 /* Close the argument list, with a space if necessary
10712 (nested templates). */
10713 if (!buf
.empty () && buf
.string ().back () == '>')
10720 /* For C++ methods, append formal parameter type
10721 information, if PHYSNAME. */
10723 if (physname
&& die
->tag
== DW_TAG_subprogram
10724 && cu
->language
== language_cplus
)
10726 struct type
*type
= read_type_die (die
, cu
);
10728 c_type_print_args (type
, &buf
, 1, cu
->language
,
10729 &type_print_raw_options
);
10731 if (cu
->language
== language_cplus
)
10733 /* Assume that an artificial first parameter is
10734 "this", but do not crash if it is not. RealView
10735 marks unnamed (and thus unused) parameters as
10736 artificial; there is no way to differentiate
10738 if (TYPE_NFIELDS (type
) > 0
10739 && TYPE_FIELD_ARTIFICIAL (type
, 0)
10740 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
10741 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
10743 buf
.puts (" const");
10747 const std::string
&intermediate_name
= buf
.string ();
10749 if (cu
->language
== language_cplus
)
10751 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
10752 &objfile
->per_bfd
->storage_obstack
);
10754 /* If we only computed INTERMEDIATE_NAME, or if
10755 INTERMEDIATE_NAME is already canonical, then we need to
10756 copy it to the appropriate obstack. */
10757 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
10758 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
10759 intermediate_name
);
10761 name
= canonical_name
;
10768 /* Return the fully qualified name of DIE, based on its DW_AT_name.
10769 If scope qualifiers are appropriate they will be added. The result
10770 will be allocated on the storage_obstack, or NULL if the DIE does
10771 not have a name. NAME may either be from a previous call to
10772 dwarf2_name or NULL.
10774 The output string will be canonicalized (if C++). */
10776 static const char *
10777 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10779 return dwarf2_compute_name (name
, die
, cu
, 0);
10782 /* Construct a physname for the given DIE in CU. NAME may either be
10783 from a previous call to dwarf2_name or NULL. The result will be
10784 allocated on the objfile_objstack or NULL if the DIE does not have a
10787 The output string will be canonicalized (if C++). */
10789 static const char *
10790 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
10792 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10793 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
10796 /* In this case dwarf2_compute_name is just a shortcut not building anything
10798 if (!die_needs_namespace (die
, cu
))
10799 return dwarf2_compute_name (name
, die
, cu
, 1);
10801 mangled
= dw2_linkage_name (die
, cu
);
10803 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
10804 See https://github.com/rust-lang/rust/issues/32925. */
10805 if (cu
->language
== language_rust
&& mangled
!= NULL
10806 && strchr (mangled
, '{') != NULL
)
10809 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
10811 gdb::unique_xmalloc_ptr
<char> demangled
;
10812 if (mangled
!= NULL
)
10815 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
10817 /* Do nothing (do not demangle the symbol name). */
10819 else if (cu
->language
== language_go
)
10821 /* This is a lie, but we already lie to the caller new_symbol.
10822 new_symbol assumes we return the mangled name.
10823 This just undoes that lie until things are cleaned up. */
10827 /* Use DMGL_RET_DROP for C++ template functions to suppress
10828 their return type. It is easier for GDB users to search
10829 for such functions as `name(params)' than `long name(params)'.
10830 In such case the minimal symbol names do not match the full
10831 symbol names but for template functions there is never a need
10832 to look up their definition from their declaration so
10833 the only disadvantage remains the minimal symbol variant
10834 `long name(params)' does not have the proper inferior type. */
10835 demangled
.reset (gdb_demangle (mangled
,
10836 (DMGL_PARAMS
| DMGL_ANSI
10837 | DMGL_RET_DROP
)));
10840 canon
= demangled
.get ();
10848 if (canon
== NULL
|| check_physname
)
10850 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
10852 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
10854 /* It may not mean a bug in GDB. The compiler could also
10855 compute DW_AT_linkage_name incorrectly. But in such case
10856 GDB would need to be bug-to-bug compatible. */
10858 complaint (_("Computed physname <%s> does not match demangled <%s> "
10859 "(from linkage <%s>) - DIE at %s [in module %s]"),
10860 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
10861 objfile_name (objfile
));
10863 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
10864 is available here - over computed PHYSNAME. It is safer
10865 against both buggy GDB and buggy compilers. */
10879 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
10884 /* Inspect DIE in CU for a namespace alias. If one exists, record
10885 a new symbol for it.
10887 Returns 1 if a namespace alias was recorded, 0 otherwise. */
10890 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
10892 struct attribute
*attr
;
10894 /* If the die does not have a name, this is not a namespace
10896 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10900 struct die_info
*d
= die
;
10901 struct dwarf2_cu
*imported_cu
= cu
;
10903 /* If the compiler has nested DW_AT_imported_declaration DIEs,
10904 keep inspecting DIEs until we hit the underlying import. */
10905 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
10906 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
10908 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
10912 d
= follow_die_ref (d
, attr
, &imported_cu
);
10913 if (d
->tag
!= DW_TAG_imported_declaration
)
10917 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
10919 complaint (_("DIE at %s has too many recursively imported "
10920 "declarations"), sect_offset_str (d
->sect_off
));
10927 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10929 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
10930 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
10932 /* This declaration is a global namespace alias. Add
10933 a symbol for it whose type is the aliased namespace. */
10934 new_symbol (die
, type
, cu
);
10943 /* Return the using directives repository (global or local?) to use in the
10944 current context for CU.
10946 For Ada, imported declarations can materialize renamings, which *may* be
10947 global. However it is impossible (for now?) in DWARF to distinguish
10948 "external" imported declarations and "static" ones. As all imported
10949 declarations seem to be static in all other languages, make them all CU-wide
10950 global only in Ada. */
10952 static struct using_direct
**
10953 using_directives (struct dwarf2_cu
*cu
)
10955 if (cu
->language
== language_ada
10956 && cu
->get_builder ()->outermost_context_p ())
10957 return cu
->get_builder ()->get_global_using_directives ();
10959 return cu
->get_builder ()->get_local_using_directives ();
10962 /* Read the import statement specified by the given die and record it. */
10965 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
10967 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10968 struct attribute
*import_attr
;
10969 struct die_info
*imported_die
, *child_die
;
10970 struct dwarf2_cu
*imported_cu
;
10971 const char *imported_name
;
10972 const char *imported_name_prefix
;
10973 const char *canonical_name
;
10974 const char *import_alias
;
10975 const char *imported_declaration
= NULL
;
10976 const char *import_prefix
;
10977 std::vector
<const char *> excludes
;
10979 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10980 if (import_attr
== NULL
)
10982 complaint (_("Tag '%s' has no DW_AT_import"),
10983 dwarf_tag_name (die
->tag
));
10988 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
10989 imported_name
= dwarf2_name (imported_die
, imported_cu
);
10990 if (imported_name
== NULL
)
10992 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
10994 The import in the following code:
11008 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11009 <52> DW_AT_decl_file : 1
11010 <53> DW_AT_decl_line : 6
11011 <54> DW_AT_import : <0x75>
11012 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11013 <59> DW_AT_name : B
11014 <5b> DW_AT_decl_file : 1
11015 <5c> DW_AT_decl_line : 2
11016 <5d> DW_AT_type : <0x6e>
11018 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11019 <76> DW_AT_byte_size : 4
11020 <77> DW_AT_encoding : 5 (signed)
11022 imports the wrong die ( 0x75 instead of 0x58 ).
11023 This case will be ignored until the gcc bug is fixed. */
11027 /* Figure out the local name after import. */
11028 import_alias
= dwarf2_name (die
, cu
);
11030 /* Figure out where the statement is being imported to. */
11031 import_prefix
= determine_prefix (die
, cu
);
11033 /* Figure out what the scope of the imported die is and prepend it
11034 to the name of the imported die. */
11035 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11037 if (imported_die
->tag
!= DW_TAG_namespace
11038 && imported_die
->tag
!= DW_TAG_module
)
11040 imported_declaration
= imported_name
;
11041 canonical_name
= imported_name_prefix
;
11043 else if (strlen (imported_name_prefix
) > 0)
11044 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11045 imported_name_prefix
,
11046 (cu
->language
== language_d
? "." : "::"),
11047 imported_name
, (char *) NULL
);
11049 canonical_name
= imported_name
;
11051 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11052 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11053 child_die
= sibling_die (child_die
))
11055 /* DWARF-4: A Fortran use statement with a “rename list” may be
11056 represented by an imported module entry with an import attribute
11057 referring to the module and owned entries corresponding to those
11058 entities that are renamed as part of being imported. */
11060 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11062 complaint (_("child DW_TAG_imported_declaration expected "
11063 "- DIE at %s [in module %s]"),
11064 sect_offset_str (child_die
->sect_off
),
11065 objfile_name (objfile
));
11069 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11070 if (import_attr
== NULL
)
11072 complaint (_("Tag '%s' has no DW_AT_import"),
11073 dwarf_tag_name (child_die
->tag
));
11078 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11080 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11081 if (imported_name
== NULL
)
11083 complaint (_("child DW_TAG_imported_declaration has unknown "
11084 "imported name - DIE at %s [in module %s]"),
11085 sect_offset_str (child_die
->sect_off
),
11086 objfile_name (objfile
));
11090 excludes
.push_back (imported_name
);
11092 process_die (child_die
, cu
);
11095 add_using_directive (using_directives (cu
),
11099 imported_declaration
,
11102 &objfile
->objfile_obstack
);
11105 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11106 types, but gives them a size of zero. Starting with version 14,
11107 ICC is compatible with GCC. */
11110 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11112 if (!cu
->checked_producer
)
11113 check_producer (cu
);
11115 return cu
->producer_is_icc_lt_14
;
11118 /* ICC generates a DW_AT_type for C void functions. This was observed on
11119 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11120 which says that void functions should not have a DW_AT_type. */
11123 producer_is_icc (struct dwarf2_cu
*cu
)
11125 if (!cu
->checked_producer
)
11126 check_producer (cu
);
11128 return cu
->producer_is_icc
;
11131 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11132 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11133 this, it was first present in GCC release 4.3.0. */
11136 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11138 if (!cu
->checked_producer
)
11139 check_producer (cu
);
11141 return cu
->producer_is_gcc_lt_4_3
;
11144 static file_and_directory
11145 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11147 file_and_directory res
;
11149 /* Find the filename. Do not use dwarf2_name here, since the filename
11150 is not a source language identifier. */
11151 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11152 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11154 if (res
.comp_dir
== NULL
11155 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11156 && IS_ABSOLUTE_PATH (res
.name
))
11158 res
.comp_dir_storage
= ldirname (res
.name
);
11159 if (!res
.comp_dir_storage
.empty ())
11160 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11162 if (res
.comp_dir
!= NULL
)
11164 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11165 directory, get rid of it. */
11166 const char *cp
= strchr (res
.comp_dir
, ':');
11168 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11169 res
.comp_dir
= cp
+ 1;
11172 if (res
.name
== NULL
)
11173 res
.name
= "<unknown>";
11178 /* Handle DW_AT_stmt_list for a compilation unit.
11179 DIE is the DW_TAG_compile_unit die for CU.
11180 COMP_DIR is the compilation directory. LOWPC is passed to
11181 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11184 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11185 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11187 struct dwarf2_per_objfile
*dwarf2_per_objfile
11188 = cu
->per_cu
->dwarf2_per_objfile
;
11189 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11190 struct attribute
*attr
;
11191 struct line_header line_header_local
;
11192 hashval_t line_header_local_hash
;
11194 int decode_mapping
;
11196 gdb_assert (! cu
->per_cu
->is_debug_types
);
11198 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11202 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11204 /* The line header hash table is only created if needed (it exists to
11205 prevent redundant reading of the line table for partial_units).
11206 If we're given a partial_unit, we'll need it. If we're given a
11207 compile_unit, then use the line header hash table if it's already
11208 created, but don't create one just yet. */
11210 if (dwarf2_per_objfile
->line_header_hash
== NULL
11211 && die
->tag
== DW_TAG_partial_unit
)
11213 dwarf2_per_objfile
->line_header_hash
11214 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11215 line_header_eq_voidp
,
11216 free_line_header_voidp
,
11217 &objfile
->objfile_obstack
,
11218 hashtab_obstack_allocate
,
11219 dummy_obstack_deallocate
);
11222 line_header_local
.sect_off
= line_offset
;
11223 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11224 line_header_local_hash
= line_header_hash (&line_header_local
);
11225 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11227 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11228 &line_header_local
,
11229 line_header_local_hash
, NO_INSERT
);
11231 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11232 is not present in *SLOT (since if there is something in *SLOT then
11233 it will be for a partial_unit). */
11234 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11236 gdb_assert (*slot
!= NULL
);
11237 cu
->line_header
= (struct line_header
*) *slot
;
11242 /* dwarf_decode_line_header does not yet provide sufficient information.
11243 We always have to call also dwarf_decode_lines for it. */
11244 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11248 cu
->line_header
= lh
.release ();
11249 cu
->line_header_die_owner
= die
;
11251 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11255 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11256 &line_header_local
,
11257 line_header_local_hash
, INSERT
);
11258 gdb_assert (slot
!= NULL
);
11260 if (slot
!= NULL
&& *slot
== NULL
)
11262 /* This newly decoded line number information unit will be owned
11263 by line_header_hash hash table. */
11264 *slot
= cu
->line_header
;
11265 cu
->line_header_die_owner
= NULL
;
11269 /* We cannot free any current entry in (*slot) as that struct line_header
11270 may be already used by multiple CUs. Create only temporary decoded
11271 line_header for this CU - it may happen at most once for each line
11272 number information unit. And if we're not using line_header_hash
11273 then this is what we want as well. */
11274 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11276 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11277 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11282 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11285 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11287 struct dwarf2_per_objfile
*dwarf2_per_objfile
11288 = cu
->per_cu
->dwarf2_per_objfile
;
11289 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11290 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11291 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11292 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11293 struct attribute
*attr
;
11294 struct die_info
*child_die
;
11295 CORE_ADDR baseaddr
;
11297 prepare_one_comp_unit (cu
, die
, cu
->language
);
11298 baseaddr
= objfile
->text_section_offset ();
11300 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11302 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11303 from finish_block. */
11304 if (lowpc
== ((CORE_ADDR
) -1))
11306 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11308 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11310 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11311 standardised yet. As a workaround for the language detection we fall
11312 back to the DW_AT_producer string. */
11313 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11314 cu
->language
= language_opencl
;
11316 /* Similar hack for Go. */
11317 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11318 set_cu_language (DW_LANG_Go
, cu
);
11320 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11322 /* Decode line number information if present. We do this before
11323 processing child DIEs, so that the line header table is available
11324 for DW_AT_decl_file. */
11325 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11327 /* Process all dies in compilation unit. */
11328 if (die
->child
!= NULL
)
11330 child_die
= die
->child
;
11331 while (child_die
&& child_die
->tag
)
11333 process_die (child_die
, cu
);
11334 child_die
= sibling_die (child_die
);
11338 /* Decode macro information, if present. Dwarf 2 macro information
11339 refers to information in the line number info statement program
11340 header, so we can only read it if we've read the header
11342 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11344 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11345 if (attr
&& cu
->line_header
)
11347 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11348 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11350 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11354 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11355 if (attr
&& cu
->line_header
)
11357 unsigned int macro_offset
= DW_UNSND (attr
);
11359 dwarf_decode_macros (cu
, macro_offset
, 0);
11365 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11367 struct type_unit_group
*tu_group
;
11369 struct attribute
*attr
;
11371 struct signatured_type
*sig_type
;
11373 gdb_assert (per_cu
->is_debug_types
);
11374 sig_type
= (struct signatured_type
*) per_cu
;
11376 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11378 /* If we're using .gdb_index (includes -readnow) then
11379 per_cu->type_unit_group may not have been set up yet. */
11380 if (sig_type
->type_unit_group
== NULL
)
11381 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11382 tu_group
= sig_type
->type_unit_group
;
11384 /* If we've already processed this stmt_list there's no real need to
11385 do it again, we could fake it and just recreate the part we need
11386 (file name,index -> symtab mapping). If data shows this optimization
11387 is useful we can do it then. */
11388 first_time
= tu_group
->compunit_symtab
== NULL
;
11390 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11395 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11396 lh
= dwarf_decode_line_header (line_offset
, this);
11401 start_symtab ("", NULL
, 0);
11404 gdb_assert (tu_group
->symtabs
== NULL
);
11405 gdb_assert (m_builder
== nullptr);
11406 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11407 m_builder
.reset (new struct buildsym_compunit
11408 (COMPUNIT_OBJFILE (cust
), "",
11409 COMPUNIT_DIRNAME (cust
),
11410 compunit_language (cust
),
11416 line_header
= lh
.release ();
11417 line_header_die_owner
= die
;
11421 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11423 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11424 still initializing it, and our caller (a few levels up)
11425 process_full_type_unit still needs to know if this is the first
11428 tu_group
->num_symtabs
= line_header
->file_names_size ();
11429 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11430 line_header
->file_names_size ());
11432 auto &file_names
= line_header
->file_names ();
11433 for (i
= 0; i
< file_names
.size (); ++i
)
11435 file_entry
&fe
= file_names
[i
];
11436 dwarf2_start_subfile (this, fe
.name
,
11437 fe
.include_dir (line_header
));
11438 buildsym_compunit
*b
= get_builder ();
11439 if (b
->get_current_subfile ()->symtab
== NULL
)
11441 /* NOTE: start_subfile will recognize when it's been
11442 passed a file it has already seen. So we can't
11443 assume there's a simple mapping from
11444 cu->line_header->file_names to subfiles, plus
11445 cu->line_header->file_names may contain dups. */
11446 b
->get_current_subfile ()->symtab
11447 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11450 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11451 tu_group
->symtabs
[i
] = fe
.symtab
;
11456 gdb_assert (m_builder
== nullptr);
11457 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11458 m_builder
.reset (new struct buildsym_compunit
11459 (COMPUNIT_OBJFILE (cust
), "",
11460 COMPUNIT_DIRNAME (cust
),
11461 compunit_language (cust
),
11464 auto &file_names
= line_header
->file_names ();
11465 for (i
= 0; i
< file_names
.size (); ++i
)
11467 file_entry
&fe
= file_names
[i
];
11468 fe
.symtab
= tu_group
->symtabs
[i
];
11472 /* The main symtab is allocated last. Type units don't have DW_AT_name
11473 so they don't have a "real" (so to speak) symtab anyway.
11474 There is later code that will assign the main symtab to all symbols
11475 that don't have one. We need to handle the case of a symbol with a
11476 missing symtab (DW_AT_decl_file) anyway. */
11479 /* Process DW_TAG_type_unit.
11480 For TUs we want to skip the first top level sibling if it's not the
11481 actual type being defined by this TU. In this case the first top
11482 level sibling is there to provide context only. */
11485 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11487 struct die_info
*child_die
;
11489 prepare_one_comp_unit (cu
, die
, language_minimal
);
11491 /* Initialize (or reinitialize) the machinery for building symtabs.
11492 We do this before processing child DIEs, so that the line header table
11493 is available for DW_AT_decl_file. */
11494 cu
->setup_type_unit_groups (die
);
11496 if (die
->child
!= NULL
)
11498 child_die
= die
->child
;
11499 while (child_die
&& child_die
->tag
)
11501 process_die (child_die
, cu
);
11502 child_die
= sibling_die (child_die
);
11509 http://gcc.gnu.org/wiki/DebugFission
11510 http://gcc.gnu.org/wiki/DebugFissionDWP
11512 To simplify handling of both DWO files ("object" files with the DWARF info)
11513 and DWP files (a file with the DWOs packaged up into one file), we treat
11514 DWP files as having a collection of virtual DWO files. */
11517 hash_dwo_file (const void *item
)
11519 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11522 hash
= htab_hash_string (dwo_file
->dwo_name
);
11523 if (dwo_file
->comp_dir
!= NULL
)
11524 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11529 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11531 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11532 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11534 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11536 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11537 return lhs
->comp_dir
== rhs
->comp_dir
;
11538 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11541 /* Allocate a hash table for DWO files. */
11544 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11546 auto delete_dwo_file
= [] (void *item
)
11548 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11553 return htab_up (htab_create_alloc_ex (41,
11557 &objfile
->objfile_obstack
,
11558 hashtab_obstack_allocate
,
11559 dummy_obstack_deallocate
));
11562 /* Lookup DWO file DWO_NAME. */
11565 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11566 const char *dwo_name
,
11567 const char *comp_dir
)
11569 struct dwo_file find_entry
;
11572 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11573 dwarf2_per_objfile
->dwo_files
11574 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11576 find_entry
.dwo_name
= dwo_name
;
11577 find_entry
.comp_dir
= comp_dir
;
11578 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11585 hash_dwo_unit (const void *item
)
11587 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11589 /* This drops the top 32 bits of the id, but is ok for a hash. */
11590 return dwo_unit
->signature
;
11594 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11596 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11597 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11599 /* The signature is assumed to be unique within the DWO file.
11600 So while object file CU dwo_id's always have the value zero,
11601 that's OK, assuming each object file DWO file has only one CU,
11602 and that's the rule for now. */
11603 return lhs
->signature
== rhs
->signature
;
11606 /* Allocate a hash table for DWO CUs,TUs.
11607 There is one of these tables for each of CUs,TUs for each DWO file. */
11610 allocate_dwo_unit_table (struct objfile
*objfile
)
11612 /* Start out with a pretty small number.
11613 Generally DWO files contain only one CU and maybe some TUs. */
11614 return htab_create_alloc_ex (3,
11618 &objfile
->objfile_obstack
,
11619 hashtab_obstack_allocate
,
11620 dummy_obstack_deallocate
);
11623 /* die_reader_func for create_dwo_cu. */
11626 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11627 const gdb_byte
*info_ptr
,
11628 struct die_info
*comp_unit_die
,
11630 struct dwo_file
*dwo_file
,
11631 struct dwo_unit
*dwo_unit
)
11633 struct dwarf2_cu
*cu
= reader
->cu
;
11634 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11635 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11637 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11638 if (!signature
.has_value ())
11640 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11641 " its dwo_id [in module %s]"),
11642 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11646 dwo_unit
->dwo_file
= dwo_file
;
11647 dwo_unit
->signature
= *signature
;
11648 dwo_unit
->section
= section
;
11649 dwo_unit
->sect_off
= sect_off
;
11650 dwo_unit
->length
= cu
->per_cu
->length
;
11652 if (dwarf_read_debug
)
11653 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11654 sect_offset_str (sect_off
),
11655 hex_string (dwo_unit
->signature
));
11658 /* Create the dwo_units for the CUs in a DWO_FILE.
11659 Note: This function processes DWO files only, not DWP files. */
11662 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11663 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11664 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11666 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11667 const gdb_byte
*info_ptr
, *end_ptr
;
11669 section
.read (objfile
);
11670 info_ptr
= section
.buffer
;
11672 if (info_ptr
== NULL
)
11675 if (dwarf_read_debug
)
11677 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11678 section
.get_name (),
11679 section
.get_file_name ());
11682 end_ptr
= info_ptr
+ section
.size
;
11683 while (info_ptr
< end_ptr
)
11685 struct dwarf2_per_cu_data per_cu
;
11686 struct dwo_unit read_unit
{};
11687 struct dwo_unit
*dwo_unit
;
11689 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11691 memset (&per_cu
, 0, sizeof (per_cu
));
11692 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11693 per_cu
.is_debug_types
= 0;
11694 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11695 per_cu
.section
= §ion
;
11697 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11698 if (!reader
.dummy_p
)
11699 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11700 reader
.has_children
, &dwo_file
, &read_unit
);
11701 info_ptr
+= per_cu
.length
;
11703 // If the unit could not be parsed, skip it.
11704 if (read_unit
.dwo_file
== NULL
)
11707 if (cus_htab
== NULL
)
11708 cus_htab
= allocate_dwo_unit_table (objfile
);
11710 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11711 *dwo_unit
= read_unit
;
11712 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11713 gdb_assert (slot
!= NULL
);
11716 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11717 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11719 complaint (_("debug cu entry at offset %s is duplicate to"
11720 " the entry at offset %s, signature %s"),
11721 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
11722 hex_string (dwo_unit
->signature
));
11724 *slot
= (void *)dwo_unit
;
11728 /* DWP file .debug_{cu,tu}_index section format:
11729 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
11733 Both index sections have the same format, and serve to map a 64-bit
11734 signature to a set of section numbers. Each section begins with a header,
11735 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
11736 indexes, and a pool of 32-bit section numbers. The index sections will be
11737 aligned at 8-byte boundaries in the file.
11739 The index section header consists of:
11741 V, 32 bit version number
11743 N, 32 bit number of compilation units or type units in the index
11744 M, 32 bit number of slots in the hash table
11746 Numbers are recorded using the byte order of the application binary.
11748 The hash table begins at offset 16 in the section, and consists of an array
11749 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
11750 order of the application binary). Unused slots in the hash table are 0.
11751 (We rely on the extreme unlikeliness of a signature being exactly 0.)
11753 The parallel table begins immediately after the hash table
11754 (at offset 16 + 8 * M from the beginning of the section), and consists of an
11755 array of 32-bit indexes (using the byte order of the application binary),
11756 corresponding 1-1 with slots in the hash table. Each entry in the parallel
11757 table contains a 32-bit index into the pool of section numbers. For unused
11758 hash table slots, the corresponding entry in the parallel table will be 0.
11760 The pool of section numbers begins immediately following the hash table
11761 (at offset 16 + 12 * M from the beginning of the section). The pool of
11762 section numbers consists of an array of 32-bit words (using the byte order
11763 of the application binary). Each item in the array is indexed starting
11764 from 0. The hash table entry provides the index of the first section
11765 number in the set. Additional section numbers in the set follow, and the
11766 set is terminated by a 0 entry (section number 0 is not used in ELF).
11768 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
11769 section must be the first entry in the set, and the .debug_abbrev.dwo must
11770 be the second entry. Other members of the set may follow in any order.
11776 DWP Version 2 combines all the .debug_info, etc. sections into one,
11777 and the entries in the index tables are now offsets into these sections.
11778 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
11781 Index Section Contents:
11783 Hash Table of Signatures dwp_hash_table.hash_table
11784 Parallel Table of Indices dwp_hash_table.unit_table
11785 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
11786 Table of Section Sizes dwp_hash_table.v2.sizes
11788 The index section header consists of:
11790 V, 32 bit version number
11791 L, 32 bit number of columns in the table of section offsets
11792 N, 32 bit number of compilation units or type units in the index
11793 M, 32 bit number of slots in the hash table
11795 Numbers are recorded using the byte order of the application binary.
11797 The hash table has the same format as version 1.
11798 The parallel table of indices has the same format as version 1,
11799 except that the entries are origin-1 indices into the table of sections
11800 offsets and the table of section sizes.
11802 The table of offsets begins immediately following the parallel table
11803 (at offset 16 + 12 * M from the beginning of the section). The table is
11804 a two-dimensional array of 32-bit words (using the byte order of the
11805 application binary), with L columns and N+1 rows, in row-major order.
11806 Each row in the array is indexed starting from 0. The first row provides
11807 a key to the remaining rows: each column in this row provides an identifier
11808 for a debug section, and the offsets in the same column of subsequent rows
11809 refer to that section. The section identifiers are:
11811 DW_SECT_INFO 1 .debug_info.dwo
11812 DW_SECT_TYPES 2 .debug_types.dwo
11813 DW_SECT_ABBREV 3 .debug_abbrev.dwo
11814 DW_SECT_LINE 4 .debug_line.dwo
11815 DW_SECT_LOC 5 .debug_loc.dwo
11816 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
11817 DW_SECT_MACINFO 7 .debug_macinfo.dwo
11818 DW_SECT_MACRO 8 .debug_macro.dwo
11820 The offsets provided by the CU and TU index sections are the base offsets
11821 for the contributions made by each CU or TU to the corresponding section
11822 in the package file. Each CU and TU header contains an abbrev_offset
11823 field, used to find the abbreviations table for that CU or TU within the
11824 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
11825 be interpreted as relative to the base offset given in the index section.
11826 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
11827 should be interpreted as relative to the base offset for .debug_line.dwo,
11828 and offsets into other debug sections obtained from DWARF attributes should
11829 also be interpreted as relative to the corresponding base offset.
11831 The table of sizes begins immediately following the table of offsets.
11832 Like the table of offsets, it is a two-dimensional array of 32-bit words,
11833 with L columns and N rows, in row-major order. Each row in the array is
11834 indexed starting from 1 (row 0 is shared by the two tables).
11838 Hash table lookup is handled the same in version 1 and 2:
11840 We assume that N and M will not exceed 2^32 - 1.
11841 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
11843 Given a 64-bit compilation unit signature or a type signature S, an entry
11844 in the hash table is located as follows:
11846 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
11847 the low-order k bits all set to 1.
11849 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
11851 3) If the hash table entry at index H matches the signature, use that
11852 entry. If the hash table entry at index H is unused (all zeroes),
11853 terminate the search: the signature is not present in the table.
11855 4) Let H = (H + H') modulo M. Repeat at Step 3.
11857 Because M > N and H' and M are relatively prime, the search is guaranteed
11858 to stop at an unused slot or find the match. */
11860 /* Create a hash table to map DWO IDs to their CU/TU entry in
11861 .debug_{info,types}.dwo in DWP_FILE.
11862 Returns NULL if there isn't one.
11863 Note: This function processes DWP files only, not DWO files. */
11865 static struct dwp_hash_table
*
11866 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11867 struct dwp_file
*dwp_file
, int is_debug_types
)
11869 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11870 bfd
*dbfd
= dwp_file
->dbfd
.get ();
11871 const gdb_byte
*index_ptr
, *index_end
;
11872 struct dwarf2_section_info
*index
;
11873 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
11874 struct dwp_hash_table
*htab
;
11876 if (is_debug_types
)
11877 index
= &dwp_file
->sections
.tu_index
;
11879 index
= &dwp_file
->sections
.cu_index
;
11881 if (index
->empty ())
11883 index
->read (objfile
);
11885 index_ptr
= index
->buffer
;
11886 index_end
= index_ptr
+ index
->size
;
11888 version
= read_4_bytes (dbfd
, index_ptr
);
11891 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
11895 nr_units
= read_4_bytes (dbfd
, index_ptr
);
11897 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
11900 if (version
!= 1 && version
!= 2)
11902 error (_("Dwarf Error: unsupported DWP file version (%s)"
11903 " [in module %s]"),
11904 pulongest (version
), dwp_file
->name
);
11906 if (nr_slots
!= (nr_slots
& -nr_slots
))
11908 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
11909 " is not power of 2 [in module %s]"),
11910 pulongest (nr_slots
), dwp_file
->name
);
11913 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
11914 htab
->version
= version
;
11915 htab
->nr_columns
= nr_columns
;
11916 htab
->nr_units
= nr_units
;
11917 htab
->nr_slots
= nr_slots
;
11918 htab
->hash_table
= index_ptr
;
11919 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
11921 /* Exit early if the table is empty. */
11922 if (nr_slots
== 0 || nr_units
== 0
11923 || (version
== 2 && nr_columns
== 0))
11925 /* All must be zero. */
11926 if (nr_slots
!= 0 || nr_units
!= 0
11927 || (version
== 2 && nr_columns
!= 0))
11929 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
11930 " all zero [in modules %s]"),
11938 htab
->section_pool
.v1
.indices
=
11939 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11940 /* It's harder to decide whether the section is too small in v1.
11941 V1 is deprecated anyway so we punt. */
11945 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
11946 int *ids
= htab
->section_pool
.v2
.section_ids
;
11947 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
11948 /* Reverse map for error checking. */
11949 int ids_seen
[DW_SECT_MAX
+ 1];
11952 if (nr_columns
< 2)
11954 error (_("Dwarf Error: bad DWP hash table, too few columns"
11955 " in section table [in module %s]"),
11958 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
11960 error (_("Dwarf Error: bad DWP hash table, too many columns"
11961 " in section table [in module %s]"),
11964 memset (ids
, 255, sizeof_ids
);
11965 memset (ids_seen
, 255, sizeof (ids_seen
));
11966 for (i
= 0; i
< nr_columns
; ++i
)
11968 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
11970 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
11972 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
11973 " in section table [in module %s]"),
11974 id
, dwp_file
->name
);
11976 if (ids_seen
[id
] != -1)
11978 error (_("Dwarf Error: bad DWP hash table, duplicate section"
11979 " id %d in section table [in module %s]"),
11980 id
, dwp_file
->name
);
11985 /* Must have exactly one info or types section. */
11986 if (((ids_seen
[DW_SECT_INFO
] != -1)
11987 + (ids_seen
[DW_SECT_TYPES
] != -1))
11990 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
11991 " DWO info/types section [in module %s]"),
11994 /* Must have an abbrev section. */
11995 if (ids_seen
[DW_SECT_ABBREV
] == -1)
11997 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
11998 " section [in module %s]"),
12001 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12002 htab
->section_pool
.v2
.sizes
=
12003 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12004 * nr_units
* nr_columns
);
12005 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12006 * nr_units
* nr_columns
))
12009 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12010 " [in module %s]"),
12018 /* Update SECTIONS with the data from SECTP.
12020 This function is like the other "locate" section routines that are
12021 passed to bfd_map_over_sections, but in this context the sections to
12022 read comes from the DWP V1 hash table, not the full ELF section table.
12024 The result is non-zero for success, or zero if an error was found. */
12027 locate_v1_virtual_dwo_sections (asection
*sectp
,
12028 struct virtual_v1_dwo_sections
*sections
)
12030 const struct dwop_section_names
*names
= &dwop_section_names
;
12032 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12034 /* There can be only one. */
12035 if (sections
->abbrev
.s
.section
!= NULL
)
12037 sections
->abbrev
.s
.section
= sectp
;
12038 sections
->abbrev
.size
= bfd_section_size (sectp
);
12040 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12041 || section_is_p (sectp
->name
, &names
->types_dwo
))
12043 /* There can be only one. */
12044 if (sections
->info_or_types
.s
.section
!= NULL
)
12046 sections
->info_or_types
.s
.section
= sectp
;
12047 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12049 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12051 /* There can be only one. */
12052 if (sections
->line
.s
.section
!= NULL
)
12054 sections
->line
.s
.section
= sectp
;
12055 sections
->line
.size
= bfd_section_size (sectp
);
12057 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12059 /* There can be only one. */
12060 if (sections
->loc
.s
.section
!= NULL
)
12062 sections
->loc
.s
.section
= sectp
;
12063 sections
->loc
.size
= bfd_section_size (sectp
);
12065 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12067 /* There can be only one. */
12068 if (sections
->macinfo
.s
.section
!= NULL
)
12070 sections
->macinfo
.s
.section
= sectp
;
12071 sections
->macinfo
.size
= bfd_section_size (sectp
);
12073 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12075 /* There can be only one. */
12076 if (sections
->macro
.s
.section
!= NULL
)
12078 sections
->macro
.s
.section
= sectp
;
12079 sections
->macro
.size
= bfd_section_size (sectp
);
12081 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12083 /* There can be only one. */
12084 if (sections
->str_offsets
.s
.section
!= NULL
)
12086 sections
->str_offsets
.s
.section
= sectp
;
12087 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12091 /* No other kind of section is valid. */
12098 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12099 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12100 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12101 This is for DWP version 1 files. */
12103 static struct dwo_unit
*
12104 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12105 struct dwp_file
*dwp_file
,
12106 uint32_t unit_index
,
12107 const char *comp_dir
,
12108 ULONGEST signature
, int is_debug_types
)
12110 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12111 const struct dwp_hash_table
*dwp_htab
=
12112 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12113 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12114 const char *kind
= is_debug_types
? "TU" : "CU";
12115 struct dwo_file
*dwo_file
;
12116 struct dwo_unit
*dwo_unit
;
12117 struct virtual_v1_dwo_sections sections
;
12118 void **dwo_file_slot
;
12121 gdb_assert (dwp_file
->version
== 1);
12123 if (dwarf_read_debug
)
12125 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12127 pulongest (unit_index
), hex_string (signature
),
12131 /* Fetch the sections of this DWO unit.
12132 Put a limit on the number of sections we look for so that bad data
12133 doesn't cause us to loop forever. */
12135 #define MAX_NR_V1_DWO_SECTIONS \
12136 (1 /* .debug_info or .debug_types */ \
12137 + 1 /* .debug_abbrev */ \
12138 + 1 /* .debug_line */ \
12139 + 1 /* .debug_loc */ \
12140 + 1 /* .debug_str_offsets */ \
12141 + 1 /* .debug_macro or .debug_macinfo */ \
12142 + 1 /* trailing zero */)
12144 memset (§ions
, 0, sizeof (sections
));
12146 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12149 uint32_t section_nr
=
12150 read_4_bytes (dbfd
,
12151 dwp_htab
->section_pool
.v1
.indices
12152 + (unit_index
+ i
) * sizeof (uint32_t));
12154 if (section_nr
== 0)
12156 if (section_nr
>= dwp_file
->num_sections
)
12158 error (_("Dwarf Error: bad DWP hash table, section number too large"
12159 " [in module %s]"),
12163 sectp
= dwp_file
->elf_sections
[section_nr
];
12164 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12166 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12167 " [in module %s]"),
12173 || sections
.info_or_types
.empty ()
12174 || sections
.abbrev
.empty ())
12176 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12177 " [in module %s]"),
12180 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12182 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12183 " [in module %s]"),
12187 /* It's easier for the rest of the code if we fake a struct dwo_file and
12188 have dwo_unit "live" in that. At least for now.
12190 The DWP file can be made up of a random collection of CUs and TUs.
12191 However, for each CU + set of TUs that came from the same original DWO
12192 file, we can combine them back into a virtual DWO file to save space
12193 (fewer struct dwo_file objects to allocate). Remember that for really
12194 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12196 std::string virtual_dwo_name
=
12197 string_printf ("virtual-dwo/%d-%d-%d-%d",
12198 sections
.abbrev
.get_id (),
12199 sections
.line
.get_id (),
12200 sections
.loc
.get_id (),
12201 sections
.str_offsets
.get_id ());
12202 /* Can we use an existing virtual DWO file? */
12203 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12204 virtual_dwo_name
.c_str (),
12206 /* Create one if necessary. */
12207 if (*dwo_file_slot
== NULL
)
12209 if (dwarf_read_debug
)
12211 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12212 virtual_dwo_name
.c_str ());
12214 dwo_file
= new struct dwo_file
;
12215 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12217 dwo_file
->comp_dir
= comp_dir
;
12218 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12219 dwo_file
->sections
.line
= sections
.line
;
12220 dwo_file
->sections
.loc
= sections
.loc
;
12221 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12222 dwo_file
->sections
.macro
= sections
.macro
;
12223 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12224 /* The "str" section is global to the entire DWP file. */
12225 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12226 /* The info or types section is assigned below to dwo_unit,
12227 there's no need to record it in dwo_file.
12228 Also, we can't simply record type sections in dwo_file because
12229 we record a pointer into the vector in dwo_unit. As we collect more
12230 types we'll grow the vector and eventually have to reallocate space
12231 for it, invalidating all copies of pointers into the previous
12233 *dwo_file_slot
= dwo_file
;
12237 if (dwarf_read_debug
)
12239 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12240 virtual_dwo_name
.c_str ());
12242 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12245 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12246 dwo_unit
->dwo_file
= dwo_file
;
12247 dwo_unit
->signature
= signature
;
12248 dwo_unit
->section
=
12249 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12250 *dwo_unit
->section
= sections
.info_or_types
;
12251 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12256 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12257 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12258 piece within that section used by a TU/CU, return a virtual section
12259 of just that piece. */
12261 static struct dwarf2_section_info
12262 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12263 struct dwarf2_section_info
*section
,
12264 bfd_size_type offset
, bfd_size_type size
)
12266 struct dwarf2_section_info result
;
12269 gdb_assert (section
!= NULL
);
12270 gdb_assert (!section
->is_virtual
);
12272 memset (&result
, 0, sizeof (result
));
12273 result
.s
.containing_section
= section
;
12274 result
.is_virtual
= true;
12279 sectp
= section
->get_bfd_section ();
12281 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12282 bounds of the real section. This is a pretty-rare event, so just
12283 flag an error (easier) instead of a warning and trying to cope. */
12285 || offset
+ size
> bfd_section_size (sectp
))
12287 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12288 " in section %s [in module %s]"),
12289 sectp
? bfd_section_name (sectp
) : "<unknown>",
12290 objfile_name (dwarf2_per_objfile
->objfile
));
12293 result
.virtual_offset
= offset
;
12294 result
.size
= size
;
12298 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12299 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12300 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12301 This is for DWP version 2 files. */
12303 static struct dwo_unit
*
12304 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12305 struct dwp_file
*dwp_file
,
12306 uint32_t unit_index
,
12307 const char *comp_dir
,
12308 ULONGEST signature
, int is_debug_types
)
12310 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12311 const struct dwp_hash_table
*dwp_htab
=
12312 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12313 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12314 const char *kind
= is_debug_types
? "TU" : "CU";
12315 struct dwo_file
*dwo_file
;
12316 struct dwo_unit
*dwo_unit
;
12317 struct virtual_v2_dwo_sections sections
;
12318 void **dwo_file_slot
;
12321 gdb_assert (dwp_file
->version
== 2);
12323 if (dwarf_read_debug
)
12325 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12327 pulongest (unit_index
), hex_string (signature
),
12331 /* Fetch the section offsets of this DWO unit. */
12333 memset (§ions
, 0, sizeof (sections
));
12335 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12337 uint32_t offset
= read_4_bytes (dbfd
,
12338 dwp_htab
->section_pool
.v2
.offsets
12339 + (((unit_index
- 1) * dwp_htab
->nr_columns
12341 * sizeof (uint32_t)));
12342 uint32_t size
= read_4_bytes (dbfd
,
12343 dwp_htab
->section_pool
.v2
.sizes
12344 + (((unit_index
- 1) * dwp_htab
->nr_columns
12346 * sizeof (uint32_t)));
12348 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12351 case DW_SECT_TYPES
:
12352 sections
.info_or_types_offset
= offset
;
12353 sections
.info_or_types_size
= size
;
12355 case DW_SECT_ABBREV
:
12356 sections
.abbrev_offset
= offset
;
12357 sections
.abbrev_size
= size
;
12360 sections
.line_offset
= offset
;
12361 sections
.line_size
= size
;
12364 sections
.loc_offset
= offset
;
12365 sections
.loc_size
= size
;
12367 case DW_SECT_STR_OFFSETS
:
12368 sections
.str_offsets_offset
= offset
;
12369 sections
.str_offsets_size
= size
;
12371 case DW_SECT_MACINFO
:
12372 sections
.macinfo_offset
= offset
;
12373 sections
.macinfo_size
= size
;
12375 case DW_SECT_MACRO
:
12376 sections
.macro_offset
= offset
;
12377 sections
.macro_size
= size
;
12382 /* It's easier for the rest of the code if we fake a struct dwo_file and
12383 have dwo_unit "live" in that. At least for now.
12385 The DWP file can be made up of a random collection of CUs and TUs.
12386 However, for each CU + set of TUs that came from the same original DWO
12387 file, we can combine them back into a virtual DWO file to save space
12388 (fewer struct dwo_file objects to allocate). Remember that for really
12389 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12391 std::string virtual_dwo_name
=
12392 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12393 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12394 (long) (sections
.line_size
? sections
.line_offset
: 0),
12395 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12396 (long) (sections
.str_offsets_size
12397 ? sections
.str_offsets_offset
: 0));
12398 /* Can we use an existing virtual DWO file? */
12399 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12400 virtual_dwo_name
.c_str (),
12402 /* Create one if necessary. */
12403 if (*dwo_file_slot
== NULL
)
12405 if (dwarf_read_debug
)
12407 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12408 virtual_dwo_name
.c_str ());
12410 dwo_file
= new struct dwo_file
;
12411 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12413 dwo_file
->comp_dir
= comp_dir
;
12414 dwo_file
->sections
.abbrev
=
12415 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12416 sections
.abbrev_offset
, sections
.abbrev_size
);
12417 dwo_file
->sections
.line
=
12418 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12419 sections
.line_offset
, sections
.line_size
);
12420 dwo_file
->sections
.loc
=
12421 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12422 sections
.loc_offset
, sections
.loc_size
);
12423 dwo_file
->sections
.macinfo
=
12424 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12425 sections
.macinfo_offset
, sections
.macinfo_size
);
12426 dwo_file
->sections
.macro
=
12427 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12428 sections
.macro_offset
, sections
.macro_size
);
12429 dwo_file
->sections
.str_offsets
=
12430 create_dwp_v2_section (dwarf2_per_objfile
,
12431 &dwp_file
->sections
.str_offsets
,
12432 sections
.str_offsets_offset
,
12433 sections
.str_offsets_size
);
12434 /* The "str" section is global to the entire DWP file. */
12435 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12436 /* The info or types section is assigned below to dwo_unit,
12437 there's no need to record it in dwo_file.
12438 Also, we can't simply record type sections in dwo_file because
12439 we record a pointer into the vector in dwo_unit. As we collect more
12440 types we'll grow the vector and eventually have to reallocate space
12441 for it, invalidating all copies of pointers into the previous
12443 *dwo_file_slot
= dwo_file
;
12447 if (dwarf_read_debug
)
12449 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12450 virtual_dwo_name
.c_str ());
12452 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12455 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12456 dwo_unit
->dwo_file
= dwo_file
;
12457 dwo_unit
->signature
= signature
;
12458 dwo_unit
->section
=
12459 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12460 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12462 ? &dwp_file
->sections
.types
12463 : &dwp_file
->sections
.info
,
12464 sections
.info_or_types_offset
,
12465 sections
.info_or_types_size
);
12466 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12471 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12472 Returns NULL if the signature isn't found. */
12474 static struct dwo_unit
*
12475 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12476 struct dwp_file
*dwp_file
, const char *comp_dir
,
12477 ULONGEST signature
, int is_debug_types
)
12479 const struct dwp_hash_table
*dwp_htab
=
12480 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12481 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12482 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12483 uint32_t hash
= signature
& mask
;
12484 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12487 struct dwo_unit find_dwo_cu
;
12489 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12490 find_dwo_cu
.signature
= signature
;
12491 slot
= htab_find_slot (is_debug_types
12492 ? dwp_file
->loaded_tus
12493 : dwp_file
->loaded_cus
,
12494 &find_dwo_cu
, INSERT
);
12497 return (struct dwo_unit
*) *slot
;
12499 /* Use a for loop so that we don't loop forever on bad debug info. */
12500 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12502 ULONGEST signature_in_table
;
12504 signature_in_table
=
12505 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12506 if (signature_in_table
== signature
)
12508 uint32_t unit_index
=
12509 read_4_bytes (dbfd
,
12510 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12512 if (dwp_file
->version
== 1)
12514 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12515 dwp_file
, unit_index
,
12516 comp_dir
, signature
,
12521 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12522 dwp_file
, unit_index
,
12523 comp_dir
, signature
,
12526 return (struct dwo_unit
*) *slot
;
12528 if (signature_in_table
== 0)
12530 hash
= (hash
+ hash2
) & mask
;
12533 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12534 " [in module %s]"),
12538 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12539 Open the file specified by FILE_NAME and hand it off to BFD for
12540 preliminary analysis. Return a newly initialized bfd *, which
12541 includes a canonicalized copy of FILE_NAME.
12542 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12543 SEARCH_CWD is true if the current directory is to be searched.
12544 It will be searched before debug-file-directory.
12545 If successful, the file is added to the bfd include table of the
12546 objfile's bfd (see gdb_bfd_record_inclusion).
12547 If unable to find/open the file, return NULL.
12548 NOTE: This function is derived from symfile_bfd_open. */
12550 static gdb_bfd_ref_ptr
12551 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12552 const char *file_name
, int is_dwp
, int search_cwd
)
12555 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12556 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12557 to debug_file_directory. */
12558 const char *search_path
;
12559 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12561 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12564 if (*debug_file_directory
!= '\0')
12566 search_path_holder
.reset (concat (".", dirname_separator_string
,
12567 debug_file_directory
,
12569 search_path
= search_path_holder
.get ();
12575 search_path
= debug_file_directory
;
12577 openp_flags flags
= OPF_RETURN_REALPATH
;
12579 flags
|= OPF_SEARCH_IN_PATH
;
12581 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12582 desc
= openp (search_path
, flags
, file_name
,
12583 O_RDONLY
| O_BINARY
, &absolute_name
);
12587 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12589 if (sym_bfd
== NULL
)
12591 bfd_set_cacheable (sym_bfd
.get (), 1);
12593 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12596 /* Success. Record the bfd as having been included by the objfile's bfd.
12597 This is important because things like demangled_names_hash lives in the
12598 objfile's per_bfd space and may have references to things like symbol
12599 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12600 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12605 /* Try to open DWO file FILE_NAME.
12606 COMP_DIR is the DW_AT_comp_dir attribute.
12607 The result is the bfd handle of the file.
12608 If there is a problem finding or opening the file, return NULL.
12609 Upon success, the canonicalized path of the file is stored in the bfd,
12610 same as symfile_bfd_open. */
12612 static gdb_bfd_ref_ptr
12613 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12614 const char *file_name
, const char *comp_dir
)
12616 if (IS_ABSOLUTE_PATH (file_name
))
12617 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12618 0 /*is_dwp*/, 0 /*search_cwd*/);
12620 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12622 if (comp_dir
!= NULL
)
12624 gdb::unique_xmalloc_ptr
<char> path_to_try
12625 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12627 /* NOTE: If comp_dir is a relative path, this will also try the
12628 search path, which seems useful. */
12629 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12630 path_to_try
.get (),
12632 1 /*search_cwd*/));
12637 /* That didn't work, try debug-file-directory, which, despite its name,
12638 is a list of paths. */
12640 if (*debug_file_directory
== '\0')
12643 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12644 0 /*is_dwp*/, 1 /*search_cwd*/);
12647 /* This function is mapped across the sections and remembers the offset and
12648 size of each of the DWO debugging sections we are interested in. */
12651 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12653 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12654 const struct dwop_section_names
*names
= &dwop_section_names
;
12656 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12658 dwo_sections
->abbrev
.s
.section
= sectp
;
12659 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12661 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12663 dwo_sections
->info
.s
.section
= sectp
;
12664 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12666 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12668 dwo_sections
->line
.s
.section
= sectp
;
12669 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12671 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12673 dwo_sections
->loc
.s
.section
= sectp
;
12674 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12676 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12678 dwo_sections
->macinfo
.s
.section
= sectp
;
12679 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12681 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12683 dwo_sections
->macro
.s
.section
= sectp
;
12684 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12686 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12688 dwo_sections
->str
.s
.section
= sectp
;
12689 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12691 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12693 dwo_sections
->str_offsets
.s
.section
= sectp
;
12694 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12696 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12698 struct dwarf2_section_info type_section
;
12700 memset (&type_section
, 0, sizeof (type_section
));
12701 type_section
.s
.section
= sectp
;
12702 type_section
.size
= bfd_section_size (sectp
);
12703 dwo_sections
->types
.push_back (type_section
);
12707 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12708 by PER_CU. This is for the non-DWP case.
12709 The result is NULL if DWO_NAME can't be found. */
12711 static struct dwo_file
*
12712 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12713 const char *dwo_name
, const char *comp_dir
)
12715 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12717 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12720 if (dwarf_read_debug
)
12721 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
12725 dwo_file_up
dwo_file (new struct dwo_file
);
12726 dwo_file
->dwo_name
= dwo_name
;
12727 dwo_file
->comp_dir
= comp_dir
;
12728 dwo_file
->dbfd
= std::move (dbfd
);
12730 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
12731 &dwo_file
->sections
);
12733 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
12734 dwo_file
->sections
.info
, dwo_file
->cus
);
12736 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
12737 dwo_file
->sections
.types
, dwo_file
->tus
);
12739 if (dwarf_read_debug
)
12740 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
12742 return dwo_file
.release ();
12745 /* This function is mapped across the sections and remembers the offset and
12746 size of each of the DWP debugging sections common to version 1 and 2 that
12747 we are interested in. */
12750 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
12751 void *dwp_file_ptr
)
12753 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12754 const struct dwop_section_names
*names
= &dwop_section_names
;
12755 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12757 /* Record the ELF section number for later lookup: this is what the
12758 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12759 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12760 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12762 /* Look for specific sections that we need. */
12763 if (section_is_p (sectp
->name
, &names
->str_dwo
))
12765 dwp_file
->sections
.str
.s
.section
= sectp
;
12766 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
12768 else if (section_is_p (sectp
->name
, &names
->cu_index
))
12770 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
12771 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
12773 else if (section_is_p (sectp
->name
, &names
->tu_index
))
12775 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
12776 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
12780 /* This function is mapped across the sections and remembers the offset and
12781 size of each of the DWP version 2 debugging sections that we are interested
12782 in. This is split into a separate function because we don't know if we
12783 have version 1 or 2 until we parse the cu_index/tu_index sections. */
12786 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
12788 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
12789 const struct dwop_section_names
*names
= &dwop_section_names
;
12790 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
12792 /* Record the ELF section number for later lookup: this is what the
12793 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
12794 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
12795 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
12797 /* Look for specific sections that we need. */
12798 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12800 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
12801 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
12803 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12805 dwp_file
->sections
.info
.s
.section
= sectp
;
12806 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
12808 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12810 dwp_file
->sections
.line
.s
.section
= sectp
;
12811 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
12813 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12815 dwp_file
->sections
.loc
.s
.section
= sectp
;
12816 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
12818 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12820 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
12821 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
12823 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12825 dwp_file
->sections
.macro
.s
.section
= sectp
;
12826 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
12828 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12830 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
12831 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
12833 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12835 dwp_file
->sections
.types
.s
.section
= sectp
;
12836 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
12840 /* Hash function for dwp_file loaded CUs/TUs. */
12843 hash_dwp_loaded_cutus (const void *item
)
12845 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
12847 /* This drops the top 32 bits of the signature, but is ok for a hash. */
12848 return dwo_unit
->signature
;
12851 /* Equality function for dwp_file loaded CUs/TUs. */
12854 eq_dwp_loaded_cutus (const void *a
, const void *b
)
12856 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
12857 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
12859 return dua
->signature
== dub
->signature
;
12862 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
12865 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
12867 return htab_create_alloc_ex (3,
12868 hash_dwp_loaded_cutus
,
12869 eq_dwp_loaded_cutus
,
12871 &objfile
->objfile_obstack
,
12872 hashtab_obstack_allocate
,
12873 dummy_obstack_deallocate
);
12876 /* Try to open DWP file FILE_NAME.
12877 The result is the bfd handle of the file.
12878 If there is a problem finding or opening the file, return NULL.
12879 Upon success, the canonicalized path of the file is stored in the bfd,
12880 same as symfile_bfd_open. */
12882 static gdb_bfd_ref_ptr
12883 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12884 const char *file_name
)
12886 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12888 1 /*search_cwd*/));
12892 /* Work around upstream bug 15652.
12893 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
12894 [Whether that's a "bug" is debatable, but it is getting in our way.]
12895 We have no real idea where the dwp file is, because gdb's realpath-ing
12896 of the executable's path may have discarded the needed info.
12897 [IWBN if the dwp file name was recorded in the executable, akin to
12898 .gnu_debuglink, but that doesn't exist yet.]
12899 Strip the directory from FILE_NAME and search again. */
12900 if (*debug_file_directory
!= '\0')
12902 /* Don't implicitly search the current directory here.
12903 If the user wants to search "." to handle this case,
12904 it must be added to debug-file-directory. */
12905 return try_open_dwop_file (dwarf2_per_objfile
,
12906 lbasename (file_name
), 1 /*is_dwp*/,
12913 /* Initialize the use of the DWP file for the current objfile.
12914 By convention the name of the DWP file is ${objfile}.dwp.
12915 The result is NULL if it can't be found. */
12917 static std::unique_ptr
<struct dwp_file
>
12918 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
12920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12922 /* Try to find first .dwp for the binary file before any symbolic links
12925 /* If the objfile is a debug file, find the name of the real binary
12926 file and get the name of dwp file from there. */
12927 std::string dwp_name
;
12928 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
12930 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
12931 const char *backlink_basename
= lbasename (backlink
->original_name
);
12933 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
12936 dwp_name
= objfile
->original_name
;
12938 dwp_name
+= ".dwp";
12940 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
12942 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
12944 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
12945 dwp_name
= objfile_name (objfile
);
12946 dwp_name
+= ".dwp";
12947 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
12952 if (dwarf_read_debug
)
12953 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
12954 return std::unique_ptr
<dwp_file
> ();
12957 const char *name
= bfd_get_filename (dbfd
.get ());
12958 std::unique_ptr
<struct dwp_file
> dwp_file
12959 (new struct dwp_file (name
, std::move (dbfd
)));
12961 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
12962 dwp_file
->elf_sections
=
12963 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
12964 dwp_file
->num_sections
, asection
*);
12966 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12967 dwarf2_locate_common_dwp_sections
,
12970 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12973 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
12976 /* The DWP file version is stored in the hash table. Oh well. */
12977 if (dwp_file
->cus
&& dwp_file
->tus
12978 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
12980 /* Technically speaking, we should try to limp along, but this is
12981 pretty bizarre. We use pulongest here because that's the established
12982 portability solution (e.g, we cannot use %u for uint32_t). */
12983 error (_("Dwarf Error: DWP file CU version %s doesn't match"
12984 " TU version %s [in DWP file %s]"),
12985 pulongest (dwp_file
->cus
->version
),
12986 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
12990 dwp_file
->version
= dwp_file
->cus
->version
;
12991 else if (dwp_file
->tus
)
12992 dwp_file
->version
= dwp_file
->tus
->version
;
12994 dwp_file
->version
= 2;
12996 if (dwp_file
->version
== 2)
12997 bfd_map_over_sections (dwp_file
->dbfd
.get (),
12998 dwarf2_locate_v2_dwp_sections
,
13001 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13002 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13004 if (dwarf_read_debug
)
13006 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13007 fprintf_unfiltered (gdb_stdlog
,
13008 " %s CUs, %s TUs\n",
13009 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13010 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13016 /* Wrapper around open_and_init_dwp_file, only open it once. */
13018 static struct dwp_file
*
13019 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13021 if (! dwarf2_per_objfile
->dwp_checked
)
13023 dwarf2_per_objfile
->dwp_file
13024 = open_and_init_dwp_file (dwarf2_per_objfile
);
13025 dwarf2_per_objfile
->dwp_checked
= 1;
13027 return dwarf2_per_objfile
->dwp_file
.get ();
13030 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13031 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13032 or in the DWP file for the objfile, referenced by THIS_UNIT.
13033 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13034 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13036 This is called, for example, when wanting to read a variable with a
13037 complex location. Therefore we don't want to do file i/o for every call.
13038 Therefore we don't want to look for a DWO file on every call.
13039 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13040 then we check if we've already seen DWO_NAME, and only THEN do we check
13043 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13044 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13046 static struct dwo_unit
*
13047 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13048 const char *dwo_name
, const char *comp_dir
,
13049 ULONGEST signature
, int is_debug_types
)
13051 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13053 const char *kind
= is_debug_types
? "TU" : "CU";
13054 void **dwo_file_slot
;
13055 struct dwo_file
*dwo_file
;
13056 struct dwp_file
*dwp_file
;
13058 /* First see if there's a DWP file.
13059 If we have a DWP file but didn't find the DWO inside it, don't
13060 look for the original DWO file. It makes gdb behave differently
13061 depending on whether one is debugging in the build tree. */
13063 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13064 if (dwp_file
!= NULL
)
13066 const struct dwp_hash_table
*dwp_htab
=
13067 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13069 if (dwp_htab
!= NULL
)
13071 struct dwo_unit
*dwo_cutu
=
13072 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13073 signature
, is_debug_types
);
13075 if (dwo_cutu
!= NULL
)
13077 if (dwarf_read_debug
)
13079 fprintf_unfiltered (gdb_stdlog
,
13080 "Virtual DWO %s %s found: @%s\n",
13081 kind
, hex_string (signature
),
13082 host_address_to_string (dwo_cutu
));
13090 /* No DWP file, look for the DWO file. */
13092 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13093 dwo_name
, comp_dir
);
13094 if (*dwo_file_slot
== NULL
)
13096 /* Read in the file and build a table of the CUs/TUs it contains. */
13097 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13099 /* NOTE: This will be NULL if unable to open the file. */
13100 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13102 if (dwo_file
!= NULL
)
13104 struct dwo_unit
*dwo_cutu
= NULL
;
13106 if (is_debug_types
&& dwo_file
->tus
)
13108 struct dwo_unit find_dwo_cutu
;
13110 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13111 find_dwo_cutu
.signature
= signature
;
13113 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13115 else if (!is_debug_types
&& dwo_file
->cus
)
13117 struct dwo_unit find_dwo_cutu
;
13119 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13120 find_dwo_cutu
.signature
= signature
;
13121 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13125 if (dwo_cutu
!= NULL
)
13127 if (dwarf_read_debug
)
13129 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13130 kind
, dwo_name
, hex_string (signature
),
13131 host_address_to_string (dwo_cutu
));
13138 /* We didn't find it. This could mean a dwo_id mismatch, or
13139 someone deleted the DWO/DWP file, or the search path isn't set up
13140 correctly to find the file. */
13142 if (dwarf_read_debug
)
13144 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13145 kind
, dwo_name
, hex_string (signature
));
13148 /* This is a warning and not a complaint because it can be caused by
13149 pilot error (e.g., user accidentally deleting the DWO). */
13151 /* Print the name of the DWP file if we looked there, helps the user
13152 better diagnose the problem. */
13153 std::string dwp_text
;
13155 if (dwp_file
!= NULL
)
13156 dwp_text
= string_printf (" [in DWP file %s]",
13157 lbasename (dwp_file
->name
));
13159 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13160 " [in module %s]"),
13161 kind
, dwo_name
, hex_string (signature
),
13163 this_unit
->is_debug_types
? "TU" : "CU",
13164 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13169 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13170 See lookup_dwo_cutu_unit for details. */
13172 static struct dwo_unit
*
13173 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13174 const char *dwo_name
, const char *comp_dir
,
13175 ULONGEST signature
)
13177 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13180 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13181 See lookup_dwo_cutu_unit for details. */
13183 static struct dwo_unit
*
13184 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13185 const char *dwo_name
, const char *comp_dir
)
13187 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13190 /* Traversal function for queue_and_load_all_dwo_tus. */
13193 queue_and_load_dwo_tu (void **slot
, void *info
)
13195 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13196 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13197 ULONGEST signature
= dwo_unit
->signature
;
13198 struct signatured_type
*sig_type
=
13199 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13201 if (sig_type
!= NULL
)
13203 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13205 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13206 a real dependency of PER_CU on SIG_TYPE. That is detected later
13207 while processing PER_CU. */
13208 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13209 load_full_type_unit (sig_cu
);
13210 per_cu
->imported_symtabs_push (sig_cu
);
13216 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13217 The DWO may have the only definition of the type, though it may not be
13218 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13219 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13222 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13224 struct dwo_unit
*dwo_unit
;
13225 struct dwo_file
*dwo_file
;
13227 gdb_assert (!per_cu
->is_debug_types
);
13228 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13229 gdb_assert (per_cu
->cu
!= NULL
);
13231 dwo_unit
= per_cu
->cu
->dwo_unit
;
13232 gdb_assert (dwo_unit
!= NULL
);
13234 dwo_file
= dwo_unit
->dwo_file
;
13235 if (dwo_file
->tus
!= NULL
)
13236 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13239 /* Read in various DIEs. */
13241 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13242 Inherit only the children of the DW_AT_abstract_origin DIE not being
13243 already referenced by DW_AT_abstract_origin from the children of the
13247 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13249 struct die_info
*child_die
;
13250 sect_offset
*offsetp
;
13251 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13252 struct die_info
*origin_die
;
13253 /* Iterator of the ORIGIN_DIE children. */
13254 struct die_info
*origin_child_die
;
13255 struct attribute
*attr
;
13256 struct dwarf2_cu
*origin_cu
;
13257 struct pending
**origin_previous_list_in_scope
;
13259 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13263 /* Note that following die references may follow to a die in a
13267 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13269 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13271 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13272 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13274 if (die
->tag
!= origin_die
->tag
13275 && !(die
->tag
== DW_TAG_inlined_subroutine
13276 && origin_die
->tag
== DW_TAG_subprogram
))
13277 complaint (_("DIE %s and its abstract origin %s have different tags"),
13278 sect_offset_str (die
->sect_off
),
13279 sect_offset_str (origin_die
->sect_off
));
13281 std::vector
<sect_offset
> offsets
;
13283 for (child_die
= die
->child
;
13284 child_die
&& child_die
->tag
;
13285 child_die
= sibling_die (child_die
))
13287 struct die_info
*child_origin_die
;
13288 struct dwarf2_cu
*child_origin_cu
;
13290 /* We are trying to process concrete instance entries:
13291 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13292 it's not relevant to our analysis here. i.e. detecting DIEs that are
13293 present in the abstract instance but not referenced in the concrete
13295 if (child_die
->tag
== DW_TAG_call_site
13296 || child_die
->tag
== DW_TAG_GNU_call_site
)
13299 /* For each CHILD_DIE, find the corresponding child of
13300 ORIGIN_DIE. If there is more than one layer of
13301 DW_AT_abstract_origin, follow them all; there shouldn't be,
13302 but GCC versions at least through 4.4 generate this (GCC PR
13304 child_origin_die
= child_die
;
13305 child_origin_cu
= cu
;
13308 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13312 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13316 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13317 counterpart may exist. */
13318 if (child_origin_die
!= child_die
)
13320 if (child_die
->tag
!= child_origin_die
->tag
13321 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13322 && child_origin_die
->tag
== DW_TAG_subprogram
))
13323 complaint (_("Child DIE %s and its abstract origin %s have "
13325 sect_offset_str (child_die
->sect_off
),
13326 sect_offset_str (child_origin_die
->sect_off
));
13327 if (child_origin_die
->parent
!= origin_die
)
13328 complaint (_("Child DIE %s and its abstract origin %s have "
13329 "different parents"),
13330 sect_offset_str (child_die
->sect_off
),
13331 sect_offset_str (child_origin_die
->sect_off
));
13333 offsets
.push_back (child_origin_die
->sect_off
);
13336 std::sort (offsets
.begin (), offsets
.end ());
13337 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13338 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13339 if (offsetp
[-1] == *offsetp
)
13340 complaint (_("Multiple children of DIE %s refer "
13341 "to DIE %s as their abstract origin"),
13342 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13344 offsetp
= offsets
.data ();
13345 origin_child_die
= origin_die
->child
;
13346 while (origin_child_die
&& origin_child_die
->tag
)
13348 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13349 while (offsetp
< offsets_end
13350 && *offsetp
< origin_child_die
->sect_off
)
13352 if (offsetp
>= offsets_end
13353 || *offsetp
> origin_child_die
->sect_off
)
13355 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13356 Check whether we're already processing ORIGIN_CHILD_DIE.
13357 This can happen with mutually referenced abstract_origins.
13359 if (!origin_child_die
->in_process
)
13360 process_die (origin_child_die
, origin_cu
);
13362 origin_child_die
= sibling_die (origin_child_die
);
13364 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13366 if (cu
!= origin_cu
)
13367 compute_delayed_physnames (origin_cu
);
13371 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13373 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13374 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13375 struct context_stack
*newobj
;
13378 struct die_info
*child_die
;
13379 struct attribute
*attr
, *call_line
, *call_file
;
13381 CORE_ADDR baseaddr
;
13382 struct block
*block
;
13383 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13384 std::vector
<struct symbol
*> template_args
;
13385 struct template_symbol
*templ_func
= NULL
;
13389 /* If we do not have call site information, we can't show the
13390 caller of this inlined function. That's too confusing, so
13391 only use the scope for local variables. */
13392 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13393 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13394 if (call_line
== NULL
|| call_file
== NULL
)
13396 read_lexical_block_scope (die
, cu
);
13401 baseaddr
= objfile
->text_section_offset ();
13403 name
= dwarf2_name (die
, cu
);
13405 /* Ignore functions with missing or empty names. These are actually
13406 illegal according to the DWARF standard. */
13409 complaint (_("missing name for subprogram DIE at %s"),
13410 sect_offset_str (die
->sect_off
));
13414 /* Ignore functions with missing or invalid low and high pc attributes. */
13415 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13416 <= PC_BOUNDS_INVALID
)
13418 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13419 if (!attr
|| !DW_UNSND (attr
))
13420 complaint (_("cannot get low and high bounds "
13421 "for subprogram DIE at %s"),
13422 sect_offset_str (die
->sect_off
));
13426 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13427 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13429 /* If we have any template arguments, then we must allocate a
13430 different sort of symbol. */
13431 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13433 if (child_die
->tag
== DW_TAG_template_type_param
13434 || child_die
->tag
== DW_TAG_template_value_param
)
13436 templ_func
= allocate_template_symbol (objfile
);
13437 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13442 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13443 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13444 (struct symbol
*) templ_func
);
13446 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13447 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13450 /* If there is a location expression for DW_AT_frame_base, record
13452 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13453 if (attr
!= nullptr)
13454 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13456 /* If there is a location for the static link, record it. */
13457 newobj
->static_link
= NULL
;
13458 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13459 if (attr
!= nullptr)
13461 newobj
->static_link
13462 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13463 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13464 dwarf2_per_cu_addr_type (cu
->per_cu
));
13467 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13469 if (die
->child
!= NULL
)
13471 child_die
= die
->child
;
13472 while (child_die
&& child_die
->tag
)
13474 if (child_die
->tag
== DW_TAG_template_type_param
13475 || child_die
->tag
== DW_TAG_template_value_param
)
13477 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13480 template_args
.push_back (arg
);
13483 process_die (child_die
, cu
);
13484 child_die
= sibling_die (child_die
);
13488 inherit_abstract_dies (die
, cu
);
13490 /* If we have a DW_AT_specification, we might need to import using
13491 directives from the context of the specification DIE. See the
13492 comment in determine_prefix. */
13493 if (cu
->language
== language_cplus
13494 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13496 struct dwarf2_cu
*spec_cu
= cu
;
13497 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13501 child_die
= spec_die
->child
;
13502 while (child_die
&& child_die
->tag
)
13504 if (child_die
->tag
== DW_TAG_imported_module
)
13505 process_die (child_die
, spec_cu
);
13506 child_die
= sibling_die (child_die
);
13509 /* In some cases, GCC generates specification DIEs that
13510 themselves contain DW_AT_specification attributes. */
13511 spec_die
= die_specification (spec_die
, &spec_cu
);
13515 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13516 /* Make a block for the local symbols within. */
13517 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13518 cstk
.static_link
, lowpc
, highpc
);
13520 /* For C++, set the block's scope. */
13521 if ((cu
->language
== language_cplus
13522 || cu
->language
== language_fortran
13523 || cu
->language
== language_d
13524 || cu
->language
== language_rust
)
13525 && cu
->processing_has_namespace_info
)
13526 block_set_scope (block
, determine_prefix (die
, cu
),
13527 &objfile
->objfile_obstack
);
13529 /* If we have address ranges, record them. */
13530 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13532 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13534 /* Attach template arguments to function. */
13535 if (!template_args
.empty ())
13537 gdb_assert (templ_func
!= NULL
);
13539 templ_func
->n_template_arguments
= template_args
.size ();
13540 templ_func
->template_arguments
13541 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13542 templ_func
->n_template_arguments
);
13543 memcpy (templ_func
->template_arguments
,
13544 template_args
.data (),
13545 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13547 /* Make sure that the symtab is set on the new symbols. Even
13548 though they don't appear in this symtab directly, other parts
13549 of gdb assume that symbols do, and this is reasonably
13551 for (symbol
*sym
: template_args
)
13552 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13555 /* In C++, we can have functions nested inside functions (e.g., when
13556 a function declares a class that has methods). This means that
13557 when we finish processing a function scope, we may need to go
13558 back to building a containing block's symbol lists. */
13559 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13560 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13562 /* If we've finished processing a top-level function, subsequent
13563 symbols go in the file symbol list. */
13564 if (cu
->get_builder ()->outermost_context_p ())
13565 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13568 /* Process all the DIES contained within a lexical block scope. Start
13569 a new scope, process the dies, and then close the scope. */
13572 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13574 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13575 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13576 CORE_ADDR lowpc
, highpc
;
13577 struct die_info
*child_die
;
13578 CORE_ADDR baseaddr
;
13580 baseaddr
= objfile
->text_section_offset ();
13582 /* Ignore blocks with missing or invalid low and high pc attributes. */
13583 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13584 as multiple lexical blocks? Handling children in a sane way would
13585 be nasty. Might be easier to properly extend generic blocks to
13586 describe ranges. */
13587 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13589 case PC_BOUNDS_NOT_PRESENT
:
13590 /* DW_TAG_lexical_block has no attributes, process its children as if
13591 there was no wrapping by that DW_TAG_lexical_block.
13592 GCC does no longer produces such DWARF since GCC r224161. */
13593 for (child_die
= die
->child
;
13594 child_die
!= NULL
&& child_die
->tag
;
13595 child_die
= sibling_die (child_die
))
13596 process_die (child_die
, cu
);
13598 case PC_BOUNDS_INVALID
:
13601 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13602 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13604 cu
->get_builder ()->push_context (0, lowpc
);
13605 if (die
->child
!= NULL
)
13607 child_die
= die
->child
;
13608 while (child_die
&& child_die
->tag
)
13610 process_die (child_die
, cu
);
13611 child_die
= sibling_die (child_die
);
13614 inherit_abstract_dies (die
, cu
);
13615 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13617 if (*cu
->get_builder ()->get_local_symbols () != NULL
13618 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13620 struct block
*block
13621 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13622 cstk
.start_addr
, highpc
);
13624 /* Note that recording ranges after traversing children, as we
13625 do here, means that recording a parent's ranges entails
13626 walking across all its children's ranges as they appear in
13627 the address map, which is quadratic behavior.
13629 It would be nicer to record the parent's ranges before
13630 traversing its children, simply overriding whatever you find
13631 there. But since we don't even decide whether to create a
13632 block until after we've traversed its children, that's hard
13634 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13636 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13637 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13640 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13643 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13645 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13646 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13647 CORE_ADDR pc
, baseaddr
;
13648 struct attribute
*attr
;
13649 struct call_site
*call_site
, call_site_local
;
13652 struct die_info
*child_die
;
13654 baseaddr
= objfile
->text_section_offset ();
13656 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13659 /* This was a pre-DWARF-5 GNU extension alias
13660 for DW_AT_call_return_pc. */
13661 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13665 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13666 "DIE %s [in module %s]"),
13667 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13670 pc
= attr_value_as_address (attr
) + baseaddr
;
13671 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13673 if (cu
->call_site_htab
== NULL
)
13674 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13675 NULL
, &objfile
->objfile_obstack
,
13676 hashtab_obstack_allocate
, NULL
);
13677 call_site_local
.pc
= pc
;
13678 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13681 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13682 "DIE %s [in module %s]"),
13683 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13684 objfile_name (objfile
));
13688 /* Count parameters at the caller. */
13691 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13692 child_die
= sibling_die (child_die
))
13694 if (child_die
->tag
!= DW_TAG_call_site_parameter
13695 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13697 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13698 "DW_TAG_call_site child DIE %s [in module %s]"),
13699 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13700 objfile_name (objfile
));
13708 = ((struct call_site
*)
13709 obstack_alloc (&objfile
->objfile_obstack
,
13710 sizeof (*call_site
)
13711 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13713 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13714 call_site
->pc
= pc
;
13716 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13717 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13719 struct die_info
*func_die
;
13721 /* Skip also over DW_TAG_inlined_subroutine. */
13722 for (func_die
= die
->parent
;
13723 func_die
&& func_die
->tag
!= DW_TAG_subprogram
13724 && func_die
->tag
!= DW_TAG_subroutine_type
;
13725 func_die
= func_die
->parent
);
13727 /* DW_AT_call_all_calls is a superset
13728 of DW_AT_call_all_tail_calls. */
13730 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
13731 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
13732 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
13733 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
13735 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
13736 not complete. But keep CALL_SITE for look ups via call_site_htab,
13737 both the initial caller containing the real return address PC and
13738 the final callee containing the current PC of a chain of tail
13739 calls do not need to have the tail call list complete. But any
13740 function candidate for a virtual tail call frame searched via
13741 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
13742 determined unambiguously. */
13746 struct type
*func_type
= NULL
;
13749 func_type
= get_die_type (func_die
, cu
);
13750 if (func_type
!= NULL
)
13752 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
13754 /* Enlist this call site to the function. */
13755 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
13756 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
13759 complaint (_("Cannot find function owning DW_TAG_call_site "
13760 "DIE %s [in module %s]"),
13761 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13765 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
13767 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
13769 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
13772 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
13773 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13775 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
13776 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
13777 /* Keep NULL DWARF_BLOCK. */;
13778 else if (attr_form_is_block (attr
))
13780 struct dwarf2_locexpr_baton
*dlbaton
;
13782 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
13783 dlbaton
->data
= DW_BLOCK (attr
)->data
;
13784 dlbaton
->size
= DW_BLOCK (attr
)->size
;
13785 dlbaton
->per_cu
= cu
->per_cu
;
13787 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
13789 else if (attr_form_is_ref (attr
))
13791 struct dwarf2_cu
*target_cu
= cu
;
13792 struct die_info
*target_die
;
13794 target_die
= follow_die_ref (die
, attr
, &target_cu
);
13795 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
13796 if (die_is_declaration (target_die
, target_cu
))
13798 const char *target_physname
;
13800 /* Prefer the mangled name; otherwise compute the demangled one. */
13801 target_physname
= dw2_linkage_name (target_die
, target_cu
);
13802 if (target_physname
== NULL
)
13803 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
13804 if (target_physname
== NULL
)
13805 complaint (_("DW_AT_call_target target DIE has invalid "
13806 "physname, for referencing DIE %s [in module %s]"),
13807 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13809 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
13815 /* DW_AT_entry_pc should be preferred. */
13816 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
13817 <= PC_BOUNDS_INVALID
)
13818 complaint (_("DW_AT_call_target target DIE has invalid "
13819 "low pc, for referencing DIE %s [in module %s]"),
13820 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13823 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13824 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
13829 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
13830 "block nor reference, for DIE %s [in module %s]"),
13831 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13833 call_site
->per_cu
= cu
->per_cu
;
13835 for (child_die
= die
->child
;
13836 child_die
&& child_die
->tag
;
13837 child_die
= sibling_die (child_die
))
13839 struct call_site_parameter
*parameter
;
13840 struct attribute
*loc
, *origin
;
13842 if (child_die
->tag
!= DW_TAG_call_site_parameter
13843 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13845 /* Already printed the complaint above. */
13849 gdb_assert (call_site
->parameter_count
< nparams
);
13850 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
13852 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
13853 specifies DW_TAG_formal_parameter. Value of the data assumed for the
13854 register is contained in DW_AT_call_value. */
13856 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
13857 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
13858 if (origin
== NULL
)
13860 /* This was a pre-DWARF-5 GNU extension alias
13861 for DW_AT_call_parameter. */
13862 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
13864 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
13866 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
13868 sect_offset sect_off
13869 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
13870 if (!offset_in_cu_p (&cu
->header
, sect_off
))
13872 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
13873 binding can be done only inside one CU. Such referenced DIE
13874 therefore cannot be even moved to DW_TAG_partial_unit. */
13875 complaint (_("DW_AT_call_parameter offset is not in CU for "
13876 "DW_TAG_call_site child DIE %s [in module %s]"),
13877 sect_offset_str (child_die
->sect_off
),
13878 objfile_name (objfile
));
13881 parameter
->u
.param_cu_off
13882 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
13884 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
13886 complaint (_("No DW_FORM_block* DW_AT_location for "
13887 "DW_TAG_call_site child DIE %s [in module %s]"),
13888 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
13893 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
13894 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
13895 if (parameter
->u
.dwarf_reg
!= -1)
13896 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
13897 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
13898 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
13899 ¶meter
->u
.fb_offset
))
13900 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
13903 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
13904 "for DW_FORM_block* DW_AT_location is supported for "
13905 "DW_TAG_call_site child DIE %s "
13907 sect_offset_str (child_die
->sect_off
),
13908 objfile_name (objfile
));
13913 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
13915 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
13916 if (!attr_form_is_block (attr
))
13918 complaint (_("No DW_FORM_block* DW_AT_call_value for "
13919 "DW_TAG_call_site child DIE %s [in module %s]"),
13920 sect_offset_str (child_die
->sect_off
),
13921 objfile_name (objfile
));
13924 parameter
->value
= DW_BLOCK (attr
)->data
;
13925 parameter
->value_size
= DW_BLOCK (attr
)->size
;
13927 /* Parameters are not pre-cleared by memset above. */
13928 parameter
->data_value
= NULL
;
13929 parameter
->data_value_size
= 0;
13930 call_site
->parameter_count
++;
13932 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
13934 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
13935 if (attr
!= nullptr)
13937 if (!attr_form_is_block (attr
))
13938 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
13939 "DW_TAG_call_site child DIE %s [in module %s]"),
13940 sect_offset_str (child_die
->sect_off
),
13941 objfile_name (objfile
));
13944 parameter
->data_value
= DW_BLOCK (attr
)->data
;
13945 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
13951 /* Helper function for read_variable. If DIE represents a virtual
13952 table, then return the type of the concrete object that is
13953 associated with the virtual table. Otherwise, return NULL. */
13955 static struct type
*
13956 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13958 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
13962 /* Find the type DIE. */
13963 struct die_info
*type_die
= NULL
;
13964 struct dwarf2_cu
*type_cu
= cu
;
13966 if (attr_form_is_ref (attr
))
13967 type_die
= follow_die_ref (die
, attr
, &type_cu
);
13968 if (type_die
== NULL
)
13971 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
13973 return die_containing_type (type_die
, type_cu
);
13976 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
13979 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
13981 struct rust_vtable_symbol
*storage
= NULL
;
13983 if (cu
->language
== language_rust
)
13985 struct type
*containing_type
= rust_containing_type (die
, cu
);
13987 if (containing_type
!= NULL
)
13989 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13991 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
13992 initialize_objfile_symbol (storage
);
13993 storage
->concrete_type
= containing_type
;
13994 storage
->subclass
= SYMBOL_RUST_VTABLE
;
13998 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
13999 struct attribute
*abstract_origin
14000 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14001 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14002 if (res
== NULL
&& loc
&& abstract_origin
)
14004 /* We have a variable without a name, but with a location and an abstract
14005 origin. This may be a concrete instance of an abstract variable
14006 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14008 struct dwarf2_cu
*origin_cu
= cu
;
14009 struct die_info
*origin_die
14010 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14011 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14012 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14016 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14017 reading .debug_rnglists.
14018 Callback's type should be:
14019 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14020 Return true if the attributes are present and valid, otherwise,
14023 template <typename Callback
>
14025 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14026 Callback
&&callback
)
14028 struct dwarf2_per_objfile
*dwarf2_per_objfile
14029 = cu
->per_cu
->dwarf2_per_objfile
;
14030 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14031 bfd
*obfd
= objfile
->obfd
;
14032 /* Base address selection entry. */
14035 const gdb_byte
*buffer
;
14036 CORE_ADDR baseaddr
;
14037 bool overflow
= false;
14039 found_base
= cu
->base_known
;
14040 base
= cu
->base_address
;
14042 dwarf2_per_objfile
->rnglists
.read (objfile
);
14043 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14045 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14049 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14051 baseaddr
= objfile
->text_section_offset ();
14055 /* Initialize it due to a false compiler warning. */
14056 CORE_ADDR range_beginning
= 0, range_end
= 0;
14057 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14058 + dwarf2_per_objfile
->rnglists
.size
);
14059 unsigned int bytes_read
;
14061 if (buffer
== buf_end
)
14066 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14069 case DW_RLE_end_of_list
:
14071 case DW_RLE_base_address
:
14072 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14077 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14079 buffer
+= bytes_read
;
14081 case DW_RLE_start_length
:
14082 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14087 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14088 buffer
+= bytes_read
;
14089 range_end
= (range_beginning
14090 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14091 buffer
+= bytes_read
;
14092 if (buffer
> buf_end
)
14098 case DW_RLE_offset_pair
:
14099 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14100 buffer
+= bytes_read
;
14101 if (buffer
> buf_end
)
14106 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14107 buffer
+= bytes_read
;
14108 if (buffer
> buf_end
)
14114 case DW_RLE_start_end
:
14115 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14120 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14121 buffer
+= bytes_read
;
14122 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14123 buffer
+= bytes_read
;
14126 complaint (_("Invalid .debug_rnglists data (no base address)"));
14129 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14131 if (rlet
== DW_RLE_base_address
)
14136 /* We have no valid base address for the ranges
14138 complaint (_("Invalid .debug_rnglists data (no base address)"));
14142 if (range_beginning
> range_end
)
14144 /* Inverted range entries are invalid. */
14145 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14149 /* Empty range entries have no effect. */
14150 if (range_beginning
== range_end
)
14153 range_beginning
+= base
;
14156 /* A not-uncommon case of bad debug info.
14157 Don't pollute the addrmap with bad data. */
14158 if (range_beginning
+ baseaddr
== 0
14159 && !dwarf2_per_objfile
->has_section_at_zero
)
14161 complaint (_(".debug_rnglists entry has start address of zero"
14162 " [in module %s]"), objfile_name (objfile
));
14166 callback (range_beginning
, range_end
);
14171 complaint (_("Offset %d is not terminated "
14172 "for DW_AT_ranges attribute"),
14180 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14181 Callback's type should be:
14182 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14183 Return 1 if the attributes are present and valid, otherwise, return 0. */
14185 template <typename Callback
>
14187 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14188 Callback
&&callback
)
14190 struct dwarf2_per_objfile
*dwarf2_per_objfile
14191 = cu
->per_cu
->dwarf2_per_objfile
;
14192 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14193 struct comp_unit_head
*cu_header
= &cu
->header
;
14194 bfd
*obfd
= objfile
->obfd
;
14195 unsigned int addr_size
= cu_header
->addr_size
;
14196 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14197 /* Base address selection entry. */
14200 unsigned int dummy
;
14201 const gdb_byte
*buffer
;
14202 CORE_ADDR baseaddr
;
14204 if (cu_header
->version
>= 5)
14205 return dwarf2_rnglists_process (offset
, cu
, callback
);
14207 found_base
= cu
->base_known
;
14208 base
= cu
->base_address
;
14210 dwarf2_per_objfile
->ranges
.read (objfile
);
14211 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14213 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14217 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14219 baseaddr
= objfile
->text_section_offset ();
14223 CORE_ADDR range_beginning
, range_end
;
14225 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14226 buffer
+= addr_size
;
14227 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14228 buffer
+= addr_size
;
14229 offset
+= 2 * addr_size
;
14231 /* An end of list marker is a pair of zero addresses. */
14232 if (range_beginning
== 0 && range_end
== 0)
14233 /* Found the end of list entry. */
14236 /* Each base address selection entry is a pair of 2 values.
14237 The first is the largest possible address, the second is
14238 the base address. Check for a base address here. */
14239 if ((range_beginning
& mask
) == mask
)
14241 /* If we found the largest possible address, then we already
14242 have the base address in range_end. */
14250 /* We have no valid base address for the ranges
14252 complaint (_("Invalid .debug_ranges data (no base address)"));
14256 if (range_beginning
> range_end
)
14258 /* Inverted range entries are invalid. */
14259 complaint (_("Invalid .debug_ranges data (inverted range)"));
14263 /* Empty range entries have no effect. */
14264 if (range_beginning
== range_end
)
14267 range_beginning
+= base
;
14270 /* A not-uncommon case of bad debug info.
14271 Don't pollute the addrmap with bad data. */
14272 if (range_beginning
+ baseaddr
== 0
14273 && !dwarf2_per_objfile
->has_section_at_zero
)
14275 complaint (_(".debug_ranges entry has start address of zero"
14276 " [in module %s]"), objfile_name (objfile
));
14280 callback (range_beginning
, range_end
);
14286 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14287 Return 1 if the attributes are present and valid, otherwise, return 0.
14288 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14291 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14292 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14293 dwarf2_psymtab
*ranges_pst
)
14295 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14296 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14297 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14300 CORE_ADDR high
= 0;
14303 retval
= dwarf2_ranges_process (offset
, cu
,
14304 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14306 if (ranges_pst
!= NULL
)
14311 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14312 range_beginning
+ baseaddr
)
14314 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14315 range_end
+ baseaddr
)
14317 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14318 lowpc
, highpc
- 1, ranges_pst
);
14321 /* FIXME: This is recording everything as a low-high
14322 segment of consecutive addresses. We should have a
14323 data structure for discontiguous block ranges
14327 low
= range_beginning
;
14333 if (range_beginning
< low
)
14334 low
= range_beginning
;
14335 if (range_end
> high
)
14343 /* If the first entry is an end-of-list marker, the range
14344 describes an empty scope, i.e. no instructions. */
14350 *high_return
= high
;
14354 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14355 definition for the return value. *LOWPC and *HIGHPC are set iff
14356 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14358 static enum pc_bounds_kind
14359 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14360 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14361 dwarf2_psymtab
*pst
)
14363 struct dwarf2_per_objfile
*dwarf2_per_objfile
14364 = cu
->per_cu
->dwarf2_per_objfile
;
14365 struct attribute
*attr
;
14366 struct attribute
*attr_high
;
14368 CORE_ADDR high
= 0;
14369 enum pc_bounds_kind ret
;
14371 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14374 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14375 if (attr
!= nullptr)
14377 low
= attr_value_as_address (attr
);
14378 high
= attr_value_as_address (attr_high
);
14379 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14383 /* Found high w/o low attribute. */
14384 return PC_BOUNDS_INVALID
;
14386 /* Found consecutive range of addresses. */
14387 ret
= PC_BOUNDS_HIGH_LOW
;
14391 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14394 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14395 We take advantage of the fact that DW_AT_ranges does not appear
14396 in DW_TAG_compile_unit of DWO files. */
14397 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14398 unsigned int ranges_offset
= (DW_UNSND (attr
)
14399 + (need_ranges_base
14403 /* Value of the DW_AT_ranges attribute is the offset in the
14404 .debug_ranges section. */
14405 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14406 return PC_BOUNDS_INVALID
;
14407 /* Found discontinuous range of addresses. */
14408 ret
= PC_BOUNDS_RANGES
;
14411 return PC_BOUNDS_NOT_PRESENT
;
14414 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14416 return PC_BOUNDS_INVALID
;
14418 /* When using the GNU linker, .gnu.linkonce. sections are used to
14419 eliminate duplicate copies of functions and vtables and such.
14420 The linker will arbitrarily choose one and discard the others.
14421 The AT_*_pc values for such functions refer to local labels in
14422 these sections. If the section from that file was discarded, the
14423 labels are not in the output, so the relocs get a value of 0.
14424 If this is a discarded function, mark the pc bounds as invalid,
14425 so that GDB will ignore it. */
14426 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14427 return PC_BOUNDS_INVALID
;
14435 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14436 its low and high PC addresses. Do nothing if these addresses could not
14437 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14438 and HIGHPC to the high address if greater than HIGHPC. */
14441 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14442 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14443 struct dwarf2_cu
*cu
)
14445 CORE_ADDR low
, high
;
14446 struct die_info
*child
= die
->child
;
14448 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14450 *lowpc
= std::min (*lowpc
, low
);
14451 *highpc
= std::max (*highpc
, high
);
14454 /* If the language does not allow nested subprograms (either inside
14455 subprograms or lexical blocks), we're done. */
14456 if (cu
->language
!= language_ada
)
14459 /* Check all the children of the given DIE. If it contains nested
14460 subprograms, then check their pc bounds. Likewise, we need to
14461 check lexical blocks as well, as they may also contain subprogram
14463 while (child
&& child
->tag
)
14465 if (child
->tag
== DW_TAG_subprogram
14466 || child
->tag
== DW_TAG_lexical_block
)
14467 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14468 child
= sibling_die (child
);
14472 /* Get the low and high pc's represented by the scope DIE, and store
14473 them in *LOWPC and *HIGHPC. If the correct values can't be
14474 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14477 get_scope_pc_bounds (struct die_info
*die
,
14478 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14479 struct dwarf2_cu
*cu
)
14481 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14482 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14483 CORE_ADDR current_low
, current_high
;
14485 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14486 >= PC_BOUNDS_RANGES
)
14488 best_low
= current_low
;
14489 best_high
= current_high
;
14493 struct die_info
*child
= die
->child
;
14495 while (child
&& child
->tag
)
14497 switch (child
->tag
) {
14498 case DW_TAG_subprogram
:
14499 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14501 case DW_TAG_namespace
:
14502 case DW_TAG_module
:
14503 /* FIXME: carlton/2004-01-16: Should we do this for
14504 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14505 that current GCC's always emit the DIEs corresponding
14506 to definitions of methods of classes as children of a
14507 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14508 the DIEs giving the declarations, which could be
14509 anywhere). But I don't see any reason why the
14510 standards says that they have to be there. */
14511 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14513 if (current_low
!= ((CORE_ADDR
) -1))
14515 best_low
= std::min (best_low
, current_low
);
14516 best_high
= std::max (best_high
, current_high
);
14524 child
= sibling_die (child
);
14529 *highpc
= best_high
;
14532 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14536 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14537 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14539 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14540 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14541 struct attribute
*attr
;
14542 struct attribute
*attr_high
;
14544 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14547 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14548 if (attr
!= nullptr)
14550 CORE_ADDR low
= attr_value_as_address (attr
);
14551 CORE_ADDR high
= attr_value_as_address (attr_high
);
14553 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14556 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14557 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14558 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14562 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14563 if (attr
!= nullptr)
14565 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14566 We take advantage of the fact that DW_AT_ranges does not appear
14567 in DW_TAG_compile_unit of DWO files. */
14568 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14570 /* The value of the DW_AT_ranges attribute is the offset of the
14571 address range list in the .debug_ranges section. */
14572 unsigned long offset
= (DW_UNSND (attr
)
14573 + (need_ranges_base
? cu
->ranges_base
: 0));
14575 std::vector
<blockrange
> blockvec
;
14576 dwarf2_ranges_process (offset
, cu
,
14577 [&] (CORE_ADDR start
, CORE_ADDR end
)
14581 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14582 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14583 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14584 blockvec
.emplace_back (start
, end
);
14587 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14591 /* Check whether the producer field indicates either of GCC < 4.6, or the
14592 Intel C/C++ compiler, and cache the result in CU. */
14595 check_producer (struct dwarf2_cu
*cu
)
14599 if (cu
->producer
== NULL
)
14601 /* For unknown compilers expect their behavior is DWARF version
14604 GCC started to support .debug_types sections by -gdwarf-4 since
14605 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14606 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14607 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14608 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14610 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14612 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14613 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14615 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14617 cu
->producer_is_icc
= true;
14618 cu
->producer_is_icc_lt_14
= major
< 14;
14620 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14621 cu
->producer_is_codewarrior
= true;
14624 /* For other non-GCC compilers, expect their behavior is DWARF version
14628 cu
->checked_producer
= true;
14631 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14632 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14633 during 4.6.0 experimental. */
14636 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14638 if (!cu
->checked_producer
)
14639 check_producer (cu
);
14641 return cu
->producer_is_gxx_lt_4_6
;
14645 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14646 with incorrect is_stmt attributes. */
14649 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14651 if (!cu
->checked_producer
)
14652 check_producer (cu
);
14654 return cu
->producer_is_codewarrior
;
14657 /* Return the default accessibility type if it is not overridden by
14658 DW_AT_accessibility. */
14660 static enum dwarf_access_attribute
14661 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14663 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14665 /* The default DWARF 2 accessibility for members is public, the default
14666 accessibility for inheritance is private. */
14668 if (die
->tag
!= DW_TAG_inheritance
)
14669 return DW_ACCESS_public
;
14671 return DW_ACCESS_private
;
14675 /* DWARF 3+ defines the default accessibility a different way. The same
14676 rules apply now for DW_TAG_inheritance as for the members and it only
14677 depends on the container kind. */
14679 if (die
->parent
->tag
== DW_TAG_class_type
)
14680 return DW_ACCESS_private
;
14682 return DW_ACCESS_public
;
14686 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14687 offset. If the attribute was not found return 0, otherwise return
14688 1. If it was found but could not properly be handled, set *OFFSET
14692 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14695 struct attribute
*attr
;
14697 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14702 /* Note that we do not check for a section offset first here.
14703 This is because DW_AT_data_member_location is new in DWARF 4,
14704 so if we see it, we can assume that a constant form is really
14705 a constant and not a section offset. */
14706 if (attr_form_is_constant (attr
))
14707 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14708 else if (attr_form_is_section_offset (attr
))
14709 dwarf2_complex_location_expr_complaint ();
14710 else if (attr_form_is_block (attr
))
14711 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14713 dwarf2_complex_location_expr_complaint ();
14721 /* Add an aggregate field to the field list. */
14724 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
14725 struct dwarf2_cu
*cu
)
14727 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14728 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14729 struct nextfield
*new_field
;
14730 struct attribute
*attr
;
14732 const char *fieldname
= "";
14734 if (die
->tag
== DW_TAG_inheritance
)
14736 fip
->baseclasses
.emplace_back ();
14737 new_field
= &fip
->baseclasses
.back ();
14741 fip
->fields
.emplace_back ();
14742 new_field
= &fip
->fields
.back ();
14747 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14748 if (attr
!= nullptr)
14749 new_field
->accessibility
= DW_UNSND (attr
);
14751 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
14752 if (new_field
->accessibility
!= DW_ACCESS_public
)
14753 fip
->non_public_fields
= 1;
14755 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
14756 if (attr
!= nullptr)
14757 new_field
->virtuality
= DW_UNSND (attr
);
14759 new_field
->virtuality
= DW_VIRTUALITY_none
;
14761 fp
= &new_field
->field
;
14763 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
14767 /* Data member other than a C++ static data member. */
14769 /* Get type of field. */
14770 fp
->type
= die_type (die
, cu
);
14772 SET_FIELD_BITPOS (*fp
, 0);
14774 /* Get bit size of field (zero if none). */
14775 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
14776 if (attr
!= nullptr)
14778 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
14782 FIELD_BITSIZE (*fp
) = 0;
14785 /* Get bit offset of field. */
14786 if (handle_data_member_location (die
, cu
, &offset
))
14787 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14788 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
14789 if (attr
!= nullptr)
14791 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
14793 /* For big endian bits, the DW_AT_bit_offset gives the
14794 additional bit offset from the MSB of the containing
14795 anonymous object to the MSB of the field. We don't
14796 have to do anything special since we don't need to
14797 know the size of the anonymous object. */
14798 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
14802 /* For little endian bits, compute the bit offset to the
14803 MSB of the anonymous object, subtract off the number of
14804 bits from the MSB of the field to the MSB of the
14805 object, and then subtract off the number of bits of
14806 the field itself. The result is the bit offset of
14807 the LSB of the field. */
14808 int anonymous_size
;
14809 int bit_offset
= DW_UNSND (attr
);
14811 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
14812 if (attr
!= nullptr)
14814 /* The size of the anonymous object containing
14815 the bit field is explicit, so use the
14816 indicated size (in bytes). */
14817 anonymous_size
= DW_UNSND (attr
);
14821 /* The size of the anonymous object containing
14822 the bit field must be inferred from the type
14823 attribute of the data member containing the
14825 anonymous_size
= TYPE_LENGTH (fp
->type
);
14827 SET_FIELD_BITPOS (*fp
,
14828 (FIELD_BITPOS (*fp
)
14829 + anonymous_size
* bits_per_byte
14830 - bit_offset
- FIELD_BITSIZE (*fp
)));
14833 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
14835 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
14836 + dwarf2_get_attr_constant_value (attr
, 0)));
14838 /* Get name of field. */
14839 fieldname
= dwarf2_name (die
, cu
);
14840 if (fieldname
== NULL
)
14843 /* The name is already allocated along with this objfile, so we don't
14844 need to duplicate it for the type. */
14845 fp
->name
= fieldname
;
14847 /* Change accessibility for artificial fields (e.g. virtual table
14848 pointer or virtual base class pointer) to private. */
14849 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
14851 FIELD_ARTIFICIAL (*fp
) = 1;
14852 new_field
->accessibility
= DW_ACCESS_private
;
14853 fip
->non_public_fields
= 1;
14856 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
14858 /* C++ static member. */
14860 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
14861 is a declaration, but all versions of G++ as of this writing
14862 (so through at least 3.2.1) incorrectly generate
14863 DW_TAG_variable tags. */
14865 const char *physname
;
14867 /* Get name of field. */
14868 fieldname
= dwarf2_name (die
, cu
);
14869 if (fieldname
== NULL
)
14872 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
14874 /* Only create a symbol if this is an external value.
14875 new_symbol checks this and puts the value in the global symbol
14876 table, which we want. If it is not external, new_symbol
14877 will try to put the value in cu->list_in_scope which is wrong. */
14878 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
14880 /* A static const member, not much different than an enum as far as
14881 we're concerned, except that we can support more types. */
14882 new_symbol (die
, NULL
, cu
);
14885 /* Get physical name. */
14886 physname
= dwarf2_physname (fieldname
, die
, cu
);
14888 /* The name is already allocated along with this objfile, so we don't
14889 need to duplicate it for the type. */
14890 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
14891 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14892 FIELD_NAME (*fp
) = fieldname
;
14894 else if (die
->tag
== DW_TAG_inheritance
)
14898 /* C++ base class field. */
14899 if (handle_data_member_location (die
, cu
, &offset
))
14900 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
14901 FIELD_BITSIZE (*fp
) = 0;
14902 FIELD_TYPE (*fp
) = die_type (die
, cu
);
14903 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
14905 else if (die
->tag
== DW_TAG_variant_part
)
14907 /* process_structure_scope will treat this DIE as a union. */
14908 process_structure_scope (die
, cu
);
14910 /* The variant part is relative to the start of the enclosing
14912 SET_FIELD_BITPOS (*fp
, 0);
14913 fp
->type
= get_die_type (die
, cu
);
14914 fp
->artificial
= 1;
14915 fp
->name
= "<<variant>>";
14917 /* Normally a DW_TAG_variant_part won't have a size, but our
14918 representation requires one, so set it to the maximum of the
14919 child sizes, being sure to account for the offset at which
14920 each child is seen. */
14921 if (TYPE_LENGTH (fp
->type
) == 0)
14924 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
14926 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
14927 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
14931 TYPE_LENGTH (fp
->type
) = max
;
14935 gdb_assert_not_reached ("missing case in dwarf2_add_field");
14938 /* Can the type given by DIE define another type? */
14941 type_can_define_types (const struct die_info
*die
)
14945 case DW_TAG_typedef
:
14946 case DW_TAG_class_type
:
14947 case DW_TAG_structure_type
:
14948 case DW_TAG_union_type
:
14949 case DW_TAG_enumeration_type
:
14957 /* Add a type definition defined in the scope of the FIP's class. */
14960 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
14961 struct dwarf2_cu
*cu
)
14963 struct decl_field fp
;
14964 memset (&fp
, 0, sizeof (fp
));
14966 gdb_assert (type_can_define_types (die
));
14968 /* Get name of field. NULL is okay here, meaning an anonymous type. */
14969 fp
.name
= dwarf2_name (die
, cu
);
14970 fp
.type
= read_type_die (die
, cu
);
14972 /* Save accessibility. */
14973 enum dwarf_access_attribute accessibility
;
14974 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
14976 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
14978 accessibility
= dwarf2_default_access_attribute (die
, cu
);
14979 switch (accessibility
)
14981 case DW_ACCESS_public
:
14982 /* The assumed value if neither private nor protected. */
14984 case DW_ACCESS_private
:
14987 case DW_ACCESS_protected
:
14988 fp
.is_protected
= 1;
14991 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
14994 if (die
->tag
== DW_TAG_typedef
)
14995 fip
->typedef_field_list
.push_back (fp
);
14997 fip
->nested_types_list
.push_back (fp
);
15000 /* Create the vector of fields, and attach it to the type. */
15003 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15004 struct dwarf2_cu
*cu
)
15006 int nfields
= fip
->nfields
;
15008 /* Record the field count, allocate space for the array of fields,
15009 and create blank accessibility bitfields if necessary. */
15010 TYPE_NFIELDS (type
) = nfields
;
15011 TYPE_FIELDS (type
) = (struct field
*)
15012 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15014 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15016 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15018 TYPE_FIELD_PRIVATE_BITS (type
) =
15019 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15020 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15022 TYPE_FIELD_PROTECTED_BITS (type
) =
15023 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15024 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15026 TYPE_FIELD_IGNORE_BITS (type
) =
15027 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15028 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15031 /* If the type has baseclasses, allocate and clear a bit vector for
15032 TYPE_FIELD_VIRTUAL_BITS. */
15033 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15035 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15036 unsigned char *pointer
;
15038 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15039 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15040 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15041 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15042 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15045 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15047 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15049 for (int index
= 0; index
< nfields
; ++index
)
15051 struct nextfield
&field
= fip
->fields
[index
];
15053 if (field
.variant
.is_discriminant
)
15054 di
->discriminant_index
= index
;
15055 else if (field
.variant
.default_branch
)
15056 di
->default_index
= index
;
15058 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15062 /* Copy the saved-up fields into the field vector. */
15063 for (int i
= 0; i
< nfields
; ++i
)
15065 struct nextfield
&field
15066 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15067 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15069 TYPE_FIELD (type
, i
) = field
.field
;
15070 switch (field
.accessibility
)
15072 case DW_ACCESS_private
:
15073 if (cu
->language
!= language_ada
)
15074 SET_TYPE_FIELD_PRIVATE (type
, i
);
15077 case DW_ACCESS_protected
:
15078 if (cu
->language
!= language_ada
)
15079 SET_TYPE_FIELD_PROTECTED (type
, i
);
15082 case DW_ACCESS_public
:
15086 /* Unknown accessibility. Complain and treat it as public. */
15088 complaint (_("unsupported accessibility %d"),
15089 field
.accessibility
);
15093 if (i
< fip
->baseclasses
.size ())
15095 switch (field
.virtuality
)
15097 case DW_VIRTUALITY_virtual
:
15098 case DW_VIRTUALITY_pure_virtual
:
15099 if (cu
->language
== language_ada
)
15100 error (_("unexpected virtuality in component of Ada type"));
15101 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15108 /* Return true if this member function is a constructor, false
15112 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15114 const char *fieldname
;
15115 const char *type_name
;
15118 if (die
->parent
== NULL
)
15121 if (die
->parent
->tag
!= DW_TAG_structure_type
15122 && die
->parent
->tag
!= DW_TAG_union_type
15123 && die
->parent
->tag
!= DW_TAG_class_type
)
15126 fieldname
= dwarf2_name (die
, cu
);
15127 type_name
= dwarf2_name (die
->parent
, cu
);
15128 if (fieldname
== NULL
|| type_name
== NULL
)
15131 len
= strlen (fieldname
);
15132 return (strncmp (fieldname
, type_name
, len
) == 0
15133 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15136 /* Check if the given VALUE is a recognized enum
15137 dwarf_defaulted_attribute constant according to DWARF5 spec,
15141 is_valid_DW_AT_defaulted (ULONGEST value
)
15145 case DW_DEFAULTED_no
:
15146 case DW_DEFAULTED_in_class
:
15147 case DW_DEFAULTED_out_of_class
:
15151 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15155 /* Add a member function to the proper fieldlist. */
15158 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15159 struct type
*type
, struct dwarf2_cu
*cu
)
15161 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15162 struct attribute
*attr
;
15164 struct fnfieldlist
*flp
= nullptr;
15165 struct fn_field
*fnp
;
15166 const char *fieldname
;
15167 struct type
*this_type
;
15168 enum dwarf_access_attribute accessibility
;
15170 if (cu
->language
== language_ada
)
15171 error (_("unexpected member function in Ada type"));
15173 /* Get name of member function. */
15174 fieldname
= dwarf2_name (die
, cu
);
15175 if (fieldname
== NULL
)
15178 /* Look up member function name in fieldlist. */
15179 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15181 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15183 flp
= &fip
->fnfieldlists
[i
];
15188 /* Create a new fnfieldlist if necessary. */
15189 if (flp
== nullptr)
15191 fip
->fnfieldlists
.emplace_back ();
15192 flp
= &fip
->fnfieldlists
.back ();
15193 flp
->name
= fieldname
;
15194 i
= fip
->fnfieldlists
.size () - 1;
15197 /* Create a new member function field and add it to the vector of
15199 flp
->fnfields
.emplace_back ();
15200 fnp
= &flp
->fnfields
.back ();
15202 /* Delay processing of the physname until later. */
15203 if (cu
->language
== language_cplus
)
15204 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15208 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15209 fnp
->physname
= physname
? physname
: "";
15212 fnp
->type
= alloc_type (objfile
);
15213 this_type
= read_type_die (die
, cu
);
15214 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15216 int nparams
= TYPE_NFIELDS (this_type
);
15218 /* TYPE is the domain of this method, and THIS_TYPE is the type
15219 of the method itself (TYPE_CODE_METHOD). */
15220 smash_to_method_type (fnp
->type
, type
,
15221 TYPE_TARGET_TYPE (this_type
),
15222 TYPE_FIELDS (this_type
),
15223 TYPE_NFIELDS (this_type
),
15224 TYPE_VARARGS (this_type
));
15226 /* Handle static member functions.
15227 Dwarf2 has no clean way to discern C++ static and non-static
15228 member functions. G++ helps GDB by marking the first
15229 parameter for non-static member functions (which is the this
15230 pointer) as artificial. We obtain this information from
15231 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15232 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15233 fnp
->voffset
= VOFFSET_STATIC
;
15236 complaint (_("member function type missing for '%s'"),
15237 dwarf2_full_name (fieldname
, die
, cu
));
15239 /* Get fcontext from DW_AT_containing_type if present. */
15240 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15241 fnp
->fcontext
= die_containing_type (die
, cu
);
15243 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15244 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15246 /* Get accessibility. */
15247 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15248 if (attr
!= nullptr)
15249 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15251 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15252 switch (accessibility
)
15254 case DW_ACCESS_private
:
15255 fnp
->is_private
= 1;
15257 case DW_ACCESS_protected
:
15258 fnp
->is_protected
= 1;
15262 /* Check for artificial methods. */
15263 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15264 if (attr
&& DW_UNSND (attr
) != 0)
15265 fnp
->is_artificial
= 1;
15267 /* Check for defaulted methods. */
15268 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15269 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15270 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15272 /* Check for deleted methods. */
15273 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15274 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15275 fnp
->is_deleted
= 1;
15277 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15279 /* Get index in virtual function table if it is a virtual member
15280 function. For older versions of GCC, this is an offset in the
15281 appropriate virtual table, as specified by DW_AT_containing_type.
15282 For everyone else, it is an expression to be evaluated relative
15283 to the object address. */
15285 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15286 if (attr
!= nullptr)
15288 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15290 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15292 /* Old-style GCC. */
15293 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15295 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15296 || (DW_BLOCK (attr
)->size
> 1
15297 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15298 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15300 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15301 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15302 dwarf2_complex_location_expr_complaint ();
15304 fnp
->voffset
/= cu
->header
.addr_size
;
15308 dwarf2_complex_location_expr_complaint ();
15310 if (!fnp
->fcontext
)
15312 /* If there is no `this' field and no DW_AT_containing_type,
15313 we cannot actually find a base class context for the
15315 if (TYPE_NFIELDS (this_type
) == 0
15316 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15318 complaint (_("cannot determine context for virtual member "
15319 "function \"%s\" (offset %s)"),
15320 fieldname
, sect_offset_str (die
->sect_off
));
15325 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15329 else if (attr_form_is_section_offset (attr
))
15331 dwarf2_complex_location_expr_complaint ();
15335 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15341 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15342 if (attr
&& DW_UNSND (attr
))
15344 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15345 complaint (_("Member function \"%s\" (offset %s) is virtual "
15346 "but the vtable offset is not specified"),
15347 fieldname
, sect_offset_str (die
->sect_off
));
15348 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15349 TYPE_CPLUS_DYNAMIC (type
) = 1;
15354 /* Create the vector of member function fields, and attach it to the type. */
15357 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15358 struct dwarf2_cu
*cu
)
15360 if (cu
->language
== language_ada
)
15361 error (_("unexpected member functions in Ada type"));
15363 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15364 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15366 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15368 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15370 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15371 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15373 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15374 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15375 fn_flp
->fn_fields
= (struct fn_field
*)
15376 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15378 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15379 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15382 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15385 /* Returns non-zero if NAME is the name of a vtable member in CU's
15386 language, zero otherwise. */
15388 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15390 static const char vptr
[] = "_vptr";
15392 /* Look for the C++ form of the vtable. */
15393 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15399 /* GCC outputs unnamed structures that are really pointers to member
15400 functions, with the ABI-specified layout. If TYPE describes
15401 such a structure, smash it into a member function type.
15403 GCC shouldn't do this; it should just output pointer to member DIEs.
15404 This is GCC PR debug/28767. */
15407 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15409 struct type
*pfn_type
, *self_type
, *new_type
;
15411 /* Check for a structure with no name and two children. */
15412 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15415 /* Check for __pfn and __delta members. */
15416 if (TYPE_FIELD_NAME (type
, 0) == NULL
15417 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15418 || TYPE_FIELD_NAME (type
, 1) == NULL
15419 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15422 /* Find the type of the method. */
15423 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15424 if (pfn_type
== NULL
15425 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15426 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15429 /* Look for the "this" argument. */
15430 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15431 if (TYPE_NFIELDS (pfn_type
) == 0
15432 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15433 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15436 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15437 new_type
= alloc_type (objfile
);
15438 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15439 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15440 TYPE_VARARGS (pfn_type
));
15441 smash_to_methodptr_type (type
, new_type
);
15444 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15445 appropriate error checking and issuing complaints if there is a
15449 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15451 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15453 if (attr
== nullptr)
15456 if (!attr_form_is_constant (attr
))
15458 complaint (_("DW_AT_alignment must have constant form"
15459 " - DIE at %s [in module %s]"),
15460 sect_offset_str (die
->sect_off
),
15461 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15466 if (attr
->form
== DW_FORM_sdata
)
15468 LONGEST val
= DW_SND (attr
);
15471 complaint (_("DW_AT_alignment value must not be negative"
15472 " - DIE at %s [in module %s]"),
15473 sect_offset_str (die
->sect_off
),
15474 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15480 align
= DW_UNSND (attr
);
15484 complaint (_("DW_AT_alignment value must not be zero"
15485 " - DIE at %s [in module %s]"),
15486 sect_offset_str (die
->sect_off
),
15487 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15490 if ((align
& (align
- 1)) != 0)
15492 complaint (_("DW_AT_alignment value must be a power of 2"
15493 " - DIE at %s [in module %s]"),
15494 sect_offset_str (die
->sect_off
),
15495 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15502 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15503 the alignment for TYPE. */
15506 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15509 if (!set_type_align (type
, get_alignment (cu
, die
)))
15510 complaint (_("DW_AT_alignment value too large"
15511 " - DIE at %s [in module %s]"),
15512 sect_offset_str (die
->sect_off
),
15513 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15516 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15517 constant for a type, according to DWARF5 spec, Table 5.5. */
15520 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15525 case DW_CC_pass_by_reference
:
15526 case DW_CC_pass_by_value
:
15530 complaint (_("unrecognized DW_AT_calling_convention value "
15531 "(%s) for a type"), pulongest (value
));
15536 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15537 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15538 also according to GNU-specific values (see include/dwarf2.h). */
15541 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15546 case DW_CC_program
:
15550 case DW_CC_GNU_renesas_sh
:
15551 case DW_CC_GNU_borland_fastcall_i386
:
15552 case DW_CC_GDB_IBM_OpenCL
:
15556 complaint (_("unrecognized DW_AT_calling_convention value "
15557 "(%s) for a subroutine"), pulongest (value
));
15562 /* Called when we find the DIE that starts a structure or union scope
15563 (definition) to create a type for the structure or union. Fill in
15564 the type's name and general properties; the members will not be
15565 processed until process_structure_scope. A symbol table entry for
15566 the type will also not be done until process_structure_scope (assuming
15567 the type has a name).
15569 NOTE: we need to call these functions regardless of whether or not the
15570 DIE has a DW_AT_name attribute, since it might be an anonymous
15571 structure or union. This gets the type entered into our set of
15572 user defined types. */
15574 static struct type
*
15575 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15577 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15579 struct attribute
*attr
;
15582 /* If the definition of this type lives in .debug_types, read that type.
15583 Don't follow DW_AT_specification though, that will take us back up
15584 the chain and we want to go down. */
15585 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15586 if (attr
!= nullptr)
15588 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15590 /* The type's CU may not be the same as CU.
15591 Ensure TYPE is recorded with CU in die_type_hash. */
15592 return set_die_type (die
, type
, cu
);
15595 type
= alloc_type (objfile
);
15596 INIT_CPLUS_SPECIFIC (type
);
15598 name
= dwarf2_name (die
, cu
);
15601 if (cu
->language
== language_cplus
15602 || cu
->language
== language_d
15603 || cu
->language
== language_rust
)
15605 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15607 /* dwarf2_full_name might have already finished building the DIE's
15608 type. If so, there is no need to continue. */
15609 if (get_die_type (die
, cu
) != NULL
)
15610 return get_die_type (die
, cu
);
15612 TYPE_NAME (type
) = full_name
;
15616 /* The name is already allocated along with this objfile, so
15617 we don't need to duplicate it for the type. */
15618 TYPE_NAME (type
) = name
;
15622 if (die
->tag
== DW_TAG_structure_type
)
15624 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15626 else if (die
->tag
== DW_TAG_union_type
)
15628 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15630 else if (die
->tag
== DW_TAG_variant_part
)
15632 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15633 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15637 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15640 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15641 TYPE_DECLARED_CLASS (type
) = 1;
15643 /* Store the calling convention in the type if it's available in
15644 the die. Otherwise the calling convention remains set to
15645 the default value DW_CC_normal. */
15646 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15647 if (attr
!= nullptr
15648 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15650 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15651 TYPE_CPLUS_CALLING_CONVENTION (type
)
15652 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15655 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15656 if (attr
!= nullptr)
15658 if (attr_form_is_constant (attr
))
15659 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15662 /* For the moment, dynamic type sizes are not supported
15663 by GDB's struct type. The actual size is determined
15664 on-demand when resolving the type of a given object,
15665 so set the type's length to zero for now. Otherwise,
15666 we record an expression as the length, and that expression
15667 could lead to a very large value, which could eventually
15668 lead to us trying to allocate that much memory when creating
15669 a value of that type. */
15670 TYPE_LENGTH (type
) = 0;
15675 TYPE_LENGTH (type
) = 0;
15678 maybe_set_alignment (cu
, die
, type
);
15680 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15682 /* ICC<14 does not output the required DW_AT_declaration on
15683 incomplete types, but gives them a size of zero. */
15684 TYPE_STUB (type
) = 1;
15687 TYPE_STUB_SUPPORTED (type
) = 1;
15689 if (die_is_declaration (die
, cu
))
15690 TYPE_STUB (type
) = 1;
15691 else if (attr
== NULL
&& die
->child
== NULL
15692 && producer_is_realview (cu
->producer
))
15693 /* RealView does not output the required DW_AT_declaration
15694 on incomplete types. */
15695 TYPE_STUB (type
) = 1;
15697 /* We need to add the type field to the die immediately so we don't
15698 infinitely recurse when dealing with pointers to the structure
15699 type within the structure itself. */
15700 set_die_type (die
, type
, cu
);
15702 /* set_die_type should be already done. */
15703 set_descriptive_type (type
, die
, cu
);
15708 /* A helper for process_structure_scope that handles a single member
15712 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15713 struct field_info
*fi
,
15714 std::vector
<struct symbol
*> *template_args
,
15715 struct dwarf2_cu
*cu
)
15717 if (child_die
->tag
== DW_TAG_member
15718 || child_die
->tag
== DW_TAG_variable
15719 || child_die
->tag
== DW_TAG_variant_part
)
15721 /* NOTE: carlton/2002-11-05: A C++ static data member
15722 should be a DW_TAG_member that is a declaration, but
15723 all versions of G++ as of this writing (so through at
15724 least 3.2.1) incorrectly generate DW_TAG_variable
15725 tags for them instead. */
15726 dwarf2_add_field (fi
, child_die
, cu
);
15728 else if (child_die
->tag
== DW_TAG_subprogram
)
15730 /* Rust doesn't have member functions in the C++ sense.
15731 However, it does emit ordinary functions as children
15732 of a struct DIE. */
15733 if (cu
->language
== language_rust
)
15734 read_func_scope (child_die
, cu
);
15737 /* C++ member function. */
15738 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15741 else if (child_die
->tag
== DW_TAG_inheritance
)
15743 /* C++ base class field. */
15744 dwarf2_add_field (fi
, child_die
, cu
);
15746 else if (type_can_define_types (child_die
))
15747 dwarf2_add_type_defn (fi
, child_die
, cu
);
15748 else if (child_die
->tag
== DW_TAG_template_type_param
15749 || child_die
->tag
== DW_TAG_template_value_param
)
15751 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15754 template_args
->push_back (arg
);
15756 else if (child_die
->tag
== DW_TAG_variant
)
15758 /* In a variant we want to get the discriminant and also add a
15759 field for our sole member child. */
15760 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15762 for (die_info
*variant_child
= child_die
->child
;
15763 variant_child
!= NULL
;
15764 variant_child
= sibling_die (variant_child
))
15766 if (variant_child
->tag
== DW_TAG_member
)
15768 handle_struct_member_die (variant_child
, type
, fi
,
15769 template_args
, cu
);
15770 /* Only handle the one. */
15775 /* We don't handle this but we might as well report it if we see
15777 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15778 complaint (_("DW_AT_discr_list is not supported yet"
15779 " - DIE at %s [in module %s]"),
15780 sect_offset_str (child_die
->sect_off
),
15781 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15783 /* The first field was just added, so we can stash the
15784 discriminant there. */
15785 gdb_assert (!fi
->fields
.empty ());
15787 fi
->fields
.back ().variant
.default_branch
= true;
15789 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15793 /* Finish creating a structure or union type, including filling in
15794 its members and creating a symbol for it. */
15797 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15799 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15800 struct die_info
*child_die
;
15803 type
= get_die_type (die
, cu
);
15805 type
= read_structure_type (die
, cu
);
15807 /* When reading a DW_TAG_variant_part, we need to notice when we
15808 read the discriminant member, so we can record it later in the
15809 discriminant_info. */
15810 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
15811 sect_offset discr_offset
{};
15812 bool has_template_parameters
= false;
15814 if (is_variant_part
)
15816 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
15819 /* Maybe it's a univariant form, an extension we support.
15820 In this case arrange not to check the offset. */
15821 is_variant_part
= false;
15823 else if (attr_form_is_ref (discr
))
15825 struct dwarf2_cu
*target_cu
= cu
;
15826 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
15828 discr_offset
= target_die
->sect_off
;
15832 complaint (_("DW_AT_discr does not have DIE reference form"
15833 " - DIE at %s [in module %s]"),
15834 sect_offset_str (die
->sect_off
),
15835 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15836 is_variant_part
= false;
15840 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
15842 struct field_info fi
;
15843 std::vector
<struct symbol
*> template_args
;
15845 child_die
= die
->child
;
15847 while (child_die
&& child_die
->tag
)
15849 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
15851 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
15852 fi
.fields
.back ().variant
.is_discriminant
= true;
15854 child_die
= sibling_die (child_die
);
15857 /* Attach template arguments to type. */
15858 if (!template_args
.empty ())
15860 has_template_parameters
= true;
15861 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15862 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
15863 TYPE_TEMPLATE_ARGUMENTS (type
)
15864 = XOBNEWVEC (&objfile
->objfile_obstack
,
15866 TYPE_N_TEMPLATE_ARGUMENTS (type
));
15867 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
15868 template_args
.data (),
15869 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
15870 * sizeof (struct symbol
*)));
15873 /* Attach fields and member functions to the type. */
15875 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
15876 if (!fi
.fnfieldlists
.empty ())
15878 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
15880 /* Get the type which refers to the base class (possibly this
15881 class itself) which contains the vtable pointer for the current
15882 class from the DW_AT_containing_type attribute. This use of
15883 DW_AT_containing_type is a GNU extension. */
15885 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15887 struct type
*t
= die_containing_type (die
, cu
);
15889 set_type_vptr_basetype (type
, t
);
15894 /* Our own class provides vtbl ptr. */
15895 for (i
= TYPE_NFIELDS (t
) - 1;
15896 i
>= TYPE_N_BASECLASSES (t
);
15899 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
15901 if (is_vtable_name (fieldname
, cu
))
15903 set_type_vptr_fieldno (type
, i
);
15908 /* Complain if virtual function table field not found. */
15909 if (i
< TYPE_N_BASECLASSES (t
))
15910 complaint (_("virtual function table pointer "
15911 "not found when defining class '%s'"),
15912 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
15916 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
15919 else if (cu
->producer
15920 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
15922 /* The IBM XLC compiler does not provide direct indication
15923 of the containing type, but the vtable pointer is
15924 always named __vfp. */
15928 for (i
= TYPE_NFIELDS (type
) - 1;
15929 i
>= TYPE_N_BASECLASSES (type
);
15932 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
15934 set_type_vptr_fieldno (type
, i
);
15935 set_type_vptr_basetype (type
, type
);
15942 /* Copy fi.typedef_field_list linked list elements content into the
15943 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
15944 if (!fi
.typedef_field_list
.empty ())
15946 int count
= fi
.typedef_field_list
.size ();
15948 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15949 TYPE_TYPEDEF_FIELD_ARRAY (type
)
15950 = ((struct decl_field
*)
15952 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
15953 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
15955 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
15956 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
15959 /* Copy fi.nested_types_list linked list elements content into the
15960 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
15961 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
15963 int count
= fi
.nested_types_list
.size ();
15965 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15966 TYPE_NESTED_TYPES_ARRAY (type
)
15967 = ((struct decl_field
*)
15968 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
15969 TYPE_NESTED_TYPES_COUNT (type
) = count
;
15971 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
15972 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
15976 quirk_gcc_member_function_pointer (type
, objfile
);
15977 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
15978 cu
->rust_unions
.push_back (type
);
15980 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
15981 snapshots) has been known to create a die giving a declaration
15982 for a class that has, as a child, a die giving a definition for a
15983 nested class. So we have to process our children even if the
15984 current die is a declaration. Normally, of course, a declaration
15985 won't have any children at all. */
15987 child_die
= die
->child
;
15989 while (child_die
!= NULL
&& child_die
->tag
)
15991 if (child_die
->tag
== DW_TAG_member
15992 || child_die
->tag
== DW_TAG_variable
15993 || child_die
->tag
== DW_TAG_inheritance
15994 || child_die
->tag
== DW_TAG_template_value_param
15995 || child_die
->tag
== DW_TAG_template_type_param
)
16000 process_die (child_die
, cu
);
16002 child_die
= sibling_die (child_die
);
16005 /* Do not consider external references. According to the DWARF standard,
16006 these DIEs are identified by the fact that they have no byte_size
16007 attribute, and a declaration attribute. */
16008 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16009 || !die_is_declaration (die
, cu
))
16011 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16013 if (has_template_parameters
)
16015 struct symtab
*symtab
;
16016 if (sym
!= nullptr)
16017 symtab
= symbol_symtab (sym
);
16018 else if (cu
->line_header
!= nullptr)
16020 /* Any related symtab will do. */
16022 = cu
->line_header
->file_names ()[0].symtab
;
16027 complaint (_("could not find suitable "
16028 "symtab for template parameter"
16029 " - DIE at %s [in module %s]"),
16030 sect_offset_str (die
->sect_off
),
16031 objfile_name (objfile
));
16034 if (symtab
!= nullptr)
16036 /* Make sure that the symtab is set on the new symbols.
16037 Even though they don't appear in this symtab directly,
16038 other parts of gdb assume that symbols do, and this is
16039 reasonably true. */
16040 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16041 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16047 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16048 update TYPE using some information only available in DIE's children. */
16051 update_enumeration_type_from_children (struct die_info
*die
,
16053 struct dwarf2_cu
*cu
)
16055 struct die_info
*child_die
;
16056 int unsigned_enum
= 1;
16060 auto_obstack obstack
;
16062 for (child_die
= die
->child
;
16063 child_die
!= NULL
&& child_die
->tag
;
16064 child_die
= sibling_die (child_die
))
16066 struct attribute
*attr
;
16068 const gdb_byte
*bytes
;
16069 struct dwarf2_locexpr_baton
*baton
;
16072 if (child_die
->tag
!= DW_TAG_enumerator
)
16075 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16079 name
= dwarf2_name (child_die
, cu
);
16081 name
= "<anonymous enumerator>";
16083 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16084 &value
, &bytes
, &baton
);
16090 else if ((mask
& value
) != 0)
16095 /* If we already know that the enum type is neither unsigned, nor
16096 a flag type, no need to look at the rest of the enumerates. */
16097 if (!unsigned_enum
&& !flag_enum
)
16102 TYPE_UNSIGNED (type
) = 1;
16104 TYPE_FLAG_ENUM (type
) = 1;
16107 /* Given a DW_AT_enumeration_type die, set its type. We do not
16108 complete the type's fields yet, or create any symbols. */
16110 static struct type
*
16111 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16113 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16115 struct attribute
*attr
;
16118 /* If the definition of this type lives in .debug_types, read that type.
16119 Don't follow DW_AT_specification though, that will take us back up
16120 the chain and we want to go down. */
16121 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16122 if (attr
!= nullptr)
16124 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16126 /* The type's CU may not be the same as CU.
16127 Ensure TYPE is recorded with CU in die_type_hash. */
16128 return set_die_type (die
, type
, cu
);
16131 type
= alloc_type (objfile
);
16133 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16134 name
= dwarf2_full_name (NULL
, die
, cu
);
16136 TYPE_NAME (type
) = name
;
16138 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16141 struct type
*underlying_type
= die_type (die
, cu
);
16143 TYPE_TARGET_TYPE (type
) = underlying_type
;
16146 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16147 if (attr
!= nullptr)
16149 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16153 TYPE_LENGTH (type
) = 0;
16156 maybe_set_alignment (cu
, die
, type
);
16158 /* The enumeration DIE can be incomplete. In Ada, any type can be
16159 declared as private in the package spec, and then defined only
16160 inside the package body. Such types are known as Taft Amendment
16161 Types. When another package uses such a type, an incomplete DIE
16162 may be generated by the compiler. */
16163 if (die_is_declaration (die
, cu
))
16164 TYPE_STUB (type
) = 1;
16166 /* Finish the creation of this type by using the enum's children.
16167 We must call this even when the underlying type has been provided
16168 so that we can determine if we're looking at a "flag" enum. */
16169 update_enumeration_type_from_children (die
, type
, cu
);
16171 /* If this type has an underlying type that is not a stub, then we
16172 may use its attributes. We always use the "unsigned" attribute
16173 in this situation, because ordinarily we guess whether the type
16174 is unsigned -- but the guess can be wrong and the underlying type
16175 can tell us the reality. However, we defer to a local size
16176 attribute if one exists, because this lets the compiler override
16177 the underlying type if needed. */
16178 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16180 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16181 if (TYPE_LENGTH (type
) == 0)
16182 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16183 if (TYPE_RAW_ALIGN (type
) == 0
16184 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16185 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16188 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16190 return set_die_type (die
, type
, cu
);
16193 /* Given a pointer to a die which begins an enumeration, process all
16194 the dies that define the members of the enumeration, and create the
16195 symbol for the enumeration type.
16197 NOTE: We reverse the order of the element list. */
16200 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16202 struct type
*this_type
;
16204 this_type
= get_die_type (die
, cu
);
16205 if (this_type
== NULL
)
16206 this_type
= read_enumeration_type (die
, cu
);
16208 if (die
->child
!= NULL
)
16210 struct die_info
*child_die
;
16211 struct symbol
*sym
;
16212 std::vector
<struct field
> fields
;
16215 child_die
= die
->child
;
16216 while (child_die
&& child_die
->tag
)
16218 if (child_die
->tag
!= DW_TAG_enumerator
)
16220 process_die (child_die
, cu
);
16224 name
= dwarf2_name (child_die
, cu
);
16227 sym
= new_symbol (child_die
, this_type
, cu
);
16229 fields
.emplace_back ();
16230 struct field
&field
= fields
.back ();
16232 FIELD_NAME (field
) = sym
->linkage_name ();
16233 FIELD_TYPE (field
) = NULL
;
16234 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16235 FIELD_BITSIZE (field
) = 0;
16239 child_die
= sibling_die (child_die
);
16242 if (!fields
.empty ())
16244 TYPE_NFIELDS (this_type
) = fields
.size ();
16245 TYPE_FIELDS (this_type
) = (struct field
*)
16246 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16247 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16248 sizeof (struct field
) * fields
.size ());
16252 /* If we are reading an enum from a .debug_types unit, and the enum
16253 is a declaration, and the enum is not the signatured type in the
16254 unit, then we do not want to add a symbol for it. Adding a
16255 symbol would in some cases obscure the true definition of the
16256 enum, giving users an incomplete type when the definition is
16257 actually available. Note that we do not want to do this for all
16258 enums which are just declarations, because C++0x allows forward
16259 enum declarations. */
16260 if (cu
->per_cu
->is_debug_types
16261 && die_is_declaration (die
, cu
))
16263 struct signatured_type
*sig_type
;
16265 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16266 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16267 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16271 new_symbol (die
, this_type
, cu
);
16274 /* Extract all information from a DW_TAG_array_type DIE and put it in
16275 the DIE's type field. For now, this only handles one dimensional
16278 static struct type
*
16279 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16281 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16282 struct die_info
*child_die
;
16284 struct type
*element_type
, *range_type
, *index_type
;
16285 struct attribute
*attr
;
16287 struct dynamic_prop
*byte_stride_prop
= NULL
;
16288 unsigned int bit_stride
= 0;
16290 element_type
= die_type (die
, cu
);
16292 /* The die_type call above may have already set the type for this DIE. */
16293 type
= get_die_type (die
, cu
);
16297 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16301 struct type
*prop_type
16302 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16305 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16306 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16310 complaint (_("unable to read array DW_AT_byte_stride "
16311 " - DIE at %s [in module %s]"),
16312 sect_offset_str (die
->sect_off
),
16313 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16314 /* Ignore this attribute. We will likely not be able to print
16315 arrays of this type correctly, but there is little we can do
16316 to help if we cannot read the attribute's value. */
16317 byte_stride_prop
= NULL
;
16321 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16323 bit_stride
= DW_UNSND (attr
);
16325 /* Irix 6.2 native cc creates array types without children for
16326 arrays with unspecified length. */
16327 if (die
->child
== NULL
)
16329 index_type
= objfile_type (objfile
)->builtin_int
;
16330 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16331 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16332 byte_stride_prop
, bit_stride
);
16333 return set_die_type (die
, type
, cu
);
16336 std::vector
<struct type
*> range_types
;
16337 child_die
= die
->child
;
16338 while (child_die
&& child_die
->tag
)
16340 if (child_die
->tag
== DW_TAG_subrange_type
)
16342 struct type
*child_type
= read_type_die (child_die
, cu
);
16344 if (child_type
!= NULL
)
16346 /* The range type was succesfully read. Save it for the
16347 array type creation. */
16348 range_types
.push_back (child_type
);
16351 child_die
= sibling_die (child_die
);
16354 /* Dwarf2 dimensions are output from left to right, create the
16355 necessary array types in backwards order. */
16357 type
= element_type
;
16359 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16363 while (i
< range_types
.size ())
16364 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16365 byte_stride_prop
, bit_stride
);
16369 size_t ndim
= range_types
.size ();
16371 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16372 byte_stride_prop
, bit_stride
);
16375 /* Understand Dwarf2 support for vector types (like they occur on
16376 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16377 array type. This is not part of the Dwarf2/3 standard yet, but a
16378 custom vendor extension. The main difference between a regular
16379 array and the vector variant is that vectors are passed by value
16381 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16382 if (attr
!= nullptr)
16383 make_vector_type (type
);
16385 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16386 implementation may choose to implement triple vectors using this
16388 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16389 if (attr
!= nullptr)
16391 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16392 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16394 complaint (_("DW_AT_byte_size for array type smaller "
16395 "than the total size of elements"));
16398 name
= dwarf2_name (die
, cu
);
16400 TYPE_NAME (type
) = name
;
16402 maybe_set_alignment (cu
, die
, type
);
16404 /* Install the type in the die. */
16405 set_die_type (die
, type
, cu
);
16407 /* set_die_type should be already done. */
16408 set_descriptive_type (type
, die
, cu
);
16413 static enum dwarf_array_dim_ordering
16414 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16416 struct attribute
*attr
;
16418 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16420 if (attr
!= nullptr)
16421 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16423 /* GNU F77 is a special case, as at 08/2004 array type info is the
16424 opposite order to the dwarf2 specification, but data is still
16425 laid out as per normal fortran.
16427 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16428 version checking. */
16430 if (cu
->language
== language_fortran
16431 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16433 return DW_ORD_row_major
;
16436 switch (cu
->language_defn
->la_array_ordering
)
16438 case array_column_major
:
16439 return DW_ORD_col_major
;
16440 case array_row_major
:
16442 return DW_ORD_row_major
;
16446 /* Extract all information from a DW_TAG_set_type DIE and put it in
16447 the DIE's type field. */
16449 static struct type
*
16450 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16452 struct type
*domain_type
, *set_type
;
16453 struct attribute
*attr
;
16455 domain_type
= die_type (die
, cu
);
16457 /* The die_type call above may have already set the type for this DIE. */
16458 set_type
= get_die_type (die
, cu
);
16462 set_type
= create_set_type (NULL
, domain_type
);
16464 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16465 if (attr
!= nullptr)
16466 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16468 maybe_set_alignment (cu
, die
, set_type
);
16470 return set_die_type (die
, set_type
, cu
);
16473 /* A helper for read_common_block that creates a locexpr baton.
16474 SYM is the symbol which we are marking as computed.
16475 COMMON_DIE is the DIE for the common block.
16476 COMMON_LOC is the location expression attribute for the common
16478 MEMBER_LOC is the location expression attribute for the particular
16479 member of the common block that we are processing.
16480 CU is the CU from which the above come. */
16483 mark_common_block_symbol_computed (struct symbol
*sym
,
16484 struct die_info
*common_die
,
16485 struct attribute
*common_loc
,
16486 struct attribute
*member_loc
,
16487 struct dwarf2_cu
*cu
)
16489 struct dwarf2_per_objfile
*dwarf2_per_objfile
16490 = cu
->per_cu
->dwarf2_per_objfile
;
16491 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16492 struct dwarf2_locexpr_baton
*baton
;
16494 unsigned int cu_off
;
16495 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16496 LONGEST offset
= 0;
16498 gdb_assert (common_loc
&& member_loc
);
16499 gdb_assert (attr_form_is_block (common_loc
));
16500 gdb_assert (attr_form_is_block (member_loc
)
16501 || attr_form_is_constant (member_loc
));
16503 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16504 baton
->per_cu
= cu
->per_cu
;
16505 gdb_assert (baton
->per_cu
);
16507 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16509 if (attr_form_is_constant (member_loc
))
16511 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16512 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16515 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16517 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16520 *ptr
++ = DW_OP_call4
;
16521 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16522 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16525 if (attr_form_is_constant (member_loc
))
16527 *ptr
++ = DW_OP_addr
;
16528 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16529 ptr
+= cu
->header
.addr_size
;
16533 /* We have to copy the data here, because DW_OP_call4 will only
16534 use a DW_AT_location attribute. */
16535 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16536 ptr
+= DW_BLOCK (member_loc
)->size
;
16539 *ptr
++ = DW_OP_plus
;
16540 gdb_assert (ptr
- baton
->data
== baton
->size
);
16542 SYMBOL_LOCATION_BATON (sym
) = baton
;
16543 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16546 /* Create appropriate locally-scoped variables for all the
16547 DW_TAG_common_block entries. Also create a struct common_block
16548 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16549 is used to separate the common blocks name namespace from regular
16553 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16555 struct attribute
*attr
;
16557 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16558 if (attr
!= nullptr)
16560 /* Support the .debug_loc offsets. */
16561 if (attr_form_is_block (attr
))
16565 else if (attr_form_is_section_offset (attr
))
16567 dwarf2_complex_location_expr_complaint ();
16572 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16573 "common block member");
16578 if (die
->child
!= NULL
)
16580 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16581 struct die_info
*child_die
;
16582 size_t n_entries
= 0, size
;
16583 struct common_block
*common_block
;
16584 struct symbol
*sym
;
16586 for (child_die
= die
->child
;
16587 child_die
&& child_die
->tag
;
16588 child_die
= sibling_die (child_die
))
16591 size
= (sizeof (struct common_block
)
16592 + (n_entries
- 1) * sizeof (struct symbol
*));
16594 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16596 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16597 common_block
->n_entries
= 0;
16599 for (child_die
= die
->child
;
16600 child_die
&& child_die
->tag
;
16601 child_die
= sibling_die (child_die
))
16603 /* Create the symbol in the DW_TAG_common_block block in the current
16605 sym
= new_symbol (child_die
, NULL
, cu
);
16608 struct attribute
*member_loc
;
16610 common_block
->contents
[common_block
->n_entries
++] = sym
;
16612 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16616 /* GDB has handled this for a long time, but it is
16617 not specified by DWARF. It seems to have been
16618 emitted by gfortran at least as recently as:
16619 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16620 complaint (_("Variable in common block has "
16621 "DW_AT_data_member_location "
16622 "- DIE at %s [in module %s]"),
16623 sect_offset_str (child_die
->sect_off
),
16624 objfile_name (objfile
));
16626 if (attr_form_is_section_offset (member_loc
))
16627 dwarf2_complex_location_expr_complaint ();
16628 else if (attr_form_is_constant (member_loc
)
16629 || attr_form_is_block (member_loc
))
16631 if (attr
!= nullptr)
16632 mark_common_block_symbol_computed (sym
, die
, attr
,
16636 dwarf2_complex_location_expr_complaint ();
16641 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16642 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16646 /* Create a type for a C++ namespace. */
16648 static struct type
*
16649 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16651 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16652 const char *previous_prefix
, *name
;
16656 /* For extensions, reuse the type of the original namespace. */
16657 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16659 struct die_info
*ext_die
;
16660 struct dwarf2_cu
*ext_cu
= cu
;
16662 ext_die
= dwarf2_extension (die
, &ext_cu
);
16663 type
= read_type_die (ext_die
, ext_cu
);
16665 /* EXT_CU may not be the same as CU.
16666 Ensure TYPE is recorded with CU in die_type_hash. */
16667 return set_die_type (die
, type
, cu
);
16670 name
= namespace_name (die
, &is_anonymous
, cu
);
16672 /* Now build the name of the current namespace. */
16674 previous_prefix
= determine_prefix (die
, cu
);
16675 if (previous_prefix
[0] != '\0')
16676 name
= typename_concat (&objfile
->objfile_obstack
,
16677 previous_prefix
, name
, 0, cu
);
16679 /* Create the type. */
16680 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16682 return set_die_type (die
, type
, cu
);
16685 /* Read a namespace scope. */
16688 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16690 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16693 /* Add a symbol associated to this if we haven't seen the namespace
16694 before. Also, add a using directive if it's an anonymous
16697 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16701 type
= read_type_die (die
, cu
);
16702 new_symbol (die
, type
, cu
);
16704 namespace_name (die
, &is_anonymous
, cu
);
16707 const char *previous_prefix
= determine_prefix (die
, cu
);
16709 std::vector
<const char *> excludes
;
16710 add_using_directive (using_directives (cu
),
16711 previous_prefix
, TYPE_NAME (type
), NULL
,
16712 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16716 if (die
->child
!= NULL
)
16718 struct die_info
*child_die
= die
->child
;
16720 while (child_die
&& child_die
->tag
)
16722 process_die (child_die
, cu
);
16723 child_die
= sibling_die (child_die
);
16728 /* Read a Fortran module as type. This DIE can be only a declaration used for
16729 imported module. Still we need that type as local Fortran "use ... only"
16730 declaration imports depend on the created type in determine_prefix. */
16732 static struct type
*
16733 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16735 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16736 const char *module_name
;
16739 module_name
= dwarf2_name (die
, cu
);
16740 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16742 return set_die_type (die
, type
, cu
);
16745 /* Read a Fortran module. */
16748 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16750 struct die_info
*child_die
= die
->child
;
16753 type
= read_type_die (die
, cu
);
16754 new_symbol (die
, type
, cu
);
16756 while (child_die
&& child_die
->tag
)
16758 process_die (child_die
, cu
);
16759 child_die
= sibling_die (child_die
);
16763 /* Return the name of the namespace represented by DIE. Set
16764 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16767 static const char *
16768 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16770 struct die_info
*current_die
;
16771 const char *name
= NULL
;
16773 /* Loop through the extensions until we find a name. */
16775 for (current_die
= die
;
16776 current_die
!= NULL
;
16777 current_die
= dwarf2_extension (die
, &cu
))
16779 /* We don't use dwarf2_name here so that we can detect the absence
16780 of a name -> anonymous namespace. */
16781 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16787 /* Is it an anonymous namespace? */
16789 *is_anonymous
= (name
== NULL
);
16791 name
= CP_ANONYMOUS_NAMESPACE_STR
;
16796 /* Extract all information from a DW_TAG_pointer_type DIE and add to
16797 the user defined type vector. */
16799 static struct type
*
16800 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16802 struct gdbarch
*gdbarch
16803 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16804 struct comp_unit_head
*cu_header
= &cu
->header
;
16806 struct attribute
*attr_byte_size
;
16807 struct attribute
*attr_address_class
;
16808 int byte_size
, addr_class
;
16809 struct type
*target_type
;
16811 target_type
= die_type (die
, cu
);
16813 /* The die_type call above may have already set the type for this DIE. */
16814 type
= get_die_type (die
, cu
);
16818 type
= lookup_pointer_type (target_type
);
16820 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16821 if (attr_byte_size
)
16822 byte_size
= DW_UNSND (attr_byte_size
);
16824 byte_size
= cu_header
->addr_size
;
16826 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
16827 if (attr_address_class
)
16828 addr_class
= DW_UNSND (attr_address_class
);
16830 addr_class
= DW_ADDR_none
;
16832 ULONGEST alignment
= get_alignment (cu
, die
);
16834 /* If the pointer size, alignment, or address class is different
16835 than the default, create a type variant marked as such and set
16836 the length accordingly. */
16837 if (TYPE_LENGTH (type
) != byte_size
16838 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
16839 && alignment
!= TYPE_RAW_ALIGN (type
))
16840 || addr_class
!= DW_ADDR_none
)
16842 if (gdbarch_address_class_type_flags_p (gdbarch
))
16846 type_flags
= gdbarch_address_class_type_flags
16847 (gdbarch
, byte_size
, addr_class
);
16848 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
16850 type
= make_type_with_address_space (type
, type_flags
);
16852 else if (TYPE_LENGTH (type
) != byte_size
)
16854 complaint (_("invalid pointer size %d"), byte_size
);
16856 else if (TYPE_RAW_ALIGN (type
) != alignment
)
16858 complaint (_("Invalid DW_AT_alignment"
16859 " - DIE at %s [in module %s]"),
16860 sect_offset_str (die
->sect_off
),
16861 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16865 /* Should we also complain about unhandled address classes? */
16869 TYPE_LENGTH (type
) = byte_size
;
16870 set_type_align (type
, alignment
);
16871 return set_die_type (die
, type
, cu
);
16874 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
16875 the user defined type vector. */
16877 static struct type
*
16878 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16881 struct type
*to_type
;
16882 struct type
*domain
;
16884 to_type
= die_type (die
, cu
);
16885 domain
= die_containing_type (die
, cu
);
16887 /* The calls above may have already set the type for this DIE. */
16888 type
= get_die_type (die
, cu
);
16892 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
16893 type
= lookup_methodptr_type (to_type
);
16894 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
16896 struct type
*new_type
16897 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
16899 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
16900 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
16901 TYPE_VARARGS (to_type
));
16902 type
= lookup_methodptr_type (new_type
);
16905 type
= lookup_memberptr_type (to_type
, domain
);
16907 return set_die_type (die
, type
, cu
);
16910 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
16911 the user defined type vector. */
16913 static struct type
*
16914 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16915 enum type_code refcode
)
16917 struct comp_unit_head
*cu_header
= &cu
->header
;
16918 struct type
*type
, *target_type
;
16919 struct attribute
*attr
;
16921 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
16923 target_type
= die_type (die
, cu
);
16925 /* The die_type call above may have already set the type for this DIE. */
16926 type
= get_die_type (die
, cu
);
16930 type
= lookup_reference_type (target_type
, refcode
);
16931 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16932 if (attr
!= nullptr)
16934 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16938 TYPE_LENGTH (type
) = cu_header
->addr_size
;
16940 maybe_set_alignment (cu
, die
, type
);
16941 return set_die_type (die
, type
, cu
);
16944 /* Add the given cv-qualifiers to the element type of the array. GCC
16945 outputs DWARF type qualifiers that apply to an array, not the
16946 element type. But GDB relies on the array element type to carry
16947 the cv-qualifiers. This mimics section 6.7.3 of the C99
16950 static struct type
*
16951 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
16952 struct type
*base_type
, int cnst
, int voltl
)
16954 struct type
*el_type
, *inner_array
;
16956 base_type
= copy_type (base_type
);
16957 inner_array
= base_type
;
16959 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
16961 TYPE_TARGET_TYPE (inner_array
) =
16962 copy_type (TYPE_TARGET_TYPE (inner_array
));
16963 inner_array
= TYPE_TARGET_TYPE (inner_array
);
16966 el_type
= TYPE_TARGET_TYPE (inner_array
);
16967 cnst
|= TYPE_CONST (el_type
);
16968 voltl
|= TYPE_VOLATILE (el_type
);
16969 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
16971 return set_die_type (die
, base_type
, cu
);
16974 static struct type
*
16975 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16977 struct type
*base_type
, *cv_type
;
16979 base_type
= die_type (die
, cu
);
16981 /* The die_type call above may have already set the type for this DIE. */
16982 cv_type
= get_die_type (die
, cu
);
16986 /* In case the const qualifier is applied to an array type, the element type
16987 is so qualified, not the array type (section 6.7.3 of C99). */
16988 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
16989 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
16991 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
16992 return set_die_type (die
, cv_type
, cu
);
16995 static struct type
*
16996 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16998 struct type
*base_type
, *cv_type
;
17000 base_type
= die_type (die
, cu
);
17002 /* The die_type call above may have already set the type for this DIE. */
17003 cv_type
= get_die_type (die
, cu
);
17007 /* In case the volatile qualifier is applied to an array type, the
17008 element type is so qualified, not the array type (section 6.7.3
17010 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17011 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17013 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17014 return set_die_type (die
, cv_type
, cu
);
17017 /* Handle DW_TAG_restrict_type. */
17019 static struct type
*
17020 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17022 struct type
*base_type
, *cv_type
;
17024 base_type
= die_type (die
, cu
);
17026 /* The die_type call above may have already set the type for this DIE. */
17027 cv_type
= get_die_type (die
, cu
);
17031 cv_type
= make_restrict_type (base_type
);
17032 return set_die_type (die
, cv_type
, cu
);
17035 /* Handle DW_TAG_atomic_type. */
17037 static struct type
*
17038 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17040 struct type
*base_type
, *cv_type
;
17042 base_type
= die_type (die
, cu
);
17044 /* The die_type call above may have already set the type for this DIE. */
17045 cv_type
= get_die_type (die
, cu
);
17049 cv_type
= make_atomic_type (base_type
);
17050 return set_die_type (die
, cv_type
, cu
);
17053 /* Extract all information from a DW_TAG_string_type DIE and add to
17054 the user defined type vector. It isn't really a user defined type,
17055 but it behaves like one, with other DIE's using an AT_user_def_type
17056 attribute to reference it. */
17058 static struct type
*
17059 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17061 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17062 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17063 struct type
*type
, *range_type
, *index_type
, *char_type
;
17064 struct attribute
*attr
;
17065 struct dynamic_prop prop
;
17066 bool length_is_constant
= true;
17069 /* There are a couple of places where bit sizes might be made use of
17070 when parsing a DW_TAG_string_type, however, no producer that we know
17071 of make use of these. Handling bit sizes that are a multiple of the
17072 byte size is easy enough, but what about other bit sizes? Lets deal
17073 with that problem when we have to. Warn about these attributes being
17074 unsupported, then parse the type and ignore them like we always
17076 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17077 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17079 static bool warning_printed
= false;
17080 if (!warning_printed
)
17082 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17083 "currently supported on DW_TAG_string_type."));
17084 warning_printed
= true;
17088 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17089 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17091 /* The string length describes the location at which the length of
17092 the string can be found. The size of the length field can be
17093 specified with one of the attributes below. */
17094 struct type
*prop_type
;
17095 struct attribute
*len
17096 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17097 if (len
== nullptr)
17098 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17099 if (len
!= nullptr && attr_form_is_constant (len
))
17101 /* Pass 0 as the default as we know this attribute is constant
17102 and the default value will not be returned. */
17103 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17104 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17108 /* If the size is not specified then we assume it is the size of
17109 an address on this target. */
17110 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17113 /* Convert the attribute into a dynamic property. */
17114 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17117 length_is_constant
= false;
17119 else if (attr
!= nullptr)
17121 /* This DW_AT_string_length just contains the length with no
17122 indirection. There's no need to create a dynamic property in this
17123 case. Pass 0 for the default value as we know it will not be
17124 returned in this case. */
17125 length
= dwarf2_get_attr_constant_value (attr
, 0);
17127 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17129 /* We don't currently support non-constant byte sizes for strings. */
17130 length
= dwarf2_get_attr_constant_value (attr
, 1);
17134 /* Use 1 as a fallback length if we have nothing else. */
17138 index_type
= objfile_type (objfile
)->builtin_int
;
17139 if (length_is_constant
)
17140 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17143 struct dynamic_prop low_bound
;
17145 low_bound
.kind
= PROP_CONST
;
17146 low_bound
.data
.const_val
= 1;
17147 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17149 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17150 type
= create_string_type (NULL
, char_type
, range_type
);
17152 return set_die_type (die
, type
, cu
);
17155 /* Assuming that DIE corresponds to a function, returns nonzero
17156 if the function is prototyped. */
17159 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17161 struct attribute
*attr
;
17163 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17164 if (attr
&& (DW_UNSND (attr
) != 0))
17167 /* The DWARF standard implies that the DW_AT_prototyped attribute
17168 is only meaningful for C, but the concept also extends to other
17169 languages that allow unprototyped functions (Eg: Objective C).
17170 For all other languages, assume that functions are always
17172 if (cu
->language
!= language_c
17173 && cu
->language
!= language_objc
17174 && cu
->language
!= language_opencl
)
17177 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17178 prototyped and unprototyped functions; default to prototyped,
17179 since that is more common in modern code (and RealView warns
17180 about unprototyped functions). */
17181 if (producer_is_realview (cu
->producer
))
17187 /* Handle DIES due to C code like:
17191 int (*funcp)(int a, long l);
17195 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17197 static struct type
*
17198 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17200 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17201 struct type
*type
; /* Type that this function returns. */
17202 struct type
*ftype
; /* Function that returns above type. */
17203 struct attribute
*attr
;
17205 type
= die_type (die
, cu
);
17207 /* The die_type call above may have already set the type for this DIE. */
17208 ftype
= get_die_type (die
, cu
);
17212 ftype
= lookup_function_type (type
);
17214 if (prototyped_function_p (die
, cu
))
17215 TYPE_PROTOTYPED (ftype
) = 1;
17217 /* Store the calling convention in the type if it's available in
17218 the subroutine die. Otherwise set the calling convention to
17219 the default value DW_CC_normal. */
17220 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17221 if (attr
!= nullptr
17222 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17223 TYPE_CALLING_CONVENTION (ftype
)
17224 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17225 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17226 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17228 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17230 /* Record whether the function returns normally to its caller or not
17231 if the DWARF producer set that information. */
17232 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17233 if (attr
&& (DW_UNSND (attr
) != 0))
17234 TYPE_NO_RETURN (ftype
) = 1;
17236 /* We need to add the subroutine type to the die immediately so
17237 we don't infinitely recurse when dealing with parameters
17238 declared as the same subroutine type. */
17239 set_die_type (die
, ftype
, cu
);
17241 if (die
->child
!= NULL
)
17243 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17244 struct die_info
*child_die
;
17245 int nparams
, iparams
;
17247 /* Count the number of parameters.
17248 FIXME: GDB currently ignores vararg functions, but knows about
17249 vararg member functions. */
17251 child_die
= die
->child
;
17252 while (child_die
&& child_die
->tag
)
17254 if (child_die
->tag
== DW_TAG_formal_parameter
)
17256 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17257 TYPE_VARARGS (ftype
) = 1;
17258 child_die
= sibling_die (child_die
);
17261 /* Allocate storage for parameters and fill them in. */
17262 TYPE_NFIELDS (ftype
) = nparams
;
17263 TYPE_FIELDS (ftype
) = (struct field
*)
17264 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17266 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17267 even if we error out during the parameters reading below. */
17268 for (iparams
= 0; iparams
< nparams
; iparams
++)
17269 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17272 child_die
= die
->child
;
17273 while (child_die
&& child_die
->tag
)
17275 if (child_die
->tag
== DW_TAG_formal_parameter
)
17277 struct type
*arg_type
;
17279 /* DWARF version 2 has no clean way to discern C++
17280 static and non-static member functions. G++ helps
17281 GDB by marking the first parameter for non-static
17282 member functions (which is the this pointer) as
17283 artificial. We pass this information to
17284 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17286 DWARF version 3 added DW_AT_object_pointer, which GCC
17287 4.5 does not yet generate. */
17288 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17289 if (attr
!= nullptr)
17290 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17292 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17293 arg_type
= die_type (child_die
, cu
);
17295 /* RealView does not mark THIS as const, which the testsuite
17296 expects. GCC marks THIS as const in method definitions,
17297 but not in the class specifications (GCC PR 43053). */
17298 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17299 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17302 struct dwarf2_cu
*arg_cu
= cu
;
17303 const char *name
= dwarf2_name (child_die
, cu
);
17305 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17306 if (attr
!= nullptr)
17308 /* If the compiler emits this, use it. */
17309 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17312 else if (name
&& strcmp (name
, "this") == 0)
17313 /* Function definitions will have the argument names. */
17315 else if (name
== NULL
&& iparams
== 0)
17316 /* Declarations may not have the names, so like
17317 elsewhere in GDB, assume an artificial first
17318 argument is "this". */
17322 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17326 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17329 child_die
= sibling_die (child_die
);
17336 static struct type
*
17337 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17339 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17340 const char *name
= NULL
;
17341 struct type
*this_type
, *target_type
;
17343 name
= dwarf2_full_name (NULL
, die
, cu
);
17344 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17345 TYPE_TARGET_STUB (this_type
) = 1;
17346 set_die_type (die
, this_type
, cu
);
17347 target_type
= die_type (die
, cu
);
17348 if (target_type
!= this_type
)
17349 TYPE_TARGET_TYPE (this_type
) = target_type
;
17352 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17353 spec and cause infinite loops in GDB. */
17354 complaint (_("Self-referential DW_TAG_typedef "
17355 "- DIE at %s [in module %s]"),
17356 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17357 TYPE_TARGET_TYPE (this_type
) = NULL
;
17362 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17363 (which may be different from NAME) to the architecture back-end to allow
17364 it to guess the correct format if necessary. */
17366 static struct type
*
17367 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17368 const char *name_hint
, enum bfd_endian byte_order
)
17370 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17371 const struct floatformat
**format
;
17374 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17376 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17378 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17383 /* Allocate an integer type of size BITS and name NAME. */
17385 static struct type
*
17386 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17387 int bits
, int unsigned_p
, const char *name
)
17391 /* Versions of Intel's C Compiler generate an integer type called "void"
17392 instead of using DW_TAG_unspecified_type. This has been seen on
17393 at least versions 14, 17, and 18. */
17394 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17395 && strcmp (name
, "void") == 0)
17396 type
= objfile_type (objfile
)->builtin_void
;
17398 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17403 /* Initialise and return a floating point type of size BITS suitable for
17404 use as a component of a complex number. The NAME_HINT is passed through
17405 when initialising the floating point type and is the name of the complex
17408 As DWARF doesn't currently provide an explicit name for the components
17409 of a complex number, but it can be helpful to have these components
17410 named, we try to select a suitable name based on the size of the
17412 static struct type
*
17413 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17414 struct objfile
*objfile
,
17415 int bits
, const char *name_hint
,
17416 enum bfd_endian byte_order
)
17418 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17419 struct type
*tt
= nullptr;
17421 /* Try to find a suitable floating point builtin type of size BITS.
17422 We're going to use the name of this type as the name for the complex
17423 target type that we are about to create. */
17424 switch (cu
->language
)
17426 case language_fortran
:
17430 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17433 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17435 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17437 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17445 tt
= builtin_type (gdbarch
)->builtin_float
;
17448 tt
= builtin_type (gdbarch
)->builtin_double
;
17450 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17452 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17458 /* If the type we found doesn't match the size we were looking for, then
17459 pretend we didn't find a type at all, the complex target type we
17460 create will then be nameless. */
17461 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17464 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17465 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17468 /* Find a representation of a given base type and install
17469 it in the TYPE field of the die. */
17471 static struct type
*
17472 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17474 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17476 struct attribute
*attr
;
17477 int encoding
= 0, bits
= 0;
17481 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17482 if (attr
!= nullptr)
17483 encoding
= DW_UNSND (attr
);
17484 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17485 if (attr
!= nullptr)
17486 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17487 name
= dwarf2_name (die
, cu
);
17489 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17491 arch
= get_objfile_arch (objfile
);
17492 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17494 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17497 int endianity
= DW_UNSND (attr
);
17502 byte_order
= BFD_ENDIAN_BIG
;
17504 case DW_END_little
:
17505 byte_order
= BFD_ENDIAN_LITTLE
;
17508 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17515 case DW_ATE_address
:
17516 /* Turn DW_ATE_address into a void * pointer. */
17517 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17518 type
= init_pointer_type (objfile
, bits
, name
, type
);
17520 case DW_ATE_boolean
:
17521 type
= init_boolean_type (objfile
, bits
, 1, name
);
17523 case DW_ATE_complex_float
:
17524 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17526 type
= init_complex_type (objfile
, name
, type
);
17528 case DW_ATE_decimal_float
:
17529 type
= init_decfloat_type (objfile
, bits
, name
);
17532 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17534 case DW_ATE_signed
:
17535 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17537 case DW_ATE_unsigned
:
17538 if (cu
->language
== language_fortran
17540 && startswith (name
, "character("))
17541 type
= init_character_type (objfile
, bits
, 1, name
);
17543 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17545 case DW_ATE_signed_char
:
17546 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17547 || cu
->language
== language_pascal
17548 || cu
->language
== language_fortran
)
17549 type
= init_character_type (objfile
, bits
, 0, name
);
17551 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17553 case DW_ATE_unsigned_char
:
17554 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17555 || cu
->language
== language_pascal
17556 || cu
->language
== language_fortran
17557 || cu
->language
== language_rust
)
17558 type
= init_character_type (objfile
, bits
, 1, name
);
17560 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17565 type
= builtin_type (arch
)->builtin_char16
;
17566 else if (bits
== 32)
17567 type
= builtin_type (arch
)->builtin_char32
;
17570 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17572 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17574 return set_die_type (die
, type
, cu
);
17579 complaint (_("unsupported DW_AT_encoding: '%s'"),
17580 dwarf_type_encoding_name (encoding
));
17581 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17585 if (name
&& strcmp (name
, "char") == 0)
17586 TYPE_NOSIGN (type
) = 1;
17588 maybe_set_alignment (cu
, die
, type
);
17590 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17592 return set_die_type (die
, type
, cu
);
17595 /* Parse dwarf attribute if it's a block, reference or constant and put the
17596 resulting value of the attribute into struct bound_prop.
17597 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17600 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17601 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17602 struct type
*default_type
)
17604 struct dwarf2_property_baton
*baton
;
17605 struct obstack
*obstack
17606 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17608 gdb_assert (default_type
!= NULL
);
17610 if (attr
== NULL
|| prop
== NULL
)
17613 if (attr_form_is_block (attr
))
17615 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17616 baton
->property_type
= default_type
;
17617 baton
->locexpr
.per_cu
= cu
->per_cu
;
17618 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17619 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17620 switch (attr
->name
)
17622 case DW_AT_string_length
:
17623 baton
->locexpr
.is_reference
= true;
17626 baton
->locexpr
.is_reference
= false;
17629 prop
->data
.baton
= baton
;
17630 prop
->kind
= PROP_LOCEXPR
;
17631 gdb_assert (prop
->data
.baton
!= NULL
);
17633 else if (attr_form_is_ref (attr
))
17635 struct dwarf2_cu
*target_cu
= cu
;
17636 struct die_info
*target_die
;
17637 struct attribute
*target_attr
;
17639 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17640 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17641 if (target_attr
== NULL
)
17642 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17644 if (target_attr
== NULL
)
17647 switch (target_attr
->name
)
17649 case DW_AT_location
:
17650 if (attr_form_is_section_offset (target_attr
))
17652 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17653 baton
->property_type
= die_type (target_die
, target_cu
);
17654 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17655 prop
->data
.baton
= baton
;
17656 prop
->kind
= PROP_LOCLIST
;
17657 gdb_assert (prop
->data
.baton
!= NULL
);
17659 else if (attr_form_is_block (target_attr
))
17661 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17662 baton
->property_type
= die_type (target_die
, target_cu
);
17663 baton
->locexpr
.per_cu
= cu
->per_cu
;
17664 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17665 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17666 baton
->locexpr
.is_reference
= true;
17667 prop
->data
.baton
= baton
;
17668 prop
->kind
= PROP_LOCEXPR
;
17669 gdb_assert (prop
->data
.baton
!= NULL
);
17673 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17674 "dynamic property");
17678 case DW_AT_data_member_location
:
17682 if (!handle_data_member_location (target_die
, target_cu
,
17686 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17687 baton
->property_type
= read_type_die (target_die
->parent
,
17689 baton
->offset_info
.offset
= offset
;
17690 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17691 prop
->data
.baton
= baton
;
17692 prop
->kind
= PROP_ADDR_OFFSET
;
17697 else if (attr_form_is_constant (attr
))
17699 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17700 prop
->kind
= PROP_CONST
;
17704 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17705 dwarf2_name (die
, cu
));
17712 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17713 UNSIGNED_P controls if the integer is unsigned or not. */
17715 static struct type
*
17716 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17717 int size_in_bytes
, bool unsigned_p
)
17719 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17720 struct type
*int_type
;
17722 /* Helper macro to examine the various builtin types. */
17723 #define TRY_TYPE(F) \
17724 int_type = (unsigned_p \
17725 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17726 : objfile_type (objfile)->builtin_ ## F); \
17727 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
17734 TRY_TYPE (long_long
);
17738 gdb_assert_not_reached ("unable to find suitable integer type");
17741 /* Find an integer type the same size as the address size given in the
17742 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17743 is unsigned or not. */
17745 static struct type
*
17746 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17749 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17750 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
17753 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17754 present (which is valid) then compute the default type based on the
17755 compilation units address size. */
17757 static struct type
*
17758 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17760 struct type
*index_type
= die_type (die
, cu
);
17762 /* Dwarf-2 specifications explicitly allows to create subrange types
17763 without specifying a base type.
17764 In that case, the base type must be set to the type of
17765 the lower bound, upper bound or count, in that order, if any of these
17766 three attributes references an object that has a type.
17767 If no base type is found, the Dwarf-2 specifications say that
17768 a signed integer type of size equal to the size of an address should
17770 For the following C code: `extern char gdb_int [];'
17771 GCC produces an empty range DIE.
17772 FIXME: muller/2010-05-28: Possible references to object for low bound,
17773 high bound or count are not yet handled by this code. */
17774 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17775 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17780 /* Read the given DW_AT_subrange DIE. */
17782 static struct type
*
17783 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17785 struct type
*base_type
, *orig_base_type
;
17786 struct type
*range_type
;
17787 struct attribute
*attr
;
17788 struct dynamic_prop low
, high
;
17789 int low_default_is_valid
;
17790 int high_bound_is_count
= 0;
17792 ULONGEST negative_mask
;
17794 orig_base_type
= read_subrange_index_type (die
, cu
);
17796 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17797 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17798 creating the range type, but we use the result of check_typedef
17799 when examining properties of the type. */
17800 base_type
= check_typedef (orig_base_type
);
17802 /* The die_type call above may have already set the type for this DIE. */
17803 range_type
= get_die_type (die
, cu
);
17807 low
.kind
= PROP_CONST
;
17808 high
.kind
= PROP_CONST
;
17809 high
.data
.const_val
= 0;
17811 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17812 omitting DW_AT_lower_bound. */
17813 switch (cu
->language
)
17816 case language_cplus
:
17817 low
.data
.const_val
= 0;
17818 low_default_is_valid
= 1;
17820 case language_fortran
:
17821 low
.data
.const_val
= 1;
17822 low_default_is_valid
= 1;
17825 case language_objc
:
17826 case language_rust
:
17827 low
.data
.const_val
= 0;
17828 low_default_is_valid
= (cu
->header
.version
>= 4);
17832 case language_pascal
:
17833 low
.data
.const_val
= 1;
17834 low_default_is_valid
= (cu
->header
.version
>= 4);
17837 low
.data
.const_val
= 0;
17838 low_default_is_valid
= 0;
17842 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17843 if (attr
!= nullptr)
17844 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17845 else if (!low_default_is_valid
)
17846 complaint (_("Missing DW_AT_lower_bound "
17847 "- DIE at %s [in module %s]"),
17848 sect_offset_str (die
->sect_off
),
17849 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17851 struct attribute
*attr_ub
, *attr_count
;
17852 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17853 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17855 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17856 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17858 /* If bounds are constant do the final calculation here. */
17859 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17860 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17862 high_bound_is_count
= 1;
17866 if (attr_ub
!= NULL
)
17867 complaint (_("Unresolved DW_AT_upper_bound "
17868 "- DIE at %s [in module %s]"),
17869 sect_offset_str (die
->sect_off
),
17870 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17871 if (attr_count
!= NULL
)
17872 complaint (_("Unresolved DW_AT_count "
17873 "- DIE at %s [in module %s]"),
17874 sect_offset_str (die
->sect_off
),
17875 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17880 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17881 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
17882 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17884 /* Normally, the DWARF producers are expected to use a signed
17885 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17886 But this is unfortunately not always the case, as witnessed
17887 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17888 is used instead. To work around that ambiguity, we treat
17889 the bounds as signed, and thus sign-extend their values, when
17890 the base type is signed. */
17892 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17893 if (low
.kind
== PROP_CONST
17894 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
17895 low
.data
.const_val
|= negative_mask
;
17896 if (high
.kind
== PROP_CONST
17897 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
17898 high
.data
.const_val
|= negative_mask
;
17900 /* Check for bit and byte strides. */
17901 struct dynamic_prop byte_stride_prop
;
17902 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
17903 if (attr_byte_stride
!= nullptr)
17905 struct type
*prop_type
17906 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17907 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
17911 struct dynamic_prop bit_stride_prop
;
17912 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
17913 if (attr_bit_stride
!= nullptr)
17915 /* It only makes sense to have either a bit or byte stride. */
17916 if (attr_byte_stride
!= nullptr)
17918 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
17919 "- DIE at %s [in module %s]"),
17920 sect_offset_str (die
->sect_off
),
17921 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17922 attr_bit_stride
= nullptr;
17926 struct type
*prop_type
17927 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17928 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
17933 if (attr_byte_stride
!= nullptr
17934 || attr_bit_stride
!= nullptr)
17936 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
17937 struct dynamic_prop
*stride
17938 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
17941 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
17942 &high
, bias
, stride
, byte_stride_p
);
17945 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
17947 if (high_bound_is_count
)
17948 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
17950 /* Ada expects an empty array on no boundary attributes. */
17951 if (attr
== NULL
&& cu
->language
!= language_ada
)
17952 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
17954 name
= dwarf2_name (die
, cu
);
17956 TYPE_NAME (range_type
) = name
;
17958 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17959 if (attr
!= nullptr)
17960 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
17962 maybe_set_alignment (cu
, die
, range_type
);
17964 set_die_type (die
, range_type
, cu
);
17966 /* set_die_type should be already done. */
17967 set_descriptive_type (range_type
, die
, cu
);
17972 static struct type
*
17973 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17977 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
17979 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
17981 /* In Ada, an unspecified type is typically used when the description
17982 of the type is deferred to a different unit. When encountering
17983 such a type, we treat it as a stub, and try to resolve it later on,
17985 if (cu
->language
== language_ada
)
17986 TYPE_STUB (type
) = 1;
17988 return set_die_type (die
, type
, cu
);
17991 /* Read a single die and all its descendents. Set the die's sibling
17992 field to NULL; set other fields in the die correctly, and set all
17993 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
17994 location of the info_ptr after reading all of those dies. PARENT
17995 is the parent of the die in question. */
17997 static struct die_info
*
17998 read_die_and_children (const struct die_reader_specs
*reader
,
17999 const gdb_byte
*info_ptr
,
18000 const gdb_byte
**new_info_ptr
,
18001 struct die_info
*parent
)
18003 struct die_info
*die
;
18004 const gdb_byte
*cur_ptr
;
18007 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18010 *new_info_ptr
= cur_ptr
;
18013 store_in_ref_table (die
, reader
->cu
);
18016 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18020 *new_info_ptr
= cur_ptr
;
18023 die
->sibling
= NULL
;
18024 die
->parent
= parent
;
18028 /* Read a die, all of its descendents, and all of its siblings; set
18029 all of the fields of all of the dies correctly. Arguments are as
18030 in read_die_and_children. */
18032 static struct die_info
*
18033 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18034 const gdb_byte
*info_ptr
,
18035 const gdb_byte
**new_info_ptr
,
18036 struct die_info
*parent
)
18038 struct die_info
*first_die
, *last_sibling
;
18039 const gdb_byte
*cur_ptr
;
18041 cur_ptr
= info_ptr
;
18042 first_die
= last_sibling
= NULL
;
18046 struct die_info
*die
18047 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18051 *new_info_ptr
= cur_ptr
;
18058 last_sibling
->sibling
= die
;
18060 last_sibling
= die
;
18064 /* Read a die, all of its descendents, and all of its siblings; set
18065 all of the fields of all of the dies correctly. Arguments are as
18066 in read_die_and_children.
18067 This the main entry point for reading a DIE and all its children. */
18069 static struct die_info
*
18070 read_die_and_siblings (const struct die_reader_specs
*reader
,
18071 const gdb_byte
*info_ptr
,
18072 const gdb_byte
**new_info_ptr
,
18073 struct die_info
*parent
)
18075 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18076 new_info_ptr
, parent
);
18078 if (dwarf_die_debug
)
18080 fprintf_unfiltered (gdb_stdlog
,
18081 "Read die from %s@0x%x of %s:\n",
18082 reader
->die_section
->get_name (),
18083 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18084 bfd_get_filename (reader
->abfd
));
18085 dump_die (die
, dwarf_die_debug
);
18091 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18093 The caller is responsible for filling in the extra attributes
18094 and updating (*DIEP)->num_attrs.
18095 Set DIEP to point to a newly allocated die with its information,
18096 except for its child, sibling, and parent fields.
18097 Set HAS_CHILDREN to tell whether the die has children or not. */
18099 static const gdb_byte
*
18100 read_full_die_1 (const struct die_reader_specs
*reader
,
18101 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18102 int *has_children
, int num_extra_attrs
)
18104 unsigned int abbrev_number
, bytes_read
, i
;
18105 struct abbrev_info
*abbrev
;
18106 struct die_info
*die
;
18107 struct dwarf2_cu
*cu
= reader
->cu
;
18108 bfd
*abfd
= reader
->abfd
;
18110 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18111 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18112 info_ptr
+= bytes_read
;
18113 if (!abbrev_number
)
18120 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18122 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18124 bfd_get_filename (abfd
));
18126 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18127 die
->sect_off
= sect_off
;
18128 die
->tag
= abbrev
->tag
;
18129 die
->abbrev
= abbrev_number
;
18131 /* Make the result usable.
18132 The caller needs to update num_attrs after adding the extra
18134 die
->num_attrs
= abbrev
->num_attrs
;
18136 std::vector
<int> indexes_that_need_reprocess
;
18137 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18139 bool need_reprocess
;
18141 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18142 info_ptr
, &need_reprocess
);
18143 if (need_reprocess
)
18144 indexes_that_need_reprocess
.push_back (i
);
18147 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18148 if (attr
!= nullptr)
18149 cu
->str_offsets_base
= DW_UNSND (attr
);
18151 auto maybe_addr_base
= lookup_addr_base(die
);
18152 if (maybe_addr_base
.has_value ())
18153 cu
->addr_base
= *maybe_addr_base
;
18154 for (int index
: indexes_that_need_reprocess
)
18155 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18157 *has_children
= abbrev
->has_children
;
18161 /* Read a die and all its attributes.
18162 Set DIEP to point to a newly allocated die with its information,
18163 except for its child, sibling, and parent fields.
18164 Set HAS_CHILDREN to tell whether the die has children or not. */
18166 static const gdb_byte
*
18167 read_full_die (const struct die_reader_specs
*reader
,
18168 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18171 const gdb_byte
*result
;
18173 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18175 if (dwarf_die_debug
)
18177 fprintf_unfiltered (gdb_stdlog
,
18178 "Read die from %s@0x%x of %s:\n",
18179 reader
->die_section
->get_name (),
18180 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18181 bfd_get_filename (reader
->abfd
));
18182 dump_die (*diep
, dwarf_die_debug
);
18189 /* Returns nonzero if TAG represents a type that we might generate a partial
18193 is_type_tag_for_partial (int tag
)
18198 /* Some types that would be reasonable to generate partial symbols for,
18199 that we don't at present. */
18200 case DW_TAG_array_type
:
18201 case DW_TAG_file_type
:
18202 case DW_TAG_ptr_to_member_type
:
18203 case DW_TAG_set_type
:
18204 case DW_TAG_string_type
:
18205 case DW_TAG_subroutine_type
:
18207 case DW_TAG_base_type
:
18208 case DW_TAG_class_type
:
18209 case DW_TAG_interface_type
:
18210 case DW_TAG_enumeration_type
:
18211 case DW_TAG_structure_type
:
18212 case DW_TAG_subrange_type
:
18213 case DW_TAG_typedef
:
18214 case DW_TAG_union_type
:
18221 /* Load all DIEs that are interesting for partial symbols into memory. */
18223 static struct partial_die_info
*
18224 load_partial_dies (const struct die_reader_specs
*reader
,
18225 const gdb_byte
*info_ptr
, int building_psymtab
)
18227 struct dwarf2_cu
*cu
= reader
->cu
;
18228 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18229 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18230 unsigned int bytes_read
;
18231 unsigned int load_all
= 0;
18232 int nesting_level
= 1;
18237 gdb_assert (cu
->per_cu
!= NULL
);
18238 if (cu
->per_cu
->load_all_dies
)
18242 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18246 &cu
->comp_unit_obstack
,
18247 hashtab_obstack_allocate
,
18248 dummy_obstack_deallocate
);
18252 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18254 /* A NULL abbrev means the end of a series of children. */
18255 if (abbrev
== NULL
)
18257 if (--nesting_level
== 0)
18260 info_ptr
+= bytes_read
;
18261 last_die
= parent_die
;
18262 parent_die
= parent_die
->die_parent
;
18266 /* Check for template arguments. We never save these; if
18267 they're seen, we just mark the parent, and go on our way. */
18268 if (parent_die
!= NULL
18269 && cu
->language
== language_cplus
18270 && (abbrev
->tag
== DW_TAG_template_type_param
18271 || abbrev
->tag
== DW_TAG_template_value_param
))
18273 parent_die
->has_template_arguments
= 1;
18277 /* We don't need a partial DIE for the template argument. */
18278 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18283 /* We only recurse into c++ subprograms looking for template arguments.
18284 Skip their other children. */
18286 && cu
->language
== language_cplus
18287 && parent_die
!= NULL
18288 && parent_die
->tag
== DW_TAG_subprogram
)
18290 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18294 /* Check whether this DIE is interesting enough to save. Normally
18295 we would not be interested in members here, but there may be
18296 later variables referencing them via DW_AT_specification (for
18297 static members). */
18299 && !is_type_tag_for_partial (abbrev
->tag
)
18300 && abbrev
->tag
!= DW_TAG_constant
18301 && abbrev
->tag
!= DW_TAG_enumerator
18302 && abbrev
->tag
!= DW_TAG_subprogram
18303 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18304 && abbrev
->tag
!= DW_TAG_lexical_block
18305 && abbrev
->tag
!= DW_TAG_variable
18306 && abbrev
->tag
!= DW_TAG_namespace
18307 && abbrev
->tag
!= DW_TAG_module
18308 && abbrev
->tag
!= DW_TAG_member
18309 && abbrev
->tag
!= DW_TAG_imported_unit
18310 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18312 /* Otherwise we skip to the next sibling, if any. */
18313 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18317 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18320 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18322 /* This two-pass algorithm for processing partial symbols has a
18323 high cost in cache pressure. Thus, handle some simple cases
18324 here which cover the majority of C partial symbols. DIEs
18325 which neither have specification tags in them, nor could have
18326 specification tags elsewhere pointing at them, can simply be
18327 processed and discarded.
18329 This segment is also optional; scan_partial_symbols and
18330 add_partial_symbol will handle these DIEs if we chain
18331 them in normally. When compilers which do not emit large
18332 quantities of duplicate debug information are more common,
18333 this code can probably be removed. */
18335 /* Any complete simple types at the top level (pretty much all
18336 of them, for a language without namespaces), can be processed
18338 if (parent_die
== NULL
18339 && pdi
.has_specification
== 0
18340 && pdi
.is_declaration
== 0
18341 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18342 || pdi
.tag
== DW_TAG_base_type
18343 || pdi
.tag
== DW_TAG_subrange_type
))
18345 if (building_psymtab
&& pdi
.name
!= NULL
)
18346 add_psymbol_to_list (pdi
.name
, false,
18347 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18348 psymbol_placement::STATIC
,
18349 0, cu
->language
, objfile
);
18350 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18354 /* The exception for DW_TAG_typedef with has_children above is
18355 a workaround of GCC PR debug/47510. In the case of this complaint
18356 type_name_or_error will error on such types later.
18358 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18359 it could not find the child DIEs referenced later, this is checked
18360 above. In correct DWARF DW_TAG_typedef should have no children. */
18362 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18363 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18364 "- DIE at %s [in module %s]"),
18365 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18367 /* If we're at the second level, and we're an enumerator, and
18368 our parent has no specification (meaning possibly lives in a
18369 namespace elsewhere), then we can add the partial symbol now
18370 instead of queueing it. */
18371 if (pdi
.tag
== DW_TAG_enumerator
18372 && parent_die
!= NULL
18373 && parent_die
->die_parent
== NULL
18374 && parent_die
->tag
== DW_TAG_enumeration_type
18375 && parent_die
->has_specification
== 0)
18377 if (pdi
.name
== NULL
)
18378 complaint (_("malformed enumerator DIE ignored"));
18379 else if (building_psymtab
)
18380 add_psymbol_to_list (pdi
.name
, false,
18381 VAR_DOMAIN
, LOC_CONST
, -1,
18382 cu
->language
== language_cplus
18383 ? psymbol_placement::GLOBAL
18384 : psymbol_placement::STATIC
,
18385 0, cu
->language
, objfile
);
18387 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18391 struct partial_die_info
*part_die
18392 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18394 /* We'll save this DIE so link it in. */
18395 part_die
->die_parent
= parent_die
;
18396 part_die
->die_sibling
= NULL
;
18397 part_die
->die_child
= NULL
;
18399 if (last_die
&& last_die
== parent_die
)
18400 last_die
->die_child
= part_die
;
18402 last_die
->die_sibling
= part_die
;
18404 last_die
= part_die
;
18406 if (first_die
== NULL
)
18407 first_die
= part_die
;
18409 /* Maybe add the DIE to the hash table. Not all DIEs that we
18410 find interesting need to be in the hash table, because we
18411 also have the parent/sibling/child chains; only those that we
18412 might refer to by offset later during partial symbol reading.
18414 For now this means things that might have be the target of a
18415 DW_AT_specification, DW_AT_abstract_origin, or
18416 DW_AT_extension. DW_AT_extension will refer only to
18417 namespaces; DW_AT_abstract_origin refers to functions (and
18418 many things under the function DIE, but we do not recurse
18419 into function DIEs during partial symbol reading) and
18420 possibly variables as well; DW_AT_specification refers to
18421 declarations. Declarations ought to have the DW_AT_declaration
18422 flag. It happens that GCC forgets to put it in sometimes, but
18423 only for functions, not for types.
18425 Adding more things than necessary to the hash table is harmless
18426 except for the performance cost. Adding too few will result in
18427 wasted time in find_partial_die, when we reread the compilation
18428 unit with load_all_dies set. */
18431 || abbrev
->tag
== DW_TAG_constant
18432 || abbrev
->tag
== DW_TAG_subprogram
18433 || abbrev
->tag
== DW_TAG_variable
18434 || abbrev
->tag
== DW_TAG_namespace
18435 || part_die
->is_declaration
)
18439 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18440 to_underlying (part_die
->sect_off
),
18445 /* For some DIEs we want to follow their children (if any). For C
18446 we have no reason to follow the children of structures; for other
18447 languages we have to, so that we can get at method physnames
18448 to infer fully qualified class names, for DW_AT_specification,
18449 and for C++ template arguments. For C++, we also look one level
18450 inside functions to find template arguments (if the name of the
18451 function does not already contain the template arguments).
18453 For Ada and Fortran, we need to scan the children of subprograms
18454 and lexical blocks as well because these languages allow the
18455 definition of nested entities that could be interesting for the
18456 debugger, such as nested subprograms for instance. */
18457 if (last_die
->has_children
18459 || last_die
->tag
== DW_TAG_namespace
18460 || last_die
->tag
== DW_TAG_module
18461 || last_die
->tag
== DW_TAG_enumeration_type
18462 || (cu
->language
== language_cplus
18463 && last_die
->tag
== DW_TAG_subprogram
18464 && (last_die
->name
== NULL
18465 || strchr (last_die
->name
, '<') == NULL
))
18466 || (cu
->language
!= language_c
18467 && (last_die
->tag
== DW_TAG_class_type
18468 || last_die
->tag
== DW_TAG_interface_type
18469 || last_die
->tag
== DW_TAG_structure_type
18470 || last_die
->tag
== DW_TAG_union_type
))
18471 || ((cu
->language
== language_ada
18472 || cu
->language
== language_fortran
)
18473 && (last_die
->tag
== DW_TAG_subprogram
18474 || last_die
->tag
== DW_TAG_lexical_block
))))
18477 parent_die
= last_die
;
18481 /* Otherwise we skip to the next sibling, if any. */
18482 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18484 /* Back to the top, do it again. */
18488 partial_die_info::partial_die_info (sect_offset sect_off_
,
18489 struct abbrev_info
*abbrev
)
18490 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18494 /* Read a minimal amount of information into the minimal die structure.
18495 INFO_PTR should point just after the initial uleb128 of a DIE. */
18498 partial_die_info::read (const struct die_reader_specs
*reader
,
18499 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18501 struct dwarf2_cu
*cu
= reader
->cu
;
18502 struct dwarf2_per_objfile
*dwarf2_per_objfile
18503 = cu
->per_cu
->dwarf2_per_objfile
;
18505 int has_low_pc_attr
= 0;
18506 int has_high_pc_attr
= 0;
18507 int high_pc_relative
= 0;
18509 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18510 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18512 bool need_reprocess
;
18513 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18514 info_ptr
, &need_reprocess
);
18515 /* String and address offsets that need to do the reprocessing have
18516 already been read at this point, so there is no need to wait until
18517 the loop terminates to do the reprocessing. */
18518 if (need_reprocess
)
18519 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18520 attribute
&attr
= attr_vec
[i
];
18521 /* Store the data if it is of an attribute we want to keep in a
18522 partial symbol table. */
18528 case DW_TAG_compile_unit
:
18529 case DW_TAG_partial_unit
:
18530 case DW_TAG_type_unit
:
18531 /* Compilation units have a DW_AT_name that is a filename, not
18532 a source language identifier. */
18533 case DW_TAG_enumeration_type
:
18534 case DW_TAG_enumerator
:
18535 /* These tags always have simple identifiers already; no need
18536 to canonicalize them. */
18537 name
= DW_STRING (&attr
);
18541 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18544 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18545 &objfile
->per_bfd
->storage_obstack
);
18550 case DW_AT_linkage_name
:
18551 case DW_AT_MIPS_linkage_name
:
18552 /* Note that both forms of linkage name might appear. We
18553 assume they will be the same, and we only store the last
18555 linkage_name
= DW_STRING (&attr
);
18558 has_low_pc_attr
= 1;
18559 lowpc
= attr_value_as_address (&attr
);
18561 case DW_AT_high_pc
:
18562 has_high_pc_attr
= 1;
18563 highpc
= attr_value_as_address (&attr
);
18564 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18565 high_pc_relative
= 1;
18567 case DW_AT_location
:
18568 /* Support the .debug_loc offsets. */
18569 if (attr_form_is_block (&attr
))
18571 d
.locdesc
= DW_BLOCK (&attr
);
18573 else if (attr_form_is_section_offset (&attr
))
18575 dwarf2_complex_location_expr_complaint ();
18579 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18580 "partial symbol information");
18583 case DW_AT_external
:
18584 is_external
= DW_UNSND (&attr
);
18586 case DW_AT_declaration
:
18587 is_declaration
= DW_UNSND (&attr
);
18592 case DW_AT_abstract_origin
:
18593 case DW_AT_specification
:
18594 case DW_AT_extension
:
18595 has_specification
= 1;
18596 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18597 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18598 || cu
->per_cu
->is_dwz
);
18600 case DW_AT_sibling
:
18601 /* Ignore absolute siblings, they might point outside of
18602 the current compile unit. */
18603 if (attr
.form
== DW_FORM_ref_addr
)
18604 complaint (_("ignoring absolute DW_AT_sibling"));
18607 const gdb_byte
*buffer
= reader
->buffer
;
18608 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18609 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18611 if (sibling_ptr
< info_ptr
)
18612 complaint (_("DW_AT_sibling points backwards"));
18613 else if (sibling_ptr
> reader
->buffer_end
)
18614 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18616 sibling
= sibling_ptr
;
18619 case DW_AT_byte_size
:
18622 case DW_AT_const_value
:
18623 has_const_value
= 1;
18625 case DW_AT_calling_convention
:
18626 /* DWARF doesn't provide a way to identify a program's source-level
18627 entry point. DW_AT_calling_convention attributes are only meant
18628 to describe functions' calling conventions.
18630 However, because it's a necessary piece of information in
18631 Fortran, and before DWARF 4 DW_CC_program was the only
18632 piece of debugging information whose definition refers to
18633 a 'main program' at all, several compilers marked Fortran
18634 main programs with DW_CC_program --- even when those
18635 functions use the standard calling conventions.
18637 Although DWARF now specifies a way to provide this
18638 information, we support this practice for backward
18640 if (DW_UNSND (&attr
) == DW_CC_program
18641 && cu
->language
== language_fortran
)
18642 main_subprogram
= 1;
18645 if (DW_UNSND (&attr
) == DW_INL_inlined
18646 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18647 may_be_inlined
= 1;
18651 if (tag
== DW_TAG_imported_unit
)
18653 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18654 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18655 || cu
->per_cu
->is_dwz
);
18659 case DW_AT_main_subprogram
:
18660 main_subprogram
= DW_UNSND (&attr
);
18665 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18666 but that requires a full DIE, so instead we just
18668 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18669 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18670 + (need_ranges_base
18674 /* Value of the DW_AT_ranges attribute is the offset in the
18675 .debug_ranges section. */
18676 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18687 /* For Ada, if both the name and the linkage name appear, we prefer
18688 the latter. This lets "catch exception" work better, regardless
18689 of the order in which the name and linkage name were emitted.
18690 Really, though, this is just a workaround for the fact that gdb
18691 doesn't store both the name and the linkage name. */
18692 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18693 name
= linkage_name
;
18695 if (high_pc_relative
)
18698 if (has_low_pc_attr
&& has_high_pc_attr
)
18700 /* When using the GNU linker, .gnu.linkonce. sections are used to
18701 eliminate duplicate copies of functions and vtables and such.
18702 The linker will arbitrarily choose one and discard the others.
18703 The AT_*_pc values for such functions refer to local labels in
18704 these sections. If the section from that file was discarded, the
18705 labels are not in the output, so the relocs get a value of 0.
18706 If this is a discarded function, mark the pc bounds as invalid,
18707 so that GDB will ignore it. */
18708 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18710 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18711 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18713 complaint (_("DW_AT_low_pc %s is zero "
18714 "for DIE at %s [in module %s]"),
18715 paddress (gdbarch
, lowpc
),
18716 sect_offset_str (sect_off
),
18717 objfile_name (objfile
));
18719 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18720 else if (lowpc
>= highpc
)
18722 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18723 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18725 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18726 "for DIE at %s [in module %s]"),
18727 paddress (gdbarch
, lowpc
),
18728 paddress (gdbarch
, highpc
),
18729 sect_offset_str (sect_off
),
18730 objfile_name (objfile
));
18739 /* Find a cached partial DIE at OFFSET in CU. */
18741 struct partial_die_info
*
18742 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18744 struct partial_die_info
*lookup_die
= NULL
;
18745 struct partial_die_info
part_die (sect_off
);
18747 lookup_die
= ((struct partial_die_info
*)
18748 htab_find_with_hash (partial_dies
, &part_die
,
18749 to_underlying (sect_off
)));
18754 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18755 except in the case of .debug_types DIEs which do not reference
18756 outside their CU (they do however referencing other types via
18757 DW_FORM_ref_sig8). */
18759 static const struct cu_partial_die_info
18760 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18762 struct dwarf2_per_objfile
*dwarf2_per_objfile
18763 = cu
->per_cu
->dwarf2_per_objfile
;
18764 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18765 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18766 struct partial_die_info
*pd
= NULL
;
18768 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18769 && offset_in_cu_p (&cu
->header
, sect_off
))
18771 pd
= cu
->find_partial_die (sect_off
);
18774 /* We missed recording what we needed.
18775 Load all dies and try again. */
18776 per_cu
= cu
->per_cu
;
18780 /* TUs don't reference other CUs/TUs (except via type signatures). */
18781 if (cu
->per_cu
->is_debug_types
)
18783 error (_("Dwarf Error: Type Unit at offset %s contains"
18784 " external reference to offset %s [in module %s].\n"),
18785 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18786 bfd_get_filename (objfile
->obfd
));
18788 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18789 dwarf2_per_objfile
);
18791 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18792 load_partial_comp_unit (per_cu
);
18794 per_cu
->cu
->last_used
= 0;
18795 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18798 /* If we didn't find it, and not all dies have been loaded,
18799 load them all and try again. */
18801 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18803 per_cu
->load_all_dies
= 1;
18805 /* This is nasty. When we reread the DIEs, somewhere up the call chain
18806 THIS_CU->cu may already be in use. So we can't just free it and
18807 replace its DIEs with the ones we read in. Instead, we leave those
18808 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
18809 and clobber THIS_CU->cu->partial_dies with the hash table for the new
18811 load_partial_comp_unit (per_cu
);
18813 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18817 internal_error (__FILE__
, __LINE__
,
18818 _("could not find partial DIE %s "
18819 "in cache [from module %s]\n"),
18820 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
18821 return { per_cu
->cu
, pd
};
18824 /* See if we can figure out if the class lives in a namespace. We do
18825 this by looking for a member function; its demangled name will
18826 contain namespace info, if there is any. */
18829 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
18830 struct dwarf2_cu
*cu
)
18832 /* NOTE: carlton/2003-10-07: Getting the info this way changes
18833 what template types look like, because the demangler
18834 frequently doesn't give the same name as the debug info. We
18835 could fix this by only using the demangled name to get the
18836 prefix (but see comment in read_structure_type). */
18838 struct partial_die_info
*real_pdi
;
18839 struct partial_die_info
*child_pdi
;
18841 /* If this DIE (this DIE's specification, if any) has a parent, then
18842 we should not do this. We'll prepend the parent's fully qualified
18843 name when we create the partial symbol. */
18845 real_pdi
= struct_pdi
;
18846 while (real_pdi
->has_specification
)
18848 auto res
= find_partial_die (real_pdi
->spec_offset
,
18849 real_pdi
->spec_is_dwz
, cu
);
18850 real_pdi
= res
.pdi
;
18854 if (real_pdi
->die_parent
!= NULL
)
18857 for (child_pdi
= struct_pdi
->die_child
;
18859 child_pdi
= child_pdi
->die_sibling
)
18861 if (child_pdi
->tag
== DW_TAG_subprogram
18862 && child_pdi
->linkage_name
!= NULL
)
18864 gdb::unique_xmalloc_ptr
<char> actual_class_name
18865 (language_class_name_from_physname (cu
->language_defn
,
18866 child_pdi
->linkage_name
));
18867 if (actual_class_name
!= NULL
)
18869 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18871 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
18872 actual_class_name
.get ());
18880 partial_die_info::fixup (struct dwarf2_cu
*cu
)
18882 /* Once we've fixed up a die, there's no point in doing so again.
18883 This also avoids a memory leak if we were to call
18884 guess_partial_die_structure_name multiple times. */
18888 /* If we found a reference attribute and the DIE has no name, try
18889 to find a name in the referred to DIE. */
18891 if (name
== NULL
&& has_specification
)
18893 struct partial_die_info
*spec_die
;
18895 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
18896 spec_die
= res
.pdi
;
18899 spec_die
->fixup (cu
);
18901 if (spec_die
->name
)
18903 name
= spec_die
->name
;
18905 /* Copy DW_AT_external attribute if it is set. */
18906 if (spec_die
->is_external
)
18907 is_external
= spec_die
->is_external
;
18911 /* Set default names for some unnamed DIEs. */
18913 if (name
== NULL
&& tag
== DW_TAG_namespace
)
18914 name
= CP_ANONYMOUS_NAMESPACE_STR
;
18916 /* If there is no parent die to provide a namespace, and there are
18917 children, see if we can determine the namespace from their linkage
18919 if (cu
->language
== language_cplus
18920 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
18921 && die_parent
== NULL
18923 && (tag
== DW_TAG_class_type
18924 || tag
== DW_TAG_structure_type
18925 || tag
== DW_TAG_union_type
))
18926 guess_partial_die_structure_name (this, cu
);
18928 /* GCC might emit a nameless struct or union that has a linkage
18929 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
18931 && (tag
== DW_TAG_class_type
18932 || tag
== DW_TAG_interface_type
18933 || tag
== DW_TAG_structure_type
18934 || tag
== DW_TAG_union_type
)
18935 && linkage_name
!= NULL
)
18937 gdb::unique_xmalloc_ptr
<char> demangled
18938 (gdb_demangle (linkage_name
, DMGL_TYPES
));
18939 if (demangled
!= nullptr)
18943 /* Strip any leading namespaces/classes, keep only the base name.
18944 DW_AT_name for named DIEs does not contain the prefixes. */
18945 base
= strrchr (demangled
.get (), ':');
18946 if (base
&& base
> demangled
.get () && base
[-1] == ':')
18949 base
= demangled
.get ();
18951 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18952 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
18959 /* Process the attributes that had to be skipped in the first round. These
18960 attributes are the ones that need str_offsets_base or addr_base attributes.
18961 They could not have been processed in the first round, because at the time
18962 the values of str_offsets_base or addr_base may not have been known. */
18963 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
18964 struct attribute
*attr
)
18966 struct dwarf2_cu
*cu
= reader
->cu
;
18967 switch (attr
->form
)
18969 case DW_FORM_addrx
:
18970 case DW_FORM_GNU_addr_index
:
18971 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
18974 case DW_FORM_strx1
:
18975 case DW_FORM_strx2
:
18976 case DW_FORM_strx3
:
18977 case DW_FORM_strx4
:
18978 case DW_FORM_GNU_str_index
:
18980 unsigned int str_index
= DW_UNSND (attr
);
18981 if (reader
->dwo_file
!= NULL
)
18983 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
18984 DW_STRING_IS_CANONICAL (attr
) = 0;
18988 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
18989 DW_STRING_IS_CANONICAL (attr
) = 0;
18994 gdb_assert_not_reached (_("Unexpected DWARF form."));
18998 /* Read an attribute value described by an attribute form. */
19000 static const gdb_byte
*
19001 read_attribute_value (const struct die_reader_specs
*reader
,
19002 struct attribute
*attr
, unsigned form
,
19003 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19004 bool *need_reprocess
)
19006 struct dwarf2_cu
*cu
= reader
->cu
;
19007 struct dwarf2_per_objfile
*dwarf2_per_objfile
19008 = cu
->per_cu
->dwarf2_per_objfile
;
19009 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19010 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19011 bfd
*abfd
= reader
->abfd
;
19012 struct comp_unit_head
*cu_header
= &cu
->header
;
19013 unsigned int bytes_read
;
19014 struct dwarf_block
*blk
;
19015 *need_reprocess
= false;
19017 attr
->form
= (enum dwarf_form
) form
;
19020 case DW_FORM_ref_addr
:
19021 if (cu
->header
.version
== 2)
19022 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19024 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19025 &cu
->header
, &bytes_read
);
19026 info_ptr
+= bytes_read
;
19028 case DW_FORM_GNU_ref_alt
:
19029 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19030 info_ptr
+= bytes_read
;
19033 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19034 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19035 info_ptr
+= bytes_read
;
19037 case DW_FORM_block2
:
19038 blk
= dwarf_alloc_block (cu
);
19039 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19041 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19042 info_ptr
+= blk
->size
;
19043 DW_BLOCK (attr
) = blk
;
19045 case DW_FORM_block4
:
19046 blk
= dwarf_alloc_block (cu
);
19047 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19049 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19050 info_ptr
+= blk
->size
;
19051 DW_BLOCK (attr
) = blk
;
19053 case DW_FORM_data2
:
19054 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19057 case DW_FORM_data4
:
19058 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19061 case DW_FORM_data8
:
19062 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19065 case DW_FORM_data16
:
19066 blk
= dwarf_alloc_block (cu
);
19068 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19070 DW_BLOCK (attr
) = blk
;
19072 case DW_FORM_sec_offset
:
19073 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19074 info_ptr
+= bytes_read
;
19076 case DW_FORM_string
:
19077 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19078 DW_STRING_IS_CANONICAL (attr
) = 0;
19079 info_ptr
+= bytes_read
;
19082 if (!cu
->per_cu
->is_dwz
)
19084 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19085 abfd
, info_ptr
, cu_header
,
19087 DW_STRING_IS_CANONICAL (attr
) = 0;
19088 info_ptr
+= bytes_read
;
19092 case DW_FORM_line_strp
:
19093 if (!cu
->per_cu
->is_dwz
)
19095 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19097 cu_header
, &bytes_read
);
19098 DW_STRING_IS_CANONICAL (attr
) = 0;
19099 info_ptr
+= bytes_read
;
19103 case DW_FORM_GNU_strp_alt
:
19105 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19106 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19109 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19111 DW_STRING_IS_CANONICAL (attr
) = 0;
19112 info_ptr
+= bytes_read
;
19115 case DW_FORM_exprloc
:
19116 case DW_FORM_block
:
19117 blk
= dwarf_alloc_block (cu
);
19118 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19119 info_ptr
+= bytes_read
;
19120 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19121 info_ptr
+= blk
->size
;
19122 DW_BLOCK (attr
) = blk
;
19124 case DW_FORM_block1
:
19125 blk
= dwarf_alloc_block (cu
);
19126 blk
->size
= read_1_byte (abfd
, info_ptr
);
19128 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19129 info_ptr
+= blk
->size
;
19130 DW_BLOCK (attr
) = blk
;
19132 case DW_FORM_data1
:
19133 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19137 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19140 case DW_FORM_flag_present
:
19141 DW_UNSND (attr
) = 1;
19143 case DW_FORM_sdata
:
19144 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19145 info_ptr
+= bytes_read
;
19147 case DW_FORM_udata
:
19148 case DW_FORM_rnglistx
:
19149 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19150 info_ptr
+= bytes_read
;
19153 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19154 + read_1_byte (abfd
, info_ptr
));
19158 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19159 + read_2_bytes (abfd
, info_ptr
));
19163 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19164 + read_4_bytes (abfd
, info_ptr
));
19168 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19169 + read_8_bytes (abfd
, info_ptr
));
19172 case DW_FORM_ref_sig8
:
19173 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19176 case DW_FORM_ref_udata
:
19177 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19178 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19179 info_ptr
+= bytes_read
;
19181 case DW_FORM_indirect
:
19182 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19183 info_ptr
+= bytes_read
;
19184 if (form
== DW_FORM_implicit_const
)
19186 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19187 info_ptr
+= bytes_read
;
19189 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19190 info_ptr
, need_reprocess
);
19192 case DW_FORM_implicit_const
:
19193 DW_SND (attr
) = implicit_const
;
19195 case DW_FORM_addrx
:
19196 case DW_FORM_GNU_addr_index
:
19197 *need_reprocess
= true;
19198 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19199 info_ptr
+= bytes_read
;
19202 case DW_FORM_strx1
:
19203 case DW_FORM_strx2
:
19204 case DW_FORM_strx3
:
19205 case DW_FORM_strx4
:
19206 case DW_FORM_GNU_str_index
:
19208 ULONGEST str_index
;
19209 if (form
== DW_FORM_strx1
)
19211 str_index
= read_1_byte (abfd
, info_ptr
);
19214 else if (form
== DW_FORM_strx2
)
19216 str_index
= read_2_bytes (abfd
, info_ptr
);
19219 else if (form
== DW_FORM_strx3
)
19221 str_index
= read_3_bytes (abfd
, info_ptr
);
19224 else if (form
== DW_FORM_strx4
)
19226 str_index
= read_4_bytes (abfd
, info_ptr
);
19231 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19232 info_ptr
+= bytes_read
;
19234 *need_reprocess
= true;
19235 DW_UNSND (attr
) = str_index
;
19239 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19240 dwarf_form_name (form
),
19241 bfd_get_filename (abfd
));
19245 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19246 attr
->form
= DW_FORM_GNU_ref_alt
;
19248 /* We have seen instances where the compiler tried to emit a byte
19249 size attribute of -1 which ended up being encoded as an unsigned
19250 0xffffffff. Although 0xffffffff is technically a valid size value,
19251 an object of this size seems pretty unlikely so we can relatively
19252 safely treat these cases as if the size attribute was invalid and
19253 treat them as zero by default. */
19254 if (attr
->name
== DW_AT_byte_size
19255 && form
== DW_FORM_data4
19256 && DW_UNSND (attr
) >= 0xffffffff)
19259 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19260 hex_string (DW_UNSND (attr
)));
19261 DW_UNSND (attr
) = 0;
19267 /* Read an attribute described by an abbreviated attribute. */
19269 static const gdb_byte
*
19270 read_attribute (const struct die_reader_specs
*reader
,
19271 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19272 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19274 attr
->name
= abbrev
->name
;
19275 return read_attribute_value (reader
, attr
, abbrev
->form
,
19276 abbrev
->implicit_const
, info_ptr
,
19281 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19282 unsigned int *bytes_read
)
19284 struct comp_unit_head
*cu_header
= &cu
->header
;
19285 CORE_ADDR retval
= 0;
19287 if (cu_header
->signed_addr_p
)
19289 switch (cu_header
->addr_size
)
19292 retval
= bfd_get_signed_16 (abfd
, buf
);
19295 retval
= bfd_get_signed_32 (abfd
, buf
);
19298 retval
= bfd_get_signed_64 (abfd
, buf
);
19301 internal_error (__FILE__
, __LINE__
,
19302 _("read_address: bad switch, signed [in module %s]"),
19303 bfd_get_filename (abfd
));
19308 switch (cu_header
->addr_size
)
19311 retval
= bfd_get_16 (abfd
, buf
);
19314 retval
= bfd_get_32 (abfd
, buf
);
19317 retval
= bfd_get_64 (abfd
, buf
);
19320 internal_error (__FILE__
, __LINE__
,
19321 _("read_address: bad switch, "
19322 "unsigned [in module %s]"),
19323 bfd_get_filename (abfd
));
19327 *bytes_read
= cu_header
->addr_size
;
19331 /* Read the initial length from a section. The (draft) DWARF 3
19332 specification allows the initial length to take up either 4 bytes
19333 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19334 bytes describe the length and all offsets will be 8 bytes in length
19337 An older, non-standard 64-bit format is also handled by this
19338 function. The older format in question stores the initial length
19339 as an 8-byte quantity without an escape value. Lengths greater
19340 than 2^32 aren't very common which means that the initial 4 bytes
19341 is almost always zero. Since a length value of zero doesn't make
19342 sense for the 32-bit format, this initial zero can be considered to
19343 be an escape value which indicates the presence of the older 64-bit
19344 format. As written, the code can't detect (old format) lengths
19345 greater than 4GB. If it becomes necessary to handle lengths
19346 somewhat larger than 4GB, we could allow other small values (such
19347 as the non-sensical values of 1, 2, and 3) to also be used as
19348 escape values indicating the presence of the old format.
19350 The value returned via bytes_read should be used to increment the
19351 relevant pointer after calling read_initial_length().
19353 [ Note: read_initial_length() and read_offset() are based on the
19354 document entitled "DWARF Debugging Information Format", revision
19355 3, draft 8, dated November 19, 2001. This document was obtained
19358 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19360 This document is only a draft and is subject to change. (So beware.)
19362 Details regarding the older, non-standard 64-bit format were
19363 determined empirically by examining 64-bit ELF files produced by
19364 the SGI toolchain on an IRIX 6.5 machine.
19366 - Kevin, July 16, 2002
19370 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19372 LONGEST length
= bfd_get_32 (abfd
, buf
);
19374 if (length
== 0xffffffff)
19376 length
= bfd_get_64 (abfd
, buf
+ 4);
19379 else if (length
== 0)
19381 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19382 length
= bfd_get_64 (abfd
, buf
);
19393 /* Cover function for read_initial_length.
19394 Returns the length of the object at BUF, and stores the size of the
19395 initial length in *BYTES_READ and stores the size that offsets will be in
19397 If the initial length size is not equivalent to that specified in
19398 CU_HEADER then issue a complaint.
19399 This is useful when reading non-comp-unit headers. */
19402 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19403 const struct comp_unit_head
*cu_header
,
19404 unsigned int *bytes_read
,
19405 unsigned int *offset_size
)
19407 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19409 gdb_assert (cu_header
->initial_length_size
== 4
19410 || cu_header
->initial_length_size
== 8
19411 || cu_header
->initial_length_size
== 12);
19413 if (cu_header
->initial_length_size
!= *bytes_read
)
19414 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19416 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19420 /* Read an offset from the data stream. The size of the offset is
19421 given by cu_header->offset_size. */
19424 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19425 const struct comp_unit_head
*cu_header
,
19426 unsigned int *bytes_read
)
19428 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19430 *bytes_read
= cu_header
->offset_size
;
19434 /* Read an offset from the data stream. */
19437 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19439 LONGEST retval
= 0;
19441 switch (offset_size
)
19444 retval
= bfd_get_32 (abfd
, buf
);
19447 retval
= bfd_get_64 (abfd
, buf
);
19450 internal_error (__FILE__
, __LINE__
,
19451 _("read_offset_1: bad switch [in module %s]"),
19452 bfd_get_filename (abfd
));
19458 static const gdb_byte
*
19459 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19461 /* If the size of a host char is 8 bits, we can return a pointer
19462 to the buffer, otherwise we have to copy the data to a buffer
19463 allocated on the temporary obstack. */
19464 gdb_assert (HOST_CHAR_BIT
== 8);
19468 static const char *
19469 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19470 unsigned int *bytes_read_ptr
)
19472 /* If the size of a host char is 8 bits, we can return a pointer
19473 to the string, otherwise we have to copy the string to a buffer
19474 allocated on the temporary obstack. */
19475 gdb_assert (HOST_CHAR_BIT
== 8);
19478 *bytes_read_ptr
= 1;
19481 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19482 return (const char *) buf
;
19485 /* Return pointer to string at section SECT offset STR_OFFSET with error
19486 reporting strings FORM_NAME and SECT_NAME. */
19488 static const char *
19489 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19490 bfd
*abfd
, LONGEST str_offset
,
19491 struct dwarf2_section_info
*sect
,
19492 const char *form_name
,
19493 const char *sect_name
)
19495 sect
->read (objfile
);
19496 if (sect
->buffer
== NULL
)
19497 error (_("%s used without %s section [in module %s]"),
19498 form_name
, sect_name
, bfd_get_filename (abfd
));
19499 if (str_offset
>= sect
->size
)
19500 error (_("%s pointing outside of %s section [in module %s]"),
19501 form_name
, sect_name
, bfd_get_filename (abfd
));
19502 gdb_assert (HOST_CHAR_BIT
== 8);
19503 if (sect
->buffer
[str_offset
] == '\0')
19505 return (const char *) (sect
->buffer
+ str_offset
);
19508 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19510 static const char *
19511 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19512 bfd
*abfd
, LONGEST str_offset
)
19514 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19516 &dwarf2_per_objfile
->str
,
19517 "DW_FORM_strp", ".debug_str");
19520 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19522 static const char *
19523 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19524 bfd
*abfd
, LONGEST str_offset
)
19526 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19528 &dwarf2_per_objfile
->line_str
,
19529 "DW_FORM_line_strp",
19530 ".debug_line_str");
19533 /* Read a string at offset STR_OFFSET in the .debug_str section from
19534 the .dwz file DWZ. Throw an error if the offset is too large. If
19535 the string consists of a single NUL byte, return NULL; otherwise
19536 return a pointer to the string. */
19538 static const char *
19539 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19540 LONGEST str_offset
)
19542 dwz
->str
.read (objfile
);
19544 if (dwz
->str
.buffer
== NULL
)
19545 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19546 "section [in module %s]"),
19547 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19548 if (str_offset
>= dwz
->str
.size
)
19549 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19550 ".debug_str section [in module %s]"),
19551 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19552 gdb_assert (HOST_CHAR_BIT
== 8);
19553 if (dwz
->str
.buffer
[str_offset
] == '\0')
19555 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19558 /* Return pointer to string at .debug_str offset as read from BUF.
19559 BUF is assumed to be in a compilation unit described by CU_HEADER.
19560 Return *BYTES_READ_PTR count of bytes read from BUF. */
19562 static const char *
19563 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19564 const gdb_byte
*buf
,
19565 const struct comp_unit_head
*cu_header
,
19566 unsigned int *bytes_read_ptr
)
19568 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19570 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19573 /* Return pointer to string at .debug_line_str offset as read from BUF.
19574 BUF is assumed to be in a compilation unit described by CU_HEADER.
19575 Return *BYTES_READ_PTR count of bytes read from BUF. */
19577 static const char *
19578 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19579 bfd
*abfd
, const gdb_byte
*buf
,
19580 const struct comp_unit_head
*cu_header
,
19581 unsigned int *bytes_read_ptr
)
19583 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19585 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19589 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19590 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
19591 ADDR_SIZE is the size of addresses from the CU header. */
19594 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19595 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
19598 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19599 bfd
*abfd
= objfile
->obfd
;
19600 const gdb_byte
*info_ptr
;
19601 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
19603 dwarf2_per_objfile
->addr
.read (objfile
);
19604 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19605 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19606 objfile_name (objfile
));
19607 if (addr_base_or_zero
+ addr_index
* addr_size
19608 >= dwarf2_per_objfile
->addr
.size
)
19609 error (_("DW_FORM_addr_index pointing outside of "
19610 ".debug_addr section [in module %s]"),
19611 objfile_name (objfile
));
19612 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19613 + addr_base_or_zero
+ addr_index
* addr_size
);
19614 if (addr_size
== 4)
19615 return bfd_get_32 (abfd
, info_ptr
);
19617 return bfd_get_64 (abfd
, info_ptr
);
19620 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19623 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19625 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19626 cu
->addr_base
, cu
->header
.addr_size
);
19629 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19632 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19633 unsigned int *bytes_read
)
19635 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19636 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19638 return read_addr_index (cu
, addr_index
);
19641 /* Given an index in .debug_addr, fetch the value.
19642 NOTE: This can be called during dwarf expression evaluation,
19643 long after the debug information has been read, and thus per_cu->cu
19644 may no longer exist. */
19647 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19648 unsigned int addr_index
)
19650 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19651 struct dwarf2_cu
*cu
= per_cu
->cu
;
19652 gdb::optional
<ULONGEST
> addr_base
;
19655 /* We need addr_base and addr_size.
19656 If we don't have PER_CU->cu, we have to get it.
19657 Nasty, but the alternative is storing the needed info in PER_CU,
19658 which at this point doesn't seem justified: it's not clear how frequently
19659 it would get used and it would increase the size of every PER_CU.
19660 Entry points like dwarf2_per_cu_addr_size do a similar thing
19661 so we're not in uncharted territory here.
19662 Alas we need to be a bit more complicated as addr_base is contained
19665 We don't need to read the entire CU(/TU).
19666 We just need the header and top level die.
19668 IWBN to use the aging mechanism to let us lazily later discard the CU.
19669 For now we skip this optimization. */
19673 addr_base
= cu
->addr_base
;
19674 addr_size
= cu
->header
.addr_size
;
19678 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
19679 addr_base
= reader
.cu
->addr_base
;
19680 addr_size
= reader
.cu
->header
.addr_size
;
19683 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
19687 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
19688 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
19691 static const char *
19692 read_str_index (struct dwarf2_cu
*cu
,
19693 struct dwarf2_section_info
*str_section
,
19694 struct dwarf2_section_info
*str_offsets_section
,
19695 ULONGEST str_offsets_base
, ULONGEST str_index
)
19697 struct dwarf2_per_objfile
*dwarf2_per_objfile
19698 = cu
->per_cu
->dwarf2_per_objfile
;
19699 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19700 const char *objf_name
= objfile_name (objfile
);
19701 bfd
*abfd
= objfile
->obfd
;
19702 const gdb_byte
*info_ptr
;
19703 ULONGEST str_offset
;
19704 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
19706 str_section
->read (objfile
);
19707 str_offsets_section
->read (objfile
);
19708 if (str_section
->buffer
== NULL
)
19709 error (_("%s used without %s section"
19710 " in CU at offset %s [in module %s]"),
19711 form_name
, str_section
->get_name (),
19712 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19713 if (str_offsets_section
->buffer
== NULL
)
19714 error (_("%s used without %s section"
19715 " in CU at offset %s [in module %s]"),
19716 form_name
, str_section
->get_name (),
19717 sect_offset_str (cu
->header
.sect_off
), objf_name
);
19718 info_ptr
= (str_offsets_section
->buffer
19720 + str_index
* cu
->header
.offset_size
);
19721 if (cu
->header
.offset_size
== 4)
19722 str_offset
= bfd_get_32 (abfd
, info_ptr
);
19724 str_offset
= bfd_get_64 (abfd
, info_ptr
);
19725 if (str_offset
>= str_section
->size
)
19726 error (_("Offset from %s pointing outside of"
19727 " .debug_str.dwo section in CU at offset %s [in module %s]"),
19728 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
19729 return (const char *) (str_section
->buffer
+ str_offset
);
19732 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
19734 static const char *
19735 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
19737 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
19738 ? reader
->cu
->header
.addr_size
: 0;
19739 return read_str_index (reader
->cu
,
19740 &reader
->dwo_file
->sections
.str
,
19741 &reader
->dwo_file
->sections
.str_offsets
,
19742 str_offsets_base
, str_index
);
19745 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
19747 static const char *
19748 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
19750 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19751 const char *objf_name
= objfile_name (objfile
);
19752 static const char form_name
[] = "DW_FORM_GNU_str_index";
19753 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
19755 if (!cu
->str_offsets_base
.has_value ())
19756 error (_("%s used in Fission stub without %s"
19757 " in CU at offset 0x%lx [in module %s]"),
19758 form_name
, str_offsets_attr_name
,
19759 (long) cu
->header
.offset_size
, objf_name
);
19761 return read_str_index (cu
,
19762 &cu
->per_cu
->dwarf2_per_objfile
->str
,
19763 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
19764 *cu
->str_offsets_base
, str_index
);
19767 /* Return the length of an LEB128 number in BUF. */
19770 leb128_size (const gdb_byte
*buf
)
19772 const gdb_byte
*begin
= buf
;
19778 if ((byte
& 128) == 0)
19779 return buf
- begin
;
19784 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
19793 cu
->language
= language_c
;
19796 case DW_LANG_C_plus_plus
:
19797 case DW_LANG_C_plus_plus_11
:
19798 case DW_LANG_C_plus_plus_14
:
19799 cu
->language
= language_cplus
;
19802 cu
->language
= language_d
;
19804 case DW_LANG_Fortran77
:
19805 case DW_LANG_Fortran90
:
19806 case DW_LANG_Fortran95
:
19807 case DW_LANG_Fortran03
:
19808 case DW_LANG_Fortran08
:
19809 cu
->language
= language_fortran
;
19812 cu
->language
= language_go
;
19814 case DW_LANG_Mips_Assembler
:
19815 cu
->language
= language_asm
;
19817 case DW_LANG_Ada83
:
19818 case DW_LANG_Ada95
:
19819 cu
->language
= language_ada
;
19821 case DW_LANG_Modula2
:
19822 cu
->language
= language_m2
;
19824 case DW_LANG_Pascal83
:
19825 cu
->language
= language_pascal
;
19828 cu
->language
= language_objc
;
19831 case DW_LANG_Rust_old
:
19832 cu
->language
= language_rust
;
19834 case DW_LANG_Cobol74
:
19835 case DW_LANG_Cobol85
:
19837 cu
->language
= language_minimal
;
19840 cu
->language_defn
= language_def (cu
->language
);
19843 /* Return the named attribute or NULL if not there. */
19845 static struct attribute
*
19846 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19851 struct attribute
*spec
= NULL
;
19853 for (i
= 0; i
< die
->num_attrs
; ++i
)
19855 if (die
->attrs
[i
].name
== name
)
19856 return &die
->attrs
[i
];
19857 if (die
->attrs
[i
].name
== DW_AT_specification
19858 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
19859 spec
= &die
->attrs
[i
];
19865 die
= follow_die_ref (die
, spec
, &cu
);
19871 /* Return the named attribute or NULL if not there,
19872 but do not follow DW_AT_specification, etc.
19873 This is for use in contexts where we're reading .debug_types dies.
19874 Following DW_AT_specification, DW_AT_abstract_origin will take us
19875 back up the chain, and we want to go down. */
19877 static struct attribute
*
19878 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
19882 for (i
= 0; i
< die
->num_attrs
; ++i
)
19883 if (die
->attrs
[i
].name
== name
)
19884 return &die
->attrs
[i
];
19889 /* Return the string associated with a string-typed attribute, or NULL if it
19890 is either not found or is of an incorrect type. */
19892 static const char *
19893 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
19895 struct attribute
*attr
;
19896 const char *str
= NULL
;
19898 attr
= dwarf2_attr (die
, name
, cu
);
19902 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
19903 || attr
->form
== DW_FORM_string
19904 || attr
->form
== DW_FORM_strx
19905 || attr
->form
== DW_FORM_strx1
19906 || attr
->form
== DW_FORM_strx2
19907 || attr
->form
== DW_FORM_strx3
19908 || attr
->form
== DW_FORM_strx4
19909 || attr
->form
== DW_FORM_GNU_str_index
19910 || attr
->form
== DW_FORM_GNU_strp_alt
)
19911 str
= DW_STRING (attr
);
19913 complaint (_("string type expected for attribute %s for "
19914 "DIE at %s in module %s"),
19915 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
19916 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
19922 /* Return the dwo name or NULL if not present. If present, it is in either
19923 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
19924 static const char *
19925 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
19927 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
19928 if (dwo_name
== nullptr)
19929 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
19933 /* Return non-zero iff the attribute NAME is defined for the given DIE,
19934 and holds a non-zero value. This function should only be used for
19935 DW_FORM_flag or DW_FORM_flag_present attributes. */
19938 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
19940 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
19942 return (attr
&& DW_UNSND (attr
));
19946 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
19948 /* A DIE is a declaration if it has a DW_AT_declaration attribute
19949 which value is non-zero. However, we have to be careful with
19950 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
19951 (via dwarf2_flag_true_p) follows this attribute. So we may
19952 end up accidently finding a declaration attribute that belongs
19953 to a different DIE referenced by the specification attribute,
19954 even though the given DIE does not have a declaration attribute. */
19955 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
19956 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
19959 /* Return the die giving the specification for DIE, if there is
19960 one. *SPEC_CU is the CU containing DIE on input, and the CU
19961 containing the return value on output. If there is no
19962 specification, but there is an abstract origin, that is
19965 static struct die_info
*
19966 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
19968 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
19971 if (spec_attr
== NULL
)
19972 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
19974 if (spec_attr
== NULL
)
19977 return follow_die_ref (die
, spec_attr
, spec_cu
);
19980 /* Stub for free_line_header to match void * callback types. */
19983 free_line_header_voidp (void *arg
)
19985 struct line_header
*lh
= (struct line_header
*) arg
;
19991 line_header::add_include_dir (const char *include_dir
)
19993 if (dwarf_line_debug
>= 2)
19997 new_size
= m_include_dirs
.size ();
19999 new_size
= m_include_dirs
.size () + 1;
20000 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20001 new_size
, include_dir
);
20003 m_include_dirs
.push_back (include_dir
);
20007 line_header::add_file_name (const char *name
,
20009 unsigned int mod_time
,
20010 unsigned int length
)
20012 if (dwarf_line_debug
>= 2)
20016 new_size
= file_names_size ();
20018 new_size
= file_names_size () + 1;
20019 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20022 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20025 /* A convenience function to find the proper .debug_line section for a CU. */
20027 static struct dwarf2_section_info
*
20028 get_debug_line_section (struct dwarf2_cu
*cu
)
20030 struct dwarf2_section_info
*section
;
20031 struct dwarf2_per_objfile
*dwarf2_per_objfile
20032 = cu
->per_cu
->dwarf2_per_objfile
;
20034 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20036 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20037 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20038 else if (cu
->per_cu
->is_dwz
)
20040 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20042 section
= &dwz
->line
;
20045 section
= &dwarf2_per_objfile
->line
;
20050 /* Read directory or file name entry format, starting with byte of
20051 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20052 entries count and the entries themselves in the described entry
20056 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20057 bfd
*abfd
, const gdb_byte
**bufp
,
20058 struct line_header
*lh
,
20059 const struct comp_unit_head
*cu_header
,
20060 void (*callback
) (struct line_header
*lh
,
20063 unsigned int mod_time
,
20064 unsigned int length
))
20066 gdb_byte format_count
, formati
;
20067 ULONGEST data_count
, datai
;
20068 const gdb_byte
*buf
= *bufp
;
20069 const gdb_byte
*format_header_data
;
20070 unsigned int bytes_read
;
20072 format_count
= read_1_byte (abfd
, buf
);
20074 format_header_data
= buf
;
20075 for (formati
= 0; formati
< format_count
; formati
++)
20077 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20079 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20083 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20085 for (datai
= 0; datai
< data_count
; datai
++)
20087 const gdb_byte
*format
= format_header_data
;
20088 struct file_entry fe
;
20090 for (formati
= 0; formati
< format_count
; formati
++)
20092 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20093 format
+= bytes_read
;
20095 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20096 format
+= bytes_read
;
20098 gdb::optional
<const char *> string
;
20099 gdb::optional
<unsigned int> uint
;
20103 case DW_FORM_string
:
20104 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20108 case DW_FORM_line_strp
:
20109 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20116 case DW_FORM_data1
:
20117 uint
.emplace (read_1_byte (abfd
, buf
));
20121 case DW_FORM_data2
:
20122 uint
.emplace (read_2_bytes (abfd
, buf
));
20126 case DW_FORM_data4
:
20127 uint
.emplace (read_4_bytes (abfd
, buf
));
20131 case DW_FORM_data8
:
20132 uint
.emplace (read_8_bytes (abfd
, buf
));
20136 case DW_FORM_data16
:
20137 /* This is used for MD5, but file_entry does not record MD5s. */
20141 case DW_FORM_udata
:
20142 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20146 case DW_FORM_block
:
20147 /* It is valid only for DW_LNCT_timestamp which is ignored by
20152 switch (content_type
)
20155 if (string
.has_value ())
20158 case DW_LNCT_directory_index
:
20159 if (uint
.has_value ())
20160 fe
.d_index
= (dir_index
) *uint
;
20162 case DW_LNCT_timestamp
:
20163 if (uint
.has_value ())
20164 fe
.mod_time
= *uint
;
20167 if (uint
.has_value ())
20173 complaint (_("Unknown format content type %s"),
20174 pulongest (content_type
));
20178 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20184 /* Read the statement program header starting at OFFSET in
20185 .debug_line, or .debug_line.dwo. Return a pointer
20186 to a struct line_header, allocated using xmalloc.
20187 Returns NULL if there is a problem reading the header, e.g., if it
20188 has a version we don't understand.
20190 NOTE: the strings in the include directory and file name tables of
20191 the returned object point into the dwarf line section buffer,
20192 and must not be freed. */
20194 static line_header_up
20195 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20197 const gdb_byte
*line_ptr
;
20198 unsigned int bytes_read
, offset_size
;
20200 const char *cur_dir
, *cur_file
;
20201 struct dwarf2_section_info
*section
;
20203 struct dwarf2_per_objfile
*dwarf2_per_objfile
20204 = cu
->per_cu
->dwarf2_per_objfile
;
20206 section
= get_debug_line_section (cu
);
20207 section
->read (dwarf2_per_objfile
->objfile
);
20208 if (section
->buffer
== NULL
)
20210 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20211 complaint (_("missing .debug_line.dwo section"));
20213 complaint (_("missing .debug_line section"));
20217 /* We can't do this until we know the section is non-empty.
20218 Only then do we know we have such a section. */
20219 abfd
= section
->get_bfd_owner ();
20221 /* Make sure that at least there's room for the total_length field.
20222 That could be 12 bytes long, but we're just going to fudge that. */
20223 if (to_underlying (sect_off
) + 4 >= section
->size
)
20225 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20229 line_header_up
lh (new line_header ());
20231 lh
->sect_off
= sect_off
;
20232 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20234 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20236 /* Read in the header. */
20238 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20239 &bytes_read
, &offset_size
);
20240 line_ptr
+= bytes_read
;
20242 const gdb_byte
*start_here
= line_ptr
;
20244 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20246 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20249 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20250 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20252 if (lh
->version
> 5)
20254 /* This is a version we don't understand. The format could have
20255 changed in ways we don't handle properly so just punt. */
20256 complaint (_("unsupported version in .debug_line section"));
20259 if (lh
->version
>= 5)
20261 gdb_byte segment_selector_size
;
20263 /* Skip address size. */
20264 read_1_byte (abfd
, line_ptr
);
20267 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20269 if (segment_selector_size
!= 0)
20271 complaint (_("unsupported segment selector size %u "
20272 "in .debug_line section"),
20273 segment_selector_size
);
20277 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20278 line_ptr
+= offset_size
;
20279 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20280 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20282 if (lh
->version
>= 4)
20284 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20288 lh
->maximum_ops_per_instruction
= 1;
20290 if (lh
->maximum_ops_per_instruction
== 0)
20292 lh
->maximum_ops_per_instruction
= 1;
20293 complaint (_("invalid maximum_ops_per_instruction "
20294 "in `.debug_line' section"));
20297 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20299 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20301 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20303 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20305 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20307 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20308 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20310 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20314 if (lh
->version
>= 5)
20316 /* Read directory table. */
20317 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20319 [] (struct line_header
*header
, const char *name
,
20320 dir_index d_index
, unsigned int mod_time
,
20321 unsigned int length
)
20323 header
->add_include_dir (name
);
20326 /* Read file name table. */
20327 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20329 [] (struct line_header
*header
, const char *name
,
20330 dir_index d_index
, unsigned int mod_time
,
20331 unsigned int length
)
20333 header
->add_file_name (name
, d_index
, mod_time
, length
);
20338 /* Read directory table. */
20339 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20341 line_ptr
+= bytes_read
;
20342 lh
->add_include_dir (cur_dir
);
20344 line_ptr
+= bytes_read
;
20346 /* Read file name table. */
20347 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20349 unsigned int mod_time
, length
;
20352 line_ptr
+= bytes_read
;
20353 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20354 line_ptr
+= bytes_read
;
20355 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20356 line_ptr
+= bytes_read
;
20357 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20358 line_ptr
+= bytes_read
;
20360 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20362 line_ptr
+= bytes_read
;
20365 if (line_ptr
> (section
->buffer
+ section
->size
))
20366 complaint (_("line number info header doesn't "
20367 "fit in `.debug_line' section"));
20372 /* Subroutine of dwarf_decode_lines to simplify it.
20373 Return the file name of the psymtab for the given file_entry.
20374 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20375 If space for the result is malloc'd, *NAME_HOLDER will be set.
20376 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20378 static const char *
20379 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20380 const dwarf2_psymtab
*pst
,
20381 const char *comp_dir
,
20382 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20384 const char *include_name
= fe
.name
;
20385 const char *include_name_to_compare
= include_name
;
20386 const char *pst_filename
;
20389 const char *dir_name
= fe
.include_dir (lh
);
20391 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20392 if (!IS_ABSOLUTE_PATH (include_name
)
20393 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20395 /* Avoid creating a duplicate psymtab for PST.
20396 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20397 Before we do the comparison, however, we need to account
20398 for DIR_NAME and COMP_DIR.
20399 First prepend dir_name (if non-NULL). If we still don't
20400 have an absolute path prepend comp_dir (if non-NULL).
20401 However, the directory we record in the include-file's
20402 psymtab does not contain COMP_DIR (to match the
20403 corresponding symtab(s)).
20408 bash$ gcc -g ./hello.c
20409 include_name = "hello.c"
20411 DW_AT_comp_dir = comp_dir = "/tmp"
20412 DW_AT_name = "./hello.c"
20416 if (dir_name
!= NULL
)
20418 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20419 include_name
, (char *) NULL
));
20420 include_name
= name_holder
->get ();
20421 include_name_to_compare
= include_name
;
20423 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20425 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20426 include_name
, (char *) NULL
));
20427 include_name_to_compare
= hold_compare
.get ();
20431 pst_filename
= pst
->filename
;
20432 gdb::unique_xmalloc_ptr
<char> copied_name
;
20433 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20435 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20436 pst_filename
, (char *) NULL
));
20437 pst_filename
= copied_name
.get ();
20440 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20444 return include_name
;
20447 /* State machine to track the state of the line number program. */
20449 class lnp_state_machine
20452 /* Initialize a machine state for the start of a line number
20454 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20455 bool record_lines_p
);
20457 file_entry
*current_file ()
20459 /* lh->file_names is 0-based, but the file name numbers in the
20460 statement program are 1-based. */
20461 return m_line_header
->file_name_at (m_file
);
20464 /* Record the line in the state machine. END_SEQUENCE is true if
20465 we're processing the end of a sequence. */
20466 void record_line (bool end_sequence
);
20468 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20469 nop-out rest of the lines in this sequence. */
20470 void check_line_address (struct dwarf2_cu
*cu
,
20471 const gdb_byte
*line_ptr
,
20472 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20474 void handle_set_discriminator (unsigned int discriminator
)
20476 m_discriminator
= discriminator
;
20477 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20480 /* Handle DW_LNE_set_address. */
20481 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20484 address
+= baseaddr
;
20485 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20488 /* Handle DW_LNS_advance_pc. */
20489 void handle_advance_pc (CORE_ADDR adjust
);
20491 /* Handle a special opcode. */
20492 void handle_special_opcode (unsigned char op_code
);
20494 /* Handle DW_LNS_advance_line. */
20495 void handle_advance_line (int line_delta
)
20497 advance_line (line_delta
);
20500 /* Handle DW_LNS_set_file. */
20501 void handle_set_file (file_name_index file
);
20503 /* Handle DW_LNS_negate_stmt. */
20504 void handle_negate_stmt ()
20506 m_is_stmt
= !m_is_stmt
;
20509 /* Handle DW_LNS_const_add_pc. */
20510 void handle_const_add_pc ();
20512 /* Handle DW_LNS_fixed_advance_pc. */
20513 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20515 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20519 /* Handle DW_LNS_copy. */
20520 void handle_copy ()
20522 record_line (false);
20523 m_discriminator
= 0;
20526 /* Handle DW_LNE_end_sequence. */
20527 void handle_end_sequence ()
20529 m_currently_recording_lines
= true;
20533 /* Advance the line by LINE_DELTA. */
20534 void advance_line (int line_delta
)
20536 m_line
+= line_delta
;
20538 if (line_delta
!= 0)
20539 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20542 struct dwarf2_cu
*m_cu
;
20544 gdbarch
*m_gdbarch
;
20546 /* True if we're recording lines.
20547 Otherwise we're building partial symtabs and are just interested in
20548 finding include files mentioned by the line number program. */
20549 bool m_record_lines_p
;
20551 /* The line number header. */
20552 line_header
*m_line_header
;
20554 /* These are part of the standard DWARF line number state machine,
20555 and initialized according to the DWARF spec. */
20557 unsigned char m_op_index
= 0;
20558 /* The line table index of the current file. */
20559 file_name_index m_file
= 1;
20560 unsigned int m_line
= 1;
20562 /* These are initialized in the constructor. */
20564 CORE_ADDR m_address
;
20566 unsigned int m_discriminator
;
20568 /* Additional bits of state we need to track. */
20570 /* The last file that we called dwarf2_start_subfile for.
20571 This is only used for TLLs. */
20572 unsigned int m_last_file
= 0;
20573 /* The last file a line number was recorded for. */
20574 struct subfile
*m_last_subfile
= NULL
;
20576 /* When true, record the lines we decode. */
20577 bool m_currently_recording_lines
= false;
20579 /* The last line number that was recorded, used to coalesce
20580 consecutive entries for the same line. This can happen, for
20581 example, when discriminators are present. PR 17276. */
20582 unsigned int m_last_line
= 0;
20583 bool m_line_has_non_zero_discriminator
= false;
20587 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20589 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20590 / m_line_header
->maximum_ops_per_instruction
)
20591 * m_line_header
->minimum_instruction_length
);
20592 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20593 m_op_index
= ((m_op_index
+ adjust
)
20594 % m_line_header
->maximum_ops_per_instruction
);
20598 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20600 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20601 CORE_ADDR addr_adj
= (((m_op_index
20602 + (adj_opcode
/ m_line_header
->line_range
))
20603 / m_line_header
->maximum_ops_per_instruction
)
20604 * m_line_header
->minimum_instruction_length
);
20605 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20606 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20607 % m_line_header
->maximum_ops_per_instruction
);
20609 int line_delta
= (m_line_header
->line_base
20610 + (adj_opcode
% m_line_header
->line_range
));
20611 advance_line (line_delta
);
20612 record_line (false);
20613 m_discriminator
= 0;
20617 lnp_state_machine::handle_set_file (file_name_index file
)
20621 const file_entry
*fe
= current_file ();
20623 dwarf2_debug_line_missing_file_complaint ();
20624 else if (m_record_lines_p
)
20626 const char *dir
= fe
->include_dir (m_line_header
);
20628 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20629 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20630 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20635 lnp_state_machine::handle_const_add_pc ()
20638 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20641 = (((m_op_index
+ adjust
)
20642 / m_line_header
->maximum_ops_per_instruction
)
20643 * m_line_header
->minimum_instruction_length
);
20645 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20646 m_op_index
= ((m_op_index
+ adjust
)
20647 % m_line_header
->maximum_ops_per_instruction
);
20650 /* Return non-zero if we should add LINE to the line number table.
20651 LINE is the line to add, LAST_LINE is the last line that was added,
20652 LAST_SUBFILE is the subfile for LAST_LINE.
20653 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20654 had a non-zero discriminator.
20656 We have to be careful in the presence of discriminators.
20657 E.g., for this line:
20659 for (i = 0; i < 100000; i++);
20661 clang can emit four line number entries for that one line,
20662 each with a different discriminator.
20663 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20665 However, we want gdb to coalesce all four entries into one.
20666 Otherwise the user could stepi into the middle of the line and
20667 gdb would get confused about whether the pc really was in the
20668 middle of the line.
20670 Things are further complicated by the fact that two consecutive
20671 line number entries for the same line is a heuristic used by gcc
20672 to denote the end of the prologue. So we can't just discard duplicate
20673 entries, we have to be selective about it. The heuristic we use is
20674 that we only collapse consecutive entries for the same line if at least
20675 one of those entries has a non-zero discriminator. PR 17276.
20677 Note: Addresses in the line number state machine can never go backwards
20678 within one sequence, thus this coalescing is ok. */
20681 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20682 unsigned int line
, unsigned int last_line
,
20683 int line_has_non_zero_discriminator
,
20684 struct subfile
*last_subfile
)
20686 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20688 if (line
!= last_line
)
20690 /* Same line for the same file that we've seen already.
20691 As a last check, for pr 17276, only record the line if the line
20692 has never had a non-zero discriminator. */
20693 if (!line_has_non_zero_discriminator
)
20698 /* Use the CU's builder to record line number LINE beginning at
20699 address ADDRESS in the line table of subfile SUBFILE. */
20702 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20703 unsigned int line
, CORE_ADDR address
,
20704 struct dwarf2_cu
*cu
)
20706 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20708 if (dwarf_line_debug
)
20710 fprintf_unfiltered (gdb_stdlog
,
20711 "Recording line %u, file %s, address %s\n",
20712 line
, lbasename (subfile
->name
),
20713 paddress (gdbarch
, address
));
20717 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20720 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20721 Mark the end of a set of line number records.
20722 The arguments are the same as for dwarf_record_line_1.
20723 If SUBFILE is NULL the request is ignored. */
20726 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20727 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20729 if (subfile
== NULL
)
20732 if (dwarf_line_debug
)
20734 fprintf_unfiltered (gdb_stdlog
,
20735 "Finishing current line, file %s, address %s\n",
20736 lbasename (subfile
->name
),
20737 paddress (gdbarch
, address
));
20740 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
20744 lnp_state_machine::record_line (bool end_sequence
)
20746 if (dwarf_line_debug
)
20748 fprintf_unfiltered (gdb_stdlog
,
20749 "Processing actual line %u: file %u,"
20750 " address %s, is_stmt %u, discrim %u%s\n",
20752 paddress (m_gdbarch
, m_address
),
20753 m_is_stmt
, m_discriminator
,
20754 (end_sequence
? "\t(end sequence)" : ""));
20757 file_entry
*fe
= current_file ();
20760 dwarf2_debug_line_missing_file_complaint ();
20761 /* For now we ignore lines not starting on an instruction boundary.
20762 But not when processing end_sequence for compatibility with the
20763 previous version of the code. */
20764 else if (m_op_index
== 0 || end_sequence
)
20766 fe
->included_p
= 1;
20767 if (m_record_lines_p
20768 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
20770 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
20773 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
20774 m_currently_recording_lines
? m_cu
: nullptr);
20779 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
20780 m_line_has_non_zero_discriminator
,
20783 buildsym_compunit
*builder
= m_cu
->get_builder ();
20784 dwarf_record_line_1 (m_gdbarch
,
20785 builder
->get_current_subfile (),
20787 m_currently_recording_lines
? m_cu
: nullptr);
20789 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20790 m_last_line
= m_line
;
20796 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
20797 line_header
*lh
, bool record_lines_p
)
20801 m_record_lines_p
= record_lines_p
;
20802 m_line_header
= lh
;
20804 m_currently_recording_lines
= true;
20806 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
20807 was a line entry for it so that the backend has a chance to adjust it
20808 and also record it in case it needs it. This is currently used by MIPS
20809 code, cf. `mips_adjust_dwarf2_line'. */
20810 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
20811 m_is_stmt
= lh
->default_is_stmt
;
20812 m_discriminator
= 0;
20816 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
20817 const gdb_byte
*line_ptr
,
20818 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
20820 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
20821 the pc range of the CU. However, we restrict the test to only ADDRESS
20822 values of zero to preserve GDB's previous behaviour which is to handle
20823 the specific case of a function being GC'd by the linker. */
20825 if (address
== 0 && address
< unrelocated_lowpc
)
20827 /* This line table is for a function which has been
20828 GCd by the linker. Ignore it. PR gdb/12528 */
20830 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20831 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
20833 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
20834 line_offset
, objfile_name (objfile
));
20835 m_currently_recording_lines
= false;
20836 /* Note: m_currently_recording_lines is left as false until we see
20837 DW_LNE_end_sequence. */
20841 /* Subroutine of dwarf_decode_lines to simplify it.
20842 Process the line number information in LH.
20843 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
20844 program in order to set included_p for every referenced header. */
20847 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
20848 const int decode_for_pst_p
, CORE_ADDR lowpc
)
20850 const gdb_byte
*line_ptr
, *extended_end
;
20851 const gdb_byte
*line_end
;
20852 unsigned int bytes_read
, extended_len
;
20853 unsigned char op_code
, extended_op
;
20854 CORE_ADDR baseaddr
;
20855 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20856 bfd
*abfd
= objfile
->obfd
;
20857 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
20858 /* True if we're recording line info (as opposed to building partial
20859 symtabs and just interested in finding include files mentioned by
20860 the line number program). */
20861 bool record_lines_p
= !decode_for_pst_p
;
20863 baseaddr
= objfile
->text_section_offset ();
20865 line_ptr
= lh
->statement_program_start
;
20866 line_end
= lh
->statement_program_end
;
20868 /* Read the statement sequences until there's nothing left. */
20869 while (line_ptr
< line_end
)
20871 /* The DWARF line number program state machine. Reset the state
20872 machine at the start of each sequence. */
20873 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
20874 bool end_sequence
= false;
20876 if (record_lines_p
)
20878 /* Start a subfile for the current file of the state
20880 const file_entry
*fe
= state_machine
.current_file ();
20883 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
20886 /* Decode the table. */
20887 while (line_ptr
< line_end
&& !end_sequence
)
20889 op_code
= read_1_byte (abfd
, line_ptr
);
20892 if (op_code
>= lh
->opcode_base
)
20894 /* Special opcode. */
20895 state_machine
.handle_special_opcode (op_code
);
20897 else switch (op_code
)
20899 case DW_LNS_extended_op
:
20900 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
20902 line_ptr
+= bytes_read
;
20903 extended_end
= line_ptr
+ extended_len
;
20904 extended_op
= read_1_byte (abfd
, line_ptr
);
20906 switch (extended_op
)
20908 case DW_LNE_end_sequence
:
20909 state_machine
.handle_end_sequence ();
20910 end_sequence
= true;
20912 case DW_LNE_set_address
:
20915 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
20916 line_ptr
+= bytes_read
;
20918 state_machine
.check_line_address (cu
, line_ptr
,
20919 lowpc
- baseaddr
, address
);
20920 state_machine
.handle_set_address (baseaddr
, address
);
20923 case DW_LNE_define_file
:
20925 const char *cur_file
;
20926 unsigned int mod_time
, length
;
20929 cur_file
= read_direct_string (abfd
, line_ptr
,
20931 line_ptr
+= bytes_read
;
20932 dindex
= (dir_index
)
20933 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20934 line_ptr
+= bytes_read
;
20936 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20937 line_ptr
+= bytes_read
;
20939 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20940 line_ptr
+= bytes_read
;
20941 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
20944 case DW_LNE_set_discriminator
:
20946 /* The discriminator is not interesting to the
20947 debugger; just ignore it. We still need to
20948 check its value though:
20949 if there are consecutive entries for the same
20950 (non-prologue) line we want to coalesce them.
20953 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20954 line_ptr
+= bytes_read
;
20956 state_machine
.handle_set_discriminator (discr
);
20960 complaint (_("mangled .debug_line section"));
20963 /* Make sure that we parsed the extended op correctly. If e.g.
20964 we expected a different address size than the producer used,
20965 we may have read the wrong number of bytes. */
20966 if (line_ptr
!= extended_end
)
20968 complaint (_("mangled .debug_line section"));
20973 state_machine
.handle_copy ();
20975 case DW_LNS_advance_pc
:
20978 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20979 line_ptr
+= bytes_read
;
20981 state_machine
.handle_advance_pc (adjust
);
20984 case DW_LNS_advance_line
:
20987 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
20988 line_ptr
+= bytes_read
;
20990 state_machine
.handle_advance_line (line_delta
);
20993 case DW_LNS_set_file
:
20995 file_name_index file
20996 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
20998 line_ptr
+= bytes_read
;
21000 state_machine
.handle_set_file (file
);
21003 case DW_LNS_set_column
:
21004 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21005 line_ptr
+= bytes_read
;
21007 case DW_LNS_negate_stmt
:
21008 state_machine
.handle_negate_stmt ();
21010 case DW_LNS_set_basic_block
:
21012 /* Add to the address register of the state machine the
21013 address increment value corresponding to special opcode
21014 255. I.e., this value is scaled by the minimum
21015 instruction length since special opcode 255 would have
21016 scaled the increment. */
21017 case DW_LNS_const_add_pc
:
21018 state_machine
.handle_const_add_pc ();
21020 case DW_LNS_fixed_advance_pc
:
21022 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21025 state_machine
.handle_fixed_advance_pc (addr_adj
);
21030 /* Unknown standard opcode, ignore it. */
21033 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21035 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21036 line_ptr
+= bytes_read
;
21043 dwarf2_debug_line_missing_end_sequence_complaint ();
21045 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21046 in which case we still finish recording the last line). */
21047 state_machine
.record_line (true);
21051 /* Decode the Line Number Program (LNP) for the given line_header
21052 structure and CU. The actual information extracted and the type
21053 of structures created from the LNP depends on the value of PST.
21055 1. If PST is NULL, then this procedure uses the data from the program
21056 to create all necessary symbol tables, and their linetables.
21058 2. If PST is not NULL, this procedure reads the program to determine
21059 the list of files included by the unit represented by PST, and
21060 builds all the associated partial symbol tables.
21062 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21063 It is used for relative paths in the line table.
21064 NOTE: When processing partial symtabs (pst != NULL),
21065 comp_dir == pst->dirname.
21067 NOTE: It is important that psymtabs have the same file name (via strcmp)
21068 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21069 symtab we don't use it in the name of the psymtabs we create.
21070 E.g. expand_line_sal requires this when finding psymtabs to expand.
21071 A good testcase for this is mb-inline.exp.
21073 LOWPC is the lowest address in CU (or 0 if not known).
21075 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21076 for its PC<->lines mapping information. Otherwise only the filename
21077 table is read in. */
21080 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21081 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21082 CORE_ADDR lowpc
, int decode_mapping
)
21084 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21085 const int decode_for_pst_p
= (pst
!= NULL
);
21087 if (decode_mapping
)
21088 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21090 if (decode_for_pst_p
)
21092 /* Now that we're done scanning the Line Header Program, we can
21093 create the psymtab of each included file. */
21094 for (auto &file_entry
: lh
->file_names ())
21095 if (file_entry
.included_p
== 1)
21097 gdb::unique_xmalloc_ptr
<char> name_holder
;
21098 const char *include_name
=
21099 psymtab_include_file_name (lh
, file_entry
, pst
,
21100 comp_dir
, &name_holder
);
21101 if (include_name
!= NULL
)
21102 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21107 /* Make sure a symtab is created for every file, even files
21108 which contain only variables (i.e. no code with associated
21110 buildsym_compunit
*builder
= cu
->get_builder ();
21111 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21113 for (auto &fe
: lh
->file_names ())
21115 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21116 if (builder
->get_current_subfile ()->symtab
== NULL
)
21118 builder
->get_current_subfile ()->symtab
21119 = allocate_symtab (cust
,
21120 builder
->get_current_subfile ()->name
);
21122 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21127 /* Start a subfile for DWARF. FILENAME is the name of the file and
21128 DIRNAME the name of the source directory which contains FILENAME
21129 or NULL if not known.
21130 This routine tries to keep line numbers from identical absolute and
21131 relative file names in a common subfile.
21133 Using the `list' example from the GDB testsuite, which resides in
21134 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21135 of /srcdir/list0.c yields the following debugging information for list0.c:
21137 DW_AT_name: /srcdir/list0.c
21138 DW_AT_comp_dir: /compdir
21139 files.files[0].name: list0.h
21140 files.files[0].dir: /srcdir
21141 files.files[1].name: list0.c
21142 files.files[1].dir: /srcdir
21144 The line number information for list0.c has to end up in a single
21145 subfile, so that `break /srcdir/list0.c:1' works as expected.
21146 start_subfile will ensure that this happens provided that we pass the
21147 concatenation of files.files[1].dir and files.files[1].name as the
21151 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21152 const char *dirname
)
21154 gdb::unique_xmalloc_ptr
<char> copy
;
21156 /* In order not to lose the line information directory,
21157 we concatenate it to the filename when it makes sense.
21158 Note that the Dwarf3 standard says (speaking of filenames in line
21159 information): ``The directory index is ignored for file names
21160 that represent full path names''. Thus ignoring dirname in the
21161 `else' branch below isn't an issue. */
21163 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21165 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21166 filename
= copy
.get ();
21169 cu
->get_builder ()->start_subfile (filename
);
21172 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21173 buildsym_compunit constructor. */
21175 struct compunit_symtab
*
21176 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21179 gdb_assert (m_builder
== nullptr);
21181 m_builder
.reset (new struct buildsym_compunit
21182 (per_cu
->dwarf2_per_objfile
->objfile
,
21183 name
, comp_dir
, language
, low_pc
));
21185 list_in_scope
= get_builder ()->get_file_symbols ();
21187 get_builder ()->record_debugformat ("DWARF 2");
21188 get_builder ()->record_producer (producer
);
21190 processing_has_namespace_info
= false;
21192 return get_builder ()->get_compunit_symtab ();
21196 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21197 struct dwarf2_cu
*cu
)
21199 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21200 struct comp_unit_head
*cu_header
= &cu
->header
;
21202 /* NOTE drow/2003-01-30: There used to be a comment and some special
21203 code here to turn a symbol with DW_AT_external and a
21204 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21205 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21206 with some versions of binutils) where shared libraries could have
21207 relocations against symbols in their debug information - the
21208 minimal symbol would have the right address, but the debug info
21209 would not. It's no longer necessary, because we will explicitly
21210 apply relocations when we read in the debug information now. */
21212 /* A DW_AT_location attribute with no contents indicates that a
21213 variable has been optimized away. */
21214 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21216 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21220 /* Handle one degenerate form of location expression specially, to
21221 preserve GDB's previous behavior when section offsets are
21222 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21223 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21225 if (attr_form_is_block (attr
)
21226 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21227 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21228 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21229 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21230 && (DW_BLOCK (attr
)->size
21231 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21233 unsigned int dummy
;
21235 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21236 SET_SYMBOL_VALUE_ADDRESS (sym
,
21237 read_address (objfile
->obfd
,
21238 DW_BLOCK (attr
)->data
+ 1,
21241 SET_SYMBOL_VALUE_ADDRESS
21242 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21244 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21245 fixup_symbol_section (sym
, objfile
);
21246 SET_SYMBOL_VALUE_ADDRESS
21248 SYMBOL_VALUE_ADDRESS (sym
)
21249 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21253 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21254 expression evaluator, and use LOC_COMPUTED only when necessary
21255 (i.e. when the value of a register or memory location is
21256 referenced, or a thread-local block, etc.). Then again, it might
21257 not be worthwhile. I'm assuming that it isn't unless performance
21258 or memory numbers show me otherwise. */
21260 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21262 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21263 cu
->has_loclist
= true;
21266 /* Given a pointer to a DWARF information entry, figure out if we need
21267 to make a symbol table entry for it, and if so, create a new entry
21268 and return a pointer to it.
21269 If TYPE is NULL, determine symbol type from the die, otherwise
21270 used the passed type.
21271 If SPACE is not NULL, use it to hold the new symbol. If it is
21272 NULL, allocate a new symbol on the objfile's obstack. */
21274 static struct symbol
*
21275 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21276 struct symbol
*space
)
21278 struct dwarf2_per_objfile
*dwarf2_per_objfile
21279 = cu
->per_cu
->dwarf2_per_objfile
;
21280 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21281 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21282 struct symbol
*sym
= NULL
;
21284 struct attribute
*attr
= NULL
;
21285 struct attribute
*attr2
= NULL
;
21286 CORE_ADDR baseaddr
;
21287 struct pending
**list_to_add
= NULL
;
21289 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21291 baseaddr
= objfile
->text_section_offset ();
21293 name
= dwarf2_name (die
, cu
);
21296 const char *linkagename
;
21297 int suppress_add
= 0;
21302 sym
= allocate_symbol (objfile
);
21303 OBJSTAT (objfile
, n_syms
++);
21305 /* Cache this symbol's name and the name's demangled form (if any). */
21306 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21307 linkagename
= dwarf2_physname (name
, die
, cu
);
21308 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21310 /* Fortran does not have mangling standard and the mangling does differ
21311 between gfortran, iFort etc. */
21312 if (cu
->language
== language_fortran
21313 && symbol_get_demangled_name (sym
) == NULL
)
21314 symbol_set_demangled_name (sym
,
21315 dwarf2_full_name (name
, die
, cu
),
21318 /* Default assumptions.
21319 Use the passed type or decode it from the die. */
21320 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21321 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21323 SYMBOL_TYPE (sym
) = type
;
21325 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21326 attr
= dwarf2_attr (die
,
21327 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21329 if (attr
!= nullptr)
21331 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21334 attr
= dwarf2_attr (die
,
21335 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21337 if (attr
!= nullptr)
21339 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21340 struct file_entry
*fe
;
21342 if (cu
->line_header
!= NULL
)
21343 fe
= cu
->line_header
->file_name_at (file_index
);
21348 complaint (_("file index out of range"));
21350 symbol_set_symtab (sym
, fe
->symtab
);
21356 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21357 if (attr
!= nullptr)
21361 addr
= attr_value_as_address (attr
);
21362 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21363 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21365 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21366 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21367 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21368 add_symbol_to_list (sym
, cu
->list_in_scope
);
21370 case DW_TAG_subprogram
:
21371 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21373 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21374 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21375 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21376 || cu
->language
== language_ada
21377 || cu
->language
== language_fortran
)
21379 /* Subprograms marked external are stored as a global symbol.
21380 Ada and Fortran subprograms, whether marked external or
21381 not, are always stored as a global symbol, because we want
21382 to be able to access them globally. For instance, we want
21383 to be able to break on a nested subprogram without having
21384 to specify the context. */
21385 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21389 list_to_add
= cu
->list_in_scope
;
21392 case DW_TAG_inlined_subroutine
:
21393 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21395 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21396 SYMBOL_INLINED (sym
) = 1;
21397 list_to_add
= cu
->list_in_scope
;
21399 case DW_TAG_template_value_param
:
21401 /* Fall through. */
21402 case DW_TAG_constant
:
21403 case DW_TAG_variable
:
21404 case DW_TAG_member
:
21405 /* Compilation with minimal debug info may result in
21406 variables with missing type entries. Change the
21407 misleading `void' type to something sensible. */
21408 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21409 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21411 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21412 /* In the case of DW_TAG_member, we should only be called for
21413 static const members. */
21414 if (die
->tag
== DW_TAG_member
)
21416 /* dwarf2_add_field uses die_is_declaration,
21417 so we do the same. */
21418 gdb_assert (die_is_declaration (die
, cu
));
21421 if (attr
!= nullptr)
21423 dwarf2_const_value (attr
, sym
, cu
);
21424 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21427 if (attr2
&& (DW_UNSND (attr2
) != 0))
21428 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21430 list_to_add
= cu
->list_in_scope
;
21434 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21435 if (attr
!= nullptr)
21437 var_decode_location (attr
, sym
, cu
);
21438 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21440 /* Fortran explicitly imports any global symbols to the local
21441 scope by DW_TAG_common_block. */
21442 if (cu
->language
== language_fortran
&& die
->parent
21443 && die
->parent
->tag
== DW_TAG_common_block
)
21446 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21447 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21448 && !dwarf2_per_objfile
->has_section_at_zero
)
21450 /* When a static variable is eliminated by the linker,
21451 the corresponding debug information is not stripped
21452 out, but the variable address is set to null;
21453 do not add such variables into symbol table. */
21455 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21457 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21458 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21459 && dwarf2_per_objfile
->can_copy
)
21461 /* A global static variable might be subject to
21462 copy relocation. We first check for a local
21463 minsym, though, because maybe the symbol was
21464 marked hidden, in which case this would not
21466 bound_minimal_symbol found
21467 = (lookup_minimal_symbol_linkage
21468 (sym
->linkage_name (), objfile
));
21469 if (found
.minsym
!= nullptr)
21470 sym
->maybe_copied
= 1;
21473 /* A variable with DW_AT_external is never static,
21474 but it may be block-scoped. */
21476 = ((cu
->list_in_scope
21477 == cu
->get_builder ()->get_file_symbols ())
21478 ? cu
->get_builder ()->get_global_symbols ()
21479 : cu
->list_in_scope
);
21482 list_to_add
= cu
->list_in_scope
;
21486 /* We do not know the address of this symbol.
21487 If it is an external symbol and we have type information
21488 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21489 The address of the variable will then be determined from
21490 the minimal symbol table whenever the variable is
21492 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21494 /* Fortran explicitly imports any global symbols to the local
21495 scope by DW_TAG_common_block. */
21496 if (cu
->language
== language_fortran
&& die
->parent
21497 && die
->parent
->tag
== DW_TAG_common_block
)
21499 /* SYMBOL_CLASS doesn't matter here because
21500 read_common_block is going to reset it. */
21502 list_to_add
= cu
->list_in_scope
;
21504 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21505 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21507 /* A variable with DW_AT_external is never static, but it
21508 may be block-scoped. */
21510 = ((cu
->list_in_scope
21511 == cu
->get_builder ()->get_file_symbols ())
21512 ? cu
->get_builder ()->get_global_symbols ()
21513 : cu
->list_in_scope
);
21515 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21517 else if (!die_is_declaration (die
, cu
))
21519 /* Use the default LOC_OPTIMIZED_OUT class. */
21520 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21522 list_to_add
= cu
->list_in_scope
;
21526 case DW_TAG_formal_parameter
:
21528 /* If we are inside a function, mark this as an argument. If
21529 not, we might be looking at an argument to an inlined function
21530 when we do not have enough information to show inlined frames;
21531 pretend it's a local variable in that case so that the user can
21533 struct context_stack
*curr
21534 = cu
->get_builder ()->get_current_context_stack ();
21535 if (curr
!= nullptr && curr
->name
!= nullptr)
21536 SYMBOL_IS_ARGUMENT (sym
) = 1;
21537 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21538 if (attr
!= nullptr)
21540 var_decode_location (attr
, sym
, cu
);
21542 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21543 if (attr
!= nullptr)
21545 dwarf2_const_value (attr
, sym
, cu
);
21548 list_to_add
= cu
->list_in_scope
;
21551 case DW_TAG_unspecified_parameters
:
21552 /* From varargs functions; gdb doesn't seem to have any
21553 interest in this information, so just ignore it for now.
21556 case DW_TAG_template_type_param
:
21558 /* Fall through. */
21559 case DW_TAG_class_type
:
21560 case DW_TAG_interface_type
:
21561 case DW_TAG_structure_type
:
21562 case DW_TAG_union_type
:
21563 case DW_TAG_set_type
:
21564 case DW_TAG_enumeration_type
:
21565 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21566 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21569 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21570 really ever be static objects: otherwise, if you try
21571 to, say, break of a class's method and you're in a file
21572 which doesn't mention that class, it won't work unless
21573 the check for all static symbols in lookup_symbol_aux
21574 saves you. See the OtherFileClass tests in
21575 gdb.c++/namespace.exp. */
21579 buildsym_compunit
*builder
= cu
->get_builder ();
21581 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21582 && cu
->language
== language_cplus
21583 ? builder
->get_global_symbols ()
21584 : cu
->list_in_scope
);
21586 /* The semantics of C++ state that "struct foo {
21587 ... }" also defines a typedef for "foo". */
21588 if (cu
->language
== language_cplus
21589 || cu
->language
== language_ada
21590 || cu
->language
== language_d
21591 || cu
->language
== language_rust
)
21593 /* The symbol's name is already allocated along
21594 with this objfile, so we don't need to
21595 duplicate it for the type. */
21596 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21597 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
21602 case DW_TAG_typedef
:
21603 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21604 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21605 list_to_add
= cu
->list_in_scope
;
21607 case DW_TAG_base_type
:
21608 case DW_TAG_subrange_type
:
21609 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21610 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21611 list_to_add
= cu
->list_in_scope
;
21613 case DW_TAG_enumerator
:
21614 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21615 if (attr
!= nullptr)
21617 dwarf2_const_value (attr
, sym
, cu
);
21620 /* NOTE: carlton/2003-11-10: See comment above in the
21621 DW_TAG_class_type, etc. block. */
21624 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21625 && cu
->language
== language_cplus
21626 ? cu
->get_builder ()->get_global_symbols ()
21627 : cu
->list_in_scope
);
21630 case DW_TAG_imported_declaration
:
21631 case DW_TAG_namespace
:
21632 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21633 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21635 case DW_TAG_module
:
21636 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21637 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21638 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21640 case DW_TAG_common_block
:
21641 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21642 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21643 add_symbol_to_list (sym
, cu
->list_in_scope
);
21646 /* Not a tag we recognize. Hopefully we aren't processing
21647 trash data, but since we must specifically ignore things
21648 we don't recognize, there is nothing else we should do at
21650 complaint (_("unsupported tag: '%s'"),
21651 dwarf_tag_name (die
->tag
));
21657 sym
->hash_next
= objfile
->template_symbols
;
21658 objfile
->template_symbols
= sym
;
21659 list_to_add
= NULL
;
21662 if (list_to_add
!= NULL
)
21663 add_symbol_to_list (sym
, list_to_add
);
21665 /* For the benefit of old versions of GCC, check for anonymous
21666 namespaces based on the demangled name. */
21667 if (!cu
->processing_has_namespace_info
21668 && cu
->language
== language_cplus
)
21669 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21674 /* Given an attr with a DW_FORM_dataN value in host byte order,
21675 zero-extend it as appropriate for the symbol's type. The DWARF
21676 standard (v4) is not entirely clear about the meaning of using
21677 DW_FORM_dataN for a constant with a signed type, where the type is
21678 wider than the data. The conclusion of a discussion on the DWARF
21679 list was that this is unspecified. We choose to always zero-extend
21680 because that is the interpretation long in use by GCC. */
21683 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21684 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21686 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21687 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21688 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21689 LONGEST l
= DW_UNSND (attr
);
21691 if (bits
< sizeof (*value
) * 8)
21693 l
&= ((LONGEST
) 1 << bits
) - 1;
21696 else if (bits
== sizeof (*value
) * 8)
21700 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21701 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21708 /* Read a constant value from an attribute. Either set *VALUE, or if
21709 the value does not fit in *VALUE, set *BYTES - either already
21710 allocated on the objfile obstack, or newly allocated on OBSTACK,
21711 or, set *BATON, if we translated the constant to a location
21715 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21716 const char *name
, struct obstack
*obstack
,
21717 struct dwarf2_cu
*cu
,
21718 LONGEST
*value
, const gdb_byte
**bytes
,
21719 struct dwarf2_locexpr_baton
**baton
)
21721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21722 struct comp_unit_head
*cu_header
= &cu
->header
;
21723 struct dwarf_block
*blk
;
21724 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21725 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21731 switch (attr
->form
)
21734 case DW_FORM_addrx
:
21735 case DW_FORM_GNU_addr_index
:
21739 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
21740 dwarf2_const_value_length_mismatch_complaint (name
,
21741 cu_header
->addr_size
,
21742 TYPE_LENGTH (type
));
21743 /* Symbols of this form are reasonably rare, so we just
21744 piggyback on the existing location code rather than writing
21745 a new implementation of symbol_computed_ops. */
21746 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
21747 (*baton
)->per_cu
= cu
->per_cu
;
21748 gdb_assert ((*baton
)->per_cu
);
21750 (*baton
)->size
= 2 + cu_header
->addr_size
;
21751 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
21752 (*baton
)->data
= data
;
21754 data
[0] = DW_OP_addr
;
21755 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
21756 byte_order
, DW_ADDR (attr
));
21757 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
21760 case DW_FORM_string
:
21763 case DW_FORM_GNU_str_index
:
21764 case DW_FORM_GNU_strp_alt
:
21765 /* DW_STRING is already allocated on the objfile obstack, point
21767 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
21769 case DW_FORM_block1
:
21770 case DW_FORM_block2
:
21771 case DW_FORM_block4
:
21772 case DW_FORM_block
:
21773 case DW_FORM_exprloc
:
21774 case DW_FORM_data16
:
21775 blk
= DW_BLOCK (attr
);
21776 if (TYPE_LENGTH (type
) != blk
->size
)
21777 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
21778 TYPE_LENGTH (type
));
21779 *bytes
= blk
->data
;
21782 /* The DW_AT_const_value attributes are supposed to carry the
21783 symbol's value "represented as it would be on the target
21784 architecture." By the time we get here, it's already been
21785 converted to host endianness, so we just need to sign- or
21786 zero-extend it as appropriate. */
21787 case DW_FORM_data1
:
21788 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
21790 case DW_FORM_data2
:
21791 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
21793 case DW_FORM_data4
:
21794 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
21796 case DW_FORM_data8
:
21797 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
21800 case DW_FORM_sdata
:
21801 case DW_FORM_implicit_const
:
21802 *value
= DW_SND (attr
);
21805 case DW_FORM_udata
:
21806 *value
= DW_UNSND (attr
);
21810 complaint (_("unsupported const value attribute form: '%s'"),
21811 dwarf_form_name (attr
->form
));
21818 /* Copy constant value from an attribute to a symbol. */
21821 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
21822 struct dwarf2_cu
*cu
)
21824 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21826 const gdb_byte
*bytes
;
21827 struct dwarf2_locexpr_baton
*baton
;
21829 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
21830 sym
->print_name (),
21831 &objfile
->objfile_obstack
, cu
,
21832 &value
, &bytes
, &baton
);
21836 SYMBOL_LOCATION_BATON (sym
) = baton
;
21837 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
21839 else if (bytes
!= NULL
)
21841 SYMBOL_VALUE_BYTES (sym
) = bytes
;
21842 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
21846 SYMBOL_VALUE (sym
) = value
;
21847 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
21851 /* Return the type of the die in question using its DW_AT_type attribute. */
21853 static struct type
*
21854 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21856 struct attribute
*type_attr
;
21858 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
21861 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21862 /* A missing DW_AT_type represents a void type. */
21863 return objfile_type (objfile
)->builtin_void
;
21866 return lookup_die_type (die
, type_attr
, cu
);
21869 /* True iff CU's producer generates GNAT Ada auxiliary information
21870 that allows to find parallel types through that information instead
21871 of having to do expensive parallel lookups by type name. */
21874 need_gnat_info (struct dwarf2_cu
*cu
)
21876 /* Assume that the Ada compiler was GNAT, which always produces
21877 the auxiliary information. */
21878 return (cu
->language
== language_ada
);
21881 /* Return the auxiliary type of the die in question using its
21882 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
21883 attribute is not present. */
21885 static struct type
*
21886 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21888 struct attribute
*type_attr
;
21890 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
21894 return lookup_die_type (die
, type_attr
, cu
);
21897 /* If DIE has a descriptive_type attribute, then set the TYPE's
21898 descriptive type accordingly. */
21901 set_descriptive_type (struct type
*type
, struct die_info
*die
,
21902 struct dwarf2_cu
*cu
)
21904 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
21906 if (descriptive_type
)
21908 ALLOCATE_GNAT_AUX_TYPE (type
);
21909 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
21913 /* Return the containing type of the die in question using its
21914 DW_AT_containing_type attribute. */
21916 static struct type
*
21917 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
21919 struct attribute
*type_attr
;
21920 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21922 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
21924 error (_("Dwarf Error: Problem turning containing type into gdb type "
21925 "[in module %s]"), objfile_name (objfile
));
21927 return lookup_die_type (die
, type_attr
, cu
);
21930 /* Return an error marker type to use for the ill formed type in DIE/CU. */
21932 static struct type
*
21933 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
21935 struct dwarf2_per_objfile
*dwarf2_per_objfile
21936 = cu
->per_cu
->dwarf2_per_objfile
;
21937 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21940 std::string message
21941 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
21942 objfile_name (objfile
),
21943 sect_offset_str (cu
->header
.sect_off
),
21944 sect_offset_str (die
->sect_off
));
21945 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
21947 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
21950 /* Look up the type of DIE in CU using its type attribute ATTR.
21951 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
21952 DW_AT_containing_type.
21953 If there is no type substitute an error marker. */
21955 static struct type
*
21956 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
21957 struct dwarf2_cu
*cu
)
21959 struct dwarf2_per_objfile
*dwarf2_per_objfile
21960 = cu
->per_cu
->dwarf2_per_objfile
;
21961 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21962 struct type
*this_type
;
21964 gdb_assert (attr
->name
== DW_AT_type
21965 || attr
->name
== DW_AT_GNAT_descriptive_type
21966 || attr
->name
== DW_AT_containing_type
);
21968 /* First see if we have it cached. */
21970 if (attr
->form
== DW_FORM_GNU_ref_alt
)
21972 struct dwarf2_per_cu_data
*per_cu
;
21973 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21975 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
21976 dwarf2_per_objfile
);
21977 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
21979 else if (attr_form_is_ref (attr
))
21981 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
21983 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
21985 else if (attr
->form
== DW_FORM_ref_sig8
)
21987 ULONGEST signature
= DW_SIGNATURE (attr
);
21989 return get_signatured_type (die
, signature
, cu
);
21993 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
21994 " at %s [in module %s]"),
21995 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
21996 objfile_name (objfile
));
21997 return build_error_marker_type (cu
, die
);
22000 /* If not cached we need to read it in. */
22002 if (this_type
== NULL
)
22004 struct die_info
*type_die
= NULL
;
22005 struct dwarf2_cu
*type_cu
= cu
;
22007 if (attr_form_is_ref (attr
))
22008 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22009 if (type_die
== NULL
)
22010 return build_error_marker_type (cu
, die
);
22011 /* If we find the type now, it's probably because the type came
22012 from an inter-CU reference and the type's CU got expanded before
22014 this_type
= read_type_die (type_die
, type_cu
);
22017 /* If we still don't have a type use an error marker. */
22019 if (this_type
== NULL
)
22020 return build_error_marker_type (cu
, die
);
22025 /* Return the type in DIE, CU.
22026 Returns NULL for invalid types.
22028 This first does a lookup in die_type_hash,
22029 and only reads the die in if necessary.
22031 NOTE: This can be called when reading in partial or full symbols. */
22033 static struct type
*
22034 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22036 struct type
*this_type
;
22038 this_type
= get_die_type (die
, cu
);
22042 return read_type_die_1 (die
, cu
);
22045 /* Read the type in DIE, CU.
22046 Returns NULL for invalid types. */
22048 static struct type
*
22049 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22051 struct type
*this_type
= NULL
;
22055 case DW_TAG_class_type
:
22056 case DW_TAG_interface_type
:
22057 case DW_TAG_structure_type
:
22058 case DW_TAG_union_type
:
22059 this_type
= read_structure_type (die
, cu
);
22061 case DW_TAG_enumeration_type
:
22062 this_type
= read_enumeration_type (die
, cu
);
22064 case DW_TAG_subprogram
:
22065 case DW_TAG_subroutine_type
:
22066 case DW_TAG_inlined_subroutine
:
22067 this_type
= read_subroutine_type (die
, cu
);
22069 case DW_TAG_array_type
:
22070 this_type
= read_array_type (die
, cu
);
22072 case DW_TAG_set_type
:
22073 this_type
= read_set_type (die
, cu
);
22075 case DW_TAG_pointer_type
:
22076 this_type
= read_tag_pointer_type (die
, cu
);
22078 case DW_TAG_ptr_to_member_type
:
22079 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22081 case DW_TAG_reference_type
:
22082 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22084 case DW_TAG_rvalue_reference_type
:
22085 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22087 case DW_TAG_const_type
:
22088 this_type
= read_tag_const_type (die
, cu
);
22090 case DW_TAG_volatile_type
:
22091 this_type
= read_tag_volatile_type (die
, cu
);
22093 case DW_TAG_restrict_type
:
22094 this_type
= read_tag_restrict_type (die
, cu
);
22096 case DW_TAG_string_type
:
22097 this_type
= read_tag_string_type (die
, cu
);
22099 case DW_TAG_typedef
:
22100 this_type
= read_typedef (die
, cu
);
22102 case DW_TAG_subrange_type
:
22103 this_type
= read_subrange_type (die
, cu
);
22105 case DW_TAG_base_type
:
22106 this_type
= read_base_type (die
, cu
);
22108 case DW_TAG_unspecified_type
:
22109 this_type
= read_unspecified_type (die
, cu
);
22111 case DW_TAG_namespace
:
22112 this_type
= read_namespace_type (die
, cu
);
22114 case DW_TAG_module
:
22115 this_type
= read_module_type (die
, cu
);
22117 case DW_TAG_atomic_type
:
22118 this_type
= read_tag_atomic_type (die
, cu
);
22121 complaint (_("unexpected tag in read_type_die: '%s'"),
22122 dwarf_tag_name (die
->tag
));
22129 /* See if we can figure out if the class lives in a namespace. We do
22130 this by looking for a member function; its demangled name will
22131 contain namespace info, if there is any.
22132 Return the computed name or NULL.
22133 Space for the result is allocated on the objfile's obstack.
22134 This is the full-die version of guess_partial_die_structure_name.
22135 In this case we know DIE has no useful parent. */
22137 static const char *
22138 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22140 struct die_info
*spec_die
;
22141 struct dwarf2_cu
*spec_cu
;
22142 struct die_info
*child
;
22143 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22146 spec_die
= die_specification (die
, &spec_cu
);
22147 if (spec_die
!= NULL
)
22153 for (child
= die
->child
;
22155 child
= child
->sibling
)
22157 if (child
->tag
== DW_TAG_subprogram
)
22159 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22161 if (linkage_name
!= NULL
)
22163 gdb::unique_xmalloc_ptr
<char> actual_name
22164 (language_class_name_from_physname (cu
->language_defn
,
22166 const char *name
= NULL
;
22168 if (actual_name
!= NULL
)
22170 const char *die_name
= dwarf2_name (die
, cu
);
22172 if (die_name
!= NULL
22173 && strcmp (die_name
, actual_name
.get ()) != 0)
22175 /* Strip off the class name from the full name.
22176 We want the prefix. */
22177 int die_name_len
= strlen (die_name
);
22178 int actual_name_len
= strlen (actual_name
.get ());
22179 const char *ptr
= actual_name
.get ();
22181 /* Test for '::' as a sanity check. */
22182 if (actual_name_len
> die_name_len
+ 2
22183 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22184 name
= obstack_strndup (
22185 &objfile
->per_bfd
->storage_obstack
,
22186 ptr
, actual_name_len
- die_name_len
- 2);
22197 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22198 prefix part in such case. See
22199 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22201 static const char *
22202 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22204 struct attribute
*attr
;
22207 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22208 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22211 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22214 attr
= dw2_linkage_name_attr (die
, cu
);
22215 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22218 /* dwarf2_name had to be already called. */
22219 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22221 /* Strip the base name, keep any leading namespaces/classes. */
22222 base
= strrchr (DW_STRING (attr
), ':');
22223 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22226 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22227 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22229 &base
[-1] - DW_STRING (attr
));
22232 /* Return the name of the namespace/class that DIE is defined within,
22233 or "" if we can't tell. The caller should not xfree the result.
22235 For example, if we're within the method foo() in the following
22245 then determine_prefix on foo's die will return "N::C". */
22247 static const char *
22248 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22250 struct dwarf2_per_objfile
*dwarf2_per_objfile
22251 = cu
->per_cu
->dwarf2_per_objfile
;
22252 struct die_info
*parent
, *spec_die
;
22253 struct dwarf2_cu
*spec_cu
;
22254 struct type
*parent_type
;
22255 const char *retval
;
22257 if (cu
->language
!= language_cplus
22258 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22259 && cu
->language
!= language_rust
)
22262 retval
= anonymous_struct_prefix (die
, cu
);
22266 /* We have to be careful in the presence of DW_AT_specification.
22267 For example, with GCC 3.4, given the code
22271 // Definition of N::foo.
22275 then we'll have a tree of DIEs like this:
22277 1: DW_TAG_compile_unit
22278 2: DW_TAG_namespace // N
22279 3: DW_TAG_subprogram // declaration of N::foo
22280 4: DW_TAG_subprogram // definition of N::foo
22281 DW_AT_specification // refers to die #3
22283 Thus, when processing die #4, we have to pretend that we're in
22284 the context of its DW_AT_specification, namely the contex of die
22287 spec_die
= die_specification (die
, &spec_cu
);
22288 if (spec_die
== NULL
)
22289 parent
= die
->parent
;
22292 parent
= spec_die
->parent
;
22296 if (parent
== NULL
)
22298 else if (parent
->building_fullname
)
22301 const char *parent_name
;
22303 /* It has been seen on RealView 2.2 built binaries,
22304 DW_TAG_template_type_param types actually _defined_ as
22305 children of the parent class:
22308 template class <class Enum> Class{};
22309 Class<enum E> class_e;
22311 1: DW_TAG_class_type (Class)
22312 2: DW_TAG_enumeration_type (E)
22313 3: DW_TAG_enumerator (enum1:0)
22314 3: DW_TAG_enumerator (enum2:1)
22316 2: DW_TAG_template_type_param
22317 DW_AT_type DW_FORM_ref_udata (E)
22319 Besides being broken debug info, it can put GDB into an
22320 infinite loop. Consider:
22322 When we're building the full name for Class<E>, we'll start
22323 at Class, and go look over its template type parameters,
22324 finding E. We'll then try to build the full name of E, and
22325 reach here. We're now trying to build the full name of E,
22326 and look over the parent DIE for containing scope. In the
22327 broken case, if we followed the parent DIE of E, we'd again
22328 find Class, and once again go look at its template type
22329 arguments, etc., etc. Simply don't consider such parent die
22330 as source-level parent of this die (it can't be, the language
22331 doesn't allow it), and break the loop here. */
22332 name
= dwarf2_name (die
, cu
);
22333 parent_name
= dwarf2_name (parent
, cu
);
22334 complaint (_("template param type '%s' defined within parent '%s'"),
22335 name
? name
: "<unknown>",
22336 parent_name
? parent_name
: "<unknown>");
22340 switch (parent
->tag
)
22342 case DW_TAG_namespace
:
22343 parent_type
= read_type_die (parent
, cu
);
22344 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22345 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22346 Work around this problem here. */
22347 if (cu
->language
== language_cplus
22348 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22350 /* We give a name to even anonymous namespaces. */
22351 return TYPE_NAME (parent_type
);
22352 case DW_TAG_class_type
:
22353 case DW_TAG_interface_type
:
22354 case DW_TAG_structure_type
:
22355 case DW_TAG_union_type
:
22356 case DW_TAG_module
:
22357 parent_type
= read_type_die (parent
, cu
);
22358 if (TYPE_NAME (parent_type
) != NULL
)
22359 return TYPE_NAME (parent_type
);
22361 /* An anonymous structure is only allowed non-static data
22362 members; no typedefs, no member functions, et cetera.
22363 So it does not need a prefix. */
22365 case DW_TAG_compile_unit
:
22366 case DW_TAG_partial_unit
:
22367 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22368 if (cu
->language
== language_cplus
22369 && !dwarf2_per_objfile
->types
.empty ()
22370 && die
->child
!= NULL
22371 && (die
->tag
== DW_TAG_class_type
22372 || die
->tag
== DW_TAG_structure_type
22373 || die
->tag
== DW_TAG_union_type
))
22375 const char *name
= guess_full_die_structure_name (die
, cu
);
22380 case DW_TAG_subprogram
:
22381 /* Nested subroutines in Fortran get a prefix with the name
22382 of the parent's subroutine. */
22383 if (cu
->language
== language_fortran
)
22385 if ((die
->tag
== DW_TAG_subprogram
)
22386 && (dwarf2_name (parent
, cu
) != NULL
))
22387 return dwarf2_name (parent
, cu
);
22389 return determine_prefix (parent
, cu
);
22390 case DW_TAG_enumeration_type
:
22391 parent_type
= read_type_die (parent
, cu
);
22392 if (TYPE_DECLARED_CLASS (parent_type
))
22394 if (TYPE_NAME (parent_type
) != NULL
)
22395 return TYPE_NAME (parent_type
);
22398 /* Fall through. */
22400 return determine_prefix (parent
, cu
);
22404 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22405 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22406 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22407 an obconcat, otherwise allocate storage for the result. The CU argument is
22408 used to determine the language and hence, the appropriate separator. */
22410 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22413 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22414 int physname
, struct dwarf2_cu
*cu
)
22416 const char *lead
= "";
22419 if (suffix
== NULL
|| suffix
[0] == '\0'
22420 || prefix
== NULL
|| prefix
[0] == '\0')
22422 else if (cu
->language
== language_d
)
22424 /* For D, the 'main' function could be defined in any module, but it
22425 should never be prefixed. */
22426 if (strcmp (suffix
, "D main") == 0)
22434 else if (cu
->language
== language_fortran
&& physname
)
22436 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22437 DW_AT_MIPS_linkage_name is preferred and used instead. */
22445 if (prefix
== NULL
)
22447 if (suffix
== NULL
)
22454 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22456 strcpy (retval
, lead
);
22457 strcat (retval
, prefix
);
22458 strcat (retval
, sep
);
22459 strcat (retval
, suffix
);
22464 /* We have an obstack. */
22465 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22469 /* Return sibling of die, NULL if no sibling. */
22471 static struct die_info
*
22472 sibling_die (struct die_info
*die
)
22474 return die
->sibling
;
22477 /* Get name of a die, return NULL if not found. */
22479 static const char *
22480 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22481 struct obstack
*obstack
)
22483 if (name
&& cu
->language
== language_cplus
)
22485 std::string canon_name
= cp_canonicalize_string (name
);
22487 if (!canon_name
.empty ())
22489 if (canon_name
!= name
)
22490 name
= obstack_strdup (obstack
, canon_name
);
22497 /* Get name of a die, return NULL if not found.
22498 Anonymous namespaces are converted to their magic string. */
22500 static const char *
22501 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22503 struct attribute
*attr
;
22504 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22506 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22507 if ((!attr
|| !DW_STRING (attr
))
22508 && die
->tag
!= DW_TAG_namespace
22509 && die
->tag
!= DW_TAG_class_type
22510 && die
->tag
!= DW_TAG_interface_type
22511 && die
->tag
!= DW_TAG_structure_type
22512 && die
->tag
!= DW_TAG_union_type
)
22517 case DW_TAG_compile_unit
:
22518 case DW_TAG_partial_unit
:
22519 /* Compilation units have a DW_AT_name that is a filename, not
22520 a source language identifier. */
22521 case DW_TAG_enumeration_type
:
22522 case DW_TAG_enumerator
:
22523 /* These tags always have simple identifiers already; no need
22524 to canonicalize them. */
22525 return DW_STRING (attr
);
22527 case DW_TAG_namespace
:
22528 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22529 return DW_STRING (attr
);
22530 return CP_ANONYMOUS_NAMESPACE_STR
;
22532 case DW_TAG_class_type
:
22533 case DW_TAG_interface_type
:
22534 case DW_TAG_structure_type
:
22535 case DW_TAG_union_type
:
22536 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22537 structures or unions. These were of the form "._%d" in GCC 4.1,
22538 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22539 and GCC 4.4. We work around this problem by ignoring these. */
22540 if (attr
&& DW_STRING (attr
)
22541 && (startswith (DW_STRING (attr
), "._")
22542 || startswith (DW_STRING (attr
), "<anonymous")))
22545 /* GCC might emit a nameless typedef that has a linkage name. See
22546 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22547 if (!attr
|| DW_STRING (attr
) == NULL
)
22549 attr
= dw2_linkage_name_attr (die
, cu
);
22550 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22553 /* Avoid demangling DW_STRING (attr) the second time on a second
22554 call for the same DIE. */
22555 if (!DW_STRING_IS_CANONICAL (attr
))
22557 gdb::unique_xmalloc_ptr
<char> demangled
22558 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
22562 /* FIXME: we already did this for the partial symbol... */
22564 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22566 DW_STRING_IS_CANONICAL (attr
) = 1;
22568 /* Strip any leading namespaces/classes, keep only the base name.
22569 DW_AT_name for named DIEs does not contain the prefixes. */
22570 base
= strrchr (DW_STRING (attr
), ':');
22571 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22574 return DW_STRING (attr
);
22583 if (!DW_STRING_IS_CANONICAL (attr
))
22586 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22587 &objfile
->per_bfd
->storage_obstack
);
22588 DW_STRING_IS_CANONICAL (attr
) = 1;
22590 return DW_STRING (attr
);
22593 /* Return the die that this die in an extension of, or NULL if there
22594 is none. *EXT_CU is the CU containing DIE on input, and the CU
22595 containing the return value on output. */
22597 static struct die_info
*
22598 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22600 struct attribute
*attr
;
22602 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22606 return follow_die_ref (die
, attr
, ext_cu
);
22609 /* A convenience function that returns an "unknown" DWARF name,
22610 including the value of V. STR is the name of the entity being
22611 printed, e.g., "TAG". */
22613 static const char *
22614 dwarf_unknown (const char *str
, unsigned v
)
22616 char *cell
= get_print_cell ();
22617 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22621 /* Convert a DIE tag into its string name. */
22623 static const char *
22624 dwarf_tag_name (unsigned tag
)
22626 const char *name
= get_DW_TAG_name (tag
);
22629 return dwarf_unknown ("TAG", tag
);
22634 /* Convert a DWARF attribute code into its string name. */
22636 static const char *
22637 dwarf_attr_name (unsigned attr
)
22641 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22642 if (attr
== DW_AT_MIPS_fde
)
22643 return "DW_AT_MIPS_fde";
22645 if (attr
== DW_AT_HP_block_index
)
22646 return "DW_AT_HP_block_index";
22649 name
= get_DW_AT_name (attr
);
22652 return dwarf_unknown ("AT", attr
);
22657 /* Convert a unit type to corresponding DW_UT name. */
22659 static const char *
22660 dwarf_unit_type_name (int unit_type
) {
22664 return "DW_UT_compile (0x01)";
22666 return "DW_UT_type (0x02)";
22668 return "DW_UT_partial (0x03)";
22670 return "DW_UT_skeleton (0x04)";
22672 return "DW_UT_split_compile (0x05)";
22674 return "DW_UT_split_type (0x06)";
22676 return "DW_UT_lo_user (0x80)";
22678 return "DW_UT_hi_user (0xff)";
22684 /* Convert a DWARF value form code into its string name. */
22686 static const char *
22687 dwarf_form_name (unsigned form
)
22689 const char *name
= get_DW_FORM_name (form
);
22692 return dwarf_unknown ("FORM", form
);
22697 static const char *
22698 dwarf_bool_name (unsigned mybool
)
22706 /* Convert a DWARF type code into its string name. */
22708 static const char *
22709 dwarf_type_encoding_name (unsigned enc
)
22711 const char *name
= get_DW_ATE_name (enc
);
22714 return dwarf_unknown ("ATE", enc
);
22720 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22724 print_spaces (indent
, f
);
22725 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22726 dwarf_tag_name (die
->tag
), die
->abbrev
,
22727 sect_offset_str (die
->sect_off
));
22729 if (die
->parent
!= NULL
)
22731 print_spaces (indent
, f
);
22732 fprintf_unfiltered (f
, " parent at offset: %s\n",
22733 sect_offset_str (die
->parent
->sect_off
));
22736 print_spaces (indent
, f
);
22737 fprintf_unfiltered (f
, " has children: %s\n",
22738 dwarf_bool_name (die
->child
!= NULL
));
22740 print_spaces (indent
, f
);
22741 fprintf_unfiltered (f
, " attributes:\n");
22743 for (i
= 0; i
< die
->num_attrs
; ++i
)
22745 print_spaces (indent
, f
);
22746 fprintf_unfiltered (f
, " %s (%s) ",
22747 dwarf_attr_name (die
->attrs
[i
].name
),
22748 dwarf_form_name (die
->attrs
[i
].form
));
22750 switch (die
->attrs
[i
].form
)
22753 case DW_FORM_addrx
:
22754 case DW_FORM_GNU_addr_index
:
22755 fprintf_unfiltered (f
, "address: ");
22756 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
22758 case DW_FORM_block2
:
22759 case DW_FORM_block4
:
22760 case DW_FORM_block
:
22761 case DW_FORM_block1
:
22762 fprintf_unfiltered (f
, "block: size %s",
22763 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22765 case DW_FORM_exprloc
:
22766 fprintf_unfiltered (f
, "expression: size %s",
22767 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
22769 case DW_FORM_data16
:
22770 fprintf_unfiltered (f
, "constant of 16 bytes");
22772 case DW_FORM_ref_addr
:
22773 fprintf_unfiltered (f
, "ref address: ");
22774 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22776 case DW_FORM_GNU_ref_alt
:
22777 fprintf_unfiltered (f
, "alt ref address: ");
22778 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
22784 case DW_FORM_ref_udata
:
22785 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
22786 (long) (DW_UNSND (&die
->attrs
[i
])));
22788 case DW_FORM_data1
:
22789 case DW_FORM_data2
:
22790 case DW_FORM_data4
:
22791 case DW_FORM_data8
:
22792 case DW_FORM_udata
:
22793 case DW_FORM_sdata
:
22794 fprintf_unfiltered (f
, "constant: %s",
22795 pulongest (DW_UNSND (&die
->attrs
[i
])));
22797 case DW_FORM_sec_offset
:
22798 fprintf_unfiltered (f
, "section offset: %s",
22799 pulongest (DW_UNSND (&die
->attrs
[i
])));
22801 case DW_FORM_ref_sig8
:
22802 fprintf_unfiltered (f
, "signature: %s",
22803 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
22805 case DW_FORM_string
:
22807 case DW_FORM_line_strp
:
22809 case DW_FORM_GNU_str_index
:
22810 case DW_FORM_GNU_strp_alt
:
22811 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
22812 DW_STRING (&die
->attrs
[i
])
22813 ? DW_STRING (&die
->attrs
[i
]) : "",
22814 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
22817 if (DW_UNSND (&die
->attrs
[i
]))
22818 fprintf_unfiltered (f
, "flag: TRUE");
22820 fprintf_unfiltered (f
, "flag: FALSE");
22822 case DW_FORM_flag_present
:
22823 fprintf_unfiltered (f
, "flag: TRUE");
22825 case DW_FORM_indirect
:
22826 /* The reader will have reduced the indirect form to
22827 the "base form" so this form should not occur. */
22828 fprintf_unfiltered (f
,
22829 "unexpected attribute form: DW_FORM_indirect");
22831 case DW_FORM_implicit_const
:
22832 fprintf_unfiltered (f
, "constant: %s",
22833 plongest (DW_SND (&die
->attrs
[i
])));
22836 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
22837 die
->attrs
[i
].form
);
22840 fprintf_unfiltered (f
, "\n");
22845 dump_die_for_error (struct die_info
*die
)
22847 dump_die_shallow (gdb_stderr
, 0, die
);
22851 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
22853 int indent
= level
* 4;
22855 gdb_assert (die
!= NULL
);
22857 if (level
>= max_level
)
22860 dump_die_shallow (f
, indent
, die
);
22862 if (die
->child
!= NULL
)
22864 print_spaces (indent
, f
);
22865 fprintf_unfiltered (f
, " Children:");
22866 if (level
+ 1 < max_level
)
22868 fprintf_unfiltered (f
, "\n");
22869 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
22873 fprintf_unfiltered (f
,
22874 " [not printed, max nesting level reached]\n");
22878 if (die
->sibling
!= NULL
&& level
> 0)
22880 dump_die_1 (f
, level
, max_level
, die
->sibling
);
22884 /* This is called from the pdie macro in gdbinit.in.
22885 It's not static so gcc will keep a copy callable from gdb. */
22888 dump_die (struct die_info
*die
, int max_level
)
22890 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
22894 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
22898 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
22899 to_underlying (die
->sect_off
),
22905 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
22909 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
22911 if (attr_form_is_ref (attr
))
22912 return (sect_offset
) DW_UNSND (attr
);
22914 complaint (_("unsupported die ref attribute form: '%s'"),
22915 dwarf_form_name (attr
->form
));
22919 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
22920 * the value held by the attribute is not constant. */
22923 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
22925 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
22926 return DW_SND (attr
);
22927 else if (attr
->form
== DW_FORM_udata
22928 || attr
->form
== DW_FORM_data1
22929 || attr
->form
== DW_FORM_data2
22930 || attr
->form
== DW_FORM_data4
22931 || attr
->form
== DW_FORM_data8
)
22932 return DW_UNSND (attr
);
22935 /* For DW_FORM_data16 see attr_form_is_constant. */
22936 complaint (_("Attribute value is not a constant (%s)"),
22937 dwarf_form_name (attr
->form
));
22938 return default_value
;
22942 /* Follow reference or signature attribute ATTR of SRC_DIE.
22943 On entry *REF_CU is the CU of SRC_DIE.
22944 On exit *REF_CU is the CU of the result. */
22946 static struct die_info
*
22947 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
22948 struct dwarf2_cu
**ref_cu
)
22950 struct die_info
*die
;
22952 if (attr_form_is_ref (attr
))
22953 die
= follow_die_ref (src_die
, attr
, ref_cu
);
22954 else if (attr
->form
== DW_FORM_ref_sig8
)
22955 die
= follow_die_sig (src_die
, attr
, ref_cu
);
22958 dump_die_for_error (src_die
);
22959 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
22960 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
22966 /* Follow reference OFFSET.
22967 On entry *REF_CU is the CU of the source die referencing OFFSET.
22968 On exit *REF_CU is the CU of the result.
22969 Returns NULL if OFFSET is invalid. */
22971 static struct die_info
*
22972 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
22973 struct dwarf2_cu
**ref_cu
)
22975 struct die_info temp_die
;
22976 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
22977 struct dwarf2_per_objfile
*dwarf2_per_objfile
22978 = cu
->per_cu
->dwarf2_per_objfile
;
22980 gdb_assert (cu
->per_cu
!= NULL
);
22984 if (cu
->per_cu
->is_debug_types
)
22986 /* .debug_types CUs cannot reference anything outside their CU.
22987 If they need to, they have to reference a signatured type via
22988 DW_FORM_ref_sig8. */
22989 if (!offset_in_cu_p (&cu
->header
, sect_off
))
22992 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
22993 || !offset_in_cu_p (&cu
->header
, sect_off
))
22995 struct dwarf2_per_cu_data
*per_cu
;
22997 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
22998 dwarf2_per_objfile
);
23000 /* If necessary, add it to the queue and load its DIEs. */
23001 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23002 load_full_comp_unit (per_cu
, false, cu
->language
);
23004 target_cu
= per_cu
->cu
;
23006 else if (cu
->dies
== NULL
)
23008 /* We're loading full DIEs during partial symbol reading. */
23009 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23010 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23013 *ref_cu
= target_cu
;
23014 temp_die
.sect_off
= sect_off
;
23016 if (target_cu
!= cu
)
23017 target_cu
->ancestor
= cu
;
23019 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23021 to_underlying (sect_off
));
23024 /* Follow reference attribute ATTR of SRC_DIE.
23025 On entry *REF_CU is the CU of SRC_DIE.
23026 On exit *REF_CU is the CU of the result. */
23028 static struct die_info
*
23029 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23030 struct dwarf2_cu
**ref_cu
)
23032 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23033 struct dwarf2_cu
*cu
= *ref_cu
;
23034 struct die_info
*die
;
23036 die
= follow_die_offset (sect_off
,
23037 (attr
->form
== DW_FORM_GNU_ref_alt
23038 || cu
->per_cu
->is_dwz
),
23041 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23042 "at %s [in module %s]"),
23043 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23044 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23049 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23050 Returned value is intended for DW_OP_call*. Returned
23051 dwarf2_locexpr_baton->data has lifetime of
23052 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23054 struct dwarf2_locexpr_baton
23055 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23056 struct dwarf2_per_cu_data
*per_cu
,
23057 CORE_ADDR (*get_frame_pc
) (void *baton
),
23058 void *baton
, bool resolve_abstract_p
)
23060 struct dwarf2_cu
*cu
;
23061 struct die_info
*die
;
23062 struct attribute
*attr
;
23063 struct dwarf2_locexpr_baton retval
;
23064 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23065 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23067 if (per_cu
->cu
== NULL
)
23068 load_cu (per_cu
, false);
23072 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23073 Instead just throw an error, not much else we can do. */
23074 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23075 sect_offset_str (sect_off
), objfile_name (objfile
));
23078 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23080 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23081 sect_offset_str (sect_off
), objfile_name (objfile
));
23083 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23084 if (!attr
&& resolve_abstract_p
23085 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23086 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23088 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23089 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23090 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23092 for (const auto &cand_off
23093 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23095 struct dwarf2_cu
*cand_cu
= cu
;
23096 struct die_info
*cand
23097 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23100 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23103 CORE_ADDR pc_low
, pc_high
;
23104 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23105 if (pc_low
== ((CORE_ADDR
) -1))
23107 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23108 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23109 if (!(pc_low
<= pc
&& pc
< pc_high
))
23113 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23120 /* DWARF: "If there is no such attribute, then there is no effect.".
23121 DATA is ignored if SIZE is 0. */
23123 retval
.data
= NULL
;
23126 else if (attr_form_is_section_offset (attr
))
23128 struct dwarf2_loclist_baton loclist_baton
;
23129 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23132 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23134 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23136 retval
.size
= size
;
23140 if (!attr_form_is_block (attr
))
23141 error (_("Dwarf Error: DIE at %s referenced in module %s "
23142 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23143 sect_offset_str (sect_off
), objfile_name (objfile
));
23145 retval
.data
= DW_BLOCK (attr
)->data
;
23146 retval
.size
= DW_BLOCK (attr
)->size
;
23148 retval
.per_cu
= cu
->per_cu
;
23150 age_cached_comp_units (dwarf2_per_objfile
);
23155 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23158 struct dwarf2_locexpr_baton
23159 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23160 struct dwarf2_per_cu_data
*per_cu
,
23161 CORE_ADDR (*get_frame_pc
) (void *baton
),
23164 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23166 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23169 /* Write a constant of a given type as target-ordered bytes into
23172 static const gdb_byte
*
23173 write_constant_as_bytes (struct obstack
*obstack
,
23174 enum bfd_endian byte_order
,
23181 *len
= TYPE_LENGTH (type
);
23182 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23183 store_unsigned_integer (result
, *len
, byte_order
, value
);
23188 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23189 pointer to the constant bytes and set LEN to the length of the
23190 data. If memory is needed, allocate it on OBSTACK. If the DIE
23191 does not have a DW_AT_const_value, return NULL. */
23194 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23195 struct dwarf2_per_cu_data
*per_cu
,
23196 struct obstack
*obstack
,
23199 struct dwarf2_cu
*cu
;
23200 struct die_info
*die
;
23201 struct attribute
*attr
;
23202 const gdb_byte
*result
= NULL
;
23205 enum bfd_endian byte_order
;
23206 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23208 if (per_cu
->cu
== NULL
)
23209 load_cu (per_cu
, false);
23213 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23214 Instead just throw an error, not much else we can do. */
23215 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23216 sect_offset_str (sect_off
), objfile_name (objfile
));
23219 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23221 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23222 sect_offset_str (sect_off
), objfile_name (objfile
));
23224 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23228 byte_order
= (bfd_big_endian (objfile
->obfd
)
23229 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23231 switch (attr
->form
)
23234 case DW_FORM_addrx
:
23235 case DW_FORM_GNU_addr_index
:
23239 *len
= cu
->header
.addr_size
;
23240 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23241 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23245 case DW_FORM_string
:
23248 case DW_FORM_GNU_str_index
:
23249 case DW_FORM_GNU_strp_alt
:
23250 /* DW_STRING is already allocated on the objfile obstack, point
23252 result
= (const gdb_byte
*) DW_STRING (attr
);
23253 *len
= strlen (DW_STRING (attr
));
23255 case DW_FORM_block1
:
23256 case DW_FORM_block2
:
23257 case DW_FORM_block4
:
23258 case DW_FORM_block
:
23259 case DW_FORM_exprloc
:
23260 case DW_FORM_data16
:
23261 result
= DW_BLOCK (attr
)->data
;
23262 *len
= DW_BLOCK (attr
)->size
;
23265 /* The DW_AT_const_value attributes are supposed to carry the
23266 symbol's value "represented as it would be on the target
23267 architecture." By the time we get here, it's already been
23268 converted to host endianness, so we just need to sign- or
23269 zero-extend it as appropriate. */
23270 case DW_FORM_data1
:
23271 type
= die_type (die
, cu
);
23272 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23273 if (result
== NULL
)
23274 result
= write_constant_as_bytes (obstack
, byte_order
,
23277 case DW_FORM_data2
:
23278 type
= die_type (die
, cu
);
23279 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23280 if (result
== NULL
)
23281 result
= write_constant_as_bytes (obstack
, byte_order
,
23284 case DW_FORM_data4
:
23285 type
= die_type (die
, cu
);
23286 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23287 if (result
== NULL
)
23288 result
= write_constant_as_bytes (obstack
, byte_order
,
23291 case DW_FORM_data8
:
23292 type
= die_type (die
, cu
);
23293 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23294 if (result
== NULL
)
23295 result
= write_constant_as_bytes (obstack
, byte_order
,
23299 case DW_FORM_sdata
:
23300 case DW_FORM_implicit_const
:
23301 type
= die_type (die
, cu
);
23302 result
= write_constant_as_bytes (obstack
, byte_order
,
23303 type
, DW_SND (attr
), len
);
23306 case DW_FORM_udata
:
23307 type
= die_type (die
, cu
);
23308 result
= write_constant_as_bytes (obstack
, byte_order
,
23309 type
, DW_UNSND (attr
), len
);
23313 complaint (_("unsupported const value attribute form: '%s'"),
23314 dwarf_form_name (attr
->form
));
23321 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23322 valid type for this die is found. */
23325 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23326 struct dwarf2_per_cu_data
*per_cu
)
23328 struct dwarf2_cu
*cu
;
23329 struct die_info
*die
;
23331 if (per_cu
->cu
== NULL
)
23332 load_cu (per_cu
, false);
23337 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23341 return die_type (die
, cu
);
23344 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23348 dwarf2_get_die_type (cu_offset die_offset
,
23349 struct dwarf2_per_cu_data
*per_cu
)
23351 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23352 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23355 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23356 On entry *REF_CU is the CU of SRC_DIE.
23357 On exit *REF_CU is the CU of the result.
23358 Returns NULL if the referenced DIE isn't found. */
23360 static struct die_info
*
23361 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23362 struct dwarf2_cu
**ref_cu
)
23364 struct die_info temp_die
;
23365 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23366 struct die_info
*die
;
23368 /* While it might be nice to assert sig_type->type == NULL here,
23369 we can get here for DW_AT_imported_declaration where we need
23370 the DIE not the type. */
23372 /* If necessary, add it to the queue and load its DIEs. */
23374 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23375 read_signatured_type (sig_type
);
23377 sig_cu
= sig_type
->per_cu
.cu
;
23378 gdb_assert (sig_cu
!= NULL
);
23379 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23380 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23381 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23382 to_underlying (temp_die
.sect_off
));
23385 struct dwarf2_per_objfile
*dwarf2_per_objfile
23386 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23388 /* For .gdb_index version 7 keep track of included TUs.
23389 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23390 if (dwarf2_per_objfile
->index_table
!= NULL
23391 && dwarf2_per_objfile
->index_table
->version
<= 7)
23393 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23398 sig_cu
->ancestor
= cu
;
23406 /* Follow signatured type referenced by ATTR in SRC_DIE.
23407 On entry *REF_CU is the CU of SRC_DIE.
23408 On exit *REF_CU is the CU of the result.
23409 The result is the DIE of the type.
23410 If the referenced type cannot be found an error is thrown. */
23412 static struct die_info
*
23413 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23414 struct dwarf2_cu
**ref_cu
)
23416 ULONGEST signature
= DW_SIGNATURE (attr
);
23417 struct signatured_type
*sig_type
;
23418 struct die_info
*die
;
23420 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23422 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23423 /* sig_type will be NULL if the signatured type is missing from
23425 if (sig_type
== NULL
)
23427 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23428 " from DIE at %s [in module %s]"),
23429 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23430 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23433 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23436 dump_die_for_error (src_die
);
23437 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23438 " from DIE at %s [in module %s]"),
23439 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23440 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23446 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23447 reading in and processing the type unit if necessary. */
23449 static struct type
*
23450 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23451 struct dwarf2_cu
*cu
)
23453 struct dwarf2_per_objfile
*dwarf2_per_objfile
23454 = cu
->per_cu
->dwarf2_per_objfile
;
23455 struct signatured_type
*sig_type
;
23456 struct dwarf2_cu
*type_cu
;
23457 struct die_info
*type_die
;
23460 sig_type
= lookup_signatured_type (cu
, signature
);
23461 /* sig_type will be NULL if the signatured type is missing from
23463 if (sig_type
== NULL
)
23465 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23466 " from DIE at %s [in module %s]"),
23467 hex_string (signature
), sect_offset_str (die
->sect_off
),
23468 objfile_name (dwarf2_per_objfile
->objfile
));
23469 return build_error_marker_type (cu
, die
);
23472 /* If we already know the type we're done. */
23473 if (sig_type
->type
!= NULL
)
23474 return sig_type
->type
;
23477 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23478 if (type_die
!= NULL
)
23480 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23481 is created. This is important, for example, because for c++ classes
23482 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23483 type
= read_type_die (type_die
, type_cu
);
23486 complaint (_("Dwarf Error: Cannot build signatured type %s"
23487 " referenced from DIE at %s [in module %s]"),
23488 hex_string (signature
), sect_offset_str (die
->sect_off
),
23489 objfile_name (dwarf2_per_objfile
->objfile
));
23490 type
= build_error_marker_type (cu
, die
);
23495 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23496 " from DIE at %s [in module %s]"),
23497 hex_string (signature
), sect_offset_str (die
->sect_off
),
23498 objfile_name (dwarf2_per_objfile
->objfile
));
23499 type
= build_error_marker_type (cu
, die
);
23501 sig_type
->type
= type
;
23506 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23507 reading in and processing the type unit if necessary. */
23509 static struct type
*
23510 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23511 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23513 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23514 if (attr_form_is_ref (attr
))
23516 struct dwarf2_cu
*type_cu
= cu
;
23517 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23519 return read_type_die (type_die
, type_cu
);
23521 else if (attr
->form
== DW_FORM_ref_sig8
)
23523 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23527 struct dwarf2_per_objfile
*dwarf2_per_objfile
23528 = cu
->per_cu
->dwarf2_per_objfile
;
23530 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23531 " at %s [in module %s]"),
23532 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23533 objfile_name (dwarf2_per_objfile
->objfile
));
23534 return build_error_marker_type (cu
, die
);
23538 /* Load the DIEs associated with type unit PER_CU into memory. */
23541 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23543 struct signatured_type
*sig_type
;
23545 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23546 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23548 /* We have the per_cu, but we need the signatured_type.
23549 Fortunately this is an easy translation. */
23550 gdb_assert (per_cu
->is_debug_types
);
23551 sig_type
= (struct signatured_type
*) per_cu
;
23553 gdb_assert (per_cu
->cu
== NULL
);
23555 read_signatured_type (sig_type
);
23557 gdb_assert (per_cu
->cu
!= NULL
);
23560 /* Read in a signatured type and build its CU and DIEs.
23561 If the type is a stub for the real type in a DWO file,
23562 read in the real type from the DWO file as well. */
23565 read_signatured_type (struct signatured_type
*sig_type
)
23567 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23569 gdb_assert (per_cu
->is_debug_types
);
23570 gdb_assert (per_cu
->cu
== NULL
);
23572 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
23574 if (!reader
.dummy_p
)
23576 struct dwarf2_cu
*cu
= reader
.cu
;
23577 const gdb_byte
*info_ptr
= reader
.info_ptr
;
23579 gdb_assert (cu
->die_hash
== NULL
);
23581 htab_create_alloc_ex (cu
->header
.length
/ 12,
23585 &cu
->comp_unit_obstack
,
23586 hashtab_obstack_allocate
,
23587 dummy_obstack_deallocate
);
23589 if (reader
.has_children
)
23590 reader
.comp_unit_die
->child
23591 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
23592 reader
.comp_unit_die
);
23593 cu
->dies
= reader
.comp_unit_die
;
23594 /* comp_unit_die is not stored in die_hash, no need. */
23596 /* We try not to read any attributes in this function, because
23597 not all CUs needed for references have been loaded yet, and
23598 symbol table processing isn't initialized. But we have to
23599 set the CU language, or we won't be able to build types
23600 correctly. Similarly, if we do not read the producer, we can
23601 not apply producer-specific interpretation. */
23602 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23605 sig_type
->per_cu
.tu_read
= 1;
23608 /* Decode simple location descriptions.
23609 Given a pointer to a dwarf block that defines a location, compute
23610 the location and return the value.
23612 NOTE drow/2003-11-18: This function is called in two situations
23613 now: for the address of static or global variables (partial symbols
23614 only) and for offsets into structures which are expected to be
23615 (more or less) constant. The partial symbol case should go away,
23616 and only the constant case should remain. That will let this
23617 function complain more accurately. A few special modes are allowed
23618 without complaint for global variables (for instance, global
23619 register values and thread-local values).
23621 A location description containing no operations indicates that the
23622 object is optimized out. The return value is 0 for that case.
23623 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23624 callers will only want a very basic result and this can become a
23627 Note that stack[0] is unused except as a default error return. */
23630 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23632 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23634 size_t size
= blk
->size
;
23635 const gdb_byte
*data
= blk
->data
;
23636 CORE_ADDR stack
[64];
23638 unsigned int bytes_read
, unsnd
;
23644 stack
[++stacki
] = 0;
23683 stack
[++stacki
] = op
- DW_OP_lit0
;
23718 stack
[++stacki
] = op
- DW_OP_reg0
;
23720 dwarf2_complex_location_expr_complaint ();
23724 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
23726 stack
[++stacki
] = unsnd
;
23728 dwarf2_complex_location_expr_complaint ();
23732 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
23737 case DW_OP_const1u
:
23738 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
23742 case DW_OP_const1s
:
23743 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
23747 case DW_OP_const2u
:
23748 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
23752 case DW_OP_const2s
:
23753 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
23757 case DW_OP_const4u
:
23758 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
23762 case DW_OP_const4s
:
23763 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
23767 case DW_OP_const8u
:
23768 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
23773 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
23779 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
23784 stack
[stacki
+ 1] = stack
[stacki
];
23789 stack
[stacki
- 1] += stack
[stacki
];
23793 case DW_OP_plus_uconst
:
23794 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
23800 stack
[stacki
- 1] -= stack
[stacki
];
23805 /* If we're not the last op, then we definitely can't encode
23806 this using GDB's address_class enum. This is valid for partial
23807 global symbols, although the variable's address will be bogus
23810 dwarf2_complex_location_expr_complaint ();
23813 case DW_OP_GNU_push_tls_address
:
23814 case DW_OP_form_tls_address
:
23815 /* The top of the stack has the offset from the beginning
23816 of the thread control block at which the variable is located. */
23817 /* Nothing should follow this operator, so the top of stack would
23819 /* This is valid for partial global symbols, but the variable's
23820 address will be bogus in the psymtab. Make it always at least
23821 non-zero to not look as a variable garbage collected by linker
23822 which have DW_OP_addr 0. */
23824 dwarf2_complex_location_expr_complaint ();
23828 case DW_OP_GNU_uninit
:
23832 case DW_OP_GNU_addr_index
:
23833 case DW_OP_GNU_const_index
:
23834 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
23841 const char *name
= get_DW_OP_name (op
);
23844 complaint (_("unsupported stack op: '%s'"),
23847 complaint (_("unsupported stack op: '%02x'"),
23851 return (stack
[stacki
]);
23854 /* Enforce maximum stack depth of SIZE-1 to avoid writing
23855 outside of the allocated space. Also enforce minimum>0. */
23856 if (stacki
>= ARRAY_SIZE (stack
) - 1)
23858 complaint (_("location description stack overflow"));
23864 complaint (_("location description stack underflow"));
23868 return (stack
[stacki
]);
23871 /* memory allocation interface */
23873 static struct dwarf_block
*
23874 dwarf_alloc_block (struct dwarf2_cu
*cu
)
23876 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
23879 static struct die_info
*
23880 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
23882 struct die_info
*die
;
23883 size_t size
= sizeof (struct die_info
);
23886 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
23888 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
23889 memset (die
, 0, sizeof (struct die_info
));
23894 /* Macro support. */
23896 /* Return file name relative to the compilation directory of file number I in
23897 *LH's file name table. The result is allocated using xmalloc; the caller is
23898 responsible for freeing it. */
23901 file_file_name (int file
, struct line_header
*lh
)
23903 /* Is the file number a valid index into the line header's file name
23904 table? Remember that file numbers start with one, not zero. */
23905 if (lh
->is_valid_file_index (file
))
23907 const file_entry
*fe
= lh
->file_name_at (file
);
23909 if (!IS_ABSOLUTE_PATH (fe
->name
))
23911 const char *dir
= fe
->include_dir (lh
);
23913 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
23915 return xstrdup (fe
->name
);
23919 /* The compiler produced a bogus file number. We can at least
23920 record the macro definitions made in the file, even if we
23921 won't be able to find the file by name. */
23922 char fake_name
[80];
23924 xsnprintf (fake_name
, sizeof (fake_name
),
23925 "<bad macro file number %d>", file
);
23927 complaint (_("bad file number in macro information (%d)"),
23930 return xstrdup (fake_name
);
23934 /* Return the full name of file number I in *LH's file name table.
23935 Use COMP_DIR as the name of the current directory of the
23936 compilation. The result is allocated using xmalloc; the caller is
23937 responsible for freeing it. */
23939 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
23941 /* Is the file number a valid index into the line header's file name
23942 table? Remember that file numbers start with one, not zero. */
23943 if (lh
->is_valid_file_index (file
))
23945 char *relative
= file_file_name (file
, lh
);
23947 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
23949 return reconcat (relative
, comp_dir
, SLASH_STRING
,
23950 relative
, (char *) NULL
);
23953 return file_file_name (file
, lh
);
23957 static struct macro_source_file
*
23958 macro_start_file (struct dwarf2_cu
*cu
,
23959 int file
, int line
,
23960 struct macro_source_file
*current_file
,
23961 struct line_header
*lh
)
23963 /* File name relative to the compilation directory of this source file. */
23964 char *file_name
= file_file_name (file
, lh
);
23966 if (! current_file
)
23968 /* Note: We don't create a macro table for this compilation unit
23969 at all until we actually get a filename. */
23970 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
23972 /* If we have no current file, then this must be the start_file
23973 directive for the compilation unit's main source file. */
23974 current_file
= macro_set_main (macro_table
, file_name
);
23975 macro_define_special (macro_table
);
23978 current_file
= macro_include (current_file
, line
, file_name
);
23982 return current_file
;
23985 static const char *
23986 consume_improper_spaces (const char *p
, const char *body
)
23990 complaint (_("macro definition contains spaces "
23991 "in formal argument list:\n`%s'"),
24003 parse_macro_definition (struct macro_source_file
*file
, int line
,
24008 /* The body string takes one of two forms. For object-like macro
24009 definitions, it should be:
24011 <macro name> " " <definition>
24013 For function-like macro definitions, it should be:
24015 <macro name> "() " <definition>
24017 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24019 Spaces may appear only where explicitly indicated, and in the
24022 The Dwarf 2 spec says that an object-like macro's name is always
24023 followed by a space, but versions of GCC around March 2002 omit
24024 the space when the macro's definition is the empty string.
24026 The Dwarf 2 spec says that there should be no spaces between the
24027 formal arguments in a function-like macro's formal argument list,
24028 but versions of GCC around March 2002 include spaces after the
24032 /* Find the extent of the macro name. The macro name is terminated
24033 by either a space or null character (for an object-like macro) or
24034 an opening paren (for a function-like macro). */
24035 for (p
= body
; *p
; p
++)
24036 if (*p
== ' ' || *p
== '(')
24039 if (*p
== ' ' || *p
== '\0')
24041 /* It's an object-like macro. */
24042 int name_len
= p
- body
;
24043 std::string
name (body
, name_len
);
24044 const char *replacement
;
24047 replacement
= body
+ name_len
+ 1;
24050 dwarf2_macro_malformed_definition_complaint (body
);
24051 replacement
= body
+ name_len
;
24054 macro_define_object (file
, line
, name
.c_str (), replacement
);
24056 else if (*p
== '(')
24058 /* It's a function-like macro. */
24059 std::string
name (body
, p
- body
);
24062 char **argv
= XNEWVEC (char *, argv_size
);
24066 p
= consume_improper_spaces (p
, body
);
24068 /* Parse the formal argument list. */
24069 while (*p
&& *p
!= ')')
24071 /* Find the extent of the current argument name. */
24072 const char *arg_start
= p
;
24074 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24077 if (! *p
|| p
== arg_start
)
24078 dwarf2_macro_malformed_definition_complaint (body
);
24081 /* Make sure argv has room for the new argument. */
24082 if (argc
>= argv_size
)
24085 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24088 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24091 p
= consume_improper_spaces (p
, body
);
24093 /* Consume the comma, if present. */
24098 p
= consume_improper_spaces (p
, body
);
24107 /* Perfectly formed definition, no complaints. */
24108 macro_define_function (file
, line
, name
.c_str (),
24109 argc
, (const char **) argv
,
24111 else if (*p
== '\0')
24113 /* Complain, but do define it. */
24114 dwarf2_macro_malformed_definition_complaint (body
);
24115 macro_define_function (file
, line
, name
.c_str (),
24116 argc
, (const char **) argv
,
24120 /* Just complain. */
24121 dwarf2_macro_malformed_definition_complaint (body
);
24124 /* Just complain. */
24125 dwarf2_macro_malformed_definition_complaint (body
);
24130 for (i
= 0; i
< argc
; i
++)
24136 dwarf2_macro_malformed_definition_complaint (body
);
24139 /* Skip some bytes from BYTES according to the form given in FORM.
24140 Returns the new pointer. */
24142 static const gdb_byte
*
24143 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24144 enum dwarf_form form
,
24145 unsigned int offset_size
,
24146 struct dwarf2_section_info
*section
)
24148 unsigned int bytes_read
;
24152 case DW_FORM_data1
:
24157 case DW_FORM_data2
:
24161 case DW_FORM_data4
:
24165 case DW_FORM_data8
:
24169 case DW_FORM_data16
:
24173 case DW_FORM_string
:
24174 read_direct_string (abfd
, bytes
, &bytes_read
);
24175 bytes
+= bytes_read
;
24178 case DW_FORM_sec_offset
:
24180 case DW_FORM_GNU_strp_alt
:
24181 bytes
+= offset_size
;
24184 case DW_FORM_block
:
24185 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24186 bytes
+= bytes_read
;
24189 case DW_FORM_block1
:
24190 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24192 case DW_FORM_block2
:
24193 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24195 case DW_FORM_block4
:
24196 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24199 case DW_FORM_addrx
:
24200 case DW_FORM_sdata
:
24202 case DW_FORM_udata
:
24203 case DW_FORM_GNU_addr_index
:
24204 case DW_FORM_GNU_str_index
:
24205 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24208 dwarf2_section_buffer_overflow_complaint (section
);
24213 case DW_FORM_implicit_const
:
24218 complaint (_("invalid form 0x%x in `%s'"),
24219 form
, section
->get_name ());
24227 /* A helper for dwarf_decode_macros that handles skipping an unknown
24228 opcode. Returns an updated pointer to the macro data buffer; or,
24229 on error, issues a complaint and returns NULL. */
24231 static const gdb_byte
*
24232 skip_unknown_opcode (unsigned int opcode
,
24233 const gdb_byte
**opcode_definitions
,
24234 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24236 unsigned int offset_size
,
24237 struct dwarf2_section_info
*section
)
24239 unsigned int bytes_read
, i
;
24241 const gdb_byte
*defn
;
24243 if (opcode_definitions
[opcode
] == NULL
)
24245 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24250 defn
= opcode_definitions
[opcode
];
24251 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24252 defn
+= bytes_read
;
24254 for (i
= 0; i
< arg
; ++i
)
24256 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24257 (enum dwarf_form
) defn
[i
], offset_size
,
24259 if (mac_ptr
== NULL
)
24261 /* skip_form_bytes already issued the complaint. */
24269 /* A helper function which parses the header of a macro section.
24270 If the macro section is the extended (for now called "GNU") type,
24271 then this updates *OFFSET_SIZE. Returns a pointer to just after
24272 the header, or issues a complaint and returns NULL on error. */
24274 static const gdb_byte
*
24275 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24277 const gdb_byte
*mac_ptr
,
24278 unsigned int *offset_size
,
24279 int section_is_gnu
)
24281 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24283 if (section_is_gnu
)
24285 unsigned int version
, flags
;
24287 version
= read_2_bytes (abfd
, mac_ptr
);
24288 if (version
!= 4 && version
!= 5)
24290 complaint (_("unrecognized version `%d' in .debug_macro section"),
24296 flags
= read_1_byte (abfd
, mac_ptr
);
24298 *offset_size
= (flags
& 1) ? 8 : 4;
24300 if ((flags
& 2) != 0)
24301 /* We don't need the line table offset. */
24302 mac_ptr
+= *offset_size
;
24304 /* Vendor opcode descriptions. */
24305 if ((flags
& 4) != 0)
24307 unsigned int i
, count
;
24309 count
= read_1_byte (abfd
, mac_ptr
);
24311 for (i
= 0; i
< count
; ++i
)
24313 unsigned int opcode
, bytes_read
;
24316 opcode
= read_1_byte (abfd
, mac_ptr
);
24318 opcode_definitions
[opcode
] = mac_ptr
;
24319 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24320 mac_ptr
+= bytes_read
;
24329 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24330 including DW_MACRO_import. */
24333 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24335 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24336 struct macro_source_file
*current_file
,
24337 struct line_header
*lh
,
24338 struct dwarf2_section_info
*section
,
24339 int section_is_gnu
, int section_is_dwz
,
24340 unsigned int offset_size
,
24341 htab_t include_hash
)
24343 struct dwarf2_per_objfile
*dwarf2_per_objfile
24344 = cu
->per_cu
->dwarf2_per_objfile
;
24345 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24346 enum dwarf_macro_record_type macinfo_type
;
24347 int at_commandline
;
24348 const gdb_byte
*opcode_definitions
[256];
24350 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24351 &offset_size
, section_is_gnu
);
24352 if (mac_ptr
== NULL
)
24354 /* We already issued a complaint. */
24358 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24359 GDB is still reading the definitions from command line. First
24360 DW_MACINFO_start_file will need to be ignored as it was already executed
24361 to create CURRENT_FILE for the main source holding also the command line
24362 definitions. On first met DW_MACINFO_start_file this flag is reset to
24363 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24365 at_commandline
= 1;
24369 /* Do we at least have room for a macinfo type byte? */
24370 if (mac_ptr
>= mac_end
)
24372 dwarf2_section_buffer_overflow_complaint (section
);
24376 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24379 /* Note that we rely on the fact that the corresponding GNU and
24380 DWARF constants are the same. */
24382 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24383 switch (macinfo_type
)
24385 /* A zero macinfo type indicates the end of the macro
24390 case DW_MACRO_define
:
24391 case DW_MACRO_undef
:
24392 case DW_MACRO_define_strp
:
24393 case DW_MACRO_undef_strp
:
24394 case DW_MACRO_define_sup
:
24395 case DW_MACRO_undef_sup
:
24397 unsigned int bytes_read
;
24402 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24403 mac_ptr
+= bytes_read
;
24405 if (macinfo_type
== DW_MACRO_define
24406 || macinfo_type
== DW_MACRO_undef
)
24408 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24409 mac_ptr
+= bytes_read
;
24413 LONGEST str_offset
;
24415 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24416 mac_ptr
+= offset_size
;
24418 if (macinfo_type
== DW_MACRO_define_sup
24419 || macinfo_type
== DW_MACRO_undef_sup
24422 struct dwz_file
*dwz
24423 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24425 body
= read_indirect_string_from_dwz (objfile
,
24429 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24433 is_define
= (macinfo_type
== DW_MACRO_define
24434 || macinfo_type
== DW_MACRO_define_strp
24435 || macinfo_type
== DW_MACRO_define_sup
);
24436 if (! current_file
)
24438 /* DWARF violation as no main source is present. */
24439 complaint (_("debug info with no main source gives macro %s "
24441 is_define
? _("definition") : _("undefinition"),
24445 if ((line
== 0 && !at_commandline
)
24446 || (line
!= 0 && at_commandline
))
24447 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24448 at_commandline
? _("command-line") : _("in-file"),
24449 is_define
? _("definition") : _("undefinition"),
24450 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24454 /* Fedora's rpm-build's "debugedit" binary
24455 corrupted .debug_macro sections.
24458 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24459 complaint (_("debug info gives %s invalid macro %s "
24460 "without body (corrupted?) at line %d "
24462 at_commandline
? _("command-line") : _("in-file"),
24463 is_define
? _("definition") : _("undefinition"),
24464 line
, current_file
->filename
);
24466 else if (is_define
)
24467 parse_macro_definition (current_file
, line
, body
);
24470 gdb_assert (macinfo_type
== DW_MACRO_undef
24471 || macinfo_type
== DW_MACRO_undef_strp
24472 || macinfo_type
== DW_MACRO_undef_sup
);
24473 macro_undef (current_file
, line
, body
);
24478 case DW_MACRO_start_file
:
24480 unsigned int bytes_read
;
24483 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24484 mac_ptr
+= bytes_read
;
24485 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24486 mac_ptr
+= bytes_read
;
24488 if ((line
== 0 && !at_commandline
)
24489 || (line
!= 0 && at_commandline
))
24490 complaint (_("debug info gives source %d included "
24491 "from %s at %s line %d"),
24492 file
, at_commandline
? _("command-line") : _("file"),
24493 line
== 0 ? _("zero") : _("non-zero"), line
);
24495 if (at_commandline
)
24497 /* This DW_MACRO_start_file was executed in the
24499 at_commandline
= 0;
24502 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24507 case DW_MACRO_end_file
:
24508 if (! current_file
)
24509 complaint (_("macro debug info has an unmatched "
24510 "`close_file' directive"));
24513 current_file
= current_file
->included_by
;
24514 if (! current_file
)
24516 enum dwarf_macro_record_type next_type
;
24518 /* GCC circa March 2002 doesn't produce the zero
24519 type byte marking the end of the compilation
24520 unit. Complain if it's not there, but exit no
24523 /* Do we at least have room for a macinfo type byte? */
24524 if (mac_ptr
>= mac_end
)
24526 dwarf2_section_buffer_overflow_complaint (section
);
24530 /* We don't increment mac_ptr here, so this is just
24533 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24535 if (next_type
!= 0)
24536 complaint (_("no terminating 0-type entry for "
24537 "macros in `.debug_macinfo' section"));
24544 case DW_MACRO_import
:
24545 case DW_MACRO_import_sup
:
24549 bfd
*include_bfd
= abfd
;
24550 struct dwarf2_section_info
*include_section
= section
;
24551 const gdb_byte
*include_mac_end
= mac_end
;
24552 int is_dwz
= section_is_dwz
;
24553 const gdb_byte
*new_mac_ptr
;
24555 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24556 mac_ptr
+= offset_size
;
24558 if (macinfo_type
== DW_MACRO_import_sup
)
24560 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24562 dwz
->macro
.read (objfile
);
24564 include_section
= &dwz
->macro
;
24565 include_bfd
= include_section
->get_bfd_owner ();
24566 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24570 new_mac_ptr
= include_section
->buffer
+ offset
;
24571 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24575 /* This has actually happened; see
24576 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24577 complaint (_("recursive DW_MACRO_import in "
24578 ".debug_macro section"));
24582 *slot
= (void *) new_mac_ptr
;
24584 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24585 include_mac_end
, current_file
, lh
,
24586 section
, section_is_gnu
, is_dwz
,
24587 offset_size
, include_hash
);
24589 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24594 case DW_MACINFO_vendor_ext
:
24595 if (!section_is_gnu
)
24597 unsigned int bytes_read
;
24599 /* This reads the constant, but since we don't recognize
24600 any vendor extensions, we ignore it. */
24601 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24602 mac_ptr
+= bytes_read
;
24603 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24604 mac_ptr
+= bytes_read
;
24606 /* We don't recognize any vendor extensions. */
24612 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24613 mac_ptr
, mac_end
, abfd
, offset_size
,
24615 if (mac_ptr
== NULL
)
24620 } while (macinfo_type
!= 0);
24624 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24625 int section_is_gnu
)
24627 struct dwarf2_per_objfile
*dwarf2_per_objfile
24628 = cu
->per_cu
->dwarf2_per_objfile
;
24629 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24630 struct line_header
*lh
= cu
->line_header
;
24632 const gdb_byte
*mac_ptr
, *mac_end
;
24633 struct macro_source_file
*current_file
= 0;
24634 enum dwarf_macro_record_type macinfo_type
;
24635 unsigned int offset_size
= cu
->header
.offset_size
;
24636 const gdb_byte
*opcode_definitions
[256];
24638 struct dwarf2_section_info
*section
;
24639 const char *section_name
;
24641 if (cu
->dwo_unit
!= NULL
)
24643 if (section_is_gnu
)
24645 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24646 section_name
= ".debug_macro.dwo";
24650 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24651 section_name
= ".debug_macinfo.dwo";
24656 if (section_is_gnu
)
24658 section
= &dwarf2_per_objfile
->macro
;
24659 section_name
= ".debug_macro";
24663 section
= &dwarf2_per_objfile
->macinfo
;
24664 section_name
= ".debug_macinfo";
24668 section
->read (objfile
);
24669 if (section
->buffer
== NULL
)
24671 complaint (_("missing %s section"), section_name
);
24674 abfd
= section
->get_bfd_owner ();
24676 /* First pass: Find the name of the base filename.
24677 This filename is needed in order to process all macros whose definition
24678 (or undefinition) comes from the command line. These macros are defined
24679 before the first DW_MACINFO_start_file entry, and yet still need to be
24680 associated to the base file.
24682 To determine the base file name, we scan the macro definitions until we
24683 reach the first DW_MACINFO_start_file entry. We then initialize
24684 CURRENT_FILE accordingly so that any macro definition found before the
24685 first DW_MACINFO_start_file can still be associated to the base file. */
24687 mac_ptr
= section
->buffer
+ offset
;
24688 mac_end
= section
->buffer
+ section
->size
;
24690 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24691 &offset_size
, section_is_gnu
);
24692 if (mac_ptr
== NULL
)
24694 /* We already issued a complaint. */
24700 /* Do we at least have room for a macinfo type byte? */
24701 if (mac_ptr
>= mac_end
)
24703 /* Complaint is printed during the second pass as GDB will probably
24704 stop the first pass earlier upon finding
24705 DW_MACINFO_start_file. */
24709 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24712 /* Note that we rely on the fact that the corresponding GNU and
24713 DWARF constants are the same. */
24715 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24716 switch (macinfo_type
)
24718 /* A zero macinfo type indicates the end of the macro
24723 case DW_MACRO_define
:
24724 case DW_MACRO_undef
:
24725 /* Only skip the data by MAC_PTR. */
24727 unsigned int bytes_read
;
24729 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24730 mac_ptr
+= bytes_read
;
24731 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24732 mac_ptr
+= bytes_read
;
24736 case DW_MACRO_start_file
:
24738 unsigned int bytes_read
;
24741 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24742 mac_ptr
+= bytes_read
;
24743 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24744 mac_ptr
+= bytes_read
;
24746 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
24750 case DW_MACRO_end_file
:
24751 /* No data to skip by MAC_PTR. */
24754 case DW_MACRO_define_strp
:
24755 case DW_MACRO_undef_strp
:
24756 case DW_MACRO_define_sup
:
24757 case DW_MACRO_undef_sup
:
24759 unsigned int bytes_read
;
24761 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24762 mac_ptr
+= bytes_read
;
24763 mac_ptr
+= offset_size
;
24767 case DW_MACRO_import
:
24768 case DW_MACRO_import_sup
:
24769 /* Note that, according to the spec, a transparent include
24770 chain cannot call DW_MACRO_start_file. So, we can just
24771 skip this opcode. */
24772 mac_ptr
+= offset_size
;
24775 case DW_MACINFO_vendor_ext
:
24776 /* Only skip the data by MAC_PTR. */
24777 if (!section_is_gnu
)
24779 unsigned int bytes_read
;
24781 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24782 mac_ptr
+= bytes_read
;
24783 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24784 mac_ptr
+= bytes_read
;
24789 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24790 mac_ptr
, mac_end
, abfd
, offset_size
,
24792 if (mac_ptr
== NULL
)
24797 } while (macinfo_type
!= 0 && current_file
== NULL
);
24799 /* Second pass: Process all entries.
24801 Use the AT_COMMAND_LINE flag to determine whether we are still processing
24802 command-line macro definitions/undefinitions. This flag is unset when we
24803 reach the first DW_MACINFO_start_file entry. */
24805 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
24807 NULL
, xcalloc
, xfree
));
24808 mac_ptr
= section
->buffer
+ offset
;
24809 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
24810 *slot
= (void *) mac_ptr
;
24811 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
24812 current_file
, lh
, section
,
24813 section_is_gnu
, 0, offset_size
,
24814 include_hash
.get ());
24817 /* Check if the attribute's form is a DW_FORM_block*
24818 if so return true else false. */
24821 attr_form_is_block (const struct attribute
*attr
)
24823 return (attr
== NULL
? 0 :
24824 attr
->form
== DW_FORM_block1
24825 || attr
->form
== DW_FORM_block2
24826 || attr
->form
== DW_FORM_block4
24827 || attr
->form
== DW_FORM_block
24828 || attr
->form
== DW_FORM_exprloc
);
24831 /* Return non-zero if ATTR's value is a section offset --- classes
24832 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
24833 You may use DW_UNSND (attr) to retrieve such offsets.
24835 Section 7.5.4, "Attribute Encodings", explains that no attribute
24836 may have a value that belongs to more than one of these classes; it
24837 would be ambiguous if we did, because we use the same forms for all
24841 attr_form_is_section_offset (const struct attribute
*attr
)
24843 return (attr
->form
== DW_FORM_data4
24844 || attr
->form
== DW_FORM_data8
24845 || attr
->form
== DW_FORM_sec_offset
);
24848 /* Return non-zero if ATTR's value falls in the 'constant' class, or
24849 zero otherwise. When this function returns true, you can apply
24850 dwarf2_get_attr_constant_value to it.
24852 However, note that for some attributes you must check
24853 attr_form_is_section_offset before using this test. DW_FORM_data4
24854 and DW_FORM_data8 are members of both the constant class, and of
24855 the classes that contain offsets into other debug sections
24856 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
24857 that, if an attribute's can be either a constant or one of the
24858 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
24859 taken as section offsets, not constants.
24861 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
24862 cannot handle that. */
24865 attr_form_is_constant (const struct attribute
*attr
)
24867 switch (attr
->form
)
24869 case DW_FORM_sdata
:
24870 case DW_FORM_udata
:
24871 case DW_FORM_data1
:
24872 case DW_FORM_data2
:
24873 case DW_FORM_data4
:
24874 case DW_FORM_data8
:
24875 case DW_FORM_implicit_const
:
24883 /* DW_ADDR is always stored already as sect_offset; despite for the forms
24884 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
24887 attr_form_is_ref (const struct attribute
*attr
)
24889 switch (attr
->form
)
24891 case DW_FORM_ref_addr
:
24896 case DW_FORM_ref_udata
:
24897 case DW_FORM_GNU_ref_alt
:
24904 /* Return the .debug_loc section to use for CU.
24905 For DWO files use .debug_loc.dwo. */
24907 static struct dwarf2_section_info
*
24908 cu_debug_loc_section (struct dwarf2_cu
*cu
)
24910 struct dwarf2_per_objfile
*dwarf2_per_objfile
24911 = cu
->per_cu
->dwarf2_per_objfile
;
24915 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
24917 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
24919 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
24920 : &dwarf2_per_objfile
->loc
);
24923 /* A helper function that fills in a dwarf2_loclist_baton. */
24926 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
24927 struct dwarf2_loclist_baton
*baton
,
24928 const struct attribute
*attr
)
24930 struct dwarf2_per_objfile
*dwarf2_per_objfile
24931 = cu
->per_cu
->dwarf2_per_objfile
;
24932 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24934 section
->read (dwarf2_per_objfile
->objfile
);
24936 baton
->per_cu
= cu
->per_cu
;
24937 gdb_assert (baton
->per_cu
);
24938 /* We don't know how long the location list is, but make sure we
24939 don't run off the edge of the section. */
24940 baton
->size
= section
->size
- DW_UNSND (attr
);
24941 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
24942 baton
->base_address
= cu
->base_address
;
24943 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
24947 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
24948 struct dwarf2_cu
*cu
, int is_block
)
24950 struct dwarf2_per_objfile
*dwarf2_per_objfile
24951 = cu
->per_cu
->dwarf2_per_objfile
;
24952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24953 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
24955 if (attr_form_is_section_offset (attr
)
24956 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
24957 the section. If so, fall through to the complaint in the
24959 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
24961 struct dwarf2_loclist_baton
*baton
;
24963 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
24965 fill_in_loclist_baton (cu
, baton
, attr
);
24967 if (cu
->base_known
== 0)
24968 complaint (_("Location list used without "
24969 "specifying the CU base address."));
24971 SYMBOL_ACLASS_INDEX (sym
) = (is_block
24972 ? dwarf2_loclist_block_index
24973 : dwarf2_loclist_index
);
24974 SYMBOL_LOCATION_BATON (sym
) = baton
;
24978 struct dwarf2_locexpr_baton
*baton
;
24980 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
24981 baton
->per_cu
= cu
->per_cu
;
24982 gdb_assert (baton
->per_cu
);
24984 if (attr_form_is_block (attr
))
24986 /* Note that we're just copying the block's data pointer
24987 here, not the actual data. We're still pointing into the
24988 info_buffer for SYM's objfile; right now we never release
24989 that buffer, but when we do clean up properly this may
24991 baton
->size
= DW_BLOCK (attr
)->size
;
24992 baton
->data
= DW_BLOCK (attr
)->data
;
24996 dwarf2_invalid_attrib_class_complaint ("location description",
24997 sym
->natural_name ());
25001 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25002 ? dwarf2_locexpr_block_index
25003 : dwarf2_locexpr_index
);
25004 SYMBOL_LOCATION_BATON (sym
) = baton
;
25008 /* Return the OBJFILE associated with the compilation unit CU. If CU
25009 came from a separate debuginfo file, then the master objfile is
25013 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25015 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25017 /* Return the master objfile, so that we can report and look up the
25018 correct file containing this variable. */
25019 if (objfile
->separate_debug_objfile_backlink
)
25020 objfile
= objfile
->separate_debug_objfile_backlink
;
25025 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25026 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25027 CU_HEADERP first. */
25029 static const struct comp_unit_head
*
25030 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25031 struct dwarf2_per_cu_data
*per_cu
)
25033 const gdb_byte
*info_ptr
;
25036 return &per_cu
->cu
->header
;
25038 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25040 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25041 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25042 rcuh_kind::COMPILE
);
25047 /* Return the address size given in the compilation unit header for CU. */
25050 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25052 struct comp_unit_head cu_header_local
;
25053 const struct comp_unit_head
*cu_headerp
;
25055 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25057 return cu_headerp
->addr_size
;
25060 /* Return the offset size given in the compilation unit header for CU. */
25063 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25065 struct comp_unit_head cu_header_local
;
25066 const struct comp_unit_head
*cu_headerp
;
25068 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25070 return cu_headerp
->offset_size
;
25073 /* See its dwarf2loc.h declaration. */
25076 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25078 struct comp_unit_head cu_header_local
;
25079 const struct comp_unit_head
*cu_headerp
;
25081 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25083 if (cu_headerp
->version
== 2)
25084 return cu_headerp
->addr_size
;
25086 return cu_headerp
->offset_size
;
25089 /* Return the text offset of the CU. The returned offset comes from
25090 this CU's objfile. If this objfile came from a separate debuginfo
25091 file, then the offset may be different from the corresponding
25092 offset in the parent objfile. */
25095 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25097 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25100 /* Return a type that is a generic pointer type, the size of which matches
25101 the address size given in the compilation unit header for PER_CU. */
25102 static struct type
*
25103 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25105 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25106 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25107 struct type
*addr_type
= lookup_pointer_type (void_type
);
25108 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25110 if (TYPE_LENGTH (addr_type
) == addr_size
)
25114 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25118 /* Return DWARF version number of PER_CU. */
25121 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25123 return per_cu
->dwarf_version
;
25126 /* Locate the .debug_info compilation unit from CU's objfile which contains
25127 the DIE at OFFSET. Raises an error on failure. */
25129 static struct dwarf2_per_cu_data
*
25130 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25131 unsigned int offset_in_dwz
,
25132 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25134 struct dwarf2_per_cu_data
*this_cu
;
25138 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25141 struct dwarf2_per_cu_data
*mid_cu
;
25142 int mid
= low
+ (high
- low
) / 2;
25144 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25145 if (mid_cu
->is_dwz
> offset_in_dwz
25146 || (mid_cu
->is_dwz
== offset_in_dwz
25147 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25152 gdb_assert (low
== high
);
25153 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25154 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25156 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25157 error (_("Dwarf Error: could not find partial DIE containing "
25158 "offset %s [in module %s]"),
25159 sect_offset_str (sect_off
),
25160 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25162 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25164 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25168 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25169 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25170 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25171 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25176 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25178 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25179 : per_cu (per_cu_
),
25181 has_loclist (false),
25182 checked_producer (false),
25183 producer_is_gxx_lt_4_6 (false),
25184 producer_is_gcc_lt_4_3 (false),
25185 producer_is_icc (false),
25186 producer_is_icc_lt_14 (false),
25187 producer_is_codewarrior (false),
25188 processing_has_namespace_info (false)
25193 /* Destroy a dwarf2_cu. */
25195 dwarf2_cu::~dwarf2_cu ()
25200 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25203 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25204 enum language pretend_language
)
25206 struct attribute
*attr
;
25208 /* Set the language we're debugging. */
25209 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25210 if (attr
!= nullptr)
25211 set_cu_language (DW_UNSND (attr
), cu
);
25214 cu
->language
= pretend_language
;
25215 cu
->language_defn
= language_def (cu
->language
);
25218 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25221 /* Increase the age counter on each cached compilation unit, and free
25222 any that are too old. */
25225 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25227 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25229 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25230 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25231 while (per_cu
!= NULL
)
25233 per_cu
->cu
->last_used
++;
25234 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25235 dwarf2_mark (per_cu
->cu
);
25236 per_cu
= per_cu
->cu
->read_in_chain
;
25239 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25240 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25241 while (per_cu
!= NULL
)
25243 struct dwarf2_per_cu_data
*next_cu
;
25245 next_cu
= per_cu
->cu
->read_in_chain
;
25247 if (!per_cu
->cu
->mark
)
25250 *last_chain
= next_cu
;
25253 last_chain
= &per_cu
->cu
->read_in_chain
;
25259 /* Remove a single compilation unit from the cache. */
25262 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25264 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25265 struct dwarf2_per_objfile
*dwarf2_per_objfile
25266 = target_per_cu
->dwarf2_per_objfile
;
25268 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25269 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25270 while (per_cu
!= NULL
)
25272 struct dwarf2_per_cu_data
*next_cu
;
25274 next_cu
= per_cu
->cu
->read_in_chain
;
25276 if (per_cu
== target_per_cu
)
25280 *last_chain
= next_cu
;
25284 last_chain
= &per_cu
->cu
->read_in_chain
;
25290 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25291 We store these in a hash table separate from the DIEs, and preserve them
25292 when the DIEs are flushed out of cache.
25294 The CU "per_cu" pointer is needed because offset alone is not enough to
25295 uniquely identify the type. A file may have multiple .debug_types sections,
25296 or the type may come from a DWO file. Furthermore, while it's more logical
25297 to use per_cu->section+offset, with Fission the section with the data is in
25298 the DWO file but we don't know that section at the point we need it.
25299 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25300 because we can enter the lookup routine, get_die_type_at_offset, from
25301 outside this file, and thus won't necessarily have PER_CU->cu.
25302 Fortunately, PER_CU is stable for the life of the objfile. */
25304 struct dwarf2_per_cu_offset_and_type
25306 const struct dwarf2_per_cu_data
*per_cu
;
25307 sect_offset sect_off
;
25311 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25314 per_cu_offset_and_type_hash (const void *item
)
25316 const struct dwarf2_per_cu_offset_and_type
*ofs
25317 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25319 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25322 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25325 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25327 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25328 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25329 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25330 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25332 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25333 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25336 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25337 table if necessary. For convenience, return TYPE.
25339 The DIEs reading must have careful ordering to:
25340 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25341 reading current DIE.
25342 * Not trying to dereference contents of still incompletely read in types
25343 while reading in other DIEs.
25344 * Enable referencing still incompletely read in types just by a pointer to
25345 the type without accessing its fields.
25347 Therefore caller should follow these rules:
25348 * Try to fetch any prerequisite types we may need to build this DIE type
25349 before building the type and calling set_die_type.
25350 * After building type call set_die_type for current DIE as soon as
25351 possible before fetching more types to complete the current type.
25352 * Make the type as complete as possible before fetching more types. */
25354 static struct type
*
25355 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25357 struct dwarf2_per_objfile
*dwarf2_per_objfile
25358 = cu
->per_cu
->dwarf2_per_objfile
;
25359 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25360 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25361 struct attribute
*attr
;
25362 struct dynamic_prop prop
;
25364 /* For Ada types, make sure that the gnat-specific data is always
25365 initialized (if not already set). There are a few types where
25366 we should not be doing so, because the type-specific area is
25367 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25368 where the type-specific area is used to store the floatformat).
25369 But this is not a problem, because the gnat-specific information
25370 is actually not needed for these types. */
25371 if (need_gnat_info (cu
)
25372 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25373 && TYPE_CODE (type
) != TYPE_CODE_FLT
25374 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25375 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25376 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25377 && !HAVE_GNAT_AUX_INFO (type
))
25378 INIT_GNAT_SPECIFIC (type
);
25380 /* Read DW_AT_allocated and set in type. */
25381 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25382 if (attr_form_is_block (attr
))
25384 struct type
*prop_type
25385 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25386 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25387 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25389 else if (attr
!= NULL
)
25391 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25392 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25393 sect_offset_str (die
->sect_off
));
25396 /* Read DW_AT_associated and set in type. */
25397 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25398 if (attr_form_is_block (attr
))
25400 struct type
*prop_type
25401 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25402 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25403 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25405 else if (attr
!= NULL
)
25407 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25408 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25409 sect_offset_str (die
->sect_off
));
25412 /* Read DW_AT_data_location and set in type. */
25413 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25414 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25415 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25416 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25418 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25420 dwarf2_per_objfile
->die_type_hash
=
25421 htab_create_alloc_ex (127,
25422 per_cu_offset_and_type_hash
,
25423 per_cu_offset_and_type_eq
,
25425 &objfile
->objfile_obstack
,
25426 hashtab_obstack_allocate
,
25427 dummy_obstack_deallocate
);
25430 ofs
.per_cu
= cu
->per_cu
;
25431 ofs
.sect_off
= die
->sect_off
;
25433 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25434 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25436 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25437 sect_offset_str (die
->sect_off
));
25438 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25439 struct dwarf2_per_cu_offset_and_type
);
25444 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25445 or return NULL if the die does not have a saved type. */
25447 static struct type
*
25448 get_die_type_at_offset (sect_offset sect_off
,
25449 struct dwarf2_per_cu_data
*per_cu
)
25451 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25452 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25454 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25457 ofs
.per_cu
= per_cu
;
25458 ofs
.sect_off
= sect_off
;
25459 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25460 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25467 /* Look up the type for DIE in CU in die_type_hash,
25468 or return NULL if DIE does not have a saved type. */
25470 static struct type
*
25471 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25473 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25476 /* Add a dependence relationship from CU to REF_PER_CU. */
25479 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25480 struct dwarf2_per_cu_data
*ref_per_cu
)
25484 if (cu
->dependencies
== NULL
)
25486 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25487 NULL
, &cu
->comp_unit_obstack
,
25488 hashtab_obstack_allocate
,
25489 dummy_obstack_deallocate
);
25491 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25493 *slot
= ref_per_cu
;
25496 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25497 Set the mark field in every compilation unit in the
25498 cache that we must keep because we are keeping CU. */
25501 dwarf2_mark_helper (void **slot
, void *data
)
25503 struct dwarf2_per_cu_data
*per_cu
;
25505 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25507 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25508 reading of the chain. As such dependencies remain valid it is not much
25509 useful to track and undo them during QUIT cleanups. */
25510 if (per_cu
->cu
== NULL
)
25513 if (per_cu
->cu
->mark
)
25515 per_cu
->cu
->mark
= true;
25517 if (per_cu
->cu
->dependencies
!= NULL
)
25518 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25523 /* Set the mark field in CU and in every other compilation unit in the
25524 cache that we must keep because we are keeping CU. */
25527 dwarf2_mark (struct dwarf2_cu
*cu
)
25532 if (cu
->dependencies
!= NULL
)
25533 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25537 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25541 per_cu
->cu
->mark
= false;
25542 per_cu
= per_cu
->cu
->read_in_chain
;
25546 /* Trivial hash function for partial_die_info: the hash value of a DIE
25547 is its offset in .debug_info for this objfile. */
25550 partial_die_hash (const void *item
)
25552 const struct partial_die_info
*part_die
25553 = (const struct partial_die_info
*) item
;
25555 return to_underlying (part_die
->sect_off
);
25558 /* Trivial comparison function for partial_die_info structures: two DIEs
25559 are equal if they have the same offset. */
25562 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25564 const struct partial_die_info
*part_die_lhs
25565 = (const struct partial_die_info
*) item_lhs
;
25566 const struct partial_die_info
*part_die_rhs
25567 = (const struct partial_die_info
*) item_rhs
;
25569 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25572 struct cmd_list_element
*set_dwarf_cmdlist
;
25573 struct cmd_list_element
*show_dwarf_cmdlist
;
25576 set_dwarf_cmd (const char *args
, int from_tty
)
25578 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25583 show_dwarf_cmd (const char *args
, int from_tty
)
25585 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25588 bool dwarf_always_disassemble
;
25591 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25592 struct cmd_list_element
*c
, const char *value
)
25594 fprintf_filtered (file
,
25595 _("Whether to always disassemble "
25596 "DWARF expressions is %s.\n"),
25601 show_check_physname (struct ui_file
*file
, int from_tty
,
25602 struct cmd_list_element
*c
, const char *value
)
25604 fprintf_filtered (file
,
25605 _("Whether to check \"physname\" is %s.\n"),
25609 void _initialize_dwarf2_read ();
25611 _initialize_dwarf2_read ()
25613 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25614 Set DWARF specific variables.\n\
25615 Configure DWARF variables such as the cache size."),
25616 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25617 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25619 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25620 Show DWARF specific variables.\n\
25621 Show DWARF variables such as the cache size."),
25622 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25623 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25625 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25626 &dwarf_max_cache_age
, _("\
25627 Set the upper bound on the age of cached DWARF compilation units."), _("\
25628 Show the upper bound on the age of cached DWARF compilation units."), _("\
25629 A higher limit means that cached compilation units will be stored\n\
25630 in memory longer, and more total memory will be used. Zero disables\n\
25631 caching, which can slow down startup."),
25633 show_dwarf_max_cache_age
,
25634 &set_dwarf_cmdlist
,
25635 &show_dwarf_cmdlist
);
25637 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25638 &dwarf_always_disassemble
, _("\
25639 Set whether `info address' always disassembles DWARF expressions."), _("\
25640 Show whether `info address' always disassembles DWARF expressions."), _("\
25641 When enabled, DWARF expressions are always printed in an assembly-like\n\
25642 syntax. When disabled, expressions will be printed in a more\n\
25643 conversational style, when possible."),
25645 show_dwarf_always_disassemble
,
25646 &set_dwarf_cmdlist
,
25647 &show_dwarf_cmdlist
);
25649 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25650 Set debugging of the DWARF reader."), _("\
25651 Show debugging of the DWARF reader."), _("\
25652 When enabled (non-zero), debugging messages are printed during DWARF\n\
25653 reading and symtab expansion. A value of 1 (one) provides basic\n\
25654 information. A value greater than 1 provides more verbose information."),
25657 &setdebuglist
, &showdebuglist
);
25659 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25660 Set debugging of the DWARF DIE reader."), _("\
25661 Show debugging of the DWARF DIE reader."), _("\
25662 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25663 The value is the maximum depth to print."),
25666 &setdebuglist
, &showdebuglist
);
25668 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25669 Set debugging of the dwarf line reader."), _("\
25670 Show debugging of the dwarf line reader."), _("\
25671 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25672 A value of 1 (one) provides basic information.\n\
25673 A value greater than 1 provides more verbose information."),
25676 &setdebuglist
, &showdebuglist
);
25678 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25679 Set cross-checking of \"physname\" code against demangler."), _("\
25680 Show cross-checking of \"physname\" code against demangler."), _("\
25681 When enabled, GDB's internal \"physname\" code is checked against\n\
25683 NULL
, show_check_physname
,
25684 &setdebuglist
, &showdebuglist
);
25686 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25687 no_class
, &use_deprecated_index_sections
, _("\
25688 Set whether to use deprecated gdb_index sections."), _("\
25689 Show whether to use deprecated gdb_index sections."), _("\
25690 When enabled, deprecated .gdb_index sections are used anyway.\n\
25691 Normally they are ignored either because of a missing feature or\n\
25692 performance issue.\n\
25693 Warning: This option must be enabled before gdb reads the file."),
25696 &setlist
, &showlist
);
25698 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25699 &dwarf2_locexpr_funcs
);
25700 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25701 &dwarf2_loclist_funcs
);
25703 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25704 &dwarf2_block_frame_base_locexpr_funcs
);
25705 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25706 &dwarf2_block_frame_base_loclist_funcs
);
25709 selftests::register_test ("dw2_expand_symtabs_matching",
25710 selftests::dw2_expand_symtabs_matching::run_test
);