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
= ANOFFSET (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
= ANOFFSET (objfile
->section_offsets
,
3220 SECT_OFF_TEXT (objfile
));
3222 auto_obstack temp_obstack
;
3223 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3225 std::unordered_map
<sect_offset
,
3226 dwarf2_per_cu_data
*,
3227 gdb::hash_enum
<sect_offset
>>
3228 debug_info_offset_to_per_cu
;
3229 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3231 const auto insertpair
3232 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3233 if (!insertpair
.second
)
3235 warning (_("Section .debug_aranges in %s has duplicate "
3236 "debug_info_offset %s, ignoring .debug_aranges."),
3237 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3242 dwarf2_read_section (objfile
, section
);
3244 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3246 const gdb_byte
*addr
= section
->buffer
;
3248 while (addr
< section
->buffer
+ section
->size
)
3250 const gdb_byte
*const entry_addr
= addr
;
3251 unsigned int bytes_read
;
3253 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3257 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3258 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3259 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3260 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3262 warning (_("Section .debug_aranges in %s entry at offset %s "
3263 "length %s exceeds section length %s, "
3264 "ignoring .debug_aranges."),
3265 objfile_name (objfile
),
3266 plongest (entry_addr
- section
->buffer
),
3267 plongest (bytes_read
+ entry_length
),
3268 pulongest (section
->size
));
3272 /* The version number. */
3273 const uint16_t version
= read_2_bytes (abfd
, addr
);
3277 warning (_("Section .debug_aranges in %s entry at offset %s "
3278 "has unsupported version %d, ignoring .debug_aranges."),
3279 objfile_name (objfile
),
3280 plongest (entry_addr
- section
->buffer
), version
);
3284 const uint64_t debug_info_offset
3285 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3286 addr
+= offset_size
;
3287 const auto per_cu_it
3288 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3289 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3291 warning (_("Section .debug_aranges in %s entry at offset %s "
3292 "debug_info_offset %s does not exists, "
3293 "ignoring .debug_aranges."),
3294 objfile_name (objfile
),
3295 plongest (entry_addr
- section
->buffer
),
3296 pulongest (debug_info_offset
));
3299 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3301 const uint8_t address_size
= *addr
++;
3302 if (address_size
< 1 || address_size
> 8)
3304 warning (_("Section .debug_aranges in %s entry at offset %s "
3305 "address_size %u is invalid, ignoring .debug_aranges."),
3306 objfile_name (objfile
),
3307 plongest (entry_addr
- section
->buffer
), address_size
);
3311 const uint8_t segment_selector_size
= *addr
++;
3312 if (segment_selector_size
!= 0)
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "segment_selector_size %u is not supported, "
3316 "ignoring .debug_aranges."),
3317 objfile_name (objfile
),
3318 plongest (entry_addr
- section
->buffer
),
3319 segment_selector_size
);
3323 /* Must pad to an alignment boundary that is twice the address
3324 size. It is undocumented by the DWARF standard but GCC does
3326 for (size_t padding
= ((-(addr
- section
->buffer
))
3327 & (2 * address_size
- 1));
3328 padding
> 0; padding
--)
3331 warning (_("Section .debug_aranges in %s entry at offset %s "
3332 "padding is not zero, ignoring .debug_aranges."),
3333 objfile_name (objfile
),
3334 plongest (entry_addr
- section
->buffer
));
3340 if (addr
+ 2 * address_size
> entry_end
)
3342 warning (_("Section .debug_aranges in %s entry at offset %s "
3343 "address list is not properly terminated, "
3344 "ignoring .debug_aranges."),
3345 objfile_name (objfile
),
3346 plongest (entry_addr
- section
->buffer
));
3349 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3351 addr
+= address_size
;
3352 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3354 addr
+= address_size
;
3355 if (start
== 0 && length
== 0)
3357 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3359 /* Symbol was eliminated due to a COMDAT group. */
3362 ULONGEST end
= start
+ length
;
3363 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3365 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3367 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3371 objfile
->partial_symtabs
->psymtabs_addrmap
3372 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3375 /* Find a slot in the mapped index INDEX for the object named NAME.
3376 If NAME is found, set *VEC_OUT to point to the CU vector in the
3377 constant pool and return true. If NAME cannot be found, return
3381 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3382 offset_type
**vec_out
)
3385 offset_type slot
, step
;
3386 int (*cmp
) (const char *, const char *);
3388 gdb::unique_xmalloc_ptr
<char> without_params
;
3389 if (current_language
->la_language
== language_cplus
3390 || current_language
->la_language
== language_fortran
3391 || current_language
->la_language
== language_d
)
3393 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3396 if (strchr (name
, '(') != NULL
)
3398 without_params
= cp_remove_params (name
);
3400 if (without_params
!= NULL
)
3401 name
= without_params
.get ();
3405 /* Index version 4 did not support case insensitive searches. But the
3406 indices for case insensitive languages are built in lowercase, therefore
3407 simulate our NAME being searched is also lowercased. */
3408 hash
= mapped_index_string_hash ((index
->version
== 4
3409 && case_sensitivity
== case_sensitive_off
3410 ? 5 : index
->version
),
3413 slot
= hash
& (index
->symbol_table
.size () - 1);
3414 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3415 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3421 const auto &bucket
= index
->symbol_table
[slot
];
3422 if (bucket
.name
== 0 && bucket
.vec
== 0)
3425 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3426 if (!cmp (name
, str
))
3428 *vec_out
= (offset_type
*) (index
->constant_pool
3429 + MAYBE_SWAP (bucket
.vec
));
3433 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3437 /* A helper function that reads the .gdb_index from BUFFER and fills
3438 in MAP. FILENAME is the name of the file containing the data;
3439 it is used for error reporting. DEPRECATED_OK is true if it is
3440 ok to use deprecated sections.
3442 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3443 out parameters that are filled in with information about the CU and
3444 TU lists in the section.
3446 Returns true if all went well, false otherwise. */
3449 read_gdb_index_from_buffer (struct objfile
*objfile
,
3450 const char *filename
,
3452 gdb::array_view
<const gdb_byte
> buffer
,
3453 struct mapped_index
*map
,
3454 const gdb_byte
**cu_list
,
3455 offset_type
*cu_list_elements
,
3456 const gdb_byte
**types_list
,
3457 offset_type
*types_list_elements
)
3459 const gdb_byte
*addr
= &buffer
[0];
3461 /* Version check. */
3462 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3463 /* Versions earlier than 3 emitted every copy of a psymbol. This
3464 causes the index to behave very poorly for certain requests. Version 3
3465 contained incomplete addrmap. So, it seems better to just ignore such
3469 static int warning_printed
= 0;
3470 if (!warning_printed
)
3472 warning (_("Skipping obsolete .gdb_index section in %s."),
3474 warning_printed
= 1;
3478 /* Index version 4 uses a different hash function than index version
3481 Versions earlier than 6 did not emit psymbols for inlined
3482 functions. Using these files will cause GDB not to be able to
3483 set breakpoints on inlined functions by name, so we ignore these
3484 indices unless the user has done
3485 "set use-deprecated-index-sections on". */
3486 if (version
< 6 && !deprecated_ok
)
3488 static int warning_printed
= 0;
3489 if (!warning_printed
)
3492 Skipping deprecated .gdb_index section in %s.\n\
3493 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3494 to use the section anyway."),
3496 warning_printed
= 1;
3500 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3501 of the TU (for symbols coming from TUs),
3502 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3503 Plus gold-generated indices can have duplicate entries for global symbols,
3504 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3505 These are just performance bugs, and we can't distinguish gdb-generated
3506 indices from gold-generated ones, so issue no warning here. */
3508 /* Indexes with higher version than the one supported by GDB may be no
3509 longer backward compatible. */
3513 map
->version
= version
;
3515 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3518 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3519 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3523 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3524 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3525 - MAYBE_SWAP (metadata
[i
]))
3529 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3530 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3532 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3535 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3536 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3538 = gdb::array_view
<mapped_index::symbol_table_slot
>
3539 ((mapped_index::symbol_table_slot
*) symbol_table
,
3540 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3543 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3548 /* Callback types for dwarf2_read_gdb_index. */
3550 typedef gdb::function_view
3551 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3552 get_gdb_index_contents_ftype
;
3553 typedef gdb::function_view
3554 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3555 get_gdb_index_contents_dwz_ftype
;
3557 /* Read .gdb_index. If everything went ok, initialize the "quick"
3558 elements of all the CUs and return 1. Otherwise, return 0. */
3561 dwarf2_read_gdb_index
3562 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3563 get_gdb_index_contents_ftype get_gdb_index_contents
,
3564 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3566 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3567 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3568 struct dwz_file
*dwz
;
3569 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3571 gdb::array_view
<const gdb_byte
> main_index_contents
3572 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3574 if (main_index_contents
.empty ())
3577 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3578 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3579 use_deprecated_index_sections
,
3580 main_index_contents
, map
.get (), &cu_list
,
3581 &cu_list_elements
, &types_list
,
3582 &types_list_elements
))
3585 /* Don't use the index if it's empty. */
3586 if (map
->symbol_table
.empty ())
3589 /* If there is a .dwz file, read it so we can get its CU list as
3591 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3594 struct mapped_index dwz_map
;
3595 const gdb_byte
*dwz_types_ignore
;
3596 offset_type dwz_types_elements_ignore
;
3598 gdb::array_view
<const gdb_byte
> dwz_index_content
3599 = get_gdb_index_contents_dwz (objfile
, dwz
);
3601 if (dwz_index_content
.empty ())
3604 if (!read_gdb_index_from_buffer (objfile
,
3605 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3606 1, dwz_index_content
, &dwz_map
,
3607 &dwz_list
, &dwz_list_elements
,
3609 &dwz_types_elements_ignore
))
3611 warning (_("could not read '.gdb_index' section from %s; skipping"),
3612 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3617 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3618 dwz_list
, dwz_list_elements
);
3620 if (types_list_elements
)
3622 /* We can only handle a single .debug_types when we have an
3624 if (dwarf2_per_objfile
->types
.size () != 1)
3627 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3629 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3630 types_list
, types_list_elements
);
3633 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3635 dwarf2_per_objfile
->index_table
= std::move (map
);
3636 dwarf2_per_objfile
->using_index
= 1;
3637 dwarf2_per_objfile
->quick_file_names_table
=
3638 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3643 /* die_reader_func for dw2_get_file_names. */
3646 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3647 const gdb_byte
*info_ptr
,
3648 struct die_info
*comp_unit_die
,
3652 struct dwarf2_cu
*cu
= reader
->cu
;
3653 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3654 struct dwarf2_per_objfile
*dwarf2_per_objfile
3655 = cu
->per_cu
->dwarf2_per_objfile
;
3656 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3657 struct dwarf2_per_cu_data
*lh_cu
;
3658 struct attribute
*attr
;
3660 struct quick_file_names
*qfn
;
3662 gdb_assert (! this_cu
->is_debug_types
);
3664 /* Our callers never want to match partial units -- instead they
3665 will match the enclosing full CU. */
3666 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3668 this_cu
->v
.quick
->no_file_data
= 1;
3676 sect_offset line_offset
{};
3678 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3679 if (attr
!= nullptr)
3681 struct quick_file_names find_entry
;
3683 line_offset
= (sect_offset
) DW_UNSND (attr
);
3685 /* We may have already read in this line header (TU line header sharing).
3686 If we have we're done. */
3687 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3688 find_entry
.hash
.line_sect_off
= line_offset
;
3689 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3690 &find_entry
, INSERT
);
3693 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3697 lh
= dwarf_decode_line_header (line_offset
, cu
);
3701 lh_cu
->v
.quick
->no_file_data
= 1;
3705 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3706 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3707 qfn
->hash
.line_sect_off
= line_offset
;
3708 gdb_assert (slot
!= NULL
);
3711 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3714 if (strcmp (fnd
.name
, "<unknown>") != 0)
3717 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3719 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3721 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3722 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3723 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3724 qfn
->real_names
= NULL
;
3726 lh_cu
->v
.quick
->file_names
= qfn
;
3729 /* A helper for the "quick" functions which attempts to read the line
3730 table for THIS_CU. */
3732 static struct quick_file_names
*
3733 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3735 /* This should never be called for TUs. */
3736 gdb_assert (! this_cu
->is_debug_types
);
3737 /* Nor type unit groups. */
3738 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3740 if (this_cu
->v
.quick
->file_names
!= NULL
)
3741 return this_cu
->v
.quick
->file_names
;
3742 /* If we know there is no line data, no point in looking again. */
3743 if (this_cu
->v
.quick
->no_file_data
)
3746 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3748 if (this_cu
->v
.quick
->no_file_data
)
3750 return this_cu
->v
.quick
->file_names
;
3753 /* A helper for the "quick" functions which computes and caches the
3754 real path for a given file name from the line table. */
3757 dw2_get_real_path (struct objfile
*objfile
,
3758 struct quick_file_names
*qfn
, int index
)
3760 if (qfn
->real_names
== NULL
)
3761 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3762 qfn
->num_file_names
, const char *);
3764 if (qfn
->real_names
[index
] == NULL
)
3765 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3767 return qfn
->real_names
[index
];
3770 static struct symtab
*
3771 dw2_find_last_source_symtab (struct objfile
*objfile
)
3773 struct dwarf2_per_objfile
*dwarf2_per_objfile
3774 = get_dwarf2_per_objfile (objfile
);
3775 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3776 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3781 return compunit_primary_filetab (cust
);
3784 /* Traversal function for dw2_forget_cached_source_info. */
3787 dw2_free_cached_file_names (void **slot
, void *info
)
3789 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3791 if (file_data
->real_names
)
3795 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3797 xfree ((void*) file_data
->real_names
[i
]);
3798 file_data
->real_names
[i
] = NULL
;
3806 dw2_forget_cached_source_info (struct objfile
*objfile
)
3808 struct dwarf2_per_objfile
*dwarf2_per_objfile
3809 = get_dwarf2_per_objfile (objfile
);
3811 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3812 dw2_free_cached_file_names
, NULL
);
3815 /* Helper function for dw2_map_symtabs_matching_filename that expands
3816 the symtabs and calls the iterator. */
3819 dw2_map_expand_apply (struct objfile
*objfile
,
3820 struct dwarf2_per_cu_data
*per_cu
,
3821 const char *name
, const char *real_path
,
3822 gdb::function_view
<bool (symtab
*)> callback
)
3824 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3826 /* Don't visit already-expanded CUs. */
3827 if (per_cu
->v
.quick
->compunit_symtab
)
3830 /* This may expand more than one symtab, and we want to iterate over
3832 dw2_instantiate_symtab (per_cu
, false);
3834 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3835 last_made
, callback
);
3838 /* Implementation of the map_symtabs_matching_filename method. */
3841 dw2_map_symtabs_matching_filename
3842 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3843 gdb::function_view
<bool (symtab
*)> callback
)
3845 const char *name_basename
= lbasename (name
);
3846 struct dwarf2_per_objfile
*dwarf2_per_objfile
3847 = get_dwarf2_per_objfile (objfile
);
3849 /* The rule is CUs specify all the files, including those used by
3850 any TU, so there's no need to scan TUs here. */
3852 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3854 /* We only need to look at symtabs not already expanded. */
3855 if (per_cu
->v
.quick
->compunit_symtab
)
3858 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3859 if (file_data
== NULL
)
3862 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3864 const char *this_name
= file_data
->file_names
[j
];
3865 const char *this_real_name
;
3867 if (compare_filenames_for_search (this_name
, name
))
3869 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3875 /* Before we invoke realpath, which can get expensive when many
3876 files are involved, do a quick comparison of the basenames. */
3877 if (! basenames_may_differ
3878 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3881 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3882 if (compare_filenames_for_search (this_real_name
, name
))
3884 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3890 if (real_path
!= NULL
)
3892 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3893 gdb_assert (IS_ABSOLUTE_PATH (name
));
3894 if (this_real_name
!= NULL
3895 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3897 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3909 /* Struct used to manage iterating over all CUs looking for a symbol. */
3911 struct dw2_symtab_iterator
3913 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3914 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3915 /* If set, only look for symbols that match that block. Valid values are
3916 GLOBAL_BLOCK and STATIC_BLOCK. */
3917 gdb::optional
<block_enum
> block_index
;
3918 /* The kind of symbol we're looking for. */
3920 /* The list of CUs from the index entry of the symbol,
3921 or NULL if not found. */
3923 /* The next element in VEC to look at. */
3925 /* The number of elements in VEC, or zero if there is no match. */
3927 /* Have we seen a global version of the symbol?
3928 If so we can ignore all further global instances.
3929 This is to work around gold/15646, inefficient gold-generated
3934 /* Initialize the index symtab iterator ITER. */
3937 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3938 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3939 gdb::optional
<block_enum
> block_index
,
3943 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3944 iter
->block_index
= block_index
;
3945 iter
->domain
= domain
;
3947 iter
->global_seen
= 0;
3949 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3951 /* index is NULL if OBJF_READNOW. */
3952 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3953 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3961 /* Return the next matching CU or NULL if there are no more. */
3963 static struct dwarf2_per_cu_data
*
3964 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3966 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3968 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3970 offset_type cu_index_and_attrs
=
3971 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3972 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3973 gdb_index_symbol_kind symbol_kind
=
3974 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3975 /* Only check the symbol attributes if they're present.
3976 Indices prior to version 7 don't record them,
3977 and indices >= 7 may elide them for certain symbols
3978 (gold does this). */
3980 (dwarf2_per_objfile
->index_table
->version
>= 7
3981 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3983 /* Don't crash on bad data. */
3984 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3985 + dwarf2_per_objfile
->all_type_units
.size ()))
3987 complaint (_(".gdb_index entry has bad CU index"
3989 objfile_name (dwarf2_per_objfile
->objfile
));
3993 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3995 /* Skip if already read in. */
3996 if (per_cu
->v
.quick
->compunit_symtab
)
3999 /* Check static vs global. */
4002 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4004 if (iter
->block_index
.has_value ())
4006 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4008 if (is_static
!= want_static
)
4012 /* Work around gold/15646. */
4013 if (!is_static
&& iter
->global_seen
)
4016 iter
->global_seen
= 1;
4019 /* Only check the symbol's kind if it has one. */
4022 switch (iter
->domain
)
4025 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4026 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4027 /* Some types are also in VAR_DOMAIN. */
4028 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4032 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4036 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4040 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4055 static struct compunit_symtab
*
4056 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4057 const char *name
, domain_enum domain
)
4059 struct compunit_symtab
*stab_best
= NULL
;
4060 struct dwarf2_per_objfile
*dwarf2_per_objfile
4061 = get_dwarf2_per_objfile (objfile
);
4063 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4065 struct dw2_symtab_iterator iter
;
4066 struct dwarf2_per_cu_data
*per_cu
;
4068 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4070 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4072 struct symbol
*sym
, *with_opaque
= NULL
;
4073 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4074 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4075 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4077 sym
= block_find_symbol (block
, name
, domain
,
4078 block_find_non_opaque_type_preferred
,
4081 /* Some caution must be observed with overloaded functions
4082 and methods, since the index will not contain any overload
4083 information (but NAME might contain it). */
4086 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4088 if (with_opaque
!= NULL
4089 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4092 /* Keep looking through other CUs. */
4099 dw2_print_stats (struct objfile
*objfile
)
4101 struct dwarf2_per_objfile
*dwarf2_per_objfile
4102 = get_dwarf2_per_objfile (objfile
);
4103 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4104 + dwarf2_per_objfile
->all_type_units
.size ());
4107 for (int i
= 0; i
< total
; ++i
)
4109 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4111 if (!per_cu
->v
.quick
->compunit_symtab
)
4114 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4115 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4118 /* This dumps minimal information about the index.
4119 It is called via "mt print objfiles".
4120 One use is to verify .gdb_index has been loaded by the
4121 gdb.dwarf2/gdb-index.exp testcase. */
4124 dw2_dump (struct objfile
*objfile
)
4126 struct dwarf2_per_objfile
*dwarf2_per_objfile
4127 = get_dwarf2_per_objfile (objfile
);
4129 gdb_assert (dwarf2_per_objfile
->using_index
);
4130 printf_filtered (".gdb_index:");
4131 if (dwarf2_per_objfile
->index_table
!= NULL
)
4133 printf_filtered (" version %d\n",
4134 dwarf2_per_objfile
->index_table
->version
);
4137 printf_filtered (" faked for \"readnow\"\n");
4138 printf_filtered ("\n");
4142 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4143 const char *func_name
)
4145 struct dwarf2_per_objfile
*dwarf2_per_objfile
4146 = get_dwarf2_per_objfile (objfile
);
4148 struct dw2_symtab_iterator iter
;
4149 struct dwarf2_per_cu_data
*per_cu
;
4151 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4153 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4154 dw2_instantiate_symtab (per_cu
, false);
4159 dw2_expand_all_symtabs (struct objfile
*objfile
)
4161 struct dwarf2_per_objfile
*dwarf2_per_objfile
4162 = get_dwarf2_per_objfile (objfile
);
4163 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4164 + dwarf2_per_objfile
->all_type_units
.size ());
4166 for (int i
= 0; i
< total_units
; ++i
)
4168 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4170 /* We don't want to directly expand a partial CU, because if we
4171 read it with the wrong language, then assertion failures can
4172 be triggered later on. See PR symtab/23010. So, tell
4173 dw2_instantiate_symtab to skip partial CUs -- any important
4174 partial CU will be read via DW_TAG_imported_unit anyway. */
4175 dw2_instantiate_symtab (per_cu
, true);
4180 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4181 const char *fullname
)
4183 struct dwarf2_per_objfile
*dwarf2_per_objfile
4184 = get_dwarf2_per_objfile (objfile
);
4186 /* We don't need to consider type units here.
4187 This is only called for examining code, e.g. expand_line_sal.
4188 There can be an order of magnitude (or more) more type units
4189 than comp units, and we avoid them if we can. */
4191 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4193 /* We only need to look at symtabs not already expanded. */
4194 if (per_cu
->v
.quick
->compunit_symtab
)
4197 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4198 if (file_data
== NULL
)
4201 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4203 const char *this_fullname
= file_data
->file_names
[j
];
4205 if (filename_cmp (this_fullname
, fullname
) == 0)
4207 dw2_instantiate_symtab (per_cu
, false);
4215 dw2_map_matching_symbols
4216 (struct objfile
*objfile
,
4217 const lookup_name_info
&name
, domain_enum domain
,
4219 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4220 symbol_compare_ftype
*ordered_compare
)
4222 /* Currently unimplemented; used for Ada. The function can be called if the
4223 current language is Ada for a non-Ada objfile using GNU index. As Ada
4224 does not look for non-Ada symbols this function should just return. */
4227 /* Starting from a search name, return the string that finds the upper
4228 bound of all strings that start with SEARCH_NAME in a sorted name
4229 list. Returns the empty string to indicate that the upper bound is
4230 the end of the list. */
4233 make_sort_after_prefix_name (const char *search_name
)
4235 /* When looking to complete "func", we find the upper bound of all
4236 symbols that start with "func" by looking for where we'd insert
4237 the closest string that would follow "func" in lexicographical
4238 order. Usually, that's "func"-with-last-character-incremented,
4239 i.e. "fund". Mind non-ASCII characters, though. Usually those
4240 will be UTF-8 multi-byte sequences, but we can't be certain.
4241 Especially mind the 0xff character, which is a valid character in
4242 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4243 rule out compilers allowing it in identifiers. Note that
4244 conveniently, strcmp/strcasecmp are specified to compare
4245 characters interpreted as unsigned char. So what we do is treat
4246 the whole string as a base 256 number composed of a sequence of
4247 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4248 to 0, and carries 1 to the following more-significant position.
4249 If the very first character in SEARCH_NAME ends up incremented
4250 and carries/overflows, then the upper bound is the end of the
4251 list. The string after the empty string is also the empty
4254 Some examples of this operation:
4256 SEARCH_NAME => "+1" RESULT
4260 "\xff" "a" "\xff" => "\xff" "b"
4265 Then, with these symbols for example:
4271 completing "func" looks for symbols between "func" and
4272 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4273 which finds "func" and "func1", but not "fund".
4277 funcÿ (Latin1 'ÿ' [0xff])
4281 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4282 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4286 ÿÿ (Latin1 'ÿ' [0xff])
4289 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4290 the end of the list.
4292 std::string after
= search_name
;
4293 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4295 if (!after
.empty ())
4296 after
.back () = (unsigned char) after
.back () + 1;
4300 /* See declaration. */
4302 std::pair
<std::vector
<name_component
>::const_iterator
,
4303 std::vector
<name_component
>::const_iterator
>
4304 mapped_index_base::find_name_components_bounds
4305 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4308 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4310 const char *lang_name
4311 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4313 /* Comparison function object for lower_bound that matches against a
4314 given symbol name. */
4315 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4318 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4319 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4320 return name_cmp (elem_name
, name
) < 0;
4323 /* Comparison function object for upper_bound that matches against a
4324 given symbol name. */
4325 auto lookup_compare_upper
= [&] (const char *name
,
4326 const name_component
&elem
)
4328 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4329 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4330 return name_cmp (name
, elem_name
) < 0;
4333 auto begin
= this->name_components
.begin ();
4334 auto end
= this->name_components
.end ();
4336 /* Find the lower bound. */
4339 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4342 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4345 /* Find the upper bound. */
4348 if (lookup_name_without_params
.completion_mode ())
4350 /* In completion mode, we want UPPER to point past all
4351 symbols names that have the same prefix. I.e., with
4352 these symbols, and completing "func":
4354 function << lower bound
4356 other_function << upper bound
4358 We find the upper bound by looking for the insertion
4359 point of "func"-with-last-character-incremented,
4361 std::string after
= make_sort_after_prefix_name (lang_name
);
4364 return std::lower_bound (lower
, end
, after
.c_str (),
4365 lookup_compare_lower
);
4368 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4371 return {lower
, upper
};
4374 /* See declaration. */
4377 mapped_index_base::build_name_components ()
4379 if (!this->name_components
.empty ())
4382 this->name_components_casing
= case_sensitivity
;
4384 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4386 /* The code below only knows how to break apart components of C++
4387 symbol names (and other languages that use '::' as
4388 namespace/module separator) and Ada symbol names. */
4389 auto count
= this->symbol_name_count ();
4390 for (offset_type idx
= 0; idx
< count
; idx
++)
4392 if (this->symbol_name_slot_invalid (idx
))
4395 const char *name
= this->symbol_name_at (idx
);
4397 /* Add each name component to the name component table. */
4398 unsigned int previous_len
= 0;
4400 if (strstr (name
, "::") != nullptr)
4402 for (unsigned int current_len
= cp_find_first_component (name
);
4403 name
[current_len
] != '\0';
4404 current_len
+= cp_find_first_component (name
+ current_len
))
4406 gdb_assert (name
[current_len
] == ':');
4407 this->name_components
.push_back ({previous_len
, idx
});
4408 /* Skip the '::'. */
4410 previous_len
= current_len
;
4415 /* Handle the Ada encoded (aka mangled) form here. */
4416 for (const char *iter
= strstr (name
, "__");
4418 iter
= strstr (iter
, "__"))
4420 this->name_components
.push_back ({previous_len
, idx
});
4422 previous_len
= iter
- name
;
4426 this->name_components
.push_back ({previous_len
, idx
});
4429 /* Sort name_components elements by name. */
4430 auto name_comp_compare
= [&] (const name_component
&left
,
4431 const name_component
&right
)
4433 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4434 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4436 const char *left_name
= left_qualified
+ left
.name_offset
;
4437 const char *right_name
= right_qualified
+ right
.name_offset
;
4439 return name_cmp (left_name
, right_name
) < 0;
4442 std::sort (this->name_components
.begin (),
4443 this->name_components
.end (),
4447 /* Helper for dw2_expand_symtabs_matching that works with a
4448 mapped_index_base instead of the containing objfile. This is split
4449 to a separate function in order to be able to unit test the
4450 name_components matching using a mock mapped_index_base. For each
4451 symbol name that matches, calls MATCH_CALLBACK, passing it the
4452 symbol's index in the mapped_index_base symbol table. */
4455 dw2_expand_symtabs_matching_symbol
4456 (mapped_index_base
&index
,
4457 const lookup_name_info
&lookup_name_in
,
4458 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4459 enum search_domain kind
,
4460 gdb::function_view
<bool (offset_type
)> match_callback
)
4462 lookup_name_info lookup_name_without_params
4463 = lookup_name_in
.make_ignore_params ();
4465 /* Build the symbol name component sorted vector, if we haven't
4467 index
.build_name_components ();
4469 /* The same symbol may appear more than once in the range though.
4470 E.g., if we're looking for symbols that complete "w", and we have
4471 a symbol named "w1::w2", we'll find the two name components for
4472 that same symbol in the range. To be sure we only call the
4473 callback once per symbol, we first collect the symbol name
4474 indexes that matched in a temporary vector and ignore
4476 std::vector
<offset_type
> matches
;
4478 struct name_and_matcher
4480 symbol_name_matcher_ftype
*matcher
;
4481 const std::string
&name
;
4483 bool operator== (const name_and_matcher
&other
) const
4485 return matcher
== other
.matcher
&& name
== other
.name
;
4489 /* A vector holding all the different symbol name matchers, for all
4491 std::vector
<name_and_matcher
> matchers
;
4493 for (int i
= 0; i
< nr_languages
; i
++)
4495 enum language lang_e
= (enum language
) i
;
4497 const language_defn
*lang
= language_def (lang_e
);
4498 symbol_name_matcher_ftype
*name_matcher
4499 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4501 name_and_matcher key
{
4503 lookup_name_without_params
.language_lookup_name (lang_e
)
4506 /* Don't insert the same comparison routine more than once.
4507 Note that we do this linear walk. This is not a problem in
4508 practice because the number of supported languages is
4510 if (std::find (matchers
.begin (), matchers
.end (), key
)
4513 matchers
.push_back (std::move (key
));
4516 = index
.find_name_components_bounds (lookup_name_without_params
,
4519 /* Now for each symbol name in range, check to see if we have a name
4520 match, and if so, call the MATCH_CALLBACK callback. */
4522 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4524 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4526 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4527 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4530 matches
.push_back (bounds
.first
->idx
);
4534 std::sort (matches
.begin (), matches
.end ());
4536 /* Finally call the callback, once per match. */
4538 for (offset_type idx
: matches
)
4542 if (!match_callback (idx
))
4548 /* Above we use a type wider than idx's for 'prev', since 0 and
4549 (offset_type)-1 are both possible values. */
4550 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4555 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4557 /* A mock .gdb_index/.debug_names-like name index table, enough to
4558 exercise dw2_expand_symtabs_matching_symbol, which works with the
4559 mapped_index_base interface. Builds an index from the symbol list
4560 passed as parameter to the constructor. */
4561 class mock_mapped_index
: public mapped_index_base
4564 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4565 : m_symbol_table (symbols
)
4568 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4570 /* Return the number of names in the symbol table. */
4571 size_t symbol_name_count () const override
4573 return m_symbol_table
.size ();
4576 /* Get the name of the symbol at IDX in the symbol table. */
4577 const char *symbol_name_at (offset_type idx
) const override
4579 return m_symbol_table
[idx
];
4583 gdb::array_view
<const char *> m_symbol_table
;
4586 /* Convenience function that converts a NULL pointer to a "<null>"
4587 string, to pass to print routines. */
4590 string_or_null (const char *str
)
4592 return str
!= NULL
? str
: "<null>";
4595 /* Check if a lookup_name_info built from
4596 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4597 index. EXPECTED_LIST is the list of expected matches, in expected
4598 matching order. If no match expected, then an empty list is
4599 specified. Returns true on success. On failure prints a warning
4600 indicating the file:line that failed, and returns false. */
4603 check_match (const char *file
, int line
,
4604 mock_mapped_index
&mock_index
,
4605 const char *name
, symbol_name_match_type match_type
,
4606 bool completion_mode
,
4607 std::initializer_list
<const char *> expected_list
)
4609 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4611 bool matched
= true;
4613 auto mismatch
= [&] (const char *expected_str
,
4616 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4617 "expected=\"%s\", got=\"%s\"\n"),
4619 (match_type
== symbol_name_match_type::FULL
4621 name
, string_or_null (expected_str
), string_or_null (got
));
4625 auto expected_it
= expected_list
.begin ();
4626 auto expected_end
= expected_list
.end ();
4628 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4630 [&] (offset_type idx
)
4632 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4633 const char *expected_str
4634 = expected_it
== expected_end
? NULL
: *expected_it
++;
4636 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4637 mismatch (expected_str
, matched_name
);
4641 const char *expected_str
4642 = expected_it
== expected_end
? NULL
: *expected_it
++;
4643 if (expected_str
!= NULL
)
4644 mismatch (expected_str
, NULL
);
4649 /* The symbols added to the mock mapped_index for testing (in
4651 static const char *test_symbols
[] = {
4660 "ns2::tmpl<int>::foo2",
4661 "(anonymous namespace)::A::B::C",
4663 /* These are used to check that the increment-last-char in the
4664 matching algorithm for completion doesn't match "t1_fund" when
4665 completing "t1_func". */
4671 /* A UTF-8 name with multi-byte sequences to make sure that
4672 cp-name-parser understands this as a single identifier ("função"
4673 is "function" in PT). */
4676 /* \377 (0xff) is Latin1 'ÿ'. */
4679 /* \377 (0xff) is Latin1 'ÿ'. */
4683 /* A name with all sorts of complications. Starts with "z" to make
4684 it easier for the completion tests below. */
4685 #define Z_SYM_NAME \
4686 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4687 "::tuple<(anonymous namespace)::ui*, " \
4688 "std::default_delete<(anonymous namespace)::ui>, void>"
4693 /* Returns true if the mapped_index_base::find_name_component_bounds
4694 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4695 in completion mode. */
4698 check_find_bounds_finds (mapped_index_base
&index
,
4699 const char *search_name
,
4700 gdb::array_view
<const char *> expected_syms
)
4702 lookup_name_info
lookup_name (search_name
,
4703 symbol_name_match_type::FULL
, true);
4705 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4708 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4709 if (distance
!= expected_syms
.size ())
4712 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4714 auto nc_elem
= bounds
.first
+ exp_elem
;
4715 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4716 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4723 /* Test the lower-level mapped_index::find_name_component_bounds
4727 test_mapped_index_find_name_component_bounds ()
4729 mock_mapped_index
mock_index (test_symbols
);
4731 mock_index
.build_name_components ();
4733 /* Test the lower-level mapped_index::find_name_component_bounds
4734 method in completion mode. */
4736 static const char *expected_syms
[] = {
4741 SELF_CHECK (check_find_bounds_finds (mock_index
,
4742 "t1_func", expected_syms
));
4745 /* Check that the increment-last-char in the name matching algorithm
4746 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4748 static const char *expected_syms1
[] = {
4752 SELF_CHECK (check_find_bounds_finds (mock_index
,
4753 "\377", expected_syms1
));
4755 static const char *expected_syms2
[] = {
4758 SELF_CHECK (check_find_bounds_finds (mock_index
,
4759 "\377\377", expected_syms2
));
4763 /* Test dw2_expand_symtabs_matching_symbol. */
4766 test_dw2_expand_symtabs_matching_symbol ()
4768 mock_mapped_index
mock_index (test_symbols
);
4770 /* We let all tests run until the end even if some fails, for debug
4772 bool any_mismatch
= false;
4774 /* Create the expected symbols list (an initializer_list). Needed
4775 because lists have commas, and we need to pass them to CHECK,
4776 which is a macro. */
4777 #define EXPECT(...) { __VA_ARGS__ }
4779 /* Wrapper for check_match that passes down the current
4780 __FILE__/__LINE__. */
4781 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4782 any_mismatch |= !check_match (__FILE__, __LINE__, \
4784 NAME, MATCH_TYPE, COMPLETION_MODE, \
4787 /* Identity checks. */
4788 for (const char *sym
: test_symbols
)
4790 /* Should be able to match all existing symbols. */
4791 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4794 /* Should be able to match all existing symbols with
4796 std::string with_params
= std::string (sym
) + "(int)";
4797 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4800 /* Should be able to match all existing symbols with
4801 parameters and qualifiers. */
4802 with_params
= std::string (sym
) + " ( int ) const";
4803 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4806 /* This should really find sym, but cp-name-parser.y doesn't
4807 know about lvalue/rvalue qualifiers yet. */
4808 with_params
= std::string (sym
) + " ( int ) &&";
4809 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4813 /* Check that the name matching algorithm for completion doesn't get
4814 confused with Latin1 'ÿ' / 0xff. */
4816 static const char str
[] = "\377";
4817 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4818 EXPECT ("\377", "\377\377123"));
4821 /* Check that the increment-last-char in the matching algorithm for
4822 completion doesn't match "t1_fund" when completing "t1_func". */
4824 static const char str
[] = "t1_func";
4825 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4826 EXPECT ("t1_func", "t1_func1"));
4829 /* Check that completion mode works at each prefix of the expected
4832 static const char str
[] = "function(int)";
4833 size_t len
= strlen (str
);
4836 for (size_t i
= 1; i
< len
; i
++)
4838 lookup
.assign (str
, i
);
4839 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4840 EXPECT ("function"));
4844 /* While "w" is a prefix of both components, the match function
4845 should still only be called once. */
4847 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4849 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4853 /* Same, with a "complicated" symbol. */
4855 static const char str
[] = Z_SYM_NAME
;
4856 size_t len
= strlen (str
);
4859 for (size_t i
= 1; i
< len
; i
++)
4861 lookup
.assign (str
, i
);
4862 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4863 EXPECT (Z_SYM_NAME
));
4867 /* In FULL mode, an incomplete symbol doesn't match. */
4869 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4873 /* A complete symbol with parameters matches any overload, since the
4874 index has no overload info. */
4876 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4877 EXPECT ("std::zfunction", "std::zfunction2"));
4878 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4879 EXPECT ("std::zfunction", "std::zfunction2"));
4880 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4881 EXPECT ("std::zfunction", "std::zfunction2"));
4884 /* Check that whitespace is ignored appropriately. A symbol with a
4885 template argument list. */
4887 static const char expected
[] = "ns::foo<int>";
4888 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4890 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4894 /* Check that whitespace is ignored appropriately. A symbol with a
4895 template argument list that includes a pointer. */
4897 static const char expected
[] = "ns::foo<char*>";
4898 /* Try both completion and non-completion modes. */
4899 static const bool completion_mode
[2] = {false, true};
4900 for (size_t i
= 0; i
< 2; i
++)
4902 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4903 completion_mode
[i
], EXPECT (expected
));
4904 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4905 completion_mode
[i
], EXPECT (expected
));
4907 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4908 completion_mode
[i
], EXPECT (expected
));
4909 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4910 completion_mode
[i
], EXPECT (expected
));
4915 /* Check method qualifiers are ignored. */
4916 static const char expected
[] = "ns::foo<char*>";
4917 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4918 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4919 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4920 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4921 CHECK_MATCH ("foo < char * > ( int ) const",
4922 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4923 CHECK_MATCH ("foo < char * > ( int ) &&",
4924 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4927 /* Test lookup names that don't match anything. */
4929 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4932 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4936 /* Some wild matching tests, exercising "(anonymous namespace)",
4937 which should not be confused with a parameter list. */
4939 static const char *syms
[] = {
4943 "A :: B :: C ( int )",
4948 for (const char *s
: syms
)
4950 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4951 EXPECT ("(anonymous namespace)::A::B::C"));
4956 static const char expected
[] = "ns2::tmpl<int>::foo2";
4957 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4959 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4963 SELF_CHECK (!any_mismatch
);
4972 test_mapped_index_find_name_component_bounds ();
4973 test_dw2_expand_symtabs_matching_symbol ();
4976 }} // namespace selftests::dw2_expand_symtabs_matching
4978 #endif /* GDB_SELF_TEST */
4980 /* If FILE_MATCHER is NULL or if PER_CU has
4981 dwarf2_per_cu_quick_data::MARK set (see
4982 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4983 EXPANSION_NOTIFY on it. */
4986 dw2_expand_symtabs_matching_one
4987 (struct dwarf2_per_cu_data
*per_cu
,
4988 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4989 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4991 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4993 bool symtab_was_null
4994 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4996 dw2_instantiate_symtab (per_cu
, false);
4998 if (expansion_notify
!= NULL
5000 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5001 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5005 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5006 matched, to expand corresponding CUs that were marked. IDX is the
5007 index of the symbol name that matched. */
5010 dw2_expand_marked_cus
5011 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5012 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5013 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5016 offset_type
*vec
, vec_len
, vec_idx
;
5017 bool global_seen
= false;
5018 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5020 vec
= (offset_type
*) (index
.constant_pool
5021 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5022 vec_len
= MAYBE_SWAP (vec
[0]);
5023 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5025 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5026 /* This value is only valid for index versions >= 7. */
5027 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5028 gdb_index_symbol_kind symbol_kind
=
5029 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5030 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5031 /* Only check the symbol attributes if they're present.
5032 Indices prior to version 7 don't record them,
5033 and indices >= 7 may elide them for certain symbols
5034 (gold does this). */
5037 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5039 /* Work around gold/15646. */
5042 if (!is_static
&& global_seen
)
5048 /* Only check the symbol's kind if it has one. */
5053 case VARIABLES_DOMAIN
:
5054 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5057 case FUNCTIONS_DOMAIN
:
5058 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5062 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5065 case MODULES_DOMAIN
:
5066 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5074 /* Don't crash on bad data. */
5075 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5076 + dwarf2_per_objfile
->all_type_units
.size ()))
5078 complaint (_(".gdb_index entry has bad CU index"
5080 objfile_name (dwarf2_per_objfile
->objfile
));
5084 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5085 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5090 /* If FILE_MATCHER is non-NULL, set all the
5091 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5092 that match FILE_MATCHER. */
5095 dw_expand_symtabs_matching_file_matcher
5096 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5097 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5099 if (file_matcher
== NULL
)
5102 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5104 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5106 NULL
, xcalloc
, xfree
));
5107 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5109 NULL
, xcalloc
, xfree
));
5111 /* The rule is CUs specify all the files, including those used by
5112 any TU, so there's no need to scan TUs here. */
5114 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5118 per_cu
->v
.quick
->mark
= 0;
5120 /* We only need to look at symtabs not already expanded. */
5121 if (per_cu
->v
.quick
->compunit_symtab
)
5124 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5125 if (file_data
== NULL
)
5128 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5130 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5132 per_cu
->v
.quick
->mark
= 1;
5136 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5138 const char *this_real_name
;
5140 if (file_matcher (file_data
->file_names
[j
], false))
5142 per_cu
->v
.quick
->mark
= 1;
5146 /* Before we invoke realpath, which can get expensive when many
5147 files are involved, do a quick comparison of the basenames. */
5148 if (!basenames_may_differ
5149 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5153 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5154 if (file_matcher (this_real_name
, false))
5156 per_cu
->v
.quick
->mark
= 1;
5161 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5162 ? visited_found
.get ()
5163 : visited_not_found
.get (),
5170 dw2_expand_symtabs_matching
5171 (struct objfile
*objfile
,
5172 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5173 const lookup_name_info
&lookup_name
,
5174 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5175 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5176 enum search_domain kind
)
5178 struct dwarf2_per_objfile
*dwarf2_per_objfile
5179 = get_dwarf2_per_objfile (objfile
);
5181 /* index_table is NULL if OBJF_READNOW. */
5182 if (!dwarf2_per_objfile
->index_table
)
5185 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5187 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5189 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5191 kind
, [&] (offset_type idx
)
5193 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5194 expansion_notify
, kind
);
5199 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5202 static struct compunit_symtab
*
5203 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5208 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5209 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5212 if (cust
->includes
== NULL
)
5215 for (i
= 0; cust
->includes
[i
]; ++i
)
5217 struct compunit_symtab
*s
= cust
->includes
[i
];
5219 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5227 static struct compunit_symtab
*
5228 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5229 struct bound_minimal_symbol msymbol
,
5231 struct obj_section
*section
,
5234 struct dwarf2_per_cu_data
*data
;
5235 struct compunit_symtab
*result
;
5237 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5240 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5241 SECT_OFF_TEXT (objfile
));
5242 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5243 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5247 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5248 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5249 paddress (get_objfile_arch (objfile
), pc
));
5252 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5255 gdb_assert (result
!= NULL
);
5260 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5261 void *data
, int need_fullname
)
5263 struct dwarf2_per_objfile
*dwarf2_per_objfile
5264 = get_dwarf2_per_objfile (objfile
);
5266 if (!dwarf2_per_objfile
->filenames_cache
)
5268 dwarf2_per_objfile
->filenames_cache
.emplace ();
5270 htab_up
visited (htab_create_alloc (10,
5271 htab_hash_pointer
, htab_eq_pointer
,
5272 NULL
, xcalloc
, xfree
));
5274 /* The rule is CUs specify all the files, including those used
5275 by any TU, so there's no need to scan TUs here. We can
5276 ignore file names coming from already-expanded CUs. */
5278 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5280 if (per_cu
->v
.quick
->compunit_symtab
)
5282 void **slot
= htab_find_slot (visited
.get (),
5283 per_cu
->v
.quick
->file_names
,
5286 *slot
= per_cu
->v
.quick
->file_names
;
5290 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5292 /* We only need to look at symtabs not already expanded. */
5293 if (per_cu
->v
.quick
->compunit_symtab
)
5296 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5297 if (file_data
== NULL
)
5300 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5303 /* Already visited. */
5308 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5310 const char *filename
= file_data
->file_names
[j
];
5311 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5316 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5318 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5321 this_real_name
= gdb_realpath (filename
);
5322 (*fun
) (filename
, this_real_name
.get (), data
);
5327 dw2_has_symbols (struct objfile
*objfile
)
5332 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5335 dw2_find_last_source_symtab
,
5336 dw2_forget_cached_source_info
,
5337 dw2_map_symtabs_matching_filename
,
5341 dw2_expand_symtabs_for_function
,
5342 dw2_expand_all_symtabs
,
5343 dw2_expand_symtabs_with_fullname
,
5344 dw2_map_matching_symbols
,
5345 dw2_expand_symtabs_matching
,
5346 dw2_find_pc_sect_compunit_symtab
,
5348 dw2_map_symbol_filenames
5351 /* DWARF-5 debug_names reader. */
5353 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5354 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5356 /* A helper function that reads the .debug_names section in SECTION
5357 and fills in MAP. FILENAME is the name of the file containing the
5358 section; it is used for error reporting.
5360 Returns true if all went well, false otherwise. */
5363 read_debug_names_from_section (struct objfile
*objfile
,
5364 const char *filename
,
5365 struct dwarf2_section_info
*section
,
5366 mapped_debug_names
&map
)
5368 if (dwarf2_section_empty_p (section
))
5371 /* Older elfutils strip versions could keep the section in the main
5372 executable while splitting it for the separate debug info file. */
5373 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5376 dwarf2_read_section (objfile
, section
);
5378 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5380 const gdb_byte
*addr
= section
->buffer
;
5382 bfd
*const abfd
= get_section_bfd_owner (section
);
5384 unsigned int bytes_read
;
5385 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5388 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5389 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5390 if (bytes_read
+ length
!= section
->size
)
5392 /* There may be multiple per-CU indices. */
5393 warning (_("Section .debug_names in %s length %s does not match "
5394 "section length %s, ignoring .debug_names."),
5395 filename
, plongest (bytes_read
+ length
),
5396 pulongest (section
->size
));
5400 /* The version number. */
5401 uint16_t version
= read_2_bytes (abfd
, addr
);
5405 warning (_("Section .debug_names in %s has unsupported version %d, "
5406 "ignoring .debug_names."),
5412 uint16_t padding
= read_2_bytes (abfd
, addr
);
5416 warning (_("Section .debug_names in %s has unsupported padding %d, "
5417 "ignoring .debug_names."),
5422 /* comp_unit_count - The number of CUs in the CU list. */
5423 map
.cu_count
= read_4_bytes (abfd
, addr
);
5426 /* local_type_unit_count - The number of TUs in the local TU
5428 map
.tu_count
= read_4_bytes (abfd
, addr
);
5431 /* foreign_type_unit_count - The number of TUs in the foreign TU
5433 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5435 if (foreign_tu_count
!= 0)
5437 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5438 "ignoring .debug_names."),
5439 filename
, static_cast<unsigned long> (foreign_tu_count
));
5443 /* bucket_count - The number of hash buckets in the hash lookup
5445 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5448 /* name_count - The number of unique names in the index. */
5449 map
.name_count
= read_4_bytes (abfd
, addr
);
5452 /* abbrev_table_size - The size in bytes of the abbreviations
5454 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5457 /* augmentation_string_size - The size in bytes of the augmentation
5458 string. This value is rounded up to a multiple of 4. */
5459 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5461 map
.augmentation_is_gdb
= ((augmentation_string_size
5462 == sizeof (dwarf5_augmentation
))
5463 && memcmp (addr
, dwarf5_augmentation
,
5464 sizeof (dwarf5_augmentation
)) == 0);
5465 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5466 addr
+= augmentation_string_size
;
5469 map
.cu_table_reordered
= addr
;
5470 addr
+= map
.cu_count
* map
.offset_size
;
5472 /* List of Local TUs */
5473 map
.tu_table_reordered
= addr
;
5474 addr
+= map
.tu_count
* map
.offset_size
;
5476 /* Hash Lookup Table */
5477 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5478 addr
+= map
.bucket_count
* 4;
5479 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5480 addr
+= map
.name_count
* 4;
5483 map
.name_table_string_offs_reordered
= addr
;
5484 addr
+= map
.name_count
* map
.offset_size
;
5485 map
.name_table_entry_offs_reordered
= addr
;
5486 addr
+= map
.name_count
* map
.offset_size
;
5488 const gdb_byte
*abbrev_table_start
= addr
;
5491 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5496 const auto insertpair
5497 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5498 if (!insertpair
.second
)
5500 warning (_("Section .debug_names in %s has duplicate index %s, "
5501 "ignoring .debug_names."),
5502 filename
, pulongest (index_num
));
5505 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5506 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5511 mapped_debug_names::index_val::attr attr
;
5512 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5514 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5516 if (attr
.form
== DW_FORM_implicit_const
)
5518 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5522 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5524 indexval
.attr_vec
.push_back (std::move (attr
));
5527 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5529 warning (_("Section .debug_names in %s has abbreviation_table "
5530 "of size %s vs. written as %u, ignoring .debug_names."),
5531 filename
, plongest (addr
- abbrev_table_start
),
5535 map
.entry_pool
= addr
;
5540 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5544 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5545 const mapped_debug_names
&map
,
5546 dwarf2_section_info
§ion
,
5549 sect_offset sect_off_prev
;
5550 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5552 sect_offset sect_off_next
;
5553 if (i
< map
.cu_count
)
5556 = (sect_offset
) (extract_unsigned_integer
5557 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5559 map
.dwarf5_byte_order
));
5562 sect_off_next
= (sect_offset
) section
.size
;
5565 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5566 dwarf2_per_cu_data
*per_cu
5567 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5568 sect_off_prev
, length
);
5569 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5571 sect_off_prev
= sect_off_next
;
5575 /* Read the CU list from the mapped index, and use it to create all
5576 the CU objects for this dwarf2_per_objfile. */
5579 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5580 const mapped_debug_names
&map
,
5581 const mapped_debug_names
&dwz_map
)
5583 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5584 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5586 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5587 dwarf2_per_objfile
->info
,
5588 false /* is_dwz */);
5590 if (dwz_map
.cu_count
== 0)
5593 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5594 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5598 /* Read .debug_names. If everything went ok, initialize the "quick"
5599 elements of all the CUs and return true. Otherwise, return false. */
5602 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5604 std::unique_ptr
<mapped_debug_names
> map
5605 (new mapped_debug_names (dwarf2_per_objfile
));
5606 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5607 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5609 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5610 &dwarf2_per_objfile
->debug_names
,
5614 /* Don't use the index if it's empty. */
5615 if (map
->name_count
== 0)
5618 /* If there is a .dwz file, read it so we can get its CU list as
5620 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5623 if (!read_debug_names_from_section (objfile
,
5624 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5625 &dwz
->debug_names
, dwz_map
))
5627 warning (_("could not read '.debug_names' section from %s; skipping"),
5628 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5633 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5635 if (map
->tu_count
!= 0)
5637 /* We can only handle a single .debug_types when we have an
5639 if (dwarf2_per_objfile
->types
.size () != 1)
5642 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5644 create_signatured_type_table_from_debug_names
5645 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5648 create_addrmap_from_aranges (dwarf2_per_objfile
,
5649 &dwarf2_per_objfile
->debug_aranges
);
5651 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5652 dwarf2_per_objfile
->using_index
= 1;
5653 dwarf2_per_objfile
->quick_file_names_table
=
5654 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5659 /* Type used to manage iterating over all CUs looking for a symbol for
5662 class dw2_debug_names_iterator
5665 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5666 gdb::optional
<block_enum
> block_index
,
5669 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5670 m_addr (find_vec_in_debug_names (map
, name
))
5673 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5674 search_domain search
, uint32_t namei
)
5677 m_addr (find_vec_in_debug_names (map
, namei
))
5680 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5681 block_enum block_index
, domain_enum domain
,
5683 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5684 m_addr (find_vec_in_debug_names (map
, namei
))
5687 /* Return the next matching CU or NULL if there are no more. */
5688 dwarf2_per_cu_data
*next ();
5691 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5693 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5696 /* The internalized form of .debug_names. */
5697 const mapped_debug_names
&m_map
;
5699 /* If set, only look for symbols that match that block. Valid values are
5700 GLOBAL_BLOCK and STATIC_BLOCK. */
5701 const gdb::optional
<block_enum
> m_block_index
;
5703 /* The kind of symbol we're looking for. */
5704 const domain_enum m_domain
= UNDEF_DOMAIN
;
5705 const search_domain m_search
= ALL_DOMAIN
;
5707 /* The list of CUs from the index entry of the symbol, or NULL if
5709 const gdb_byte
*m_addr
;
5713 mapped_debug_names::namei_to_name (uint32_t namei
) const
5715 const ULONGEST namei_string_offs
5716 = extract_unsigned_integer ((name_table_string_offs_reordered
5717 + namei
* offset_size
),
5720 return read_indirect_string_at_offset
5721 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5724 /* Find a slot in .debug_names for the object named NAME. If NAME is
5725 found, return pointer to its pool data. If NAME cannot be found,
5729 dw2_debug_names_iterator::find_vec_in_debug_names
5730 (const mapped_debug_names
&map
, const char *name
)
5732 int (*cmp
) (const char *, const char *);
5734 gdb::unique_xmalloc_ptr
<char> without_params
;
5735 if (current_language
->la_language
== language_cplus
5736 || current_language
->la_language
== language_fortran
5737 || current_language
->la_language
== language_d
)
5739 /* NAME is already canonical. Drop any qualifiers as
5740 .debug_names does not contain any. */
5742 if (strchr (name
, '(') != NULL
)
5744 without_params
= cp_remove_params (name
);
5745 if (without_params
!= NULL
)
5746 name
= without_params
.get ();
5750 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5752 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5754 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5755 (map
.bucket_table_reordered
5756 + (full_hash
% map
.bucket_count
)), 4,
5757 map
.dwarf5_byte_order
);
5761 if (namei
>= map
.name_count
)
5763 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5765 namei
, map
.name_count
,
5766 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5772 const uint32_t namei_full_hash
5773 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5774 (map
.hash_table_reordered
+ namei
), 4,
5775 map
.dwarf5_byte_order
);
5776 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5779 if (full_hash
== namei_full_hash
)
5781 const char *const namei_string
= map
.namei_to_name (namei
);
5783 #if 0 /* An expensive sanity check. */
5784 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5786 complaint (_("Wrong .debug_names hash for string at index %u "
5788 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5793 if (cmp (namei_string
, name
) == 0)
5795 const ULONGEST namei_entry_offs
5796 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5797 + namei
* map
.offset_size
),
5798 map
.offset_size
, map
.dwarf5_byte_order
);
5799 return map
.entry_pool
+ namei_entry_offs
;
5804 if (namei
>= map
.name_count
)
5810 dw2_debug_names_iterator::find_vec_in_debug_names
5811 (const mapped_debug_names
&map
, uint32_t namei
)
5813 if (namei
>= map
.name_count
)
5815 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5817 namei
, map
.name_count
,
5818 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5822 const ULONGEST namei_entry_offs
5823 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5824 + namei
* map
.offset_size
),
5825 map
.offset_size
, map
.dwarf5_byte_order
);
5826 return map
.entry_pool
+ namei_entry_offs
;
5829 /* See dw2_debug_names_iterator. */
5831 dwarf2_per_cu_data
*
5832 dw2_debug_names_iterator::next ()
5837 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5838 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5839 bfd
*const abfd
= objfile
->obfd
;
5843 unsigned int bytes_read
;
5844 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5845 m_addr
+= bytes_read
;
5849 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5850 if (indexval_it
== m_map
.abbrev_map
.cend ())
5852 complaint (_("Wrong .debug_names undefined abbrev code %s "
5854 pulongest (abbrev
), objfile_name (objfile
));
5857 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5858 enum class symbol_linkage
{
5862 } symbol_linkage_
= symbol_linkage::unknown
;
5863 dwarf2_per_cu_data
*per_cu
= NULL
;
5864 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5869 case DW_FORM_implicit_const
:
5870 ull
= attr
.implicit_const
;
5872 case DW_FORM_flag_present
:
5876 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5877 m_addr
+= bytes_read
;
5880 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5881 dwarf_form_name (attr
.form
),
5882 objfile_name (objfile
));
5885 switch (attr
.dw_idx
)
5887 case DW_IDX_compile_unit
:
5888 /* Don't crash on bad data. */
5889 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5891 complaint (_(".debug_names entry has bad CU index %s"
5894 objfile_name (dwarf2_per_objfile
->objfile
));
5897 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5899 case DW_IDX_type_unit
:
5900 /* Don't crash on bad data. */
5901 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5903 complaint (_(".debug_names entry has bad TU index %s"
5906 objfile_name (dwarf2_per_objfile
->objfile
));
5909 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5911 case DW_IDX_GNU_internal
:
5912 if (!m_map
.augmentation_is_gdb
)
5914 symbol_linkage_
= symbol_linkage::static_
;
5916 case DW_IDX_GNU_external
:
5917 if (!m_map
.augmentation_is_gdb
)
5919 symbol_linkage_
= symbol_linkage::extern_
;
5924 /* Skip if already read in. */
5925 if (per_cu
->v
.quick
->compunit_symtab
)
5928 /* Check static vs global. */
5929 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5931 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5932 const bool symbol_is_static
=
5933 symbol_linkage_
== symbol_linkage::static_
;
5934 if (want_static
!= symbol_is_static
)
5938 /* Match dw2_symtab_iter_next, symbol_kind
5939 and debug_names::psymbol_tag. */
5943 switch (indexval
.dwarf_tag
)
5945 case DW_TAG_variable
:
5946 case DW_TAG_subprogram
:
5947 /* Some types are also in VAR_DOMAIN. */
5948 case DW_TAG_typedef
:
5949 case DW_TAG_structure_type
:
5956 switch (indexval
.dwarf_tag
)
5958 case DW_TAG_typedef
:
5959 case DW_TAG_structure_type
:
5966 switch (indexval
.dwarf_tag
)
5969 case DW_TAG_variable
:
5976 switch (indexval
.dwarf_tag
)
5988 /* Match dw2_expand_symtabs_matching, symbol_kind and
5989 debug_names::psymbol_tag. */
5992 case VARIABLES_DOMAIN
:
5993 switch (indexval
.dwarf_tag
)
5995 case DW_TAG_variable
:
6001 case FUNCTIONS_DOMAIN
:
6002 switch (indexval
.dwarf_tag
)
6004 case DW_TAG_subprogram
:
6011 switch (indexval
.dwarf_tag
)
6013 case DW_TAG_typedef
:
6014 case DW_TAG_structure_type
:
6020 case MODULES_DOMAIN
:
6021 switch (indexval
.dwarf_tag
)
6035 static struct compunit_symtab
*
6036 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6037 const char *name
, domain_enum domain
)
6039 struct dwarf2_per_objfile
*dwarf2_per_objfile
6040 = get_dwarf2_per_objfile (objfile
);
6042 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6045 /* index is NULL if OBJF_READNOW. */
6048 const auto &map
= *mapp
;
6050 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6052 struct compunit_symtab
*stab_best
= NULL
;
6053 struct dwarf2_per_cu_data
*per_cu
;
6054 while ((per_cu
= iter
.next ()) != NULL
)
6056 struct symbol
*sym
, *with_opaque
= NULL
;
6057 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6058 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6059 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6061 sym
= block_find_symbol (block
, name
, domain
,
6062 block_find_non_opaque_type_preferred
,
6065 /* Some caution must be observed with overloaded functions and
6066 methods, since the index will not contain any overload
6067 information (but NAME might contain it). */
6070 && strcmp_iw (sym
->search_name (), name
) == 0)
6072 if (with_opaque
!= NULL
6073 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6076 /* Keep looking through other CUs. */
6082 /* This dumps minimal information about .debug_names. It is called
6083 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6084 uses this to verify that .debug_names has been loaded. */
6087 dw2_debug_names_dump (struct objfile
*objfile
)
6089 struct dwarf2_per_objfile
*dwarf2_per_objfile
6090 = get_dwarf2_per_objfile (objfile
);
6092 gdb_assert (dwarf2_per_objfile
->using_index
);
6093 printf_filtered (".debug_names:");
6094 if (dwarf2_per_objfile
->debug_names_table
)
6095 printf_filtered (" exists\n");
6097 printf_filtered (" faked for \"readnow\"\n");
6098 printf_filtered ("\n");
6102 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6103 const char *func_name
)
6105 struct dwarf2_per_objfile
*dwarf2_per_objfile
6106 = get_dwarf2_per_objfile (objfile
);
6108 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6109 if (dwarf2_per_objfile
->debug_names_table
)
6111 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6113 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6115 struct dwarf2_per_cu_data
*per_cu
;
6116 while ((per_cu
= iter
.next ()) != NULL
)
6117 dw2_instantiate_symtab (per_cu
, false);
6122 dw2_debug_names_map_matching_symbols
6123 (struct objfile
*objfile
,
6124 const lookup_name_info
&name
, domain_enum domain
,
6126 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6127 symbol_compare_ftype
*ordered_compare
)
6129 struct dwarf2_per_objfile
*dwarf2_per_objfile
6130 = get_dwarf2_per_objfile (objfile
);
6132 /* debug_names_table is NULL if OBJF_READNOW. */
6133 if (!dwarf2_per_objfile
->debug_names_table
)
6136 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6137 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6139 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6140 auto matcher
= [&] (const char *symname
)
6142 if (ordered_compare
== nullptr)
6144 return ordered_compare (symname
, match_name
) == 0;
6147 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6148 [&] (offset_type namei
)
6150 /* The name was matched, now expand corresponding CUs that were
6152 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6154 struct dwarf2_per_cu_data
*per_cu
;
6155 while ((per_cu
= iter
.next ()) != NULL
)
6156 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6160 /* It's a shame we couldn't do this inside the
6161 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6162 that have already been expanded. Instead, this loop matches what
6163 the psymtab code does. */
6164 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6166 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6167 if (cust
!= nullptr)
6169 const struct block
*block
6170 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6171 if (!iterate_over_symbols_terminated (block
, name
,
6179 dw2_debug_names_expand_symtabs_matching
6180 (struct objfile
*objfile
,
6181 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6182 const lookup_name_info
&lookup_name
,
6183 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6184 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6185 enum search_domain kind
)
6187 struct dwarf2_per_objfile
*dwarf2_per_objfile
6188 = get_dwarf2_per_objfile (objfile
);
6190 /* debug_names_table is NULL if OBJF_READNOW. */
6191 if (!dwarf2_per_objfile
->debug_names_table
)
6194 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6196 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6198 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6200 kind
, [&] (offset_type namei
)
6202 /* The name was matched, now expand corresponding CUs that were
6204 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6206 struct dwarf2_per_cu_data
*per_cu
;
6207 while ((per_cu
= iter
.next ()) != NULL
)
6208 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6214 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6217 dw2_find_last_source_symtab
,
6218 dw2_forget_cached_source_info
,
6219 dw2_map_symtabs_matching_filename
,
6220 dw2_debug_names_lookup_symbol
,
6222 dw2_debug_names_dump
,
6223 dw2_debug_names_expand_symtabs_for_function
,
6224 dw2_expand_all_symtabs
,
6225 dw2_expand_symtabs_with_fullname
,
6226 dw2_debug_names_map_matching_symbols
,
6227 dw2_debug_names_expand_symtabs_matching
,
6228 dw2_find_pc_sect_compunit_symtab
,
6230 dw2_map_symbol_filenames
6233 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6234 to either a dwarf2_per_objfile or dwz_file object. */
6236 template <typename T
>
6237 static gdb::array_view
<const gdb_byte
>
6238 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6240 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6242 if (dwarf2_section_empty_p (section
))
6245 /* Older elfutils strip versions could keep the section in the main
6246 executable while splitting it for the separate debug info file. */
6247 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6250 dwarf2_read_section (obj
, section
);
6252 /* dwarf2_section_info::size is a bfd_size_type, while
6253 gdb::array_view works with size_t. On 32-bit hosts, with
6254 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6255 is 32-bit. So we need an explicit narrowing conversion here.
6256 This is fine, because it's impossible to allocate or mmap an
6257 array/buffer larger than what size_t can represent. */
6258 return gdb::make_array_view (section
->buffer
, section
->size
);
6261 /* Lookup the index cache for the contents of the index associated to
6264 static gdb::array_view
<const gdb_byte
>
6265 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6267 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6268 if (build_id
== nullptr)
6271 return global_index_cache
.lookup_gdb_index (build_id
,
6272 &dwarf2_obj
->index_cache_res
);
6275 /* Same as the above, but for DWZ. */
6277 static gdb::array_view
<const gdb_byte
>
6278 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6280 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6281 if (build_id
== nullptr)
6284 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6287 /* See symfile.h. */
6290 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6292 struct dwarf2_per_objfile
*dwarf2_per_objfile
6293 = get_dwarf2_per_objfile (objfile
);
6295 /* If we're about to read full symbols, don't bother with the
6296 indices. In this case we also don't care if some other debug
6297 format is making psymtabs, because they are all about to be
6299 if ((objfile
->flags
& OBJF_READNOW
))
6301 dwarf2_per_objfile
->using_index
= 1;
6302 create_all_comp_units (dwarf2_per_objfile
);
6303 create_all_type_units (dwarf2_per_objfile
);
6304 dwarf2_per_objfile
->quick_file_names_table
6305 = create_quick_file_names_table
6306 (dwarf2_per_objfile
->all_comp_units
.size ());
6308 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6309 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6311 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6313 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6314 struct dwarf2_per_cu_quick_data
);
6317 /* Return 1 so that gdb sees the "quick" functions. However,
6318 these functions will be no-ops because we will have expanded
6320 *index_kind
= dw_index_kind::GDB_INDEX
;
6324 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6326 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6330 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6331 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6332 get_gdb_index_contents_from_section
<dwz_file
>))
6334 *index_kind
= dw_index_kind::GDB_INDEX
;
6338 /* ... otherwise, try to find the index in the index cache. */
6339 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6340 get_gdb_index_contents_from_cache
,
6341 get_gdb_index_contents_from_cache_dwz
))
6343 global_index_cache
.hit ();
6344 *index_kind
= dw_index_kind::GDB_INDEX
;
6348 global_index_cache
.miss ();
6354 /* Build a partial symbol table. */
6357 dwarf2_build_psymtabs (struct objfile
*objfile
)
6359 struct dwarf2_per_objfile
*dwarf2_per_objfile
6360 = get_dwarf2_per_objfile (objfile
);
6362 init_psymbol_list (objfile
, 1024);
6366 /* This isn't really ideal: all the data we allocate on the
6367 objfile's obstack is still uselessly kept around. However,
6368 freeing it seems unsafe. */
6369 psymtab_discarder
psymtabs (objfile
);
6370 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6373 /* (maybe) store an index in the cache. */
6374 global_index_cache
.store (dwarf2_per_objfile
);
6376 catch (const gdb_exception_error
&except
)
6378 exception_print (gdb_stderr
, except
);
6382 /* Return the total length of the CU described by HEADER. */
6385 get_cu_length (const struct comp_unit_head
*header
)
6387 return header
->initial_length_size
+ header
->length
;
6390 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6393 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6395 sect_offset bottom
= cu_header
->sect_off
;
6396 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6398 return sect_off
>= bottom
&& sect_off
< top
;
6401 /* Find the base address of the compilation unit for range lists and
6402 location lists. It will normally be specified by DW_AT_low_pc.
6403 In DWARF-3 draft 4, the base address could be overridden by
6404 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6405 compilation units with discontinuous ranges. */
6408 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6410 struct attribute
*attr
;
6413 cu
->base_address
= 0;
6415 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6416 if (attr
!= nullptr)
6418 cu
->base_address
= attr_value_as_address (attr
);
6423 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6424 if (attr
!= nullptr)
6426 cu
->base_address
= attr_value_as_address (attr
);
6432 /* Read in the comp unit header information from the debug_info at info_ptr.
6433 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6434 NOTE: This leaves members offset, first_die_offset to be filled in
6437 static const gdb_byte
*
6438 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6439 const gdb_byte
*info_ptr
,
6440 struct dwarf2_section_info
*section
,
6441 rcuh_kind section_kind
)
6444 unsigned int bytes_read
;
6445 const char *filename
= get_section_file_name (section
);
6446 bfd
*abfd
= get_section_bfd_owner (section
);
6448 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6449 cu_header
->initial_length_size
= bytes_read
;
6450 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6451 info_ptr
+= bytes_read
;
6452 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6453 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6454 error (_("Dwarf Error: wrong version in compilation unit header "
6455 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6456 cu_header
->version
, filename
);
6458 if (cu_header
->version
< 5)
6459 switch (section_kind
)
6461 case rcuh_kind::COMPILE
:
6462 cu_header
->unit_type
= DW_UT_compile
;
6464 case rcuh_kind::TYPE
:
6465 cu_header
->unit_type
= DW_UT_type
;
6468 internal_error (__FILE__
, __LINE__
,
6469 _("read_comp_unit_head: invalid section_kind"));
6473 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6474 (read_1_byte (abfd
, info_ptr
));
6476 switch (cu_header
->unit_type
)
6480 case DW_UT_skeleton
:
6481 case DW_UT_split_compile
:
6482 if (section_kind
!= rcuh_kind::COMPILE
)
6483 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6484 "(is %s, should be %s) [in module %s]"),
6485 dwarf_unit_type_name (cu_header
->unit_type
),
6486 dwarf_unit_type_name (DW_UT_type
), filename
);
6489 case DW_UT_split_type
:
6490 section_kind
= rcuh_kind::TYPE
;
6493 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6494 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6495 "[in module %s]"), cu_header
->unit_type
,
6496 dwarf_unit_type_name (DW_UT_compile
),
6497 dwarf_unit_type_name (DW_UT_skeleton
),
6498 dwarf_unit_type_name (DW_UT_split_compile
),
6499 dwarf_unit_type_name (DW_UT_type
),
6500 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6503 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6506 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6509 info_ptr
+= bytes_read
;
6510 if (cu_header
->version
< 5)
6512 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6515 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6516 if (signed_addr
< 0)
6517 internal_error (__FILE__
, __LINE__
,
6518 _("read_comp_unit_head: dwarf from non elf file"));
6519 cu_header
->signed_addr_p
= signed_addr
;
6521 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6522 || cu_header
->unit_type
== DW_UT_skeleton
6523 || cu_header
->unit_type
== DW_UT_split_compile
;
6525 if (header_has_signature
)
6527 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6531 if (section_kind
== rcuh_kind::TYPE
)
6533 LONGEST type_offset
;
6534 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6535 info_ptr
+= bytes_read
;
6536 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6537 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6538 error (_("Dwarf Error: Too big type_offset in compilation unit "
6539 "header (is %s) [in module %s]"), plongest (type_offset
),
6546 /* Helper function that returns the proper abbrev section for
6549 static struct dwarf2_section_info
*
6550 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6552 struct dwarf2_section_info
*abbrev
;
6553 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6555 if (this_cu
->is_dwz
)
6556 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6558 abbrev
= &dwarf2_per_objfile
->abbrev
;
6563 /* Subroutine of read_and_check_comp_unit_head and
6564 read_and_check_type_unit_head to simplify them.
6565 Perform various error checking on the header. */
6568 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6569 struct comp_unit_head
*header
,
6570 struct dwarf2_section_info
*section
,
6571 struct dwarf2_section_info
*abbrev_section
)
6573 const char *filename
= get_section_file_name (section
);
6575 if (to_underlying (header
->abbrev_sect_off
)
6576 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6577 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6578 "(offset %s + 6) [in module %s]"),
6579 sect_offset_str (header
->abbrev_sect_off
),
6580 sect_offset_str (header
->sect_off
),
6583 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6584 avoid potential 32-bit overflow. */
6585 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6587 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6588 "(offset %s + 0) [in module %s]"),
6589 header
->length
, sect_offset_str (header
->sect_off
),
6593 /* Read in a CU/TU header and perform some basic error checking.
6594 The contents of the header are stored in HEADER.
6595 The result is a pointer to the start of the first DIE. */
6597 static const gdb_byte
*
6598 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6599 struct comp_unit_head
*header
,
6600 struct dwarf2_section_info
*section
,
6601 struct dwarf2_section_info
*abbrev_section
,
6602 const gdb_byte
*info_ptr
,
6603 rcuh_kind section_kind
)
6605 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6607 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6609 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6611 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6613 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6619 /* Fetch the abbreviation table offset from a comp or type unit header. */
6622 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6623 struct dwarf2_section_info
*section
,
6624 sect_offset sect_off
)
6626 bfd
*abfd
= get_section_bfd_owner (section
);
6627 const gdb_byte
*info_ptr
;
6628 unsigned int initial_length_size
, offset_size
;
6631 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6632 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6633 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6634 offset_size
= initial_length_size
== 4 ? 4 : 8;
6635 info_ptr
+= initial_length_size
;
6637 version
= read_2_bytes (abfd
, info_ptr
);
6641 /* Skip unit type and address size. */
6645 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6648 /* Allocate a new partial symtab for file named NAME and mark this new
6649 partial symtab as being an include of PST. */
6652 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6653 struct objfile
*objfile
)
6655 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6657 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6659 /* It shares objfile->objfile_obstack. */
6660 subpst
->dirname
= pst
->dirname
;
6663 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6664 subpst
->dependencies
[0] = pst
;
6665 subpst
->number_of_dependencies
= 1;
6667 subpst
->read_symtab
= pst
->read_symtab
;
6669 /* No private part is necessary for include psymtabs. This property
6670 can be used to differentiate between such include psymtabs and
6671 the regular ones. */
6672 subpst
->read_symtab_private
= NULL
;
6675 /* Read the Line Number Program data and extract the list of files
6676 included by the source file represented by PST. Build an include
6677 partial symtab for each of these included files. */
6680 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6681 struct die_info
*die
,
6682 struct partial_symtab
*pst
)
6685 struct attribute
*attr
;
6687 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6688 if (attr
!= nullptr)
6689 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6691 return; /* No linetable, so no includes. */
6693 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6694 that we pass in the raw text_low here; that is ok because we're
6695 only decoding the line table to make include partial symtabs, and
6696 so the addresses aren't really used. */
6697 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6698 pst
->raw_text_low (), 1);
6702 hash_signatured_type (const void *item
)
6704 const struct signatured_type
*sig_type
6705 = (const struct signatured_type
*) item
;
6707 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6708 return sig_type
->signature
;
6712 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6714 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6715 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6717 return lhs
->signature
== rhs
->signature
;
6720 /* Allocate a hash table for signatured types. */
6723 allocate_signatured_type_table (struct objfile
*objfile
)
6725 return htab_create_alloc_ex (41,
6726 hash_signatured_type
,
6729 &objfile
->objfile_obstack
,
6730 hashtab_obstack_allocate
,
6731 dummy_obstack_deallocate
);
6734 /* A helper function to add a signatured type CU to a table. */
6737 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6739 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6740 std::vector
<signatured_type
*> *all_type_units
6741 = (std::vector
<signatured_type
*> *) datum
;
6743 all_type_units
->push_back (sigt
);
6748 /* A helper for create_debug_types_hash_table. Read types from SECTION
6749 and fill them into TYPES_HTAB. It will process only type units,
6750 therefore DW_UT_type. */
6753 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6754 struct dwo_file
*dwo_file
,
6755 dwarf2_section_info
*section
, htab_t
&types_htab
,
6756 rcuh_kind section_kind
)
6758 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6759 struct dwarf2_section_info
*abbrev_section
;
6761 const gdb_byte
*info_ptr
, *end_ptr
;
6763 abbrev_section
= (dwo_file
!= NULL
6764 ? &dwo_file
->sections
.abbrev
6765 : &dwarf2_per_objfile
->abbrev
);
6767 if (dwarf_read_debug
)
6768 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6769 get_section_name (section
),
6770 get_section_file_name (abbrev_section
));
6772 dwarf2_read_section (objfile
, section
);
6773 info_ptr
= section
->buffer
;
6775 if (info_ptr
== NULL
)
6778 /* We can't set abfd until now because the section may be empty or
6779 not present, in which case the bfd is unknown. */
6780 abfd
= get_section_bfd_owner (section
);
6782 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6783 because we don't need to read any dies: the signature is in the
6786 end_ptr
= info_ptr
+ section
->size
;
6787 while (info_ptr
< end_ptr
)
6789 struct signatured_type
*sig_type
;
6790 struct dwo_unit
*dwo_tu
;
6792 const gdb_byte
*ptr
= info_ptr
;
6793 struct comp_unit_head header
;
6794 unsigned int length
;
6796 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6798 /* Initialize it due to a false compiler warning. */
6799 header
.signature
= -1;
6800 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6802 /* We need to read the type's signature in order to build the hash
6803 table, but we don't need anything else just yet. */
6805 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6806 abbrev_section
, ptr
, section_kind
);
6808 length
= get_cu_length (&header
);
6810 /* Skip dummy type units. */
6811 if (ptr
>= info_ptr
+ length
6812 || peek_abbrev_code (abfd
, ptr
) == 0
6813 || header
.unit_type
!= DW_UT_type
)
6819 if (types_htab
== NULL
)
6822 types_htab
= allocate_dwo_unit_table (objfile
);
6824 types_htab
= allocate_signatured_type_table (objfile
);
6830 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6832 dwo_tu
->dwo_file
= dwo_file
;
6833 dwo_tu
->signature
= header
.signature
;
6834 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6835 dwo_tu
->section
= section
;
6836 dwo_tu
->sect_off
= sect_off
;
6837 dwo_tu
->length
= length
;
6841 /* N.B.: type_offset is not usable if this type uses a DWO file.
6842 The real type_offset is in the DWO file. */
6844 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6845 struct signatured_type
);
6846 sig_type
->signature
= header
.signature
;
6847 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6848 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6849 sig_type
->per_cu
.is_debug_types
= 1;
6850 sig_type
->per_cu
.section
= section
;
6851 sig_type
->per_cu
.sect_off
= sect_off
;
6852 sig_type
->per_cu
.length
= length
;
6855 slot
= htab_find_slot (types_htab
,
6856 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6858 gdb_assert (slot
!= NULL
);
6861 sect_offset dup_sect_off
;
6865 const struct dwo_unit
*dup_tu
6866 = (const struct dwo_unit
*) *slot
;
6868 dup_sect_off
= dup_tu
->sect_off
;
6872 const struct signatured_type
*dup_tu
6873 = (const struct signatured_type
*) *slot
;
6875 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6878 complaint (_("debug type entry at offset %s is duplicate to"
6879 " the entry at offset %s, signature %s"),
6880 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6881 hex_string (header
.signature
));
6883 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6885 if (dwarf_read_debug
> 1)
6886 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6887 sect_offset_str (sect_off
),
6888 hex_string (header
.signature
));
6894 /* Create the hash table of all entries in the .debug_types
6895 (or .debug_types.dwo) section(s).
6896 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6897 otherwise it is NULL.
6899 The result is a pointer to the hash table or NULL if there are no types.
6901 Note: This function processes DWO files only, not DWP files. */
6904 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6905 struct dwo_file
*dwo_file
,
6906 gdb::array_view
<dwarf2_section_info
> type_sections
,
6909 for (dwarf2_section_info
§ion
: type_sections
)
6910 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6911 types_htab
, rcuh_kind::TYPE
);
6914 /* Create the hash table of all entries in the .debug_types section,
6915 and initialize all_type_units.
6916 The result is zero if there is an error (e.g. missing .debug_types section),
6917 otherwise non-zero. */
6920 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6922 htab_t types_htab
= NULL
;
6924 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6925 &dwarf2_per_objfile
->info
, types_htab
,
6926 rcuh_kind::COMPILE
);
6927 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6928 dwarf2_per_objfile
->types
, types_htab
);
6929 if (types_htab
== NULL
)
6931 dwarf2_per_objfile
->signatured_types
= NULL
;
6935 dwarf2_per_objfile
->signatured_types
= types_htab
;
6937 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6938 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6940 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6941 &dwarf2_per_objfile
->all_type_units
);
6946 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6947 If SLOT is non-NULL, it is the entry to use in the hash table.
6948 Otherwise we find one. */
6950 static struct signatured_type
*
6951 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6954 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6956 if (dwarf2_per_objfile
->all_type_units
.size ()
6957 == dwarf2_per_objfile
->all_type_units
.capacity ())
6958 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6960 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6961 struct signatured_type
);
6963 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6964 sig_type
->signature
= sig
;
6965 sig_type
->per_cu
.is_debug_types
= 1;
6966 if (dwarf2_per_objfile
->using_index
)
6968 sig_type
->per_cu
.v
.quick
=
6969 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6970 struct dwarf2_per_cu_quick_data
);
6975 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6978 gdb_assert (*slot
== NULL
);
6980 /* The rest of sig_type must be filled in by the caller. */
6984 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6985 Fill in SIG_ENTRY with DWO_ENTRY. */
6988 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6989 struct signatured_type
*sig_entry
,
6990 struct dwo_unit
*dwo_entry
)
6992 /* Make sure we're not clobbering something we don't expect to. */
6993 gdb_assert (! sig_entry
->per_cu
.queued
);
6994 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6995 if (dwarf2_per_objfile
->using_index
)
6997 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6998 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7001 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7002 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7003 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7004 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7005 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7007 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7008 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7009 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7010 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7011 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7012 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7013 sig_entry
->dwo_unit
= dwo_entry
;
7016 /* Subroutine of lookup_signatured_type.
7017 If we haven't read the TU yet, create the signatured_type data structure
7018 for a TU to be read in directly from a DWO file, bypassing the stub.
7019 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7020 using .gdb_index, then when reading a CU we want to stay in the DWO file
7021 containing that CU. Otherwise we could end up reading several other DWO
7022 files (due to comdat folding) to process the transitive closure of all the
7023 mentioned TUs, and that can be slow. The current DWO file will have every
7024 type signature that it needs.
7025 We only do this for .gdb_index because in the psymtab case we already have
7026 to read all the DWOs to build the type unit groups. */
7028 static struct signatured_type
*
7029 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7031 struct dwarf2_per_objfile
*dwarf2_per_objfile
7032 = cu
->per_cu
->dwarf2_per_objfile
;
7033 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7034 struct dwo_file
*dwo_file
;
7035 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7036 struct signatured_type find_sig_entry
, *sig_entry
;
7039 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7041 /* If TU skeletons have been removed then we may not have read in any
7043 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7045 dwarf2_per_objfile
->signatured_types
7046 = allocate_signatured_type_table (objfile
);
7049 /* We only ever need to read in one copy of a signatured type.
7050 Use the global signatured_types array to do our own comdat-folding
7051 of types. If this is the first time we're reading this TU, and
7052 the TU has an entry in .gdb_index, replace the recorded data from
7053 .gdb_index with this TU. */
7055 find_sig_entry
.signature
= sig
;
7056 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7057 &find_sig_entry
, INSERT
);
7058 sig_entry
= (struct signatured_type
*) *slot
;
7060 /* We can get here with the TU already read, *or* in the process of being
7061 read. Don't reassign the global entry to point to this DWO if that's
7062 the case. Also note that if the TU is already being read, it may not
7063 have come from a DWO, the program may be a mix of Fission-compiled
7064 code and non-Fission-compiled code. */
7066 /* Have we already tried to read this TU?
7067 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7068 needn't exist in the global table yet). */
7069 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7072 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7073 dwo_unit of the TU itself. */
7074 dwo_file
= cu
->dwo_unit
->dwo_file
;
7076 /* Ok, this is the first time we're reading this TU. */
7077 if (dwo_file
->tus
== NULL
)
7079 find_dwo_entry
.signature
= sig
;
7080 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7081 if (dwo_entry
== NULL
)
7084 /* If the global table doesn't have an entry for this TU, add one. */
7085 if (sig_entry
== NULL
)
7086 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7088 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7089 sig_entry
->per_cu
.tu_read
= 1;
7093 /* Subroutine of lookup_signatured_type.
7094 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7095 then try the DWP file. If the TU stub (skeleton) has been removed then
7096 it won't be in .gdb_index. */
7098 static struct signatured_type
*
7099 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7101 struct dwarf2_per_objfile
*dwarf2_per_objfile
7102 = cu
->per_cu
->dwarf2_per_objfile
;
7103 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7104 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7105 struct dwo_unit
*dwo_entry
;
7106 struct signatured_type find_sig_entry
, *sig_entry
;
7109 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7110 gdb_assert (dwp_file
!= NULL
);
7112 /* If TU skeletons have been removed then we may not have read in any
7114 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7116 dwarf2_per_objfile
->signatured_types
7117 = allocate_signatured_type_table (objfile
);
7120 find_sig_entry
.signature
= sig
;
7121 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7122 &find_sig_entry
, INSERT
);
7123 sig_entry
= (struct signatured_type
*) *slot
;
7125 /* Have we already tried to read this TU?
7126 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7127 needn't exist in the global table yet). */
7128 if (sig_entry
!= NULL
)
7131 if (dwp_file
->tus
== NULL
)
7133 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7134 sig
, 1 /* is_debug_types */);
7135 if (dwo_entry
== NULL
)
7138 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7139 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7144 /* Lookup a signature based type for DW_FORM_ref_sig8.
7145 Returns NULL if signature SIG is not present in the table.
7146 It is up to the caller to complain about this. */
7148 static struct signatured_type
*
7149 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7151 struct dwarf2_per_objfile
*dwarf2_per_objfile
7152 = cu
->per_cu
->dwarf2_per_objfile
;
7155 && dwarf2_per_objfile
->using_index
)
7157 /* We're in a DWO/DWP file, and we're using .gdb_index.
7158 These cases require special processing. */
7159 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7160 return lookup_dwo_signatured_type (cu
, sig
);
7162 return lookup_dwp_signatured_type (cu
, sig
);
7166 struct signatured_type find_entry
, *entry
;
7168 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7170 find_entry
.signature
= sig
;
7171 entry
= ((struct signatured_type
*)
7172 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7177 /* Low level DIE reading support. */
7179 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7182 init_cu_die_reader (struct die_reader_specs
*reader
,
7183 struct dwarf2_cu
*cu
,
7184 struct dwarf2_section_info
*section
,
7185 struct dwo_file
*dwo_file
,
7186 struct abbrev_table
*abbrev_table
)
7188 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7189 reader
->abfd
= get_section_bfd_owner (section
);
7191 reader
->dwo_file
= dwo_file
;
7192 reader
->die_section
= section
;
7193 reader
->buffer
= section
->buffer
;
7194 reader
->buffer_end
= section
->buffer
+ section
->size
;
7195 reader
->comp_dir
= NULL
;
7196 reader
->abbrev_table
= abbrev_table
;
7199 /* Subroutine of init_cutu_and_read_dies to simplify it.
7200 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7201 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7204 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7205 from it to the DIE in the DWO. If NULL we are skipping the stub.
7206 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7207 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7208 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7209 STUB_COMP_DIR may be non-NULL.
7210 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7211 are filled in with the info of the DIE from the DWO file.
7212 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7213 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7214 kept around for at least as long as *RESULT_READER.
7216 The result is non-zero if a valid (non-dummy) DIE was found. */
7219 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7220 struct dwo_unit
*dwo_unit
,
7221 struct die_info
*stub_comp_unit_die
,
7222 const char *stub_comp_dir
,
7223 struct die_reader_specs
*result_reader
,
7224 const gdb_byte
**result_info_ptr
,
7225 struct die_info
**result_comp_unit_die
,
7226 int *result_has_children
,
7227 abbrev_table_up
*result_dwo_abbrev_table
)
7229 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7230 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7231 struct dwarf2_cu
*cu
= this_cu
->cu
;
7233 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7234 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7235 int i
,num_extra_attrs
;
7236 struct dwarf2_section_info
*dwo_abbrev_section
;
7237 struct attribute
*attr
;
7238 struct die_info
*comp_unit_die
;
7240 /* At most one of these may be provided. */
7241 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7243 /* These attributes aren't processed until later:
7244 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7245 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7246 referenced later. However, these attributes are found in the stub
7247 which we won't have later. In order to not impose this complication
7248 on the rest of the code, we read them here and copy them to the
7257 if (stub_comp_unit_die
!= NULL
)
7259 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7261 if (! this_cu
->is_debug_types
)
7262 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7263 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7264 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7265 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7266 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7268 /* There should be a DW_AT_addr_base attribute here (if needed).
7269 We need the value before we can process DW_FORM_GNU_addr_index
7270 or DW_FORM_addrx. */
7272 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7273 if (attr
!= nullptr)
7274 cu
->addr_base
= DW_UNSND (attr
);
7276 /* There should be a DW_AT_ranges_base attribute here (if needed).
7277 We need the value before we can process DW_AT_ranges. */
7278 cu
->ranges_base
= 0;
7279 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7280 if (attr
!= nullptr)
7281 cu
->ranges_base
= DW_UNSND (attr
);
7283 else if (stub_comp_dir
!= NULL
)
7285 /* Reconstruct the comp_dir attribute to simplify the code below. */
7286 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7287 comp_dir
->name
= DW_AT_comp_dir
;
7288 comp_dir
->form
= DW_FORM_string
;
7289 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7290 DW_STRING (comp_dir
) = stub_comp_dir
;
7293 /* Set up for reading the DWO CU/TU. */
7294 cu
->dwo_unit
= dwo_unit
;
7295 dwarf2_section_info
*section
= dwo_unit
->section
;
7296 dwarf2_read_section (objfile
, section
);
7297 abfd
= get_section_bfd_owner (section
);
7298 begin_info_ptr
= info_ptr
= (section
->buffer
7299 + to_underlying (dwo_unit
->sect_off
));
7300 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7302 if (this_cu
->is_debug_types
)
7304 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7306 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7307 &cu
->header
, section
,
7309 info_ptr
, rcuh_kind::TYPE
);
7310 /* This is not an assert because it can be caused by bad debug info. */
7311 if (sig_type
->signature
!= cu
->header
.signature
)
7313 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7314 " TU at offset %s [in module %s]"),
7315 hex_string (sig_type
->signature
),
7316 hex_string (cu
->header
.signature
),
7317 sect_offset_str (dwo_unit
->sect_off
),
7318 bfd_get_filename (abfd
));
7320 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7321 /* For DWOs coming from DWP files, we don't know the CU length
7322 nor the type's offset in the TU until now. */
7323 dwo_unit
->length
= get_cu_length (&cu
->header
);
7324 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7326 /* Establish the type offset that can be used to lookup the type.
7327 For DWO files, we don't know it until now. */
7328 sig_type
->type_offset_in_section
7329 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7333 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7334 &cu
->header
, section
,
7336 info_ptr
, rcuh_kind::COMPILE
);
7337 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7338 /* For DWOs coming from DWP files, we don't know the CU length
7340 dwo_unit
->length
= get_cu_length (&cu
->header
);
7343 *result_dwo_abbrev_table
7344 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7345 cu
->header
.abbrev_sect_off
);
7346 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7347 result_dwo_abbrev_table
->get ());
7349 /* Read in the die, but leave space to copy over the attributes
7350 from the stub. This has the benefit of simplifying the rest of
7351 the code - all the work to maintain the illusion of a single
7352 DW_TAG_{compile,type}_unit DIE is done here. */
7353 num_extra_attrs
= ((stmt_list
!= NULL
)
7357 + (comp_dir
!= NULL
));
7358 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7359 result_has_children
, num_extra_attrs
);
7361 /* Copy over the attributes from the stub to the DIE we just read in. */
7362 comp_unit_die
= *result_comp_unit_die
;
7363 i
= comp_unit_die
->num_attrs
;
7364 if (stmt_list
!= NULL
)
7365 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7367 comp_unit_die
->attrs
[i
++] = *low_pc
;
7368 if (high_pc
!= NULL
)
7369 comp_unit_die
->attrs
[i
++] = *high_pc
;
7371 comp_unit_die
->attrs
[i
++] = *ranges
;
7372 if (comp_dir
!= NULL
)
7373 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7374 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7376 if (dwarf_die_debug
)
7378 fprintf_unfiltered (gdb_stdlog
,
7379 "Read die from %s@0x%x of %s:\n",
7380 get_section_name (section
),
7381 (unsigned) (begin_info_ptr
- section
->buffer
),
7382 bfd_get_filename (abfd
));
7383 dump_die (comp_unit_die
, dwarf_die_debug
);
7386 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7387 TUs by skipping the stub and going directly to the entry in the DWO file.
7388 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7389 to get it via circuitous means. Blech. */
7390 if (comp_dir
!= NULL
)
7391 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7393 /* Skip dummy compilation units. */
7394 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7395 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7398 *result_info_ptr
= info_ptr
;
7402 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7403 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7404 signature is part of the header. */
7405 static gdb::optional
<ULONGEST
>
7406 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7408 if (cu
->header
.version
>= 5)
7409 return cu
->header
.signature
;
7410 struct attribute
*attr
;
7411 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7412 if (attr
== nullptr)
7413 return gdb::optional
<ULONGEST
> ();
7414 return DW_UNSND (attr
);
7417 /* Subroutine of init_cutu_and_read_dies to simplify it.
7418 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7419 Returns NULL if the specified DWO unit cannot be found. */
7421 static struct dwo_unit
*
7422 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7423 struct die_info
*comp_unit_die
)
7425 struct dwarf2_cu
*cu
= this_cu
->cu
;
7426 struct dwo_unit
*dwo_unit
;
7427 const char *comp_dir
, *dwo_name
;
7429 gdb_assert (cu
!= NULL
);
7431 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7432 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7433 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7435 if (this_cu
->is_debug_types
)
7437 struct signatured_type
*sig_type
;
7439 /* Since this_cu is the first member of struct signatured_type,
7440 we can go from a pointer to one to a pointer to the other. */
7441 sig_type
= (struct signatured_type
*) this_cu
;
7442 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7446 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7447 if (!signature
.has_value ())
7448 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7450 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7451 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7458 /* Subroutine of init_cutu_and_read_dies to simplify it.
7459 See it for a description of the parameters.
7460 Read a TU directly from a DWO file, bypassing the stub. */
7463 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7464 int use_existing_cu
, int keep
,
7465 die_reader_func_ftype
*die_reader_func
,
7468 std::unique_ptr
<dwarf2_cu
> new_cu
;
7469 struct signatured_type
*sig_type
;
7470 struct die_reader_specs reader
;
7471 const gdb_byte
*info_ptr
;
7472 struct die_info
*comp_unit_die
;
7474 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7476 /* Verify we can do the following downcast, and that we have the
7478 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7479 sig_type
= (struct signatured_type
*) this_cu
;
7480 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7482 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7484 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7485 /* There's no need to do the rereading_dwo_cu handling that
7486 init_cutu_and_read_dies does since we don't read the stub. */
7490 /* If !use_existing_cu, this_cu->cu must be NULL. */
7491 gdb_assert (this_cu
->cu
== NULL
);
7492 new_cu
.reset (new dwarf2_cu (this_cu
));
7495 /* A future optimization, if needed, would be to use an existing
7496 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7497 could share abbrev tables. */
7499 /* The abbreviation table used by READER, this must live at least as long as
7501 abbrev_table_up dwo_abbrev_table
;
7503 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7504 NULL
/* stub_comp_unit_die */,
7505 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7507 &comp_unit_die
, &has_children
,
7508 &dwo_abbrev_table
) == 0)
7514 /* All the "real" work is done here. */
7515 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7517 /* This duplicates the code in init_cutu_and_read_dies,
7518 but the alternative is making the latter more complex.
7519 This function is only for the special case of using DWO files directly:
7520 no point in overly complicating the general case just to handle this. */
7521 if (new_cu
!= NULL
&& keep
)
7523 /* Link this CU into read_in_chain. */
7524 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7525 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7526 /* The chain owns it now. */
7531 /* Initialize a CU (or TU) and read its DIEs.
7532 If the CU defers to a DWO file, read the DWO file as well.
7534 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7535 Otherwise the table specified in the comp unit header is read in and used.
7536 This is an optimization for when we already have the abbrev table.
7538 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7539 Otherwise, a new CU is allocated with xmalloc.
7541 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7542 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7544 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7545 linker) then DIE_READER_FUNC will not get called. */
7548 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7549 struct abbrev_table
*abbrev_table
,
7550 int use_existing_cu
, int keep
,
7552 die_reader_func_ftype
*die_reader_func
,
7555 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7557 struct dwarf2_section_info
*section
= this_cu
->section
;
7558 bfd
*abfd
= get_section_bfd_owner (section
);
7559 struct dwarf2_cu
*cu
;
7560 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7561 struct die_reader_specs reader
;
7562 struct die_info
*comp_unit_die
;
7564 struct signatured_type
*sig_type
= NULL
;
7565 struct dwarf2_section_info
*abbrev_section
;
7566 /* Non-zero if CU currently points to a DWO file and we need to
7567 reread it. When this happens we need to reread the skeleton die
7568 before we can reread the DWO file (this only applies to CUs, not TUs). */
7569 int rereading_dwo_cu
= 0;
7571 if (dwarf_die_debug
)
7572 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7573 this_cu
->is_debug_types
? "type" : "comp",
7574 sect_offset_str (this_cu
->sect_off
));
7576 if (use_existing_cu
)
7579 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7580 file (instead of going through the stub), short-circuit all of this. */
7581 if (this_cu
->reading_dwo_directly
)
7583 /* Narrow down the scope of possibilities to have to understand. */
7584 gdb_assert (this_cu
->is_debug_types
);
7585 gdb_assert (abbrev_table
== NULL
);
7586 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7587 die_reader_func
, data
);
7591 /* This is cheap if the section is already read in. */
7592 dwarf2_read_section (objfile
, section
);
7594 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7596 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7598 std::unique_ptr
<dwarf2_cu
> new_cu
;
7599 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7602 /* If this CU is from a DWO file we need to start over, we need to
7603 refetch the attributes from the skeleton CU.
7604 This could be optimized by retrieving those attributes from when we
7605 were here the first time: the previous comp_unit_die was stored in
7606 comp_unit_obstack. But there's no data yet that we need this
7608 if (cu
->dwo_unit
!= NULL
)
7609 rereading_dwo_cu
= 1;
7613 /* If !use_existing_cu, this_cu->cu must be NULL. */
7614 gdb_assert (this_cu
->cu
== NULL
);
7615 new_cu
.reset (new dwarf2_cu (this_cu
));
7619 /* Get the header. */
7620 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7622 /* We already have the header, there's no need to read it in again. */
7623 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7627 if (this_cu
->is_debug_types
)
7629 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7630 &cu
->header
, section
,
7631 abbrev_section
, info_ptr
,
7634 /* Since per_cu is the first member of struct signatured_type,
7635 we can go from a pointer to one to a pointer to the other. */
7636 sig_type
= (struct signatured_type
*) this_cu
;
7637 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7638 gdb_assert (sig_type
->type_offset_in_tu
7639 == cu
->header
.type_cu_offset_in_tu
);
7640 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7642 /* LENGTH has not been set yet for type units if we're
7643 using .gdb_index. */
7644 this_cu
->length
= get_cu_length (&cu
->header
);
7646 /* Establish the type offset that can be used to lookup the type. */
7647 sig_type
->type_offset_in_section
=
7648 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7650 this_cu
->dwarf_version
= cu
->header
.version
;
7654 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7655 &cu
->header
, section
,
7658 rcuh_kind::COMPILE
);
7660 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7661 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7662 this_cu
->dwarf_version
= cu
->header
.version
;
7666 /* Skip dummy compilation units. */
7667 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7668 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7671 /* If we don't have them yet, read the abbrevs for this compilation unit.
7672 And if we need to read them now, make sure they're freed when we're
7673 done (own the table through ABBREV_TABLE_HOLDER). */
7674 abbrev_table_up abbrev_table_holder
;
7675 if (abbrev_table
!= NULL
)
7676 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7680 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7681 cu
->header
.abbrev_sect_off
);
7682 abbrev_table
= abbrev_table_holder
.get ();
7685 /* Read the top level CU/TU die. */
7686 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7687 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7689 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7692 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7693 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7694 table from the DWO file and pass the ownership over to us. It will be
7695 referenced from READER, so we must make sure to free it after we're done
7698 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7699 DWO CU, that this test will fail (the attribute will not be present). */
7700 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7701 abbrev_table_up dwo_abbrev_table
;
7702 if (dwo_name
!= nullptr)
7704 struct dwo_unit
*dwo_unit
;
7705 struct die_info
*dwo_comp_unit_die
;
7709 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7710 " has children (offset %s) [in module %s]"),
7711 sect_offset_str (this_cu
->sect_off
),
7712 bfd_get_filename (abfd
));
7714 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7715 if (dwo_unit
!= NULL
)
7717 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7718 comp_unit_die
, NULL
,
7720 &dwo_comp_unit_die
, &has_children
,
7721 &dwo_abbrev_table
) == 0)
7726 comp_unit_die
= dwo_comp_unit_die
;
7730 /* Yikes, we couldn't find the rest of the DIE, we only have
7731 the stub. A complaint has already been logged. There's
7732 not much more we can do except pass on the stub DIE to
7733 die_reader_func. We don't want to throw an error on bad
7738 /* All of the above is setup for this call. Yikes. */
7739 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7741 /* Done, clean up. */
7742 if (new_cu
!= NULL
&& keep
)
7744 /* Link this CU into read_in_chain. */
7745 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7746 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7747 /* The chain owns it now. */
7752 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7753 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7754 to have already done the lookup to find the DWO file).
7756 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7757 THIS_CU->is_debug_types, but nothing else.
7759 We fill in THIS_CU->length.
7761 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7762 linker) then DIE_READER_FUNC will not get called.
7764 THIS_CU->cu is always freed when done.
7765 This is done in order to not leave THIS_CU->cu in a state where we have
7766 to care whether it refers to the "main" CU or the DWO CU. */
7769 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7770 struct dwo_file
*dwo_file
,
7771 die_reader_func_ftype
*die_reader_func
,
7774 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7775 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7776 struct dwarf2_section_info
*section
= this_cu
->section
;
7777 bfd
*abfd
= get_section_bfd_owner (section
);
7778 struct dwarf2_section_info
*abbrev_section
;
7779 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7780 struct die_reader_specs reader
;
7781 struct die_info
*comp_unit_die
;
7784 if (dwarf_die_debug
)
7785 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7786 this_cu
->is_debug_types
? "type" : "comp",
7787 sect_offset_str (this_cu
->sect_off
));
7789 gdb_assert (this_cu
->cu
== NULL
);
7791 abbrev_section
= (dwo_file
!= NULL
7792 ? &dwo_file
->sections
.abbrev
7793 : get_abbrev_section_for_cu (this_cu
));
7795 /* This is cheap if the section is already read in. */
7796 dwarf2_read_section (objfile
, section
);
7798 struct dwarf2_cu
cu (this_cu
);
7800 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7801 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7802 &cu
.header
, section
,
7803 abbrev_section
, info_ptr
,
7804 (this_cu
->is_debug_types
7806 : rcuh_kind::COMPILE
));
7808 this_cu
->length
= get_cu_length (&cu
.header
);
7810 /* Skip dummy compilation units. */
7811 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7812 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7815 abbrev_table_up abbrev_table
7816 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7817 cu
.header
.abbrev_sect_off
);
7819 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7820 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7822 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7825 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7826 does not lookup the specified DWO file.
7827 This cannot be used to read DWO files.
7829 THIS_CU->cu is always freed when done.
7830 This is done in order to not leave THIS_CU->cu in a state where we have
7831 to care whether it refers to the "main" CU or the DWO CU.
7832 We can revisit this if the data shows there's a performance issue. */
7835 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7836 die_reader_func_ftype
*die_reader_func
,
7839 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7842 /* Type Unit Groups.
7844 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7845 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7846 so that all types coming from the same compilation (.o file) are grouped
7847 together. A future step could be to put the types in the same symtab as
7848 the CU the types ultimately came from. */
7851 hash_type_unit_group (const void *item
)
7853 const struct type_unit_group
*tu_group
7854 = (const struct type_unit_group
*) item
;
7856 return hash_stmt_list_entry (&tu_group
->hash
);
7860 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7862 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7863 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7865 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7868 /* Allocate a hash table for type unit groups. */
7871 allocate_type_unit_groups_table (struct objfile
*objfile
)
7873 return htab_create_alloc_ex (3,
7874 hash_type_unit_group
,
7877 &objfile
->objfile_obstack
,
7878 hashtab_obstack_allocate
,
7879 dummy_obstack_deallocate
);
7882 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7883 partial symtabs. We combine several TUs per psymtab to not let the size
7884 of any one psymtab grow too big. */
7885 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7886 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7888 /* Helper routine for get_type_unit_group.
7889 Create the type_unit_group object used to hold one or more TUs. */
7891 static struct type_unit_group
*
7892 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7894 struct dwarf2_per_objfile
*dwarf2_per_objfile
7895 = cu
->per_cu
->dwarf2_per_objfile
;
7896 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7897 struct dwarf2_per_cu_data
*per_cu
;
7898 struct type_unit_group
*tu_group
;
7900 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7901 struct type_unit_group
);
7902 per_cu
= &tu_group
->per_cu
;
7903 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7905 if (dwarf2_per_objfile
->using_index
)
7907 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7908 struct dwarf2_per_cu_quick_data
);
7912 unsigned int line_offset
= to_underlying (line_offset_struct
);
7913 struct partial_symtab
*pst
;
7916 /* Give the symtab a useful name for debug purposes. */
7917 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7918 name
= string_printf ("<type_units_%d>",
7919 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7921 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7923 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7927 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7928 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7933 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7934 STMT_LIST is a DW_AT_stmt_list attribute. */
7936 static struct type_unit_group
*
7937 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7939 struct dwarf2_per_objfile
*dwarf2_per_objfile
7940 = cu
->per_cu
->dwarf2_per_objfile
;
7941 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7942 struct type_unit_group
*tu_group
;
7944 unsigned int line_offset
;
7945 struct type_unit_group type_unit_group_for_lookup
;
7947 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7949 dwarf2_per_objfile
->type_unit_groups
=
7950 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7953 /* Do we need to create a new group, or can we use an existing one? */
7957 line_offset
= DW_UNSND (stmt_list
);
7958 ++tu_stats
->nr_symtab_sharers
;
7962 /* Ugh, no stmt_list. Rare, but we have to handle it.
7963 We can do various things here like create one group per TU or
7964 spread them over multiple groups to split up the expansion work.
7965 To avoid worst case scenarios (too many groups or too large groups)
7966 we, umm, group them in bunches. */
7967 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7968 | (tu_stats
->nr_stmt_less_type_units
7969 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7970 ++tu_stats
->nr_stmt_less_type_units
;
7973 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7974 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7975 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7976 &type_unit_group_for_lookup
, INSERT
);
7979 tu_group
= (struct type_unit_group
*) *slot
;
7980 gdb_assert (tu_group
!= NULL
);
7984 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7985 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7987 ++tu_stats
->nr_symtabs
;
7993 /* Partial symbol tables. */
7995 /* Create a psymtab named NAME and assign it to PER_CU.
7997 The caller must fill in the following details:
7998 dirname, textlow, texthigh. */
8000 static struct partial_symtab
*
8001 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8003 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8004 struct partial_symtab
*pst
;
8006 pst
= start_psymtab_common (objfile
, name
, 0);
8008 pst
->psymtabs_addrmap_supported
= 1;
8010 /* This is the glue that links PST into GDB's symbol API. */
8011 pst
->read_symtab_private
= per_cu
;
8012 pst
->read_symtab
= dwarf2_read_symtab
;
8013 per_cu
->v
.psymtab
= pst
;
8018 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8021 struct process_psymtab_comp_unit_data
8023 /* True if we are reading a DW_TAG_partial_unit. */
8025 int want_partial_unit
;
8027 /* The "pretend" language that is used if the CU doesn't declare a
8030 enum language pretend_language
;
8033 /* die_reader_func for process_psymtab_comp_unit. */
8036 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8037 const gdb_byte
*info_ptr
,
8038 struct die_info
*comp_unit_die
,
8042 struct dwarf2_cu
*cu
= reader
->cu
;
8043 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8044 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8045 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8047 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8048 struct partial_symtab
*pst
;
8049 enum pc_bounds_kind cu_bounds_kind
;
8050 const char *filename
;
8051 struct process_psymtab_comp_unit_data
*info
8052 = (struct process_psymtab_comp_unit_data
*) data
;
8054 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8057 gdb_assert (! per_cu
->is_debug_types
);
8059 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8061 /* Allocate a new partial symbol table structure. */
8062 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8063 if (filename
== NULL
)
8066 pst
= create_partial_symtab (per_cu
, filename
);
8068 /* This must be done before calling dwarf2_build_include_psymtabs. */
8069 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8071 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8073 dwarf2_find_base_address (comp_unit_die
, cu
);
8075 /* Possibly set the default values of LOWPC and HIGHPC from
8077 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8078 &best_highpc
, cu
, pst
);
8079 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8082 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8085 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8087 /* Store the contiguous range if it is not empty; it can be
8088 empty for CUs with no code. */
8089 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8093 /* Check if comp unit has_children.
8094 If so, read the rest of the partial symbols from this comp unit.
8095 If not, there's no more debug_info for this comp unit. */
8098 struct partial_die_info
*first_die
;
8099 CORE_ADDR lowpc
, highpc
;
8101 lowpc
= ((CORE_ADDR
) -1);
8102 highpc
= ((CORE_ADDR
) 0);
8104 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8106 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8107 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8109 /* If we didn't find a lowpc, set it to highpc to avoid
8110 complaints from `maint check'. */
8111 if (lowpc
== ((CORE_ADDR
) -1))
8114 /* If the compilation unit didn't have an explicit address range,
8115 then use the information extracted from its child dies. */
8116 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8119 best_highpc
= highpc
;
8122 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8123 best_lowpc
+ baseaddr
)
8125 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8126 best_highpc
+ baseaddr
)
8129 end_psymtab_common (objfile
, pst
);
8131 if (!cu
->per_cu
->imported_symtabs_empty ())
8134 int len
= cu
->per_cu
->imported_symtabs_size ();
8136 /* Fill in 'dependencies' here; we fill in 'users' in a
8138 pst
->number_of_dependencies
= len
;
8140 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8141 for (i
= 0; i
< len
; ++i
)
8143 pst
->dependencies
[i
]
8144 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8147 cu
->per_cu
->imported_symtabs_free ();
8150 /* Get the list of files included in the current compilation unit,
8151 and build a psymtab for each of them. */
8152 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8154 if (dwarf_read_debug
)
8155 fprintf_unfiltered (gdb_stdlog
,
8156 "Psymtab for %s unit @%s: %s - %s"
8157 ", %d global, %d static syms\n",
8158 per_cu
->is_debug_types
? "type" : "comp",
8159 sect_offset_str (per_cu
->sect_off
),
8160 paddress (gdbarch
, pst
->text_low (objfile
)),
8161 paddress (gdbarch
, pst
->text_high (objfile
)),
8162 pst
->n_global_syms
, pst
->n_static_syms
);
8165 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8166 Process compilation unit THIS_CU for a psymtab. */
8169 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8170 int want_partial_unit
,
8171 enum language pretend_language
)
8173 /* If this compilation unit was already read in, free the
8174 cached copy in order to read it in again. This is
8175 necessary because we skipped some symbols when we first
8176 read in the compilation unit (see load_partial_dies).
8177 This problem could be avoided, but the benefit is unclear. */
8178 if (this_cu
->cu
!= NULL
)
8179 free_one_cached_comp_unit (this_cu
);
8181 if (this_cu
->is_debug_types
)
8182 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8183 build_type_psymtabs_reader
, NULL
);
8186 process_psymtab_comp_unit_data info
;
8187 info
.want_partial_unit
= want_partial_unit
;
8188 info
.pretend_language
= pretend_language
;
8189 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8190 process_psymtab_comp_unit_reader
, &info
);
8193 /* Age out any secondary CUs. */
8194 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8197 /* Reader function for build_type_psymtabs. */
8200 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8201 const gdb_byte
*info_ptr
,
8202 struct die_info
*type_unit_die
,
8206 struct dwarf2_per_objfile
*dwarf2_per_objfile
8207 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8208 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8209 struct dwarf2_cu
*cu
= reader
->cu
;
8210 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8211 struct signatured_type
*sig_type
;
8212 struct type_unit_group
*tu_group
;
8213 struct attribute
*attr
;
8214 struct partial_die_info
*first_die
;
8215 CORE_ADDR lowpc
, highpc
;
8216 struct partial_symtab
*pst
;
8218 gdb_assert (data
== NULL
);
8219 gdb_assert (per_cu
->is_debug_types
);
8220 sig_type
= (struct signatured_type
*) per_cu
;
8225 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8226 tu_group
= get_type_unit_group (cu
, attr
);
8228 if (tu_group
->tus
== nullptr)
8229 tu_group
->tus
= new std::vector
<signatured_type
*>;
8230 tu_group
->tus
->push_back (sig_type
);
8232 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8233 pst
= create_partial_symtab (per_cu
, "");
8236 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8238 lowpc
= (CORE_ADDR
) -1;
8239 highpc
= (CORE_ADDR
) 0;
8240 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8242 end_psymtab_common (objfile
, pst
);
8245 /* Struct used to sort TUs by their abbreviation table offset. */
8247 struct tu_abbrev_offset
8249 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8250 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8253 signatured_type
*sig_type
;
8254 sect_offset abbrev_offset
;
8257 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8260 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8261 const struct tu_abbrev_offset
&b
)
8263 return a
.abbrev_offset
< b
.abbrev_offset
;
8266 /* Efficiently read all the type units.
8267 This does the bulk of the work for build_type_psymtabs.
8269 The efficiency is because we sort TUs by the abbrev table they use and
8270 only read each abbrev table once. In one program there are 200K TUs
8271 sharing 8K abbrev tables.
8273 The main purpose of this function is to support building the
8274 dwarf2_per_objfile->type_unit_groups table.
8275 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8276 can collapse the search space by grouping them by stmt_list.
8277 The savings can be significant, in the same program from above the 200K TUs
8278 share 8K stmt_list tables.
8280 FUNC is expected to call get_type_unit_group, which will create the
8281 struct type_unit_group if necessary and add it to
8282 dwarf2_per_objfile->type_unit_groups. */
8285 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8287 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8288 abbrev_table_up abbrev_table
;
8289 sect_offset abbrev_offset
;
8291 /* It's up to the caller to not call us multiple times. */
8292 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8294 if (dwarf2_per_objfile
->all_type_units
.empty ())
8297 /* TUs typically share abbrev tables, and there can be way more TUs than
8298 abbrev tables. Sort by abbrev table to reduce the number of times we
8299 read each abbrev table in.
8300 Alternatives are to punt or to maintain a cache of abbrev tables.
8301 This is simpler and efficient enough for now.
8303 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8304 symtab to use). Typically TUs with the same abbrev offset have the same
8305 stmt_list value too so in practice this should work well.
8307 The basic algorithm here is:
8309 sort TUs by abbrev table
8310 for each TU with same abbrev table:
8311 read abbrev table if first user
8312 read TU top level DIE
8313 [IWBN if DWO skeletons had DW_AT_stmt_list]
8316 if (dwarf_read_debug
)
8317 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8319 /* Sort in a separate table to maintain the order of all_type_units
8320 for .gdb_index: TU indices directly index all_type_units. */
8321 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8322 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8324 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8325 sorted_by_abbrev
.emplace_back
8326 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8327 sig_type
->per_cu
.section
,
8328 sig_type
->per_cu
.sect_off
));
8330 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8331 sort_tu_by_abbrev_offset
);
8333 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8335 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8337 /* Switch to the next abbrev table if necessary. */
8338 if (abbrev_table
== NULL
8339 || tu
.abbrev_offset
!= abbrev_offset
)
8341 abbrev_offset
= tu
.abbrev_offset
;
8343 abbrev_table_read_table (dwarf2_per_objfile
,
8344 &dwarf2_per_objfile
->abbrev
,
8346 ++tu_stats
->nr_uniq_abbrev_tables
;
8349 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8350 0, 0, false, build_type_psymtabs_reader
, NULL
);
8354 /* Print collected type unit statistics. */
8357 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8359 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8361 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8362 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8363 dwarf2_per_objfile
->all_type_units
.size ());
8364 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8365 tu_stats
->nr_uniq_abbrev_tables
);
8366 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8367 tu_stats
->nr_symtabs
);
8368 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8369 tu_stats
->nr_symtab_sharers
);
8370 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8371 tu_stats
->nr_stmt_less_type_units
);
8372 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8373 tu_stats
->nr_all_type_units_reallocs
);
8376 /* Traversal function for build_type_psymtabs. */
8379 build_type_psymtab_dependencies (void **slot
, void *info
)
8381 struct dwarf2_per_objfile
*dwarf2_per_objfile
8382 = (struct dwarf2_per_objfile
*) info
;
8383 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8384 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8385 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8386 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8387 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8390 gdb_assert (len
> 0);
8391 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8393 pst
->number_of_dependencies
= len
;
8394 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8395 for (i
= 0; i
< len
; ++i
)
8397 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8398 gdb_assert (iter
->per_cu
.is_debug_types
);
8399 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8400 iter
->type_unit_group
= tu_group
;
8403 delete tu_group
->tus
;
8404 tu_group
->tus
= nullptr;
8409 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8410 Build partial symbol tables for the .debug_types comp-units. */
8413 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8415 if (! create_all_type_units (dwarf2_per_objfile
))
8418 build_type_psymtabs_1 (dwarf2_per_objfile
);
8421 /* Traversal function for process_skeletonless_type_unit.
8422 Read a TU in a DWO file and build partial symbols for it. */
8425 process_skeletonless_type_unit (void **slot
, void *info
)
8427 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8428 struct dwarf2_per_objfile
*dwarf2_per_objfile
8429 = (struct dwarf2_per_objfile
*) info
;
8430 struct signatured_type find_entry
, *entry
;
8432 /* If this TU doesn't exist in the global table, add it and read it in. */
8434 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8436 dwarf2_per_objfile
->signatured_types
8437 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8440 find_entry
.signature
= dwo_unit
->signature
;
8441 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8443 /* If we've already seen this type there's nothing to do. What's happening
8444 is we're doing our own version of comdat-folding here. */
8448 /* This does the job that create_all_type_units would have done for
8450 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8451 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8454 /* This does the job that build_type_psymtabs_1 would have done. */
8455 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8456 build_type_psymtabs_reader
, NULL
);
8461 /* Traversal function for process_skeletonless_type_units. */
8464 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8466 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8468 if (dwo_file
->tus
!= NULL
)
8470 htab_traverse_noresize (dwo_file
->tus
,
8471 process_skeletonless_type_unit
, info
);
8477 /* Scan all TUs of DWO files, verifying we've processed them.
8478 This is needed in case a TU was emitted without its skeleton.
8479 Note: This can't be done until we know what all the DWO files are. */
8482 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8484 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8485 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8486 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8488 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8489 process_dwo_file_for_skeletonless_type_units
,
8490 dwarf2_per_objfile
);
8494 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8497 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8499 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8501 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8506 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8508 /* Set the 'user' field only if it is not already set. */
8509 if (pst
->dependencies
[j
]->user
== NULL
)
8510 pst
->dependencies
[j
]->user
= pst
;
8515 /* Build the partial symbol table by doing a quick pass through the
8516 .debug_info and .debug_abbrev sections. */
8519 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8521 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8523 if (dwarf_read_debug
)
8525 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8526 objfile_name (objfile
));
8529 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8531 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8533 /* Any cached compilation units will be linked by the per-objfile
8534 read_in_chain. Make sure to free them when we're done. */
8535 free_cached_comp_units
freer (dwarf2_per_objfile
);
8537 build_type_psymtabs (dwarf2_per_objfile
);
8539 create_all_comp_units (dwarf2_per_objfile
);
8541 /* Create a temporary address map on a temporary obstack. We later
8542 copy this to the final obstack. */
8543 auto_obstack temp_obstack
;
8545 scoped_restore save_psymtabs_addrmap
8546 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8547 addrmap_create_mutable (&temp_obstack
));
8549 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8550 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8552 /* This has to wait until we read the CUs, we need the list of DWOs. */
8553 process_skeletonless_type_units (dwarf2_per_objfile
);
8555 /* Now that all TUs have been processed we can fill in the dependencies. */
8556 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8558 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8559 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8562 if (dwarf_read_debug
)
8563 print_tu_stats (dwarf2_per_objfile
);
8565 set_partial_user (dwarf2_per_objfile
);
8567 objfile
->partial_symtabs
->psymtabs_addrmap
8568 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8569 objfile
->partial_symtabs
->obstack ());
8570 /* At this point we want to keep the address map. */
8571 save_psymtabs_addrmap
.release ();
8573 if (dwarf_read_debug
)
8574 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8575 objfile_name (objfile
));
8578 /* die_reader_func for load_partial_comp_unit. */
8581 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8582 const gdb_byte
*info_ptr
,
8583 struct die_info
*comp_unit_die
,
8587 struct dwarf2_cu
*cu
= reader
->cu
;
8589 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8591 /* Check if comp unit has_children.
8592 If so, read the rest of the partial symbols from this comp unit.
8593 If not, there's no more debug_info for this comp unit. */
8595 load_partial_dies (reader
, info_ptr
, 0);
8598 /* Load the partial DIEs for a secondary CU into memory.
8599 This is also used when rereading a primary CU with load_all_dies. */
8602 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8604 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8605 load_partial_comp_unit_reader
, NULL
);
8609 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8610 struct dwarf2_section_info
*section
,
8611 struct dwarf2_section_info
*abbrev_section
,
8612 unsigned int is_dwz
)
8614 const gdb_byte
*info_ptr
;
8615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8617 if (dwarf_read_debug
)
8618 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8619 get_section_name (section
),
8620 get_section_file_name (section
));
8622 dwarf2_read_section (objfile
, section
);
8624 info_ptr
= section
->buffer
;
8626 while (info_ptr
< section
->buffer
+ section
->size
)
8628 struct dwarf2_per_cu_data
*this_cu
;
8630 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8632 comp_unit_head cu_header
;
8633 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8634 abbrev_section
, info_ptr
,
8635 rcuh_kind::COMPILE
);
8637 /* Save the compilation unit for later lookup. */
8638 if (cu_header
.unit_type
!= DW_UT_type
)
8640 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8641 struct dwarf2_per_cu_data
);
8642 memset (this_cu
, 0, sizeof (*this_cu
));
8646 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8647 struct signatured_type
);
8648 memset (sig_type
, 0, sizeof (*sig_type
));
8649 sig_type
->signature
= cu_header
.signature
;
8650 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8651 this_cu
= &sig_type
->per_cu
;
8653 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8654 this_cu
->sect_off
= sect_off
;
8655 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8656 this_cu
->is_dwz
= is_dwz
;
8657 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8658 this_cu
->section
= section
;
8660 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8662 info_ptr
= info_ptr
+ this_cu
->length
;
8666 /* Create a list of all compilation units in OBJFILE.
8667 This is only done for -readnow and building partial symtabs. */
8670 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8672 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8673 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8674 &dwarf2_per_objfile
->abbrev
, 0);
8676 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8678 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8682 /* Process all loaded DIEs for compilation unit CU, starting at
8683 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8684 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8685 DW_AT_ranges). See the comments of add_partial_subprogram on how
8686 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8689 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8690 CORE_ADDR
*highpc
, int set_addrmap
,
8691 struct dwarf2_cu
*cu
)
8693 struct partial_die_info
*pdi
;
8695 /* Now, march along the PDI's, descending into ones which have
8696 interesting children but skipping the children of the other ones,
8697 until we reach the end of the compilation unit. */
8705 /* Anonymous namespaces or modules have no name but have interesting
8706 children, so we need to look at them. Ditto for anonymous
8709 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8710 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8711 || pdi
->tag
== DW_TAG_imported_unit
8712 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8716 case DW_TAG_subprogram
:
8717 case DW_TAG_inlined_subroutine
:
8718 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8720 case DW_TAG_constant
:
8721 case DW_TAG_variable
:
8722 case DW_TAG_typedef
:
8723 case DW_TAG_union_type
:
8724 if (!pdi
->is_declaration
)
8726 add_partial_symbol (pdi
, cu
);
8729 case DW_TAG_class_type
:
8730 case DW_TAG_interface_type
:
8731 case DW_TAG_structure_type
:
8732 if (!pdi
->is_declaration
)
8734 add_partial_symbol (pdi
, cu
);
8736 if ((cu
->language
== language_rust
8737 || cu
->language
== language_cplus
) && pdi
->has_children
)
8738 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8741 case DW_TAG_enumeration_type
:
8742 if (!pdi
->is_declaration
)
8743 add_partial_enumeration (pdi
, cu
);
8745 case DW_TAG_base_type
:
8746 case DW_TAG_subrange_type
:
8747 /* File scope base type definitions are added to the partial
8749 add_partial_symbol (pdi
, cu
);
8751 case DW_TAG_namespace
:
8752 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8755 if (!pdi
->is_declaration
)
8756 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8758 case DW_TAG_imported_unit
:
8760 struct dwarf2_per_cu_data
*per_cu
;
8762 /* For now we don't handle imported units in type units. */
8763 if (cu
->per_cu
->is_debug_types
)
8765 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8766 " supported in type units [in module %s]"),
8767 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8770 per_cu
= dwarf2_find_containing_comp_unit
8771 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8772 cu
->per_cu
->dwarf2_per_objfile
);
8774 /* Go read the partial unit, if needed. */
8775 if (per_cu
->v
.psymtab
== NULL
)
8776 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8778 cu
->per_cu
->imported_symtabs_push (per_cu
);
8781 case DW_TAG_imported_declaration
:
8782 add_partial_symbol (pdi
, cu
);
8789 /* If the die has a sibling, skip to the sibling. */
8791 pdi
= pdi
->die_sibling
;
8795 /* Functions used to compute the fully scoped name of a partial DIE.
8797 Normally, this is simple. For C++, the parent DIE's fully scoped
8798 name is concatenated with "::" and the partial DIE's name.
8799 Enumerators are an exception; they use the scope of their parent
8800 enumeration type, i.e. the name of the enumeration type is not
8801 prepended to the enumerator.
8803 There are two complexities. One is DW_AT_specification; in this
8804 case "parent" means the parent of the target of the specification,
8805 instead of the direct parent of the DIE. The other is compilers
8806 which do not emit DW_TAG_namespace; in this case we try to guess
8807 the fully qualified name of structure types from their members'
8808 linkage names. This must be done using the DIE's children rather
8809 than the children of any DW_AT_specification target. We only need
8810 to do this for structures at the top level, i.e. if the target of
8811 any DW_AT_specification (if any; otherwise the DIE itself) does not
8814 /* Compute the scope prefix associated with PDI's parent, in
8815 compilation unit CU. The result will be allocated on CU's
8816 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8817 field. NULL is returned if no prefix is necessary. */
8819 partial_die_parent_scope (struct partial_die_info
*pdi
,
8820 struct dwarf2_cu
*cu
)
8822 const char *grandparent_scope
;
8823 struct partial_die_info
*parent
, *real_pdi
;
8825 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8826 then this means the parent of the specification DIE. */
8829 while (real_pdi
->has_specification
)
8831 auto res
= find_partial_die (real_pdi
->spec_offset
,
8832 real_pdi
->spec_is_dwz
, cu
);
8837 parent
= real_pdi
->die_parent
;
8841 if (parent
->scope_set
)
8842 return parent
->scope
;
8846 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8848 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8849 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8850 Work around this problem here. */
8851 if (cu
->language
== language_cplus
8852 && parent
->tag
== DW_TAG_namespace
8853 && strcmp (parent
->name
, "::") == 0
8854 && grandparent_scope
== NULL
)
8856 parent
->scope
= NULL
;
8857 parent
->scope_set
= 1;
8861 /* Nested subroutines in Fortran get a prefix. */
8862 if (pdi
->tag
== DW_TAG_enumerator
)
8863 /* Enumerators should not get the name of the enumeration as a prefix. */
8864 parent
->scope
= grandparent_scope
;
8865 else if (parent
->tag
== DW_TAG_namespace
8866 || parent
->tag
== DW_TAG_module
8867 || parent
->tag
== DW_TAG_structure_type
8868 || parent
->tag
== DW_TAG_class_type
8869 || parent
->tag
== DW_TAG_interface_type
8870 || parent
->tag
== DW_TAG_union_type
8871 || parent
->tag
== DW_TAG_enumeration_type
8872 || (cu
->language
== language_fortran
8873 && parent
->tag
== DW_TAG_subprogram
8874 && pdi
->tag
== DW_TAG_subprogram
))
8876 if (grandparent_scope
== NULL
)
8877 parent
->scope
= parent
->name
;
8879 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8881 parent
->name
, 0, cu
);
8885 /* FIXME drow/2004-04-01: What should we be doing with
8886 function-local names? For partial symbols, we should probably be
8888 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8889 dwarf_tag_name (parent
->tag
),
8890 sect_offset_str (pdi
->sect_off
));
8891 parent
->scope
= grandparent_scope
;
8894 parent
->scope_set
= 1;
8895 return parent
->scope
;
8898 /* Return the fully scoped name associated with PDI, from compilation unit
8899 CU. The result will be allocated with malloc. */
8901 static gdb::unique_xmalloc_ptr
<char>
8902 partial_die_full_name (struct partial_die_info
*pdi
,
8903 struct dwarf2_cu
*cu
)
8905 const char *parent_scope
;
8907 /* If this is a template instantiation, we can not work out the
8908 template arguments from partial DIEs. So, unfortunately, we have
8909 to go through the full DIEs. At least any work we do building
8910 types here will be reused if full symbols are loaded later. */
8911 if (pdi
->has_template_arguments
)
8915 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8917 struct die_info
*die
;
8918 struct attribute attr
;
8919 struct dwarf2_cu
*ref_cu
= cu
;
8921 /* DW_FORM_ref_addr is using section offset. */
8922 attr
.name
= (enum dwarf_attribute
) 0;
8923 attr
.form
= DW_FORM_ref_addr
;
8924 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8925 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8927 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8931 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8932 if (parent_scope
== NULL
)
8935 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8940 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8942 struct dwarf2_per_objfile
*dwarf2_per_objfile
8943 = cu
->per_cu
->dwarf2_per_objfile
;
8944 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8945 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8947 const char *actual_name
= NULL
;
8950 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8952 gdb::unique_xmalloc_ptr
<char> built_actual_name
8953 = partial_die_full_name (pdi
, cu
);
8954 if (built_actual_name
!= NULL
)
8955 actual_name
= built_actual_name
.get ();
8957 if (actual_name
== NULL
)
8958 actual_name
= pdi
->name
;
8962 case DW_TAG_inlined_subroutine
:
8963 case DW_TAG_subprogram
:
8964 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8966 if (pdi
->is_external
8967 || cu
->language
== language_ada
8968 || (cu
->language
== language_fortran
8969 && pdi
->die_parent
!= NULL
8970 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8972 /* Normally, only "external" DIEs are part of the global scope.
8973 But in Ada and Fortran, we want to be able to access nested
8974 procedures globally. So all Ada and Fortran subprograms are
8975 stored in the global scope. */
8976 add_psymbol_to_list (actual_name
,
8977 built_actual_name
!= NULL
,
8978 VAR_DOMAIN
, LOC_BLOCK
,
8979 SECT_OFF_TEXT (objfile
),
8980 psymbol_placement::GLOBAL
,
8982 cu
->language
, objfile
);
8986 add_psymbol_to_list (actual_name
,
8987 built_actual_name
!= NULL
,
8988 VAR_DOMAIN
, LOC_BLOCK
,
8989 SECT_OFF_TEXT (objfile
),
8990 psymbol_placement::STATIC
,
8991 addr
, cu
->language
, objfile
);
8994 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8995 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8997 case DW_TAG_constant
:
8998 add_psymbol_to_list (actual_name
,
8999 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9000 -1, (pdi
->is_external
9001 ? psymbol_placement::GLOBAL
9002 : psymbol_placement::STATIC
),
9003 0, cu
->language
, objfile
);
9005 case DW_TAG_variable
:
9007 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9011 && !dwarf2_per_objfile
->has_section_at_zero
)
9013 /* A global or static variable may also have been stripped
9014 out by the linker if unused, in which case its address
9015 will be nullified; do not add such variables into partial
9016 symbol table then. */
9018 else if (pdi
->is_external
)
9021 Don't enter into the minimal symbol tables as there is
9022 a minimal symbol table entry from the ELF symbols already.
9023 Enter into partial symbol table if it has a location
9024 descriptor or a type.
9025 If the location descriptor is missing, new_symbol will create
9026 a LOC_UNRESOLVED symbol, the address of the variable will then
9027 be determined from the minimal symbol table whenever the variable
9029 The address for the partial symbol table entry is not
9030 used by GDB, but it comes in handy for debugging partial symbol
9033 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9034 add_psymbol_to_list (actual_name
,
9035 built_actual_name
!= NULL
,
9036 VAR_DOMAIN
, LOC_STATIC
,
9037 SECT_OFF_TEXT (objfile
),
9038 psymbol_placement::GLOBAL
,
9039 addr
, cu
->language
, objfile
);
9043 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9045 /* Static Variable. Skip symbols whose value we cannot know (those
9046 without location descriptors or constant values). */
9047 if (!has_loc
&& !pdi
->has_const_value
)
9050 add_psymbol_to_list (actual_name
,
9051 built_actual_name
!= NULL
,
9052 VAR_DOMAIN
, LOC_STATIC
,
9053 SECT_OFF_TEXT (objfile
),
9054 psymbol_placement::STATIC
,
9056 cu
->language
, objfile
);
9059 case DW_TAG_typedef
:
9060 case DW_TAG_base_type
:
9061 case DW_TAG_subrange_type
:
9062 add_psymbol_to_list (actual_name
,
9063 built_actual_name
!= NULL
,
9064 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9065 psymbol_placement::STATIC
,
9066 0, cu
->language
, objfile
);
9068 case DW_TAG_imported_declaration
:
9069 case DW_TAG_namespace
:
9070 add_psymbol_to_list (actual_name
,
9071 built_actual_name
!= NULL
,
9072 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9073 psymbol_placement::GLOBAL
,
9074 0, cu
->language
, objfile
);
9077 /* With Fortran 77 there might be a "BLOCK DATA" module
9078 available without any name. If so, we skip the module as it
9079 doesn't bring any value. */
9080 if (actual_name
!= nullptr)
9081 add_psymbol_to_list (actual_name
,
9082 built_actual_name
!= NULL
,
9083 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9084 psymbol_placement::GLOBAL
,
9085 0, cu
->language
, objfile
);
9087 case DW_TAG_class_type
:
9088 case DW_TAG_interface_type
:
9089 case DW_TAG_structure_type
:
9090 case DW_TAG_union_type
:
9091 case DW_TAG_enumeration_type
:
9092 /* Skip external references. The DWARF standard says in the section
9093 about "Structure, Union, and Class Type Entries": "An incomplete
9094 structure, union or class type is represented by a structure,
9095 union or class entry that does not have a byte size attribute
9096 and that has a DW_AT_declaration attribute." */
9097 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9100 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9101 static vs. global. */
9102 add_psymbol_to_list (actual_name
,
9103 built_actual_name
!= NULL
,
9104 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9105 cu
->language
== language_cplus
9106 ? psymbol_placement::GLOBAL
9107 : psymbol_placement::STATIC
,
9108 0, cu
->language
, objfile
);
9111 case DW_TAG_enumerator
:
9112 add_psymbol_to_list (actual_name
,
9113 built_actual_name
!= NULL
,
9114 VAR_DOMAIN
, LOC_CONST
, -1,
9115 cu
->language
== language_cplus
9116 ? psymbol_placement::GLOBAL
9117 : psymbol_placement::STATIC
,
9118 0, cu
->language
, objfile
);
9125 /* Read a partial die corresponding to a namespace; also, add a symbol
9126 corresponding to that namespace to the symbol table. NAMESPACE is
9127 the name of the enclosing namespace. */
9130 add_partial_namespace (struct partial_die_info
*pdi
,
9131 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9132 int set_addrmap
, struct dwarf2_cu
*cu
)
9134 /* Add a symbol for the namespace. */
9136 add_partial_symbol (pdi
, cu
);
9138 /* Now scan partial symbols in that namespace. */
9140 if (pdi
->has_children
)
9141 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9144 /* Read a partial die corresponding to a Fortran module. */
9147 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9148 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9150 /* Add a symbol for the namespace. */
9152 add_partial_symbol (pdi
, cu
);
9154 /* Now scan partial symbols in that module. */
9156 if (pdi
->has_children
)
9157 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9160 /* Read a partial die corresponding to a subprogram or an inlined
9161 subprogram and create a partial symbol for that subprogram.
9162 When the CU language allows it, this routine also defines a partial
9163 symbol for each nested subprogram that this subprogram contains.
9164 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9165 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9167 PDI may also be a lexical block, in which case we simply search
9168 recursively for subprograms defined inside that lexical block.
9169 Again, this is only performed when the CU language allows this
9170 type of definitions. */
9173 add_partial_subprogram (struct partial_die_info
*pdi
,
9174 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9175 int set_addrmap
, struct dwarf2_cu
*cu
)
9177 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9179 if (pdi
->has_pc_info
)
9181 if (pdi
->lowpc
< *lowpc
)
9182 *lowpc
= pdi
->lowpc
;
9183 if (pdi
->highpc
> *highpc
)
9184 *highpc
= pdi
->highpc
;
9187 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9188 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9190 CORE_ADDR this_highpc
;
9191 CORE_ADDR this_lowpc
;
9193 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9194 SECT_OFF_TEXT (objfile
));
9196 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9197 pdi
->lowpc
+ baseaddr
)
9200 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9201 pdi
->highpc
+ baseaddr
)
9203 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9204 this_lowpc
, this_highpc
- 1,
9205 cu
->per_cu
->v
.psymtab
);
9209 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9211 if (!pdi
->is_declaration
)
9212 /* Ignore subprogram DIEs that do not have a name, they are
9213 illegal. Do not emit a complaint at this point, we will
9214 do so when we convert this psymtab into a symtab. */
9216 add_partial_symbol (pdi
, cu
);
9220 if (! pdi
->has_children
)
9223 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9225 pdi
= pdi
->die_child
;
9229 if (pdi
->tag
== DW_TAG_subprogram
9230 || pdi
->tag
== DW_TAG_inlined_subroutine
9231 || pdi
->tag
== DW_TAG_lexical_block
)
9232 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9233 pdi
= pdi
->die_sibling
;
9238 /* Read a partial die corresponding to an enumeration type. */
9241 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9242 struct dwarf2_cu
*cu
)
9244 struct partial_die_info
*pdi
;
9246 if (enum_pdi
->name
!= NULL
)
9247 add_partial_symbol (enum_pdi
, cu
);
9249 pdi
= enum_pdi
->die_child
;
9252 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9253 complaint (_("malformed enumerator DIE ignored"));
9255 add_partial_symbol (pdi
, cu
);
9256 pdi
= pdi
->die_sibling
;
9260 /* Return the initial uleb128 in the die at INFO_PTR. */
9263 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9265 unsigned int bytes_read
;
9267 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9270 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9271 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9273 Return the corresponding abbrev, or NULL if the number is zero (indicating
9274 an empty DIE). In either case *BYTES_READ will be set to the length of
9275 the initial number. */
9277 static struct abbrev_info
*
9278 peek_die_abbrev (const die_reader_specs
&reader
,
9279 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9281 dwarf2_cu
*cu
= reader
.cu
;
9282 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9283 unsigned int abbrev_number
9284 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9286 if (abbrev_number
== 0)
9289 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9292 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9293 " at offset %s [in module %s]"),
9294 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9295 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9301 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9302 Returns a pointer to the end of a series of DIEs, terminated by an empty
9303 DIE. Any children of the skipped DIEs will also be skipped. */
9305 static const gdb_byte
*
9306 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9310 unsigned int bytes_read
;
9311 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9314 return info_ptr
+ bytes_read
;
9316 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9320 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9321 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9322 abbrev corresponding to that skipped uleb128 should be passed in
9323 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9326 static const gdb_byte
*
9327 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9328 struct abbrev_info
*abbrev
)
9330 unsigned int bytes_read
;
9331 struct attribute attr
;
9332 bfd
*abfd
= reader
->abfd
;
9333 struct dwarf2_cu
*cu
= reader
->cu
;
9334 const gdb_byte
*buffer
= reader
->buffer
;
9335 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9336 unsigned int form
, i
;
9338 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9340 /* The only abbrev we care about is DW_AT_sibling. */
9341 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9343 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9344 if (attr
.form
== DW_FORM_ref_addr
)
9345 complaint (_("ignoring absolute DW_AT_sibling"));
9348 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9349 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9351 if (sibling_ptr
< info_ptr
)
9352 complaint (_("DW_AT_sibling points backwards"));
9353 else if (sibling_ptr
> reader
->buffer_end
)
9354 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9360 /* If it isn't DW_AT_sibling, skip this attribute. */
9361 form
= abbrev
->attrs
[i
].form
;
9365 case DW_FORM_ref_addr
:
9366 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9367 and later it is offset sized. */
9368 if (cu
->header
.version
== 2)
9369 info_ptr
+= cu
->header
.addr_size
;
9371 info_ptr
+= cu
->header
.offset_size
;
9373 case DW_FORM_GNU_ref_alt
:
9374 info_ptr
+= cu
->header
.offset_size
;
9377 info_ptr
+= cu
->header
.addr_size
;
9385 case DW_FORM_flag_present
:
9386 case DW_FORM_implicit_const
:
9403 case DW_FORM_ref_sig8
:
9406 case DW_FORM_data16
:
9409 case DW_FORM_string
:
9410 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9411 info_ptr
+= bytes_read
;
9413 case DW_FORM_sec_offset
:
9415 case DW_FORM_GNU_strp_alt
:
9416 info_ptr
+= cu
->header
.offset_size
;
9418 case DW_FORM_exprloc
:
9420 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9421 info_ptr
+= bytes_read
;
9423 case DW_FORM_block1
:
9424 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9426 case DW_FORM_block2
:
9427 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9429 case DW_FORM_block4
:
9430 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9436 case DW_FORM_ref_udata
:
9437 case DW_FORM_GNU_addr_index
:
9438 case DW_FORM_GNU_str_index
:
9439 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9441 case DW_FORM_indirect
:
9442 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9443 info_ptr
+= bytes_read
;
9444 /* We need to continue parsing from here, so just go back to
9446 goto skip_attribute
;
9449 error (_("Dwarf Error: Cannot handle %s "
9450 "in DWARF reader [in module %s]"),
9451 dwarf_form_name (form
),
9452 bfd_get_filename (abfd
));
9456 if (abbrev
->has_children
)
9457 return skip_children (reader
, info_ptr
);
9462 /* Locate ORIG_PDI's sibling.
9463 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9465 static const gdb_byte
*
9466 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9467 struct partial_die_info
*orig_pdi
,
9468 const gdb_byte
*info_ptr
)
9470 /* Do we know the sibling already? */
9472 if (orig_pdi
->sibling
)
9473 return orig_pdi
->sibling
;
9475 /* Are there any children to deal with? */
9477 if (!orig_pdi
->has_children
)
9480 /* Skip the children the long way. */
9482 return skip_children (reader
, info_ptr
);
9485 /* Expand this partial symbol table into a full symbol table. SELF is
9489 dwarf2_read_symtab (struct partial_symtab
*self
,
9490 struct objfile
*objfile
)
9492 struct dwarf2_per_objfile
*dwarf2_per_objfile
9493 = get_dwarf2_per_objfile (objfile
);
9497 warning (_("bug: psymtab for %s is already read in."),
9504 printf_filtered (_("Reading in symbols for %s..."),
9506 gdb_flush (gdb_stdout
);
9509 /* If this psymtab is constructed from a debug-only objfile, the
9510 has_section_at_zero flag will not necessarily be correct. We
9511 can get the correct value for this flag by looking at the data
9512 associated with the (presumably stripped) associated objfile. */
9513 if (objfile
->separate_debug_objfile_backlink
)
9515 struct dwarf2_per_objfile
*dpo_backlink
9516 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9518 dwarf2_per_objfile
->has_section_at_zero
9519 = dpo_backlink
->has_section_at_zero
;
9522 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9524 psymtab_to_symtab_1 (self
);
9526 /* Finish up the debug error message. */
9528 printf_filtered (_("done.\n"));
9531 process_cu_includes (dwarf2_per_objfile
);
9534 /* Reading in full CUs. */
9536 /* Add PER_CU to the queue. */
9539 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9540 enum language pretend_language
)
9542 struct dwarf2_queue_item
*item
;
9545 item
= XNEW (struct dwarf2_queue_item
);
9546 item
->per_cu
= per_cu
;
9547 item
->pretend_language
= pretend_language
;
9550 if (dwarf2_queue
== NULL
)
9551 dwarf2_queue
= item
;
9553 dwarf2_queue_tail
->next
= item
;
9555 dwarf2_queue_tail
= item
;
9558 /* If PER_CU is not yet queued, add it to the queue.
9559 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9561 The result is non-zero if PER_CU was queued, otherwise the result is zero
9562 meaning either PER_CU is already queued or it is already loaded.
9564 N.B. There is an invariant here that if a CU is queued then it is loaded.
9565 The caller is required to load PER_CU if we return non-zero. */
9568 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9569 struct dwarf2_per_cu_data
*per_cu
,
9570 enum language pretend_language
)
9572 /* We may arrive here during partial symbol reading, if we need full
9573 DIEs to process an unusual case (e.g. template arguments). Do
9574 not queue PER_CU, just tell our caller to load its DIEs. */
9575 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9577 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9582 /* Mark the dependence relation so that we don't flush PER_CU
9584 if (dependent_cu
!= NULL
)
9585 dwarf2_add_dependence (dependent_cu
, per_cu
);
9587 /* If it's already on the queue, we have nothing to do. */
9591 /* If the compilation unit is already loaded, just mark it as
9593 if (per_cu
->cu
!= NULL
)
9595 per_cu
->cu
->last_used
= 0;
9599 /* Add it to the queue. */
9600 queue_comp_unit (per_cu
, pretend_language
);
9605 /* Process the queue. */
9608 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9610 struct dwarf2_queue_item
*item
, *next_item
;
9612 if (dwarf_read_debug
)
9614 fprintf_unfiltered (gdb_stdlog
,
9615 "Expanding one or more symtabs of objfile %s ...\n",
9616 objfile_name (dwarf2_per_objfile
->objfile
));
9619 /* The queue starts out with one item, but following a DIE reference
9620 may load a new CU, adding it to the end of the queue. */
9621 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9623 if ((dwarf2_per_objfile
->using_index
9624 ? !item
->per_cu
->v
.quick
->compunit_symtab
9625 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9626 /* Skip dummy CUs. */
9627 && item
->per_cu
->cu
!= NULL
)
9629 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9630 unsigned int debug_print_threshold
;
9633 if (per_cu
->is_debug_types
)
9635 struct signatured_type
*sig_type
=
9636 (struct signatured_type
*) per_cu
;
9638 sprintf (buf
, "TU %s at offset %s",
9639 hex_string (sig_type
->signature
),
9640 sect_offset_str (per_cu
->sect_off
));
9641 /* There can be 100s of TUs.
9642 Only print them in verbose mode. */
9643 debug_print_threshold
= 2;
9647 sprintf (buf
, "CU at offset %s",
9648 sect_offset_str (per_cu
->sect_off
));
9649 debug_print_threshold
= 1;
9652 if (dwarf_read_debug
>= debug_print_threshold
)
9653 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9655 if (per_cu
->is_debug_types
)
9656 process_full_type_unit (per_cu
, item
->pretend_language
);
9658 process_full_comp_unit (per_cu
, item
->pretend_language
);
9660 if (dwarf_read_debug
>= debug_print_threshold
)
9661 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9664 item
->per_cu
->queued
= 0;
9665 next_item
= item
->next
;
9669 dwarf2_queue_tail
= NULL
;
9671 if (dwarf_read_debug
)
9673 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9674 objfile_name (dwarf2_per_objfile
->objfile
));
9678 /* Read in full symbols for PST, and anything it depends on. */
9681 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9683 struct dwarf2_per_cu_data
*per_cu
;
9689 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9690 if (!pst
->dependencies
[i
]->readin
9691 && pst
->dependencies
[i
]->user
== NULL
)
9693 /* Inform about additional files that need to be read in. */
9696 /* FIXME: i18n: Need to make this a single string. */
9697 fputs_filtered (" ", gdb_stdout
);
9699 fputs_filtered ("and ", gdb_stdout
);
9701 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9702 wrap_here (""); /* Flush output. */
9703 gdb_flush (gdb_stdout
);
9705 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9708 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9712 /* It's an include file, no symbols to read for it.
9713 Everything is in the parent symtab. */
9718 dw2_do_instantiate_symtab (per_cu
, false);
9721 /* Trivial hash function for die_info: the hash value of a DIE
9722 is its offset in .debug_info for this objfile. */
9725 die_hash (const void *item
)
9727 const struct die_info
*die
= (const struct die_info
*) item
;
9729 return to_underlying (die
->sect_off
);
9732 /* Trivial comparison function for die_info structures: two DIEs
9733 are equal if they have the same offset. */
9736 die_eq (const void *item_lhs
, const void *item_rhs
)
9738 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9739 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9741 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9744 /* die_reader_func for load_full_comp_unit.
9745 This is identical to read_signatured_type_reader,
9746 but is kept separate for now. */
9749 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9750 const gdb_byte
*info_ptr
,
9751 struct die_info
*comp_unit_die
,
9755 struct dwarf2_cu
*cu
= reader
->cu
;
9756 enum language
*language_ptr
= (enum language
*) data
;
9758 gdb_assert (cu
->die_hash
== NULL
);
9760 htab_create_alloc_ex (cu
->header
.length
/ 12,
9764 &cu
->comp_unit_obstack
,
9765 hashtab_obstack_allocate
,
9766 dummy_obstack_deallocate
);
9769 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9770 &info_ptr
, comp_unit_die
);
9771 cu
->dies
= comp_unit_die
;
9772 /* comp_unit_die is not stored in die_hash, no need. */
9774 /* We try not to read any attributes in this function, because not
9775 all CUs needed for references have been loaded yet, and symbol
9776 table processing isn't initialized. But we have to set the CU language,
9777 or we won't be able to build types correctly.
9778 Similarly, if we do not read the producer, we can not apply
9779 producer-specific interpretation. */
9780 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9783 /* Load the DIEs associated with PER_CU into memory. */
9786 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9788 enum language pretend_language
)
9790 gdb_assert (! this_cu
->is_debug_types
);
9792 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9793 load_full_comp_unit_reader
, &pretend_language
);
9796 /* Add a DIE to the delayed physname list. */
9799 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9800 const char *name
, struct die_info
*die
,
9801 struct dwarf2_cu
*cu
)
9803 struct delayed_method_info mi
;
9805 mi
.fnfield_index
= fnfield_index
;
9809 cu
->method_list
.push_back (mi
);
9812 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9813 "const" / "volatile". If so, decrements LEN by the length of the
9814 modifier and return true. Otherwise return false. */
9818 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9820 size_t mod_len
= sizeof (mod
) - 1;
9821 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9829 /* Compute the physnames of any methods on the CU's method list.
9831 The computation of method physnames is delayed in order to avoid the
9832 (bad) condition that one of the method's formal parameters is of an as yet
9836 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9838 /* Only C++ delays computing physnames. */
9839 if (cu
->method_list
.empty ())
9841 gdb_assert (cu
->language
== language_cplus
);
9843 for (const delayed_method_info
&mi
: cu
->method_list
)
9845 const char *physname
;
9846 struct fn_fieldlist
*fn_flp
9847 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9848 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9849 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9850 = physname
? physname
: "";
9852 /* Since there's no tag to indicate whether a method is a
9853 const/volatile overload, extract that information out of the
9855 if (physname
!= NULL
)
9857 size_t len
= strlen (physname
);
9861 if (physname
[len
] == ')') /* shortcut */
9863 else if (check_modifier (physname
, len
, " const"))
9864 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9865 else if (check_modifier (physname
, len
, " volatile"))
9866 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9873 /* The list is no longer needed. */
9874 cu
->method_list
.clear ();
9877 /* Go objects should be embedded in a DW_TAG_module DIE,
9878 and it's not clear if/how imported objects will appear.
9879 To keep Go support simple until that's worked out,
9880 go back through what we've read and create something usable.
9881 We could do this while processing each DIE, and feels kinda cleaner,
9882 but that way is more invasive.
9883 This is to, for example, allow the user to type "p var" or "b main"
9884 without having to specify the package name, and allow lookups
9885 of module.object to work in contexts that use the expression
9889 fixup_go_packaging (struct dwarf2_cu
*cu
)
9891 gdb::unique_xmalloc_ptr
<char> package_name
;
9892 struct pending
*list
;
9895 for (list
= *cu
->get_builder ()->get_global_symbols ();
9899 for (i
= 0; i
< list
->nsyms
; ++i
)
9901 struct symbol
*sym
= list
->symbol
[i
];
9903 if (sym
->language () == language_go
9904 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9906 gdb::unique_xmalloc_ptr
<char> this_package_name
9907 (go_symbol_package_name (sym
));
9909 if (this_package_name
== NULL
)
9911 if (package_name
== NULL
)
9912 package_name
= std::move (this_package_name
);
9915 struct objfile
*objfile
9916 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9917 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9918 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9919 (symbol_symtab (sym
) != NULL
9920 ? symtab_to_filename_for_display
9921 (symbol_symtab (sym
))
9922 : objfile_name (objfile
)),
9923 this_package_name
.get (), package_name
.get ());
9929 if (package_name
!= NULL
)
9931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9932 const char *saved_package_name
9933 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9934 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9935 saved_package_name
);
9938 sym
= allocate_symbol (objfile
);
9939 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9940 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9941 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9942 e.g., "main" finds the "main" module and not C's main(). */
9943 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9944 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9945 SYMBOL_TYPE (sym
) = type
;
9947 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9951 /* Allocate a fully-qualified name consisting of the two parts on the
9955 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9957 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9960 /* A helper that allocates a struct discriminant_info to attach to a
9963 static struct discriminant_info
*
9964 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9967 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9968 gdb_assert (discriminant_index
== -1
9969 || (discriminant_index
>= 0
9970 && discriminant_index
< TYPE_NFIELDS (type
)));
9971 gdb_assert (default_index
== -1
9972 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9974 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9976 struct discriminant_info
*disc
9977 = ((struct discriminant_info
*)
9979 offsetof (struct discriminant_info
, discriminants
)
9980 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9981 disc
->default_index
= default_index
;
9982 disc
->discriminant_index
= discriminant_index
;
9984 struct dynamic_prop prop
;
9985 prop
.kind
= PROP_UNDEFINED
;
9986 prop
.data
.baton
= disc
;
9988 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9993 /* Some versions of rustc emitted enums in an unusual way.
9995 Ordinary enums were emitted as unions. The first element of each
9996 structure in the union was named "RUST$ENUM$DISR". This element
9997 held the discriminant.
9999 These versions of Rust also implemented the "non-zero"
10000 optimization. When the enum had two values, and one is empty and
10001 the other holds a pointer that cannot be zero, the pointer is used
10002 as the discriminant, with a zero value meaning the empty variant.
10003 Here, the union's first member is of the form
10004 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10005 where the fieldnos are the indices of the fields that should be
10006 traversed in order to find the field (which may be several fields deep)
10007 and the variantname is the name of the variant of the case when the
10010 This function recognizes whether TYPE is of one of these forms,
10011 and, if so, smashes it to be a variant type. */
10014 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10016 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10018 /* We don't need to deal with empty enums. */
10019 if (TYPE_NFIELDS (type
) == 0)
10022 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10023 if (TYPE_NFIELDS (type
) == 1
10024 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10026 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10028 /* Decode the field name to find the offset of the
10030 ULONGEST bit_offset
= 0;
10031 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10032 while (name
[0] >= '0' && name
[0] <= '9')
10035 unsigned long index
= strtoul (name
, &tail
, 10);
10038 || index
>= TYPE_NFIELDS (field_type
)
10039 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10040 != FIELD_LOC_KIND_BITPOS
))
10042 complaint (_("Could not parse Rust enum encoding string \"%s\""
10044 TYPE_FIELD_NAME (type
, 0),
10045 objfile_name (objfile
));
10050 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10051 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10054 /* Make a union to hold the variants. */
10055 struct type
*union_type
= alloc_type (objfile
);
10056 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10057 TYPE_NFIELDS (union_type
) = 3;
10058 TYPE_FIELDS (union_type
)
10059 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10060 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10061 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10063 /* Put the discriminant must at index 0. */
10064 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10065 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10066 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10067 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10069 /* The order of fields doesn't really matter, so put the real
10070 field at index 1 and the data-less field at index 2. */
10071 struct discriminant_info
*disc
10072 = alloc_discriminant_info (union_type
, 0, 1);
10073 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10074 TYPE_FIELD_NAME (union_type
, 1)
10075 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10076 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10077 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10078 TYPE_FIELD_NAME (union_type
, 1));
10080 const char *dataless_name
10081 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10083 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10085 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10086 /* NAME points into the original discriminant name, which
10087 already has the correct lifetime. */
10088 TYPE_FIELD_NAME (union_type
, 2) = name
;
10089 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10090 disc
->discriminants
[2] = 0;
10092 /* Smash this type to be a structure type. We have to do this
10093 because the type has already been recorded. */
10094 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10095 TYPE_NFIELDS (type
) = 1;
10097 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10099 /* Install the variant part. */
10100 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10101 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10102 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10104 /* A union with a single anonymous field is probably an old-style
10105 univariant enum. */
10106 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10108 /* Smash this type to be a structure type. We have to do this
10109 because the type has already been recorded. */
10110 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10112 /* Make a union to hold the variants. */
10113 struct type
*union_type
= alloc_type (objfile
);
10114 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10115 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10116 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10117 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10118 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10120 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10121 const char *variant_name
10122 = rust_last_path_segment (TYPE_NAME (field_type
));
10123 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10124 TYPE_NAME (field_type
)
10125 = rust_fully_qualify (&objfile
->objfile_obstack
,
10126 TYPE_NAME (type
), variant_name
);
10128 /* Install the union in the outer struct type. */
10129 TYPE_NFIELDS (type
) = 1;
10131 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10132 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10133 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10134 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10136 alloc_discriminant_info (union_type
, -1, 0);
10140 struct type
*disr_type
= nullptr;
10141 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10143 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10145 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10147 /* All fields of a true enum will be structs. */
10150 else if (TYPE_NFIELDS (disr_type
) == 0)
10152 /* Could be data-less variant, so keep going. */
10153 disr_type
= nullptr;
10155 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10156 "RUST$ENUM$DISR") != 0)
10158 /* Not a Rust enum. */
10168 /* If we got here without a discriminant, then it's probably
10170 if (disr_type
== nullptr)
10173 /* Smash this type to be a structure type. We have to do this
10174 because the type has already been recorded. */
10175 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10177 /* Make a union to hold the variants. */
10178 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10179 struct type
*union_type
= alloc_type (objfile
);
10180 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10181 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10182 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10183 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10184 TYPE_FIELDS (union_type
)
10185 = (struct field
*) TYPE_ZALLOC (union_type
,
10186 (TYPE_NFIELDS (union_type
)
10187 * sizeof (struct field
)));
10189 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10190 TYPE_NFIELDS (type
) * sizeof (struct field
));
10192 /* Install the discriminant at index 0 in the union. */
10193 TYPE_FIELD (union_type
, 0) = *disr_field
;
10194 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10195 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10197 /* Install the union in the outer struct type. */
10198 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10199 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10200 TYPE_NFIELDS (type
) = 1;
10202 /* Set the size and offset of the union type. */
10203 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10205 /* We need a way to find the correct discriminant given a
10206 variant name. For convenience we build a map here. */
10207 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10208 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10209 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10211 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10214 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10215 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10219 int n_fields
= TYPE_NFIELDS (union_type
);
10220 struct discriminant_info
*disc
10221 = alloc_discriminant_info (union_type
, 0, -1);
10222 /* Skip the discriminant here. */
10223 for (int i
= 1; i
< n_fields
; ++i
)
10225 /* Find the final word in the name of this variant's type.
10226 That name can be used to look up the correct
10228 const char *variant_name
10229 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10232 auto iter
= discriminant_map
.find (variant_name
);
10233 if (iter
!= discriminant_map
.end ())
10234 disc
->discriminants
[i
] = iter
->second
;
10236 /* Remove the discriminant field, if it exists. */
10237 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10238 if (TYPE_NFIELDS (sub_type
) > 0)
10240 --TYPE_NFIELDS (sub_type
);
10241 ++TYPE_FIELDS (sub_type
);
10243 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10244 TYPE_NAME (sub_type
)
10245 = rust_fully_qualify (&objfile
->objfile_obstack
,
10246 TYPE_NAME (type
), variant_name
);
10251 /* Rewrite some Rust unions to be structures with variants parts. */
10254 rust_union_quirks (struct dwarf2_cu
*cu
)
10256 gdb_assert (cu
->language
== language_rust
);
10257 for (type
*type_
: cu
->rust_unions
)
10258 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10259 /* We don't need this any more. */
10260 cu
->rust_unions
.clear ();
10263 /* Return the symtab for PER_CU. This works properly regardless of
10264 whether we're using the index or psymtabs. */
10266 static struct compunit_symtab
*
10267 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10269 return (per_cu
->dwarf2_per_objfile
->using_index
10270 ? per_cu
->v
.quick
->compunit_symtab
10271 : per_cu
->v
.psymtab
->compunit_symtab
);
10274 /* A helper function for computing the list of all symbol tables
10275 included by PER_CU. */
10278 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10279 htab_t all_children
, htab_t all_type_symtabs
,
10280 struct dwarf2_per_cu_data
*per_cu
,
10281 struct compunit_symtab
*immediate_parent
)
10284 struct compunit_symtab
*cust
;
10286 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10289 /* This inclusion and its children have been processed. */
10294 /* Only add a CU if it has a symbol table. */
10295 cust
= get_compunit_symtab (per_cu
);
10298 /* If this is a type unit only add its symbol table if we haven't
10299 seen it yet (type unit per_cu's can share symtabs). */
10300 if (per_cu
->is_debug_types
)
10302 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10306 result
->push_back (cust
);
10307 if (cust
->user
== NULL
)
10308 cust
->user
= immediate_parent
;
10313 result
->push_back (cust
);
10314 if (cust
->user
== NULL
)
10315 cust
->user
= immediate_parent
;
10319 if (!per_cu
->imported_symtabs_empty ())
10320 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10322 recursively_compute_inclusions (result
, all_children
,
10323 all_type_symtabs
, ptr
, cust
);
10327 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10331 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10333 gdb_assert (! per_cu
->is_debug_types
);
10335 if (!per_cu
->imported_symtabs_empty ())
10338 std::vector
<compunit_symtab
*> result_symtabs
;
10339 htab_t all_children
, all_type_symtabs
;
10340 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10342 /* If we don't have a symtab, we can just skip this case. */
10346 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10347 NULL
, xcalloc
, xfree
);
10348 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10349 NULL
, xcalloc
, xfree
);
10351 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10353 recursively_compute_inclusions (&result_symtabs
, all_children
,
10354 all_type_symtabs
, ptr
, cust
);
10357 /* Now we have a transitive closure of all the included symtabs. */
10358 len
= result_symtabs
.size ();
10360 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10361 struct compunit_symtab
*, len
+ 1);
10362 memcpy (cust
->includes
, result_symtabs
.data (),
10363 len
* sizeof (compunit_symtab
*));
10364 cust
->includes
[len
] = NULL
;
10366 htab_delete (all_children
);
10367 htab_delete (all_type_symtabs
);
10371 /* Compute the 'includes' field for the symtabs of all the CUs we just
10375 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10377 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10379 if (! iter
->is_debug_types
)
10380 compute_compunit_symtab_includes (iter
);
10383 dwarf2_per_objfile
->just_read_cus
.clear ();
10386 /* Generate full symbol information for PER_CU, whose DIEs have
10387 already been loaded into memory. */
10390 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10391 enum language pretend_language
)
10393 struct dwarf2_cu
*cu
= per_cu
->cu
;
10394 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10395 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10396 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10397 CORE_ADDR lowpc
, highpc
;
10398 struct compunit_symtab
*cust
;
10399 CORE_ADDR baseaddr
;
10400 struct block
*static_block
;
10403 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10405 /* Clear the list here in case something was left over. */
10406 cu
->method_list
.clear ();
10408 cu
->language
= pretend_language
;
10409 cu
->language_defn
= language_def (cu
->language
);
10411 /* Do line number decoding in read_file_scope () */
10412 process_die (cu
->dies
, cu
);
10414 /* For now fudge the Go package. */
10415 if (cu
->language
== language_go
)
10416 fixup_go_packaging (cu
);
10418 /* Now that we have processed all the DIEs in the CU, all the types
10419 should be complete, and it should now be safe to compute all of the
10421 compute_delayed_physnames (cu
);
10423 if (cu
->language
== language_rust
)
10424 rust_union_quirks (cu
);
10426 /* Some compilers don't define a DW_AT_high_pc attribute for the
10427 compilation unit. If the DW_AT_high_pc is missing, synthesize
10428 it, by scanning the DIE's below the compilation unit. */
10429 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10431 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10432 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10434 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10435 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10436 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10437 addrmap to help ensure it has an accurate map of pc values belonging to
10439 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10441 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10442 SECT_OFF_TEXT (objfile
),
10447 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10449 /* Set symtab language to language from DW_AT_language. If the
10450 compilation is from a C file generated by language preprocessors, do
10451 not set the language if it was already deduced by start_subfile. */
10452 if (!(cu
->language
== language_c
10453 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10454 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10456 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10457 produce DW_AT_location with location lists but it can be possibly
10458 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10459 there were bugs in prologue debug info, fixed later in GCC-4.5
10460 by "unwind info for epilogues" patch (which is not directly related).
10462 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10463 needed, it would be wrong due to missing DW_AT_producer there.
10465 Still one can confuse GDB by using non-standard GCC compilation
10466 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10468 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10469 cust
->locations_valid
= 1;
10471 if (gcc_4_minor
>= 5)
10472 cust
->epilogue_unwind_valid
= 1;
10474 cust
->call_site_htab
= cu
->call_site_htab
;
10477 if (dwarf2_per_objfile
->using_index
)
10478 per_cu
->v
.quick
->compunit_symtab
= cust
;
10481 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10482 pst
->compunit_symtab
= cust
;
10486 /* Push it for inclusion processing later. */
10487 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10489 /* Not needed any more. */
10490 cu
->reset_builder ();
10493 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10494 already been loaded into memory. */
10497 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10498 enum language pretend_language
)
10500 struct dwarf2_cu
*cu
= per_cu
->cu
;
10501 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10502 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10503 struct compunit_symtab
*cust
;
10504 struct signatured_type
*sig_type
;
10506 gdb_assert (per_cu
->is_debug_types
);
10507 sig_type
= (struct signatured_type
*) per_cu
;
10509 /* Clear the list here in case something was left over. */
10510 cu
->method_list
.clear ();
10512 cu
->language
= pretend_language
;
10513 cu
->language_defn
= language_def (cu
->language
);
10515 /* The symbol tables are set up in read_type_unit_scope. */
10516 process_die (cu
->dies
, cu
);
10518 /* For now fudge the Go package. */
10519 if (cu
->language
== language_go
)
10520 fixup_go_packaging (cu
);
10522 /* Now that we have processed all the DIEs in the CU, all the types
10523 should be complete, and it should now be safe to compute all of the
10525 compute_delayed_physnames (cu
);
10527 if (cu
->language
== language_rust
)
10528 rust_union_quirks (cu
);
10530 /* TUs share symbol tables.
10531 If this is the first TU to use this symtab, complete the construction
10532 of it with end_expandable_symtab. Otherwise, complete the addition of
10533 this TU's symbols to the existing symtab. */
10534 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10536 buildsym_compunit
*builder
= cu
->get_builder ();
10537 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10538 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10542 /* Set symtab language to language from DW_AT_language. If the
10543 compilation is from a C file generated by language preprocessors,
10544 do not set the language if it was already deduced by
10546 if (!(cu
->language
== language_c
10547 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10548 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10553 cu
->get_builder ()->augment_type_symtab ();
10554 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10557 if (dwarf2_per_objfile
->using_index
)
10558 per_cu
->v
.quick
->compunit_symtab
= cust
;
10561 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10562 pst
->compunit_symtab
= cust
;
10566 /* Not needed any more. */
10567 cu
->reset_builder ();
10570 /* Process an imported unit DIE. */
10573 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10575 struct attribute
*attr
;
10577 /* For now we don't handle imported units in type units. */
10578 if (cu
->per_cu
->is_debug_types
)
10580 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10581 " supported in type units [in module %s]"),
10582 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10585 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10588 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10589 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10590 dwarf2_per_cu_data
*per_cu
10591 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10592 cu
->per_cu
->dwarf2_per_objfile
);
10594 /* If necessary, add it to the queue and load its DIEs. */
10595 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10596 load_full_comp_unit (per_cu
, false, cu
->language
);
10598 cu
->per_cu
->imported_symtabs_push (per_cu
);
10602 /* RAII object that represents a process_die scope: i.e.,
10603 starts/finishes processing a DIE. */
10604 class process_die_scope
10607 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10608 : m_die (die
), m_cu (cu
)
10610 /* We should only be processing DIEs not already in process. */
10611 gdb_assert (!m_die
->in_process
);
10612 m_die
->in_process
= true;
10615 ~process_die_scope ()
10617 m_die
->in_process
= false;
10619 /* If we're done processing the DIE for the CU that owns the line
10620 header, we don't need the line header anymore. */
10621 if (m_cu
->line_header_die_owner
== m_die
)
10623 delete m_cu
->line_header
;
10624 m_cu
->line_header
= NULL
;
10625 m_cu
->line_header_die_owner
= NULL
;
10634 /* Process a die and its children. */
10637 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10639 process_die_scope
scope (die
, cu
);
10643 case DW_TAG_padding
:
10645 case DW_TAG_compile_unit
:
10646 case DW_TAG_partial_unit
:
10647 read_file_scope (die
, cu
);
10649 case DW_TAG_type_unit
:
10650 read_type_unit_scope (die
, cu
);
10652 case DW_TAG_subprogram
:
10653 /* Nested subprograms in Fortran get a prefix. */
10654 if (cu
->language
== language_fortran
10655 && die
->parent
!= NULL
10656 && die
->parent
->tag
== DW_TAG_subprogram
)
10657 cu
->processing_has_namespace_info
= true;
10658 /* Fall through. */
10659 case DW_TAG_inlined_subroutine
:
10660 read_func_scope (die
, cu
);
10662 case DW_TAG_lexical_block
:
10663 case DW_TAG_try_block
:
10664 case DW_TAG_catch_block
:
10665 read_lexical_block_scope (die
, cu
);
10667 case DW_TAG_call_site
:
10668 case DW_TAG_GNU_call_site
:
10669 read_call_site_scope (die
, cu
);
10671 case DW_TAG_class_type
:
10672 case DW_TAG_interface_type
:
10673 case DW_TAG_structure_type
:
10674 case DW_TAG_union_type
:
10675 process_structure_scope (die
, cu
);
10677 case DW_TAG_enumeration_type
:
10678 process_enumeration_scope (die
, cu
);
10681 /* These dies have a type, but processing them does not create
10682 a symbol or recurse to process the children. Therefore we can
10683 read them on-demand through read_type_die. */
10684 case DW_TAG_subroutine_type
:
10685 case DW_TAG_set_type
:
10686 case DW_TAG_array_type
:
10687 case DW_TAG_pointer_type
:
10688 case DW_TAG_ptr_to_member_type
:
10689 case DW_TAG_reference_type
:
10690 case DW_TAG_rvalue_reference_type
:
10691 case DW_TAG_string_type
:
10694 case DW_TAG_base_type
:
10695 case DW_TAG_subrange_type
:
10696 case DW_TAG_typedef
:
10697 /* Add a typedef symbol for the type definition, if it has a
10699 new_symbol (die
, read_type_die (die
, cu
), cu
);
10701 case DW_TAG_common_block
:
10702 read_common_block (die
, cu
);
10704 case DW_TAG_common_inclusion
:
10706 case DW_TAG_namespace
:
10707 cu
->processing_has_namespace_info
= true;
10708 read_namespace (die
, cu
);
10710 case DW_TAG_module
:
10711 cu
->processing_has_namespace_info
= true;
10712 read_module (die
, cu
);
10714 case DW_TAG_imported_declaration
:
10715 cu
->processing_has_namespace_info
= true;
10716 if (read_namespace_alias (die
, cu
))
10718 /* The declaration is not a global namespace alias. */
10719 /* Fall through. */
10720 case DW_TAG_imported_module
:
10721 cu
->processing_has_namespace_info
= true;
10722 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10723 || cu
->language
!= language_fortran
))
10724 complaint (_("Tag '%s' has unexpected children"),
10725 dwarf_tag_name (die
->tag
));
10726 read_import_statement (die
, cu
);
10729 case DW_TAG_imported_unit
:
10730 process_imported_unit_die (die
, cu
);
10733 case DW_TAG_variable
:
10734 read_variable (die
, cu
);
10738 new_symbol (die
, NULL
, cu
);
10743 /* DWARF name computation. */
10745 /* A helper function for dwarf2_compute_name which determines whether DIE
10746 needs to have the name of the scope prepended to the name listed in the
10750 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10752 struct attribute
*attr
;
10756 case DW_TAG_namespace
:
10757 case DW_TAG_typedef
:
10758 case DW_TAG_class_type
:
10759 case DW_TAG_interface_type
:
10760 case DW_TAG_structure_type
:
10761 case DW_TAG_union_type
:
10762 case DW_TAG_enumeration_type
:
10763 case DW_TAG_enumerator
:
10764 case DW_TAG_subprogram
:
10765 case DW_TAG_inlined_subroutine
:
10766 case DW_TAG_member
:
10767 case DW_TAG_imported_declaration
:
10770 case DW_TAG_variable
:
10771 case DW_TAG_constant
:
10772 /* We only need to prefix "globally" visible variables. These include
10773 any variable marked with DW_AT_external or any variable that
10774 lives in a namespace. [Variables in anonymous namespaces
10775 require prefixing, but they are not DW_AT_external.] */
10777 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10779 struct dwarf2_cu
*spec_cu
= cu
;
10781 return die_needs_namespace (die_specification (die
, &spec_cu
),
10785 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10786 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10787 && die
->parent
->tag
!= DW_TAG_module
)
10789 /* A variable in a lexical block of some kind does not need a
10790 namespace, even though in C++ such variables may be external
10791 and have a mangled name. */
10792 if (die
->parent
->tag
== DW_TAG_lexical_block
10793 || die
->parent
->tag
== DW_TAG_try_block
10794 || die
->parent
->tag
== DW_TAG_catch_block
10795 || die
->parent
->tag
== DW_TAG_subprogram
)
10804 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10805 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10806 defined for the given DIE. */
10808 static struct attribute
*
10809 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10811 struct attribute
*attr
;
10813 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10815 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10820 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10821 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10822 defined for the given DIE. */
10824 static const char *
10825 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10827 const char *linkage_name
;
10829 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10830 if (linkage_name
== NULL
)
10831 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10833 return linkage_name
;
10836 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10837 compute the physname for the object, which include a method's:
10838 - formal parameters (C++),
10839 - receiver type (Go),
10841 The term "physname" is a bit confusing.
10842 For C++, for example, it is the demangled name.
10843 For Go, for example, it's the mangled name.
10845 For Ada, return the DIE's linkage name rather than the fully qualified
10846 name. PHYSNAME is ignored..
10848 The result is allocated on the objfile_obstack and canonicalized. */
10850 static const char *
10851 dwarf2_compute_name (const char *name
,
10852 struct die_info
*die
, struct dwarf2_cu
*cu
,
10855 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10858 name
= dwarf2_name (die
, cu
);
10860 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10861 but otherwise compute it by typename_concat inside GDB.
10862 FIXME: Actually this is not really true, or at least not always true.
10863 It's all very confusing. compute_and_set_names doesn't try to demangle
10864 Fortran names because there is no mangling standard. So new_symbol
10865 will set the demangled name to the result of dwarf2_full_name, and it is
10866 the demangled name that GDB uses if it exists. */
10867 if (cu
->language
== language_ada
10868 || (cu
->language
== language_fortran
&& physname
))
10870 /* For Ada unit, we prefer the linkage name over the name, as
10871 the former contains the exported name, which the user expects
10872 to be able to reference. Ideally, we want the user to be able
10873 to reference this entity using either natural or linkage name,
10874 but we haven't started looking at this enhancement yet. */
10875 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10877 if (linkage_name
!= NULL
)
10878 return linkage_name
;
10881 /* These are the only languages we know how to qualify names in. */
10883 && (cu
->language
== language_cplus
10884 || cu
->language
== language_fortran
|| cu
->language
== language_d
10885 || cu
->language
== language_rust
))
10887 if (die_needs_namespace (die
, cu
))
10889 const char *prefix
;
10890 const char *canonical_name
= NULL
;
10894 prefix
= determine_prefix (die
, cu
);
10895 if (*prefix
!= '\0')
10897 gdb::unique_xmalloc_ptr
<char> prefixed_name
10898 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10900 buf
.puts (prefixed_name
.get ());
10905 /* Template parameters may be specified in the DIE's DW_AT_name, or
10906 as children with DW_TAG_template_type_param or
10907 DW_TAG_value_type_param. If the latter, add them to the name
10908 here. If the name already has template parameters, then
10909 skip this step; some versions of GCC emit both, and
10910 it is more efficient to use the pre-computed name.
10912 Something to keep in mind about this process: it is very
10913 unlikely, or in some cases downright impossible, to produce
10914 something that will match the mangled name of a function.
10915 If the definition of the function has the same debug info,
10916 we should be able to match up with it anyway. But fallbacks
10917 using the minimal symbol, for instance to find a method
10918 implemented in a stripped copy of libstdc++, will not work.
10919 If we do not have debug info for the definition, we will have to
10920 match them up some other way.
10922 When we do name matching there is a related problem with function
10923 templates; two instantiated function templates are allowed to
10924 differ only by their return types, which we do not add here. */
10926 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10928 struct attribute
*attr
;
10929 struct die_info
*child
;
10932 die
->building_fullname
= 1;
10934 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10938 const gdb_byte
*bytes
;
10939 struct dwarf2_locexpr_baton
*baton
;
10942 if (child
->tag
!= DW_TAG_template_type_param
10943 && child
->tag
!= DW_TAG_template_value_param
)
10954 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10957 complaint (_("template parameter missing DW_AT_type"));
10958 buf
.puts ("UNKNOWN_TYPE");
10961 type
= die_type (child
, cu
);
10963 if (child
->tag
== DW_TAG_template_type_param
)
10965 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10966 &type_print_raw_options
);
10970 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10973 complaint (_("template parameter missing "
10974 "DW_AT_const_value"));
10975 buf
.puts ("UNKNOWN_VALUE");
10979 dwarf2_const_value_attr (attr
, type
, name
,
10980 &cu
->comp_unit_obstack
, cu
,
10981 &value
, &bytes
, &baton
);
10983 if (TYPE_NOSIGN (type
))
10984 /* GDB prints characters as NUMBER 'CHAR'. If that's
10985 changed, this can use value_print instead. */
10986 c_printchar (value
, type
, &buf
);
10989 struct value_print_options opts
;
10992 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10996 else if (bytes
!= NULL
)
10998 v
= allocate_value (type
);
10999 memcpy (value_contents_writeable (v
), bytes
,
11000 TYPE_LENGTH (type
));
11003 v
= value_from_longest (type
, value
);
11005 /* Specify decimal so that we do not depend on
11007 get_formatted_print_options (&opts
, 'd');
11009 value_print (v
, &buf
, &opts
);
11014 die
->building_fullname
= 0;
11018 /* Close the argument list, with a space if necessary
11019 (nested templates). */
11020 if (!buf
.empty () && buf
.string ().back () == '>')
11027 /* For C++ methods, append formal parameter type
11028 information, if PHYSNAME. */
11030 if (physname
&& die
->tag
== DW_TAG_subprogram
11031 && cu
->language
== language_cplus
)
11033 struct type
*type
= read_type_die (die
, cu
);
11035 c_type_print_args (type
, &buf
, 1, cu
->language
,
11036 &type_print_raw_options
);
11038 if (cu
->language
== language_cplus
)
11040 /* Assume that an artificial first parameter is
11041 "this", but do not crash if it is not. RealView
11042 marks unnamed (and thus unused) parameters as
11043 artificial; there is no way to differentiate
11045 if (TYPE_NFIELDS (type
) > 0
11046 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11047 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11048 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11050 buf
.puts (" const");
11054 const std::string
&intermediate_name
= buf
.string ();
11056 if (cu
->language
== language_cplus
)
11058 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11059 &objfile
->per_bfd
->storage_obstack
);
11061 /* If we only computed INTERMEDIATE_NAME, or if
11062 INTERMEDIATE_NAME is already canonical, then we need to
11063 copy it to the appropriate obstack. */
11064 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11065 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11066 intermediate_name
);
11068 name
= canonical_name
;
11075 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11076 If scope qualifiers are appropriate they will be added. The result
11077 will be allocated on the storage_obstack, or NULL if the DIE does
11078 not have a name. NAME may either be from a previous call to
11079 dwarf2_name or NULL.
11081 The output string will be canonicalized (if C++). */
11083 static const char *
11084 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11086 return dwarf2_compute_name (name
, die
, cu
, 0);
11089 /* Construct a physname for the given DIE in CU. NAME may either be
11090 from a previous call to dwarf2_name or NULL. The result will be
11091 allocated on the objfile_objstack or NULL if the DIE does not have a
11094 The output string will be canonicalized (if C++). */
11096 static const char *
11097 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11099 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11100 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11103 /* In this case dwarf2_compute_name is just a shortcut not building anything
11105 if (!die_needs_namespace (die
, cu
))
11106 return dwarf2_compute_name (name
, die
, cu
, 1);
11108 mangled
= dw2_linkage_name (die
, cu
);
11110 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11111 See https://github.com/rust-lang/rust/issues/32925. */
11112 if (cu
->language
== language_rust
&& mangled
!= NULL
11113 && strchr (mangled
, '{') != NULL
)
11116 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11118 gdb::unique_xmalloc_ptr
<char> demangled
;
11119 if (mangled
!= NULL
)
11122 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11124 /* Do nothing (do not demangle the symbol name). */
11126 else if (cu
->language
== language_go
)
11128 /* This is a lie, but we already lie to the caller new_symbol.
11129 new_symbol assumes we return the mangled name.
11130 This just undoes that lie until things are cleaned up. */
11134 /* Use DMGL_RET_DROP for C++ template functions to suppress
11135 their return type. It is easier for GDB users to search
11136 for such functions as `name(params)' than `long name(params)'.
11137 In such case the minimal symbol names do not match the full
11138 symbol names but for template functions there is never a need
11139 to look up their definition from their declaration so
11140 the only disadvantage remains the minimal symbol variant
11141 `long name(params)' does not have the proper inferior type. */
11142 demangled
.reset (gdb_demangle (mangled
,
11143 (DMGL_PARAMS
| DMGL_ANSI
11144 | DMGL_RET_DROP
)));
11147 canon
= demangled
.get ();
11155 if (canon
== NULL
|| check_physname
)
11157 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11159 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11161 /* It may not mean a bug in GDB. The compiler could also
11162 compute DW_AT_linkage_name incorrectly. But in such case
11163 GDB would need to be bug-to-bug compatible. */
11165 complaint (_("Computed physname <%s> does not match demangled <%s> "
11166 "(from linkage <%s>) - DIE at %s [in module %s]"),
11167 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11168 objfile_name (objfile
));
11170 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11171 is available here - over computed PHYSNAME. It is safer
11172 against both buggy GDB and buggy compilers. */
11186 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11191 /* Inspect DIE in CU for a namespace alias. If one exists, record
11192 a new symbol for it.
11194 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11197 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11199 struct attribute
*attr
;
11201 /* If the die does not have a name, this is not a namespace
11203 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11207 struct die_info
*d
= die
;
11208 struct dwarf2_cu
*imported_cu
= cu
;
11210 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11211 keep inspecting DIEs until we hit the underlying import. */
11212 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11213 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11215 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11219 d
= follow_die_ref (d
, attr
, &imported_cu
);
11220 if (d
->tag
!= DW_TAG_imported_declaration
)
11224 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11226 complaint (_("DIE at %s has too many recursively imported "
11227 "declarations"), sect_offset_str (d
->sect_off
));
11234 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11236 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11237 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11239 /* This declaration is a global namespace alias. Add
11240 a symbol for it whose type is the aliased namespace. */
11241 new_symbol (die
, type
, cu
);
11250 /* Return the using directives repository (global or local?) to use in the
11251 current context for CU.
11253 For Ada, imported declarations can materialize renamings, which *may* be
11254 global. However it is impossible (for now?) in DWARF to distinguish
11255 "external" imported declarations and "static" ones. As all imported
11256 declarations seem to be static in all other languages, make them all CU-wide
11257 global only in Ada. */
11259 static struct using_direct
**
11260 using_directives (struct dwarf2_cu
*cu
)
11262 if (cu
->language
== language_ada
11263 && cu
->get_builder ()->outermost_context_p ())
11264 return cu
->get_builder ()->get_global_using_directives ();
11266 return cu
->get_builder ()->get_local_using_directives ();
11269 /* Read the import statement specified by the given die and record it. */
11272 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11274 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11275 struct attribute
*import_attr
;
11276 struct die_info
*imported_die
, *child_die
;
11277 struct dwarf2_cu
*imported_cu
;
11278 const char *imported_name
;
11279 const char *imported_name_prefix
;
11280 const char *canonical_name
;
11281 const char *import_alias
;
11282 const char *imported_declaration
= NULL
;
11283 const char *import_prefix
;
11284 std::vector
<const char *> excludes
;
11286 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11287 if (import_attr
== NULL
)
11289 complaint (_("Tag '%s' has no DW_AT_import"),
11290 dwarf_tag_name (die
->tag
));
11295 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11296 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11297 if (imported_name
== NULL
)
11299 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11301 The import in the following code:
11315 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11316 <52> DW_AT_decl_file : 1
11317 <53> DW_AT_decl_line : 6
11318 <54> DW_AT_import : <0x75>
11319 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11320 <59> DW_AT_name : B
11321 <5b> DW_AT_decl_file : 1
11322 <5c> DW_AT_decl_line : 2
11323 <5d> DW_AT_type : <0x6e>
11325 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11326 <76> DW_AT_byte_size : 4
11327 <77> DW_AT_encoding : 5 (signed)
11329 imports the wrong die ( 0x75 instead of 0x58 ).
11330 This case will be ignored until the gcc bug is fixed. */
11334 /* Figure out the local name after import. */
11335 import_alias
= dwarf2_name (die
, cu
);
11337 /* Figure out where the statement is being imported to. */
11338 import_prefix
= determine_prefix (die
, cu
);
11340 /* Figure out what the scope of the imported die is and prepend it
11341 to the name of the imported die. */
11342 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11344 if (imported_die
->tag
!= DW_TAG_namespace
11345 && imported_die
->tag
!= DW_TAG_module
)
11347 imported_declaration
= imported_name
;
11348 canonical_name
= imported_name_prefix
;
11350 else if (strlen (imported_name_prefix
) > 0)
11351 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11352 imported_name_prefix
,
11353 (cu
->language
== language_d
? "." : "::"),
11354 imported_name
, (char *) NULL
);
11356 canonical_name
= imported_name
;
11358 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11359 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11360 child_die
= sibling_die (child_die
))
11362 /* DWARF-4: A Fortran use statement with a “rename list” may be
11363 represented by an imported module entry with an import attribute
11364 referring to the module and owned entries corresponding to those
11365 entities that are renamed as part of being imported. */
11367 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11369 complaint (_("child DW_TAG_imported_declaration expected "
11370 "- DIE at %s [in module %s]"),
11371 sect_offset_str (child_die
->sect_off
),
11372 objfile_name (objfile
));
11376 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11377 if (import_attr
== NULL
)
11379 complaint (_("Tag '%s' has no DW_AT_import"),
11380 dwarf_tag_name (child_die
->tag
));
11385 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11387 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11388 if (imported_name
== NULL
)
11390 complaint (_("child DW_TAG_imported_declaration has unknown "
11391 "imported name - DIE at %s [in module %s]"),
11392 sect_offset_str (child_die
->sect_off
),
11393 objfile_name (objfile
));
11397 excludes
.push_back (imported_name
);
11399 process_die (child_die
, cu
);
11402 add_using_directive (using_directives (cu
),
11406 imported_declaration
,
11409 &objfile
->objfile_obstack
);
11412 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11413 types, but gives them a size of zero. Starting with version 14,
11414 ICC is compatible with GCC. */
11417 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11419 if (!cu
->checked_producer
)
11420 check_producer (cu
);
11422 return cu
->producer_is_icc_lt_14
;
11425 /* ICC generates a DW_AT_type for C void functions. This was observed on
11426 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11427 which says that void functions should not have a DW_AT_type. */
11430 producer_is_icc (struct dwarf2_cu
*cu
)
11432 if (!cu
->checked_producer
)
11433 check_producer (cu
);
11435 return cu
->producer_is_icc
;
11438 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11439 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11440 this, it was first present in GCC release 4.3.0. */
11443 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11445 if (!cu
->checked_producer
)
11446 check_producer (cu
);
11448 return cu
->producer_is_gcc_lt_4_3
;
11451 static file_and_directory
11452 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11454 file_and_directory res
;
11456 /* Find the filename. Do not use dwarf2_name here, since the filename
11457 is not a source language identifier. */
11458 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11459 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11461 if (res
.comp_dir
== NULL
11462 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11463 && IS_ABSOLUTE_PATH (res
.name
))
11465 res
.comp_dir_storage
= ldirname (res
.name
);
11466 if (!res
.comp_dir_storage
.empty ())
11467 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11469 if (res
.comp_dir
!= NULL
)
11471 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11472 directory, get rid of it. */
11473 const char *cp
= strchr (res
.comp_dir
, ':');
11475 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11476 res
.comp_dir
= cp
+ 1;
11479 if (res
.name
== NULL
)
11480 res
.name
= "<unknown>";
11485 /* Handle DW_AT_stmt_list for a compilation unit.
11486 DIE is the DW_TAG_compile_unit die for CU.
11487 COMP_DIR is the compilation directory. LOWPC is passed to
11488 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11491 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11492 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11494 struct dwarf2_per_objfile
*dwarf2_per_objfile
11495 = cu
->per_cu
->dwarf2_per_objfile
;
11496 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11497 struct attribute
*attr
;
11498 struct line_header line_header_local
;
11499 hashval_t line_header_local_hash
;
11501 int decode_mapping
;
11503 gdb_assert (! cu
->per_cu
->is_debug_types
);
11505 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11509 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11511 /* The line header hash table is only created if needed (it exists to
11512 prevent redundant reading of the line table for partial_units).
11513 If we're given a partial_unit, we'll need it. If we're given a
11514 compile_unit, then use the line header hash table if it's already
11515 created, but don't create one just yet. */
11517 if (dwarf2_per_objfile
->line_header_hash
== NULL
11518 && die
->tag
== DW_TAG_partial_unit
)
11520 dwarf2_per_objfile
->line_header_hash
11521 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11522 line_header_eq_voidp
,
11523 free_line_header_voidp
,
11524 &objfile
->objfile_obstack
,
11525 hashtab_obstack_allocate
,
11526 dummy_obstack_deallocate
);
11529 line_header_local
.sect_off
= line_offset
;
11530 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11531 line_header_local_hash
= line_header_hash (&line_header_local
);
11532 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11534 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11535 &line_header_local
,
11536 line_header_local_hash
, NO_INSERT
);
11538 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11539 is not present in *SLOT (since if there is something in *SLOT then
11540 it will be for a partial_unit). */
11541 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11543 gdb_assert (*slot
!= NULL
);
11544 cu
->line_header
= (struct line_header
*) *slot
;
11549 /* dwarf_decode_line_header does not yet provide sufficient information.
11550 We always have to call also dwarf_decode_lines for it. */
11551 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11555 cu
->line_header
= lh
.release ();
11556 cu
->line_header_die_owner
= die
;
11558 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11562 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11563 &line_header_local
,
11564 line_header_local_hash
, INSERT
);
11565 gdb_assert (slot
!= NULL
);
11567 if (slot
!= NULL
&& *slot
== NULL
)
11569 /* This newly decoded line number information unit will be owned
11570 by line_header_hash hash table. */
11571 *slot
= cu
->line_header
;
11572 cu
->line_header_die_owner
= NULL
;
11576 /* We cannot free any current entry in (*slot) as that struct line_header
11577 may be already used by multiple CUs. Create only temporary decoded
11578 line_header for this CU - it may happen at most once for each line
11579 number information unit. And if we're not using line_header_hash
11580 then this is what we want as well. */
11581 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11583 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11584 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11589 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11592 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11594 struct dwarf2_per_objfile
*dwarf2_per_objfile
11595 = cu
->per_cu
->dwarf2_per_objfile
;
11596 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11597 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11598 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11599 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11600 struct attribute
*attr
;
11601 struct die_info
*child_die
;
11602 CORE_ADDR baseaddr
;
11604 prepare_one_comp_unit (cu
, die
, cu
->language
);
11605 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11607 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11609 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11610 from finish_block. */
11611 if (lowpc
== ((CORE_ADDR
) -1))
11613 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11615 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11617 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11618 standardised yet. As a workaround for the language detection we fall
11619 back to the DW_AT_producer string. */
11620 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11621 cu
->language
= language_opencl
;
11623 /* Similar hack for Go. */
11624 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11625 set_cu_language (DW_LANG_Go
, cu
);
11627 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11629 /* Decode line number information if present. We do this before
11630 processing child DIEs, so that the line header table is available
11631 for DW_AT_decl_file. */
11632 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11634 /* Process all dies in compilation unit. */
11635 if (die
->child
!= NULL
)
11637 child_die
= die
->child
;
11638 while (child_die
&& child_die
->tag
)
11640 process_die (child_die
, cu
);
11641 child_die
= sibling_die (child_die
);
11645 /* Decode macro information, if present. Dwarf 2 macro information
11646 refers to information in the line number info statement program
11647 header, so we can only read it if we've read the header
11649 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11651 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11652 if (attr
&& cu
->line_header
)
11654 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11655 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11657 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11661 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11662 if (attr
&& cu
->line_header
)
11664 unsigned int macro_offset
= DW_UNSND (attr
);
11666 dwarf_decode_macros (cu
, macro_offset
, 0);
11672 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11674 struct type_unit_group
*tu_group
;
11676 struct attribute
*attr
;
11678 struct signatured_type
*sig_type
;
11680 gdb_assert (per_cu
->is_debug_types
);
11681 sig_type
= (struct signatured_type
*) per_cu
;
11683 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11685 /* If we're using .gdb_index (includes -readnow) then
11686 per_cu->type_unit_group may not have been set up yet. */
11687 if (sig_type
->type_unit_group
== NULL
)
11688 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11689 tu_group
= sig_type
->type_unit_group
;
11691 /* If we've already processed this stmt_list there's no real need to
11692 do it again, we could fake it and just recreate the part we need
11693 (file name,index -> symtab mapping). If data shows this optimization
11694 is useful we can do it then. */
11695 first_time
= tu_group
->compunit_symtab
== NULL
;
11697 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11702 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11703 lh
= dwarf_decode_line_header (line_offset
, this);
11708 start_symtab ("", NULL
, 0);
11711 gdb_assert (tu_group
->symtabs
== NULL
);
11712 gdb_assert (m_builder
== nullptr);
11713 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11714 m_builder
.reset (new struct buildsym_compunit
11715 (COMPUNIT_OBJFILE (cust
), "",
11716 COMPUNIT_DIRNAME (cust
),
11717 compunit_language (cust
),
11723 line_header
= lh
.release ();
11724 line_header_die_owner
= die
;
11728 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11730 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11731 still initializing it, and our caller (a few levels up)
11732 process_full_type_unit still needs to know if this is the first
11735 tu_group
->num_symtabs
= line_header
->file_names_size ();
11736 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11737 line_header
->file_names_size ());
11739 auto &file_names
= line_header
->file_names ();
11740 for (i
= 0; i
< file_names
.size (); ++i
)
11742 file_entry
&fe
= file_names
[i
];
11743 dwarf2_start_subfile (this, fe
.name
,
11744 fe
.include_dir (line_header
));
11745 buildsym_compunit
*b
= get_builder ();
11746 if (b
->get_current_subfile ()->symtab
== NULL
)
11748 /* NOTE: start_subfile will recognize when it's been
11749 passed a file it has already seen. So we can't
11750 assume there's a simple mapping from
11751 cu->line_header->file_names to subfiles, plus
11752 cu->line_header->file_names may contain dups. */
11753 b
->get_current_subfile ()->symtab
11754 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11757 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11758 tu_group
->symtabs
[i
] = fe
.symtab
;
11763 gdb_assert (m_builder
== nullptr);
11764 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11765 m_builder
.reset (new struct buildsym_compunit
11766 (COMPUNIT_OBJFILE (cust
), "",
11767 COMPUNIT_DIRNAME (cust
),
11768 compunit_language (cust
),
11771 auto &file_names
= line_header
->file_names ();
11772 for (i
= 0; i
< file_names
.size (); ++i
)
11774 file_entry
&fe
= file_names
[i
];
11775 fe
.symtab
= tu_group
->symtabs
[i
];
11779 /* The main symtab is allocated last. Type units don't have DW_AT_name
11780 so they don't have a "real" (so to speak) symtab anyway.
11781 There is later code that will assign the main symtab to all symbols
11782 that don't have one. We need to handle the case of a symbol with a
11783 missing symtab (DW_AT_decl_file) anyway. */
11786 /* Process DW_TAG_type_unit.
11787 For TUs we want to skip the first top level sibling if it's not the
11788 actual type being defined by this TU. In this case the first top
11789 level sibling is there to provide context only. */
11792 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11794 struct die_info
*child_die
;
11796 prepare_one_comp_unit (cu
, die
, language_minimal
);
11798 /* Initialize (or reinitialize) the machinery for building symtabs.
11799 We do this before processing child DIEs, so that the line header table
11800 is available for DW_AT_decl_file. */
11801 cu
->setup_type_unit_groups (die
);
11803 if (die
->child
!= NULL
)
11805 child_die
= die
->child
;
11806 while (child_die
&& child_die
->tag
)
11808 process_die (child_die
, cu
);
11809 child_die
= sibling_die (child_die
);
11816 http://gcc.gnu.org/wiki/DebugFission
11817 http://gcc.gnu.org/wiki/DebugFissionDWP
11819 To simplify handling of both DWO files ("object" files with the DWARF info)
11820 and DWP files (a file with the DWOs packaged up into one file), we treat
11821 DWP files as having a collection of virtual DWO files. */
11824 hash_dwo_file (const void *item
)
11826 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11829 hash
= htab_hash_string (dwo_file
->dwo_name
);
11830 if (dwo_file
->comp_dir
!= NULL
)
11831 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11836 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11838 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11839 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11841 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11843 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11844 return lhs
->comp_dir
== rhs
->comp_dir
;
11845 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11848 /* Allocate a hash table for DWO files. */
11851 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11853 auto delete_dwo_file
= [] (void *item
)
11855 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11860 return htab_up (htab_create_alloc_ex (41,
11864 &objfile
->objfile_obstack
,
11865 hashtab_obstack_allocate
,
11866 dummy_obstack_deallocate
));
11869 /* Lookup DWO file DWO_NAME. */
11872 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11873 const char *dwo_name
,
11874 const char *comp_dir
)
11876 struct dwo_file find_entry
;
11879 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11880 dwarf2_per_objfile
->dwo_files
11881 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11883 find_entry
.dwo_name
= dwo_name
;
11884 find_entry
.comp_dir
= comp_dir
;
11885 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11892 hash_dwo_unit (const void *item
)
11894 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11896 /* This drops the top 32 bits of the id, but is ok for a hash. */
11897 return dwo_unit
->signature
;
11901 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11903 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11904 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11906 /* The signature is assumed to be unique within the DWO file.
11907 So while object file CU dwo_id's always have the value zero,
11908 that's OK, assuming each object file DWO file has only one CU,
11909 and that's the rule for now. */
11910 return lhs
->signature
== rhs
->signature
;
11913 /* Allocate a hash table for DWO CUs,TUs.
11914 There is one of these tables for each of CUs,TUs for each DWO file. */
11917 allocate_dwo_unit_table (struct objfile
*objfile
)
11919 /* Start out with a pretty small number.
11920 Generally DWO files contain only one CU and maybe some TUs. */
11921 return htab_create_alloc_ex (3,
11925 &objfile
->objfile_obstack
,
11926 hashtab_obstack_allocate
,
11927 dummy_obstack_deallocate
);
11930 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11932 struct create_dwo_cu_data
11934 struct dwo_file
*dwo_file
;
11935 struct dwo_unit dwo_unit
;
11938 /* die_reader_func for create_dwo_cu. */
11941 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11942 const gdb_byte
*info_ptr
,
11943 struct die_info
*comp_unit_die
,
11947 struct dwarf2_cu
*cu
= reader
->cu
;
11948 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11949 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11950 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11951 struct dwo_file
*dwo_file
= data
->dwo_file
;
11952 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11954 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11955 if (!signature
.has_value ())
11957 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11958 " its dwo_id [in module %s]"),
11959 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11963 dwo_unit
->dwo_file
= dwo_file
;
11964 dwo_unit
->signature
= *signature
;
11965 dwo_unit
->section
= section
;
11966 dwo_unit
->sect_off
= sect_off
;
11967 dwo_unit
->length
= cu
->per_cu
->length
;
11969 if (dwarf_read_debug
)
11970 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11971 sect_offset_str (sect_off
),
11972 hex_string (dwo_unit
->signature
));
11975 /* Create the dwo_units for the CUs in a DWO_FILE.
11976 Note: This function processes DWO files only, not DWP files. */
11979 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11980 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11983 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11984 const gdb_byte
*info_ptr
, *end_ptr
;
11986 dwarf2_read_section (objfile
, §ion
);
11987 info_ptr
= section
.buffer
;
11989 if (info_ptr
== NULL
)
11992 if (dwarf_read_debug
)
11994 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11995 get_section_name (§ion
),
11996 get_section_file_name (§ion
));
11999 end_ptr
= info_ptr
+ section
.size
;
12000 while (info_ptr
< end_ptr
)
12002 struct dwarf2_per_cu_data per_cu
;
12003 struct create_dwo_cu_data create_dwo_cu_data
;
12004 struct dwo_unit
*dwo_unit
;
12006 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12008 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12009 sizeof (create_dwo_cu_data
.dwo_unit
));
12010 memset (&per_cu
, 0, sizeof (per_cu
));
12011 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12012 per_cu
.is_debug_types
= 0;
12013 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12014 per_cu
.section
= §ion
;
12015 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12017 init_cutu_and_read_dies_no_follow (
12018 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12019 info_ptr
+= per_cu
.length
;
12021 // If the unit could not be parsed, skip it.
12022 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12025 if (cus_htab
== NULL
)
12026 cus_htab
= allocate_dwo_unit_table (objfile
);
12028 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12029 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12030 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12031 gdb_assert (slot
!= NULL
);
12034 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12035 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12037 complaint (_("debug cu entry at offset %s is duplicate to"
12038 " the entry at offset %s, signature %s"),
12039 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12040 hex_string (dwo_unit
->signature
));
12042 *slot
= (void *)dwo_unit
;
12046 /* DWP file .debug_{cu,tu}_index section format:
12047 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12051 Both index sections have the same format, and serve to map a 64-bit
12052 signature to a set of section numbers. Each section begins with a header,
12053 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12054 indexes, and a pool of 32-bit section numbers. The index sections will be
12055 aligned at 8-byte boundaries in the file.
12057 The index section header consists of:
12059 V, 32 bit version number
12061 N, 32 bit number of compilation units or type units in the index
12062 M, 32 bit number of slots in the hash table
12064 Numbers are recorded using the byte order of the application binary.
12066 The hash table begins at offset 16 in the section, and consists of an array
12067 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12068 order of the application binary). Unused slots in the hash table are 0.
12069 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12071 The parallel table begins immediately after the hash table
12072 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12073 array of 32-bit indexes (using the byte order of the application binary),
12074 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12075 table contains a 32-bit index into the pool of section numbers. For unused
12076 hash table slots, the corresponding entry in the parallel table will be 0.
12078 The pool of section numbers begins immediately following the hash table
12079 (at offset 16 + 12 * M from the beginning of the section). The pool of
12080 section numbers consists of an array of 32-bit words (using the byte order
12081 of the application binary). Each item in the array is indexed starting
12082 from 0. The hash table entry provides the index of the first section
12083 number in the set. Additional section numbers in the set follow, and the
12084 set is terminated by a 0 entry (section number 0 is not used in ELF).
12086 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12087 section must be the first entry in the set, and the .debug_abbrev.dwo must
12088 be the second entry. Other members of the set may follow in any order.
12094 DWP Version 2 combines all the .debug_info, etc. sections into one,
12095 and the entries in the index tables are now offsets into these sections.
12096 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12099 Index Section Contents:
12101 Hash Table of Signatures dwp_hash_table.hash_table
12102 Parallel Table of Indices dwp_hash_table.unit_table
12103 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12104 Table of Section Sizes dwp_hash_table.v2.sizes
12106 The index section header consists of:
12108 V, 32 bit version number
12109 L, 32 bit number of columns in the table of section offsets
12110 N, 32 bit number of compilation units or type units in the index
12111 M, 32 bit number of slots in the hash table
12113 Numbers are recorded using the byte order of the application binary.
12115 The hash table has the same format as version 1.
12116 The parallel table of indices has the same format as version 1,
12117 except that the entries are origin-1 indices into the table of sections
12118 offsets and the table of section sizes.
12120 The table of offsets begins immediately following the parallel table
12121 (at offset 16 + 12 * M from the beginning of the section). The table is
12122 a two-dimensional array of 32-bit words (using the byte order of the
12123 application binary), with L columns and N+1 rows, in row-major order.
12124 Each row in the array is indexed starting from 0. The first row provides
12125 a key to the remaining rows: each column in this row provides an identifier
12126 for a debug section, and the offsets in the same column of subsequent rows
12127 refer to that section. The section identifiers are:
12129 DW_SECT_INFO 1 .debug_info.dwo
12130 DW_SECT_TYPES 2 .debug_types.dwo
12131 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12132 DW_SECT_LINE 4 .debug_line.dwo
12133 DW_SECT_LOC 5 .debug_loc.dwo
12134 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12135 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12136 DW_SECT_MACRO 8 .debug_macro.dwo
12138 The offsets provided by the CU and TU index sections are the base offsets
12139 for the contributions made by each CU or TU to the corresponding section
12140 in the package file. Each CU and TU header contains an abbrev_offset
12141 field, used to find the abbreviations table for that CU or TU within the
12142 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12143 be interpreted as relative to the base offset given in the index section.
12144 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12145 should be interpreted as relative to the base offset for .debug_line.dwo,
12146 and offsets into other debug sections obtained from DWARF attributes should
12147 also be interpreted as relative to the corresponding base offset.
12149 The table of sizes begins immediately following the table of offsets.
12150 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12151 with L columns and N rows, in row-major order. Each row in the array is
12152 indexed starting from 1 (row 0 is shared by the two tables).
12156 Hash table lookup is handled the same in version 1 and 2:
12158 We assume that N and M will not exceed 2^32 - 1.
12159 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12161 Given a 64-bit compilation unit signature or a type signature S, an entry
12162 in the hash table is located as follows:
12164 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12165 the low-order k bits all set to 1.
12167 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12169 3) If the hash table entry at index H matches the signature, use that
12170 entry. If the hash table entry at index H is unused (all zeroes),
12171 terminate the search: the signature is not present in the table.
12173 4) Let H = (H + H') modulo M. Repeat at Step 3.
12175 Because M > N and H' and M are relatively prime, the search is guaranteed
12176 to stop at an unused slot or find the match. */
12178 /* Create a hash table to map DWO IDs to their CU/TU entry in
12179 .debug_{info,types}.dwo in DWP_FILE.
12180 Returns NULL if there isn't one.
12181 Note: This function processes DWP files only, not DWO files. */
12183 static struct dwp_hash_table
*
12184 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12185 struct dwp_file
*dwp_file
, int is_debug_types
)
12187 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12188 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12189 const gdb_byte
*index_ptr
, *index_end
;
12190 struct dwarf2_section_info
*index
;
12191 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12192 struct dwp_hash_table
*htab
;
12194 if (is_debug_types
)
12195 index
= &dwp_file
->sections
.tu_index
;
12197 index
= &dwp_file
->sections
.cu_index
;
12199 if (dwarf2_section_empty_p (index
))
12201 dwarf2_read_section (objfile
, index
);
12203 index_ptr
= index
->buffer
;
12204 index_end
= index_ptr
+ index
->size
;
12206 version
= read_4_bytes (dbfd
, index_ptr
);
12209 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12213 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12215 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12218 if (version
!= 1 && version
!= 2)
12220 error (_("Dwarf Error: unsupported DWP file version (%s)"
12221 " [in module %s]"),
12222 pulongest (version
), dwp_file
->name
);
12224 if (nr_slots
!= (nr_slots
& -nr_slots
))
12226 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12227 " is not power of 2 [in module %s]"),
12228 pulongest (nr_slots
), dwp_file
->name
);
12231 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12232 htab
->version
= version
;
12233 htab
->nr_columns
= nr_columns
;
12234 htab
->nr_units
= nr_units
;
12235 htab
->nr_slots
= nr_slots
;
12236 htab
->hash_table
= index_ptr
;
12237 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12239 /* Exit early if the table is empty. */
12240 if (nr_slots
== 0 || nr_units
== 0
12241 || (version
== 2 && nr_columns
== 0))
12243 /* All must be zero. */
12244 if (nr_slots
!= 0 || nr_units
!= 0
12245 || (version
== 2 && nr_columns
!= 0))
12247 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12248 " all zero [in modules %s]"),
12256 htab
->section_pool
.v1
.indices
=
12257 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12258 /* It's harder to decide whether the section is too small in v1.
12259 V1 is deprecated anyway so we punt. */
12263 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12264 int *ids
= htab
->section_pool
.v2
.section_ids
;
12265 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12266 /* Reverse map for error checking. */
12267 int ids_seen
[DW_SECT_MAX
+ 1];
12270 if (nr_columns
< 2)
12272 error (_("Dwarf Error: bad DWP hash table, too few columns"
12273 " in section table [in module %s]"),
12276 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12278 error (_("Dwarf Error: bad DWP hash table, too many columns"
12279 " in section table [in module %s]"),
12282 memset (ids
, 255, sizeof_ids
);
12283 memset (ids_seen
, 255, sizeof (ids_seen
));
12284 for (i
= 0; i
< nr_columns
; ++i
)
12286 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12288 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12290 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12291 " in section table [in module %s]"),
12292 id
, dwp_file
->name
);
12294 if (ids_seen
[id
] != -1)
12296 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12297 " id %d in section table [in module %s]"),
12298 id
, dwp_file
->name
);
12303 /* Must have exactly one info or types section. */
12304 if (((ids_seen
[DW_SECT_INFO
] != -1)
12305 + (ids_seen
[DW_SECT_TYPES
] != -1))
12308 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12309 " DWO info/types section [in module %s]"),
12312 /* Must have an abbrev section. */
12313 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12315 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12316 " section [in module %s]"),
12319 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12320 htab
->section_pool
.v2
.sizes
=
12321 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12322 * nr_units
* nr_columns
);
12323 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12324 * nr_units
* nr_columns
))
12327 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12328 " [in module %s]"),
12336 /* Update SECTIONS with the data from SECTP.
12338 This function is like the other "locate" section routines that are
12339 passed to bfd_map_over_sections, but in this context the sections to
12340 read comes from the DWP V1 hash table, not the full ELF section table.
12342 The result is non-zero for success, or zero if an error was found. */
12345 locate_v1_virtual_dwo_sections (asection
*sectp
,
12346 struct virtual_v1_dwo_sections
*sections
)
12348 const struct dwop_section_names
*names
= &dwop_section_names
;
12350 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12352 /* There can be only one. */
12353 if (sections
->abbrev
.s
.section
!= NULL
)
12355 sections
->abbrev
.s
.section
= sectp
;
12356 sections
->abbrev
.size
= bfd_section_size (sectp
);
12358 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12359 || section_is_p (sectp
->name
, &names
->types_dwo
))
12361 /* There can be only one. */
12362 if (sections
->info_or_types
.s
.section
!= NULL
)
12364 sections
->info_or_types
.s
.section
= sectp
;
12365 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12367 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12369 /* There can be only one. */
12370 if (sections
->line
.s
.section
!= NULL
)
12372 sections
->line
.s
.section
= sectp
;
12373 sections
->line
.size
= bfd_section_size (sectp
);
12375 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12377 /* There can be only one. */
12378 if (sections
->loc
.s
.section
!= NULL
)
12380 sections
->loc
.s
.section
= sectp
;
12381 sections
->loc
.size
= bfd_section_size (sectp
);
12383 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12385 /* There can be only one. */
12386 if (sections
->macinfo
.s
.section
!= NULL
)
12388 sections
->macinfo
.s
.section
= sectp
;
12389 sections
->macinfo
.size
= bfd_section_size (sectp
);
12391 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12393 /* There can be only one. */
12394 if (sections
->macro
.s
.section
!= NULL
)
12396 sections
->macro
.s
.section
= sectp
;
12397 sections
->macro
.size
= bfd_section_size (sectp
);
12399 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12401 /* There can be only one. */
12402 if (sections
->str_offsets
.s
.section
!= NULL
)
12404 sections
->str_offsets
.s
.section
= sectp
;
12405 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12409 /* No other kind of section is valid. */
12416 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12417 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12418 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12419 This is for DWP version 1 files. */
12421 static struct dwo_unit
*
12422 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12423 struct dwp_file
*dwp_file
,
12424 uint32_t unit_index
,
12425 const char *comp_dir
,
12426 ULONGEST signature
, int is_debug_types
)
12428 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12429 const struct dwp_hash_table
*dwp_htab
=
12430 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12431 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12432 const char *kind
= is_debug_types
? "TU" : "CU";
12433 struct dwo_file
*dwo_file
;
12434 struct dwo_unit
*dwo_unit
;
12435 struct virtual_v1_dwo_sections sections
;
12436 void **dwo_file_slot
;
12439 gdb_assert (dwp_file
->version
== 1);
12441 if (dwarf_read_debug
)
12443 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12445 pulongest (unit_index
), hex_string (signature
),
12449 /* Fetch the sections of this DWO unit.
12450 Put a limit on the number of sections we look for so that bad data
12451 doesn't cause us to loop forever. */
12453 #define MAX_NR_V1_DWO_SECTIONS \
12454 (1 /* .debug_info or .debug_types */ \
12455 + 1 /* .debug_abbrev */ \
12456 + 1 /* .debug_line */ \
12457 + 1 /* .debug_loc */ \
12458 + 1 /* .debug_str_offsets */ \
12459 + 1 /* .debug_macro or .debug_macinfo */ \
12460 + 1 /* trailing zero */)
12462 memset (§ions
, 0, sizeof (sections
));
12464 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12467 uint32_t section_nr
=
12468 read_4_bytes (dbfd
,
12469 dwp_htab
->section_pool
.v1
.indices
12470 + (unit_index
+ i
) * sizeof (uint32_t));
12472 if (section_nr
== 0)
12474 if (section_nr
>= dwp_file
->num_sections
)
12476 error (_("Dwarf Error: bad DWP hash table, section number too large"
12477 " [in module %s]"),
12481 sectp
= dwp_file
->elf_sections
[section_nr
];
12482 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12484 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12485 " [in module %s]"),
12491 || dwarf2_section_empty_p (§ions
.info_or_types
)
12492 || dwarf2_section_empty_p (§ions
.abbrev
))
12494 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12495 " [in module %s]"),
12498 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12500 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12501 " [in module %s]"),
12505 /* It's easier for the rest of the code if we fake a struct dwo_file and
12506 have dwo_unit "live" in that. At least for now.
12508 The DWP file can be made up of a random collection of CUs and TUs.
12509 However, for each CU + set of TUs that came from the same original DWO
12510 file, we can combine them back into a virtual DWO file to save space
12511 (fewer struct dwo_file objects to allocate). Remember that for really
12512 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12514 std::string virtual_dwo_name
=
12515 string_printf ("virtual-dwo/%d-%d-%d-%d",
12516 get_section_id (§ions
.abbrev
),
12517 get_section_id (§ions
.line
),
12518 get_section_id (§ions
.loc
),
12519 get_section_id (§ions
.str_offsets
));
12520 /* Can we use an existing virtual DWO file? */
12521 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12522 virtual_dwo_name
.c_str (),
12524 /* Create one if necessary. */
12525 if (*dwo_file_slot
== NULL
)
12527 if (dwarf_read_debug
)
12529 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12530 virtual_dwo_name
.c_str ());
12532 dwo_file
= new struct dwo_file
;
12533 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12535 dwo_file
->comp_dir
= comp_dir
;
12536 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12537 dwo_file
->sections
.line
= sections
.line
;
12538 dwo_file
->sections
.loc
= sections
.loc
;
12539 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12540 dwo_file
->sections
.macro
= sections
.macro
;
12541 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12542 /* The "str" section is global to the entire DWP file. */
12543 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12544 /* The info or types section is assigned below to dwo_unit,
12545 there's no need to record it in dwo_file.
12546 Also, we can't simply record type sections in dwo_file because
12547 we record a pointer into the vector in dwo_unit. As we collect more
12548 types we'll grow the vector and eventually have to reallocate space
12549 for it, invalidating all copies of pointers into the previous
12551 *dwo_file_slot
= dwo_file
;
12555 if (dwarf_read_debug
)
12557 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12558 virtual_dwo_name
.c_str ());
12560 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12563 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12564 dwo_unit
->dwo_file
= dwo_file
;
12565 dwo_unit
->signature
= signature
;
12566 dwo_unit
->section
=
12567 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12568 *dwo_unit
->section
= sections
.info_or_types
;
12569 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12574 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12575 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12576 piece within that section used by a TU/CU, return a virtual section
12577 of just that piece. */
12579 static struct dwarf2_section_info
12580 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12581 struct dwarf2_section_info
*section
,
12582 bfd_size_type offset
, bfd_size_type size
)
12584 struct dwarf2_section_info result
;
12587 gdb_assert (section
!= NULL
);
12588 gdb_assert (!section
->is_virtual
);
12590 memset (&result
, 0, sizeof (result
));
12591 result
.s
.containing_section
= section
;
12592 result
.is_virtual
= true;
12597 sectp
= get_section_bfd_section (section
);
12599 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12600 bounds of the real section. This is a pretty-rare event, so just
12601 flag an error (easier) instead of a warning and trying to cope. */
12603 || offset
+ size
> bfd_section_size (sectp
))
12605 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12606 " in section %s [in module %s]"),
12607 sectp
? bfd_section_name (sectp
) : "<unknown>",
12608 objfile_name (dwarf2_per_objfile
->objfile
));
12611 result
.virtual_offset
= offset
;
12612 result
.size
= size
;
12616 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12617 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12618 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12619 This is for DWP version 2 files. */
12621 static struct dwo_unit
*
12622 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12623 struct dwp_file
*dwp_file
,
12624 uint32_t unit_index
,
12625 const char *comp_dir
,
12626 ULONGEST signature
, int is_debug_types
)
12628 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12629 const struct dwp_hash_table
*dwp_htab
=
12630 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12631 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12632 const char *kind
= is_debug_types
? "TU" : "CU";
12633 struct dwo_file
*dwo_file
;
12634 struct dwo_unit
*dwo_unit
;
12635 struct virtual_v2_dwo_sections sections
;
12636 void **dwo_file_slot
;
12639 gdb_assert (dwp_file
->version
== 2);
12641 if (dwarf_read_debug
)
12643 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12645 pulongest (unit_index
), hex_string (signature
),
12649 /* Fetch the section offsets of this DWO unit. */
12651 memset (§ions
, 0, sizeof (sections
));
12653 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12655 uint32_t offset
= read_4_bytes (dbfd
,
12656 dwp_htab
->section_pool
.v2
.offsets
12657 + (((unit_index
- 1) * dwp_htab
->nr_columns
12659 * sizeof (uint32_t)));
12660 uint32_t size
= read_4_bytes (dbfd
,
12661 dwp_htab
->section_pool
.v2
.sizes
12662 + (((unit_index
- 1) * dwp_htab
->nr_columns
12664 * sizeof (uint32_t)));
12666 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12669 case DW_SECT_TYPES
:
12670 sections
.info_or_types_offset
= offset
;
12671 sections
.info_or_types_size
= size
;
12673 case DW_SECT_ABBREV
:
12674 sections
.abbrev_offset
= offset
;
12675 sections
.abbrev_size
= size
;
12678 sections
.line_offset
= offset
;
12679 sections
.line_size
= size
;
12682 sections
.loc_offset
= offset
;
12683 sections
.loc_size
= size
;
12685 case DW_SECT_STR_OFFSETS
:
12686 sections
.str_offsets_offset
= offset
;
12687 sections
.str_offsets_size
= size
;
12689 case DW_SECT_MACINFO
:
12690 sections
.macinfo_offset
= offset
;
12691 sections
.macinfo_size
= size
;
12693 case DW_SECT_MACRO
:
12694 sections
.macro_offset
= offset
;
12695 sections
.macro_size
= size
;
12700 /* It's easier for the rest of the code if we fake a struct dwo_file and
12701 have dwo_unit "live" in that. At least for now.
12703 The DWP file can be made up of a random collection of CUs and TUs.
12704 However, for each CU + set of TUs that came from the same original DWO
12705 file, we can combine them back into a virtual DWO file to save space
12706 (fewer struct dwo_file objects to allocate). Remember that for really
12707 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12709 std::string virtual_dwo_name
=
12710 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12711 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12712 (long) (sections
.line_size
? sections
.line_offset
: 0),
12713 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12714 (long) (sections
.str_offsets_size
12715 ? sections
.str_offsets_offset
: 0));
12716 /* Can we use an existing virtual DWO file? */
12717 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12718 virtual_dwo_name
.c_str (),
12720 /* Create one if necessary. */
12721 if (*dwo_file_slot
== NULL
)
12723 if (dwarf_read_debug
)
12725 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12726 virtual_dwo_name
.c_str ());
12728 dwo_file
= new struct dwo_file
;
12729 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12731 dwo_file
->comp_dir
= comp_dir
;
12732 dwo_file
->sections
.abbrev
=
12733 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12734 sections
.abbrev_offset
, sections
.abbrev_size
);
12735 dwo_file
->sections
.line
=
12736 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12737 sections
.line_offset
, sections
.line_size
);
12738 dwo_file
->sections
.loc
=
12739 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12740 sections
.loc_offset
, sections
.loc_size
);
12741 dwo_file
->sections
.macinfo
=
12742 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12743 sections
.macinfo_offset
, sections
.macinfo_size
);
12744 dwo_file
->sections
.macro
=
12745 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12746 sections
.macro_offset
, sections
.macro_size
);
12747 dwo_file
->sections
.str_offsets
=
12748 create_dwp_v2_section (dwarf2_per_objfile
,
12749 &dwp_file
->sections
.str_offsets
,
12750 sections
.str_offsets_offset
,
12751 sections
.str_offsets_size
);
12752 /* The "str" section is global to the entire DWP file. */
12753 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12754 /* The info or types section is assigned below to dwo_unit,
12755 there's no need to record it in dwo_file.
12756 Also, we can't simply record type sections in dwo_file because
12757 we record a pointer into the vector in dwo_unit. As we collect more
12758 types we'll grow the vector and eventually have to reallocate space
12759 for it, invalidating all copies of pointers into the previous
12761 *dwo_file_slot
= dwo_file
;
12765 if (dwarf_read_debug
)
12767 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12768 virtual_dwo_name
.c_str ());
12770 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12773 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12774 dwo_unit
->dwo_file
= dwo_file
;
12775 dwo_unit
->signature
= signature
;
12776 dwo_unit
->section
=
12777 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12778 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12780 ? &dwp_file
->sections
.types
12781 : &dwp_file
->sections
.info
,
12782 sections
.info_or_types_offset
,
12783 sections
.info_or_types_size
);
12784 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12789 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12790 Returns NULL if the signature isn't found. */
12792 static struct dwo_unit
*
12793 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12794 struct dwp_file
*dwp_file
, const char *comp_dir
,
12795 ULONGEST signature
, int is_debug_types
)
12797 const struct dwp_hash_table
*dwp_htab
=
12798 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12799 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12800 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12801 uint32_t hash
= signature
& mask
;
12802 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12805 struct dwo_unit find_dwo_cu
;
12807 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12808 find_dwo_cu
.signature
= signature
;
12809 slot
= htab_find_slot (is_debug_types
12810 ? dwp_file
->loaded_tus
12811 : dwp_file
->loaded_cus
,
12812 &find_dwo_cu
, INSERT
);
12815 return (struct dwo_unit
*) *slot
;
12817 /* Use a for loop so that we don't loop forever on bad debug info. */
12818 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12820 ULONGEST signature_in_table
;
12822 signature_in_table
=
12823 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12824 if (signature_in_table
== signature
)
12826 uint32_t unit_index
=
12827 read_4_bytes (dbfd
,
12828 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12830 if (dwp_file
->version
== 1)
12832 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12833 dwp_file
, unit_index
,
12834 comp_dir
, signature
,
12839 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12840 dwp_file
, unit_index
,
12841 comp_dir
, signature
,
12844 return (struct dwo_unit
*) *slot
;
12846 if (signature_in_table
== 0)
12848 hash
= (hash
+ hash2
) & mask
;
12851 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12852 " [in module %s]"),
12856 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12857 Open the file specified by FILE_NAME and hand it off to BFD for
12858 preliminary analysis. Return a newly initialized bfd *, which
12859 includes a canonicalized copy of FILE_NAME.
12860 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12861 SEARCH_CWD is true if the current directory is to be searched.
12862 It will be searched before debug-file-directory.
12863 If successful, the file is added to the bfd include table of the
12864 objfile's bfd (see gdb_bfd_record_inclusion).
12865 If unable to find/open the file, return NULL.
12866 NOTE: This function is derived from symfile_bfd_open. */
12868 static gdb_bfd_ref_ptr
12869 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12870 const char *file_name
, int is_dwp
, int search_cwd
)
12873 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12874 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12875 to debug_file_directory. */
12876 const char *search_path
;
12877 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12879 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12882 if (*debug_file_directory
!= '\0')
12884 search_path_holder
.reset (concat (".", dirname_separator_string
,
12885 debug_file_directory
,
12887 search_path
= search_path_holder
.get ();
12893 search_path
= debug_file_directory
;
12895 openp_flags flags
= OPF_RETURN_REALPATH
;
12897 flags
|= OPF_SEARCH_IN_PATH
;
12899 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12900 desc
= openp (search_path
, flags
, file_name
,
12901 O_RDONLY
| O_BINARY
, &absolute_name
);
12905 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12907 if (sym_bfd
== NULL
)
12909 bfd_set_cacheable (sym_bfd
.get (), 1);
12911 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12914 /* Success. Record the bfd as having been included by the objfile's bfd.
12915 This is important because things like demangled_names_hash lives in the
12916 objfile's per_bfd space and may have references to things like symbol
12917 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12918 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12923 /* Try to open DWO file FILE_NAME.
12924 COMP_DIR is the DW_AT_comp_dir attribute.
12925 The result is the bfd handle of the file.
12926 If there is a problem finding or opening the file, return NULL.
12927 Upon success, the canonicalized path of the file is stored in the bfd,
12928 same as symfile_bfd_open. */
12930 static gdb_bfd_ref_ptr
12931 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12932 const char *file_name
, const char *comp_dir
)
12934 if (IS_ABSOLUTE_PATH (file_name
))
12935 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12936 0 /*is_dwp*/, 0 /*search_cwd*/);
12938 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12940 if (comp_dir
!= NULL
)
12942 gdb::unique_xmalloc_ptr
<char> path_to_try
12943 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12945 /* NOTE: If comp_dir is a relative path, this will also try the
12946 search path, which seems useful. */
12947 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12948 path_to_try
.get (),
12950 1 /*search_cwd*/));
12955 /* That didn't work, try debug-file-directory, which, despite its name,
12956 is a list of paths. */
12958 if (*debug_file_directory
== '\0')
12961 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12962 0 /*is_dwp*/, 1 /*search_cwd*/);
12965 /* This function is mapped across the sections and remembers the offset and
12966 size of each of the DWO debugging sections we are interested in. */
12969 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12971 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12972 const struct dwop_section_names
*names
= &dwop_section_names
;
12974 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12976 dwo_sections
->abbrev
.s
.section
= sectp
;
12977 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12979 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12981 dwo_sections
->info
.s
.section
= sectp
;
12982 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12984 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12986 dwo_sections
->line
.s
.section
= sectp
;
12987 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12989 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12991 dwo_sections
->loc
.s
.section
= sectp
;
12992 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12994 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12996 dwo_sections
->macinfo
.s
.section
= sectp
;
12997 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12999 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13001 dwo_sections
->macro
.s
.section
= sectp
;
13002 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13004 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13006 dwo_sections
->str
.s
.section
= sectp
;
13007 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13009 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13011 dwo_sections
->str_offsets
.s
.section
= sectp
;
13012 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13014 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13016 struct dwarf2_section_info type_section
;
13018 memset (&type_section
, 0, sizeof (type_section
));
13019 type_section
.s
.section
= sectp
;
13020 type_section
.size
= bfd_section_size (sectp
);
13021 dwo_sections
->types
.push_back (type_section
);
13025 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13026 by PER_CU. This is for the non-DWP case.
13027 The result is NULL if DWO_NAME can't be found. */
13029 static struct dwo_file
*
13030 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13031 const char *dwo_name
, const char *comp_dir
)
13033 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13035 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13038 if (dwarf_read_debug
)
13039 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13043 dwo_file_up
dwo_file (new struct dwo_file
);
13044 dwo_file
->dwo_name
= dwo_name
;
13045 dwo_file
->comp_dir
= comp_dir
;
13046 dwo_file
->dbfd
= std::move (dbfd
);
13048 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13049 &dwo_file
->sections
);
13051 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13054 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13055 dwo_file
->sections
.types
, dwo_file
->tus
);
13057 if (dwarf_read_debug
)
13058 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13060 return dwo_file
.release ();
13063 /* This function is mapped across the sections and remembers the offset and
13064 size of each of the DWP debugging sections common to version 1 and 2 that
13065 we are interested in. */
13068 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13069 void *dwp_file_ptr
)
13071 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13072 const struct dwop_section_names
*names
= &dwop_section_names
;
13073 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13075 /* Record the ELF section number for later lookup: this is what the
13076 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13077 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13078 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13080 /* Look for specific sections that we need. */
13081 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13083 dwp_file
->sections
.str
.s
.section
= sectp
;
13084 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13086 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13088 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13089 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13091 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13093 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13094 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13098 /* This function is mapped across the sections and remembers the offset and
13099 size of each of the DWP version 2 debugging sections that we are interested
13100 in. This is split into a separate function because we don't know if we
13101 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13104 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13106 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13107 const struct dwop_section_names
*names
= &dwop_section_names
;
13108 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13110 /* Record the ELF section number for later lookup: this is what the
13111 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13112 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13113 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13115 /* Look for specific sections that we need. */
13116 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13118 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13119 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13121 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13123 dwp_file
->sections
.info
.s
.section
= sectp
;
13124 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13126 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13128 dwp_file
->sections
.line
.s
.section
= sectp
;
13129 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13131 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13133 dwp_file
->sections
.loc
.s
.section
= sectp
;
13134 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13136 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13138 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13139 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13141 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13143 dwp_file
->sections
.macro
.s
.section
= sectp
;
13144 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13146 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13148 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13149 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13151 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13153 dwp_file
->sections
.types
.s
.section
= sectp
;
13154 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13158 /* Hash function for dwp_file loaded CUs/TUs. */
13161 hash_dwp_loaded_cutus (const void *item
)
13163 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13165 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13166 return dwo_unit
->signature
;
13169 /* Equality function for dwp_file loaded CUs/TUs. */
13172 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13174 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13175 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13177 return dua
->signature
== dub
->signature
;
13180 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13183 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13185 return htab_create_alloc_ex (3,
13186 hash_dwp_loaded_cutus
,
13187 eq_dwp_loaded_cutus
,
13189 &objfile
->objfile_obstack
,
13190 hashtab_obstack_allocate
,
13191 dummy_obstack_deallocate
);
13194 /* Try to open DWP file FILE_NAME.
13195 The result is the bfd handle of the file.
13196 If there is a problem finding or opening the file, return NULL.
13197 Upon success, the canonicalized path of the file is stored in the bfd,
13198 same as symfile_bfd_open. */
13200 static gdb_bfd_ref_ptr
13201 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13202 const char *file_name
)
13204 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13206 1 /*search_cwd*/));
13210 /* Work around upstream bug 15652.
13211 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13212 [Whether that's a "bug" is debatable, but it is getting in our way.]
13213 We have no real idea where the dwp file is, because gdb's realpath-ing
13214 of the executable's path may have discarded the needed info.
13215 [IWBN if the dwp file name was recorded in the executable, akin to
13216 .gnu_debuglink, but that doesn't exist yet.]
13217 Strip the directory from FILE_NAME and search again. */
13218 if (*debug_file_directory
!= '\0')
13220 /* Don't implicitly search the current directory here.
13221 If the user wants to search "." to handle this case,
13222 it must be added to debug-file-directory. */
13223 return try_open_dwop_file (dwarf2_per_objfile
,
13224 lbasename (file_name
), 1 /*is_dwp*/,
13231 /* Initialize the use of the DWP file for the current objfile.
13232 By convention the name of the DWP file is ${objfile}.dwp.
13233 The result is NULL if it can't be found. */
13235 static std::unique_ptr
<struct dwp_file
>
13236 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13238 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13240 /* Try to find first .dwp for the binary file before any symbolic links
13243 /* If the objfile is a debug file, find the name of the real binary
13244 file and get the name of dwp file from there. */
13245 std::string dwp_name
;
13246 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13248 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13249 const char *backlink_basename
= lbasename (backlink
->original_name
);
13251 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13254 dwp_name
= objfile
->original_name
;
13256 dwp_name
+= ".dwp";
13258 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13260 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13262 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13263 dwp_name
= objfile_name (objfile
);
13264 dwp_name
+= ".dwp";
13265 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13270 if (dwarf_read_debug
)
13271 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13272 return std::unique_ptr
<dwp_file
> ();
13275 const char *name
= bfd_get_filename (dbfd
.get ());
13276 std::unique_ptr
<struct dwp_file
> dwp_file
13277 (new struct dwp_file (name
, std::move (dbfd
)));
13279 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13280 dwp_file
->elf_sections
=
13281 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13282 dwp_file
->num_sections
, asection
*);
13284 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13285 dwarf2_locate_common_dwp_sections
,
13288 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13291 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13294 /* The DWP file version is stored in the hash table. Oh well. */
13295 if (dwp_file
->cus
&& dwp_file
->tus
13296 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13298 /* Technically speaking, we should try to limp along, but this is
13299 pretty bizarre. We use pulongest here because that's the established
13300 portability solution (e.g, we cannot use %u for uint32_t). */
13301 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13302 " TU version %s [in DWP file %s]"),
13303 pulongest (dwp_file
->cus
->version
),
13304 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13308 dwp_file
->version
= dwp_file
->cus
->version
;
13309 else if (dwp_file
->tus
)
13310 dwp_file
->version
= dwp_file
->tus
->version
;
13312 dwp_file
->version
= 2;
13314 if (dwp_file
->version
== 2)
13315 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13316 dwarf2_locate_v2_dwp_sections
,
13319 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13320 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13322 if (dwarf_read_debug
)
13324 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13325 fprintf_unfiltered (gdb_stdlog
,
13326 " %s CUs, %s TUs\n",
13327 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13328 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13334 /* Wrapper around open_and_init_dwp_file, only open it once. */
13336 static struct dwp_file
*
13337 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13339 if (! dwarf2_per_objfile
->dwp_checked
)
13341 dwarf2_per_objfile
->dwp_file
13342 = open_and_init_dwp_file (dwarf2_per_objfile
);
13343 dwarf2_per_objfile
->dwp_checked
= 1;
13345 return dwarf2_per_objfile
->dwp_file
.get ();
13348 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13349 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13350 or in the DWP file for the objfile, referenced by THIS_UNIT.
13351 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13352 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13354 This is called, for example, when wanting to read a variable with a
13355 complex location. Therefore we don't want to do file i/o for every call.
13356 Therefore we don't want to look for a DWO file on every call.
13357 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13358 then we check if we've already seen DWO_NAME, and only THEN do we check
13361 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13362 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13364 static struct dwo_unit
*
13365 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13366 const char *dwo_name
, const char *comp_dir
,
13367 ULONGEST signature
, int is_debug_types
)
13369 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13370 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13371 const char *kind
= is_debug_types
? "TU" : "CU";
13372 void **dwo_file_slot
;
13373 struct dwo_file
*dwo_file
;
13374 struct dwp_file
*dwp_file
;
13376 /* First see if there's a DWP file.
13377 If we have a DWP file but didn't find the DWO inside it, don't
13378 look for the original DWO file. It makes gdb behave differently
13379 depending on whether one is debugging in the build tree. */
13381 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13382 if (dwp_file
!= NULL
)
13384 const struct dwp_hash_table
*dwp_htab
=
13385 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13387 if (dwp_htab
!= NULL
)
13389 struct dwo_unit
*dwo_cutu
=
13390 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13391 signature
, is_debug_types
);
13393 if (dwo_cutu
!= NULL
)
13395 if (dwarf_read_debug
)
13397 fprintf_unfiltered (gdb_stdlog
,
13398 "Virtual DWO %s %s found: @%s\n",
13399 kind
, hex_string (signature
),
13400 host_address_to_string (dwo_cutu
));
13408 /* No DWP file, look for the DWO file. */
13410 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13411 dwo_name
, comp_dir
);
13412 if (*dwo_file_slot
== NULL
)
13414 /* Read in the file and build a table of the CUs/TUs it contains. */
13415 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13417 /* NOTE: This will be NULL if unable to open the file. */
13418 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13420 if (dwo_file
!= NULL
)
13422 struct dwo_unit
*dwo_cutu
= NULL
;
13424 if (is_debug_types
&& dwo_file
->tus
)
13426 struct dwo_unit find_dwo_cutu
;
13428 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13429 find_dwo_cutu
.signature
= signature
;
13431 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13433 else if (!is_debug_types
&& dwo_file
->cus
)
13435 struct dwo_unit find_dwo_cutu
;
13437 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13438 find_dwo_cutu
.signature
= signature
;
13439 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13443 if (dwo_cutu
!= NULL
)
13445 if (dwarf_read_debug
)
13447 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13448 kind
, dwo_name
, hex_string (signature
),
13449 host_address_to_string (dwo_cutu
));
13456 /* We didn't find it. This could mean a dwo_id mismatch, or
13457 someone deleted the DWO/DWP file, or the search path isn't set up
13458 correctly to find the file. */
13460 if (dwarf_read_debug
)
13462 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13463 kind
, dwo_name
, hex_string (signature
));
13466 /* This is a warning and not a complaint because it can be caused by
13467 pilot error (e.g., user accidentally deleting the DWO). */
13469 /* Print the name of the DWP file if we looked there, helps the user
13470 better diagnose the problem. */
13471 std::string dwp_text
;
13473 if (dwp_file
!= NULL
)
13474 dwp_text
= string_printf (" [in DWP file %s]",
13475 lbasename (dwp_file
->name
));
13477 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13478 " [in module %s]"),
13479 kind
, dwo_name
, hex_string (signature
),
13481 this_unit
->is_debug_types
? "TU" : "CU",
13482 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13487 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13488 See lookup_dwo_cutu_unit for details. */
13490 static struct dwo_unit
*
13491 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13492 const char *dwo_name
, const char *comp_dir
,
13493 ULONGEST signature
)
13495 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13498 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13499 See lookup_dwo_cutu_unit for details. */
13501 static struct dwo_unit
*
13502 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13503 const char *dwo_name
, const char *comp_dir
)
13505 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13508 /* Traversal function for queue_and_load_all_dwo_tus. */
13511 queue_and_load_dwo_tu (void **slot
, void *info
)
13513 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13514 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13515 ULONGEST signature
= dwo_unit
->signature
;
13516 struct signatured_type
*sig_type
=
13517 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13519 if (sig_type
!= NULL
)
13521 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13523 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13524 a real dependency of PER_CU on SIG_TYPE. That is detected later
13525 while processing PER_CU. */
13526 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13527 load_full_type_unit (sig_cu
);
13528 per_cu
->imported_symtabs_push (sig_cu
);
13534 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13535 The DWO may have the only definition of the type, though it may not be
13536 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13537 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13540 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13542 struct dwo_unit
*dwo_unit
;
13543 struct dwo_file
*dwo_file
;
13545 gdb_assert (!per_cu
->is_debug_types
);
13546 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13547 gdb_assert (per_cu
->cu
!= NULL
);
13549 dwo_unit
= per_cu
->cu
->dwo_unit
;
13550 gdb_assert (dwo_unit
!= NULL
);
13552 dwo_file
= dwo_unit
->dwo_file
;
13553 if (dwo_file
->tus
!= NULL
)
13554 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13557 /* Read in various DIEs. */
13559 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13560 Inherit only the children of the DW_AT_abstract_origin DIE not being
13561 already referenced by DW_AT_abstract_origin from the children of the
13565 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13567 struct die_info
*child_die
;
13568 sect_offset
*offsetp
;
13569 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13570 struct die_info
*origin_die
;
13571 /* Iterator of the ORIGIN_DIE children. */
13572 struct die_info
*origin_child_die
;
13573 struct attribute
*attr
;
13574 struct dwarf2_cu
*origin_cu
;
13575 struct pending
**origin_previous_list_in_scope
;
13577 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13581 /* Note that following die references may follow to a die in a
13585 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13587 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13589 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13590 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13592 if (die
->tag
!= origin_die
->tag
13593 && !(die
->tag
== DW_TAG_inlined_subroutine
13594 && origin_die
->tag
== DW_TAG_subprogram
))
13595 complaint (_("DIE %s and its abstract origin %s have different tags"),
13596 sect_offset_str (die
->sect_off
),
13597 sect_offset_str (origin_die
->sect_off
));
13599 std::vector
<sect_offset
> offsets
;
13601 for (child_die
= die
->child
;
13602 child_die
&& child_die
->tag
;
13603 child_die
= sibling_die (child_die
))
13605 struct die_info
*child_origin_die
;
13606 struct dwarf2_cu
*child_origin_cu
;
13608 /* We are trying to process concrete instance entries:
13609 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13610 it's not relevant to our analysis here. i.e. detecting DIEs that are
13611 present in the abstract instance but not referenced in the concrete
13613 if (child_die
->tag
== DW_TAG_call_site
13614 || child_die
->tag
== DW_TAG_GNU_call_site
)
13617 /* For each CHILD_DIE, find the corresponding child of
13618 ORIGIN_DIE. If there is more than one layer of
13619 DW_AT_abstract_origin, follow them all; there shouldn't be,
13620 but GCC versions at least through 4.4 generate this (GCC PR
13622 child_origin_die
= child_die
;
13623 child_origin_cu
= cu
;
13626 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13630 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13634 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13635 counterpart may exist. */
13636 if (child_origin_die
!= child_die
)
13638 if (child_die
->tag
!= child_origin_die
->tag
13639 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13640 && child_origin_die
->tag
== DW_TAG_subprogram
))
13641 complaint (_("Child DIE %s and its abstract origin %s have "
13643 sect_offset_str (child_die
->sect_off
),
13644 sect_offset_str (child_origin_die
->sect_off
));
13645 if (child_origin_die
->parent
!= origin_die
)
13646 complaint (_("Child DIE %s and its abstract origin %s have "
13647 "different parents"),
13648 sect_offset_str (child_die
->sect_off
),
13649 sect_offset_str (child_origin_die
->sect_off
));
13651 offsets
.push_back (child_origin_die
->sect_off
);
13654 std::sort (offsets
.begin (), offsets
.end ());
13655 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13656 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13657 if (offsetp
[-1] == *offsetp
)
13658 complaint (_("Multiple children of DIE %s refer "
13659 "to DIE %s as their abstract origin"),
13660 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13662 offsetp
= offsets
.data ();
13663 origin_child_die
= origin_die
->child
;
13664 while (origin_child_die
&& origin_child_die
->tag
)
13666 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13667 while (offsetp
< offsets_end
13668 && *offsetp
< origin_child_die
->sect_off
)
13670 if (offsetp
>= offsets_end
13671 || *offsetp
> origin_child_die
->sect_off
)
13673 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13674 Check whether we're already processing ORIGIN_CHILD_DIE.
13675 This can happen with mutually referenced abstract_origins.
13677 if (!origin_child_die
->in_process
)
13678 process_die (origin_child_die
, origin_cu
);
13680 origin_child_die
= sibling_die (origin_child_die
);
13682 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13684 if (cu
!= origin_cu
)
13685 compute_delayed_physnames (origin_cu
);
13689 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13691 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13692 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13693 struct context_stack
*newobj
;
13696 struct die_info
*child_die
;
13697 struct attribute
*attr
, *call_line
, *call_file
;
13699 CORE_ADDR baseaddr
;
13700 struct block
*block
;
13701 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13702 std::vector
<struct symbol
*> template_args
;
13703 struct template_symbol
*templ_func
= NULL
;
13707 /* If we do not have call site information, we can't show the
13708 caller of this inlined function. That's too confusing, so
13709 only use the scope for local variables. */
13710 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13711 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13712 if (call_line
== NULL
|| call_file
== NULL
)
13714 read_lexical_block_scope (die
, cu
);
13719 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13721 name
= dwarf2_name (die
, cu
);
13723 /* Ignore functions with missing or empty names. These are actually
13724 illegal according to the DWARF standard. */
13727 complaint (_("missing name for subprogram DIE at %s"),
13728 sect_offset_str (die
->sect_off
));
13732 /* Ignore functions with missing or invalid low and high pc attributes. */
13733 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13734 <= PC_BOUNDS_INVALID
)
13736 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13737 if (!attr
|| !DW_UNSND (attr
))
13738 complaint (_("cannot get low and high bounds "
13739 "for subprogram DIE at %s"),
13740 sect_offset_str (die
->sect_off
));
13744 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13745 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13747 /* If we have any template arguments, then we must allocate a
13748 different sort of symbol. */
13749 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13751 if (child_die
->tag
== DW_TAG_template_type_param
13752 || child_die
->tag
== DW_TAG_template_value_param
)
13754 templ_func
= allocate_template_symbol (objfile
);
13755 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13760 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13761 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13762 (struct symbol
*) templ_func
);
13764 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13765 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13768 /* If there is a location expression for DW_AT_frame_base, record
13770 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13771 if (attr
!= nullptr)
13772 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13774 /* If there is a location for the static link, record it. */
13775 newobj
->static_link
= NULL
;
13776 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13777 if (attr
!= nullptr)
13779 newobj
->static_link
13780 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13781 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13782 dwarf2_per_cu_addr_type (cu
->per_cu
));
13785 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13787 if (die
->child
!= NULL
)
13789 child_die
= die
->child
;
13790 while (child_die
&& child_die
->tag
)
13792 if (child_die
->tag
== DW_TAG_template_type_param
13793 || child_die
->tag
== DW_TAG_template_value_param
)
13795 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13798 template_args
.push_back (arg
);
13801 process_die (child_die
, cu
);
13802 child_die
= sibling_die (child_die
);
13806 inherit_abstract_dies (die
, cu
);
13808 /* If we have a DW_AT_specification, we might need to import using
13809 directives from the context of the specification DIE. See the
13810 comment in determine_prefix. */
13811 if (cu
->language
== language_cplus
13812 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13814 struct dwarf2_cu
*spec_cu
= cu
;
13815 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13819 child_die
= spec_die
->child
;
13820 while (child_die
&& child_die
->tag
)
13822 if (child_die
->tag
== DW_TAG_imported_module
)
13823 process_die (child_die
, spec_cu
);
13824 child_die
= sibling_die (child_die
);
13827 /* In some cases, GCC generates specification DIEs that
13828 themselves contain DW_AT_specification attributes. */
13829 spec_die
= die_specification (spec_die
, &spec_cu
);
13833 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13834 /* Make a block for the local symbols within. */
13835 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13836 cstk
.static_link
, lowpc
, highpc
);
13838 /* For C++, set the block's scope. */
13839 if ((cu
->language
== language_cplus
13840 || cu
->language
== language_fortran
13841 || cu
->language
== language_d
13842 || cu
->language
== language_rust
)
13843 && cu
->processing_has_namespace_info
)
13844 block_set_scope (block
, determine_prefix (die
, cu
),
13845 &objfile
->objfile_obstack
);
13847 /* If we have address ranges, record them. */
13848 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13850 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13852 /* Attach template arguments to function. */
13853 if (!template_args
.empty ())
13855 gdb_assert (templ_func
!= NULL
);
13857 templ_func
->n_template_arguments
= template_args
.size ();
13858 templ_func
->template_arguments
13859 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13860 templ_func
->n_template_arguments
);
13861 memcpy (templ_func
->template_arguments
,
13862 template_args
.data (),
13863 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13865 /* Make sure that the symtab is set on the new symbols. Even
13866 though they don't appear in this symtab directly, other parts
13867 of gdb assume that symbols do, and this is reasonably
13869 for (symbol
*sym
: template_args
)
13870 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13873 /* In C++, we can have functions nested inside functions (e.g., when
13874 a function declares a class that has methods). This means that
13875 when we finish processing a function scope, we may need to go
13876 back to building a containing block's symbol lists. */
13877 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13878 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13880 /* If we've finished processing a top-level function, subsequent
13881 symbols go in the file symbol list. */
13882 if (cu
->get_builder ()->outermost_context_p ())
13883 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13886 /* Process all the DIES contained within a lexical block scope. Start
13887 a new scope, process the dies, and then close the scope. */
13890 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13892 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13893 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13894 CORE_ADDR lowpc
, highpc
;
13895 struct die_info
*child_die
;
13896 CORE_ADDR baseaddr
;
13898 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13900 /* Ignore blocks with missing or invalid low and high pc attributes. */
13901 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13902 as multiple lexical blocks? Handling children in a sane way would
13903 be nasty. Might be easier to properly extend generic blocks to
13904 describe ranges. */
13905 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13907 case PC_BOUNDS_NOT_PRESENT
:
13908 /* DW_TAG_lexical_block has no attributes, process its children as if
13909 there was no wrapping by that DW_TAG_lexical_block.
13910 GCC does no longer produces such DWARF since GCC r224161. */
13911 for (child_die
= die
->child
;
13912 child_die
!= NULL
&& child_die
->tag
;
13913 child_die
= sibling_die (child_die
))
13914 process_die (child_die
, cu
);
13916 case PC_BOUNDS_INVALID
:
13919 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13920 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13922 cu
->get_builder ()->push_context (0, lowpc
);
13923 if (die
->child
!= NULL
)
13925 child_die
= die
->child
;
13926 while (child_die
&& child_die
->tag
)
13928 process_die (child_die
, cu
);
13929 child_die
= sibling_die (child_die
);
13932 inherit_abstract_dies (die
, cu
);
13933 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13935 if (*cu
->get_builder ()->get_local_symbols () != NULL
13936 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13938 struct block
*block
13939 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13940 cstk
.start_addr
, highpc
);
13942 /* Note that recording ranges after traversing children, as we
13943 do here, means that recording a parent's ranges entails
13944 walking across all its children's ranges as they appear in
13945 the address map, which is quadratic behavior.
13947 It would be nicer to record the parent's ranges before
13948 traversing its children, simply overriding whatever you find
13949 there. But since we don't even decide whether to create a
13950 block until after we've traversed its children, that's hard
13952 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13954 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13955 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13958 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13961 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13963 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13964 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13965 CORE_ADDR pc
, baseaddr
;
13966 struct attribute
*attr
;
13967 struct call_site
*call_site
, call_site_local
;
13970 struct die_info
*child_die
;
13972 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13974 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13977 /* This was a pre-DWARF-5 GNU extension alias
13978 for DW_AT_call_return_pc. */
13979 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13983 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13984 "DIE %s [in module %s]"),
13985 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13988 pc
= attr_value_as_address (attr
) + baseaddr
;
13989 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13991 if (cu
->call_site_htab
== NULL
)
13992 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13993 NULL
, &objfile
->objfile_obstack
,
13994 hashtab_obstack_allocate
, NULL
);
13995 call_site_local
.pc
= pc
;
13996 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13999 complaint (_("Duplicate PC %s for DW_TAG_call_site "
14000 "DIE %s [in module %s]"),
14001 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14002 objfile_name (objfile
));
14006 /* Count parameters at the caller. */
14009 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14010 child_die
= sibling_die (child_die
))
14012 if (child_die
->tag
!= DW_TAG_call_site_parameter
14013 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14015 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14016 "DW_TAG_call_site child DIE %s [in module %s]"),
14017 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14018 objfile_name (objfile
));
14026 = ((struct call_site
*)
14027 obstack_alloc (&objfile
->objfile_obstack
,
14028 sizeof (*call_site
)
14029 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14031 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14032 call_site
->pc
= pc
;
14034 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14035 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14037 struct die_info
*func_die
;
14039 /* Skip also over DW_TAG_inlined_subroutine. */
14040 for (func_die
= die
->parent
;
14041 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14042 && func_die
->tag
!= DW_TAG_subroutine_type
;
14043 func_die
= func_die
->parent
);
14045 /* DW_AT_call_all_calls is a superset
14046 of DW_AT_call_all_tail_calls. */
14048 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14049 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14050 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14051 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14053 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14054 not complete. But keep CALL_SITE for look ups via call_site_htab,
14055 both the initial caller containing the real return address PC and
14056 the final callee containing the current PC of a chain of tail
14057 calls do not need to have the tail call list complete. But any
14058 function candidate for a virtual tail call frame searched via
14059 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14060 determined unambiguously. */
14064 struct type
*func_type
= NULL
;
14067 func_type
= get_die_type (func_die
, cu
);
14068 if (func_type
!= NULL
)
14070 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14072 /* Enlist this call site to the function. */
14073 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14074 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14077 complaint (_("Cannot find function owning DW_TAG_call_site "
14078 "DIE %s [in module %s]"),
14079 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14083 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14085 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14087 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14090 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14091 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14093 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14094 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14095 /* Keep NULL DWARF_BLOCK. */;
14096 else if (attr_form_is_block (attr
))
14098 struct dwarf2_locexpr_baton
*dlbaton
;
14100 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14101 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14102 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14103 dlbaton
->per_cu
= cu
->per_cu
;
14105 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14107 else if (attr_form_is_ref (attr
))
14109 struct dwarf2_cu
*target_cu
= cu
;
14110 struct die_info
*target_die
;
14112 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14113 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14114 if (die_is_declaration (target_die
, target_cu
))
14116 const char *target_physname
;
14118 /* Prefer the mangled name; otherwise compute the demangled one. */
14119 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14120 if (target_physname
== NULL
)
14121 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14122 if (target_physname
== NULL
)
14123 complaint (_("DW_AT_call_target target DIE has invalid "
14124 "physname, for referencing DIE %s [in module %s]"),
14125 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14127 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14133 /* DW_AT_entry_pc should be preferred. */
14134 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14135 <= PC_BOUNDS_INVALID
)
14136 complaint (_("DW_AT_call_target target DIE has invalid "
14137 "low pc, for referencing DIE %s [in module %s]"),
14138 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14141 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14142 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14147 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14148 "block nor reference, for DIE %s [in module %s]"),
14149 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14151 call_site
->per_cu
= cu
->per_cu
;
14153 for (child_die
= die
->child
;
14154 child_die
&& child_die
->tag
;
14155 child_die
= sibling_die (child_die
))
14157 struct call_site_parameter
*parameter
;
14158 struct attribute
*loc
, *origin
;
14160 if (child_die
->tag
!= DW_TAG_call_site_parameter
14161 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14163 /* Already printed the complaint above. */
14167 gdb_assert (call_site
->parameter_count
< nparams
);
14168 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14170 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14171 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14172 register is contained in DW_AT_call_value. */
14174 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14175 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14176 if (origin
== NULL
)
14178 /* This was a pre-DWARF-5 GNU extension alias
14179 for DW_AT_call_parameter. */
14180 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14182 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14184 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14186 sect_offset sect_off
14187 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14188 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14190 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14191 binding can be done only inside one CU. Such referenced DIE
14192 therefore cannot be even moved to DW_TAG_partial_unit. */
14193 complaint (_("DW_AT_call_parameter offset is not in CU for "
14194 "DW_TAG_call_site child DIE %s [in module %s]"),
14195 sect_offset_str (child_die
->sect_off
),
14196 objfile_name (objfile
));
14199 parameter
->u
.param_cu_off
14200 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14202 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14204 complaint (_("No DW_FORM_block* DW_AT_location for "
14205 "DW_TAG_call_site child DIE %s [in module %s]"),
14206 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14211 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14212 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14213 if (parameter
->u
.dwarf_reg
!= -1)
14214 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14215 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14216 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14217 ¶meter
->u
.fb_offset
))
14218 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14221 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14222 "for DW_FORM_block* DW_AT_location is supported for "
14223 "DW_TAG_call_site child DIE %s "
14225 sect_offset_str (child_die
->sect_off
),
14226 objfile_name (objfile
));
14231 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14233 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14234 if (!attr_form_is_block (attr
))
14236 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14237 "DW_TAG_call_site child DIE %s [in module %s]"),
14238 sect_offset_str (child_die
->sect_off
),
14239 objfile_name (objfile
));
14242 parameter
->value
= DW_BLOCK (attr
)->data
;
14243 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14245 /* Parameters are not pre-cleared by memset above. */
14246 parameter
->data_value
= NULL
;
14247 parameter
->data_value_size
= 0;
14248 call_site
->parameter_count
++;
14250 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14252 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14253 if (attr
!= nullptr)
14255 if (!attr_form_is_block (attr
))
14256 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14257 "DW_TAG_call_site child DIE %s [in module %s]"),
14258 sect_offset_str (child_die
->sect_off
),
14259 objfile_name (objfile
));
14262 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14263 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14269 /* Helper function for read_variable. If DIE represents a virtual
14270 table, then return the type of the concrete object that is
14271 associated with the virtual table. Otherwise, return NULL. */
14273 static struct type
*
14274 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14276 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14280 /* Find the type DIE. */
14281 struct die_info
*type_die
= NULL
;
14282 struct dwarf2_cu
*type_cu
= cu
;
14284 if (attr_form_is_ref (attr
))
14285 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14286 if (type_die
== NULL
)
14289 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14291 return die_containing_type (type_die
, type_cu
);
14294 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14297 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14299 struct rust_vtable_symbol
*storage
= NULL
;
14301 if (cu
->language
== language_rust
)
14303 struct type
*containing_type
= rust_containing_type (die
, cu
);
14305 if (containing_type
!= NULL
)
14307 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14309 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14310 initialize_objfile_symbol (storage
);
14311 storage
->concrete_type
= containing_type
;
14312 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14316 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14317 struct attribute
*abstract_origin
14318 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14319 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14320 if (res
== NULL
&& loc
&& abstract_origin
)
14322 /* We have a variable without a name, but with a location and an abstract
14323 origin. This may be a concrete instance of an abstract variable
14324 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14326 struct dwarf2_cu
*origin_cu
= cu
;
14327 struct die_info
*origin_die
14328 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14329 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14330 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14334 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14335 reading .debug_rnglists.
14336 Callback's type should be:
14337 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14338 Return true if the attributes are present and valid, otherwise,
14341 template <typename Callback
>
14343 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14344 Callback
&&callback
)
14346 struct dwarf2_per_objfile
*dwarf2_per_objfile
14347 = cu
->per_cu
->dwarf2_per_objfile
;
14348 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14349 bfd
*obfd
= objfile
->obfd
;
14350 /* Base address selection entry. */
14353 const gdb_byte
*buffer
;
14354 CORE_ADDR baseaddr
;
14355 bool overflow
= false;
14357 found_base
= cu
->base_known
;
14358 base
= cu
->base_address
;
14360 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14361 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14363 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14367 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14369 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14373 /* Initialize it due to a false compiler warning. */
14374 CORE_ADDR range_beginning
= 0, range_end
= 0;
14375 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14376 + dwarf2_per_objfile
->rnglists
.size
);
14377 unsigned int bytes_read
;
14379 if (buffer
== buf_end
)
14384 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14387 case DW_RLE_end_of_list
:
14389 case DW_RLE_base_address
:
14390 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14395 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14397 buffer
+= bytes_read
;
14399 case DW_RLE_start_length
:
14400 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14405 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14406 buffer
+= bytes_read
;
14407 range_end
= (range_beginning
14408 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14409 buffer
+= bytes_read
;
14410 if (buffer
> buf_end
)
14416 case DW_RLE_offset_pair
:
14417 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14418 buffer
+= bytes_read
;
14419 if (buffer
> buf_end
)
14424 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14425 buffer
+= bytes_read
;
14426 if (buffer
> buf_end
)
14432 case DW_RLE_start_end
:
14433 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14438 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14439 buffer
+= bytes_read
;
14440 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14441 buffer
+= bytes_read
;
14444 complaint (_("Invalid .debug_rnglists data (no base address)"));
14447 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14449 if (rlet
== DW_RLE_base_address
)
14454 /* We have no valid base address for the ranges
14456 complaint (_("Invalid .debug_rnglists data (no base address)"));
14460 if (range_beginning
> range_end
)
14462 /* Inverted range entries are invalid. */
14463 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14467 /* Empty range entries have no effect. */
14468 if (range_beginning
== range_end
)
14471 range_beginning
+= base
;
14474 /* A not-uncommon case of bad debug info.
14475 Don't pollute the addrmap with bad data. */
14476 if (range_beginning
+ baseaddr
== 0
14477 && !dwarf2_per_objfile
->has_section_at_zero
)
14479 complaint (_(".debug_rnglists entry has start address of zero"
14480 " [in module %s]"), objfile_name (objfile
));
14484 callback (range_beginning
, range_end
);
14489 complaint (_("Offset %d is not terminated "
14490 "for DW_AT_ranges attribute"),
14498 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14499 Callback's type should be:
14500 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14501 Return 1 if the attributes are present and valid, otherwise, return 0. */
14503 template <typename Callback
>
14505 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14506 Callback
&&callback
)
14508 struct dwarf2_per_objfile
*dwarf2_per_objfile
14509 = cu
->per_cu
->dwarf2_per_objfile
;
14510 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14511 struct comp_unit_head
*cu_header
= &cu
->header
;
14512 bfd
*obfd
= objfile
->obfd
;
14513 unsigned int addr_size
= cu_header
->addr_size
;
14514 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14515 /* Base address selection entry. */
14518 unsigned int dummy
;
14519 const gdb_byte
*buffer
;
14520 CORE_ADDR baseaddr
;
14522 if (cu_header
->version
>= 5)
14523 return dwarf2_rnglists_process (offset
, cu
, callback
);
14525 found_base
= cu
->base_known
;
14526 base
= cu
->base_address
;
14528 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14529 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14531 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14535 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14537 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14541 CORE_ADDR range_beginning
, range_end
;
14543 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14544 buffer
+= addr_size
;
14545 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14546 buffer
+= addr_size
;
14547 offset
+= 2 * addr_size
;
14549 /* An end of list marker is a pair of zero addresses. */
14550 if (range_beginning
== 0 && range_end
== 0)
14551 /* Found the end of list entry. */
14554 /* Each base address selection entry is a pair of 2 values.
14555 The first is the largest possible address, the second is
14556 the base address. Check for a base address here. */
14557 if ((range_beginning
& mask
) == mask
)
14559 /* If we found the largest possible address, then we already
14560 have the base address in range_end. */
14568 /* We have no valid base address for the ranges
14570 complaint (_("Invalid .debug_ranges data (no base address)"));
14574 if (range_beginning
> range_end
)
14576 /* Inverted range entries are invalid. */
14577 complaint (_("Invalid .debug_ranges data (inverted range)"));
14581 /* Empty range entries have no effect. */
14582 if (range_beginning
== range_end
)
14585 range_beginning
+= base
;
14588 /* A not-uncommon case of bad debug info.
14589 Don't pollute the addrmap with bad data. */
14590 if (range_beginning
+ baseaddr
== 0
14591 && !dwarf2_per_objfile
->has_section_at_zero
)
14593 complaint (_(".debug_ranges entry has start address of zero"
14594 " [in module %s]"), objfile_name (objfile
));
14598 callback (range_beginning
, range_end
);
14604 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14605 Return 1 if the attributes are present and valid, otherwise, return 0.
14606 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14609 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14610 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14611 struct partial_symtab
*ranges_pst
)
14613 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14614 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14615 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14616 SECT_OFF_TEXT (objfile
));
14619 CORE_ADDR high
= 0;
14622 retval
= dwarf2_ranges_process (offset
, cu
,
14623 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14625 if (ranges_pst
!= NULL
)
14630 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14631 range_beginning
+ baseaddr
)
14633 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14634 range_end
+ baseaddr
)
14636 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14637 lowpc
, highpc
- 1, ranges_pst
);
14640 /* FIXME: This is recording everything as a low-high
14641 segment of consecutive addresses. We should have a
14642 data structure for discontiguous block ranges
14646 low
= range_beginning
;
14652 if (range_beginning
< low
)
14653 low
= range_beginning
;
14654 if (range_end
> high
)
14662 /* If the first entry is an end-of-list marker, the range
14663 describes an empty scope, i.e. no instructions. */
14669 *high_return
= high
;
14673 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14674 definition for the return value. *LOWPC and *HIGHPC are set iff
14675 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14677 static enum pc_bounds_kind
14678 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14679 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14680 struct partial_symtab
*pst
)
14682 struct dwarf2_per_objfile
*dwarf2_per_objfile
14683 = cu
->per_cu
->dwarf2_per_objfile
;
14684 struct attribute
*attr
;
14685 struct attribute
*attr_high
;
14687 CORE_ADDR high
= 0;
14688 enum pc_bounds_kind ret
;
14690 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14693 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14694 if (attr
!= nullptr)
14696 low
= attr_value_as_address (attr
);
14697 high
= attr_value_as_address (attr_high
);
14698 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14702 /* Found high w/o low attribute. */
14703 return PC_BOUNDS_INVALID
;
14705 /* Found consecutive range of addresses. */
14706 ret
= PC_BOUNDS_HIGH_LOW
;
14710 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14713 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14714 We take advantage of the fact that DW_AT_ranges does not appear
14715 in DW_TAG_compile_unit of DWO files. */
14716 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14717 unsigned int ranges_offset
= (DW_UNSND (attr
)
14718 + (need_ranges_base
14722 /* Value of the DW_AT_ranges attribute is the offset in the
14723 .debug_ranges section. */
14724 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14725 return PC_BOUNDS_INVALID
;
14726 /* Found discontinuous range of addresses. */
14727 ret
= PC_BOUNDS_RANGES
;
14730 return PC_BOUNDS_NOT_PRESENT
;
14733 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14735 return PC_BOUNDS_INVALID
;
14737 /* When using the GNU linker, .gnu.linkonce. sections are used to
14738 eliminate duplicate copies of functions and vtables and such.
14739 The linker will arbitrarily choose one and discard the others.
14740 The AT_*_pc values for such functions refer to local labels in
14741 these sections. If the section from that file was discarded, the
14742 labels are not in the output, so the relocs get a value of 0.
14743 If this is a discarded function, mark the pc bounds as invalid,
14744 so that GDB will ignore it. */
14745 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14746 return PC_BOUNDS_INVALID
;
14754 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14755 its low and high PC addresses. Do nothing if these addresses could not
14756 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14757 and HIGHPC to the high address if greater than HIGHPC. */
14760 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14762 struct dwarf2_cu
*cu
)
14764 CORE_ADDR low
, high
;
14765 struct die_info
*child
= die
->child
;
14767 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14769 *lowpc
= std::min (*lowpc
, low
);
14770 *highpc
= std::max (*highpc
, high
);
14773 /* If the language does not allow nested subprograms (either inside
14774 subprograms or lexical blocks), we're done. */
14775 if (cu
->language
!= language_ada
)
14778 /* Check all the children of the given DIE. If it contains nested
14779 subprograms, then check their pc bounds. Likewise, we need to
14780 check lexical blocks as well, as they may also contain subprogram
14782 while (child
&& child
->tag
)
14784 if (child
->tag
== DW_TAG_subprogram
14785 || child
->tag
== DW_TAG_lexical_block
)
14786 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14787 child
= sibling_die (child
);
14791 /* Get the low and high pc's represented by the scope DIE, and store
14792 them in *LOWPC and *HIGHPC. If the correct values can't be
14793 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14796 get_scope_pc_bounds (struct die_info
*die
,
14797 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14798 struct dwarf2_cu
*cu
)
14800 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14801 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14802 CORE_ADDR current_low
, current_high
;
14804 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14805 >= PC_BOUNDS_RANGES
)
14807 best_low
= current_low
;
14808 best_high
= current_high
;
14812 struct die_info
*child
= die
->child
;
14814 while (child
&& child
->tag
)
14816 switch (child
->tag
) {
14817 case DW_TAG_subprogram
:
14818 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14820 case DW_TAG_namespace
:
14821 case DW_TAG_module
:
14822 /* FIXME: carlton/2004-01-16: Should we do this for
14823 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14824 that current GCC's always emit the DIEs corresponding
14825 to definitions of methods of classes as children of a
14826 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14827 the DIEs giving the declarations, which could be
14828 anywhere). But I don't see any reason why the
14829 standards says that they have to be there. */
14830 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14832 if (current_low
!= ((CORE_ADDR
) -1))
14834 best_low
= std::min (best_low
, current_low
);
14835 best_high
= std::max (best_high
, current_high
);
14843 child
= sibling_die (child
);
14848 *highpc
= best_high
;
14851 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14855 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14856 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14858 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14859 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14860 struct attribute
*attr
;
14861 struct attribute
*attr_high
;
14863 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14866 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14867 if (attr
!= nullptr)
14869 CORE_ADDR low
= attr_value_as_address (attr
);
14870 CORE_ADDR high
= attr_value_as_address (attr_high
);
14872 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14875 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14876 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14877 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14881 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14882 if (attr
!= nullptr)
14884 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14885 We take advantage of the fact that DW_AT_ranges does not appear
14886 in DW_TAG_compile_unit of DWO files. */
14887 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14889 /* The value of the DW_AT_ranges attribute is the offset of the
14890 address range list in the .debug_ranges section. */
14891 unsigned long offset
= (DW_UNSND (attr
)
14892 + (need_ranges_base
? cu
->ranges_base
: 0));
14894 std::vector
<blockrange
> blockvec
;
14895 dwarf2_ranges_process (offset
, cu
,
14896 [&] (CORE_ADDR start
, CORE_ADDR end
)
14900 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14901 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14902 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14903 blockvec
.emplace_back (start
, end
);
14906 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14910 /* Check whether the producer field indicates either of GCC < 4.6, or the
14911 Intel C/C++ compiler, and cache the result in CU. */
14914 check_producer (struct dwarf2_cu
*cu
)
14918 if (cu
->producer
== NULL
)
14920 /* For unknown compilers expect their behavior is DWARF version
14923 GCC started to support .debug_types sections by -gdwarf-4 since
14924 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14925 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14926 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14927 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14929 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14931 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14932 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14934 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14936 cu
->producer_is_icc
= true;
14937 cu
->producer_is_icc_lt_14
= major
< 14;
14939 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14940 cu
->producer_is_codewarrior
= true;
14943 /* For other non-GCC compilers, expect their behavior is DWARF version
14947 cu
->checked_producer
= true;
14950 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14951 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14952 during 4.6.0 experimental. */
14955 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14957 if (!cu
->checked_producer
)
14958 check_producer (cu
);
14960 return cu
->producer_is_gxx_lt_4_6
;
14964 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14965 with incorrect is_stmt attributes. */
14968 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14970 if (!cu
->checked_producer
)
14971 check_producer (cu
);
14973 return cu
->producer_is_codewarrior
;
14976 /* Return the default accessibility type if it is not overridden by
14977 DW_AT_accessibility. */
14979 static enum dwarf_access_attribute
14980 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14982 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14984 /* The default DWARF 2 accessibility for members is public, the default
14985 accessibility for inheritance is private. */
14987 if (die
->tag
!= DW_TAG_inheritance
)
14988 return DW_ACCESS_public
;
14990 return DW_ACCESS_private
;
14994 /* DWARF 3+ defines the default accessibility a different way. The same
14995 rules apply now for DW_TAG_inheritance as for the members and it only
14996 depends on the container kind. */
14998 if (die
->parent
->tag
== DW_TAG_class_type
)
14999 return DW_ACCESS_private
;
15001 return DW_ACCESS_public
;
15005 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15006 offset. If the attribute was not found return 0, otherwise return
15007 1. If it was found but could not properly be handled, set *OFFSET
15011 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15014 struct attribute
*attr
;
15016 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15021 /* Note that we do not check for a section offset first here.
15022 This is because DW_AT_data_member_location is new in DWARF 4,
15023 so if we see it, we can assume that a constant form is really
15024 a constant and not a section offset. */
15025 if (attr_form_is_constant (attr
))
15026 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15027 else if (attr_form_is_section_offset (attr
))
15028 dwarf2_complex_location_expr_complaint ();
15029 else if (attr_form_is_block (attr
))
15030 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15032 dwarf2_complex_location_expr_complaint ();
15040 /* Add an aggregate field to the field list. */
15043 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15044 struct dwarf2_cu
*cu
)
15046 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15048 struct nextfield
*new_field
;
15049 struct attribute
*attr
;
15051 const char *fieldname
= "";
15053 if (die
->tag
== DW_TAG_inheritance
)
15055 fip
->baseclasses
.emplace_back ();
15056 new_field
= &fip
->baseclasses
.back ();
15060 fip
->fields
.emplace_back ();
15061 new_field
= &fip
->fields
.back ();
15066 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15067 if (attr
!= nullptr)
15068 new_field
->accessibility
= DW_UNSND (attr
);
15070 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15071 if (new_field
->accessibility
!= DW_ACCESS_public
)
15072 fip
->non_public_fields
= 1;
15074 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15075 if (attr
!= nullptr)
15076 new_field
->virtuality
= DW_UNSND (attr
);
15078 new_field
->virtuality
= DW_VIRTUALITY_none
;
15080 fp
= &new_field
->field
;
15082 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15086 /* Data member other than a C++ static data member. */
15088 /* Get type of field. */
15089 fp
->type
= die_type (die
, cu
);
15091 SET_FIELD_BITPOS (*fp
, 0);
15093 /* Get bit size of field (zero if none). */
15094 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15095 if (attr
!= nullptr)
15097 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15101 FIELD_BITSIZE (*fp
) = 0;
15104 /* Get bit offset of field. */
15105 if (handle_data_member_location (die
, cu
, &offset
))
15106 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15107 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15108 if (attr
!= nullptr)
15110 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15112 /* For big endian bits, the DW_AT_bit_offset gives the
15113 additional bit offset from the MSB of the containing
15114 anonymous object to the MSB of the field. We don't
15115 have to do anything special since we don't need to
15116 know the size of the anonymous object. */
15117 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15121 /* For little endian bits, compute the bit offset to the
15122 MSB of the anonymous object, subtract off the number of
15123 bits from the MSB of the field to the MSB of the
15124 object, and then subtract off the number of bits of
15125 the field itself. The result is the bit offset of
15126 the LSB of the field. */
15127 int anonymous_size
;
15128 int bit_offset
= DW_UNSND (attr
);
15130 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15131 if (attr
!= nullptr)
15133 /* The size of the anonymous object containing
15134 the bit field is explicit, so use the
15135 indicated size (in bytes). */
15136 anonymous_size
= DW_UNSND (attr
);
15140 /* The size of the anonymous object containing
15141 the bit field must be inferred from the type
15142 attribute of the data member containing the
15144 anonymous_size
= TYPE_LENGTH (fp
->type
);
15146 SET_FIELD_BITPOS (*fp
,
15147 (FIELD_BITPOS (*fp
)
15148 + anonymous_size
* bits_per_byte
15149 - bit_offset
- FIELD_BITSIZE (*fp
)));
15152 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15154 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15155 + dwarf2_get_attr_constant_value (attr
, 0)));
15157 /* Get name of field. */
15158 fieldname
= dwarf2_name (die
, cu
);
15159 if (fieldname
== NULL
)
15162 /* The name is already allocated along with this objfile, so we don't
15163 need to duplicate it for the type. */
15164 fp
->name
= fieldname
;
15166 /* Change accessibility for artificial fields (e.g. virtual table
15167 pointer or virtual base class pointer) to private. */
15168 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15170 FIELD_ARTIFICIAL (*fp
) = 1;
15171 new_field
->accessibility
= DW_ACCESS_private
;
15172 fip
->non_public_fields
= 1;
15175 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15177 /* C++ static member. */
15179 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15180 is a declaration, but all versions of G++ as of this writing
15181 (so through at least 3.2.1) incorrectly generate
15182 DW_TAG_variable tags. */
15184 const char *physname
;
15186 /* Get name of field. */
15187 fieldname
= dwarf2_name (die
, cu
);
15188 if (fieldname
== NULL
)
15191 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15193 /* Only create a symbol if this is an external value.
15194 new_symbol checks this and puts the value in the global symbol
15195 table, which we want. If it is not external, new_symbol
15196 will try to put the value in cu->list_in_scope which is wrong. */
15197 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15199 /* A static const member, not much different than an enum as far as
15200 we're concerned, except that we can support more types. */
15201 new_symbol (die
, NULL
, cu
);
15204 /* Get physical name. */
15205 physname
= dwarf2_physname (fieldname
, die
, cu
);
15207 /* The name is already allocated along with this objfile, so we don't
15208 need to duplicate it for the type. */
15209 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15210 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15211 FIELD_NAME (*fp
) = fieldname
;
15213 else if (die
->tag
== DW_TAG_inheritance
)
15217 /* C++ base class field. */
15218 if (handle_data_member_location (die
, cu
, &offset
))
15219 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15220 FIELD_BITSIZE (*fp
) = 0;
15221 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15222 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15224 else if (die
->tag
== DW_TAG_variant_part
)
15226 /* process_structure_scope will treat this DIE as a union. */
15227 process_structure_scope (die
, cu
);
15229 /* The variant part is relative to the start of the enclosing
15231 SET_FIELD_BITPOS (*fp
, 0);
15232 fp
->type
= get_die_type (die
, cu
);
15233 fp
->artificial
= 1;
15234 fp
->name
= "<<variant>>";
15236 /* Normally a DW_TAG_variant_part won't have a size, but our
15237 representation requires one, so set it to the maximum of the
15238 child sizes, being sure to account for the offset at which
15239 each child is seen. */
15240 if (TYPE_LENGTH (fp
->type
) == 0)
15243 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15245 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15246 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15250 TYPE_LENGTH (fp
->type
) = max
;
15254 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15257 /* Can the type given by DIE define another type? */
15260 type_can_define_types (const struct die_info
*die
)
15264 case DW_TAG_typedef
:
15265 case DW_TAG_class_type
:
15266 case DW_TAG_structure_type
:
15267 case DW_TAG_union_type
:
15268 case DW_TAG_enumeration_type
:
15276 /* Add a type definition defined in the scope of the FIP's class. */
15279 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15280 struct dwarf2_cu
*cu
)
15282 struct decl_field fp
;
15283 memset (&fp
, 0, sizeof (fp
));
15285 gdb_assert (type_can_define_types (die
));
15287 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15288 fp
.name
= dwarf2_name (die
, cu
);
15289 fp
.type
= read_type_die (die
, cu
);
15291 /* Save accessibility. */
15292 enum dwarf_access_attribute accessibility
;
15293 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15295 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15297 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15298 switch (accessibility
)
15300 case DW_ACCESS_public
:
15301 /* The assumed value if neither private nor protected. */
15303 case DW_ACCESS_private
:
15306 case DW_ACCESS_protected
:
15307 fp
.is_protected
= 1;
15310 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15313 if (die
->tag
== DW_TAG_typedef
)
15314 fip
->typedef_field_list
.push_back (fp
);
15316 fip
->nested_types_list
.push_back (fp
);
15319 /* Create the vector of fields, and attach it to the type. */
15322 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15323 struct dwarf2_cu
*cu
)
15325 int nfields
= fip
->nfields
;
15327 /* Record the field count, allocate space for the array of fields,
15328 and create blank accessibility bitfields if necessary. */
15329 TYPE_NFIELDS (type
) = nfields
;
15330 TYPE_FIELDS (type
) = (struct field
*)
15331 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15333 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15335 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15337 TYPE_FIELD_PRIVATE_BITS (type
) =
15338 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15339 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15341 TYPE_FIELD_PROTECTED_BITS (type
) =
15342 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15343 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15345 TYPE_FIELD_IGNORE_BITS (type
) =
15346 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15347 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15350 /* If the type has baseclasses, allocate and clear a bit vector for
15351 TYPE_FIELD_VIRTUAL_BITS. */
15352 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15354 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15355 unsigned char *pointer
;
15357 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15358 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15359 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15360 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15361 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15364 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15366 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15368 for (int index
= 0; index
< nfields
; ++index
)
15370 struct nextfield
&field
= fip
->fields
[index
];
15372 if (field
.variant
.is_discriminant
)
15373 di
->discriminant_index
= index
;
15374 else if (field
.variant
.default_branch
)
15375 di
->default_index
= index
;
15377 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15381 /* Copy the saved-up fields into the field vector. */
15382 for (int i
= 0; i
< nfields
; ++i
)
15384 struct nextfield
&field
15385 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15386 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15388 TYPE_FIELD (type
, i
) = field
.field
;
15389 switch (field
.accessibility
)
15391 case DW_ACCESS_private
:
15392 if (cu
->language
!= language_ada
)
15393 SET_TYPE_FIELD_PRIVATE (type
, i
);
15396 case DW_ACCESS_protected
:
15397 if (cu
->language
!= language_ada
)
15398 SET_TYPE_FIELD_PROTECTED (type
, i
);
15401 case DW_ACCESS_public
:
15405 /* Unknown accessibility. Complain and treat it as public. */
15407 complaint (_("unsupported accessibility %d"),
15408 field
.accessibility
);
15412 if (i
< fip
->baseclasses
.size ())
15414 switch (field
.virtuality
)
15416 case DW_VIRTUALITY_virtual
:
15417 case DW_VIRTUALITY_pure_virtual
:
15418 if (cu
->language
== language_ada
)
15419 error (_("unexpected virtuality in component of Ada type"));
15420 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15427 /* Return true if this member function is a constructor, false
15431 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15433 const char *fieldname
;
15434 const char *type_name
;
15437 if (die
->parent
== NULL
)
15440 if (die
->parent
->tag
!= DW_TAG_structure_type
15441 && die
->parent
->tag
!= DW_TAG_union_type
15442 && die
->parent
->tag
!= DW_TAG_class_type
)
15445 fieldname
= dwarf2_name (die
, cu
);
15446 type_name
= dwarf2_name (die
->parent
, cu
);
15447 if (fieldname
== NULL
|| type_name
== NULL
)
15450 len
= strlen (fieldname
);
15451 return (strncmp (fieldname
, type_name
, len
) == 0
15452 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15455 /* Check if the given VALUE is a recognized enum
15456 dwarf_defaulted_attribute constant according to DWARF5 spec,
15460 is_valid_DW_AT_defaulted (ULONGEST value
)
15464 case DW_DEFAULTED_no
:
15465 case DW_DEFAULTED_in_class
:
15466 case DW_DEFAULTED_out_of_class
:
15470 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15474 /* Add a member function to the proper fieldlist. */
15477 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15478 struct type
*type
, struct dwarf2_cu
*cu
)
15480 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15481 struct attribute
*attr
;
15483 struct fnfieldlist
*flp
= nullptr;
15484 struct fn_field
*fnp
;
15485 const char *fieldname
;
15486 struct type
*this_type
;
15487 enum dwarf_access_attribute accessibility
;
15489 if (cu
->language
== language_ada
)
15490 error (_("unexpected member function in Ada type"));
15492 /* Get name of member function. */
15493 fieldname
= dwarf2_name (die
, cu
);
15494 if (fieldname
== NULL
)
15497 /* Look up member function name in fieldlist. */
15498 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15500 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15502 flp
= &fip
->fnfieldlists
[i
];
15507 /* Create a new fnfieldlist if necessary. */
15508 if (flp
== nullptr)
15510 fip
->fnfieldlists
.emplace_back ();
15511 flp
= &fip
->fnfieldlists
.back ();
15512 flp
->name
= fieldname
;
15513 i
= fip
->fnfieldlists
.size () - 1;
15516 /* Create a new member function field and add it to the vector of
15518 flp
->fnfields
.emplace_back ();
15519 fnp
= &flp
->fnfields
.back ();
15521 /* Delay processing of the physname until later. */
15522 if (cu
->language
== language_cplus
)
15523 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15527 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15528 fnp
->physname
= physname
? physname
: "";
15531 fnp
->type
= alloc_type (objfile
);
15532 this_type
= read_type_die (die
, cu
);
15533 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15535 int nparams
= TYPE_NFIELDS (this_type
);
15537 /* TYPE is the domain of this method, and THIS_TYPE is the type
15538 of the method itself (TYPE_CODE_METHOD). */
15539 smash_to_method_type (fnp
->type
, type
,
15540 TYPE_TARGET_TYPE (this_type
),
15541 TYPE_FIELDS (this_type
),
15542 TYPE_NFIELDS (this_type
),
15543 TYPE_VARARGS (this_type
));
15545 /* Handle static member functions.
15546 Dwarf2 has no clean way to discern C++ static and non-static
15547 member functions. G++ helps GDB by marking the first
15548 parameter for non-static member functions (which is the this
15549 pointer) as artificial. We obtain this information from
15550 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15551 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15552 fnp
->voffset
= VOFFSET_STATIC
;
15555 complaint (_("member function type missing for '%s'"),
15556 dwarf2_full_name (fieldname
, die
, cu
));
15558 /* Get fcontext from DW_AT_containing_type if present. */
15559 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15560 fnp
->fcontext
= die_containing_type (die
, cu
);
15562 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15563 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15565 /* Get accessibility. */
15566 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15567 if (attr
!= nullptr)
15568 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15570 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15571 switch (accessibility
)
15573 case DW_ACCESS_private
:
15574 fnp
->is_private
= 1;
15576 case DW_ACCESS_protected
:
15577 fnp
->is_protected
= 1;
15581 /* Check for artificial methods. */
15582 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15583 if (attr
&& DW_UNSND (attr
) != 0)
15584 fnp
->is_artificial
= 1;
15586 /* Check for defaulted methods. */
15587 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15588 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15589 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15591 /* Check for deleted methods. */
15592 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15593 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15594 fnp
->is_deleted
= 1;
15596 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15598 /* Get index in virtual function table if it is a virtual member
15599 function. For older versions of GCC, this is an offset in the
15600 appropriate virtual table, as specified by DW_AT_containing_type.
15601 For everyone else, it is an expression to be evaluated relative
15602 to the object address. */
15604 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15605 if (attr
!= nullptr)
15607 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15609 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15611 /* Old-style GCC. */
15612 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15614 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15615 || (DW_BLOCK (attr
)->size
> 1
15616 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15617 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15619 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15620 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15621 dwarf2_complex_location_expr_complaint ();
15623 fnp
->voffset
/= cu
->header
.addr_size
;
15627 dwarf2_complex_location_expr_complaint ();
15629 if (!fnp
->fcontext
)
15631 /* If there is no `this' field and no DW_AT_containing_type,
15632 we cannot actually find a base class context for the
15634 if (TYPE_NFIELDS (this_type
) == 0
15635 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15637 complaint (_("cannot determine context for virtual member "
15638 "function \"%s\" (offset %s)"),
15639 fieldname
, sect_offset_str (die
->sect_off
));
15644 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15648 else if (attr_form_is_section_offset (attr
))
15650 dwarf2_complex_location_expr_complaint ();
15654 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15660 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15661 if (attr
&& DW_UNSND (attr
))
15663 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15664 complaint (_("Member function \"%s\" (offset %s) is virtual "
15665 "but the vtable offset is not specified"),
15666 fieldname
, sect_offset_str (die
->sect_off
));
15667 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15668 TYPE_CPLUS_DYNAMIC (type
) = 1;
15673 /* Create the vector of member function fields, and attach it to the type. */
15676 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15677 struct dwarf2_cu
*cu
)
15679 if (cu
->language
== language_ada
)
15680 error (_("unexpected member functions in Ada type"));
15682 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15683 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15685 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15687 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15689 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15690 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15692 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15693 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15694 fn_flp
->fn_fields
= (struct fn_field
*)
15695 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15697 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15698 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15701 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15704 /* Returns non-zero if NAME is the name of a vtable member in CU's
15705 language, zero otherwise. */
15707 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15709 static const char vptr
[] = "_vptr";
15711 /* Look for the C++ form of the vtable. */
15712 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15718 /* GCC outputs unnamed structures that are really pointers to member
15719 functions, with the ABI-specified layout. If TYPE describes
15720 such a structure, smash it into a member function type.
15722 GCC shouldn't do this; it should just output pointer to member DIEs.
15723 This is GCC PR debug/28767. */
15726 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15728 struct type
*pfn_type
, *self_type
, *new_type
;
15730 /* Check for a structure with no name and two children. */
15731 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15734 /* Check for __pfn and __delta members. */
15735 if (TYPE_FIELD_NAME (type
, 0) == NULL
15736 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15737 || TYPE_FIELD_NAME (type
, 1) == NULL
15738 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15741 /* Find the type of the method. */
15742 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15743 if (pfn_type
== NULL
15744 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15745 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15748 /* Look for the "this" argument. */
15749 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15750 if (TYPE_NFIELDS (pfn_type
) == 0
15751 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15752 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15755 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15756 new_type
= alloc_type (objfile
);
15757 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15758 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15759 TYPE_VARARGS (pfn_type
));
15760 smash_to_methodptr_type (type
, new_type
);
15763 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15764 appropriate error checking and issuing complaints if there is a
15768 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15770 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15772 if (attr
== nullptr)
15775 if (!attr_form_is_constant (attr
))
15777 complaint (_("DW_AT_alignment must have constant form"
15778 " - DIE at %s [in module %s]"),
15779 sect_offset_str (die
->sect_off
),
15780 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15785 if (attr
->form
== DW_FORM_sdata
)
15787 LONGEST val
= DW_SND (attr
);
15790 complaint (_("DW_AT_alignment value must not be negative"
15791 " - DIE at %s [in module %s]"),
15792 sect_offset_str (die
->sect_off
),
15793 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15799 align
= DW_UNSND (attr
);
15803 complaint (_("DW_AT_alignment value must not be zero"
15804 " - DIE at %s [in module %s]"),
15805 sect_offset_str (die
->sect_off
),
15806 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15809 if ((align
& (align
- 1)) != 0)
15811 complaint (_("DW_AT_alignment value must be a power of 2"
15812 " - DIE at %s [in module %s]"),
15813 sect_offset_str (die
->sect_off
),
15814 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15821 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15822 the alignment for TYPE. */
15825 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15828 if (!set_type_align (type
, get_alignment (cu
, die
)))
15829 complaint (_("DW_AT_alignment value too large"
15830 " - DIE at %s [in module %s]"),
15831 sect_offset_str (die
->sect_off
),
15832 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15835 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15836 constant for a type, according to DWARF5 spec, Table 5.5. */
15839 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15844 case DW_CC_pass_by_reference
:
15845 case DW_CC_pass_by_value
:
15849 complaint (_("unrecognized DW_AT_calling_convention value "
15850 "(%s) for a type"), pulongest (value
));
15855 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15856 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15857 also according to GNU-specific values (see include/dwarf2.h). */
15860 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15865 case DW_CC_program
:
15869 case DW_CC_GNU_renesas_sh
:
15870 case DW_CC_GNU_borland_fastcall_i386
:
15871 case DW_CC_GDB_IBM_OpenCL
:
15875 complaint (_("unrecognized DW_AT_calling_convention value "
15876 "(%s) for a subroutine"), pulongest (value
));
15881 /* Called when we find the DIE that starts a structure or union scope
15882 (definition) to create a type for the structure or union. Fill in
15883 the type's name and general properties; the members will not be
15884 processed until process_structure_scope. A symbol table entry for
15885 the type will also not be done until process_structure_scope (assuming
15886 the type has a name).
15888 NOTE: we need to call these functions regardless of whether or not the
15889 DIE has a DW_AT_name attribute, since it might be an anonymous
15890 structure or union. This gets the type entered into our set of
15891 user defined types. */
15893 static struct type
*
15894 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15896 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15898 struct attribute
*attr
;
15901 /* If the definition of this type lives in .debug_types, read that type.
15902 Don't follow DW_AT_specification though, that will take us back up
15903 the chain and we want to go down. */
15904 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15905 if (attr
!= nullptr)
15907 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15909 /* The type's CU may not be the same as CU.
15910 Ensure TYPE is recorded with CU in die_type_hash. */
15911 return set_die_type (die
, type
, cu
);
15914 type
= alloc_type (objfile
);
15915 INIT_CPLUS_SPECIFIC (type
);
15917 name
= dwarf2_name (die
, cu
);
15920 if (cu
->language
== language_cplus
15921 || cu
->language
== language_d
15922 || cu
->language
== language_rust
)
15924 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15926 /* dwarf2_full_name might have already finished building the DIE's
15927 type. If so, there is no need to continue. */
15928 if (get_die_type (die
, cu
) != NULL
)
15929 return get_die_type (die
, cu
);
15931 TYPE_NAME (type
) = full_name
;
15935 /* The name is already allocated along with this objfile, so
15936 we don't need to duplicate it for the type. */
15937 TYPE_NAME (type
) = name
;
15941 if (die
->tag
== DW_TAG_structure_type
)
15943 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15945 else if (die
->tag
== DW_TAG_union_type
)
15947 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15949 else if (die
->tag
== DW_TAG_variant_part
)
15951 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15952 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15956 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15959 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15960 TYPE_DECLARED_CLASS (type
) = 1;
15962 /* Store the calling convention in the type if it's available in
15963 the die. Otherwise the calling convention remains set to
15964 the default value DW_CC_normal. */
15965 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15966 if (attr
!= nullptr
15967 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15969 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15970 TYPE_CPLUS_CALLING_CONVENTION (type
)
15971 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15974 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15975 if (attr
!= nullptr)
15977 if (attr_form_is_constant (attr
))
15978 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15981 /* For the moment, dynamic type sizes are not supported
15982 by GDB's struct type. The actual size is determined
15983 on-demand when resolving the type of a given object,
15984 so set the type's length to zero for now. Otherwise,
15985 we record an expression as the length, and that expression
15986 could lead to a very large value, which could eventually
15987 lead to us trying to allocate that much memory when creating
15988 a value of that type. */
15989 TYPE_LENGTH (type
) = 0;
15994 TYPE_LENGTH (type
) = 0;
15997 maybe_set_alignment (cu
, die
, type
);
15999 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16001 /* ICC<14 does not output the required DW_AT_declaration on
16002 incomplete types, but gives them a size of zero. */
16003 TYPE_STUB (type
) = 1;
16006 TYPE_STUB_SUPPORTED (type
) = 1;
16008 if (die_is_declaration (die
, cu
))
16009 TYPE_STUB (type
) = 1;
16010 else if (attr
== NULL
&& die
->child
== NULL
16011 && producer_is_realview (cu
->producer
))
16012 /* RealView does not output the required DW_AT_declaration
16013 on incomplete types. */
16014 TYPE_STUB (type
) = 1;
16016 /* We need to add the type field to the die immediately so we don't
16017 infinitely recurse when dealing with pointers to the structure
16018 type within the structure itself. */
16019 set_die_type (die
, type
, cu
);
16021 /* set_die_type should be already done. */
16022 set_descriptive_type (type
, die
, cu
);
16027 /* A helper for process_structure_scope that handles a single member
16031 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16032 struct field_info
*fi
,
16033 std::vector
<struct symbol
*> *template_args
,
16034 struct dwarf2_cu
*cu
)
16036 if (child_die
->tag
== DW_TAG_member
16037 || child_die
->tag
== DW_TAG_variable
16038 || child_die
->tag
== DW_TAG_variant_part
)
16040 /* NOTE: carlton/2002-11-05: A C++ static data member
16041 should be a DW_TAG_member that is a declaration, but
16042 all versions of G++ as of this writing (so through at
16043 least 3.2.1) incorrectly generate DW_TAG_variable
16044 tags for them instead. */
16045 dwarf2_add_field (fi
, child_die
, cu
);
16047 else if (child_die
->tag
== DW_TAG_subprogram
)
16049 /* Rust doesn't have member functions in the C++ sense.
16050 However, it does emit ordinary functions as children
16051 of a struct DIE. */
16052 if (cu
->language
== language_rust
)
16053 read_func_scope (child_die
, cu
);
16056 /* C++ member function. */
16057 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16060 else if (child_die
->tag
== DW_TAG_inheritance
)
16062 /* C++ base class field. */
16063 dwarf2_add_field (fi
, child_die
, cu
);
16065 else if (type_can_define_types (child_die
))
16066 dwarf2_add_type_defn (fi
, child_die
, cu
);
16067 else if (child_die
->tag
== DW_TAG_template_type_param
16068 || child_die
->tag
== DW_TAG_template_value_param
)
16070 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16073 template_args
->push_back (arg
);
16075 else if (child_die
->tag
== DW_TAG_variant
)
16077 /* In a variant we want to get the discriminant and also add a
16078 field for our sole member child. */
16079 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16081 for (die_info
*variant_child
= child_die
->child
;
16082 variant_child
!= NULL
;
16083 variant_child
= sibling_die (variant_child
))
16085 if (variant_child
->tag
== DW_TAG_member
)
16087 handle_struct_member_die (variant_child
, type
, fi
,
16088 template_args
, cu
);
16089 /* Only handle the one. */
16094 /* We don't handle this but we might as well report it if we see
16096 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16097 complaint (_("DW_AT_discr_list is not supported yet"
16098 " - DIE at %s [in module %s]"),
16099 sect_offset_str (child_die
->sect_off
),
16100 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16102 /* The first field was just added, so we can stash the
16103 discriminant there. */
16104 gdb_assert (!fi
->fields
.empty ());
16106 fi
->fields
.back ().variant
.default_branch
= true;
16108 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16112 /* Finish creating a structure or union type, including filling in
16113 its members and creating a symbol for it. */
16116 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16118 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16119 struct die_info
*child_die
;
16122 type
= get_die_type (die
, cu
);
16124 type
= read_structure_type (die
, cu
);
16126 /* When reading a DW_TAG_variant_part, we need to notice when we
16127 read the discriminant member, so we can record it later in the
16128 discriminant_info. */
16129 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16130 sect_offset discr_offset
{};
16131 bool has_template_parameters
= false;
16133 if (is_variant_part
)
16135 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16138 /* Maybe it's a univariant form, an extension we support.
16139 In this case arrange not to check the offset. */
16140 is_variant_part
= false;
16142 else if (attr_form_is_ref (discr
))
16144 struct dwarf2_cu
*target_cu
= cu
;
16145 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16147 discr_offset
= target_die
->sect_off
;
16151 complaint (_("DW_AT_discr does not have DIE reference form"
16152 " - DIE at %s [in module %s]"),
16153 sect_offset_str (die
->sect_off
),
16154 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16155 is_variant_part
= false;
16159 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16161 struct field_info fi
;
16162 std::vector
<struct symbol
*> template_args
;
16164 child_die
= die
->child
;
16166 while (child_die
&& child_die
->tag
)
16168 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16170 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16171 fi
.fields
.back ().variant
.is_discriminant
= true;
16173 child_die
= sibling_die (child_die
);
16176 /* Attach template arguments to type. */
16177 if (!template_args
.empty ())
16179 has_template_parameters
= true;
16180 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16181 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16182 TYPE_TEMPLATE_ARGUMENTS (type
)
16183 = XOBNEWVEC (&objfile
->objfile_obstack
,
16185 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16186 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16187 template_args
.data (),
16188 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16189 * sizeof (struct symbol
*)));
16192 /* Attach fields and member functions to the type. */
16194 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16195 if (!fi
.fnfieldlists
.empty ())
16197 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16199 /* Get the type which refers to the base class (possibly this
16200 class itself) which contains the vtable pointer for the current
16201 class from the DW_AT_containing_type attribute. This use of
16202 DW_AT_containing_type is a GNU extension. */
16204 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16206 struct type
*t
= die_containing_type (die
, cu
);
16208 set_type_vptr_basetype (type
, t
);
16213 /* Our own class provides vtbl ptr. */
16214 for (i
= TYPE_NFIELDS (t
) - 1;
16215 i
>= TYPE_N_BASECLASSES (t
);
16218 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16220 if (is_vtable_name (fieldname
, cu
))
16222 set_type_vptr_fieldno (type
, i
);
16227 /* Complain if virtual function table field not found. */
16228 if (i
< TYPE_N_BASECLASSES (t
))
16229 complaint (_("virtual function table pointer "
16230 "not found when defining class '%s'"),
16231 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16235 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16238 else if (cu
->producer
16239 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16241 /* The IBM XLC compiler does not provide direct indication
16242 of the containing type, but the vtable pointer is
16243 always named __vfp. */
16247 for (i
= TYPE_NFIELDS (type
) - 1;
16248 i
>= TYPE_N_BASECLASSES (type
);
16251 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16253 set_type_vptr_fieldno (type
, i
);
16254 set_type_vptr_basetype (type
, type
);
16261 /* Copy fi.typedef_field_list linked list elements content into the
16262 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16263 if (!fi
.typedef_field_list
.empty ())
16265 int count
= fi
.typedef_field_list
.size ();
16267 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16268 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16269 = ((struct decl_field
*)
16271 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16272 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16274 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16275 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16278 /* Copy fi.nested_types_list linked list elements content into the
16279 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16280 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16282 int count
= fi
.nested_types_list
.size ();
16284 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16285 TYPE_NESTED_TYPES_ARRAY (type
)
16286 = ((struct decl_field
*)
16287 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16288 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16290 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16291 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16295 quirk_gcc_member_function_pointer (type
, objfile
);
16296 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16297 cu
->rust_unions
.push_back (type
);
16299 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16300 snapshots) has been known to create a die giving a declaration
16301 for a class that has, as a child, a die giving a definition for a
16302 nested class. So we have to process our children even if the
16303 current die is a declaration. Normally, of course, a declaration
16304 won't have any children at all. */
16306 child_die
= die
->child
;
16308 while (child_die
!= NULL
&& child_die
->tag
)
16310 if (child_die
->tag
== DW_TAG_member
16311 || child_die
->tag
== DW_TAG_variable
16312 || child_die
->tag
== DW_TAG_inheritance
16313 || child_die
->tag
== DW_TAG_template_value_param
16314 || child_die
->tag
== DW_TAG_template_type_param
)
16319 process_die (child_die
, cu
);
16321 child_die
= sibling_die (child_die
);
16324 /* Do not consider external references. According to the DWARF standard,
16325 these DIEs are identified by the fact that they have no byte_size
16326 attribute, and a declaration attribute. */
16327 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16328 || !die_is_declaration (die
, cu
))
16330 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16332 if (has_template_parameters
)
16334 struct symtab
*symtab
;
16335 if (sym
!= nullptr)
16336 symtab
= symbol_symtab (sym
);
16337 else if (cu
->line_header
!= nullptr)
16339 /* Any related symtab will do. */
16341 = cu
->line_header
->file_names ()[0].symtab
;
16346 complaint (_("could not find suitable "
16347 "symtab for template parameter"
16348 " - DIE at %s [in module %s]"),
16349 sect_offset_str (die
->sect_off
),
16350 objfile_name (objfile
));
16353 if (symtab
!= nullptr)
16355 /* Make sure that the symtab is set on the new symbols.
16356 Even though they don't appear in this symtab directly,
16357 other parts of gdb assume that symbols do, and this is
16358 reasonably true. */
16359 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16360 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16366 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16367 update TYPE using some information only available in DIE's children. */
16370 update_enumeration_type_from_children (struct die_info
*die
,
16372 struct dwarf2_cu
*cu
)
16374 struct die_info
*child_die
;
16375 int unsigned_enum
= 1;
16379 auto_obstack obstack
;
16381 for (child_die
= die
->child
;
16382 child_die
!= NULL
&& child_die
->tag
;
16383 child_die
= sibling_die (child_die
))
16385 struct attribute
*attr
;
16387 const gdb_byte
*bytes
;
16388 struct dwarf2_locexpr_baton
*baton
;
16391 if (child_die
->tag
!= DW_TAG_enumerator
)
16394 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16398 name
= dwarf2_name (child_die
, cu
);
16400 name
= "<anonymous enumerator>";
16402 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16403 &value
, &bytes
, &baton
);
16409 else if ((mask
& value
) != 0)
16414 /* If we already know that the enum type is neither unsigned, nor
16415 a flag type, no need to look at the rest of the enumerates. */
16416 if (!unsigned_enum
&& !flag_enum
)
16421 TYPE_UNSIGNED (type
) = 1;
16423 TYPE_FLAG_ENUM (type
) = 1;
16426 /* Given a DW_AT_enumeration_type die, set its type. We do not
16427 complete the type's fields yet, or create any symbols. */
16429 static struct type
*
16430 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16432 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16434 struct attribute
*attr
;
16437 /* If the definition of this type lives in .debug_types, read that type.
16438 Don't follow DW_AT_specification though, that will take us back up
16439 the chain and we want to go down. */
16440 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16441 if (attr
!= nullptr)
16443 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16445 /* The type's CU may not be the same as CU.
16446 Ensure TYPE is recorded with CU in die_type_hash. */
16447 return set_die_type (die
, type
, cu
);
16450 type
= alloc_type (objfile
);
16452 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16453 name
= dwarf2_full_name (NULL
, die
, cu
);
16455 TYPE_NAME (type
) = name
;
16457 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16460 struct type
*underlying_type
= die_type (die
, cu
);
16462 TYPE_TARGET_TYPE (type
) = underlying_type
;
16465 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16466 if (attr
!= nullptr)
16468 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16472 TYPE_LENGTH (type
) = 0;
16475 maybe_set_alignment (cu
, die
, type
);
16477 /* The enumeration DIE can be incomplete. In Ada, any type can be
16478 declared as private in the package spec, and then defined only
16479 inside the package body. Such types are known as Taft Amendment
16480 Types. When another package uses such a type, an incomplete DIE
16481 may be generated by the compiler. */
16482 if (die_is_declaration (die
, cu
))
16483 TYPE_STUB (type
) = 1;
16485 /* Finish the creation of this type by using the enum's children.
16486 We must call this even when the underlying type has been provided
16487 so that we can determine if we're looking at a "flag" enum. */
16488 update_enumeration_type_from_children (die
, type
, cu
);
16490 /* If this type has an underlying type that is not a stub, then we
16491 may use its attributes. We always use the "unsigned" attribute
16492 in this situation, because ordinarily we guess whether the type
16493 is unsigned -- but the guess can be wrong and the underlying type
16494 can tell us the reality. However, we defer to a local size
16495 attribute if one exists, because this lets the compiler override
16496 the underlying type if needed. */
16497 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16499 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16500 if (TYPE_LENGTH (type
) == 0)
16501 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16502 if (TYPE_RAW_ALIGN (type
) == 0
16503 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16504 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16507 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16509 return set_die_type (die
, type
, cu
);
16512 /* Given a pointer to a die which begins an enumeration, process all
16513 the dies that define the members of the enumeration, and create the
16514 symbol for the enumeration type.
16516 NOTE: We reverse the order of the element list. */
16519 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16521 struct type
*this_type
;
16523 this_type
= get_die_type (die
, cu
);
16524 if (this_type
== NULL
)
16525 this_type
= read_enumeration_type (die
, cu
);
16527 if (die
->child
!= NULL
)
16529 struct die_info
*child_die
;
16530 struct symbol
*sym
;
16531 std::vector
<struct field
> fields
;
16534 child_die
= die
->child
;
16535 while (child_die
&& child_die
->tag
)
16537 if (child_die
->tag
!= DW_TAG_enumerator
)
16539 process_die (child_die
, cu
);
16543 name
= dwarf2_name (child_die
, cu
);
16546 sym
= new_symbol (child_die
, this_type
, cu
);
16548 fields
.emplace_back ();
16549 struct field
&field
= fields
.back ();
16551 FIELD_NAME (field
) = sym
->linkage_name ();
16552 FIELD_TYPE (field
) = NULL
;
16553 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16554 FIELD_BITSIZE (field
) = 0;
16558 child_die
= sibling_die (child_die
);
16561 if (!fields
.empty ())
16563 TYPE_NFIELDS (this_type
) = fields
.size ();
16564 TYPE_FIELDS (this_type
) = (struct field
*)
16565 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16566 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16567 sizeof (struct field
) * fields
.size ());
16571 /* If we are reading an enum from a .debug_types unit, and the enum
16572 is a declaration, and the enum is not the signatured type in the
16573 unit, then we do not want to add a symbol for it. Adding a
16574 symbol would in some cases obscure the true definition of the
16575 enum, giving users an incomplete type when the definition is
16576 actually available. Note that we do not want to do this for all
16577 enums which are just declarations, because C++0x allows forward
16578 enum declarations. */
16579 if (cu
->per_cu
->is_debug_types
16580 && die_is_declaration (die
, cu
))
16582 struct signatured_type
*sig_type
;
16584 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16585 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16586 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16590 new_symbol (die
, this_type
, cu
);
16593 /* Extract all information from a DW_TAG_array_type DIE and put it in
16594 the DIE's type field. For now, this only handles one dimensional
16597 static struct type
*
16598 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16600 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16601 struct die_info
*child_die
;
16603 struct type
*element_type
, *range_type
, *index_type
;
16604 struct attribute
*attr
;
16606 struct dynamic_prop
*byte_stride_prop
= NULL
;
16607 unsigned int bit_stride
= 0;
16609 element_type
= die_type (die
, cu
);
16611 /* The die_type call above may have already set the type for this DIE. */
16612 type
= get_die_type (die
, cu
);
16616 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16620 struct type
*prop_type
16621 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16624 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16625 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16629 complaint (_("unable to read array DW_AT_byte_stride "
16630 " - DIE at %s [in module %s]"),
16631 sect_offset_str (die
->sect_off
),
16632 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16633 /* Ignore this attribute. We will likely not be able to print
16634 arrays of this type correctly, but there is little we can do
16635 to help if we cannot read the attribute's value. */
16636 byte_stride_prop
= NULL
;
16640 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16642 bit_stride
= DW_UNSND (attr
);
16644 /* Irix 6.2 native cc creates array types without children for
16645 arrays with unspecified length. */
16646 if (die
->child
== NULL
)
16648 index_type
= objfile_type (objfile
)->builtin_int
;
16649 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16650 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16651 byte_stride_prop
, bit_stride
);
16652 return set_die_type (die
, type
, cu
);
16655 std::vector
<struct type
*> range_types
;
16656 child_die
= die
->child
;
16657 while (child_die
&& child_die
->tag
)
16659 if (child_die
->tag
== DW_TAG_subrange_type
)
16661 struct type
*child_type
= read_type_die (child_die
, cu
);
16663 if (child_type
!= NULL
)
16665 /* The range type was succesfully read. Save it for the
16666 array type creation. */
16667 range_types
.push_back (child_type
);
16670 child_die
= sibling_die (child_die
);
16673 /* Dwarf2 dimensions are output from left to right, create the
16674 necessary array types in backwards order. */
16676 type
= element_type
;
16678 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16682 while (i
< range_types
.size ())
16683 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16684 byte_stride_prop
, bit_stride
);
16688 size_t ndim
= range_types
.size ();
16690 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16691 byte_stride_prop
, bit_stride
);
16694 /* Understand Dwarf2 support for vector types (like they occur on
16695 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16696 array type. This is not part of the Dwarf2/3 standard yet, but a
16697 custom vendor extension. The main difference between a regular
16698 array and the vector variant is that vectors are passed by value
16700 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16701 if (attr
!= nullptr)
16702 make_vector_type (type
);
16704 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16705 implementation may choose to implement triple vectors using this
16707 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16708 if (attr
!= nullptr)
16710 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16711 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16713 complaint (_("DW_AT_byte_size for array type smaller "
16714 "than the total size of elements"));
16717 name
= dwarf2_name (die
, cu
);
16719 TYPE_NAME (type
) = name
;
16721 maybe_set_alignment (cu
, die
, type
);
16723 /* Install the type in the die. */
16724 set_die_type (die
, type
, cu
);
16726 /* set_die_type should be already done. */
16727 set_descriptive_type (type
, die
, cu
);
16732 static enum dwarf_array_dim_ordering
16733 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16735 struct attribute
*attr
;
16737 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16739 if (attr
!= nullptr)
16740 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16742 /* GNU F77 is a special case, as at 08/2004 array type info is the
16743 opposite order to the dwarf2 specification, but data is still
16744 laid out as per normal fortran.
16746 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16747 version checking. */
16749 if (cu
->language
== language_fortran
16750 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16752 return DW_ORD_row_major
;
16755 switch (cu
->language_defn
->la_array_ordering
)
16757 case array_column_major
:
16758 return DW_ORD_col_major
;
16759 case array_row_major
:
16761 return DW_ORD_row_major
;
16765 /* Extract all information from a DW_TAG_set_type DIE and put it in
16766 the DIE's type field. */
16768 static struct type
*
16769 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16771 struct type
*domain_type
, *set_type
;
16772 struct attribute
*attr
;
16774 domain_type
= die_type (die
, cu
);
16776 /* The die_type call above may have already set the type for this DIE. */
16777 set_type
= get_die_type (die
, cu
);
16781 set_type
= create_set_type (NULL
, domain_type
);
16783 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16784 if (attr
!= nullptr)
16785 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16787 maybe_set_alignment (cu
, die
, set_type
);
16789 return set_die_type (die
, set_type
, cu
);
16792 /* A helper for read_common_block that creates a locexpr baton.
16793 SYM is the symbol which we are marking as computed.
16794 COMMON_DIE is the DIE for the common block.
16795 COMMON_LOC is the location expression attribute for the common
16797 MEMBER_LOC is the location expression attribute for the particular
16798 member of the common block that we are processing.
16799 CU is the CU from which the above come. */
16802 mark_common_block_symbol_computed (struct symbol
*sym
,
16803 struct die_info
*common_die
,
16804 struct attribute
*common_loc
,
16805 struct attribute
*member_loc
,
16806 struct dwarf2_cu
*cu
)
16808 struct dwarf2_per_objfile
*dwarf2_per_objfile
16809 = cu
->per_cu
->dwarf2_per_objfile
;
16810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16811 struct dwarf2_locexpr_baton
*baton
;
16813 unsigned int cu_off
;
16814 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16815 LONGEST offset
= 0;
16817 gdb_assert (common_loc
&& member_loc
);
16818 gdb_assert (attr_form_is_block (common_loc
));
16819 gdb_assert (attr_form_is_block (member_loc
)
16820 || attr_form_is_constant (member_loc
));
16822 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16823 baton
->per_cu
= cu
->per_cu
;
16824 gdb_assert (baton
->per_cu
);
16826 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16828 if (attr_form_is_constant (member_loc
))
16830 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16831 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16834 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16836 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16839 *ptr
++ = DW_OP_call4
;
16840 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16841 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16844 if (attr_form_is_constant (member_loc
))
16846 *ptr
++ = DW_OP_addr
;
16847 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16848 ptr
+= cu
->header
.addr_size
;
16852 /* We have to copy the data here, because DW_OP_call4 will only
16853 use a DW_AT_location attribute. */
16854 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16855 ptr
+= DW_BLOCK (member_loc
)->size
;
16858 *ptr
++ = DW_OP_plus
;
16859 gdb_assert (ptr
- baton
->data
== baton
->size
);
16861 SYMBOL_LOCATION_BATON (sym
) = baton
;
16862 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16865 /* Create appropriate locally-scoped variables for all the
16866 DW_TAG_common_block entries. Also create a struct common_block
16867 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16868 is used to separate the common blocks name namespace from regular
16872 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16874 struct attribute
*attr
;
16876 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16877 if (attr
!= nullptr)
16879 /* Support the .debug_loc offsets. */
16880 if (attr_form_is_block (attr
))
16884 else if (attr_form_is_section_offset (attr
))
16886 dwarf2_complex_location_expr_complaint ();
16891 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16892 "common block member");
16897 if (die
->child
!= NULL
)
16899 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16900 struct die_info
*child_die
;
16901 size_t n_entries
= 0, size
;
16902 struct common_block
*common_block
;
16903 struct symbol
*sym
;
16905 for (child_die
= die
->child
;
16906 child_die
&& child_die
->tag
;
16907 child_die
= sibling_die (child_die
))
16910 size
= (sizeof (struct common_block
)
16911 + (n_entries
- 1) * sizeof (struct symbol
*));
16913 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16915 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16916 common_block
->n_entries
= 0;
16918 for (child_die
= die
->child
;
16919 child_die
&& child_die
->tag
;
16920 child_die
= sibling_die (child_die
))
16922 /* Create the symbol in the DW_TAG_common_block block in the current
16924 sym
= new_symbol (child_die
, NULL
, cu
);
16927 struct attribute
*member_loc
;
16929 common_block
->contents
[common_block
->n_entries
++] = sym
;
16931 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16935 /* GDB has handled this for a long time, but it is
16936 not specified by DWARF. It seems to have been
16937 emitted by gfortran at least as recently as:
16938 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16939 complaint (_("Variable in common block has "
16940 "DW_AT_data_member_location "
16941 "- DIE at %s [in module %s]"),
16942 sect_offset_str (child_die
->sect_off
),
16943 objfile_name (objfile
));
16945 if (attr_form_is_section_offset (member_loc
))
16946 dwarf2_complex_location_expr_complaint ();
16947 else if (attr_form_is_constant (member_loc
)
16948 || attr_form_is_block (member_loc
))
16950 if (attr
!= nullptr)
16951 mark_common_block_symbol_computed (sym
, die
, attr
,
16955 dwarf2_complex_location_expr_complaint ();
16960 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16961 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16965 /* Create a type for a C++ namespace. */
16967 static struct type
*
16968 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16970 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16971 const char *previous_prefix
, *name
;
16975 /* For extensions, reuse the type of the original namespace. */
16976 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16978 struct die_info
*ext_die
;
16979 struct dwarf2_cu
*ext_cu
= cu
;
16981 ext_die
= dwarf2_extension (die
, &ext_cu
);
16982 type
= read_type_die (ext_die
, ext_cu
);
16984 /* EXT_CU may not be the same as CU.
16985 Ensure TYPE is recorded with CU in die_type_hash. */
16986 return set_die_type (die
, type
, cu
);
16989 name
= namespace_name (die
, &is_anonymous
, cu
);
16991 /* Now build the name of the current namespace. */
16993 previous_prefix
= determine_prefix (die
, cu
);
16994 if (previous_prefix
[0] != '\0')
16995 name
= typename_concat (&objfile
->objfile_obstack
,
16996 previous_prefix
, name
, 0, cu
);
16998 /* Create the type. */
16999 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17001 return set_die_type (die
, type
, cu
);
17004 /* Read a namespace scope. */
17007 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17009 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17012 /* Add a symbol associated to this if we haven't seen the namespace
17013 before. Also, add a using directive if it's an anonymous
17016 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17020 type
= read_type_die (die
, cu
);
17021 new_symbol (die
, type
, cu
);
17023 namespace_name (die
, &is_anonymous
, cu
);
17026 const char *previous_prefix
= determine_prefix (die
, cu
);
17028 std::vector
<const char *> excludes
;
17029 add_using_directive (using_directives (cu
),
17030 previous_prefix
, TYPE_NAME (type
), NULL
,
17031 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17035 if (die
->child
!= NULL
)
17037 struct die_info
*child_die
= die
->child
;
17039 while (child_die
&& child_die
->tag
)
17041 process_die (child_die
, cu
);
17042 child_die
= sibling_die (child_die
);
17047 /* Read a Fortran module as type. This DIE can be only a declaration used for
17048 imported module. Still we need that type as local Fortran "use ... only"
17049 declaration imports depend on the created type in determine_prefix. */
17051 static struct type
*
17052 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17054 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17055 const char *module_name
;
17058 module_name
= dwarf2_name (die
, cu
);
17059 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17061 return set_die_type (die
, type
, cu
);
17064 /* Read a Fortran module. */
17067 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17069 struct die_info
*child_die
= die
->child
;
17072 type
= read_type_die (die
, cu
);
17073 new_symbol (die
, type
, cu
);
17075 while (child_die
&& child_die
->tag
)
17077 process_die (child_die
, cu
);
17078 child_die
= sibling_die (child_die
);
17082 /* Return the name of the namespace represented by DIE. Set
17083 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17086 static const char *
17087 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17089 struct die_info
*current_die
;
17090 const char *name
= NULL
;
17092 /* Loop through the extensions until we find a name. */
17094 for (current_die
= die
;
17095 current_die
!= NULL
;
17096 current_die
= dwarf2_extension (die
, &cu
))
17098 /* We don't use dwarf2_name here so that we can detect the absence
17099 of a name -> anonymous namespace. */
17100 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17106 /* Is it an anonymous namespace? */
17108 *is_anonymous
= (name
== NULL
);
17110 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17115 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17116 the user defined type vector. */
17118 static struct type
*
17119 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17121 struct gdbarch
*gdbarch
17122 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17123 struct comp_unit_head
*cu_header
= &cu
->header
;
17125 struct attribute
*attr_byte_size
;
17126 struct attribute
*attr_address_class
;
17127 int byte_size
, addr_class
;
17128 struct type
*target_type
;
17130 target_type
= die_type (die
, cu
);
17132 /* The die_type call above may have already set the type for this DIE. */
17133 type
= get_die_type (die
, cu
);
17137 type
= lookup_pointer_type (target_type
);
17139 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17140 if (attr_byte_size
)
17141 byte_size
= DW_UNSND (attr_byte_size
);
17143 byte_size
= cu_header
->addr_size
;
17145 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17146 if (attr_address_class
)
17147 addr_class
= DW_UNSND (attr_address_class
);
17149 addr_class
= DW_ADDR_none
;
17151 ULONGEST alignment
= get_alignment (cu
, die
);
17153 /* If the pointer size, alignment, or address class is different
17154 than the default, create a type variant marked as such and set
17155 the length accordingly. */
17156 if (TYPE_LENGTH (type
) != byte_size
17157 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17158 && alignment
!= TYPE_RAW_ALIGN (type
))
17159 || addr_class
!= DW_ADDR_none
)
17161 if (gdbarch_address_class_type_flags_p (gdbarch
))
17165 type_flags
= gdbarch_address_class_type_flags
17166 (gdbarch
, byte_size
, addr_class
);
17167 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17169 type
= make_type_with_address_space (type
, type_flags
);
17171 else if (TYPE_LENGTH (type
) != byte_size
)
17173 complaint (_("invalid pointer size %d"), byte_size
);
17175 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17177 complaint (_("Invalid DW_AT_alignment"
17178 " - DIE at %s [in module %s]"),
17179 sect_offset_str (die
->sect_off
),
17180 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17184 /* Should we also complain about unhandled address classes? */
17188 TYPE_LENGTH (type
) = byte_size
;
17189 set_type_align (type
, alignment
);
17190 return set_die_type (die
, type
, cu
);
17193 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17194 the user defined type vector. */
17196 static struct type
*
17197 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17200 struct type
*to_type
;
17201 struct type
*domain
;
17203 to_type
= die_type (die
, cu
);
17204 domain
= die_containing_type (die
, cu
);
17206 /* The calls above may have already set the type for this DIE. */
17207 type
= get_die_type (die
, cu
);
17211 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17212 type
= lookup_methodptr_type (to_type
);
17213 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17215 struct type
*new_type
17216 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17218 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17219 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17220 TYPE_VARARGS (to_type
));
17221 type
= lookup_methodptr_type (new_type
);
17224 type
= lookup_memberptr_type (to_type
, domain
);
17226 return set_die_type (die
, type
, cu
);
17229 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17230 the user defined type vector. */
17232 static struct type
*
17233 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17234 enum type_code refcode
)
17236 struct comp_unit_head
*cu_header
= &cu
->header
;
17237 struct type
*type
, *target_type
;
17238 struct attribute
*attr
;
17240 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17242 target_type
= die_type (die
, cu
);
17244 /* The die_type call above may have already set the type for this DIE. */
17245 type
= get_die_type (die
, cu
);
17249 type
= lookup_reference_type (target_type
, refcode
);
17250 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17251 if (attr
!= nullptr)
17253 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17257 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17259 maybe_set_alignment (cu
, die
, type
);
17260 return set_die_type (die
, type
, cu
);
17263 /* Add the given cv-qualifiers to the element type of the array. GCC
17264 outputs DWARF type qualifiers that apply to an array, not the
17265 element type. But GDB relies on the array element type to carry
17266 the cv-qualifiers. This mimics section 6.7.3 of the C99
17269 static struct type
*
17270 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17271 struct type
*base_type
, int cnst
, int voltl
)
17273 struct type
*el_type
, *inner_array
;
17275 base_type
= copy_type (base_type
);
17276 inner_array
= base_type
;
17278 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17280 TYPE_TARGET_TYPE (inner_array
) =
17281 copy_type (TYPE_TARGET_TYPE (inner_array
));
17282 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17285 el_type
= TYPE_TARGET_TYPE (inner_array
);
17286 cnst
|= TYPE_CONST (el_type
);
17287 voltl
|= TYPE_VOLATILE (el_type
);
17288 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17290 return set_die_type (die
, base_type
, cu
);
17293 static struct type
*
17294 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17296 struct type
*base_type
, *cv_type
;
17298 base_type
= die_type (die
, cu
);
17300 /* The die_type call above may have already set the type for this DIE. */
17301 cv_type
= get_die_type (die
, cu
);
17305 /* In case the const qualifier is applied to an array type, the element type
17306 is so qualified, not the array type (section 6.7.3 of C99). */
17307 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17308 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17310 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17311 return set_die_type (die
, cv_type
, cu
);
17314 static struct type
*
17315 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17317 struct type
*base_type
, *cv_type
;
17319 base_type
= die_type (die
, cu
);
17321 /* The die_type call above may have already set the type for this DIE. */
17322 cv_type
= get_die_type (die
, cu
);
17326 /* In case the volatile qualifier is applied to an array type, the
17327 element type is so qualified, not the array type (section 6.7.3
17329 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17330 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17332 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17333 return set_die_type (die
, cv_type
, cu
);
17336 /* Handle DW_TAG_restrict_type. */
17338 static struct type
*
17339 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17341 struct type
*base_type
, *cv_type
;
17343 base_type
= die_type (die
, cu
);
17345 /* The die_type call above may have already set the type for this DIE. */
17346 cv_type
= get_die_type (die
, cu
);
17350 cv_type
= make_restrict_type (base_type
);
17351 return set_die_type (die
, cv_type
, cu
);
17354 /* Handle DW_TAG_atomic_type. */
17356 static struct type
*
17357 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17359 struct type
*base_type
, *cv_type
;
17361 base_type
= die_type (die
, cu
);
17363 /* The die_type call above may have already set the type for this DIE. */
17364 cv_type
= get_die_type (die
, cu
);
17368 cv_type
= make_atomic_type (base_type
);
17369 return set_die_type (die
, cv_type
, cu
);
17372 /* Extract all information from a DW_TAG_string_type DIE and add to
17373 the user defined type vector. It isn't really a user defined type,
17374 but it behaves like one, with other DIE's using an AT_user_def_type
17375 attribute to reference it. */
17377 static struct type
*
17378 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17380 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17381 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17382 struct type
*type
, *range_type
, *index_type
, *char_type
;
17383 struct attribute
*attr
;
17384 struct dynamic_prop prop
;
17385 bool length_is_constant
= true;
17388 /* There are a couple of places where bit sizes might be made use of
17389 when parsing a DW_TAG_string_type, however, no producer that we know
17390 of make use of these. Handling bit sizes that are a multiple of the
17391 byte size is easy enough, but what about other bit sizes? Lets deal
17392 with that problem when we have to. Warn about these attributes being
17393 unsupported, then parse the type and ignore them like we always
17395 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17396 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17398 static bool warning_printed
= false;
17399 if (!warning_printed
)
17401 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17402 "currently supported on DW_TAG_string_type."));
17403 warning_printed
= true;
17407 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17408 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17410 /* The string length describes the location at which the length of
17411 the string can be found. The size of the length field can be
17412 specified with one of the attributes below. */
17413 struct type
*prop_type
;
17414 struct attribute
*len
17415 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17416 if (len
== nullptr)
17417 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17418 if (len
!= nullptr && attr_form_is_constant (len
))
17420 /* Pass 0 as the default as we know this attribute is constant
17421 and the default value will not be returned. */
17422 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17423 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17427 /* If the size is not specified then we assume it is the size of
17428 an address on this target. */
17429 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17432 /* Convert the attribute into a dynamic property. */
17433 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17436 length_is_constant
= false;
17438 else if (attr
!= nullptr)
17440 /* This DW_AT_string_length just contains the length with no
17441 indirection. There's no need to create a dynamic property in this
17442 case. Pass 0 for the default value as we know it will not be
17443 returned in this case. */
17444 length
= dwarf2_get_attr_constant_value (attr
, 0);
17446 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17448 /* We don't currently support non-constant byte sizes for strings. */
17449 length
= dwarf2_get_attr_constant_value (attr
, 1);
17453 /* Use 1 as a fallback length if we have nothing else. */
17457 index_type
= objfile_type (objfile
)->builtin_int
;
17458 if (length_is_constant
)
17459 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17462 struct dynamic_prop low_bound
;
17464 low_bound
.kind
= PROP_CONST
;
17465 low_bound
.data
.const_val
= 1;
17466 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17468 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17469 type
= create_string_type (NULL
, char_type
, range_type
);
17471 return set_die_type (die
, type
, cu
);
17474 /* Assuming that DIE corresponds to a function, returns nonzero
17475 if the function is prototyped. */
17478 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17480 struct attribute
*attr
;
17482 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17483 if (attr
&& (DW_UNSND (attr
) != 0))
17486 /* The DWARF standard implies that the DW_AT_prototyped attribute
17487 is only meaningful for C, but the concept also extends to other
17488 languages that allow unprototyped functions (Eg: Objective C).
17489 For all other languages, assume that functions are always
17491 if (cu
->language
!= language_c
17492 && cu
->language
!= language_objc
17493 && cu
->language
!= language_opencl
)
17496 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17497 prototyped and unprototyped functions; default to prototyped,
17498 since that is more common in modern code (and RealView warns
17499 about unprototyped functions). */
17500 if (producer_is_realview (cu
->producer
))
17506 /* Handle DIES due to C code like:
17510 int (*funcp)(int a, long l);
17514 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17516 static struct type
*
17517 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17519 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17520 struct type
*type
; /* Type that this function returns. */
17521 struct type
*ftype
; /* Function that returns above type. */
17522 struct attribute
*attr
;
17524 type
= die_type (die
, cu
);
17526 /* The die_type call above may have already set the type for this DIE. */
17527 ftype
= get_die_type (die
, cu
);
17531 ftype
= lookup_function_type (type
);
17533 if (prototyped_function_p (die
, cu
))
17534 TYPE_PROTOTYPED (ftype
) = 1;
17536 /* Store the calling convention in the type if it's available in
17537 the subroutine die. Otherwise set the calling convention to
17538 the default value DW_CC_normal. */
17539 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17540 if (attr
!= nullptr
17541 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17542 TYPE_CALLING_CONVENTION (ftype
)
17543 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17544 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17545 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17547 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17549 /* Record whether the function returns normally to its caller or not
17550 if the DWARF producer set that information. */
17551 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17552 if (attr
&& (DW_UNSND (attr
) != 0))
17553 TYPE_NO_RETURN (ftype
) = 1;
17555 /* We need to add the subroutine type to the die immediately so
17556 we don't infinitely recurse when dealing with parameters
17557 declared as the same subroutine type. */
17558 set_die_type (die
, ftype
, cu
);
17560 if (die
->child
!= NULL
)
17562 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17563 struct die_info
*child_die
;
17564 int nparams
, iparams
;
17566 /* Count the number of parameters.
17567 FIXME: GDB currently ignores vararg functions, but knows about
17568 vararg member functions. */
17570 child_die
= die
->child
;
17571 while (child_die
&& child_die
->tag
)
17573 if (child_die
->tag
== DW_TAG_formal_parameter
)
17575 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17576 TYPE_VARARGS (ftype
) = 1;
17577 child_die
= sibling_die (child_die
);
17580 /* Allocate storage for parameters and fill them in. */
17581 TYPE_NFIELDS (ftype
) = nparams
;
17582 TYPE_FIELDS (ftype
) = (struct field
*)
17583 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17585 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17586 even if we error out during the parameters reading below. */
17587 for (iparams
= 0; iparams
< nparams
; iparams
++)
17588 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17591 child_die
= die
->child
;
17592 while (child_die
&& child_die
->tag
)
17594 if (child_die
->tag
== DW_TAG_formal_parameter
)
17596 struct type
*arg_type
;
17598 /* DWARF version 2 has no clean way to discern C++
17599 static and non-static member functions. G++ helps
17600 GDB by marking the first parameter for non-static
17601 member functions (which is the this pointer) as
17602 artificial. We pass this information to
17603 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17605 DWARF version 3 added DW_AT_object_pointer, which GCC
17606 4.5 does not yet generate. */
17607 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17608 if (attr
!= nullptr)
17609 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17611 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17612 arg_type
= die_type (child_die
, cu
);
17614 /* RealView does not mark THIS as const, which the testsuite
17615 expects. GCC marks THIS as const in method definitions,
17616 but not in the class specifications (GCC PR 43053). */
17617 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17618 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17621 struct dwarf2_cu
*arg_cu
= cu
;
17622 const char *name
= dwarf2_name (child_die
, cu
);
17624 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17625 if (attr
!= nullptr)
17627 /* If the compiler emits this, use it. */
17628 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17631 else if (name
&& strcmp (name
, "this") == 0)
17632 /* Function definitions will have the argument names. */
17634 else if (name
== NULL
&& iparams
== 0)
17635 /* Declarations may not have the names, so like
17636 elsewhere in GDB, assume an artificial first
17637 argument is "this". */
17641 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17645 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17648 child_die
= sibling_die (child_die
);
17655 static struct type
*
17656 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17658 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17659 const char *name
= NULL
;
17660 struct type
*this_type
, *target_type
;
17662 name
= dwarf2_full_name (NULL
, die
, cu
);
17663 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17664 TYPE_TARGET_STUB (this_type
) = 1;
17665 set_die_type (die
, this_type
, cu
);
17666 target_type
= die_type (die
, cu
);
17667 if (target_type
!= this_type
)
17668 TYPE_TARGET_TYPE (this_type
) = target_type
;
17671 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17672 spec and cause infinite loops in GDB. */
17673 complaint (_("Self-referential DW_TAG_typedef "
17674 "- DIE at %s [in module %s]"),
17675 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17676 TYPE_TARGET_TYPE (this_type
) = NULL
;
17681 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17682 (which may be different from NAME) to the architecture back-end to allow
17683 it to guess the correct format if necessary. */
17685 static struct type
*
17686 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17687 const char *name_hint
, enum bfd_endian byte_order
)
17689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17690 const struct floatformat
**format
;
17693 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17695 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17697 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17702 /* Allocate an integer type of size BITS and name NAME. */
17704 static struct type
*
17705 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17706 int bits
, int unsigned_p
, const char *name
)
17710 /* Versions of Intel's C Compiler generate an integer type called "void"
17711 instead of using DW_TAG_unspecified_type. This has been seen on
17712 at least versions 14, 17, and 18. */
17713 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17714 && strcmp (name
, "void") == 0)
17715 type
= objfile_type (objfile
)->builtin_void
;
17717 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17722 /* Initialise and return a floating point type of size BITS suitable for
17723 use as a component of a complex number. The NAME_HINT is passed through
17724 when initialising the floating point type and is the name of the complex
17727 As DWARF doesn't currently provide an explicit name for the components
17728 of a complex number, but it can be helpful to have these components
17729 named, we try to select a suitable name based on the size of the
17731 static struct type
*
17732 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17733 struct objfile
*objfile
,
17734 int bits
, const char *name_hint
,
17735 enum bfd_endian byte_order
)
17737 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17738 struct type
*tt
= nullptr;
17740 /* Try to find a suitable floating point builtin type of size BITS.
17741 We're going to use the name of this type as the name for the complex
17742 target type that we are about to create. */
17743 switch (cu
->language
)
17745 case language_fortran
:
17749 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17752 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17754 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17756 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17764 tt
= builtin_type (gdbarch
)->builtin_float
;
17767 tt
= builtin_type (gdbarch
)->builtin_double
;
17769 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17771 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17777 /* If the type we found doesn't match the size we were looking for, then
17778 pretend we didn't find a type at all, the complex target type we
17779 create will then be nameless. */
17780 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17783 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17784 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17787 /* Find a representation of a given base type and install
17788 it in the TYPE field of the die. */
17790 static struct type
*
17791 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17793 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17795 struct attribute
*attr
;
17796 int encoding
= 0, bits
= 0;
17800 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17801 if (attr
!= nullptr)
17802 encoding
= DW_UNSND (attr
);
17803 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17804 if (attr
!= nullptr)
17805 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17806 name
= dwarf2_name (die
, cu
);
17808 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17810 arch
= get_objfile_arch (objfile
);
17811 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17813 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17816 int endianity
= DW_UNSND (attr
);
17821 byte_order
= BFD_ENDIAN_BIG
;
17823 case DW_END_little
:
17824 byte_order
= BFD_ENDIAN_LITTLE
;
17827 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17834 case DW_ATE_address
:
17835 /* Turn DW_ATE_address into a void * pointer. */
17836 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17837 type
= init_pointer_type (objfile
, bits
, name
, type
);
17839 case DW_ATE_boolean
:
17840 type
= init_boolean_type (objfile
, bits
, 1, name
);
17842 case DW_ATE_complex_float
:
17843 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17845 type
= init_complex_type (objfile
, name
, type
);
17847 case DW_ATE_decimal_float
:
17848 type
= init_decfloat_type (objfile
, bits
, name
);
17851 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17853 case DW_ATE_signed
:
17854 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17856 case DW_ATE_unsigned
:
17857 if (cu
->language
== language_fortran
17859 && startswith (name
, "character("))
17860 type
= init_character_type (objfile
, bits
, 1, name
);
17862 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17864 case DW_ATE_signed_char
:
17865 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17866 || cu
->language
== language_pascal
17867 || cu
->language
== language_fortran
)
17868 type
= init_character_type (objfile
, bits
, 0, name
);
17870 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17872 case DW_ATE_unsigned_char
:
17873 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17874 || cu
->language
== language_pascal
17875 || cu
->language
== language_fortran
17876 || cu
->language
== language_rust
)
17877 type
= init_character_type (objfile
, bits
, 1, name
);
17879 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17884 type
= builtin_type (arch
)->builtin_char16
;
17885 else if (bits
== 32)
17886 type
= builtin_type (arch
)->builtin_char32
;
17889 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17891 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17893 return set_die_type (die
, type
, cu
);
17898 complaint (_("unsupported DW_AT_encoding: '%s'"),
17899 dwarf_type_encoding_name (encoding
));
17900 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17904 if (name
&& strcmp (name
, "char") == 0)
17905 TYPE_NOSIGN (type
) = 1;
17907 maybe_set_alignment (cu
, die
, type
);
17909 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17911 return set_die_type (die
, type
, cu
);
17914 /* Parse dwarf attribute if it's a block, reference or constant and put the
17915 resulting value of the attribute into struct bound_prop.
17916 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17919 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17920 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17921 struct type
*default_type
)
17923 struct dwarf2_property_baton
*baton
;
17924 struct obstack
*obstack
17925 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17927 gdb_assert (default_type
!= NULL
);
17929 if (attr
== NULL
|| prop
== NULL
)
17932 if (attr_form_is_block (attr
))
17934 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17935 baton
->property_type
= default_type
;
17936 baton
->locexpr
.per_cu
= cu
->per_cu
;
17937 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17938 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17939 switch (attr
->name
)
17941 case DW_AT_string_length
:
17942 baton
->locexpr
.is_reference
= true;
17945 baton
->locexpr
.is_reference
= false;
17948 prop
->data
.baton
= baton
;
17949 prop
->kind
= PROP_LOCEXPR
;
17950 gdb_assert (prop
->data
.baton
!= NULL
);
17952 else if (attr_form_is_ref (attr
))
17954 struct dwarf2_cu
*target_cu
= cu
;
17955 struct die_info
*target_die
;
17956 struct attribute
*target_attr
;
17958 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17959 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17960 if (target_attr
== NULL
)
17961 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17963 if (target_attr
== NULL
)
17966 switch (target_attr
->name
)
17968 case DW_AT_location
:
17969 if (attr_form_is_section_offset (target_attr
))
17971 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17972 baton
->property_type
= die_type (target_die
, target_cu
);
17973 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17974 prop
->data
.baton
= baton
;
17975 prop
->kind
= PROP_LOCLIST
;
17976 gdb_assert (prop
->data
.baton
!= NULL
);
17978 else if (attr_form_is_block (target_attr
))
17980 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17981 baton
->property_type
= die_type (target_die
, target_cu
);
17982 baton
->locexpr
.per_cu
= cu
->per_cu
;
17983 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17984 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17985 baton
->locexpr
.is_reference
= true;
17986 prop
->data
.baton
= baton
;
17987 prop
->kind
= PROP_LOCEXPR
;
17988 gdb_assert (prop
->data
.baton
!= NULL
);
17992 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17993 "dynamic property");
17997 case DW_AT_data_member_location
:
18001 if (!handle_data_member_location (target_die
, target_cu
,
18005 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18006 baton
->property_type
= read_type_die (target_die
->parent
,
18008 baton
->offset_info
.offset
= offset
;
18009 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18010 prop
->data
.baton
= baton
;
18011 prop
->kind
= PROP_ADDR_OFFSET
;
18016 else if (attr_form_is_constant (attr
))
18018 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18019 prop
->kind
= PROP_CONST
;
18023 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18024 dwarf2_name (die
, cu
));
18031 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18032 UNSIGNED_P controls if the integer is unsigned or not. */
18034 static struct type
*
18035 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18036 int size_in_bytes
, bool unsigned_p
)
18038 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18039 struct type
*int_type
;
18041 /* Helper macro to examine the various builtin types. */
18042 #define TRY_TYPE(F) \
18043 int_type = (unsigned_p \
18044 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18045 : objfile_type (objfile)->builtin_ ## F); \
18046 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18053 TRY_TYPE (long_long
);
18057 gdb_assert_not_reached ("unable to find suitable integer type");
18060 /* Find an integer type the same size as the address size given in the
18061 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18062 is unsigned or not. */
18064 static struct type
*
18065 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18068 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18069 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18072 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18073 present (which is valid) then compute the default type based on the
18074 compilation units address size. */
18076 static struct type
*
18077 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18079 struct type
*index_type
= die_type (die
, cu
);
18081 /* Dwarf-2 specifications explicitly allows to create subrange types
18082 without specifying a base type.
18083 In that case, the base type must be set to the type of
18084 the lower bound, upper bound or count, in that order, if any of these
18085 three attributes references an object that has a type.
18086 If no base type is found, the Dwarf-2 specifications say that
18087 a signed integer type of size equal to the size of an address should
18089 For the following C code: `extern char gdb_int [];'
18090 GCC produces an empty range DIE.
18091 FIXME: muller/2010-05-28: Possible references to object for low bound,
18092 high bound or count are not yet handled by this code. */
18093 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18094 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18099 /* Read the given DW_AT_subrange DIE. */
18101 static struct type
*
18102 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18104 struct type
*base_type
, *orig_base_type
;
18105 struct type
*range_type
;
18106 struct attribute
*attr
;
18107 struct dynamic_prop low
, high
;
18108 int low_default_is_valid
;
18109 int high_bound_is_count
= 0;
18111 ULONGEST negative_mask
;
18113 orig_base_type
= read_subrange_index_type (die
, cu
);
18115 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18116 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18117 creating the range type, but we use the result of check_typedef
18118 when examining properties of the type. */
18119 base_type
= check_typedef (orig_base_type
);
18121 /* The die_type call above may have already set the type for this DIE. */
18122 range_type
= get_die_type (die
, cu
);
18126 low
.kind
= PROP_CONST
;
18127 high
.kind
= PROP_CONST
;
18128 high
.data
.const_val
= 0;
18130 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18131 omitting DW_AT_lower_bound. */
18132 switch (cu
->language
)
18135 case language_cplus
:
18136 low
.data
.const_val
= 0;
18137 low_default_is_valid
= 1;
18139 case language_fortran
:
18140 low
.data
.const_val
= 1;
18141 low_default_is_valid
= 1;
18144 case language_objc
:
18145 case language_rust
:
18146 low
.data
.const_val
= 0;
18147 low_default_is_valid
= (cu
->header
.version
>= 4);
18151 case language_pascal
:
18152 low
.data
.const_val
= 1;
18153 low_default_is_valid
= (cu
->header
.version
>= 4);
18156 low
.data
.const_val
= 0;
18157 low_default_is_valid
= 0;
18161 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18162 if (attr
!= nullptr)
18163 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18164 else if (!low_default_is_valid
)
18165 complaint (_("Missing DW_AT_lower_bound "
18166 "- DIE at %s [in module %s]"),
18167 sect_offset_str (die
->sect_off
),
18168 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18170 struct attribute
*attr_ub
, *attr_count
;
18171 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18172 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18174 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18175 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18177 /* If bounds are constant do the final calculation here. */
18178 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18179 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18181 high_bound_is_count
= 1;
18185 if (attr_ub
!= NULL
)
18186 complaint (_("Unresolved DW_AT_upper_bound "
18187 "- DIE at %s [in module %s]"),
18188 sect_offset_str (die
->sect_off
),
18189 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18190 if (attr_count
!= NULL
)
18191 complaint (_("Unresolved DW_AT_count "
18192 "- DIE at %s [in module %s]"),
18193 sect_offset_str (die
->sect_off
),
18194 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18199 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18200 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18201 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18203 /* Normally, the DWARF producers are expected to use a signed
18204 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18205 But this is unfortunately not always the case, as witnessed
18206 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18207 is used instead. To work around that ambiguity, we treat
18208 the bounds as signed, and thus sign-extend their values, when
18209 the base type is signed. */
18211 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18212 if (low
.kind
== PROP_CONST
18213 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18214 low
.data
.const_val
|= negative_mask
;
18215 if (high
.kind
== PROP_CONST
18216 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18217 high
.data
.const_val
|= negative_mask
;
18219 /* Check for bit and byte strides. */
18220 struct dynamic_prop byte_stride_prop
;
18221 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18222 if (attr_byte_stride
!= nullptr)
18224 struct type
*prop_type
18225 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18226 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18230 struct dynamic_prop bit_stride_prop
;
18231 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18232 if (attr_bit_stride
!= nullptr)
18234 /* It only makes sense to have either a bit or byte stride. */
18235 if (attr_byte_stride
!= nullptr)
18237 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18238 "- DIE at %s [in module %s]"),
18239 sect_offset_str (die
->sect_off
),
18240 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18241 attr_bit_stride
= nullptr;
18245 struct type
*prop_type
18246 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18247 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18252 if (attr_byte_stride
!= nullptr
18253 || attr_bit_stride
!= nullptr)
18255 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18256 struct dynamic_prop
*stride
18257 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18260 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18261 &high
, bias
, stride
, byte_stride_p
);
18264 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18266 if (high_bound_is_count
)
18267 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18269 /* Ada expects an empty array on no boundary attributes. */
18270 if (attr
== NULL
&& cu
->language
!= language_ada
)
18271 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18273 name
= dwarf2_name (die
, cu
);
18275 TYPE_NAME (range_type
) = name
;
18277 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18278 if (attr
!= nullptr)
18279 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18281 maybe_set_alignment (cu
, die
, range_type
);
18283 set_die_type (die
, range_type
, cu
);
18285 /* set_die_type should be already done. */
18286 set_descriptive_type (range_type
, die
, cu
);
18291 static struct type
*
18292 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18296 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18298 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18300 /* In Ada, an unspecified type is typically used when the description
18301 of the type is deferred to a different unit. When encountering
18302 such a type, we treat it as a stub, and try to resolve it later on,
18304 if (cu
->language
== language_ada
)
18305 TYPE_STUB (type
) = 1;
18307 return set_die_type (die
, type
, cu
);
18310 /* Read a single die and all its descendents. Set the die's sibling
18311 field to NULL; set other fields in the die correctly, and set all
18312 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18313 location of the info_ptr after reading all of those dies. PARENT
18314 is the parent of the die in question. */
18316 static struct die_info
*
18317 read_die_and_children (const struct die_reader_specs
*reader
,
18318 const gdb_byte
*info_ptr
,
18319 const gdb_byte
**new_info_ptr
,
18320 struct die_info
*parent
)
18322 struct die_info
*die
;
18323 const gdb_byte
*cur_ptr
;
18326 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18329 *new_info_ptr
= cur_ptr
;
18332 store_in_ref_table (die
, reader
->cu
);
18335 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18339 *new_info_ptr
= cur_ptr
;
18342 die
->sibling
= NULL
;
18343 die
->parent
= parent
;
18347 /* Read a die, all of its descendents, and all of its siblings; set
18348 all of the fields of all of the dies correctly. Arguments are as
18349 in read_die_and_children. */
18351 static struct die_info
*
18352 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18353 const gdb_byte
*info_ptr
,
18354 const gdb_byte
**new_info_ptr
,
18355 struct die_info
*parent
)
18357 struct die_info
*first_die
, *last_sibling
;
18358 const gdb_byte
*cur_ptr
;
18360 cur_ptr
= info_ptr
;
18361 first_die
= last_sibling
= NULL
;
18365 struct die_info
*die
18366 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18370 *new_info_ptr
= cur_ptr
;
18377 last_sibling
->sibling
= die
;
18379 last_sibling
= die
;
18383 /* Read a die, all of its descendents, and all of its siblings; set
18384 all of the fields of all of the dies correctly. Arguments are as
18385 in read_die_and_children.
18386 This the main entry point for reading a DIE and all its children. */
18388 static struct die_info
*
18389 read_die_and_siblings (const struct die_reader_specs
*reader
,
18390 const gdb_byte
*info_ptr
,
18391 const gdb_byte
**new_info_ptr
,
18392 struct die_info
*parent
)
18394 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18395 new_info_ptr
, parent
);
18397 if (dwarf_die_debug
)
18399 fprintf_unfiltered (gdb_stdlog
,
18400 "Read die from %s@0x%x of %s:\n",
18401 get_section_name (reader
->die_section
),
18402 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18403 bfd_get_filename (reader
->abfd
));
18404 dump_die (die
, dwarf_die_debug
);
18410 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18412 The caller is responsible for filling in the extra attributes
18413 and updating (*DIEP)->num_attrs.
18414 Set DIEP to point to a newly allocated die with its information,
18415 except for its child, sibling, and parent fields.
18416 Set HAS_CHILDREN to tell whether the die has children or not. */
18418 static const gdb_byte
*
18419 read_full_die_1 (const struct die_reader_specs
*reader
,
18420 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18421 int *has_children
, int num_extra_attrs
)
18423 unsigned int abbrev_number
, bytes_read
, i
;
18424 struct abbrev_info
*abbrev
;
18425 struct die_info
*die
;
18426 struct dwarf2_cu
*cu
= reader
->cu
;
18427 bfd
*abfd
= reader
->abfd
;
18429 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18430 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18431 info_ptr
+= bytes_read
;
18432 if (!abbrev_number
)
18439 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18441 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18443 bfd_get_filename (abfd
));
18445 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18446 die
->sect_off
= sect_off
;
18447 die
->tag
= abbrev
->tag
;
18448 die
->abbrev
= abbrev_number
;
18450 /* Make the result usable.
18451 The caller needs to update num_attrs after adding the extra
18453 die
->num_attrs
= abbrev
->num_attrs
;
18455 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18456 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18460 *has_children
= abbrev
->has_children
;
18464 /* Read a die and all its attributes.
18465 Set DIEP to point to a newly allocated die with its information,
18466 except for its child, sibling, and parent fields.
18467 Set HAS_CHILDREN to tell whether the die has children or not. */
18469 static const gdb_byte
*
18470 read_full_die (const struct die_reader_specs
*reader
,
18471 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18474 const gdb_byte
*result
;
18476 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18478 if (dwarf_die_debug
)
18480 fprintf_unfiltered (gdb_stdlog
,
18481 "Read die from %s@0x%x of %s:\n",
18482 get_section_name (reader
->die_section
),
18483 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18484 bfd_get_filename (reader
->abfd
));
18485 dump_die (*diep
, dwarf_die_debug
);
18491 /* Abbreviation tables.
18493 In DWARF version 2, the description of the debugging information is
18494 stored in a separate .debug_abbrev section. Before we read any
18495 dies from a section we read in all abbreviations and install them
18496 in a hash table. */
18498 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18500 struct abbrev_info
*
18501 abbrev_table::alloc_abbrev ()
18503 struct abbrev_info
*abbrev
;
18505 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18506 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18511 /* Add an abbreviation to the table. */
18514 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18515 struct abbrev_info
*abbrev
)
18517 unsigned int hash_number
;
18519 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18520 abbrev
->next
= m_abbrevs
[hash_number
];
18521 m_abbrevs
[hash_number
] = abbrev
;
18524 /* Look up an abbrev in the table.
18525 Returns NULL if the abbrev is not found. */
18527 struct abbrev_info
*
18528 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18530 unsigned int hash_number
;
18531 struct abbrev_info
*abbrev
;
18533 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18534 abbrev
= m_abbrevs
[hash_number
];
18538 if (abbrev
->number
== abbrev_number
)
18540 abbrev
= abbrev
->next
;
18545 /* Read in an abbrev table. */
18547 static abbrev_table_up
18548 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18549 struct dwarf2_section_info
*section
,
18550 sect_offset sect_off
)
18552 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18553 bfd
*abfd
= get_section_bfd_owner (section
);
18554 const gdb_byte
*abbrev_ptr
;
18555 struct abbrev_info
*cur_abbrev
;
18556 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18557 unsigned int abbrev_form
;
18558 std::vector
<struct attr_abbrev
> cur_attrs
;
18560 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18562 dwarf2_read_section (objfile
, section
);
18563 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18564 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18565 abbrev_ptr
+= bytes_read
;
18567 /* Loop until we reach an abbrev number of 0. */
18568 while (abbrev_number
)
18570 cur_attrs
.clear ();
18571 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18573 /* read in abbrev header */
18574 cur_abbrev
->number
= abbrev_number
;
18576 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18577 abbrev_ptr
+= bytes_read
;
18578 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18581 /* now read in declarations */
18584 LONGEST implicit_const
;
18586 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18587 abbrev_ptr
+= bytes_read
;
18588 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18589 abbrev_ptr
+= bytes_read
;
18590 if (abbrev_form
== DW_FORM_implicit_const
)
18592 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18594 abbrev_ptr
+= bytes_read
;
18598 /* Initialize it due to a false compiler warning. */
18599 implicit_const
= -1;
18602 if (abbrev_name
== 0)
18605 cur_attrs
.emplace_back ();
18606 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18607 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18608 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18609 cur_attr
.implicit_const
= implicit_const
;
18610 ++cur_abbrev
->num_attrs
;
18613 cur_abbrev
->attrs
=
18614 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18615 cur_abbrev
->num_attrs
);
18616 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18617 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18619 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18621 /* Get next abbreviation.
18622 Under Irix6 the abbreviations for a compilation unit are not
18623 always properly terminated with an abbrev number of 0.
18624 Exit loop if we encounter an abbreviation which we have
18625 already read (which means we are about to read the abbreviations
18626 for the next compile unit) or if the end of the abbreviation
18627 table is reached. */
18628 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18630 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18631 abbrev_ptr
+= bytes_read
;
18632 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18636 return abbrev_table
;
18639 /* Returns nonzero if TAG represents a type that we might generate a partial
18643 is_type_tag_for_partial (int tag
)
18648 /* Some types that would be reasonable to generate partial symbols for,
18649 that we don't at present. */
18650 case DW_TAG_array_type
:
18651 case DW_TAG_file_type
:
18652 case DW_TAG_ptr_to_member_type
:
18653 case DW_TAG_set_type
:
18654 case DW_TAG_string_type
:
18655 case DW_TAG_subroutine_type
:
18657 case DW_TAG_base_type
:
18658 case DW_TAG_class_type
:
18659 case DW_TAG_interface_type
:
18660 case DW_TAG_enumeration_type
:
18661 case DW_TAG_structure_type
:
18662 case DW_TAG_subrange_type
:
18663 case DW_TAG_typedef
:
18664 case DW_TAG_union_type
:
18671 /* Load all DIEs that are interesting for partial symbols into memory. */
18673 static struct partial_die_info
*
18674 load_partial_dies (const struct die_reader_specs
*reader
,
18675 const gdb_byte
*info_ptr
, int building_psymtab
)
18677 struct dwarf2_cu
*cu
= reader
->cu
;
18678 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18679 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18680 unsigned int bytes_read
;
18681 unsigned int load_all
= 0;
18682 int nesting_level
= 1;
18687 gdb_assert (cu
->per_cu
!= NULL
);
18688 if (cu
->per_cu
->load_all_dies
)
18692 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18696 &cu
->comp_unit_obstack
,
18697 hashtab_obstack_allocate
,
18698 dummy_obstack_deallocate
);
18702 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18704 /* A NULL abbrev means the end of a series of children. */
18705 if (abbrev
== NULL
)
18707 if (--nesting_level
== 0)
18710 info_ptr
+= bytes_read
;
18711 last_die
= parent_die
;
18712 parent_die
= parent_die
->die_parent
;
18716 /* Check for template arguments. We never save these; if
18717 they're seen, we just mark the parent, and go on our way. */
18718 if (parent_die
!= NULL
18719 && cu
->language
== language_cplus
18720 && (abbrev
->tag
== DW_TAG_template_type_param
18721 || abbrev
->tag
== DW_TAG_template_value_param
))
18723 parent_die
->has_template_arguments
= 1;
18727 /* We don't need a partial DIE for the template argument. */
18728 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18733 /* We only recurse into c++ subprograms looking for template arguments.
18734 Skip their other children. */
18736 && cu
->language
== language_cplus
18737 && parent_die
!= NULL
18738 && parent_die
->tag
== DW_TAG_subprogram
)
18740 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18744 /* Check whether this DIE is interesting enough to save. Normally
18745 we would not be interested in members here, but there may be
18746 later variables referencing them via DW_AT_specification (for
18747 static members). */
18749 && !is_type_tag_for_partial (abbrev
->tag
)
18750 && abbrev
->tag
!= DW_TAG_constant
18751 && abbrev
->tag
!= DW_TAG_enumerator
18752 && abbrev
->tag
!= DW_TAG_subprogram
18753 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18754 && abbrev
->tag
!= DW_TAG_lexical_block
18755 && abbrev
->tag
!= DW_TAG_variable
18756 && abbrev
->tag
!= DW_TAG_namespace
18757 && abbrev
->tag
!= DW_TAG_module
18758 && abbrev
->tag
!= DW_TAG_member
18759 && abbrev
->tag
!= DW_TAG_imported_unit
18760 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18762 /* Otherwise we skip to the next sibling, if any. */
18763 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18767 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18770 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18772 /* This two-pass algorithm for processing partial symbols has a
18773 high cost in cache pressure. Thus, handle some simple cases
18774 here which cover the majority of C partial symbols. DIEs
18775 which neither have specification tags in them, nor could have
18776 specification tags elsewhere pointing at them, can simply be
18777 processed and discarded.
18779 This segment is also optional; scan_partial_symbols and
18780 add_partial_symbol will handle these DIEs if we chain
18781 them in normally. When compilers which do not emit large
18782 quantities of duplicate debug information are more common,
18783 this code can probably be removed. */
18785 /* Any complete simple types at the top level (pretty much all
18786 of them, for a language without namespaces), can be processed
18788 if (parent_die
== NULL
18789 && pdi
.has_specification
== 0
18790 && pdi
.is_declaration
== 0
18791 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18792 || pdi
.tag
== DW_TAG_base_type
18793 || pdi
.tag
== DW_TAG_subrange_type
))
18795 if (building_psymtab
&& pdi
.name
!= NULL
)
18796 add_psymbol_to_list (pdi
.name
, false,
18797 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18798 psymbol_placement::STATIC
,
18799 0, cu
->language
, objfile
);
18800 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18804 /* The exception for DW_TAG_typedef with has_children above is
18805 a workaround of GCC PR debug/47510. In the case of this complaint
18806 type_name_or_error will error on such types later.
18808 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18809 it could not find the child DIEs referenced later, this is checked
18810 above. In correct DWARF DW_TAG_typedef should have no children. */
18812 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18813 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18814 "- DIE at %s [in module %s]"),
18815 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18817 /* If we're at the second level, and we're an enumerator, and
18818 our parent has no specification (meaning possibly lives in a
18819 namespace elsewhere), then we can add the partial symbol now
18820 instead of queueing it. */
18821 if (pdi
.tag
== DW_TAG_enumerator
18822 && parent_die
!= NULL
18823 && parent_die
->die_parent
== NULL
18824 && parent_die
->tag
== DW_TAG_enumeration_type
18825 && parent_die
->has_specification
== 0)
18827 if (pdi
.name
== NULL
)
18828 complaint (_("malformed enumerator DIE ignored"));
18829 else if (building_psymtab
)
18830 add_psymbol_to_list (pdi
.name
, false,
18831 VAR_DOMAIN
, LOC_CONST
, -1,
18832 cu
->language
== language_cplus
18833 ? psymbol_placement::GLOBAL
18834 : psymbol_placement::STATIC
,
18835 0, cu
->language
, objfile
);
18837 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18841 struct partial_die_info
*part_die
18842 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18844 /* We'll save this DIE so link it in. */
18845 part_die
->die_parent
= parent_die
;
18846 part_die
->die_sibling
= NULL
;
18847 part_die
->die_child
= NULL
;
18849 if (last_die
&& last_die
== parent_die
)
18850 last_die
->die_child
= part_die
;
18852 last_die
->die_sibling
= part_die
;
18854 last_die
= part_die
;
18856 if (first_die
== NULL
)
18857 first_die
= part_die
;
18859 /* Maybe add the DIE to the hash table. Not all DIEs that we
18860 find interesting need to be in the hash table, because we
18861 also have the parent/sibling/child chains; only those that we
18862 might refer to by offset later during partial symbol reading.
18864 For now this means things that might have be the target of a
18865 DW_AT_specification, DW_AT_abstract_origin, or
18866 DW_AT_extension. DW_AT_extension will refer only to
18867 namespaces; DW_AT_abstract_origin refers to functions (and
18868 many things under the function DIE, but we do not recurse
18869 into function DIEs during partial symbol reading) and
18870 possibly variables as well; DW_AT_specification refers to
18871 declarations. Declarations ought to have the DW_AT_declaration
18872 flag. It happens that GCC forgets to put it in sometimes, but
18873 only for functions, not for types.
18875 Adding more things than necessary to the hash table is harmless
18876 except for the performance cost. Adding too few will result in
18877 wasted time in find_partial_die, when we reread the compilation
18878 unit with load_all_dies set. */
18881 || abbrev
->tag
== DW_TAG_constant
18882 || abbrev
->tag
== DW_TAG_subprogram
18883 || abbrev
->tag
== DW_TAG_variable
18884 || abbrev
->tag
== DW_TAG_namespace
18885 || part_die
->is_declaration
)
18889 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18890 to_underlying (part_die
->sect_off
),
18895 /* For some DIEs we want to follow their children (if any). For C
18896 we have no reason to follow the children of structures; for other
18897 languages we have to, so that we can get at method physnames
18898 to infer fully qualified class names, for DW_AT_specification,
18899 and for C++ template arguments. For C++, we also look one level
18900 inside functions to find template arguments (if the name of the
18901 function does not already contain the template arguments).
18903 For Ada and Fortran, we need to scan the children of subprograms
18904 and lexical blocks as well because these languages allow the
18905 definition of nested entities that could be interesting for the
18906 debugger, such as nested subprograms for instance. */
18907 if (last_die
->has_children
18909 || last_die
->tag
== DW_TAG_namespace
18910 || last_die
->tag
== DW_TAG_module
18911 || last_die
->tag
== DW_TAG_enumeration_type
18912 || (cu
->language
== language_cplus
18913 && last_die
->tag
== DW_TAG_subprogram
18914 && (last_die
->name
== NULL
18915 || strchr (last_die
->name
, '<') == NULL
))
18916 || (cu
->language
!= language_c
18917 && (last_die
->tag
== DW_TAG_class_type
18918 || last_die
->tag
== DW_TAG_interface_type
18919 || last_die
->tag
== DW_TAG_structure_type
18920 || last_die
->tag
== DW_TAG_union_type
))
18921 || ((cu
->language
== language_ada
18922 || cu
->language
== language_fortran
)
18923 && (last_die
->tag
== DW_TAG_subprogram
18924 || last_die
->tag
== DW_TAG_lexical_block
))))
18927 parent_die
= last_die
;
18931 /* Otherwise we skip to the next sibling, if any. */
18932 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18934 /* Back to the top, do it again. */
18938 partial_die_info::partial_die_info (sect_offset sect_off_
,
18939 struct abbrev_info
*abbrev
)
18940 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18944 /* Read a minimal amount of information into the minimal die structure.
18945 INFO_PTR should point just after the initial uleb128 of a DIE. */
18948 partial_die_info::read (const struct die_reader_specs
*reader
,
18949 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18951 struct dwarf2_cu
*cu
= reader
->cu
;
18952 struct dwarf2_per_objfile
*dwarf2_per_objfile
18953 = cu
->per_cu
->dwarf2_per_objfile
;
18955 int has_low_pc_attr
= 0;
18956 int has_high_pc_attr
= 0;
18957 int high_pc_relative
= 0;
18959 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18961 struct attribute attr
;
18963 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18965 /* Store the data if it is of an attribute we want to keep in a
18966 partial symbol table. */
18972 case DW_TAG_compile_unit
:
18973 case DW_TAG_partial_unit
:
18974 case DW_TAG_type_unit
:
18975 /* Compilation units have a DW_AT_name that is a filename, not
18976 a source language identifier. */
18977 case DW_TAG_enumeration_type
:
18978 case DW_TAG_enumerator
:
18979 /* These tags always have simple identifiers already; no need
18980 to canonicalize them. */
18981 name
= DW_STRING (&attr
);
18985 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18988 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18989 &objfile
->per_bfd
->storage_obstack
);
18994 case DW_AT_linkage_name
:
18995 case DW_AT_MIPS_linkage_name
:
18996 /* Note that both forms of linkage name might appear. We
18997 assume they will be the same, and we only store the last
18999 linkage_name
= DW_STRING (&attr
);
19002 has_low_pc_attr
= 1;
19003 lowpc
= attr_value_as_address (&attr
);
19005 case DW_AT_high_pc
:
19006 has_high_pc_attr
= 1;
19007 highpc
= attr_value_as_address (&attr
);
19008 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19009 high_pc_relative
= 1;
19011 case DW_AT_location
:
19012 /* Support the .debug_loc offsets. */
19013 if (attr_form_is_block (&attr
))
19015 d
.locdesc
= DW_BLOCK (&attr
);
19017 else if (attr_form_is_section_offset (&attr
))
19019 dwarf2_complex_location_expr_complaint ();
19023 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19024 "partial symbol information");
19027 case DW_AT_external
:
19028 is_external
= DW_UNSND (&attr
);
19030 case DW_AT_declaration
:
19031 is_declaration
= DW_UNSND (&attr
);
19036 case DW_AT_abstract_origin
:
19037 case DW_AT_specification
:
19038 case DW_AT_extension
:
19039 has_specification
= 1;
19040 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19041 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19042 || cu
->per_cu
->is_dwz
);
19044 case DW_AT_sibling
:
19045 /* Ignore absolute siblings, they might point outside of
19046 the current compile unit. */
19047 if (attr
.form
== DW_FORM_ref_addr
)
19048 complaint (_("ignoring absolute DW_AT_sibling"));
19051 const gdb_byte
*buffer
= reader
->buffer
;
19052 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19053 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19055 if (sibling_ptr
< info_ptr
)
19056 complaint (_("DW_AT_sibling points backwards"));
19057 else if (sibling_ptr
> reader
->buffer_end
)
19058 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19060 sibling
= sibling_ptr
;
19063 case DW_AT_byte_size
:
19066 case DW_AT_const_value
:
19067 has_const_value
= 1;
19069 case DW_AT_calling_convention
:
19070 /* DWARF doesn't provide a way to identify a program's source-level
19071 entry point. DW_AT_calling_convention attributes are only meant
19072 to describe functions' calling conventions.
19074 However, because it's a necessary piece of information in
19075 Fortran, and before DWARF 4 DW_CC_program was the only
19076 piece of debugging information whose definition refers to
19077 a 'main program' at all, several compilers marked Fortran
19078 main programs with DW_CC_program --- even when those
19079 functions use the standard calling conventions.
19081 Although DWARF now specifies a way to provide this
19082 information, we support this practice for backward
19084 if (DW_UNSND (&attr
) == DW_CC_program
19085 && cu
->language
== language_fortran
)
19086 main_subprogram
= 1;
19089 if (DW_UNSND (&attr
) == DW_INL_inlined
19090 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19091 may_be_inlined
= 1;
19095 if (tag
== DW_TAG_imported_unit
)
19097 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19098 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19099 || cu
->per_cu
->is_dwz
);
19103 case DW_AT_main_subprogram
:
19104 main_subprogram
= DW_UNSND (&attr
);
19109 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19110 but that requires a full DIE, so instead we just
19112 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19113 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19114 + (need_ranges_base
19118 /* Value of the DW_AT_ranges attribute is the offset in the
19119 .debug_ranges section. */
19120 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19131 /* For Ada, if both the name and the linkage name appear, we prefer
19132 the latter. This lets "catch exception" work better, regardless
19133 of the order in which the name and linkage name were emitted.
19134 Really, though, this is just a workaround for the fact that gdb
19135 doesn't store both the name and the linkage name. */
19136 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19137 name
= linkage_name
;
19139 if (high_pc_relative
)
19142 if (has_low_pc_attr
&& has_high_pc_attr
)
19144 /* When using the GNU linker, .gnu.linkonce. sections are used to
19145 eliminate duplicate copies of functions and vtables and such.
19146 The linker will arbitrarily choose one and discard the others.
19147 The AT_*_pc values for such functions refer to local labels in
19148 these sections. If the section from that file was discarded, the
19149 labels are not in the output, so the relocs get a value of 0.
19150 If this is a discarded function, mark the pc bounds as invalid,
19151 so that GDB will ignore it. */
19152 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19154 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19155 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19157 complaint (_("DW_AT_low_pc %s is zero "
19158 "for DIE at %s [in module %s]"),
19159 paddress (gdbarch
, lowpc
),
19160 sect_offset_str (sect_off
),
19161 objfile_name (objfile
));
19163 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19164 else if (lowpc
>= highpc
)
19166 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19167 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19169 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19170 "for DIE at %s [in module %s]"),
19171 paddress (gdbarch
, lowpc
),
19172 paddress (gdbarch
, highpc
),
19173 sect_offset_str (sect_off
),
19174 objfile_name (objfile
));
19183 /* Find a cached partial DIE at OFFSET in CU. */
19185 struct partial_die_info
*
19186 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19188 struct partial_die_info
*lookup_die
= NULL
;
19189 struct partial_die_info
part_die (sect_off
);
19191 lookup_die
= ((struct partial_die_info
*)
19192 htab_find_with_hash (partial_dies
, &part_die
,
19193 to_underlying (sect_off
)));
19198 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19199 except in the case of .debug_types DIEs which do not reference
19200 outside their CU (they do however referencing other types via
19201 DW_FORM_ref_sig8). */
19203 static const struct cu_partial_die_info
19204 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19206 struct dwarf2_per_objfile
*dwarf2_per_objfile
19207 = cu
->per_cu
->dwarf2_per_objfile
;
19208 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19209 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19210 struct partial_die_info
*pd
= NULL
;
19212 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19213 && offset_in_cu_p (&cu
->header
, sect_off
))
19215 pd
= cu
->find_partial_die (sect_off
);
19218 /* We missed recording what we needed.
19219 Load all dies and try again. */
19220 per_cu
= cu
->per_cu
;
19224 /* TUs don't reference other CUs/TUs (except via type signatures). */
19225 if (cu
->per_cu
->is_debug_types
)
19227 error (_("Dwarf Error: Type Unit at offset %s contains"
19228 " external reference to offset %s [in module %s].\n"),
19229 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19230 bfd_get_filename (objfile
->obfd
));
19232 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19233 dwarf2_per_objfile
);
19235 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19236 load_partial_comp_unit (per_cu
);
19238 per_cu
->cu
->last_used
= 0;
19239 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19242 /* If we didn't find it, and not all dies have been loaded,
19243 load them all and try again. */
19245 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19247 per_cu
->load_all_dies
= 1;
19249 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19250 THIS_CU->cu may already be in use. So we can't just free it and
19251 replace its DIEs with the ones we read in. Instead, we leave those
19252 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19253 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19255 load_partial_comp_unit (per_cu
);
19257 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19261 internal_error (__FILE__
, __LINE__
,
19262 _("could not find partial DIE %s "
19263 "in cache [from module %s]\n"),
19264 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19265 return { per_cu
->cu
, pd
};
19268 /* See if we can figure out if the class lives in a namespace. We do
19269 this by looking for a member function; its demangled name will
19270 contain namespace info, if there is any. */
19273 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19274 struct dwarf2_cu
*cu
)
19276 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19277 what template types look like, because the demangler
19278 frequently doesn't give the same name as the debug info. We
19279 could fix this by only using the demangled name to get the
19280 prefix (but see comment in read_structure_type). */
19282 struct partial_die_info
*real_pdi
;
19283 struct partial_die_info
*child_pdi
;
19285 /* If this DIE (this DIE's specification, if any) has a parent, then
19286 we should not do this. We'll prepend the parent's fully qualified
19287 name when we create the partial symbol. */
19289 real_pdi
= struct_pdi
;
19290 while (real_pdi
->has_specification
)
19292 auto res
= find_partial_die (real_pdi
->spec_offset
,
19293 real_pdi
->spec_is_dwz
, cu
);
19294 real_pdi
= res
.pdi
;
19298 if (real_pdi
->die_parent
!= NULL
)
19301 for (child_pdi
= struct_pdi
->die_child
;
19303 child_pdi
= child_pdi
->die_sibling
)
19305 if (child_pdi
->tag
== DW_TAG_subprogram
19306 && child_pdi
->linkage_name
!= NULL
)
19308 gdb::unique_xmalloc_ptr
<char> actual_class_name
19309 (language_class_name_from_physname (cu
->language_defn
,
19310 child_pdi
->linkage_name
));
19311 if (actual_class_name
!= NULL
)
19313 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19315 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19316 actual_class_name
.get ());
19324 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19326 /* Once we've fixed up a die, there's no point in doing so again.
19327 This also avoids a memory leak if we were to call
19328 guess_partial_die_structure_name multiple times. */
19332 /* If we found a reference attribute and the DIE has no name, try
19333 to find a name in the referred to DIE. */
19335 if (name
== NULL
&& has_specification
)
19337 struct partial_die_info
*spec_die
;
19339 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19340 spec_die
= res
.pdi
;
19343 spec_die
->fixup (cu
);
19345 if (spec_die
->name
)
19347 name
= spec_die
->name
;
19349 /* Copy DW_AT_external attribute if it is set. */
19350 if (spec_die
->is_external
)
19351 is_external
= spec_die
->is_external
;
19355 /* Set default names for some unnamed DIEs. */
19357 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19358 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19360 /* If there is no parent die to provide a namespace, and there are
19361 children, see if we can determine the namespace from their linkage
19363 if (cu
->language
== language_cplus
19364 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19365 && die_parent
== NULL
19367 && (tag
== DW_TAG_class_type
19368 || tag
== DW_TAG_structure_type
19369 || tag
== DW_TAG_union_type
))
19370 guess_partial_die_structure_name (this, cu
);
19372 /* GCC might emit a nameless struct or union that has a linkage
19373 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19375 && (tag
== DW_TAG_class_type
19376 || tag
== DW_TAG_interface_type
19377 || tag
== DW_TAG_structure_type
19378 || tag
== DW_TAG_union_type
)
19379 && linkage_name
!= NULL
)
19381 gdb::unique_xmalloc_ptr
<char> demangled
19382 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19383 if (demangled
!= nullptr)
19387 /* Strip any leading namespaces/classes, keep only the base name.
19388 DW_AT_name for named DIEs does not contain the prefixes. */
19389 base
= strrchr (demangled
.get (), ':');
19390 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19393 base
= demangled
.get ();
19395 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19396 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19403 /* Read an attribute value described by an attribute form. */
19405 static const gdb_byte
*
19406 read_attribute_value (const struct die_reader_specs
*reader
,
19407 struct attribute
*attr
, unsigned form
,
19408 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19410 struct dwarf2_cu
*cu
= reader
->cu
;
19411 struct dwarf2_per_objfile
*dwarf2_per_objfile
19412 = cu
->per_cu
->dwarf2_per_objfile
;
19413 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19414 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19415 bfd
*abfd
= reader
->abfd
;
19416 struct comp_unit_head
*cu_header
= &cu
->header
;
19417 unsigned int bytes_read
;
19418 struct dwarf_block
*blk
;
19420 attr
->form
= (enum dwarf_form
) form
;
19423 case DW_FORM_ref_addr
:
19424 if (cu
->header
.version
== 2)
19425 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19427 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19428 &cu
->header
, &bytes_read
);
19429 info_ptr
+= bytes_read
;
19431 case DW_FORM_GNU_ref_alt
:
19432 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19433 info_ptr
+= bytes_read
;
19436 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19437 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19438 info_ptr
+= bytes_read
;
19440 case DW_FORM_block2
:
19441 blk
= dwarf_alloc_block (cu
);
19442 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19444 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19445 info_ptr
+= blk
->size
;
19446 DW_BLOCK (attr
) = blk
;
19448 case DW_FORM_block4
:
19449 blk
= dwarf_alloc_block (cu
);
19450 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19452 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19453 info_ptr
+= blk
->size
;
19454 DW_BLOCK (attr
) = blk
;
19456 case DW_FORM_data2
:
19457 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19460 case DW_FORM_data4
:
19461 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19464 case DW_FORM_data8
:
19465 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19468 case DW_FORM_data16
:
19469 blk
= dwarf_alloc_block (cu
);
19471 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19473 DW_BLOCK (attr
) = blk
;
19475 case DW_FORM_sec_offset
:
19476 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19477 info_ptr
+= bytes_read
;
19479 case DW_FORM_string
:
19480 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19481 DW_STRING_IS_CANONICAL (attr
) = 0;
19482 info_ptr
+= bytes_read
;
19485 if (!cu
->per_cu
->is_dwz
)
19487 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19488 abfd
, info_ptr
, cu_header
,
19490 DW_STRING_IS_CANONICAL (attr
) = 0;
19491 info_ptr
+= bytes_read
;
19495 case DW_FORM_line_strp
:
19496 if (!cu
->per_cu
->is_dwz
)
19498 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19500 cu_header
, &bytes_read
);
19501 DW_STRING_IS_CANONICAL (attr
) = 0;
19502 info_ptr
+= bytes_read
;
19506 case DW_FORM_GNU_strp_alt
:
19508 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19509 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19512 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19514 DW_STRING_IS_CANONICAL (attr
) = 0;
19515 info_ptr
+= bytes_read
;
19518 case DW_FORM_exprloc
:
19519 case DW_FORM_block
:
19520 blk
= dwarf_alloc_block (cu
);
19521 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19522 info_ptr
+= bytes_read
;
19523 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19524 info_ptr
+= blk
->size
;
19525 DW_BLOCK (attr
) = blk
;
19527 case DW_FORM_block1
:
19528 blk
= dwarf_alloc_block (cu
);
19529 blk
->size
= read_1_byte (abfd
, info_ptr
);
19531 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19532 info_ptr
+= blk
->size
;
19533 DW_BLOCK (attr
) = blk
;
19535 case DW_FORM_data1
:
19536 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19540 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19543 case DW_FORM_flag_present
:
19544 DW_UNSND (attr
) = 1;
19546 case DW_FORM_sdata
:
19547 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19548 info_ptr
+= bytes_read
;
19550 case DW_FORM_udata
:
19551 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19552 info_ptr
+= bytes_read
;
19555 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19556 + read_1_byte (abfd
, info_ptr
));
19560 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19561 + read_2_bytes (abfd
, info_ptr
));
19565 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19566 + read_4_bytes (abfd
, info_ptr
));
19570 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19571 + read_8_bytes (abfd
, info_ptr
));
19574 case DW_FORM_ref_sig8
:
19575 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19578 case DW_FORM_ref_udata
:
19579 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19580 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19581 info_ptr
+= bytes_read
;
19583 case DW_FORM_indirect
:
19584 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19585 info_ptr
+= bytes_read
;
19586 if (form
== DW_FORM_implicit_const
)
19588 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19589 info_ptr
+= bytes_read
;
19591 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19594 case DW_FORM_implicit_const
:
19595 DW_SND (attr
) = implicit_const
;
19597 case DW_FORM_addrx
:
19598 case DW_FORM_GNU_addr_index
:
19599 if (reader
->dwo_file
== NULL
)
19601 /* For now flag a hard error.
19602 Later we can turn this into a complaint. */
19603 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19604 dwarf_form_name (form
),
19605 bfd_get_filename (abfd
));
19607 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19608 info_ptr
+= bytes_read
;
19611 case DW_FORM_strx1
:
19612 case DW_FORM_strx2
:
19613 case DW_FORM_strx3
:
19614 case DW_FORM_strx4
:
19615 case DW_FORM_GNU_str_index
:
19616 if (reader
->dwo_file
== NULL
)
19618 /* For now flag a hard error.
19619 Later we can turn this into a complaint if warranted. */
19620 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19621 dwarf_form_name (form
),
19622 bfd_get_filename (abfd
));
19625 ULONGEST str_index
;
19626 if (form
== DW_FORM_strx1
)
19628 str_index
= read_1_byte (abfd
, info_ptr
);
19631 else if (form
== DW_FORM_strx2
)
19633 str_index
= read_2_bytes (abfd
, info_ptr
);
19636 else if (form
== DW_FORM_strx3
)
19638 str_index
= read_3_bytes (abfd
, info_ptr
);
19641 else if (form
== DW_FORM_strx4
)
19643 str_index
= read_4_bytes (abfd
, info_ptr
);
19648 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19649 info_ptr
+= bytes_read
;
19651 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19652 DW_STRING_IS_CANONICAL (attr
) = 0;
19656 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19657 dwarf_form_name (form
),
19658 bfd_get_filename (abfd
));
19662 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19663 attr
->form
= DW_FORM_GNU_ref_alt
;
19665 /* We have seen instances where the compiler tried to emit a byte
19666 size attribute of -1 which ended up being encoded as an unsigned
19667 0xffffffff. Although 0xffffffff is technically a valid size value,
19668 an object of this size seems pretty unlikely so we can relatively
19669 safely treat these cases as if the size attribute was invalid and
19670 treat them as zero by default. */
19671 if (attr
->name
== DW_AT_byte_size
19672 && form
== DW_FORM_data4
19673 && DW_UNSND (attr
) >= 0xffffffff)
19676 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19677 hex_string (DW_UNSND (attr
)));
19678 DW_UNSND (attr
) = 0;
19684 /* Read an attribute described by an abbreviated attribute. */
19686 static const gdb_byte
*
19687 read_attribute (const struct die_reader_specs
*reader
,
19688 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19689 const gdb_byte
*info_ptr
)
19691 attr
->name
= abbrev
->name
;
19692 return read_attribute_value (reader
, attr
, abbrev
->form
,
19693 abbrev
->implicit_const
, info_ptr
);
19696 /* Read dwarf information from a buffer. */
19698 static unsigned int
19699 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19701 return bfd_get_8 (abfd
, buf
);
19705 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19707 return bfd_get_signed_8 (abfd
, buf
);
19710 static unsigned int
19711 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19713 return bfd_get_16 (abfd
, buf
);
19717 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19719 return bfd_get_signed_16 (abfd
, buf
);
19722 static unsigned int
19723 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19725 unsigned int result
= 0;
19726 for (int i
= 0; i
< 3; ++i
)
19728 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19730 result
|= ((unsigned int) byte
<< (i
* 8));
19735 static unsigned int
19736 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19738 return bfd_get_32 (abfd
, buf
);
19742 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19744 return bfd_get_signed_32 (abfd
, buf
);
19748 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19750 return bfd_get_64 (abfd
, buf
);
19754 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19755 unsigned int *bytes_read
)
19757 struct comp_unit_head
*cu_header
= &cu
->header
;
19758 CORE_ADDR retval
= 0;
19760 if (cu_header
->signed_addr_p
)
19762 switch (cu_header
->addr_size
)
19765 retval
= bfd_get_signed_16 (abfd
, buf
);
19768 retval
= bfd_get_signed_32 (abfd
, buf
);
19771 retval
= bfd_get_signed_64 (abfd
, buf
);
19774 internal_error (__FILE__
, __LINE__
,
19775 _("read_address: bad switch, signed [in module %s]"),
19776 bfd_get_filename (abfd
));
19781 switch (cu_header
->addr_size
)
19784 retval
= bfd_get_16 (abfd
, buf
);
19787 retval
= bfd_get_32 (abfd
, buf
);
19790 retval
= bfd_get_64 (abfd
, buf
);
19793 internal_error (__FILE__
, __LINE__
,
19794 _("read_address: bad switch, "
19795 "unsigned [in module %s]"),
19796 bfd_get_filename (abfd
));
19800 *bytes_read
= cu_header
->addr_size
;
19804 /* Read the initial length from a section. The (draft) DWARF 3
19805 specification allows the initial length to take up either 4 bytes
19806 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19807 bytes describe the length and all offsets will be 8 bytes in length
19810 An older, non-standard 64-bit format is also handled by this
19811 function. The older format in question stores the initial length
19812 as an 8-byte quantity without an escape value. Lengths greater
19813 than 2^32 aren't very common which means that the initial 4 bytes
19814 is almost always zero. Since a length value of zero doesn't make
19815 sense for the 32-bit format, this initial zero can be considered to
19816 be an escape value which indicates the presence of the older 64-bit
19817 format. As written, the code can't detect (old format) lengths
19818 greater than 4GB. If it becomes necessary to handle lengths
19819 somewhat larger than 4GB, we could allow other small values (such
19820 as the non-sensical values of 1, 2, and 3) to also be used as
19821 escape values indicating the presence of the old format.
19823 The value returned via bytes_read should be used to increment the
19824 relevant pointer after calling read_initial_length().
19826 [ Note: read_initial_length() and read_offset() are based on the
19827 document entitled "DWARF Debugging Information Format", revision
19828 3, draft 8, dated November 19, 2001. This document was obtained
19831 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19833 This document is only a draft and is subject to change. (So beware.)
19835 Details regarding the older, non-standard 64-bit format were
19836 determined empirically by examining 64-bit ELF files produced by
19837 the SGI toolchain on an IRIX 6.5 machine.
19839 - Kevin, July 16, 2002
19843 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19845 LONGEST length
= bfd_get_32 (abfd
, buf
);
19847 if (length
== 0xffffffff)
19849 length
= bfd_get_64 (abfd
, buf
+ 4);
19852 else if (length
== 0)
19854 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19855 length
= bfd_get_64 (abfd
, buf
);
19866 /* Cover function for read_initial_length.
19867 Returns the length of the object at BUF, and stores the size of the
19868 initial length in *BYTES_READ and stores the size that offsets will be in
19870 If the initial length size is not equivalent to that specified in
19871 CU_HEADER then issue a complaint.
19872 This is useful when reading non-comp-unit headers. */
19875 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19876 const struct comp_unit_head
*cu_header
,
19877 unsigned int *bytes_read
,
19878 unsigned int *offset_size
)
19880 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19882 gdb_assert (cu_header
->initial_length_size
== 4
19883 || cu_header
->initial_length_size
== 8
19884 || cu_header
->initial_length_size
== 12);
19886 if (cu_header
->initial_length_size
!= *bytes_read
)
19887 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19889 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19893 /* Read an offset from the data stream. The size of the offset is
19894 given by cu_header->offset_size. */
19897 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19898 const struct comp_unit_head
*cu_header
,
19899 unsigned int *bytes_read
)
19901 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19903 *bytes_read
= cu_header
->offset_size
;
19907 /* Read an offset from the data stream. */
19910 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19912 LONGEST retval
= 0;
19914 switch (offset_size
)
19917 retval
= bfd_get_32 (abfd
, buf
);
19920 retval
= bfd_get_64 (abfd
, buf
);
19923 internal_error (__FILE__
, __LINE__
,
19924 _("read_offset_1: bad switch [in module %s]"),
19925 bfd_get_filename (abfd
));
19931 static const gdb_byte
*
19932 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19934 /* If the size of a host char is 8 bits, we can return a pointer
19935 to the buffer, otherwise we have to copy the data to a buffer
19936 allocated on the temporary obstack. */
19937 gdb_assert (HOST_CHAR_BIT
== 8);
19941 static const char *
19942 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19943 unsigned int *bytes_read_ptr
)
19945 /* If the size of a host char is 8 bits, we can return a pointer
19946 to the string, otherwise we have to copy the string to a buffer
19947 allocated on the temporary obstack. */
19948 gdb_assert (HOST_CHAR_BIT
== 8);
19951 *bytes_read_ptr
= 1;
19954 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19955 return (const char *) buf
;
19958 /* Return pointer to string at section SECT offset STR_OFFSET with error
19959 reporting strings FORM_NAME and SECT_NAME. */
19961 static const char *
19962 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19963 bfd
*abfd
, LONGEST str_offset
,
19964 struct dwarf2_section_info
*sect
,
19965 const char *form_name
,
19966 const char *sect_name
)
19968 dwarf2_read_section (objfile
, sect
);
19969 if (sect
->buffer
== NULL
)
19970 error (_("%s used without %s section [in module %s]"),
19971 form_name
, sect_name
, bfd_get_filename (abfd
));
19972 if (str_offset
>= sect
->size
)
19973 error (_("%s pointing outside of %s section [in module %s]"),
19974 form_name
, sect_name
, bfd_get_filename (abfd
));
19975 gdb_assert (HOST_CHAR_BIT
== 8);
19976 if (sect
->buffer
[str_offset
] == '\0')
19978 return (const char *) (sect
->buffer
+ str_offset
);
19981 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19983 static const char *
19984 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19985 bfd
*abfd
, LONGEST str_offset
)
19987 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19989 &dwarf2_per_objfile
->str
,
19990 "DW_FORM_strp", ".debug_str");
19993 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19995 static const char *
19996 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19997 bfd
*abfd
, LONGEST str_offset
)
19999 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20001 &dwarf2_per_objfile
->line_str
,
20002 "DW_FORM_line_strp",
20003 ".debug_line_str");
20006 /* Read a string at offset STR_OFFSET in the .debug_str section from
20007 the .dwz file DWZ. Throw an error if the offset is too large. If
20008 the string consists of a single NUL byte, return NULL; otherwise
20009 return a pointer to the string. */
20011 static const char *
20012 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20013 LONGEST str_offset
)
20015 dwarf2_read_section (objfile
, &dwz
->str
);
20017 if (dwz
->str
.buffer
== NULL
)
20018 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20019 "section [in module %s]"),
20020 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20021 if (str_offset
>= dwz
->str
.size
)
20022 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20023 ".debug_str section [in module %s]"),
20024 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20025 gdb_assert (HOST_CHAR_BIT
== 8);
20026 if (dwz
->str
.buffer
[str_offset
] == '\0')
20028 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20031 /* Return pointer to string at .debug_str offset as read from BUF.
20032 BUF is assumed to be in a compilation unit described by CU_HEADER.
20033 Return *BYTES_READ_PTR count of bytes read from BUF. */
20035 static const char *
20036 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20037 const gdb_byte
*buf
,
20038 const struct comp_unit_head
*cu_header
,
20039 unsigned int *bytes_read_ptr
)
20041 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20043 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20046 /* Return pointer to string at .debug_line_str offset as read from BUF.
20047 BUF is assumed to be in a compilation unit described by CU_HEADER.
20048 Return *BYTES_READ_PTR count of bytes read from BUF. */
20050 static const char *
20051 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20052 bfd
*abfd
, const gdb_byte
*buf
,
20053 const struct comp_unit_head
*cu_header
,
20054 unsigned int *bytes_read_ptr
)
20056 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20058 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20063 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20064 unsigned int *bytes_read_ptr
)
20067 unsigned int num_read
;
20069 unsigned char byte
;
20076 byte
= bfd_get_8 (abfd
, buf
);
20079 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20080 if ((byte
& 128) == 0)
20086 *bytes_read_ptr
= num_read
;
20091 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20092 unsigned int *bytes_read_ptr
)
20095 int shift
, num_read
;
20096 unsigned char byte
;
20103 byte
= bfd_get_8 (abfd
, buf
);
20106 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20108 if ((byte
& 128) == 0)
20113 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20114 result
|= -(((ULONGEST
) 1) << shift
);
20115 *bytes_read_ptr
= num_read
;
20119 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20120 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
20121 ADDR_SIZE is the size of addresses from the CU header. */
20124 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20125 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
20127 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20128 bfd
*abfd
= objfile
->obfd
;
20129 const gdb_byte
*info_ptr
;
20131 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20132 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20133 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20134 objfile_name (objfile
));
20135 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
20136 error (_("DW_FORM_addr_index pointing outside of "
20137 ".debug_addr section [in module %s]"),
20138 objfile_name (objfile
));
20139 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20140 + addr_base
+ addr_index
* addr_size
);
20141 if (addr_size
== 4)
20142 return bfd_get_32 (abfd
, info_ptr
);
20144 return bfd_get_64 (abfd
, info_ptr
);
20147 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20150 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20152 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20153 cu
->addr_base
, cu
->header
.addr_size
);
20156 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20159 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20160 unsigned int *bytes_read
)
20162 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20163 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20165 return read_addr_index (cu
, addr_index
);
20168 /* Data structure to pass results from dwarf2_read_addr_index_reader
20169 back to dwarf2_read_addr_index. */
20171 struct dwarf2_read_addr_index_data
20173 ULONGEST addr_base
;
20177 /* die_reader_func for dwarf2_read_addr_index. */
20180 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20181 const gdb_byte
*info_ptr
,
20182 struct die_info
*comp_unit_die
,
20186 struct dwarf2_cu
*cu
= reader
->cu
;
20187 struct dwarf2_read_addr_index_data
*aidata
=
20188 (struct dwarf2_read_addr_index_data
*) data
;
20190 aidata
->addr_base
= cu
->addr_base
;
20191 aidata
->addr_size
= cu
->header
.addr_size
;
20194 /* Given an index in .debug_addr, fetch the value.
20195 NOTE: This can be called during dwarf expression evaluation,
20196 long after the debug information has been read, and thus per_cu->cu
20197 may no longer exist. */
20200 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20201 unsigned int addr_index
)
20203 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20204 struct dwarf2_cu
*cu
= per_cu
->cu
;
20205 ULONGEST addr_base
;
20208 /* We need addr_base and addr_size.
20209 If we don't have PER_CU->cu, we have to get it.
20210 Nasty, but the alternative is storing the needed info in PER_CU,
20211 which at this point doesn't seem justified: it's not clear how frequently
20212 it would get used and it would increase the size of every PER_CU.
20213 Entry points like dwarf2_per_cu_addr_size do a similar thing
20214 so we're not in uncharted territory here.
20215 Alas we need to be a bit more complicated as addr_base is contained
20218 We don't need to read the entire CU(/TU).
20219 We just need the header and top level die.
20221 IWBN to use the aging mechanism to let us lazily later discard the CU.
20222 For now we skip this optimization. */
20226 addr_base
= cu
->addr_base
;
20227 addr_size
= cu
->header
.addr_size
;
20231 struct dwarf2_read_addr_index_data aidata
;
20233 /* Note: We can't use init_cutu_and_read_dies_simple here,
20234 we need addr_base. */
20235 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20236 dwarf2_read_addr_index_reader
, &aidata
);
20237 addr_base
= aidata
.addr_base
;
20238 addr_size
= aidata
.addr_size
;
20241 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20245 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20246 This is only used by the Fission support. */
20248 static const char *
20249 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20251 struct dwarf2_cu
*cu
= reader
->cu
;
20252 struct dwarf2_per_objfile
*dwarf2_per_objfile
20253 = cu
->per_cu
->dwarf2_per_objfile
;
20254 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20255 const char *objf_name
= objfile_name (objfile
);
20256 bfd
*abfd
= objfile
->obfd
;
20257 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20258 struct dwarf2_section_info
*str_offsets_section
=
20259 &reader
->dwo_file
->sections
.str_offsets
;
20260 const gdb_byte
*info_ptr
;
20261 ULONGEST str_offset
;
20262 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20264 dwarf2_read_section (objfile
, str_section
);
20265 dwarf2_read_section (objfile
, str_offsets_section
);
20266 if (str_section
->buffer
== NULL
)
20267 error (_("%s used without .debug_str.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_offsets_section
->buffer
== NULL
)
20271 error (_("%s used without .debug_str_offsets.dwo section"
20272 " in CU at offset %s [in module %s]"),
20273 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20274 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20275 error (_("%s pointing outside of .debug_str_offsets.dwo"
20276 " section in CU at offset %s [in module %s]"),
20277 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20278 info_ptr
= (str_offsets_section
->buffer
20279 + str_index
* cu
->header
.offset_size
);
20280 if (cu
->header
.offset_size
== 4)
20281 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20283 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20284 if (str_offset
>= str_section
->size
)
20285 error (_("Offset from %s pointing outside of"
20286 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20287 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20288 return (const char *) (str_section
->buffer
+ str_offset
);
20291 /* Return the length of an LEB128 number in BUF. */
20294 leb128_size (const gdb_byte
*buf
)
20296 const gdb_byte
*begin
= buf
;
20302 if ((byte
& 128) == 0)
20303 return buf
- begin
;
20308 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20317 cu
->language
= language_c
;
20320 case DW_LANG_C_plus_plus
:
20321 case DW_LANG_C_plus_plus_11
:
20322 case DW_LANG_C_plus_plus_14
:
20323 cu
->language
= language_cplus
;
20326 cu
->language
= language_d
;
20328 case DW_LANG_Fortran77
:
20329 case DW_LANG_Fortran90
:
20330 case DW_LANG_Fortran95
:
20331 case DW_LANG_Fortran03
:
20332 case DW_LANG_Fortran08
:
20333 cu
->language
= language_fortran
;
20336 cu
->language
= language_go
;
20338 case DW_LANG_Mips_Assembler
:
20339 cu
->language
= language_asm
;
20341 case DW_LANG_Ada83
:
20342 case DW_LANG_Ada95
:
20343 cu
->language
= language_ada
;
20345 case DW_LANG_Modula2
:
20346 cu
->language
= language_m2
;
20348 case DW_LANG_Pascal83
:
20349 cu
->language
= language_pascal
;
20352 cu
->language
= language_objc
;
20355 case DW_LANG_Rust_old
:
20356 cu
->language
= language_rust
;
20358 case DW_LANG_Cobol74
:
20359 case DW_LANG_Cobol85
:
20361 cu
->language
= language_minimal
;
20364 cu
->language_defn
= language_def (cu
->language
);
20367 /* Return the named attribute or NULL if not there. */
20369 static struct attribute
*
20370 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20375 struct attribute
*spec
= NULL
;
20377 for (i
= 0; i
< die
->num_attrs
; ++i
)
20379 if (die
->attrs
[i
].name
== name
)
20380 return &die
->attrs
[i
];
20381 if (die
->attrs
[i
].name
== DW_AT_specification
20382 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20383 spec
= &die
->attrs
[i
];
20389 die
= follow_die_ref (die
, spec
, &cu
);
20395 /* Return the named attribute or NULL if not there,
20396 but do not follow DW_AT_specification, etc.
20397 This is for use in contexts where we're reading .debug_types dies.
20398 Following DW_AT_specification, DW_AT_abstract_origin will take us
20399 back up the chain, and we want to go down. */
20401 static struct attribute
*
20402 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20406 for (i
= 0; i
< die
->num_attrs
; ++i
)
20407 if (die
->attrs
[i
].name
== name
)
20408 return &die
->attrs
[i
];
20413 /* Return the string associated with a string-typed attribute, or NULL if it
20414 is either not found or is of an incorrect type. */
20416 static const char *
20417 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20419 struct attribute
*attr
;
20420 const char *str
= NULL
;
20422 attr
= dwarf2_attr (die
, name
, cu
);
20426 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20427 || attr
->form
== DW_FORM_string
20428 || attr
->form
== DW_FORM_strx
20429 || attr
->form
== DW_FORM_strx1
20430 || attr
->form
== DW_FORM_strx2
20431 || attr
->form
== DW_FORM_strx3
20432 || attr
->form
== DW_FORM_strx4
20433 || attr
->form
== DW_FORM_GNU_str_index
20434 || attr
->form
== DW_FORM_GNU_strp_alt
)
20435 str
= DW_STRING (attr
);
20437 complaint (_("string type expected for attribute %s for "
20438 "DIE at %s in module %s"),
20439 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20440 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20446 /* Return the dwo name or NULL if not present. If present, it is in either
20447 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20448 static const char *
20449 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20451 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20452 if (dwo_name
== nullptr)
20453 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20457 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20458 and holds a non-zero value. This function should only be used for
20459 DW_FORM_flag or DW_FORM_flag_present attributes. */
20462 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20464 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20466 return (attr
&& DW_UNSND (attr
));
20470 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20472 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20473 which value is non-zero. However, we have to be careful with
20474 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20475 (via dwarf2_flag_true_p) follows this attribute. So we may
20476 end up accidently finding a declaration attribute that belongs
20477 to a different DIE referenced by the specification attribute,
20478 even though the given DIE does not have a declaration attribute. */
20479 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20480 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20483 /* Return the die giving the specification for DIE, if there is
20484 one. *SPEC_CU is the CU containing DIE on input, and the CU
20485 containing the return value on output. If there is no
20486 specification, but there is an abstract origin, that is
20489 static struct die_info
*
20490 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20492 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20495 if (spec_attr
== NULL
)
20496 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20498 if (spec_attr
== NULL
)
20501 return follow_die_ref (die
, spec_attr
, spec_cu
);
20504 /* Stub for free_line_header to match void * callback types. */
20507 free_line_header_voidp (void *arg
)
20509 struct line_header
*lh
= (struct line_header
*) arg
;
20515 line_header::add_include_dir (const char *include_dir
)
20517 if (dwarf_line_debug
>= 2)
20521 new_size
= m_include_dirs
.size ();
20523 new_size
= m_include_dirs
.size () + 1;
20524 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20525 new_size
, include_dir
);
20527 m_include_dirs
.push_back (include_dir
);
20531 line_header::add_file_name (const char *name
,
20533 unsigned int mod_time
,
20534 unsigned int length
)
20536 if (dwarf_line_debug
>= 2)
20540 new_size
= file_names_size ();
20542 new_size
= file_names_size () + 1;
20543 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20546 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20549 /* A convenience function to find the proper .debug_line section for a CU. */
20551 static struct dwarf2_section_info
*
20552 get_debug_line_section (struct dwarf2_cu
*cu
)
20554 struct dwarf2_section_info
*section
;
20555 struct dwarf2_per_objfile
*dwarf2_per_objfile
20556 = cu
->per_cu
->dwarf2_per_objfile
;
20558 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20560 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20561 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20562 else if (cu
->per_cu
->is_dwz
)
20564 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20566 section
= &dwz
->line
;
20569 section
= &dwarf2_per_objfile
->line
;
20574 /* Read directory or file name entry format, starting with byte of
20575 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20576 entries count and the entries themselves in the described entry
20580 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20581 bfd
*abfd
, const gdb_byte
**bufp
,
20582 struct line_header
*lh
,
20583 const struct comp_unit_head
*cu_header
,
20584 void (*callback
) (struct line_header
*lh
,
20587 unsigned int mod_time
,
20588 unsigned int length
))
20590 gdb_byte format_count
, formati
;
20591 ULONGEST data_count
, datai
;
20592 const gdb_byte
*buf
= *bufp
;
20593 const gdb_byte
*format_header_data
;
20594 unsigned int bytes_read
;
20596 format_count
= read_1_byte (abfd
, buf
);
20598 format_header_data
= buf
;
20599 for (formati
= 0; formati
< format_count
; formati
++)
20601 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20603 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20607 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20609 for (datai
= 0; datai
< data_count
; datai
++)
20611 const gdb_byte
*format
= format_header_data
;
20612 struct file_entry fe
;
20614 for (formati
= 0; formati
< format_count
; formati
++)
20616 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20617 format
+= bytes_read
;
20619 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20620 format
+= bytes_read
;
20622 gdb::optional
<const char *> string
;
20623 gdb::optional
<unsigned int> uint
;
20627 case DW_FORM_string
:
20628 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20632 case DW_FORM_line_strp
:
20633 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20640 case DW_FORM_data1
:
20641 uint
.emplace (read_1_byte (abfd
, buf
));
20645 case DW_FORM_data2
:
20646 uint
.emplace (read_2_bytes (abfd
, buf
));
20650 case DW_FORM_data4
:
20651 uint
.emplace (read_4_bytes (abfd
, buf
));
20655 case DW_FORM_data8
:
20656 uint
.emplace (read_8_bytes (abfd
, buf
));
20660 case DW_FORM_data16
:
20661 /* This is used for MD5, but file_entry does not record MD5s. */
20665 case DW_FORM_udata
:
20666 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20670 case DW_FORM_block
:
20671 /* It is valid only for DW_LNCT_timestamp which is ignored by
20676 switch (content_type
)
20679 if (string
.has_value ())
20682 case DW_LNCT_directory_index
:
20683 if (uint
.has_value ())
20684 fe
.d_index
= (dir_index
) *uint
;
20686 case DW_LNCT_timestamp
:
20687 if (uint
.has_value ())
20688 fe
.mod_time
= *uint
;
20691 if (uint
.has_value ())
20697 complaint (_("Unknown format content type %s"),
20698 pulongest (content_type
));
20702 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20708 /* Read the statement program header starting at OFFSET in
20709 .debug_line, or .debug_line.dwo. Return a pointer
20710 to a struct line_header, allocated using xmalloc.
20711 Returns NULL if there is a problem reading the header, e.g., if it
20712 has a version we don't understand.
20714 NOTE: the strings in the include directory and file name tables of
20715 the returned object point into the dwarf line section buffer,
20716 and must not be freed. */
20718 static line_header_up
20719 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20721 const gdb_byte
*line_ptr
;
20722 unsigned int bytes_read
, offset_size
;
20724 const char *cur_dir
, *cur_file
;
20725 struct dwarf2_section_info
*section
;
20727 struct dwarf2_per_objfile
*dwarf2_per_objfile
20728 = cu
->per_cu
->dwarf2_per_objfile
;
20730 section
= get_debug_line_section (cu
);
20731 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20732 if (section
->buffer
== NULL
)
20734 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20735 complaint (_("missing .debug_line.dwo section"));
20737 complaint (_("missing .debug_line section"));
20741 /* We can't do this until we know the section is non-empty.
20742 Only then do we know we have such a section. */
20743 abfd
= get_section_bfd_owner (section
);
20745 /* Make sure that at least there's room for the total_length field.
20746 That could be 12 bytes long, but we're just going to fudge that. */
20747 if (to_underlying (sect_off
) + 4 >= section
->size
)
20749 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20753 line_header_up
lh (new line_header ());
20755 lh
->sect_off
= sect_off
;
20756 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20758 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20760 /* Read in the header. */
20762 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20763 &bytes_read
, &offset_size
);
20764 line_ptr
+= bytes_read
;
20766 const gdb_byte
*start_here
= line_ptr
;
20768 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20770 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20773 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20774 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20776 if (lh
->version
> 5)
20778 /* This is a version we don't understand. The format could have
20779 changed in ways we don't handle properly so just punt. */
20780 complaint (_("unsupported version in .debug_line section"));
20783 if (lh
->version
>= 5)
20785 gdb_byte segment_selector_size
;
20787 /* Skip address size. */
20788 read_1_byte (abfd
, line_ptr
);
20791 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20793 if (segment_selector_size
!= 0)
20795 complaint (_("unsupported segment selector size %u "
20796 "in .debug_line section"),
20797 segment_selector_size
);
20801 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20802 line_ptr
+= offset_size
;
20803 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20804 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20806 if (lh
->version
>= 4)
20808 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20812 lh
->maximum_ops_per_instruction
= 1;
20814 if (lh
->maximum_ops_per_instruction
== 0)
20816 lh
->maximum_ops_per_instruction
= 1;
20817 complaint (_("invalid maximum_ops_per_instruction "
20818 "in `.debug_line' section"));
20821 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20823 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20825 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20827 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20829 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20831 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20832 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20834 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20838 if (lh
->version
>= 5)
20840 /* Read directory table. */
20841 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20843 [] (struct line_header
*header
, const char *name
,
20844 dir_index d_index
, unsigned int mod_time
,
20845 unsigned int length
)
20847 header
->add_include_dir (name
);
20850 /* Read file name table. */
20851 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20853 [] (struct line_header
*header
, const char *name
,
20854 dir_index d_index
, unsigned int mod_time
,
20855 unsigned int length
)
20857 header
->add_file_name (name
, d_index
, mod_time
, length
);
20862 /* Read directory table. */
20863 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20865 line_ptr
+= bytes_read
;
20866 lh
->add_include_dir (cur_dir
);
20868 line_ptr
+= bytes_read
;
20870 /* Read file name table. */
20871 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20873 unsigned int mod_time
, length
;
20876 line_ptr
+= bytes_read
;
20877 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20878 line_ptr
+= bytes_read
;
20879 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20880 line_ptr
+= bytes_read
;
20881 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20882 line_ptr
+= bytes_read
;
20884 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20886 line_ptr
+= bytes_read
;
20889 if (line_ptr
> (section
->buffer
+ section
->size
))
20890 complaint (_("line number info header doesn't "
20891 "fit in `.debug_line' section"));
20896 /* Subroutine of dwarf_decode_lines to simplify it.
20897 Return the file name of the psymtab for the given file_entry.
20898 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20899 If space for the result is malloc'd, *NAME_HOLDER will be set.
20900 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20902 static const char *
20903 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20904 const struct partial_symtab
*pst
,
20905 const char *comp_dir
,
20906 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20908 const char *include_name
= fe
.name
;
20909 const char *include_name_to_compare
= include_name
;
20910 const char *pst_filename
;
20913 const char *dir_name
= fe
.include_dir (lh
);
20915 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20916 if (!IS_ABSOLUTE_PATH (include_name
)
20917 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20919 /* Avoid creating a duplicate psymtab for PST.
20920 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20921 Before we do the comparison, however, we need to account
20922 for DIR_NAME and COMP_DIR.
20923 First prepend dir_name (if non-NULL). If we still don't
20924 have an absolute path prepend comp_dir (if non-NULL).
20925 However, the directory we record in the include-file's
20926 psymtab does not contain COMP_DIR (to match the
20927 corresponding symtab(s)).
20932 bash$ gcc -g ./hello.c
20933 include_name = "hello.c"
20935 DW_AT_comp_dir = comp_dir = "/tmp"
20936 DW_AT_name = "./hello.c"
20940 if (dir_name
!= NULL
)
20942 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20943 include_name
, (char *) NULL
));
20944 include_name
= name_holder
->get ();
20945 include_name_to_compare
= include_name
;
20947 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20949 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20950 include_name
, (char *) NULL
));
20951 include_name_to_compare
= hold_compare
.get ();
20955 pst_filename
= pst
->filename
;
20956 gdb::unique_xmalloc_ptr
<char> copied_name
;
20957 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20959 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20960 pst_filename
, (char *) NULL
));
20961 pst_filename
= copied_name
.get ();
20964 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20968 return include_name
;
20971 /* State machine to track the state of the line number program. */
20973 class lnp_state_machine
20976 /* Initialize a machine state for the start of a line number
20978 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20979 bool record_lines_p
);
20981 file_entry
*current_file ()
20983 /* lh->file_names is 0-based, but the file name numbers in the
20984 statement program are 1-based. */
20985 return m_line_header
->file_name_at (m_file
);
20988 /* Record the line in the state machine. END_SEQUENCE is true if
20989 we're processing the end of a sequence. */
20990 void record_line (bool end_sequence
);
20992 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20993 nop-out rest of the lines in this sequence. */
20994 void check_line_address (struct dwarf2_cu
*cu
,
20995 const gdb_byte
*line_ptr
,
20996 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20998 void handle_set_discriminator (unsigned int discriminator
)
21000 m_discriminator
= discriminator
;
21001 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21004 /* Handle DW_LNE_set_address. */
21005 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21008 address
+= baseaddr
;
21009 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21012 /* Handle DW_LNS_advance_pc. */
21013 void handle_advance_pc (CORE_ADDR adjust
);
21015 /* Handle a special opcode. */
21016 void handle_special_opcode (unsigned char op_code
);
21018 /* Handle DW_LNS_advance_line. */
21019 void handle_advance_line (int line_delta
)
21021 advance_line (line_delta
);
21024 /* Handle DW_LNS_set_file. */
21025 void handle_set_file (file_name_index file
);
21027 /* Handle DW_LNS_negate_stmt. */
21028 void handle_negate_stmt ()
21030 m_is_stmt
= !m_is_stmt
;
21033 /* Handle DW_LNS_const_add_pc. */
21034 void handle_const_add_pc ();
21036 /* Handle DW_LNS_fixed_advance_pc. */
21037 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21039 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21043 /* Handle DW_LNS_copy. */
21044 void handle_copy ()
21046 record_line (false);
21047 m_discriminator
= 0;
21050 /* Handle DW_LNE_end_sequence. */
21051 void handle_end_sequence ()
21053 m_currently_recording_lines
= true;
21057 /* Advance the line by LINE_DELTA. */
21058 void advance_line (int line_delta
)
21060 m_line
+= line_delta
;
21062 if (line_delta
!= 0)
21063 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21066 struct dwarf2_cu
*m_cu
;
21068 gdbarch
*m_gdbarch
;
21070 /* True if we're recording lines.
21071 Otherwise we're building partial symtabs and are just interested in
21072 finding include files mentioned by the line number program. */
21073 bool m_record_lines_p
;
21075 /* The line number header. */
21076 line_header
*m_line_header
;
21078 /* These are part of the standard DWARF line number state machine,
21079 and initialized according to the DWARF spec. */
21081 unsigned char m_op_index
= 0;
21082 /* The line table index of the current file. */
21083 file_name_index m_file
= 1;
21084 unsigned int m_line
= 1;
21086 /* These are initialized in the constructor. */
21088 CORE_ADDR m_address
;
21090 unsigned int m_discriminator
;
21092 /* Additional bits of state we need to track. */
21094 /* The last file that we called dwarf2_start_subfile for.
21095 This is only used for TLLs. */
21096 unsigned int m_last_file
= 0;
21097 /* The last file a line number was recorded for. */
21098 struct subfile
*m_last_subfile
= NULL
;
21100 /* When true, record the lines we decode. */
21101 bool m_currently_recording_lines
= false;
21103 /* The last line number that was recorded, used to coalesce
21104 consecutive entries for the same line. This can happen, for
21105 example, when discriminators are present. PR 17276. */
21106 unsigned int m_last_line
= 0;
21107 bool m_line_has_non_zero_discriminator
= false;
21111 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21113 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21114 / m_line_header
->maximum_ops_per_instruction
)
21115 * m_line_header
->minimum_instruction_length
);
21116 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21117 m_op_index
= ((m_op_index
+ adjust
)
21118 % m_line_header
->maximum_ops_per_instruction
);
21122 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21124 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21125 CORE_ADDR addr_adj
= (((m_op_index
21126 + (adj_opcode
/ m_line_header
->line_range
))
21127 / m_line_header
->maximum_ops_per_instruction
)
21128 * m_line_header
->minimum_instruction_length
);
21129 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21130 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21131 % m_line_header
->maximum_ops_per_instruction
);
21133 int line_delta
= (m_line_header
->line_base
21134 + (adj_opcode
% m_line_header
->line_range
));
21135 advance_line (line_delta
);
21136 record_line (false);
21137 m_discriminator
= 0;
21141 lnp_state_machine::handle_set_file (file_name_index file
)
21145 const file_entry
*fe
= current_file ();
21147 dwarf2_debug_line_missing_file_complaint ();
21148 else if (m_record_lines_p
)
21150 const char *dir
= fe
->include_dir (m_line_header
);
21152 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21153 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21154 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21159 lnp_state_machine::handle_const_add_pc ()
21162 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21165 = (((m_op_index
+ adjust
)
21166 / m_line_header
->maximum_ops_per_instruction
)
21167 * m_line_header
->minimum_instruction_length
);
21169 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21170 m_op_index
= ((m_op_index
+ adjust
)
21171 % m_line_header
->maximum_ops_per_instruction
);
21174 /* Return non-zero if we should add LINE to the line number table.
21175 LINE is the line to add, LAST_LINE is the last line that was added,
21176 LAST_SUBFILE is the subfile for LAST_LINE.
21177 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21178 had a non-zero discriminator.
21180 We have to be careful in the presence of discriminators.
21181 E.g., for this line:
21183 for (i = 0; i < 100000; i++);
21185 clang can emit four line number entries for that one line,
21186 each with a different discriminator.
21187 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21189 However, we want gdb to coalesce all four entries into one.
21190 Otherwise the user could stepi into the middle of the line and
21191 gdb would get confused about whether the pc really was in the
21192 middle of the line.
21194 Things are further complicated by the fact that two consecutive
21195 line number entries for the same line is a heuristic used by gcc
21196 to denote the end of the prologue. So we can't just discard duplicate
21197 entries, we have to be selective about it. The heuristic we use is
21198 that we only collapse consecutive entries for the same line if at least
21199 one of those entries has a non-zero discriminator. PR 17276.
21201 Note: Addresses in the line number state machine can never go backwards
21202 within one sequence, thus this coalescing is ok. */
21205 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21206 unsigned int line
, unsigned int last_line
,
21207 int line_has_non_zero_discriminator
,
21208 struct subfile
*last_subfile
)
21210 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21212 if (line
!= last_line
)
21214 /* Same line for the same file that we've seen already.
21215 As a last check, for pr 17276, only record the line if the line
21216 has never had a non-zero discriminator. */
21217 if (!line_has_non_zero_discriminator
)
21222 /* Use the CU's builder to record line number LINE beginning at
21223 address ADDRESS in the line table of subfile SUBFILE. */
21226 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21227 unsigned int line
, CORE_ADDR address
,
21228 struct dwarf2_cu
*cu
)
21230 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21232 if (dwarf_line_debug
)
21234 fprintf_unfiltered (gdb_stdlog
,
21235 "Recording line %u, file %s, address %s\n",
21236 line
, lbasename (subfile
->name
),
21237 paddress (gdbarch
, address
));
21241 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21244 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21245 Mark the end of a set of line number records.
21246 The arguments are the same as for dwarf_record_line_1.
21247 If SUBFILE is NULL the request is ignored. */
21250 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21251 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21253 if (subfile
== NULL
)
21256 if (dwarf_line_debug
)
21258 fprintf_unfiltered (gdb_stdlog
,
21259 "Finishing current line, file %s, address %s\n",
21260 lbasename (subfile
->name
),
21261 paddress (gdbarch
, address
));
21264 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21268 lnp_state_machine::record_line (bool end_sequence
)
21270 if (dwarf_line_debug
)
21272 fprintf_unfiltered (gdb_stdlog
,
21273 "Processing actual line %u: file %u,"
21274 " address %s, is_stmt %u, discrim %u\n",
21276 paddress (m_gdbarch
, m_address
),
21277 m_is_stmt
, m_discriminator
);
21280 file_entry
*fe
= current_file ();
21283 dwarf2_debug_line_missing_file_complaint ();
21284 /* For now we ignore lines not starting on an instruction boundary.
21285 But not when processing end_sequence for compatibility with the
21286 previous version of the code. */
21287 else if (m_op_index
== 0 || end_sequence
)
21289 fe
->included_p
= 1;
21290 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21292 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21295 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21296 m_currently_recording_lines
? m_cu
: nullptr);
21301 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21302 m_line_has_non_zero_discriminator
,
21305 buildsym_compunit
*builder
= m_cu
->get_builder ();
21306 dwarf_record_line_1 (m_gdbarch
,
21307 builder
->get_current_subfile (),
21309 m_currently_recording_lines
? m_cu
: nullptr);
21311 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21312 m_last_line
= m_line
;
21318 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21319 line_header
*lh
, bool record_lines_p
)
21323 m_record_lines_p
= record_lines_p
;
21324 m_line_header
= lh
;
21326 m_currently_recording_lines
= true;
21328 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21329 was a line entry for it so that the backend has a chance to adjust it
21330 and also record it in case it needs it. This is currently used by MIPS
21331 code, cf. `mips_adjust_dwarf2_line'. */
21332 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21333 m_is_stmt
= lh
->default_is_stmt
;
21334 m_discriminator
= 0;
21338 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21339 const gdb_byte
*line_ptr
,
21340 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21342 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21343 the pc range of the CU. However, we restrict the test to only ADDRESS
21344 values of zero to preserve GDB's previous behaviour which is to handle
21345 the specific case of a function being GC'd by the linker. */
21347 if (address
== 0 && address
< unrelocated_lowpc
)
21349 /* This line table is for a function which has been
21350 GCd by the linker. Ignore it. PR gdb/12528 */
21352 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21353 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21355 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21356 line_offset
, objfile_name (objfile
));
21357 m_currently_recording_lines
= false;
21358 /* Note: m_currently_recording_lines is left as false until we see
21359 DW_LNE_end_sequence. */
21363 /* Subroutine of dwarf_decode_lines to simplify it.
21364 Process the line number information in LH.
21365 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21366 program in order to set included_p for every referenced header. */
21369 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21370 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21372 const gdb_byte
*line_ptr
, *extended_end
;
21373 const gdb_byte
*line_end
;
21374 unsigned int bytes_read
, extended_len
;
21375 unsigned char op_code
, extended_op
;
21376 CORE_ADDR baseaddr
;
21377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21378 bfd
*abfd
= objfile
->obfd
;
21379 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21380 /* True if we're recording line info (as opposed to building partial
21381 symtabs and just interested in finding include files mentioned by
21382 the line number program). */
21383 bool record_lines_p
= !decode_for_pst_p
;
21385 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21387 line_ptr
= lh
->statement_program_start
;
21388 line_end
= lh
->statement_program_end
;
21390 /* Read the statement sequences until there's nothing left. */
21391 while (line_ptr
< line_end
)
21393 /* The DWARF line number program state machine. Reset the state
21394 machine at the start of each sequence. */
21395 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21396 bool end_sequence
= false;
21398 if (record_lines_p
)
21400 /* Start a subfile for the current file of the state
21402 const file_entry
*fe
= state_machine
.current_file ();
21405 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21408 /* Decode the table. */
21409 while (line_ptr
< line_end
&& !end_sequence
)
21411 op_code
= read_1_byte (abfd
, line_ptr
);
21414 if (op_code
>= lh
->opcode_base
)
21416 /* Special opcode. */
21417 state_machine
.handle_special_opcode (op_code
);
21419 else switch (op_code
)
21421 case DW_LNS_extended_op
:
21422 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21424 line_ptr
+= bytes_read
;
21425 extended_end
= line_ptr
+ extended_len
;
21426 extended_op
= read_1_byte (abfd
, line_ptr
);
21428 switch (extended_op
)
21430 case DW_LNE_end_sequence
:
21431 state_machine
.handle_end_sequence ();
21432 end_sequence
= true;
21434 case DW_LNE_set_address
:
21437 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21438 line_ptr
+= bytes_read
;
21440 state_machine
.check_line_address (cu
, line_ptr
,
21441 lowpc
- baseaddr
, address
);
21442 state_machine
.handle_set_address (baseaddr
, address
);
21445 case DW_LNE_define_file
:
21447 const char *cur_file
;
21448 unsigned int mod_time
, length
;
21451 cur_file
= read_direct_string (abfd
, line_ptr
,
21453 line_ptr
+= bytes_read
;
21454 dindex
= (dir_index
)
21455 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21458 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21459 line_ptr
+= bytes_read
;
21461 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21462 line_ptr
+= bytes_read
;
21463 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21466 case DW_LNE_set_discriminator
:
21468 /* The discriminator is not interesting to the
21469 debugger; just ignore it. We still need to
21470 check its value though:
21471 if there are consecutive entries for the same
21472 (non-prologue) line we want to coalesce them.
21475 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21476 line_ptr
+= bytes_read
;
21478 state_machine
.handle_set_discriminator (discr
);
21482 complaint (_("mangled .debug_line section"));
21485 /* Make sure that we parsed the extended op correctly. If e.g.
21486 we expected a different address size than the producer used,
21487 we may have read the wrong number of bytes. */
21488 if (line_ptr
!= extended_end
)
21490 complaint (_("mangled .debug_line section"));
21495 state_machine
.handle_copy ();
21497 case DW_LNS_advance_pc
:
21500 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21501 line_ptr
+= bytes_read
;
21503 state_machine
.handle_advance_pc (adjust
);
21506 case DW_LNS_advance_line
:
21509 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21510 line_ptr
+= bytes_read
;
21512 state_machine
.handle_advance_line (line_delta
);
21515 case DW_LNS_set_file
:
21517 file_name_index file
21518 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21520 line_ptr
+= bytes_read
;
21522 state_machine
.handle_set_file (file
);
21525 case DW_LNS_set_column
:
21526 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21527 line_ptr
+= bytes_read
;
21529 case DW_LNS_negate_stmt
:
21530 state_machine
.handle_negate_stmt ();
21532 case DW_LNS_set_basic_block
:
21534 /* Add to the address register of the state machine the
21535 address increment value corresponding to special opcode
21536 255. I.e., this value is scaled by the minimum
21537 instruction length since special opcode 255 would have
21538 scaled the increment. */
21539 case DW_LNS_const_add_pc
:
21540 state_machine
.handle_const_add_pc ();
21542 case DW_LNS_fixed_advance_pc
:
21544 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21547 state_machine
.handle_fixed_advance_pc (addr_adj
);
21552 /* Unknown standard opcode, ignore it. */
21555 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21557 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21558 line_ptr
+= bytes_read
;
21565 dwarf2_debug_line_missing_end_sequence_complaint ();
21567 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21568 in which case we still finish recording the last line). */
21569 state_machine
.record_line (true);
21573 /* Decode the Line Number Program (LNP) for the given line_header
21574 structure and CU. The actual information extracted and the type
21575 of structures created from the LNP depends on the value of PST.
21577 1. If PST is NULL, then this procedure uses the data from the program
21578 to create all necessary symbol tables, and their linetables.
21580 2. If PST is not NULL, this procedure reads the program to determine
21581 the list of files included by the unit represented by PST, and
21582 builds all the associated partial symbol tables.
21584 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21585 It is used for relative paths in the line table.
21586 NOTE: When processing partial symtabs (pst != NULL),
21587 comp_dir == pst->dirname.
21589 NOTE: It is important that psymtabs have the same file name (via strcmp)
21590 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21591 symtab we don't use it in the name of the psymtabs we create.
21592 E.g. expand_line_sal requires this when finding psymtabs to expand.
21593 A good testcase for this is mb-inline.exp.
21595 LOWPC is the lowest address in CU (or 0 if not known).
21597 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21598 for its PC<->lines mapping information. Otherwise only the filename
21599 table is read in. */
21602 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21603 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21604 CORE_ADDR lowpc
, int decode_mapping
)
21606 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21607 const int decode_for_pst_p
= (pst
!= NULL
);
21609 if (decode_mapping
)
21610 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21612 if (decode_for_pst_p
)
21614 /* Now that we're done scanning the Line Header Program, we can
21615 create the psymtab of each included file. */
21616 for (auto &file_entry
: lh
->file_names ())
21617 if (file_entry
.included_p
== 1)
21619 gdb::unique_xmalloc_ptr
<char> name_holder
;
21620 const char *include_name
=
21621 psymtab_include_file_name (lh
, file_entry
, pst
,
21622 comp_dir
, &name_holder
);
21623 if (include_name
!= NULL
)
21624 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21629 /* Make sure a symtab is created for every file, even files
21630 which contain only variables (i.e. no code with associated
21632 buildsym_compunit
*builder
= cu
->get_builder ();
21633 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21635 for (auto &fe
: lh
->file_names ())
21637 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21638 if (builder
->get_current_subfile ()->symtab
== NULL
)
21640 builder
->get_current_subfile ()->symtab
21641 = allocate_symtab (cust
,
21642 builder
->get_current_subfile ()->name
);
21644 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21649 /* Start a subfile for DWARF. FILENAME is the name of the file and
21650 DIRNAME the name of the source directory which contains FILENAME
21651 or NULL if not known.
21652 This routine tries to keep line numbers from identical absolute and
21653 relative file names in a common subfile.
21655 Using the `list' example from the GDB testsuite, which resides in
21656 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21657 of /srcdir/list0.c yields the following debugging information for list0.c:
21659 DW_AT_name: /srcdir/list0.c
21660 DW_AT_comp_dir: /compdir
21661 files.files[0].name: list0.h
21662 files.files[0].dir: /srcdir
21663 files.files[1].name: list0.c
21664 files.files[1].dir: /srcdir
21666 The line number information for list0.c has to end up in a single
21667 subfile, so that `break /srcdir/list0.c:1' works as expected.
21668 start_subfile will ensure that this happens provided that we pass the
21669 concatenation of files.files[1].dir and files.files[1].name as the
21673 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21674 const char *dirname
)
21676 gdb::unique_xmalloc_ptr
<char> copy
;
21678 /* In order not to lose the line information directory,
21679 we concatenate it to the filename when it makes sense.
21680 Note that the Dwarf3 standard says (speaking of filenames in line
21681 information): ``The directory index is ignored for file names
21682 that represent full path names''. Thus ignoring dirname in the
21683 `else' branch below isn't an issue. */
21685 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21687 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21688 filename
= copy
.get ();
21691 cu
->get_builder ()->start_subfile (filename
);
21694 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21695 buildsym_compunit constructor. */
21697 struct compunit_symtab
*
21698 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21701 gdb_assert (m_builder
== nullptr);
21703 m_builder
.reset (new struct buildsym_compunit
21704 (per_cu
->dwarf2_per_objfile
->objfile
,
21705 name
, comp_dir
, language
, low_pc
));
21707 list_in_scope
= get_builder ()->get_file_symbols ();
21709 get_builder ()->record_debugformat ("DWARF 2");
21710 get_builder ()->record_producer (producer
);
21712 processing_has_namespace_info
= false;
21714 return get_builder ()->get_compunit_symtab ();
21718 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21719 struct dwarf2_cu
*cu
)
21721 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21722 struct comp_unit_head
*cu_header
= &cu
->header
;
21724 /* NOTE drow/2003-01-30: There used to be a comment and some special
21725 code here to turn a symbol with DW_AT_external and a
21726 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21727 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21728 with some versions of binutils) where shared libraries could have
21729 relocations against symbols in their debug information - the
21730 minimal symbol would have the right address, but the debug info
21731 would not. It's no longer necessary, because we will explicitly
21732 apply relocations when we read in the debug information now. */
21734 /* A DW_AT_location attribute with no contents indicates that a
21735 variable has been optimized away. */
21736 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21738 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21742 /* Handle one degenerate form of location expression specially, to
21743 preserve GDB's previous behavior when section offsets are
21744 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21745 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21747 if (attr_form_is_block (attr
)
21748 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21749 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21750 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21751 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21752 && (DW_BLOCK (attr
)->size
21753 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21755 unsigned int dummy
;
21757 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21758 SET_SYMBOL_VALUE_ADDRESS (sym
,
21759 read_address (objfile
->obfd
,
21760 DW_BLOCK (attr
)->data
+ 1,
21763 SET_SYMBOL_VALUE_ADDRESS
21764 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21766 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21767 fixup_symbol_section (sym
, objfile
);
21768 SET_SYMBOL_VALUE_ADDRESS (sym
,
21769 SYMBOL_VALUE_ADDRESS (sym
)
21770 + ANOFFSET (objfile
->section_offsets
,
21771 SYMBOL_SECTION (sym
)));
21775 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21776 expression evaluator, and use LOC_COMPUTED only when necessary
21777 (i.e. when the value of a register or memory location is
21778 referenced, or a thread-local block, etc.). Then again, it might
21779 not be worthwhile. I'm assuming that it isn't unless performance
21780 or memory numbers show me otherwise. */
21782 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21784 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21785 cu
->has_loclist
= true;
21788 /* Given a pointer to a DWARF information entry, figure out if we need
21789 to make a symbol table entry for it, and if so, create a new entry
21790 and return a pointer to it.
21791 If TYPE is NULL, determine symbol type from the die, otherwise
21792 used the passed type.
21793 If SPACE is not NULL, use it to hold the new symbol. If it is
21794 NULL, allocate a new symbol on the objfile's obstack. */
21796 static struct symbol
*
21797 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21798 struct symbol
*space
)
21800 struct dwarf2_per_objfile
*dwarf2_per_objfile
21801 = cu
->per_cu
->dwarf2_per_objfile
;
21802 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21803 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21804 struct symbol
*sym
= NULL
;
21806 struct attribute
*attr
= NULL
;
21807 struct attribute
*attr2
= NULL
;
21808 CORE_ADDR baseaddr
;
21809 struct pending
**list_to_add
= NULL
;
21811 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21813 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21815 name
= dwarf2_name (die
, cu
);
21818 const char *linkagename
;
21819 int suppress_add
= 0;
21824 sym
= allocate_symbol (objfile
);
21825 OBJSTAT (objfile
, n_syms
++);
21827 /* Cache this symbol's name and the name's demangled form (if any). */
21828 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21829 linkagename
= dwarf2_physname (name
, die
, cu
);
21830 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21832 /* Fortran does not have mangling standard and the mangling does differ
21833 between gfortran, iFort etc. */
21834 if (cu
->language
== language_fortran
21835 && symbol_get_demangled_name (sym
) == NULL
)
21836 symbol_set_demangled_name (sym
,
21837 dwarf2_full_name (name
, die
, cu
),
21840 /* Default assumptions.
21841 Use the passed type or decode it from the die. */
21842 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21843 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21845 SYMBOL_TYPE (sym
) = type
;
21847 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21848 attr
= dwarf2_attr (die
,
21849 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21851 if (attr
!= nullptr)
21853 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21856 attr
= dwarf2_attr (die
,
21857 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21859 if (attr
!= nullptr)
21861 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21862 struct file_entry
*fe
;
21864 if (cu
->line_header
!= NULL
)
21865 fe
= cu
->line_header
->file_name_at (file_index
);
21870 complaint (_("file index out of range"));
21872 symbol_set_symtab (sym
, fe
->symtab
);
21878 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21879 if (attr
!= nullptr)
21883 addr
= attr_value_as_address (attr
);
21884 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21885 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21887 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21888 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21889 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21890 add_symbol_to_list (sym
, cu
->list_in_scope
);
21892 case DW_TAG_subprogram
:
21893 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21895 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21896 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21897 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21898 || cu
->language
== language_ada
21899 || cu
->language
== language_fortran
)
21901 /* Subprograms marked external are stored as a global symbol.
21902 Ada and Fortran subprograms, whether marked external or
21903 not, are always stored as a global symbol, because we want
21904 to be able to access them globally. For instance, we want
21905 to be able to break on a nested subprogram without having
21906 to specify the context. */
21907 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21911 list_to_add
= cu
->list_in_scope
;
21914 case DW_TAG_inlined_subroutine
:
21915 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21917 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21918 SYMBOL_INLINED (sym
) = 1;
21919 list_to_add
= cu
->list_in_scope
;
21921 case DW_TAG_template_value_param
:
21923 /* Fall through. */
21924 case DW_TAG_constant
:
21925 case DW_TAG_variable
:
21926 case DW_TAG_member
:
21927 /* Compilation with minimal debug info may result in
21928 variables with missing type entries. Change the
21929 misleading `void' type to something sensible. */
21930 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21931 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21933 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21934 /* In the case of DW_TAG_member, we should only be called for
21935 static const members. */
21936 if (die
->tag
== DW_TAG_member
)
21938 /* dwarf2_add_field uses die_is_declaration,
21939 so we do the same. */
21940 gdb_assert (die_is_declaration (die
, cu
));
21943 if (attr
!= nullptr)
21945 dwarf2_const_value (attr
, sym
, cu
);
21946 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21949 if (attr2
&& (DW_UNSND (attr2
) != 0))
21950 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21952 list_to_add
= cu
->list_in_scope
;
21956 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21957 if (attr
!= nullptr)
21959 var_decode_location (attr
, sym
, cu
);
21960 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21962 /* Fortran explicitly imports any global symbols to the local
21963 scope by DW_TAG_common_block. */
21964 if (cu
->language
== language_fortran
&& die
->parent
21965 && die
->parent
->tag
== DW_TAG_common_block
)
21968 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21969 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21970 && !dwarf2_per_objfile
->has_section_at_zero
)
21972 /* When a static variable is eliminated by the linker,
21973 the corresponding debug information is not stripped
21974 out, but the variable address is set to null;
21975 do not add such variables into symbol table. */
21977 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21979 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21980 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21981 && dwarf2_per_objfile
->can_copy
)
21983 /* A global static variable might be subject to
21984 copy relocation. We first check for a local
21985 minsym, though, because maybe the symbol was
21986 marked hidden, in which case this would not
21988 bound_minimal_symbol found
21989 = (lookup_minimal_symbol_linkage
21990 (sym
->linkage_name (), objfile
));
21991 if (found
.minsym
!= nullptr)
21992 sym
->maybe_copied
= 1;
21995 /* A variable with DW_AT_external is never static,
21996 but it may be block-scoped. */
21998 = ((cu
->list_in_scope
21999 == cu
->get_builder ()->get_file_symbols ())
22000 ? cu
->get_builder ()->get_global_symbols ()
22001 : cu
->list_in_scope
);
22004 list_to_add
= cu
->list_in_scope
;
22008 /* We do not know the address of this symbol.
22009 If it is an external symbol and we have type information
22010 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22011 The address of the variable will then be determined from
22012 the minimal symbol table whenever the variable is
22014 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22016 /* Fortran explicitly imports any global symbols to the local
22017 scope by DW_TAG_common_block. */
22018 if (cu
->language
== language_fortran
&& die
->parent
22019 && die
->parent
->tag
== DW_TAG_common_block
)
22021 /* SYMBOL_CLASS doesn't matter here because
22022 read_common_block is going to reset it. */
22024 list_to_add
= cu
->list_in_scope
;
22026 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22027 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22029 /* A variable with DW_AT_external is never static, but it
22030 may be block-scoped. */
22032 = ((cu
->list_in_scope
22033 == cu
->get_builder ()->get_file_symbols ())
22034 ? cu
->get_builder ()->get_global_symbols ()
22035 : cu
->list_in_scope
);
22037 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22039 else if (!die_is_declaration (die
, cu
))
22041 /* Use the default LOC_OPTIMIZED_OUT class. */
22042 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22044 list_to_add
= cu
->list_in_scope
;
22048 case DW_TAG_formal_parameter
:
22050 /* If we are inside a function, mark this as an argument. If
22051 not, we might be looking at an argument to an inlined function
22052 when we do not have enough information to show inlined frames;
22053 pretend it's a local variable in that case so that the user can
22055 struct context_stack
*curr
22056 = cu
->get_builder ()->get_current_context_stack ();
22057 if (curr
!= nullptr && curr
->name
!= nullptr)
22058 SYMBOL_IS_ARGUMENT (sym
) = 1;
22059 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22060 if (attr
!= nullptr)
22062 var_decode_location (attr
, sym
, cu
);
22064 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22065 if (attr
!= nullptr)
22067 dwarf2_const_value (attr
, sym
, cu
);
22070 list_to_add
= cu
->list_in_scope
;
22073 case DW_TAG_unspecified_parameters
:
22074 /* From varargs functions; gdb doesn't seem to have any
22075 interest in this information, so just ignore it for now.
22078 case DW_TAG_template_type_param
:
22080 /* Fall through. */
22081 case DW_TAG_class_type
:
22082 case DW_TAG_interface_type
:
22083 case DW_TAG_structure_type
:
22084 case DW_TAG_union_type
:
22085 case DW_TAG_set_type
:
22086 case DW_TAG_enumeration_type
:
22087 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22088 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22091 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22092 really ever be static objects: otherwise, if you try
22093 to, say, break of a class's method and you're in a file
22094 which doesn't mention that class, it won't work unless
22095 the check for all static symbols in lookup_symbol_aux
22096 saves you. See the OtherFileClass tests in
22097 gdb.c++/namespace.exp. */
22101 buildsym_compunit
*builder
= cu
->get_builder ();
22103 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22104 && cu
->language
== language_cplus
22105 ? builder
->get_global_symbols ()
22106 : cu
->list_in_scope
);
22108 /* The semantics of C++ state that "struct foo {
22109 ... }" also defines a typedef for "foo". */
22110 if (cu
->language
== language_cplus
22111 || cu
->language
== language_ada
22112 || cu
->language
== language_d
22113 || cu
->language
== language_rust
)
22115 /* The symbol's name is already allocated along
22116 with this objfile, so we don't need to
22117 duplicate it for the type. */
22118 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22119 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22124 case DW_TAG_typedef
:
22125 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22126 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22127 list_to_add
= cu
->list_in_scope
;
22129 case DW_TAG_base_type
:
22130 case DW_TAG_subrange_type
:
22131 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22132 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22133 list_to_add
= cu
->list_in_scope
;
22135 case DW_TAG_enumerator
:
22136 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22137 if (attr
!= nullptr)
22139 dwarf2_const_value (attr
, sym
, cu
);
22142 /* NOTE: carlton/2003-11-10: See comment above in the
22143 DW_TAG_class_type, etc. block. */
22146 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22147 && cu
->language
== language_cplus
22148 ? cu
->get_builder ()->get_global_symbols ()
22149 : cu
->list_in_scope
);
22152 case DW_TAG_imported_declaration
:
22153 case DW_TAG_namespace
:
22154 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22155 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22157 case DW_TAG_module
:
22158 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22159 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22160 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22162 case DW_TAG_common_block
:
22163 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22164 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22165 add_symbol_to_list (sym
, cu
->list_in_scope
);
22168 /* Not a tag we recognize. Hopefully we aren't processing
22169 trash data, but since we must specifically ignore things
22170 we don't recognize, there is nothing else we should do at
22172 complaint (_("unsupported tag: '%s'"),
22173 dwarf_tag_name (die
->tag
));
22179 sym
->hash_next
= objfile
->template_symbols
;
22180 objfile
->template_symbols
= sym
;
22181 list_to_add
= NULL
;
22184 if (list_to_add
!= NULL
)
22185 add_symbol_to_list (sym
, list_to_add
);
22187 /* For the benefit of old versions of GCC, check for anonymous
22188 namespaces based on the demangled name. */
22189 if (!cu
->processing_has_namespace_info
22190 && cu
->language
== language_cplus
)
22191 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22196 /* Given an attr with a DW_FORM_dataN value in host byte order,
22197 zero-extend it as appropriate for the symbol's type. The DWARF
22198 standard (v4) is not entirely clear about the meaning of using
22199 DW_FORM_dataN for a constant with a signed type, where the type is
22200 wider than the data. The conclusion of a discussion on the DWARF
22201 list was that this is unspecified. We choose to always zero-extend
22202 because that is the interpretation long in use by GCC. */
22205 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22206 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22208 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22209 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22210 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22211 LONGEST l
= DW_UNSND (attr
);
22213 if (bits
< sizeof (*value
) * 8)
22215 l
&= ((LONGEST
) 1 << bits
) - 1;
22218 else if (bits
== sizeof (*value
) * 8)
22222 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22223 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22230 /* Read a constant value from an attribute. Either set *VALUE, or if
22231 the value does not fit in *VALUE, set *BYTES - either already
22232 allocated on the objfile obstack, or newly allocated on OBSTACK,
22233 or, set *BATON, if we translated the constant to a location
22237 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22238 const char *name
, struct obstack
*obstack
,
22239 struct dwarf2_cu
*cu
,
22240 LONGEST
*value
, const gdb_byte
**bytes
,
22241 struct dwarf2_locexpr_baton
**baton
)
22243 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22244 struct comp_unit_head
*cu_header
= &cu
->header
;
22245 struct dwarf_block
*blk
;
22246 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22247 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22253 switch (attr
->form
)
22256 case DW_FORM_addrx
:
22257 case DW_FORM_GNU_addr_index
:
22261 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22262 dwarf2_const_value_length_mismatch_complaint (name
,
22263 cu_header
->addr_size
,
22264 TYPE_LENGTH (type
));
22265 /* Symbols of this form are reasonably rare, so we just
22266 piggyback on the existing location code rather than writing
22267 a new implementation of symbol_computed_ops. */
22268 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22269 (*baton
)->per_cu
= cu
->per_cu
;
22270 gdb_assert ((*baton
)->per_cu
);
22272 (*baton
)->size
= 2 + cu_header
->addr_size
;
22273 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22274 (*baton
)->data
= data
;
22276 data
[0] = DW_OP_addr
;
22277 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22278 byte_order
, DW_ADDR (attr
));
22279 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22282 case DW_FORM_string
:
22285 case DW_FORM_GNU_str_index
:
22286 case DW_FORM_GNU_strp_alt
:
22287 /* DW_STRING is already allocated on the objfile obstack, point
22289 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22291 case DW_FORM_block1
:
22292 case DW_FORM_block2
:
22293 case DW_FORM_block4
:
22294 case DW_FORM_block
:
22295 case DW_FORM_exprloc
:
22296 case DW_FORM_data16
:
22297 blk
= DW_BLOCK (attr
);
22298 if (TYPE_LENGTH (type
) != blk
->size
)
22299 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22300 TYPE_LENGTH (type
));
22301 *bytes
= blk
->data
;
22304 /* The DW_AT_const_value attributes are supposed to carry the
22305 symbol's value "represented as it would be on the target
22306 architecture." By the time we get here, it's already been
22307 converted to host endianness, so we just need to sign- or
22308 zero-extend it as appropriate. */
22309 case DW_FORM_data1
:
22310 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22312 case DW_FORM_data2
:
22313 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22315 case DW_FORM_data4
:
22316 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22318 case DW_FORM_data8
:
22319 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22322 case DW_FORM_sdata
:
22323 case DW_FORM_implicit_const
:
22324 *value
= DW_SND (attr
);
22327 case DW_FORM_udata
:
22328 *value
= DW_UNSND (attr
);
22332 complaint (_("unsupported const value attribute form: '%s'"),
22333 dwarf_form_name (attr
->form
));
22340 /* Copy constant value from an attribute to a symbol. */
22343 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22344 struct dwarf2_cu
*cu
)
22346 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22348 const gdb_byte
*bytes
;
22349 struct dwarf2_locexpr_baton
*baton
;
22351 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22352 sym
->print_name (),
22353 &objfile
->objfile_obstack
, cu
,
22354 &value
, &bytes
, &baton
);
22358 SYMBOL_LOCATION_BATON (sym
) = baton
;
22359 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22361 else if (bytes
!= NULL
)
22363 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22364 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22368 SYMBOL_VALUE (sym
) = value
;
22369 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22373 /* Return the type of the die in question using its DW_AT_type attribute. */
22375 static struct type
*
22376 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22378 struct attribute
*type_attr
;
22380 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22383 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22384 /* A missing DW_AT_type represents a void type. */
22385 return objfile_type (objfile
)->builtin_void
;
22388 return lookup_die_type (die
, type_attr
, cu
);
22391 /* True iff CU's producer generates GNAT Ada auxiliary information
22392 that allows to find parallel types through that information instead
22393 of having to do expensive parallel lookups by type name. */
22396 need_gnat_info (struct dwarf2_cu
*cu
)
22398 /* Assume that the Ada compiler was GNAT, which always produces
22399 the auxiliary information. */
22400 return (cu
->language
== language_ada
);
22403 /* Return the auxiliary type of the die in question using its
22404 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22405 attribute is not present. */
22407 static struct type
*
22408 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22410 struct attribute
*type_attr
;
22412 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22416 return lookup_die_type (die
, type_attr
, cu
);
22419 /* If DIE has a descriptive_type attribute, then set the TYPE's
22420 descriptive type accordingly. */
22423 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22424 struct dwarf2_cu
*cu
)
22426 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22428 if (descriptive_type
)
22430 ALLOCATE_GNAT_AUX_TYPE (type
);
22431 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22435 /* Return the containing type of the die in question using its
22436 DW_AT_containing_type attribute. */
22438 static struct type
*
22439 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22441 struct attribute
*type_attr
;
22442 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22444 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22446 error (_("Dwarf Error: Problem turning containing type into gdb type "
22447 "[in module %s]"), objfile_name (objfile
));
22449 return lookup_die_type (die
, type_attr
, cu
);
22452 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22454 static struct type
*
22455 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22457 struct dwarf2_per_objfile
*dwarf2_per_objfile
22458 = cu
->per_cu
->dwarf2_per_objfile
;
22459 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22462 std::string message
22463 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22464 objfile_name (objfile
),
22465 sect_offset_str (cu
->header
.sect_off
),
22466 sect_offset_str (die
->sect_off
));
22467 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22469 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22472 /* Look up the type of DIE in CU using its type attribute ATTR.
22473 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22474 DW_AT_containing_type.
22475 If there is no type substitute an error marker. */
22477 static struct type
*
22478 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22479 struct dwarf2_cu
*cu
)
22481 struct dwarf2_per_objfile
*dwarf2_per_objfile
22482 = cu
->per_cu
->dwarf2_per_objfile
;
22483 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22484 struct type
*this_type
;
22486 gdb_assert (attr
->name
== DW_AT_type
22487 || attr
->name
== DW_AT_GNAT_descriptive_type
22488 || attr
->name
== DW_AT_containing_type
);
22490 /* First see if we have it cached. */
22492 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22494 struct dwarf2_per_cu_data
*per_cu
;
22495 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22497 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22498 dwarf2_per_objfile
);
22499 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22501 else if (attr_form_is_ref (attr
))
22503 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22505 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22507 else if (attr
->form
== DW_FORM_ref_sig8
)
22509 ULONGEST signature
= DW_SIGNATURE (attr
);
22511 return get_signatured_type (die
, signature
, cu
);
22515 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22516 " at %s [in module %s]"),
22517 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22518 objfile_name (objfile
));
22519 return build_error_marker_type (cu
, die
);
22522 /* If not cached we need to read it in. */
22524 if (this_type
== NULL
)
22526 struct die_info
*type_die
= NULL
;
22527 struct dwarf2_cu
*type_cu
= cu
;
22529 if (attr_form_is_ref (attr
))
22530 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22531 if (type_die
== NULL
)
22532 return build_error_marker_type (cu
, die
);
22533 /* If we find the type now, it's probably because the type came
22534 from an inter-CU reference and the type's CU got expanded before
22536 this_type
= read_type_die (type_die
, type_cu
);
22539 /* If we still don't have a type use an error marker. */
22541 if (this_type
== NULL
)
22542 return build_error_marker_type (cu
, die
);
22547 /* Return the type in DIE, CU.
22548 Returns NULL for invalid types.
22550 This first does a lookup in die_type_hash,
22551 and only reads the die in if necessary.
22553 NOTE: This can be called when reading in partial or full symbols. */
22555 static struct type
*
22556 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22558 struct type
*this_type
;
22560 this_type
= get_die_type (die
, cu
);
22564 return read_type_die_1 (die
, cu
);
22567 /* Read the type in DIE, CU.
22568 Returns NULL for invalid types. */
22570 static struct type
*
22571 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22573 struct type
*this_type
= NULL
;
22577 case DW_TAG_class_type
:
22578 case DW_TAG_interface_type
:
22579 case DW_TAG_structure_type
:
22580 case DW_TAG_union_type
:
22581 this_type
= read_structure_type (die
, cu
);
22583 case DW_TAG_enumeration_type
:
22584 this_type
= read_enumeration_type (die
, cu
);
22586 case DW_TAG_subprogram
:
22587 case DW_TAG_subroutine_type
:
22588 case DW_TAG_inlined_subroutine
:
22589 this_type
= read_subroutine_type (die
, cu
);
22591 case DW_TAG_array_type
:
22592 this_type
= read_array_type (die
, cu
);
22594 case DW_TAG_set_type
:
22595 this_type
= read_set_type (die
, cu
);
22597 case DW_TAG_pointer_type
:
22598 this_type
= read_tag_pointer_type (die
, cu
);
22600 case DW_TAG_ptr_to_member_type
:
22601 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22603 case DW_TAG_reference_type
:
22604 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22606 case DW_TAG_rvalue_reference_type
:
22607 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22609 case DW_TAG_const_type
:
22610 this_type
= read_tag_const_type (die
, cu
);
22612 case DW_TAG_volatile_type
:
22613 this_type
= read_tag_volatile_type (die
, cu
);
22615 case DW_TAG_restrict_type
:
22616 this_type
= read_tag_restrict_type (die
, cu
);
22618 case DW_TAG_string_type
:
22619 this_type
= read_tag_string_type (die
, cu
);
22621 case DW_TAG_typedef
:
22622 this_type
= read_typedef (die
, cu
);
22624 case DW_TAG_subrange_type
:
22625 this_type
= read_subrange_type (die
, cu
);
22627 case DW_TAG_base_type
:
22628 this_type
= read_base_type (die
, cu
);
22630 case DW_TAG_unspecified_type
:
22631 this_type
= read_unspecified_type (die
, cu
);
22633 case DW_TAG_namespace
:
22634 this_type
= read_namespace_type (die
, cu
);
22636 case DW_TAG_module
:
22637 this_type
= read_module_type (die
, cu
);
22639 case DW_TAG_atomic_type
:
22640 this_type
= read_tag_atomic_type (die
, cu
);
22643 complaint (_("unexpected tag in read_type_die: '%s'"),
22644 dwarf_tag_name (die
->tag
));
22651 /* See if we can figure out if the class lives in a namespace. We do
22652 this by looking for a member function; its demangled name will
22653 contain namespace info, if there is any.
22654 Return the computed name or NULL.
22655 Space for the result is allocated on the objfile's obstack.
22656 This is the full-die version of guess_partial_die_structure_name.
22657 In this case we know DIE has no useful parent. */
22659 static const char *
22660 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22662 struct die_info
*spec_die
;
22663 struct dwarf2_cu
*spec_cu
;
22664 struct die_info
*child
;
22665 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22668 spec_die
= die_specification (die
, &spec_cu
);
22669 if (spec_die
!= NULL
)
22675 for (child
= die
->child
;
22677 child
= child
->sibling
)
22679 if (child
->tag
== DW_TAG_subprogram
)
22681 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22683 if (linkage_name
!= NULL
)
22685 gdb::unique_xmalloc_ptr
<char> actual_name
22686 (language_class_name_from_physname (cu
->language_defn
,
22688 const char *name
= NULL
;
22690 if (actual_name
!= NULL
)
22692 const char *die_name
= dwarf2_name (die
, cu
);
22694 if (die_name
!= NULL
22695 && strcmp (die_name
, actual_name
.get ()) != 0)
22697 /* Strip off the class name from the full name.
22698 We want the prefix. */
22699 int die_name_len
= strlen (die_name
);
22700 int actual_name_len
= strlen (actual_name
.get ());
22701 const char *ptr
= actual_name
.get ();
22703 /* Test for '::' as a sanity check. */
22704 if (actual_name_len
> die_name_len
+ 2
22705 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22706 name
= obstack_strndup (
22707 &objfile
->per_bfd
->storage_obstack
,
22708 ptr
, actual_name_len
- die_name_len
- 2);
22719 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22720 prefix part in such case. See
22721 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22723 static const char *
22724 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22726 struct attribute
*attr
;
22729 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22730 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22733 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22736 attr
= dw2_linkage_name_attr (die
, cu
);
22737 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22740 /* dwarf2_name had to be already called. */
22741 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22743 /* Strip the base name, keep any leading namespaces/classes. */
22744 base
= strrchr (DW_STRING (attr
), ':');
22745 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22748 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22749 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22751 &base
[-1] - DW_STRING (attr
));
22754 /* Return the name of the namespace/class that DIE is defined within,
22755 or "" if we can't tell. The caller should not xfree the result.
22757 For example, if we're within the method foo() in the following
22767 then determine_prefix on foo's die will return "N::C". */
22769 static const char *
22770 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22772 struct dwarf2_per_objfile
*dwarf2_per_objfile
22773 = cu
->per_cu
->dwarf2_per_objfile
;
22774 struct die_info
*parent
, *spec_die
;
22775 struct dwarf2_cu
*spec_cu
;
22776 struct type
*parent_type
;
22777 const char *retval
;
22779 if (cu
->language
!= language_cplus
22780 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22781 && cu
->language
!= language_rust
)
22784 retval
= anonymous_struct_prefix (die
, cu
);
22788 /* We have to be careful in the presence of DW_AT_specification.
22789 For example, with GCC 3.4, given the code
22793 // Definition of N::foo.
22797 then we'll have a tree of DIEs like this:
22799 1: DW_TAG_compile_unit
22800 2: DW_TAG_namespace // N
22801 3: DW_TAG_subprogram // declaration of N::foo
22802 4: DW_TAG_subprogram // definition of N::foo
22803 DW_AT_specification // refers to die #3
22805 Thus, when processing die #4, we have to pretend that we're in
22806 the context of its DW_AT_specification, namely the contex of die
22809 spec_die
= die_specification (die
, &spec_cu
);
22810 if (spec_die
== NULL
)
22811 parent
= die
->parent
;
22814 parent
= spec_die
->parent
;
22818 if (parent
== NULL
)
22820 else if (parent
->building_fullname
)
22823 const char *parent_name
;
22825 /* It has been seen on RealView 2.2 built binaries,
22826 DW_TAG_template_type_param types actually _defined_ as
22827 children of the parent class:
22830 template class <class Enum> Class{};
22831 Class<enum E> class_e;
22833 1: DW_TAG_class_type (Class)
22834 2: DW_TAG_enumeration_type (E)
22835 3: DW_TAG_enumerator (enum1:0)
22836 3: DW_TAG_enumerator (enum2:1)
22838 2: DW_TAG_template_type_param
22839 DW_AT_type DW_FORM_ref_udata (E)
22841 Besides being broken debug info, it can put GDB into an
22842 infinite loop. Consider:
22844 When we're building the full name for Class<E>, we'll start
22845 at Class, and go look over its template type parameters,
22846 finding E. We'll then try to build the full name of E, and
22847 reach here. We're now trying to build the full name of E,
22848 and look over the parent DIE for containing scope. In the
22849 broken case, if we followed the parent DIE of E, we'd again
22850 find Class, and once again go look at its template type
22851 arguments, etc., etc. Simply don't consider such parent die
22852 as source-level parent of this die (it can't be, the language
22853 doesn't allow it), and break the loop here. */
22854 name
= dwarf2_name (die
, cu
);
22855 parent_name
= dwarf2_name (parent
, cu
);
22856 complaint (_("template param type '%s' defined within parent '%s'"),
22857 name
? name
: "<unknown>",
22858 parent_name
? parent_name
: "<unknown>");
22862 switch (parent
->tag
)
22864 case DW_TAG_namespace
:
22865 parent_type
= read_type_die (parent
, cu
);
22866 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22867 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22868 Work around this problem here. */
22869 if (cu
->language
== language_cplus
22870 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22872 /* We give a name to even anonymous namespaces. */
22873 return TYPE_NAME (parent_type
);
22874 case DW_TAG_class_type
:
22875 case DW_TAG_interface_type
:
22876 case DW_TAG_structure_type
:
22877 case DW_TAG_union_type
:
22878 case DW_TAG_module
:
22879 parent_type
= read_type_die (parent
, cu
);
22880 if (TYPE_NAME (parent_type
) != NULL
)
22881 return TYPE_NAME (parent_type
);
22883 /* An anonymous structure is only allowed non-static data
22884 members; no typedefs, no member functions, et cetera.
22885 So it does not need a prefix. */
22887 case DW_TAG_compile_unit
:
22888 case DW_TAG_partial_unit
:
22889 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22890 if (cu
->language
== language_cplus
22891 && !dwarf2_per_objfile
->types
.empty ()
22892 && die
->child
!= NULL
22893 && (die
->tag
== DW_TAG_class_type
22894 || die
->tag
== DW_TAG_structure_type
22895 || die
->tag
== DW_TAG_union_type
))
22897 const char *name
= guess_full_die_structure_name (die
, cu
);
22902 case DW_TAG_subprogram
:
22903 /* Nested subroutines in Fortran get a prefix with the name
22904 of the parent's subroutine. */
22905 if (cu
->language
== language_fortran
)
22907 if ((die
->tag
== DW_TAG_subprogram
)
22908 && (dwarf2_name (parent
, cu
) != NULL
))
22909 return dwarf2_name (parent
, cu
);
22911 return determine_prefix (parent
, cu
);
22912 case DW_TAG_enumeration_type
:
22913 parent_type
= read_type_die (parent
, cu
);
22914 if (TYPE_DECLARED_CLASS (parent_type
))
22916 if (TYPE_NAME (parent_type
) != NULL
)
22917 return TYPE_NAME (parent_type
);
22920 /* Fall through. */
22922 return determine_prefix (parent
, cu
);
22926 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22927 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22928 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22929 an obconcat, otherwise allocate storage for the result. The CU argument is
22930 used to determine the language and hence, the appropriate separator. */
22932 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22935 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22936 int physname
, struct dwarf2_cu
*cu
)
22938 const char *lead
= "";
22941 if (suffix
== NULL
|| suffix
[0] == '\0'
22942 || prefix
== NULL
|| prefix
[0] == '\0')
22944 else if (cu
->language
== language_d
)
22946 /* For D, the 'main' function could be defined in any module, but it
22947 should never be prefixed. */
22948 if (strcmp (suffix
, "D main") == 0)
22956 else if (cu
->language
== language_fortran
&& physname
)
22958 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22959 DW_AT_MIPS_linkage_name is preferred and used instead. */
22967 if (prefix
== NULL
)
22969 if (suffix
== NULL
)
22976 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22978 strcpy (retval
, lead
);
22979 strcat (retval
, prefix
);
22980 strcat (retval
, sep
);
22981 strcat (retval
, suffix
);
22986 /* We have an obstack. */
22987 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22991 /* Return sibling of die, NULL if no sibling. */
22993 static struct die_info
*
22994 sibling_die (struct die_info
*die
)
22996 return die
->sibling
;
22999 /* Get name of a die, return NULL if not found. */
23001 static const char *
23002 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23003 struct obstack
*obstack
)
23005 if (name
&& cu
->language
== language_cplus
)
23007 std::string canon_name
= cp_canonicalize_string (name
);
23009 if (!canon_name
.empty ())
23011 if (canon_name
!= name
)
23012 name
= obstack_strdup (obstack
, canon_name
);
23019 /* Get name of a die, return NULL if not found.
23020 Anonymous namespaces are converted to their magic string. */
23022 static const char *
23023 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23025 struct attribute
*attr
;
23026 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23028 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23029 if ((!attr
|| !DW_STRING (attr
))
23030 && die
->tag
!= DW_TAG_namespace
23031 && die
->tag
!= DW_TAG_class_type
23032 && die
->tag
!= DW_TAG_interface_type
23033 && die
->tag
!= DW_TAG_structure_type
23034 && die
->tag
!= DW_TAG_union_type
)
23039 case DW_TAG_compile_unit
:
23040 case DW_TAG_partial_unit
:
23041 /* Compilation units have a DW_AT_name that is a filename, not
23042 a source language identifier. */
23043 case DW_TAG_enumeration_type
:
23044 case DW_TAG_enumerator
:
23045 /* These tags always have simple identifiers already; no need
23046 to canonicalize them. */
23047 return DW_STRING (attr
);
23049 case DW_TAG_namespace
:
23050 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23051 return DW_STRING (attr
);
23052 return CP_ANONYMOUS_NAMESPACE_STR
;
23054 case DW_TAG_class_type
:
23055 case DW_TAG_interface_type
:
23056 case DW_TAG_structure_type
:
23057 case DW_TAG_union_type
:
23058 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23059 structures or unions. These were of the form "._%d" in GCC 4.1,
23060 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23061 and GCC 4.4. We work around this problem by ignoring these. */
23062 if (attr
&& DW_STRING (attr
)
23063 && (startswith (DW_STRING (attr
), "._")
23064 || startswith (DW_STRING (attr
), "<anonymous")))
23067 /* GCC might emit a nameless typedef that has a linkage name. See
23068 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23069 if (!attr
|| DW_STRING (attr
) == NULL
)
23071 attr
= dw2_linkage_name_attr (die
, cu
);
23072 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23075 /* Avoid demangling DW_STRING (attr) the second time on a second
23076 call for the same DIE. */
23077 if (!DW_STRING_IS_CANONICAL (attr
))
23079 gdb::unique_xmalloc_ptr
<char> demangled
23080 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23084 /* FIXME: we already did this for the partial symbol... */
23086 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23088 DW_STRING_IS_CANONICAL (attr
) = 1;
23090 /* Strip any leading namespaces/classes, keep only the base name.
23091 DW_AT_name for named DIEs does not contain the prefixes. */
23092 base
= strrchr (DW_STRING (attr
), ':');
23093 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23096 return DW_STRING (attr
);
23105 if (!DW_STRING_IS_CANONICAL (attr
))
23108 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23109 &objfile
->per_bfd
->storage_obstack
);
23110 DW_STRING_IS_CANONICAL (attr
) = 1;
23112 return DW_STRING (attr
);
23115 /* Return the die that this die in an extension of, or NULL if there
23116 is none. *EXT_CU is the CU containing DIE on input, and the CU
23117 containing the return value on output. */
23119 static struct die_info
*
23120 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23122 struct attribute
*attr
;
23124 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23128 return follow_die_ref (die
, attr
, ext_cu
);
23131 /* A convenience function that returns an "unknown" DWARF name,
23132 including the value of V. STR is the name of the entity being
23133 printed, e.g., "TAG". */
23135 static const char *
23136 dwarf_unknown (const char *str
, unsigned v
)
23138 char *cell
= get_print_cell ();
23139 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23143 /* Convert a DIE tag into its string name. */
23145 static const char *
23146 dwarf_tag_name (unsigned tag
)
23148 const char *name
= get_DW_TAG_name (tag
);
23151 return dwarf_unknown ("TAG", tag
);
23156 /* Convert a DWARF attribute code into its string name. */
23158 static const char *
23159 dwarf_attr_name (unsigned attr
)
23163 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23164 if (attr
== DW_AT_MIPS_fde
)
23165 return "DW_AT_MIPS_fde";
23167 if (attr
== DW_AT_HP_block_index
)
23168 return "DW_AT_HP_block_index";
23171 name
= get_DW_AT_name (attr
);
23174 return dwarf_unknown ("AT", attr
);
23179 /* Convert a unit type to corresponding DW_UT name. */
23181 static const char *
23182 dwarf_unit_type_name (int unit_type
) {
23186 return "DW_UT_compile (0x01)";
23188 return "DW_UT_type (0x02)";
23190 return "DW_UT_partial (0x03)";
23192 return "DW_UT_skeleton (0x04)";
23194 return "DW_UT_split_compile (0x05)";
23196 return "DW_UT_split_type (0x06)";
23198 return "DW_UT_lo_user (0x80)";
23200 return "DW_UT_hi_user (0xff)";
23206 /* Convert a DWARF value form code into its string name. */
23208 static const char *
23209 dwarf_form_name (unsigned form
)
23211 const char *name
= get_DW_FORM_name (form
);
23214 return dwarf_unknown ("FORM", form
);
23219 static const char *
23220 dwarf_bool_name (unsigned mybool
)
23228 /* Convert a DWARF type code into its string name. */
23230 static const char *
23231 dwarf_type_encoding_name (unsigned enc
)
23233 const char *name
= get_DW_ATE_name (enc
);
23236 return dwarf_unknown ("ATE", enc
);
23242 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23246 print_spaces (indent
, f
);
23247 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23248 dwarf_tag_name (die
->tag
), die
->abbrev
,
23249 sect_offset_str (die
->sect_off
));
23251 if (die
->parent
!= NULL
)
23253 print_spaces (indent
, f
);
23254 fprintf_unfiltered (f
, " parent at offset: %s\n",
23255 sect_offset_str (die
->parent
->sect_off
));
23258 print_spaces (indent
, f
);
23259 fprintf_unfiltered (f
, " has children: %s\n",
23260 dwarf_bool_name (die
->child
!= NULL
));
23262 print_spaces (indent
, f
);
23263 fprintf_unfiltered (f
, " attributes:\n");
23265 for (i
= 0; i
< die
->num_attrs
; ++i
)
23267 print_spaces (indent
, f
);
23268 fprintf_unfiltered (f
, " %s (%s) ",
23269 dwarf_attr_name (die
->attrs
[i
].name
),
23270 dwarf_form_name (die
->attrs
[i
].form
));
23272 switch (die
->attrs
[i
].form
)
23275 case DW_FORM_addrx
:
23276 case DW_FORM_GNU_addr_index
:
23277 fprintf_unfiltered (f
, "address: ");
23278 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23280 case DW_FORM_block2
:
23281 case DW_FORM_block4
:
23282 case DW_FORM_block
:
23283 case DW_FORM_block1
:
23284 fprintf_unfiltered (f
, "block: size %s",
23285 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23287 case DW_FORM_exprloc
:
23288 fprintf_unfiltered (f
, "expression: size %s",
23289 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23291 case DW_FORM_data16
:
23292 fprintf_unfiltered (f
, "constant of 16 bytes");
23294 case DW_FORM_ref_addr
:
23295 fprintf_unfiltered (f
, "ref address: ");
23296 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23298 case DW_FORM_GNU_ref_alt
:
23299 fprintf_unfiltered (f
, "alt ref address: ");
23300 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23306 case DW_FORM_ref_udata
:
23307 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23308 (long) (DW_UNSND (&die
->attrs
[i
])));
23310 case DW_FORM_data1
:
23311 case DW_FORM_data2
:
23312 case DW_FORM_data4
:
23313 case DW_FORM_data8
:
23314 case DW_FORM_udata
:
23315 case DW_FORM_sdata
:
23316 fprintf_unfiltered (f
, "constant: %s",
23317 pulongest (DW_UNSND (&die
->attrs
[i
])));
23319 case DW_FORM_sec_offset
:
23320 fprintf_unfiltered (f
, "section offset: %s",
23321 pulongest (DW_UNSND (&die
->attrs
[i
])));
23323 case DW_FORM_ref_sig8
:
23324 fprintf_unfiltered (f
, "signature: %s",
23325 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23327 case DW_FORM_string
:
23329 case DW_FORM_line_strp
:
23331 case DW_FORM_GNU_str_index
:
23332 case DW_FORM_GNU_strp_alt
:
23333 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23334 DW_STRING (&die
->attrs
[i
])
23335 ? DW_STRING (&die
->attrs
[i
]) : "",
23336 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23339 if (DW_UNSND (&die
->attrs
[i
]))
23340 fprintf_unfiltered (f
, "flag: TRUE");
23342 fprintf_unfiltered (f
, "flag: FALSE");
23344 case DW_FORM_flag_present
:
23345 fprintf_unfiltered (f
, "flag: TRUE");
23347 case DW_FORM_indirect
:
23348 /* The reader will have reduced the indirect form to
23349 the "base form" so this form should not occur. */
23350 fprintf_unfiltered (f
,
23351 "unexpected attribute form: DW_FORM_indirect");
23353 case DW_FORM_implicit_const
:
23354 fprintf_unfiltered (f
, "constant: %s",
23355 plongest (DW_SND (&die
->attrs
[i
])));
23358 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23359 die
->attrs
[i
].form
);
23362 fprintf_unfiltered (f
, "\n");
23367 dump_die_for_error (struct die_info
*die
)
23369 dump_die_shallow (gdb_stderr
, 0, die
);
23373 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23375 int indent
= level
* 4;
23377 gdb_assert (die
!= NULL
);
23379 if (level
>= max_level
)
23382 dump_die_shallow (f
, indent
, die
);
23384 if (die
->child
!= NULL
)
23386 print_spaces (indent
, f
);
23387 fprintf_unfiltered (f
, " Children:");
23388 if (level
+ 1 < max_level
)
23390 fprintf_unfiltered (f
, "\n");
23391 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23395 fprintf_unfiltered (f
,
23396 " [not printed, max nesting level reached]\n");
23400 if (die
->sibling
!= NULL
&& level
> 0)
23402 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23406 /* This is called from the pdie macro in gdbinit.in.
23407 It's not static so gcc will keep a copy callable from gdb. */
23410 dump_die (struct die_info
*die
, int max_level
)
23412 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23416 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23420 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23421 to_underlying (die
->sect_off
),
23427 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23431 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23433 if (attr_form_is_ref (attr
))
23434 return (sect_offset
) DW_UNSND (attr
);
23436 complaint (_("unsupported die ref attribute form: '%s'"),
23437 dwarf_form_name (attr
->form
));
23441 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23442 * the value held by the attribute is not constant. */
23445 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23447 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23448 return DW_SND (attr
);
23449 else if (attr
->form
== DW_FORM_udata
23450 || attr
->form
== DW_FORM_data1
23451 || attr
->form
== DW_FORM_data2
23452 || attr
->form
== DW_FORM_data4
23453 || attr
->form
== DW_FORM_data8
)
23454 return DW_UNSND (attr
);
23457 /* For DW_FORM_data16 see attr_form_is_constant. */
23458 complaint (_("Attribute value is not a constant (%s)"),
23459 dwarf_form_name (attr
->form
));
23460 return default_value
;
23464 /* Follow reference or signature attribute ATTR of SRC_DIE.
23465 On entry *REF_CU is the CU of SRC_DIE.
23466 On exit *REF_CU is the CU of the result. */
23468 static struct die_info
*
23469 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23470 struct dwarf2_cu
**ref_cu
)
23472 struct die_info
*die
;
23474 if (attr_form_is_ref (attr
))
23475 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23476 else if (attr
->form
== DW_FORM_ref_sig8
)
23477 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23480 dump_die_for_error (src_die
);
23481 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23482 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23488 /* Follow reference OFFSET.
23489 On entry *REF_CU is the CU of the source die referencing OFFSET.
23490 On exit *REF_CU is the CU of the result.
23491 Returns NULL if OFFSET is invalid. */
23493 static struct die_info
*
23494 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23495 struct dwarf2_cu
**ref_cu
)
23497 struct die_info temp_die
;
23498 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23499 struct dwarf2_per_objfile
*dwarf2_per_objfile
23500 = cu
->per_cu
->dwarf2_per_objfile
;
23502 gdb_assert (cu
->per_cu
!= NULL
);
23506 if (cu
->per_cu
->is_debug_types
)
23508 /* .debug_types CUs cannot reference anything outside their CU.
23509 If they need to, they have to reference a signatured type via
23510 DW_FORM_ref_sig8. */
23511 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23514 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23515 || !offset_in_cu_p (&cu
->header
, sect_off
))
23517 struct dwarf2_per_cu_data
*per_cu
;
23519 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23520 dwarf2_per_objfile
);
23522 /* If necessary, add it to the queue and load its DIEs. */
23523 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23524 load_full_comp_unit (per_cu
, false, cu
->language
);
23526 target_cu
= per_cu
->cu
;
23528 else if (cu
->dies
== NULL
)
23530 /* We're loading full DIEs during partial symbol reading. */
23531 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23532 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23535 *ref_cu
= target_cu
;
23536 temp_die
.sect_off
= sect_off
;
23538 if (target_cu
!= cu
)
23539 target_cu
->ancestor
= cu
;
23541 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23543 to_underlying (sect_off
));
23546 /* Follow reference attribute ATTR of SRC_DIE.
23547 On entry *REF_CU is the CU of SRC_DIE.
23548 On exit *REF_CU is the CU of the result. */
23550 static struct die_info
*
23551 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23552 struct dwarf2_cu
**ref_cu
)
23554 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23555 struct dwarf2_cu
*cu
= *ref_cu
;
23556 struct die_info
*die
;
23558 die
= follow_die_offset (sect_off
,
23559 (attr
->form
== DW_FORM_GNU_ref_alt
23560 || cu
->per_cu
->is_dwz
),
23563 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23564 "at %s [in module %s]"),
23565 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23566 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23571 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23572 Returned value is intended for DW_OP_call*. Returned
23573 dwarf2_locexpr_baton->data has lifetime of
23574 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23576 struct dwarf2_locexpr_baton
23577 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23578 struct dwarf2_per_cu_data
*per_cu
,
23579 CORE_ADDR (*get_frame_pc
) (void *baton
),
23580 void *baton
, bool resolve_abstract_p
)
23582 struct dwarf2_cu
*cu
;
23583 struct die_info
*die
;
23584 struct attribute
*attr
;
23585 struct dwarf2_locexpr_baton retval
;
23586 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23587 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23589 if (per_cu
->cu
== NULL
)
23590 load_cu (per_cu
, false);
23594 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23595 Instead just throw an error, not much else we can do. */
23596 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23597 sect_offset_str (sect_off
), objfile_name (objfile
));
23600 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23602 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23603 sect_offset_str (sect_off
), objfile_name (objfile
));
23605 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23606 if (!attr
&& resolve_abstract_p
23607 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23608 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23610 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23612 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23613 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23615 for (const auto &cand_off
23616 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23618 struct dwarf2_cu
*cand_cu
= cu
;
23619 struct die_info
*cand
23620 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23623 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23626 CORE_ADDR pc_low
, pc_high
;
23627 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23628 if (pc_low
== ((CORE_ADDR
) -1))
23630 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23631 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23632 if (!(pc_low
<= pc
&& pc
< pc_high
))
23636 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23643 /* DWARF: "If there is no such attribute, then there is no effect.".
23644 DATA is ignored if SIZE is 0. */
23646 retval
.data
= NULL
;
23649 else if (attr_form_is_section_offset (attr
))
23651 struct dwarf2_loclist_baton loclist_baton
;
23652 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23655 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23657 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23659 retval
.size
= size
;
23663 if (!attr_form_is_block (attr
))
23664 error (_("Dwarf Error: DIE at %s referenced in module %s "
23665 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23666 sect_offset_str (sect_off
), objfile_name (objfile
));
23668 retval
.data
= DW_BLOCK (attr
)->data
;
23669 retval
.size
= DW_BLOCK (attr
)->size
;
23671 retval
.per_cu
= cu
->per_cu
;
23673 age_cached_comp_units (dwarf2_per_objfile
);
23678 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23681 struct dwarf2_locexpr_baton
23682 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23683 struct dwarf2_per_cu_data
*per_cu
,
23684 CORE_ADDR (*get_frame_pc
) (void *baton
),
23687 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23689 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23692 /* Write a constant of a given type as target-ordered bytes into
23695 static const gdb_byte
*
23696 write_constant_as_bytes (struct obstack
*obstack
,
23697 enum bfd_endian byte_order
,
23704 *len
= TYPE_LENGTH (type
);
23705 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23706 store_unsigned_integer (result
, *len
, byte_order
, value
);
23711 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23712 pointer to the constant bytes and set LEN to the length of the
23713 data. If memory is needed, allocate it on OBSTACK. If the DIE
23714 does not have a DW_AT_const_value, return NULL. */
23717 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23718 struct dwarf2_per_cu_data
*per_cu
,
23719 struct obstack
*obstack
,
23722 struct dwarf2_cu
*cu
;
23723 struct die_info
*die
;
23724 struct attribute
*attr
;
23725 const gdb_byte
*result
= NULL
;
23728 enum bfd_endian byte_order
;
23729 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23731 if (per_cu
->cu
== NULL
)
23732 load_cu (per_cu
, false);
23736 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23737 Instead just throw an error, not much else we can do. */
23738 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23739 sect_offset_str (sect_off
), objfile_name (objfile
));
23742 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23744 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23745 sect_offset_str (sect_off
), objfile_name (objfile
));
23747 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23751 byte_order
= (bfd_big_endian (objfile
->obfd
)
23752 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23754 switch (attr
->form
)
23757 case DW_FORM_addrx
:
23758 case DW_FORM_GNU_addr_index
:
23762 *len
= cu
->header
.addr_size
;
23763 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23764 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23768 case DW_FORM_string
:
23771 case DW_FORM_GNU_str_index
:
23772 case DW_FORM_GNU_strp_alt
:
23773 /* DW_STRING is already allocated on the objfile obstack, point
23775 result
= (const gdb_byte
*) DW_STRING (attr
);
23776 *len
= strlen (DW_STRING (attr
));
23778 case DW_FORM_block1
:
23779 case DW_FORM_block2
:
23780 case DW_FORM_block4
:
23781 case DW_FORM_block
:
23782 case DW_FORM_exprloc
:
23783 case DW_FORM_data16
:
23784 result
= DW_BLOCK (attr
)->data
;
23785 *len
= DW_BLOCK (attr
)->size
;
23788 /* The DW_AT_const_value attributes are supposed to carry the
23789 symbol's value "represented as it would be on the target
23790 architecture." By the time we get here, it's already been
23791 converted to host endianness, so we just need to sign- or
23792 zero-extend it as appropriate. */
23793 case DW_FORM_data1
:
23794 type
= die_type (die
, cu
);
23795 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23796 if (result
== NULL
)
23797 result
= write_constant_as_bytes (obstack
, byte_order
,
23800 case DW_FORM_data2
:
23801 type
= die_type (die
, cu
);
23802 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23803 if (result
== NULL
)
23804 result
= write_constant_as_bytes (obstack
, byte_order
,
23807 case DW_FORM_data4
:
23808 type
= die_type (die
, cu
);
23809 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23810 if (result
== NULL
)
23811 result
= write_constant_as_bytes (obstack
, byte_order
,
23814 case DW_FORM_data8
:
23815 type
= die_type (die
, cu
);
23816 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23817 if (result
== NULL
)
23818 result
= write_constant_as_bytes (obstack
, byte_order
,
23822 case DW_FORM_sdata
:
23823 case DW_FORM_implicit_const
:
23824 type
= die_type (die
, cu
);
23825 result
= write_constant_as_bytes (obstack
, byte_order
,
23826 type
, DW_SND (attr
), len
);
23829 case DW_FORM_udata
:
23830 type
= die_type (die
, cu
);
23831 result
= write_constant_as_bytes (obstack
, byte_order
,
23832 type
, DW_UNSND (attr
), len
);
23836 complaint (_("unsupported const value attribute form: '%s'"),
23837 dwarf_form_name (attr
->form
));
23844 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23845 valid type for this die is found. */
23848 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23849 struct dwarf2_per_cu_data
*per_cu
)
23851 struct dwarf2_cu
*cu
;
23852 struct die_info
*die
;
23854 if (per_cu
->cu
== NULL
)
23855 load_cu (per_cu
, false);
23860 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23864 return die_type (die
, cu
);
23867 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23871 dwarf2_get_die_type (cu_offset die_offset
,
23872 struct dwarf2_per_cu_data
*per_cu
)
23874 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23875 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23878 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23879 On entry *REF_CU is the CU of SRC_DIE.
23880 On exit *REF_CU is the CU of the result.
23881 Returns NULL if the referenced DIE isn't found. */
23883 static struct die_info
*
23884 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23885 struct dwarf2_cu
**ref_cu
)
23887 struct die_info temp_die
;
23888 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23889 struct die_info
*die
;
23891 /* While it might be nice to assert sig_type->type == NULL here,
23892 we can get here for DW_AT_imported_declaration where we need
23893 the DIE not the type. */
23895 /* If necessary, add it to the queue and load its DIEs. */
23897 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23898 read_signatured_type (sig_type
);
23900 sig_cu
= sig_type
->per_cu
.cu
;
23901 gdb_assert (sig_cu
!= NULL
);
23902 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23903 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23904 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23905 to_underlying (temp_die
.sect_off
));
23908 struct dwarf2_per_objfile
*dwarf2_per_objfile
23909 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23911 /* For .gdb_index version 7 keep track of included TUs.
23912 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23913 if (dwarf2_per_objfile
->index_table
!= NULL
23914 && dwarf2_per_objfile
->index_table
->version
<= 7)
23916 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23921 sig_cu
->ancestor
= cu
;
23929 /* Follow signatured type referenced by ATTR in SRC_DIE.
23930 On entry *REF_CU is the CU of SRC_DIE.
23931 On exit *REF_CU is the CU of the result.
23932 The result is the DIE of the type.
23933 If the referenced type cannot be found an error is thrown. */
23935 static struct die_info
*
23936 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23937 struct dwarf2_cu
**ref_cu
)
23939 ULONGEST signature
= DW_SIGNATURE (attr
);
23940 struct signatured_type
*sig_type
;
23941 struct die_info
*die
;
23943 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23945 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23946 /* sig_type will be NULL if the signatured type is missing from
23948 if (sig_type
== NULL
)
23950 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23951 " from DIE at %s [in module %s]"),
23952 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23953 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23956 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23959 dump_die_for_error (src_die
);
23960 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23961 " from DIE at %s [in module %s]"),
23962 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23963 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23969 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23970 reading in and processing the type unit if necessary. */
23972 static struct type
*
23973 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23974 struct dwarf2_cu
*cu
)
23976 struct dwarf2_per_objfile
*dwarf2_per_objfile
23977 = cu
->per_cu
->dwarf2_per_objfile
;
23978 struct signatured_type
*sig_type
;
23979 struct dwarf2_cu
*type_cu
;
23980 struct die_info
*type_die
;
23983 sig_type
= lookup_signatured_type (cu
, signature
);
23984 /* sig_type will be NULL if the signatured type is missing from
23986 if (sig_type
== NULL
)
23988 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23989 " from DIE at %s [in module %s]"),
23990 hex_string (signature
), sect_offset_str (die
->sect_off
),
23991 objfile_name (dwarf2_per_objfile
->objfile
));
23992 return build_error_marker_type (cu
, die
);
23995 /* If we already know the type we're done. */
23996 if (sig_type
->type
!= NULL
)
23997 return sig_type
->type
;
24000 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24001 if (type_die
!= NULL
)
24003 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24004 is created. This is important, for example, because for c++ classes
24005 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24006 type
= read_type_die (type_die
, type_cu
);
24009 complaint (_("Dwarf Error: Cannot build signatured type %s"
24010 " referenced from DIE at %s [in module %s]"),
24011 hex_string (signature
), sect_offset_str (die
->sect_off
),
24012 objfile_name (dwarf2_per_objfile
->objfile
));
24013 type
= build_error_marker_type (cu
, die
);
24018 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24019 " from DIE at %s [in module %s]"),
24020 hex_string (signature
), sect_offset_str (die
->sect_off
),
24021 objfile_name (dwarf2_per_objfile
->objfile
));
24022 type
= build_error_marker_type (cu
, die
);
24024 sig_type
->type
= type
;
24029 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24030 reading in and processing the type unit if necessary. */
24032 static struct type
*
24033 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24034 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24036 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24037 if (attr_form_is_ref (attr
))
24039 struct dwarf2_cu
*type_cu
= cu
;
24040 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24042 return read_type_die (type_die
, type_cu
);
24044 else if (attr
->form
== DW_FORM_ref_sig8
)
24046 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24050 struct dwarf2_per_objfile
*dwarf2_per_objfile
24051 = cu
->per_cu
->dwarf2_per_objfile
;
24053 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24054 " at %s [in module %s]"),
24055 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24056 objfile_name (dwarf2_per_objfile
->objfile
));
24057 return build_error_marker_type (cu
, die
);
24061 /* Load the DIEs associated with type unit PER_CU into memory. */
24064 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24066 struct signatured_type
*sig_type
;
24068 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24069 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24071 /* We have the per_cu, but we need the signatured_type.
24072 Fortunately this is an easy translation. */
24073 gdb_assert (per_cu
->is_debug_types
);
24074 sig_type
= (struct signatured_type
*) per_cu
;
24076 gdb_assert (per_cu
->cu
== NULL
);
24078 read_signatured_type (sig_type
);
24080 gdb_assert (per_cu
->cu
!= NULL
);
24083 /* die_reader_func for read_signatured_type.
24084 This is identical to load_full_comp_unit_reader,
24085 but is kept separate for now. */
24088 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24089 const gdb_byte
*info_ptr
,
24090 struct die_info
*comp_unit_die
,
24094 struct dwarf2_cu
*cu
= reader
->cu
;
24096 gdb_assert (cu
->die_hash
== NULL
);
24098 htab_create_alloc_ex (cu
->header
.length
/ 12,
24102 &cu
->comp_unit_obstack
,
24103 hashtab_obstack_allocate
,
24104 dummy_obstack_deallocate
);
24107 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24108 &info_ptr
, comp_unit_die
);
24109 cu
->dies
= comp_unit_die
;
24110 /* comp_unit_die is not stored in die_hash, no need. */
24112 /* We try not to read any attributes in this function, because not
24113 all CUs needed for references have been loaded yet, and symbol
24114 table processing isn't initialized. But we have to set the CU language,
24115 or we won't be able to build types correctly.
24116 Similarly, if we do not read the producer, we can not apply
24117 producer-specific interpretation. */
24118 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24121 /* Read in a signatured type and build its CU and DIEs.
24122 If the type is a stub for the real type in a DWO file,
24123 read in the real type from the DWO file as well. */
24126 read_signatured_type (struct signatured_type
*sig_type
)
24128 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24130 gdb_assert (per_cu
->is_debug_types
);
24131 gdb_assert (per_cu
->cu
== NULL
);
24133 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24134 read_signatured_type_reader
, NULL
);
24135 sig_type
->per_cu
.tu_read
= 1;
24138 /* Decode simple location descriptions.
24139 Given a pointer to a dwarf block that defines a location, compute
24140 the location and return the value.
24142 NOTE drow/2003-11-18: This function is called in two situations
24143 now: for the address of static or global variables (partial symbols
24144 only) and for offsets into structures which are expected to be
24145 (more or less) constant. The partial symbol case should go away,
24146 and only the constant case should remain. That will let this
24147 function complain more accurately. A few special modes are allowed
24148 without complaint for global variables (for instance, global
24149 register values and thread-local values).
24151 A location description containing no operations indicates that the
24152 object is optimized out. The return value is 0 for that case.
24153 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24154 callers will only want a very basic result and this can become a
24157 Note that stack[0] is unused except as a default error return. */
24160 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24162 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24164 size_t size
= blk
->size
;
24165 const gdb_byte
*data
= blk
->data
;
24166 CORE_ADDR stack
[64];
24168 unsigned int bytes_read
, unsnd
;
24174 stack
[++stacki
] = 0;
24213 stack
[++stacki
] = op
- DW_OP_lit0
;
24248 stack
[++stacki
] = op
- DW_OP_reg0
;
24250 dwarf2_complex_location_expr_complaint ();
24254 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24256 stack
[++stacki
] = unsnd
;
24258 dwarf2_complex_location_expr_complaint ();
24262 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24267 case DW_OP_const1u
:
24268 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24272 case DW_OP_const1s
:
24273 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24277 case DW_OP_const2u
:
24278 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24282 case DW_OP_const2s
:
24283 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24287 case DW_OP_const4u
:
24288 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24292 case DW_OP_const4s
:
24293 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24297 case DW_OP_const8u
:
24298 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24303 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24309 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24314 stack
[stacki
+ 1] = stack
[stacki
];
24319 stack
[stacki
- 1] += stack
[stacki
];
24323 case DW_OP_plus_uconst
:
24324 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24330 stack
[stacki
- 1] -= stack
[stacki
];
24335 /* If we're not the last op, then we definitely can't encode
24336 this using GDB's address_class enum. This is valid for partial
24337 global symbols, although the variable's address will be bogus
24340 dwarf2_complex_location_expr_complaint ();
24343 case DW_OP_GNU_push_tls_address
:
24344 case DW_OP_form_tls_address
:
24345 /* The top of the stack has the offset from the beginning
24346 of the thread control block at which the variable is located. */
24347 /* Nothing should follow this operator, so the top of stack would
24349 /* This is valid for partial global symbols, but the variable's
24350 address will be bogus in the psymtab. Make it always at least
24351 non-zero to not look as a variable garbage collected by linker
24352 which have DW_OP_addr 0. */
24354 dwarf2_complex_location_expr_complaint ();
24358 case DW_OP_GNU_uninit
:
24362 case DW_OP_GNU_addr_index
:
24363 case DW_OP_GNU_const_index
:
24364 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24371 const char *name
= get_DW_OP_name (op
);
24374 complaint (_("unsupported stack op: '%s'"),
24377 complaint (_("unsupported stack op: '%02x'"),
24381 return (stack
[stacki
]);
24384 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24385 outside of the allocated space. Also enforce minimum>0. */
24386 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24388 complaint (_("location description stack overflow"));
24394 complaint (_("location description stack underflow"));
24398 return (stack
[stacki
]);
24401 /* memory allocation interface */
24403 static struct dwarf_block
*
24404 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24406 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24409 static struct die_info
*
24410 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24412 struct die_info
*die
;
24413 size_t size
= sizeof (struct die_info
);
24416 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24418 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24419 memset (die
, 0, sizeof (struct die_info
));
24424 /* Macro support. */
24426 /* Return file name relative to the compilation directory of file number I in
24427 *LH's file name table. The result is allocated using xmalloc; the caller is
24428 responsible for freeing it. */
24431 file_file_name (int file
, struct line_header
*lh
)
24433 /* Is the file number a valid index into the line header's file name
24434 table? Remember that file numbers start with one, not zero. */
24435 if (lh
->is_valid_file_index (file
))
24437 const file_entry
*fe
= lh
->file_name_at (file
);
24439 if (!IS_ABSOLUTE_PATH (fe
->name
))
24441 const char *dir
= fe
->include_dir (lh
);
24443 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24445 return xstrdup (fe
->name
);
24449 /* The compiler produced a bogus file number. We can at least
24450 record the macro definitions made in the file, even if we
24451 won't be able to find the file by name. */
24452 char fake_name
[80];
24454 xsnprintf (fake_name
, sizeof (fake_name
),
24455 "<bad macro file number %d>", file
);
24457 complaint (_("bad file number in macro information (%d)"),
24460 return xstrdup (fake_name
);
24464 /* Return the full name of file number I in *LH's file name table.
24465 Use COMP_DIR as the name of the current directory of the
24466 compilation. The result is allocated using xmalloc; the caller is
24467 responsible for freeing it. */
24469 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24471 /* Is the file number a valid index into the line header's file name
24472 table? Remember that file numbers start with one, not zero. */
24473 if (lh
->is_valid_file_index (file
))
24475 char *relative
= file_file_name (file
, lh
);
24477 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24479 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24480 relative
, (char *) NULL
);
24483 return file_file_name (file
, lh
);
24487 static struct macro_source_file
*
24488 macro_start_file (struct dwarf2_cu
*cu
,
24489 int file
, int line
,
24490 struct macro_source_file
*current_file
,
24491 struct line_header
*lh
)
24493 /* File name relative to the compilation directory of this source file. */
24494 char *file_name
= file_file_name (file
, lh
);
24496 if (! current_file
)
24498 /* Note: We don't create a macro table for this compilation unit
24499 at all until we actually get a filename. */
24500 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24502 /* If we have no current file, then this must be the start_file
24503 directive for the compilation unit's main source file. */
24504 current_file
= macro_set_main (macro_table
, file_name
);
24505 macro_define_special (macro_table
);
24508 current_file
= macro_include (current_file
, line
, file_name
);
24512 return current_file
;
24515 static const char *
24516 consume_improper_spaces (const char *p
, const char *body
)
24520 complaint (_("macro definition contains spaces "
24521 "in formal argument list:\n`%s'"),
24533 parse_macro_definition (struct macro_source_file
*file
, int line
,
24538 /* The body string takes one of two forms. For object-like macro
24539 definitions, it should be:
24541 <macro name> " " <definition>
24543 For function-like macro definitions, it should be:
24545 <macro name> "() " <definition>
24547 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24549 Spaces may appear only where explicitly indicated, and in the
24552 The Dwarf 2 spec says that an object-like macro's name is always
24553 followed by a space, but versions of GCC around March 2002 omit
24554 the space when the macro's definition is the empty string.
24556 The Dwarf 2 spec says that there should be no spaces between the
24557 formal arguments in a function-like macro's formal argument list,
24558 but versions of GCC around March 2002 include spaces after the
24562 /* Find the extent of the macro name. The macro name is terminated
24563 by either a space or null character (for an object-like macro) or
24564 an opening paren (for a function-like macro). */
24565 for (p
= body
; *p
; p
++)
24566 if (*p
== ' ' || *p
== '(')
24569 if (*p
== ' ' || *p
== '\0')
24571 /* It's an object-like macro. */
24572 int name_len
= p
- body
;
24573 std::string
name (body
, name_len
);
24574 const char *replacement
;
24577 replacement
= body
+ name_len
+ 1;
24580 dwarf2_macro_malformed_definition_complaint (body
);
24581 replacement
= body
+ name_len
;
24584 macro_define_object (file
, line
, name
.c_str (), replacement
);
24586 else if (*p
== '(')
24588 /* It's a function-like macro. */
24589 std::string
name (body
, p
- body
);
24592 char **argv
= XNEWVEC (char *, argv_size
);
24596 p
= consume_improper_spaces (p
, body
);
24598 /* Parse the formal argument list. */
24599 while (*p
&& *p
!= ')')
24601 /* Find the extent of the current argument name. */
24602 const char *arg_start
= p
;
24604 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24607 if (! *p
|| p
== arg_start
)
24608 dwarf2_macro_malformed_definition_complaint (body
);
24611 /* Make sure argv has room for the new argument. */
24612 if (argc
>= argv_size
)
24615 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24618 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24621 p
= consume_improper_spaces (p
, body
);
24623 /* Consume the comma, if present. */
24628 p
= consume_improper_spaces (p
, body
);
24637 /* Perfectly formed definition, no complaints. */
24638 macro_define_function (file
, line
, name
.c_str (),
24639 argc
, (const char **) argv
,
24641 else if (*p
== '\0')
24643 /* Complain, but do define it. */
24644 dwarf2_macro_malformed_definition_complaint (body
);
24645 macro_define_function (file
, line
, name
.c_str (),
24646 argc
, (const char **) argv
,
24650 /* Just complain. */
24651 dwarf2_macro_malformed_definition_complaint (body
);
24654 /* Just complain. */
24655 dwarf2_macro_malformed_definition_complaint (body
);
24660 for (i
= 0; i
< argc
; i
++)
24666 dwarf2_macro_malformed_definition_complaint (body
);
24669 /* Skip some bytes from BYTES according to the form given in FORM.
24670 Returns the new pointer. */
24672 static const gdb_byte
*
24673 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24674 enum dwarf_form form
,
24675 unsigned int offset_size
,
24676 struct dwarf2_section_info
*section
)
24678 unsigned int bytes_read
;
24682 case DW_FORM_data1
:
24687 case DW_FORM_data2
:
24691 case DW_FORM_data4
:
24695 case DW_FORM_data8
:
24699 case DW_FORM_data16
:
24703 case DW_FORM_string
:
24704 read_direct_string (abfd
, bytes
, &bytes_read
);
24705 bytes
+= bytes_read
;
24708 case DW_FORM_sec_offset
:
24710 case DW_FORM_GNU_strp_alt
:
24711 bytes
+= offset_size
;
24714 case DW_FORM_block
:
24715 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24716 bytes
+= bytes_read
;
24719 case DW_FORM_block1
:
24720 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24722 case DW_FORM_block2
:
24723 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24725 case DW_FORM_block4
:
24726 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24729 case DW_FORM_addrx
:
24730 case DW_FORM_sdata
:
24732 case DW_FORM_udata
:
24733 case DW_FORM_GNU_addr_index
:
24734 case DW_FORM_GNU_str_index
:
24735 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24738 dwarf2_section_buffer_overflow_complaint (section
);
24743 case DW_FORM_implicit_const
:
24748 complaint (_("invalid form 0x%x in `%s'"),
24749 form
, get_section_name (section
));
24757 /* A helper for dwarf_decode_macros that handles skipping an unknown
24758 opcode. Returns an updated pointer to the macro data buffer; or,
24759 on error, issues a complaint and returns NULL. */
24761 static const gdb_byte
*
24762 skip_unknown_opcode (unsigned int opcode
,
24763 const gdb_byte
**opcode_definitions
,
24764 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24766 unsigned int offset_size
,
24767 struct dwarf2_section_info
*section
)
24769 unsigned int bytes_read
, i
;
24771 const gdb_byte
*defn
;
24773 if (opcode_definitions
[opcode
] == NULL
)
24775 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24780 defn
= opcode_definitions
[opcode
];
24781 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24782 defn
+= bytes_read
;
24784 for (i
= 0; i
< arg
; ++i
)
24786 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24787 (enum dwarf_form
) defn
[i
], offset_size
,
24789 if (mac_ptr
== NULL
)
24791 /* skip_form_bytes already issued the complaint. */
24799 /* A helper function which parses the header of a macro section.
24800 If the macro section is the extended (for now called "GNU") type,
24801 then this updates *OFFSET_SIZE. Returns a pointer to just after
24802 the header, or issues a complaint and returns NULL on error. */
24804 static const gdb_byte
*
24805 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24807 const gdb_byte
*mac_ptr
,
24808 unsigned int *offset_size
,
24809 int section_is_gnu
)
24811 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24813 if (section_is_gnu
)
24815 unsigned int version
, flags
;
24817 version
= read_2_bytes (abfd
, mac_ptr
);
24818 if (version
!= 4 && version
!= 5)
24820 complaint (_("unrecognized version `%d' in .debug_macro section"),
24826 flags
= read_1_byte (abfd
, mac_ptr
);
24828 *offset_size
= (flags
& 1) ? 8 : 4;
24830 if ((flags
& 2) != 0)
24831 /* We don't need the line table offset. */
24832 mac_ptr
+= *offset_size
;
24834 /* Vendor opcode descriptions. */
24835 if ((flags
& 4) != 0)
24837 unsigned int i
, count
;
24839 count
= read_1_byte (abfd
, mac_ptr
);
24841 for (i
= 0; i
< count
; ++i
)
24843 unsigned int opcode
, bytes_read
;
24846 opcode
= read_1_byte (abfd
, mac_ptr
);
24848 opcode_definitions
[opcode
] = mac_ptr
;
24849 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24850 mac_ptr
+= bytes_read
;
24859 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24860 including DW_MACRO_import. */
24863 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24865 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24866 struct macro_source_file
*current_file
,
24867 struct line_header
*lh
,
24868 struct dwarf2_section_info
*section
,
24869 int section_is_gnu
, int section_is_dwz
,
24870 unsigned int offset_size
,
24871 htab_t include_hash
)
24873 struct dwarf2_per_objfile
*dwarf2_per_objfile
24874 = cu
->per_cu
->dwarf2_per_objfile
;
24875 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24876 enum dwarf_macro_record_type macinfo_type
;
24877 int at_commandline
;
24878 const gdb_byte
*opcode_definitions
[256];
24880 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24881 &offset_size
, section_is_gnu
);
24882 if (mac_ptr
== NULL
)
24884 /* We already issued a complaint. */
24888 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24889 GDB is still reading the definitions from command line. First
24890 DW_MACINFO_start_file will need to be ignored as it was already executed
24891 to create CURRENT_FILE for the main source holding also the command line
24892 definitions. On first met DW_MACINFO_start_file this flag is reset to
24893 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24895 at_commandline
= 1;
24899 /* Do we at least have room for a macinfo type byte? */
24900 if (mac_ptr
>= mac_end
)
24902 dwarf2_section_buffer_overflow_complaint (section
);
24906 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24909 /* Note that we rely on the fact that the corresponding GNU and
24910 DWARF constants are the same. */
24912 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24913 switch (macinfo_type
)
24915 /* A zero macinfo type indicates the end of the macro
24920 case DW_MACRO_define
:
24921 case DW_MACRO_undef
:
24922 case DW_MACRO_define_strp
:
24923 case DW_MACRO_undef_strp
:
24924 case DW_MACRO_define_sup
:
24925 case DW_MACRO_undef_sup
:
24927 unsigned int bytes_read
;
24932 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24933 mac_ptr
+= bytes_read
;
24935 if (macinfo_type
== DW_MACRO_define
24936 || macinfo_type
== DW_MACRO_undef
)
24938 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24939 mac_ptr
+= bytes_read
;
24943 LONGEST str_offset
;
24945 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24946 mac_ptr
+= offset_size
;
24948 if (macinfo_type
== DW_MACRO_define_sup
24949 || macinfo_type
== DW_MACRO_undef_sup
24952 struct dwz_file
*dwz
24953 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24955 body
= read_indirect_string_from_dwz (objfile
,
24959 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24963 is_define
= (macinfo_type
== DW_MACRO_define
24964 || macinfo_type
== DW_MACRO_define_strp
24965 || macinfo_type
== DW_MACRO_define_sup
);
24966 if (! current_file
)
24968 /* DWARF violation as no main source is present. */
24969 complaint (_("debug info with no main source gives macro %s "
24971 is_define
? _("definition") : _("undefinition"),
24975 if ((line
== 0 && !at_commandline
)
24976 || (line
!= 0 && at_commandline
))
24977 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24978 at_commandline
? _("command-line") : _("in-file"),
24979 is_define
? _("definition") : _("undefinition"),
24980 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24984 /* Fedora's rpm-build's "debugedit" binary
24985 corrupted .debug_macro sections.
24988 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24989 complaint (_("debug info gives %s invalid macro %s "
24990 "without body (corrupted?) at line %d "
24992 at_commandline
? _("command-line") : _("in-file"),
24993 is_define
? _("definition") : _("undefinition"),
24994 line
, current_file
->filename
);
24996 else if (is_define
)
24997 parse_macro_definition (current_file
, line
, body
);
25000 gdb_assert (macinfo_type
== DW_MACRO_undef
25001 || macinfo_type
== DW_MACRO_undef_strp
25002 || macinfo_type
== DW_MACRO_undef_sup
);
25003 macro_undef (current_file
, line
, body
);
25008 case DW_MACRO_start_file
:
25010 unsigned int bytes_read
;
25013 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25014 mac_ptr
+= bytes_read
;
25015 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25016 mac_ptr
+= bytes_read
;
25018 if ((line
== 0 && !at_commandline
)
25019 || (line
!= 0 && at_commandline
))
25020 complaint (_("debug info gives source %d included "
25021 "from %s at %s line %d"),
25022 file
, at_commandline
? _("command-line") : _("file"),
25023 line
== 0 ? _("zero") : _("non-zero"), line
);
25025 if (at_commandline
)
25027 /* This DW_MACRO_start_file was executed in the
25029 at_commandline
= 0;
25032 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25037 case DW_MACRO_end_file
:
25038 if (! current_file
)
25039 complaint (_("macro debug info has an unmatched "
25040 "`close_file' directive"));
25043 current_file
= current_file
->included_by
;
25044 if (! current_file
)
25046 enum dwarf_macro_record_type next_type
;
25048 /* GCC circa March 2002 doesn't produce the zero
25049 type byte marking the end of the compilation
25050 unit. Complain if it's not there, but exit no
25053 /* Do we at least have room for a macinfo type byte? */
25054 if (mac_ptr
>= mac_end
)
25056 dwarf2_section_buffer_overflow_complaint (section
);
25060 /* We don't increment mac_ptr here, so this is just
25063 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25065 if (next_type
!= 0)
25066 complaint (_("no terminating 0-type entry for "
25067 "macros in `.debug_macinfo' section"));
25074 case DW_MACRO_import
:
25075 case DW_MACRO_import_sup
:
25079 bfd
*include_bfd
= abfd
;
25080 struct dwarf2_section_info
*include_section
= section
;
25081 const gdb_byte
*include_mac_end
= mac_end
;
25082 int is_dwz
= section_is_dwz
;
25083 const gdb_byte
*new_mac_ptr
;
25085 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25086 mac_ptr
+= offset_size
;
25088 if (macinfo_type
== DW_MACRO_import_sup
)
25090 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25092 dwarf2_read_section (objfile
, &dwz
->macro
);
25094 include_section
= &dwz
->macro
;
25095 include_bfd
= get_section_bfd_owner (include_section
);
25096 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25100 new_mac_ptr
= include_section
->buffer
+ offset
;
25101 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25105 /* This has actually happened; see
25106 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25107 complaint (_("recursive DW_MACRO_import in "
25108 ".debug_macro section"));
25112 *slot
= (void *) new_mac_ptr
;
25114 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25115 include_mac_end
, current_file
, lh
,
25116 section
, section_is_gnu
, is_dwz
,
25117 offset_size
, include_hash
);
25119 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25124 case DW_MACINFO_vendor_ext
:
25125 if (!section_is_gnu
)
25127 unsigned int bytes_read
;
25129 /* This reads the constant, but since we don't recognize
25130 any vendor extensions, we ignore it. */
25131 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25132 mac_ptr
+= bytes_read
;
25133 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25134 mac_ptr
+= bytes_read
;
25136 /* We don't recognize any vendor extensions. */
25142 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25143 mac_ptr
, mac_end
, abfd
, offset_size
,
25145 if (mac_ptr
== NULL
)
25150 } while (macinfo_type
!= 0);
25154 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25155 int section_is_gnu
)
25157 struct dwarf2_per_objfile
*dwarf2_per_objfile
25158 = cu
->per_cu
->dwarf2_per_objfile
;
25159 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25160 struct line_header
*lh
= cu
->line_header
;
25162 const gdb_byte
*mac_ptr
, *mac_end
;
25163 struct macro_source_file
*current_file
= 0;
25164 enum dwarf_macro_record_type macinfo_type
;
25165 unsigned int offset_size
= cu
->header
.offset_size
;
25166 const gdb_byte
*opcode_definitions
[256];
25168 struct dwarf2_section_info
*section
;
25169 const char *section_name
;
25171 if (cu
->dwo_unit
!= NULL
)
25173 if (section_is_gnu
)
25175 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25176 section_name
= ".debug_macro.dwo";
25180 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25181 section_name
= ".debug_macinfo.dwo";
25186 if (section_is_gnu
)
25188 section
= &dwarf2_per_objfile
->macro
;
25189 section_name
= ".debug_macro";
25193 section
= &dwarf2_per_objfile
->macinfo
;
25194 section_name
= ".debug_macinfo";
25198 dwarf2_read_section (objfile
, section
);
25199 if (section
->buffer
== NULL
)
25201 complaint (_("missing %s section"), section_name
);
25204 abfd
= get_section_bfd_owner (section
);
25206 /* First pass: Find the name of the base filename.
25207 This filename is needed in order to process all macros whose definition
25208 (or undefinition) comes from the command line. These macros are defined
25209 before the first DW_MACINFO_start_file entry, and yet still need to be
25210 associated to the base file.
25212 To determine the base file name, we scan the macro definitions until we
25213 reach the first DW_MACINFO_start_file entry. We then initialize
25214 CURRENT_FILE accordingly so that any macro definition found before the
25215 first DW_MACINFO_start_file can still be associated to the base file. */
25217 mac_ptr
= section
->buffer
+ offset
;
25218 mac_end
= section
->buffer
+ section
->size
;
25220 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25221 &offset_size
, section_is_gnu
);
25222 if (mac_ptr
== NULL
)
25224 /* We already issued a complaint. */
25230 /* Do we at least have room for a macinfo type byte? */
25231 if (mac_ptr
>= mac_end
)
25233 /* Complaint is printed during the second pass as GDB will probably
25234 stop the first pass earlier upon finding
25235 DW_MACINFO_start_file. */
25239 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25242 /* Note that we rely on the fact that the corresponding GNU and
25243 DWARF constants are the same. */
25245 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25246 switch (macinfo_type
)
25248 /* A zero macinfo type indicates the end of the macro
25253 case DW_MACRO_define
:
25254 case DW_MACRO_undef
:
25255 /* Only skip the data by MAC_PTR. */
25257 unsigned int bytes_read
;
25259 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25260 mac_ptr
+= bytes_read
;
25261 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25262 mac_ptr
+= bytes_read
;
25266 case DW_MACRO_start_file
:
25268 unsigned int bytes_read
;
25271 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25272 mac_ptr
+= bytes_read
;
25273 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25274 mac_ptr
+= bytes_read
;
25276 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25280 case DW_MACRO_end_file
:
25281 /* No data to skip by MAC_PTR. */
25284 case DW_MACRO_define_strp
:
25285 case DW_MACRO_undef_strp
:
25286 case DW_MACRO_define_sup
:
25287 case DW_MACRO_undef_sup
:
25289 unsigned int bytes_read
;
25291 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25292 mac_ptr
+= bytes_read
;
25293 mac_ptr
+= offset_size
;
25297 case DW_MACRO_import
:
25298 case DW_MACRO_import_sup
:
25299 /* Note that, according to the spec, a transparent include
25300 chain cannot call DW_MACRO_start_file. So, we can just
25301 skip this opcode. */
25302 mac_ptr
+= offset_size
;
25305 case DW_MACINFO_vendor_ext
:
25306 /* Only skip the data by MAC_PTR. */
25307 if (!section_is_gnu
)
25309 unsigned int bytes_read
;
25311 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25312 mac_ptr
+= bytes_read
;
25313 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25314 mac_ptr
+= bytes_read
;
25319 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25320 mac_ptr
, mac_end
, abfd
, offset_size
,
25322 if (mac_ptr
== NULL
)
25327 } while (macinfo_type
!= 0 && current_file
== NULL
);
25329 /* Second pass: Process all entries.
25331 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25332 command-line macro definitions/undefinitions. This flag is unset when we
25333 reach the first DW_MACINFO_start_file entry. */
25335 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25337 NULL
, xcalloc
, xfree
));
25338 mac_ptr
= section
->buffer
+ offset
;
25339 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25340 *slot
= (void *) mac_ptr
;
25341 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25342 current_file
, lh
, section
,
25343 section_is_gnu
, 0, offset_size
,
25344 include_hash
.get ());
25347 /* Check if the attribute's form is a DW_FORM_block*
25348 if so return true else false. */
25351 attr_form_is_block (const struct attribute
*attr
)
25353 return (attr
== NULL
? 0 :
25354 attr
->form
== DW_FORM_block1
25355 || attr
->form
== DW_FORM_block2
25356 || attr
->form
== DW_FORM_block4
25357 || attr
->form
== DW_FORM_block
25358 || attr
->form
== DW_FORM_exprloc
);
25361 /* Return non-zero if ATTR's value is a section offset --- classes
25362 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25363 You may use DW_UNSND (attr) to retrieve such offsets.
25365 Section 7.5.4, "Attribute Encodings", explains that no attribute
25366 may have a value that belongs to more than one of these classes; it
25367 would be ambiguous if we did, because we use the same forms for all
25371 attr_form_is_section_offset (const struct attribute
*attr
)
25373 return (attr
->form
== DW_FORM_data4
25374 || attr
->form
== DW_FORM_data8
25375 || attr
->form
== DW_FORM_sec_offset
);
25378 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25379 zero otherwise. When this function returns true, you can apply
25380 dwarf2_get_attr_constant_value to it.
25382 However, note that for some attributes you must check
25383 attr_form_is_section_offset before using this test. DW_FORM_data4
25384 and DW_FORM_data8 are members of both the constant class, and of
25385 the classes that contain offsets into other debug sections
25386 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25387 that, if an attribute's can be either a constant or one of the
25388 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25389 taken as section offsets, not constants.
25391 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25392 cannot handle that. */
25395 attr_form_is_constant (const struct attribute
*attr
)
25397 switch (attr
->form
)
25399 case DW_FORM_sdata
:
25400 case DW_FORM_udata
:
25401 case DW_FORM_data1
:
25402 case DW_FORM_data2
:
25403 case DW_FORM_data4
:
25404 case DW_FORM_data8
:
25405 case DW_FORM_implicit_const
:
25413 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25414 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25417 attr_form_is_ref (const struct attribute
*attr
)
25419 switch (attr
->form
)
25421 case DW_FORM_ref_addr
:
25426 case DW_FORM_ref_udata
:
25427 case DW_FORM_GNU_ref_alt
:
25434 /* Return the .debug_loc section to use for CU.
25435 For DWO files use .debug_loc.dwo. */
25437 static struct dwarf2_section_info
*
25438 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25440 struct dwarf2_per_objfile
*dwarf2_per_objfile
25441 = cu
->per_cu
->dwarf2_per_objfile
;
25445 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25447 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25449 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25450 : &dwarf2_per_objfile
->loc
);
25453 /* A helper function that fills in a dwarf2_loclist_baton. */
25456 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25457 struct dwarf2_loclist_baton
*baton
,
25458 const struct attribute
*attr
)
25460 struct dwarf2_per_objfile
*dwarf2_per_objfile
25461 = cu
->per_cu
->dwarf2_per_objfile
;
25462 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25464 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25466 baton
->per_cu
= cu
->per_cu
;
25467 gdb_assert (baton
->per_cu
);
25468 /* We don't know how long the location list is, but make sure we
25469 don't run off the edge of the section. */
25470 baton
->size
= section
->size
- DW_UNSND (attr
);
25471 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25472 baton
->base_address
= cu
->base_address
;
25473 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25477 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25478 struct dwarf2_cu
*cu
, int is_block
)
25480 struct dwarf2_per_objfile
*dwarf2_per_objfile
25481 = cu
->per_cu
->dwarf2_per_objfile
;
25482 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25483 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25485 if (attr_form_is_section_offset (attr
)
25486 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25487 the section. If so, fall through to the complaint in the
25489 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25491 struct dwarf2_loclist_baton
*baton
;
25493 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25495 fill_in_loclist_baton (cu
, baton
, attr
);
25497 if (cu
->base_known
== 0)
25498 complaint (_("Location list used without "
25499 "specifying the CU base address."));
25501 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25502 ? dwarf2_loclist_block_index
25503 : dwarf2_loclist_index
);
25504 SYMBOL_LOCATION_BATON (sym
) = baton
;
25508 struct dwarf2_locexpr_baton
*baton
;
25510 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25511 baton
->per_cu
= cu
->per_cu
;
25512 gdb_assert (baton
->per_cu
);
25514 if (attr_form_is_block (attr
))
25516 /* Note that we're just copying the block's data pointer
25517 here, not the actual data. We're still pointing into the
25518 info_buffer for SYM's objfile; right now we never release
25519 that buffer, but when we do clean up properly this may
25521 baton
->size
= DW_BLOCK (attr
)->size
;
25522 baton
->data
= DW_BLOCK (attr
)->data
;
25526 dwarf2_invalid_attrib_class_complaint ("location description",
25527 sym
->natural_name ());
25531 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25532 ? dwarf2_locexpr_block_index
25533 : dwarf2_locexpr_index
);
25534 SYMBOL_LOCATION_BATON (sym
) = baton
;
25538 /* Return the OBJFILE associated with the compilation unit CU. If CU
25539 came from a separate debuginfo file, then the master objfile is
25543 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25545 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25547 /* Return the master objfile, so that we can report and look up the
25548 correct file containing this variable. */
25549 if (objfile
->separate_debug_objfile_backlink
)
25550 objfile
= objfile
->separate_debug_objfile_backlink
;
25555 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25556 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25557 CU_HEADERP first. */
25559 static const struct comp_unit_head
*
25560 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25561 struct dwarf2_per_cu_data
*per_cu
)
25563 const gdb_byte
*info_ptr
;
25566 return &per_cu
->cu
->header
;
25568 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25570 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25571 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25572 rcuh_kind::COMPILE
);
25577 /* Return the address size given in the compilation unit header for CU. */
25580 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25582 struct comp_unit_head cu_header_local
;
25583 const struct comp_unit_head
*cu_headerp
;
25585 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25587 return cu_headerp
->addr_size
;
25590 /* Return the offset size given in the compilation unit header for CU. */
25593 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25595 struct comp_unit_head cu_header_local
;
25596 const struct comp_unit_head
*cu_headerp
;
25598 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25600 return cu_headerp
->offset_size
;
25603 /* See its dwarf2loc.h declaration. */
25606 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25608 struct comp_unit_head cu_header_local
;
25609 const struct comp_unit_head
*cu_headerp
;
25611 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25613 if (cu_headerp
->version
== 2)
25614 return cu_headerp
->addr_size
;
25616 return cu_headerp
->offset_size
;
25619 /* Return the text offset of the CU. The returned offset comes from
25620 this CU's objfile. If this objfile came from a separate debuginfo
25621 file, then the offset may be different from the corresponding
25622 offset in the parent objfile. */
25625 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25627 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25629 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25632 /* Return a type that is a generic pointer type, the size of which matches
25633 the address size given in the compilation unit header for PER_CU. */
25634 static struct type
*
25635 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25637 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25638 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25639 struct type
*addr_type
= lookup_pointer_type (void_type
);
25640 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25642 if (TYPE_LENGTH (addr_type
) == addr_size
)
25646 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25650 /* Return DWARF version number of PER_CU. */
25653 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25655 return per_cu
->dwarf_version
;
25658 /* Locate the .debug_info compilation unit from CU's objfile which contains
25659 the DIE at OFFSET. Raises an error on failure. */
25661 static struct dwarf2_per_cu_data
*
25662 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25663 unsigned int offset_in_dwz
,
25664 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25666 struct dwarf2_per_cu_data
*this_cu
;
25670 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25673 struct dwarf2_per_cu_data
*mid_cu
;
25674 int mid
= low
+ (high
- low
) / 2;
25676 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25677 if (mid_cu
->is_dwz
> offset_in_dwz
25678 || (mid_cu
->is_dwz
== offset_in_dwz
25679 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25684 gdb_assert (low
== high
);
25685 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25686 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25688 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25689 error (_("Dwarf Error: could not find partial DIE containing "
25690 "offset %s [in module %s]"),
25691 sect_offset_str (sect_off
),
25692 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25694 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25696 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25700 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25701 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25702 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25703 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25708 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25710 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25711 : per_cu (per_cu_
),
25713 has_loclist (false),
25714 checked_producer (false),
25715 producer_is_gxx_lt_4_6 (false),
25716 producer_is_gcc_lt_4_3 (false),
25717 producer_is_icc (false),
25718 producer_is_icc_lt_14 (false),
25719 producer_is_codewarrior (false),
25720 processing_has_namespace_info (false)
25725 /* Destroy a dwarf2_cu. */
25727 dwarf2_cu::~dwarf2_cu ()
25732 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25735 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25736 enum language pretend_language
)
25738 struct attribute
*attr
;
25740 /* Set the language we're debugging. */
25741 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25742 if (attr
!= nullptr)
25743 set_cu_language (DW_UNSND (attr
), cu
);
25746 cu
->language
= pretend_language
;
25747 cu
->language_defn
= language_def (cu
->language
);
25750 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25753 /* Increase the age counter on each cached compilation unit, and free
25754 any that are too old. */
25757 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25759 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25761 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25762 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25763 while (per_cu
!= NULL
)
25765 per_cu
->cu
->last_used
++;
25766 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25767 dwarf2_mark (per_cu
->cu
);
25768 per_cu
= per_cu
->cu
->read_in_chain
;
25771 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25772 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25773 while (per_cu
!= NULL
)
25775 struct dwarf2_per_cu_data
*next_cu
;
25777 next_cu
= per_cu
->cu
->read_in_chain
;
25779 if (!per_cu
->cu
->mark
)
25782 *last_chain
= next_cu
;
25785 last_chain
= &per_cu
->cu
->read_in_chain
;
25791 /* Remove a single compilation unit from the cache. */
25794 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25796 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25797 struct dwarf2_per_objfile
*dwarf2_per_objfile
25798 = target_per_cu
->dwarf2_per_objfile
;
25800 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25801 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25802 while (per_cu
!= NULL
)
25804 struct dwarf2_per_cu_data
*next_cu
;
25806 next_cu
= per_cu
->cu
->read_in_chain
;
25808 if (per_cu
== target_per_cu
)
25812 *last_chain
= next_cu
;
25816 last_chain
= &per_cu
->cu
->read_in_chain
;
25822 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25823 We store these in a hash table separate from the DIEs, and preserve them
25824 when the DIEs are flushed out of cache.
25826 The CU "per_cu" pointer is needed because offset alone is not enough to
25827 uniquely identify the type. A file may have multiple .debug_types sections,
25828 or the type may come from a DWO file. Furthermore, while it's more logical
25829 to use per_cu->section+offset, with Fission the section with the data is in
25830 the DWO file but we don't know that section at the point we need it.
25831 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25832 because we can enter the lookup routine, get_die_type_at_offset, from
25833 outside this file, and thus won't necessarily have PER_CU->cu.
25834 Fortunately, PER_CU is stable for the life of the objfile. */
25836 struct dwarf2_per_cu_offset_and_type
25838 const struct dwarf2_per_cu_data
*per_cu
;
25839 sect_offset sect_off
;
25843 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25846 per_cu_offset_and_type_hash (const void *item
)
25848 const struct dwarf2_per_cu_offset_and_type
*ofs
25849 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25851 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25854 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25857 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25859 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25860 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25861 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25862 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25864 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25865 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25868 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25869 table if necessary. For convenience, return TYPE.
25871 The DIEs reading must have careful ordering to:
25872 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25873 reading current DIE.
25874 * Not trying to dereference contents of still incompletely read in types
25875 while reading in other DIEs.
25876 * Enable referencing still incompletely read in types just by a pointer to
25877 the type without accessing its fields.
25879 Therefore caller should follow these rules:
25880 * Try to fetch any prerequisite types we may need to build this DIE type
25881 before building the type and calling set_die_type.
25882 * After building type call set_die_type for current DIE as soon as
25883 possible before fetching more types to complete the current type.
25884 * Make the type as complete as possible before fetching more types. */
25886 static struct type
*
25887 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25889 struct dwarf2_per_objfile
*dwarf2_per_objfile
25890 = cu
->per_cu
->dwarf2_per_objfile
;
25891 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25892 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25893 struct attribute
*attr
;
25894 struct dynamic_prop prop
;
25896 /* For Ada types, make sure that the gnat-specific data is always
25897 initialized (if not already set). There are a few types where
25898 we should not be doing so, because the type-specific area is
25899 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25900 where the type-specific area is used to store the floatformat).
25901 But this is not a problem, because the gnat-specific information
25902 is actually not needed for these types. */
25903 if (need_gnat_info (cu
)
25904 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25905 && TYPE_CODE (type
) != TYPE_CODE_FLT
25906 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25907 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25908 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25909 && !HAVE_GNAT_AUX_INFO (type
))
25910 INIT_GNAT_SPECIFIC (type
);
25912 /* Read DW_AT_allocated and set in type. */
25913 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25914 if (attr_form_is_block (attr
))
25916 struct type
*prop_type
25917 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25918 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25919 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25921 else if (attr
!= NULL
)
25923 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25924 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25925 sect_offset_str (die
->sect_off
));
25928 /* Read DW_AT_associated and set in type. */
25929 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25930 if (attr_form_is_block (attr
))
25932 struct type
*prop_type
25933 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25934 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25935 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25937 else if (attr
!= NULL
)
25939 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25940 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25941 sect_offset_str (die
->sect_off
));
25944 /* Read DW_AT_data_location and set in type. */
25945 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25946 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25947 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25948 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25950 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25952 dwarf2_per_objfile
->die_type_hash
=
25953 htab_create_alloc_ex (127,
25954 per_cu_offset_and_type_hash
,
25955 per_cu_offset_and_type_eq
,
25957 &objfile
->objfile_obstack
,
25958 hashtab_obstack_allocate
,
25959 dummy_obstack_deallocate
);
25962 ofs
.per_cu
= cu
->per_cu
;
25963 ofs
.sect_off
= die
->sect_off
;
25965 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25966 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25968 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25969 sect_offset_str (die
->sect_off
));
25970 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25971 struct dwarf2_per_cu_offset_and_type
);
25976 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25977 or return NULL if the die does not have a saved type. */
25979 static struct type
*
25980 get_die_type_at_offset (sect_offset sect_off
,
25981 struct dwarf2_per_cu_data
*per_cu
)
25983 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25984 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25986 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25989 ofs
.per_cu
= per_cu
;
25990 ofs
.sect_off
= sect_off
;
25991 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25992 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25999 /* Look up the type for DIE in CU in die_type_hash,
26000 or return NULL if DIE does not have a saved type. */
26002 static struct type
*
26003 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26005 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26008 /* Add a dependence relationship from CU to REF_PER_CU. */
26011 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26012 struct dwarf2_per_cu_data
*ref_per_cu
)
26016 if (cu
->dependencies
== NULL
)
26018 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26019 NULL
, &cu
->comp_unit_obstack
,
26020 hashtab_obstack_allocate
,
26021 dummy_obstack_deallocate
);
26023 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26025 *slot
= ref_per_cu
;
26028 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26029 Set the mark field in every compilation unit in the
26030 cache that we must keep because we are keeping CU. */
26033 dwarf2_mark_helper (void **slot
, void *data
)
26035 struct dwarf2_per_cu_data
*per_cu
;
26037 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26039 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26040 reading of the chain. As such dependencies remain valid it is not much
26041 useful to track and undo them during QUIT cleanups. */
26042 if (per_cu
->cu
== NULL
)
26045 if (per_cu
->cu
->mark
)
26047 per_cu
->cu
->mark
= true;
26049 if (per_cu
->cu
->dependencies
!= NULL
)
26050 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26055 /* Set the mark field in CU and in every other compilation unit in the
26056 cache that we must keep because we are keeping CU. */
26059 dwarf2_mark (struct dwarf2_cu
*cu
)
26064 if (cu
->dependencies
!= NULL
)
26065 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26069 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26073 per_cu
->cu
->mark
= false;
26074 per_cu
= per_cu
->cu
->read_in_chain
;
26078 /* Trivial hash function for partial_die_info: the hash value of a DIE
26079 is its offset in .debug_info for this objfile. */
26082 partial_die_hash (const void *item
)
26084 const struct partial_die_info
*part_die
26085 = (const struct partial_die_info
*) item
;
26087 return to_underlying (part_die
->sect_off
);
26090 /* Trivial comparison function for partial_die_info structures: two DIEs
26091 are equal if they have the same offset. */
26094 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26096 const struct partial_die_info
*part_die_lhs
26097 = (const struct partial_die_info
*) item_lhs
;
26098 const struct partial_die_info
*part_die_rhs
26099 = (const struct partial_die_info
*) item_rhs
;
26101 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26104 struct cmd_list_element
*set_dwarf_cmdlist
;
26105 struct cmd_list_element
*show_dwarf_cmdlist
;
26108 set_dwarf_cmd (const char *args
, int from_tty
)
26110 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26115 show_dwarf_cmd (const char *args
, int from_tty
)
26117 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26120 bool dwarf_always_disassemble
;
26123 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26124 struct cmd_list_element
*c
, const char *value
)
26126 fprintf_filtered (file
,
26127 _("Whether to always disassemble "
26128 "DWARF expressions is %s.\n"),
26133 show_check_physname (struct ui_file
*file
, int from_tty
,
26134 struct cmd_list_element
*c
, const char *value
)
26136 fprintf_filtered (file
,
26137 _("Whether to check \"physname\" is %s.\n"),
26142 _initialize_dwarf2_read (void)
26144 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26145 Set DWARF specific variables.\n\
26146 Configure DWARF variables such as the cache size."),
26147 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26148 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26150 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26151 Show DWARF specific variables.\n\
26152 Show DWARF variables such as the cache size."),
26153 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26154 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26156 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26157 &dwarf_max_cache_age
, _("\
26158 Set the upper bound on the age of cached DWARF compilation units."), _("\
26159 Show the upper bound on the age of cached DWARF compilation units."), _("\
26160 A higher limit means that cached compilation units will be stored\n\
26161 in memory longer, and more total memory will be used. Zero disables\n\
26162 caching, which can slow down startup."),
26164 show_dwarf_max_cache_age
,
26165 &set_dwarf_cmdlist
,
26166 &show_dwarf_cmdlist
);
26168 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26169 &dwarf_always_disassemble
, _("\
26170 Set whether `info address' always disassembles DWARF expressions."), _("\
26171 Show whether `info address' always disassembles DWARF expressions."), _("\
26172 When enabled, DWARF expressions are always printed in an assembly-like\n\
26173 syntax. When disabled, expressions will be printed in a more\n\
26174 conversational style, when possible."),
26176 show_dwarf_always_disassemble
,
26177 &set_dwarf_cmdlist
,
26178 &show_dwarf_cmdlist
);
26180 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26181 Set debugging of the DWARF reader."), _("\
26182 Show debugging of the DWARF reader."), _("\
26183 When enabled (non-zero), debugging messages are printed during DWARF\n\
26184 reading and symtab expansion. A value of 1 (one) provides basic\n\
26185 information. A value greater than 1 provides more verbose information."),
26188 &setdebuglist
, &showdebuglist
);
26190 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26191 Set debugging of the DWARF DIE reader."), _("\
26192 Show debugging of the DWARF DIE reader."), _("\
26193 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26194 The value is the maximum depth to print."),
26197 &setdebuglist
, &showdebuglist
);
26199 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26200 Set debugging of the dwarf line reader."), _("\
26201 Show debugging of the dwarf line reader."), _("\
26202 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26203 A value of 1 (one) provides basic information.\n\
26204 A value greater than 1 provides more verbose information."),
26207 &setdebuglist
, &showdebuglist
);
26209 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26210 Set cross-checking of \"physname\" code against demangler."), _("\
26211 Show cross-checking of \"physname\" code against demangler."), _("\
26212 When enabled, GDB's internal \"physname\" code is checked against\n\
26214 NULL
, show_check_physname
,
26215 &setdebuglist
, &showdebuglist
);
26217 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26218 no_class
, &use_deprecated_index_sections
, _("\
26219 Set whether to use deprecated gdb_index sections."), _("\
26220 Show whether to use deprecated gdb_index sections."), _("\
26221 When enabled, deprecated .gdb_index sections are used anyway.\n\
26222 Normally they are ignored either because of a missing feature or\n\
26223 performance issue.\n\
26224 Warning: This option must be enabled before gdb reads the file."),
26227 &setlist
, &showlist
);
26229 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26230 &dwarf2_locexpr_funcs
);
26231 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26232 &dwarf2_loclist_funcs
);
26234 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26235 &dwarf2_block_frame_base_locexpr_funcs
);
26236 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26237 &dwarf2_block_frame_base_loclist_funcs
);
26240 selftests::register_test ("dw2_expand_symtabs_matching",
26241 selftests::dw2_expand_symtabs_matching::run_test
);