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 "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
43 #include "gdb-demangle.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
48 #include "dwarf2expr.h"
49 #include "dwarf2loc.h"
50 #include "cp-support.h"
56 #include "typeprint.h"
61 #include "gdbcore.h" /* for gnutarget */
62 #include "gdb/gdb-index.h"
67 #include "namespace.h"
68 #include "gdbsupport/function-view.h"
69 #include "gdbsupport/gdb_optional.h"
70 #include "gdbsupport/underlying.h"
71 #include "gdbsupport/hash_enum.h"
72 #include "filename-seen-cache.h"
76 #include <unordered_map>
77 #include "gdbsupport/selftest.h"
78 #include "rust-lang.h"
79 #include "gdbsupport/pathstuff.h"
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When true, cross-check physname against demangler. */
93 static bool check_physname
= false;
95 /* When true, do not reject deprecated .gdb_index sections. */
96 static bool use_deprecated_index_sections
= false;
98 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* An index into a (C++) symbol name component in a symbol name as
108 recorded in the mapped_index's symbol table. For each C++ symbol
109 in the symbol table, we record one entry for the start of each
110 component in the symbol in a table of name components, and then
111 sort the table, in order to be able to binary search symbol names,
112 ignoring leading namespaces, both completion and regular look up.
113 For example, for symbol "A::B::C", we'll have an entry that points
114 to "A::B::C", another that points to "B::C", and another for "C".
115 Note that function symbols in GDB index have no parameter
116 information, just the function/method names. You can convert a
117 name_component to a "const char *" using the
118 'mapped_index::symbol_name_at(offset_type)' method. */
120 struct name_component
122 /* Offset in the symbol name where the component starts. Stored as
123 a (32-bit) offset instead of a pointer to save memory and improve
124 locality on 64-bit architectures. */
125 offset_type name_offset
;
127 /* The symbol's index in the symbol and constant pool tables of a
132 /* Base class containing bits shared by both .gdb_index and
133 .debug_name indexes. */
135 struct mapped_index_base
137 mapped_index_base () = default;
138 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
140 /* The name_component table (a sorted vector). See name_component's
141 description above. */
142 std::vector
<name_component
> name_components
;
144 /* How NAME_COMPONENTS is sorted. */
145 enum case_sensitivity name_components_casing
;
147 /* Return the number of names in the symbol table. */
148 virtual size_t symbol_name_count () const = 0;
150 /* Get the name of the symbol at IDX in the symbol table. */
151 virtual const char *symbol_name_at (offset_type idx
) const = 0;
153 /* Return whether the name at IDX in the symbol table should be
155 virtual bool symbol_name_slot_invalid (offset_type idx
) const
160 /* Build the symbol name component sorted vector, if we haven't
162 void build_name_components ();
164 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
165 possible matches for LN_NO_PARAMS in the name component
167 std::pair
<std::vector
<name_component
>::const_iterator
,
168 std::vector
<name_component
>::const_iterator
>
169 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
170 enum language lang
) const;
172 /* Prevent deleting/destroying via a base class pointer. */
174 ~mapped_index_base() = default;
177 /* A description of the mapped index. The file format is described in
178 a comment by the code that writes the index. */
179 struct mapped_index final
: public mapped_index_base
181 /* A slot/bucket in the symbol table hash. */
182 struct symbol_table_slot
184 const offset_type name
;
185 const offset_type vec
;
188 /* Index data format version. */
191 /* The address table data. */
192 gdb::array_view
<const gdb_byte
> address_table
;
194 /* The symbol table, implemented as a hash table. */
195 gdb::array_view
<symbol_table_slot
> symbol_table
;
197 /* A pointer to the constant pool. */
198 const char *constant_pool
= nullptr;
200 bool symbol_name_slot_invalid (offset_type idx
) const override
202 const auto &bucket
= this->symbol_table
[idx
];
203 return bucket
.name
== 0 && bucket
.vec
== 0;
206 /* Convenience method to get at the name of the symbol at IDX in the
208 const char *symbol_name_at (offset_type idx
) const override
209 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
211 size_t symbol_name_count () const override
212 { return this->symbol_table
.size (); }
215 /* A description of the mapped .debug_names.
216 Uninitialized map has CU_COUNT 0. */
217 struct mapped_debug_names final
: public mapped_index_base
219 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
220 : dwarf2_per_objfile (dwarf2_per_objfile_
)
223 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
224 bfd_endian dwarf5_byte_order
;
225 bool dwarf5_is_dwarf64
;
226 bool augmentation_is_gdb
;
228 uint32_t cu_count
= 0;
229 uint32_t tu_count
, bucket_count
, name_count
;
230 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
231 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
232 const gdb_byte
*name_table_string_offs_reordered
;
233 const gdb_byte
*name_table_entry_offs_reordered
;
234 const gdb_byte
*entry_pool
;
241 /* Attribute name DW_IDX_*. */
244 /* Attribute form DW_FORM_*. */
247 /* Value if FORM is DW_FORM_implicit_const. */
248 LONGEST implicit_const
;
250 std::vector
<attr
> attr_vec
;
253 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
255 const char *namei_to_name (uint32_t namei
) const;
257 /* Implementation of the mapped_index_base virtual interface, for
258 the name_components cache. */
260 const char *symbol_name_at (offset_type idx
) const override
261 { return namei_to_name (idx
); }
263 size_t symbol_name_count () const override
264 { return this->name_count
; }
267 /* See dwarf2read.h. */
270 get_dwarf2_per_objfile (struct objfile
*objfile
)
272 return dwarf2_objfile_data_key
.get (objfile
);
275 /* Default names of the debugging sections. */
277 /* Note that if the debugging section has been compressed, it might
278 have a name like .zdebug_info. */
280 static const struct dwarf2_debug_sections dwarf2_elf_names
=
282 { ".debug_info", ".zdebug_info" },
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_line", ".zdebug_line" },
285 { ".debug_loc", ".zdebug_loc" },
286 { ".debug_loclists", ".zdebug_loclists" },
287 { ".debug_macinfo", ".zdebug_macinfo" },
288 { ".debug_macro", ".zdebug_macro" },
289 { ".debug_str", ".zdebug_str" },
290 { ".debug_line_str", ".zdebug_line_str" },
291 { ".debug_ranges", ".zdebug_ranges" },
292 { ".debug_rnglists", ".zdebug_rnglists" },
293 { ".debug_types", ".zdebug_types" },
294 { ".debug_addr", ".zdebug_addr" },
295 { ".debug_frame", ".zdebug_frame" },
296 { ".eh_frame", NULL
},
297 { ".gdb_index", ".zgdb_index" },
298 { ".debug_names", ".zdebug_names" },
299 { ".debug_aranges", ".zdebug_aranges" },
303 /* List of DWO/DWP sections. */
305 static const struct dwop_section_names
307 struct dwarf2_section_names abbrev_dwo
;
308 struct dwarf2_section_names info_dwo
;
309 struct dwarf2_section_names line_dwo
;
310 struct dwarf2_section_names loc_dwo
;
311 struct dwarf2_section_names loclists_dwo
;
312 struct dwarf2_section_names macinfo_dwo
;
313 struct dwarf2_section_names macro_dwo
;
314 struct dwarf2_section_names str_dwo
;
315 struct dwarf2_section_names str_offsets_dwo
;
316 struct dwarf2_section_names types_dwo
;
317 struct dwarf2_section_names cu_index
;
318 struct dwarf2_section_names tu_index
;
322 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
323 { ".debug_info.dwo", ".zdebug_info.dwo" },
324 { ".debug_line.dwo", ".zdebug_line.dwo" },
325 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
326 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
327 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
328 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
329 { ".debug_str.dwo", ".zdebug_str.dwo" },
330 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
331 { ".debug_types.dwo", ".zdebug_types.dwo" },
332 { ".debug_cu_index", ".zdebug_cu_index" },
333 { ".debug_tu_index", ".zdebug_tu_index" },
336 /* local data types */
338 /* The data in a compilation unit header, after target2host
339 translation, looks like this. */
340 struct comp_unit_head
344 unsigned char addr_size
;
345 unsigned char signed_addr_p
;
346 sect_offset abbrev_sect_off
;
348 /* Size of file offsets; either 4 or 8. */
349 unsigned int offset_size
;
351 /* Size of the length field; either 4 or 12. */
352 unsigned int initial_length_size
;
354 enum dwarf_unit_type unit_type
;
356 /* Offset to the first byte of this compilation unit header in the
357 .debug_info section, for resolving relative reference dies. */
358 sect_offset sect_off
;
360 /* Offset to first die in this cu from the start of the cu.
361 This will be the first byte following the compilation unit header. */
362 cu_offset first_die_cu_offset
;
365 /* 64-bit signature of this unit. For type units, it denotes the signature of
366 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
367 Also used in DWARF 5, to denote the dwo id when the unit type is
368 DW_UT_skeleton or DW_UT_split_compile. */
371 /* For types, offset in the type's DIE of the type defined by this TU. */
372 cu_offset type_cu_offset_in_tu
;
375 /* Type used for delaying computation of method physnames.
376 See comments for compute_delayed_physnames. */
377 struct delayed_method_info
379 /* The type to which the method is attached, i.e., its parent class. */
382 /* The index of the method in the type's function fieldlists. */
385 /* The index of the method in the fieldlist. */
388 /* The name of the DIE. */
391 /* The DIE associated with this method. */
392 struct die_info
*die
;
395 /* Internal state when decoding a particular compilation unit. */
398 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
401 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
403 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
404 Create the set of symtabs used by this TU, or if this TU is sharing
405 symtabs with another TU and the symtabs have already been created
406 then restore those symtabs in the line header.
407 We don't need the pc/line-number mapping for type units. */
408 void setup_type_unit_groups (struct die_info
*die
);
410 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
411 buildsym_compunit constructor. */
412 struct compunit_symtab
*start_symtab (const char *name
,
413 const char *comp_dir
,
416 /* Reset the builder. */
417 void reset_builder () { m_builder
.reset (); }
419 /* The header of the compilation unit. */
420 struct comp_unit_head header
{};
422 /* Base address of this compilation unit. */
423 CORE_ADDR base_address
= 0;
425 /* Non-zero if base_address has been set. */
428 /* The language we are debugging. */
429 enum language language
= language_unknown
;
430 const struct language_defn
*language_defn
= nullptr;
432 const char *producer
= nullptr;
435 /* The symtab builder for this CU. This is only non-NULL when full
436 symbols are being read. */
437 std::unique_ptr
<buildsym_compunit
> m_builder
;
440 /* The generic symbol table building routines have separate lists for
441 file scope symbols and all all other scopes (local scopes). So
442 we need to select the right one to pass to add_symbol_to_list().
443 We do it by keeping a pointer to the correct list in list_in_scope.
445 FIXME: The original dwarf code just treated the file scope as the
446 first local scope, and all other local scopes as nested local
447 scopes, and worked fine. Check to see if we really need to
448 distinguish these in buildsym.c. */
449 struct pending
**list_in_scope
= nullptr;
451 /* Hash table holding all the loaded partial DIEs
452 with partial_die->offset.SECT_OFF as hash. */
453 htab_t partial_dies
= nullptr;
455 /* Storage for things with the same lifetime as this read-in compilation
456 unit, including partial DIEs. */
457 auto_obstack comp_unit_obstack
;
459 /* When multiple dwarf2_cu structures are living in memory, this field
460 chains them all together, so that they can be released efficiently.
461 We will probably also want a generation counter so that most-recently-used
462 compilation units are cached... */
463 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
465 /* Backlink to our per_cu entry. */
466 struct dwarf2_per_cu_data
*per_cu
;
468 /* How many compilation units ago was this CU last referenced? */
471 /* A hash table of DIE cu_offset for following references with
472 die_info->offset.sect_off as hash. */
473 htab_t die_hash
= nullptr;
475 /* Full DIEs if read in. */
476 struct die_info
*dies
= nullptr;
478 /* A set of pointers to dwarf2_per_cu_data objects for compilation
479 units referenced by this one. Only set during full symbol processing;
480 partial symbol tables do not have dependencies. */
481 htab_t dependencies
= nullptr;
483 /* Header data from the line table, during full symbol processing. */
484 struct line_header
*line_header
= nullptr;
485 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
486 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
487 this is the DW_TAG_compile_unit die for this CU. We'll hold on
488 to the line header as long as this DIE is being processed. See
489 process_die_scope. */
490 die_info
*line_header_die_owner
= nullptr;
492 /* A list of methods which need to have physnames computed
493 after all type information has been read. */
494 std::vector
<delayed_method_info
> method_list
;
496 /* To be copied to symtab->call_site_htab. */
497 htab_t call_site_htab
= nullptr;
499 /* Non-NULL if this CU came from a DWO file.
500 There is an invariant here that is important to remember:
501 Except for attributes copied from the top level DIE in the "main"
502 (or "stub") file in preparation for reading the DWO file
503 (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU.
504 Either there isn't a DWO file (in which case this is NULL and the point
505 is moot), or there is and either we're not going to read it (in which
506 case this is NULL) or there is and we are reading it (in which case this
508 struct dwo_unit
*dwo_unit
= nullptr;
510 /* The DW_AT_addr_base attribute if present, zero otherwise
511 (zero is a valid value though).
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 ULONGEST addr_base
= 0;
515 /* The DW_AT_ranges_base attribute if present, zero otherwise
516 (zero is a valid value though).
517 Note this value comes from the Fission stub CU/TU's DIE.
518 Also note that the value is zero in the non-DWO case so this value can
519 be used without needing to know whether DWO files are in use or not.
520 N.B. This does not apply to DW_AT_ranges appearing in
521 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
522 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
523 DW_AT_ranges_base *would* have to be applied, and we'd have to care
524 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
525 ULONGEST ranges_base
= 0;
527 /* When reading debug info generated by older versions of rustc, we
528 have to rewrite some union types to be struct types with a
529 variant part. This rewriting must be done after the CU is fully
530 read in, because otherwise at the point of rewriting some struct
531 type might not have been fully processed. So, we keep a list of
532 all such types here and process them after expansion. */
533 std::vector
<struct type
*> rust_unions
;
535 /* Mark used when releasing cached dies. */
538 /* This CU references .debug_loc. See the symtab->locations_valid field.
539 This test is imperfect as there may exist optimized debug code not using
540 any location list and still facing inlining issues if handled as
541 unoptimized code. For a future better test see GCC PR other/32998. */
542 bool has_loclist
: 1;
544 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
545 if all the producer_is_* fields are valid. This information is cached
546 because profiling CU expansion showed excessive time spent in
547 producer_is_gxx_lt_4_6. */
548 bool checked_producer
: 1;
549 bool producer_is_gxx_lt_4_6
: 1;
550 bool producer_is_gcc_lt_4_3
: 1;
551 bool producer_is_icc
: 1;
552 bool producer_is_icc_lt_14
: 1;
553 bool producer_is_codewarrior
: 1;
555 /* When true, the file that we're processing is known to have
556 debugging info for C++ namespaces. GCC 3.3.x did not produce
557 this information, but later versions do. */
559 bool processing_has_namespace_info
: 1;
561 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
563 /* If this CU was inherited by another CU (via specification,
564 abstract_origin, etc), this is the ancestor CU. */
567 /* Get the buildsym_compunit for this CU. */
568 buildsym_compunit
*get_builder ()
570 /* If this CU has a builder associated with it, use that. */
571 if (m_builder
!= nullptr)
572 return m_builder
.get ();
574 /* Otherwise, search ancestors for a valid builder. */
575 if (ancestor
!= nullptr)
576 return ancestor
->get_builder ();
582 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
583 This includes type_unit_group and quick_file_names. */
585 struct stmt_list_hash
587 /* The DWO unit this table is from or NULL if there is none. */
588 struct dwo_unit
*dwo_unit
;
590 /* Offset in .debug_line or .debug_line.dwo. */
591 sect_offset line_sect_off
;
594 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
595 an object of this type. */
597 struct type_unit_group
599 /* dwarf2read.c's main "handle" on a TU symtab.
600 To simplify things we create an artificial CU that "includes" all the
601 type units using this stmt_list so that the rest of the code still has
602 a "per_cu" handle on the symtab.
603 This PER_CU is recognized by having no section. */
604 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
605 struct dwarf2_per_cu_data per_cu
;
607 /* The TUs that share this DW_AT_stmt_list entry.
608 This is added to while parsing type units to build partial symtabs,
609 and is deleted afterwards and not used again. */
610 std::vector
<signatured_type
*> *tus
;
612 /* The compunit symtab.
613 Type units in a group needn't all be defined in the same source file,
614 so we create an essentially anonymous symtab as the compunit symtab. */
615 struct compunit_symtab
*compunit_symtab
;
617 /* The data used to construct the hash key. */
618 struct stmt_list_hash hash
;
620 /* The number of symtabs from the line header.
621 The value here must match line_header.num_file_names. */
622 unsigned int num_symtabs
;
624 /* The symbol tables for this TU (obtained from the files listed in
626 WARNING: The order of entries here must match the order of entries
627 in the line header. After the first TU using this type_unit_group, the
628 line header for the subsequent TUs is recreated from this. This is done
629 because we need to use the same symtabs for each TU using the same
630 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
631 there's no guarantee the line header doesn't have duplicate entries. */
632 struct symtab
**symtabs
;
635 /* These sections are what may appear in a (real or virtual) DWO file. */
639 struct dwarf2_section_info abbrev
;
640 struct dwarf2_section_info line
;
641 struct dwarf2_section_info loc
;
642 struct dwarf2_section_info loclists
;
643 struct dwarf2_section_info macinfo
;
644 struct dwarf2_section_info macro
;
645 struct dwarf2_section_info str
;
646 struct dwarf2_section_info str_offsets
;
647 /* In the case of a virtual DWO file, these two are unused. */
648 struct dwarf2_section_info info
;
649 std::vector
<dwarf2_section_info
> types
;
652 /* CUs/TUs in DWP/DWO files. */
656 /* Backlink to the containing struct dwo_file. */
657 struct dwo_file
*dwo_file
;
659 /* The "id" that distinguishes this CU/TU.
660 .debug_info calls this "dwo_id", .debug_types calls this "signature".
661 Since signatures came first, we stick with it for consistency. */
664 /* The section this CU/TU lives in, in the DWO file. */
665 struct dwarf2_section_info
*section
;
667 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
668 sect_offset sect_off
;
671 /* For types, offset in the type's DIE of the type defined by this TU. */
672 cu_offset type_offset_in_tu
;
675 /* include/dwarf2.h defines the DWP section codes.
676 It defines a max value but it doesn't define a min value, which we
677 use for error checking, so provide one. */
679 enum dwp_v2_section_ids
684 /* Data for one DWO file.
686 This includes virtual DWO files (a virtual DWO file is a DWO file as it
687 appears in a DWP file). DWP files don't really have DWO files per se -
688 comdat folding of types "loses" the DWO file they came from, and from
689 a high level view DWP files appear to contain a mass of random types.
690 However, to maintain consistency with the non-DWP case we pretend DWP
691 files contain virtual DWO files, and we assign each TU with one virtual
692 DWO file (generally based on the line and abbrev section offsets -
693 a heuristic that seems to work in practice). */
697 dwo_file () = default;
698 DISABLE_COPY_AND_ASSIGN (dwo_file
);
700 /* The DW_AT_GNU_dwo_name attribute.
701 For virtual DWO files the name is constructed from the section offsets
702 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
703 from related CU+TUs. */
704 const char *dwo_name
= nullptr;
706 /* The DW_AT_comp_dir attribute. */
707 const char *comp_dir
= nullptr;
709 /* The bfd, when the file is open. Otherwise this is NULL.
710 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
711 gdb_bfd_ref_ptr dbfd
;
713 /* The sections that make up this DWO file.
714 Remember that for virtual DWO files in DWP V2, these are virtual
715 sections (for lack of a better name). */
716 struct dwo_sections sections
{};
718 /* The CUs in the file.
719 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
720 an extension to handle LLVM's Link Time Optimization output (where
721 multiple source files may be compiled into a single object/dwo pair). */
724 /* Table of TUs in the file.
725 Each element is a struct dwo_unit. */
729 /* These sections are what may appear in a DWP file. */
733 /* These are used by both DWP version 1 and 2. */
734 struct dwarf2_section_info str
;
735 struct dwarf2_section_info cu_index
;
736 struct dwarf2_section_info tu_index
;
738 /* These are only used by DWP version 2 files.
739 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
740 sections are referenced by section number, and are not recorded here.
741 In DWP version 2 there is at most one copy of all these sections, each
742 section being (effectively) comprised of the concatenation of all of the
743 individual sections that exist in the version 1 format.
744 To keep the code simple we treat each of these concatenated pieces as a
745 section itself (a virtual section?). */
746 struct dwarf2_section_info abbrev
;
747 struct dwarf2_section_info info
;
748 struct dwarf2_section_info line
;
749 struct dwarf2_section_info loc
;
750 struct dwarf2_section_info macinfo
;
751 struct dwarf2_section_info macro
;
752 struct dwarf2_section_info str_offsets
;
753 struct dwarf2_section_info types
;
756 /* These sections are what may appear in a virtual DWO file in DWP version 1.
757 A virtual DWO file is a DWO file as it appears in a DWP file. */
759 struct virtual_v1_dwo_sections
761 struct dwarf2_section_info abbrev
;
762 struct dwarf2_section_info line
;
763 struct dwarf2_section_info loc
;
764 struct dwarf2_section_info macinfo
;
765 struct dwarf2_section_info macro
;
766 struct dwarf2_section_info str_offsets
;
767 /* Each DWP hash table entry records one CU or one TU.
768 That is recorded here, and copied to dwo_unit.section. */
769 struct dwarf2_section_info info_or_types
;
772 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
773 In version 2, the sections of the DWO files are concatenated together
774 and stored in one section of that name. Thus each ELF section contains
775 several "virtual" sections. */
777 struct virtual_v2_dwo_sections
779 bfd_size_type abbrev_offset
;
780 bfd_size_type abbrev_size
;
782 bfd_size_type line_offset
;
783 bfd_size_type line_size
;
785 bfd_size_type loc_offset
;
786 bfd_size_type loc_size
;
788 bfd_size_type macinfo_offset
;
789 bfd_size_type macinfo_size
;
791 bfd_size_type macro_offset
;
792 bfd_size_type macro_size
;
794 bfd_size_type str_offsets_offset
;
795 bfd_size_type str_offsets_size
;
797 /* Each DWP hash table entry records one CU or one TU.
798 That is recorded here, and copied to dwo_unit.section. */
799 bfd_size_type info_or_types_offset
;
800 bfd_size_type info_or_types_size
;
803 /* Contents of DWP hash tables. */
805 struct dwp_hash_table
807 uint32_t version
, nr_columns
;
808 uint32_t nr_units
, nr_slots
;
809 const gdb_byte
*hash_table
, *unit_table
;
814 const gdb_byte
*indices
;
818 /* This is indexed by column number and gives the id of the section
820 #define MAX_NR_V2_DWO_SECTIONS \
821 (1 /* .debug_info or .debug_types */ \
822 + 1 /* .debug_abbrev */ \
823 + 1 /* .debug_line */ \
824 + 1 /* .debug_loc */ \
825 + 1 /* .debug_str_offsets */ \
826 + 1 /* .debug_macro or .debug_macinfo */)
827 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
828 const gdb_byte
*offsets
;
829 const gdb_byte
*sizes
;
834 /* Data for one DWP file. */
838 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
840 dbfd (std::move (abfd
))
844 /* Name of the file. */
847 /* File format version. */
851 gdb_bfd_ref_ptr dbfd
;
853 /* Section info for this file. */
854 struct dwp_sections sections
{};
856 /* Table of CUs in the file. */
857 const struct dwp_hash_table
*cus
= nullptr;
859 /* Table of TUs in the file. */
860 const struct dwp_hash_table
*tus
= nullptr;
862 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
863 htab_t loaded_cus
{};
864 htab_t loaded_tus
{};
866 /* Table to map ELF section numbers to their sections.
867 This is only needed for the DWP V1 file format. */
868 unsigned int num_sections
= 0;
869 asection
**elf_sections
= nullptr;
872 /* Struct used to pass misc. parameters to read_die_and_children, et
873 al. which are used for both .debug_info and .debug_types dies.
874 All parameters here are unchanging for the life of the call. This
875 struct exists to abstract away the constant parameters of die reading. */
877 struct die_reader_specs
879 /* The bfd of die_section. */
882 /* The CU of the DIE we are parsing. */
883 struct dwarf2_cu
*cu
;
885 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
886 struct dwo_file
*dwo_file
;
888 /* The section the die comes from.
889 This is either .debug_info or .debug_types, or the .dwo variants. */
890 struct dwarf2_section_info
*die_section
;
892 /* die_section->buffer. */
893 const gdb_byte
*buffer
;
895 /* The end of the buffer. */
896 const gdb_byte
*buffer_end
;
898 /* The value of the DW_AT_comp_dir attribute. */
899 const char *comp_dir
;
901 /* The abbreviation table to use when reading the DIEs. */
902 struct abbrev_table
*abbrev_table
;
905 /* Type of function passed to init_cutu_and_read_dies, et.al. */
906 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
907 const gdb_byte
*info_ptr
,
908 struct die_info
*comp_unit_die
,
912 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
914 typedef int dir_index
;
916 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
918 typedef int file_name_index
;
922 file_entry () = default;
924 file_entry (const char *name_
, dir_index d_index_
,
925 unsigned int mod_time_
, unsigned int length_
)
928 mod_time (mod_time_
),
932 /* Return the include directory at D_INDEX stored in LH. Returns
933 NULL if D_INDEX is out of bounds. */
934 const char *include_dir (const line_header
*lh
) const;
936 /* The file name. Note this is an observing pointer. The memory is
937 owned by debug_line_buffer. */
940 /* The directory index (1-based). */
941 dir_index d_index
{};
943 unsigned int mod_time
{};
945 unsigned int length
{};
947 /* True if referenced by the Line Number Program. */
950 /* The associated symbol table, if any. */
951 struct symtab
*symtab
{};
954 /* The line number information for a compilation unit (found in the
955 .debug_line section) begins with a "statement program header",
956 which contains the following information. */
963 /* Add an entry to the include directory table. */
964 void add_include_dir (const char *include_dir
);
966 /* Add an entry to the file name table. */
967 void add_file_name (const char *name
, dir_index d_index
,
968 unsigned int mod_time
, unsigned int length
);
970 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
971 Returns NULL if INDEX is out of bounds. */
972 const char *include_dir_at (dir_index index
) const
978 vec_index
= index
- 1;
979 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
981 return m_include_dirs
[vec_index
];
984 bool is_valid_file_index (int file_index
)
987 return 0 <= file_index
&& file_index
< file_names_size ();
988 return 1 <= file_index
&& file_index
<= file_names_size ();
991 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
992 Returns NULL if INDEX is out of bounds. */
993 file_entry
*file_name_at (file_name_index index
)
999 vec_index
= index
- 1;
1000 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1002 return &m_file_names
[vec_index
];
1005 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1006 this method should only be used to iterate through all file entries in an
1007 index-agnostic manner. */
1008 std::vector
<file_entry
> &file_names ()
1009 { return m_file_names
; }
1011 /* Offset of line number information in .debug_line section. */
1012 sect_offset sect_off
{};
1014 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1015 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1017 unsigned int total_length
{};
1018 unsigned short version
{};
1019 unsigned int header_length
{};
1020 unsigned char minimum_instruction_length
{};
1021 unsigned char maximum_ops_per_instruction
{};
1022 unsigned char default_is_stmt
{};
1024 unsigned char line_range
{};
1025 unsigned char opcode_base
{};
1027 /* standard_opcode_lengths[i] is the number of operands for the
1028 standard opcode whose value is i. This means that
1029 standard_opcode_lengths[0] is unused, and the last meaningful
1030 element is standard_opcode_lengths[opcode_base - 1]. */
1031 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1033 int file_names_size ()
1034 { return m_file_names
.size(); }
1036 /* The start and end of the statement program following this
1037 header. These point into dwarf2_per_objfile->line_buffer. */
1038 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1041 /* The include_directories table. Note these are observing
1042 pointers. The memory is owned by debug_line_buffer. */
1043 std::vector
<const char *> m_include_dirs
;
1045 /* The file_names table. This is private because the meaning of indexes
1046 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1047 before, and is 0 in DWARF 5 and later). So the client should use
1048 file_name_at method for access. */
1049 std::vector
<file_entry
> m_file_names
;
1052 typedef std::unique_ptr
<line_header
> line_header_up
;
1055 file_entry::include_dir (const line_header
*lh
) const
1057 return lh
->include_dir_at (d_index
);
1060 /* When we construct a partial symbol table entry we only
1061 need this much information. */
1062 struct partial_die_info
: public allocate_on_obstack
1064 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1066 /* Disable assign but still keep copy ctor, which is needed
1067 load_partial_dies. */
1068 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1070 /* Adjust the partial die before generating a symbol for it. This
1071 function may set the is_external flag or change the DIE's
1073 void fixup (struct dwarf2_cu
*cu
);
1075 /* Read a minimal amount of information into the minimal die
1077 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1078 const struct abbrev_info
&abbrev
,
1079 const gdb_byte
*info_ptr
);
1081 /* Offset of this DIE. */
1082 const sect_offset sect_off
;
1084 /* DWARF-2 tag for this DIE. */
1085 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1087 /* Assorted flags describing the data found in this DIE. */
1088 const unsigned int has_children
: 1;
1090 unsigned int is_external
: 1;
1091 unsigned int is_declaration
: 1;
1092 unsigned int has_type
: 1;
1093 unsigned int has_specification
: 1;
1094 unsigned int has_pc_info
: 1;
1095 unsigned int may_be_inlined
: 1;
1097 /* This DIE has been marked DW_AT_main_subprogram. */
1098 unsigned int main_subprogram
: 1;
1100 /* Flag set if the SCOPE field of this structure has been
1102 unsigned int scope_set
: 1;
1104 /* Flag set if the DIE has a byte_size attribute. */
1105 unsigned int has_byte_size
: 1;
1107 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1108 unsigned int has_const_value
: 1;
1110 /* Flag set if any of the DIE's children are template arguments. */
1111 unsigned int has_template_arguments
: 1;
1113 /* Flag set if fixup has been called on this die. */
1114 unsigned int fixup_called
: 1;
1116 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1117 unsigned int is_dwz
: 1;
1119 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1120 unsigned int spec_is_dwz
: 1;
1122 /* The name of this DIE. Normally the value of DW_AT_name, but
1123 sometimes a default name for unnamed DIEs. */
1124 const char *name
= nullptr;
1126 /* The linkage name, if present. */
1127 const char *linkage_name
= nullptr;
1129 /* The scope to prepend to our children. This is generally
1130 allocated on the comp_unit_obstack, so will disappear
1131 when this compilation unit leaves the cache. */
1132 const char *scope
= nullptr;
1134 /* Some data associated with the partial DIE. The tag determines
1135 which field is live. */
1138 /* The location description associated with this DIE, if any. */
1139 struct dwarf_block
*locdesc
;
1140 /* The offset of an import, for DW_TAG_imported_unit. */
1141 sect_offset sect_off
;
1144 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1145 CORE_ADDR lowpc
= 0;
1146 CORE_ADDR highpc
= 0;
1148 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1149 DW_AT_sibling, if any. */
1150 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1151 could return DW_AT_sibling values to its caller load_partial_dies. */
1152 const gdb_byte
*sibling
= nullptr;
1154 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1155 DW_AT_specification (or DW_AT_abstract_origin or
1156 DW_AT_extension). */
1157 sect_offset spec_offset
{};
1159 /* Pointers to this DIE's parent, first child, and next sibling,
1161 struct partial_die_info
*die_parent
= nullptr;
1162 struct partial_die_info
*die_child
= nullptr;
1163 struct partial_die_info
*die_sibling
= nullptr;
1165 friend struct partial_die_info
*
1166 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1169 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1170 partial_die_info (sect_offset sect_off
)
1171 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1175 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1177 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1182 has_specification
= 0;
1185 main_subprogram
= 0;
1188 has_const_value
= 0;
1189 has_template_arguments
= 0;
1196 /* This data structure holds the information of an abbrev. */
1199 unsigned int number
; /* number identifying abbrev */
1200 enum dwarf_tag tag
; /* dwarf tag */
1201 unsigned short has_children
; /* boolean */
1202 unsigned short num_attrs
; /* number of attributes */
1203 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1204 struct abbrev_info
*next
; /* next in chain */
1209 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1210 ENUM_BITFIELD(dwarf_form
) form
: 16;
1212 /* It is valid only if FORM is DW_FORM_implicit_const. */
1213 LONGEST implicit_const
;
1216 /* Size of abbrev_table.abbrev_hash_table. */
1217 #define ABBREV_HASH_SIZE 121
1219 /* Top level data structure to contain an abbreviation table. */
1223 explicit abbrev_table (sect_offset off
)
1227 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1228 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1231 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1233 /* Allocate space for a struct abbrev_info object in
1235 struct abbrev_info
*alloc_abbrev ();
1237 /* Add an abbreviation to the table. */
1238 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1240 /* Look up an abbrev in the table.
1241 Returns NULL if the abbrev is not found. */
1243 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1246 /* Where the abbrev table came from.
1247 This is used as a sanity check when the table is used. */
1248 const sect_offset sect_off
;
1250 /* Storage for the abbrev table. */
1251 auto_obstack abbrev_obstack
;
1255 /* Hash table of abbrevs.
1256 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1257 It could be statically allocated, but the previous code didn't so we
1259 struct abbrev_info
**m_abbrevs
;
1262 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1264 /* Attributes have a name and a value. */
1267 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1268 ENUM_BITFIELD(dwarf_form
) form
: 15;
1270 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1271 field should be in u.str (existing only for DW_STRING) but it is kept
1272 here for better struct attribute alignment. */
1273 unsigned int string_is_canonical
: 1;
1278 struct dwarf_block
*blk
;
1287 /* This data structure holds a complete die structure. */
1290 /* DWARF-2 tag for this DIE. */
1291 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1293 /* Number of attributes */
1294 unsigned char num_attrs
;
1296 /* True if we're presently building the full type name for the
1297 type derived from this DIE. */
1298 unsigned char building_fullname
: 1;
1300 /* True if this die is in process. PR 16581. */
1301 unsigned char in_process
: 1;
1304 unsigned int abbrev
;
1306 /* Offset in .debug_info or .debug_types section. */
1307 sect_offset sect_off
;
1309 /* The dies in a compilation unit form an n-ary tree. PARENT
1310 points to this die's parent; CHILD points to the first child of
1311 this node; and all the children of a given node are chained
1312 together via their SIBLING fields. */
1313 struct die_info
*child
; /* Its first child, if any. */
1314 struct die_info
*sibling
; /* Its next sibling, if any. */
1315 struct die_info
*parent
; /* Its parent, if any. */
1317 /* An array of attributes, with NUM_ATTRS elements. There may be
1318 zero, but it's not common and zero-sized arrays are not
1319 sufficiently portable C. */
1320 struct attribute attrs
[1];
1323 /* Get at parts of an attribute structure. */
1325 #define DW_STRING(attr) ((attr)->u.str)
1326 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1327 #define DW_UNSND(attr) ((attr)->u.unsnd)
1328 #define DW_BLOCK(attr) ((attr)->u.blk)
1329 #define DW_SND(attr) ((attr)->u.snd)
1330 #define DW_ADDR(attr) ((attr)->u.addr)
1331 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1333 /* Blocks are a bunch of untyped bytes. */
1338 /* Valid only if SIZE is not zero. */
1339 const gdb_byte
*data
;
1342 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1343 but this would require a corresponding change in unpack_field_as_long
1345 static int bits_per_byte
= 8;
1347 /* When reading a variant or variant part, we track a bit more
1348 information about the field, and store it in an object of this
1351 struct variant_field
1353 /* If we see a DW_TAG_variant, then this will be the discriminant
1355 ULONGEST discriminant_value
;
1356 /* If we see a DW_TAG_variant, then this will be set if this is the
1358 bool default_branch
;
1359 /* While reading a DW_TAG_variant_part, this will be set if this
1360 field is the discriminant. */
1361 bool is_discriminant
;
1366 int accessibility
= 0;
1368 /* Extra information to describe a variant or variant part. */
1369 struct variant_field variant
{};
1370 struct field field
{};
1375 const char *name
= nullptr;
1376 std::vector
<struct fn_field
> fnfields
;
1379 /* The routines that read and process dies for a C struct or C++ class
1380 pass lists of data member fields and lists of member function fields
1381 in an instance of a field_info structure, as defined below. */
1384 /* List of data member and baseclasses fields. */
1385 std::vector
<struct nextfield
> fields
;
1386 std::vector
<struct nextfield
> baseclasses
;
1388 /* Number of fields (including baseclasses). */
1391 /* Set if the accessibility of one of the fields is not public. */
1392 int non_public_fields
= 0;
1394 /* Member function fieldlist array, contains name of possibly overloaded
1395 member function, number of overloaded member functions and a pointer
1396 to the head of the member function field chain. */
1397 std::vector
<struct fnfieldlist
> fnfieldlists
;
1399 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1400 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1401 std::vector
<struct decl_field
> typedef_field_list
;
1403 /* Nested types defined by this class and the number of elements in this
1405 std::vector
<struct decl_field
> nested_types_list
;
1408 /* One item on the queue of compilation units to read in full symbols
1410 struct dwarf2_queue_item
1412 struct dwarf2_per_cu_data
*per_cu
;
1413 enum language pretend_language
;
1414 struct dwarf2_queue_item
*next
;
1417 /* The current queue. */
1418 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1420 /* Loaded secondary compilation units are kept in memory until they
1421 have not been referenced for the processing of this many
1422 compilation units. Set this to zero to disable caching. Cache
1423 sizes of up to at least twenty will improve startup time for
1424 typical inter-CU-reference binaries, at an obvious memory cost. */
1425 static int dwarf_max_cache_age
= 5;
1427 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1428 struct cmd_list_element
*c
, const char *value
)
1430 fprintf_filtered (file
, _("The upper bound on the age of cached "
1431 "DWARF compilation units is %s.\n"),
1435 /* local function prototypes */
1437 static const char *get_section_name (const struct dwarf2_section_info
*);
1439 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1441 static void dwarf2_find_base_address (struct die_info
*die
,
1442 struct dwarf2_cu
*cu
);
1444 static struct partial_symtab
*create_partial_symtab
1445 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1447 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1448 const gdb_byte
*info_ptr
,
1449 struct die_info
*type_unit_die
,
1450 int has_children
, void *data
);
1452 static void dwarf2_build_psymtabs_hard
1453 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1455 static void scan_partial_symbols (struct partial_die_info
*,
1456 CORE_ADDR
*, CORE_ADDR
*,
1457 int, struct dwarf2_cu
*);
1459 static void add_partial_symbol (struct partial_die_info
*,
1460 struct dwarf2_cu
*);
1462 static void add_partial_namespace (struct partial_die_info
*pdi
,
1463 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1464 int set_addrmap
, struct dwarf2_cu
*cu
);
1466 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1467 CORE_ADDR
*highpc
, int set_addrmap
,
1468 struct dwarf2_cu
*cu
);
1470 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1471 struct dwarf2_cu
*cu
);
1473 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1474 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1475 int need_pc
, struct dwarf2_cu
*cu
);
1477 static void dwarf2_read_symtab (struct partial_symtab
*,
1480 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1482 static abbrev_table_up abbrev_table_read_table
1483 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1486 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1488 static struct partial_die_info
*load_partial_dies
1489 (const struct die_reader_specs
*, const gdb_byte
*, int);
1491 /* A pair of partial_die_info and compilation unit. */
1492 struct cu_partial_die_info
1494 /* The compilation unit of the partial_die_info. */
1495 struct dwarf2_cu
*cu
;
1496 /* A partial_die_info. */
1497 struct partial_die_info
*pdi
;
1499 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1505 cu_partial_die_info () = delete;
1508 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1509 struct dwarf2_cu
*);
1511 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1512 struct attribute
*, struct attr_abbrev
*,
1515 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1517 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1519 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1521 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1522 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1524 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1526 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1528 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1531 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1533 static LONGEST read_checked_initial_length_and_offset
1534 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1535 unsigned int *, unsigned int *);
1537 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1538 const struct comp_unit_head
*,
1541 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1543 static sect_offset read_abbrev_offset
1544 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1545 struct dwarf2_section_info
*, sect_offset
);
1547 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1549 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1551 static const char *read_indirect_string
1552 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1553 const struct comp_unit_head
*, unsigned int *);
1555 static const char *read_indirect_line_string
1556 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1557 const struct comp_unit_head
*, unsigned int *);
1559 static const char *read_indirect_string_at_offset
1560 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1561 LONGEST str_offset
);
1563 static const char *read_indirect_string_from_dwz
1564 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1566 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1568 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1572 static const char *read_str_index (const struct die_reader_specs
*reader
,
1573 ULONGEST str_index
);
1575 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1577 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1578 struct dwarf2_cu
*);
1580 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1583 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1584 struct dwarf2_cu
*cu
);
1586 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1588 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1589 struct dwarf2_cu
*cu
);
1591 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1593 static struct die_info
*die_specification (struct die_info
*die
,
1594 struct dwarf2_cu
**);
1596 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1597 struct dwarf2_cu
*cu
);
1599 static void dwarf_decode_lines (struct line_header
*, const char *,
1600 struct dwarf2_cu
*, struct partial_symtab
*,
1601 CORE_ADDR
, int decode_mapping
);
1603 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1606 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1607 struct dwarf2_cu
*, struct symbol
* = NULL
);
1609 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1610 struct dwarf2_cu
*);
1612 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1615 struct obstack
*obstack
,
1616 struct dwarf2_cu
*cu
, LONGEST
*value
,
1617 const gdb_byte
**bytes
,
1618 struct dwarf2_locexpr_baton
**baton
);
1620 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1622 static int need_gnat_info (struct dwarf2_cu
*);
1624 static struct type
*die_descriptive_type (struct die_info
*,
1625 struct dwarf2_cu
*);
1627 static void set_descriptive_type (struct type
*, struct die_info
*,
1628 struct dwarf2_cu
*);
1630 static struct type
*die_containing_type (struct die_info
*,
1631 struct dwarf2_cu
*);
1633 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1634 struct dwarf2_cu
*);
1636 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1638 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1640 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1642 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1643 const char *suffix
, int physname
,
1644 struct dwarf2_cu
*cu
);
1646 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1648 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1650 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1652 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1654 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1656 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1658 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1659 struct dwarf2_cu
*, struct partial_symtab
*);
1661 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1662 values. Keep the items ordered with increasing constraints compliance. */
1665 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1666 PC_BOUNDS_NOT_PRESENT
,
1668 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1669 were present but they do not form a valid range of PC addresses. */
1672 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1675 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1679 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1680 CORE_ADDR
*, CORE_ADDR
*,
1682 struct partial_symtab
*);
1684 static void get_scope_pc_bounds (struct die_info
*,
1685 CORE_ADDR
*, CORE_ADDR
*,
1686 struct dwarf2_cu
*);
1688 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1689 CORE_ADDR
, struct dwarf2_cu
*);
1691 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1692 struct dwarf2_cu
*);
1694 static void dwarf2_attach_fields_to_type (struct field_info
*,
1695 struct type
*, struct dwarf2_cu
*);
1697 static void dwarf2_add_member_fn (struct field_info
*,
1698 struct die_info
*, struct type
*,
1699 struct dwarf2_cu
*);
1701 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1703 struct dwarf2_cu
*);
1705 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1707 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1709 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1711 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1713 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1715 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1717 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1719 static struct type
*read_module_type (struct die_info
*die
,
1720 struct dwarf2_cu
*cu
);
1722 static const char *namespace_name (struct die_info
*die
,
1723 int *is_anonymous
, struct dwarf2_cu
*);
1725 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1727 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1729 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1730 struct dwarf2_cu
*);
1732 static struct die_info
*read_die_and_siblings_1
1733 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1736 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1737 const gdb_byte
*info_ptr
,
1738 const gdb_byte
**new_info_ptr
,
1739 struct die_info
*parent
);
1741 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1742 struct die_info
**, const gdb_byte
*,
1745 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1746 struct die_info
**, const gdb_byte
*,
1749 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1751 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1754 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1756 static const char *dwarf2_full_name (const char *name
,
1757 struct die_info
*die
,
1758 struct dwarf2_cu
*cu
);
1760 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1761 struct dwarf2_cu
*cu
);
1763 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1764 struct dwarf2_cu
**);
1766 static const char *dwarf_tag_name (unsigned int);
1768 static const char *dwarf_attr_name (unsigned int);
1770 static const char *dwarf_unit_type_name (int unit_type
);
1772 static const char *dwarf_form_name (unsigned int);
1774 static const char *dwarf_bool_name (unsigned int);
1776 static const char *dwarf_type_encoding_name (unsigned int);
1778 static struct die_info
*sibling_die (struct die_info
*);
1780 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1782 static void dump_die_for_error (struct die_info
*);
1784 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1787 /*static*/ void dump_die (struct die_info
*, int max_level
);
1789 static void store_in_ref_table (struct die_info
*,
1790 struct dwarf2_cu
*);
1792 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1794 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1796 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1797 const struct attribute
*,
1798 struct dwarf2_cu
**);
1800 static struct die_info
*follow_die_ref (struct die_info
*,
1801 const struct attribute
*,
1802 struct dwarf2_cu
**);
1804 static struct die_info
*follow_die_sig (struct die_info
*,
1805 const struct attribute
*,
1806 struct dwarf2_cu
**);
1808 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1809 struct dwarf2_cu
*);
1811 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1812 const struct attribute
*,
1813 struct dwarf2_cu
*);
1815 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1817 static void read_signatured_type (struct signatured_type
*);
1819 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1820 struct die_info
*die
, struct dwarf2_cu
*cu
,
1821 struct dynamic_prop
*prop
, struct type
*type
);
1823 /* memory allocation interface */
1825 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1827 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1829 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1831 static int attr_form_is_block (const struct attribute
*);
1833 static int attr_form_is_section_offset (const struct attribute
*);
1835 static int attr_form_is_constant (const struct attribute
*);
1837 static int attr_form_is_ref (const struct attribute
*);
1839 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1840 struct dwarf2_loclist_baton
*baton
,
1841 const struct attribute
*attr
);
1843 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1845 struct dwarf2_cu
*cu
,
1848 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1849 const gdb_byte
*info_ptr
,
1850 struct abbrev_info
*abbrev
);
1852 static hashval_t
partial_die_hash (const void *item
);
1854 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1856 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1857 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1858 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1860 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1861 struct die_info
*comp_unit_die
,
1862 enum language pretend_language
);
1864 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1866 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1868 static struct type
*set_die_type (struct die_info
*, struct type
*,
1869 struct dwarf2_cu
*);
1871 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1873 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1875 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1878 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1881 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1884 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1885 struct dwarf2_per_cu_data
*);
1887 static void dwarf2_mark (struct dwarf2_cu
*);
1889 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1891 static struct type
*get_die_type_at_offset (sect_offset
,
1892 struct dwarf2_per_cu_data
*);
1894 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1896 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1897 enum language pretend_language
);
1899 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1901 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1902 static struct type
*dwarf2_per_cu_addr_sized_int_type
1903 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1904 static struct type
*dwarf2_per_cu_int_type
1905 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1908 /* Class, the destructor of which frees all allocated queue entries. This
1909 will only have work to do if an error was thrown while processing the
1910 dwarf. If no error was thrown then the queue entries should have all
1911 been processed, and freed, as we went along. */
1913 class dwarf2_queue_guard
1916 dwarf2_queue_guard () = default;
1918 /* Free any entries remaining on the queue. There should only be
1919 entries left if we hit an error while processing the dwarf. */
1920 ~dwarf2_queue_guard ()
1922 struct dwarf2_queue_item
*item
, *last
;
1924 item
= dwarf2_queue
;
1927 /* Anything still marked queued is likely to be in an
1928 inconsistent state, so discard it. */
1929 if (item
->per_cu
->queued
)
1931 if (item
->per_cu
->cu
!= NULL
)
1932 free_one_cached_comp_unit (item
->per_cu
);
1933 item
->per_cu
->queued
= 0;
1941 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1945 /* The return type of find_file_and_directory. Note, the enclosed
1946 string pointers are only valid while this object is valid. */
1948 struct file_and_directory
1950 /* The filename. This is never NULL. */
1953 /* The compilation directory. NULL if not known. If we needed to
1954 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1955 points directly to the DW_AT_comp_dir string attribute owned by
1956 the obstack that owns the DIE. */
1957 const char *comp_dir
;
1959 /* If we needed to build a new string for comp_dir, this is what
1960 owns the storage. */
1961 std::string comp_dir_storage
;
1964 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1965 struct dwarf2_cu
*cu
);
1967 static char *file_full_name (int file
, struct line_header
*lh
,
1968 const char *comp_dir
);
1970 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1971 enum class rcuh_kind
{ COMPILE
, TYPE
};
1973 static const gdb_byte
*read_and_check_comp_unit_head
1974 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1975 struct comp_unit_head
*header
,
1976 struct dwarf2_section_info
*section
,
1977 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1978 rcuh_kind section_kind
);
1980 static void init_cutu_and_read_dies
1981 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1982 int use_existing_cu
, int keep
, bool skip_partial
,
1983 die_reader_func_ftype
*die_reader_func
, void *data
);
1985 static void init_cutu_and_read_dies_simple
1986 (struct dwarf2_per_cu_data
*this_cu
,
1987 die_reader_func_ftype
*die_reader_func
, void *data
);
1989 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1991 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1993 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1994 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1995 struct dwp_file
*dwp_file
, const char *comp_dir
,
1996 ULONGEST signature
, int is_debug_types
);
1998 static struct dwp_file
*get_dwp_file
1999 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2001 static struct dwo_unit
*lookup_dwo_comp_unit
2002 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2004 static struct dwo_unit
*lookup_dwo_type_unit
2005 (struct signatured_type
*, const char *, const char *);
2007 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2009 /* A unique pointer to a dwo_file. */
2011 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2013 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2015 static void check_producer (struct dwarf2_cu
*cu
);
2017 static void free_line_header_voidp (void *arg
);
2019 /* Various complaints about symbol reading that don't abort the process. */
2022 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2024 complaint (_("statement list doesn't fit in .debug_line section"));
2028 dwarf2_debug_line_missing_file_complaint (void)
2030 complaint (_(".debug_line section has line data without a file"));
2034 dwarf2_debug_line_missing_end_sequence_complaint (void)
2036 complaint (_(".debug_line section has line "
2037 "program sequence without an end"));
2041 dwarf2_complex_location_expr_complaint (void)
2043 complaint (_("location expression too complex"));
2047 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2050 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2055 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2057 complaint (_("debug info runs off end of %s section"
2059 get_section_name (section
),
2060 get_section_file_name (section
));
2064 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2066 complaint (_("macro debug info contains a "
2067 "malformed macro definition:\n`%s'"),
2072 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2074 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2078 /* Hash function for line_header_hash. */
2081 line_header_hash (const struct line_header
*ofs
)
2083 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2086 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2089 line_header_hash_voidp (const void *item
)
2091 const struct line_header
*ofs
= (const struct line_header
*) item
;
2093 return line_header_hash (ofs
);
2096 /* Equality function for line_header_hash. */
2099 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2101 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2102 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2104 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2105 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2110 /* Read the given attribute value as an address, taking the attribute's
2111 form into account. */
2114 attr_value_as_address (struct attribute
*attr
)
2118 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2119 && attr
->form
!= DW_FORM_GNU_addr_index
)
2121 /* Aside from a few clearly defined exceptions, attributes that
2122 contain an address must always be in DW_FORM_addr form.
2123 Unfortunately, some compilers happen to be violating this
2124 requirement by encoding addresses using other forms, such
2125 as DW_FORM_data4 for example. For those broken compilers,
2126 we try to do our best, without any guarantee of success,
2127 to interpret the address correctly. It would also be nice
2128 to generate a complaint, but that would require us to maintain
2129 a list of legitimate cases where a non-address form is allowed,
2130 as well as update callers to pass in at least the CU's DWARF
2131 version. This is more overhead than what we're willing to
2132 expand for a pretty rare case. */
2133 addr
= DW_UNSND (attr
);
2136 addr
= DW_ADDR (attr
);
2141 /* See declaration. */
2143 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2144 const dwarf2_debug_sections
*names
,
2146 : objfile (objfile_
),
2147 can_copy (can_copy_
)
2150 names
= &dwarf2_elf_names
;
2152 bfd
*obfd
= objfile
->obfd
;
2154 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2155 locate_sections (obfd
, sec
, *names
);
2158 dwarf2_per_objfile::~dwarf2_per_objfile ()
2160 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2161 free_cached_comp_units ();
2163 if (quick_file_names_table
)
2164 htab_delete (quick_file_names_table
);
2166 if (line_header_hash
)
2167 htab_delete (line_header_hash
);
2169 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2170 per_cu
->imported_symtabs_free ();
2172 for (signatured_type
*sig_type
: all_type_units
)
2173 sig_type
->per_cu
.imported_symtabs_free ();
2175 /* Everything else should be on the objfile obstack. */
2178 /* See declaration. */
2181 dwarf2_per_objfile::free_cached_comp_units ()
2183 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2184 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2185 while (per_cu
!= NULL
)
2187 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2190 *last_chain
= next_cu
;
2195 /* A helper class that calls free_cached_comp_units on
2198 class free_cached_comp_units
2202 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2203 : m_per_objfile (per_objfile
)
2207 ~free_cached_comp_units ()
2209 m_per_objfile
->free_cached_comp_units ();
2212 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2216 dwarf2_per_objfile
*m_per_objfile
;
2219 /* Try to locate the sections we need for DWARF 2 debugging
2220 information and return true if we have enough to do something.
2221 NAMES points to the dwarf2 section names, or is NULL if the standard
2222 ELF names are used. CAN_COPY is true for formats where symbol
2223 interposition is possible and so symbol values must follow copy
2224 relocation rules. */
2227 dwarf2_has_info (struct objfile
*objfile
,
2228 const struct dwarf2_debug_sections
*names
,
2231 if (objfile
->flags
& OBJF_READNEVER
)
2234 struct dwarf2_per_objfile
*dwarf2_per_objfile
2235 = get_dwarf2_per_objfile (objfile
);
2237 if (dwarf2_per_objfile
== NULL
)
2238 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2242 return (!dwarf2_per_objfile
->info
.is_virtual
2243 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2244 && !dwarf2_per_objfile
->abbrev
.is_virtual
2245 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2248 /* Return the containing section of virtual section SECTION. */
2250 static struct dwarf2_section_info
*
2251 get_containing_section (const struct dwarf2_section_info
*section
)
2253 gdb_assert (section
->is_virtual
);
2254 return section
->s
.containing_section
;
2257 /* Return the bfd owner of SECTION. */
2260 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2262 if (section
->is_virtual
)
2264 section
= get_containing_section (section
);
2265 gdb_assert (!section
->is_virtual
);
2267 return section
->s
.section
->owner
;
2270 /* Return the bfd section of SECTION.
2271 Returns NULL if the section is not present. */
2274 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2276 if (section
->is_virtual
)
2278 section
= get_containing_section (section
);
2279 gdb_assert (!section
->is_virtual
);
2281 return section
->s
.section
;
2284 /* Return the name of SECTION. */
2287 get_section_name (const struct dwarf2_section_info
*section
)
2289 asection
*sectp
= get_section_bfd_section (section
);
2291 gdb_assert (sectp
!= NULL
);
2292 return bfd_section_name (sectp
);
2295 /* Return the name of the file SECTION is in. */
2298 get_section_file_name (const struct dwarf2_section_info
*section
)
2300 bfd
*abfd
= get_section_bfd_owner (section
);
2302 return bfd_get_filename (abfd
);
2305 /* Return the id of SECTION.
2306 Returns 0 if SECTION doesn't exist. */
2309 get_section_id (const struct dwarf2_section_info
*section
)
2311 asection
*sectp
= get_section_bfd_section (section
);
2318 /* Return the flags of SECTION.
2319 SECTION (or containing section if this is a virtual section) must exist. */
2322 get_section_flags (const struct dwarf2_section_info
*section
)
2324 asection
*sectp
= get_section_bfd_section (section
);
2326 gdb_assert (sectp
!= NULL
);
2327 return bfd_section_flags (sectp
);
2330 /* When loading sections, we look either for uncompressed section or for
2331 compressed section names. */
2334 section_is_p (const char *section_name
,
2335 const struct dwarf2_section_names
*names
)
2337 if (names
->normal
!= NULL
2338 && strcmp (section_name
, names
->normal
) == 0)
2340 if (names
->compressed
!= NULL
2341 && strcmp (section_name
, names
->compressed
) == 0)
2346 /* See declaration. */
2349 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2350 const dwarf2_debug_sections
&names
)
2352 flagword aflag
= bfd_section_flags (sectp
);
2354 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2357 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2358 > bfd_get_file_size (abfd
))
2360 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2361 warning (_("Discarding section %s which has a section size (%s"
2362 ") larger than the file size [in module %s]"),
2363 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2364 bfd_get_filename (abfd
));
2366 else if (section_is_p (sectp
->name
, &names
.info
))
2368 this->info
.s
.section
= sectp
;
2369 this->info
.size
= bfd_section_size (sectp
);
2371 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2373 this->abbrev
.s
.section
= sectp
;
2374 this->abbrev
.size
= bfd_section_size (sectp
);
2376 else if (section_is_p (sectp
->name
, &names
.line
))
2378 this->line
.s
.section
= sectp
;
2379 this->line
.size
= bfd_section_size (sectp
);
2381 else if (section_is_p (sectp
->name
, &names
.loc
))
2383 this->loc
.s
.section
= sectp
;
2384 this->loc
.size
= bfd_section_size (sectp
);
2386 else if (section_is_p (sectp
->name
, &names
.loclists
))
2388 this->loclists
.s
.section
= sectp
;
2389 this->loclists
.size
= bfd_section_size (sectp
);
2391 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2393 this->macinfo
.s
.section
= sectp
;
2394 this->macinfo
.size
= bfd_section_size (sectp
);
2396 else if (section_is_p (sectp
->name
, &names
.macro
))
2398 this->macro
.s
.section
= sectp
;
2399 this->macro
.size
= bfd_section_size (sectp
);
2401 else if (section_is_p (sectp
->name
, &names
.str
))
2403 this->str
.s
.section
= sectp
;
2404 this->str
.size
= bfd_section_size (sectp
);
2406 else if (section_is_p (sectp
->name
, &names
.line_str
))
2408 this->line_str
.s
.section
= sectp
;
2409 this->line_str
.size
= bfd_section_size (sectp
);
2411 else if (section_is_p (sectp
->name
, &names
.addr
))
2413 this->addr
.s
.section
= sectp
;
2414 this->addr
.size
= bfd_section_size (sectp
);
2416 else if (section_is_p (sectp
->name
, &names
.frame
))
2418 this->frame
.s
.section
= sectp
;
2419 this->frame
.size
= bfd_section_size (sectp
);
2421 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2423 this->eh_frame
.s
.section
= sectp
;
2424 this->eh_frame
.size
= bfd_section_size (sectp
);
2426 else if (section_is_p (sectp
->name
, &names
.ranges
))
2428 this->ranges
.s
.section
= sectp
;
2429 this->ranges
.size
= bfd_section_size (sectp
);
2431 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2433 this->rnglists
.s
.section
= sectp
;
2434 this->rnglists
.size
= bfd_section_size (sectp
);
2436 else if (section_is_p (sectp
->name
, &names
.types
))
2438 struct dwarf2_section_info type_section
;
2440 memset (&type_section
, 0, sizeof (type_section
));
2441 type_section
.s
.section
= sectp
;
2442 type_section
.size
= bfd_section_size (sectp
);
2444 this->types
.push_back (type_section
);
2446 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2448 this->gdb_index
.s
.section
= sectp
;
2449 this->gdb_index
.size
= bfd_section_size (sectp
);
2451 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2453 this->debug_names
.s
.section
= sectp
;
2454 this->debug_names
.size
= bfd_section_size (sectp
);
2456 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2458 this->debug_aranges
.s
.section
= sectp
;
2459 this->debug_aranges
.size
= bfd_section_size (sectp
);
2462 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2463 && bfd_section_vma (sectp
) == 0)
2464 this->has_section_at_zero
= true;
2467 /* A helper function that decides whether a section is empty,
2471 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2473 if (section
->is_virtual
)
2474 return section
->size
== 0;
2475 return section
->s
.section
== NULL
|| section
->size
== 0;
2478 /* See dwarf2read.h. */
2481 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2485 gdb_byte
*buf
, *retbuf
;
2489 info
->buffer
= NULL
;
2490 info
->readin
= true;
2492 if (dwarf2_section_empty_p (info
))
2495 sectp
= get_section_bfd_section (info
);
2497 /* If this is a virtual section we need to read in the real one first. */
2498 if (info
->is_virtual
)
2500 struct dwarf2_section_info
*containing_section
=
2501 get_containing_section (info
);
2503 gdb_assert (sectp
!= NULL
);
2504 if ((sectp
->flags
& SEC_RELOC
) != 0)
2506 error (_("Dwarf Error: DWP format V2 with relocations is not"
2507 " supported in section %s [in module %s]"),
2508 get_section_name (info
), get_section_file_name (info
));
2510 dwarf2_read_section (objfile
, containing_section
);
2511 /* Other code should have already caught virtual sections that don't
2513 gdb_assert (info
->virtual_offset
+ info
->size
2514 <= containing_section
->size
);
2515 /* If the real section is empty or there was a problem reading the
2516 section we shouldn't get here. */
2517 gdb_assert (containing_section
->buffer
!= NULL
);
2518 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2522 /* If the section has relocations, we must read it ourselves.
2523 Otherwise we attach it to the BFD. */
2524 if ((sectp
->flags
& SEC_RELOC
) == 0)
2526 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2530 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2533 /* When debugging .o files, we may need to apply relocations; see
2534 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2535 We never compress sections in .o files, so we only need to
2536 try this when the section is not compressed. */
2537 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2540 info
->buffer
= retbuf
;
2544 abfd
= get_section_bfd_owner (info
);
2545 gdb_assert (abfd
!= NULL
);
2547 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2548 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2550 error (_("Dwarf Error: Can't read DWARF data"
2551 " in section %s [in module %s]"),
2552 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2556 /* A helper function that returns the size of a section in a safe way.
2557 If you are positive that the section has been read before using the
2558 size, then it is safe to refer to the dwarf2_section_info object's
2559 "size" field directly. In other cases, you must call this
2560 function, because for compressed sections the size field is not set
2561 correctly until the section has been read. */
2563 static bfd_size_type
2564 dwarf2_section_size (struct objfile
*objfile
,
2565 struct dwarf2_section_info
*info
)
2568 dwarf2_read_section (objfile
, info
);
2572 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2576 dwarf2_get_section_info (struct objfile
*objfile
,
2577 enum dwarf2_section_enum sect
,
2578 asection
**sectp
, const gdb_byte
**bufp
,
2579 bfd_size_type
*sizep
)
2581 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2582 struct dwarf2_section_info
*info
;
2584 /* We may see an objfile without any DWARF, in which case we just
2595 case DWARF2_DEBUG_FRAME
:
2596 info
= &data
->frame
;
2598 case DWARF2_EH_FRAME
:
2599 info
= &data
->eh_frame
;
2602 gdb_assert_not_reached ("unexpected section");
2605 dwarf2_read_section (objfile
, info
);
2607 *sectp
= get_section_bfd_section (info
);
2608 *bufp
= info
->buffer
;
2609 *sizep
= info
->size
;
2612 /* A helper function to find the sections for a .dwz file. */
2615 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2617 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2619 /* Note that we only support the standard ELF names, because .dwz
2620 is ELF-only (at the time of writing). */
2621 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2623 dwz_file
->abbrev
.s
.section
= sectp
;
2624 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2626 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2628 dwz_file
->info
.s
.section
= sectp
;
2629 dwz_file
->info
.size
= bfd_section_size (sectp
);
2631 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2633 dwz_file
->str
.s
.section
= sectp
;
2634 dwz_file
->str
.size
= bfd_section_size (sectp
);
2636 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2638 dwz_file
->line
.s
.section
= sectp
;
2639 dwz_file
->line
.size
= bfd_section_size (sectp
);
2641 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2643 dwz_file
->macro
.s
.section
= sectp
;
2644 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2646 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2648 dwz_file
->gdb_index
.s
.section
= sectp
;
2649 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2651 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2653 dwz_file
->debug_names
.s
.section
= sectp
;
2654 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2658 /* See dwarf2read.h. */
2661 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2663 const char *filename
;
2664 bfd_size_type buildid_len_arg
;
2668 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2669 return dwarf2_per_objfile
->dwz_file
.get ();
2671 bfd_set_error (bfd_error_no_error
);
2672 gdb::unique_xmalloc_ptr
<char> data
2673 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2674 &buildid_len_arg
, &buildid
));
2677 if (bfd_get_error () == bfd_error_no_error
)
2679 error (_("could not read '.gnu_debugaltlink' section: %s"),
2680 bfd_errmsg (bfd_get_error ()));
2683 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2685 buildid_len
= (size_t) buildid_len_arg
;
2687 filename
= data
.get ();
2689 std::string abs_storage
;
2690 if (!IS_ABSOLUTE_PATH (filename
))
2692 gdb::unique_xmalloc_ptr
<char> abs
2693 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2695 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2696 filename
= abs_storage
.c_str ();
2699 /* First try the file name given in the section. If that doesn't
2700 work, try to use the build-id instead. */
2701 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2702 if (dwz_bfd
!= NULL
)
2704 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2705 dwz_bfd
.reset (nullptr);
2708 if (dwz_bfd
== NULL
)
2709 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2711 if (dwz_bfd
== NULL
)
2712 error (_("could not find '.gnu_debugaltlink' file for %s"),
2713 objfile_name (dwarf2_per_objfile
->objfile
));
2715 std::unique_ptr
<struct dwz_file
> result
2716 (new struct dwz_file (std::move (dwz_bfd
)));
2718 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2721 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2722 result
->dwz_bfd
.get ());
2723 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2724 return dwarf2_per_objfile
->dwz_file
.get ();
2727 /* DWARF quick_symbols_functions support. */
2729 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2730 unique line tables, so we maintain a separate table of all .debug_line
2731 derived entries to support the sharing.
2732 All the quick functions need is the list of file names. We discard the
2733 line_header when we're done and don't need to record it here. */
2734 struct quick_file_names
2736 /* The data used to construct the hash key. */
2737 struct stmt_list_hash hash
;
2739 /* The number of entries in file_names, real_names. */
2740 unsigned int num_file_names
;
2742 /* The file names from the line table, after being run through
2744 const char **file_names
;
2746 /* The file names from the line table after being run through
2747 gdb_realpath. These are computed lazily. */
2748 const char **real_names
;
2751 /* When using the index (and thus not using psymtabs), each CU has an
2752 object of this type. This is used to hold information needed by
2753 the various "quick" methods. */
2754 struct dwarf2_per_cu_quick_data
2756 /* The file table. This can be NULL if there was no file table
2757 or it's currently not read in.
2758 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2759 struct quick_file_names
*file_names
;
2761 /* The corresponding symbol table. This is NULL if symbols for this
2762 CU have not yet been read. */
2763 struct compunit_symtab
*compunit_symtab
;
2765 /* A temporary mark bit used when iterating over all CUs in
2766 expand_symtabs_matching. */
2767 unsigned int mark
: 1;
2769 /* True if we've tried to read the file table and found there isn't one.
2770 There will be no point in trying to read it again next time. */
2771 unsigned int no_file_data
: 1;
2774 /* Utility hash function for a stmt_list_hash. */
2777 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2781 if (stmt_list_hash
->dwo_unit
!= NULL
)
2782 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2783 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2787 /* Utility equality function for a stmt_list_hash. */
2790 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2791 const struct stmt_list_hash
*rhs
)
2793 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2795 if (lhs
->dwo_unit
!= NULL
2796 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2799 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2802 /* Hash function for a quick_file_names. */
2805 hash_file_name_entry (const void *e
)
2807 const struct quick_file_names
*file_data
2808 = (const struct quick_file_names
*) e
;
2810 return hash_stmt_list_entry (&file_data
->hash
);
2813 /* Equality function for a quick_file_names. */
2816 eq_file_name_entry (const void *a
, const void *b
)
2818 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2819 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2821 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2824 /* Delete function for a quick_file_names. */
2827 delete_file_name_entry (void *e
)
2829 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2832 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2834 xfree ((void*) file_data
->file_names
[i
]);
2835 if (file_data
->real_names
)
2836 xfree ((void*) file_data
->real_names
[i
]);
2839 /* The space for the struct itself lives on objfile_obstack,
2840 so we don't free it here. */
2843 /* Create a quick_file_names hash table. */
2846 create_quick_file_names_table (unsigned int nr_initial_entries
)
2848 return htab_create_alloc (nr_initial_entries
,
2849 hash_file_name_entry
, eq_file_name_entry
,
2850 delete_file_name_entry
, xcalloc
, xfree
);
2853 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2854 have to be created afterwards. You should call age_cached_comp_units after
2855 processing PER_CU->CU. dw2_setup must have been already called. */
2858 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2860 if (per_cu
->is_debug_types
)
2861 load_full_type_unit (per_cu
);
2863 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2865 if (per_cu
->cu
== NULL
)
2866 return; /* Dummy CU. */
2868 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2871 /* Read in the symbols for PER_CU. */
2874 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2876 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2878 /* Skip type_unit_groups, reading the type units they contain
2879 is handled elsewhere. */
2880 if (IS_TYPE_UNIT_GROUP (per_cu
))
2883 /* The destructor of dwarf2_queue_guard frees any entries left on
2884 the queue. After this point we're guaranteed to leave this function
2885 with the dwarf queue empty. */
2886 dwarf2_queue_guard q_guard
;
2888 if (dwarf2_per_objfile
->using_index
2889 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2890 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2892 queue_comp_unit (per_cu
, language_minimal
);
2893 load_cu (per_cu
, skip_partial
);
2895 /* If we just loaded a CU from a DWO, and we're working with an index
2896 that may badly handle TUs, load all the TUs in that DWO as well.
2897 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2898 if (!per_cu
->is_debug_types
2899 && per_cu
->cu
!= NULL
2900 && per_cu
->cu
->dwo_unit
!= NULL
2901 && dwarf2_per_objfile
->index_table
!= NULL
2902 && dwarf2_per_objfile
->index_table
->version
<= 7
2903 /* DWP files aren't supported yet. */
2904 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2905 queue_and_load_all_dwo_tus (per_cu
);
2908 process_queue (dwarf2_per_objfile
);
2910 /* Age the cache, releasing compilation units that have not
2911 been used recently. */
2912 age_cached_comp_units (dwarf2_per_objfile
);
2915 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2916 the objfile from which this CU came. Returns the resulting symbol
2919 static struct compunit_symtab
*
2920 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2922 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2924 gdb_assert (dwarf2_per_objfile
->using_index
);
2925 if (!per_cu
->v
.quick
->compunit_symtab
)
2927 free_cached_comp_units
freer (dwarf2_per_objfile
);
2928 scoped_restore decrementer
= increment_reading_symtab ();
2929 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2930 process_cu_includes (dwarf2_per_objfile
);
2933 return per_cu
->v
.quick
->compunit_symtab
;
2936 /* See declaration. */
2938 dwarf2_per_cu_data
*
2939 dwarf2_per_objfile::get_cutu (int index
)
2941 if (index
>= this->all_comp_units
.size ())
2943 index
-= this->all_comp_units
.size ();
2944 gdb_assert (index
< this->all_type_units
.size ());
2945 return &this->all_type_units
[index
]->per_cu
;
2948 return this->all_comp_units
[index
];
2951 /* See declaration. */
2953 dwarf2_per_cu_data
*
2954 dwarf2_per_objfile::get_cu (int index
)
2956 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2958 return this->all_comp_units
[index
];
2961 /* See declaration. */
2964 dwarf2_per_objfile::get_tu (int index
)
2966 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2968 return this->all_type_units
[index
];
2971 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2972 objfile_obstack, and constructed with the specified field
2975 static dwarf2_per_cu_data
*
2976 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2977 struct dwarf2_section_info
*section
,
2979 sect_offset sect_off
, ULONGEST length
)
2981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2982 dwarf2_per_cu_data
*the_cu
2983 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2984 struct dwarf2_per_cu_data
);
2985 the_cu
->sect_off
= sect_off
;
2986 the_cu
->length
= length
;
2987 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2988 the_cu
->section
= section
;
2989 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2990 struct dwarf2_per_cu_quick_data
);
2991 the_cu
->is_dwz
= is_dwz
;
2995 /* A helper for create_cus_from_index that handles a given list of
2999 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3000 const gdb_byte
*cu_list
, offset_type n_elements
,
3001 struct dwarf2_section_info
*section
,
3004 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3006 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3008 sect_offset sect_off
3009 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3010 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3013 dwarf2_per_cu_data
*per_cu
3014 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3016 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3020 /* Read the CU list from the mapped index, and use it to create all
3021 the CU objects for this objfile. */
3024 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3025 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3026 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3028 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3029 dwarf2_per_objfile
->all_comp_units
.reserve
3030 ((cu_list_elements
+ dwz_elements
) / 2);
3032 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3033 &dwarf2_per_objfile
->info
, 0);
3035 if (dwz_elements
== 0)
3038 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3039 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3043 /* Create the signatured type hash table from the index. */
3046 create_signatured_type_table_from_index
3047 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3048 struct dwarf2_section_info
*section
,
3049 const gdb_byte
*bytes
,
3050 offset_type elements
)
3052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3054 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3055 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3057 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3059 for (offset_type i
= 0; i
< elements
; i
+= 3)
3061 struct signatured_type
*sig_type
;
3064 cu_offset type_offset_in_tu
;
3066 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3067 sect_offset sect_off
3068 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3070 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3072 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3075 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3076 struct signatured_type
);
3077 sig_type
->signature
= signature
;
3078 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3079 sig_type
->per_cu
.is_debug_types
= 1;
3080 sig_type
->per_cu
.section
= section
;
3081 sig_type
->per_cu
.sect_off
= sect_off
;
3082 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3083 sig_type
->per_cu
.v
.quick
3084 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3085 struct dwarf2_per_cu_quick_data
);
3087 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3090 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3093 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3096 /* Create the signatured type hash table from .debug_names. */
3099 create_signatured_type_table_from_debug_names
3100 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3101 const mapped_debug_names
&map
,
3102 struct dwarf2_section_info
*section
,
3103 struct dwarf2_section_info
*abbrev_section
)
3105 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3107 dwarf2_read_section (objfile
, section
);
3108 dwarf2_read_section (objfile
, abbrev_section
);
3110 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3111 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3113 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3115 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3117 struct signatured_type
*sig_type
;
3120 sect_offset sect_off
3121 = (sect_offset
) (extract_unsigned_integer
3122 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3124 map
.dwarf5_byte_order
));
3126 comp_unit_head cu_header
;
3127 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3129 section
->buffer
+ to_underlying (sect_off
),
3132 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3133 struct signatured_type
);
3134 sig_type
->signature
= cu_header
.signature
;
3135 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3136 sig_type
->per_cu
.is_debug_types
= 1;
3137 sig_type
->per_cu
.section
= section
;
3138 sig_type
->per_cu
.sect_off
= sect_off
;
3139 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3140 sig_type
->per_cu
.v
.quick
3141 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3142 struct dwarf2_per_cu_quick_data
);
3144 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3147 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3150 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3153 /* Read the address map data from the mapped index, and use it to
3154 populate the objfile's psymtabs_addrmap. */
3157 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3158 struct mapped_index
*index
)
3160 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3161 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3162 const gdb_byte
*iter
, *end
;
3163 struct addrmap
*mutable_map
;
3166 auto_obstack temp_obstack
;
3168 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3170 iter
= index
->address_table
.data ();
3171 end
= iter
+ index
->address_table
.size ();
3173 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3177 ULONGEST hi
, lo
, cu_index
;
3178 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3180 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3182 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3187 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3188 hex_string (lo
), hex_string (hi
));
3192 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3194 complaint (_(".gdb_index address table has invalid CU number %u"),
3195 (unsigned) cu_index
);
3199 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3200 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3201 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3202 dwarf2_per_objfile
->get_cu (cu_index
));
3205 objfile
->partial_symtabs
->psymtabs_addrmap
3206 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3209 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3210 populate the objfile's psymtabs_addrmap. */
3213 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3214 struct dwarf2_section_info
*section
)
3216 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3217 bfd
*abfd
= objfile
->obfd
;
3218 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3219 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3221 auto_obstack temp_obstack
;
3222 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3224 std::unordered_map
<sect_offset
,
3225 dwarf2_per_cu_data
*,
3226 gdb::hash_enum
<sect_offset
>>
3227 debug_info_offset_to_per_cu
;
3228 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3230 const auto insertpair
3231 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3232 if (!insertpair
.second
)
3234 warning (_("Section .debug_aranges in %s has duplicate "
3235 "debug_info_offset %s, ignoring .debug_aranges."),
3236 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3241 dwarf2_read_section (objfile
, section
);
3243 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3245 const gdb_byte
*addr
= section
->buffer
;
3247 while (addr
< section
->buffer
+ section
->size
)
3249 const gdb_byte
*const entry_addr
= addr
;
3250 unsigned int bytes_read
;
3252 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3256 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3257 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3258 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3259 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3261 warning (_("Section .debug_aranges in %s entry at offset %s "
3262 "length %s exceeds section length %s, "
3263 "ignoring .debug_aranges."),
3264 objfile_name (objfile
),
3265 plongest (entry_addr
- section
->buffer
),
3266 plongest (bytes_read
+ entry_length
),
3267 pulongest (section
->size
));
3271 /* The version number. */
3272 const uint16_t version
= read_2_bytes (abfd
, addr
);
3276 warning (_("Section .debug_aranges in %s entry at offset %s "
3277 "has unsupported version %d, ignoring .debug_aranges."),
3278 objfile_name (objfile
),
3279 plongest (entry_addr
- section
->buffer
), version
);
3283 const uint64_t debug_info_offset
3284 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3285 addr
+= offset_size
;
3286 const auto per_cu_it
3287 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3288 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3290 warning (_("Section .debug_aranges in %s entry at offset %s "
3291 "debug_info_offset %s does not exists, "
3292 "ignoring .debug_aranges."),
3293 objfile_name (objfile
),
3294 plongest (entry_addr
- section
->buffer
),
3295 pulongest (debug_info_offset
));
3298 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3300 const uint8_t address_size
= *addr
++;
3301 if (address_size
< 1 || address_size
> 8)
3303 warning (_("Section .debug_aranges in %s entry at offset %s "
3304 "address_size %u is invalid, ignoring .debug_aranges."),
3305 objfile_name (objfile
),
3306 plongest (entry_addr
- section
->buffer
), address_size
);
3310 const uint8_t segment_selector_size
= *addr
++;
3311 if (segment_selector_size
!= 0)
3313 warning (_("Section .debug_aranges in %s entry at offset %s "
3314 "segment_selector_size %u is not supported, "
3315 "ignoring .debug_aranges."),
3316 objfile_name (objfile
),
3317 plongest (entry_addr
- section
->buffer
),
3318 segment_selector_size
);
3322 /* Must pad to an alignment boundary that is twice the address
3323 size. It is undocumented by the DWARF standard but GCC does
3325 for (size_t padding
= ((-(addr
- section
->buffer
))
3326 & (2 * address_size
- 1));
3327 padding
> 0; padding
--)
3330 warning (_("Section .debug_aranges in %s entry at offset %s "
3331 "padding is not zero, ignoring .debug_aranges."),
3332 objfile_name (objfile
),
3333 plongest (entry_addr
- section
->buffer
));
3339 if (addr
+ 2 * address_size
> entry_end
)
3341 warning (_("Section .debug_aranges in %s entry at offset %s "
3342 "address list is not properly terminated, "
3343 "ignoring .debug_aranges."),
3344 objfile_name (objfile
),
3345 plongest (entry_addr
- section
->buffer
));
3348 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3350 addr
+= address_size
;
3351 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3353 addr
+= address_size
;
3354 if (start
== 0 && length
== 0)
3356 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3358 /* Symbol was eliminated due to a COMDAT group. */
3361 ULONGEST end
= start
+ length
;
3362 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3364 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3366 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3370 objfile
->partial_symtabs
->psymtabs_addrmap
3371 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3374 /* Find a slot in the mapped index INDEX for the object named NAME.
3375 If NAME is found, set *VEC_OUT to point to the CU vector in the
3376 constant pool and return true. If NAME cannot be found, return
3380 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3381 offset_type
**vec_out
)
3384 offset_type slot
, step
;
3385 int (*cmp
) (const char *, const char *);
3387 gdb::unique_xmalloc_ptr
<char> without_params
;
3388 if (current_language
->la_language
== language_cplus
3389 || current_language
->la_language
== language_fortran
3390 || current_language
->la_language
== language_d
)
3392 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3395 if (strchr (name
, '(') != NULL
)
3397 without_params
= cp_remove_params (name
);
3399 if (without_params
!= NULL
)
3400 name
= without_params
.get ();
3404 /* Index version 4 did not support case insensitive searches. But the
3405 indices for case insensitive languages are built in lowercase, therefore
3406 simulate our NAME being searched is also lowercased. */
3407 hash
= mapped_index_string_hash ((index
->version
== 4
3408 && case_sensitivity
== case_sensitive_off
3409 ? 5 : index
->version
),
3412 slot
= hash
& (index
->symbol_table
.size () - 1);
3413 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3414 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3420 const auto &bucket
= index
->symbol_table
[slot
];
3421 if (bucket
.name
== 0 && bucket
.vec
== 0)
3424 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3425 if (!cmp (name
, str
))
3427 *vec_out
= (offset_type
*) (index
->constant_pool
3428 + MAYBE_SWAP (bucket
.vec
));
3432 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3436 /* A helper function that reads the .gdb_index from BUFFER and fills
3437 in MAP. FILENAME is the name of the file containing the data;
3438 it is used for error reporting. DEPRECATED_OK is true if it is
3439 ok to use deprecated sections.
3441 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3442 out parameters that are filled in with information about the CU and
3443 TU lists in the section.
3445 Returns true if all went well, false otherwise. */
3448 read_gdb_index_from_buffer (struct objfile
*objfile
,
3449 const char *filename
,
3451 gdb::array_view
<const gdb_byte
> buffer
,
3452 struct mapped_index
*map
,
3453 const gdb_byte
**cu_list
,
3454 offset_type
*cu_list_elements
,
3455 const gdb_byte
**types_list
,
3456 offset_type
*types_list_elements
)
3458 const gdb_byte
*addr
= &buffer
[0];
3460 /* Version check. */
3461 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3462 /* Versions earlier than 3 emitted every copy of a psymbol. This
3463 causes the index to behave very poorly for certain requests. Version 3
3464 contained incomplete addrmap. So, it seems better to just ignore such
3468 static int warning_printed
= 0;
3469 if (!warning_printed
)
3471 warning (_("Skipping obsolete .gdb_index section in %s."),
3473 warning_printed
= 1;
3477 /* Index version 4 uses a different hash function than index version
3480 Versions earlier than 6 did not emit psymbols for inlined
3481 functions. Using these files will cause GDB not to be able to
3482 set breakpoints on inlined functions by name, so we ignore these
3483 indices unless the user has done
3484 "set use-deprecated-index-sections on". */
3485 if (version
< 6 && !deprecated_ok
)
3487 static int warning_printed
= 0;
3488 if (!warning_printed
)
3491 Skipping deprecated .gdb_index section in %s.\n\
3492 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3493 to use the section anyway."),
3495 warning_printed
= 1;
3499 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3500 of the TU (for symbols coming from TUs),
3501 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3502 Plus gold-generated indices can have duplicate entries for global symbols,
3503 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3504 These are just performance bugs, and we can't distinguish gdb-generated
3505 indices from gold-generated ones, so issue no warning here. */
3507 /* Indexes with higher version than the one supported by GDB may be no
3508 longer backward compatible. */
3512 map
->version
= version
;
3514 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3517 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3518 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3522 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3523 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3524 - MAYBE_SWAP (metadata
[i
]))
3528 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3529 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3531 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3534 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3535 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3537 = gdb::array_view
<mapped_index::symbol_table_slot
>
3538 ((mapped_index::symbol_table_slot
*) symbol_table
,
3539 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3542 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3547 /* Callback types for dwarf2_read_gdb_index. */
3549 typedef gdb::function_view
3550 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3551 get_gdb_index_contents_ftype
;
3552 typedef gdb::function_view
3553 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3554 get_gdb_index_contents_dwz_ftype
;
3556 /* Read .gdb_index. If everything went ok, initialize the "quick"
3557 elements of all the CUs and return 1. Otherwise, return 0. */
3560 dwarf2_read_gdb_index
3561 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3562 get_gdb_index_contents_ftype get_gdb_index_contents
,
3563 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3565 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3566 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3567 struct dwz_file
*dwz
;
3568 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3570 gdb::array_view
<const gdb_byte
> main_index_contents
3571 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3573 if (main_index_contents
.empty ())
3576 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3577 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3578 use_deprecated_index_sections
,
3579 main_index_contents
, map
.get (), &cu_list
,
3580 &cu_list_elements
, &types_list
,
3581 &types_list_elements
))
3584 /* Don't use the index if it's empty. */
3585 if (map
->symbol_table
.empty ())
3588 /* If there is a .dwz file, read it so we can get its CU list as
3590 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3593 struct mapped_index dwz_map
;
3594 const gdb_byte
*dwz_types_ignore
;
3595 offset_type dwz_types_elements_ignore
;
3597 gdb::array_view
<const gdb_byte
> dwz_index_content
3598 = get_gdb_index_contents_dwz (objfile
, dwz
);
3600 if (dwz_index_content
.empty ())
3603 if (!read_gdb_index_from_buffer (objfile
,
3604 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3605 1, dwz_index_content
, &dwz_map
,
3606 &dwz_list
, &dwz_list_elements
,
3608 &dwz_types_elements_ignore
))
3610 warning (_("could not read '.gdb_index' section from %s; skipping"),
3611 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3616 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3617 dwz_list
, dwz_list_elements
);
3619 if (types_list_elements
)
3621 /* We can only handle a single .debug_types when we have an
3623 if (dwarf2_per_objfile
->types
.size () != 1)
3626 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3628 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3629 types_list
, types_list_elements
);
3632 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3634 dwarf2_per_objfile
->index_table
= std::move (map
);
3635 dwarf2_per_objfile
->using_index
= 1;
3636 dwarf2_per_objfile
->quick_file_names_table
=
3637 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3642 /* die_reader_func for dw2_get_file_names. */
3645 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3646 const gdb_byte
*info_ptr
,
3647 struct die_info
*comp_unit_die
,
3651 struct dwarf2_cu
*cu
= reader
->cu
;
3652 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3653 struct dwarf2_per_objfile
*dwarf2_per_objfile
3654 = cu
->per_cu
->dwarf2_per_objfile
;
3655 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3656 struct dwarf2_per_cu_data
*lh_cu
;
3657 struct attribute
*attr
;
3659 struct quick_file_names
*qfn
;
3661 gdb_assert (! this_cu
->is_debug_types
);
3663 /* Our callers never want to match partial units -- instead they
3664 will match the enclosing full CU. */
3665 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3667 this_cu
->v
.quick
->no_file_data
= 1;
3675 sect_offset line_offset
{};
3677 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3678 if (attr
!= nullptr)
3680 struct quick_file_names find_entry
;
3682 line_offset
= (sect_offset
) DW_UNSND (attr
);
3684 /* We may have already read in this line header (TU line header sharing).
3685 If we have we're done. */
3686 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3687 find_entry
.hash
.line_sect_off
= line_offset
;
3688 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3689 &find_entry
, INSERT
);
3692 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3696 lh
= dwarf_decode_line_header (line_offset
, cu
);
3700 lh_cu
->v
.quick
->no_file_data
= 1;
3704 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3705 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3706 qfn
->hash
.line_sect_off
= line_offset
;
3707 gdb_assert (slot
!= NULL
);
3710 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3713 if (strcmp (fnd
.name
, "<unknown>") != 0)
3716 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3718 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3720 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3721 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3722 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3723 qfn
->real_names
= NULL
;
3725 lh_cu
->v
.quick
->file_names
= qfn
;
3728 /* A helper for the "quick" functions which attempts to read the line
3729 table for THIS_CU. */
3731 static struct quick_file_names
*
3732 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3734 /* This should never be called for TUs. */
3735 gdb_assert (! this_cu
->is_debug_types
);
3736 /* Nor type unit groups. */
3737 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3739 if (this_cu
->v
.quick
->file_names
!= NULL
)
3740 return this_cu
->v
.quick
->file_names
;
3741 /* If we know there is no line data, no point in looking again. */
3742 if (this_cu
->v
.quick
->no_file_data
)
3745 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3747 if (this_cu
->v
.quick
->no_file_data
)
3749 return this_cu
->v
.quick
->file_names
;
3752 /* A helper for the "quick" functions which computes and caches the
3753 real path for a given file name from the line table. */
3756 dw2_get_real_path (struct objfile
*objfile
,
3757 struct quick_file_names
*qfn
, int index
)
3759 if (qfn
->real_names
== NULL
)
3760 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3761 qfn
->num_file_names
, const char *);
3763 if (qfn
->real_names
[index
] == NULL
)
3764 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3766 return qfn
->real_names
[index
];
3769 static struct symtab
*
3770 dw2_find_last_source_symtab (struct objfile
*objfile
)
3772 struct dwarf2_per_objfile
*dwarf2_per_objfile
3773 = get_dwarf2_per_objfile (objfile
);
3774 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3775 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3780 return compunit_primary_filetab (cust
);
3783 /* Traversal function for dw2_forget_cached_source_info. */
3786 dw2_free_cached_file_names (void **slot
, void *info
)
3788 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3790 if (file_data
->real_names
)
3794 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3796 xfree ((void*) file_data
->real_names
[i
]);
3797 file_data
->real_names
[i
] = NULL
;
3805 dw2_forget_cached_source_info (struct objfile
*objfile
)
3807 struct dwarf2_per_objfile
*dwarf2_per_objfile
3808 = get_dwarf2_per_objfile (objfile
);
3810 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3811 dw2_free_cached_file_names
, NULL
);
3814 /* Helper function for dw2_map_symtabs_matching_filename that expands
3815 the symtabs and calls the iterator. */
3818 dw2_map_expand_apply (struct objfile
*objfile
,
3819 struct dwarf2_per_cu_data
*per_cu
,
3820 const char *name
, const char *real_path
,
3821 gdb::function_view
<bool (symtab
*)> callback
)
3823 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3825 /* Don't visit already-expanded CUs. */
3826 if (per_cu
->v
.quick
->compunit_symtab
)
3829 /* This may expand more than one symtab, and we want to iterate over
3831 dw2_instantiate_symtab (per_cu
, false);
3833 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3834 last_made
, callback
);
3837 /* Implementation of the map_symtabs_matching_filename method. */
3840 dw2_map_symtabs_matching_filename
3841 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3842 gdb::function_view
<bool (symtab
*)> callback
)
3844 const char *name_basename
= lbasename (name
);
3845 struct dwarf2_per_objfile
*dwarf2_per_objfile
3846 = get_dwarf2_per_objfile (objfile
);
3848 /* The rule is CUs specify all the files, including those used by
3849 any TU, so there's no need to scan TUs here. */
3851 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3853 /* We only need to look at symtabs not already expanded. */
3854 if (per_cu
->v
.quick
->compunit_symtab
)
3857 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3858 if (file_data
== NULL
)
3861 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3863 const char *this_name
= file_data
->file_names
[j
];
3864 const char *this_real_name
;
3866 if (compare_filenames_for_search (this_name
, name
))
3868 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3874 /* Before we invoke realpath, which can get expensive when many
3875 files are involved, do a quick comparison of the basenames. */
3876 if (! basenames_may_differ
3877 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3880 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3881 if (compare_filenames_for_search (this_real_name
, name
))
3883 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3889 if (real_path
!= NULL
)
3891 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3892 gdb_assert (IS_ABSOLUTE_PATH (name
));
3893 if (this_real_name
!= NULL
3894 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3896 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3908 /* Struct used to manage iterating over all CUs looking for a symbol. */
3910 struct dw2_symtab_iterator
3912 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3913 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3914 /* If set, only look for symbols that match that block. Valid values are
3915 GLOBAL_BLOCK and STATIC_BLOCK. */
3916 gdb::optional
<block_enum
> block_index
;
3917 /* The kind of symbol we're looking for. */
3919 /* The list of CUs from the index entry of the symbol,
3920 or NULL if not found. */
3922 /* The next element in VEC to look at. */
3924 /* The number of elements in VEC, or zero if there is no match. */
3926 /* Have we seen a global version of the symbol?
3927 If so we can ignore all further global instances.
3928 This is to work around gold/15646, inefficient gold-generated
3933 /* Initialize the index symtab iterator ITER. */
3936 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3937 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3938 gdb::optional
<block_enum
> block_index
,
3942 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3943 iter
->block_index
= block_index
;
3944 iter
->domain
= domain
;
3946 iter
->global_seen
= 0;
3948 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3950 /* index is NULL if OBJF_READNOW. */
3951 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3952 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3960 /* Return the next matching CU or NULL if there are no more. */
3962 static struct dwarf2_per_cu_data
*
3963 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3965 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3967 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3969 offset_type cu_index_and_attrs
=
3970 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3971 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3972 gdb_index_symbol_kind symbol_kind
=
3973 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3974 /* Only check the symbol attributes if they're present.
3975 Indices prior to version 7 don't record them,
3976 and indices >= 7 may elide them for certain symbols
3977 (gold does this). */
3979 (dwarf2_per_objfile
->index_table
->version
>= 7
3980 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3982 /* Don't crash on bad data. */
3983 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3984 + dwarf2_per_objfile
->all_type_units
.size ()))
3986 complaint (_(".gdb_index entry has bad CU index"
3988 objfile_name (dwarf2_per_objfile
->objfile
));
3992 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3994 /* Skip if already read in. */
3995 if (per_cu
->v
.quick
->compunit_symtab
)
3998 /* Check static vs global. */
4001 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4003 if (iter
->block_index
.has_value ())
4005 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4007 if (is_static
!= want_static
)
4011 /* Work around gold/15646. */
4012 if (!is_static
&& iter
->global_seen
)
4015 iter
->global_seen
= 1;
4018 /* Only check the symbol's kind if it has one. */
4021 switch (iter
->domain
)
4024 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4025 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4026 /* Some types are also in VAR_DOMAIN. */
4027 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4031 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4035 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4039 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4054 static struct compunit_symtab
*
4055 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4056 const char *name
, domain_enum domain
)
4058 struct compunit_symtab
*stab_best
= NULL
;
4059 struct dwarf2_per_objfile
*dwarf2_per_objfile
4060 = get_dwarf2_per_objfile (objfile
);
4062 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4064 struct dw2_symtab_iterator iter
;
4065 struct dwarf2_per_cu_data
*per_cu
;
4067 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4069 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4071 struct symbol
*sym
, *with_opaque
= NULL
;
4072 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4073 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4074 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4076 sym
= block_find_symbol (block
, name
, domain
,
4077 block_find_non_opaque_type_preferred
,
4080 /* Some caution must be observed with overloaded functions
4081 and methods, since the index will not contain any overload
4082 information (but NAME might contain it). */
4085 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4087 if (with_opaque
!= NULL
4088 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4091 /* Keep looking through other CUs. */
4098 dw2_print_stats (struct objfile
*objfile
)
4100 struct dwarf2_per_objfile
*dwarf2_per_objfile
4101 = get_dwarf2_per_objfile (objfile
);
4102 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4103 + dwarf2_per_objfile
->all_type_units
.size ());
4106 for (int i
= 0; i
< total
; ++i
)
4108 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4110 if (!per_cu
->v
.quick
->compunit_symtab
)
4113 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4114 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4117 /* This dumps minimal information about the index.
4118 It is called via "mt print objfiles".
4119 One use is to verify .gdb_index has been loaded by the
4120 gdb.dwarf2/gdb-index.exp testcase. */
4123 dw2_dump (struct objfile
*objfile
)
4125 struct dwarf2_per_objfile
*dwarf2_per_objfile
4126 = get_dwarf2_per_objfile (objfile
);
4128 gdb_assert (dwarf2_per_objfile
->using_index
);
4129 printf_filtered (".gdb_index:");
4130 if (dwarf2_per_objfile
->index_table
!= NULL
)
4132 printf_filtered (" version %d\n",
4133 dwarf2_per_objfile
->index_table
->version
);
4136 printf_filtered (" faked for \"readnow\"\n");
4137 printf_filtered ("\n");
4141 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4142 const char *func_name
)
4144 struct dwarf2_per_objfile
*dwarf2_per_objfile
4145 = get_dwarf2_per_objfile (objfile
);
4147 struct dw2_symtab_iterator iter
;
4148 struct dwarf2_per_cu_data
*per_cu
;
4150 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4152 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4153 dw2_instantiate_symtab (per_cu
, false);
4158 dw2_expand_all_symtabs (struct objfile
*objfile
)
4160 struct dwarf2_per_objfile
*dwarf2_per_objfile
4161 = get_dwarf2_per_objfile (objfile
);
4162 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4163 + dwarf2_per_objfile
->all_type_units
.size ());
4165 for (int i
= 0; i
< total_units
; ++i
)
4167 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4169 /* We don't want to directly expand a partial CU, because if we
4170 read it with the wrong language, then assertion failures can
4171 be triggered later on. See PR symtab/23010. So, tell
4172 dw2_instantiate_symtab to skip partial CUs -- any important
4173 partial CU will be read via DW_TAG_imported_unit anyway. */
4174 dw2_instantiate_symtab (per_cu
, true);
4179 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4180 const char *fullname
)
4182 struct dwarf2_per_objfile
*dwarf2_per_objfile
4183 = get_dwarf2_per_objfile (objfile
);
4185 /* We don't need to consider type units here.
4186 This is only called for examining code, e.g. expand_line_sal.
4187 There can be an order of magnitude (or more) more type units
4188 than comp units, and we avoid them if we can. */
4190 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4192 /* We only need to look at symtabs not already expanded. */
4193 if (per_cu
->v
.quick
->compunit_symtab
)
4196 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4197 if (file_data
== NULL
)
4200 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4202 const char *this_fullname
= file_data
->file_names
[j
];
4204 if (filename_cmp (this_fullname
, fullname
) == 0)
4206 dw2_instantiate_symtab (per_cu
, false);
4214 dw2_map_matching_symbols
4215 (struct objfile
*objfile
,
4216 const lookup_name_info
&name
, domain_enum domain
,
4218 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4219 symbol_compare_ftype
*ordered_compare
)
4221 /* Currently unimplemented; used for Ada. The function can be called if the
4222 current language is Ada for a non-Ada objfile using GNU index. As Ada
4223 does not look for non-Ada symbols this function should just return. */
4226 /* Starting from a search name, return the string that finds the upper
4227 bound of all strings that start with SEARCH_NAME in a sorted name
4228 list. Returns the empty string to indicate that the upper bound is
4229 the end of the list. */
4232 make_sort_after_prefix_name (const char *search_name
)
4234 /* When looking to complete "func", we find the upper bound of all
4235 symbols that start with "func" by looking for where we'd insert
4236 the closest string that would follow "func" in lexicographical
4237 order. Usually, that's "func"-with-last-character-incremented,
4238 i.e. "fund". Mind non-ASCII characters, though. Usually those
4239 will be UTF-8 multi-byte sequences, but we can't be certain.
4240 Especially mind the 0xff character, which is a valid character in
4241 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4242 rule out compilers allowing it in identifiers. Note that
4243 conveniently, strcmp/strcasecmp are specified to compare
4244 characters interpreted as unsigned char. So what we do is treat
4245 the whole string as a base 256 number composed of a sequence of
4246 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4247 to 0, and carries 1 to the following more-significant position.
4248 If the very first character in SEARCH_NAME ends up incremented
4249 and carries/overflows, then the upper bound is the end of the
4250 list. The string after the empty string is also the empty
4253 Some examples of this operation:
4255 SEARCH_NAME => "+1" RESULT
4259 "\xff" "a" "\xff" => "\xff" "b"
4264 Then, with these symbols for example:
4270 completing "func" looks for symbols between "func" and
4271 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4272 which finds "func" and "func1", but not "fund".
4276 funcÿ (Latin1 'ÿ' [0xff])
4280 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4281 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4285 ÿÿ (Latin1 'ÿ' [0xff])
4288 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4289 the end of the list.
4291 std::string after
= search_name
;
4292 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4294 if (!after
.empty ())
4295 after
.back () = (unsigned char) after
.back () + 1;
4299 /* See declaration. */
4301 std::pair
<std::vector
<name_component
>::const_iterator
,
4302 std::vector
<name_component
>::const_iterator
>
4303 mapped_index_base::find_name_components_bounds
4304 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4307 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4309 const char *lang_name
4310 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4312 /* Comparison function object for lower_bound that matches against a
4313 given symbol name. */
4314 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4317 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4318 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4319 return name_cmp (elem_name
, name
) < 0;
4322 /* Comparison function object for upper_bound that matches against a
4323 given symbol name. */
4324 auto lookup_compare_upper
= [&] (const char *name
,
4325 const name_component
&elem
)
4327 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4328 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4329 return name_cmp (name
, elem_name
) < 0;
4332 auto begin
= this->name_components
.begin ();
4333 auto end
= this->name_components
.end ();
4335 /* Find the lower bound. */
4338 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4341 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4344 /* Find the upper bound. */
4347 if (lookup_name_without_params
.completion_mode ())
4349 /* In completion mode, we want UPPER to point past all
4350 symbols names that have the same prefix. I.e., with
4351 these symbols, and completing "func":
4353 function << lower bound
4355 other_function << upper bound
4357 We find the upper bound by looking for the insertion
4358 point of "func"-with-last-character-incremented,
4360 std::string after
= make_sort_after_prefix_name (lang_name
);
4363 return std::lower_bound (lower
, end
, after
.c_str (),
4364 lookup_compare_lower
);
4367 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4370 return {lower
, upper
};
4373 /* See declaration. */
4376 mapped_index_base::build_name_components ()
4378 if (!this->name_components
.empty ())
4381 this->name_components_casing
= case_sensitivity
;
4383 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4385 /* The code below only knows how to break apart components of C++
4386 symbol names (and other languages that use '::' as
4387 namespace/module separator) and Ada symbol names. */
4388 auto count
= this->symbol_name_count ();
4389 for (offset_type idx
= 0; idx
< count
; idx
++)
4391 if (this->symbol_name_slot_invalid (idx
))
4394 const char *name
= this->symbol_name_at (idx
);
4396 /* Add each name component to the name component table. */
4397 unsigned int previous_len
= 0;
4399 if (strstr (name
, "::") != nullptr)
4401 for (unsigned int current_len
= cp_find_first_component (name
);
4402 name
[current_len
] != '\0';
4403 current_len
+= cp_find_first_component (name
+ current_len
))
4405 gdb_assert (name
[current_len
] == ':');
4406 this->name_components
.push_back ({previous_len
, idx
});
4407 /* Skip the '::'. */
4409 previous_len
= current_len
;
4414 /* Handle the Ada encoded (aka mangled) form here. */
4415 for (const char *iter
= strstr (name
, "__");
4417 iter
= strstr (iter
, "__"))
4419 this->name_components
.push_back ({previous_len
, idx
});
4421 previous_len
= iter
- name
;
4425 this->name_components
.push_back ({previous_len
, idx
});
4428 /* Sort name_components elements by name. */
4429 auto name_comp_compare
= [&] (const name_component
&left
,
4430 const name_component
&right
)
4432 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4433 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4435 const char *left_name
= left_qualified
+ left
.name_offset
;
4436 const char *right_name
= right_qualified
+ right
.name_offset
;
4438 return name_cmp (left_name
, right_name
) < 0;
4441 std::sort (this->name_components
.begin (),
4442 this->name_components
.end (),
4446 /* Helper for dw2_expand_symtabs_matching that works with a
4447 mapped_index_base instead of the containing objfile. This is split
4448 to a separate function in order to be able to unit test the
4449 name_components matching using a mock mapped_index_base. For each
4450 symbol name that matches, calls MATCH_CALLBACK, passing it the
4451 symbol's index in the mapped_index_base symbol table. */
4454 dw2_expand_symtabs_matching_symbol
4455 (mapped_index_base
&index
,
4456 const lookup_name_info
&lookup_name_in
,
4457 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4458 enum search_domain kind
,
4459 gdb::function_view
<bool (offset_type
)> match_callback
)
4461 lookup_name_info lookup_name_without_params
4462 = lookup_name_in
.make_ignore_params ();
4464 /* Build the symbol name component sorted vector, if we haven't
4466 index
.build_name_components ();
4468 /* The same symbol may appear more than once in the range though.
4469 E.g., if we're looking for symbols that complete "w", and we have
4470 a symbol named "w1::w2", we'll find the two name components for
4471 that same symbol in the range. To be sure we only call the
4472 callback once per symbol, we first collect the symbol name
4473 indexes that matched in a temporary vector and ignore
4475 std::vector
<offset_type
> matches
;
4477 struct name_and_matcher
4479 symbol_name_matcher_ftype
*matcher
;
4480 const std::string
&name
;
4482 bool operator== (const name_and_matcher
&other
) const
4484 return matcher
== other
.matcher
&& name
== other
.name
;
4488 /* A vector holding all the different symbol name matchers, for all
4490 std::vector
<name_and_matcher
> matchers
;
4492 for (int i
= 0; i
< nr_languages
; i
++)
4494 enum language lang_e
= (enum language
) i
;
4496 const language_defn
*lang
= language_def (lang_e
);
4497 symbol_name_matcher_ftype
*name_matcher
4498 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4500 name_and_matcher key
{
4502 lookup_name_without_params
.language_lookup_name (lang_e
)
4505 /* Don't insert the same comparison routine more than once.
4506 Note that we do this linear walk. This is not a problem in
4507 practice because the number of supported languages is
4509 if (std::find (matchers
.begin (), matchers
.end (), key
)
4512 matchers
.push_back (std::move (key
));
4515 = index
.find_name_components_bounds (lookup_name_without_params
,
4518 /* Now for each symbol name in range, check to see if we have a name
4519 match, and if so, call the MATCH_CALLBACK callback. */
4521 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4523 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4525 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4526 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4529 matches
.push_back (bounds
.first
->idx
);
4533 std::sort (matches
.begin (), matches
.end ());
4535 /* Finally call the callback, once per match. */
4537 for (offset_type idx
: matches
)
4541 if (!match_callback (idx
))
4547 /* Above we use a type wider than idx's for 'prev', since 0 and
4548 (offset_type)-1 are both possible values. */
4549 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4554 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4556 /* A mock .gdb_index/.debug_names-like name index table, enough to
4557 exercise dw2_expand_symtabs_matching_symbol, which works with the
4558 mapped_index_base interface. Builds an index from the symbol list
4559 passed as parameter to the constructor. */
4560 class mock_mapped_index
: public mapped_index_base
4563 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4564 : m_symbol_table (symbols
)
4567 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4569 /* Return the number of names in the symbol table. */
4570 size_t symbol_name_count () const override
4572 return m_symbol_table
.size ();
4575 /* Get the name of the symbol at IDX in the symbol table. */
4576 const char *symbol_name_at (offset_type idx
) const override
4578 return m_symbol_table
[idx
];
4582 gdb::array_view
<const char *> m_symbol_table
;
4585 /* Convenience function that converts a NULL pointer to a "<null>"
4586 string, to pass to print routines. */
4589 string_or_null (const char *str
)
4591 return str
!= NULL
? str
: "<null>";
4594 /* Check if a lookup_name_info built from
4595 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4596 index. EXPECTED_LIST is the list of expected matches, in expected
4597 matching order. If no match expected, then an empty list is
4598 specified. Returns true on success. On failure prints a warning
4599 indicating the file:line that failed, and returns false. */
4602 check_match (const char *file
, int line
,
4603 mock_mapped_index
&mock_index
,
4604 const char *name
, symbol_name_match_type match_type
,
4605 bool completion_mode
,
4606 std::initializer_list
<const char *> expected_list
)
4608 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4610 bool matched
= true;
4612 auto mismatch
= [&] (const char *expected_str
,
4615 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4616 "expected=\"%s\", got=\"%s\"\n"),
4618 (match_type
== symbol_name_match_type::FULL
4620 name
, string_or_null (expected_str
), string_or_null (got
));
4624 auto expected_it
= expected_list
.begin ();
4625 auto expected_end
= expected_list
.end ();
4627 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4629 [&] (offset_type idx
)
4631 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4632 const char *expected_str
4633 = expected_it
== expected_end
? NULL
: *expected_it
++;
4635 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4636 mismatch (expected_str
, matched_name
);
4640 const char *expected_str
4641 = expected_it
== expected_end
? NULL
: *expected_it
++;
4642 if (expected_str
!= NULL
)
4643 mismatch (expected_str
, NULL
);
4648 /* The symbols added to the mock mapped_index for testing (in
4650 static const char *test_symbols
[] = {
4659 "ns2::tmpl<int>::foo2",
4660 "(anonymous namespace)::A::B::C",
4662 /* These are used to check that the increment-last-char in the
4663 matching algorithm for completion doesn't match "t1_fund" when
4664 completing "t1_func". */
4670 /* A UTF-8 name with multi-byte sequences to make sure that
4671 cp-name-parser understands this as a single identifier ("função"
4672 is "function" in PT). */
4675 /* \377 (0xff) is Latin1 'ÿ'. */
4678 /* \377 (0xff) is Latin1 'ÿ'. */
4682 /* A name with all sorts of complications. Starts with "z" to make
4683 it easier for the completion tests below. */
4684 #define Z_SYM_NAME \
4685 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4686 "::tuple<(anonymous namespace)::ui*, " \
4687 "std::default_delete<(anonymous namespace)::ui>, void>"
4692 /* Returns true if the mapped_index_base::find_name_component_bounds
4693 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4694 in completion mode. */
4697 check_find_bounds_finds (mapped_index_base
&index
,
4698 const char *search_name
,
4699 gdb::array_view
<const char *> expected_syms
)
4701 lookup_name_info
lookup_name (search_name
,
4702 symbol_name_match_type::FULL
, true);
4704 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4707 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4708 if (distance
!= expected_syms
.size ())
4711 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4713 auto nc_elem
= bounds
.first
+ exp_elem
;
4714 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4715 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4722 /* Test the lower-level mapped_index::find_name_component_bounds
4726 test_mapped_index_find_name_component_bounds ()
4728 mock_mapped_index
mock_index (test_symbols
);
4730 mock_index
.build_name_components ();
4732 /* Test the lower-level mapped_index::find_name_component_bounds
4733 method in completion mode. */
4735 static const char *expected_syms
[] = {
4740 SELF_CHECK (check_find_bounds_finds (mock_index
,
4741 "t1_func", expected_syms
));
4744 /* Check that the increment-last-char in the name matching algorithm
4745 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4747 static const char *expected_syms1
[] = {
4751 SELF_CHECK (check_find_bounds_finds (mock_index
,
4752 "\377", expected_syms1
));
4754 static const char *expected_syms2
[] = {
4757 SELF_CHECK (check_find_bounds_finds (mock_index
,
4758 "\377\377", expected_syms2
));
4762 /* Test dw2_expand_symtabs_matching_symbol. */
4765 test_dw2_expand_symtabs_matching_symbol ()
4767 mock_mapped_index
mock_index (test_symbols
);
4769 /* We let all tests run until the end even if some fails, for debug
4771 bool any_mismatch
= false;
4773 /* Create the expected symbols list (an initializer_list). Needed
4774 because lists have commas, and we need to pass them to CHECK,
4775 which is a macro. */
4776 #define EXPECT(...) { __VA_ARGS__ }
4778 /* Wrapper for check_match that passes down the current
4779 __FILE__/__LINE__. */
4780 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4781 any_mismatch |= !check_match (__FILE__, __LINE__, \
4783 NAME, MATCH_TYPE, COMPLETION_MODE, \
4786 /* Identity checks. */
4787 for (const char *sym
: test_symbols
)
4789 /* Should be able to match all existing symbols. */
4790 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4793 /* Should be able to match all existing symbols with
4795 std::string with_params
= std::string (sym
) + "(int)";
4796 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4799 /* Should be able to match all existing symbols with
4800 parameters and qualifiers. */
4801 with_params
= std::string (sym
) + " ( int ) const";
4802 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4805 /* This should really find sym, but cp-name-parser.y doesn't
4806 know about lvalue/rvalue qualifiers yet. */
4807 with_params
= std::string (sym
) + " ( int ) &&";
4808 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4812 /* Check that the name matching algorithm for completion doesn't get
4813 confused with Latin1 'ÿ' / 0xff. */
4815 static const char str
[] = "\377";
4816 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4817 EXPECT ("\377", "\377\377123"));
4820 /* Check that the increment-last-char in the matching algorithm for
4821 completion doesn't match "t1_fund" when completing "t1_func". */
4823 static const char str
[] = "t1_func";
4824 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4825 EXPECT ("t1_func", "t1_func1"));
4828 /* Check that completion mode works at each prefix of the expected
4831 static const char str
[] = "function(int)";
4832 size_t len
= strlen (str
);
4835 for (size_t i
= 1; i
< len
; i
++)
4837 lookup
.assign (str
, i
);
4838 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4839 EXPECT ("function"));
4843 /* While "w" is a prefix of both components, the match function
4844 should still only be called once. */
4846 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4848 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4852 /* Same, with a "complicated" symbol. */
4854 static const char str
[] = Z_SYM_NAME
;
4855 size_t len
= strlen (str
);
4858 for (size_t i
= 1; i
< len
; i
++)
4860 lookup
.assign (str
, i
);
4861 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4862 EXPECT (Z_SYM_NAME
));
4866 /* In FULL mode, an incomplete symbol doesn't match. */
4868 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4872 /* A complete symbol with parameters matches any overload, since the
4873 index has no overload info. */
4875 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4876 EXPECT ("std::zfunction", "std::zfunction2"));
4877 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4878 EXPECT ("std::zfunction", "std::zfunction2"));
4879 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4880 EXPECT ("std::zfunction", "std::zfunction2"));
4883 /* Check that whitespace is ignored appropriately. A symbol with a
4884 template argument list. */
4886 static const char expected
[] = "ns::foo<int>";
4887 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4889 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4893 /* Check that whitespace is ignored appropriately. A symbol with a
4894 template argument list that includes a pointer. */
4896 static const char expected
[] = "ns::foo<char*>";
4897 /* Try both completion and non-completion modes. */
4898 static const bool completion_mode
[2] = {false, true};
4899 for (size_t i
= 0; i
< 2; i
++)
4901 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4902 completion_mode
[i
], EXPECT (expected
));
4903 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4904 completion_mode
[i
], EXPECT (expected
));
4906 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4907 completion_mode
[i
], EXPECT (expected
));
4908 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4909 completion_mode
[i
], EXPECT (expected
));
4914 /* Check method qualifiers are ignored. */
4915 static const char expected
[] = "ns::foo<char*>";
4916 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4917 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4918 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4919 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4920 CHECK_MATCH ("foo < char * > ( int ) const",
4921 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4922 CHECK_MATCH ("foo < char * > ( int ) &&",
4923 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4926 /* Test lookup names that don't match anything. */
4928 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4931 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4935 /* Some wild matching tests, exercising "(anonymous namespace)",
4936 which should not be confused with a parameter list. */
4938 static const char *syms
[] = {
4942 "A :: B :: C ( int )",
4947 for (const char *s
: syms
)
4949 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4950 EXPECT ("(anonymous namespace)::A::B::C"));
4955 static const char expected
[] = "ns2::tmpl<int>::foo2";
4956 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4958 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4962 SELF_CHECK (!any_mismatch
);
4971 test_mapped_index_find_name_component_bounds ();
4972 test_dw2_expand_symtabs_matching_symbol ();
4975 }} // namespace selftests::dw2_expand_symtabs_matching
4977 #endif /* GDB_SELF_TEST */
4979 /* If FILE_MATCHER is NULL or if PER_CU has
4980 dwarf2_per_cu_quick_data::MARK set (see
4981 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4982 EXPANSION_NOTIFY on it. */
4985 dw2_expand_symtabs_matching_one
4986 (struct dwarf2_per_cu_data
*per_cu
,
4987 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4988 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4990 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4992 bool symtab_was_null
4993 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4995 dw2_instantiate_symtab (per_cu
, false);
4997 if (expansion_notify
!= NULL
4999 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5000 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5004 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5005 matched, to expand corresponding CUs that were marked. IDX is the
5006 index of the symbol name that matched. */
5009 dw2_expand_marked_cus
5010 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5011 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5012 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5015 offset_type
*vec
, vec_len
, vec_idx
;
5016 bool global_seen
= false;
5017 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5019 vec
= (offset_type
*) (index
.constant_pool
5020 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5021 vec_len
= MAYBE_SWAP (vec
[0]);
5022 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5024 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5025 /* This value is only valid for index versions >= 7. */
5026 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5027 gdb_index_symbol_kind symbol_kind
=
5028 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5029 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5030 /* Only check the symbol attributes if they're present.
5031 Indices prior to version 7 don't record them,
5032 and indices >= 7 may elide them for certain symbols
5033 (gold does this). */
5036 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5038 /* Work around gold/15646. */
5041 if (!is_static
&& global_seen
)
5047 /* Only check the symbol's kind if it has one. */
5052 case VARIABLES_DOMAIN
:
5053 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5056 case FUNCTIONS_DOMAIN
:
5057 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5061 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5064 case MODULES_DOMAIN
:
5065 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5073 /* Don't crash on bad data. */
5074 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5075 + dwarf2_per_objfile
->all_type_units
.size ()))
5077 complaint (_(".gdb_index entry has bad CU index"
5079 objfile_name (dwarf2_per_objfile
->objfile
));
5083 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5084 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5089 /* If FILE_MATCHER is non-NULL, set all the
5090 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5091 that match FILE_MATCHER. */
5094 dw_expand_symtabs_matching_file_matcher
5095 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5096 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5098 if (file_matcher
== NULL
)
5101 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5103 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5105 NULL
, xcalloc
, xfree
));
5106 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5108 NULL
, xcalloc
, xfree
));
5110 /* The rule is CUs specify all the files, including those used by
5111 any TU, so there's no need to scan TUs here. */
5113 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5117 per_cu
->v
.quick
->mark
= 0;
5119 /* We only need to look at symtabs not already expanded. */
5120 if (per_cu
->v
.quick
->compunit_symtab
)
5123 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5124 if (file_data
== NULL
)
5127 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5129 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5131 per_cu
->v
.quick
->mark
= 1;
5135 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5137 const char *this_real_name
;
5139 if (file_matcher (file_data
->file_names
[j
], false))
5141 per_cu
->v
.quick
->mark
= 1;
5145 /* Before we invoke realpath, which can get expensive when many
5146 files are involved, do a quick comparison of the basenames. */
5147 if (!basenames_may_differ
5148 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5152 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5153 if (file_matcher (this_real_name
, false))
5155 per_cu
->v
.quick
->mark
= 1;
5160 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5161 ? visited_found
.get ()
5162 : visited_not_found
.get (),
5169 dw2_expand_symtabs_matching
5170 (struct objfile
*objfile
,
5171 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5172 const lookup_name_info
&lookup_name
,
5173 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5174 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5175 enum search_domain kind
)
5177 struct dwarf2_per_objfile
*dwarf2_per_objfile
5178 = get_dwarf2_per_objfile (objfile
);
5180 /* index_table is NULL if OBJF_READNOW. */
5181 if (!dwarf2_per_objfile
->index_table
)
5184 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5186 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5188 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5190 kind
, [&] (offset_type idx
)
5192 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5193 expansion_notify
, kind
);
5198 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5201 static struct compunit_symtab
*
5202 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5207 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5208 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5211 if (cust
->includes
== NULL
)
5214 for (i
= 0; cust
->includes
[i
]; ++i
)
5216 struct compunit_symtab
*s
= cust
->includes
[i
];
5218 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5226 static struct compunit_symtab
*
5227 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5228 struct bound_minimal_symbol msymbol
,
5230 struct obj_section
*section
,
5233 struct dwarf2_per_cu_data
*data
;
5234 struct compunit_symtab
*result
;
5236 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5239 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
5240 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5241 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5245 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5246 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5247 paddress (get_objfile_arch (objfile
), pc
));
5250 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5253 gdb_assert (result
!= NULL
);
5258 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5259 void *data
, int need_fullname
)
5261 struct dwarf2_per_objfile
*dwarf2_per_objfile
5262 = get_dwarf2_per_objfile (objfile
);
5264 if (!dwarf2_per_objfile
->filenames_cache
)
5266 dwarf2_per_objfile
->filenames_cache
.emplace ();
5268 htab_up
visited (htab_create_alloc (10,
5269 htab_hash_pointer
, htab_eq_pointer
,
5270 NULL
, xcalloc
, xfree
));
5272 /* The rule is CUs specify all the files, including those used
5273 by any TU, so there's no need to scan TUs here. We can
5274 ignore file names coming from already-expanded CUs. */
5276 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5278 if (per_cu
->v
.quick
->compunit_symtab
)
5280 void **slot
= htab_find_slot (visited
.get (),
5281 per_cu
->v
.quick
->file_names
,
5284 *slot
= per_cu
->v
.quick
->file_names
;
5288 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5290 /* We only need to look at symtabs not already expanded. */
5291 if (per_cu
->v
.quick
->compunit_symtab
)
5294 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5295 if (file_data
== NULL
)
5298 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5301 /* Already visited. */
5306 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5308 const char *filename
= file_data
->file_names
[j
];
5309 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5314 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5316 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5319 this_real_name
= gdb_realpath (filename
);
5320 (*fun
) (filename
, this_real_name
.get (), data
);
5325 dw2_has_symbols (struct objfile
*objfile
)
5330 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5333 dw2_find_last_source_symtab
,
5334 dw2_forget_cached_source_info
,
5335 dw2_map_symtabs_matching_filename
,
5339 dw2_expand_symtabs_for_function
,
5340 dw2_expand_all_symtabs
,
5341 dw2_expand_symtabs_with_fullname
,
5342 dw2_map_matching_symbols
,
5343 dw2_expand_symtabs_matching
,
5344 dw2_find_pc_sect_compunit_symtab
,
5346 dw2_map_symbol_filenames
5349 /* DWARF-5 debug_names reader. */
5351 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5352 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5354 /* A helper function that reads the .debug_names section in SECTION
5355 and fills in MAP. FILENAME is the name of the file containing the
5356 section; it is used for error reporting.
5358 Returns true if all went well, false otherwise. */
5361 read_debug_names_from_section (struct objfile
*objfile
,
5362 const char *filename
,
5363 struct dwarf2_section_info
*section
,
5364 mapped_debug_names
&map
)
5366 if (dwarf2_section_empty_p (section
))
5369 /* Older elfutils strip versions could keep the section in the main
5370 executable while splitting it for the separate debug info file. */
5371 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5374 dwarf2_read_section (objfile
, section
);
5376 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5378 const gdb_byte
*addr
= section
->buffer
;
5380 bfd
*const abfd
= get_section_bfd_owner (section
);
5382 unsigned int bytes_read
;
5383 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5386 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5387 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5388 if (bytes_read
+ length
!= section
->size
)
5390 /* There may be multiple per-CU indices. */
5391 warning (_("Section .debug_names in %s length %s does not match "
5392 "section length %s, ignoring .debug_names."),
5393 filename
, plongest (bytes_read
+ length
),
5394 pulongest (section
->size
));
5398 /* The version number. */
5399 uint16_t version
= read_2_bytes (abfd
, addr
);
5403 warning (_("Section .debug_names in %s has unsupported version %d, "
5404 "ignoring .debug_names."),
5410 uint16_t padding
= read_2_bytes (abfd
, addr
);
5414 warning (_("Section .debug_names in %s has unsupported padding %d, "
5415 "ignoring .debug_names."),
5420 /* comp_unit_count - The number of CUs in the CU list. */
5421 map
.cu_count
= read_4_bytes (abfd
, addr
);
5424 /* local_type_unit_count - The number of TUs in the local TU
5426 map
.tu_count
= read_4_bytes (abfd
, addr
);
5429 /* foreign_type_unit_count - The number of TUs in the foreign TU
5431 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5433 if (foreign_tu_count
!= 0)
5435 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5436 "ignoring .debug_names."),
5437 filename
, static_cast<unsigned long> (foreign_tu_count
));
5441 /* bucket_count - The number of hash buckets in the hash lookup
5443 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5446 /* name_count - The number of unique names in the index. */
5447 map
.name_count
= read_4_bytes (abfd
, addr
);
5450 /* abbrev_table_size - The size in bytes of the abbreviations
5452 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5455 /* augmentation_string_size - The size in bytes of the augmentation
5456 string. This value is rounded up to a multiple of 4. */
5457 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5459 map
.augmentation_is_gdb
= ((augmentation_string_size
5460 == sizeof (dwarf5_augmentation
))
5461 && memcmp (addr
, dwarf5_augmentation
,
5462 sizeof (dwarf5_augmentation
)) == 0);
5463 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5464 addr
+= augmentation_string_size
;
5467 map
.cu_table_reordered
= addr
;
5468 addr
+= map
.cu_count
* map
.offset_size
;
5470 /* List of Local TUs */
5471 map
.tu_table_reordered
= addr
;
5472 addr
+= map
.tu_count
* map
.offset_size
;
5474 /* Hash Lookup Table */
5475 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5476 addr
+= map
.bucket_count
* 4;
5477 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5478 addr
+= map
.name_count
* 4;
5481 map
.name_table_string_offs_reordered
= addr
;
5482 addr
+= map
.name_count
* map
.offset_size
;
5483 map
.name_table_entry_offs_reordered
= addr
;
5484 addr
+= map
.name_count
* map
.offset_size
;
5486 const gdb_byte
*abbrev_table_start
= addr
;
5489 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5494 const auto insertpair
5495 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5496 if (!insertpair
.second
)
5498 warning (_("Section .debug_names in %s has duplicate index %s, "
5499 "ignoring .debug_names."),
5500 filename
, pulongest (index_num
));
5503 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5504 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5509 mapped_debug_names::index_val::attr attr
;
5510 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5512 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5514 if (attr
.form
== DW_FORM_implicit_const
)
5516 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5520 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5522 indexval
.attr_vec
.push_back (std::move (attr
));
5525 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5527 warning (_("Section .debug_names in %s has abbreviation_table "
5528 "of size %s vs. written as %u, ignoring .debug_names."),
5529 filename
, plongest (addr
- abbrev_table_start
),
5533 map
.entry_pool
= addr
;
5538 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5542 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5543 const mapped_debug_names
&map
,
5544 dwarf2_section_info
§ion
,
5547 sect_offset sect_off_prev
;
5548 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5550 sect_offset sect_off_next
;
5551 if (i
< map
.cu_count
)
5554 = (sect_offset
) (extract_unsigned_integer
5555 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5557 map
.dwarf5_byte_order
));
5560 sect_off_next
= (sect_offset
) section
.size
;
5563 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5564 dwarf2_per_cu_data
*per_cu
5565 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5566 sect_off_prev
, length
);
5567 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5569 sect_off_prev
= sect_off_next
;
5573 /* Read the CU list from the mapped index, and use it to create all
5574 the CU objects for this dwarf2_per_objfile. */
5577 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5578 const mapped_debug_names
&map
,
5579 const mapped_debug_names
&dwz_map
)
5581 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5582 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5584 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5585 dwarf2_per_objfile
->info
,
5586 false /* is_dwz */);
5588 if (dwz_map
.cu_count
== 0)
5591 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5592 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5596 /* Read .debug_names. If everything went ok, initialize the "quick"
5597 elements of all the CUs and return true. Otherwise, return false. */
5600 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5602 std::unique_ptr
<mapped_debug_names
> map
5603 (new mapped_debug_names (dwarf2_per_objfile
));
5604 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5605 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5607 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5608 &dwarf2_per_objfile
->debug_names
,
5612 /* Don't use the index if it's empty. */
5613 if (map
->name_count
== 0)
5616 /* If there is a .dwz file, read it so we can get its CU list as
5618 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5621 if (!read_debug_names_from_section (objfile
,
5622 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5623 &dwz
->debug_names
, dwz_map
))
5625 warning (_("could not read '.debug_names' section from %s; skipping"),
5626 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5631 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5633 if (map
->tu_count
!= 0)
5635 /* We can only handle a single .debug_types when we have an
5637 if (dwarf2_per_objfile
->types
.size () != 1)
5640 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5642 create_signatured_type_table_from_debug_names
5643 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5646 create_addrmap_from_aranges (dwarf2_per_objfile
,
5647 &dwarf2_per_objfile
->debug_aranges
);
5649 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5650 dwarf2_per_objfile
->using_index
= 1;
5651 dwarf2_per_objfile
->quick_file_names_table
=
5652 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5657 /* Type used to manage iterating over all CUs looking for a symbol for
5660 class dw2_debug_names_iterator
5663 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5664 gdb::optional
<block_enum
> block_index
,
5667 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5668 m_addr (find_vec_in_debug_names (map
, name
))
5671 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5672 search_domain search
, uint32_t namei
)
5675 m_addr (find_vec_in_debug_names (map
, namei
))
5678 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5679 block_enum block_index
, domain_enum domain
,
5681 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5682 m_addr (find_vec_in_debug_names (map
, namei
))
5685 /* Return the next matching CU or NULL if there are no more. */
5686 dwarf2_per_cu_data
*next ();
5689 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5691 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5694 /* The internalized form of .debug_names. */
5695 const mapped_debug_names
&m_map
;
5697 /* If set, only look for symbols that match that block. Valid values are
5698 GLOBAL_BLOCK and STATIC_BLOCK. */
5699 const gdb::optional
<block_enum
> m_block_index
;
5701 /* The kind of symbol we're looking for. */
5702 const domain_enum m_domain
= UNDEF_DOMAIN
;
5703 const search_domain m_search
= ALL_DOMAIN
;
5705 /* The list of CUs from the index entry of the symbol, or NULL if
5707 const gdb_byte
*m_addr
;
5711 mapped_debug_names::namei_to_name (uint32_t namei
) const
5713 const ULONGEST namei_string_offs
5714 = extract_unsigned_integer ((name_table_string_offs_reordered
5715 + namei
* offset_size
),
5718 return read_indirect_string_at_offset
5719 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5722 /* Find a slot in .debug_names for the object named NAME. If NAME is
5723 found, return pointer to its pool data. If NAME cannot be found,
5727 dw2_debug_names_iterator::find_vec_in_debug_names
5728 (const mapped_debug_names
&map
, const char *name
)
5730 int (*cmp
) (const char *, const char *);
5732 gdb::unique_xmalloc_ptr
<char> without_params
;
5733 if (current_language
->la_language
== language_cplus
5734 || current_language
->la_language
== language_fortran
5735 || current_language
->la_language
== language_d
)
5737 /* NAME is already canonical. Drop any qualifiers as
5738 .debug_names does not contain any. */
5740 if (strchr (name
, '(') != NULL
)
5742 without_params
= cp_remove_params (name
);
5743 if (without_params
!= NULL
)
5744 name
= without_params
.get ();
5748 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5750 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5752 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5753 (map
.bucket_table_reordered
5754 + (full_hash
% map
.bucket_count
)), 4,
5755 map
.dwarf5_byte_order
);
5759 if (namei
>= map
.name_count
)
5761 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5763 namei
, map
.name_count
,
5764 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5770 const uint32_t namei_full_hash
5771 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5772 (map
.hash_table_reordered
+ namei
), 4,
5773 map
.dwarf5_byte_order
);
5774 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5777 if (full_hash
== namei_full_hash
)
5779 const char *const namei_string
= map
.namei_to_name (namei
);
5781 #if 0 /* An expensive sanity check. */
5782 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5784 complaint (_("Wrong .debug_names hash for string at index %u "
5786 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5791 if (cmp (namei_string
, name
) == 0)
5793 const ULONGEST namei_entry_offs
5794 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5795 + namei
* map
.offset_size
),
5796 map
.offset_size
, map
.dwarf5_byte_order
);
5797 return map
.entry_pool
+ namei_entry_offs
;
5802 if (namei
>= map
.name_count
)
5808 dw2_debug_names_iterator::find_vec_in_debug_names
5809 (const mapped_debug_names
&map
, uint32_t namei
)
5811 if (namei
>= map
.name_count
)
5813 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5815 namei
, map
.name_count
,
5816 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5820 const ULONGEST namei_entry_offs
5821 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5822 + namei
* map
.offset_size
),
5823 map
.offset_size
, map
.dwarf5_byte_order
);
5824 return map
.entry_pool
+ namei_entry_offs
;
5827 /* See dw2_debug_names_iterator. */
5829 dwarf2_per_cu_data
*
5830 dw2_debug_names_iterator::next ()
5835 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5836 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5837 bfd
*const abfd
= objfile
->obfd
;
5841 unsigned int bytes_read
;
5842 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5843 m_addr
+= bytes_read
;
5847 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5848 if (indexval_it
== m_map
.abbrev_map
.cend ())
5850 complaint (_("Wrong .debug_names undefined abbrev code %s "
5852 pulongest (abbrev
), objfile_name (objfile
));
5855 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5856 enum class symbol_linkage
{
5860 } symbol_linkage_
= symbol_linkage::unknown
;
5861 dwarf2_per_cu_data
*per_cu
= NULL
;
5862 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5867 case DW_FORM_implicit_const
:
5868 ull
= attr
.implicit_const
;
5870 case DW_FORM_flag_present
:
5874 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5875 m_addr
+= bytes_read
;
5878 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5879 dwarf_form_name (attr
.form
),
5880 objfile_name (objfile
));
5883 switch (attr
.dw_idx
)
5885 case DW_IDX_compile_unit
:
5886 /* Don't crash on bad data. */
5887 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5889 complaint (_(".debug_names entry has bad CU index %s"
5892 objfile_name (dwarf2_per_objfile
->objfile
));
5895 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5897 case DW_IDX_type_unit
:
5898 /* Don't crash on bad data. */
5899 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5901 complaint (_(".debug_names entry has bad TU index %s"
5904 objfile_name (dwarf2_per_objfile
->objfile
));
5907 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5909 case DW_IDX_GNU_internal
:
5910 if (!m_map
.augmentation_is_gdb
)
5912 symbol_linkage_
= symbol_linkage::static_
;
5914 case DW_IDX_GNU_external
:
5915 if (!m_map
.augmentation_is_gdb
)
5917 symbol_linkage_
= symbol_linkage::extern_
;
5922 /* Skip if already read in. */
5923 if (per_cu
->v
.quick
->compunit_symtab
)
5926 /* Check static vs global. */
5927 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5929 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5930 const bool symbol_is_static
=
5931 symbol_linkage_
== symbol_linkage::static_
;
5932 if (want_static
!= symbol_is_static
)
5936 /* Match dw2_symtab_iter_next, symbol_kind
5937 and debug_names::psymbol_tag. */
5941 switch (indexval
.dwarf_tag
)
5943 case DW_TAG_variable
:
5944 case DW_TAG_subprogram
:
5945 /* Some types are also in VAR_DOMAIN. */
5946 case DW_TAG_typedef
:
5947 case DW_TAG_structure_type
:
5954 switch (indexval
.dwarf_tag
)
5956 case DW_TAG_typedef
:
5957 case DW_TAG_structure_type
:
5964 switch (indexval
.dwarf_tag
)
5967 case DW_TAG_variable
:
5974 switch (indexval
.dwarf_tag
)
5986 /* Match dw2_expand_symtabs_matching, symbol_kind and
5987 debug_names::psymbol_tag. */
5990 case VARIABLES_DOMAIN
:
5991 switch (indexval
.dwarf_tag
)
5993 case DW_TAG_variable
:
5999 case FUNCTIONS_DOMAIN
:
6000 switch (indexval
.dwarf_tag
)
6002 case DW_TAG_subprogram
:
6009 switch (indexval
.dwarf_tag
)
6011 case DW_TAG_typedef
:
6012 case DW_TAG_structure_type
:
6018 case MODULES_DOMAIN
:
6019 switch (indexval
.dwarf_tag
)
6033 static struct compunit_symtab
*
6034 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6035 const char *name
, domain_enum domain
)
6037 struct dwarf2_per_objfile
*dwarf2_per_objfile
6038 = get_dwarf2_per_objfile (objfile
);
6040 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6043 /* index is NULL if OBJF_READNOW. */
6046 const auto &map
= *mapp
;
6048 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6050 struct compunit_symtab
*stab_best
= NULL
;
6051 struct dwarf2_per_cu_data
*per_cu
;
6052 while ((per_cu
= iter
.next ()) != NULL
)
6054 struct symbol
*sym
, *with_opaque
= NULL
;
6055 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6056 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6057 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6059 sym
= block_find_symbol (block
, name
, domain
,
6060 block_find_non_opaque_type_preferred
,
6063 /* Some caution must be observed with overloaded functions and
6064 methods, since the index will not contain any overload
6065 information (but NAME might contain it). */
6068 && strcmp_iw (sym
->search_name (), name
) == 0)
6070 if (with_opaque
!= NULL
6071 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6074 /* Keep looking through other CUs. */
6080 /* This dumps minimal information about .debug_names. It is called
6081 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6082 uses this to verify that .debug_names has been loaded. */
6085 dw2_debug_names_dump (struct objfile
*objfile
)
6087 struct dwarf2_per_objfile
*dwarf2_per_objfile
6088 = get_dwarf2_per_objfile (objfile
);
6090 gdb_assert (dwarf2_per_objfile
->using_index
);
6091 printf_filtered (".debug_names:");
6092 if (dwarf2_per_objfile
->debug_names_table
)
6093 printf_filtered (" exists\n");
6095 printf_filtered (" faked for \"readnow\"\n");
6096 printf_filtered ("\n");
6100 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6101 const char *func_name
)
6103 struct dwarf2_per_objfile
*dwarf2_per_objfile
6104 = get_dwarf2_per_objfile (objfile
);
6106 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6107 if (dwarf2_per_objfile
->debug_names_table
)
6109 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6111 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6113 struct dwarf2_per_cu_data
*per_cu
;
6114 while ((per_cu
= iter
.next ()) != NULL
)
6115 dw2_instantiate_symtab (per_cu
, false);
6120 dw2_debug_names_map_matching_symbols
6121 (struct objfile
*objfile
,
6122 const lookup_name_info
&name
, domain_enum domain
,
6124 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6125 symbol_compare_ftype
*ordered_compare
)
6127 struct dwarf2_per_objfile
*dwarf2_per_objfile
6128 = get_dwarf2_per_objfile (objfile
);
6130 /* debug_names_table is NULL if OBJF_READNOW. */
6131 if (!dwarf2_per_objfile
->debug_names_table
)
6134 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6135 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6137 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6138 auto matcher
= [&] (const char *symname
)
6140 if (ordered_compare
== nullptr)
6142 return ordered_compare (symname
, match_name
) == 0;
6145 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6146 [&] (offset_type namei
)
6148 /* The name was matched, now expand corresponding CUs that were
6150 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6152 struct dwarf2_per_cu_data
*per_cu
;
6153 while ((per_cu
= iter
.next ()) != NULL
)
6154 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6158 /* It's a shame we couldn't do this inside the
6159 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6160 that have already been expanded. Instead, this loop matches what
6161 the psymtab code does. */
6162 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6164 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6165 if (cust
!= nullptr)
6167 const struct block
*block
6168 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6169 if (!iterate_over_symbols_terminated (block
, name
,
6177 dw2_debug_names_expand_symtabs_matching
6178 (struct objfile
*objfile
,
6179 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6180 const lookup_name_info
&lookup_name
,
6181 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6182 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6183 enum search_domain kind
)
6185 struct dwarf2_per_objfile
*dwarf2_per_objfile
6186 = get_dwarf2_per_objfile (objfile
);
6188 /* debug_names_table is NULL if OBJF_READNOW. */
6189 if (!dwarf2_per_objfile
->debug_names_table
)
6192 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6194 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6196 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6198 kind
, [&] (offset_type namei
)
6200 /* The name was matched, now expand corresponding CUs that were
6202 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6204 struct dwarf2_per_cu_data
*per_cu
;
6205 while ((per_cu
= iter
.next ()) != NULL
)
6206 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6212 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6215 dw2_find_last_source_symtab
,
6216 dw2_forget_cached_source_info
,
6217 dw2_map_symtabs_matching_filename
,
6218 dw2_debug_names_lookup_symbol
,
6220 dw2_debug_names_dump
,
6221 dw2_debug_names_expand_symtabs_for_function
,
6222 dw2_expand_all_symtabs
,
6223 dw2_expand_symtabs_with_fullname
,
6224 dw2_debug_names_map_matching_symbols
,
6225 dw2_debug_names_expand_symtabs_matching
,
6226 dw2_find_pc_sect_compunit_symtab
,
6228 dw2_map_symbol_filenames
6231 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6232 to either a dwarf2_per_objfile or dwz_file object. */
6234 template <typename T
>
6235 static gdb::array_view
<const gdb_byte
>
6236 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6238 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6240 if (dwarf2_section_empty_p (section
))
6243 /* Older elfutils strip versions could keep the section in the main
6244 executable while splitting it for the separate debug info file. */
6245 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6248 dwarf2_read_section (obj
, section
);
6250 /* dwarf2_section_info::size is a bfd_size_type, while
6251 gdb::array_view works with size_t. On 32-bit hosts, with
6252 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6253 is 32-bit. So we need an explicit narrowing conversion here.
6254 This is fine, because it's impossible to allocate or mmap an
6255 array/buffer larger than what size_t can represent. */
6256 return gdb::make_array_view (section
->buffer
, section
->size
);
6259 /* Lookup the index cache for the contents of the index associated to
6262 static gdb::array_view
<const gdb_byte
>
6263 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6265 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6266 if (build_id
== nullptr)
6269 return global_index_cache
.lookup_gdb_index (build_id
,
6270 &dwarf2_obj
->index_cache_res
);
6273 /* Same as the above, but for DWZ. */
6275 static gdb::array_view
<const gdb_byte
>
6276 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6278 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6279 if (build_id
== nullptr)
6282 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6285 /* See symfile.h. */
6288 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6290 struct dwarf2_per_objfile
*dwarf2_per_objfile
6291 = get_dwarf2_per_objfile (objfile
);
6293 /* If we're about to read full symbols, don't bother with the
6294 indices. In this case we also don't care if some other debug
6295 format is making psymtabs, because they are all about to be
6297 if ((objfile
->flags
& OBJF_READNOW
))
6299 dwarf2_per_objfile
->using_index
= 1;
6300 create_all_comp_units (dwarf2_per_objfile
);
6301 create_all_type_units (dwarf2_per_objfile
);
6302 dwarf2_per_objfile
->quick_file_names_table
6303 = create_quick_file_names_table
6304 (dwarf2_per_objfile
->all_comp_units
.size ());
6306 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6307 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6309 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6311 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6312 struct dwarf2_per_cu_quick_data
);
6315 /* Return 1 so that gdb sees the "quick" functions. However,
6316 these functions will be no-ops because we will have expanded
6318 *index_kind
= dw_index_kind::GDB_INDEX
;
6322 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6324 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6328 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6329 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6330 get_gdb_index_contents_from_section
<dwz_file
>))
6332 *index_kind
= dw_index_kind::GDB_INDEX
;
6336 /* ... otherwise, try to find the index in the index cache. */
6337 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6338 get_gdb_index_contents_from_cache
,
6339 get_gdb_index_contents_from_cache_dwz
))
6341 global_index_cache
.hit ();
6342 *index_kind
= dw_index_kind::GDB_INDEX
;
6346 global_index_cache
.miss ();
6352 /* Build a partial symbol table. */
6355 dwarf2_build_psymtabs (struct objfile
*objfile
)
6357 struct dwarf2_per_objfile
*dwarf2_per_objfile
6358 = get_dwarf2_per_objfile (objfile
);
6360 init_psymbol_list (objfile
, 1024);
6364 /* This isn't really ideal: all the data we allocate on the
6365 objfile's obstack is still uselessly kept around. However,
6366 freeing it seems unsafe. */
6367 psymtab_discarder
psymtabs (objfile
);
6368 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6371 /* (maybe) store an index in the cache. */
6372 global_index_cache
.store (dwarf2_per_objfile
);
6374 catch (const gdb_exception_error
&except
)
6376 exception_print (gdb_stderr
, except
);
6380 /* Return the total length of the CU described by HEADER. */
6383 get_cu_length (const struct comp_unit_head
*header
)
6385 return header
->initial_length_size
+ header
->length
;
6388 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6391 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6393 sect_offset bottom
= cu_header
->sect_off
;
6394 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6396 return sect_off
>= bottom
&& sect_off
< top
;
6399 /* Find the base address of the compilation unit for range lists and
6400 location lists. It will normally be specified by DW_AT_low_pc.
6401 In DWARF-3 draft 4, the base address could be overridden by
6402 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6403 compilation units with discontinuous ranges. */
6406 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6408 struct attribute
*attr
;
6411 cu
->base_address
= 0;
6413 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6414 if (attr
!= nullptr)
6416 cu
->base_address
= attr_value_as_address (attr
);
6421 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6422 if (attr
!= nullptr)
6424 cu
->base_address
= attr_value_as_address (attr
);
6430 /* Read in the comp unit header information from the debug_info at info_ptr.
6431 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6432 NOTE: This leaves members offset, first_die_offset to be filled in
6435 static const gdb_byte
*
6436 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6437 const gdb_byte
*info_ptr
,
6438 struct dwarf2_section_info
*section
,
6439 rcuh_kind section_kind
)
6442 unsigned int bytes_read
;
6443 const char *filename
= get_section_file_name (section
);
6444 bfd
*abfd
= get_section_bfd_owner (section
);
6446 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6447 cu_header
->initial_length_size
= bytes_read
;
6448 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6449 info_ptr
+= bytes_read
;
6450 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6451 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6452 error (_("Dwarf Error: wrong version in compilation unit header "
6453 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6454 cu_header
->version
, filename
);
6456 if (cu_header
->version
< 5)
6457 switch (section_kind
)
6459 case rcuh_kind::COMPILE
:
6460 cu_header
->unit_type
= DW_UT_compile
;
6462 case rcuh_kind::TYPE
:
6463 cu_header
->unit_type
= DW_UT_type
;
6466 internal_error (__FILE__
, __LINE__
,
6467 _("read_comp_unit_head: invalid section_kind"));
6471 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6472 (read_1_byte (abfd
, info_ptr
));
6474 switch (cu_header
->unit_type
)
6478 case DW_UT_skeleton
:
6479 case DW_UT_split_compile
:
6480 if (section_kind
!= rcuh_kind::COMPILE
)
6481 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6482 "(is %s, should be %s) [in module %s]"),
6483 dwarf_unit_type_name (cu_header
->unit_type
),
6484 dwarf_unit_type_name (DW_UT_type
), filename
);
6487 case DW_UT_split_type
:
6488 section_kind
= rcuh_kind::TYPE
;
6491 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6492 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6493 "[in module %s]"), cu_header
->unit_type
,
6494 dwarf_unit_type_name (DW_UT_compile
),
6495 dwarf_unit_type_name (DW_UT_skeleton
),
6496 dwarf_unit_type_name (DW_UT_split_compile
),
6497 dwarf_unit_type_name (DW_UT_type
),
6498 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6501 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6504 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6507 info_ptr
+= bytes_read
;
6508 if (cu_header
->version
< 5)
6510 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6513 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6514 if (signed_addr
< 0)
6515 internal_error (__FILE__
, __LINE__
,
6516 _("read_comp_unit_head: dwarf from non elf file"));
6517 cu_header
->signed_addr_p
= signed_addr
;
6519 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6520 || cu_header
->unit_type
== DW_UT_skeleton
6521 || cu_header
->unit_type
== DW_UT_split_compile
;
6523 if (header_has_signature
)
6525 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6529 if (section_kind
== rcuh_kind::TYPE
)
6531 LONGEST type_offset
;
6532 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6533 info_ptr
+= bytes_read
;
6534 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6535 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6536 error (_("Dwarf Error: Too big type_offset in compilation unit "
6537 "header (is %s) [in module %s]"), plongest (type_offset
),
6544 /* Helper function that returns the proper abbrev section for
6547 static struct dwarf2_section_info
*
6548 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6550 struct dwarf2_section_info
*abbrev
;
6551 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6553 if (this_cu
->is_dwz
)
6554 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6556 abbrev
= &dwarf2_per_objfile
->abbrev
;
6561 /* Subroutine of read_and_check_comp_unit_head and
6562 read_and_check_type_unit_head to simplify them.
6563 Perform various error checking on the header. */
6566 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6567 struct comp_unit_head
*header
,
6568 struct dwarf2_section_info
*section
,
6569 struct dwarf2_section_info
*abbrev_section
)
6571 const char *filename
= get_section_file_name (section
);
6573 if (to_underlying (header
->abbrev_sect_off
)
6574 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6575 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6576 "(offset %s + 6) [in module %s]"),
6577 sect_offset_str (header
->abbrev_sect_off
),
6578 sect_offset_str (header
->sect_off
),
6581 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6582 avoid potential 32-bit overflow. */
6583 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6585 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6586 "(offset %s + 0) [in module %s]"),
6587 header
->length
, sect_offset_str (header
->sect_off
),
6591 /* Read in a CU/TU header and perform some basic error checking.
6592 The contents of the header are stored in HEADER.
6593 The result is a pointer to the start of the first DIE. */
6595 static const gdb_byte
*
6596 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6597 struct comp_unit_head
*header
,
6598 struct dwarf2_section_info
*section
,
6599 struct dwarf2_section_info
*abbrev_section
,
6600 const gdb_byte
*info_ptr
,
6601 rcuh_kind section_kind
)
6603 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6605 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6607 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6609 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6611 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6617 /* Fetch the abbreviation table offset from a comp or type unit header. */
6620 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6621 struct dwarf2_section_info
*section
,
6622 sect_offset sect_off
)
6624 bfd
*abfd
= get_section_bfd_owner (section
);
6625 const gdb_byte
*info_ptr
;
6626 unsigned int initial_length_size
, offset_size
;
6629 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6630 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6631 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6632 offset_size
= initial_length_size
== 4 ? 4 : 8;
6633 info_ptr
+= initial_length_size
;
6635 version
= read_2_bytes (abfd
, info_ptr
);
6639 /* Skip unit type and address size. */
6643 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6646 /* Allocate a new partial symtab for file named NAME and mark this new
6647 partial symtab as being an include of PST. */
6650 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6651 struct objfile
*objfile
)
6653 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6655 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6657 /* It shares objfile->objfile_obstack. */
6658 subpst
->dirname
= pst
->dirname
;
6661 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6662 subpst
->dependencies
[0] = pst
;
6663 subpst
->number_of_dependencies
= 1;
6665 subpst
->read_symtab
= pst
->read_symtab
;
6667 /* No private part is necessary for include psymtabs. This property
6668 can be used to differentiate between such include psymtabs and
6669 the regular ones. */
6670 subpst
->read_symtab_private
= NULL
;
6673 /* Read the Line Number Program data and extract the list of files
6674 included by the source file represented by PST. Build an include
6675 partial symtab for each of these included files. */
6678 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6679 struct die_info
*die
,
6680 struct partial_symtab
*pst
)
6683 struct attribute
*attr
;
6685 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6686 if (attr
!= nullptr)
6687 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6689 return; /* No linetable, so no includes. */
6691 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6692 that we pass in the raw text_low here; that is ok because we're
6693 only decoding the line table to make include partial symtabs, and
6694 so the addresses aren't really used. */
6695 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6696 pst
->raw_text_low (), 1);
6700 hash_signatured_type (const void *item
)
6702 const struct signatured_type
*sig_type
6703 = (const struct signatured_type
*) item
;
6705 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6706 return sig_type
->signature
;
6710 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6712 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6713 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6715 return lhs
->signature
== rhs
->signature
;
6718 /* Allocate a hash table for signatured types. */
6721 allocate_signatured_type_table (struct objfile
*objfile
)
6723 return htab_create_alloc_ex (41,
6724 hash_signatured_type
,
6727 &objfile
->objfile_obstack
,
6728 hashtab_obstack_allocate
,
6729 dummy_obstack_deallocate
);
6732 /* A helper function to add a signatured type CU to a table. */
6735 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6737 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6738 std::vector
<signatured_type
*> *all_type_units
6739 = (std::vector
<signatured_type
*> *) datum
;
6741 all_type_units
->push_back (sigt
);
6746 /* A helper for create_debug_types_hash_table. Read types from SECTION
6747 and fill them into TYPES_HTAB. It will process only type units,
6748 therefore DW_UT_type. */
6751 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6752 struct dwo_file
*dwo_file
,
6753 dwarf2_section_info
*section
, htab_t
&types_htab
,
6754 rcuh_kind section_kind
)
6756 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6757 struct dwarf2_section_info
*abbrev_section
;
6759 const gdb_byte
*info_ptr
, *end_ptr
;
6761 abbrev_section
= (dwo_file
!= NULL
6762 ? &dwo_file
->sections
.abbrev
6763 : &dwarf2_per_objfile
->abbrev
);
6765 if (dwarf_read_debug
)
6766 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6767 get_section_name (section
),
6768 get_section_file_name (abbrev_section
));
6770 dwarf2_read_section (objfile
, section
);
6771 info_ptr
= section
->buffer
;
6773 if (info_ptr
== NULL
)
6776 /* We can't set abfd until now because the section may be empty or
6777 not present, in which case the bfd is unknown. */
6778 abfd
= get_section_bfd_owner (section
);
6780 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6781 because we don't need to read any dies: the signature is in the
6784 end_ptr
= info_ptr
+ section
->size
;
6785 while (info_ptr
< end_ptr
)
6787 struct signatured_type
*sig_type
;
6788 struct dwo_unit
*dwo_tu
;
6790 const gdb_byte
*ptr
= info_ptr
;
6791 struct comp_unit_head header
;
6792 unsigned int length
;
6794 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6796 /* Initialize it due to a false compiler warning. */
6797 header
.signature
= -1;
6798 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6800 /* We need to read the type's signature in order to build the hash
6801 table, but we don't need anything else just yet. */
6803 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6804 abbrev_section
, ptr
, section_kind
);
6806 length
= get_cu_length (&header
);
6808 /* Skip dummy type units. */
6809 if (ptr
>= info_ptr
+ length
6810 || peek_abbrev_code (abfd
, ptr
) == 0
6811 || header
.unit_type
!= DW_UT_type
)
6817 if (types_htab
== NULL
)
6820 types_htab
= allocate_dwo_unit_table (objfile
);
6822 types_htab
= allocate_signatured_type_table (objfile
);
6828 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6830 dwo_tu
->dwo_file
= dwo_file
;
6831 dwo_tu
->signature
= header
.signature
;
6832 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6833 dwo_tu
->section
= section
;
6834 dwo_tu
->sect_off
= sect_off
;
6835 dwo_tu
->length
= length
;
6839 /* N.B.: type_offset is not usable if this type uses a DWO file.
6840 The real type_offset is in the DWO file. */
6842 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6843 struct signatured_type
);
6844 sig_type
->signature
= header
.signature
;
6845 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6846 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6847 sig_type
->per_cu
.is_debug_types
= 1;
6848 sig_type
->per_cu
.section
= section
;
6849 sig_type
->per_cu
.sect_off
= sect_off
;
6850 sig_type
->per_cu
.length
= length
;
6853 slot
= htab_find_slot (types_htab
,
6854 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6856 gdb_assert (slot
!= NULL
);
6859 sect_offset dup_sect_off
;
6863 const struct dwo_unit
*dup_tu
6864 = (const struct dwo_unit
*) *slot
;
6866 dup_sect_off
= dup_tu
->sect_off
;
6870 const struct signatured_type
*dup_tu
6871 = (const struct signatured_type
*) *slot
;
6873 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6876 complaint (_("debug type entry at offset %s is duplicate to"
6877 " the entry at offset %s, signature %s"),
6878 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6879 hex_string (header
.signature
));
6881 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6883 if (dwarf_read_debug
> 1)
6884 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6885 sect_offset_str (sect_off
),
6886 hex_string (header
.signature
));
6892 /* Create the hash table of all entries in the .debug_types
6893 (or .debug_types.dwo) section(s).
6894 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6895 otherwise it is NULL.
6897 The result is a pointer to the hash table or NULL if there are no types.
6899 Note: This function processes DWO files only, not DWP files. */
6902 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6903 struct dwo_file
*dwo_file
,
6904 gdb::array_view
<dwarf2_section_info
> type_sections
,
6907 for (dwarf2_section_info
§ion
: type_sections
)
6908 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6909 types_htab
, rcuh_kind::TYPE
);
6912 /* Create the hash table of all entries in the .debug_types section,
6913 and initialize all_type_units.
6914 The result is zero if there is an error (e.g. missing .debug_types section),
6915 otherwise non-zero. */
6918 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6920 htab_t types_htab
= NULL
;
6922 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6923 &dwarf2_per_objfile
->info
, types_htab
,
6924 rcuh_kind::COMPILE
);
6925 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6926 dwarf2_per_objfile
->types
, types_htab
);
6927 if (types_htab
== NULL
)
6929 dwarf2_per_objfile
->signatured_types
= NULL
;
6933 dwarf2_per_objfile
->signatured_types
= types_htab
;
6935 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6936 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6938 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6939 &dwarf2_per_objfile
->all_type_units
);
6944 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6945 If SLOT is non-NULL, it is the entry to use in the hash table.
6946 Otherwise we find one. */
6948 static struct signatured_type
*
6949 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6952 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6954 if (dwarf2_per_objfile
->all_type_units
.size ()
6955 == dwarf2_per_objfile
->all_type_units
.capacity ())
6956 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6958 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6959 struct signatured_type
);
6961 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6962 sig_type
->signature
= sig
;
6963 sig_type
->per_cu
.is_debug_types
= 1;
6964 if (dwarf2_per_objfile
->using_index
)
6966 sig_type
->per_cu
.v
.quick
=
6967 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6968 struct dwarf2_per_cu_quick_data
);
6973 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6976 gdb_assert (*slot
== NULL
);
6978 /* The rest of sig_type must be filled in by the caller. */
6982 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6983 Fill in SIG_ENTRY with DWO_ENTRY. */
6986 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6987 struct signatured_type
*sig_entry
,
6988 struct dwo_unit
*dwo_entry
)
6990 /* Make sure we're not clobbering something we don't expect to. */
6991 gdb_assert (! sig_entry
->per_cu
.queued
);
6992 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6993 if (dwarf2_per_objfile
->using_index
)
6995 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6996 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6999 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7000 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7001 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7002 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7003 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7005 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7006 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7007 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7008 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7009 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7010 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7011 sig_entry
->dwo_unit
= dwo_entry
;
7014 /* Subroutine of lookup_signatured_type.
7015 If we haven't read the TU yet, create the signatured_type data structure
7016 for a TU to be read in directly from a DWO file, bypassing the stub.
7017 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7018 using .gdb_index, then when reading a CU we want to stay in the DWO file
7019 containing that CU. Otherwise we could end up reading several other DWO
7020 files (due to comdat folding) to process the transitive closure of all the
7021 mentioned TUs, and that can be slow. The current DWO file will have every
7022 type signature that it needs.
7023 We only do this for .gdb_index because in the psymtab case we already have
7024 to read all the DWOs to build the type unit groups. */
7026 static struct signatured_type
*
7027 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7029 struct dwarf2_per_objfile
*dwarf2_per_objfile
7030 = cu
->per_cu
->dwarf2_per_objfile
;
7031 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7032 struct dwo_file
*dwo_file
;
7033 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7034 struct signatured_type find_sig_entry
, *sig_entry
;
7037 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7039 /* If TU skeletons have been removed then we may not have read in any
7041 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7043 dwarf2_per_objfile
->signatured_types
7044 = allocate_signatured_type_table (objfile
);
7047 /* We only ever need to read in one copy of a signatured type.
7048 Use the global signatured_types array to do our own comdat-folding
7049 of types. If this is the first time we're reading this TU, and
7050 the TU has an entry in .gdb_index, replace the recorded data from
7051 .gdb_index with this TU. */
7053 find_sig_entry
.signature
= sig
;
7054 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7055 &find_sig_entry
, INSERT
);
7056 sig_entry
= (struct signatured_type
*) *slot
;
7058 /* We can get here with the TU already read, *or* in the process of being
7059 read. Don't reassign the global entry to point to this DWO if that's
7060 the case. Also note that if the TU is already being read, it may not
7061 have come from a DWO, the program may be a mix of Fission-compiled
7062 code and non-Fission-compiled code. */
7064 /* Have we already tried to read this TU?
7065 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7066 needn't exist in the global table yet). */
7067 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7070 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7071 dwo_unit of the TU itself. */
7072 dwo_file
= cu
->dwo_unit
->dwo_file
;
7074 /* Ok, this is the first time we're reading this TU. */
7075 if (dwo_file
->tus
== NULL
)
7077 find_dwo_entry
.signature
= sig
;
7078 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7079 if (dwo_entry
== NULL
)
7082 /* If the global table doesn't have an entry for this TU, add one. */
7083 if (sig_entry
== NULL
)
7084 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7086 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7087 sig_entry
->per_cu
.tu_read
= 1;
7091 /* Subroutine of lookup_signatured_type.
7092 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7093 then try the DWP file. If the TU stub (skeleton) has been removed then
7094 it won't be in .gdb_index. */
7096 static struct signatured_type
*
7097 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7099 struct dwarf2_per_objfile
*dwarf2_per_objfile
7100 = cu
->per_cu
->dwarf2_per_objfile
;
7101 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7102 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7103 struct dwo_unit
*dwo_entry
;
7104 struct signatured_type find_sig_entry
, *sig_entry
;
7107 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7108 gdb_assert (dwp_file
!= NULL
);
7110 /* If TU skeletons have been removed then we may not have read in any
7112 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7114 dwarf2_per_objfile
->signatured_types
7115 = allocate_signatured_type_table (objfile
);
7118 find_sig_entry
.signature
= sig
;
7119 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7120 &find_sig_entry
, INSERT
);
7121 sig_entry
= (struct signatured_type
*) *slot
;
7123 /* Have we already tried to read this TU?
7124 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7125 needn't exist in the global table yet). */
7126 if (sig_entry
!= NULL
)
7129 if (dwp_file
->tus
== NULL
)
7131 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7132 sig
, 1 /* is_debug_types */);
7133 if (dwo_entry
== NULL
)
7136 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7137 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7142 /* Lookup a signature based type for DW_FORM_ref_sig8.
7143 Returns NULL if signature SIG is not present in the table.
7144 It is up to the caller to complain about this. */
7146 static struct signatured_type
*
7147 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7149 struct dwarf2_per_objfile
*dwarf2_per_objfile
7150 = cu
->per_cu
->dwarf2_per_objfile
;
7153 && dwarf2_per_objfile
->using_index
)
7155 /* We're in a DWO/DWP file, and we're using .gdb_index.
7156 These cases require special processing. */
7157 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7158 return lookup_dwo_signatured_type (cu
, sig
);
7160 return lookup_dwp_signatured_type (cu
, sig
);
7164 struct signatured_type find_entry
, *entry
;
7166 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7168 find_entry
.signature
= sig
;
7169 entry
= ((struct signatured_type
*)
7170 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7175 /* Low level DIE reading support. */
7177 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7180 init_cu_die_reader (struct die_reader_specs
*reader
,
7181 struct dwarf2_cu
*cu
,
7182 struct dwarf2_section_info
*section
,
7183 struct dwo_file
*dwo_file
,
7184 struct abbrev_table
*abbrev_table
)
7186 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7187 reader
->abfd
= get_section_bfd_owner (section
);
7189 reader
->dwo_file
= dwo_file
;
7190 reader
->die_section
= section
;
7191 reader
->buffer
= section
->buffer
;
7192 reader
->buffer_end
= section
->buffer
+ section
->size
;
7193 reader
->comp_dir
= NULL
;
7194 reader
->abbrev_table
= abbrev_table
;
7197 /* Subroutine of init_cutu_and_read_dies to simplify it.
7198 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7199 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7202 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7203 from it to the DIE in the DWO. If NULL we are skipping the stub.
7204 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7205 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7206 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7207 STUB_COMP_DIR may be non-NULL.
7208 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7209 are filled in with the info of the DIE from the DWO file.
7210 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7211 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7212 kept around for at least as long as *RESULT_READER.
7214 The result is non-zero if a valid (non-dummy) DIE was found. */
7217 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7218 struct dwo_unit
*dwo_unit
,
7219 struct die_info
*stub_comp_unit_die
,
7220 const char *stub_comp_dir
,
7221 struct die_reader_specs
*result_reader
,
7222 const gdb_byte
**result_info_ptr
,
7223 struct die_info
**result_comp_unit_die
,
7224 int *result_has_children
,
7225 abbrev_table_up
*result_dwo_abbrev_table
)
7227 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7228 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7229 struct dwarf2_cu
*cu
= this_cu
->cu
;
7231 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7232 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7233 int i
,num_extra_attrs
;
7234 struct dwarf2_section_info
*dwo_abbrev_section
;
7235 struct attribute
*attr
;
7236 struct die_info
*comp_unit_die
;
7238 /* At most one of these may be provided. */
7239 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7241 /* These attributes aren't processed until later:
7242 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7243 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7244 referenced later. However, these attributes are found in the stub
7245 which we won't have later. In order to not impose this complication
7246 on the rest of the code, we read them here and copy them to the
7255 if (stub_comp_unit_die
!= NULL
)
7257 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7259 if (! this_cu
->is_debug_types
)
7260 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7261 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7262 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7263 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7264 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7266 /* There should be a DW_AT_addr_base attribute here (if needed).
7267 We need the value before we can process DW_FORM_GNU_addr_index
7268 or DW_FORM_addrx. */
7270 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7271 if (attr
!= nullptr)
7272 cu
->addr_base
= DW_UNSND (attr
);
7274 /* There should be a DW_AT_ranges_base attribute here (if needed).
7275 We need the value before we can process DW_AT_ranges. */
7276 cu
->ranges_base
= 0;
7277 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7278 if (attr
!= nullptr)
7279 cu
->ranges_base
= DW_UNSND (attr
);
7281 else if (stub_comp_dir
!= NULL
)
7283 /* Reconstruct the comp_dir attribute to simplify the code below. */
7284 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7285 comp_dir
->name
= DW_AT_comp_dir
;
7286 comp_dir
->form
= DW_FORM_string
;
7287 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7288 DW_STRING (comp_dir
) = stub_comp_dir
;
7291 /* Set up for reading the DWO CU/TU. */
7292 cu
->dwo_unit
= dwo_unit
;
7293 dwarf2_section_info
*section
= dwo_unit
->section
;
7294 dwarf2_read_section (objfile
, section
);
7295 abfd
= get_section_bfd_owner (section
);
7296 begin_info_ptr
= info_ptr
= (section
->buffer
7297 + to_underlying (dwo_unit
->sect_off
));
7298 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7300 if (this_cu
->is_debug_types
)
7302 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7304 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7305 &cu
->header
, section
,
7307 info_ptr
, rcuh_kind::TYPE
);
7308 /* This is not an assert because it can be caused by bad debug info. */
7309 if (sig_type
->signature
!= cu
->header
.signature
)
7311 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7312 " TU at offset %s [in module %s]"),
7313 hex_string (sig_type
->signature
),
7314 hex_string (cu
->header
.signature
),
7315 sect_offset_str (dwo_unit
->sect_off
),
7316 bfd_get_filename (abfd
));
7318 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7319 /* For DWOs coming from DWP files, we don't know the CU length
7320 nor the type's offset in the TU until now. */
7321 dwo_unit
->length
= get_cu_length (&cu
->header
);
7322 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7324 /* Establish the type offset that can be used to lookup the type.
7325 For DWO files, we don't know it until now. */
7326 sig_type
->type_offset_in_section
7327 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7331 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7332 &cu
->header
, section
,
7334 info_ptr
, rcuh_kind::COMPILE
);
7335 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7336 /* For DWOs coming from DWP files, we don't know the CU length
7338 dwo_unit
->length
= get_cu_length (&cu
->header
);
7341 *result_dwo_abbrev_table
7342 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7343 cu
->header
.abbrev_sect_off
);
7344 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7345 result_dwo_abbrev_table
->get ());
7347 /* Read in the die, but leave space to copy over the attributes
7348 from the stub. This has the benefit of simplifying the rest of
7349 the code - all the work to maintain the illusion of a single
7350 DW_TAG_{compile,type}_unit DIE is done here. */
7351 num_extra_attrs
= ((stmt_list
!= NULL
)
7355 + (comp_dir
!= NULL
));
7356 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7357 result_has_children
, num_extra_attrs
);
7359 /* Copy over the attributes from the stub to the DIE we just read in. */
7360 comp_unit_die
= *result_comp_unit_die
;
7361 i
= comp_unit_die
->num_attrs
;
7362 if (stmt_list
!= NULL
)
7363 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7365 comp_unit_die
->attrs
[i
++] = *low_pc
;
7366 if (high_pc
!= NULL
)
7367 comp_unit_die
->attrs
[i
++] = *high_pc
;
7369 comp_unit_die
->attrs
[i
++] = *ranges
;
7370 if (comp_dir
!= NULL
)
7371 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7372 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7374 if (dwarf_die_debug
)
7376 fprintf_unfiltered (gdb_stdlog
,
7377 "Read die from %s@0x%x of %s:\n",
7378 get_section_name (section
),
7379 (unsigned) (begin_info_ptr
- section
->buffer
),
7380 bfd_get_filename (abfd
));
7381 dump_die (comp_unit_die
, dwarf_die_debug
);
7384 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7385 TUs by skipping the stub and going directly to the entry in the DWO file.
7386 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7387 to get it via circuitous means. Blech. */
7388 if (comp_dir
!= NULL
)
7389 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7391 /* Skip dummy compilation units. */
7392 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7393 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7396 *result_info_ptr
= info_ptr
;
7400 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7401 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7402 signature is part of the header. */
7403 static gdb::optional
<ULONGEST
>
7404 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7406 if (cu
->header
.version
>= 5)
7407 return cu
->header
.signature
;
7408 struct attribute
*attr
;
7409 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7410 if (attr
== nullptr)
7411 return gdb::optional
<ULONGEST
> ();
7412 return DW_UNSND (attr
);
7415 /* Subroutine of init_cutu_and_read_dies to simplify it.
7416 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7417 Returns NULL if the specified DWO unit cannot be found. */
7419 static struct dwo_unit
*
7420 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7421 struct die_info
*comp_unit_die
)
7423 struct dwarf2_cu
*cu
= this_cu
->cu
;
7424 struct dwo_unit
*dwo_unit
;
7425 const char *comp_dir
, *dwo_name
;
7427 gdb_assert (cu
!= NULL
);
7429 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7430 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7431 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7433 if (this_cu
->is_debug_types
)
7435 struct signatured_type
*sig_type
;
7437 /* Since this_cu is the first member of struct signatured_type,
7438 we can go from a pointer to one to a pointer to the other. */
7439 sig_type
= (struct signatured_type
*) this_cu
;
7440 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7444 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7445 if (!signature
.has_value ())
7446 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7448 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7449 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7456 /* Subroutine of init_cutu_and_read_dies to simplify it.
7457 See it for a description of the parameters.
7458 Read a TU directly from a DWO file, bypassing the stub. */
7461 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7462 int use_existing_cu
, int keep
,
7463 die_reader_func_ftype
*die_reader_func
,
7466 std::unique_ptr
<dwarf2_cu
> new_cu
;
7467 struct signatured_type
*sig_type
;
7468 struct die_reader_specs reader
;
7469 const gdb_byte
*info_ptr
;
7470 struct die_info
*comp_unit_die
;
7472 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7474 /* Verify we can do the following downcast, and that we have the
7476 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7477 sig_type
= (struct signatured_type
*) this_cu
;
7478 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7480 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7482 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7483 /* There's no need to do the rereading_dwo_cu handling that
7484 init_cutu_and_read_dies does since we don't read the stub. */
7488 /* If !use_existing_cu, this_cu->cu must be NULL. */
7489 gdb_assert (this_cu
->cu
== NULL
);
7490 new_cu
.reset (new dwarf2_cu (this_cu
));
7493 /* A future optimization, if needed, would be to use an existing
7494 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7495 could share abbrev tables. */
7497 /* The abbreviation table used by READER, this must live at least as long as
7499 abbrev_table_up dwo_abbrev_table
;
7501 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7502 NULL
/* stub_comp_unit_die */,
7503 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7505 &comp_unit_die
, &has_children
,
7506 &dwo_abbrev_table
) == 0)
7512 /* All the "real" work is done here. */
7513 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7515 /* This duplicates the code in init_cutu_and_read_dies,
7516 but the alternative is making the latter more complex.
7517 This function is only for the special case of using DWO files directly:
7518 no point in overly complicating the general case just to handle this. */
7519 if (new_cu
!= NULL
&& keep
)
7521 /* Link this CU into read_in_chain. */
7522 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7523 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7524 /* The chain owns it now. */
7529 /* Initialize a CU (or TU) and read its DIEs.
7530 If the CU defers to a DWO file, read the DWO file as well.
7532 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7533 Otherwise the table specified in the comp unit header is read in and used.
7534 This is an optimization for when we already have the abbrev table.
7536 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7537 Otherwise, a new CU is allocated with xmalloc.
7539 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7540 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7542 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7543 linker) then DIE_READER_FUNC will not get called. */
7546 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7547 struct abbrev_table
*abbrev_table
,
7548 int use_existing_cu
, int keep
,
7550 die_reader_func_ftype
*die_reader_func
,
7553 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7554 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7555 struct dwarf2_section_info
*section
= this_cu
->section
;
7556 bfd
*abfd
= get_section_bfd_owner (section
);
7557 struct dwarf2_cu
*cu
;
7558 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7559 struct die_reader_specs reader
;
7560 struct die_info
*comp_unit_die
;
7562 struct signatured_type
*sig_type
= NULL
;
7563 struct dwarf2_section_info
*abbrev_section
;
7564 /* Non-zero if CU currently points to a DWO file and we need to
7565 reread it. When this happens we need to reread the skeleton die
7566 before we can reread the DWO file (this only applies to CUs, not TUs). */
7567 int rereading_dwo_cu
= 0;
7569 if (dwarf_die_debug
)
7570 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7571 this_cu
->is_debug_types
? "type" : "comp",
7572 sect_offset_str (this_cu
->sect_off
));
7574 if (use_existing_cu
)
7577 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7578 file (instead of going through the stub), short-circuit all of this. */
7579 if (this_cu
->reading_dwo_directly
)
7581 /* Narrow down the scope of possibilities to have to understand. */
7582 gdb_assert (this_cu
->is_debug_types
);
7583 gdb_assert (abbrev_table
== NULL
);
7584 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7585 die_reader_func
, data
);
7589 /* This is cheap if the section is already read in. */
7590 dwarf2_read_section (objfile
, section
);
7592 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7594 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7596 std::unique_ptr
<dwarf2_cu
> new_cu
;
7597 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7600 /* If this CU is from a DWO file we need to start over, we need to
7601 refetch the attributes from the skeleton CU.
7602 This could be optimized by retrieving those attributes from when we
7603 were here the first time: the previous comp_unit_die was stored in
7604 comp_unit_obstack. But there's no data yet that we need this
7606 if (cu
->dwo_unit
!= NULL
)
7607 rereading_dwo_cu
= 1;
7611 /* If !use_existing_cu, this_cu->cu must be NULL. */
7612 gdb_assert (this_cu
->cu
== NULL
);
7613 new_cu
.reset (new dwarf2_cu (this_cu
));
7617 /* Get the header. */
7618 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7620 /* We already have the header, there's no need to read it in again. */
7621 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7625 if (this_cu
->is_debug_types
)
7627 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7628 &cu
->header
, section
,
7629 abbrev_section
, info_ptr
,
7632 /* Since per_cu is the first member of struct signatured_type,
7633 we can go from a pointer to one to a pointer to the other. */
7634 sig_type
= (struct signatured_type
*) this_cu
;
7635 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7636 gdb_assert (sig_type
->type_offset_in_tu
7637 == cu
->header
.type_cu_offset_in_tu
);
7638 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7640 /* LENGTH has not been set yet for type units if we're
7641 using .gdb_index. */
7642 this_cu
->length
= get_cu_length (&cu
->header
);
7644 /* Establish the type offset that can be used to lookup the type. */
7645 sig_type
->type_offset_in_section
=
7646 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7648 this_cu
->dwarf_version
= cu
->header
.version
;
7652 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7653 &cu
->header
, section
,
7656 rcuh_kind::COMPILE
);
7658 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7659 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7660 this_cu
->dwarf_version
= cu
->header
.version
;
7664 /* Skip dummy compilation units. */
7665 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7666 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7669 /* If we don't have them yet, read the abbrevs for this compilation unit.
7670 And if we need to read them now, make sure they're freed when we're
7671 done (own the table through ABBREV_TABLE_HOLDER). */
7672 abbrev_table_up abbrev_table_holder
;
7673 if (abbrev_table
!= NULL
)
7674 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7678 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7679 cu
->header
.abbrev_sect_off
);
7680 abbrev_table
= abbrev_table_holder
.get ();
7683 /* Read the top level CU/TU die. */
7684 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7685 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7687 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7690 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7691 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7692 table from the DWO file and pass the ownership over to us. It will be
7693 referenced from READER, so we must make sure to free it after we're done
7696 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7697 DWO CU, that this test will fail (the attribute will not be present). */
7698 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7699 abbrev_table_up dwo_abbrev_table
;
7700 if (dwo_name
!= nullptr)
7702 struct dwo_unit
*dwo_unit
;
7703 struct die_info
*dwo_comp_unit_die
;
7707 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7708 " has children (offset %s) [in module %s]"),
7709 sect_offset_str (this_cu
->sect_off
),
7710 bfd_get_filename (abfd
));
7712 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7713 if (dwo_unit
!= NULL
)
7715 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7716 comp_unit_die
, NULL
,
7718 &dwo_comp_unit_die
, &has_children
,
7719 &dwo_abbrev_table
) == 0)
7724 comp_unit_die
= dwo_comp_unit_die
;
7728 /* Yikes, we couldn't find the rest of the DIE, we only have
7729 the stub. A complaint has already been logged. There's
7730 not much more we can do except pass on the stub DIE to
7731 die_reader_func. We don't want to throw an error on bad
7736 /* All of the above is setup for this call. Yikes. */
7737 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7739 /* Done, clean up. */
7740 if (new_cu
!= NULL
&& keep
)
7742 /* Link this CU into read_in_chain. */
7743 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7744 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7745 /* The chain owns it now. */
7750 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7751 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7752 to have already done the lookup to find the DWO file).
7754 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7755 THIS_CU->is_debug_types, but nothing else.
7757 We fill in THIS_CU->length.
7759 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7760 linker) then DIE_READER_FUNC will not get called.
7762 THIS_CU->cu is always freed when done.
7763 This is done in order to not leave THIS_CU->cu in a state where we have
7764 to care whether it refers to the "main" CU or the DWO CU. */
7767 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7768 struct dwo_file
*dwo_file
,
7769 die_reader_func_ftype
*die_reader_func
,
7772 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7773 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7774 struct dwarf2_section_info
*section
= this_cu
->section
;
7775 bfd
*abfd
= get_section_bfd_owner (section
);
7776 struct dwarf2_section_info
*abbrev_section
;
7777 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7778 struct die_reader_specs reader
;
7779 struct die_info
*comp_unit_die
;
7782 if (dwarf_die_debug
)
7783 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7784 this_cu
->is_debug_types
? "type" : "comp",
7785 sect_offset_str (this_cu
->sect_off
));
7787 gdb_assert (this_cu
->cu
== NULL
);
7789 abbrev_section
= (dwo_file
!= NULL
7790 ? &dwo_file
->sections
.abbrev
7791 : get_abbrev_section_for_cu (this_cu
));
7793 /* This is cheap if the section is already read in. */
7794 dwarf2_read_section (objfile
, section
);
7796 struct dwarf2_cu
cu (this_cu
);
7798 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7799 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7800 &cu
.header
, section
,
7801 abbrev_section
, info_ptr
,
7802 (this_cu
->is_debug_types
7804 : rcuh_kind::COMPILE
));
7806 this_cu
->length
= get_cu_length (&cu
.header
);
7808 /* Skip dummy compilation units. */
7809 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7810 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7813 abbrev_table_up abbrev_table
7814 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7815 cu
.header
.abbrev_sect_off
);
7817 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7818 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7820 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7823 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7824 does not lookup the specified DWO file.
7825 This cannot be used to read DWO files.
7827 THIS_CU->cu is always freed when done.
7828 This is done in order to not leave THIS_CU->cu in a state where we have
7829 to care whether it refers to the "main" CU or the DWO CU.
7830 We can revisit this if the data shows there's a performance issue. */
7833 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7834 die_reader_func_ftype
*die_reader_func
,
7837 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7840 /* Type Unit Groups.
7842 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7843 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7844 so that all types coming from the same compilation (.o file) are grouped
7845 together. A future step could be to put the types in the same symtab as
7846 the CU the types ultimately came from. */
7849 hash_type_unit_group (const void *item
)
7851 const struct type_unit_group
*tu_group
7852 = (const struct type_unit_group
*) item
;
7854 return hash_stmt_list_entry (&tu_group
->hash
);
7858 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7860 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7861 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7863 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7866 /* Allocate a hash table for type unit groups. */
7869 allocate_type_unit_groups_table (struct objfile
*objfile
)
7871 return htab_create_alloc_ex (3,
7872 hash_type_unit_group
,
7875 &objfile
->objfile_obstack
,
7876 hashtab_obstack_allocate
,
7877 dummy_obstack_deallocate
);
7880 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7881 partial symtabs. We combine several TUs per psymtab to not let the size
7882 of any one psymtab grow too big. */
7883 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7884 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7886 /* Helper routine for get_type_unit_group.
7887 Create the type_unit_group object used to hold one or more TUs. */
7889 static struct type_unit_group
*
7890 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7892 struct dwarf2_per_objfile
*dwarf2_per_objfile
7893 = cu
->per_cu
->dwarf2_per_objfile
;
7894 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7895 struct dwarf2_per_cu_data
*per_cu
;
7896 struct type_unit_group
*tu_group
;
7898 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7899 struct type_unit_group
);
7900 per_cu
= &tu_group
->per_cu
;
7901 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7903 if (dwarf2_per_objfile
->using_index
)
7905 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7906 struct dwarf2_per_cu_quick_data
);
7910 unsigned int line_offset
= to_underlying (line_offset_struct
);
7911 struct partial_symtab
*pst
;
7914 /* Give the symtab a useful name for debug purposes. */
7915 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7916 name
= string_printf ("<type_units_%d>",
7917 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7919 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7921 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7925 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7926 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7931 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7932 STMT_LIST is a DW_AT_stmt_list attribute. */
7934 static struct type_unit_group
*
7935 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7937 struct dwarf2_per_objfile
*dwarf2_per_objfile
7938 = cu
->per_cu
->dwarf2_per_objfile
;
7939 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7940 struct type_unit_group
*tu_group
;
7942 unsigned int line_offset
;
7943 struct type_unit_group type_unit_group_for_lookup
;
7945 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7947 dwarf2_per_objfile
->type_unit_groups
=
7948 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7951 /* Do we need to create a new group, or can we use an existing one? */
7955 line_offset
= DW_UNSND (stmt_list
);
7956 ++tu_stats
->nr_symtab_sharers
;
7960 /* Ugh, no stmt_list. Rare, but we have to handle it.
7961 We can do various things here like create one group per TU or
7962 spread them over multiple groups to split up the expansion work.
7963 To avoid worst case scenarios (too many groups or too large groups)
7964 we, umm, group them in bunches. */
7965 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7966 | (tu_stats
->nr_stmt_less_type_units
7967 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7968 ++tu_stats
->nr_stmt_less_type_units
;
7971 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7972 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7973 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7974 &type_unit_group_for_lookup
, INSERT
);
7977 tu_group
= (struct type_unit_group
*) *slot
;
7978 gdb_assert (tu_group
!= NULL
);
7982 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7983 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7985 ++tu_stats
->nr_symtabs
;
7991 /* Partial symbol tables. */
7993 /* Create a psymtab named NAME and assign it to PER_CU.
7995 The caller must fill in the following details:
7996 dirname, textlow, texthigh. */
7998 static struct partial_symtab
*
7999 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8001 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8002 struct partial_symtab
*pst
;
8004 pst
= start_psymtab_common (objfile
, name
, 0);
8006 pst
->psymtabs_addrmap_supported
= 1;
8008 /* This is the glue that links PST into GDB's symbol API. */
8009 pst
->read_symtab_private
= per_cu
;
8010 pst
->read_symtab
= dwarf2_read_symtab
;
8011 per_cu
->v
.psymtab
= pst
;
8016 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8019 struct process_psymtab_comp_unit_data
8021 /* True if we are reading a DW_TAG_partial_unit. */
8023 int want_partial_unit
;
8025 /* The "pretend" language that is used if the CU doesn't declare a
8028 enum language pretend_language
;
8031 /* die_reader_func for process_psymtab_comp_unit. */
8034 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8035 const gdb_byte
*info_ptr
,
8036 struct die_info
*comp_unit_die
,
8040 struct dwarf2_cu
*cu
= reader
->cu
;
8041 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8042 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8043 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8045 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8046 struct partial_symtab
*pst
;
8047 enum pc_bounds_kind cu_bounds_kind
;
8048 const char *filename
;
8049 struct process_psymtab_comp_unit_data
*info
8050 = (struct process_psymtab_comp_unit_data
*) data
;
8052 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8055 gdb_assert (! per_cu
->is_debug_types
);
8057 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8059 /* Allocate a new partial symbol table structure. */
8060 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8061 if (filename
== NULL
)
8064 pst
= create_partial_symtab (per_cu
, filename
);
8066 /* This must be done before calling dwarf2_build_include_psymtabs. */
8067 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8069 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8071 dwarf2_find_base_address (comp_unit_die
, cu
);
8073 /* Possibly set the default values of LOWPC and HIGHPC from
8075 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8076 &best_highpc
, cu
, pst
);
8077 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8080 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8083 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8085 /* Store the contiguous range if it is not empty; it can be
8086 empty for CUs with no code. */
8087 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8091 /* Check if comp unit has_children.
8092 If so, read the rest of the partial symbols from this comp unit.
8093 If not, there's no more debug_info for this comp unit. */
8096 struct partial_die_info
*first_die
;
8097 CORE_ADDR lowpc
, highpc
;
8099 lowpc
= ((CORE_ADDR
) -1);
8100 highpc
= ((CORE_ADDR
) 0);
8102 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8104 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8105 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8107 /* If we didn't find a lowpc, set it to highpc to avoid
8108 complaints from `maint check'. */
8109 if (lowpc
== ((CORE_ADDR
) -1))
8112 /* If the compilation unit didn't have an explicit address range,
8113 then use the information extracted from its child dies. */
8114 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8117 best_highpc
= highpc
;
8120 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8121 best_lowpc
+ baseaddr
)
8123 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8124 best_highpc
+ baseaddr
)
8127 end_psymtab_common (objfile
, pst
);
8129 if (!cu
->per_cu
->imported_symtabs_empty ())
8132 int len
= cu
->per_cu
->imported_symtabs_size ();
8134 /* Fill in 'dependencies' here; we fill in 'users' in a
8136 pst
->number_of_dependencies
= len
;
8138 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8139 for (i
= 0; i
< len
; ++i
)
8141 pst
->dependencies
[i
]
8142 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8145 cu
->per_cu
->imported_symtabs_free ();
8148 /* Get the list of files included in the current compilation unit,
8149 and build a psymtab for each of them. */
8150 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8152 if (dwarf_read_debug
)
8153 fprintf_unfiltered (gdb_stdlog
,
8154 "Psymtab for %s unit @%s: %s - %s"
8155 ", %d global, %d static syms\n",
8156 per_cu
->is_debug_types
? "type" : "comp",
8157 sect_offset_str (per_cu
->sect_off
),
8158 paddress (gdbarch
, pst
->text_low (objfile
)),
8159 paddress (gdbarch
, pst
->text_high (objfile
)),
8160 pst
->n_global_syms
, pst
->n_static_syms
);
8163 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8164 Process compilation unit THIS_CU for a psymtab. */
8167 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8168 int want_partial_unit
,
8169 enum language pretend_language
)
8171 /* If this compilation unit was already read in, free the
8172 cached copy in order to read it in again. This is
8173 necessary because we skipped some symbols when we first
8174 read in the compilation unit (see load_partial_dies).
8175 This problem could be avoided, but the benefit is unclear. */
8176 if (this_cu
->cu
!= NULL
)
8177 free_one_cached_comp_unit (this_cu
);
8179 if (this_cu
->is_debug_types
)
8180 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8181 build_type_psymtabs_reader
, NULL
);
8184 process_psymtab_comp_unit_data info
;
8185 info
.want_partial_unit
= want_partial_unit
;
8186 info
.pretend_language
= pretend_language
;
8187 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8188 process_psymtab_comp_unit_reader
, &info
);
8191 /* Age out any secondary CUs. */
8192 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8195 /* Reader function for build_type_psymtabs. */
8198 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8199 const gdb_byte
*info_ptr
,
8200 struct die_info
*type_unit_die
,
8204 struct dwarf2_per_objfile
*dwarf2_per_objfile
8205 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8206 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8207 struct dwarf2_cu
*cu
= reader
->cu
;
8208 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8209 struct signatured_type
*sig_type
;
8210 struct type_unit_group
*tu_group
;
8211 struct attribute
*attr
;
8212 struct partial_die_info
*first_die
;
8213 CORE_ADDR lowpc
, highpc
;
8214 struct partial_symtab
*pst
;
8216 gdb_assert (data
== NULL
);
8217 gdb_assert (per_cu
->is_debug_types
);
8218 sig_type
= (struct signatured_type
*) per_cu
;
8223 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8224 tu_group
= get_type_unit_group (cu
, attr
);
8226 if (tu_group
->tus
== nullptr)
8227 tu_group
->tus
= new std::vector
<signatured_type
*>;
8228 tu_group
->tus
->push_back (sig_type
);
8230 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8231 pst
= create_partial_symtab (per_cu
, "");
8234 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8236 lowpc
= (CORE_ADDR
) -1;
8237 highpc
= (CORE_ADDR
) 0;
8238 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8240 end_psymtab_common (objfile
, pst
);
8243 /* Struct used to sort TUs by their abbreviation table offset. */
8245 struct tu_abbrev_offset
8247 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8248 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8251 signatured_type
*sig_type
;
8252 sect_offset abbrev_offset
;
8255 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8258 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8259 const struct tu_abbrev_offset
&b
)
8261 return a
.abbrev_offset
< b
.abbrev_offset
;
8264 /* Efficiently read all the type units.
8265 This does the bulk of the work for build_type_psymtabs.
8267 The efficiency is because we sort TUs by the abbrev table they use and
8268 only read each abbrev table once. In one program there are 200K TUs
8269 sharing 8K abbrev tables.
8271 The main purpose of this function is to support building the
8272 dwarf2_per_objfile->type_unit_groups table.
8273 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8274 can collapse the search space by grouping them by stmt_list.
8275 The savings can be significant, in the same program from above the 200K TUs
8276 share 8K stmt_list tables.
8278 FUNC is expected to call get_type_unit_group, which will create the
8279 struct type_unit_group if necessary and add it to
8280 dwarf2_per_objfile->type_unit_groups. */
8283 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8285 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8286 abbrev_table_up abbrev_table
;
8287 sect_offset abbrev_offset
;
8289 /* It's up to the caller to not call us multiple times. */
8290 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8292 if (dwarf2_per_objfile
->all_type_units
.empty ())
8295 /* TUs typically share abbrev tables, and there can be way more TUs than
8296 abbrev tables. Sort by abbrev table to reduce the number of times we
8297 read each abbrev table in.
8298 Alternatives are to punt or to maintain a cache of abbrev tables.
8299 This is simpler and efficient enough for now.
8301 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8302 symtab to use). Typically TUs with the same abbrev offset have the same
8303 stmt_list value too so in practice this should work well.
8305 The basic algorithm here is:
8307 sort TUs by abbrev table
8308 for each TU with same abbrev table:
8309 read abbrev table if first user
8310 read TU top level DIE
8311 [IWBN if DWO skeletons had DW_AT_stmt_list]
8314 if (dwarf_read_debug
)
8315 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8317 /* Sort in a separate table to maintain the order of all_type_units
8318 for .gdb_index: TU indices directly index all_type_units. */
8319 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8320 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8322 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8323 sorted_by_abbrev
.emplace_back
8324 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8325 sig_type
->per_cu
.section
,
8326 sig_type
->per_cu
.sect_off
));
8328 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8329 sort_tu_by_abbrev_offset
);
8331 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8333 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8335 /* Switch to the next abbrev table if necessary. */
8336 if (abbrev_table
== NULL
8337 || tu
.abbrev_offset
!= abbrev_offset
)
8339 abbrev_offset
= tu
.abbrev_offset
;
8341 abbrev_table_read_table (dwarf2_per_objfile
,
8342 &dwarf2_per_objfile
->abbrev
,
8344 ++tu_stats
->nr_uniq_abbrev_tables
;
8347 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8348 0, 0, false, build_type_psymtabs_reader
, NULL
);
8352 /* Print collected type unit statistics. */
8355 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8357 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8359 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8360 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8361 dwarf2_per_objfile
->all_type_units
.size ());
8362 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8363 tu_stats
->nr_uniq_abbrev_tables
);
8364 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8365 tu_stats
->nr_symtabs
);
8366 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8367 tu_stats
->nr_symtab_sharers
);
8368 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8369 tu_stats
->nr_stmt_less_type_units
);
8370 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8371 tu_stats
->nr_all_type_units_reallocs
);
8374 /* Traversal function for build_type_psymtabs. */
8377 build_type_psymtab_dependencies (void **slot
, void *info
)
8379 struct dwarf2_per_objfile
*dwarf2_per_objfile
8380 = (struct dwarf2_per_objfile
*) info
;
8381 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8382 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8383 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8384 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8385 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8388 gdb_assert (len
> 0);
8389 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8391 pst
->number_of_dependencies
= len
;
8392 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8393 for (i
= 0; i
< len
; ++i
)
8395 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8396 gdb_assert (iter
->per_cu
.is_debug_types
);
8397 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8398 iter
->type_unit_group
= tu_group
;
8401 delete tu_group
->tus
;
8402 tu_group
->tus
= nullptr;
8407 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8408 Build partial symbol tables for the .debug_types comp-units. */
8411 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8413 if (! create_all_type_units (dwarf2_per_objfile
))
8416 build_type_psymtabs_1 (dwarf2_per_objfile
);
8419 /* Traversal function for process_skeletonless_type_unit.
8420 Read a TU in a DWO file and build partial symbols for it. */
8423 process_skeletonless_type_unit (void **slot
, void *info
)
8425 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8426 struct dwarf2_per_objfile
*dwarf2_per_objfile
8427 = (struct dwarf2_per_objfile
*) info
;
8428 struct signatured_type find_entry
, *entry
;
8430 /* If this TU doesn't exist in the global table, add it and read it in. */
8432 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8434 dwarf2_per_objfile
->signatured_types
8435 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8438 find_entry
.signature
= dwo_unit
->signature
;
8439 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8441 /* If we've already seen this type there's nothing to do. What's happening
8442 is we're doing our own version of comdat-folding here. */
8446 /* This does the job that create_all_type_units would have done for
8448 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8449 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8452 /* This does the job that build_type_psymtabs_1 would have done. */
8453 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8454 build_type_psymtabs_reader
, NULL
);
8459 /* Traversal function for process_skeletonless_type_units. */
8462 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8464 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8466 if (dwo_file
->tus
!= NULL
)
8468 htab_traverse_noresize (dwo_file
->tus
,
8469 process_skeletonless_type_unit
, info
);
8475 /* Scan all TUs of DWO files, verifying we've processed them.
8476 This is needed in case a TU was emitted without its skeleton.
8477 Note: This can't be done until we know what all the DWO files are. */
8480 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8482 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8483 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8484 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8486 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8487 process_dwo_file_for_skeletonless_type_units
,
8488 dwarf2_per_objfile
);
8492 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8495 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8497 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8499 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8504 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8506 /* Set the 'user' field only if it is not already set. */
8507 if (pst
->dependencies
[j
]->user
== NULL
)
8508 pst
->dependencies
[j
]->user
= pst
;
8513 /* Build the partial symbol table by doing a quick pass through the
8514 .debug_info and .debug_abbrev sections. */
8517 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8519 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8521 if (dwarf_read_debug
)
8523 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8524 objfile_name (objfile
));
8527 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8529 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8531 /* Any cached compilation units will be linked by the per-objfile
8532 read_in_chain. Make sure to free them when we're done. */
8533 free_cached_comp_units
freer (dwarf2_per_objfile
);
8535 build_type_psymtabs (dwarf2_per_objfile
);
8537 create_all_comp_units (dwarf2_per_objfile
);
8539 /* Create a temporary address map on a temporary obstack. We later
8540 copy this to the final obstack. */
8541 auto_obstack temp_obstack
;
8543 scoped_restore save_psymtabs_addrmap
8544 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8545 addrmap_create_mutable (&temp_obstack
));
8547 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8548 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8550 /* This has to wait until we read the CUs, we need the list of DWOs. */
8551 process_skeletonless_type_units (dwarf2_per_objfile
);
8553 /* Now that all TUs have been processed we can fill in the dependencies. */
8554 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8556 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8557 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8560 if (dwarf_read_debug
)
8561 print_tu_stats (dwarf2_per_objfile
);
8563 set_partial_user (dwarf2_per_objfile
);
8565 objfile
->partial_symtabs
->psymtabs_addrmap
8566 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8567 objfile
->partial_symtabs
->obstack ());
8568 /* At this point we want to keep the address map. */
8569 save_psymtabs_addrmap
.release ();
8571 if (dwarf_read_debug
)
8572 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8573 objfile_name (objfile
));
8576 /* die_reader_func for load_partial_comp_unit. */
8579 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8580 const gdb_byte
*info_ptr
,
8581 struct die_info
*comp_unit_die
,
8585 struct dwarf2_cu
*cu
= reader
->cu
;
8587 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8589 /* Check if comp unit has_children.
8590 If so, read the rest of the partial symbols from this comp unit.
8591 If not, there's no more debug_info for this comp unit. */
8593 load_partial_dies (reader
, info_ptr
, 0);
8596 /* Load the partial DIEs for a secondary CU into memory.
8597 This is also used when rereading a primary CU with load_all_dies. */
8600 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8602 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8603 load_partial_comp_unit_reader
, NULL
);
8607 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8608 struct dwarf2_section_info
*section
,
8609 struct dwarf2_section_info
*abbrev_section
,
8610 unsigned int is_dwz
)
8612 const gdb_byte
*info_ptr
;
8613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8615 if (dwarf_read_debug
)
8616 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8617 get_section_name (section
),
8618 get_section_file_name (section
));
8620 dwarf2_read_section (objfile
, section
);
8622 info_ptr
= section
->buffer
;
8624 while (info_ptr
< section
->buffer
+ section
->size
)
8626 struct dwarf2_per_cu_data
*this_cu
;
8628 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8630 comp_unit_head cu_header
;
8631 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8632 abbrev_section
, info_ptr
,
8633 rcuh_kind::COMPILE
);
8635 /* Save the compilation unit for later lookup. */
8636 if (cu_header
.unit_type
!= DW_UT_type
)
8638 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8639 struct dwarf2_per_cu_data
);
8640 memset (this_cu
, 0, sizeof (*this_cu
));
8644 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8645 struct signatured_type
);
8646 memset (sig_type
, 0, sizeof (*sig_type
));
8647 sig_type
->signature
= cu_header
.signature
;
8648 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8649 this_cu
= &sig_type
->per_cu
;
8651 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8652 this_cu
->sect_off
= sect_off
;
8653 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8654 this_cu
->is_dwz
= is_dwz
;
8655 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8656 this_cu
->section
= section
;
8658 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8660 info_ptr
= info_ptr
+ this_cu
->length
;
8664 /* Create a list of all compilation units in OBJFILE.
8665 This is only done for -readnow and building partial symtabs. */
8668 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8670 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8671 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8672 &dwarf2_per_objfile
->abbrev
, 0);
8674 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8676 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8680 /* Process all loaded DIEs for compilation unit CU, starting at
8681 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8682 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8683 DW_AT_ranges). See the comments of add_partial_subprogram on how
8684 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8687 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8688 CORE_ADDR
*highpc
, int set_addrmap
,
8689 struct dwarf2_cu
*cu
)
8691 struct partial_die_info
*pdi
;
8693 /* Now, march along the PDI's, descending into ones which have
8694 interesting children but skipping the children of the other ones,
8695 until we reach the end of the compilation unit. */
8703 /* Anonymous namespaces or modules have no name but have interesting
8704 children, so we need to look at them. Ditto for anonymous
8707 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8708 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8709 || pdi
->tag
== DW_TAG_imported_unit
8710 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8714 case DW_TAG_subprogram
:
8715 case DW_TAG_inlined_subroutine
:
8716 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8718 case DW_TAG_constant
:
8719 case DW_TAG_variable
:
8720 case DW_TAG_typedef
:
8721 case DW_TAG_union_type
:
8722 if (!pdi
->is_declaration
)
8724 add_partial_symbol (pdi
, cu
);
8727 case DW_TAG_class_type
:
8728 case DW_TAG_interface_type
:
8729 case DW_TAG_structure_type
:
8730 if (!pdi
->is_declaration
)
8732 add_partial_symbol (pdi
, cu
);
8734 if ((cu
->language
== language_rust
8735 || cu
->language
== language_cplus
) && pdi
->has_children
)
8736 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8739 case DW_TAG_enumeration_type
:
8740 if (!pdi
->is_declaration
)
8741 add_partial_enumeration (pdi
, cu
);
8743 case DW_TAG_base_type
:
8744 case DW_TAG_subrange_type
:
8745 /* File scope base type definitions are added to the partial
8747 add_partial_symbol (pdi
, cu
);
8749 case DW_TAG_namespace
:
8750 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8753 if (!pdi
->is_declaration
)
8754 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8756 case DW_TAG_imported_unit
:
8758 struct dwarf2_per_cu_data
*per_cu
;
8760 /* For now we don't handle imported units in type units. */
8761 if (cu
->per_cu
->is_debug_types
)
8763 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8764 " supported in type units [in module %s]"),
8765 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8768 per_cu
= dwarf2_find_containing_comp_unit
8769 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8770 cu
->per_cu
->dwarf2_per_objfile
);
8772 /* Go read the partial unit, if needed. */
8773 if (per_cu
->v
.psymtab
== NULL
)
8774 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8776 cu
->per_cu
->imported_symtabs_push (per_cu
);
8779 case DW_TAG_imported_declaration
:
8780 add_partial_symbol (pdi
, cu
);
8787 /* If the die has a sibling, skip to the sibling. */
8789 pdi
= pdi
->die_sibling
;
8793 /* Functions used to compute the fully scoped name of a partial DIE.
8795 Normally, this is simple. For C++, the parent DIE's fully scoped
8796 name is concatenated with "::" and the partial DIE's name.
8797 Enumerators are an exception; they use the scope of their parent
8798 enumeration type, i.e. the name of the enumeration type is not
8799 prepended to the enumerator.
8801 There are two complexities. One is DW_AT_specification; in this
8802 case "parent" means the parent of the target of the specification,
8803 instead of the direct parent of the DIE. The other is compilers
8804 which do not emit DW_TAG_namespace; in this case we try to guess
8805 the fully qualified name of structure types from their members'
8806 linkage names. This must be done using the DIE's children rather
8807 than the children of any DW_AT_specification target. We only need
8808 to do this for structures at the top level, i.e. if the target of
8809 any DW_AT_specification (if any; otherwise the DIE itself) does not
8812 /* Compute the scope prefix associated with PDI's parent, in
8813 compilation unit CU. The result will be allocated on CU's
8814 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8815 field. NULL is returned if no prefix is necessary. */
8817 partial_die_parent_scope (struct partial_die_info
*pdi
,
8818 struct dwarf2_cu
*cu
)
8820 const char *grandparent_scope
;
8821 struct partial_die_info
*parent
, *real_pdi
;
8823 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8824 then this means the parent of the specification DIE. */
8827 while (real_pdi
->has_specification
)
8829 auto res
= find_partial_die (real_pdi
->spec_offset
,
8830 real_pdi
->spec_is_dwz
, cu
);
8835 parent
= real_pdi
->die_parent
;
8839 if (parent
->scope_set
)
8840 return parent
->scope
;
8844 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8846 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8847 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8848 Work around this problem here. */
8849 if (cu
->language
== language_cplus
8850 && parent
->tag
== DW_TAG_namespace
8851 && strcmp (parent
->name
, "::") == 0
8852 && grandparent_scope
== NULL
)
8854 parent
->scope
= NULL
;
8855 parent
->scope_set
= 1;
8859 /* Nested subroutines in Fortran get a prefix. */
8860 if (pdi
->tag
== DW_TAG_enumerator
)
8861 /* Enumerators should not get the name of the enumeration as a prefix. */
8862 parent
->scope
= grandparent_scope
;
8863 else if (parent
->tag
== DW_TAG_namespace
8864 || parent
->tag
== DW_TAG_module
8865 || parent
->tag
== DW_TAG_structure_type
8866 || parent
->tag
== DW_TAG_class_type
8867 || parent
->tag
== DW_TAG_interface_type
8868 || parent
->tag
== DW_TAG_union_type
8869 || parent
->tag
== DW_TAG_enumeration_type
8870 || (cu
->language
== language_fortran
8871 && parent
->tag
== DW_TAG_subprogram
8872 && pdi
->tag
== DW_TAG_subprogram
))
8874 if (grandparent_scope
== NULL
)
8875 parent
->scope
= parent
->name
;
8877 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8879 parent
->name
, 0, cu
);
8883 /* FIXME drow/2004-04-01: What should we be doing with
8884 function-local names? For partial symbols, we should probably be
8886 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8887 dwarf_tag_name (parent
->tag
),
8888 sect_offset_str (pdi
->sect_off
));
8889 parent
->scope
= grandparent_scope
;
8892 parent
->scope_set
= 1;
8893 return parent
->scope
;
8896 /* Return the fully scoped name associated with PDI, from compilation unit
8897 CU. The result will be allocated with malloc. */
8899 static gdb::unique_xmalloc_ptr
<char>
8900 partial_die_full_name (struct partial_die_info
*pdi
,
8901 struct dwarf2_cu
*cu
)
8903 const char *parent_scope
;
8905 /* If this is a template instantiation, we can not work out the
8906 template arguments from partial DIEs. So, unfortunately, we have
8907 to go through the full DIEs. At least any work we do building
8908 types here will be reused if full symbols are loaded later. */
8909 if (pdi
->has_template_arguments
)
8913 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8915 struct die_info
*die
;
8916 struct attribute attr
;
8917 struct dwarf2_cu
*ref_cu
= cu
;
8919 /* DW_FORM_ref_addr is using section offset. */
8920 attr
.name
= (enum dwarf_attribute
) 0;
8921 attr
.form
= DW_FORM_ref_addr
;
8922 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8923 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8925 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8929 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8930 if (parent_scope
== NULL
)
8933 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8938 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8940 struct dwarf2_per_objfile
*dwarf2_per_objfile
8941 = cu
->per_cu
->dwarf2_per_objfile
;
8942 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8943 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8945 const char *actual_name
= NULL
;
8948 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8950 gdb::unique_xmalloc_ptr
<char> built_actual_name
8951 = partial_die_full_name (pdi
, cu
);
8952 if (built_actual_name
!= NULL
)
8953 actual_name
= built_actual_name
.get ();
8955 if (actual_name
== NULL
)
8956 actual_name
= pdi
->name
;
8960 case DW_TAG_inlined_subroutine
:
8961 case DW_TAG_subprogram
:
8962 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8964 if (pdi
->is_external
8965 || cu
->language
== language_ada
8966 || (cu
->language
== language_fortran
8967 && pdi
->die_parent
!= NULL
8968 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8970 /* Normally, only "external" DIEs are part of the global scope.
8971 But in Ada and Fortran, we want to be able to access nested
8972 procedures globally. So all Ada and Fortran subprograms are
8973 stored in the global scope. */
8974 add_psymbol_to_list (actual_name
,
8975 built_actual_name
!= NULL
,
8976 VAR_DOMAIN
, LOC_BLOCK
,
8977 SECT_OFF_TEXT (objfile
),
8978 psymbol_placement::GLOBAL
,
8980 cu
->language
, objfile
);
8984 add_psymbol_to_list (actual_name
,
8985 built_actual_name
!= NULL
,
8986 VAR_DOMAIN
, LOC_BLOCK
,
8987 SECT_OFF_TEXT (objfile
),
8988 psymbol_placement::STATIC
,
8989 addr
, cu
->language
, objfile
);
8992 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8993 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8995 case DW_TAG_constant
:
8996 add_psymbol_to_list (actual_name
,
8997 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8998 -1, (pdi
->is_external
8999 ? psymbol_placement::GLOBAL
9000 : psymbol_placement::STATIC
),
9001 0, cu
->language
, objfile
);
9003 case DW_TAG_variable
:
9005 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9009 && !dwarf2_per_objfile
->has_section_at_zero
)
9011 /* A global or static variable may also have been stripped
9012 out by the linker if unused, in which case its address
9013 will be nullified; do not add such variables into partial
9014 symbol table then. */
9016 else if (pdi
->is_external
)
9019 Don't enter into the minimal symbol tables as there is
9020 a minimal symbol table entry from the ELF symbols already.
9021 Enter into partial symbol table if it has a location
9022 descriptor or a type.
9023 If the location descriptor is missing, new_symbol will create
9024 a LOC_UNRESOLVED symbol, the address of the variable will then
9025 be determined from the minimal symbol table whenever the variable
9027 The address for the partial symbol table entry is not
9028 used by GDB, but it comes in handy for debugging partial symbol
9031 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9032 add_psymbol_to_list (actual_name
,
9033 built_actual_name
!= NULL
,
9034 VAR_DOMAIN
, LOC_STATIC
,
9035 SECT_OFF_TEXT (objfile
),
9036 psymbol_placement::GLOBAL
,
9037 addr
, cu
->language
, objfile
);
9041 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9043 /* Static Variable. Skip symbols whose value we cannot know (those
9044 without location descriptors or constant values). */
9045 if (!has_loc
&& !pdi
->has_const_value
)
9048 add_psymbol_to_list (actual_name
,
9049 built_actual_name
!= NULL
,
9050 VAR_DOMAIN
, LOC_STATIC
,
9051 SECT_OFF_TEXT (objfile
),
9052 psymbol_placement::STATIC
,
9054 cu
->language
, objfile
);
9057 case DW_TAG_typedef
:
9058 case DW_TAG_base_type
:
9059 case DW_TAG_subrange_type
:
9060 add_psymbol_to_list (actual_name
,
9061 built_actual_name
!= NULL
,
9062 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9063 psymbol_placement::STATIC
,
9064 0, cu
->language
, objfile
);
9066 case DW_TAG_imported_declaration
:
9067 case DW_TAG_namespace
:
9068 add_psymbol_to_list (actual_name
,
9069 built_actual_name
!= NULL
,
9070 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9071 psymbol_placement::GLOBAL
,
9072 0, cu
->language
, objfile
);
9075 /* With Fortran 77 there might be a "BLOCK DATA" module
9076 available without any name. If so, we skip the module as it
9077 doesn't bring any value. */
9078 if (actual_name
!= nullptr)
9079 add_psymbol_to_list (actual_name
,
9080 built_actual_name
!= NULL
,
9081 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9082 psymbol_placement::GLOBAL
,
9083 0, cu
->language
, objfile
);
9085 case DW_TAG_class_type
:
9086 case DW_TAG_interface_type
:
9087 case DW_TAG_structure_type
:
9088 case DW_TAG_union_type
:
9089 case DW_TAG_enumeration_type
:
9090 /* Skip external references. The DWARF standard says in the section
9091 about "Structure, Union, and Class Type Entries": "An incomplete
9092 structure, union or class type is represented by a structure,
9093 union or class entry that does not have a byte size attribute
9094 and that has a DW_AT_declaration attribute." */
9095 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9098 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9099 static vs. global. */
9100 add_psymbol_to_list (actual_name
,
9101 built_actual_name
!= NULL
,
9102 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9103 cu
->language
== language_cplus
9104 ? psymbol_placement::GLOBAL
9105 : psymbol_placement::STATIC
,
9106 0, cu
->language
, objfile
);
9109 case DW_TAG_enumerator
:
9110 add_psymbol_to_list (actual_name
,
9111 built_actual_name
!= NULL
,
9112 VAR_DOMAIN
, LOC_CONST
, -1,
9113 cu
->language
== language_cplus
9114 ? psymbol_placement::GLOBAL
9115 : psymbol_placement::STATIC
,
9116 0, cu
->language
, objfile
);
9123 /* Read a partial die corresponding to a namespace; also, add a symbol
9124 corresponding to that namespace to the symbol table. NAMESPACE is
9125 the name of the enclosing namespace. */
9128 add_partial_namespace (struct partial_die_info
*pdi
,
9129 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9130 int set_addrmap
, struct dwarf2_cu
*cu
)
9132 /* Add a symbol for the namespace. */
9134 add_partial_symbol (pdi
, cu
);
9136 /* Now scan partial symbols in that namespace. */
9138 if (pdi
->has_children
)
9139 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9142 /* Read a partial die corresponding to a Fortran module. */
9145 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9146 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9148 /* Add a symbol for the namespace. */
9150 add_partial_symbol (pdi
, cu
);
9152 /* Now scan partial symbols in that module. */
9154 if (pdi
->has_children
)
9155 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9158 /* Read a partial die corresponding to a subprogram or an inlined
9159 subprogram and create a partial symbol for that subprogram.
9160 When the CU language allows it, this routine also defines a partial
9161 symbol for each nested subprogram that this subprogram contains.
9162 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9163 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9165 PDI may also be a lexical block, in which case we simply search
9166 recursively for subprograms defined inside that lexical block.
9167 Again, this is only performed when the CU language allows this
9168 type of definitions. */
9171 add_partial_subprogram (struct partial_die_info
*pdi
,
9172 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9173 int set_addrmap
, struct dwarf2_cu
*cu
)
9175 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9177 if (pdi
->has_pc_info
)
9179 if (pdi
->lowpc
< *lowpc
)
9180 *lowpc
= pdi
->lowpc
;
9181 if (pdi
->highpc
> *highpc
)
9182 *highpc
= pdi
->highpc
;
9185 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9186 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9188 CORE_ADDR this_highpc
;
9189 CORE_ADDR this_lowpc
;
9191 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
9193 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9194 pdi
->lowpc
+ baseaddr
)
9197 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9198 pdi
->highpc
+ baseaddr
)
9200 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9201 this_lowpc
, this_highpc
- 1,
9202 cu
->per_cu
->v
.psymtab
);
9206 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9208 if (!pdi
->is_declaration
)
9209 /* Ignore subprogram DIEs that do not have a name, they are
9210 illegal. Do not emit a complaint at this point, we will
9211 do so when we convert this psymtab into a symtab. */
9213 add_partial_symbol (pdi
, cu
);
9217 if (! pdi
->has_children
)
9220 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9222 pdi
= pdi
->die_child
;
9226 if (pdi
->tag
== DW_TAG_subprogram
9227 || pdi
->tag
== DW_TAG_inlined_subroutine
9228 || pdi
->tag
== DW_TAG_lexical_block
)
9229 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9230 pdi
= pdi
->die_sibling
;
9235 /* Read a partial die corresponding to an enumeration type. */
9238 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9239 struct dwarf2_cu
*cu
)
9241 struct partial_die_info
*pdi
;
9243 if (enum_pdi
->name
!= NULL
)
9244 add_partial_symbol (enum_pdi
, cu
);
9246 pdi
= enum_pdi
->die_child
;
9249 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9250 complaint (_("malformed enumerator DIE ignored"));
9252 add_partial_symbol (pdi
, cu
);
9253 pdi
= pdi
->die_sibling
;
9257 /* Return the initial uleb128 in the die at INFO_PTR. */
9260 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9262 unsigned int bytes_read
;
9264 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9267 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9268 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9270 Return the corresponding abbrev, or NULL if the number is zero (indicating
9271 an empty DIE). In either case *BYTES_READ will be set to the length of
9272 the initial number. */
9274 static struct abbrev_info
*
9275 peek_die_abbrev (const die_reader_specs
&reader
,
9276 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9278 dwarf2_cu
*cu
= reader
.cu
;
9279 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9280 unsigned int abbrev_number
9281 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9283 if (abbrev_number
== 0)
9286 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9289 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9290 " at offset %s [in module %s]"),
9291 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9292 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9298 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9299 Returns a pointer to the end of a series of DIEs, terminated by an empty
9300 DIE. Any children of the skipped DIEs will also be skipped. */
9302 static const gdb_byte
*
9303 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9307 unsigned int bytes_read
;
9308 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9311 return info_ptr
+ bytes_read
;
9313 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9317 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9318 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9319 abbrev corresponding to that skipped uleb128 should be passed in
9320 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9323 static const gdb_byte
*
9324 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9325 struct abbrev_info
*abbrev
)
9327 unsigned int bytes_read
;
9328 struct attribute attr
;
9329 bfd
*abfd
= reader
->abfd
;
9330 struct dwarf2_cu
*cu
= reader
->cu
;
9331 const gdb_byte
*buffer
= reader
->buffer
;
9332 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9333 unsigned int form
, i
;
9335 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9337 /* The only abbrev we care about is DW_AT_sibling. */
9338 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9340 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9341 if (attr
.form
== DW_FORM_ref_addr
)
9342 complaint (_("ignoring absolute DW_AT_sibling"));
9345 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9346 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9348 if (sibling_ptr
< info_ptr
)
9349 complaint (_("DW_AT_sibling points backwards"));
9350 else if (sibling_ptr
> reader
->buffer_end
)
9351 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9357 /* If it isn't DW_AT_sibling, skip this attribute. */
9358 form
= abbrev
->attrs
[i
].form
;
9362 case DW_FORM_ref_addr
:
9363 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9364 and later it is offset sized. */
9365 if (cu
->header
.version
== 2)
9366 info_ptr
+= cu
->header
.addr_size
;
9368 info_ptr
+= cu
->header
.offset_size
;
9370 case DW_FORM_GNU_ref_alt
:
9371 info_ptr
+= cu
->header
.offset_size
;
9374 info_ptr
+= cu
->header
.addr_size
;
9382 case DW_FORM_flag_present
:
9383 case DW_FORM_implicit_const
:
9400 case DW_FORM_ref_sig8
:
9403 case DW_FORM_data16
:
9406 case DW_FORM_string
:
9407 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9408 info_ptr
+= bytes_read
;
9410 case DW_FORM_sec_offset
:
9412 case DW_FORM_GNU_strp_alt
:
9413 info_ptr
+= cu
->header
.offset_size
;
9415 case DW_FORM_exprloc
:
9417 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9418 info_ptr
+= bytes_read
;
9420 case DW_FORM_block1
:
9421 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9423 case DW_FORM_block2
:
9424 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9426 case DW_FORM_block4
:
9427 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9433 case DW_FORM_ref_udata
:
9434 case DW_FORM_GNU_addr_index
:
9435 case DW_FORM_GNU_str_index
:
9436 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9438 case DW_FORM_indirect
:
9439 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9440 info_ptr
+= bytes_read
;
9441 /* We need to continue parsing from here, so just go back to
9443 goto skip_attribute
;
9446 error (_("Dwarf Error: Cannot handle %s "
9447 "in DWARF reader [in module %s]"),
9448 dwarf_form_name (form
),
9449 bfd_get_filename (abfd
));
9453 if (abbrev
->has_children
)
9454 return skip_children (reader
, info_ptr
);
9459 /* Locate ORIG_PDI's sibling.
9460 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9462 static const gdb_byte
*
9463 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9464 struct partial_die_info
*orig_pdi
,
9465 const gdb_byte
*info_ptr
)
9467 /* Do we know the sibling already? */
9469 if (orig_pdi
->sibling
)
9470 return orig_pdi
->sibling
;
9472 /* Are there any children to deal with? */
9474 if (!orig_pdi
->has_children
)
9477 /* Skip the children the long way. */
9479 return skip_children (reader
, info_ptr
);
9482 /* Expand this partial symbol table into a full symbol table. SELF is
9486 dwarf2_read_symtab (struct partial_symtab
*self
,
9487 struct objfile
*objfile
)
9489 struct dwarf2_per_objfile
*dwarf2_per_objfile
9490 = get_dwarf2_per_objfile (objfile
);
9494 warning (_("bug: psymtab for %s is already read in."),
9501 printf_filtered (_("Reading in symbols for %s..."),
9503 gdb_flush (gdb_stdout
);
9506 /* If this psymtab is constructed from a debug-only objfile, the
9507 has_section_at_zero flag will not necessarily be correct. We
9508 can get the correct value for this flag by looking at the data
9509 associated with the (presumably stripped) associated objfile. */
9510 if (objfile
->separate_debug_objfile_backlink
)
9512 struct dwarf2_per_objfile
*dpo_backlink
9513 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9515 dwarf2_per_objfile
->has_section_at_zero
9516 = dpo_backlink
->has_section_at_zero
;
9519 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9521 psymtab_to_symtab_1 (self
);
9523 /* Finish up the debug error message. */
9525 printf_filtered (_("done.\n"));
9528 process_cu_includes (dwarf2_per_objfile
);
9531 /* Reading in full CUs. */
9533 /* Add PER_CU to the queue. */
9536 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9537 enum language pretend_language
)
9539 struct dwarf2_queue_item
*item
;
9542 item
= XNEW (struct dwarf2_queue_item
);
9543 item
->per_cu
= per_cu
;
9544 item
->pretend_language
= pretend_language
;
9547 if (dwarf2_queue
== NULL
)
9548 dwarf2_queue
= item
;
9550 dwarf2_queue_tail
->next
= item
;
9552 dwarf2_queue_tail
= item
;
9555 /* If PER_CU is not yet queued, add it to the queue.
9556 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9558 The result is non-zero if PER_CU was queued, otherwise the result is zero
9559 meaning either PER_CU is already queued or it is already loaded.
9561 N.B. There is an invariant here that if a CU is queued then it is loaded.
9562 The caller is required to load PER_CU if we return non-zero. */
9565 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9566 struct dwarf2_per_cu_data
*per_cu
,
9567 enum language pretend_language
)
9569 /* We may arrive here during partial symbol reading, if we need full
9570 DIEs to process an unusual case (e.g. template arguments). Do
9571 not queue PER_CU, just tell our caller to load its DIEs. */
9572 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9574 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9579 /* Mark the dependence relation so that we don't flush PER_CU
9581 if (dependent_cu
!= NULL
)
9582 dwarf2_add_dependence (dependent_cu
, per_cu
);
9584 /* If it's already on the queue, we have nothing to do. */
9588 /* If the compilation unit is already loaded, just mark it as
9590 if (per_cu
->cu
!= NULL
)
9592 per_cu
->cu
->last_used
= 0;
9596 /* Add it to the queue. */
9597 queue_comp_unit (per_cu
, pretend_language
);
9602 /* Process the queue. */
9605 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9607 struct dwarf2_queue_item
*item
, *next_item
;
9609 if (dwarf_read_debug
)
9611 fprintf_unfiltered (gdb_stdlog
,
9612 "Expanding one or more symtabs of objfile %s ...\n",
9613 objfile_name (dwarf2_per_objfile
->objfile
));
9616 /* The queue starts out with one item, but following a DIE reference
9617 may load a new CU, adding it to the end of the queue. */
9618 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9620 if ((dwarf2_per_objfile
->using_index
9621 ? !item
->per_cu
->v
.quick
->compunit_symtab
9622 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9623 /* Skip dummy CUs. */
9624 && item
->per_cu
->cu
!= NULL
)
9626 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9627 unsigned int debug_print_threshold
;
9630 if (per_cu
->is_debug_types
)
9632 struct signatured_type
*sig_type
=
9633 (struct signatured_type
*) per_cu
;
9635 sprintf (buf
, "TU %s at offset %s",
9636 hex_string (sig_type
->signature
),
9637 sect_offset_str (per_cu
->sect_off
));
9638 /* There can be 100s of TUs.
9639 Only print them in verbose mode. */
9640 debug_print_threshold
= 2;
9644 sprintf (buf
, "CU at offset %s",
9645 sect_offset_str (per_cu
->sect_off
));
9646 debug_print_threshold
= 1;
9649 if (dwarf_read_debug
>= debug_print_threshold
)
9650 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9652 if (per_cu
->is_debug_types
)
9653 process_full_type_unit (per_cu
, item
->pretend_language
);
9655 process_full_comp_unit (per_cu
, item
->pretend_language
);
9657 if (dwarf_read_debug
>= debug_print_threshold
)
9658 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9661 item
->per_cu
->queued
= 0;
9662 next_item
= item
->next
;
9666 dwarf2_queue_tail
= NULL
;
9668 if (dwarf_read_debug
)
9670 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9671 objfile_name (dwarf2_per_objfile
->objfile
));
9675 /* Read in full symbols for PST, and anything it depends on. */
9678 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9680 struct dwarf2_per_cu_data
*per_cu
;
9686 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9687 if (!pst
->dependencies
[i
]->readin
9688 && pst
->dependencies
[i
]->user
== NULL
)
9690 /* Inform about additional files that need to be read in. */
9693 /* FIXME: i18n: Need to make this a single string. */
9694 fputs_filtered (" ", gdb_stdout
);
9696 fputs_filtered ("and ", gdb_stdout
);
9698 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9699 wrap_here (""); /* Flush output. */
9700 gdb_flush (gdb_stdout
);
9702 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9705 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9709 /* It's an include file, no symbols to read for it.
9710 Everything is in the parent symtab. */
9715 dw2_do_instantiate_symtab (per_cu
, false);
9718 /* Trivial hash function for die_info: the hash value of a DIE
9719 is its offset in .debug_info for this objfile. */
9722 die_hash (const void *item
)
9724 const struct die_info
*die
= (const struct die_info
*) item
;
9726 return to_underlying (die
->sect_off
);
9729 /* Trivial comparison function for die_info structures: two DIEs
9730 are equal if they have the same offset. */
9733 die_eq (const void *item_lhs
, const void *item_rhs
)
9735 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9736 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9738 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9741 /* die_reader_func for load_full_comp_unit.
9742 This is identical to read_signatured_type_reader,
9743 but is kept separate for now. */
9746 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9747 const gdb_byte
*info_ptr
,
9748 struct die_info
*comp_unit_die
,
9752 struct dwarf2_cu
*cu
= reader
->cu
;
9753 enum language
*language_ptr
= (enum language
*) data
;
9755 gdb_assert (cu
->die_hash
== NULL
);
9757 htab_create_alloc_ex (cu
->header
.length
/ 12,
9761 &cu
->comp_unit_obstack
,
9762 hashtab_obstack_allocate
,
9763 dummy_obstack_deallocate
);
9766 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9767 &info_ptr
, comp_unit_die
);
9768 cu
->dies
= comp_unit_die
;
9769 /* comp_unit_die is not stored in die_hash, no need. */
9771 /* We try not to read any attributes in this function, because not
9772 all CUs needed for references have been loaded yet, and symbol
9773 table processing isn't initialized. But we have to set the CU language,
9774 or we won't be able to build types correctly.
9775 Similarly, if we do not read the producer, we can not apply
9776 producer-specific interpretation. */
9777 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9780 /* Load the DIEs associated with PER_CU into memory. */
9783 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9785 enum language pretend_language
)
9787 gdb_assert (! this_cu
->is_debug_types
);
9789 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9790 load_full_comp_unit_reader
, &pretend_language
);
9793 /* Add a DIE to the delayed physname list. */
9796 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9797 const char *name
, struct die_info
*die
,
9798 struct dwarf2_cu
*cu
)
9800 struct delayed_method_info mi
;
9802 mi
.fnfield_index
= fnfield_index
;
9806 cu
->method_list
.push_back (mi
);
9809 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9810 "const" / "volatile". If so, decrements LEN by the length of the
9811 modifier and return true. Otherwise return false. */
9815 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9817 size_t mod_len
= sizeof (mod
) - 1;
9818 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9826 /* Compute the physnames of any methods on the CU's method list.
9828 The computation of method physnames is delayed in order to avoid the
9829 (bad) condition that one of the method's formal parameters is of an as yet
9833 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9835 /* Only C++ delays computing physnames. */
9836 if (cu
->method_list
.empty ())
9838 gdb_assert (cu
->language
== language_cplus
);
9840 for (const delayed_method_info
&mi
: cu
->method_list
)
9842 const char *physname
;
9843 struct fn_fieldlist
*fn_flp
9844 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9845 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9846 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9847 = physname
? physname
: "";
9849 /* Since there's no tag to indicate whether a method is a
9850 const/volatile overload, extract that information out of the
9852 if (physname
!= NULL
)
9854 size_t len
= strlen (physname
);
9858 if (physname
[len
] == ')') /* shortcut */
9860 else if (check_modifier (physname
, len
, " const"))
9861 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9862 else if (check_modifier (physname
, len
, " volatile"))
9863 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9870 /* The list is no longer needed. */
9871 cu
->method_list
.clear ();
9874 /* Go objects should be embedded in a DW_TAG_module DIE,
9875 and it's not clear if/how imported objects will appear.
9876 To keep Go support simple until that's worked out,
9877 go back through what we've read and create something usable.
9878 We could do this while processing each DIE, and feels kinda cleaner,
9879 but that way is more invasive.
9880 This is to, for example, allow the user to type "p var" or "b main"
9881 without having to specify the package name, and allow lookups
9882 of module.object to work in contexts that use the expression
9886 fixup_go_packaging (struct dwarf2_cu
*cu
)
9888 gdb::unique_xmalloc_ptr
<char> package_name
;
9889 struct pending
*list
;
9892 for (list
= *cu
->get_builder ()->get_global_symbols ();
9896 for (i
= 0; i
< list
->nsyms
; ++i
)
9898 struct symbol
*sym
= list
->symbol
[i
];
9900 if (sym
->language () == language_go
9901 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9903 gdb::unique_xmalloc_ptr
<char> this_package_name
9904 (go_symbol_package_name (sym
));
9906 if (this_package_name
== NULL
)
9908 if (package_name
== NULL
)
9909 package_name
= std::move (this_package_name
);
9912 struct objfile
*objfile
9913 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9914 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9915 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9916 (symbol_symtab (sym
) != NULL
9917 ? symtab_to_filename_for_display
9918 (symbol_symtab (sym
))
9919 : objfile_name (objfile
)),
9920 this_package_name
.get (), package_name
.get ());
9926 if (package_name
!= NULL
)
9928 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9929 const char *saved_package_name
9930 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9931 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9932 saved_package_name
);
9935 sym
= allocate_symbol (objfile
);
9936 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9937 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9938 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9939 e.g., "main" finds the "main" module and not C's main(). */
9940 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9941 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9942 SYMBOL_TYPE (sym
) = type
;
9944 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9948 /* Allocate a fully-qualified name consisting of the two parts on the
9952 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9954 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9957 /* A helper that allocates a struct discriminant_info to attach to a
9960 static struct discriminant_info
*
9961 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9964 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9965 gdb_assert (discriminant_index
== -1
9966 || (discriminant_index
>= 0
9967 && discriminant_index
< TYPE_NFIELDS (type
)));
9968 gdb_assert (default_index
== -1
9969 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9971 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9973 struct discriminant_info
*disc
9974 = ((struct discriminant_info
*)
9976 offsetof (struct discriminant_info
, discriminants
)
9977 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9978 disc
->default_index
= default_index
;
9979 disc
->discriminant_index
= discriminant_index
;
9981 struct dynamic_prop prop
;
9982 prop
.kind
= PROP_UNDEFINED
;
9983 prop
.data
.baton
= disc
;
9985 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9990 /* Some versions of rustc emitted enums in an unusual way.
9992 Ordinary enums were emitted as unions. The first element of each
9993 structure in the union was named "RUST$ENUM$DISR". This element
9994 held the discriminant.
9996 These versions of Rust also implemented the "non-zero"
9997 optimization. When the enum had two values, and one is empty and
9998 the other holds a pointer that cannot be zero, the pointer is used
9999 as the discriminant, with a zero value meaning the empty variant.
10000 Here, the union's first member is of the form
10001 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10002 where the fieldnos are the indices of the fields that should be
10003 traversed in order to find the field (which may be several fields deep)
10004 and the variantname is the name of the variant of the case when the
10007 This function recognizes whether TYPE is of one of these forms,
10008 and, if so, smashes it to be a variant type. */
10011 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10013 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10015 /* We don't need to deal with empty enums. */
10016 if (TYPE_NFIELDS (type
) == 0)
10019 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10020 if (TYPE_NFIELDS (type
) == 1
10021 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10023 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10025 /* Decode the field name to find the offset of the
10027 ULONGEST bit_offset
= 0;
10028 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10029 while (name
[0] >= '0' && name
[0] <= '9')
10032 unsigned long index
= strtoul (name
, &tail
, 10);
10035 || index
>= TYPE_NFIELDS (field_type
)
10036 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10037 != FIELD_LOC_KIND_BITPOS
))
10039 complaint (_("Could not parse Rust enum encoding string \"%s\""
10041 TYPE_FIELD_NAME (type
, 0),
10042 objfile_name (objfile
));
10047 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10048 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10051 /* Make a union to hold the variants. */
10052 struct type
*union_type
= alloc_type (objfile
);
10053 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10054 TYPE_NFIELDS (union_type
) = 3;
10055 TYPE_FIELDS (union_type
)
10056 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10057 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10058 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10060 /* Put the discriminant must at index 0. */
10061 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10062 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10063 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10064 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10066 /* The order of fields doesn't really matter, so put the real
10067 field at index 1 and the data-less field at index 2. */
10068 struct discriminant_info
*disc
10069 = alloc_discriminant_info (union_type
, 0, 1);
10070 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10071 TYPE_FIELD_NAME (union_type
, 1)
10072 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10073 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10074 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10075 TYPE_FIELD_NAME (union_type
, 1));
10077 const char *dataless_name
10078 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10080 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10082 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10083 /* NAME points into the original discriminant name, which
10084 already has the correct lifetime. */
10085 TYPE_FIELD_NAME (union_type
, 2) = name
;
10086 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10087 disc
->discriminants
[2] = 0;
10089 /* Smash this type to be a structure type. We have to do this
10090 because the type has already been recorded. */
10091 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10092 TYPE_NFIELDS (type
) = 1;
10094 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10096 /* Install the variant part. */
10097 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10098 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10099 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10101 /* A union with a single anonymous field is probably an old-style
10102 univariant enum. */
10103 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10105 /* Smash this type to be a structure type. We have to do this
10106 because the type has already been recorded. */
10107 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10109 /* Make a union to hold the variants. */
10110 struct type
*union_type
= alloc_type (objfile
);
10111 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10112 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10113 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10114 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10115 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10117 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10118 const char *variant_name
10119 = rust_last_path_segment (TYPE_NAME (field_type
));
10120 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10121 TYPE_NAME (field_type
)
10122 = rust_fully_qualify (&objfile
->objfile_obstack
,
10123 TYPE_NAME (type
), variant_name
);
10125 /* Install the union in the outer struct type. */
10126 TYPE_NFIELDS (type
) = 1;
10128 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10129 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10130 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10131 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10133 alloc_discriminant_info (union_type
, -1, 0);
10137 struct type
*disr_type
= nullptr;
10138 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10140 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10142 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10144 /* All fields of a true enum will be structs. */
10147 else if (TYPE_NFIELDS (disr_type
) == 0)
10149 /* Could be data-less variant, so keep going. */
10150 disr_type
= nullptr;
10152 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10153 "RUST$ENUM$DISR") != 0)
10155 /* Not a Rust enum. */
10165 /* If we got here without a discriminant, then it's probably
10167 if (disr_type
== nullptr)
10170 /* Smash this type to be a structure type. We have to do this
10171 because the type has already been recorded. */
10172 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10174 /* Make a union to hold the variants. */
10175 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10176 struct type
*union_type
= alloc_type (objfile
);
10177 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10178 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10179 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10180 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10181 TYPE_FIELDS (union_type
)
10182 = (struct field
*) TYPE_ZALLOC (union_type
,
10183 (TYPE_NFIELDS (union_type
)
10184 * sizeof (struct field
)));
10186 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10187 TYPE_NFIELDS (type
) * sizeof (struct field
));
10189 /* Install the discriminant at index 0 in the union. */
10190 TYPE_FIELD (union_type
, 0) = *disr_field
;
10191 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10192 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10194 /* Install the union in the outer struct type. */
10195 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10196 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10197 TYPE_NFIELDS (type
) = 1;
10199 /* Set the size and offset of the union type. */
10200 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10202 /* We need a way to find the correct discriminant given a
10203 variant name. For convenience we build a map here. */
10204 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10205 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10206 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10208 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10211 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10212 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10216 int n_fields
= TYPE_NFIELDS (union_type
);
10217 struct discriminant_info
*disc
10218 = alloc_discriminant_info (union_type
, 0, -1);
10219 /* Skip the discriminant here. */
10220 for (int i
= 1; i
< n_fields
; ++i
)
10222 /* Find the final word in the name of this variant's type.
10223 That name can be used to look up the correct
10225 const char *variant_name
10226 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10229 auto iter
= discriminant_map
.find (variant_name
);
10230 if (iter
!= discriminant_map
.end ())
10231 disc
->discriminants
[i
] = iter
->second
;
10233 /* Remove the discriminant field, if it exists. */
10234 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10235 if (TYPE_NFIELDS (sub_type
) > 0)
10237 --TYPE_NFIELDS (sub_type
);
10238 ++TYPE_FIELDS (sub_type
);
10240 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10241 TYPE_NAME (sub_type
)
10242 = rust_fully_qualify (&objfile
->objfile_obstack
,
10243 TYPE_NAME (type
), variant_name
);
10248 /* Rewrite some Rust unions to be structures with variants parts. */
10251 rust_union_quirks (struct dwarf2_cu
*cu
)
10253 gdb_assert (cu
->language
== language_rust
);
10254 for (type
*type_
: cu
->rust_unions
)
10255 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10256 /* We don't need this any more. */
10257 cu
->rust_unions
.clear ();
10260 /* Return the symtab for PER_CU. This works properly regardless of
10261 whether we're using the index or psymtabs. */
10263 static struct compunit_symtab
*
10264 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10266 return (per_cu
->dwarf2_per_objfile
->using_index
10267 ? per_cu
->v
.quick
->compunit_symtab
10268 : per_cu
->v
.psymtab
->compunit_symtab
);
10271 /* A helper function for computing the list of all symbol tables
10272 included by PER_CU. */
10275 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10276 htab_t all_children
, htab_t all_type_symtabs
,
10277 struct dwarf2_per_cu_data
*per_cu
,
10278 struct compunit_symtab
*immediate_parent
)
10281 struct compunit_symtab
*cust
;
10283 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10286 /* This inclusion and its children have been processed. */
10291 /* Only add a CU if it has a symbol table. */
10292 cust
= get_compunit_symtab (per_cu
);
10295 /* If this is a type unit only add its symbol table if we haven't
10296 seen it yet (type unit per_cu's can share symtabs). */
10297 if (per_cu
->is_debug_types
)
10299 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10303 result
->push_back (cust
);
10304 if (cust
->user
== NULL
)
10305 cust
->user
= immediate_parent
;
10310 result
->push_back (cust
);
10311 if (cust
->user
== NULL
)
10312 cust
->user
= immediate_parent
;
10316 if (!per_cu
->imported_symtabs_empty ())
10317 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10319 recursively_compute_inclusions (result
, all_children
,
10320 all_type_symtabs
, ptr
, cust
);
10324 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10328 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10330 gdb_assert (! per_cu
->is_debug_types
);
10332 if (!per_cu
->imported_symtabs_empty ())
10335 std::vector
<compunit_symtab
*> result_symtabs
;
10336 htab_t all_children
, all_type_symtabs
;
10337 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10339 /* If we don't have a symtab, we can just skip this case. */
10343 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10344 NULL
, xcalloc
, xfree
);
10345 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10346 NULL
, xcalloc
, xfree
);
10348 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10350 recursively_compute_inclusions (&result_symtabs
, all_children
,
10351 all_type_symtabs
, ptr
, cust
);
10354 /* Now we have a transitive closure of all the included symtabs. */
10355 len
= result_symtabs
.size ();
10357 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10358 struct compunit_symtab
*, len
+ 1);
10359 memcpy (cust
->includes
, result_symtabs
.data (),
10360 len
* sizeof (compunit_symtab
*));
10361 cust
->includes
[len
] = NULL
;
10363 htab_delete (all_children
);
10364 htab_delete (all_type_symtabs
);
10368 /* Compute the 'includes' field for the symtabs of all the CUs we just
10372 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10374 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10376 if (! iter
->is_debug_types
)
10377 compute_compunit_symtab_includes (iter
);
10380 dwarf2_per_objfile
->just_read_cus
.clear ();
10383 /* Generate full symbol information for PER_CU, whose DIEs have
10384 already been loaded into memory. */
10387 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10388 enum language pretend_language
)
10390 struct dwarf2_cu
*cu
= per_cu
->cu
;
10391 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10392 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10393 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10394 CORE_ADDR lowpc
, highpc
;
10395 struct compunit_symtab
*cust
;
10396 CORE_ADDR baseaddr
;
10397 struct block
*static_block
;
10400 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
10402 /* Clear the list here in case something was left over. */
10403 cu
->method_list
.clear ();
10405 cu
->language
= pretend_language
;
10406 cu
->language_defn
= language_def (cu
->language
);
10408 /* Do line number decoding in read_file_scope () */
10409 process_die (cu
->dies
, cu
);
10411 /* For now fudge the Go package. */
10412 if (cu
->language
== language_go
)
10413 fixup_go_packaging (cu
);
10415 /* Now that we have processed all the DIEs in the CU, all the types
10416 should be complete, and it should now be safe to compute all of the
10418 compute_delayed_physnames (cu
);
10420 if (cu
->language
== language_rust
)
10421 rust_union_quirks (cu
);
10423 /* Some compilers don't define a DW_AT_high_pc attribute for the
10424 compilation unit. If the DW_AT_high_pc is missing, synthesize
10425 it, by scanning the DIE's below the compilation unit. */
10426 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10428 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10429 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10431 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10432 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10433 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10434 addrmap to help ensure it has an accurate map of pc values belonging to
10436 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10438 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10439 SECT_OFF_TEXT (objfile
),
10444 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10446 /* Set symtab language to language from DW_AT_language. If the
10447 compilation is from a C file generated by language preprocessors, do
10448 not set the language if it was already deduced by start_subfile. */
10449 if (!(cu
->language
== language_c
10450 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10451 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10453 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10454 produce DW_AT_location with location lists but it can be possibly
10455 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10456 there were bugs in prologue debug info, fixed later in GCC-4.5
10457 by "unwind info for epilogues" patch (which is not directly related).
10459 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10460 needed, it would be wrong due to missing DW_AT_producer there.
10462 Still one can confuse GDB by using non-standard GCC compilation
10463 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10465 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10466 cust
->locations_valid
= 1;
10468 if (gcc_4_minor
>= 5)
10469 cust
->epilogue_unwind_valid
= 1;
10471 cust
->call_site_htab
= cu
->call_site_htab
;
10474 if (dwarf2_per_objfile
->using_index
)
10475 per_cu
->v
.quick
->compunit_symtab
= cust
;
10478 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10479 pst
->compunit_symtab
= cust
;
10483 /* Push it for inclusion processing later. */
10484 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10486 /* Not needed any more. */
10487 cu
->reset_builder ();
10490 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10491 already been loaded into memory. */
10494 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10495 enum language pretend_language
)
10497 struct dwarf2_cu
*cu
= per_cu
->cu
;
10498 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10499 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10500 struct compunit_symtab
*cust
;
10501 struct signatured_type
*sig_type
;
10503 gdb_assert (per_cu
->is_debug_types
);
10504 sig_type
= (struct signatured_type
*) per_cu
;
10506 /* Clear the list here in case something was left over. */
10507 cu
->method_list
.clear ();
10509 cu
->language
= pretend_language
;
10510 cu
->language_defn
= language_def (cu
->language
);
10512 /* The symbol tables are set up in read_type_unit_scope. */
10513 process_die (cu
->dies
, cu
);
10515 /* For now fudge the Go package. */
10516 if (cu
->language
== language_go
)
10517 fixup_go_packaging (cu
);
10519 /* Now that we have processed all the DIEs in the CU, all the types
10520 should be complete, and it should now be safe to compute all of the
10522 compute_delayed_physnames (cu
);
10524 if (cu
->language
== language_rust
)
10525 rust_union_quirks (cu
);
10527 /* TUs share symbol tables.
10528 If this is the first TU to use this symtab, complete the construction
10529 of it with end_expandable_symtab. Otherwise, complete the addition of
10530 this TU's symbols to the existing symtab. */
10531 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10533 buildsym_compunit
*builder
= cu
->get_builder ();
10534 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10535 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10539 /* Set symtab language to language from DW_AT_language. If the
10540 compilation is from a C file generated by language preprocessors,
10541 do not set the language if it was already deduced by
10543 if (!(cu
->language
== language_c
10544 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10545 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10550 cu
->get_builder ()->augment_type_symtab ();
10551 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10554 if (dwarf2_per_objfile
->using_index
)
10555 per_cu
->v
.quick
->compunit_symtab
= cust
;
10558 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10559 pst
->compunit_symtab
= cust
;
10563 /* Not needed any more. */
10564 cu
->reset_builder ();
10567 /* Process an imported unit DIE. */
10570 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10572 struct attribute
*attr
;
10574 /* For now we don't handle imported units in type units. */
10575 if (cu
->per_cu
->is_debug_types
)
10577 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10578 " supported in type units [in module %s]"),
10579 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10582 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10585 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10586 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10587 dwarf2_per_cu_data
*per_cu
10588 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10589 cu
->per_cu
->dwarf2_per_objfile
);
10591 /* If necessary, add it to the queue and load its DIEs. */
10592 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10593 load_full_comp_unit (per_cu
, false, cu
->language
);
10595 cu
->per_cu
->imported_symtabs_push (per_cu
);
10599 /* RAII object that represents a process_die scope: i.e.,
10600 starts/finishes processing a DIE. */
10601 class process_die_scope
10604 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10605 : m_die (die
), m_cu (cu
)
10607 /* We should only be processing DIEs not already in process. */
10608 gdb_assert (!m_die
->in_process
);
10609 m_die
->in_process
= true;
10612 ~process_die_scope ()
10614 m_die
->in_process
= false;
10616 /* If we're done processing the DIE for the CU that owns the line
10617 header, we don't need the line header anymore. */
10618 if (m_cu
->line_header_die_owner
== m_die
)
10620 delete m_cu
->line_header
;
10621 m_cu
->line_header
= NULL
;
10622 m_cu
->line_header_die_owner
= NULL
;
10631 /* Process a die and its children. */
10634 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10636 process_die_scope
scope (die
, cu
);
10640 case DW_TAG_padding
:
10642 case DW_TAG_compile_unit
:
10643 case DW_TAG_partial_unit
:
10644 read_file_scope (die
, cu
);
10646 case DW_TAG_type_unit
:
10647 read_type_unit_scope (die
, cu
);
10649 case DW_TAG_subprogram
:
10650 /* Nested subprograms in Fortran get a prefix. */
10651 if (cu
->language
== language_fortran
10652 && die
->parent
!= NULL
10653 && die
->parent
->tag
== DW_TAG_subprogram
)
10654 cu
->processing_has_namespace_info
= true;
10655 /* Fall through. */
10656 case DW_TAG_inlined_subroutine
:
10657 read_func_scope (die
, cu
);
10659 case DW_TAG_lexical_block
:
10660 case DW_TAG_try_block
:
10661 case DW_TAG_catch_block
:
10662 read_lexical_block_scope (die
, cu
);
10664 case DW_TAG_call_site
:
10665 case DW_TAG_GNU_call_site
:
10666 read_call_site_scope (die
, cu
);
10668 case DW_TAG_class_type
:
10669 case DW_TAG_interface_type
:
10670 case DW_TAG_structure_type
:
10671 case DW_TAG_union_type
:
10672 process_structure_scope (die
, cu
);
10674 case DW_TAG_enumeration_type
:
10675 process_enumeration_scope (die
, cu
);
10678 /* These dies have a type, but processing them does not create
10679 a symbol or recurse to process the children. Therefore we can
10680 read them on-demand through read_type_die. */
10681 case DW_TAG_subroutine_type
:
10682 case DW_TAG_set_type
:
10683 case DW_TAG_array_type
:
10684 case DW_TAG_pointer_type
:
10685 case DW_TAG_ptr_to_member_type
:
10686 case DW_TAG_reference_type
:
10687 case DW_TAG_rvalue_reference_type
:
10688 case DW_TAG_string_type
:
10691 case DW_TAG_base_type
:
10692 case DW_TAG_subrange_type
:
10693 case DW_TAG_typedef
:
10694 /* Add a typedef symbol for the type definition, if it has a
10696 new_symbol (die
, read_type_die (die
, cu
), cu
);
10698 case DW_TAG_common_block
:
10699 read_common_block (die
, cu
);
10701 case DW_TAG_common_inclusion
:
10703 case DW_TAG_namespace
:
10704 cu
->processing_has_namespace_info
= true;
10705 read_namespace (die
, cu
);
10707 case DW_TAG_module
:
10708 cu
->processing_has_namespace_info
= true;
10709 read_module (die
, cu
);
10711 case DW_TAG_imported_declaration
:
10712 cu
->processing_has_namespace_info
= true;
10713 if (read_namespace_alias (die
, cu
))
10715 /* The declaration is not a global namespace alias. */
10716 /* Fall through. */
10717 case DW_TAG_imported_module
:
10718 cu
->processing_has_namespace_info
= true;
10719 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10720 || cu
->language
!= language_fortran
))
10721 complaint (_("Tag '%s' has unexpected children"),
10722 dwarf_tag_name (die
->tag
));
10723 read_import_statement (die
, cu
);
10726 case DW_TAG_imported_unit
:
10727 process_imported_unit_die (die
, cu
);
10730 case DW_TAG_variable
:
10731 read_variable (die
, cu
);
10735 new_symbol (die
, NULL
, cu
);
10740 /* DWARF name computation. */
10742 /* A helper function for dwarf2_compute_name which determines whether DIE
10743 needs to have the name of the scope prepended to the name listed in the
10747 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10749 struct attribute
*attr
;
10753 case DW_TAG_namespace
:
10754 case DW_TAG_typedef
:
10755 case DW_TAG_class_type
:
10756 case DW_TAG_interface_type
:
10757 case DW_TAG_structure_type
:
10758 case DW_TAG_union_type
:
10759 case DW_TAG_enumeration_type
:
10760 case DW_TAG_enumerator
:
10761 case DW_TAG_subprogram
:
10762 case DW_TAG_inlined_subroutine
:
10763 case DW_TAG_member
:
10764 case DW_TAG_imported_declaration
:
10767 case DW_TAG_variable
:
10768 case DW_TAG_constant
:
10769 /* We only need to prefix "globally" visible variables. These include
10770 any variable marked with DW_AT_external or any variable that
10771 lives in a namespace. [Variables in anonymous namespaces
10772 require prefixing, but they are not DW_AT_external.] */
10774 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10776 struct dwarf2_cu
*spec_cu
= cu
;
10778 return die_needs_namespace (die_specification (die
, &spec_cu
),
10782 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10783 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10784 && die
->parent
->tag
!= DW_TAG_module
)
10786 /* A variable in a lexical block of some kind does not need a
10787 namespace, even though in C++ such variables may be external
10788 and have a mangled name. */
10789 if (die
->parent
->tag
== DW_TAG_lexical_block
10790 || die
->parent
->tag
== DW_TAG_try_block
10791 || die
->parent
->tag
== DW_TAG_catch_block
10792 || die
->parent
->tag
== DW_TAG_subprogram
)
10801 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10802 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10803 defined for the given DIE. */
10805 static struct attribute
*
10806 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10808 struct attribute
*attr
;
10810 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10812 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10817 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10818 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10819 defined for the given DIE. */
10821 static const char *
10822 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10824 const char *linkage_name
;
10826 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10827 if (linkage_name
== NULL
)
10828 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10830 return linkage_name
;
10833 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10834 compute the physname for the object, which include a method's:
10835 - formal parameters (C++),
10836 - receiver type (Go),
10838 The term "physname" is a bit confusing.
10839 For C++, for example, it is the demangled name.
10840 For Go, for example, it's the mangled name.
10842 For Ada, return the DIE's linkage name rather than the fully qualified
10843 name. PHYSNAME is ignored..
10845 The result is allocated on the objfile_obstack and canonicalized. */
10847 static const char *
10848 dwarf2_compute_name (const char *name
,
10849 struct die_info
*die
, struct dwarf2_cu
*cu
,
10852 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10855 name
= dwarf2_name (die
, cu
);
10857 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10858 but otherwise compute it by typename_concat inside GDB.
10859 FIXME: Actually this is not really true, or at least not always true.
10860 It's all very confusing. compute_and_set_names doesn't try to demangle
10861 Fortran names because there is no mangling standard. So new_symbol
10862 will set the demangled name to the result of dwarf2_full_name, and it is
10863 the demangled name that GDB uses if it exists. */
10864 if (cu
->language
== language_ada
10865 || (cu
->language
== language_fortran
&& physname
))
10867 /* For Ada unit, we prefer the linkage name over the name, as
10868 the former contains the exported name, which the user expects
10869 to be able to reference. Ideally, we want the user to be able
10870 to reference this entity using either natural or linkage name,
10871 but we haven't started looking at this enhancement yet. */
10872 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10874 if (linkage_name
!= NULL
)
10875 return linkage_name
;
10878 /* These are the only languages we know how to qualify names in. */
10880 && (cu
->language
== language_cplus
10881 || cu
->language
== language_fortran
|| cu
->language
== language_d
10882 || cu
->language
== language_rust
))
10884 if (die_needs_namespace (die
, cu
))
10886 const char *prefix
;
10887 const char *canonical_name
= NULL
;
10891 prefix
= determine_prefix (die
, cu
);
10892 if (*prefix
!= '\0')
10894 gdb::unique_xmalloc_ptr
<char> prefixed_name
10895 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10897 buf
.puts (prefixed_name
.get ());
10902 /* Template parameters may be specified in the DIE's DW_AT_name, or
10903 as children with DW_TAG_template_type_param or
10904 DW_TAG_value_type_param. If the latter, add them to the name
10905 here. If the name already has template parameters, then
10906 skip this step; some versions of GCC emit both, and
10907 it is more efficient to use the pre-computed name.
10909 Something to keep in mind about this process: it is very
10910 unlikely, or in some cases downright impossible, to produce
10911 something that will match the mangled name of a function.
10912 If the definition of the function has the same debug info,
10913 we should be able to match up with it anyway. But fallbacks
10914 using the minimal symbol, for instance to find a method
10915 implemented in a stripped copy of libstdc++, will not work.
10916 If we do not have debug info for the definition, we will have to
10917 match them up some other way.
10919 When we do name matching there is a related problem with function
10920 templates; two instantiated function templates are allowed to
10921 differ only by their return types, which we do not add here. */
10923 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10925 struct attribute
*attr
;
10926 struct die_info
*child
;
10929 die
->building_fullname
= 1;
10931 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10935 const gdb_byte
*bytes
;
10936 struct dwarf2_locexpr_baton
*baton
;
10939 if (child
->tag
!= DW_TAG_template_type_param
10940 && child
->tag
!= DW_TAG_template_value_param
)
10951 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10954 complaint (_("template parameter missing DW_AT_type"));
10955 buf
.puts ("UNKNOWN_TYPE");
10958 type
= die_type (child
, cu
);
10960 if (child
->tag
== DW_TAG_template_type_param
)
10962 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10963 &type_print_raw_options
);
10967 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10970 complaint (_("template parameter missing "
10971 "DW_AT_const_value"));
10972 buf
.puts ("UNKNOWN_VALUE");
10976 dwarf2_const_value_attr (attr
, type
, name
,
10977 &cu
->comp_unit_obstack
, cu
,
10978 &value
, &bytes
, &baton
);
10980 if (TYPE_NOSIGN (type
))
10981 /* GDB prints characters as NUMBER 'CHAR'. If that's
10982 changed, this can use value_print instead. */
10983 c_printchar (value
, type
, &buf
);
10986 struct value_print_options opts
;
10989 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10993 else if (bytes
!= NULL
)
10995 v
= allocate_value (type
);
10996 memcpy (value_contents_writeable (v
), bytes
,
10997 TYPE_LENGTH (type
));
11000 v
= value_from_longest (type
, value
);
11002 /* Specify decimal so that we do not depend on
11004 get_formatted_print_options (&opts
, 'd');
11006 value_print (v
, &buf
, &opts
);
11011 die
->building_fullname
= 0;
11015 /* Close the argument list, with a space if necessary
11016 (nested templates). */
11017 if (!buf
.empty () && buf
.string ().back () == '>')
11024 /* For C++ methods, append formal parameter type
11025 information, if PHYSNAME. */
11027 if (physname
&& die
->tag
== DW_TAG_subprogram
11028 && cu
->language
== language_cplus
)
11030 struct type
*type
= read_type_die (die
, cu
);
11032 c_type_print_args (type
, &buf
, 1, cu
->language
,
11033 &type_print_raw_options
);
11035 if (cu
->language
== language_cplus
)
11037 /* Assume that an artificial first parameter is
11038 "this", but do not crash if it is not. RealView
11039 marks unnamed (and thus unused) parameters as
11040 artificial; there is no way to differentiate
11042 if (TYPE_NFIELDS (type
) > 0
11043 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11044 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11045 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11047 buf
.puts (" const");
11051 const std::string
&intermediate_name
= buf
.string ();
11053 if (cu
->language
== language_cplus
)
11055 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11056 &objfile
->per_bfd
->storage_obstack
);
11058 /* If we only computed INTERMEDIATE_NAME, or if
11059 INTERMEDIATE_NAME is already canonical, then we need to
11060 copy it to the appropriate obstack. */
11061 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11062 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11063 intermediate_name
);
11065 name
= canonical_name
;
11072 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11073 If scope qualifiers are appropriate they will be added. The result
11074 will be allocated on the storage_obstack, or NULL if the DIE does
11075 not have a name. NAME may either be from a previous call to
11076 dwarf2_name or NULL.
11078 The output string will be canonicalized (if C++). */
11080 static const char *
11081 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11083 return dwarf2_compute_name (name
, die
, cu
, 0);
11086 /* Construct a physname for the given DIE in CU. NAME may either be
11087 from a previous call to dwarf2_name or NULL. The result will be
11088 allocated on the objfile_objstack or NULL if the DIE does not have a
11091 The output string will be canonicalized (if C++). */
11093 static const char *
11094 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11096 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11097 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11100 /* In this case dwarf2_compute_name is just a shortcut not building anything
11102 if (!die_needs_namespace (die
, cu
))
11103 return dwarf2_compute_name (name
, die
, cu
, 1);
11105 mangled
= dw2_linkage_name (die
, cu
);
11107 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11108 See https://github.com/rust-lang/rust/issues/32925. */
11109 if (cu
->language
== language_rust
&& mangled
!= NULL
11110 && strchr (mangled
, '{') != NULL
)
11113 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11115 gdb::unique_xmalloc_ptr
<char> demangled
;
11116 if (mangled
!= NULL
)
11119 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11121 /* Do nothing (do not demangle the symbol name). */
11123 else if (cu
->language
== language_go
)
11125 /* This is a lie, but we already lie to the caller new_symbol.
11126 new_symbol assumes we return the mangled name.
11127 This just undoes that lie until things are cleaned up. */
11131 /* Use DMGL_RET_DROP for C++ template functions to suppress
11132 their return type. It is easier for GDB users to search
11133 for such functions as `name(params)' than `long name(params)'.
11134 In such case the minimal symbol names do not match the full
11135 symbol names but for template functions there is never a need
11136 to look up their definition from their declaration so
11137 the only disadvantage remains the minimal symbol variant
11138 `long name(params)' does not have the proper inferior type. */
11139 demangled
.reset (gdb_demangle (mangled
,
11140 (DMGL_PARAMS
| DMGL_ANSI
11141 | DMGL_RET_DROP
)));
11144 canon
= demangled
.get ();
11152 if (canon
== NULL
|| check_physname
)
11154 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11156 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11158 /* It may not mean a bug in GDB. The compiler could also
11159 compute DW_AT_linkage_name incorrectly. But in such case
11160 GDB would need to be bug-to-bug compatible. */
11162 complaint (_("Computed physname <%s> does not match demangled <%s> "
11163 "(from linkage <%s>) - DIE at %s [in module %s]"),
11164 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11165 objfile_name (objfile
));
11167 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11168 is available here - over computed PHYSNAME. It is safer
11169 against both buggy GDB and buggy compilers. */
11183 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11188 /* Inspect DIE in CU for a namespace alias. If one exists, record
11189 a new symbol for it.
11191 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11194 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11196 struct attribute
*attr
;
11198 /* If the die does not have a name, this is not a namespace
11200 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11204 struct die_info
*d
= die
;
11205 struct dwarf2_cu
*imported_cu
= cu
;
11207 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11208 keep inspecting DIEs until we hit the underlying import. */
11209 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11210 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11212 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11216 d
= follow_die_ref (d
, attr
, &imported_cu
);
11217 if (d
->tag
!= DW_TAG_imported_declaration
)
11221 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11223 complaint (_("DIE at %s has too many recursively imported "
11224 "declarations"), sect_offset_str (d
->sect_off
));
11231 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11233 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11234 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11236 /* This declaration is a global namespace alias. Add
11237 a symbol for it whose type is the aliased namespace. */
11238 new_symbol (die
, type
, cu
);
11247 /* Return the using directives repository (global or local?) to use in the
11248 current context for CU.
11250 For Ada, imported declarations can materialize renamings, which *may* be
11251 global. However it is impossible (for now?) in DWARF to distinguish
11252 "external" imported declarations and "static" ones. As all imported
11253 declarations seem to be static in all other languages, make them all CU-wide
11254 global only in Ada. */
11256 static struct using_direct
**
11257 using_directives (struct dwarf2_cu
*cu
)
11259 if (cu
->language
== language_ada
11260 && cu
->get_builder ()->outermost_context_p ())
11261 return cu
->get_builder ()->get_global_using_directives ();
11263 return cu
->get_builder ()->get_local_using_directives ();
11266 /* Read the import statement specified by the given die and record it. */
11269 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11271 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11272 struct attribute
*import_attr
;
11273 struct die_info
*imported_die
, *child_die
;
11274 struct dwarf2_cu
*imported_cu
;
11275 const char *imported_name
;
11276 const char *imported_name_prefix
;
11277 const char *canonical_name
;
11278 const char *import_alias
;
11279 const char *imported_declaration
= NULL
;
11280 const char *import_prefix
;
11281 std::vector
<const char *> excludes
;
11283 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11284 if (import_attr
== NULL
)
11286 complaint (_("Tag '%s' has no DW_AT_import"),
11287 dwarf_tag_name (die
->tag
));
11292 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11293 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11294 if (imported_name
== NULL
)
11296 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11298 The import in the following code:
11312 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11313 <52> DW_AT_decl_file : 1
11314 <53> DW_AT_decl_line : 6
11315 <54> DW_AT_import : <0x75>
11316 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11317 <59> DW_AT_name : B
11318 <5b> DW_AT_decl_file : 1
11319 <5c> DW_AT_decl_line : 2
11320 <5d> DW_AT_type : <0x6e>
11322 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11323 <76> DW_AT_byte_size : 4
11324 <77> DW_AT_encoding : 5 (signed)
11326 imports the wrong die ( 0x75 instead of 0x58 ).
11327 This case will be ignored until the gcc bug is fixed. */
11331 /* Figure out the local name after import. */
11332 import_alias
= dwarf2_name (die
, cu
);
11334 /* Figure out where the statement is being imported to. */
11335 import_prefix
= determine_prefix (die
, cu
);
11337 /* Figure out what the scope of the imported die is and prepend it
11338 to the name of the imported die. */
11339 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11341 if (imported_die
->tag
!= DW_TAG_namespace
11342 && imported_die
->tag
!= DW_TAG_module
)
11344 imported_declaration
= imported_name
;
11345 canonical_name
= imported_name_prefix
;
11347 else if (strlen (imported_name_prefix
) > 0)
11348 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11349 imported_name_prefix
,
11350 (cu
->language
== language_d
? "." : "::"),
11351 imported_name
, (char *) NULL
);
11353 canonical_name
= imported_name
;
11355 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11356 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11357 child_die
= sibling_die (child_die
))
11359 /* DWARF-4: A Fortran use statement with a “rename list” may be
11360 represented by an imported module entry with an import attribute
11361 referring to the module and owned entries corresponding to those
11362 entities that are renamed as part of being imported. */
11364 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11366 complaint (_("child DW_TAG_imported_declaration expected "
11367 "- DIE at %s [in module %s]"),
11368 sect_offset_str (child_die
->sect_off
),
11369 objfile_name (objfile
));
11373 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11374 if (import_attr
== NULL
)
11376 complaint (_("Tag '%s' has no DW_AT_import"),
11377 dwarf_tag_name (child_die
->tag
));
11382 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11384 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11385 if (imported_name
== NULL
)
11387 complaint (_("child DW_TAG_imported_declaration has unknown "
11388 "imported name - DIE at %s [in module %s]"),
11389 sect_offset_str (child_die
->sect_off
),
11390 objfile_name (objfile
));
11394 excludes
.push_back (imported_name
);
11396 process_die (child_die
, cu
);
11399 add_using_directive (using_directives (cu
),
11403 imported_declaration
,
11406 &objfile
->objfile_obstack
);
11409 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11410 types, but gives them a size of zero. Starting with version 14,
11411 ICC is compatible with GCC. */
11414 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11416 if (!cu
->checked_producer
)
11417 check_producer (cu
);
11419 return cu
->producer_is_icc_lt_14
;
11422 /* ICC generates a DW_AT_type for C void functions. This was observed on
11423 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11424 which says that void functions should not have a DW_AT_type. */
11427 producer_is_icc (struct dwarf2_cu
*cu
)
11429 if (!cu
->checked_producer
)
11430 check_producer (cu
);
11432 return cu
->producer_is_icc
;
11435 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11436 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11437 this, it was first present in GCC release 4.3.0. */
11440 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11442 if (!cu
->checked_producer
)
11443 check_producer (cu
);
11445 return cu
->producer_is_gcc_lt_4_3
;
11448 static file_and_directory
11449 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11451 file_and_directory res
;
11453 /* Find the filename. Do not use dwarf2_name here, since the filename
11454 is not a source language identifier. */
11455 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11456 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11458 if (res
.comp_dir
== NULL
11459 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11460 && IS_ABSOLUTE_PATH (res
.name
))
11462 res
.comp_dir_storage
= ldirname (res
.name
);
11463 if (!res
.comp_dir_storage
.empty ())
11464 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11466 if (res
.comp_dir
!= NULL
)
11468 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11469 directory, get rid of it. */
11470 const char *cp
= strchr (res
.comp_dir
, ':');
11472 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11473 res
.comp_dir
= cp
+ 1;
11476 if (res
.name
== NULL
)
11477 res
.name
= "<unknown>";
11482 /* Handle DW_AT_stmt_list for a compilation unit.
11483 DIE is the DW_TAG_compile_unit die for CU.
11484 COMP_DIR is the compilation directory. LOWPC is passed to
11485 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11488 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11489 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11491 struct dwarf2_per_objfile
*dwarf2_per_objfile
11492 = cu
->per_cu
->dwarf2_per_objfile
;
11493 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11494 struct attribute
*attr
;
11495 struct line_header line_header_local
;
11496 hashval_t line_header_local_hash
;
11498 int decode_mapping
;
11500 gdb_assert (! cu
->per_cu
->is_debug_types
);
11502 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11506 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11508 /* The line header hash table is only created if needed (it exists to
11509 prevent redundant reading of the line table for partial_units).
11510 If we're given a partial_unit, we'll need it. If we're given a
11511 compile_unit, then use the line header hash table if it's already
11512 created, but don't create one just yet. */
11514 if (dwarf2_per_objfile
->line_header_hash
== NULL
11515 && die
->tag
== DW_TAG_partial_unit
)
11517 dwarf2_per_objfile
->line_header_hash
11518 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11519 line_header_eq_voidp
,
11520 free_line_header_voidp
,
11521 &objfile
->objfile_obstack
,
11522 hashtab_obstack_allocate
,
11523 dummy_obstack_deallocate
);
11526 line_header_local
.sect_off
= line_offset
;
11527 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11528 line_header_local_hash
= line_header_hash (&line_header_local
);
11529 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11531 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11532 &line_header_local
,
11533 line_header_local_hash
, NO_INSERT
);
11535 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11536 is not present in *SLOT (since if there is something in *SLOT then
11537 it will be for a partial_unit). */
11538 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11540 gdb_assert (*slot
!= NULL
);
11541 cu
->line_header
= (struct line_header
*) *slot
;
11546 /* dwarf_decode_line_header does not yet provide sufficient information.
11547 We always have to call also dwarf_decode_lines for it. */
11548 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11552 cu
->line_header
= lh
.release ();
11553 cu
->line_header_die_owner
= die
;
11555 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11559 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11560 &line_header_local
,
11561 line_header_local_hash
, INSERT
);
11562 gdb_assert (slot
!= NULL
);
11564 if (slot
!= NULL
&& *slot
== NULL
)
11566 /* This newly decoded line number information unit will be owned
11567 by line_header_hash hash table. */
11568 *slot
= cu
->line_header
;
11569 cu
->line_header_die_owner
= NULL
;
11573 /* We cannot free any current entry in (*slot) as that struct line_header
11574 may be already used by multiple CUs. Create only temporary decoded
11575 line_header for this CU - it may happen at most once for each line
11576 number information unit. And if we're not using line_header_hash
11577 then this is what we want as well. */
11578 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11580 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11581 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11586 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11589 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11591 struct dwarf2_per_objfile
*dwarf2_per_objfile
11592 = cu
->per_cu
->dwarf2_per_objfile
;
11593 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11594 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11595 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11596 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11597 struct attribute
*attr
;
11598 struct die_info
*child_die
;
11599 CORE_ADDR baseaddr
;
11601 prepare_one_comp_unit (cu
, die
, cu
->language
);
11602 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
11604 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11606 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11607 from finish_block. */
11608 if (lowpc
== ((CORE_ADDR
) -1))
11610 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11612 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11614 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11615 standardised yet. As a workaround for the language detection we fall
11616 back to the DW_AT_producer string. */
11617 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11618 cu
->language
= language_opencl
;
11620 /* Similar hack for Go. */
11621 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11622 set_cu_language (DW_LANG_Go
, cu
);
11624 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11626 /* Decode line number information if present. We do this before
11627 processing child DIEs, so that the line header table is available
11628 for DW_AT_decl_file. */
11629 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11631 /* Process all dies in compilation unit. */
11632 if (die
->child
!= NULL
)
11634 child_die
= die
->child
;
11635 while (child_die
&& child_die
->tag
)
11637 process_die (child_die
, cu
);
11638 child_die
= sibling_die (child_die
);
11642 /* Decode macro information, if present. Dwarf 2 macro information
11643 refers to information in the line number info statement program
11644 header, so we can only read it if we've read the header
11646 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11648 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11649 if (attr
&& cu
->line_header
)
11651 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11652 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11654 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11658 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11659 if (attr
&& cu
->line_header
)
11661 unsigned int macro_offset
= DW_UNSND (attr
);
11663 dwarf_decode_macros (cu
, macro_offset
, 0);
11669 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11671 struct type_unit_group
*tu_group
;
11673 struct attribute
*attr
;
11675 struct signatured_type
*sig_type
;
11677 gdb_assert (per_cu
->is_debug_types
);
11678 sig_type
= (struct signatured_type
*) per_cu
;
11680 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11682 /* If we're using .gdb_index (includes -readnow) then
11683 per_cu->type_unit_group may not have been set up yet. */
11684 if (sig_type
->type_unit_group
== NULL
)
11685 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11686 tu_group
= sig_type
->type_unit_group
;
11688 /* If we've already processed this stmt_list there's no real need to
11689 do it again, we could fake it and just recreate the part we need
11690 (file name,index -> symtab mapping). If data shows this optimization
11691 is useful we can do it then. */
11692 first_time
= tu_group
->compunit_symtab
== NULL
;
11694 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11699 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11700 lh
= dwarf_decode_line_header (line_offset
, this);
11705 start_symtab ("", NULL
, 0);
11708 gdb_assert (tu_group
->symtabs
== NULL
);
11709 gdb_assert (m_builder
== nullptr);
11710 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11711 m_builder
.reset (new struct buildsym_compunit
11712 (COMPUNIT_OBJFILE (cust
), "",
11713 COMPUNIT_DIRNAME (cust
),
11714 compunit_language (cust
),
11720 line_header
= lh
.release ();
11721 line_header_die_owner
= die
;
11725 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11727 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11728 still initializing it, and our caller (a few levels up)
11729 process_full_type_unit still needs to know if this is the first
11732 tu_group
->num_symtabs
= line_header
->file_names_size ();
11733 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11734 line_header
->file_names_size ());
11736 auto &file_names
= line_header
->file_names ();
11737 for (i
= 0; i
< file_names
.size (); ++i
)
11739 file_entry
&fe
= file_names
[i
];
11740 dwarf2_start_subfile (this, fe
.name
,
11741 fe
.include_dir (line_header
));
11742 buildsym_compunit
*b
= get_builder ();
11743 if (b
->get_current_subfile ()->symtab
== NULL
)
11745 /* NOTE: start_subfile will recognize when it's been
11746 passed a file it has already seen. So we can't
11747 assume there's a simple mapping from
11748 cu->line_header->file_names to subfiles, plus
11749 cu->line_header->file_names may contain dups. */
11750 b
->get_current_subfile ()->symtab
11751 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11754 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11755 tu_group
->symtabs
[i
] = fe
.symtab
;
11760 gdb_assert (m_builder
== nullptr);
11761 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11762 m_builder
.reset (new struct buildsym_compunit
11763 (COMPUNIT_OBJFILE (cust
), "",
11764 COMPUNIT_DIRNAME (cust
),
11765 compunit_language (cust
),
11768 auto &file_names
= line_header
->file_names ();
11769 for (i
= 0; i
< file_names
.size (); ++i
)
11771 file_entry
&fe
= file_names
[i
];
11772 fe
.symtab
= tu_group
->symtabs
[i
];
11776 /* The main symtab is allocated last. Type units don't have DW_AT_name
11777 so they don't have a "real" (so to speak) symtab anyway.
11778 There is later code that will assign the main symtab to all symbols
11779 that don't have one. We need to handle the case of a symbol with a
11780 missing symtab (DW_AT_decl_file) anyway. */
11783 /* Process DW_TAG_type_unit.
11784 For TUs we want to skip the first top level sibling if it's not the
11785 actual type being defined by this TU. In this case the first top
11786 level sibling is there to provide context only. */
11789 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11791 struct die_info
*child_die
;
11793 prepare_one_comp_unit (cu
, die
, language_minimal
);
11795 /* Initialize (or reinitialize) the machinery for building symtabs.
11796 We do this before processing child DIEs, so that the line header table
11797 is available for DW_AT_decl_file. */
11798 cu
->setup_type_unit_groups (die
);
11800 if (die
->child
!= NULL
)
11802 child_die
= die
->child
;
11803 while (child_die
&& child_die
->tag
)
11805 process_die (child_die
, cu
);
11806 child_die
= sibling_die (child_die
);
11813 http://gcc.gnu.org/wiki/DebugFission
11814 http://gcc.gnu.org/wiki/DebugFissionDWP
11816 To simplify handling of both DWO files ("object" files with the DWARF info)
11817 and DWP files (a file with the DWOs packaged up into one file), we treat
11818 DWP files as having a collection of virtual DWO files. */
11821 hash_dwo_file (const void *item
)
11823 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11826 hash
= htab_hash_string (dwo_file
->dwo_name
);
11827 if (dwo_file
->comp_dir
!= NULL
)
11828 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11833 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11835 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11836 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11838 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11840 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11841 return lhs
->comp_dir
== rhs
->comp_dir
;
11842 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11845 /* Allocate a hash table for DWO files. */
11848 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11850 auto delete_dwo_file
= [] (void *item
)
11852 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11857 return htab_up (htab_create_alloc_ex (41,
11861 &objfile
->objfile_obstack
,
11862 hashtab_obstack_allocate
,
11863 dummy_obstack_deallocate
));
11866 /* Lookup DWO file DWO_NAME. */
11869 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11870 const char *dwo_name
,
11871 const char *comp_dir
)
11873 struct dwo_file find_entry
;
11876 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11877 dwarf2_per_objfile
->dwo_files
11878 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11880 find_entry
.dwo_name
= dwo_name
;
11881 find_entry
.comp_dir
= comp_dir
;
11882 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11889 hash_dwo_unit (const void *item
)
11891 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11893 /* This drops the top 32 bits of the id, but is ok for a hash. */
11894 return dwo_unit
->signature
;
11898 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11900 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11901 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11903 /* The signature is assumed to be unique within the DWO file.
11904 So while object file CU dwo_id's always have the value zero,
11905 that's OK, assuming each object file DWO file has only one CU,
11906 and that's the rule for now. */
11907 return lhs
->signature
== rhs
->signature
;
11910 /* Allocate a hash table for DWO CUs,TUs.
11911 There is one of these tables for each of CUs,TUs for each DWO file. */
11914 allocate_dwo_unit_table (struct objfile
*objfile
)
11916 /* Start out with a pretty small number.
11917 Generally DWO files contain only one CU and maybe some TUs. */
11918 return htab_create_alloc_ex (3,
11922 &objfile
->objfile_obstack
,
11923 hashtab_obstack_allocate
,
11924 dummy_obstack_deallocate
);
11927 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11929 struct create_dwo_cu_data
11931 struct dwo_file
*dwo_file
;
11932 struct dwo_unit dwo_unit
;
11935 /* die_reader_func for create_dwo_cu. */
11938 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11939 const gdb_byte
*info_ptr
,
11940 struct die_info
*comp_unit_die
,
11944 struct dwarf2_cu
*cu
= reader
->cu
;
11945 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11946 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11947 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11948 struct dwo_file
*dwo_file
= data
->dwo_file
;
11949 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11951 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11952 if (!signature
.has_value ())
11954 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11955 " its dwo_id [in module %s]"),
11956 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11960 dwo_unit
->dwo_file
= dwo_file
;
11961 dwo_unit
->signature
= *signature
;
11962 dwo_unit
->section
= section
;
11963 dwo_unit
->sect_off
= sect_off
;
11964 dwo_unit
->length
= cu
->per_cu
->length
;
11966 if (dwarf_read_debug
)
11967 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11968 sect_offset_str (sect_off
),
11969 hex_string (dwo_unit
->signature
));
11972 /* Create the dwo_units for the CUs in a DWO_FILE.
11973 Note: This function processes DWO files only, not DWP files. */
11976 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11977 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11980 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11981 const gdb_byte
*info_ptr
, *end_ptr
;
11983 dwarf2_read_section (objfile
, §ion
);
11984 info_ptr
= section
.buffer
;
11986 if (info_ptr
== NULL
)
11989 if (dwarf_read_debug
)
11991 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11992 get_section_name (§ion
),
11993 get_section_file_name (§ion
));
11996 end_ptr
= info_ptr
+ section
.size
;
11997 while (info_ptr
< end_ptr
)
11999 struct dwarf2_per_cu_data per_cu
;
12000 struct create_dwo_cu_data create_dwo_cu_data
;
12001 struct dwo_unit
*dwo_unit
;
12003 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12005 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12006 sizeof (create_dwo_cu_data
.dwo_unit
));
12007 memset (&per_cu
, 0, sizeof (per_cu
));
12008 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12009 per_cu
.is_debug_types
= 0;
12010 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12011 per_cu
.section
= §ion
;
12012 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12014 init_cutu_and_read_dies_no_follow (
12015 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12016 info_ptr
+= per_cu
.length
;
12018 // If the unit could not be parsed, skip it.
12019 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12022 if (cus_htab
== NULL
)
12023 cus_htab
= allocate_dwo_unit_table (objfile
);
12025 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12026 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12027 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12028 gdb_assert (slot
!= NULL
);
12031 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12032 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12034 complaint (_("debug cu entry at offset %s is duplicate to"
12035 " the entry at offset %s, signature %s"),
12036 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12037 hex_string (dwo_unit
->signature
));
12039 *slot
= (void *)dwo_unit
;
12043 /* DWP file .debug_{cu,tu}_index section format:
12044 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12048 Both index sections have the same format, and serve to map a 64-bit
12049 signature to a set of section numbers. Each section begins with a header,
12050 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12051 indexes, and a pool of 32-bit section numbers. The index sections will be
12052 aligned at 8-byte boundaries in the file.
12054 The index section header consists of:
12056 V, 32 bit version number
12058 N, 32 bit number of compilation units or type units in the index
12059 M, 32 bit number of slots in the hash table
12061 Numbers are recorded using the byte order of the application binary.
12063 The hash table begins at offset 16 in the section, and consists of an array
12064 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12065 order of the application binary). Unused slots in the hash table are 0.
12066 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12068 The parallel table begins immediately after the hash table
12069 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12070 array of 32-bit indexes (using the byte order of the application binary),
12071 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12072 table contains a 32-bit index into the pool of section numbers. For unused
12073 hash table slots, the corresponding entry in the parallel table will be 0.
12075 The pool of section numbers begins immediately following the hash table
12076 (at offset 16 + 12 * M from the beginning of the section). The pool of
12077 section numbers consists of an array of 32-bit words (using the byte order
12078 of the application binary). Each item in the array is indexed starting
12079 from 0. The hash table entry provides the index of the first section
12080 number in the set. Additional section numbers in the set follow, and the
12081 set is terminated by a 0 entry (section number 0 is not used in ELF).
12083 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12084 section must be the first entry in the set, and the .debug_abbrev.dwo must
12085 be the second entry. Other members of the set may follow in any order.
12091 DWP Version 2 combines all the .debug_info, etc. sections into one,
12092 and the entries in the index tables are now offsets into these sections.
12093 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12096 Index Section Contents:
12098 Hash Table of Signatures dwp_hash_table.hash_table
12099 Parallel Table of Indices dwp_hash_table.unit_table
12100 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12101 Table of Section Sizes dwp_hash_table.v2.sizes
12103 The index section header consists of:
12105 V, 32 bit version number
12106 L, 32 bit number of columns in the table of section offsets
12107 N, 32 bit number of compilation units or type units in the index
12108 M, 32 bit number of slots in the hash table
12110 Numbers are recorded using the byte order of the application binary.
12112 The hash table has the same format as version 1.
12113 The parallel table of indices has the same format as version 1,
12114 except that the entries are origin-1 indices into the table of sections
12115 offsets and the table of section sizes.
12117 The table of offsets begins immediately following the parallel table
12118 (at offset 16 + 12 * M from the beginning of the section). The table is
12119 a two-dimensional array of 32-bit words (using the byte order of the
12120 application binary), with L columns and N+1 rows, in row-major order.
12121 Each row in the array is indexed starting from 0. The first row provides
12122 a key to the remaining rows: each column in this row provides an identifier
12123 for a debug section, and the offsets in the same column of subsequent rows
12124 refer to that section. The section identifiers are:
12126 DW_SECT_INFO 1 .debug_info.dwo
12127 DW_SECT_TYPES 2 .debug_types.dwo
12128 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12129 DW_SECT_LINE 4 .debug_line.dwo
12130 DW_SECT_LOC 5 .debug_loc.dwo
12131 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12132 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12133 DW_SECT_MACRO 8 .debug_macro.dwo
12135 The offsets provided by the CU and TU index sections are the base offsets
12136 for the contributions made by each CU or TU to the corresponding section
12137 in the package file. Each CU and TU header contains an abbrev_offset
12138 field, used to find the abbreviations table for that CU or TU within the
12139 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12140 be interpreted as relative to the base offset given in the index section.
12141 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12142 should be interpreted as relative to the base offset for .debug_line.dwo,
12143 and offsets into other debug sections obtained from DWARF attributes should
12144 also be interpreted as relative to the corresponding base offset.
12146 The table of sizes begins immediately following the table of offsets.
12147 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12148 with L columns and N rows, in row-major order. Each row in the array is
12149 indexed starting from 1 (row 0 is shared by the two tables).
12153 Hash table lookup is handled the same in version 1 and 2:
12155 We assume that N and M will not exceed 2^32 - 1.
12156 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12158 Given a 64-bit compilation unit signature or a type signature S, an entry
12159 in the hash table is located as follows:
12161 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12162 the low-order k bits all set to 1.
12164 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12166 3) If the hash table entry at index H matches the signature, use that
12167 entry. If the hash table entry at index H is unused (all zeroes),
12168 terminate the search: the signature is not present in the table.
12170 4) Let H = (H + H') modulo M. Repeat at Step 3.
12172 Because M > N and H' and M are relatively prime, the search is guaranteed
12173 to stop at an unused slot or find the match. */
12175 /* Create a hash table to map DWO IDs to their CU/TU entry in
12176 .debug_{info,types}.dwo in DWP_FILE.
12177 Returns NULL if there isn't one.
12178 Note: This function processes DWP files only, not DWO files. */
12180 static struct dwp_hash_table
*
12181 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12182 struct dwp_file
*dwp_file
, int is_debug_types
)
12184 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12185 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12186 const gdb_byte
*index_ptr
, *index_end
;
12187 struct dwarf2_section_info
*index
;
12188 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12189 struct dwp_hash_table
*htab
;
12191 if (is_debug_types
)
12192 index
= &dwp_file
->sections
.tu_index
;
12194 index
= &dwp_file
->sections
.cu_index
;
12196 if (dwarf2_section_empty_p (index
))
12198 dwarf2_read_section (objfile
, index
);
12200 index_ptr
= index
->buffer
;
12201 index_end
= index_ptr
+ index
->size
;
12203 version
= read_4_bytes (dbfd
, index_ptr
);
12206 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12210 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12212 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12215 if (version
!= 1 && version
!= 2)
12217 error (_("Dwarf Error: unsupported DWP file version (%s)"
12218 " [in module %s]"),
12219 pulongest (version
), dwp_file
->name
);
12221 if (nr_slots
!= (nr_slots
& -nr_slots
))
12223 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12224 " is not power of 2 [in module %s]"),
12225 pulongest (nr_slots
), dwp_file
->name
);
12228 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12229 htab
->version
= version
;
12230 htab
->nr_columns
= nr_columns
;
12231 htab
->nr_units
= nr_units
;
12232 htab
->nr_slots
= nr_slots
;
12233 htab
->hash_table
= index_ptr
;
12234 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12236 /* Exit early if the table is empty. */
12237 if (nr_slots
== 0 || nr_units
== 0
12238 || (version
== 2 && nr_columns
== 0))
12240 /* All must be zero. */
12241 if (nr_slots
!= 0 || nr_units
!= 0
12242 || (version
== 2 && nr_columns
!= 0))
12244 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12245 " all zero [in modules %s]"),
12253 htab
->section_pool
.v1
.indices
=
12254 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12255 /* It's harder to decide whether the section is too small in v1.
12256 V1 is deprecated anyway so we punt. */
12260 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12261 int *ids
= htab
->section_pool
.v2
.section_ids
;
12262 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12263 /* Reverse map for error checking. */
12264 int ids_seen
[DW_SECT_MAX
+ 1];
12267 if (nr_columns
< 2)
12269 error (_("Dwarf Error: bad DWP hash table, too few columns"
12270 " in section table [in module %s]"),
12273 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12275 error (_("Dwarf Error: bad DWP hash table, too many columns"
12276 " in section table [in module %s]"),
12279 memset (ids
, 255, sizeof_ids
);
12280 memset (ids_seen
, 255, sizeof (ids_seen
));
12281 for (i
= 0; i
< nr_columns
; ++i
)
12283 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12285 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12287 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12288 " in section table [in module %s]"),
12289 id
, dwp_file
->name
);
12291 if (ids_seen
[id
] != -1)
12293 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12294 " id %d in section table [in module %s]"),
12295 id
, dwp_file
->name
);
12300 /* Must have exactly one info or types section. */
12301 if (((ids_seen
[DW_SECT_INFO
] != -1)
12302 + (ids_seen
[DW_SECT_TYPES
] != -1))
12305 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12306 " DWO info/types section [in module %s]"),
12309 /* Must have an abbrev section. */
12310 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12312 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12313 " section [in module %s]"),
12316 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12317 htab
->section_pool
.v2
.sizes
=
12318 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12319 * nr_units
* nr_columns
);
12320 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12321 * nr_units
* nr_columns
))
12324 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12325 " [in module %s]"),
12333 /* Update SECTIONS with the data from SECTP.
12335 This function is like the other "locate" section routines that are
12336 passed to bfd_map_over_sections, but in this context the sections to
12337 read comes from the DWP V1 hash table, not the full ELF section table.
12339 The result is non-zero for success, or zero if an error was found. */
12342 locate_v1_virtual_dwo_sections (asection
*sectp
,
12343 struct virtual_v1_dwo_sections
*sections
)
12345 const struct dwop_section_names
*names
= &dwop_section_names
;
12347 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12349 /* There can be only one. */
12350 if (sections
->abbrev
.s
.section
!= NULL
)
12352 sections
->abbrev
.s
.section
= sectp
;
12353 sections
->abbrev
.size
= bfd_section_size (sectp
);
12355 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12356 || section_is_p (sectp
->name
, &names
->types_dwo
))
12358 /* There can be only one. */
12359 if (sections
->info_or_types
.s
.section
!= NULL
)
12361 sections
->info_or_types
.s
.section
= sectp
;
12362 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12364 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12366 /* There can be only one. */
12367 if (sections
->line
.s
.section
!= NULL
)
12369 sections
->line
.s
.section
= sectp
;
12370 sections
->line
.size
= bfd_section_size (sectp
);
12372 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12374 /* There can be only one. */
12375 if (sections
->loc
.s
.section
!= NULL
)
12377 sections
->loc
.s
.section
= sectp
;
12378 sections
->loc
.size
= bfd_section_size (sectp
);
12380 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12382 /* There can be only one. */
12383 if (sections
->macinfo
.s
.section
!= NULL
)
12385 sections
->macinfo
.s
.section
= sectp
;
12386 sections
->macinfo
.size
= bfd_section_size (sectp
);
12388 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12390 /* There can be only one. */
12391 if (sections
->macro
.s
.section
!= NULL
)
12393 sections
->macro
.s
.section
= sectp
;
12394 sections
->macro
.size
= bfd_section_size (sectp
);
12396 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12398 /* There can be only one. */
12399 if (sections
->str_offsets
.s
.section
!= NULL
)
12401 sections
->str_offsets
.s
.section
= sectp
;
12402 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12406 /* No other kind of section is valid. */
12413 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12414 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12415 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12416 This is for DWP version 1 files. */
12418 static struct dwo_unit
*
12419 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12420 struct dwp_file
*dwp_file
,
12421 uint32_t unit_index
,
12422 const char *comp_dir
,
12423 ULONGEST signature
, int is_debug_types
)
12425 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12426 const struct dwp_hash_table
*dwp_htab
=
12427 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12428 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12429 const char *kind
= is_debug_types
? "TU" : "CU";
12430 struct dwo_file
*dwo_file
;
12431 struct dwo_unit
*dwo_unit
;
12432 struct virtual_v1_dwo_sections sections
;
12433 void **dwo_file_slot
;
12436 gdb_assert (dwp_file
->version
== 1);
12438 if (dwarf_read_debug
)
12440 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12442 pulongest (unit_index
), hex_string (signature
),
12446 /* Fetch the sections of this DWO unit.
12447 Put a limit on the number of sections we look for so that bad data
12448 doesn't cause us to loop forever. */
12450 #define MAX_NR_V1_DWO_SECTIONS \
12451 (1 /* .debug_info or .debug_types */ \
12452 + 1 /* .debug_abbrev */ \
12453 + 1 /* .debug_line */ \
12454 + 1 /* .debug_loc */ \
12455 + 1 /* .debug_str_offsets */ \
12456 + 1 /* .debug_macro or .debug_macinfo */ \
12457 + 1 /* trailing zero */)
12459 memset (§ions
, 0, sizeof (sections
));
12461 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12464 uint32_t section_nr
=
12465 read_4_bytes (dbfd
,
12466 dwp_htab
->section_pool
.v1
.indices
12467 + (unit_index
+ i
) * sizeof (uint32_t));
12469 if (section_nr
== 0)
12471 if (section_nr
>= dwp_file
->num_sections
)
12473 error (_("Dwarf Error: bad DWP hash table, section number too large"
12474 " [in module %s]"),
12478 sectp
= dwp_file
->elf_sections
[section_nr
];
12479 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12481 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12482 " [in module %s]"),
12488 || dwarf2_section_empty_p (§ions
.info_or_types
)
12489 || dwarf2_section_empty_p (§ions
.abbrev
))
12491 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12492 " [in module %s]"),
12495 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12497 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12498 " [in module %s]"),
12502 /* It's easier for the rest of the code if we fake a struct dwo_file and
12503 have dwo_unit "live" in that. At least for now.
12505 The DWP file can be made up of a random collection of CUs and TUs.
12506 However, for each CU + set of TUs that came from the same original DWO
12507 file, we can combine them back into a virtual DWO file to save space
12508 (fewer struct dwo_file objects to allocate). Remember that for really
12509 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12511 std::string virtual_dwo_name
=
12512 string_printf ("virtual-dwo/%d-%d-%d-%d",
12513 get_section_id (§ions
.abbrev
),
12514 get_section_id (§ions
.line
),
12515 get_section_id (§ions
.loc
),
12516 get_section_id (§ions
.str_offsets
));
12517 /* Can we use an existing virtual DWO file? */
12518 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12519 virtual_dwo_name
.c_str (),
12521 /* Create one if necessary. */
12522 if (*dwo_file_slot
== NULL
)
12524 if (dwarf_read_debug
)
12526 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12527 virtual_dwo_name
.c_str ());
12529 dwo_file
= new struct dwo_file
;
12530 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12532 dwo_file
->comp_dir
= comp_dir
;
12533 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12534 dwo_file
->sections
.line
= sections
.line
;
12535 dwo_file
->sections
.loc
= sections
.loc
;
12536 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12537 dwo_file
->sections
.macro
= sections
.macro
;
12538 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12539 /* The "str" section is global to the entire DWP file. */
12540 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12541 /* The info or types section is assigned below to dwo_unit,
12542 there's no need to record it in dwo_file.
12543 Also, we can't simply record type sections in dwo_file because
12544 we record a pointer into the vector in dwo_unit. As we collect more
12545 types we'll grow the vector and eventually have to reallocate space
12546 for it, invalidating all copies of pointers into the previous
12548 *dwo_file_slot
= dwo_file
;
12552 if (dwarf_read_debug
)
12554 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12555 virtual_dwo_name
.c_str ());
12557 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12560 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12561 dwo_unit
->dwo_file
= dwo_file
;
12562 dwo_unit
->signature
= signature
;
12563 dwo_unit
->section
=
12564 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12565 *dwo_unit
->section
= sections
.info_or_types
;
12566 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12571 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12572 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12573 piece within that section used by a TU/CU, return a virtual section
12574 of just that piece. */
12576 static struct dwarf2_section_info
12577 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12578 struct dwarf2_section_info
*section
,
12579 bfd_size_type offset
, bfd_size_type size
)
12581 struct dwarf2_section_info result
;
12584 gdb_assert (section
!= NULL
);
12585 gdb_assert (!section
->is_virtual
);
12587 memset (&result
, 0, sizeof (result
));
12588 result
.s
.containing_section
= section
;
12589 result
.is_virtual
= true;
12594 sectp
= get_section_bfd_section (section
);
12596 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12597 bounds of the real section. This is a pretty-rare event, so just
12598 flag an error (easier) instead of a warning and trying to cope. */
12600 || offset
+ size
> bfd_section_size (sectp
))
12602 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12603 " in section %s [in module %s]"),
12604 sectp
? bfd_section_name (sectp
) : "<unknown>",
12605 objfile_name (dwarf2_per_objfile
->objfile
));
12608 result
.virtual_offset
= offset
;
12609 result
.size
= size
;
12613 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12614 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12615 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12616 This is for DWP version 2 files. */
12618 static struct dwo_unit
*
12619 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12620 struct dwp_file
*dwp_file
,
12621 uint32_t unit_index
,
12622 const char *comp_dir
,
12623 ULONGEST signature
, int is_debug_types
)
12625 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12626 const struct dwp_hash_table
*dwp_htab
=
12627 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12628 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12629 const char *kind
= is_debug_types
? "TU" : "CU";
12630 struct dwo_file
*dwo_file
;
12631 struct dwo_unit
*dwo_unit
;
12632 struct virtual_v2_dwo_sections sections
;
12633 void **dwo_file_slot
;
12636 gdb_assert (dwp_file
->version
== 2);
12638 if (dwarf_read_debug
)
12640 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12642 pulongest (unit_index
), hex_string (signature
),
12646 /* Fetch the section offsets of this DWO unit. */
12648 memset (§ions
, 0, sizeof (sections
));
12650 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12652 uint32_t offset
= read_4_bytes (dbfd
,
12653 dwp_htab
->section_pool
.v2
.offsets
12654 + (((unit_index
- 1) * dwp_htab
->nr_columns
12656 * sizeof (uint32_t)));
12657 uint32_t size
= read_4_bytes (dbfd
,
12658 dwp_htab
->section_pool
.v2
.sizes
12659 + (((unit_index
- 1) * dwp_htab
->nr_columns
12661 * sizeof (uint32_t)));
12663 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12666 case DW_SECT_TYPES
:
12667 sections
.info_or_types_offset
= offset
;
12668 sections
.info_or_types_size
= size
;
12670 case DW_SECT_ABBREV
:
12671 sections
.abbrev_offset
= offset
;
12672 sections
.abbrev_size
= size
;
12675 sections
.line_offset
= offset
;
12676 sections
.line_size
= size
;
12679 sections
.loc_offset
= offset
;
12680 sections
.loc_size
= size
;
12682 case DW_SECT_STR_OFFSETS
:
12683 sections
.str_offsets_offset
= offset
;
12684 sections
.str_offsets_size
= size
;
12686 case DW_SECT_MACINFO
:
12687 sections
.macinfo_offset
= offset
;
12688 sections
.macinfo_size
= size
;
12690 case DW_SECT_MACRO
:
12691 sections
.macro_offset
= offset
;
12692 sections
.macro_size
= size
;
12697 /* It's easier for the rest of the code if we fake a struct dwo_file and
12698 have dwo_unit "live" in that. At least for now.
12700 The DWP file can be made up of a random collection of CUs and TUs.
12701 However, for each CU + set of TUs that came from the same original DWO
12702 file, we can combine them back into a virtual DWO file to save space
12703 (fewer struct dwo_file objects to allocate). Remember that for really
12704 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12706 std::string virtual_dwo_name
=
12707 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12708 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12709 (long) (sections
.line_size
? sections
.line_offset
: 0),
12710 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12711 (long) (sections
.str_offsets_size
12712 ? sections
.str_offsets_offset
: 0));
12713 /* Can we use an existing virtual DWO file? */
12714 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12715 virtual_dwo_name
.c_str (),
12717 /* Create one if necessary. */
12718 if (*dwo_file_slot
== NULL
)
12720 if (dwarf_read_debug
)
12722 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12723 virtual_dwo_name
.c_str ());
12725 dwo_file
= new struct dwo_file
;
12726 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12728 dwo_file
->comp_dir
= comp_dir
;
12729 dwo_file
->sections
.abbrev
=
12730 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12731 sections
.abbrev_offset
, sections
.abbrev_size
);
12732 dwo_file
->sections
.line
=
12733 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12734 sections
.line_offset
, sections
.line_size
);
12735 dwo_file
->sections
.loc
=
12736 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12737 sections
.loc_offset
, sections
.loc_size
);
12738 dwo_file
->sections
.macinfo
=
12739 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12740 sections
.macinfo_offset
, sections
.macinfo_size
);
12741 dwo_file
->sections
.macro
=
12742 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12743 sections
.macro_offset
, sections
.macro_size
);
12744 dwo_file
->sections
.str_offsets
=
12745 create_dwp_v2_section (dwarf2_per_objfile
,
12746 &dwp_file
->sections
.str_offsets
,
12747 sections
.str_offsets_offset
,
12748 sections
.str_offsets_size
);
12749 /* The "str" section is global to the entire DWP file. */
12750 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12751 /* The info or types section is assigned below to dwo_unit,
12752 there's no need to record it in dwo_file.
12753 Also, we can't simply record type sections in dwo_file because
12754 we record a pointer into the vector in dwo_unit. As we collect more
12755 types we'll grow the vector and eventually have to reallocate space
12756 for it, invalidating all copies of pointers into the previous
12758 *dwo_file_slot
= dwo_file
;
12762 if (dwarf_read_debug
)
12764 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12765 virtual_dwo_name
.c_str ());
12767 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12770 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12771 dwo_unit
->dwo_file
= dwo_file
;
12772 dwo_unit
->signature
= signature
;
12773 dwo_unit
->section
=
12774 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12775 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12777 ? &dwp_file
->sections
.types
12778 : &dwp_file
->sections
.info
,
12779 sections
.info_or_types_offset
,
12780 sections
.info_or_types_size
);
12781 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12786 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12787 Returns NULL if the signature isn't found. */
12789 static struct dwo_unit
*
12790 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12791 struct dwp_file
*dwp_file
, const char *comp_dir
,
12792 ULONGEST signature
, int is_debug_types
)
12794 const struct dwp_hash_table
*dwp_htab
=
12795 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12796 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12797 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12798 uint32_t hash
= signature
& mask
;
12799 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12802 struct dwo_unit find_dwo_cu
;
12804 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12805 find_dwo_cu
.signature
= signature
;
12806 slot
= htab_find_slot (is_debug_types
12807 ? dwp_file
->loaded_tus
12808 : dwp_file
->loaded_cus
,
12809 &find_dwo_cu
, INSERT
);
12812 return (struct dwo_unit
*) *slot
;
12814 /* Use a for loop so that we don't loop forever on bad debug info. */
12815 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12817 ULONGEST signature_in_table
;
12819 signature_in_table
=
12820 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12821 if (signature_in_table
== signature
)
12823 uint32_t unit_index
=
12824 read_4_bytes (dbfd
,
12825 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12827 if (dwp_file
->version
== 1)
12829 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12830 dwp_file
, unit_index
,
12831 comp_dir
, signature
,
12836 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12837 dwp_file
, unit_index
,
12838 comp_dir
, signature
,
12841 return (struct dwo_unit
*) *slot
;
12843 if (signature_in_table
== 0)
12845 hash
= (hash
+ hash2
) & mask
;
12848 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12849 " [in module %s]"),
12853 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12854 Open the file specified by FILE_NAME and hand it off to BFD for
12855 preliminary analysis. Return a newly initialized bfd *, which
12856 includes a canonicalized copy of FILE_NAME.
12857 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12858 SEARCH_CWD is true if the current directory is to be searched.
12859 It will be searched before debug-file-directory.
12860 If successful, the file is added to the bfd include table of the
12861 objfile's bfd (see gdb_bfd_record_inclusion).
12862 If unable to find/open the file, return NULL.
12863 NOTE: This function is derived from symfile_bfd_open. */
12865 static gdb_bfd_ref_ptr
12866 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12867 const char *file_name
, int is_dwp
, int search_cwd
)
12870 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12871 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12872 to debug_file_directory. */
12873 const char *search_path
;
12874 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12876 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12879 if (*debug_file_directory
!= '\0')
12881 search_path_holder
.reset (concat (".", dirname_separator_string
,
12882 debug_file_directory
,
12884 search_path
= search_path_holder
.get ();
12890 search_path
= debug_file_directory
;
12892 openp_flags flags
= OPF_RETURN_REALPATH
;
12894 flags
|= OPF_SEARCH_IN_PATH
;
12896 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12897 desc
= openp (search_path
, flags
, file_name
,
12898 O_RDONLY
| O_BINARY
, &absolute_name
);
12902 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12904 if (sym_bfd
== NULL
)
12906 bfd_set_cacheable (sym_bfd
.get (), 1);
12908 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12911 /* Success. Record the bfd as having been included by the objfile's bfd.
12912 This is important because things like demangled_names_hash lives in the
12913 objfile's per_bfd space and may have references to things like symbol
12914 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12915 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12920 /* Try to open DWO file FILE_NAME.
12921 COMP_DIR is the DW_AT_comp_dir attribute.
12922 The result is the bfd handle of the file.
12923 If there is a problem finding or opening the file, return NULL.
12924 Upon success, the canonicalized path of the file is stored in the bfd,
12925 same as symfile_bfd_open. */
12927 static gdb_bfd_ref_ptr
12928 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12929 const char *file_name
, const char *comp_dir
)
12931 if (IS_ABSOLUTE_PATH (file_name
))
12932 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12933 0 /*is_dwp*/, 0 /*search_cwd*/);
12935 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12937 if (comp_dir
!= NULL
)
12939 gdb::unique_xmalloc_ptr
<char> path_to_try
12940 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12942 /* NOTE: If comp_dir is a relative path, this will also try the
12943 search path, which seems useful. */
12944 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12945 path_to_try
.get (),
12947 1 /*search_cwd*/));
12952 /* That didn't work, try debug-file-directory, which, despite its name,
12953 is a list of paths. */
12955 if (*debug_file_directory
== '\0')
12958 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12959 0 /*is_dwp*/, 1 /*search_cwd*/);
12962 /* This function is mapped across the sections and remembers the offset and
12963 size of each of the DWO debugging sections we are interested in. */
12966 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12968 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12969 const struct dwop_section_names
*names
= &dwop_section_names
;
12971 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12973 dwo_sections
->abbrev
.s
.section
= sectp
;
12974 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12976 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12978 dwo_sections
->info
.s
.section
= sectp
;
12979 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12981 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12983 dwo_sections
->line
.s
.section
= sectp
;
12984 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12986 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12988 dwo_sections
->loc
.s
.section
= sectp
;
12989 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12991 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12993 dwo_sections
->macinfo
.s
.section
= sectp
;
12994 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12996 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12998 dwo_sections
->macro
.s
.section
= sectp
;
12999 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13001 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13003 dwo_sections
->str
.s
.section
= sectp
;
13004 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13006 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13008 dwo_sections
->str_offsets
.s
.section
= sectp
;
13009 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13011 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13013 struct dwarf2_section_info type_section
;
13015 memset (&type_section
, 0, sizeof (type_section
));
13016 type_section
.s
.section
= sectp
;
13017 type_section
.size
= bfd_section_size (sectp
);
13018 dwo_sections
->types
.push_back (type_section
);
13022 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13023 by PER_CU. This is for the non-DWP case.
13024 The result is NULL if DWO_NAME can't be found. */
13026 static struct dwo_file
*
13027 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13028 const char *dwo_name
, const char *comp_dir
)
13030 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13032 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13035 if (dwarf_read_debug
)
13036 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13040 dwo_file_up
dwo_file (new struct dwo_file
);
13041 dwo_file
->dwo_name
= dwo_name
;
13042 dwo_file
->comp_dir
= comp_dir
;
13043 dwo_file
->dbfd
= std::move (dbfd
);
13045 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13046 &dwo_file
->sections
);
13048 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13051 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13052 dwo_file
->sections
.types
, dwo_file
->tus
);
13054 if (dwarf_read_debug
)
13055 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13057 return dwo_file
.release ();
13060 /* This function is mapped across the sections and remembers the offset and
13061 size of each of the DWP debugging sections common to version 1 and 2 that
13062 we are interested in. */
13065 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13066 void *dwp_file_ptr
)
13068 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13069 const struct dwop_section_names
*names
= &dwop_section_names
;
13070 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13072 /* Record the ELF section number for later lookup: this is what the
13073 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13074 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13075 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13077 /* Look for specific sections that we need. */
13078 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13080 dwp_file
->sections
.str
.s
.section
= sectp
;
13081 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13083 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13085 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13086 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13088 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13090 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13091 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13095 /* This function is mapped across the sections and remembers the offset and
13096 size of each of the DWP version 2 debugging sections that we are interested
13097 in. This is split into a separate function because we don't know if we
13098 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13101 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13103 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13104 const struct dwop_section_names
*names
= &dwop_section_names
;
13105 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13107 /* Record the ELF section number for later lookup: this is what the
13108 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13109 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13110 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13112 /* Look for specific sections that we need. */
13113 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13115 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13116 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13118 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13120 dwp_file
->sections
.info
.s
.section
= sectp
;
13121 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13123 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13125 dwp_file
->sections
.line
.s
.section
= sectp
;
13126 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13128 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13130 dwp_file
->sections
.loc
.s
.section
= sectp
;
13131 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13133 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13135 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13136 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13138 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13140 dwp_file
->sections
.macro
.s
.section
= sectp
;
13141 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13143 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13145 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13146 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13148 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13150 dwp_file
->sections
.types
.s
.section
= sectp
;
13151 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13155 /* Hash function for dwp_file loaded CUs/TUs. */
13158 hash_dwp_loaded_cutus (const void *item
)
13160 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13162 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13163 return dwo_unit
->signature
;
13166 /* Equality function for dwp_file loaded CUs/TUs. */
13169 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13171 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13172 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13174 return dua
->signature
== dub
->signature
;
13177 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13180 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13182 return htab_create_alloc_ex (3,
13183 hash_dwp_loaded_cutus
,
13184 eq_dwp_loaded_cutus
,
13186 &objfile
->objfile_obstack
,
13187 hashtab_obstack_allocate
,
13188 dummy_obstack_deallocate
);
13191 /* Try to open DWP file FILE_NAME.
13192 The result is the bfd handle of the file.
13193 If there is a problem finding or opening the file, return NULL.
13194 Upon success, the canonicalized path of the file is stored in the bfd,
13195 same as symfile_bfd_open. */
13197 static gdb_bfd_ref_ptr
13198 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13199 const char *file_name
)
13201 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13203 1 /*search_cwd*/));
13207 /* Work around upstream bug 15652.
13208 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13209 [Whether that's a "bug" is debatable, but it is getting in our way.]
13210 We have no real idea where the dwp file is, because gdb's realpath-ing
13211 of the executable's path may have discarded the needed info.
13212 [IWBN if the dwp file name was recorded in the executable, akin to
13213 .gnu_debuglink, but that doesn't exist yet.]
13214 Strip the directory from FILE_NAME and search again. */
13215 if (*debug_file_directory
!= '\0')
13217 /* Don't implicitly search the current directory here.
13218 If the user wants to search "." to handle this case,
13219 it must be added to debug-file-directory. */
13220 return try_open_dwop_file (dwarf2_per_objfile
,
13221 lbasename (file_name
), 1 /*is_dwp*/,
13228 /* Initialize the use of the DWP file for the current objfile.
13229 By convention the name of the DWP file is ${objfile}.dwp.
13230 The result is NULL if it can't be found. */
13232 static std::unique_ptr
<struct dwp_file
>
13233 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13237 /* Try to find first .dwp for the binary file before any symbolic links
13240 /* If the objfile is a debug file, find the name of the real binary
13241 file and get the name of dwp file from there. */
13242 std::string dwp_name
;
13243 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13245 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13246 const char *backlink_basename
= lbasename (backlink
->original_name
);
13248 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13251 dwp_name
= objfile
->original_name
;
13253 dwp_name
+= ".dwp";
13255 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13257 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13259 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13260 dwp_name
= objfile_name (objfile
);
13261 dwp_name
+= ".dwp";
13262 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13267 if (dwarf_read_debug
)
13268 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13269 return std::unique_ptr
<dwp_file
> ();
13272 const char *name
= bfd_get_filename (dbfd
.get ());
13273 std::unique_ptr
<struct dwp_file
> dwp_file
13274 (new struct dwp_file (name
, std::move (dbfd
)));
13276 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13277 dwp_file
->elf_sections
=
13278 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13279 dwp_file
->num_sections
, asection
*);
13281 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13282 dwarf2_locate_common_dwp_sections
,
13285 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13288 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13291 /* The DWP file version is stored in the hash table. Oh well. */
13292 if (dwp_file
->cus
&& dwp_file
->tus
13293 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13295 /* Technically speaking, we should try to limp along, but this is
13296 pretty bizarre. We use pulongest here because that's the established
13297 portability solution (e.g, we cannot use %u for uint32_t). */
13298 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13299 " TU version %s [in DWP file %s]"),
13300 pulongest (dwp_file
->cus
->version
),
13301 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13305 dwp_file
->version
= dwp_file
->cus
->version
;
13306 else if (dwp_file
->tus
)
13307 dwp_file
->version
= dwp_file
->tus
->version
;
13309 dwp_file
->version
= 2;
13311 if (dwp_file
->version
== 2)
13312 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13313 dwarf2_locate_v2_dwp_sections
,
13316 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13317 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13319 if (dwarf_read_debug
)
13321 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13322 fprintf_unfiltered (gdb_stdlog
,
13323 " %s CUs, %s TUs\n",
13324 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13325 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13331 /* Wrapper around open_and_init_dwp_file, only open it once. */
13333 static struct dwp_file
*
13334 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13336 if (! dwarf2_per_objfile
->dwp_checked
)
13338 dwarf2_per_objfile
->dwp_file
13339 = open_and_init_dwp_file (dwarf2_per_objfile
);
13340 dwarf2_per_objfile
->dwp_checked
= 1;
13342 return dwarf2_per_objfile
->dwp_file
.get ();
13345 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13346 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13347 or in the DWP file for the objfile, referenced by THIS_UNIT.
13348 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13349 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13351 This is called, for example, when wanting to read a variable with a
13352 complex location. Therefore we don't want to do file i/o for every call.
13353 Therefore we don't want to look for a DWO file on every call.
13354 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13355 then we check if we've already seen DWO_NAME, and only THEN do we check
13358 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13359 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13361 static struct dwo_unit
*
13362 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13363 const char *dwo_name
, const char *comp_dir
,
13364 ULONGEST signature
, int is_debug_types
)
13366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13368 const char *kind
= is_debug_types
? "TU" : "CU";
13369 void **dwo_file_slot
;
13370 struct dwo_file
*dwo_file
;
13371 struct dwp_file
*dwp_file
;
13373 /* First see if there's a DWP file.
13374 If we have a DWP file but didn't find the DWO inside it, don't
13375 look for the original DWO file. It makes gdb behave differently
13376 depending on whether one is debugging in the build tree. */
13378 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13379 if (dwp_file
!= NULL
)
13381 const struct dwp_hash_table
*dwp_htab
=
13382 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13384 if (dwp_htab
!= NULL
)
13386 struct dwo_unit
*dwo_cutu
=
13387 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13388 signature
, is_debug_types
);
13390 if (dwo_cutu
!= NULL
)
13392 if (dwarf_read_debug
)
13394 fprintf_unfiltered (gdb_stdlog
,
13395 "Virtual DWO %s %s found: @%s\n",
13396 kind
, hex_string (signature
),
13397 host_address_to_string (dwo_cutu
));
13405 /* No DWP file, look for the DWO file. */
13407 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13408 dwo_name
, comp_dir
);
13409 if (*dwo_file_slot
== NULL
)
13411 /* Read in the file and build a table of the CUs/TUs it contains. */
13412 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13414 /* NOTE: This will be NULL if unable to open the file. */
13415 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13417 if (dwo_file
!= NULL
)
13419 struct dwo_unit
*dwo_cutu
= NULL
;
13421 if (is_debug_types
&& dwo_file
->tus
)
13423 struct dwo_unit find_dwo_cutu
;
13425 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13426 find_dwo_cutu
.signature
= signature
;
13428 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13430 else if (!is_debug_types
&& dwo_file
->cus
)
13432 struct dwo_unit find_dwo_cutu
;
13434 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13435 find_dwo_cutu
.signature
= signature
;
13436 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13440 if (dwo_cutu
!= NULL
)
13442 if (dwarf_read_debug
)
13444 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13445 kind
, dwo_name
, hex_string (signature
),
13446 host_address_to_string (dwo_cutu
));
13453 /* We didn't find it. This could mean a dwo_id mismatch, or
13454 someone deleted the DWO/DWP file, or the search path isn't set up
13455 correctly to find the file. */
13457 if (dwarf_read_debug
)
13459 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13460 kind
, dwo_name
, hex_string (signature
));
13463 /* This is a warning and not a complaint because it can be caused by
13464 pilot error (e.g., user accidentally deleting the DWO). */
13466 /* Print the name of the DWP file if we looked there, helps the user
13467 better diagnose the problem. */
13468 std::string dwp_text
;
13470 if (dwp_file
!= NULL
)
13471 dwp_text
= string_printf (" [in DWP file %s]",
13472 lbasename (dwp_file
->name
));
13474 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13475 " [in module %s]"),
13476 kind
, dwo_name
, hex_string (signature
),
13478 this_unit
->is_debug_types
? "TU" : "CU",
13479 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13484 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13485 See lookup_dwo_cutu_unit for details. */
13487 static struct dwo_unit
*
13488 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13489 const char *dwo_name
, const char *comp_dir
,
13490 ULONGEST signature
)
13492 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13495 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13496 See lookup_dwo_cutu_unit for details. */
13498 static struct dwo_unit
*
13499 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13500 const char *dwo_name
, const char *comp_dir
)
13502 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13505 /* Traversal function for queue_and_load_all_dwo_tus. */
13508 queue_and_load_dwo_tu (void **slot
, void *info
)
13510 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13511 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13512 ULONGEST signature
= dwo_unit
->signature
;
13513 struct signatured_type
*sig_type
=
13514 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13516 if (sig_type
!= NULL
)
13518 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13520 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13521 a real dependency of PER_CU on SIG_TYPE. That is detected later
13522 while processing PER_CU. */
13523 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13524 load_full_type_unit (sig_cu
);
13525 per_cu
->imported_symtabs_push (sig_cu
);
13531 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13532 The DWO may have the only definition of the type, though it may not be
13533 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13534 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13537 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13539 struct dwo_unit
*dwo_unit
;
13540 struct dwo_file
*dwo_file
;
13542 gdb_assert (!per_cu
->is_debug_types
);
13543 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13544 gdb_assert (per_cu
->cu
!= NULL
);
13546 dwo_unit
= per_cu
->cu
->dwo_unit
;
13547 gdb_assert (dwo_unit
!= NULL
);
13549 dwo_file
= dwo_unit
->dwo_file
;
13550 if (dwo_file
->tus
!= NULL
)
13551 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13554 /* Read in various DIEs. */
13556 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13557 Inherit only the children of the DW_AT_abstract_origin DIE not being
13558 already referenced by DW_AT_abstract_origin from the children of the
13562 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13564 struct die_info
*child_die
;
13565 sect_offset
*offsetp
;
13566 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13567 struct die_info
*origin_die
;
13568 /* Iterator of the ORIGIN_DIE children. */
13569 struct die_info
*origin_child_die
;
13570 struct attribute
*attr
;
13571 struct dwarf2_cu
*origin_cu
;
13572 struct pending
**origin_previous_list_in_scope
;
13574 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13578 /* Note that following die references may follow to a die in a
13582 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13584 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13586 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13587 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13589 if (die
->tag
!= origin_die
->tag
13590 && !(die
->tag
== DW_TAG_inlined_subroutine
13591 && origin_die
->tag
== DW_TAG_subprogram
))
13592 complaint (_("DIE %s and its abstract origin %s have different tags"),
13593 sect_offset_str (die
->sect_off
),
13594 sect_offset_str (origin_die
->sect_off
));
13596 std::vector
<sect_offset
> offsets
;
13598 for (child_die
= die
->child
;
13599 child_die
&& child_die
->tag
;
13600 child_die
= sibling_die (child_die
))
13602 struct die_info
*child_origin_die
;
13603 struct dwarf2_cu
*child_origin_cu
;
13605 /* We are trying to process concrete instance entries:
13606 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13607 it's not relevant to our analysis here. i.e. detecting DIEs that are
13608 present in the abstract instance but not referenced in the concrete
13610 if (child_die
->tag
== DW_TAG_call_site
13611 || child_die
->tag
== DW_TAG_GNU_call_site
)
13614 /* For each CHILD_DIE, find the corresponding child of
13615 ORIGIN_DIE. If there is more than one layer of
13616 DW_AT_abstract_origin, follow them all; there shouldn't be,
13617 but GCC versions at least through 4.4 generate this (GCC PR
13619 child_origin_die
= child_die
;
13620 child_origin_cu
= cu
;
13623 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13627 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13631 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13632 counterpart may exist. */
13633 if (child_origin_die
!= child_die
)
13635 if (child_die
->tag
!= child_origin_die
->tag
13636 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13637 && child_origin_die
->tag
== DW_TAG_subprogram
))
13638 complaint (_("Child DIE %s and its abstract origin %s have "
13640 sect_offset_str (child_die
->sect_off
),
13641 sect_offset_str (child_origin_die
->sect_off
));
13642 if (child_origin_die
->parent
!= origin_die
)
13643 complaint (_("Child DIE %s and its abstract origin %s have "
13644 "different parents"),
13645 sect_offset_str (child_die
->sect_off
),
13646 sect_offset_str (child_origin_die
->sect_off
));
13648 offsets
.push_back (child_origin_die
->sect_off
);
13651 std::sort (offsets
.begin (), offsets
.end ());
13652 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13653 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13654 if (offsetp
[-1] == *offsetp
)
13655 complaint (_("Multiple children of DIE %s refer "
13656 "to DIE %s as their abstract origin"),
13657 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13659 offsetp
= offsets
.data ();
13660 origin_child_die
= origin_die
->child
;
13661 while (origin_child_die
&& origin_child_die
->tag
)
13663 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13664 while (offsetp
< offsets_end
13665 && *offsetp
< origin_child_die
->sect_off
)
13667 if (offsetp
>= offsets_end
13668 || *offsetp
> origin_child_die
->sect_off
)
13670 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13671 Check whether we're already processing ORIGIN_CHILD_DIE.
13672 This can happen with mutually referenced abstract_origins.
13674 if (!origin_child_die
->in_process
)
13675 process_die (origin_child_die
, origin_cu
);
13677 origin_child_die
= sibling_die (origin_child_die
);
13679 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13681 if (cu
!= origin_cu
)
13682 compute_delayed_physnames (origin_cu
);
13686 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13688 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13690 struct context_stack
*newobj
;
13693 struct die_info
*child_die
;
13694 struct attribute
*attr
, *call_line
, *call_file
;
13696 CORE_ADDR baseaddr
;
13697 struct block
*block
;
13698 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13699 std::vector
<struct symbol
*> template_args
;
13700 struct template_symbol
*templ_func
= NULL
;
13704 /* If we do not have call site information, we can't show the
13705 caller of this inlined function. That's too confusing, so
13706 only use the scope for local variables. */
13707 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13708 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13709 if (call_line
== NULL
|| call_file
== NULL
)
13711 read_lexical_block_scope (die
, cu
);
13716 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13718 name
= dwarf2_name (die
, cu
);
13720 /* Ignore functions with missing or empty names. These are actually
13721 illegal according to the DWARF standard. */
13724 complaint (_("missing name for subprogram DIE at %s"),
13725 sect_offset_str (die
->sect_off
));
13729 /* Ignore functions with missing or invalid low and high pc attributes. */
13730 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13731 <= PC_BOUNDS_INVALID
)
13733 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13734 if (!attr
|| !DW_UNSND (attr
))
13735 complaint (_("cannot get low and high bounds "
13736 "for subprogram DIE at %s"),
13737 sect_offset_str (die
->sect_off
));
13741 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13742 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13744 /* If we have any template arguments, then we must allocate a
13745 different sort of symbol. */
13746 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13748 if (child_die
->tag
== DW_TAG_template_type_param
13749 || child_die
->tag
== DW_TAG_template_value_param
)
13751 templ_func
= allocate_template_symbol (objfile
);
13752 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13757 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13758 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13759 (struct symbol
*) templ_func
);
13761 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13762 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13765 /* If there is a location expression for DW_AT_frame_base, record
13767 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13768 if (attr
!= nullptr)
13769 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13771 /* If there is a location for the static link, record it. */
13772 newobj
->static_link
= NULL
;
13773 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13774 if (attr
!= nullptr)
13776 newobj
->static_link
13777 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13778 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13779 dwarf2_per_cu_addr_type (cu
->per_cu
));
13782 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13784 if (die
->child
!= NULL
)
13786 child_die
= die
->child
;
13787 while (child_die
&& child_die
->tag
)
13789 if (child_die
->tag
== DW_TAG_template_type_param
13790 || child_die
->tag
== DW_TAG_template_value_param
)
13792 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13795 template_args
.push_back (arg
);
13798 process_die (child_die
, cu
);
13799 child_die
= sibling_die (child_die
);
13803 inherit_abstract_dies (die
, cu
);
13805 /* If we have a DW_AT_specification, we might need to import using
13806 directives from the context of the specification DIE. See the
13807 comment in determine_prefix. */
13808 if (cu
->language
== language_cplus
13809 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13811 struct dwarf2_cu
*spec_cu
= cu
;
13812 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13816 child_die
= spec_die
->child
;
13817 while (child_die
&& child_die
->tag
)
13819 if (child_die
->tag
== DW_TAG_imported_module
)
13820 process_die (child_die
, spec_cu
);
13821 child_die
= sibling_die (child_die
);
13824 /* In some cases, GCC generates specification DIEs that
13825 themselves contain DW_AT_specification attributes. */
13826 spec_die
= die_specification (spec_die
, &spec_cu
);
13830 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13831 /* Make a block for the local symbols within. */
13832 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13833 cstk
.static_link
, lowpc
, highpc
);
13835 /* For C++, set the block's scope. */
13836 if ((cu
->language
== language_cplus
13837 || cu
->language
== language_fortran
13838 || cu
->language
== language_d
13839 || cu
->language
== language_rust
)
13840 && cu
->processing_has_namespace_info
)
13841 block_set_scope (block
, determine_prefix (die
, cu
),
13842 &objfile
->objfile_obstack
);
13844 /* If we have address ranges, record them. */
13845 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13847 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13849 /* Attach template arguments to function. */
13850 if (!template_args
.empty ())
13852 gdb_assert (templ_func
!= NULL
);
13854 templ_func
->n_template_arguments
= template_args
.size ();
13855 templ_func
->template_arguments
13856 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13857 templ_func
->n_template_arguments
);
13858 memcpy (templ_func
->template_arguments
,
13859 template_args
.data (),
13860 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13862 /* Make sure that the symtab is set on the new symbols. Even
13863 though they don't appear in this symtab directly, other parts
13864 of gdb assume that symbols do, and this is reasonably
13866 for (symbol
*sym
: template_args
)
13867 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13870 /* In C++, we can have functions nested inside functions (e.g., when
13871 a function declares a class that has methods). This means that
13872 when we finish processing a function scope, we may need to go
13873 back to building a containing block's symbol lists. */
13874 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13875 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13877 /* If we've finished processing a top-level function, subsequent
13878 symbols go in the file symbol list. */
13879 if (cu
->get_builder ()->outermost_context_p ())
13880 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13883 /* Process all the DIES contained within a lexical block scope. Start
13884 a new scope, process the dies, and then close the scope. */
13887 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13889 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13890 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13891 CORE_ADDR lowpc
, highpc
;
13892 struct die_info
*child_die
;
13893 CORE_ADDR baseaddr
;
13895 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13897 /* Ignore blocks with missing or invalid low and high pc attributes. */
13898 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13899 as multiple lexical blocks? Handling children in a sane way would
13900 be nasty. Might be easier to properly extend generic blocks to
13901 describe ranges. */
13902 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13904 case PC_BOUNDS_NOT_PRESENT
:
13905 /* DW_TAG_lexical_block has no attributes, process its children as if
13906 there was no wrapping by that DW_TAG_lexical_block.
13907 GCC does no longer produces such DWARF since GCC r224161. */
13908 for (child_die
= die
->child
;
13909 child_die
!= NULL
&& child_die
->tag
;
13910 child_die
= sibling_die (child_die
))
13911 process_die (child_die
, cu
);
13913 case PC_BOUNDS_INVALID
:
13916 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13917 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13919 cu
->get_builder ()->push_context (0, lowpc
);
13920 if (die
->child
!= NULL
)
13922 child_die
= die
->child
;
13923 while (child_die
&& child_die
->tag
)
13925 process_die (child_die
, cu
);
13926 child_die
= sibling_die (child_die
);
13929 inherit_abstract_dies (die
, cu
);
13930 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13932 if (*cu
->get_builder ()->get_local_symbols () != NULL
13933 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13935 struct block
*block
13936 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13937 cstk
.start_addr
, highpc
);
13939 /* Note that recording ranges after traversing children, as we
13940 do here, means that recording a parent's ranges entails
13941 walking across all its children's ranges as they appear in
13942 the address map, which is quadratic behavior.
13944 It would be nicer to record the parent's ranges before
13945 traversing its children, simply overriding whatever you find
13946 there. But since we don't even decide whether to create a
13947 block until after we've traversed its children, that's hard
13949 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13951 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13952 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13955 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13958 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13960 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13961 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13962 CORE_ADDR pc
, baseaddr
;
13963 struct attribute
*attr
;
13964 struct call_site
*call_site
, call_site_local
;
13967 struct die_info
*child_die
;
13969 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13971 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13974 /* This was a pre-DWARF-5 GNU extension alias
13975 for DW_AT_call_return_pc. */
13976 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13980 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13981 "DIE %s [in module %s]"),
13982 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13985 pc
= attr_value_as_address (attr
) + baseaddr
;
13986 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13988 if (cu
->call_site_htab
== NULL
)
13989 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13990 NULL
, &objfile
->objfile_obstack
,
13991 hashtab_obstack_allocate
, NULL
);
13992 call_site_local
.pc
= pc
;
13993 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13996 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13997 "DIE %s [in module %s]"),
13998 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13999 objfile_name (objfile
));
14003 /* Count parameters at the caller. */
14006 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14007 child_die
= sibling_die (child_die
))
14009 if (child_die
->tag
!= DW_TAG_call_site_parameter
14010 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14012 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14013 "DW_TAG_call_site child DIE %s [in module %s]"),
14014 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14015 objfile_name (objfile
));
14023 = ((struct call_site
*)
14024 obstack_alloc (&objfile
->objfile_obstack
,
14025 sizeof (*call_site
)
14026 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14028 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14029 call_site
->pc
= pc
;
14031 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14032 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14034 struct die_info
*func_die
;
14036 /* Skip also over DW_TAG_inlined_subroutine. */
14037 for (func_die
= die
->parent
;
14038 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14039 && func_die
->tag
!= DW_TAG_subroutine_type
;
14040 func_die
= func_die
->parent
);
14042 /* DW_AT_call_all_calls is a superset
14043 of DW_AT_call_all_tail_calls. */
14045 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14046 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14047 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14048 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14050 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14051 not complete. But keep CALL_SITE for look ups via call_site_htab,
14052 both the initial caller containing the real return address PC and
14053 the final callee containing the current PC of a chain of tail
14054 calls do not need to have the tail call list complete. But any
14055 function candidate for a virtual tail call frame searched via
14056 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14057 determined unambiguously. */
14061 struct type
*func_type
= NULL
;
14064 func_type
= get_die_type (func_die
, cu
);
14065 if (func_type
!= NULL
)
14067 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14069 /* Enlist this call site to the function. */
14070 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14071 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14074 complaint (_("Cannot find function owning DW_TAG_call_site "
14075 "DIE %s [in module %s]"),
14076 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14080 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14082 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14084 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14087 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14088 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14090 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14091 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14092 /* Keep NULL DWARF_BLOCK. */;
14093 else if (attr_form_is_block (attr
))
14095 struct dwarf2_locexpr_baton
*dlbaton
;
14097 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14098 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14099 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14100 dlbaton
->per_cu
= cu
->per_cu
;
14102 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14104 else if (attr_form_is_ref (attr
))
14106 struct dwarf2_cu
*target_cu
= cu
;
14107 struct die_info
*target_die
;
14109 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14110 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14111 if (die_is_declaration (target_die
, target_cu
))
14113 const char *target_physname
;
14115 /* Prefer the mangled name; otherwise compute the demangled one. */
14116 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14117 if (target_physname
== NULL
)
14118 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14119 if (target_physname
== NULL
)
14120 complaint (_("DW_AT_call_target target DIE has invalid "
14121 "physname, for referencing DIE %s [in module %s]"),
14122 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14124 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14130 /* DW_AT_entry_pc should be preferred. */
14131 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14132 <= PC_BOUNDS_INVALID
)
14133 complaint (_("DW_AT_call_target target DIE has invalid "
14134 "low pc, for referencing DIE %s [in module %s]"),
14135 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14138 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14139 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14144 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14145 "block nor reference, for DIE %s [in module %s]"),
14146 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14148 call_site
->per_cu
= cu
->per_cu
;
14150 for (child_die
= die
->child
;
14151 child_die
&& child_die
->tag
;
14152 child_die
= sibling_die (child_die
))
14154 struct call_site_parameter
*parameter
;
14155 struct attribute
*loc
, *origin
;
14157 if (child_die
->tag
!= DW_TAG_call_site_parameter
14158 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14160 /* Already printed the complaint above. */
14164 gdb_assert (call_site
->parameter_count
< nparams
);
14165 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14167 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14168 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14169 register is contained in DW_AT_call_value. */
14171 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14172 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14173 if (origin
== NULL
)
14175 /* This was a pre-DWARF-5 GNU extension alias
14176 for DW_AT_call_parameter. */
14177 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14179 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14181 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14183 sect_offset sect_off
14184 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14185 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14187 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14188 binding can be done only inside one CU. Such referenced DIE
14189 therefore cannot be even moved to DW_TAG_partial_unit. */
14190 complaint (_("DW_AT_call_parameter offset is not in CU for "
14191 "DW_TAG_call_site child DIE %s [in module %s]"),
14192 sect_offset_str (child_die
->sect_off
),
14193 objfile_name (objfile
));
14196 parameter
->u
.param_cu_off
14197 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14199 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14201 complaint (_("No DW_FORM_block* DW_AT_location for "
14202 "DW_TAG_call_site child DIE %s [in module %s]"),
14203 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14208 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14209 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14210 if (parameter
->u
.dwarf_reg
!= -1)
14211 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14212 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14213 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14214 ¶meter
->u
.fb_offset
))
14215 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14218 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14219 "for DW_FORM_block* DW_AT_location is supported for "
14220 "DW_TAG_call_site child DIE %s "
14222 sect_offset_str (child_die
->sect_off
),
14223 objfile_name (objfile
));
14228 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14230 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14231 if (!attr_form_is_block (attr
))
14233 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14234 "DW_TAG_call_site child DIE %s [in module %s]"),
14235 sect_offset_str (child_die
->sect_off
),
14236 objfile_name (objfile
));
14239 parameter
->value
= DW_BLOCK (attr
)->data
;
14240 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14242 /* Parameters are not pre-cleared by memset above. */
14243 parameter
->data_value
= NULL
;
14244 parameter
->data_value_size
= 0;
14245 call_site
->parameter_count
++;
14247 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14249 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14250 if (attr
!= nullptr)
14252 if (!attr_form_is_block (attr
))
14253 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14254 "DW_TAG_call_site child DIE %s [in module %s]"),
14255 sect_offset_str (child_die
->sect_off
),
14256 objfile_name (objfile
));
14259 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14260 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14266 /* Helper function for read_variable. If DIE represents a virtual
14267 table, then return the type of the concrete object that is
14268 associated with the virtual table. Otherwise, return NULL. */
14270 static struct type
*
14271 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14273 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14277 /* Find the type DIE. */
14278 struct die_info
*type_die
= NULL
;
14279 struct dwarf2_cu
*type_cu
= cu
;
14281 if (attr_form_is_ref (attr
))
14282 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14283 if (type_die
== NULL
)
14286 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14288 return die_containing_type (type_die
, type_cu
);
14291 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14294 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14296 struct rust_vtable_symbol
*storage
= NULL
;
14298 if (cu
->language
== language_rust
)
14300 struct type
*containing_type
= rust_containing_type (die
, cu
);
14302 if (containing_type
!= NULL
)
14304 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14306 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14307 initialize_objfile_symbol (storage
);
14308 storage
->concrete_type
= containing_type
;
14309 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14313 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14314 struct attribute
*abstract_origin
14315 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14316 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14317 if (res
== NULL
&& loc
&& abstract_origin
)
14319 /* We have a variable without a name, but with a location and an abstract
14320 origin. This may be a concrete instance of an abstract variable
14321 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14323 struct dwarf2_cu
*origin_cu
= cu
;
14324 struct die_info
*origin_die
14325 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14326 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14327 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14331 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14332 reading .debug_rnglists.
14333 Callback's type should be:
14334 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14335 Return true if the attributes are present and valid, otherwise,
14338 template <typename Callback
>
14340 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14341 Callback
&&callback
)
14343 struct dwarf2_per_objfile
*dwarf2_per_objfile
14344 = cu
->per_cu
->dwarf2_per_objfile
;
14345 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14346 bfd
*obfd
= objfile
->obfd
;
14347 /* Base address selection entry. */
14350 const gdb_byte
*buffer
;
14351 CORE_ADDR baseaddr
;
14352 bool overflow
= false;
14354 found_base
= cu
->base_known
;
14355 base
= cu
->base_address
;
14357 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14358 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14360 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14364 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14366 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14370 /* Initialize it due to a false compiler warning. */
14371 CORE_ADDR range_beginning
= 0, range_end
= 0;
14372 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14373 + dwarf2_per_objfile
->rnglists
.size
);
14374 unsigned int bytes_read
;
14376 if (buffer
== buf_end
)
14381 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14384 case DW_RLE_end_of_list
:
14386 case DW_RLE_base_address
:
14387 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14392 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14394 buffer
+= bytes_read
;
14396 case DW_RLE_start_length
:
14397 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14402 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14403 buffer
+= bytes_read
;
14404 range_end
= (range_beginning
14405 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14406 buffer
+= bytes_read
;
14407 if (buffer
> buf_end
)
14413 case DW_RLE_offset_pair
:
14414 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14415 buffer
+= bytes_read
;
14416 if (buffer
> buf_end
)
14421 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14422 buffer
+= bytes_read
;
14423 if (buffer
> buf_end
)
14429 case DW_RLE_start_end
:
14430 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14435 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14436 buffer
+= bytes_read
;
14437 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14438 buffer
+= bytes_read
;
14441 complaint (_("Invalid .debug_rnglists data (no base address)"));
14444 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14446 if (rlet
== DW_RLE_base_address
)
14451 /* We have no valid base address for the ranges
14453 complaint (_("Invalid .debug_rnglists data (no base address)"));
14457 if (range_beginning
> range_end
)
14459 /* Inverted range entries are invalid. */
14460 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14464 /* Empty range entries have no effect. */
14465 if (range_beginning
== range_end
)
14468 range_beginning
+= base
;
14471 /* A not-uncommon case of bad debug info.
14472 Don't pollute the addrmap with bad data. */
14473 if (range_beginning
+ baseaddr
== 0
14474 && !dwarf2_per_objfile
->has_section_at_zero
)
14476 complaint (_(".debug_rnglists entry has start address of zero"
14477 " [in module %s]"), objfile_name (objfile
));
14481 callback (range_beginning
, range_end
);
14486 complaint (_("Offset %d is not terminated "
14487 "for DW_AT_ranges attribute"),
14495 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14496 Callback's type should be:
14497 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14498 Return 1 if the attributes are present and valid, otherwise, return 0. */
14500 template <typename Callback
>
14502 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14503 Callback
&&callback
)
14505 struct dwarf2_per_objfile
*dwarf2_per_objfile
14506 = cu
->per_cu
->dwarf2_per_objfile
;
14507 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14508 struct comp_unit_head
*cu_header
= &cu
->header
;
14509 bfd
*obfd
= objfile
->obfd
;
14510 unsigned int addr_size
= cu_header
->addr_size
;
14511 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14512 /* Base address selection entry. */
14515 unsigned int dummy
;
14516 const gdb_byte
*buffer
;
14517 CORE_ADDR baseaddr
;
14519 if (cu_header
->version
>= 5)
14520 return dwarf2_rnglists_process (offset
, cu
, callback
);
14522 found_base
= cu
->base_known
;
14523 base
= cu
->base_address
;
14525 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14526 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14528 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14532 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14534 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14538 CORE_ADDR range_beginning
, range_end
;
14540 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14541 buffer
+= addr_size
;
14542 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14543 buffer
+= addr_size
;
14544 offset
+= 2 * addr_size
;
14546 /* An end of list marker is a pair of zero addresses. */
14547 if (range_beginning
== 0 && range_end
== 0)
14548 /* Found the end of list entry. */
14551 /* Each base address selection entry is a pair of 2 values.
14552 The first is the largest possible address, the second is
14553 the base address. Check for a base address here. */
14554 if ((range_beginning
& mask
) == mask
)
14556 /* If we found the largest possible address, then we already
14557 have the base address in range_end. */
14565 /* We have no valid base address for the ranges
14567 complaint (_("Invalid .debug_ranges data (no base address)"));
14571 if (range_beginning
> range_end
)
14573 /* Inverted range entries are invalid. */
14574 complaint (_("Invalid .debug_ranges data (inverted range)"));
14578 /* Empty range entries have no effect. */
14579 if (range_beginning
== range_end
)
14582 range_beginning
+= base
;
14585 /* A not-uncommon case of bad debug info.
14586 Don't pollute the addrmap with bad data. */
14587 if (range_beginning
+ baseaddr
== 0
14588 && !dwarf2_per_objfile
->has_section_at_zero
)
14590 complaint (_(".debug_ranges entry has start address of zero"
14591 " [in module %s]"), objfile_name (objfile
));
14595 callback (range_beginning
, range_end
);
14601 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14602 Return 1 if the attributes are present and valid, otherwise, return 0.
14603 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14606 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14607 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14608 struct partial_symtab
*ranges_pst
)
14610 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14611 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14612 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14615 CORE_ADDR high
= 0;
14618 retval
= dwarf2_ranges_process (offset
, cu
,
14619 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14621 if (ranges_pst
!= NULL
)
14626 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14627 range_beginning
+ baseaddr
)
14629 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14630 range_end
+ baseaddr
)
14632 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14633 lowpc
, highpc
- 1, ranges_pst
);
14636 /* FIXME: This is recording everything as a low-high
14637 segment of consecutive addresses. We should have a
14638 data structure for discontiguous block ranges
14642 low
= range_beginning
;
14648 if (range_beginning
< low
)
14649 low
= range_beginning
;
14650 if (range_end
> high
)
14658 /* If the first entry is an end-of-list marker, the range
14659 describes an empty scope, i.e. no instructions. */
14665 *high_return
= high
;
14669 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14670 definition for the return value. *LOWPC and *HIGHPC are set iff
14671 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14673 static enum pc_bounds_kind
14674 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14675 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14676 struct partial_symtab
*pst
)
14678 struct dwarf2_per_objfile
*dwarf2_per_objfile
14679 = cu
->per_cu
->dwarf2_per_objfile
;
14680 struct attribute
*attr
;
14681 struct attribute
*attr_high
;
14683 CORE_ADDR high
= 0;
14684 enum pc_bounds_kind ret
;
14686 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14689 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14690 if (attr
!= nullptr)
14692 low
= attr_value_as_address (attr
);
14693 high
= attr_value_as_address (attr_high
);
14694 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14698 /* Found high w/o low attribute. */
14699 return PC_BOUNDS_INVALID
;
14701 /* Found consecutive range of addresses. */
14702 ret
= PC_BOUNDS_HIGH_LOW
;
14706 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14709 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14710 We take advantage of the fact that DW_AT_ranges does not appear
14711 in DW_TAG_compile_unit of DWO files. */
14712 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14713 unsigned int ranges_offset
= (DW_UNSND (attr
)
14714 + (need_ranges_base
14718 /* Value of the DW_AT_ranges attribute is the offset in the
14719 .debug_ranges section. */
14720 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14721 return PC_BOUNDS_INVALID
;
14722 /* Found discontinuous range of addresses. */
14723 ret
= PC_BOUNDS_RANGES
;
14726 return PC_BOUNDS_NOT_PRESENT
;
14729 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14731 return PC_BOUNDS_INVALID
;
14733 /* When using the GNU linker, .gnu.linkonce. sections are used to
14734 eliminate duplicate copies of functions and vtables and such.
14735 The linker will arbitrarily choose one and discard the others.
14736 The AT_*_pc values for such functions refer to local labels in
14737 these sections. If the section from that file was discarded, the
14738 labels are not in the output, so the relocs get a value of 0.
14739 If this is a discarded function, mark the pc bounds as invalid,
14740 so that GDB will ignore it. */
14741 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14742 return PC_BOUNDS_INVALID
;
14750 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14751 its low and high PC addresses. Do nothing if these addresses could not
14752 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14753 and HIGHPC to the high address if greater than HIGHPC. */
14756 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14757 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14758 struct dwarf2_cu
*cu
)
14760 CORE_ADDR low
, high
;
14761 struct die_info
*child
= die
->child
;
14763 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14765 *lowpc
= std::min (*lowpc
, low
);
14766 *highpc
= std::max (*highpc
, high
);
14769 /* If the language does not allow nested subprograms (either inside
14770 subprograms or lexical blocks), we're done. */
14771 if (cu
->language
!= language_ada
)
14774 /* Check all the children of the given DIE. If it contains nested
14775 subprograms, then check their pc bounds. Likewise, we need to
14776 check lexical blocks as well, as they may also contain subprogram
14778 while (child
&& child
->tag
)
14780 if (child
->tag
== DW_TAG_subprogram
14781 || child
->tag
== DW_TAG_lexical_block
)
14782 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14783 child
= sibling_die (child
);
14787 /* Get the low and high pc's represented by the scope DIE, and store
14788 them in *LOWPC and *HIGHPC. If the correct values can't be
14789 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14792 get_scope_pc_bounds (struct die_info
*die
,
14793 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14794 struct dwarf2_cu
*cu
)
14796 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14797 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14798 CORE_ADDR current_low
, current_high
;
14800 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14801 >= PC_BOUNDS_RANGES
)
14803 best_low
= current_low
;
14804 best_high
= current_high
;
14808 struct die_info
*child
= die
->child
;
14810 while (child
&& child
->tag
)
14812 switch (child
->tag
) {
14813 case DW_TAG_subprogram
:
14814 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14816 case DW_TAG_namespace
:
14817 case DW_TAG_module
:
14818 /* FIXME: carlton/2004-01-16: Should we do this for
14819 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14820 that current GCC's always emit the DIEs corresponding
14821 to definitions of methods of classes as children of a
14822 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14823 the DIEs giving the declarations, which could be
14824 anywhere). But I don't see any reason why the
14825 standards says that they have to be there. */
14826 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14828 if (current_low
!= ((CORE_ADDR
) -1))
14830 best_low
= std::min (best_low
, current_low
);
14831 best_high
= std::max (best_high
, current_high
);
14839 child
= sibling_die (child
);
14844 *highpc
= best_high
;
14847 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14851 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14852 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14855 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14856 struct attribute
*attr
;
14857 struct attribute
*attr_high
;
14859 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14862 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14863 if (attr
!= nullptr)
14865 CORE_ADDR low
= attr_value_as_address (attr
);
14866 CORE_ADDR high
= attr_value_as_address (attr_high
);
14868 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14871 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14872 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14873 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14877 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14878 if (attr
!= nullptr)
14880 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14881 We take advantage of the fact that DW_AT_ranges does not appear
14882 in DW_TAG_compile_unit of DWO files. */
14883 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14885 /* The value of the DW_AT_ranges attribute is the offset of the
14886 address range list in the .debug_ranges section. */
14887 unsigned long offset
= (DW_UNSND (attr
)
14888 + (need_ranges_base
? cu
->ranges_base
: 0));
14890 std::vector
<blockrange
> blockvec
;
14891 dwarf2_ranges_process (offset
, cu
,
14892 [&] (CORE_ADDR start
, CORE_ADDR end
)
14896 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14897 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14898 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14899 blockvec
.emplace_back (start
, end
);
14902 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14906 /* Check whether the producer field indicates either of GCC < 4.6, or the
14907 Intel C/C++ compiler, and cache the result in CU. */
14910 check_producer (struct dwarf2_cu
*cu
)
14914 if (cu
->producer
== NULL
)
14916 /* For unknown compilers expect their behavior is DWARF version
14919 GCC started to support .debug_types sections by -gdwarf-4 since
14920 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14921 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14922 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14923 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14925 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14927 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14928 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14930 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14932 cu
->producer_is_icc
= true;
14933 cu
->producer_is_icc_lt_14
= major
< 14;
14935 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14936 cu
->producer_is_codewarrior
= true;
14939 /* For other non-GCC compilers, expect their behavior is DWARF version
14943 cu
->checked_producer
= true;
14946 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14947 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14948 during 4.6.0 experimental. */
14951 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14953 if (!cu
->checked_producer
)
14954 check_producer (cu
);
14956 return cu
->producer_is_gxx_lt_4_6
;
14960 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14961 with incorrect is_stmt attributes. */
14964 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14966 if (!cu
->checked_producer
)
14967 check_producer (cu
);
14969 return cu
->producer_is_codewarrior
;
14972 /* Return the default accessibility type if it is not overridden by
14973 DW_AT_accessibility. */
14975 static enum dwarf_access_attribute
14976 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14978 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14980 /* The default DWARF 2 accessibility for members is public, the default
14981 accessibility for inheritance is private. */
14983 if (die
->tag
!= DW_TAG_inheritance
)
14984 return DW_ACCESS_public
;
14986 return DW_ACCESS_private
;
14990 /* DWARF 3+ defines the default accessibility a different way. The same
14991 rules apply now for DW_TAG_inheritance as for the members and it only
14992 depends on the container kind. */
14994 if (die
->parent
->tag
== DW_TAG_class_type
)
14995 return DW_ACCESS_private
;
14997 return DW_ACCESS_public
;
15001 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15002 offset. If the attribute was not found return 0, otherwise return
15003 1. If it was found but could not properly be handled, set *OFFSET
15007 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15010 struct attribute
*attr
;
15012 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15017 /* Note that we do not check for a section offset first here.
15018 This is because DW_AT_data_member_location is new in DWARF 4,
15019 so if we see it, we can assume that a constant form is really
15020 a constant and not a section offset. */
15021 if (attr_form_is_constant (attr
))
15022 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15023 else if (attr_form_is_section_offset (attr
))
15024 dwarf2_complex_location_expr_complaint ();
15025 else if (attr_form_is_block (attr
))
15026 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15028 dwarf2_complex_location_expr_complaint ();
15036 /* Add an aggregate field to the field list. */
15039 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15040 struct dwarf2_cu
*cu
)
15042 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15044 struct nextfield
*new_field
;
15045 struct attribute
*attr
;
15047 const char *fieldname
= "";
15049 if (die
->tag
== DW_TAG_inheritance
)
15051 fip
->baseclasses
.emplace_back ();
15052 new_field
= &fip
->baseclasses
.back ();
15056 fip
->fields
.emplace_back ();
15057 new_field
= &fip
->fields
.back ();
15062 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15063 if (attr
!= nullptr)
15064 new_field
->accessibility
= DW_UNSND (attr
);
15066 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15067 if (new_field
->accessibility
!= DW_ACCESS_public
)
15068 fip
->non_public_fields
= 1;
15070 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15071 if (attr
!= nullptr)
15072 new_field
->virtuality
= DW_UNSND (attr
);
15074 new_field
->virtuality
= DW_VIRTUALITY_none
;
15076 fp
= &new_field
->field
;
15078 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15082 /* Data member other than a C++ static data member. */
15084 /* Get type of field. */
15085 fp
->type
= die_type (die
, cu
);
15087 SET_FIELD_BITPOS (*fp
, 0);
15089 /* Get bit size of field (zero if none). */
15090 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15091 if (attr
!= nullptr)
15093 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15097 FIELD_BITSIZE (*fp
) = 0;
15100 /* Get bit offset of field. */
15101 if (handle_data_member_location (die
, cu
, &offset
))
15102 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15103 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15104 if (attr
!= nullptr)
15106 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15108 /* For big endian bits, the DW_AT_bit_offset gives the
15109 additional bit offset from the MSB of the containing
15110 anonymous object to the MSB of the field. We don't
15111 have to do anything special since we don't need to
15112 know the size of the anonymous object. */
15113 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15117 /* For little endian bits, compute the bit offset to the
15118 MSB of the anonymous object, subtract off the number of
15119 bits from the MSB of the field to the MSB of the
15120 object, and then subtract off the number of bits of
15121 the field itself. The result is the bit offset of
15122 the LSB of the field. */
15123 int anonymous_size
;
15124 int bit_offset
= DW_UNSND (attr
);
15126 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15127 if (attr
!= nullptr)
15129 /* The size of the anonymous object containing
15130 the bit field is explicit, so use the
15131 indicated size (in bytes). */
15132 anonymous_size
= DW_UNSND (attr
);
15136 /* The size of the anonymous object containing
15137 the bit field must be inferred from the type
15138 attribute of the data member containing the
15140 anonymous_size
= TYPE_LENGTH (fp
->type
);
15142 SET_FIELD_BITPOS (*fp
,
15143 (FIELD_BITPOS (*fp
)
15144 + anonymous_size
* bits_per_byte
15145 - bit_offset
- FIELD_BITSIZE (*fp
)));
15148 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15150 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15151 + dwarf2_get_attr_constant_value (attr
, 0)));
15153 /* Get name of field. */
15154 fieldname
= dwarf2_name (die
, cu
);
15155 if (fieldname
== NULL
)
15158 /* The name is already allocated along with this objfile, so we don't
15159 need to duplicate it for the type. */
15160 fp
->name
= fieldname
;
15162 /* Change accessibility for artificial fields (e.g. virtual table
15163 pointer or virtual base class pointer) to private. */
15164 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15166 FIELD_ARTIFICIAL (*fp
) = 1;
15167 new_field
->accessibility
= DW_ACCESS_private
;
15168 fip
->non_public_fields
= 1;
15171 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15173 /* C++ static member. */
15175 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15176 is a declaration, but all versions of G++ as of this writing
15177 (so through at least 3.2.1) incorrectly generate
15178 DW_TAG_variable tags. */
15180 const char *physname
;
15182 /* Get name of field. */
15183 fieldname
= dwarf2_name (die
, cu
);
15184 if (fieldname
== NULL
)
15187 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15189 /* Only create a symbol if this is an external value.
15190 new_symbol checks this and puts the value in the global symbol
15191 table, which we want. If it is not external, new_symbol
15192 will try to put the value in cu->list_in_scope which is wrong. */
15193 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15195 /* A static const member, not much different than an enum as far as
15196 we're concerned, except that we can support more types. */
15197 new_symbol (die
, NULL
, cu
);
15200 /* Get physical name. */
15201 physname
= dwarf2_physname (fieldname
, die
, cu
);
15203 /* The name is already allocated along with this objfile, so we don't
15204 need to duplicate it for the type. */
15205 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15206 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15207 FIELD_NAME (*fp
) = fieldname
;
15209 else if (die
->tag
== DW_TAG_inheritance
)
15213 /* C++ base class field. */
15214 if (handle_data_member_location (die
, cu
, &offset
))
15215 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15216 FIELD_BITSIZE (*fp
) = 0;
15217 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15218 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15220 else if (die
->tag
== DW_TAG_variant_part
)
15222 /* process_structure_scope will treat this DIE as a union. */
15223 process_structure_scope (die
, cu
);
15225 /* The variant part is relative to the start of the enclosing
15227 SET_FIELD_BITPOS (*fp
, 0);
15228 fp
->type
= get_die_type (die
, cu
);
15229 fp
->artificial
= 1;
15230 fp
->name
= "<<variant>>";
15232 /* Normally a DW_TAG_variant_part won't have a size, but our
15233 representation requires one, so set it to the maximum of the
15234 child sizes, being sure to account for the offset at which
15235 each child is seen. */
15236 if (TYPE_LENGTH (fp
->type
) == 0)
15239 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15241 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15242 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15246 TYPE_LENGTH (fp
->type
) = max
;
15250 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15253 /* Can the type given by DIE define another type? */
15256 type_can_define_types (const struct die_info
*die
)
15260 case DW_TAG_typedef
:
15261 case DW_TAG_class_type
:
15262 case DW_TAG_structure_type
:
15263 case DW_TAG_union_type
:
15264 case DW_TAG_enumeration_type
:
15272 /* Add a type definition defined in the scope of the FIP's class. */
15275 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15276 struct dwarf2_cu
*cu
)
15278 struct decl_field fp
;
15279 memset (&fp
, 0, sizeof (fp
));
15281 gdb_assert (type_can_define_types (die
));
15283 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15284 fp
.name
= dwarf2_name (die
, cu
);
15285 fp
.type
= read_type_die (die
, cu
);
15287 /* Save accessibility. */
15288 enum dwarf_access_attribute accessibility
;
15289 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15291 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15293 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15294 switch (accessibility
)
15296 case DW_ACCESS_public
:
15297 /* The assumed value if neither private nor protected. */
15299 case DW_ACCESS_private
:
15302 case DW_ACCESS_protected
:
15303 fp
.is_protected
= 1;
15306 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15309 if (die
->tag
== DW_TAG_typedef
)
15310 fip
->typedef_field_list
.push_back (fp
);
15312 fip
->nested_types_list
.push_back (fp
);
15315 /* Create the vector of fields, and attach it to the type. */
15318 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15319 struct dwarf2_cu
*cu
)
15321 int nfields
= fip
->nfields
;
15323 /* Record the field count, allocate space for the array of fields,
15324 and create blank accessibility bitfields if necessary. */
15325 TYPE_NFIELDS (type
) = nfields
;
15326 TYPE_FIELDS (type
) = (struct field
*)
15327 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15329 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15331 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15333 TYPE_FIELD_PRIVATE_BITS (type
) =
15334 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15335 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15337 TYPE_FIELD_PROTECTED_BITS (type
) =
15338 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15339 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15341 TYPE_FIELD_IGNORE_BITS (type
) =
15342 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15343 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15346 /* If the type has baseclasses, allocate and clear a bit vector for
15347 TYPE_FIELD_VIRTUAL_BITS. */
15348 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15350 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15351 unsigned char *pointer
;
15353 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15354 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15355 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15356 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15357 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15360 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15362 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15364 for (int index
= 0; index
< nfields
; ++index
)
15366 struct nextfield
&field
= fip
->fields
[index
];
15368 if (field
.variant
.is_discriminant
)
15369 di
->discriminant_index
= index
;
15370 else if (field
.variant
.default_branch
)
15371 di
->default_index
= index
;
15373 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15377 /* Copy the saved-up fields into the field vector. */
15378 for (int i
= 0; i
< nfields
; ++i
)
15380 struct nextfield
&field
15381 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15382 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15384 TYPE_FIELD (type
, i
) = field
.field
;
15385 switch (field
.accessibility
)
15387 case DW_ACCESS_private
:
15388 if (cu
->language
!= language_ada
)
15389 SET_TYPE_FIELD_PRIVATE (type
, i
);
15392 case DW_ACCESS_protected
:
15393 if (cu
->language
!= language_ada
)
15394 SET_TYPE_FIELD_PROTECTED (type
, i
);
15397 case DW_ACCESS_public
:
15401 /* Unknown accessibility. Complain and treat it as public. */
15403 complaint (_("unsupported accessibility %d"),
15404 field
.accessibility
);
15408 if (i
< fip
->baseclasses
.size ())
15410 switch (field
.virtuality
)
15412 case DW_VIRTUALITY_virtual
:
15413 case DW_VIRTUALITY_pure_virtual
:
15414 if (cu
->language
== language_ada
)
15415 error (_("unexpected virtuality in component of Ada type"));
15416 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15423 /* Return true if this member function is a constructor, false
15427 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15429 const char *fieldname
;
15430 const char *type_name
;
15433 if (die
->parent
== NULL
)
15436 if (die
->parent
->tag
!= DW_TAG_structure_type
15437 && die
->parent
->tag
!= DW_TAG_union_type
15438 && die
->parent
->tag
!= DW_TAG_class_type
)
15441 fieldname
= dwarf2_name (die
, cu
);
15442 type_name
= dwarf2_name (die
->parent
, cu
);
15443 if (fieldname
== NULL
|| type_name
== NULL
)
15446 len
= strlen (fieldname
);
15447 return (strncmp (fieldname
, type_name
, len
) == 0
15448 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15451 /* Check if the given VALUE is a recognized enum
15452 dwarf_defaulted_attribute constant according to DWARF5 spec,
15456 is_valid_DW_AT_defaulted (ULONGEST value
)
15460 case DW_DEFAULTED_no
:
15461 case DW_DEFAULTED_in_class
:
15462 case DW_DEFAULTED_out_of_class
:
15466 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15470 /* Add a member function to the proper fieldlist. */
15473 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15474 struct type
*type
, struct dwarf2_cu
*cu
)
15476 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15477 struct attribute
*attr
;
15479 struct fnfieldlist
*flp
= nullptr;
15480 struct fn_field
*fnp
;
15481 const char *fieldname
;
15482 struct type
*this_type
;
15483 enum dwarf_access_attribute accessibility
;
15485 if (cu
->language
== language_ada
)
15486 error (_("unexpected member function in Ada type"));
15488 /* Get name of member function. */
15489 fieldname
= dwarf2_name (die
, cu
);
15490 if (fieldname
== NULL
)
15493 /* Look up member function name in fieldlist. */
15494 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15496 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15498 flp
= &fip
->fnfieldlists
[i
];
15503 /* Create a new fnfieldlist if necessary. */
15504 if (flp
== nullptr)
15506 fip
->fnfieldlists
.emplace_back ();
15507 flp
= &fip
->fnfieldlists
.back ();
15508 flp
->name
= fieldname
;
15509 i
= fip
->fnfieldlists
.size () - 1;
15512 /* Create a new member function field and add it to the vector of
15514 flp
->fnfields
.emplace_back ();
15515 fnp
= &flp
->fnfields
.back ();
15517 /* Delay processing of the physname until later. */
15518 if (cu
->language
== language_cplus
)
15519 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15523 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15524 fnp
->physname
= physname
? physname
: "";
15527 fnp
->type
= alloc_type (objfile
);
15528 this_type
= read_type_die (die
, cu
);
15529 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15531 int nparams
= TYPE_NFIELDS (this_type
);
15533 /* TYPE is the domain of this method, and THIS_TYPE is the type
15534 of the method itself (TYPE_CODE_METHOD). */
15535 smash_to_method_type (fnp
->type
, type
,
15536 TYPE_TARGET_TYPE (this_type
),
15537 TYPE_FIELDS (this_type
),
15538 TYPE_NFIELDS (this_type
),
15539 TYPE_VARARGS (this_type
));
15541 /* Handle static member functions.
15542 Dwarf2 has no clean way to discern C++ static and non-static
15543 member functions. G++ helps GDB by marking the first
15544 parameter for non-static member functions (which is the this
15545 pointer) as artificial. We obtain this information from
15546 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15547 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15548 fnp
->voffset
= VOFFSET_STATIC
;
15551 complaint (_("member function type missing for '%s'"),
15552 dwarf2_full_name (fieldname
, die
, cu
));
15554 /* Get fcontext from DW_AT_containing_type if present. */
15555 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15556 fnp
->fcontext
= die_containing_type (die
, cu
);
15558 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15559 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15561 /* Get accessibility. */
15562 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15563 if (attr
!= nullptr)
15564 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15566 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15567 switch (accessibility
)
15569 case DW_ACCESS_private
:
15570 fnp
->is_private
= 1;
15572 case DW_ACCESS_protected
:
15573 fnp
->is_protected
= 1;
15577 /* Check for artificial methods. */
15578 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15579 if (attr
&& DW_UNSND (attr
) != 0)
15580 fnp
->is_artificial
= 1;
15582 /* Check for defaulted methods. */
15583 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15584 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15585 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15587 /* Check for deleted methods. */
15588 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15589 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15590 fnp
->is_deleted
= 1;
15592 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15594 /* Get index in virtual function table if it is a virtual member
15595 function. For older versions of GCC, this is an offset in the
15596 appropriate virtual table, as specified by DW_AT_containing_type.
15597 For everyone else, it is an expression to be evaluated relative
15598 to the object address. */
15600 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15601 if (attr
!= nullptr)
15603 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15605 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15607 /* Old-style GCC. */
15608 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15610 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15611 || (DW_BLOCK (attr
)->size
> 1
15612 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15613 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15615 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15616 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15617 dwarf2_complex_location_expr_complaint ();
15619 fnp
->voffset
/= cu
->header
.addr_size
;
15623 dwarf2_complex_location_expr_complaint ();
15625 if (!fnp
->fcontext
)
15627 /* If there is no `this' field and no DW_AT_containing_type,
15628 we cannot actually find a base class context for the
15630 if (TYPE_NFIELDS (this_type
) == 0
15631 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15633 complaint (_("cannot determine context for virtual member "
15634 "function \"%s\" (offset %s)"),
15635 fieldname
, sect_offset_str (die
->sect_off
));
15640 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15644 else if (attr_form_is_section_offset (attr
))
15646 dwarf2_complex_location_expr_complaint ();
15650 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15656 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15657 if (attr
&& DW_UNSND (attr
))
15659 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15660 complaint (_("Member function \"%s\" (offset %s) is virtual "
15661 "but the vtable offset is not specified"),
15662 fieldname
, sect_offset_str (die
->sect_off
));
15663 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15664 TYPE_CPLUS_DYNAMIC (type
) = 1;
15669 /* Create the vector of member function fields, and attach it to the type. */
15672 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15673 struct dwarf2_cu
*cu
)
15675 if (cu
->language
== language_ada
)
15676 error (_("unexpected member functions in Ada type"));
15678 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15679 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15681 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15683 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15685 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15686 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15688 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15689 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15690 fn_flp
->fn_fields
= (struct fn_field
*)
15691 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15693 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15694 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15697 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15700 /* Returns non-zero if NAME is the name of a vtable member in CU's
15701 language, zero otherwise. */
15703 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15705 static const char vptr
[] = "_vptr";
15707 /* Look for the C++ form of the vtable. */
15708 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15714 /* GCC outputs unnamed structures that are really pointers to member
15715 functions, with the ABI-specified layout. If TYPE describes
15716 such a structure, smash it into a member function type.
15718 GCC shouldn't do this; it should just output pointer to member DIEs.
15719 This is GCC PR debug/28767. */
15722 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15724 struct type
*pfn_type
, *self_type
, *new_type
;
15726 /* Check for a structure with no name and two children. */
15727 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15730 /* Check for __pfn and __delta members. */
15731 if (TYPE_FIELD_NAME (type
, 0) == NULL
15732 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15733 || TYPE_FIELD_NAME (type
, 1) == NULL
15734 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15737 /* Find the type of the method. */
15738 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15739 if (pfn_type
== NULL
15740 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15741 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15744 /* Look for the "this" argument. */
15745 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15746 if (TYPE_NFIELDS (pfn_type
) == 0
15747 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15748 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15751 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15752 new_type
= alloc_type (objfile
);
15753 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15754 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15755 TYPE_VARARGS (pfn_type
));
15756 smash_to_methodptr_type (type
, new_type
);
15759 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15760 appropriate error checking and issuing complaints if there is a
15764 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15766 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15768 if (attr
== nullptr)
15771 if (!attr_form_is_constant (attr
))
15773 complaint (_("DW_AT_alignment must have constant form"
15774 " - DIE at %s [in module %s]"),
15775 sect_offset_str (die
->sect_off
),
15776 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15781 if (attr
->form
== DW_FORM_sdata
)
15783 LONGEST val
= DW_SND (attr
);
15786 complaint (_("DW_AT_alignment value must not be negative"
15787 " - DIE at %s [in module %s]"),
15788 sect_offset_str (die
->sect_off
),
15789 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15795 align
= DW_UNSND (attr
);
15799 complaint (_("DW_AT_alignment value must not be zero"
15800 " - DIE at %s [in module %s]"),
15801 sect_offset_str (die
->sect_off
),
15802 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15805 if ((align
& (align
- 1)) != 0)
15807 complaint (_("DW_AT_alignment value must be a power of 2"
15808 " - DIE at %s [in module %s]"),
15809 sect_offset_str (die
->sect_off
),
15810 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15817 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15818 the alignment for TYPE. */
15821 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15824 if (!set_type_align (type
, get_alignment (cu
, die
)))
15825 complaint (_("DW_AT_alignment value too large"
15826 " - DIE at %s [in module %s]"),
15827 sect_offset_str (die
->sect_off
),
15828 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15831 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15832 constant for a type, according to DWARF5 spec, Table 5.5. */
15835 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15840 case DW_CC_pass_by_reference
:
15841 case DW_CC_pass_by_value
:
15845 complaint (_("unrecognized DW_AT_calling_convention value "
15846 "(%s) for a type"), pulongest (value
));
15851 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15852 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15853 also according to GNU-specific values (see include/dwarf2.h). */
15856 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15861 case DW_CC_program
:
15865 case DW_CC_GNU_renesas_sh
:
15866 case DW_CC_GNU_borland_fastcall_i386
:
15867 case DW_CC_GDB_IBM_OpenCL
:
15871 complaint (_("unrecognized DW_AT_calling_convention value "
15872 "(%s) for a subroutine"), pulongest (value
));
15877 /* Called when we find the DIE that starts a structure or union scope
15878 (definition) to create a type for the structure or union. Fill in
15879 the type's name and general properties; the members will not be
15880 processed until process_structure_scope. A symbol table entry for
15881 the type will also not be done until process_structure_scope (assuming
15882 the type has a name).
15884 NOTE: we need to call these functions regardless of whether or not the
15885 DIE has a DW_AT_name attribute, since it might be an anonymous
15886 structure or union. This gets the type entered into our set of
15887 user defined types. */
15889 static struct type
*
15890 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15894 struct attribute
*attr
;
15897 /* If the definition of this type lives in .debug_types, read that type.
15898 Don't follow DW_AT_specification though, that will take us back up
15899 the chain and we want to go down. */
15900 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15901 if (attr
!= nullptr)
15903 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15905 /* The type's CU may not be the same as CU.
15906 Ensure TYPE is recorded with CU in die_type_hash. */
15907 return set_die_type (die
, type
, cu
);
15910 type
= alloc_type (objfile
);
15911 INIT_CPLUS_SPECIFIC (type
);
15913 name
= dwarf2_name (die
, cu
);
15916 if (cu
->language
== language_cplus
15917 || cu
->language
== language_d
15918 || cu
->language
== language_rust
)
15920 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15922 /* dwarf2_full_name might have already finished building the DIE's
15923 type. If so, there is no need to continue. */
15924 if (get_die_type (die
, cu
) != NULL
)
15925 return get_die_type (die
, cu
);
15927 TYPE_NAME (type
) = full_name
;
15931 /* The name is already allocated along with this objfile, so
15932 we don't need to duplicate it for the type. */
15933 TYPE_NAME (type
) = name
;
15937 if (die
->tag
== DW_TAG_structure_type
)
15939 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15941 else if (die
->tag
== DW_TAG_union_type
)
15943 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15945 else if (die
->tag
== DW_TAG_variant_part
)
15947 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15948 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15952 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15955 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15956 TYPE_DECLARED_CLASS (type
) = 1;
15958 /* Store the calling convention in the type if it's available in
15959 the die. Otherwise the calling convention remains set to
15960 the default value DW_CC_normal. */
15961 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15962 if (attr
!= nullptr
15963 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15965 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15966 TYPE_CPLUS_CALLING_CONVENTION (type
)
15967 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15970 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15971 if (attr
!= nullptr)
15973 if (attr_form_is_constant (attr
))
15974 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15977 /* For the moment, dynamic type sizes are not supported
15978 by GDB's struct type. The actual size is determined
15979 on-demand when resolving the type of a given object,
15980 so set the type's length to zero for now. Otherwise,
15981 we record an expression as the length, and that expression
15982 could lead to a very large value, which could eventually
15983 lead to us trying to allocate that much memory when creating
15984 a value of that type. */
15985 TYPE_LENGTH (type
) = 0;
15990 TYPE_LENGTH (type
) = 0;
15993 maybe_set_alignment (cu
, die
, type
);
15995 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15997 /* ICC<14 does not output the required DW_AT_declaration on
15998 incomplete types, but gives them a size of zero. */
15999 TYPE_STUB (type
) = 1;
16002 TYPE_STUB_SUPPORTED (type
) = 1;
16004 if (die_is_declaration (die
, cu
))
16005 TYPE_STUB (type
) = 1;
16006 else if (attr
== NULL
&& die
->child
== NULL
16007 && producer_is_realview (cu
->producer
))
16008 /* RealView does not output the required DW_AT_declaration
16009 on incomplete types. */
16010 TYPE_STUB (type
) = 1;
16012 /* We need to add the type field to the die immediately so we don't
16013 infinitely recurse when dealing with pointers to the structure
16014 type within the structure itself. */
16015 set_die_type (die
, type
, cu
);
16017 /* set_die_type should be already done. */
16018 set_descriptive_type (type
, die
, cu
);
16023 /* A helper for process_structure_scope that handles a single member
16027 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16028 struct field_info
*fi
,
16029 std::vector
<struct symbol
*> *template_args
,
16030 struct dwarf2_cu
*cu
)
16032 if (child_die
->tag
== DW_TAG_member
16033 || child_die
->tag
== DW_TAG_variable
16034 || child_die
->tag
== DW_TAG_variant_part
)
16036 /* NOTE: carlton/2002-11-05: A C++ static data member
16037 should be a DW_TAG_member that is a declaration, but
16038 all versions of G++ as of this writing (so through at
16039 least 3.2.1) incorrectly generate DW_TAG_variable
16040 tags for them instead. */
16041 dwarf2_add_field (fi
, child_die
, cu
);
16043 else if (child_die
->tag
== DW_TAG_subprogram
)
16045 /* Rust doesn't have member functions in the C++ sense.
16046 However, it does emit ordinary functions as children
16047 of a struct DIE. */
16048 if (cu
->language
== language_rust
)
16049 read_func_scope (child_die
, cu
);
16052 /* C++ member function. */
16053 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16056 else if (child_die
->tag
== DW_TAG_inheritance
)
16058 /* C++ base class field. */
16059 dwarf2_add_field (fi
, child_die
, cu
);
16061 else if (type_can_define_types (child_die
))
16062 dwarf2_add_type_defn (fi
, child_die
, cu
);
16063 else if (child_die
->tag
== DW_TAG_template_type_param
16064 || child_die
->tag
== DW_TAG_template_value_param
)
16066 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16069 template_args
->push_back (arg
);
16071 else if (child_die
->tag
== DW_TAG_variant
)
16073 /* In a variant we want to get the discriminant and also add a
16074 field for our sole member child. */
16075 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16077 for (die_info
*variant_child
= child_die
->child
;
16078 variant_child
!= NULL
;
16079 variant_child
= sibling_die (variant_child
))
16081 if (variant_child
->tag
== DW_TAG_member
)
16083 handle_struct_member_die (variant_child
, type
, fi
,
16084 template_args
, cu
);
16085 /* Only handle the one. */
16090 /* We don't handle this but we might as well report it if we see
16092 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16093 complaint (_("DW_AT_discr_list is not supported yet"
16094 " - DIE at %s [in module %s]"),
16095 sect_offset_str (child_die
->sect_off
),
16096 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16098 /* The first field was just added, so we can stash the
16099 discriminant there. */
16100 gdb_assert (!fi
->fields
.empty ());
16102 fi
->fields
.back ().variant
.default_branch
= true;
16104 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16108 /* Finish creating a structure or union type, including filling in
16109 its members and creating a symbol for it. */
16112 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16114 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16115 struct die_info
*child_die
;
16118 type
= get_die_type (die
, cu
);
16120 type
= read_structure_type (die
, cu
);
16122 /* When reading a DW_TAG_variant_part, we need to notice when we
16123 read the discriminant member, so we can record it later in the
16124 discriminant_info. */
16125 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16126 sect_offset discr_offset
{};
16127 bool has_template_parameters
= false;
16129 if (is_variant_part
)
16131 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16134 /* Maybe it's a univariant form, an extension we support.
16135 In this case arrange not to check the offset. */
16136 is_variant_part
= false;
16138 else if (attr_form_is_ref (discr
))
16140 struct dwarf2_cu
*target_cu
= cu
;
16141 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16143 discr_offset
= target_die
->sect_off
;
16147 complaint (_("DW_AT_discr does not have DIE reference form"
16148 " - DIE at %s [in module %s]"),
16149 sect_offset_str (die
->sect_off
),
16150 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16151 is_variant_part
= false;
16155 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16157 struct field_info fi
;
16158 std::vector
<struct symbol
*> template_args
;
16160 child_die
= die
->child
;
16162 while (child_die
&& child_die
->tag
)
16164 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16166 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16167 fi
.fields
.back ().variant
.is_discriminant
= true;
16169 child_die
= sibling_die (child_die
);
16172 /* Attach template arguments to type. */
16173 if (!template_args
.empty ())
16175 has_template_parameters
= true;
16176 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16177 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16178 TYPE_TEMPLATE_ARGUMENTS (type
)
16179 = XOBNEWVEC (&objfile
->objfile_obstack
,
16181 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16182 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16183 template_args
.data (),
16184 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16185 * sizeof (struct symbol
*)));
16188 /* Attach fields and member functions to the type. */
16190 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16191 if (!fi
.fnfieldlists
.empty ())
16193 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16195 /* Get the type which refers to the base class (possibly this
16196 class itself) which contains the vtable pointer for the current
16197 class from the DW_AT_containing_type attribute. This use of
16198 DW_AT_containing_type is a GNU extension. */
16200 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16202 struct type
*t
= die_containing_type (die
, cu
);
16204 set_type_vptr_basetype (type
, t
);
16209 /* Our own class provides vtbl ptr. */
16210 for (i
= TYPE_NFIELDS (t
) - 1;
16211 i
>= TYPE_N_BASECLASSES (t
);
16214 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16216 if (is_vtable_name (fieldname
, cu
))
16218 set_type_vptr_fieldno (type
, i
);
16223 /* Complain if virtual function table field not found. */
16224 if (i
< TYPE_N_BASECLASSES (t
))
16225 complaint (_("virtual function table pointer "
16226 "not found when defining class '%s'"),
16227 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16231 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16234 else if (cu
->producer
16235 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16237 /* The IBM XLC compiler does not provide direct indication
16238 of the containing type, but the vtable pointer is
16239 always named __vfp. */
16243 for (i
= TYPE_NFIELDS (type
) - 1;
16244 i
>= TYPE_N_BASECLASSES (type
);
16247 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16249 set_type_vptr_fieldno (type
, i
);
16250 set_type_vptr_basetype (type
, type
);
16257 /* Copy fi.typedef_field_list linked list elements content into the
16258 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16259 if (!fi
.typedef_field_list
.empty ())
16261 int count
= fi
.typedef_field_list
.size ();
16263 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16264 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16265 = ((struct decl_field
*)
16267 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16268 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16270 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16271 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16274 /* Copy fi.nested_types_list linked list elements content into the
16275 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16276 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16278 int count
= fi
.nested_types_list
.size ();
16280 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16281 TYPE_NESTED_TYPES_ARRAY (type
)
16282 = ((struct decl_field
*)
16283 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16284 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16286 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16287 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16291 quirk_gcc_member_function_pointer (type
, objfile
);
16292 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16293 cu
->rust_unions
.push_back (type
);
16295 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16296 snapshots) has been known to create a die giving a declaration
16297 for a class that has, as a child, a die giving a definition for a
16298 nested class. So we have to process our children even if the
16299 current die is a declaration. Normally, of course, a declaration
16300 won't have any children at all. */
16302 child_die
= die
->child
;
16304 while (child_die
!= NULL
&& child_die
->tag
)
16306 if (child_die
->tag
== DW_TAG_member
16307 || child_die
->tag
== DW_TAG_variable
16308 || child_die
->tag
== DW_TAG_inheritance
16309 || child_die
->tag
== DW_TAG_template_value_param
16310 || child_die
->tag
== DW_TAG_template_type_param
)
16315 process_die (child_die
, cu
);
16317 child_die
= sibling_die (child_die
);
16320 /* Do not consider external references. According to the DWARF standard,
16321 these DIEs are identified by the fact that they have no byte_size
16322 attribute, and a declaration attribute. */
16323 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16324 || !die_is_declaration (die
, cu
))
16326 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16328 if (has_template_parameters
)
16330 struct symtab
*symtab
;
16331 if (sym
!= nullptr)
16332 symtab
= symbol_symtab (sym
);
16333 else if (cu
->line_header
!= nullptr)
16335 /* Any related symtab will do. */
16337 = cu
->line_header
->file_names ()[0].symtab
;
16342 complaint (_("could not find suitable "
16343 "symtab for template parameter"
16344 " - DIE at %s [in module %s]"),
16345 sect_offset_str (die
->sect_off
),
16346 objfile_name (objfile
));
16349 if (symtab
!= nullptr)
16351 /* Make sure that the symtab is set on the new symbols.
16352 Even though they don't appear in this symtab directly,
16353 other parts of gdb assume that symbols do, and this is
16354 reasonably true. */
16355 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16356 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16362 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16363 update TYPE using some information only available in DIE's children. */
16366 update_enumeration_type_from_children (struct die_info
*die
,
16368 struct dwarf2_cu
*cu
)
16370 struct die_info
*child_die
;
16371 int unsigned_enum
= 1;
16375 auto_obstack obstack
;
16377 for (child_die
= die
->child
;
16378 child_die
!= NULL
&& child_die
->tag
;
16379 child_die
= sibling_die (child_die
))
16381 struct attribute
*attr
;
16383 const gdb_byte
*bytes
;
16384 struct dwarf2_locexpr_baton
*baton
;
16387 if (child_die
->tag
!= DW_TAG_enumerator
)
16390 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16394 name
= dwarf2_name (child_die
, cu
);
16396 name
= "<anonymous enumerator>";
16398 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16399 &value
, &bytes
, &baton
);
16405 else if ((mask
& value
) != 0)
16410 /* If we already know that the enum type is neither unsigned, nor
16411 a flag type, no need to look at the rest of the enumerates. */
16412 if (!unsigned_enum
&& !flag_enum
)
16417 TYPE_UNSIGNED (type
) = 1;
16419 TYPE_FLAG_ENUM (type
) = 1;
16422 /* Given a DW_AT_enumeration_type die, set its type. We do not
16423 complete the type's fields yet, or create any symbols. */
16425 static struct type
*
16426 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16428 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16430 struct attribute
*attr
;
16433 /* If the definition of this type lives in .debug_types, read that type.
16434 Don't follow DW_AT_specification though, that will take us back up
16435 the chain and we want to go down. */
16436 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16437 if (attr
!= nullptr)
16439 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16441 /* The type's CU may not be the same as CU.
16442 Ensure TYPE is recorded with CU in die_type_hash. */
16443 return set_die_type (die
, type
, cu
);
16446 type
= alloc_type (objfile
);
16448 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16449 name
= dwarf2_full_name (NULL
, die
, cu
);
16451 TYPE_NAME (type
) = name
;
16453 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16456 struct type
*underlying_type
= die_type (die
, cu
);
16458 TYPE_TARGET_TYPE (type
) = underlying_type
;
16461 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16462 if (attr
!= nullptr)
16464 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16468 TYPE_LENGTH (type
) = 0;
16471 maybe_set_alignment (cu
, die
, type
);
16473 /* The enumeration DIE can be incomplete. In Ada, any type can be
16474 declared as private in the package spec, and then defined only
16475 inside the package body. Such types are known as Taft Amendment
16476 Types. When another package uses such a type, an incomplete DIE
16477 may be generated by the compiler. */
16478 if (die_is_declaration (die
, cu
))
16479 TYPE_STUB (type
) = 1;
16481 /* Finish the creation of this type by using the enum's children.
16482 We must call this even when the underlying type has been provided
16483 so that we can determine if we're looking at a "flag" enum. */
16484 update_enumeration_type_from_children (die
, type
, cu
);
16486 /* If this type has an underlying type that is not a stub, then we
16487 may use its attributes. We always use the "unsigned" attribute
16488 in this situation, because ordinarily we guess whether the type
16489 is unsigned -- but the guess can be wrong and the underlying type
16490 can tell us the reality. However, we defer to a local size
16491 attribute if one exists, because this lets the compiler override
16492 the underlying type if needed. */
16493 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16495 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16496 if (TYPE_LENGTH (type
) == 0)
16497 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16498 if (TYPE_RAW_ALIGN (type
) == 0
16499 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16500 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16503 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16505 return set_die_type (die
, type
, cu
);
16508 /* Given a pointer to a die which begins an enumeration, process all
16509 the dies that define the members of the enumeration, and create the
16510 symbol for the enumeration type.
16512 NOTE: We reverse the order of the element list. */
16515 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16517 struct type
*this_type
;
16519 this_type
= get_die_type (die
, cu
);
16520 if (this_type
== NULL
)
16521 this_type
= read_enumeration_type (die
, cu
);
16523 if (die
->child
!= NULL
)
16525 struct die_info
*child_die
;
16526 struct symbol
*sym
;
16527 std::vector
<struct field
> fields
;
16530 child_die
= die
->child
;
16531 while (child_die
&& child_die
->tag
)
16533 if (child_die
->tag
!= DW_TAG_enumerator
)
16535 process_die (child_die
, cu
);
16539 name
= dwarf2_name (child_die
, cu
);
16542 sym
= new_symbol (child_die
, this_type
, cu
);
16544 fields
.emplace_back ();
16545 struct field
&field
= fields
.back ();
16547 FIELD_NAME (field
) = sym
->linkage_name ();
16548 FIELD_TYPE (field
) = NULL
;
16549 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16550 FIELD_BITSIZE (field
) = 0;
16554 child_die
= sibling_die (child_die
);
16557 if (!fields
.empty ())
16559 TYPE_NFIELDS (this_type
) = fields
.size ();
16560 TYPE_FIELDS (this_type
) = (struct field
*)
16561 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16562 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16563 sizeof (struct field
) * fields
.size ());
16567 /* If we are reading an enum from a .debug_types unit, and the enum
16568 is a declaration, and the enum is not the signatured type in the
16569 unit, then we do not want to add a symbol for it. Adding a
16570 symbol would in some cases obscure the true definition of the
16571 enum, giving users an incomplete type when the definition is
16572 actually available. Note that we do not want to do this for all
16573 enums which are just declarations, because C++0x allows forward
16574 enum declarations. */
16575 if (cu
->per_cu
->is_debug_types
16576 && die_is_declaration (die
, cu
))
16578 struct signatured_type
*sig_type
;
16580 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16581 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16582 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16586 new_symbol (die
, this_type
, cu
);
16589 /* Extract all information from a DW_TAG_array_type DIE and put it in
16590 the DIE's type field. For now, this only handles one dimensional
16593 static struct type
*
16594 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16596 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16597 struct die_info
*child_die
;
16599 struct type
*element_type
, *range_type
, *index_type
;
16600 struct attribute
*attr
;
16602 struct dynamic_prop
*byte_stride_prop
= NULL
;
16603 unsigned int bit_stride
= 0;
16605 element_type
= die_type (die
, cu
);
16607 /* The die_type call above may have already set the type for this DIE. */
16608 type
= get_die_type (die
, cu
);
16612 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16616 struct type
*prop_type
16617 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16620 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16621 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16625 complaint (_("unable to read array DW_AT_byte_stride "
16626 " - DIE at %s [in module %s]"),
16627 sect_offset_str (die
->sect_off
),
16628 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16629 /* Ignore this attribute. We will likely not be able to print
16630 arrays of this type correctly, but there is little we can do
16631 to help if we cannot read the attribute's value. */
16632 byte_stride_prop
= NULL
;
16636 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16638 bit_stride
= DW_UNSND (attr
);
16640 /* Irix 6.2 native cc creates array types without children for
16641 arrays with unspecified length. */
16642 if (die
->child
== NULL
)
16644 index_type
= objfile_type (objfile
)->builtin_int
;
16645 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16646 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16647 byte_stride_prop
, bit_stride
);
16648 return set_die_type (die
, type
, cu
);
16651 std::vector
<struct type
*> range_types
;
16652 child_die
= die
->child
;
16653 while (child_die
&& child_die
->tag
)
16655 if (child_die
->tag
== DW_TAG_subrange_type
)
16657 struct type
*child_type
= read_type_die (child_die
, cu
);
16659 if (child_type
!= NULL
)
16661 /* The range type was succesfully read. Save it for the
16662 array type creation. */
16663 range_types
.push_back (child_type
);
16666 child_die
= sibling_die (child_die
);
16669 /* Dwarf2 dimensions are output from left to right, create the
16670 necessary array types in backwards order. */
16672 type
= element_type
;
16674 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16678 while (i
< range_types
.size ())
16679 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16680 byte_stride_prop
, bit_stride
);
16684 size_t ndim
= range_types
.size ();
16686 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16687 byte_stride_prop
, bit_stride
);
16690 /* Understand Dwarf2 support for vector types (like they occur on
16691 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16692 array type. This is not part of the Dwarf2/3 standard yet, but a
16693 custom vendor extension. The main difference between a regular
16694 array and the vector variant is that vectors are passed by value
16696 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16697 if (attr
!= nullptr)
16698 make_vector_type (type
);
16700 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16701 implementation may choose to implement triple vectors using this
16703 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16704 if (attr
!= nullptr)
16706 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16707 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16709 complaint (_("DW_AT_byte_size for array type smaller "
16710 "than the total size of elements"));
16713 name
= dwarf2_name (die
, cu
);
16715 TYPE_NAME (type
) = name
;
16717 maybe_set_alignment (cu
, die
, type
);
16719 /* Install the type in the die. */
16720 set_die_type (die
, type
, cu
);
16722 /* set_die_type should be already done. */
16723 set_descriptive_type (type
, die
, cu
);
16728 static enum dwarf_array_dim_ordering
16729 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16731 struct attribute
*attr
;
16733 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16735 if (attr
!= nullptr)
16736 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16738 /* GNU F77 is a special case, as at 08/2004 array type info is the
16739 opposite order to the dwarf2 specification, but data is still
16740 laid out as per normal fortran.
16742 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16743 version checking. */
16745 if (cu
->language
== language_fortran
16746 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16748 return DW_ORD_row_major
;
16751 switch (cu
->language_defn
->la_array_ordering
)
16753 case array_column_major
:
16754 return DW_ORD_col_major
;
16755 case array_row_major
:
16757 return DW_ORD_row_major
;
16761 /* Extract all information from a DW_TAG_set_type DIE and put it in
16762 the DIE's type field. */
16764 static struct type
*
16765 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16767 struct type
*domain_type
, *set_type
;
16768 struct attribute
*attr
;
16770 domain_type
= die_type (die
, cu
);
16772 /* The die_type call above may have already set the type for this DIE. */
16773 set_type
= get_die_type (die
, cu
);
16777 set_type
= create_set_type (NULL
, domain_type
);
16779 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16780 if (attr
!= nullptr)
16781 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16783 maybe_set_alignment (cu
, die
, set_type
);
16785 return set_die_type (die
, set_type
, cu
);
16788 /* A helper for read_common_block that creates a locexpr baton.
16789 SYM is the symbol which we are marking as computed.
16790 COMMON_DIE is the DIE for the common block.
16791 COMMON_LOC is the location expression attribute for the common
16793 MEMBER_LOC is the location expression attribute for the particular
16794 member of the common block that we are processing.
16795 CU is the CU from which the above come. */
16798 mark_common_block_symbol_computed (struct symbol
*sym
,
16799 struct die_info
*common_die
,
16800 struct attribute
*common_loc
,
16801 struct attribute
*member_loc
,
16802 struct dwarf2_cu
*cu
)
16804 struct dwarf2_per_objfile
*dwarf2_per_objfile
16805 = cu
->per_cu
->dwarf2_per_objfile
;
16806 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16807 struct dwarf2_locexpr_baton
*baton
;
16809 unsigned int cu_off
;
16810 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16811 LONGEST offset
= 0;
16813 gdb_assert (common_loc
&& member_loc
);
16814 gdb_assert (attr_form_is_block (common_loc
));
16815 gdb_assert (attr_form_is_block (member_loc
)
16816 || attr_form_is_constant (member_loc
));
16818 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16819 baton
->per_cu
= cu
->per_cu
;
16820 gdb_assert (baton
->per_cu
);
16822 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16824 if (attr_form_is_constant (member_loc
))
16826 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16827 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16830 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16832 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16835 *ptr
++ = DW_OP_call4
;
16836 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16837 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16840 if (attr_form_is_constant (member_loc
))
16842 *ptr
++ = DW_OP_addr
;
16843 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16844 ptr
+= cu
->header
.addr_size
;
16848 /* We have to copy the data here, because DW_OP_call4 will only
16849 use a DW_AT_location attribute. */
16850 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16851 ptr
+= DW_BLOCK (member_loc
)->size
;
16854 *ptr
++ = DW_OP_plus
;
16855 gdb_assert (ptr
- baton
->data
== baton
->size
);
16857 SYMBOL_LOCATION_BATON (sym
) = baton
;
16858 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16861 /* Create appropriate locally-scoped variables for all the
16862 DW_TAG_common_block entries. Also create a struct common_block
16863 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16864 is used to separate the common blocks name namespace from regular
16868 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16870 struct attribute
*attr
;
16872 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16873 if (attr
!= nullptr)
16875 /* Support the .debug_loc offsets. */
16876 if (attr_form_is_block (attr
))
16880 else if (attr_form_is_section_offset (attr
))
16882 dwarf2_complex_location_expr_complaint ();
16887 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16888 "common block member");
16893 if (die
->child
!= NULL
)
16895 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16896 struct die_info
*child_die
;
16897 size_t n_entries
= 0, size
;
16898 struct common_block
*common_block
;
16899 struct symbol
*sym
;
16901 for (child_die
= die
->child
;
16902 child_die
&& child_die
->tag
;
16903 child_die
= sibling_die (child_die
))
16906 size
= (sizeof (struct common_block
)
16907 + (n_entries
- 1) * sizeof (struct symbol
*));
16909 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16911 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16912 common_block
->n_entries
= 0;
16914 for (child_die
= die
->child
;
16915 child_die
&& child_die
->tag
;
16916 child_die
= sibling_die (child_die
))
16918 /* Create the symbol in the DW_TAG_common_block block in the current
16920 sym
= new_symbol (child_die
, NULL
, cu
);
16923 struct attribute
*member_loc
;
16925 common_block
->contents
[common_block
->n_entries
++] = sym
;
16927 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16931 /* GDB has handled this for a long time, but it is
16932 not specified by DWARF. It seems to have been
16933 emitted by gfortran at least as recently as:
16934 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16935 complaint (_("Variable in common block has "
16936 "DW_AT_data_member_location "
16937 "- DIE at %s [in module %s]"),
16938 sect_offset_str (child_die
->sect_off
),
16939 objfile_name (objfile
));
16941 if (attr_form_is_section_offset (member_loc
))
16942 dwarf2_complex_location_expr_complaint ();
16943 else if (attr_form_is_constant (member_loc
)
16944 || attr_form_is_block (member_loc
))
16946 if (attr
!= nullptr)
16947 mark_common_block_symbol_computed (sym
, die
, attr
,
16951 dwarf2_complex_location_expr_complaint ();
16956 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16957 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16961 /* Create a type for a C++ namespace. */
16963 static struct type
*
16964 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16966 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16967 const char *previous_prefix
, *name
;
16971 /* For extensions, reuse the type of the original namespace. */
16972 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16974 struct die_info
*ext_die
;
16975 struct dwarf2_cu
*ext_cu
= cu
;
16977 ext_die
= dwarf2_extension (die
, &ext_cu
);
16978 type
= read_type_die (ext_die
, ext_cu
);
16980 /* EXT_CU may not be the same as CU.
16981 Ensure TYPE is recorded with CU in die_type_hash. */
16982 return set_die_type (die
, type
, cu
);
16985 name
= namespace_name (die
, &is_anonymous
, cu
);
16987 /* Now build the name of the current namespace. */
16989 previous_prefix
= determine_prefix (die
, cu
);
16990 if (previous_prefix
[0] != '\0')
16991 name
= typename_concat (&objfile
->objfile_obstack
,
16992 previous_prefix
, name
, 0, cu
);
16994 /* Create the type. */
16995 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16997 return set_die_type (die
, type
, cu
);
17000 /* Read a namespace scope. */
17003 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17005 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17008 /* Add a symbol associated to this if we haven't seen the namespace
17009 before. Also, add a using directive if it's an anonymous
17012 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17016 type
= read_type_die (die
, cu
);
17017 new_symbol (die
, type
, cu
);
17019 namespace_name (die
, &is_anonymous
, cu
);
17022 const char *previous_prefix
= determine_prefix (die
, cu
);
17024 std::vector
<const char *> excludes
;
17025 add_using_directive (using_directives (cu
),
17026 previous_prefix
, TYPE_NAME (type
), NULL
,
17027 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17031 if (die
->child
!= NULL
)
17033 struct die_info
*child_die
= die
->child
;
17035 while (child_die
&& child_die
->tag
)
17037 process_die (child_die
, cu
);
17038 child_die
= sibling_die (child_die
);
17043 /* Read a Fortran module as type. This DIE can be only a declaration used for
17044 imported module. Still we need that type as local Fortran "use ... only"
17045 declaration imports depend on the created type in determine_prefix. */
17047 static struct type
*
17048 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17050 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17051 const char *module_name
;
17054 module_name
= dwarf2_name (die
, cu
);
17055 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17057 return set_die_type (die
, type
, cu
);
17060 /* Read a Fortran module. */
17063 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17065 struct die_info
*child_die
= die
->child
;
17068 type
= read_type_die (die
, cu
);
17069 new_symbol (die
, type
, cu
);
17071 while (child_die
&& child_die
->tag
)
17073 process_die (child_die
, cu
);
17074 child_die
= sibling_die (child_die
);
17078 /* Return the name of the namespace represented by DIE. Set
17079 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17082 static const char *
17083 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17085 struct die_info
*current_die
;
17086 const char *name
= NULL
;
17088 /* Loop through the extensions until we find a name. */
17090 for (current_die
= die
;
17091 current_die
!= NULL
;
17092 current_die
= dwarf2_extension (die
, &cu
))
17094 /* We don't use dwarf2_name here so that we can detect the absence
17095 of a name -> anonymous namespace. */
17096 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17102 /* Is it an anonymous namespace? */
17104 *is_anonymous
= (name
== NULL
);
17106 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17111 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17112 the user defined type vector. */
17114 static struct type
*
17115 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17117 struct gdbarch
*gdbarch
17118 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17119 struct comp_unit_head
*cu_header
= &cu
->header
;
17121 struct attribute
*attr_byte_size
;
17122 struct attribute
*attr_address_class
;
17123 int byte_size
, addr_class
;
17124 struct type
*target_type
;
17126 target_type
= die_type (die
, cu
);
17128 /* The die_type call above may have already set the type for this DIE. */
17129 type
= get_die_type (die
, cu
);
17133 type
= lookup_pointer_type (target_type
);
17135 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17136 if (attr_byte_size
)
17137 byte_size
= DW_UNSND (attr_byte_size
);
17139 byte_size
= cu_header
->addr_size
;
17141 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17142 if (attr_address_class
)
17143 addr_class
= DW_UNSND (attr_address_class
);
17145 addr_class
= DW_ADDR_none
;
17147 ULONGEST alignment
= get_alignment (cu
, die
);
17149 /* If the pointer size, alignment, or address class is different
17150 than the default, create a type variant marked as such and set
17151 the length accordingly. */
17152 if (TYPE_LENGTH (type
) != byte_size
17153 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17154 && alignment
!= TYPE_RAW_ALIGN (type
))
17155 || addr_class
!= DW_ADDR_none
)
17157 if (gdbarch_address_class_type_flags_p (gdbarch
))
17161 type_flags
= gdbarch_address_class_type_flags
17162 (gdbarch
, byte_size
, addr_class
);
17163 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17165 type
= make_type_with_address_space (type
, type_flags
);
17167 else if (TYPE_LENGTH (type
) != byte_size
)
17169 complaint (_("invalid pointer size %d"), byte_size
);
17171 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17173 complaint (_("Invalid DW_AT_alignment"
17174 " - DIE at %s [in module %s]"),
17175 sect_offset_str (die
->sect_off
),
17176 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17180 /* Should we also complain about unhandled address classes? */
17184 TYPE_LENGTH (type
) = byte_size
;
17185 set_type_align (type
, alignment
);
17186 return set_die_type (die
, type
, cu
);
17189 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17190 the user defined type vector. */
17192 static struct type
*
17193 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17196 struct type
*to_type
;
17197 struct type
*domain
;
17199 to_type
= die_type (die
, cu
);
17200 domain
= die_containing_type (die
, cu
);
17202 /* The calls above may have already set the type for this DIE. */
17203 type
= get_die_type (die
, cu
);
17207 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17208 type
= lookup_methodptr_type (to_type
);
17209 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17211 struct type
*new_type
17212 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17214 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17215 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17216 TYPE_VARARGS (to_type
));
17217 type
= lookup_methodptr_type (new_type
);
17220 type
= lookup_memberptr_type (to_type
, domain
);
17222 return set_die_type (die
, type
, cu
);
17225 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17226 the user defined type vector. */
17228 static struct type
*
17229 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17230 enum type_code refcode
)
17232 struct comp_unit_head
*cu_header
= &cu
->header
;
17233 struct type
*type
, *target_type
;
17234 struct attribute
*attr
;
17236 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17238 target_type
= die_type (die
, cu
);
17240 /* The die_type call above may have already set the type for this DIE. */
17241 type
= get_die_type (die
, cu
);
17245 type
= lookup_reference_type (target_type
, refcode
);
17246 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17247 if (attr
!= nullptr)
17249 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17253 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17255 maybe_set_alignment (cu
, die
, type
);
17256 return set_die_type (die
, type
, cu
);
17259 /* Add the given cv-qualifiers to the element type of the array. GCC
17260 outputs DWARF type qualifiers that apply to an array, not the
17261 element type. But GDB relies on the array element type to carry
17262 the cv-qualifiers. This mimics section 6.7.3 of the C99
17265 static struct type
*
17266 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17267 struct type
*base_type
, int cnst
, int voltl
)
17269 struct type
*el_type
, *inner_array
;
17271 base_type
= copy_type (base_type
);
17272 inner_array
= base_type
;
17274 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17276 TYPE_TARGET_TYPE (inner_array
) =
17277 copy_type (TYPE_TARGET_TYPE (inner_array
));
17278 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17281 el_type
= TYPE_TARGET_TYPE (inner_array
);
17282 cnst
|= TYPE_CONST (el_type
);
17283 voltl
|= TYPE_VOLATILE (el_type
);
17284 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17286 return set_die_type (die
, base_type
, cu
);
17289 static struct type
*
17290 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17292 struct type
*base_type
, *cv_type
;
17294 base_type
= die_type (die
, cu
);
17296 /* The die_type call above may have already set the type for this DIE. */
17297 cv_type
= get_die_type (die
, cu
);
17301 /* In case the const qualifier is applied to an array type, the element type
17302 is so qualified, not the array type (section 6.7.3 of C99). */
17303 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17304 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17306 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17307 return set_die_type (die
, cv_type
, cu
);
17310 static struct type
*
17311 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17313 struct type
*base_type
, *cv_type
;
17315 base_type
= die_type (die
, cu
);
17317 /* The die_type call above may have already set the type for this DIE. */
17318 cv_type
= get_die_type (die
, cu
);
17322 /* In case the volatile qualifier is applied to an array type, the
17323 element type is so qualified, not the array type (section 6.7.3
17325 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17326 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17328 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17329 return set_die_type (die
, cv_type
, cu
);
17332 /* Handle DW_TAG_restrict_type. */
17334 static struct type
*
17335 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17337 struct type
*base_type
, *cv_type
;
17339 base_type
= die_type (die
, cu
);
17341 /* The die_type call above may have already set the type for this DIE. */
17342 cv_type
= get_die_type (die
, cu
);
17346 cv_type
= make_restrict_type (base_type
);
17347 return set_die_type (die
, cv_type
, cu
);
17350 /* Handle DW_TAG_atomic_type. */
17352 static struct type
*
17353 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17355 struct type
*base_type
, *cv_type
;
17357 base_type
= die_type (die
, cu
);
17359 /* The die_type call above may have already set the type for this DIE. */
17360 cv_type
= get_die_type (die
, cu
);
17364 cv_type
= make_atomic_type (base_type
);
17365 return set_die_type (die
, cv_type
, cu
);
17368 /* Extract all information from a DW_TAG_string_type DIE and add to
17369 the user defined type vector. It isn't really a user defined type,
17370 but it behaves like one, with other DIE's using an AT_user_def_type
17371 attribute to reference it. */
17373 static struct type
*
17374 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17376 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17377 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17378 struct type
*type
, *range_type
, *index_type
, *char_type
;
17379 struct attribute
*attr
;
17380 struct dynamic_prop prop
;
17381 bool length_is_constant
= true;
17384 /* There are a couple of places where bit sizes might be made use of
17385 when parsing a DW_TAG_string_type, however, no producer that we know
17386 of make use of these. Handling bit sizes that are a multiple of the
17387 byte size is easy enough, but what about other bit sizes? Lets deal
17388 with that problem when we have to. Warn about these attributes being
17389 unsupported, then parse the type and ignore them like we always
17391 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17392 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17394 static bool warning_printed
= false;
17395 if (!warning_printed
)
17397 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17398 "currently supported on DW_TAG_string_type."));
17399 warning_printed
= true;
17403 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17404 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17406 /* The string length describes the location at which the length of
17407 the string can be found. The size of the length field can be
17408 specified with one of the attributes below. */
17409 struct type
*prop_type
;
17410 struct attribute
*len
17411 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17412 if (len
== nullptr)
17413 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17414 if (len
!= nullptr && attr_form_is_constant (len
))
17416 /* Pass 0 as the default as we know this attribute is constant
17417 and the default value will not be returned. */
17418 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17419 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17423 /* If the size is not specified then we assume it is the size of
17424 an address on this target. */
17425 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17428 /* Convert the attribute into a dynamic property. */
17429 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17432 length_is_constant
= false;
17434 else if (attr
!= nullptr)
17436 /* This DW_AT_string_length just contains the length with no
17437 indirection. There's no need to create a dynamic property in this
17438 case. Pass 0 for the default value as we know it will not be
17439 returned in this case. */
17440 length
= dwarf2_get_attr_constant_value (attr
, 0);
17442 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17444 /* We don't currently support non-constant byte sizes for strings. */
17445 length
= dwarf2_get_attr_constant_value (attr
, 1);
17449 /* Use 1 as a fallback length if we have nothing else. */
17453 index_type
= objfile_type (objfile
)->builtin_int
;
17454 if (length_is_constant
)
17455 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17458 struct dynamic_prop low_bound
;
17460 low_bound
.kind
= PROP_CONST
;
17461 low_bound
.data
.const_val
= 1;
17462 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17464 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17465 type
= create_string_type (NULL
, char_type
, range_type
);
17467 return set_die_type (die
, type
, cu
);
17470 /* Assuming that DIE corresponds to a function, returns nonzero
17471 if the function is prototyped. */
17474 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17476 struct attribute
*attr
;
17478 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17479 if (attr
&& (DW_UNSND (attr
) != 0))
17482 /* The DWARF standard implies that the DW_AT_prototyped attribute
17483 is only meaningful for C, but the concept also extends to other
17484 languages that allow unprototyped functions (Eg: Objective C).
17485 For all other languages, assume that functions are always
17487 if (cu
->language
!= language_c
17488 && cu
->language
!= language_objc
17489 && cu
->language
!= language_opencl
)
17492 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17493 prototyped and unprototyped functions; default to prototyped,
17494 since that is more common in modern code (and RealView warns
17495 about unprototyped functions). */
17496 if (producer_is_realview (cu
->producer
))
17502 /* Handle DIES due to C code like:
17506 int (*funcp)(int a, long l);
17510 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17512 static struct type
*
17513 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17515 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17516 struct type
*type
; /* Type that this function returns. */
17517 struct type
*ftype
; /* Function that returns above type. */
17518 struct attribute
*attr
;
17520 type
= die_type (die
, cu
);
17522 /* The die_type call above may have already set the type for this DIE. */
17523 ftype
= get_die_type (die
, cu
);
17527 ftype
= lookup_function_type (type
);
17529 if (prototyped_function_p (die
, cu
))
17530 TYPE_PROTOTYPED (ftype
) = 1;
17532 /* Store the calling convention in the type if it's available in
17533 the subroutine die. Otherwise set the calling convention to
17534 the default value DW_CC_normal. */
17535 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17536 if (attr
!= nullptr
17537 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17538 TYPE_CALLING_CONVENTION (ftype
)
17539 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17540 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17541 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17543 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17545 /* Record whether the function returns normally to its caller or not
17546 if the DWARF producer set that information. */
17547 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17548 if (attr
&& (DW_UNSND (attr
) != 0))
17549 TYPE_NO_RETURN (ftype
) = 1;
17551 /* We need to add the subroutine type to the die immediately so
17552 we don't infinitely recurse when dealing with parameters
17553 declared as the same subroutine type. */
17554 set_die_type (die
, ftype
, cu
);
17556 if (die
->child
!= NULL
)
17558 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17559 struct die_info
*child_die
;
17560 int nparams
, iparams
;
17562 /* Count the number of parameters.
17563 FIXME: GDB currently ignores vararg functions, but knows about
17564 vararg member functions. */
17566 child_die
= die
->child
;
17567 while (child_die
&& child_die
->tag
)
17569 if (child_die
->tag
== DW_TAG_formal_parameter
)
17571 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17572 TYPE_VARARGS (ftype
) = 1;
17573 child_die
= sibling_die (child_die
);
17576 /* Allocate storage for parameters and fill them in. */
17577 TYPE_NFIELDS (ftype
) = nparams
;
17578 TYPE_FIELDS (ftype
) = (struct field
*)
17579 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17581 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17582 even if we error out during the parameters reading below. */
17583 for (iparams
= 0; iparams
< nparams
; iparams
++)
17584 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17587 child_die
= die
->child
;
17588 while (child_die
&& child_die
->tag
)
17590 if (child_die
->tag
== DW_TAG_formal_parameter
)
17592 struct type
*arg_type
;
17594 /* DWARF version 2 has no clean way to discern C++
17595 static and non-static member functions. G++ helps
17596 GDB by marking the first parameter for non-static
17597 member functions (which is the this pointer) as
17598 artificial. We pass this information to
17599 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17601 DWARF version 3 added DW_AT_object_pointer, which GCC
17602 4.5 does not yet generate. */
17603 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17604 if (attr
!= nullptr)
17605 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17607 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17608 arg_type
= die_type (child_die
, cu
);
17610 /* RealView does not mark THIS as const, which the testsuite
17611 expects. GCC marks THIS as const in method definitions,
17612 but not in the class specifications (GCC PR 43053). */
17613 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17614 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17617 struct dwarf2_cu
*arg_cu
= cu
;
17618 const char *name
= dwarf2_name (child_die
, cu
);
17620 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17621 if (attr
!= nullptr)
17623 /* If the compiler emits this, use it. */
17624 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17627 else if (name
&& strcmp (name
, "this") == 0)
17628 /* Function definitions will have the argument names. */
17630 else if (name
== NULL
&& iparams
== 0)
17631 /* Declarations may not have the names, so like
17632 elsewhere in GDB, assume an artificial first
17633 argument is "this". */
17637 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17641 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17644 child_die
= sibling_die (child_die
);
17651 static struct type
*
17652 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17654 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17655 const char *name
= NULL
;
17656 struct type
*this_type
, *target_type
;
17658 name
= dwarf2_full_name (NULL
, die
, cu
);
17659 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17660 TYPE_TARGET_STUB (this_type
) = 1;
17661 set_die_type (die
, this_type
, cu
);
17662 target_type
= die_type (die
, cu
);
17663 if (target_type
!= this_type
)
17664 TYPE_TARGET_TYPE (this_type
) = target_type
;
17667 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17668 spec and cause infinite loops in GDB. */
17669 complaint (_("Self-referential DW_TAG_typedef "
17670 "- DIE at %s [in module %s]"),
17671 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17672 TYPE_TARGET_TYPE (this_type
) = NULL
;
17677 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17678 (which may be different from NAME) to the architecture back-end to allow
17679 it to guess the correct format if necessary. */
17681 static struct type
*
17682 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17683 const char *name_hint
, enum bfd_endian byte_order
)
17685 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17686 const struct floatformat
**format
;
17689 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17691 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17693 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17698 /* Allocate an integer type of size BITS and name NAME. */
17700 static struct type
*
17701 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17702 int bits
, int unsigned_p
, const char *name
)
17706 /* Versions of Intel's C Compiler generate an integer type called "void"
17707 instead of using DW_TAG_unspecified_type. This has been seen on
17708 at least versions 14, 17, and 18. */
17709 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17710 && strcmp (name
, "void") == 0)
17711 type
= objfile_type (objfile
)->builtin_void
;
17713 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17718 /* Initialise and return a floating point type of size BITS suitable for
17719 use as a component of a complex number. The NAME_HINT is passed through
17720 when initialising the floating point type and is the name of the complex
17723 As DWARF doesn't currently provide an explicit name for the components
17724 of a complex number, but it can be helpful to have these components
17725 named, we try to select a suitable name based on the size of the
17727 static struct type
*
17728 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17729 struct objfile
*objfile
,
17730 int bits
, const char *name_hint
,
17731 enum bfd_endian byte_order
)
17733 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17734 struct type
*tt
= nullptr;
17736 /* Try to find a suitable floating point builtin type of size BITS.
17737 We're going to use the name of this type as the name for the complex
17738 target type that we are about to create. */
17739 switch (cu
->language
)
17741 case language_fortran
:
17745 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17748 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17750 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17752 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17760 tt
= builtin_type (gdbarch
)->builtin_float
;
17763 tt
= builtin_type (gdbarch
)->builtin_double
;
17765 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17767 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17773 /* If the type we found doesn't match the size we were looking for, then
17774 pretend we didn't find a type at all, the complex target type we
17775 create will then be nameless. */
17776 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17779 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17780 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17783 /* Find a representation of a given base type and install
17784 it in the TYPE field of the die. */
17786 static struct type
*
17787 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17789 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17791 struct attribute
*attr
;
17792 int encoding
= 0, bits
= 0;
17796 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17797 if (attr
!= nullptr)
17798 encoding
= DW_UNSND (attr
);
17799 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17800 if (attr
!= nullptr)
17801 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17802 name
= dwarf2_name (die
, cu
);
17804 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17806 arch
= get_objfile_arch (objfile
);
17807 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17809 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17812 int endianity
= DW_UNSND (attr
);
17817 byte_order
= BFD_ENDIAN_BIG
;
17819 case DW_END_little
:
17820 byte_order
= BFD_ENDIAN_LITTLE
;
17823 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17830 case DW_ATE_address
:
17831 /* Turn DW_ATE_address into a void * pointer. */
17832 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17833 type
= init_pointer_type (objfile
, bits
, name
, type
);
17835 case DW_ATE_boolean
:
17836 type
= init_boolean_type (objfile
, bits
, 1, name
);
17838 case DW_ATE_complex_float
:
17839 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17841 type
= init_complex_type (objfile
, name
, type
);
17843 case DW_ATE_decimal_float
:
17844 type
= init_decfloat_type (objfile
, bits
, name
);
17847 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17849 case DW_ATE_signed
:
17850 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17852 case DW_ATE_unsigned
:
17853 if (cu
->language
== language_fortran
17855 && startswith (name
, "character("))
17856 type
= init_character_type (objfile
, bits
, 1, name
);
17858 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17860 case DW_ATE_signed_char
:
17861 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17862 || cu
->language
== language_pascal
17863 || cu
->language
== language_fortran
)
17864 type
= init_character_type (objfile
, bits
, 0, name
);
17866 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17868 case DW_ATE_unsigned_char
:
17869 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17870 || cu
->language
== language_pascal
17871 || cu
->language
== language_fortran
17872 || cu
->language
== language_rust
)
17873 type
= init_character_type (objfile
, bits
, 1, name
);
17875 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17880 type
= builtin_type (arch
)->builtin_char16
;
17881 else if (bits
== 32)
17882 type
= builtin_type (arch
)->builtin_char32
;
17885 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17887 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17889 return set_die_type (die
, type
, cu
);
17894 complaint (_("unsupported DW_AT_encoding: '%s'"),
17895 dwarf_type_encoding_name (encoding
));
17896 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17900 if (name
&& strcmp (name
, "char") == 0)
17901 TYPE_NOSIGN (type
) = 1;
17903 maybe_set_alignment (cu
, die
, type
);
17905 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17907 return set_die_type (die
, type
, cu
);
17910 /* Parse dwarf attribute if it's a block, reference or constant and put the
17911 resulting value of the attribute into struct bound_prop.
17912 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17915 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17916 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17917 struct type
*default_type
)
17919 struct dwarf2_property_baton
*baton
;
17920 struct obstack
*obstack
17921 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17923 gdb_assert (default_type
!= NULL
);
17925 if (attr
== NULL
|| prop
== NULL
)
17928 if (attr_form_is_block (attr
))
17930 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17931 baton
->property_type
= default_type
;
17932 baton
->locexpr
.per_cu
= cu
->per_cu
;
17933 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17934 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17935 switch (attr
->name
)
17937 case DW_AT_string_length
:
17938 baton
->locexpr
.is_reference
= true;
17941 baton
->locexpr
.is_reference
= false;
17944 prop
->data
.baton
= baton
;
17945 prop
->kind
= PROP_LOCEXPR
;
17946 gdb_assert (prop
->data
.baton
!= NULL
);
17948 else if (attr_form_is_ref (attr
))
17950 struct dwarf2_cu
*target_cu
= cu
;
17951 struct die_info
*target_die
;
17952 struct attribute
*target_attr
;
17954 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17955 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17956 if (target_attr
== NULL
)
17957 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17959 if (target_attr
== NULL
)
17962 switch (target_attr
->name
)
17964 case DW_AT_location
:
17965 if (attr_form_is_section_offset (target_attr
))
17967 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17968 baton
->property_type
= die_type (target_die
, target_cu
);
17969 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17970 prop
->data
.baton
= baton
;
17971 prop
->kind
= PROP_LOCLIST
;
17972 gdb_assert (prop
->data
.baton
!= NULL
);
17974 else if (attr_form_is_block (target_attr
))
17976 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17977 baton
->property_type
= die_type (target_die
, target_cu
);
17978 baton
->locexpr
.per_cu
= cu
->per_cu
;
17979 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17980 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17981 baton
->locexpr
.is_reference
= true;
17982 prop
->data
.baton
= baton
;
17983 prop
->kind
= PROP_LOCEXPR
;
17984 gdb_assert (prop
->data
.baton
!= NULL
);
17988 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17989 "dynamic property");
17993 case DW_AT_data_member_location
:
17997 if (!handle_data_member_location (target_die
, target_cu
,
18001 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18002 baton
->property_type
= read_type_die (target_die
->parent
,
18004 baton
->offset_info
.offset
= offset
;
18005 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18006 prop
->data
.baton
= baton
;
18007 prop
->kind
= PROP_ADDR_OFFSET
;
18012 else if (attr_form_is_constant (attr
))
18014 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18015 prop
->kind
= PROP_CONST
;
18019 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18020 dwarf2_name (die
, cu
));
18027 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18028 UNSIGNED_P controls if the integer is unsigned or not. */
18030 static struct type
*
18031 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18032 int size_in_bytes
, bool unsigned_p
)
18034 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18035 struct type
*int_type
;
18037 /* Helper macro to examine the various builtin types. */
18038 #define TRY_TYPE(F) \
18039 int_type = (unsigned_p \
18040 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18041 : objfile_type (objfile)->builtin_ ## F); \
18042 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18049 TRY_TYPE (long_long
);
18053 gdb_assert_not_reached ("unable to find suitable integer type");
18056 /* Find an integer type the same size as the address size given in the
18057 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18058 is unsigned or not. */
18060 static struct type
*
18061 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18064 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18065 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18068 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18069 present (which is valid) then compute the default type based on the
18070 compilation units address size. */
18072 static struct type
*
18073 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18075 struct type
*index_type
= die_type (die
, cu
);
18077 /* Dwarf-2 specifications explicitly allows to create subrange types
18078 without specifying a base type.
18079 In that case, the base type must be set to the type of
18080 the lower bound, upper bound or count, in that order, if any of these
18081 three attributes references an object that has a type.
18082 If no base type is found, the Dwarf-2 specifications say that
18083 a signed integer type of size equal to the size of an address should
18085 For the following C code: `extern char gdb_int [];'
18086 GCC produces an empty range DIE.
18087 FIXME: muller/2010-05-28: Possible references to object for low bound,
18088 high bound or count are not yet handled by this code. */
18089 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18090 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18095 /* Read the given DW_AT_subrange DIE. */
18097 static struct type
*
18098 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18100 struct type
*base_type
, *orig_base_type
;
18101 struct type
*range_type
;
18102 struct attribute
*attr
;
18103 struct dynamic_prop low
, high
;
18104 int low_default_is_valid
;
18105 int high_bound_is_count
= 0;
18107 ULONGEST negative_mask
;
18109 orig_base_type
= read_subrange_index_type (die
, cu
);
18111 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18112 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18113 creating the range type, but we use the result of check_typedef
18114 when examining properties of the type. */
18115 base_type
= check_typedef (orig_base_type
);
18117 /* The die_type call above may have already set the type for this DIE. */
18118 range_type
= get_die_type (die
, cu
);
18122 low
.kind
= PROP_CONST
;
18123 high
.kind
= PROP_CONST
;
18124 high
.data
.const_val
= 0;
18126 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18127 omitting DW_AT_lower_bound. */
18128 switch (cu
->language
)
18131 case language_cplus
:
18132 low
.data
.const_val
= 0;
18133 low_default_is_valid
= 1;
18135 case language_fortran
:
18136 low
.data
.const_val
= 1;
18137 low_default_is_valid
= 1;
18140 case language_objc
:
18141 case language_rust
:
18142 low
.data
.const_val
= 0;
18143 low_default_is_valid
= (cu
->header
.version
>= 4);
18147 case language_pascal
:
18148 low
.data
.const_val
= 1;
18149 low_default_is_valid
= (cu
->header
.version
>= 4);
18152 low
.data
.const_val
= 0;
18153 low_default_is_valid
= 0;
18157 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18158 if (attr
!= nullptr)
18159 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18160 else if (!low_default_is_valid
)
18161 complaint (_("Missing DW_AT_lower_bound "
18162 "- DIE at %s [in module %s]"),
18163 sect_offset_str (die
->sect_off
),
18164 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18166 struct attribute
*attr_ub
, *attr_count
;
18167 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18168 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18170 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18171 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18173 /* If bounds are constant do the final calculation here. */
18174 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18175 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18177 high_bound_is_count
= 1;
18181 if (attr_ub
!= NULL
)
18182 complaint (_("Unresolved DW_AT_upper_bound "
18183 "- DIE at %s [in module %s]"),
18184 sect_offset_str (die
->sect_off
),
18185 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18186 if (attr_count
!= NULL
)
18187 complaint (_("Unresolved DW_AT_count "
18188 "- DIE at %s [in module %s]"),
18189 sect_offset_str (die
->sect_off
),
18190 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18195 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18196 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18197 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18199 /* Normally, the DWARF producers are expected to use a signed
18200 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18201 But this is unfortunately not always the case, as witnessed
18202 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18203 is used instead. To work around that ambiguity, we treat
18204 the bounds as signed, and thus sign-extend their values, when
18205 the base type is signed. */
18207 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18208 if (low
.kind
== PROP_CONST
18209 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18210 low
.data
.const_val
|= negative_mask
;
18211 if (high
.kind
== PROP_CONST
18212 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18213 high
.data
.const_val
|= negative_mask
;
18215 /* Check for bit and byte strides. */
18216 struct dynamic_prop byte_stride_prop
;
18217 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18218 if (attr_byte_stride
!= nullptr)
18220 struct type
*prop_type
18221 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18222 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18226 struct dynamic_prop bit_stride_prop
;
18227 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18228 if (attr_bit_stride
!= nullptr)
18230 /* It only makes sense to have either a bit or byte stride. */
18231 if (attr_byte_stride
!= nullptr)
18233 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18234 "- DIE at %s [in module %s]"),
18235 sect_offset_str (die
->sect_off
),
18236 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18237 attr_bit_stride
= nullptr;
18241 struct type
*prop_type
18242 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18243 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18248 if (attr_byte_stride
!= nullptr
18249 || attr_bit_stride
!= nullptr)
18251 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18252 struct dynamic_prop
*stride
18253 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18256 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18257 &high
, bias
, stride
, byte_stride_p
);
18260 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18262 if (high_bound_is_count
)
18263 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18265 /* Ada expects an empty array on no boundary attributes. */
18266 if (attr
== NULL
&& cu
->language
!= language_ada
)
18267 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18269 name
= dwarf2_name (die
, cu
);
18271 TYPE_NAME (range_type
) = name
;
18273 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18274 if (attr
!= nullptr)
18275 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18277 maybe_set_alignment (cu
, die
, range_type
);
18279 set_die_type (die
, range_type
, cu
);
18281 /* set_die_type should be already done. */
18282 set_descriptive_type (range_type
, die
, cu
);
18287 static struct type
*
18288 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18292 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18294 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18296 /* In Ada, an unspecified type is typically used when the description
18297 of the type is deferred to a different unit. When encountering
18298 such a type, we treat it as a stub, and try to resolve it later on,
18300 if (cu
->language
== language_ada
)
18301 TYPE_STUB (type
) = 1;
18303 return set_die_type (die
, type
, cu
);
18306 /* Read a single die and all its descendents. Set the die's sibling
18307 field to NULL; set other fields in the die correctly, and set all
18308 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18309 location of the info_ptr after reading all of those dies. PARENT
18310 is the parent of the die in question. */
18312 static struct die_info
*
18313 read_die_and_children (const struct die_reader_specs
*reader
,
18314 const gdb_byte
*info_ptr
,
18315 const gdb_byte
**new_info_ptr
,
18316 struct die_info
*parent
)
18318 struct die_info
*die
;
18319 const gdb_byte
*cur_ptr
;
18322 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18325 *new_info_ptr
= cur_ptr
;
18328 store_in_ref_table (die
, reader
->cu
);
18331 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18335 *new_info_ptr
= cur_ptr
;
18338 die
->sibling
= NULL
;
18339 die
->parent
= parent
;
18343 /* Read a die, all of its descendents, and all of its siblings; set
18344 all of the fields of all of the dies correctly. Arguments are as
18345 in read_die_and_children. */
18347 static struct die_info
*
18348 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18349 const gdb_byte
*info_ptr
,
18350 const gdb_byte
**new_info_ptr
,
18351 struct die_info
*parent
)
18353 struct die_info
*first_die
, *last_sibling
;
18354 const gdb_byte
*cur_ptr
;
18356 cur_ptr
= info_ptr
;
18357 first_die
= last_sibling
= NULL
;
18361 struct die_info
*die
18362 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18366 *new_info_ptr
= cur_ptr
;
18373 last_sibling
->sibling
= die
;
18375 last_sibling
= die
;
18379 /* Read a die, all of its descendents, and all of its siblings; set
18380 all of the fields of all of the dies correctly. Arguments are as
18381 in read_die_and_children.
18382 This the main entry point for reading a DIE and all its children. */
18384 static struct die_info
*
18385 read_die_and_siblings (const struct die_reader_specs
*reader
,
18386 const gdb_byte
*info_ptr
,
18387 const gdb_byte
**new_info_ptr
,
18388 struct die_info
*parent
)
18390 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18391 new_info_ptr
, parent
);
18393 if (dwarf_die_debug
)
18395 fprintf_unfiltered (gdb_stdlog
,
18396 "Read die from %s@0x%x of %s:\n",
18397 get_section_name (reader
->die_section
),
18398 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18399 bfd_get_filename (reader
->abfd
));
18400 dump_die (die
, dwarf_die_debug
);
18406 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18408 The caller is responsible for filling in the extra attributes
18409 and updating (*DIEP)->num_attrs.
18410 Set DIEP to point to a newly allocated die with its information,
18411 except for its child, sibling, and parent fields.
18412 Set HAS_CHILDREN to tell whether the die has children or not. */
18414 static const gdb_byte
*
18415 read_full_die_1 (const struct die_reader_specs
*reader
,
18416 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18417 int *has_children
, int num_extra_attrs
)
18419 unsigned int abbrev_number
, bytes_read
, i
;
18420 struct abbrev_info
*abbrev
;
18421 struct die_info
*die
;
18422 struct dwarf2_cu
*cu
= reader
->cu
;
18423 bfd
*abfd
= reader
->abfd
;
18425 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18426 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18427 info_ptr
+= bytes_read
;
18428 if (!abbrev_number
)
18435 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18437 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18439 bfd_get_filename (abfd
));
18441 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18442 die
->sect_off
= sect_off
;
18443 die
->tag
= abbrev
->tag
;
18444 die
->abbrev
= abbrev_number
;
18446 /* Make the result usable.
18447 The caller needs to update num_attrs after adding the extra
18449 die
->num_attrs
= abbrev
->num_attrs
;
18451 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18452 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18456 *has_children
= abbrev
->has_children
;
18460 /* Read a die and all its attributes.
18461 Set DIEP to point to a newly allocated die with its information,
18462 except for its child, sibling, and parent fields.
18463 Set HAS_CHILDREN to tell whether the die has children or not. */
18465 static const gdb_byte
*
18466 read_full_die (const struct die_reader_specs
*reader
,
18467 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18470 const gdb_byte
*result
;
18472 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18474 if (dwarf_die_debug
)
18476 fprintf_unfiltered (gdb_stdlog
,
18477 "Read die from %s@0x%x of %s:\n",
18478 get_section_name (reader
->die_section
),
18479 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18480 bfd_get_filename (reader
->abfd
));
18481 dump_die (*diep
, dwarf_die_debug
);
18487 /* Abbreviation tables.
18489 In DWARF version 2, the description of the debugging information is
18490 stored in a separate .debug_abbrev section. Before we read any
18491 dies from a section we read in all abbreviations and install them
18492 in a hash table. */
18494 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18496 struct abbrev_info
*
18497 abbrev_table::alloc_abbrev ()
18499 struct abbrev_info
*abbrev
;
18501 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18502 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18507 /* Add an abbreviation to the table. */
18510 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18511 struct abbrev_info
*abbrev
)
18513 unsigned int hash_number
;
18515 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18516 abbrev
->next
= m_abbrevs
[hash_number
];
18517 m_abbrevs
[hash_number
] = abbrev
;
18520 /* Look up an abbrev in the table.
18521 Returns NULL if the abbrev is not found. */
18523 struct abbrev_info
*
18524 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18526 unsigned int hash_number
;
18527 struct abbrev_info
*abbrev
;
18529 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18530 abbrev
= m_abbrevs
[hash_number
];
18534 if (abbrev
->number
== abbrev_number
)
18536 abbrev
= abbrev
->next
;
18541 /* Read in an abbrev table. */
18543 static abbrev_table_up
18544 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18545 struct dwarf2_section_info
*section
,
18546 sect_offset sect_off
)
18548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18549 bfd
*abfd
= get_section_bfd_owner (section
);
18550 const gdb_byte
*abbrev_ptr
;
18551 struct abbrev_info
*cur_abbrev
;
18552 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18553 unsigned int abbrev_form
;
18554 std::vector
<struct attr_abbrev
> cur_attrs
;
18556 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18558 dwarf2_read_section (objfile
, section
);
18559 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18560 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18561 abbrev_ptr
+= bytes_read
;
18563 /* Loop until we reach an abbrev number of 0. */
18564 while (abbrev_number
)
18566 cur_attrs
.clear ();
18567 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18569 /* read in abbrev header */
18570 cur_abbrev
->number
= abbrev_number
;
18572 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18573 abbrev_ptr
+= bytes_read
;
18574 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18577 /* now read in declarations */
18580 LONGEST implicit_const
;
18582 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18583 abbrev_ptr
+= bytes_read
;
18584 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18585 abbrev_ptr
+= bytes_read
;
18586 if (abbrev_form
== DW_FORM_implicit_const
)
18588 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18590 abbrev_ptr
+= bytes_read
;
18594 /* Initialize it due to a false compiler warning. */
18595 implicit_const
= -1;
18598 if (abbrev_name
== 0)
18601 cur_attrs
.emplace_back ();
18602 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18603 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18604 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18605 cur_attr
.implicit_const
= implicit_const
;
18606 ++cur_abbrev
->num_attrs
;
18609 cur_abbrev
->attrs
=
18610 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18611 cur_abbrev
->num_attrs
);
18612 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18613 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18615 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18617 /* Get next abbreviation.
18618 Under Irix6 the abbreviations for a compilation unit are not
18619 always properly terminated with an abbrev number of 0.
18620 Exit loop if we encounter an abbreviation which we have
18621 already read (which means we are about to read the abbreviations
18622 for the next compile unit) or if the end of the abbreviation
18623 table is reached. */
18624 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18626 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18627 abbrev_ptr
+= bytes_read
;
18628 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18632 return abbrev_table
;
18635 /* Returns nonzero if TAG represents a type that we might generate a partial
18639 is_type_tag_for_partial (int tag
)
18644 /* Some types that would be reasonable to generate partial symbols for,
18645 that we don't at present. */
18646 case DW_TAG_array_type
:
18647 case DW_TAG_file_type
:
18648 case DW_TAG_ptr_to_member_type
:
18649 case DW_TAG_set_type
:
18650 case DW_TAG_string_type
:
18651 case DW_TAG_subroutine_type
:
18653 case DW_TAG_base_type
:
18654 case DW_TAG_class_type
:
18655 case DW_TAG_interface_type
:
18656 case DW_TAG_enumeration_type
:
18657 case DW_TAG_structure_type
:
18658 case DW_TAG_subrange_type
:
18659 case DW_TAG_typedef
:
18660 case DW_TAG_union_type
:
18667 /* Load all DIEs that are interesting for partial symbols into memory. */
18669 static struct partial_die_info
*
18670 load_partial_dies (const struct die_reader_specs
*reader
,
18671 const gdb_byte
*info_ptr
, int building_psymtab
)
18673 struct dwarf2_cu
*cu
= reader
->cu
;
18674 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18675 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18676 unsigned int bytes_read
;
18677 unsigned int load_all
= 0;
18678 int nesting_level
= 1;
18683 gdb_assert (cu
->per_cu
!= NULL
);
18684 if (cu
->per_cu
->load_all_dies
)
18688 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18692 &cu
->comp_unit_obstack
,
18693 hashtab_obstack_allocate
,
18694 dummy_obstack_deallocate
);
18698 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18700 /* A NULL abbrev means the end of a series of children. */
18701 if (abbrev
== NULL
)
18703 if (--nesting_level
== 0)
18706 info_ptr
+= bytes_read
;
18707 last_die
= parent_die
;
18708 parent_die
= parent_die
->die_parent
;
18712 /* Check for template arguments. We never save these; if
18713 they're seen, we just mark the parent, and go on our way. */
18714 if (parent_die
!= NULL
18715 && cu
->language
== language_cplus
18716 && (abbrev
->tag
== DW_TAG_template_type_param
18717 || abbrev
->tag
== DW_TAG_template_value_param
))
18719 parent_die
->has_template_arguments
= 1;
18723 /* We don't need a partial DIE for the template argument. */
18724 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18729 /* We only recurse into c++ subprograms looking for template arguments.
18730 Skip their other children. */
18732 && cu
->language
== language_cplus
18733 && parent_die
!= NULL
18734 && parent_die
->tag
== DW_TAG_subprogram
)
18736 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18740 /* Check whether this DIE is interesting enough to save. Normally
18741 we would not be interested in members here, but there may be
18742 later variables referencing them via DW_AT_specification (for
18743 static members). */
18745 && !is_type_tag_for_partial (abbrev
->tag
)
18746 && abbrev
->tag
!= DW_TAG_constant
18747 && abbrev
->tag
!= DW_TAG_enumerator
18748 && abbrev
->tag
!= DW_TAG_subprogram
18749 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18750 && abbrev
->tag
!= DW_TAG_lexical_block
18751 && abbrev
->tag
!= DW_TAG_variable
18752 && abbrev
->tag
!= DW_TAG_namespace
18753 && abbrev
->tag
!= DW_TAG_module
18754 && abbrev
->tag
!= DW_TAG_member
18755 && abbrev
->tag
!= DW_TAG_imported_unit
18756 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18758 /* Otherwise we skip to the next sibling, if any. */
18759 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18763 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18766 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18768 /* This two-pass algorithm for processing partial symbols has a
18769 high cost in cache pressure. Thus, handle some simple cases
18770 here which cover the majority of C partial symbols. DIEs
18771 which neither have specification tags in them, nor could have
18772 specification tags elsewhere pointing at them, can simply be
18773 processed and discarded.
18775 This segment is also optional; scan_partial_symbols and
18776 add_partial_symbol will handle these DIEs if we chain
18777 them in normally. When compilers which do not emit large
18778 quantities of duplicate debug information are more common,
18779 this code can probably be removed. */
18781 /* Any complete simple types at the top level (pretty much all
18782 of them, for a language without namespaces), can be processed
18784 if (parent_die
== NULL
18785 && pdi
.has_specification
== 0
18786 && pdi
.is_declaration
== 0
18787 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18788 || pdi
.tag
== DW_TAG_base_type
18789 || pdi
.tag
== DW_TAG_subrange_type
))
18791 if (building_psymtab
&& pdi
.name
!= NULL
)
18792 add_psymbol_to_list (pdi
.name
, false,
18793 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18794 psymbol_placement::STATIC
,
18795 0, cu
->language
, objfile
);
18796 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18800 /* The exception for DW_TAG_typedef with has_children above is
18801 a workaround of GCC PR debug/47510. In the case of this complaint
18802 type_name_or_error will error on such types later.
18804 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18805 it could not find the child DIEs referenced later, this is checked
18806 above. In correct DWARF DW_TAG_typedef should have no children. */
18808 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18809 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18810 "- DIE at %s [in module %s]"),
18811 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18813 /* If we're at the second level, and we're an enumerator, and
18814 our parent has no specification (meaning possibly lives in a
18815 namespace elsewhere), then we can add the partial symbol now
18816 instead of queueing it. */
18817 if (pdi
.tag
== DW_TAG_enumerator
18818 && parent_die
!= NULL
18819 && parent_die
->die_parent
== NULL
18820 && parent_die
->tag
== DW_TAG_enumeration_type
18821 && parent_die
->has_specification
== 0)
18823 if (pdi
.name
== NULL
)
18824 complaint (_("malformed enumerator DIE ignored"));
18825 else if (building_psymtab
)
18826 add_psymbol_to_list (pdi
.name
, false,
18827 VAR_DOMAIN
, LOC_CONST
, -1,
18828 cu
->language
== language_cplus
18829 ? psymbol_placement::GLOBAL
18830 : psymbol_placement::STATIC
,
18831 0, cu
->language
, objfile
);
18833 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18837 struct partial_die_info
*part_die
18838 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18840 /* We'll save this DIE so link it in. */
18841 part_die
->die_parent
= parent_die
;
18842 part_die
->die_sibling
= NULL
;
18843 part_die
->die_child
= NULL
;
18845 if (last_die
&& last_die
== parent_die
)
18846 last_die
->die_child
= part_die
;
18848 last_die
->die_sibling
= part_die
;
18850 last_die
= part_die
;
18852 if (first_die
== NULL
)
18853 first_die
= part_die
;
18855 /* Maybe add the DIE to the hash table. Not all DIEs that we
18856 find interesting need to be in the hash table, because we
18857 also have the parent/sibling/child chains; only those that we
18858 might refer to by offset later during partial symbol reading.
18860 For now this means things that might have be the target of a
18861 DW_AT_specification, DW_AT_abstract_origin, or
18862 DW_AT_extension. DW_AT_extension will refer only to
18863 namespaces; DW_AT_abstract_origin refers to functions (and
18864 many things under the function DIE, but we do not recurse
18865 into function DIEs during partial symbol reading) and
18866 possibly variables as well; DW_AT_specification refers to
18867 declarations. Declarations ought to have the DW_AT_declaration
18868 flag. It happens that GCC forgets to put it in sometimes, but
18869 only for functions, not for types.
18871 Adding more things than necessary to the hash table is harmless
18872 except for the performance cost. Adding too few will result in
18873 wasted time in find_partial_die, when we reread the compilation
18874 unit with load_all_dies set. */
18877 || abbrev
->tag
== DW_TAG_constant
18878 || abbrev
->tag
== DW_TAG_subprogram
18879 || abbrev
->tag
== DW_TAG_variable
18880 || abbrev
->tag
== DW_TAG_namespace
18881 || part_die
->is_declaration
)
18885 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18886 to_underlying (part_die
->sect_off
),
18891 /* For some DIEs we want to follow their children (if any). For C
18892 we have no reason to follow the children of structures; for other
18893 languages we have to, so that we can get at method physnames
18894 to infer fully qualified class names, for DW_AT_specification,
18895 and for C++ template arguments. For C++, we also look one level
18896 inside functions to find template arguments (if the name of the
18897 function does not already contain the template arguments).
18899 For Ada and Fortran, we need to scan the children of subprograms
18900 and lexical blocks as well because these languages allow the
18901 definition of nested entities that could be interesting for the
18902 debugger, such as nested subprograms for instance. */
18903 if (last_die
->has_children
18905 || last_die
->tag
== DW_TAG_namespace
18906 || last_die
->tag
== DW_TAG_module
18907 || last_die
->tag
== DW_TAG_enumeration_type
18908 || (cu
->language
== language_cplus
18909 && last_die
->tag
== DW_TAG_subprogram
18910 && (last_die
->name
== NULL
18911 || strchr (last_die
->name
, '<') == NULL
))
18912 || (cu
->language
!= language_c
18913 && (last_die
->tag
== DW_TAG_class_type
18914 || last_die
->tag
== DW_TAG_interface_type
18915 || last_die
->tag
== DW_TAG_structure_type
18916 || last_die
->tag
== DW_TAG_union_type
))
18917 || ((cu
->language
== language_ada
18918 || cu
->language
== language_fortran
)
18919 && (last_die
->tag
== DW_TAG_subprogram
18920 || last_die
->tag
== DW_TAG_lexical_block
))))
18923 parent_die
= last_die
;
18927 /* Otherwise we skip to the next sibling, if any. */
18928 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18930 /* Back to the top, do it again. */
18934 partial_die_info::partial_die_info (sect_offset sect_off_
,
18935 struct abbrev_info
*abbrev
)
18936 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18940 /* Read a minimal amount of information into the minimal die structure.
18941 INFO_PTR should point just after the initial uleb128 of a DIE. */
18944 partial_die_info::read (const struct die_reader_specs
*reader
,
18945 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18947 struct dwarf2_cu
*cu
= reader
->cu
;
18948 struct dwarf2_per_objfile
*dwarf2_per_objfile
18949 = cu
->per_cu
->dwarf2_per_objfile
;
18951 int has_low_pc_attr
= 0;
18952 int has_high_pc_attr
= 0;
18953 int high_pc_relative
= 0;
18955 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18957 struct attribute attr
;
18959 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18961 /* Store the data if it is of an attribute we want to keep in a
18962 partial symbol table. */
18968 case DW_TAG_compile_unit
:
18969 case DW_TAG_partial_unit
:
18970 case DW_TAG_type_unit
:
18971 /* Compilation units have a DW_AT_name that is a filename, not
18972 a source language identifier. */
18973 case DW_TAG_enumeration_type
:
18974 case DW_TAG_enumerator
:
18975 /* These tags always have simple identifiers already; no need
18976 to canonicalize them. */
18977 name
= DW_STRING (&attr
);
18981 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18984 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18985 &objfile
->per_bfd
->storage_obstack
);
18990 case DW_AT_linkage_name
:
18991 case DW_AT_MIPS_linkage_name
:
18992 /* Note that both forms of linkage name might appear. We
18993 assume they will be the same, and we only store the last
18995 linkage_name
= DW_STRING (&attr
);
18998 has_low_pc_attr
= 1;
18999 lowpc
= attr_value_as_address (&attr
);
19001 case DW_AT_high_pc
:
19002 has_high_pc_attr
= 1;
19003 highpc
= attr_value_as_address (&attr
);
19004 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19005 high_pc_relative
= 1;
19007 case DW_AT_location
:
19008 /* Support the .debug_loc offsets. */
19009 if (attr_form_is_block (&attr
))
19011 d
.locdesc
= DW_BLOCK (&attr
);
19013 else if (attr_form_is_section_offset (&attr
))
19015 dwarf2_complex_location_expr_complaint ();
19019 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19020 "partial symbol information");
19023 case DW_AT_external
:
19024 is_external
= DW_UNSND (&attr
);
19026 case DW_AT_declaration
:
19027 is_declaration
= DW_UNSND (&attr
);
19032 case DW_AT_abstract_origin
:
19033 case DW_AT_specification
:
19034 case DW_AT_extension
:
19035 has_specification
= 1;
19036 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19037 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19038 || cu
->per_cu
->is_dwz
);
19040 case DW_AT_sibling
:
19041 /* Ignore absolute siblings, they might point outside of
19042 the current compile unit. */
19043 if (attr
.form
== DW_FORM_ref_addr
)
19044 complaint (_("ignoring absolute DW_AT_sibling"));
19047 const gdb_byte
*buffer
= reader
->buffer
;
19048 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19049 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19051 if (sibling_ptr
< info_ptr
)
19052 complaint (_("DW_AT_sibling points backwards"));
19053 else if (sibling_ptr
> reader
->buffer_end
)
19054 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19056 sibling
= sibling_ptr
;
19059 case DW_AT_byte_size
:
19062 case DW_AT_const_value
:
19063 has_const_value
= 1;
19065 case DW_AT_calling_convention
:
19066 /* DWARF doesn't provide a way to identify a program's source-level
19067 entry point. DW_AT_calling_convention attributes are only meant
19068 to describe functions' calling conventions.
19070 However, because it's a necessary piece of information in
19071 Fortran, and before DWARF 4 DW_CC_program was the only
19072 piece of debugging information whose definition refers to
19073 a 'main program' at all, several compilers marked Fortran
19074 main programs with DW_CC_program --- even when those
19075 functions use the standard calling conventions.
19077 Although DWARF now specifies a way to provide this
19078 information, we support this practice for backward
19080 if (DW_UNSND (&attr
) == DW_CC_program
19081 && cu
->language
== language_fortran
)
19082 main_subprogram
= 1;
19085 if (DW_UNSND (&attr
) == DW_INL_inlined
19086 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19087 may_be_inlined
= 1;
19091 if (tag
== DW_TAG_imported_unit
)
19093 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19094 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19095 || cu
->per_cu
->is_dwz
);
19099 case DW_AT_main_subprogram
:
19100 main_subprogram
= DW_UNSND (&attr
);
19105 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19106 but that requires a full DIE, so instead we just
19108 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19109 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19110 + (need_ranges_base
19114 /* Value of the DW_AT_ranges attribute is the offset in the
19115 .debug_ranges section. */
19116 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19127 /* For Ada, if both the name and the linkage name appear, we prefer
19128 the latter. This lets "catch exception" work better, regardless
19129 of the order in which the name and linkage name were emitted.
19130 Really, though, this is just a workaround for the fact that gdb
19131 doesn't store both the name and the linkage name. */
19132 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19133 name
= linkage_name
;
19135 if (high_pc_relative
)
19138 if (has_low_pc_attr
&& has_high_pc_attr
)
19140 /* When using the GNU linker, .gnu.linkonce. sections are used to
19141 eliminate duplicate copies of functions and vtables and such.
19142 The linker will arbitrarily choose one and discard the others.
19143 The AT_*_pc values for such functions refer to local labels in
19144 these sections. If the section from that file was discarded, the
19145 labels are not in the output, so the relocs get a value of 0.
19146 If this is a discarded function, mark the pc bounds as invalid,
19147 so that GDB will ignore it. */
19148 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19150 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19151 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19153 complaint (_("DW_AT_low_pc %s is zero "
19154 "for DIE at %s [in module %s]"),
19155 paddress (gdbarch
, lowpc
),
19156 sect_offset_str (sect_off
),
19157 objfile_name (objfile
));
19159 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19160 else if (lowpc
>= highpc
)
19162 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19163 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19165 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19166 "for DIE at %s [in module %s]"),
19167 paddress (gdbarch
, lowpc
),
19168 paddress (gdbarch
, highpc
),
19169 sect_offset_str (sect_off
),
19170 objfile_name (objfile
));
19179 /* Find a cached partial DIE at OFFSET in CU. */
19181 struct partial_die_info
*
19182 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19184 struct partial_die_info
*lookup_die
= NULL
;
19185 struct partial_die_info
part_die (sect_off
);
19187 lookup_die
= ((struct partial_die_info
*)
19188 htab_find_with_hash (partial_dies
, &part_die
,
19189 to_underlying (sect_off
)));
19194 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19195 except in the case of .debug_types DIEs which do not reference
19196 outside their CU (they do however referencing other types via
19197 DW_FORM_ref_sig8). */
19199 static const struct cu_partial_die_info
19200 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19202 struct dwarf2_per_objfile
*dwarf2_per_objfile
19203 = cu
->per_cu
->dwarf2_per_objfile
;
19204 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19205 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19206 struct partial_die_info
*pd
= NULL
;
19208 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19209 && offset_in_cu_p (&cu
->header
, sect_off
))
19211 pd
= cu
->find_partial_die (sect_off
);
19214 /* We missed recording what we needed.
19215 Load all dies and try again. */
19216 per_cu
= cu
->per_cu
;
19220 /* TUs don't reference other CUs/TUs (except via type signatures). */
19221 if (cu
->per_cu
->is_debug_types
)
19223 error (_("Dwarf Error: Type Unit at offset %s contains"
19224 " external reference to offset %s [in module %s].\n"),
19225 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19226 bfd_get_filename (objfile
->obfd
));
19228 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19229 dwarf2_per_objfile
);
19231 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19232 load_partial_comp_unit (per_cu
);
19234 per_cu
->cu
->last_used
= 0;
19235 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19238 /* If we didn't find it, and not all dies have been loaded,
19239 load them all and try again. */
19241 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19243 per_cu
->load_all_dies
= 1;
19245 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19246 THIS_CU->cu may already be in use. So we can't just free it and
19247 replace its DIEs with the ones we read in. Instead, we leave those
19248 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19249 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19251 load_partial_comp_unit (per_cu
);
19253 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19257 internal_error (__FILE__
, __LINE__
,
19258 _("could not find partial DIE %s "
19259 "in cache [from module %s]\n"),
19260 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19261 return { per_cu
->cu
, pd
};
19264 /* See if we can figure out if the class lives in a namespace. We do
19265 this by looking for a member function; its demangled name will
19266 contain namespace info, if there is any. */
19269 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19270 struct dwarf2_cu
*cu
)
19272 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19273 what template types look like, because the demangler
19274 frequently doesn't give the same name as the debug info. We
19275 could fix this by only using the demangled name to get the
19276 prefix (but see comment in read_structure_type). */
19278 struct partial_die_info
*real_pdi
;
19279 struct partial_die_info
*child_pdi
;
19281 /* If this DIE (this DIE's specification, if any) has a parent, then
19282 we should not do this. We'll prepend the parent's fully qualified
19283 name when we create the partial symbol. */
19285 real_pdi
= struct_pdi
;
19286 while (real_pdi
->has_specification
)
19288 auto res
= find_partial_die (real_pdi
->spec_offset
,
19289 real_pdi
->spec_is_dwz
, cu
);
19290 real_pdi
= res
.pdi
;
19294 if (real_pdi
->die_parent
!= NULL
)
19297 for (child_pdi
= struct_pdi
->die_child
;
19299 child_pdi
= child_pdi
->die_sibling
)
19301 if (child_pdi
->tag
== DW_TAG_subprogram
19302 && child_pdi
->linkage_name
!= NULL
)
19304 gdb::unique_xmalloc_ptr
<char> actual_class_name
19305 (language_class_name_from_physname (cu
->language_defn
,
19306 child_pdi
->linkage_name
));
19307 if (actual_class_name
!= NULL
)
19309 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19311 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19312 actual_class_name
.get ());
19320 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19322 /* Once we've fixed up a die, there's no point in doing so again.
19323 This also avoids a memory leak if we were to call
19324 guess_partial_die_structure_name multiple times. */
19328 /* If we found a reference attribute and the DIE has no name, try
19329 to find a name in the referred to DIE. */
19331 if (name
== NULL
&& has_specification
)
19333 struct partial_die_info
*spec_die
;
19335 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19336 spec_die
= res
.pdi
;
19339 spec_die
->fixup (cu
);
19341 if (spec_die
->name
)
19343 name
= spec_die
->name
;
19345 /* Copy DW_AT_external attribute if it is set. */
19346 if (spec_die
->is_external
)
19347 is_external
= spec_die
->is_external
;
19351 /* Set default names for some unnamed DIEs. */
19353 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19354 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19356 /* If there is no parent die to provide a namespace, and there are
19357 children, see if we can determine the namespace from their linkage
19359 if (cu
->language
== language_cplus
19360 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19361 && die_parent
== NULL
19363 && (tag
== DW_TAG_class_type
19364 || tag
== DW_TAG_structure_type
19365 || tag
== DW_TAG_union_type
))
19366 guess_partial_die_structure_name (this, cu
);
19368 /* GCC might emit a nameless struct or union that has a linkage
19369 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19371 && (tag
== DW_TAG_class_type
19372 || tag
== DW_TAG_interface_type
19373 || tag
== DW_TAG_structure_type
19374 || tag
== DW_TAG_union_type
)
19375 && linkage_name
!= NULL
)
19377 gdb::unique_xmalloc_ptr
<char> demangled
19378 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19379 if (demangled
!= nullptr)
19383 /* Strip any leading namespaces/classes, keep only the base name.
19384 DW_AT_name for named DIEs does not contain the prefixes. */
19385 base
= strrchr (demangled
.get (), ':');
19386 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19389 base
= demangled
.get ();
19391 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19392 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19399 /* Read an attribute value described by an attribute form. */
19401 static const gdb_byte
*
19402 read_attribute_value (const struct die_reader_specs
*reader
,
19403 struct attribute
*attr
, unsigned form
,
19404 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19406 struct dwarf2_cu
*cu
= reader
->cu
;
19407 struct dwarf2_per_objfile
*dwarf2_per_objfile
19408 = cu
->per_cu
->dwarf2_per_objfile
;
19409 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19410 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19411 bfd
*abfd
= reader
->abfd
;
19412 struct comp_unit_head
*cu_header
= &cu
->header
;
19413 unsigned int bytes_read
;
19414 struct dwarf_block
*blk
;
19416 attr
->form
= (enum dwarf_form
) form
;
19419 case DW_FORM_ref_addr
:
19420 if (cu
->header
.version
== 2)
19421 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19423 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19424 &cu
->header
, &bytes_read
);
19425 info_ptr
+= bytes_read
;
19427 case DW_FORM_GNU_ref_alt
:
19428 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19429 info_ptr
+= bytes_read
;
19432 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19433 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19434 info_ptr
+= bytes_read
;
19436 case DW_FORM_block2
:
19437 blk
= dwarf_alloc_block (cu
);
19438 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19440 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19441 info_ptr
+= blk
->size
;
19442 DW_BLOCK (attr
) = blk
;
19444 case DW_FORM_block4
:
19445 blk
= dwarf_alloc_block (cu
);
19446 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19449 info_ptr
+= blk
->size
;
19450 DW_BLOCK (attr
) = blk
;
19452 case DW_FORM_data2
:
19453 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19456 case DW_FORM_data4
:
19457 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19460 case DW_FORM_data8
:
19461 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19464 case DW_FORM_data16
:
19465 blk
= dwarf_alloc_block (cu
);
19467 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19469 DW_BLOCK (attr
) = blk
;
19471 case DW_FORM_sec_offset
:
19472 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19473 info_ptr
+= bytes_read
;
19475 case DW_FORM_string
:
19476 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19477 DW_STRING_IS_CANONICAL (attr
) = 0;
19478 info_ptr
+= bytes_read
;
19481 if (!cu
->per_cu
->is_dwz
)
19483 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19484 abfd
, info_ptr
, cu_header
,
19486 DW_STRING_IS_CANONICAL (attr
) = 0;
19487 info_ptr
+= bytes_read
;
19491 case DW_FORM_line_strp
:
19492 if (!cu
->per_cu
->is_dwz
)
19494 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19496 cu_header
, &bytes_read
);
19497 DW_STRING_IS_CANONICAL (attr
) = 0;
19498 info_ptr
+= bytes_read
;
19502 case DW_FORM_GNU_strp_alt
:
19504 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19505 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19508 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19510 DW_STRING_IS_CANONICAL (attr
) = 0;
19511 info_ptr
+= bytes_read
;
19514 case DW_FORM_exprloc
:
19515 case DW_FORM_block
:
19516 blk
= dwarf_alloc_block (cu
);
19517 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19518 info_ptr
+= bytes_read
;
19519 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19520 info_ptr
+= blk
->size
;
19521 DW_BLOCK (attr
) = blk
;
19523 case DW_FORM_block1
:
19524 blk
= dwarf_alloc_block (cu
);
19525 blk
->size
= read_1_byte (abfd
, info_ptr
);
19527 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19528 info_ptr
+= blk
->size
;
19529 DW_BLOCK (attr
) = blk
;
19531 case DW_FORM_data1
:
19532 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19536 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19539 case DW_FORM_flag_present
:
19540 DW_UNSND (attr
) = 1;
19542 case DW_FORM_sdata
:
19543 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19544 info_ptr
+= bytes_read
;
19546 case DW_FORM_udata
:
19547 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19548 info_ptr
+= bytes_read
;
19551 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19552 + read_1_byte (abfd
, info_ptr
));
19556 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19557 + read_2_bytes (abfd
, info_ptr
));
19561 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19562 + read_4_bytes (abfd
, info_ptr
));
19566 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19567 + read_8_bytes (abfd
, info_ptr
));
19570 case DW_FORM_ref_sig8
:
19571 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19574 case DW_FORM_ref_udata
:
19575 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19576 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19577 info_ptr
+= bytes_read
;
19579 case DW_FORM_indirect
:
19580 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19581 info_ptr
+= bytes_read
;
19582 if (form
== DW_FORM_implicit_const
)
19584 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19585 info_ptr
+= bytes_read
;
19587 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19590 case DW_FORM_implicit_const
:
19591 DW_SND (attr
) = implicit_const
;
19593 case DW_FORM_addrx
:
19594 case DW_FORM_GNU_addr_index
:
19595 if (reader
->dwo_file
== NULL
)
19597 /* For now flag a hard error.
19598 Later we can turn this into a complaint. */
19599 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19600 dwarf_form_name (form
),
19601 bfd_get_filename (abfd
));
19603 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19604 info_ptr
+= bytes_read
;
19607 case DW_FORM_strx1
:
19608 case DW_FORM_strx2
:
19609 case DW_FORM_strx3
:
19610 case DW_FORM_strx4
:
19611 case DW_FORM_GNU_str_index
:
19612 if (reader
->dwo_file
== NULL
)
19614 /* For now flag a hard error.
19615 Later we can turn this into a complaint if warranted. */
19616 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19617 dwarf_form_name (form
),
19618 bfd_get_filename (abfd
));
19621 ULONGEST str_index
;
19622 if (form
== DW_FORM_strx1
)
19624 str_index
= read_1_byte (abfd
, info_ptr
);
19627 else if (form
== DW_FORM_strx2
)
19629 str_index
= read_2_bytes (abfd
, info_ptr
);
19632 else if (form
== DW_FORM_strx3
)
19634 str_index
= read_3_bytes (abfd
, info_ptr
);
19637 else if (form
== DW_FORM_strx4
)
19639 str_index
= read_4_bytes (abfd
, info_ptr
);
19644 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19645 info_ptr
+= bytes_read
;
19647 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19648 DW_STRING_IS_CANONICAL (attr
) = 0;
19652 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19653 dwarf_form_name (form
),
19654 bfd_get_filename (abfd
));
19658 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19659 attr
->form
= DW_FORM_GNU_ref_alt
;
19661 /* We have seen instances where the compiler tried to emit a byte
19662 size attribute of -1 which ended up being encoded as an unsigned
19663 0xffffffff. Although 0xffffffff is technically a valid size value,
19664 an object of this size seems pretty unlikely so we can relatively
19665 safely treat these cases as if the size attribute was invalid and
19666 treat them as zero by default. */
19667 if (attr
->name
== DW_AT_byte_size
19668 && form
== DW_FORM_data4
19669 && DW_UNSND (attr
) >= 0xffffffff)
19672 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19673 hex_string (DW_UNSND (attr
)));
19674 DW_UNSND (attr
) = 0;
19680 /* Read an attribute described by an abbreviated attribute. */
19682 static const gdb_byte
*
19683 read_attribute (const struct die_reader_specs
*reader
,
19684 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19685 const gdb_byte
*info_ptr
)
19687 attr
->name
= abbrev
->name
;
19688 return read_attribute_value (reader
, attr
, abbrev
->form
,
19689 abbrev
->implicit_const
, info_ptr
);
19692 /* Read dwarf information from a buffer. */
19694 static unsigned int
19695 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19697 return bfd_get_8 (abfd
, buf
);
19701 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19703 return bfd_get_signed_8 (abfd
, buf
);
19706 static unsigned int
19707 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19709 return bfd_get_16 (abfd
, buf
);
19713 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19715 return bfd_get_signed_16 (abfd
, buf
);
19718 static unsigned int
19719 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19721 unsigned int result
= 0;
19722 for (int i
= 0; i
< 3; ++i
)
19724 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19726 result
|= ((unsigned int) byte
<< (i
* 8));
19731 static unsigned int
19732 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19734 return bfd_get_32 (abfd
, buf
);
19738 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19740 return bfd_get_signed_32 (abfd
, buf
);
19744 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19746 return bfd_get_64 (abfd
, buf
);
19750 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19751 unsigned int *bytes_read
)
19753 struct comp_unit_head
*cu_header
= &cu
->header
;
19754 CORE_ADDR retval
= 0;
19756 if (cu_header
->signed_addr_p
)
19758 switch (cu_header
->addr_size
)
19761 retval
= bfd_get_signed_16 (abfd
, buf
);
19764 retval
= bfd_get_signed_32 (abfd
, buf
);
19767 retval
= bfd_get_signed_64 (abfd
, buf
);
19770 internal_error (__FILE__
, __LINE__
,
19771 _("read_address: bad switch, signed [in module %s]"),
19772 bfd_get_filename (abfd
));
19777 switch (cu_header
->addr_size
)
19780 retval
= bfd_get_16 (abfd
, buf
);
19783 retval
= bfd_get_32 (abfd
, buf
);
19786 retval
= bfd_get_64 (abfd
, buf
);
19789 internal_error (__FILE__
, __LINE__
,
19790 _("read_address: bad switch, "
19791 "unsigned [in module %s]"),
19792 bfd_get_filename (abfd
));
19796 *bytes_read
= cu_header
->addr_size
;
19800 /* Read the initial length from a section. The (draft) DWARF 3
19801 specification allows the initial length to take up either 4 bytes
19802 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19803 bytes describe the length and all offsets will be 8 bytes in length
19806 An older, non-standard 64-bit format is also handled by this
19807 function. The older format in question stores the initial length
19808 as an 8-byte quantity without an escape value. Lengths greater
19809 than 2^32 aren't very common which means that the initial 4 bytes
19810 is almost always zero. Since a length value of zero doesn't make
19811 sense for the 32-bit format, this initial zero can be considered to
19812 be an escape value which indicates the presence of the older 64-bit
19813 format. As written, the code can't detect (old format) lengths
19814 greater than 4GB. If it becomes necessary to handle lengths
19815 somewhat larger than 4GB, we could allow other small values (such
19816 as the non-sensical values of 1, 2, and 3) to also be used as
19817 escape values indicating the presence of the old format.
19819 The value returned via bytes_read should be used to increment the
19820 relevant pointer after calling read_initial_length().
19822 [ Note: read_initial_length() and read_offset() are based on the
19823 document entitled "DWARF Debugging Information Format", revision
19824 3, draft 8, dated November 19, 2001. This document was obtained
19827 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19829 This document is only a draft and is subject to change. (So beware.)
19831 Details regarding the older, non-standard 64-bit format were
19832 determined empirically by examining 64-bit ELF files produced by
19833 the SGI toolchain on an IRIX 6.5 machine.
19835 - Kevin, July 16, 2002
19839 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19841 LONGEST length
= bfd_get_32 (abfd
, buf
);
19843 if (length
== 0xffffffff)
19845 length
= bfd_get_64 (abfd
, buf
+ 4);
19848 else if (length
== 0)
19850 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19851 length
= bfd_get_64 (abfd
, buf
);
19862 /* Cover function for read_initial_length.
19863 Returns the length of the object at BUF, and stores the size of the
19864 initial length in *BYTES_READ and stores the size that offsets will be in
19866 If the initial length size is not equivalent to that specified in
19867 CU_HEADER then issue a complaint.
19868 This is useful when reading non-comp-unit headers. */
19871 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19872 const struct comp_unit_head
*cu_header
,
19873 unsigned int *bytes_read
,
19874 unsigned int *offset_size
)
19876 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19878 gdb_assert (cu_header
->initial_length_size
== 4
19879 || cu_header
->initial_length_size
== 8
19880 || cu_header
->initial_length_size
== 12);
19882 if (cu_header
->initial_length_size
!= *bytes_read
)
19883 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19885 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19889 /* Read an offset from the data stream. The size of the offset is
19890 given by cu_header->offset_size. */
19893 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19894 const struct comp_unit_head
*cu_header
,
19895 unsigned int *bytes_read
)
19897 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19899 *bytes_read
= cu_header
->offset_size
;
19903 /* Read an offset from the data stream. */
19906 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19908 LONGEST retval
= 0;
19910 switch (offset_size
)
19913 retval
= bfd_get_32 (abfd
, buf
);
19916 retval
= bfd_get_64 (abfd
, buf
);
19919 internal_error (__FILE__
, __LINE__
,
19920 _("read_offset_1: bad switch [in module %s]"),
19921 bfd_get_filename (abfd
));
19927 static const gdb_byte
*
19928 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19930 /* If the size of a host char is 8 bits, we can return a pointer
19931 to the buffer, otherwise we have to copy the data to a buffer
19932 allocated on the temporary obstack. */
19933 gdb_assert (HOST_CHAR_BIT
== 8);
19937 static const char *
19938 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19939 unsigned int *bytes_read_ptr
)
19941 /* If the size of a host char is 8 bits, we can return a pointer
19942 to the string, otherwise we have to copy the string to a buffer
19943 allocated on the temporary obstack. */
19944 gdb_assert (HOST_CHAR_BIT
== 8);
19947 *bytes_read_ptr
= 1;
19950 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19951 return (const char *) buf
;
19954 /* Return pointer to string at section SECT offset STR_OFFSET with error
19955 reporting strings FORM_NAME and SECT_NAME. */
19957 static const char *
19958 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19959 bfd
*abfd
, LONGEST str_offset
,
19960 struct dwarf2_section_info
*sect
,
19961 const char *form_name
,
19962 const char *sect_name
)
19964 dwarf2_read_section (objfile
, sect
);
19965 if (sect
->buffer
== NULL
)
19966 error (_("%s used without %s section [in module %s]"),
19967 form_name
, sect_name
, bfd_get_filename (abfd
));
19968 if (str_offset
>= sect
->size
)
19969 error (_("%s pointing outside of %s section [in module %s]"),
19970 form_name
, sect_name
, bfd_get_filename (abfd
));
19971 gdb_assert (HOST_CHAR_BIT
== 8);
19972 if (sect
->buffer
[str_offset
] == '\0')
19974 return (const char *) (sect
->buffer
+ str_offset
);
19977 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19979 static const char *
19980 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19981 bfd
*abfd
, LONGEST str_offset
)
19983 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19985 &dwarf2_per_objfile
->str
,
19986 "DW_FORM_strp", ".debug_str");
19989 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19991 static const char *
19992 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19993 bfd
*abfd
, LONGEST str_offset
)
19995 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19997 &dwarf2_per_objfile
->line_str
,
19998 "DW_FORM_line_strp",
19999 ".debug_line_str");
20002 /* Read a string at offset STR_OFFSET in the .debug_str section from
20003 the .dwz file DWZ. Throw an error if the offset is too large. If
20004 the string consists of a single NUL byte, return NULL; otherwise
20005 return a pointer to the string. */
20007 static const char *
20008 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20009 LONGEST str_offset
)
20011 dwarf2_read_section (objfile
, &dwz
->str
);
20013 if (dwz
->str
.buffer
== NULL
)
20014 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20015 "section [in module %s]"),
20016 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20017 if (str_offset
>= dwz
->str
.size
)
20018 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20019 ".debug_str section [in module %s]"),
20020 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20021 gdb_assert (HOST_CHAR_BIT
== 8);
20022 if (dwz
->str
.buffer
[str_offset
] == '\0')
20024 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20027 /* Return pointer to string at .debug_str offset as read from BUF.
20028 BUF is assumed to be in a compilation unit described by CU_HEADER.
20029 Return *BYTES_READ_PTR count of bytes read from BUF. */
20031 static const char *
20032 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20033 const gdb_byte
*buf
,
20034 const struct comp_unit_head
*cu_header
,
20035 unsigned int *bytes_read_ptr
)
20037 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20039 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20042 /* Return pointer to string at .debug_line_str offset as read from BUF.
20043 BUF is assumed to be in a compilation unit described by CU_HEADER.
20044 Return *BYTES_READ_PTR count of bytes read from BUF. */
20046 static const char *
20047 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20048 bfd
*abfd
, const gdb_byte
*buf
,
20049 const struct comp_unit_head
*cu_header
,
20050 unsigned int *bytes_read_ptr
)
20052 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20054 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20059 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20060 unsigned int *bytes_read_ptr
)
20063 unsigned int num_read
;
20065 unsigned char byte
;
20072 byte
= bfd_get_8 (abfd
, buf
);
20075 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20076 if ((byte
& 128) == 0)
20082 *bytes_read_ptr
= num_read
;
20087 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20088 unsigned int *bytes_read_ptr
)
20091 int shift
, num_read
;
20092 unsigned char byte
;
20099 byte
= bfd_get_8 (abfd
, buf
);
20102 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20104 if ((byte
& 128) == 0)
20109 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20110 result
|= -(((ULONGEST
) 1) << shift
);
20111 *bytes_read_ptr
= num_read
;
20115 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20116 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20117 ADDR_SIZE is the size of addresses from the CU header. */
20120 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20121 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20124 bfd
*abfd
= objfile
->obfd
;
20125 const gdb_byte
*info_ptr
;
20127 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20128 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20129 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20130 objfile_name (objfile
));
20131 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20132 error (_("DW_FORM_addr_index pointing outside of "
20133 ".debug_addr section [in module %s]"),
20134 objfile_name (objfile
));
20135 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20136 + addr_base
+ addr_index
* addr_size
);
20137 if (addr_size
== 4)
20138 return bfd_get_32 (abfd
, info_ptr
);
20140 return bfd_get_64 (abfd
, info_ptr
);
20143 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20146 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20148 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20149 cu
->addr_base
, cu
->header
.addr_size
);
20152 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20155 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20156 unsigned int *bytes_read
)
20158 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20159 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20161 return read_addr_index (cu
, addr_index
);
20164 /* Data structure to pass results from dwarf2_read_addr_index_reader
20165 back to dwarf2_read_addr_index. */
20167 struct dwarf2_read_addr_index_data
20169 ULONGEST addr_base
;
20173 /* die_reader_func for dwarf2_read_addr_index. */
20176 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20177 const gdb_byte
*info_ptr
,
20178 struct die_info
*comp_unit_die
,
20182 struct dwarf2_cu
*cu
= reader
->cu
;
20183 struct dwarf2_read_addr_index_data
*aidata
=
20184 (struct dwarf2_read_addr_index_data
*) data
;
20186 aidata
->addr_base
= cu
->addr_base
;
20187 aidata
->addr_size
= cu
->header
.addr_size
;
20190 /* Given an index in .debug_addr, fetch the value.
20191 NOTE: This can be called during dwarf expression evaluation,
20192 long after the debug information has been read, and thus per_cu->cu
20193 may no longer exist. */
20196 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20197 unsigned int addr_index
)
20199 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20200 struct dwarf2_cu
*cu
= per_cu
->cu
;
20201 ULONGEST addr_base
;
20204 /* We need addr_base and addr_size.
20205 If we don't have PER_CU->cu, we have to get it.
20206 Nasty, but the alternative is storing the needed info in PER_CU,
20207 which at this point doesn't seem justified: it's not clear how frequently
20208 it would get used and it would increase the size of every PER_CU.
20209 Entry points like dwarf2_per_cu_addr_size do a similar thing
20210 so we're not in uncharted territory here.
20211 Alas we need to be a bit more complicated as addr_base is contained
20214 We don't need to read the entire CU(/TU).
20215 We just need the header and top level die.
20217 IWBN to use the aging mechanism to let us lazily later discard the CU.
20218 For now we skip this optimization. */
20222 addr_base
= cu
->addr_base
;
20223 addr_size
= cu
->header
.addr_size
;
20227 struct dwarf2_read_addr_index_data aidata
;
20229 /* Note: We can't use init_cutu_and_read_dies_simple here,
20230 we need addr_base. */
20231 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20232 dwarf2_read_addr_index_reader
, &aidata
);
20233 addr_base
= aidata
.addr_base
;
20234 addr_size
= aidata
.addr_size
;
20237 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20241 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20242 This is only used by the Fission support. */
20244 static const char *
20245 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20247 struct dwarf2_cu
*cu
= reader
->cu
;
20248 struct dwarf2_per_objfile
*dwarf2_per_objfile
20249 = cu
->per_cu
->dwarf2_per_objfile
;
20250 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20251 const char *objf_name
= objfile_name (objfile
);
20252 bfd
*abfd
= objfile
->obfd
;
20253 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20254 struct dwarf2_section_info
*str_offsets_section
=
20255 &reader
->dwo_file
->sections
.str_offsets
;
20256 const gdb_byte
*info_ptr
;
20257 ULONGEST str_offset
;
20258 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20260 dwarf2_read_section (objfile
, str_section
);
20261 dwarf2_read_section (objfile
, str_offsets_section
);
20262 if (str_section
->buffer
== NULL
)
20263 error (_("%s used without .debug_str.dwo section"
20264 " in CU at offset %s [in module %s]"),
20265 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20266 if (str_offsets_section
->buffer
== NULL
)
20267 error (_("%s used without .debug_str_offsets.dwo section"
20268 " in CU at offset %s [in module %s]"),
20269 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20270 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20271 error (_("%s pointing outside of .debug_str_offsets.dwo"
20272 " section in CU at offset %s [in module %s]"),
20273 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20274 info_ptr
= (str_offsets_section
->buffer
20275 + str_index
* cu
->header
.offset_size
);
20276 if (cu
->header
.offset_size
== 4)
20277 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20279 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20280 if (str_offset
>= str_section
->size
)
20281 error (_("Offset from %s pointing outside of"
20282 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20283 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20284 return (const char *) (str_section
->buffer
+ str_offset
);
20287 /* Return the length of an LEB128 number in BUF. */
20290 leb128_size (const gdb_byte
*buf
)
20292 const gdb_byte
*begin
= buf
;
20298 if ((byte
& 128) == 0)
20299 return buf
- begin
;
20304 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20313 cu
->language
= language_c
;
20316 case DW_LANG_C_plus_plus
:
20317 case DW_LANG_C_plus_plus_11
:
20318 case DW_LANG_C_plus_plus_14
:
20319 cu
->language
= language_cplus
;
20322 cu
->language
= language_d
;
20324 case DW_LANG_Fortran77
:
20325 case DW_LANG_Fortran90
:
20326 case DW_LANG_Fortran95
:
20327 case DW_LANG_Fortran03
:
20328 case DW_LANG_Fortran08
:
20329 cu
->language
= language_fortran
;
20332 cu
->language
= language_go
;
20334 case DW_LANG_Mips_Assembler
:
20335 cu
->language
= language_asm
;
20337 case DW_LANG_Ada83
:
20338 case DW_LANG_Ada95
:
20339 cu
->language
= language_ada
;
20341 case DW_LANG_Modula2
:
20342 cu
->language
= language_m2
;
20344 case DW_LANG_Pascal83
:
20345 cu
->language
= language_pascal
;
20348 cu
->language
= language_objc
;
20351 case DW_LANG_Rust_old
:
20352 cu
->language
= language_rust
;
20354 case DW_LANG_Cobol74
:
20355 case DW_LANG_Cobol85
:
20357 cu
->language
= language_minimal
;
20360 cu
->language_defn
= language_def (cu
->language
);
20363 /* Return the named attribute or NULL if not there. */
20365 static struct attribute
*
20366 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20371 struct attribute
*spec
= NULL
;
20373 for (i
= 0; i
< die
->num_attrs
; ++i
)
20375 if (die
->attrs
[i
].name
== name
)
20376 return &die
->attrs
[i
];
20377 if (die
->attrs
[i
].name
== DW_AT_specification
20378 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20379 spec
= &die
->attrs
[i
];
20385 die
= follow_die_ref (die
, spec
, &cu
);
20391 /* Return the named attribute or NULL if not there,
20392 but do not follow DW_AT_specification, etc.
20393 This is for use in contexts where we're reading .debug_types dies.
20394 Following DW_AT_specification, DW_AT_abstract_origin will take us
20395 back up the chain, and we want to go down. */
20397 static struct attribute
*
20398 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20402 for (i
= 0; i
< die
->num_attrs
; ++i
)
20403 if (die
->attrs
[i
].name
== name
)
20404 return &die
->attrs
[i
];
20409 /* Return the string associated with a string-typed attribute, or NULL if it
20410 is either not found or is of an incorrect type. */
20412 static const char *
20413 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20415 struct attribute
*attr
;
20416 const char *str
= NULL
;
20418 attr
= dwarf2_attr (die
, name
, cu
);
20422 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20423 || attr
->form
== DW_FORM_string
20424 || attr
->form
== DW_FORM_strx
20425 || attr
->form
== DW_FORM_strx1
20426 || attr
->form
== DW_FORM_strx2
20427 || attr
->form
== DW_FORM_strx3
20428 || attr
->form
== DW_FORM_strx4
20429 || attr
->form
== DW_FORM_GNU_str_index
20430 || attr
->form
== DW_FORM_GNU_strp_alt
)
20431 str
= DW_STRING (attr
);
20433 complaint (_("string type expected for attribute %s for "
20434 "DIE at %s in module %s"),
20435 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20436 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20442 /* Return the dwo name or NULL if not present. If present, it is in either
20443 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20444 static const char *
20445 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20447 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20448 if (dwo_name
== nullptr)
20449 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20453 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20454 and holds a non-zero value. This function should only be used for
20455 DW_FORM_flag or DW_FORM_flag_present attributes. */
20458 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20460 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20462 return (attr
&& DW_UNSND (attr
));
20466 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20468 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20469 which value is non-zero. However, we have to be careful with
20470 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20471 (via dwarf2_flag_true_p) follows this attribute. So we may
20472 end up accidently finding a declaration attribute that belongs
20473 to a different DIE referenced by the specification attribute,
20474 even though the given DIE does not have a declaration attribute. */
20475 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20476 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20479 /* Return the die giving the specification for DIE, if there is
20480 one. *SPEC_CU is the CU containing DIE on input, and the CU
20481 containing the return value on output. If there is no
20482 specification, but there is an abstract origin, that is
20485 static struct die_info
*
20486 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20488 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20491 if (spec_attr
== NULL
)
20492 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20494 if (spec_attr
== NULL
)
20497 return follow_die_ref (die
, spec_attr
, spec_cu
);
20500 /* Stub for free_line_header to match void * callback types. */
20503 free_line_header_voidp (void *arg
)
20505 struct line_header
*lh
= (struct line_header
*) arg
;
20511 line_header::add_include_dir (const char *include_dir
)
20513 if (dwarf_line_debug
>= 2)
20517 new_size
= m_include_dirs
.size ();
20519 new_size
= m_include_dirs
.size () + 1;
20520 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20521 new_size
, include_dir
);
20523 m_include_dirs
.push_back (include_dir
);
20527 line_header::add_file_name (const char *name
,
20529 unsigned int mod_time
,
20530 unsigned int length
)
20532 if (dwarf_line_debug
>= 2)
20536 new_size
= file_names_size ();
20538 new_size
= file_names_size () + 1;
20539 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20542 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20545 /* A convenience function to find the proper .debug_line section for a CU. */
20547 static struct dwarf2_section_info
*
20548 get_debug_line_section (struct dwarf2_cu
*cu
)
20550 struct dwarf2_section_info
*section
;
20551 struct dwarf2_per_objfile
*dwarf2_per_objfile
20552 = cu
->per_cu
->dwarf2_per_objfile
;
20554 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20556 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20557 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20558 else if (cu
->per_cu
->is_dwz
)
20560 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20562 section
= &dwz
->line
;
20565 section
= &dwarf2_per_objfile
->line
;
20570 /* Read directory or file name entry format, starting with byte of
20571 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20572 entries count and the entries themselves in the described entry
20576 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20577 bfd
*abfd
, const gdb_byte
**bufp
,
20578 struct line_header
*lh
,
20579 const struct comp_unit_head
*cu_header
,
20580 void (*callback
) (struct line_header
*lh
,
20583 unsigned int mod_time
,
20584 unsigned int length
))
20586 gdb_byte format_count
, formati
;
20587 ULONGEST data_count
, datai
;
20588 const gdb_byte
*buf
= *bufp
;
20589 const gdb_byte
*format_header_data
;
20590 unsigned int bytes_read
;
20592 format_count
= read_1_byte (abfd
, buf
);
20594 format_header_data
= buf
;
20595 for (formati
= 0; formati
< format_count
; formati
++)
20597 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20599 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20603 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20605 for (datai
= 0; datai
< data_count
; datai
++)
20607 const gdb_byte
*format
= format_header_data
;
20608 struct file_entry fe
;
20610 for (formati
= 0; formati
< format_count
; formati
++)
20612 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20613 format
+= bytes_read
;
20615 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20616 format
+= bytes_read
;
20618 gdb::optional
<const char *> string
;
20619 gdb::optional
<unsigned int> uint
;
20623 case DW_FORM_string
:
20624 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20628 case DW_FORM_line_strp
:
20629 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20636 case DW_FORM_data1
:
20637 uint
.emplace (read_1_byte (abfd
, buf
));
20641 case DW_FORM_data2
:
20642 uint
.emplace (read_2_bytes (abfd
, buf
));
20646 case DW_FORM_data4
:
20647 uint
.emplace (read_4_bytes (abfd
, buf
));
20651 case DW_FORM_data8
:
20652 uint
.emplace (read_8_bytes (abfd
, buf
));
20656 case DW_FORM_data16
:
20657 /* This is used for MD5, but file_entry does not record MD5s. */
20661 case DW_FORM_udata
:
20662 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20666 case DW_FORM_block
:
20667 /* It is valid only for DW_LNCT_timestamp which is ignored by
20672 switch (content_type
)
20675 if (string
.has_value ())
20678 case DW_LNCT_directory_index
:
20679 if (uint
.has_value ())
20680 fe
.d_index
= (dir_index
) *uint
;
20682 case DW_LNCT_timestamp
:
20683 if (uint
.has_value ())
20684 fe
.mod_time
= *uint
;
20687 if (uint
.has_value ())
20693 complaint (_("Unknown format content type %s"),
20694 pulongest (content_type
));
20698 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20704 /* Read the statement program header starting at OFFSET in
20705 .debug_line, or .debug_line.dwo. Return a pointer
20706 to a struct line_header, allocated using xmalloc.
20707 Returns NULL if there is a problem reading the header, e.g., if it
20708 has a version we don't understand.
20710 NOTE: the strings in the include directory and file name tables of
20711 the returned object point into the dwarf line section buffer,
20712 and must not be freed. */
20714 static line_header_up
20715 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20717 const gdb_byte
*line_ptr
;
20718 unsigned int bytes_read
, offset_size
;
20720 const char *cur_dir
, *cur_file
;
20721 struct dwarf2_section_info
*section
;
20723 struct dwarf2_per_objfile
*dwarf2_per_objfile
20724 = cu
->per_cu
->dwarf2_per_objfile
;
20726 section
= get_debug_line_section (cu
);
20727 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20728 if (section
->buffer
== NULL
)
20730 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20731 complaint (_("missing .debug_line.dwo section"));
20733 complaint (_("missing .debug_line section"));
20737 /* We can't do this until we know the section is non-empty.
20738 Only then do we know we have such a section. */
20739 abfd
= get_section_bfd_owner (section
);
20741 /* Make sure that at least there's room for the total_length field.
20742 That could be 12 bytes long, but we're just going to fudge that. */
20743 if (to_underlying (sect_off
) + 4 >= section
->size
)
20745 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20749 line_header_up
lh (new line_header ());
20751 lh
->sect_off
= sect_off
;
20752 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20754 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20756 /* Read in the header. */
20758 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20759 &bytes_read
, &offset_size
);
20760 line_ptr
+= bytes_read
;
20762 const gdb_byte
*start_here
= line_ptr
;
20764 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20766 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20769 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20770 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20772 if (lh
->version
> 5)
20774 /* This is a version we don't understand. The format could have
20775 changed in ways we don't handle properly so just punt. */
20776 complaint (_("unsupported version in .debug_line section"));
20779 if (lh
->version
>= 5)
20781 gdb_byte segment_selector_size
;
20783 /* Skip address size. */
20784 read_1_byte (abfd
, line_ptr
);
20787 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20789 if (segment_selector_size
!= 0)
20791 complaint (_("unsupported segment selector size %u "
20792 "in .debug_line section"),
20793 segment_selector_size
);
20797 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20798 line_ptr
+= offset_size
;
20799 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20800 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20802 if (lh
->version
>= 4)
20804 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20808 lh
->maximum_ops_per_instruction
= 1;
20810 if (lh
->maximum_ops_per_instruction
== 0)
20812 lh
->maximum_ops_per_instruction
= 1;
20813 complaint (_("invalid maximum_ops_per_instruction "
20814 "in `.debug_line' section"));
20817 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20819 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20821 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20823 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20825 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20827 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20828 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20830 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20834 if (lh
->version
>= 5)
20836 /* Read directory table. */
20837 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20839 [] (struct line_header
*header
, const char *name
,
20840 dir_index d_index
, unsigned int mod_time
,
20841 unsigned int length
)
20843 header
->add_include_dir (name
);
20846 /* Read file name table. */
20847 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20849 [] (struct line_header
*header
, const char *name
,
20850 dir_index d_index
, unsigned int mod_time
,
20851 unsigned int length
)
20853 header
->add_file_name (name
, d_index
, mod_time
, length
);
20858 /* Read directory table. */
20859 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20861 line_ptr
+= bytes_read
;
20862 lh
->add_include_dir (cur_dir
);
20864 line_ptr
+= bytes_read
;
20866 /* Read file name table. */
20867 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20869 unsigned int mod_time
, length
;
20872 line_ptr
+= bytes_read
;
20873 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20874 line_ptr
+= bytes_read
;
20875 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20876 line_ptr
+= bytes_read
;
20877 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20878 line_ptr
+= bytes_read
;
20880 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20882 line_ptr
+= bytes_read
;
20885 if (line_ptr
> (section
->buffer
+ section
->size
))
20886 complaint (_("line number info header doesn't "
20887 "fit in `.debug_line' section"));
20892 /* Subroutine of dwarf_decode_lines to simplify it.
20893 Return the file name of the psymtab for the given file_entry.
20894 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20895 If space for the result is malloc'd, *NAME_HOLDER will be set.
20896 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20898 static const char *
20899 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20900 const struct partial_symtab
*pst
,
20901 const char *comp_dir
,
20902 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20904 const char *include_name
= fe
.name
;
20905 const char *include_name_to_compare
= include_name
;
20906 const char *pst_filename
;
20909 const char *dir_name
= fe
.include_dir (lh
);
20911 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20912 if (!IS_ABSOLUTE_PATH (include_name
)
20913 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20915 /* Avoid creating a duplicate psymtab for PST.
20916 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20917 Before we do the comparison, however, we need to account
20918 for DIR_NAME and COMP_DIR.
20919 First prepend dir_name (if non-NULL). If we still don't
20920 have an absolute path prepend comp_dir (if non-NULL).
20921 However, the directory we record in the include-file's
20922 psymtab does not contain COMP_DIR (to match the
20923 corresponding symtab(s)).
20928 bash$ gcc -g ./hello.c
20929 include_name = "hello.c"
20931 DW_AT_comp_dir = comp_dir = "/tmp"
20932 DW_AT_name = "./hello.c"
20936 if (dir_name
!= NULL
)
20938 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20939 include_name
, (char *) NULL
));
20940 include_name
= name_holder
->get ();
20941 include_name_to_compare
= include_name
;
20943 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20945 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20946 include_name
, (char *) NULL
));
20947 include_name_to_compare
= hold_compare
.get ();
20951 pst_filename
= pst
->filename
;
20952 gdb::unique_xmalloc_ptr
<char> copied_name
;
20953 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20955 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20956 pst_filename
, (char *) NULL
));
20957 pst_filename
= copied_name
.get ();
20960 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20964 return include_name
;
20967 /* State machine to track the state of the line number program. */
20969 class lnp_state_machine
20972 /* Initialize a machine state for the start of a line number
20974 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20975 bool record_lines_p
);
20977 file_entry
*current_file ()
20979 /* lh->file_names is 0-based, but the file name numbers in the
20980 statement program are 1-based. */
20981 return m_line_header
->file_name_at (m_file
);
20984 /* Record the line in the state machine. END_SEQUENCE is true if
20985 we're processing the end of a sequence. */
20986 void record_line (bool end_sequence
);
20988 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20989 nop-out rest of the lines in this sequence. */
20990 void check_line_address (struct dwarf2_cu
*cu
,
20991 const gdb_byte
*line_ptr
,
20992 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20994 void handle_set_discriminator (unsigned int discriminator
)
20996 m_discriminator
= discriminator
;
20997 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21000 /* Handle DW_LNE_set_address. */
21001 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21004 address
+= baseaddr
;
21005 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21008 /* Handle DW_LNS_advance_pc. */
21009 void handle_advance_pc (CORE_ADDR adjust
);
21011 /* Handle a special opcode. */
21012 void handle_special_opcode (unsigned char op_code
);
21014 /* Handle DW_LNS_advance_line. */
21015 void handle_advance_line (int line_delta
)
21017 advance_line (line_delta
);
21020 /* Handle DW_LNS_set_file. */
21021 void handle_set_file (file_name_index file
);
21023 /* Handle DW_LNS_negate_stmt. */
21024 void handle_negate_stmt ()
21026 m_is_stmt
= !m_is_stmt
;
21029 /* Handle DW_LNS_const_add_pc. */
21030 void handle_const_add_pc ();
21032 /* Handle DW_LNS_fixed_advance_pc. */
21033 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21035 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21039 /* Handle DW_LNS_copy. */
21040 void handle_copy ()
21042 record_line (false);
21043 m_discriminator
= 0;
21046 /* Handle DW_LNE_end_sequence. */
21047 void handle_end_sequence ()
21049 m_currently_recording_lines
= true;
21053 /* Advance the line by LINE_DELTA. */
21054 void advance_line (int line_delta
)
21056 m_line
+= line_delta
;
21058 if (line_delta
!= 0)
21059 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21062 struct dwarf2_cu
*m_cu
;
21064 gdbarch
*m_gdbarch
;
21066 /* True if we're recording lines.
21067 Otherwise we're building partial symtabs and are just interested in
21068 finding include files mentioned by the line number program. */
21069 bool m_record_lines_p
;
21071 /* The line number header. */
21072 line_header
*m_line_header
;
21074 /* These are part of the standard DWARF line number state machine,
21075 and initialized according to the DWARF spec. */
21077 unsigned char m_op_index
= 0;
21078 /* The line table index of the current file. */
21079 file_name_index m_file
= 1;
21080 unsigned int m_line
= 1;
21082 /* These are initialized in the constructor. */
21084 CORE_ADDR m_address
;
21086 unsigned int m_discriminator
;
21088 /* Additional bits of state we need to track. */
21090 /* The last file that we called dwarf2_start_subfile for.
21091 This is only used for TLLs. */
21092 unsigned int m_last_file
= 0;
21093 /* The last file a line number was recorded for. */
21094 struct subfile
*m_last_subfile
= NULL
;
21096 /* When true, record the lines we decode. */
21097 bool m_currently_recording_lines
= false;
21099 /* The last line number that was recorded, used to coalesce
21100 consecutive entries for the same line. This can happen, for
21101 example, when discriminators are present. PR 17276. */
21102 unsigned int m_last_line
= 0;
21103 bool m_line_has_non_zero_discriminator
= false;
21107 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21109 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21110 / m_line_header
->maximum_ops_per_instruction
)
21111 * m_line_header
->minimum_instruction_length
);
21112 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21113 m_op_index
= ((m_op_index
+ adjust
)
21114 % m_line_header
->maximum_ops_per_instruction
);
21118 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21120 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21121 CORE_ADDR addr_adj
= (((m_op_index
21122 + (adj_opcode
/ m_line_header
->line_range
))
21123 / m_line_header
->maximum_ops_per_instruction
)
21124 * m_line_header
->minimum_instruction_length
);
21125 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21126 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21127 % m_line_header
->maximum_ops_per_instruction
);
21129 int line_delta
= (m_line_header
->line_base
21130 + (adj_opcode
% m_line_header
->line_range
));
21131 advance_line (line_delta
);
21132 record_line (false);
21133 m_discriminator
= 0;
21137 lnp_state_machine::handle_set_file (file_name_index file
)
21141 const file_entry
*fe
= current_file ();
21143 dwarf2_debug_line_missing_file_complaint ();
21144 else if (m_record_lines_p
)
21146 const char *dir
= fe
->include_dir (m_line_header
);
21148 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21149 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21150 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21155 lnp_state_machine::handle_const_add_pc ()
21158 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21161 = (((m_op_index
+ adjust
)
21162 / m_line_header
->maximum_ops_per_instruction
)
21163 * m_line_header
->minimum_instruction_length
);
21165 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21166 m_op_index
= ((m_op_index
+ adjust
)
21167 % m_line_header
->maximum_ops_per_instruction
);
21170 /* Return non-zero if we should add LINE to the line number table.
21171 LINE is the line to add, LAST_LINE is the last line that was added,
21172 LAST_SUBFILE is the subfile for LAST_LINE.
21173 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21174 had a non-zero discriminator.
21176 We have to be careful in the presence of discriminators.
21177 E.g., for this line:
21179 for (i = 0; i < 100000; i++);
21181 clang can emit four line number entries for that one line,
21182 each with a different discriminator.
21183 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21185 However, we want gdb to coalesce all four entries into one.
21186 Otherwise the user could stepi into the middle of the line and
21187 gdb would get confused about whether the pc really was in the
21188 middle of the line.
21190 Things are further complicated by the fact that two consecutive
21191 line number entries for the same line is a heuristic used by gcc
21192 to denote the end of the prologue. So we can't just discard duplicate
21193 entries, we have to be selective about it. The heuristic we use is
21194 that we only collapse consecutive entries for the same line if at least
21195 one of those entries has a non-zero discriminator. PR 17276.
21197 Note: Addresses in the line number state machine can never go backwards
21198 within one sequence, thus this coalescing is ok. */
21201 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21202 unsigned int line
, unsigned int last_line
,
21203 int line_has_non_zero_discriminator
,
21204 struct subfile
*last_subfile
)
21206 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21208 if (line
!= last_line
)
21210 /* Same line for the same file that we've seen already.
21211 As a last check, for pr 17276, only record the line if the line
21212 has never had a non-zero discriminator. */
21213 if (!line_has_non_zero_discriminator
)
21218 /* Use the CU's builder to record line number LINE beginning at
21219 address ADDRESS in the line table of subfile SUBFILE. */
21222 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21223 unsigned int line
, CORE_ADDR address
,
21224 struct dwarf2_cu
*cu
)
21226 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21228 if (dwarf_line_debug
)
21230 fprintf_unfiltered (gdb_stdlog
,
21231 "Recording line %u, file %s, address %s\n",
21232 line
, lbasename (subfile
->name
),
21233 paddress (gdbarch
, address
));
21237 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21240 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21241 Mark the end of a set of line number records.
21242 The arguments are the same as for dwarf_record_line_1.
21243 If SUBFILE is NULL the request is ignored. */
21246 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21247 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21249 if (subfile
== NULL
)
21252 if (dwarf_line_debug
)
21254 fprintf_unfiltered (gdb_stdlog
,
21255 "Finishing current line, file %s, address %s\n",
21256 lbasename (subfile
->name
),
21257 paddress (gdbarch
, address
));
21260 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21264 lnp_state_machine::record_line (bool end_sequence
)
21266 if (dwarf_line_debug
)
21268 fprintf_unfiltered (gdb_stdlog
,
21269 "Processing actual line %u: file %u,"
21270 " address %s, is_stmt %u, discrim %u\n",
21272 paddress (m_gdbarch
, m_address
),
21273 m_is_stmt
, m_discriminator
);
21276 file_entry
*fe
= current_file ();
21279 dwarf2_debug_line_missing_file_complaint ();
21280 /* For now we ignore lines not starting on an instruction boundary.
21281 But not when processing end_sequence for compatibility with the
21282 previous version of the code. */
21283 else if (m_op_index
== 0 || end_sequence
)
21285 fe
->included_p
= 1;
21286 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21288 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21291 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21292 m_currently_recording_lines
? m_cu
: nullptr);
21297 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21298 m_line_has_non_zero_discriminator
,
21301 buildsym_compunit
*builder
= m_cu
->get_builder ();
21302 dwarf_record_line_1 (m_gdbarch
,
21303 builder
->get_current_subfile (),
21305 m_currently_recording_lines
? m_cu
: nullptr);
21307 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21308 m_last_line
= m_line
;
21314 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21315 line_header
*lh
, bool record_lines_p
)
21319 m_record_lines_p
= record_lines_p
;
21320 m_line_header
= lh
;
21322 m_currently_recording_lines
= true;
21324 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21325 was a line entry for it so that the backend has a chance to adjust it
21326 and also record it in case it needs it. This is currently used by MIPS
21327 code, cf. `mips_adjust_dwarf2_line'. */
21328 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21329 m_is_stmt
= lh
->default_is_stmt
;
21330 m_discriminator
= 0;
21334 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21335 const gdb_byte
*line_ptr
,
21336 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21338 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21339 the pc range of the CU. However, we restrict the test to only ADDRESS
21340 values of zero to preserve GDB's previous behaviour which is to handle
21341 the specific case of a function being GC'd by the linker. */
21343 if (address
== 0 && address
< unrelocated_lowpc
)
21345 /* This line table is for a function which has been
21346 GCd by the linker. Ignore it. PR gdb/12528 */
21348 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21349 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21351 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21352 line_offset
, objfile_name (objfile
));
21353 m_currently_recording_lines
= false;
21354 /* Note: m_currently_recording_lines is left as false until we see
21355 DW_LNE_end_sequence. */
21359 /* Subroutine of dwarf_decode_lines to simplify it.
21360 Process the line number information in LH.
21361 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21362 program in order to set included_p for every referenced header. */
21365 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21366 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21368 const gdb_byte
*line_ptr
, *extended_end
;
21369 const gdb_byte
*line_end
;
21370 unsigned int bytes_read
, extended_len
;
21371 unsigned char op_code
, extended_op
;
21372 CORE_ADDR baseaddr
;
21373 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21374 bfd
*abfd
= objfile
->obfd
;
21375 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21376 /* True if we're recording line info (as opposed to building partial
21377 symtabs and just interested in finding include files mentioned by
21378 the line number program). */
21379 bool record_lines_p
= !decode_for_pst_p
;
21381 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21383 line_ptr
= lh
->statement_program_start
;
21384 line_end
= lh
->statement_program_end
;
21386 /* Read the statement sequences until there's nothing left. */
21387 while (line_ptr
< line_end
)
21389 /* The DWARF line number program state machine. Reset the state
21390 machine at the start of each sequence. */
21391 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21392 bool end_sequence
= false;
21394 if (record_lines_p
)
21396 /* Start a subfile for the current file of the state
21398 const file_entry
*fe
= state_machine
.current_file ();
21401 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21404 /* Decode the table. */
21405 while (line_ptr
< line_end
&& !end_sequence
)
21407 op_code
= read_1_byte (abfd
, line_ptr
);
21410 if (op_code
>= lh
->opcode_base
)
21412 /* Special opcode. */
21413 state_machine
.handle_special_opcode (op_code
);
21415 else switch (op_code
)
21417 case DW_LNS_extended_op
:
21418 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21420 line_ptr
+= bytes_read
;
21421 extended_end
= line_ptr
+ extended_len
;
21422 extended_op
= read_1_byte (abfd
, line_ptr
);
21424 switch (extended_op
)
21426 case DW_LNE_end_sequence
:
21427 state_machine
.handle_end_sequence ();
21428 end_sequence
= true;
21430 case DW_LNE_set_address
:
21433 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21434 line_ptr
+= bytes_read
;
21436 state_machine
.check_line_address (cu
, line_ptr
,
21437 lowpc
- baseaddr
, address
);
21438 state_machine
.handle_set_address (baseaddr
, address
);
21441 case DW_LNE_define_file
:
21443 const char *cur_file
;
21444 unsigned int mod_time
, length
;
21447 cur_file
= read_direct_string (abfd
, line_ptr
,
21449 line_ptr
+= bytes_read
;
21450 dindex
= (dir_index
)
21451 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21452 line_ptr
+= bytes_read
;
21454 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21455 line_ptr
+= bytes_read
;
21457 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21458 line_ptr
+= bytes_read
;
21459 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21462 case DW_LNE_set_discriminator
:
21464 /* The discriminator is not interesting to the
21465 debugger; just ignore it. We still need to
21466 check its value though:
21467 if there are consecutive entries for the same
21468 (non-prologue) line we want to coalesce them.
21471 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21472 line_ptr
+= bytes_read
;
21474 state_machine
.handle_set_discriminator (discr
);
21478 complaint (_("mangled .debug_line section"));
21481 /* Make sure that we parsed the extended op correctly. If e.g.
21482 we expected a different address size than the producer used,
21483 we may have read the wrong number of bytes. */
21484 if (line_ptr
!= extended_end
)
21486 complaint (_("mangled .debug_line section"));
21491 state_machine
.handle_copy ();
21493 case DW_LNS_advance_pc
:
21496 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21497 line_ptr
+= bytes_read
;
21499 state_machine
.handle_advance_pc (adjust
);
21502 case DW_LNS_advance_line
:
21505 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21506 line_ptr
+= bytes_read
;
21508 state_machine
.handle_advance_line (line_delta
);
21511 case DW_LNS_set_file
:
21513 file_name_index file
21514 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21516 line_ptr
+= bytes_read
;
21518 state_machine
.handle_set_file (file
);
21521 case DW_LNS_set_column
:
21522 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21523 line_ptr
+= bytes_read
;
21525 case DW_LNS_negate_stmt
:
21526 state_machine
.handle_negate_stmt ();
21528 case DW_LNS_set_basic_block
:
21530 /* Add to the address register of the state machine the
21531 address increment value corresponding to special opcode
21532 255. I.e., this value is scaled by the minimum
21533 instruction length since special opcode 255 would have
21534 scaled the increment. */
21535 case DW_LNS_const_add_pc
:
21536 state_machine
.handle_const_add_pc ();
21538 case DW_LNS_fixed_advance_pc
:
21540 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21543 state_machine
.handle_fixed_advance_pc (addr_adj
);
21548 /* Unknown standard opcode, ignore it. */
21551 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21553 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21554 line_ptr
+= bytes_read
;
21561 dwarf2_debug_line_missing_end_sequence_complaint ();
21563 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21564 in which case we still finish recording the last line). */
21565 state_machine
.record_line (true);
21569 /* Decode the Line Number Program (LNP) for the given line_header
21570 structure and CU. The actual information extracted and the type
21571 of structures created from the LNP depends on the value of PST.
21573 1. If PST is NULL, then this procedure uses the data from the program
21574 to create all necessary symbol tables, and their linetables.
21576 2. If PST is not NULL, this procedure reads the program to determine
21577 the list of files included by the unit represented by PST, and
21578 builds all the associated partial symbol tables.
21580 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21581 It is used for relative paths in the line table.
21582 NOTE: When processing partial symtabs (pst != NULL),
21583 comp_dir == pst->dirname.
21585 NOTE: It is important that psymtabs have the same file name (via strcmp)
21586 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21587 symtab we don't use it in the name of the psymtabs we create.
21588 E.g. expand_line_sal requires this when finding psymtabs to expand.
21589 A good testcase for this is mb-inline.exp.
21591 LOWPC is the lowest address in CU (or 0 if not known).
21593 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21594 for its PC<->lines mapping information. Otherwise only the filename
21595 table is read in. */
21598 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21599 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21600 CORE_ADDR lowpc
, int decode_mapping
)
21602 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21603 const int decode_for_pst_p
= (pst
!= NULL
);
21605 if (decode_mapping
)
21606 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21608 if (decode_for_pst_p
)
21610 /* Now that we're done scanning the Line Header Program, we can
21611 create the psymtab of each included file. */
21612 for (auto &file_entry
: lh
->file_names ())
21613 if (file_entry
.included_p
== 1)
21615 gdb::unique_xmalloc_ptr
<char> name_holder
;
21616 const char *include_name
=
21617 psymtab_include_file_name (lh
, file_entry
, pst
,
21618 comp_dir
, &name_holder
);
21619 if (include_name
!= NULL
)
21620 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21625 /* Make sure a symtab is created for every file, even files
21626 which contain only variables (i.e. no code with associated
21628 buildsym_compunit
*builder
= cu
->get_builder ();
21629 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21631 for (auto &fe
: lh
->file_names ())
21633 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21634 if (builder
->get_current_subfile ()->symtab
== NULL
)
21636 builder
->get_current_subfile ()->symtab
21637 = allocate_symtab (cust
,
21638 builder
->get_current_subfile ()->name
);
21640 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21645 /* Start a subfile for DWARF. FILENAME is the name of the file and
21646 DIRNAME the name of the source directory which contains FILENAME
21647 or NULL if not known.
21648 This routine tries to keep line numbers from identical absolute and
21649 relative file names in a common subfile.
21651 Using the `list' example from the GDB testsuite, which resides in
21652 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21653 of /srcdir/list0.c yields the following debugging information for list0.c:
21655 DW_AT_name: /srcdir/list0.c
21656 DW_AT_comp_dir: /compdir
21657 files.files[0].name: list0.h
21658 files.files[0].dir: /srcdir
21659 files.files[1].name: list0.c
21660 files.files[1].dir: /srcdir
21662 The line number information for list0.c has to end up in a single
21663 subfile, so that `break /srcdir/list0.c:1' works as expected.
21664 start_subfile will ensure that this happens provided that we pass the
21665 concatenation of files.files[1].dir and files.files[1].name as the
21669 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21670 const char *dirname
)
21672 gdb::unique_xmalloc_ptr
<char> copy
;
21674 /* In order not to lose the line information directory,
21675 we concatenate it to the filename when it makes sense.
21676 Note that the Dwarf3 standard says (speaking of filenames in line
21677 information): ``The directory index is ignored for file names
21678 that represent full path names''. Thus ignoring dirname in the
21679 `else' branch below isn't an issue. */
21681 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21683 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21684 filename
= copy
.get ();
21687 cu
->get_builder ()->start_subfile (filename
);
21690 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21691 buildsym_compunit constructor. */
21693 struct compunit_symtab
*
21694 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21697 gdb_assert (m_builder
== nullptr);
21699 m_builder
.reset (new struct buildsym_compunit
21700 (per_cu
->dwarf2_per_objfile
->objfile
,
21701 name
, comp_dir
, language
, low_pc
));
21703 list_in_scope
= get_builder ()->get_file_symbols ();
21705 get_builder ()->record_debugformat ("DWARF 2");
21706 get_builder ()->record_producer (producer
);
21708 processing_has_namespace_info
= false;
21710 return get_builder ()->get_compunit_symtab ();
21714 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21715 struct dwarf2_cu
*cu
)
21717 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21718 struct comp_unit_head
*cu_header
= &cu
->header
;
21720 /* NOTE drow/2003-01-30: There used to be a comment and some special
21721 code here to turn a symbol with DW_AT_external and a
21722 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21723 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21724 with some versions of binutils) where shared libraries could have
21725 relocations against symbols in their debug information - the
21726 minimal symbol would have the right address, but the debug info
21727 would not. It's no longer necessary, because we will explicitly
21728 apply relocations when we read in the debug information now. */
21730 /* A DW_AT_location attribute with no contents indicates that a
21731 variable has been optimized away. */
21732 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21734 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21738 /* Handle one degenerate form of location expression specially, to
21739 preserve GDB's previous behavior when section offsets are
21740 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21741 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21743 if (attr_form_is_block (attr
)
21744 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21745 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21746 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21747 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21748 && (DW_BLOCK (attr
)->size
21749 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21751 unsigned int dummy
;
21753 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21754 SET_SYMBOL_VALUE_ADDRESS (sym
,
21755 read_address (objfile
->obfd
,
21756 DW_BLOCK (attr
)->data
+ 1,
21759 SET_SYMBOL_VALUE_ADDRESS
21760 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21762 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21763 fixup_symbol_section (sym
, objfile
);
21764 SET_SYMBOL_VALUE_ADDRESS
21766 SYMBOL_VALUE_ADDRESS (sym
)
21767 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21771 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21772 expression evaluator, and use LOC_COMPUTED only when necessary
21773 (i.e. when the value of a register or memory location is
21774 referenced, or a thread-local block, etc.). Then again, it might
21775 not be worthwhile. I'm assuming that it isn't unless performance
21776 or memory numbers show me otherwise. */
21778 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21780 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21781 cu
->has_loclist
= true;
21784 /* Given a pointer to a DWARF information entry, figure out if we need
21785 to make a symbol table entry for it, and if so, create a new entry
21786 and return a pointer to it.
21787 If TYPE is NULL, determine symbol type from the die, otherwise
21788 used the passed type.
21789 If SPACE is not NULL, use it to hold the new symbol. If it is
21790 NULL, allocate a new symbol on the objfile's obstack. */
21792 static struct symbol
*
21793 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21794 struct symbol
*space
)
21796 struct dwarf2_per_objfile
*dwarf2_per_objfile
21797 = cu
->per_cu
->dwarf2_per_objfile
;
21798 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21799 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21800 struct symbol
*sym
= NULL
;
21802 struct attribute
*attr
= NULL
;
21803 struct attribute
*attr2
= NULL
;
21804 CORE_ADDR baseaddr
;
21805 struct pending
**list_to_add
= NULL
;
21807 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21809 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21811 name
= dwarf2_name (die
, cu
);
21814 const char *linkagename
;
21815 int suppress_add
= 0;
21820 sym
= allocate_symbol (objfile
);
21821 OBJSTAT (objfile
, n_syms
++);
21823 /* Cache this symbol's name and the name's demangled form (if any). */
21824 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21825 linkagename
= dwarf2_physname (name
, die
, cu
);
21826 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21828 /* Fortran does not have mangling standard and the mangling does differ
21829 between gfortran, iFort etc. */
21830 if (cu
->language
== language_fortran
21831 && symbol_get_demangled_name (sym
) == NULL
)
21832 symbol_set_demangled_name (sym
,
21833 dwarf2_full_name (name
, die
, cu
),
21836 /* Default assumptions.
21837 Use the passed type or decode it from the die. */
21838 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21839 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21841 SYMBOL_TYPE (sym
) = type
;
21843 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21844 attr
= dwarf2_attr (die
,
21845 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21847 if (attr
!= nullptr)
21849 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21852 attr
= dwarf2_attr (die
,
21853 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21855 if (attr
!= nullptr)
21857 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21858 struct file_entry
*fe
;
21860 if (cu
->line_header
!= NULL
)
21861 fe
= cu
->line_header
->file_name_at (file_index
);
21866 complaint (_("file index out of range"));
21868 symbol_set_symtab (sym
, fe
->symtab
);
21874 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21875 if (attr
!= nullptr)
21879 addr
= attr_value_as_address (attr
);
21880 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21881 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21883 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21884 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21885 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21886 add_symbol_to_list (sym
, cu
->list_in_scope
);
21888 case DW_TAG_subprogram
:
21889 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21891 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21892 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21893 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21894 || cu
->language
== language_ada
21895 || cu
->language
== language_fortran
)
21897 /* Subprograms marked external are stored as a global symbol.
21898 Ada and Fortran subprograms, whether marked external or
21899 not, are always stored as a global symbol, because we want
21900 to be able to access them globally. For instance, we want
21901 to be able to break on a nested subprogram without having
21902 to specify the context. */
21903 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21907 list_to_add
= cu
->list_in_scope
;
21910 case DW_TAG_inlined_subroutine
:
21911 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21913 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21914 SYMBOL_INLINED (sym
) = 1;
21915 list_to_add
= cu
->list_in_scope
;
21917 case DW_TAG_template_value_param
:
21919 /* Fall through. */
21920 case DW_TAG_constant
:
21921 case DW_TAG_variable
:
21922 case DW_TAG_member
:
21923 /* Compilation with minimal debug info may result in
21924 variables with missing type entries. Change the
21925 misleading `void' type to something sensible. */
21926 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21927 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21929 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21930 /* In the case of DW_TAG_member, we should only be called for
21931 static const members. */
21932 if (die
->tag
== DW_TAG_member
)
21934 /* dwarf2_add_field uses die_is_declaration,
21935 so we do the same. */
21936 gdb_assert (die_is_declaration (die
, cu
));
21939 if (attr
!= nullptr)
21941 dwarf2_const_value (attr
, sym
, cu
);
21942 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21945 if (attr2
&& (DW_UNSND (attr2
) != 0))
21946 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21948 list_to_add
= cu
->list_in_scope
;
21952 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21953 if (attr
!= nullptr)
21955 var_decode_location (attr
, sym
, cu
);
21956 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21958 /* Fortran explicitly imports any global symbols to the local
21959 scope by DW_TAG_common_block. */
21960 if (cu
->language
== language_fortran
&& die
->parent
21961 && die
->parent
->tag
== DW_TAG_common_block
)
21964 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21965 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21966 && !dwarf2_per_objfile
->has_section_at_zero
)
21968 /* When a static variable is eliminated by the linker,
21969 the corresponding debug information is not stripped
21970 out, but the variable address is set to null;
21971 do not add such variables into symbol table. */
21973 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21975 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21976 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21977 && dwarf2_per_objfile
->can_copy
)
21979 /* A global static variable might be subject to
21980 copy relocation. We first check for a local
21981 minsym, though, because maybe the symbol was
21982 marked hidden, in which case this would not
21984 bound_minimal_symbol found
21985 = (lookup_minimal_symbol_linkage
21986 (sym
->linkage_name (), objfile
));
21987 if (found
.minsym
!= nullptr)
21988 sym
->maybe_copied
= 1;
21991 /* A variable with DW_AT_external is never static,
21992 but it may be block-scoped. */
21994 = ((cu
->list_in_scope
21995 == cu
->get_builder ()->get_file_symbols ())
21996 ? cu
->get_builder ()->get_global_symbols ()
21997 : cu
->list_in_scope
);
22000 list_to_add
= cu
->list_in_scope
;
22004 /* We do not know the address of this symbol.
22005 If it is an external symbol and we have type information
22006 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22007 The address of the variable will then be determined from
22008 the minimal symbol table whenever the variable is
22010 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22012 /* Fortran explicitly imports any global symbols to the local
22013 scope by DW_TAG_common_block. */
22014 if (cu
->language
== language_fortran
&& die
->parent
22015 && die
->parent
->tag
== DW_TAG_common_block
)
22017 /* SYMBOL_CLASS doesn't matter here because
22018 read_common_block is going to reset it. */
22020 list_to_add
= cu
->list_in_scope
;
22022 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22023 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22025 /* A variable with DW_AT_external is never static, but it
22026 may be block-scoped. */
22028 = ((cu
->list_in_scope
22029 == cu
->get_builder ()->get_file_symbols ())
22030 ? cu
->get_builder ()->get_global_symbols ()
22031 : cu
->list_in_scope
);
22033 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22035 else if (!die_is_declaration (die
, cu
))
22037 /* Use the default LOC_OPTIMIZED_OUT class. */
22038 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22040 list_to_add
= cu
->list_in_scope
;
22044 case DW_TAG_formal_parameter
:
22046 /* If we are inside a function, mark this as an argument. If
22047 not, we might be looking at an argument to an inlined function
22048 when we do not have enough information to show inlined frames;
22049 pretend it's a local variable in that case so that the user can
22051 struct context_stack
*curr
22052 = cu
->get_builder ()->get_current_context_stack ();
22053 if (curr
!= nullptr && curr
->name
!= nullptr)
22054 SYMBOL_IS_ARGUMENT (sym
) = 1;
22055 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22056 if (attr
!= nullptr)
22058 var_decode_location (attr
, sym
, cu
);
22060 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22061 if (attr
!= nullptr)
22063 dwarf2_const_value (attr
, sym
, cu
);
22066 list_to_add
= cu
->list_in_scope
;
22069 case DW_TAG_unspecified_parameters
:
22070 /* From varargs functions; gdb doesn't seem to have any
22071 interest in this information, so just ignore it for now.
22074 case DW_TAG_template_type_param
:
22076 /* Fall through. */
22077 case DW_TAG_class_type
:
22078 case DW_TAG_interface_type
:
22079 case DW_TAG_structure_type
:
22080 case DW_TAG_union_type
:
22081 case DW_TAG_set_type
:
22082 case DW_TAG_enumeration_type
:
22083 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22084 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22087 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22088 really ever be static objects: otherwise, if you try
22089 to, say, break of a class's method and you're in a file
22090 which doesn't mention that class, it won't work unless
22091 the check for all static symbols in lookup_symbol_aux
22092 saves you. See the OtherFileClass tests in
22093 gdb.c++/namespace.exp. */
22097 buildsym_compunit
*builder
= cu
->get_builder ();
22099 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22100 && cu
->language
== language_cplus
22101 ? builder
->get_global_symbols ()
22102 : cu
->list_in_scope
);
22104 /* The semantics of C++ state that "struct foo {
22105 ... }" also defines a typedef for "foo". */
22106 if (cu
->language
== language_cplus
22107 || cu
->language
== language_ada
22108 || cu
->language
== language_d
22109 || cu
->language
== language_rust
)
22111 /* The symbol's name is already allocated along
22112 with this objfile, so we don't need to
22113 duplicate it for the type. */
22114 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22115 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22120 case DW_TAG_typedef
:
22121 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22122 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22123 list_to_add
= cu
->list_in_scope
;
22125 case DW_TAG_base_type
:
22126 case DW_TAG_subrange_type
:
22127 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22128 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22129 list_to_add
= cu
->list_in_scope
;
22131 case DW_TAG_enumerator
:
22132 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22133 if (attr
!= nullptr)
22135 dwarf2_const_value (attr
, sym
, cu
);
22138 /* NOTE: carlton/2003-11-10: See comment above in the
22139 DW_TAG_class_type, etc. block. */
22142 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22143 && cu
->language
== language_cplus
22144 ? cu
->get_builder ()->get_global_symbols ()
22145 : cu
->list_in_scope
);
22148 case DW_TAG_imported_declaration
:
22149 case DW_TAG_namespace
:
22150 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22151 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22153 case DW_TAG_module
:
22154 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22155 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22156 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22158 case DW_TAG_common_block
:
22159 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22160 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22161 add_symbol_to_list (sym
, cu
->list_in_scope
);
22164 /* Not a tag we recognize. Hopefully we aren't processing
22165 trash data, but since we must specifically ignore things
22166 we don't recognize, there is nothing else we should do at
22168 complaint (_("unsupported tag: '%s'"),
22169 dwarf_tag_name (die
->tag
));
22175 sym
->hash_next
= objfile
->template_symbols
;
22176 objfile
->template_symbols
= sym
;
22177 list_to_add
= NULL
;
22180 if (list_to_add
!= NULL
)
22181 add_symbol_to_list (sym
, list_to_add
);
22183 /* For the benefit of old versions of GCC, check for anonymous
22184 namespaces based on the demangled name. */
22185 if (!cu
->processing_has_namespace_info
22186 && cu
->language
== language_cplus
)
22187 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22192 /* Given an attr with a DW_FORM_dataN value in host byte order,
22193 zero-extend it as appropriate for the symbol's type. The DWARF
22194 standard (v4) is not entirely clear about the meaning of using
22195 DW_FORM_dataN for a constant with a signed type, where the type is
22196 wider than the data. The conclusion of a discussion on the DWARF
22197 list was that this is unspecified. We choose to always zero-extend
22198 because that is the interpretation long in use by GCC. */
22201 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22202 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22204 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22205 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22206 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22207 LONGEST l
= DW_UNSND (attr
);
22209 if (bits
< sizeof (*value
) * 8)
22211 l
&= ((LONGEST
) 1 << bits
) - 1;
22214 else if (bits
== sizeof (*value
) * 8)
22218 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22219 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22226 /* Read a constant value from an attribute. Either set *VALUE, or if
22227 the value does not fit in *VALUE, set *BYTES - either already
22228 allocated on the objfile obstack, or newly allocated on OBSTACK,
22229 or, set *BATON, if we translated the constant to a location
22233 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22234 const char *name
, struct obstack
*obstack
,
22235 struct dwarf2_cu
*cu
,
22236 LONGEST
*value
, const gdb_byte
**bytes
,
22237 struct dwarf2_locexpr_baton
**baton
)
22239 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22240 struct comp_unit_head
*cu_header
= &cu
->header
;
22241 struct dwarf_block
*blk
;
22242 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22243 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22249 switch (attr
->form
)
22252 case DW_FORM_addrx
:
22253 case DW_FORM_GNU_addr_index
:
22257 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22258 dwarf2_const_value_length_mismatch_complaint (name
,
22259 cu_header
->addr_size
,
22260 TYPE_LENGTH (type
));
22261 /* Symbols of this form are reasonably rare, so we just
22262 piggyback on the existing location code rather than writing
22263 a new implementation of symbol_computed_ops. */
22264 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22265 (*baton
)->per_cu
= cu
->per_cu
;
22266 gdb_assert ((*baton
)->per_cu
);
22268 (*baton
)->size
= 2 + cu_header
->addr_size
;
22269 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22270 (*baton
)->data
= data
;
22272 data
[0] = DW_OP_addr
;
22273 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22274 byte_order
, DW_ADDR (attr
));
22275 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22278 case DW_FORM_string
:
22281 case DW_FORM_GNU_str_index
:
22282 case DW_FORM_GNU_strp_alt
:
22283 /* DW_STRING is already allocated on the objfile obstack, point
22285 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22287 case DW_FORM_block1
:
22288 case DW_FORM_block2
:
22289 case DW_FORM_block4
:
22290 case DW_FORM_block
:
22291 case DW_FORM_exprloc
:
22292 case DW_FORM_data16
:
22293 blk
= DW_BLOCK (attr
);
22294 if (TYPE_LENGTH (type
) != blk
->size
)
22295 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22296 TYPE_LENGTH (type
));
22297 *bytes
= blk
->data
;
22300 /* The DW_AT_const_value attributes are supposed to carry the
22301 symbol's value "represented as it would be on the target
22302 architecture." By the time we get here, it's already been
22303 converted to host endianness, so we just need to sign- or
22304 zero-extend it as appropriate. */
22305 case DW_FORM_data1
:
22306 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22308 case DW_FORM_data2
:
22309 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22311 case DW_FORM_data4
:
22312 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22314 case DW_FORM_data8
:
22315 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22318 case DW_FORM_sdata
:
22319 case DW_FORM_implicit_const
:
22320 *value
= DW_SND (attr
);
22323 case DW_FORM_udata
:
22324 *value
= DW_UNSND (attr
);
22328 complaint (_("unsupported const value attribute form: '%s'"),
22329 dwarf_form_name (attr
->form
));
22336 /* Copy constant value from an attribute to a symbol. */
22339 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22340 struct dwarf2_cu
*cu
)
22342 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22344 const gdb_byte
*bytes
;
22345 struct dwarf2_locexpr_baton
*baton
;
22347 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22348 sym
->print_name (),
22349 &objfile
->objfile_obstack
, cu
,
22350 &value
, &bytes
, &baton
);
22354 SYMBOL_LOCATION_BATON (sym
) = baton
;
22355 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22357 else if (bytes
!= NULL
)
22359 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22360 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22364 SYMBOL_VALUE (sym
) = value
;
22365 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22369 /* Return the type of the die in question using its DW_AT_type attribute. */
22371 static struct type
*
22372 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22374 struct attribute
*type_attr
;
22376 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22379 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22380 /* A missing DW_AT_type represents a void type. */
22381 return objfile_type (objfile
)->builtin_void
;
22384 return lookup_die_type (die
, type_attr
, cu
);
22387 /* True iff CU's producer generates GNAT Ada auxiliary information
22388 that allows to find parallel types through that information instead
22389 of having to do expensive parallel lookups by type name. */
22392 need_gnat_info (struct dwarf2_cu
*cu
)
22394 /* Assume that the Ada compiler was GNAT, which always produces
22395 the auxiliary information. */
22396 return (cu
->language
== language_ada
);
22399 /* Return the auxiliary type of the die in question using its
22400 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22401 attribute is not present. */
22403 static struct type
*
22404 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22406 struct attribute
*type_attr
;
22408 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22412 return lookup_die_type (die
, type_attr
, cu
);
22415 /* If DIE has a descriptive_type attribute, then set the TYPE's
22416 descriptive type accordingly. */
22419 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22420 struct dwarf2_cu
*cu
)
22422 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22424 if (descriptive_type
)
22426 ALLOCATE_GNAT_AUX_TYPE (type
);
22427 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22431 /* Return the containing type of the die in question using its
22432 DW_AT_containing_type attribute. */
22434 static struct type
*
22435 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22437 struct attribute
*type_attr
;
22438 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22440 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22442 error (_("Dwarf Error: Problem turning containing type into gdb type "
22443 "[in module %s]"), objfile_name (objfile
));
22445 return lookup_die_type (die
, type_attr
, cu
);
22448 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22450 static struct type
*
22451 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22453 struct dwarf2_per_objfile
*dwarf2_per_objfile
22454 = cu
->per_cu
->dwarf2_per_objfile
;
22455 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22458 std::string message
22459 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22460 objfile_name (objfile
),
22461 sect_offset_str (cu
->header
.sect_off
),
22462 sect_offset_str (die
->sect_off
));
22463 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22465 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22468 /* Look up the type of DIE in CU using its type attribute ATTR.
22469 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22470 DW_AT_containing_type.
22471 If there is no type substitute an error marker. */
22473 static struct type
*
22474 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22475 struct dwarf2_cu
*cu
)
22477 struct dwarf2_per_objfile
*dwarf2_per_objfile
22478 = cu
->per_cu
->dwarf2_per_objfile
;
22479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22480 struct type
*this_type
;
22482 gdb_assert (attr
->name
== DW_AT_type
22483 || attr
->name
== DW_AT_GNAT_descriptive_type
22484 || attr
->name
== DW_AT_containing_type
);
22486 /* First see if we have it cached. */
22488 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22490 struct dwarf2_per_cu_data
*per_cu
;
22491 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22493 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22494 dwarf2_per_objfile
);
22495 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22497 else if (attr_form_is_ref (attr
))
22499 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22501 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22503 else if (attr
->form
== DW_FORM_ref_sig8
)
22505 ULONGEST signature
= DW_SIGNATURE (attr
);
22507 return get_signatured_type (die
, signature
, cu
);
22511 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22512 " at %s [in module %s]"),
22513 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22514 objfile_name (objfile
));
22515 return build_error_marker_type (cu
, die
);
22518 /* If not cached we need to read it in. */
22520 if (this_type
== NULL
)
22522 struct die_info
*type_die
= NULL
;
22523 struct dwarf2_cu
*type_cu
= cu
;
22525 if (attr_form_is_ref (attr
))
22526 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22527 if (type_die
== NULL
)
22528 return build_error_marker_type (cu
, die
);
22529 /* If we find the type now, it's probably because the type came
22530 from an inter-CU reference and the type's CU got expanded before
22532 this_type
= read_type_die (type_die
, type_cu
);
22535 /* If we still don't have a type use an error marker. */
22537 if (this_type
== NULL
)
22538 return build_error_marker_type (cu
, die
);
22543 /* Return the type in DIE, CU.
22544 Returns NULL for invalid types.
22546 This first does a lookup in die_type_hash,
22547 and only reads the die in if necessary.
22549 NOTE: This can be called when reading in partial or full symbols. */
22551 static struct type
*
22552 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22554 struct type
*this_type
;
22556 this_type
= get_die_type (die
, cu
);
22560 return read_type_die_1 (die
, cu
);
22563 /* Read the type in DIE, CU.
22564 Returns NULL for invalid types. */
22566 static struct type
*
22567 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22569 struct type
*this_type
= NULL
;
22573 case DW_TAG_class_type
:
22574 case DW_TAG_interface_type
:
22575 case DW_TAG_structure_type
:
22576 case DW_TAG_union_type
:
22577 this_type
= read_structure_type (die
, cu
);
22579 case DW_TAG_enumeration_type
:
22580 this_type
= read_enumeration_type (die
, cu
);
22582 case DW_TAG_subprogram
:
22583 case DW_TAG_subroutine_type
:
22584 case DW_TAG_inlined_subroutine
:
22585 this_type
= read_subroutine_type (die
, cu
);
22587 case DW_TAG_array_type
:
22588 this_type
= read_array_type (die
, cu
);
22590 case DW_TAG_set_type
:
22591 this_type
= read_set_type (die
, cu
);
22593 case DW_TAG_pointer_type
:
22594 this_type
= read_tag_pointer_type (die
, cu
);
22596 case DW_TAG_ptr_to_member_type
:
22597 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22599 case DW_TAG_reference_type
:
22600 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22602 case DW_TAG_rvalue_reference_type
:
22603 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22605 case DW_TAG_const_type
:
22606 this_type
= read_tag_const_type (die
, cu
);
22608 case DW_TAG_volatile_type
:
22609 this_type
= read_tag_volatile_type (die
, cu
);
22611 case DW_TAG_restrict_type
:
22612 this_type
= read_tag_restrict_type (die
, cu
);
22614 case DW_TAG_string_type
:
22615 this_type
= read_tag_string_type (die
, cu
);
22617 case DW_TAG_typedef
:
22618 this_type
= read_typedef (die
, cu
);
22620 case DW_TAG_subrange_type
:
22621 this_type
= read_subrange_type (die
, cu
);
22623 case DW_TAG_base_type
:
22624 this_type
= read_base_type (die
, cu
);
22626 case DW_TAG_unspecified_type
:
22627 this_type
= read_unspecified_type (die
, cu
);
22629 case DW_TAG_namespace
:
22630 this_type
= read_namespace_type (die
, cu
);
22632 case DW_TAG_module
:
22633 this_type
= read_module_type (die
, cu
);
22635 case DW_TAG_atomic_type
:
22636 this_type
= read_tag_atomic_type (die
, cu
);
22639 complaint (_("unexpected tag in read_type_die: '%s'"),
22640 dwarf_tag_name (die
->tag
));
22647 /* See if we can figure out if the class lives in a namespace. We do
22648 this by looking for a member function; its demangled name will
22649 contain namespace info, if there is any.
22650 Return the computed name or NULL.
22651 Space for the result is allocated on the objfile's obstack.
22652 This is the full-die version of guess_partial_die_structure_name.
22653 In this case we know DIE has no useful parent. */
22655 static const char *
22656 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22658 struct die_info
*spec_die
;
22659 struct dwarf2_cu
*spec_cu
;
22660 struct die_info
*child
;
22661 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22664 spec_die
= die_specification (die
, &spec_cu
);
22665 if (spec_die
!= NULL
)
22671 for (child
= die
->child
;
22673 child
= child
->sibling
)
22675 if (child
->tag
== DW_TAG_subprogram
)
22677 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22679 if (linkage_name
!= NULL
)
22681 gdb::unique_xmalloc_ptr
<char> actual_name
22682 (language_class_name_from_physname (cu
->language_defn
,
22684 const char *name
= NULL
;
22686 if (actual_name
!= NULL
)
22688 const char *die_name
= dwarf2_name (die
, cu
);
22690 if (die_name
!= NULL
22691 && strcmp (die_name
, actual_name
.get ()) != 0)
22693 /* Strip off the class name from the full name.
22694 We want the prefix. */
22695 int die_name_len
= strlen (die_name
);
22696 int actual_name_len
= strlen (actual_name
.get ());
22697 const char *ptr
= actual_name
.get ();
22699 /* Test for '::' as a sanity check. */
22700 if (actual_name_len
> die_name_len
+ 2
22701 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22702 name
= obstack_strndup (
22703 &objfile
->per_bfd
->storage_obstack
,
22704 ptr
, actual_name_len
- die_name_len
- 2);
22715 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22716 prefix part in such case. See
22717 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22719 static const char *
22720 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22722 struct attribute
*attr
;
22725 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22726 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22729 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22732 attr
= dw2_linkage_name_attr (die
, cu
);
22733 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22736 /* dwarf2_name had to be already called. */
22737 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22739 /* Strip the base name, keep any leading namespaces/classes. */
22740 base
= strrchr (DW_STRING (attr
), ':');
22741 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22744 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22745 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22747 &base
[-1] - DW_STRING (attr
));
22750 /* Return the name of the namespace/class that DIE is defined within,
22751 or "" if we can't tell. The caller should not xfree the result.
22753 For example, if we're within the method foo() in the following
22763 then determine_prefix on foo's die will return "N::C". */
22765 static const char *
22766 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22768 struct dwarf2_per_objfile
*dwarf2_per_objfile
22769 = cu
->per_cu
->dwarf2_per_objfile
;
22770 struct die_info
*parent
, *spec_die
;
22771 struct dwarf2_cu
*spec_cu
;
22772 struct type
*parent_type
;
22773 const char *retval
;
22775 if (cu
->language
!= language_cplus
22776 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22777 && cu
->language
!= language_rust
)
22780 retval
= anonymous_struct_prefix (die
, cu
);
22784 /* We have to be careful in the presence of DW_AT_specification.
22785 For example, with GCC 3.4, given the code
22789 // Definition of N::foo.
22793 then we'll have a tree of DIEs like this:
22795 1: DW_TAG_compile_unit
22796 2: DW_TAG_namespace // N
22797 3: DW_TAG_subprogram // declaration of N::foo
22798 4: DW_TAG_subprogram // definition of N::foo
22799 DW_AT_specification // refers to die #3
22801 Thus, when processing die #4, we have to pretend that we're in
22802 the context of its DW_AT_specification, namely the contex of die
22805 spec_die
= die_specification (die
, &spec_cu
);
22806 if (spec_die
== NULL
)
22807 parent
= die
->parent
;
22810 parent
= spec_die
->parent
;
22814 if (parent
== NULL
)
22816 else if (parent
->building_fullname
)
22819 const char *parent_name
;
22821 /* It has been seen on RealView 2.2 built binaries,
22822 DW_TAG_template_type_param types actually _defined_ as
22823 children of the parent class:
22826 template class <class Enum> Class{};
22827 Class<enum E> class_e;
22829 1: DW_TAG_class_type (Class)
22830 2: DW_TAG_enumeration_type (E)
22831 3: DW_TAG_enumerator (enum1:0)
22832 3: DW_TAG_enumerator (enum2:1)
22834 2: DW_TAG_template_type_param
22835 DW_AT_type DW_FORM_ref_udata (E)
22837 Besides being broken debug info, it can put GDB into an
22838 infinite loop. Consider:
22840 When we're building the full name for Class<E>, we'll start
22841 at Class, and go look over its template type parameters,
22842 finding E. We'll then try to build the full name of E, and
22843 reach here. We're now trying to build the full name of E,
22844 and look over the parent DIE for containing scope. In the
22845 broken case, if we followed the parent DIE of E, we'd again
22846 find Class, and once again go look at its template type
22847 arguments, etc., etc. Simply don't consider such parent die
22848 as source-level parent of this die (it can't be, the language
22849 doesn't allow it), and break the loop here. */
22850 name
= dwarf2_name (die
, cu
);
22851 parent_name
= dwarf2_name (parent
, cu
);
22852 complaint (_("template param type '%s' defined within parent '%s'"),
22853 name
? name
: "<unknown>",
22854 parent_name
? parent_name
: "<unknown>");
22858 switch (parent
->tag
)
22860 case DW_TAG_namespace
:
22861 parent_type
= read_type_die (parent
, cu
);
22862 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22863 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22864 Work around this problem here. */
22865 if (cu
->language
== language_cplus
22866 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22868 /* We give a name to even anonymous namespaces. */
22869 return TYPE_NAME (parent_type
);
22870 case DW_TAG_class_type
:
22871 case DW_TAG_interface_type
:
22872 case DW_TAG_structure_type
:
22873 case DW_TAG_union_type
:
22874 case DW_TAG_module
:
22875 parent_type
= read_type_die (parent
, cu
);
22876 if (TYPE_NAME (parent_type
) != NULL
)
22877 return TYPE_NAME (parent_type
);
22879 /* An anonymous structure is only allowed non-static data
22880 members; no typedefs, no member functions, et cetera.
22881 So it does not need a prefix. */
22883 case DW_TAG_compile_unit
:
22884 case DW_TAG_partial_unit
:
22885 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22886 if (cu
->language
== language_cplus
22887 && !dwarf2_per_objfile
->types
.empty ()
22888 && die
->child
!= NULL
22889 && (die
->tag
== DW_TAG_class_type
22890 || die
->tag
== DW_TAG_structure_type
22891 || die
->tag
== DW_TAG_union_type
))
22893 const char *name
= guess_full_die_structure_name (die
, cu
);
22898 case DW_TAG_subprogram
:
22899 /* Nested subroutines in Fortran get a prefix with the name
22900 of the parent's subroutine. */
22901 if (cu
->language
== language_fortran
)
22903 if ((die
->tag
== DW_TAG_subprogram
)
22904 && (dwarf2_name (parent
, cu
) != NULL
))
22905 return dwarf2_name (parent
, cu
);
22907 return determine_prefix (parent
, cu
);
22908 case DW_TAG_enumeration_type
:
22909 parent_type
= read_type_die (parent
, cu
);
22910 if (TYPE_DECLARED_CLASS (parent_type
))
22912 if (TYPE_NAME (parent_type
) != NULL
)
22913 return TYPE_NAME (parent_type
);
22916 /* Fall through. */
22918 return determine_prefix (parent
, cu
);
22922 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22923 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22924 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22925 an obconcat, otherwise allocate storage for the result. The CU argument is
22926 used to determine the language and hence, the appropriate separator. */
22928 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22931 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22932 int physname
, struct dwarf2_cu
*cu
)
22934 const char *lead
= "";
22937 if (suffix
== NULL
|| suffix
[0] == '\0'
22938 || prefix
== NULL
|| prefix
[0] == '\0')
22940 else if (cu
->language
== language_d
)
22942 /* For D, the 'main' function could be defined in any module, but it
22943 should never be prefixed. */
22944 if (strcmp (suffix
, "D main") == 0)
22952 else if (cu
->language
== language_fortran
&& physname
)
22954 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22955 DW_AT_MIPS_linkage_name is preferred and used instead. */
22963 if (prefix
== NULL
)
22965 if (suffix
== NULL
)
22972 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22974 strcpy (retval
, lead
);
22975 strcat (retval
, prefix
);
22976 strcat (retval
, sep
);
22977 strcat (retval
, suffix
);
22982 /* We have an obstack. */
22983 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22987 /* Return sibling of die, NULL if no sibling. */
22989 static struct die_info
*
22990 sibling_die (struct die_info
*die
)
22992 return die
->sibling
;
22995 /* Get name of a die, return NULL if not found. */
22997 static const char *
22998 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22999 struct obstack
*obstack
)
23001 if (name
&& cu
->language
== language_cplus
)
23003 std::string canon_name
= cp_canonicalize_string (name
);
23005 if (!canon_name
.empty ())
23007 if (canon_name
!= name
)
23008 name
= obstack_strdup (obstack
, canon_name
);
23015 /* Get name of a die, return NULL if not found.
23016 Anonymous namespaces are converted to their magic string. */
23018 static const char *
23019 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23021 struct attribute
*attr
;
23022 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23024 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23025 if ((!attr
|| !DW_STRING (attr
))
23026 && die
->tag
!= DW_TAG_namespace
23027 && die
->tag
!= DW_TAG_class_type
23028 && die
->tag
!= DW_TAG_interface_type
23029 && die
->tag
!= DW_TAG_structure_type
23030 && die
->tag
!= DW_TAG_union_type
)
23035 case DW_TAG_compile_unit
:
23036 case DW_TAG_partial_unit
:
23037 /* Compilation units have a DW_AT_name that is a filename, not
23038 a source language identifier. */
23039 case DW_TAG_enumeration_type
:
23040 case DW_TAG_enumerator
:
23041 /* These tags always have simple identifiers already; no need
23042 to canonicalize them. */
23043 return DW_STRING (attr
);
23045 case DW_TAG_namespace
:
23046 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23047 return DW_STRING (attr
);
23048 return CP_ANONYMOUS_NAMESPACE_STR
;
23050 case DW_TAG_class_type
:
23051 case DW_TAG_interface_type
:
23052 case DW_TAG_structure_type
:
23053 case DW_TAG_union_type
:
23054 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23055 structures or unions. These were of the form "._%d" in GCC 4.1,
23056 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23057 and GCC 4.4. We work around this problem by ignoring these. */
23058 if (attr
&& DW_STRING (attr
)
23059 && (startswith (DW_STRING (attr
), "._")
23060 || startswith (DW_STRING (attr
), "<anonymous")))
23063 /* GCC might emit a nameless typedef that has a linkage name. See
23064 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23065 if (!attr
|| DW_STRING (attr
) == NULL
)
23067 attr
= dw2_linkage_name_attr (die
, cu
);
23068 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23071 /* Avoid demangling DW_STRING (attr) the second time on a second
23072 call for the same DIE. */
23073 if (!DW_STRING_IS_CANONICAL (attr
))
23075 gdb::unique_xmalloc_ptr
<char> demangled
23076 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23080 /* FIXME: we already did this for the partial symbol... */
23082 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23084 DW_STRING_IS_CANONICAL (attr
) = 1;
23086 /* Strip any leading namespaces/classes, keep only the base name.
23087 DW_AT_name for named DIEs does not contain the prefixes. */
23088 base
= strrchr (DW_STRING (attr
), ':');
23089 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23092 return DW_STRING (attr
);
23101 if (!DW_STRING_IS_CANONICAL (attr
))
23104 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23105 &objfile
->per_bfd
->storage_obstack
);
23106 DW_STRING_IS_CANONICAL (attr
) = 1;
23108 return DW_STRING (attr
);
23111 /* Return the die that this die in an extension of, or NULL if there
23112 is none. *EXT_CU is the CU containing DIE on input, and the CU
23113 containing the return value on output. */
23115 static struct die_info
*
23116 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23118 struct attribute
*attr
;
23120 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23124 return follow_die_ref (die
, attr
, ext_cu
);
23127 /* A convenience function that returns an "unknown" DWARF name,
23128 including the value of V. STR is the name of the entity being
23129 printed, e.g., "TAG". */
23131 static const char *
23132 dwarf_unknown (const char *str
, unsigned v
)
23134 char *cell
= get_print_cell ();
23135 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23139 /* Convert a DIE tag into its string name. */
23141 static const char *
23142 dwarf_tag_name (unsigned tag
)
23144 const char *name
= get_DW_TAG_name (tag
);
23147 return dwarf_unknown ("TAG", tag
);
23152 /* Convert a DWARF attribute code into its string name. */
23154 static const char *
23155 dwarf_attr_name (unsigned attr
)
23159 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23160 if (attr
== DW_AT_MIPS_fde
)
23161 return "DW_AT_MIPS_fde";
23163 if (attr
== DW_AT_HP_block_index
)
23164 return "DW_AT_HP_block_index";
23167 name
= get_DW_AT_name (attr
);
23170 return dwarf_unknown ("AT", attr
);
23175 /* Convert a unit type to corresponding DW_UT name. */
23177 static const char *
23178 dwarf_unit_type_name (int unit_type
) {
23182 return "DW_UT_compile (0x01)";
23184 return "DW_UT_type (0x02)";
23186 return "DW_UT_partial (0x03)";
23188 return "DW_UT_skeleton (0x04)";
23190 return "DW_UT_split_compile (0x05)";
23192 return "DW_UT_split_type (0x06)";
23194 return "DW_UT_lo_user (0x80)";
23196 return "DW_UT_hi_user (0xff)";
23202 /* Convert a DWARF value form code into its string name. */
23204 static const char *
23205 dwarf_form_name (unsigned form
)
23207 const char *name
= get_DW_FORM_name (form
);
23210 return dwarf_unknown ("FORM", form
);
23215 static const char *
23216 dwarf_bool_name (unsigned mybool
)
23224 /* Convert a DWARF type code into its string name. */
23226 static const char *
23227 dwarf_type_encoding_name (unsigned enc
)
23229 const char *name
= get_DW_ATE_name (enc
);
23232 return dwarf_unknown ("ATE", enc
);
23238 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23242 print_spaces (indent
, f
);
23243 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23244 dwarf_tag_name (die
->tag
), die
->abbrev
,
23245 sect_offset_str (die
->sect_off
));
23247 if (die
->parent
!= NULL
)
23249 print_spaces (indent
, f
);
23250 fprintf_unfiltered (f
, " parent at offset: %s\n",
23251 sect_offset_str (die
->parent
->sect_off
));
23254 print_spaces (indent
, f
);
23255 fprintf_unfiltered (f
, " has children: %s\n",
23256 dwarf_bool_name (die
->child
!= NULL
));
23258 print_spaces (indent
, f
);
23259 fprintf_unfiltered (f
, " attributes:\n");
23261 for (i
= 0; i
< die
->num_attrs
; ++i
)
23263 print_spaces (indent
, f
);
23264 fprintf_unfiltered (f
, " %s (%s) ",
23265 dwarf_attr_name (die
->attrs
[i
].name
),
23266 dwarf_form_name (die
->attrs
[i
].form
));
23268 switch (die
->attrs
[i
].form
)
23271 case DW_FORM_addrx
:
23272 case DW_FORM_GNU_addr_index
:
23273 fprintf_unfiltered (f
, "address: ");
23274 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23276 case DW_FORM_block2
:
23277 case DW_FORM_block4
:
23278 case DW_FORM_block
:
23279 case DW_FORM_block1
:
23280 fprintf_unfiltered (f
, "block: size %s",
23281 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23283 case DW_FORM_exprloc
:
23284 fprintf_unfiltered (f
, "expression: size %s",
23285 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23287 case DW_FORM_data16
:
23288 fprintf_unfiltered (f
, "constant of 16 bytes");
23290 case DW_FORM_ref_addr
:
23291 fprintf_unfiltered (f
, "ref address: ");
23292 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23294 case DW_FORM_GNU_ref_alt
:
23295 fprintf_unfiltered (f
, "alt ref address: ");
23296 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23302 case DW_FORM_ref_udata
:
23303 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23304 (long) (DW_UNSND (&die
->attrs
[i
])));
23306 case DW_FORM_data1
:
23307 case DW_FORM_data2
:
23308 case DW_FORM_data4
:
23309 case DW_FORM_data8
:
23310 case DW_FORM_udata
:
23311 case DW_FORM_sdata
:
23312 fprintf_unfiltered (f
, "constant: %s",
23313 pulongest (DW_UNSND (&die
->attrs
[i
])));
23315 case DW_FORM_sec_offset
:
23316 fprintf_unfiltered (f
, "section offset: %s",
23317 pulongest (DW_UNSND (&die
->attrs
[i
])));
23319 case DW_FORM_ref_sig8
:
23320 fprintf_unfiltered (f
, "signature: %s",
23321 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23323 case DW_FORM_string
:
23325 case DW_FORM_line_strp
:
23327 case DW_FORM_GNU_str_index
:
23328 case DW_FORM_GNU_strp_alt
:
23329 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23330 DW_STRING (&die
->attrs
[i
])
23331 ? DW_STRING (&die
->attrs
[i
]) : "",
23332 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23335 if (DW_UNSND (&die
->attrs
[i
]))
23336 fprintf_unfiltered (f
, "flag: TRUE");
23338 fprintf_unfiltered (f
, "flag: FALSE");
23340 case DW_FORM_flag_present
:
23341 fprintf_unfiltered (f
, "flag: TRUE");
23343 case DW_FORM_indirect
:
23344 /* The reader will have reduced the indirect form to
23345 the "base form" so this form should not occur. */
23346 fprintf_unfiltered (f
,
23347 "unexpected attribute form: DW_FORM_indirect");
23349 case DW_FORM_implicit_const
:
23350 fprintf_unfiltered (f
, "constant: %s",
23351 plongest (DW_SND (&die
->attrs
[i
])));
23354 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23355 die
->attrs
[i
].form
);
23358 fprintf_unfiltered (f
, "\n");
23363 dump_die_for_error (struct die_info
*die
)
23365 dump_die_shallow (gdb_stderr
, 0, die
);
23369 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23371 int indent
= level
* 4;
23373 gdb_assert (die
!= NULL
);
23375 if (level
>= max_level
)
23378 dump_die_shallow (f
, indent
, die
);
23380 if (die
->child
!= NULL
)
23382 print_spaces (indent
, f
);
23383 fprintf_unfiltered (f
, " Children:");
23384 if (level
+ 1 < max_level
)
23386 fprintf_unfiltered (f
, "\n");
23387 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23391 fprintf_unfiltered (f
,
23392 " [not printed, max nesting level reached]\n");
23396 if (die
->sibling
!= NULL
&& level
> 0)
23398 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23402 /* This is called from the pdie macro in gdbinit.in.
23403 It's not static so gcc will keep a copy callable from gdb. */
23406 dump_die (struct die_info
*die
, int max_level
)
23408 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23412 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23416 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23417 to_underlying (die
->sect_off
),
23423 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23427 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23429 if (attr_form_is_ref (attr
))
23430 return (sect_offset
) DW_UNSND (attr
);
23432 complaint (_("unsupported die ref attribute form: '%s'"),
23433 dwarf_form_name (attr
->form
));
23437 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23438 * the value held by the attribute is not constant. */
23441 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23443 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23444 return DW_SND (attr
);
23445 else if (attr
->form
== DW_FORM_udata
23446 || attr
->form
== DW_FORM_data1
23447 || attr
->form
== DW_FORM_data2
23448 || attr
->form
== DW_FORM_data4
23449 || attr
->form
== DW_FORM_data8
)
23450 return DW_UNSND (attr
);
23453 /* For DW_FORM_data16 see attr_form_is_constant. */
23454 complaint (_("Attribute value is not a constant (%s)"),
23455 dwarf_form_name (attr
->form
));
23456 return default_value
;
23460 /* Follow reference or signature attribute ATTR of SRC_DIE.
23461 On entry *REF_CU is the CU of SRC_DIE.
23462 On exit *REF_CU is the CU of the result. */
23464 static struct die_info
*
23465 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23466 struct dwarf2_cu
**ref_cu
)
23468 struct die_info
*die
;
23470 if (attr_form_is_ref (attr
))
23471 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23472 else if (attr
->form
== DW_FORM_ref_sig8
)
23473 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23476 dump_die_for_error (src_die
);
23477 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23478 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23484 /* Follow reference OFFSET.
23485 On entry *REF_CU is the CU of the source die referencing OFFSET.
23486 On exit *REF_CU is the CU of the result.
23487 Returns NULL if OFFSET is invalid. */
23489 static struct die_info
*
23490 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23491 struct dwarf2_cu
**ref_cu
)
23493 struct die_info temp_die
;
23494 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23495 struct dwarf2_per_objfile
*dwarf2_per_objfile
23496 = cu
->per_cu
->dwarf2_per_objfile
;
23498 gdb_assert (cu
->per_cu
!= NULL
);
23502 if (cu
->per_cu
->is_debug_types
)
23504 /* .debug_types CUs cannot reference anything outside their CU.
23505 If they need to, they have to reference a signatured type via
23506 DW_FORM_ref_sig8. */
23507 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23510 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23511 || !offset_in_cu_p (&cu
->header
, sect_off
))
23513 struct dwarf2_per_cu_data
*per_cu
;
23515 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23516 dwarf2_per_objfile
);
23518 /* If necessary, add it to the queue and load its DIEs. */
23519 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23520 load_full_comp_unit (per_cu
, false, cu
->language
);
23522 target_cu
= per_cu
->cu
;
23524 else if (cu
->dies
== NULL
)
23526 /* We're loading full DIEs during partial symbol reading. */
23527 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23528 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23531 *ref_cu
= target_cu
;
23532 temp_die
.sect_off
= sect_off
;
23534 if (target_cu
!= cu
)
23535 target_cu
->ancestor
= cu
;
23537 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23539 to_underlying (sect_off
));
23542 /* Follow reference attribute ATTR of SRC_DIE.
23543 On entry *REF_CU is the CU of SRC_DIE.
23544 On exit *REF_CU is the CU of the result. */
23546 static struct die_info
*
23547 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23548 struct dwarf2_cu
**ref_cu
)
23550 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23551 struct dwarf2_cu
*cu
= *ref_cu
;
23552 struct die_info
*die
;
23554 die
= follow_die_offset (sect_off
,
23555 (attr
->form
== DW_FORM_GNU_ref_alt
23556 || cu
->per_cu
->is_dwz
),
23559 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23560 "at %s [in module %s]"),
23561 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23562 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23567 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23568 Returned value is intended for DW_OP_call*. Returned
23569 dwarf2_locexpr_baton->data has lifetime of
23570 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23572 struct dwarf2_locexpr_baton
23573 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23574 struct dwarf2_per_cu_data
*per_cu
,
23575 CORE_ADDR (*get_frame_pc
) (void *baton
),
23576 void *baton
, bool resolve_abstract_p
)
23578 struct dwarf2_cu
*cu
;
23579 struct die_info
*die
;
23580 struct attribute
*attr
;
23581 struct dwarf2_locexpr_baton retval
;
23582 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23583 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23585 if (per_cu
->cu
== NULL
)
23586 load_cu (per_cu
, false);
23590 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23591 Instead just throw an error, not much else we can do. */
23592 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23593 sect_offset_str (sect_off
), objfile_name (objfile
));
23596 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23598 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23599 sect_offset_str (sect_off
), objfile_name (objfile
));
23601 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23602 if (!attr
&& resolve_abstract_p
23603 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23604 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23606 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23607 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
23608 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23610 for (const auto &cand_off
23611 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23613 struct dwarf2_cu
*cand_cu
= cu
;
23614 struct die_info
*cand
23615 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23618 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23621 CORE_ADDR pc_low
, pc_high
;
23622 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23623 if (pc_low
== ((CORE_ADDR
) -1))
23625 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23626 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23627 if (!(pc_low
<= pc
&& pc
< pc_high
))
23631 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23638 /* DWARF: "If there is no such attribute, then there is no effect.".
23639 DATA is ignored if SIZE is 0. */
23641 retval
.data
= NULL
;
23644 else if (attr_form_is_section_offset (attr
))
23646 struct dwarf2_loclist_baton loclist_baton
;
23647 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23650 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23652 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23654 retval
.size
= size
;
23658 if (!attr_form_is_block (attr
))
23659 error (_("Dwarf Error: DIE at %s referenced in module %s "
23660 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23661 sect_offset_str (sect_off
), objfile_name (objfile
));
23663 retval
.data
= DW_BLOCK (attr
)->data
;
23664 retval
.size
= DW_BLOCK (attr
)->size
;
23666 retval
.per_cu
= cu
->per_cu
;
23668 age_cached_comp_units (dwarf2_per_objfile
);
23673 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23676 struct dwarf2_locexpr_baton
23677 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23678 struct dwarf2_per_cu_data
*per_cu
,
23679 CORE_ADDR (*get_frame_pc
) (void *baton
),
23682 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23684 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23687 /* Write a constant of a given type as target-ordered bytes into
23690 static const gdb_byte
*
23691 write_constant_as_bytes (struct obstack
*obstack
,
23692 enum bfd_endian byte_order
,
23699 *len
= TYPE_LENGTH (type
);
23700 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23701 store_unsigned_integer (result
, *len
, byte_order
, value
);
23706 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23707 pointer to the constant bytes and set LEN to the length of the
23708 data. If memory is needed, allocate it on OBSTACK. If the DIE
23709 does not have a DW_AT_const_value, return NULL. */
23712 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23713 struct dwarf2_per_cu_data
*per_cu
,
23714 struct obstack
*obstack
,
23717 struct dwarf2_cu
*cu
;
23718 struct die_info
*die
;
23719 struct attribute
*attr
;
23720 const gdb_byte
*result
= NULL
;
23723 enum bfd_endian byte_order
;
23724 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23726 if (per_cu
->cu
== NULL
)
23727 load_cu (per_cu
, false);
23731 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23732 Instead just throw an error, not much else we can do. */
23733 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23734 sect_offset_str (sect_off
), objfile_name (objfile
));
23737 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23739 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23740 sect_offset_str (sect_off
), objfile_name (objfile
));
23742 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23746 byte_order
= (bfd_big_endian (objfile
->obfd
)
23747 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23749 switch (attr
->form
)
23752 case DW_FORM_addrx
:
23753 case DW_FORM_GNU_addr_index
:
23757 *len
= cu
->header
.addr_size
;
23758 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23759 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23763 case DW_FORM_string
:
23766 case DW_FORM_GNU_str_index
:
23767 case DW_FORM_GNU_strp_alt
:
23768 /* DW_STRING is already allocated on the objfile obstack, point
23770 result
= (const gdb_byte
*) DW_STRING (attr
);
23771 *len
= strlen (DW_STRING (attr
));
23773 case DW_FORM_block1
:
23774 case DW_FORM_block2
:
23775 case DW_FORM_block4
:
23776 case DW_FORM_block
:
23777 case DW_FORM_exprloc
:
23778 case DW_FORM_data16
:
23779 result
= DW_BLOCK (attr
)->data
;
23780 *len
= DW_BLOCK (attr
)->size
;
23783 /* The DW_AT_const_value attributes are supposed to carry the
23784 symbol's value "represented as it would be on the target
23785 architecture." By the time we get here, it's already been
23786 converted to host endianness, so we just need to sign- or
23787 zero-extend it as appropriate. */
23788 case DW_FORM_data1
:
23789 type
= die_type (die
, cu
);
23790 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23791 if (result
== NULL
)
23792 result
= write_constant_as_bytes (obstack
, byte_order
,
23795 case DW_FORM_data2
:
23796 type
= die_type (die
, cu
);
23797 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23798 if (result
== NULL
)
23799 result
= write_constant_as_bytes (obstack
, byte_order
,
23802 case DW_FORM_data4
:
23803 type
= die_type (die
, cu
);
23804 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23805 if (result
== NULL
)
23806 result
= write_constant_as_bytes (obstack
, byte_order
,
23809 case DW_FORM_data8
:
23810 type
= die_type (die
, cu
);
23811 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23812 if (result
== NULL
)
23813 result
= write_constant_as_bytes (obstack
, byte_order
,
23817 case DW_FORM_sdata
:
23818 case DW_FORM_implicit_const
:
23819 type
= die_type (die
, cu
);
23820 result
= write_constant_as_bytes (obstack
, byte_order
,
23821 type
, DW_SND (attr
), len
);
23824 case DW_FORM_udata
:
23825 type
= die_type (die
, cu
);
23826 result
= write_constant_as_bytes (obstack
, byte_order
,
23827 type
, DW_UNSND (attr
), len
);
23831 complaint (_("unsupported const value attribute form: '%s'"),
23832 dwarf_form_name (attr
->form
));
23839 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23840 valid type for this die is found. */
23843 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23844 struct dwarf2_per_cu_data
*per_cu
)
23846 struct dwarf2_cu
*cu
;
23847 struct die_info
*die
;
23849 if (per_cu
->cu
== NULL
)
23850 load_cu (per_cu
, false);
23855 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23859 return die_type (die
, cu
);
23862 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23866 dwarf2_get_die_type (cu_offset die_offset
,
23867 struct dwarf2_per_cu_data
*per_cu
)
23869 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23870 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23873 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23874 On entry *REF_CU is the CU of SRC_DIE.
23875 On exit *REF_CU is the CU of the result.
23876 Returns NULL if the referenced DIE isn't found. */
23878 static struct die_info
*
23879 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23880 struct dwarf2_cu
**ref_cu
)
23882 struct die_info temp_die
;
23883 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23884 struct die_info
*die
;
23886 /* While it might be nice to assert sig_type->type == NULL here,
23887 we can get here for DW_AT_imported_declaration where we need
23888 the DIE not the type. */
23890 /* If necessary, add it to the queue and load its DIEs. */
23892 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23893 read_signatured_type (sig_type
);
23895 sig_cu
= sig_type
->per_cu
.cu
;
23896 gdb_assert (sig_cu
!= NULL
);
23897 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23898 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23899 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23900 to_underlying (temp_die
.sect_off
));
23903 struct dwarf2_per_objfile
*dwarf2_per_objfile
23904 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23906 /* For .gdb_index version 7 keep track of included TUs.
23907 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23908 if (dwarf2_per_objfile
->index_table
!= NULL
23909 && dwarf2_per_objfile
->index_table
->version
<= 7)
23911 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23916 sig_cu
->ancestor
= cu
;
23924 /* Follow signatured type referenced by ATTR in SRC_DIE.
23925 On entry *REF_CU is the CU of SRC_DIE.
23926 On exit *REF_CU is the CU of the result.
23927 The result is the DIE of the type.
23928 If the referenced type cannot be found an error is thrown. */
23930 static struct die_info
*
23931 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23932 struct dwarf2_cu
**ref_cu
)
23934 ULONGEST signature
= DW_SIGNATURE (attr
);
23935 struct signatured_type
*sig_type
;
23936 struct die_info
*die
;
23938 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23940 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23941 /* sig_type will be NULL if the signatured type is missing from
23943 if (sig_type
== NULL
)
23945 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23946 " from DIE at %s [in module %s]"),
23947 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23948 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23951 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23954 dump_die_for_error (src_die
);
23955 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23956 " from DIE at %s [in module %s]"),
23957 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23958 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23964 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23965 reading in and processing the type unit if necessary. */
23967 static struct type
*
23968 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23969 struct dwarf2_cu
*cu
)
23971 struct dwarf2_per_objfile
*dwarf2_per_objfile
23972 = cu
->per_cu
->dwarf2_per_objfile
;
23973 struct signatured_type
*sig_type
;
23974 struct dwarf2_cu
*type_cu
;
23975 struct die_info
*type_die
;
23978 sig_type
= lookup_signatured_type (cu
, signature
);
23979 /* sig_type will be NULL if the signatured type is missing from
23981 if (sig_type
== NULL
)
23983 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23984 " from DIE at %s [in module %s]"),
23985 hex_string (signature
), sect_offset_str (die
->sect_off
),
23986 objfile_name (dwarf2_per_objfile
->objfile
));
23987 return build_error_marker_type (cu
, die
);
23990 /* If we already know the type we're done. */
23991 if (sig_type
->type
!= NULL
)
23992 return sig_type
->type
;
23995 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23996 if (type_die
!= NULL
)
23998 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23999 is created. This is important, for example, because for c++ classes
24000 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24001 type
= read_type_die (type_die
, type_cu
);
24004 complaint (_("Dwarf Error: Cannot build signatured type %s"
24005 " referenced from DIE at %s [in module %s]"),
24006 hex_string (signature
), sect_offset_str (die
->sect_off
),
24007 objfile_name (dwarf2_per_objfile
->objfile
));
24008 type
= build_error_marker_type (cu
, die
);
24013 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24014 " from DIE at %s [in module %s]"),
24015 hex_string (signature
), sect_offset_str (die
->sect_off
),
24016 objfile_name (dwarf2_per_objfile
->objfile
));
24017 type
= build_error_marker_type (cu
, die
);
24019 sig_type
->type
= type
;
24024 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24025 reading in and processing the type unit if necessary. */
24027 static struct type
*
24028 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24029 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24031 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24032 if (attr_form_is_ref (attr
))
24034 struct dwarf2_cu
*type_cu
= cu
;
24035 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24037 return read_type_die (type_die
, type_cu
);
24039 else if (attr
->form
== DW_FORM_ref_sig8
)
24041 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24045 struct dwarf2_per_objfile
*dwarf2_per_objfile
24046 = cu
->per_cu
->dwarf2_per_objfile
;
24048 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24049 " at %s [in module %s]"),
24050 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24051 objfile_name (dwarf2_per_objfile
->objfile
));
24052 return build_error_marker_type (cu
, die
);
24056 /* Load the DIEs associated with type unit PER_CU into memory. */
24059 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24061 struct signatured_type
*sig_type
;
24063 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24064 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24066 /* We have the per_cu, but we need the signatured_type.
24067 Fortunately this is an easy translation. */
24068 gdb_assert (per_cu
->is_debug_types
);
24069 sig_type
= (struct signatured_type
*) per_cu
;
24071 gdb_assert (per_cu
->cu
== NULL
);
24073 read_signatured_type (sig_type
);
24075 gdb_assert (per_cu
->cu
!= NULL
);
24078 /* die_reader_func for read_signatured_type.
24079 This is identical to load_full_comp_unit_reader,
24080 but is kept separate for now. */
24083 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24084 const gdb_byte
*info_ptr
,
24085 struct die_info
*comp_unit_die
,
24089 struct dwarf2_cu
*cu
= reader
->cu
;
24091 gdb_assert (cu
->die_hash
== NULL
);
24093 htab_create_alloc_ex (cu
->header
.length
/ 12,
24097 &cu
->comp_unit_obstack
,
24098 hashtab_obstack_allocate
,
24099 dummy_obstack_deallocate
);
24102 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24103 &info_ptr
, comp_unit_die
);
24104 cu
->dies
= comp_unit_die
;
24105 /* comp_unit_die is not stored in die_hash, no need. */
24107 /* We try not to read any attributes in this function, because not
24108 all CUs needed for references have been loaded yet, and symbol
24109 table processing isn't initialized. But we have to set the CU language,
24110 or we won't be able to build types correctly.
24111 Similarly, if we do not read the producer, we can not apply
24112 producer-specific interpretation. */
24113 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24116 /* Read in a signatured type and build its CU and DIEs.
24117 If the type is a stub for the real type in a DWO file,
24118 read in the real type from the DWO file as well. */
24121 read_signatured_type (struct signatured_type
*sig_type
)
24123 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24125 gdb_assert (per_cu
->is_debug_types
);
24126 gdb_assert (per_cu
->cu
== NULL
);
24128 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24129 read_signatured_type_reader
, NULL
);
24130 sig_type
->per_cu
.tu_read
= 1;
24133 /* Decode simple location descriptions.
24134 Given a pointer to a dwarf block that defines a location, compute
24135 the location and return the value.
24137 NOTE drow/2003-11-18: This function is called in two situations
24138 now: for the address of static or global variables (partial symbols
24139 only) and for offsets into structures which are expected to be
24140 (more or less) constant. The partial symbol case should go away,
24141 and only the constant case should remain. That will let this
24142 function complain more accurately. A few special modes are allowed
24143 without complaint for global variables (for instance, global
24144 register values and thread-local values).
24146 A location description containing no operations indicates that the
24147 object is optimized out. The return value is 0 for that case.
24148 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24149 callers will only want a very basic result and this can become a
24152 Note that stack[0] is unused except as a default error return. */
24155 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24157 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24159 size_t size
= blk
->size
;
24160 const gdb_byte
*data
= blk
->data
;
24161 CORE_ADDR stack
[64];
24163 unsigned int bytes_read
, unsnd
;
24169 stack
[++stacki
] = 0;
24208 stack
[++stacki
] = op
- DW_OP_lit0
;
24243 stack
[++stacki
] = op
- DW_OP_reg0
;
24245 dwarf2_complex_location_expr_complaint ();
24249 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24251 stack
[++stacki
] = unsnd
;
24253 dwarf2_complex_location_expr_complaint ();
24257 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24262 case DW_OP_const1u
:
24263 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24267 case DW_OP_const1s
:
24268 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24272 case DW_OP_const2u
:
24273 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24277 case DW_OP_const2s
:
24278 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24282 case DW_OP_const4u
:
24283 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24287 case DW_OP_const4s
:
24288 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24292 case DW_OP_const8u
:
24293 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24298 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24304 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24309 stack
[stacki
+ 1] = stack
[stacki
];
24314 stack
[stacki
- 1] += stack
[stacki
];
24318 case DW_OP_plus_uconst
:
24319 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24325 stack
[stacki
- 1] -= stack
[stacki
];
24330 /* If we're not the last op, then we definitely can't encode
24331 this using GDB's address_class enum. This is valid for partial
24332 global symbols, although the variable's address will be bogus
24335 dwarf2_complex_location_expr_complaint ();
24338 case DW_OP_GNU_push_tls_address
:
24339 case DW_OP_form_tls_address
:
24340 /* The top of the stack has the offset from the beginning
24341 of the thread control block at which the variable is located. */
24342 /* Nothing should follow this operator, so the top of stack would
24344 /* This is valid for partial global symbols, but the variable's
24345 address will be bogus in the psymtab. Make it always at least
24346 non-zero to not look as a variable garbage collected by linker
24347 which have DW_OP_addr 0. */
24349 dwarf2_complex_location_expr_complaint ();
24353 case DW_OP_GNU_uninit
:
24357 case DW_OP_GNU_addr_index
:
24358 case DW_OP_GNU_const_index
:
24359 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24366 const char *name
= get_DW_OP_name (op
);
24369 complaint (_("unsupported stack op: '%s'"),
24372 complaint (_("unsupported stack op: '%02x'"),
24376 return (stack
[stacki
]);
24379 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24380 outside of the allocated space. Also enforce minimum>0. */
24381 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24383 complaint (_("location description stack overflow"));
24389 complaint (_("location description stack underflow"));
24393 return (stack
[stacki
]);
24396 /* memory allocation interface */
24398 static struct dwarf_block
*
24399 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24401 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24404 static struct die_info
*
24405 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24407 struct die_info
*die
;
24408 size_t size
= sizeof (struct die_info
);
24411 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24413 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24414 memset (die
, 0, sizeof (struct die_info
));
24419 /* Macro support. */
24421 /* Return file name relative to the compilation directory of file number I in
24422 *LH's file name table. The result is allocated using xmalloc; the caller is
24423 responsible for freeing it. */
24426 file_file_name (int file
, struct line_header
*lh
)
24428 /* Is the file number a valid index into the line header's file name
24429 table? Remember that file numbers start with one, not zero. */
24430 if (lh
->is_valid_file_index (file
))
24432 const file_entry
*fe
= lh
->file_name_at (file
);
24434 if (!IS_ABSOLUTE_PATH (fe
->name
))
24436 const char *dir
= fe
->include_dir (lh
);
24438 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24440 return xstrdup (fe
->name
);
24444 /* The compiler produced a bogus file number. We can at least
24445 record the macro definitions made in the file, even if we
24446 won't be able to find the file by name. */
24447 char fake_name
[80];
24449 xsnprintf (fake_name
, sizeof (fake_name
),
24450 "<bad macro file number %d>", file
);
24452 complaint (_("bad file number in macro information (%d)"),
24455 return xstrdup (fake_name
);
24459 /* Return the full name of file number I in *LH's file name table.
24460 Use COMP_DIR as the name of the current directory of the
24461 compilation. The result is allocated using xmalloc; the caller is
24462 responsible for freeing it. */
24464 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24466 /* Is the file number a valid index into the line header's file name
24467 table? Remember that file numbers start with one, not zero. */
24468 if (lh
->is_valid_file_index (file
))
24470 char *relative
= file_file_name (file
, lh
);
24472 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24474 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24475 relative
, (char *) NULL
);
24478 return file_file_name (file
, lh
);
24482 static struct macro_source_file
*
24483 macro_start_file (struct dwarf2_cu
*cu
,
24484 int file
, int line
,
24485 struct macro_source_file
*current_file
,
24486 struct line_header
*lh
)
24488 /* File name relative to the compilation directory of this source file. */
24489 char *file_name
= file_file_name (file
, lh
);
24491 if (! current_file
)
24493 /* Note: We don't create a macro table for this compilation unit
24494 at all until we actually get a filename. */
24495 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24497 /* If we have no current file, then this must be the start_file
24498 directive for the compilation unit's main source file. */
24499 current_file
= macro_set_main (macro_table
, file_name
);
24500 macro_define_special (macro_table
);
24503 current_file
= macro_include (current_file
, line
, file_name
);
24507 return current_file
;
24510 static const char *
24511 consume_improper_spaces (const char *p
, const char *body
)
24515 complaint (_("macro definition contains spaces "
24516 "in formal argument list:\n`%s'"),
24528 parse_macro_definition (struct macro_source_file
*file
, int line
,
24533 /* The body string takes one of two forms. For object-like macro
24534 definitions, it should be:
24536 <macro name> " " <definition>
24538 For function-like macro definitions, it should be:
24540 <macro name> "() " <definition>
24542 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24544 Spaces may appear only where explicitly indicated, and in the
24547 The Dwarf 2 spec says that an object-like macro's name is always
24548 followed by a space, but versions of GCC around March 2002 omit
24549 the space when the macro's definition is the empty string.
24551 The Dwarf 2 spec says that there should be no spaces between the
24552 formal arguments in a function-like macro's formal argument list,
24553 but versions of GCC around March 2002 include spaces after the
24557 /* Find the extent of the macro name. The macro name is terminated
24558 by either a space or null character (for an object-like macro) or
24559 an opening paren (for a function-like macro). */
24560 for (p
= body
; *p
; p
++)
24561 if (*p
== ' ' || *p
== '(')
24564 if (*p
== ' ' || *p
== '\0')
24566 /* It's an object-like macro. */
24567 int name_len
= p
- body
;
24568 std::string
name (body
, name_len
);
24569 const char *replacement
;
24572 replacement
= body
+ name_len
+ 1;
24575 dwarf2_macro_malformed_definition_complaint (body
);
24576 replacement
= body
+ name_len
;
24579 macro_define_object (file
, line
, name
.c_str (), replacement
);
24581 else if (*p
== '(')
24583 /* It's a function-like macro. */
24584 std::string
name (body
, p
- body
);
24587 char **argv
= XNEWVEC (char *, argv_size
);
24591 p
= consume_improper_spaces (p
, body
);
24593 /* Parse the formal argument list. */
24594 while (*p
&& *p
!= ')')
24596 /* Find the extent of the current argument name. */
24597 const char *arg_start
= p
;
24599 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24602 if (! *p
|| p
== arg_start
)
24603 dwarf2_macro_malformed_definition_complaint (body
);
24606 /* Make sure argv has room for the new argument. */
24607 if (argc
>= argv_size
)
24610 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24613 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24616 p
= consume_improper_spaces (p
, body
);
24618 /* Consume the comma, if present. */
24623 p
= consume_improper_spaces (p
, body
);
24632 /* Perfectly formed definition, no complaints. */
24633 macro_define_function (file
, line
, name
.c_str (),
24634 argc
, (const char **) argv
,
24636 else if (*p
== '\0')
24638 /* Complain, but do define it. */
24639 dwarf2_macro_malformed_definition_complaint (body
);
24640 macro_define_function (file
, line
, name
.c_str (),
24641 argc
, (const char **) argv
,
24645 /* Just complain. */
24646 dwarf2_macro_malformed_definition_complaint (body
);
24649 /* Just complain. */
24650 dwarf2_macro_malformed_definition_complaint (body
);
24655 for (i
= 0; i
< argc
; i
++)
24661 dwarf2_macro_malformed_definition_complaint (body
);
24664 /* Skip some bytes from BYTES according to the form given in FORM.
24665 Returns the new pointer. */
24667 static const gdb_byte
*
24668 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24669 enum dwarf_form form
,
24670 unsigned int offset_size
,
24671 struct dwarf2_section_info
*section
)
24673 unsigned int bytes_read
;
24677 case DW_FORM_data1
:
24682 case DW_FORM_data2
:
24686 case DW_FORM_data4
:
24690 case DW_FORM_data8
:
24694 case DW_FORM_data16
:
24698 case DW_FORM_string
:
24699 read_direct_string (abfd
, bytes
, &bytes_read
);
24700 bytes
+= bytes_read
;
24703 case DW_FORM_sec_offset
:
24705 case DW_FORM_GNU_strp_alt
:
24706 bytes
+= offset_size
;
24709 case DW_FORM_block
:
24710 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24711 bytes
+= bytes_read
;
24714 case DW_FORM_block1
:
24715 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24717 case DW_FORM_block2
:
24718 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24720 case DW_FORM_block4
:
24721 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24724 case DW_FORM_addrx
:
24725 case DW_FORM_sdata
:
24727 case DW_FORM_udata
:
24728 case DW_FORM_GNU_addr_index
:
24729 case DW_FORM_GNU_str_index
:
24730 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24733 dwarf2_section_buffer_overflow_complaint (section
);
24738 case DW_FORM_implicit_const
:
24743 complaint (_("invalid form 0x%x in `%s'"),
24744 form
, get_section_name (section
));
24752 /* A helper for dwarf_decode_macros that handles skipping an unknown
24753 opcode. Returns an updated pointer to the macro data buffer; or,
24754 on error, issues a complaint and returns NULL. */
24756 static const gdb_byte
*
24757 skip_unknown_opcode (unsigned int opcode
,
24758 const gdb_byte
**opcode_definitions
,
24759 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24761 unsigned int offset_size
,
24762 struct dwarf2_section_info
*section
)
24764 unsigned int bytes_read
, i
;
24766 const gdb_byte
*defn
;
24768 if (opcode_definitions
[opcode
] == NULL
)
24770 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24775 defn
= opcode_definitions
[opcode
];
24776 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24777 defn
+= bytes_read
;
24779 for (i
= 0; i
< arg
; ++i
)
24781 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24782 (enum dwarf_form
) defn
[i
], offset_size
,
24784 if (mac_ptr
== NULL
)
24786 /* skip_form_bytes already issued the complaint. */
24794 /* A helper function which parses the header of a macro section.
24795 If the macro section is the extended (for now called "GNU") type,
24796 then this updates *OFFSET_SIZE. Returns a pointer to just after
24797 the header, or issues a complaint and returns NULL on error. */
24799 static const gdb_byte
*
24800 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24802 const gdb_byte
*mac_ptr
,
24803 unsigned int *offset_size
,
24804 int section_is_gnu
)
24806 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24808 if (section_is_gnu
)
24810 unsigned int version
, flags
;
24812 version
= read_2_bytes (abfd
, mac_ptr
);
24813 if (version
!= 4 && version
!= 5)
24815 complaint (_("unrecognized version `%d' in .debug_macro section"),
24821 flags
= read_1_byte (abfd
, mac_ptr
);
24823 *offset_size
= (flags
& 1) ? 8 : 4;
24825 if ((flags
& 2) != 0)
24826 /* We don't need the line table offset. */
24827 mac_ptr
+= *offset_size
;
24829 /* Vendor opcode descriptions. */
24830 if ((flags
& 4) != 0)
24832 unsigned int i
, count
;
24834 count
= read_1_byte (abfd
, mac_ptr
);
24836 for (i
= 0; i
< count
; ++i
)
24838 unsigned int opcode
, bytes_read
;
24841 opcode
= read_1_byte (abfd
, mac_ptr
);
24843 opcode_definitions
[opcode
] = mac_ptr
;
24844 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24845 mac_ptr
+= bytes_read
;
24854 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24855 including DW_MACRO_import. */
24858 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24860 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24861 struct macro_source_file
*current_file
,
24862 struct line_header
*lh
,
24863 struct dwarf2_section_info
*section
,
24864 int section_is_gnu
, int section_is_dwz
,
24865 unsigned int offset_size
,
24866 htab_t include_hash
)
24868 struct dwarf2_per_objfile
*dwarf2_per_objfile
24869 = cu
->per_cu
->dwarf2_per_objfile
;
24870 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24871 enum dwarf_macro_record_type macinfo_type
;
24872 int at_commandline
;
24873 const gdb_byte
*opcode_definitions
[256];
24875 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24876 &offset_size
, section_is_gnu
);
24877 if (mac_ptr
== NULL
)
24879 /* We already issued a complaint. */
24883 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24884 GDB is still reading the definitions from command line. First
24885 DW_MACINFO_start_file will need to be ignored as it was already executed
24886 to create CURRENT_FILE for the main source holding also the command line
24887 definitions. On first met DW_MACINFO_start_file this flag is reset to
24888 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24890 at_commandline
= 1;
24894 /* Do we at least have room for a macinfo type byte? */
24895 if (mac_ptr
>= mac_end
)
24897 dwarf2_section_buffer_overflow_complaint (section
);
24901 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24904 /* Note that we rely on the fact that the corresponding GNU and
24905 DWARF constants are the same. */
24907 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24908 switch (macinfo_type
)
24910 /* A zero macinfo type indicates the end of the macro
24915 case DW_MACRO_define
:
24916 case DW_MACRO_undef
:
24917 case DW_MACRO_define_strp
:
24918 case DW_MACRO_undef_strp
:
24919 case DW_MACRO_define_sup
:
24920 case DW_MACRO_undef_sup
:
24922 unsigned int bytes_read
;
24927 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24928 mac_ptr
+= bytes_read
;
24930 if (macinfo_type
== DW_MACRO_define
24931 || macinfo_type
== DW_MACRO_undef
)
24933 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24934 mac_ptr
+= bytes_read
;
24938 LONGEST str_offset
;
24940 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24941 mac_ptr
+= offset_size
;
24943 if (macinfo_type
== DW_MACRO_define_sup
24944 || macinfo_type
== DW_MACRO_undef_sup
24947 struct dwz_file
*dwz
24948 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24950 body
= read_indirect_string_from_dwz (objfile
,
24954 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24958 is_define
= (macinfo_type
== DW_MACRO_define
24959 || macinfo_type
== DW_MACRO_define_strp
24960 || macinfo_type
== DW_MACRO_define_sup
);
24961 if (! current_file
)
24963 /* DWARF violation as no main source is present. */
24964 complaint (_("debug info with no main source gives macro %s "
24966 is_define
? _("definition") : _("undefinition"),
24970 if ((line
== 0 && !at_commandline
)
24971 || (line
!= 0 && at_commandline
))
24972 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24973 at_commandline
? _("command-line") : _("in-file"),
24974 is_define
? _("definition") : _("undefinition"),
24975 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24979 /* Fedora's rpm-build's "debugedit" binary
24980 corrupted .debug_macro sections.
24983 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24984 complaint (_("debug info gives %s invalid macro %s "
24985 "without body (corrupted?) at line %d "
24987 at_commandline
? _("command-line") : _("in-file"),
24988 is_define
? _("definition") : _("undefinition"),
24989 line
, current_file
->filename
);
24991 else if (is_define
)
24992 parse_macro_definition (current_file
, line
, body
);
24995 gdb_assert (macinfo_type
== DW_MACRO_undef
24996 || macinfo_type
== DW_MACRO_undef_strp
24997 || macinfo_type
== DW_MACRO_undef_sup
);
24998 macro_undef (current_file
, line
, body
);
25003 case DW_MACRO_start_file
:
25005 unsigned int bytes_read
;
25008 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25009 mac_ptr
+= bytes_read
;
25010 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25011 mac_ptr
+= bytes_read
;
25013 if ((line
== 0 && !at_commandline
)
25014 || (line
!= 0 && at_commandline
))
25015 complaint (_("debug info gives source %d included "
25016 "from %s at %s line %d"),
25017 file
, at_commandline
? _("command-line") : _("file"),
25018 line
== 0 ? _("zero") : _("non-zero"), line
);
25020 if (at_commandline
)
25022 /* This DW_MACRO_start_file was executed in the
25024 at_commandline
= 0;
25027 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25032 case DW_MACRO_end_file
:
25033 if (! current_file
)
25034 complaint (_("macro debug info has an unmatched "
25035 "`close_file' directive"));
25038 current_file
= current_file
->included_by
;
25039 if (! current_file
)
25041 enum dwarf_macro_record_type next_type
;
25043 /* GCC circa March 2002 doesn't produce the zero
25044 type byte marking the end of the compilation
25045 unit. Complain if it's not there, but exit no
25048 /* Do we at least have room for a macinfo type byte? */
25049 if (mac_ptr
>= mac_end
)
25051 dwarf2_section_buffer_overflow_complaint (section
);
25055 /* We don't increment mac_ptr here, so this is just
25058 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25060 if (next_type
!= 0)
25061 complaint (_("no terminating 0-type entry for "
25062 "macros in `.debug_macinfo' section"));
25069 case DW_MACRO_import
:
25070 case DW_MACRO_import_sup
:
25074 bfd
*include_bfd
= abfd
;
25075 struct dwarf2_section_info
*include_section
= section
;
25076 const gdb_byte
*include_mac_end
= mac_end
;
25077 int is_dwz
= section_is_dwz
;
25078 const gdb_byte
*new_mac_ptr
;
25080 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25081 mac_ptr
+= offset_size
;
25083 if (macinfo_type
== DW_MACRO_import_sup
)
25085 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25087 dwarf2_read_section (objfile
, &dwz
->macro
);
25089 include_section
= &dwz
->macro
;
25090 include_bfd
= get_section_bfd_owner (include_section
);
25091 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25095 new_mac_ptr
= include_section
->buffer
+ offset
;
25096 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25100 /* This has actually happened; see
25101 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25102 complaint (_("recursive DW_MACRO_import in "
25103 ".debug_macro section"));
25107 *slot
= (void *) new_mac_ptr
;
25109 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25110 include_mac_end
, current_file
, lh
,
25111 section
, section_is_gnu
, is_dwz
,
25112 offset_size
, include_hash
);
25114 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25119 case DW_MACINFO_vendor_ext
:
25120 if (!section_is_gnu
)
25122 unsigned int bytes_read
;
25124 /* This reads the constant, but since we don't recognize
25125 any vendor extensions, we ignore it. */
25126 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25127 mac_ptr
+= bytes_read
;
25128 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25129 mac_ptr
+= bytes_read
;
25131 /* We don't recognize any vendor extensions. */
25137 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25138 mac_ptr
, mac_end
, abfd
, offset_size
,
25140 if (mac_ptr
== NULL
)
25145 } while (macinfo_type
!= 0);
25149 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25150 int section_is_gnu
)
25152 struct dwarf2_per_objfile
*dwarf2_per_objfile
25153 = cu
->per_cu
->dwarf2_per_objfile
;
25154 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25155 struct line_header
*lh
= cu
->line_header
;
25157 const gdb_byte
*mac_ptr
, *mac_end
;
25158 struct macro_source_file
*current_file
= 0;
25159 enum dwarf_macro_record_type macinfo_type
;
25160 unsigned int offset_size
= cu
->header
.offset_size
;
25161 const gdb_byte
*opcode_definitions
[256];
25163 struct dwarf2_section_info
*section
;
25164 const char *section_name
;
25166 if (cu
->dwo_unit
!= NULL
)
25168 if (section_is_gnu
)
25170 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25171 section_name
= ".debug_macro.dwo";
25175 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25176 section_name
= ".debug_macinfo.dwo";
25181 if (section_is_gnu
)
25183 section
= &dwarf2_per_objfile
->macro
;
25184 section_name
= ".debug_macro";
25188 section
= &dwarf2_per_objfile
->macinfo
;
25189 section_name
= ".debug_macinfo";
25193 dwarf2_read_section (objfile
, section
);
25194 if (section
->buffer
== NULL
)
25196 complaint (_("missing %s section"), section_name
);
25199 abfd
= get_section_bfd_owner (section
);
25201 /* First pass: Find the name of the base filename.
25202 This filename is needed in order to process all macros whose definition
25203 (or undefinition) comes from the command line. These macros are defined
25204 before the first DW_MACINFO_start_file entry, and yet still need to be
25205 associated to the base file.
25207 To determine the base file name, we scan the macro definitions until we
25208 reach the first DW_MACINFO_start_file entry. We then initialize
25209 CURRENT_FILE accordingly so that any macro definition found before the
25210 first DW_MACINFO_start_file can still be associated to the base file. */
25212 mac_ptr
= section
->buffer
+ offset
;
25213 mac_end
= section
->buffer
+ section
->size
;
25215 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25216 &offset_size
, section_is_gnu
);
25217 if (mac_ptr
== NULL
)
25219 /* We already issued a complaint. */
25225 /* Do we at least have room for a macinfo type byte? */
25226 if (mac_ptr
>= mac_end
)
25228 /* Complaint is printed during the second pass as GDB will probably
25229 stop the first pass earlier upon finding
25230 DW_MACINFO_start_file. */
25234 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25237 /* Note that we rely on the fact that the corresponding GNU and
25238 DWARF constants are the same. */
25240 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25241 switch (macinfo_type
)
25243 /* A zero macinfo type indicates the end of the macro
25248 case DW_MACRO_define
:
25249 case DW_MACRO_undef
:
25250 /* Only skip the data by MAC_PTR. */
25252 unsigned int bytes_read
;
25254 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25255 mac_ptr
+= bytes_read
;
25256 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25257 mac_ptr
+= bytes_read
;
25261 case DW_MACRO_start_file
:
25263 unsigned int bytes_read
;
25266 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25267 mac_ptr
+= bytes_read
;
25268 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25269 mac_ptr
+= bytes_read
;
25271 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25275 case DW_MACRO_end_file
:
25276 /* No data to skip by MAC_PTR. */
25279 case DW_MACRO_define_strp
:
25280 case DW_MACRO_undef_strp
:
25281 case DW_MACRO_define_sup
:
25282 case DW_MACRO_undef_sup
:
25284 unsigned int bytes_read
;
25286 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25287 mac_ptr
+= bytes_read
;
25288 mac_ptr
+= offset_size
;
25292 case DW_MACRO_import
:
25293 case DW_MACRO_import_sup
:
25294 /* Note that, according to the spec, a transparent include
25295 chain cannot call DW_MACRO_start_file. So, we can just
25296 skip this opcode. */
25297 mac_ptr
+= offset_size
;
25300 case DW_MACINFO_vendor_ext
:
25301 /* Only skip the data by MAC_PTR. */
25302 if (!section_is_gnu
)
25304 unsigned int bytes_read
;
25306 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25307 mac_ptr
+= bytes_read
;
25308 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25309 mac_ptr
+= bytes_read
;
25314 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25315 mac_ptr
, mac_end
, abfd
, offset_size
,
25317 if (mac_ptr
== NULL
)
25322 } while (macinfo_type
!= 0 && current_file
== NULL
);
25324 /* Second pass: Process all entries.
25326 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25327 command-line macro definitions/undefinitions. This flag is unset when we
25328 reach the first DW_MACINFO_start_file entry. */
25330 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25332 NULL
, xcalloc
, xfree
));
25333 mac_ptr
= section
->buffer
+ offset
;
25334 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25335 *slot
= (void *) mac_ptr
;
25336 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25337 current_file
, lh
, section
,
25338 section_is_gnu
, 0, offset_size
,
25339 include_hash
.get ());
25342 /* Check if the attribute's form is a DW_FORM_block*
25343 if so return true else false. */
25346 attr_form_is_block (const struct attribute
*attr
)
25348 return (attr
== NULL
? 0 :
25349 attr
->form
== DW_FORM_block1
25350 || attr
->form
== DW_FORM_block2
25351 || attr
->form
== DW_FORM_block4
25352 || attr
->form
== DW_FORM_block
25353 || attr
->form
== DW_FORM_exprloc
);
25356 /* Return non-zero if ATTR's value is a section offset --- classes
25357 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25358 You may use DW_UNSND (attr) to retrieve such offsets.
25360 Section 7.5.4, "Attribute Encodings", explains that no attribute
25361 may have a value that belongs to more than one of these classes; it
25362 would be ambiguous if we did, because we use the same forms for all
25366 attr_form_is_section_offset (const struct attribute
*attr
)
25368 return (attr
->form
== DW_FORM_data4
25369 || attr
->form
== DW_FORM_data8
25370 || attr
->form
== DW_FORM_sec_offset
);
25373 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25374 zero otherwise. When this function returns true, you can apply
25375 dwarf2_get_attr_constant_value to it.
25377 However, note that for some attributes you must check
25378 attr_form_is_section_offset before using this test. DW_FORM_data4
25379 and DW_FORM_data8 are members of both the constant class, and of
25380 the classes that contain offsets into other debug sections
25381 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25382 that, if an attribute's can be either a constant or one of the
25383 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25384 taken as section offsets, not constants.
25386 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25387 cannot handle that. */
25390 attr_form_is_constant (const struct attribute
*attr
)
25392 switch (attr
->form
)
25394 case DW_FORM_sdata
:
25395 case DW_FORM_udata
:
25396 case DW_FORM_data1
:
25397 case DW_FORM_data2
:
25398 case DW_FORM_data4
:
25399 case DW_FORM_data8
:
25400 case DW_FORM_implicit_const
:
25408 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25409 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25412 attr_form_is_ref (const struct attribute
*attr
)
25414 switch (attr
->form
)
25416 case DW_FORM_ref_addr
:
25421 case DW_FORM_ref_udata
:
25422 case DW_FORM_GNU_ref_alt
:
25429 /* Return the .debug_loc section to use for CU.
25430 For DWO files use .debug_loc.dwo. */
25432 static struct dwarf2_section_info
*
25433 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25435 struct dwarf2_per_objfile
*dwarf2_per_objfile
25436 = cu
->per_cu
->dwarf2_per_objfile
;
25440 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25442 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25444 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25445 : &dwarf2_per_objfile
->loc
);
25448 /* A helper function that fills in a dwarf2_loclist_baton. */
25451 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25452 struct dwarf2_loclist_baton
*baton
,
25453 const struct attribute
*attr
)
25455 struct dwarf2_per_objfile
*dwarf2_per_objfile
25456 = cu
->per_cu
->dwarf2_per_objfile
;
25457 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25459 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25461 baton
->per_cu
= cu
->per_cu
;
25462 gdb_assert (baton
->per_cu
);
25463 /* We don't know how long the location list is, but make sure we
25464 don't run off the edge of the section. */
25465 baton
->size
= section
->size
- DW_UNSND (attr
);
25466 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25467 baton
->base_address
= cu
->base_address
;
25468 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25472 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25473 struct dwarf2_cu
*cu
, int is_block
)
25475 struct dwarf2_per_objfile
*dwarf2_per_objfile
25476 = cu
->per_cu
->dwarf2_per_objfile
;
25477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25478 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25480 if (attr_form_is_section_offset (attr
)
25481 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25482 the section. If so, fall through to the complaint in the
25484 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25486 struct dwarf2_loclist_baton
*baton
;
25488 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25490 fill_in_loclist_baton (cu
, baton
, attr
);
25492 if (cu
->base_known
== 0)
25493 complaint (_("Location list used without "
25494 "specifying the CU base address."));
25496 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25497 ? dwarf2_loclist_block_index
25498 : dwarf2_loclist_index
);
25499 SYMBOL_LOCATION_BATON (sym
) = baton
;
25503 struct dwarf2_locexpr_baton
*baton
;
25505 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25506 baton
->per_cu
= cu
->per_cu
;
25507 gdb_assert (baton
->per_cu
);
25509 if (attr_form_is_block (attr
))
25511 /* Note that we're just copying the block's data pointer
25512 here, not the actual data. We're still pointing into the
25513 info_buffer for SYM's objfile; right now we never release
25514 that buffer, but when we do clean up properly this may
25516 baton
->size
= DW_BLOCK (attr
)->size
;
25517 baton
->data
= DW_BLOCK (attr
)->data
;
25521 dwarf2_invalid_attrib_class_complaint ("location description",
25522 sym
->natural_name ());
25526 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25527 ? dwarf2_locexpr_block_index
25528 : dwarf2_locexpr_index
);
25529 SYMBOL_LOCATION_BATON (sym
) = baton
;
25533 /* Return the OBJFILE associated with the compilation unit CU. If CU
25534 came from a separate debuginfo file, then the master objfile is
25538 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25540 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25542 /* Return the master objfile, so that we can report and look up the
25543 correct file containing this variable. */
25544 if (objfile
->separate_debug_objfile_backlink
)
25545 objfile
= objfile
->separate_debug_objfile_backlink
;
25550 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25551 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25552 CU_HEADERP first. */
25554 static const struct comp_unit_head
*
25555 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25556 struct dwarf2_per_cu_data
*per_cu
)
25558 const gdb_byte
*info_ptr
;
25561 return &per_cu
->cu
->header
;
25563 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25565 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25566 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25567 rcuh_kind::COMPILE
);
25572 /* Return the address size given in the compilation unit header for CU. */
25575 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25577 struct comp_unit_head cu_header_local
;
25578 const struct comp_unit_head
*cu_headerp
;
25580 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25582 return cu_headerp
->addr_size
;
25585 /* Return the offset size given in the compilation unit header for CU. */
25588 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25590 struct comp_unit_head cu_header_local
;
25591 const struct comp_unit_head
*cu_headerp
;
25593 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25595 return cu_headerp
->offset_size
;
25598 /* See its dwarf2loc.h declaration. */
25601 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25603 struct comp_unit_head cu_header_local
;
25604 const struct comp_unit_head
*cu_headerp
;
25606 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25608 if (cu_headerp
->version
== 2)
25609 return cu_headerp
->addr_size
;
25611 return cu_headerp
->offset_size
;
25614 /* Return the text offset of the CU. The returned offset comes from
25615 this CU's objfile. If this objfile came from a separate debuginfo
25616 file, then the offset may be different from the corresponding
25617 offset in the parent objfile. */
25620 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25622 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25624 return objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
25627 /* Return a type that is a generic pointer type, the size of which matches
25628 the address size given in the compilation unit header for PER_CU. */
25629 static struct type
*
25630 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25632 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25633 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25634 struct type
*addr_type
= lookup_pointer_type (void_type
);
25635 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25637 if (TYPE_LENGTH (addr_type
) == addr_size
)
25641 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25645 /* Return DWARF version number of PER_CU. */
25648 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25650 return per_cu
->dwarf_version
;
25653 /* Locate the .debug_info compilation unit from CU's objfile which contains
25654 the DIE at OFFSET. Raises an error on failure. */
25656 static struct dwarf2_per_cu_data
*
25657 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25658 unsigned int offset_in_dwz
,
25659 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25661 struct dwarf2_per_cu_data
*this_cu
;
25665 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25668 struct dwarf2_per_cu_data
*mid_cu
;
25669 int mid
= low
+ (high
- low
) / 2;
25671 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25672 if (mid_cu
->is_dwz
> offset_in_dwz
25673 || (mid_cu
->is_dwz
== offset_in_dwz
25674 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25679 gdb_assert (low
== high
);
25680 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25681 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25683 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25684 error (_("Dwarf Error: could not find partial DIE containing "
25685 "offset %s [in module %s]"),
25686 sect_offset_str (sect_off
),
25687 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25689 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25691 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25695 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25696 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25697 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25698 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25703 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25705 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25706 : per_cu (per_cu_
),
25708 has_loclist (false),
25709 checked_producer (false),
25710 producer_is_gxx_lt_4_6 (false),
25711 producer_is_gcc_lt_4_3 (false),
25712 producer_is_icc (false),
25713 producer_is_icc_lt_14 (false),
25714 producer_is_codewarrior (false),
25715 processing_has_namespace_info (false)
25720 /* Destroy a dwarf2_cu. */
25722 dwarf2_cu::~dwarf2_cu ()
25727 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25730 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25731 enum language pretend_language
)
25733 struct attribute
*attr
;
25735 /* Set the language we're debugging. */
25736 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25737 if (attr
!= nullptr)
25738 set_cu_language (DW_UNSND (attr
), cu
);
25741 cu
->language
= pretend_language
;
25742 cu
->language_defn
= language_def (cu
->language
);
25745 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25748 /* Increase the age counter on each cached compilation unit, and free
25749 any that are too old. */
25752 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25754 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25756 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25757 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25758 while (per_cu
!= NULL
)
25760 per_cu
->cu
->last_used
++;
25761 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25762 dwarf2_mark (per_cu
->cu
);
25763 per_cu
= per_cu
->cu
->read_in_chain
;
25766 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25767 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25768 while (per_cu
!= NULL
)
25770 struct dwarf2_per_cu_data
*next_cu
;
25772 next_cu
= per_cu
->cu
->read_in_chain
;
25774 if (!per_cu
->cu
->mark
)
25777 *last_chain
= next_cu
;
25780 last_chain
= &per_cu
->cu
->read_in_chain
;
25786 /* Remove a single compilation unit from the cache. */
25789 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25791 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25792 struct dwarf2_per_objfile
*dwarf2_per_objfile
25793 = target_per_cu
->dwarf2_per_objfile
;
25795 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25796 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25797 while (per_cu
!= NULL
)
25799 struct dwarf2_per_cu_data
*next_cu
;
25801 next_cu
= per_cu
->cu
->read_in_chain
;
25803 if (per_cu
== target_per_cu
)
25807 *last_chain
= next_cu
;
25811 last_chain
= &per_cu
->cu
->read_in_chain
;
25817 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25818 We store these in a hash table separate from the DIEs, and preserve them
25819 when the DIEs are flushed out of cache.
25821 The CU "per_cu" pointer is needed because offset alone is not enough to
25822 uniquely identify the type. A file may have multiple .debug_types sections,
25823 or the type may come from a DWO file. Furthermore, while it's more logical
25824 to use per_cu->section+offset, with Fission the section with the data is in
25825 the DWO file but we don't know that section at the point we need it.
25826 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25827 because we can enter the lookup routine, get_die_type_at_offset, from
25828 outside this file, and thus won't necessarily have PER_CU->cu.
25829 Fortunately, PER_CU is stable for the life of the objfile. */
25831 struct dwarf2_per_cu_offset_and_type
25833 const struct dwarf2_per_cu_data
*per_cu
;
25834 sect_offset sect_off
;
25838 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25841 per_cu_offset_and_type_hash (const void *item
)
25843 const struct dwarf2_per_cu_offset_and_type
*ofs
25844 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25846 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25849 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25852 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25854 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25855 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25856 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25857 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25859 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25860 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25863 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25864 table if necessary. For convenience, return TYPE.
25866 The DIEs reading must have careful ordering to:
25867 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25868 reading current DIE.
25869 * Not trying to dereference contents of still incompletely read in types
25870 while reading in other DIEs.
25871 * Enable referencing still incompletely read in types just by a pointer to
25872 the type without accessing its fields.
25874 Therefore caller should follow these rules:
25875 * Try to fetch any prerequisite types we may need to build this DIE type
25876 before building the type and calling set_die_type.
25877 * After building type call set_die_type for current DIE as soon as
25878 possible before fetching more types to complete the current type.
25879 * Make the type as complete as possible before fetching more types. */
25881 static struct type
*
25882 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25884 struct dwarf2_per_objfile
*dwarf2_per_objfile
25885 = cu
->per_cu
->dwarf2_per_objfile
;
25886 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25887 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25888 struct attribute
*attr
;
25889 struct dynamic_prop prop
;
25891 /* For Ada types, make sure that the gnat-specific data is always
25892 initialized (if not already set). There are a few types where
25893 we should not be doing so, because the type-specific area is
25894 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25895 where the type-specific area is used to store the floatformat).
25896 But this is not a problem, because the gnat-specific information
25897 is actually not needed for these types. */
25898 if (need_gnat_info (cu
)
25899 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25900 && TYPE_CODE (type
) != TYPE_CODE_FLT
25901 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25902 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25903 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25904 && !HAVE_GNAT_AUX_INFO (type
))
25905 INIT_GNAT_SPECIFIC (type
);
25907 /* Read DW_AT_allocated and set in type. */
25908 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25909 if (attr_form_is_block (attr
))
25911 struct type
*prop_type
25912 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25913 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25914 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25916 else if (attr
!= NULL
)
25918 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25919 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25920 sect_offset_str (die
->sect_off
));
25923 /* Read DW_AT_associated and set in type. */
25924 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25925 if (attr_form_is_block (attr
))
25927 struct type
*prop_type
25928 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25929 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25930 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25932 else if (attr
!= NULL
)
25934 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25935 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25936 sect_offset_str (die
->sect_off
));
25939 /* Read DW_AT_data_location and set in type. */
25940 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25941 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25942 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25943 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25945 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25947 dwarf2_per_objfile
->die_type_hash
=
25948 htab_create_alloc_ex (127,
25949 per_cu_offset_and_type_hash
,
25950 per_cu_offset_and_type_eq
,
25952 &objfile
->objfile_obstack
,
25953 hashtab_obstack_allocate
,
25954 dummy_obstack_deallocate
);
25957 ofs
.per_cu
= cu
->per_cu
;
25958 ofs
.sect_off
= die
->sect_off
;
25960 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25961 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25963 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25964 sect_offset_str (die
->sect_off
));
25965 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25966 struct dwarf2_per_cu_offset_and_type
);
25971 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25972 or return NULL if the die does not have a saved type. */
25974 static struct type
*
25975 get_die_type_at_offset (sect_offset sect_off
,
25976 struct dwarf2_per_cu_data
*per_cu
)
25978 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25979 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25981 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25984 ofs
.per_cu
= per_cu
;
25985 ofs
.sect_off
= sect_off
;
25986 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25987 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25994 /* Look up the type for DIE in CU in die_type_hash,
25995 or return NULL if DIE does not have a saved type. */
25997 static struct type
*
25998 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26000 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26003 /* Add a dependence relationship from CU to REF_PER_CU. */
26006 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26007 struct dwarf2_per_cu_data
*ref_per_cu
)
26011 if (cu
->dependencies
== NULL
)
26013 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26014 NULL
, &cu
->comp_unit_obstack
,
26015 hashtab_obstack_allocate
,
26016 dummy_obstack_deallocate
);
26018 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26020 *slot
= ref_per_cu
;
26023 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26024 Set the mark field in every compilation unit in the
26025 cache that we must keep because we are keeping CU. */
26028 dwarf2_mark_helper (void **slot
, void *data
)
26030 struct dwarf2_per_cu_data
*per_cu
;
26032 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26034 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26035 reading of the chain. As such dependencies remain valid it is not much
26036 useful to track and undo them during QUIT cleanups. */
26037 if (per_cu
->cu
== NULL
)
26040 if (per_cu
->cu
->mark
)
26042 per_cu
->cu
->mark
= true;
26044 if (per_cu
->cu
->dependencies
!= NULL
)
26045 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26050 /* Set the mark field in CU and in every other compilation unit in the
26051 cache that we must keep because we are keeping CU. */
26054 dwarf2_mark (struct dwarf2_cu
*cu
)
26059 if (cu
->dependencies
!= NULL
)
26060 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26064 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26068 per_cu
->cu
->mark
= false;
26069 per_cu
= per_cu
->cu
->read_in_chain
;
26073 /* Trivial hash function for partial_die_info: the hash value of a DIE
26074 is its offset in .debug_info for this objfile. */
26077 partial_die_hash (const void *item
)
26079 const struct partial_die_info
*part_die
26080 = (const struct partial_die_info
*) item
;
26082 return to_underlying (part_die
->sect_off
);
26085 /* Trivial comparison function for partial_die_info structures: two DIEs
26086 are equal if they have the same offset. */
26089 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26091 const struct partial_die_info
*part_die_lhs
26092 = (const struct partial_die_info
*) item_lhs
;
26093 const struct partial_die_info
*part_die_rhs
26094 = (const struct partial_die_info
*) item_rhs
;
26096 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26099 struct cmd_list_element
*set_dwarf_cmdlist
;
26100 struct cmd_list_element
*show_dwarf_cmdlist
;
26103 set_dwarf_cmd (const char *args
, int from_tty
)
26105 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26110 show_dwarf_cmd (const char *args
, int from_tty
)
26112 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26115 bool dwarf_always_disassemble
;
26118 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26119 struct cmd_list_element
*c
, const char *value
)
26121 fprintf_filtered (file
,
26122 _("Whether to always disassemble "
26123 "DWARF expressions is %s.\n"),
26128 show_check_physname (struct ui_file
*file
, int from_tty
,
26129 struct cmd_list_element
*c
, const char *value
)
26131 fprintf_filtered (file
,
26132 _("Whether to check \"physname\" is %s.\n"),
26137 _initialize_dwarf2_read (void)
26139 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26140 Set DWARF specific variables.\n\
26141 Configure DWARF variables such as the cache size."),
26142 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26143 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26145 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26146 Show DWARF specific variables.\n\
26147 Show DWARF variables such as the cache size."),
26148 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26149 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26151 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26152 &dwarf_max_cache_age
, _("\
26153 Set the upper bound on the age of cached DWARF compilation units."), _("\
26154 Show the upper bound on the age of cached DWARF compilation units."), _("\
26155 A higher limit means that cached compilation units will be stored\n\
26156 in memory longer, and more total memory will be used. Zero disables\n\
26157 caching, which can slow down startup."),
26159 show_dwarf_max_cache_age
,
26160 &set_dwarf_cmdlist
,
26161 &show_dwarf_cmdlist
);
26163 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26164 &dwarf_always_disassemble
, _("\
26165 Set whether `info address' always disassembles DWARF expressions."), _("\
26166 Show whether `info address' always disassembles DWARF expressions."), _("\
26167 When enabled, DWARF expressions are always printed in an assembly-like\n\
26168 syntax. When disabled, expressions will be printed in a more\n\
26169 conversational style, when possible."),
26171 show_dwarf_always_disassemble
,
26172 &set_dwarf_cmdlist
,
26173 &show_dwarf_cmdlist
);
26175 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26176 Set debugging of the DWARF reader."), _("\
26177 Show debugging of the DWARF reader."), _("\
26178 When enabled (non-zero), debugging messages are printed during DWARF\n\
26179 reading and symtab expansion. A value of 1 (one) provides basic\n\
26180 information. A value greater than 1 provides more verbose information."),
26183 &setdebuglist
, &showdebuglist
);
26185 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26186 Set debugging of the DWARF DIE reader."), _("\
26187 Show debugging of the DWARF DIE reader."), _("\
26188 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26189 The value is the maximum depth to print."),
26192 &setdebuglist
, &showdebuglist
);
26194 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26195 Set debugging of the dwarf line reader."), _("\
26196 Show debugging of the dwarf line reader."), _("\
26197 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26198 A value of 1 (one) provides basic information.\n\
26199 A value greater than 1 provides more verbose information."),
26202 &setdebuglist
, &showdebuglist
);
26204 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26205 Set cross-checking of \"physname\" code against demangler."), _("\
26206 Show cross-checking of \"physname\" code against demangler."), _("\
26207 When enabled, GDB's internal \"physname\" code is checked against\n\
26209 NULL
, show_check_physname
,
26210 &setdebuglist
, &showdebuglist
);
26212 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26213 no_class
, &use_deprecated_index_sections
, _("\
26214 Set whether to use deprecated gdb_index sections."), _("\
26215 Show whether to use deprecated gdb_index sections."), _("\
26216 When enabled, deprecated .gdb_index sections are used anyway.\n\
26217 Normally they are ignored either because of a missing feature or\n\
26218 performance issue.\n\
26219 Warning: This option must be enabled before gdb reads the file."),
26222 &setlist
, &showlist
);
26224 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26225 &dwarf2_locexpr_funcs
);
26226 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26227 &dwarf2_loclist_funcs
);
26229 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26230 &dwarf2_block_frame_base_locexpr_funcs
);
26231 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26232 &dwarf2_block_frame_base_loclist_funcs
);
26235 selftests::register_test ("dw2_expand_symtabs_matching",
26236 selftests::dw2_expand_symtabs_matching::run_test
);