1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2019 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 /* A 1-based directory index. This is a strong typedef to prevent
913 accidentally using a directory index as a 0-based index into an
915 enum class dir_index
: unsigned int {};
917 /* Likewise, a 1-based file name index. */
918 enum class file_name_index
: unsigned int {};
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 (1-based). Returns NULL if INDEX
972 const char *include_dir_at (dir_index index
) const
974 /* Convert directory index number (1-based) to vector index
976 size_t vec_index
= to_underlying (index
) - 1;
978 if (vec_index
>= include_dirs
.size ())
980 return include_dirs
[vec_index
];
983 /* Return the file name at INDEX (1-based). Returns NULL if INDEX
985 file_entry
*file_name_at (file_name_index index
)
987 /* Convert file name index number (1-based) to vector index
989 size_t vec_index
= to_underlying (index
) - 1;
991 if (vec_index
>= file_names
.size ())
993 return &file_names
[vec_index
];
996 /* Offset of line number information in .debug_line section. */
997 sect_offset sect_off
{};
999 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1000 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1002 unsigned int total_length
{};
1003 unsigned short version
{};
1004 unsigned int header_length
{};
1005 unsigned char minimum_instruction_length
{};
1006 unsigned char maximum_ops_per_instruction
{};
1007 unsigned char default_is_stmt
{};
1009 unsigned char line_range
{};
1010 unsigned char opcode_base
{};
1012 /* standard_opcode_lengths[i] is the number of operands for the
1013 standard opcode whose value is i. This means that
1014 standard_opcode_lengths[0] is unused, and the last meaningful
1015 element is standard_opcode_lengths[opcode_base - 1]. */
1016 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1018 /* The include_directories table. Note these are observing
1019 pointers. The memory is owned by debug_line_buffer. */
1020 std::vector
<const char *> include_dirs
;
1022 /* The file_names table. */
1023 std::vector
<file_entry
> file_names
;
1025 /* The start and end of the statement program following this
1026 header. These point into dwarf2_per_objfile->line_buffer. */
1027 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1030 typedef std::unique_ptr
<line_header
> line_header_up
;
1033 file_entry::include_dir (const line_header
*lh
) const
1035 return lh
->include_dir_at (d_index
);
1038 /* When we construct a partial symbol table entry we only
1039 need this much information. */
1040 struct partial_die_info
: public allocate_on_obstack
1042 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1044 /* Disable assign but still keep copy ctor, which is needed
1045 load_partial_dies. */
1046 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1048 /* Adjust the partial die before generating a symbol for it. This
1049 function may set the is_external flag or change the DIE's
1051 void fixup (struct dwarf2_cu
*cu
);
1053 /* Read a minimal amount of information into the minimal die
1055 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1056 const struct abbrev_info
&abbrev
,
1057 const gdb_byte
*info_ptr
);
1059 /* Offset of this DIE. */
1060 const sect_offset sect_off
;
1062 /* DWARF-2 tag for this DIE. */
1063 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1065 /* Assorted flags describing the data found in this DIE. */
1066 const unsigned int has_children
: 1;
1068 unsigned int is_external
: 1;
1069 unsigned int is_declaration
: 1;
1070 unsigned int has_type
: 1;
1071 unsigned int has_specification
: 1;
1072 unsigned int has_pc_info
: 1;
1073 unsigned int may_be_inlined
: 1;
1075 /* This DIE has been marked DW_AT_main_subprogram. */
1076 unsigned int main_subprogram
: 1;
1078 /* Flag set if the SCOPE field of this structure has been
1080 unsigned int scope_set
: 1;
1082 /* Flag set if the DIE has a byte_size attribute. */
1083 unsigned int has_byte_size
: 1;
1085 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1086 unsigned int has_const_value
: 1;
1088 /* Flag set if any of the DIE's children are template arguments. */
1089 unsigned int has_template_arguments
: 1;
1091 /* Flag set if fixup has been called on this die. */
1092 unsigned int fixup_called
: 1;
1094 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1095 unsigned int is_dwz
: 1;
1097 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1098 unsigned int spec_is_dwz
: 1;
1100 /* The name of this DIE. Normally the value of DW_AT_name, but
1101 sometimes a default name for unnamed DIEs. */
1102 const char *name
= nullptr;
1104 /* The linkage name, if present. */
1105 const char *linkage_name
= nullptr;
1107 /* The scope to prepend to our children. This is generally
1108 allocated on the comp_unit_obstack, so will disappear
1109 when this compilation unit leaves the cache. */
1110 const char *scope
= nullptr;
1112 /* Some data associated with the partial DIE. The tag determines
1113 which field is live. */
1116 /* The location description associated with this DIE, if any. */
1117 struct dwarf_block
*locdesc
;
1118 /* The offset of an import, for DW_TAG_imported_unit. */
1119 sect_offset sect_off
;
1122 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1123 CORE_ADDR lowpc
= 0;
1124 CORE_ADDR highpc
= 0;
1126 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1127 DW_AT_sibling, if any. */
1128 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1129 could return DW_AT_sibling values to its caller load_partial_dies. */
1130 const gdb_byte
*sibling
= nullptr;
1132 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1133 DW_AT_specification (or DW_AT_abstract_origin or
1134 DW_AT_extension). */
1135 sect_offset spec_offset
{};
1137 /* Pointers to this DIE's parent, first child, and next sibling,
1139 struct partial_die_info
*die_parent
= nullptr;
1140 struct partial_die_info
*die_child
= nullptr;
1141 struct partial_die_info
*die_sibling
= nullptr;
1143 friend struct partial_die_info
*
1144 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1147 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1148 partial_die_info (sect_offset sect_off
)
1149 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1153 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1155 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1160 has_specification
= 0;
1163 main_subprogram
= 0;
1166 has_const_value
= 0;
1167 has_template_arguments
= 0;
1174 /* This data structure holds the information of an abbrev. */
1177 unsigned int number
; /* number identifying abbrev */
1178 enum dwarf_tag tag
; /* dwarf tag */
1179 unsigned short has_children
; /* boolean */
1180 unsigned short num_attrs
; /* number of attributes */
1181 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1182 struct abbrev_info
*next
; /* next in chain */
1187 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1188 ENUM_BITFIELD(dwarf_form
) form
: 16;
1190 /* It is valid only if FORM is DW_FORM_implicit_const. */
1191 LONGEST implicit_const
;
1194 /* Size of abbrev_table.abbrev_hash_table. */
1195 #define ABBREV_HASH_SIZE 121
1197 /* Top level data structure to contain an abbreviation table. */
1201 explicit abbrev_table (sect_offset off
)
1205 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1206 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1209 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1211 /* Allocate space for a struct abbrev_info object in
1213 struct abbrev_info
*alloc_abbrev ();
1215 /* Add an abbreviation to the table. */
1216 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1218 /* Look up an abbrev in the table.
1219 Returns NULL if the abbrev is not found. */
1221 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1224 /* Where the abbrev table came from.
1225 This is used as a sanity check when the table is used. */
1226 const sect_offset sect_off
;
1228 /* Storage for the abbrev table. */
1229 auto_obstack abbrev_obstack
;
1233 /* Hash table of abbrevs.
1234 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1235 It could be statically allocated, but the previous code didn't so we
1237 struct abbrev_info
**m_abbrevs
;
1240 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1242 /* Attributes have a name and a value. */
1245 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1246 ENUM_BITFIELD(dwarf_form
) form
: 15;
1248 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1249 field should be in u.str (existing only for DW_STRING) but it is kept
1250 here for better struct attribute alignment. */
1251 unsigned int string_is_canonical
: 1;
1256 struct dwarf_block
*blk
;
1265 /* This data structure holds a complete die structure. */
1268 /* DWARF-2 tag for this DIE. */
1269 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1271 /* Number of attributes */
1272 unsigned char num_attrs
;
1274 /* True if we're presently building the full type name for the
1275 type derived from this DIE. */
1276 unsigned char building_fullname
: 1;
1278 /* True if this die is in process. PR 16581. */
1279 unsigned char in_process
: 1;
1282 unsigned int abbrev
;
1284 /* Offset in .debug_info or .debug_types section. */
1285 sect_offset sect_off
;
1287 /* The dies in a compilation unit form an n-ary tree. PARENT
1288 points to this die's parent; CHILD points to the first child of
1289 this node; and all the children of a given node are chained
1290 together via their SIBLING fields. */
1291 struct die_info
*child
; /* Its first child, if any. */
1292 struct die_info
*sibling
; /* Its next sibling, if any. */
1293 struct die_info
*parent
; /* Its parent, if any. */
1295 /* An array of attributes, with NUM_ATTRS elements. There may be
1296 zero, but it's not common and zero-sized arrays are not
1297 sufficiently portable C. */
1298 struct attribute attrs
[1];
1301 /* Get at parts of an attribute structure. */
1303 #define DW_STRING(attr) ((attr)->u.str)
1304 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1305 #define DW_UNSND(attr) ((attr)->u.unsnd)
1306 #define DW_BLOCK(attr) ((attr)->u.blk)
1307 #define DW_SND(attr) ((attr)->u.snd)
1308 #define DW_ADDR(attr) ((attr)->u.addr)
1309 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1311 /* Blocks are a bunch of untyped bytes. */
1316 /* Valid only if SIZE is not zero. */
1317 const gdb_byte
*data
;
1320 #ifndef ATTR_ALLOC_CHUNK
1321 #define ATTR_ALLOC_CHUNK 4
1324 /* Allocate fields for structs, unions and enums in this size. */
1325 #ifndef DW_FIELD_ALLOC_CHUNK
1326 #define DW_FIELD_ALLOC_CHUNK 4
1329 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1330 but this would require a corresponding change in unpack_field_as_long
1332 static int bits_per_byte
= 8;
1334 /* When reading a variant or variant part, we track a bit more
1335 information about the field, and store it in an object of this
1338 struct variant_field
1340 /* If we see a DW_TAG_variant, then this will be the discriminant
1342 ULONGEST discriminant_value
;
1343 /* If we see a DW_TAG_variant, then this will be set if this is the
1345 bool default_branch
;
1346 /* While reading a DW_TAG_variant_part, this will be set if this
1347 field is the discriminant. */
1348 bool is_discriminant
;
1353 int accessibility
= 0;
1355 /* Extra information to describe a variant or variant part. */
1356 struct variant_field variant
{};
1357 struct field field
{};
1362 const char *name
= nullptr;
1363 std::vector
<struct fn_field
> fnfields
;
1366 /* The routines that read and process dies for a C struct or C++ class
1367 pass lists of data member fields and lists of member function fields
1368 in an instance of a field_info structure, as defined below. */
1371 /* List of data member and baseclasses fields. */
1372 std::vector
<struct nextfield
> fields
;
1373 std::vector
<struct nextfield
> baseclasses
;
1375 /* Number of fields (including baseclasses). */
1378 /* Set if the accesibility of one of the fields is not public. */
1379 int non_public_fields
= 0;
1381 /* Member function fieldlist array, contains name of possibly overloaded
1382 member function, number of overloaded member functions and a pointer
1383 to the head of the member function field chain. */
1384 std::vector
<struct fnfieldlist
> fnfieldlists
;
1386 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1387 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1388 std::vector
<struct decl_field
> typedef_field_list
;
1390 /* Nested types defined by this class and the number of elements in this
1392 std::vector
<struct decl_field
> nested_types_list
;
1395 /* One item on the queue of compilation units to read in full symbols
1397 struct dwarf2_queue_item
1399 struct dwarf2_per_cu_data
*per_cu
;
1400 enum language pretend_language
;
1401 struct dwarf2_queue_item
*next
;
1404 /* The current queue. */
1405 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1407 /* Loaded secondary compilation units are kept in memory until they
1408 have not been referenced for the processing of this many
1409 compilation units. Set this to zero to disable caching. Cache
1410 sizes of up to at least twenty will improve startup time for
1411 typical inter-CU-reference binaries, at an obvious memory cost. */
1412 static int dwarf_max_cache_age
= 5;
1414 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1415 struct cmd_list_element
*c
, const char *value
)
1417 fprintf_filtered (file
, _("The upper bound on the age of cached "
1418 "DWARF compilation units is %s.\n"),
1422 /* local function prototypes */
1424 static const char *get_section_name (const struct dwarf2_section_info
*);
1426 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1428 static void dwarf2_find_base_address (struct die_info
*die
,
1429 struct dwarf2_cu
*cu
);
1431 static struct partial_symtab
*create_partial_symtab
1432 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1434 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1435 const gdb_byte
*info_ptr
,
1436 struct die_info
*type_unit_die
,
1437 int has_children
, void *data
);
1439 static void dwarf2_build_psymtabs_hard
1440 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1442 static void scan_partial_symbols (struct partial_die_info
*,
1443 CORE_ADDR
*, CORE_ADDR
*,
1444 int, struct dwarf2_cu
*);
1446 static void add_partial_symbol (struct partial_die_info
*,
1447 struct dwarf2_cu
*);
1449 static void add_partial_namespace (struct partial_die_info
*pdi
,
1450 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1451 int set_addrmap
, struct dwarf2_cu
*cu
);
1453 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1454 CORE_ADDR
*highpc
, int set_addrmap
,
1455 struct dwarf2_cu
*cu
);
1457 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1458 struct dwarf2_cu
*cu
);
1460 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1461 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1462 int need_pc
, struct dwarf2_cu
*cu
);
1464 static void dwarf2_read_symtab (struct partial_symtab
*,
1467 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1469 static abbrev_table_up abbrev_table_read_table
1470 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1473 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1475 static struct partial_die_info
*load_partial_dies
1476 (const struct die_reader_specs
*, const gdb_byte
*, int);
1478 /* A pair of partial_die_info and compilation unit. */
1479 struct cu_partial_die_info
1481 /* The compilation unit of the partial_die_info. */
1482 struct dwarf2_cu
*cu
;
1483 /* A partial_die_info. */
1484 struct partial_die_info
*pdi
;
1486 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1492 cu_partial_die_info () = delete;
1495 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1496 struct dwarf2_cu
*);
1498 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1499 struct attribute
*, struct attr_abbrev
*,
1502 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1504 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1506 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1508 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1509 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1511 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1513 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1515 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1518 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1520 static LONGEST read_checked_initial_length_and_offset
1521 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1522 unsigned int *, unsigned int *);
1524 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1525 const struct comp_unit_head
*,
1528 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1530 static sect_offset read_abbrev_offset
1531 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1532 struct dwarf2_section_info
*, sect_offset
);
1534 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1536 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1538 static const char *read_indirect_string
1539 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1540 const struct comp_unit_head
*, unsigned int *);
1542 static const char *read_indirect_line_string
1543 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1544 const struct comp_unit_head
*, unsigned int *);
1546 static const char *read_indirect_string_at_offset
1547 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1548 LONGEST str_offset
);
1550 static const char *read_indirect_string_from_dwz
1551 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1553 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1555 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1559 static const char *read_str_index (const struct die_reader_specs
*reader
,
1560 ULONGEST str_index
);
1562 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1564 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1565 struct dwarf2_cu
*);
1567 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1570 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1571 struct dwarf2_cu
*cu
);
1573 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1575 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1576 struct dwarf2_cu
*cu
);
1578 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1580 static struct die_info
*die_specification (struct die_info
*die
,
1581 struct dwarf2_cu
**);
1583 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1584 struct dwarf2_cu
*cu
);
1586 static void dwarf_decode_lines (struct line_header
*, const char *,
1587 struct dwarf2_cu
*, struct partial_symtab
*,
1588 CORE_ADDR
, int decode_mapping
);
1590 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1593 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1594 struct dwarf2_cu
*, struct symbol
* = NULL
);
1596 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1597 struct dwarf2_cu
*);
1599 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1602 struct obstack
*obstack
,
1603 struct dwarf2_cu
*cu
, LONGEST
*value
,
1604 const gdb_byte
**bytes
,
1605 struct dwarf2_locexpr_baton
**baton
);
1607 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1609 static int need_gnat_info (struct dwarf2_cu
*);
1611 static struct type
*die_descriptive_type (struct die_info
*,
1612 struct dwarf2_cu
*);
1614 static void set_descriptive_type (struct type
*, struct die_info
*,
1615 struct dwarf2_cu
*);
1617 static struct type
*die_containing_type (struct die_info
*,
1618 struct dwarf2_cu
*);
1620 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1621 struct dwarf2_cu
*);
1623 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1625 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1627 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1629 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1630 const char *suffix
, int physname
,
1631 struct dwarf2_cu
*cu
);
1633 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1635 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1637 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1639 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1641 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1643 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1645 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1646 struct dwarf2_cu
*, struct partial_symtab
*);
1648 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1649 values. Keep the items ordered with increasing constraints compliance. */
1652 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1653 PC_BOUNDS_NOT_PRESENT
,
1655 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1656 were present but they do not form a valid range of PC addresses. */
1659 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1662 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1666 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1667 CORE_ADDR
*, CORE_ADDR
*,
1669 struct partial_symtab
*);
1671 static void get_scope_pc_bounds (struct die_info
*,
1672 CORE_ADDR
*, CORE_ADDR
*,
1673 struct dwarf2_cu
*);
1675 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1676 CORE_ADDR
, struct dwarf2_cu
*);
1678 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1679 struct dwarf2_cu
*);
1681 static void dwarf2_attach_fields_to_type (struct field_info
*,
1682 struct type
*, struct dwarf2_cu
*);
1684 static void dwarf2_add_member_fn (struct field_info
*,
1685 struct die_info
*, struct type
*,
1686 struct dwarf2_cu
*);
1688 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1690 struct dwarf2_cu
*);
1692 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1694 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1696 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1698 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1700 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1702 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1704 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1706 static struct type
*read_module_type (struct die_info
*die
,
1707 struct dwarf2_cu
*cu
);
1709 static const char *namespace_name (struct die_info
*die
,
1710 int *is_anonymous
, struct dwarf2_cu
*);
1712 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1714 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1716 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1717 struct dwarf2_cu
*);
1719 static struct die_info
*read_die_and_siblings_1
1720 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1723 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1724 const gdb_byte
*info_ptr
,
1725 const gdb_byte
**new_info_ptr
,
1726 struct die_info
*parent
);
1728 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1729 struct die_info
**, const gdb_byte
*,
1732 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1733 struct die_info
**, const gdb_byte
*,
1736 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1738 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1741 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1743 static const char *dwarf2_full_name (const char *name
,
1744 struct die_info
*die
,
1745 struct dwarf2_cu
*cu
);
1747 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1748 struct dwarf2_cu
*cu
);
1750 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1751 struct dwarf2_cu
**);
1753 static const char *dwarf_tag_name (unsigned int);
1755 static const char *dwarf_attr_name (unsigned int);
1757 static const char *dwarf_unit_type_name (int unit_type
);
1759 static const char *dwarf_form_name (unsigned int);
1761 static const char *dwarf_bool_name (unsigned int);
1763 static const char *dwarf_type_encoding_name (unsigned int);
1765 static struct die_info
*sibling_die (struct die_info
*);
1767 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1769 static void dump_die_for_error (struct die_info
*);
1771 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1774 /*static*/ void dump_die (struct die_info
*, int max_level
);
1776 static void store_in_ref_table (struct die_info
*,
1777 struct dwarf2_cu
*);
1779 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1781 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1783 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1784 const struct attribute
*,
1785 struct dwarf2_cu
**);
1787 static struct die_info
*follow_die_ref (struct die_info
*,
1788 const struct attribute
*,
1789 struct dwarf2_cu
**);
1791 static struct die_info
*follow_die_sig (struct die_info
*,
1792 const struct attribute
*,
1793 struct dwarf2_cu
**);
1795 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1796 struct dwarf2_cu
*);
1798 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1799 const struct attribute
*,
1800 struct dwarf2_cu
*);
1802 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1804 static void read_signatured_type (struct signatured_type
*);
1806 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1807 struct die_info
*die
, struct dwarf2_cu
*cu
,
1808 struct dynamic_prop
*prop
, struct type
*type
);
1810 /* memory allocation interface */
1812 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1814 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1816 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1818 static int attr_form_is_block (const struct attribute
*);
1820 static int attr_form_is_section_offset (const struct attribute
*);
1822 static int attr_form_is_constant (const struct attribute
*);
1824 static int attr_form_is_ref (const struct attribute
*);
1826 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1827 struct dwarf2_loclist_baton
*baton
,
1828 const struct attribute
*attr
);
1830 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1832 struct dwarf2_cu
*cu
,
1835 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1836 const gdb_byte
*info_ptr
,
1837 struct abbrev_info
*abbrev
);
1839 static hashval_t
partial_die_hash (const void *item
);
1841 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1843 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1844 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1845 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1847 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1848 struct die_info
*comp_unit_die
,
1849 enum language pretend_language
);
1851 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1853 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1855 static struct type
*set_die_type (struct die_info
*, struct type
*,
1856 struct dwarf2_cu
*);
1858 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1860 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1862 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1865 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1868 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1871 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1872 struct dwarf2_per_cu_data
*);
1874 static void dwarf2_mark (struct dwarf2_cu
*);
1876 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1878 static struct type
*get_die_type_at_offset (sect_offset
,
1879 struct dwarf2_per_cu_data
*);
1881 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1883 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1884 enum language pretend_language
);
1886 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1888 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1889 static struct type
*dwarf2_per_cu_addr_sized_int_type
1890 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1892 /* Class, the destructor of which frees all allocated queue entries. This
1893 will only have work to do if an error was thrown while processing the
1894 dwarf. If no error was thrown then the queue entries should have all
1895 been processed, and freed, as we went along. */
1897 class dwarf2_queue_guard
1900 dwarf2_queue_guard () = default;
1902 /* Free any entries remaining on the queue. There should only be
1903 entries left if we hit an error while processing the dwarf. */
1904 ~dwarf2_queue_guard ()
1906 struct dwarf2_queue_item
*item
, *last
;
1908 item
= dwarf2_queue
;
1911 /* Anything still marked queued is likely to be in an
1912 inconsistent state, so discard it. */
1913 if (item
->per_cu
->queued
)
1915 if (item
->per_cu
->cu
!= NULL
)
1916 free_one_cached_comp_unit (item
->per_cu
);
1917 item
->per_cu
->queued
= 0;
1925 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1929 /* The return type of find_file_and_directory. Note, the enclosed
1930 string pointers are only valid while this object is valid. */
1932 struct file_and_directory
1934 /* The filename. This is never NULL. */
1937 /* The compilation directory. NULL if not known. If we needed to
1938 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1939 points directly to the DW_AT_comp_dir string attribute owned by
1940 the obstack that owns the DIE. */
1941 const char *comp_dir
;
1943 /* If we needed to build a new string for comp_dir, this is what
1944 owns the storage. */
1945 std::string comp_dir_storage
;
1948 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1949 struct dwarf2_cu
*cu
);
1951 static char *file_full_name (int file
, struct line_header
*lh
,
1952 const char *comp_dir
);
1954 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1955 enum class rcuh_kind
{ COMPILE
, TYPE
};
1957 static const gdb_byte
*read_and_check_comp_unit_head
1958 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1959 struct comp_unit_head
*header
,
1960 struct dwarf2_section_info
*section
,
1961 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1962 rcuh_kind section_kind
);
1964 static void init_cutu_and_read_dies
1965 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1966 int use_existing_cu
, int keep
, bool skip_partial
,
1967 die_reader_func_ftype
*die_reader_func
, void *data
);
1969 static void init_cutu_and_read_dies_simple
1970 (struct dwarf2_per_cu_data
*this_cu
,
1971 die_reader_func_ftype
*die_reader_func
, void *data
);
1973 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1975 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
1977 static struct dwo_unit
*lookup_dwo_unit_in_dwp
1978 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1979 struct dwp_file
*dwp_file
, const char *comp_dir
,
1980 ULONGEST signature
, int is_debug_types
);
1982 static struct dwp_file
*get_dwp_file
1983 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1985 static struct dwo_unit
*lookup_dwo_comp_unit
1986 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
1988 static struct dwo_unit
*lookup_dwo_type_unit
1989 (struct signatured_type
*, const char *, const char *);
1991 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
1993 /* A unique pointer to a dwo_file. */
1995 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
1997 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1999 static void check_producer (struct dwarf2_cu
*cu
);
2001 static void free_line_header_voidp (void *arg
);
2003 /* Various complaints about symbol reading that don't abort the process. */
2006 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2008 complaint (_("statement list doesn't fit in .debug_line section"));
2012 dwarf2_debug_line_missing_file_complaint (void)
2014 complaint (_(".debug_line section has line data without a file"));
2018 dwarf2_debug_line_missing_end_sequence_complaint (void)
2020 complaint (_(".debug_line section has line "
2021 "program sequence without an end"));
2025 dwarf2_complex_location_expr_complaint (void)
2027 complaint (_("location expression too complex"));
2031 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2034 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2039 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2041 complaint (_("debug info runs off end of %s section"
2043 get_section_name (section
),
2044 get_section_file_name (section
));
2048 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2050 complaint (_("macro debug info contains a "
2051 "malformed macro definition:\n`%s'"),
2056 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2058 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2062 /* Hash function for line_header_hash. */
2065 line_header_hash (const struct line_header
*ofs
)
2067 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2070 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2073 line_header_hash_voidp (const void *item
)
2075 const struct line_header
*ofs
= (const struct line_header
*) item
;
2077 return line_header_hash (ofs
);
2080 /* Equality function for line_header_hash. */
2083 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2085 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2086 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2088 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2089 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2094 /* Read the given attribute value as an address, taking the attribute's
2095 form into account. */
2098 attr_value_as_address (struct attribute
*attr
)
2102 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2103 && attr
->form
!= DW_FORM_GNU_addr_index
)
2105 /* Aside from a few clearly defined exceptions, attributes that
2106 contain an address must always be in DW_FORM_addr form.
2107 Unfortunately, some compilers happen to be violating this
2108 requirement by encoding addresses using other forms, such
2109 as DW_FORM_data4 for example. For those broken compilers,
2110 we try to do our best, without any guarantee of success,
2111 to interpret the address correctly. It would also be nice
2112 to generate a complaint, but that would require us to maintain
2113 a list of legitimate cases where a non-address form is allowed,
2114 as well as update callers to pass in at least the CU's DWARF
2115 version. This is more overhead than what we're willing to
2116 expand for a pretty rare case. */
2117 addr
= DW_UNSND (attr
);
2120 addr
= DW_ADDR (attr
);
2125 /* See declaration. */
2127 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2128 const dwarf2_debug_sections
*names
,
2130 : objfile (objfile_
),
2131 can_copy (can_copy_
)
2134 names
= &dwarf2_elf_names
;
2136 bfd
*obfd
= objfile
->obfd
;
2138 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2139 locate_sections (obfd
, sec
, *names
);
2142 dwarf2_per_objfile::~dwarf2_per_objfile ()
2144 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2145 free_cached_comp_units ();
2147 if (quick_file_names_table
)
2148 htab_delete (quick_file_names_table
);
2150 if (line_header_hash
)
2151 htab_delete (line_header_hash
);
2153 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2154 per_cu
->imported_symtabs_free ();
2156 for (signatured_type
*sig_type
: all_type_units
)
2157 sig_type
->per_cu
.imported_symtabs_free ();
2159 /* Everything else should be on the objfile obstack. */
2162 /* See declaration. */
2165 dwarf2_per_objfile::free_cached_comp_units ()
2167 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2168 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2169 while (per_cu
!= NULL
)
2171 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2174 *last_chain
= next_cu
;
2179 /* A helper class that calls free_cached_comp_units on
2182 class free_cached_comp_units
2186 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2187 : m_per_objfile (per_objfile
)
2191 ~free_cached_comp_units ()
2193 m_per_objfile
->free_cached_comp_units ();
2196 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2200 dwarf2_per_objfile
*m_per_objfile
;
2203 /* Try to locate the sections we need for DWARF 2 debugging
2204 information and return true if we have enough to do something.
2205 NAMES points to the dwarf2 section names, or is NULL if the standard
2206 ELF names are used. CAN_COPY is true for formats where symbol
2207 interposition is possible and so symbol values must follow copy
2208 relocation rules. */
2211 dwarf2_has_info (struct objfile
*objfile
,
2212 const struct dwarf2_debug_sections
*names
,
2215 if (objfile
->flags
& OBJF_READNEVER
)
2218 struct dwarf2_per_objfile
*dwarf2_per_objfile
2219 = get_dwarf2_per_objfile (objfile
);
2221 if (dwarf2_per_objfile
== NULL
)
2222 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2226 return (!dwarf2_per_objfile
->info
.is_virtual
2227 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2228 && !dwarf2_per_objfile
->abbrev
.is_virtual
2229 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2232 /* Return the containing section of virtual section SECTION. */
2234 static struct dwarf2_section_info
*
2235 get_containing_section (const struct dwarf2_section_info
*section
)
2237 gdb_assert (section
->is_virtual
);
2238 return section
->s
.containing_section
;
2241 /* Return the bfd owner of SECTION. */
2244 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2246 if (section
->is_virtual
)
2248 section
= get_containing_section (section
);
2249 gdb_assert (!section
->is_virtual
);
2251 return section
->s
.section
->owner
;
2254 /* Return the bfd section of SECTION.
2255 Returns NULL if the section is not present. */
2258 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2260 if (section
->is_virtual
)
2262 section
= get_containing_section (section
);
2263 gdb_assert (!section
->is_virtual
);
2265 return section
->s
.section
;
2268 /* Return the name of SECTION. */
2271 get_section_name (const struct dwarf2_section_info
*section
)
2273 asection
*sectp
= get_section_bfd_section (section
);
2275 gdb_assert (sectp
!= NULL
);
2276 return bfd_section_name (sectp
);
2279 /* Return the name of the file SECTION is in. */
2282 get_section_file_name (const struct dwarf2_section_info
*section
)
2284 bfd
*abfd
= get_section_bfd_owner (section
);
2286 return bfd_get_filename (abfd
);
2289 /* Return the id of SECTION.
2290 Returns 0 if SECTION doesn't exist. */
2293 get_section_id (const struct dwarf2_section_info
*section
)
2295 asection
*sectp
= get_section_bfd_section (section
);
2302 /* Return the flags of SECTION.
2303 SECTION (or containing section if this is a virtual section) must exist. */
2306 get_section_flags (const struct dwarf2_section_info
*section
)
2308 asection
*sectp
= get_section_bfd_section (section
);
2310 gdb_assert (sectp
!= NULL
);
2311 return bfd_section_flags (sectp
);
2314 /* When loading sections, we look either for uncompressed section or for
2315 compressed section names. */
2318 section_is_p (const char *section_name
,
2319 const struct dwarf2_section_names
*names
)
2321 if (names
->normal
!= NULL
2322 && strcmp (section_name
, names
->normal
) == 0)
2324 if (names
->compressed
!= NULL
2325 && strcmp (section_name
, names
->compressed
) == 0)
2330 /* See declaration. */
2333 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2334 const dwarf2_debug_sections
&names
)
2336 flagword aflag
= bfd_section_flags (sectp
);
2338 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2341 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2342 > bfd_get_file_size (abfd
))
2344 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2345 warning (_("Discarding section %s which has a section size (%s"
2346 ") larger than the file size [in module %s]"),
2347 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2348 bfd_get_filename (abfd
));
2350 else if (section_is_p (sectp
->name
, &names
.info
))
2352 this->info
.s
.section
= sectp
;
2353 this->info
.size
= bfd_section_size (sectp
);
2355 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2357 this->abbrev
.s
.section
= sectp
;
2358 this->abbrev
.size
= bfd_section_size (sectp
);
2360 else if (section_is_p (sectp
->name
, &names
.line
))
2362 this->line
.s
.section
= sectp
;
2363 this->line
.size
= bfd_section_size (sectp
);
2365 else if (section_is_p (sectp
->name
, &names
.loc
))
2367 this->loc
.s
.section
= sectp
;
2368 this->loc
.size
= bfd_section_size (sectp
);
2370 else if (section_is_p (sectp
->name
, &names
.loclists
))
2372 this->loclists
.s
.section
= sectp
;
2373 this->loclists
.size
= bfd_section_size (sectp
);
2375 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2377 this->macinfo
.s
.section
= sectp
;
2378 this->macinfo
.size
= bfd_section_size (sectp
);
2380 else if (section_is_p (sectp
->name
, &names
.macro
))
2382 this->macro
.s
.section
= sectp
;
2383 this->macro
.size
= bfd_section_size (sectp
);
2385 else if (section_is_p (sectp
->name
, &names
.str
))
2387 this->str
.s
.section
= sectp
;
2388 this->str
.size
= bfd_section_size (sectp
);
2390 else if (section_is_p (sectp
->name
, &names
.line_str
))
2392 this->line_str
.s
.section
= sectp
;
2393 this->line_str
.size
= bfd_section_size (sectp
);
2395 else if (section_is_p (sectp
->name
, &names
.addr
))
2397 this->addr
.s
.section
= sectp
;
2398 this->addr
.size
= bfd_section_size (sectp
);
2400 else if (section_is_p (sectp
->name
, &names
.frame
))
2402 this->frame
.s
.section
= sectp
;
2403 this->frame
.size
= bfd_section_size (sectp
);
2405 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2407 this->eh_frame
.s
.section
= sectp
;
2408 this->eh_frame
.size
= bfd_section_size (sectp
);
2410 else if (section_is_p (sectp
->name
, &names
.ranges
))
2412 this->ranges
.s
.section
= sectp
;
2413 this->ranges
.size
= bfd_section_size (sectp
);
2415 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2417 this->rnglists
.s
.section
= sectp
;
2418 this->rnglists
.size
= bfd_section_size (sectp
);
2420 else if (section_is_p (sectp
->name
, &names
.types
))
2422 struct dwarf2_section_info type_section
;
2424 memset (&type_section
, 0, sizeof (type_section
));
2425 type_section
.s
.section
= sectp
;
2426 type_section
.size
= bfd_section_size (sectp
);
2428 this->types
.push_back (type_section
);
2430 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2432 this->gdb_index
.s
.section
= sectp
;
2433 this->gdb_index
.size
= bfd_section_size (sectp
);
2435 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2437 this->debug_names
.s
.section
= sectp
;
2438 this->debug_names
.size
= bfd_section_size (sectp
);
2440 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2442 this->debug_aranges
.s
.section
= sectp
;
2443 this->debug_aranges
.size
= bfd_section_size (sectp
);
2446 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2447 && bfd_section_vma (sectp
) == 0)
2448 this->has_section_at_zero
= true;
2451 /* A helper function that decides whether a section is empty,
2455 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2457 if (section
->is_virtual
)
2458 return section
->size
== 0;
2459 return section
->s
.section
== NULL
|| section
->size
== 0;
2462 /* See dwarf2read.h. */
2465 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2469 gdb_byte
*buf
, *retbuf
;
2473 info
->buffer
= NULL
;
2474 info
->readin
= true;
2476 if (dwarf2_section_empty_p (info
))
2479 sectp
= get_section_bfd_section (info
);
2481 /* If this is a virtual section we need to read in the real one first. */
2482 if (info
->is_virtual
)
2484 struct dwarf2_section_info
*containing_section
=
2485 get_containing_section (info
);
2487 gdb_assert (sectp
!= NULL
);
2488 if ((sectp
->flags
& SEC_RELOC
) != 0)
2490 error (_("Dwarf Error: DWP format V2 with relocations is not"
2491 " supported in section %s [in module %s]"),
2492 get_section_name (info
), get_section_file_name (info
));
2494 dwarf2_read_section (objfile
, containing_section
);
2495 /* Other code should have already caught virtual sections that don't
2497 gdb_assert (info
->virtual_offset
+ info
->size
2498 <= containing_section
->size
);
2499 /* If the real section is empty or there was a problem reading the
2500 section we shouldn't get here. */
2501 gdb_assert (containing_section
->buffer
!= NULL
);
2502 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2506 /* If the section has relocations, we must read it ourselves.
2507 Otherwise we attach it to the BFD. */
2508 if ((sectp
->flags
& SEC_RELOC
) == 0)
2510 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2514 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2517 /* When debugging .o files, we may need to apply relocations; see
2518 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2519 We never compress sections in .o files, so we only need to
2520 try this when the section is not compressed. */
2521 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2524 info
->buffer
= retbuf
;
2528 abfd
= get_section_bfd_owner (info
);
2529 gdb_assert (abfd
!= NULL
);
2531 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2532 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2534 error (_("Dwarf Error: Can't read DWARF data"
2535 " in section %s [in module %s]"),
2536 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2540 /* A helper function that returns the size of a section in a safe way.
2541 If you are positive that the section has been read before using the
2542 size, then it is safe to refer to the dwarf2_section_info object's
2543 "size" field directly. In other cases, you must call this
2544 function, because for compressed sections the size field is not set
2545 correctly until the section has been read. */
2547 static bfd_size_type
2548 dwarf2_section_size (struct objfile
*objfile
,
2549 struct dwarf2_section_info
*info
)
2552 dwarf2_read_section (objfile
, info
);
2556 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2560 dwarf2_get_section_info (struct objfile
*objfile
,
2561 enum dwarf2_section_enum sect
,
2562 asection
**sectp
, const gdb_byte
**bufp
,
2563 bfd_size_type
*sizep
)
2565 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2566 struct dwarf2_section_info
*info
;
2568 /* We may see an objfile without any DWARF, in which case we just
2579 case DWARF2_DEBUG_FRAME
:
2580 info
= &data
->frame
;
2582 case DWARF2_EH_FRAME
:
2583 info
= &data
->eh_frame
;
2586 gdb_assert_not_reached ("unexpected section");
2589 dwarf2_read_section (objfile
, info
);
2591 *sectp
= get_section_bfd_section (info
);
2592 *bufp
= info
->buffer
;
2593 *sizep
= info
->size
;
2596 /* A helper function to find the sections for a .dwz file. */
2599 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2601 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2603 /* Note that we only support the standard ELF names, because .dwz
2604 is ELF-only (at the time of writing). */
2605 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2607 dwz_file
->abbrev
.s
.section
= sectp
;
2608 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2610 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2612 dwz_file
->info
.s
.section
= sectp
;
2613 dwz_file
->info
.size
= bfd_section_size (sectp
);
2615 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2617 dwz_file
->str
.s
.section
= sectp
;
2618 dwz_file
->str
.size
= bfd_section_size (sectp
);
2620 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2622 dwz_file
->line
.s
.section
= sectp
;
2623 dwz_file
->line
.size
= bfd_section_size (sectp
);
2625 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2627 dwz_file
->macro
.s
.section
= sectp
;
2628 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2630 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2632 dwz_file
->gdb_index
.s
.section
= sectp
;
2633 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2635 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2637 dwz_file
->debug_names
.s
.section
= sectp
;
2638 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2642 /* See dwarf2read.h. */
2645 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2647 const char *filename
;
2648 bfd_size_type buildid_len_arg
;
2652 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2653 return dwarf2_per_objfile
->dwz_file
.get ();
2655 bfd_set_error (bfd_error_no_error
);
2656 gdb::unique_xmalloc_ptr
<char> data
2657 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2658 &buildid_len_arg
, &buildid
));
2661 if (bfd_get_error () == bfd_error_no_error
)
2663 error (_("could not read '.gnu_debugaltlink' section: %s"),
2664 bfd_errmsg (bfd_get_error ()));
2667 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2669 buildid_len
= (size_t) buildid_len_arg
;
2671 filename
= data
.get ();
2673 std::string abs_storage
;
2674 if (!IS_ABSOLUTE_PATH (filename
))
2676 gdb::unique_xmalloc_ptr
<char> abs
2677 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2679 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2680 filename
= abs_storage
.c_str ();
2683 /* First try the file name given in the section. If that doesn't
2684 work, try to use the build-id instead. */
2685 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2686 if (dwz_bfd
!= NULL
)
2688 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2689 dwz_bfd
.reset (nullptr);
2692 if (dwz_bfd
== NULL
)
2693 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2695 if (dwz_bfd
== NULL
)
2696 error (_("could not find '.gnu_debugaltlink' file for %s"),
2697 objfile_name (dwarf2_per_objfile
->objfile
));
2699 std::unique_ptr
<struct dwz_file
> result
2700 (new struct dwz_file (std::move (dwz_bfd
)));
2702 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2705 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2706 result
->dwz_bfd
.get ());
2707 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2708 return dwarf2_per_objfile
->dwz_file
.get ();
2711 /* DWARF quick_symbols_functions support. */
2713 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2714 unique line tables, so we maintain a separate table of all .debug_line
2715 derived entries to support the sharing.
2716 All the quick functions need is the list of file names. We discard the
2717 line_header when we're done and don't need to record it here. */
2718 struct quick_file_names
2720 /* The data used to construct the hash key. */
2721 struct stmt_list_hash hash
;
2723 /* The number of entries in file_names, real_names. */
2724 unsigned int num_file_names
;
2726 /* The file names from the line table, after being run through
2728 const char **file_names
;
2730 /* The file names from the line table after being run through
2731 gdb_realpath. These are computed lazily. */
2732 const char **real_names
;
2735 /* When using the index (and thus not using psymtabs), each CU has an
2736 object of this type. This is used to hold information needed by
2737 the various "quick" methods. */
2738 struct dwarf2_per_cu_quick_data
2740 /* The file table. This can be NULL if there was no file table
2741 or it's currently not read in.
2742 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2743 struct quick_file_names
*file_names
;
2745 /* The corresponding symbol table. This is NULL if symbols for this
2746 CU have not yet been read. */
2747 struct compunit_symtab
*compunit_symtab
;
2749 /* A temporary mark bit used when iterating over all CUs in
2750 expand_symtabs_matching. */
2751 unsigned int mark
: 1;
2753 /* True if we've tried to read the file table and found there isn't one.
2754 There will be no point in trying to read it again next time. */
2755 unsigned int no_file_data
: 1;
2758 /* Utility hash function for a stmt_list_hash. */
2761 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2765 if (stmt_list_hash
->dwo_unit
!= NULL
)
2766 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2767 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2771 /* Utility equality function for a stmt_list_hash. */
2774 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2775 const struct stmt_list_hash
*rhs
)
2777 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2779 if (lhs
->dwo_unit
!= NULL
2780 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2783 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2786 /* Hash function for a quick_file_names. */
2789 hash_file_name_entry (const void *e
)
2791 const struct quick_file_names
*file_data
2792 = (const struct quick_file_names
*) e
;
2794 return hash_stmt_list_entry (&file_data
->hash
);
2797 /* Equality function for a quick_file_names. */
2800 eq_file_name_entry (const void *a
, const void *b
)
2802 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2803 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2805 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2808 /* Delete function for a quick_file_names. */
2811 delete_file_name_entry (void *e
)
2813 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2816 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2818 xfree ((void*) file_data
->file_names
[i
]);
2819 if (file_data
->real_names
)
2820 xfree ((void*) file_data
->real_names
[i
]);
2823 /* The space for the struct itself lives on objfile_obstack,
2824 so we don't free it here. */
2827 /* Create a quick_file_names hash table. */
2830 create_quick_file_names_table (unsigned int nr_initial_entries
)
2832 return htab_create_alloc (nr_initial_entries
,
2833 hash_file_name_entry
, eq_file_name_entry
,
2834 delete_file_name_entry
, xcalloc
, xfree
);
2837 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2838 have to be created afterwards. You should call age_cached_comp_units after
2839 processing PER_CU->CU. dw2_setup must have been already called. */
2842 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2844 if (per_cu
->is_debug_types
)
2845 load_full_type_unit (per_cu
);
2847 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2849 if (per_cu
->cu
== NULL
)
2850 return; /* Dummy CU. */
2852 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2855 /* Read in the symbols for PER_CU. */
2858 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2860 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2862 /* Skip type_unit_groups, reading the type units they contain
2863 is handled elsewhere. */
2864 if (IS_TYPE_UNIT_GROUP (per_cu
))
2867 /* The destructor of dwarf2_queue_guard frees any entries left on
2868 the queue. After this point we're guaranteed to leave this function
2869 with the dwarf queue empty. */
2870 dwarf2_queue_guard q_guard
;
2872 if (dwarf2_per_objfile
->using_index
2873 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2874 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2876 queue_comp_unit (per_cu
, language_minimal
);
2877 load_cu (per_cu
, skip_partial
);
2879 /* If we just loaded a CU from a DWO, and we're working with an index
2880 that may badly handle TUs, load all the TUs in that DWO as well.
2881 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2882 if (!per_cu
->is_debug_types
2883 && per_cu
->cu
!= NULL
2884 && per_cu
->cu
->dwo_unit
!= NULL
2885 && dwarf2_per_objfile
->index_table
!= NULL
2886 && dwarf2_per_objfile
->index_table
->version
<= 7
2887 /* DWP files aren't supported yet. */
2888 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2889 queue_and_load_all_dwo_tus (per_cu
);
2892 process_queue (dwarf2_per_objfile
);
2894 /* Age the cache, releasing compilation units that have not
2895 been used recently. */
2896 age_cached_comp_units (dwarf2_per_objfile
);
2899 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2900 the objfile from which this CU came. Returns the resulting symbol
2903 static struct compunit_symtab
*
2904 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2906 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2908 gdb_assert (dwarf2_per_objfile
->using_index
);
2909 if (!per_cu
->v
.quick
->compunit_symtab
)
2911 free_cached_comp_units
freer (dwarf2_per_objfile
);
2912 scoped_restore decrementer
= increment_reading_symtab ();
2913 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2914 process_cu_includes (dwarf2_per_objfile
);
2917 return per_cu
->v
.quick
->compunit_symtab
;
2920 /* See declaration. */
2922 dwarf2_per_cu_data
*
2923 dwarf2_per_objfile::get_cutu (int index
)
2925 if (index
>= this->all_comp_units
.size ())
2927 index
-= this->all_comp_units
.size ();
2928 gdb_assert (index
< this->all_type_units
.size ());
2929 return &this->all_type_units
[index
]->per_cu
;
2932 return this->all_comp_units
[index
];
2935 /* See declaration. */
2937 dwarf2_per_cu_data
*
2938 dwarf2_per_objfile::get_cu (int index
)
2940 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2942 return this->all_comp_units
[index
];
2945 /* See declaration. */
2948 dwarf2_per_objfile::get_tu (int index
)
2950 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2952 return this->all_type_units
[index
];
2955 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2956 objfile_obstack, and constructed with the specified field
2959 static dwarf2_per_cu_data
*
2960 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2961 struct dwarf2_section_info
*section
,
2963 sect_offset sect_off
, ULONGEST length
)
2965 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
2966 dwarf2_per_cu_data
*the_cu
2967 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2968 struct dwarf2_per_cu_data
);
2969 the_cu
->sect_off
= sect_off
;
2970 the_cu
->length
= length
;
2971 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
2972 the_cu
->section
= section
;
2973 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2974 struct dwarf2_per_cu_quick_data
);
2975 the_cu
->is_dwz
= is_dwz
;
2979 /* A helper for create_cus_from_index that handles a given list of
2983 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2984 const gdb_byte
*cu_list
, offset_type n_elements
,
2985 struct dwarf2_section_info
*section
,
2988 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
2990 gdb_static_assert (sizeof (ULONGEST
) >= 8);
2992 sect_offset sect_off
2993 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
2994 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
2997 dwarf2_per_cu_data
*per_cu
2998 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3000 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3004 /* Read the CU list from the mapped index, and use it to create all
3005 the CU objects for this objfile. */
3008 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3009 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3010 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3012 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3013 dwarf2_per_objfile
->all_comp_units
.reserve
3014 ((cu_list_elements
+ dwz_elements
) / 2);
3016 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3017 &dwarf2_per_objfile
->info
, 0);
3019 if (dwz_elements
== 0)
3022 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3023 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3027 /* Create the signatured type hash table from the index. */
3030 create_signatured_type_table_from_index
3031 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3032 struct dwarf2_section_info
*section
,
3033 const gdb_byte
*bytes
,
3034 offset_type elements
)
3036 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3038 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3039 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3041 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3043 for (offset_type i
= 0; i
< elements
; i
+= 3)
3045 struct signatured_type
*sig_type
;
3048 cu_offset type_offset_in_tu
;
3050 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3051 sect_offset sect_off
3052 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3054 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3056 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3059 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3060 struct signatured_type
);
3061 sig_type
->signature
= signature
;
3062 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3063 sig_type
->per_cu
.is_debug_types
= 1;
3064 sig_type
->per_cu
.section
= section
;
3065 sig_type
->per_cu
.sect_off
= sect_off
;
3066 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3067 sig_type
->per_cu
.v
.quick
3068 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3069 struct dwarf2_per_cu_quick_data
);
3071 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3074 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3077 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3080 /* Create the signatured type hash table from .debug_names. */
3083 create_signatured_type_table_from_debug_names
3084 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3085 const mapped_debug_names
&map
,
3086 struct dwarf2_section_info
*section
,
3087 struct dwarf2_section_info
*abbrev_section
)
3089 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3091 dwarf2_read_section (objfile
, section
);
3092 dwarf2_read_section (objfile
, abbrev_section
);
3094 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3095 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3097 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3099 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3101 struct signatured_type
*sig_type
;
3104 sect_offset sect_off
3105 = (sect_offset
) (extract_unsigned_integer
3106 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3108 map
.dwarf5_byte_order
));
3110 comp_unit_head cu_header
;
3111 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3113 section
->buffer
+ to_underlying (sect_off
),
3116 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3117 struct signatured_type
);
3118 sig_type
->signature
= cu_header
.signature
;
3119 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3120 sig_type
->per_cu
.is_debug_types
= 1;
3121 sig_type
->per_cu
.section
= section
;
3122 sig_type
->per_cu
.sect_off
= sect_off
;
3123 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3124 sig_type
->per_cu
.v
.quick
3125 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3126 struct dwarf2_per_cu_quick_data
);
3128 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3131 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3134 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3137 /* Read the address map data from the mapped index, and use it to
3138 populate the objfile's psymtabs_addrmap. */
3141 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3142 struct mapped_index
*index
)
3144 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3145 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3146 const gdb_byte
*iter
, *end
;
3147 struct addrmap
*mutable_map
;
3150 auto_obstack temp_obstack
;
3152 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3154 iter
= index
->address_table
.data ();
3155 end
= iter
+ index
->address_table
.size ();
3157 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3161 ULONGEST hi
, lo
, cu_index
;
3162 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3164 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3166 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3171 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3172 hex_string (lo
), hex_string (hi
));
3176 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3178 complaint (_(".gdb_index address table has invalid CU number %u"),
3179 (unsigned) cu_index
);
3183 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3184 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3185 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3186 dwarf2_per_objfile
->get_cu (cu_index
));
3189 objfile
->partial_symtabs
->psymtabs_addrmap
3190 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3193 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3194 populate the objfile's psymtabs_addrmap. */
3197 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3198 struct dwarf2_section_info
*section
)
3200 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3201 bfd
*abfd
= objfile
->obfd
;
3202 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3203 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
3204 SECT_OFF_TEXT (objfile
));
3206 auto_obstack temp_obstack
;
3207 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3209 std::unordered_map
<sect_offset
,
3210 dwarf2_per_cu_data
*,
3211 gdb::hash_enum
<sect_offset
>>
3212 debug_info_offset_to_per_cu
;
3213 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3215 const auto insertpair
3216 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3217 if (!insertpair
.second
)
3219 warning (_("Section .debug_aranges in %s has duplicate "
3220 "debug_info_offset %s, ignoring .debug_aranges."),
3221 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3226 dwarf2_read_section (objfile
, section
);
3228 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3230 const gdb_byte
*addr
= section
->buffer
;
3232 while (addr
< section
->buffer
+ section
->size
)
3234 const gdb_byte
*const entry_addr
= addr
;
3235 unsigned int bytes_read
;
3237 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3241 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3242 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3243 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3244 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3246 warning (_("Section .debug_aranges in %s entry at offset %s "
3247 "length %s exceeds section length %s, "
3248 "ignoring .debug_aranges."),
3249 objfile_name (objfile
),
3250 plongest (entry_addr
- section
->buffer
),
3251 plongest (bytes_read
+ entry_length
),
3252 pulongest (section
->size
));
3256 /* The version number. */
3257 const uint16_t version
= read_2_bytes (abfd
, addr
);
3261 warning (_("Section .debug_aranges in %s entry at offset %s "
3262 "has unsupported version %d, ignoring .debug_aranges."),
3263 objfile_name (objfile
),
3264 plongest (entry_addr
- section
->buffer
), version
);
3268 const uint64_t debug_info_offset
3269 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3270 addr
+= offset_size
;
3271 const auto per_cu_it
3272 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3273 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3275 warning (_("Section .debug_aranges in %s entry at offset %s "
3276 "debug_info_offset %s does not exists, "
3277 "ignoring .debug_aranges."),
3278 objfile_name (objfile
),
3279 plongest (entry_addr
- section
->buffer
),
3280 pulongest (debug_info_offset
));
3283 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3285 const uint8_t address_size
= *addr
++;
3286 if (address_size
< 1 || address_size
> 8)
3288 warning (_("Section .debug_aranges in %s entry at offset %s "
3289 "address_size %u is invalid, ignoring .debug_aranges."),
3290 objfile_name (objfile
),
3291 plongest (entry_addr
- section
->buffer
), address_size
);
3295 const uint8_t segment_selector_size
= *addr
++;
3296 if (segment_selector_size
!= 0)
3298 warning (_("Section .debug_aranges in %s entry at offset %s "
3299 "segment_selector_size %u is not supported, "
3300 "ignoring .debug_aranges."),
3301 objfile_name (objfile
),
3302 plongest (entry_addr
- section
->buffer
),
3303 segment_selector_size
);
3307 /* Must pad to an alignment boundary that is twice the address
3308 size. It is undocumented by the DWARF standard but GCC does
3310 for (size_t padding
= ((-(addr
- section
->buffer
))
3311 & (2 * address_size
- 1));
3312 padding
> 0; padding
--)
3315 warning (_("Section .debug_aranges in %s entry at offset %s "
3316 "padding is not zero, ignoring .debug_aranges."),
3317 objfile_name (objfile
),
3318 plongest (entry_addr
- section
->buffer
));
3324 if (addr
+ 2 * address_size
> entry_end
)
3326 warning (_("Section .debug_aranges in %s entry at offset %s "
3327 "address list is not properly terminated, "
3328 "ignoring .debug_aranges."),
3329 objfile_name (objfile
),
3330 plongest (entry_addr
- section
->buffer
));
3333 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3335 addr
+= address_size
;
3336 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3338 addr
+= address_size
;
3339 if (start
== 0 && length
== 0)
3341 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3343 /* Symbol was eliminated due to a COMDAT group. */
3346 ULONGEST end
= start
+ length
;
3347 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3349 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3351 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3355 objfile
->partial_symtabs
->psymtabs_addrmap
3356 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3359 /* Find a slot in the mapped index INDEX for the object named NAME.
3360 If NAME is found, set *VEC_OUT to point to the CU vector in the
3361 constant pool and return true. If NAME cannot be found, return
3365 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3366 offset_type
**vec_out
)
3369 offset_type slot
, step
;
3370 int (*cmp
) (const char *, const char *);
3372 gdb::unique_xmalloc_ptr
<char> without_params
;
3373 if (current_language
->la_language
== language_cplus
3374 || current_language
->la_language
== language_fortran
3375 || current_language
->la_language
== language_d
)
3377 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3380 if (strchr (name
, '(') != NULL
)
3382 without_params
= cp_remove_params (name
);
3384 if (without_params
!= NULL
)
3385 name
= without_params
.get ();
3389 /* Index version 4 did not support case insensitive searches. But the
3390 indices for case insensitive languages are built in lowercase, therefore
3391 simulate our NAME being searched is also lowercased. */
3392 hash
= mapped_index_string_hash ((index
->version
== 4
3393 && case_sensitivity
== case_sensitive_off
3394 ? 5 : index
->version
),
3397 slot
= hash
& (index
->symbol_table
.size () - 1);
3398 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3399 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3405 const auto &bucket
= index
->symbol_table
[slot
];
3406 if (bucket
.name
== 0 && bucket
.vec
== 0)
3409 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3410 if (!cmp (name
, str
))
3412 *vec_out
= (offset_type
*) (index
->constant_pool
3413 + MAYBE_SWAP (bucket
.vec
));
3417 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3421 /* A helper function that reads the .gdb_index from BUFFER and fills
3422 in MAP. FILENAME is the name of the file containing the data;
3423 it is used for error reporting. DEPRECATED_OK is true if it is
3424 ok to use deprecated sections.
3426 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3427 out parameters that are filled in with information about the CU and
3428 TU lists in the section.
3430 Returns true if all went well, false otherwise. */
3433 read_gdb_index_from_buffer (struct objfile
*objfile
,
3434 const char *filename
,
3436 gdb::array_view
<const gdb_byte
> buffer
,
3437 struct mapped_index
*map
,
3438 const gdb_byte
**cu_list
,
3439 offset_type
*cu_list_elements
,
3440 const gdb_byte
**types_list
,
3441 offset_type
*types_list_elements
)
3443 const gdb_byte
*addr
= &buffer
[0];
3445 /* Version check. */
3446 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3447 /* Versions earlier than 3 emitted every copy of a psymbol. This
3448 causes the index to behave very poorly for certain requests. Version 3
3449 contained incomplete addrmap. So, it seems better to just ignore such
3453 static int warning_printed
= 0;
3454 if (!warning_printed
)
3456 warning (_("Skipping obsolete .gdb_index section in %s."),
3458 warning_printed
= 1;
3462 /* Index version 4 uses a different hash function than index version
3465 Versions earlier than 6 did not emit psymbols for inlined
3466 functions. Using these files will cause GDB not to be able to
3467 set breakpoints on inlined functions by name, so we ignore these
3468 indices unless the user has done
3469 "set use-deprecated-index-sections on". */
3470 if (version
< 6 && !deprecated_ok
)
3472 static int warning_printed
= 0;
3473 if (!warning_printed
)
3476 Skipping deprecated .gdb_index section in %s.\n\
3477 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3478 to use the section anyway."),
3480 warning_printed
= 1;
3484 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3485 of the TU (for symbols coming from TUs),
3486 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3487 Plus gold-generated indices can have duplicate entries for global symbols,
3488 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3489 These are just performance bugs, and we can't distinguish gdb-generated
3490 indices from gold-generated ones, so issue no warning here. */
3492 /* Indexes with higher version than the one supported by GDB may be no
3493 longer backward compatible. */
3497 map
->version
= version
;
3499 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3502 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3503 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3507 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3508 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3509 - MAYBE_SWAP (metadata
[i
]))
3513 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3514 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3516 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3519 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3520 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3522 = gdb::array_view
<mapped_index::symbol_table_slot
>
3523 ((mapped_index::symbol_table_slot
*) symbol_table
,
3524 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3527 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3532 /* Callback types for dwarf2_read_gdb_index. */
3534 typedef gdb::function_view
3535 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3536 get_gdb_index_contents_ftype
;
3537 typedef gdb::function_view
3538 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3539 get_gdb_index_contents_dwz_ftype
;
3541 /* Read .gdb_index. If everything went ok, initialize the "quick"
3542 elements of all the CUs and return 1. Otherwise, return 0. */
3545 dwarf2_read_gdb_index
3546 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3547 get_gdb_index_contents_ftype get_gdb_index_contents
,
3548 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3550 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3551 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3552 struct dwz_file
*dwz
;
3553 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3555 gdb::array_view
<const gdb_byte
> main_index_contents
3556 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3558 if (main_index_contents
.empty ())
3561 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3562 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3563 use_deprecated_index_sections
,
3564 main_index_contents
, map
.get (), &cu_list
,
3565 &cu_list_elements
, &types_list
,
3566 &types_list_elements
))
3569 /* Don't use the index if it's empty. */
3570 if (map
->symbol_table
.empty ())
3573 /* If there is a .dwz file, read it so we can get its CU list as
3575 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3578 struct mapped_index dwz_map
;
3579 const gdb_byte
*dwz_types_ignore
;
3580 offset_type dwz_types_elements_ignore
;
3582 gdb::array_view
<const gdb_byte
> dwz_index_content
3583 = get_gdb_index_contents_dwz (objfile
, dwz
);
3585 if (dwz_index_content
.empty ())
3588 if (!read_gdb_index_from_buffer (objfile
,
3589 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3590 1, dwz_index_content
, &dwz_map
,
3591 &dwz_list
, &dwz_list_elements
,
3593 &dwz_types_elements_ignore
))
3595 warning (_("could not read '.gdb_index' section from %s; skipping"),
3596 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3601 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3602 dwz_list
, dwz_list_elements
);
3604 if (types_list_elements
)
3606 /* We can only handle a single .debug_types when we have an
3608 if (dwarf2_per_objfile
->types
.size () != 1)
3611 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3613 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3614 types_list
, types_list_elements
);
3617 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3619 dwarf2_per_objfile
->index_table
= std::move (map
);
3620 dwarf2_per_objfile
->using_index
= 1;
3621 dwarf2_per_objfile
->quick_file_names_table
=
3622 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3627 /* die_reader_func for dw2_get_file_names. */
3630 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3631 const gdb_byte
*info_ptr
,
3632 struct die_info
*comp_unit_die
,
3636 struct dwarf2_cu
*cu
= reader
->cu
;
3637 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3638 struct dwarf2_per_objfile
*dwarf2_per_objfile
3639 = cu
->per_cu
->dwarf2_per_objfile
;
3640 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3641 struct dwarf2_per_cu_data
*lh_cu
;
3642 struct attribute
*attr
;
3645 struct quick_file_names
*qfn
;
3647 gdb_assert (! this_cu
->is_debug_types
);
3649 /* Our callers never want to match partial units -- instead they
3650 will match the enclosing full CU. */
3651 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3653 this_cu
->v
.quick
->no_file_data
= 1;
3661 sect_offset line_offset
{};
3663 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3666 struct quick_file_names find_entry
;
3668 line_offset
= (sect_offset
) DW_UNSND (attr
);
3670 /* We may have already read in this line header (TU line header sharing).
3671 If we have we're done. */
3672 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3673 find_entry
.hash
.line_sect_off
= line_offset
;
3674 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3675 &find_entry
, INSERT
);
3678 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3682 lh
= dwarf_decode_line_header (line_offset
, cu
);
3686 lh_cu
->v
.quick
->no_file_data
= 1;
3690 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3691 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3692 qfn
->hash
.line_sect_off
= line_offset
;
3693 gdb_assert (slot
!= NULL
);
3696 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3699 if (strcmp (fnd
.name
, "<unknown>") != 0)
3702 qfn
->num_file_names
= offset
+ lh
->file_names
.size ();
3704 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3706 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3707 for (i
= 0; i
< lh
->file_names
.size (); ++i
)
3708 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3709 qfn
->real_names
= NULL
;
3711 lh_cu
->v
.quick
->file_names
= qfn
;
3714 /* A helper for the "quick" functions which attempts to read the line
3715 table for THIS_CU. */
3717 static struct quick_file_names
*
3718 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3720 /* This should never be called for TUs. */
3721 gdb_assert (! this_cu
->is_debug_types
);
3722 /* Nor type unit groups. */
3723 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3725 if (this_cu
->v
.quick
->file_names
!= NULL
)
3726 return this_cu
->v
.quick
->file_names
;
3727 /* If we know there is no line data, no point in looking again. */
3728 if (this_cu
->v
.quick
->no_file_data
)
3731 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3733 if (this_cu
->v
.quick
->no_file_data
)
3735 return this_cu
->v
.quick
->file_names
;
3738 /* A helper for the "quick" functions which computes and caches the
3739 real path for a given file name from the line table. */
3742 dw2_get_real_path (struct objfile
*objfile
,
3743 struct quick_file_names
*qfn
, int index
)
3745 if (qfn
->real_names
== NULL
)
3746 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3747 qfn
->num_file_names
, const char *);
3749 if (qfn
->real_names
[index
] == NULL
)
3750 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3752 return qfn
->real_names
[index
];
3755 static struct symtab
*
3756 dw2_find_last_source_symtab (struct objfile
*objfile
)
3758 struct dwarf2_per_objfile
*dwarf2_per_objfile
3759 = get_dwarf2_per_objfile (objfile
);
3760 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3761 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3766 return compunit_primary_filetab (cust
);
3769 /* Traversal function for dw2_forget_cached_source_info. */
3772 dw2_free_cached_file_names (void **slot
, void *info
)
3774 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3776 if (file_data
->real_names
)
3780 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3782 xfree ((void*) file_data
->real_names
[i
]);
3783 file_data
->real_names
[i
] = NULL
;
3791 dw2_forget_cached_source_info (struct objfile
*objfile
)
3793 struct dwarf2_per_objfile
*dwarf2_per_objfile
3794 = get_dwarf2_per_objfile (objfile
);
3796 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3797 dw2_free_cached_file_names
, NULL
);
3800 /* Helper function for dw2_map_symtabs_matching_filename that expands
3801 the symtabs and calls the iterator. */
3804 dw2_map_expand_apply (struct objfile
*objfile
,
3805 struct dwarf2_per_cu_data
*per_cu
,
3806 const char *name
, const char *real_path
,
3807 gdb::function_view
<bool (symtab
*)> callback
)
3809 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3811 /* Don't visit already-expanded CUs. */
3812 if (per_cu
->v
.quick
->compunit_symtab
)
3815 /* This may expand more than one symtab, and we want to iterate over
3817 dw2_instantiate_symtab (per_cu
, false);
3819 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3820 last_made
, callback
);
3823 /* Implementation of the map_symtabs_matching_filename method. */
3826 dw2_map_symtabs_matching_filename
3827 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3828 gdb::function_view
<bool (symtab
*)> callback
)
3830 const char *name_basename
= lbasename (name
);
3831 struct dwarf2_per_objfile
*dwarf2_per_objfile
3832 = get_dwarf2_per_objfile (objfile
);
3834 /* The rule is CUs specify all the files, including those used by
3835 any TU, so there's no need to scan TUs here. */
3837 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3839 /* We only need to look at symtabs not already expanded. */
3840 if (per_cu
->v
.quick
->compunit_symtab
)
3843 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3844 if (file_data
== NULL
)
3847 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3849 const char *this_name
= file_data
->file_names
[j
];
3850 const char *this_real_name
;
3852 if (compare_filenames_for_search (this_name
, name
))
3854 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3860 /* Before we invoke realpath, which can get expensive when many
3861 files are involved, do a quick comparison of the basenames. */
3862 if (! basenames_may_differ
3863 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3866 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3867 if (compare_filenames_for_search (this_real_name
, name
))
3869 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3875 if (real_path
!= NULL
)
3877 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3878 gdb_assert (IS_ABSOLUTE_PATH (name
));
3879 if (this_real_name
!= NULL
3880 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3882 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3894 /* Struct used to manage iterating over all CUs looking for a symbol. */
3896 struct dw2_symtab_iterator
3898 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3899 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3900 /* If set, only look for symbols that match that block. Valid values are
3901 GLOBAL_BLOCK and STATIC_BLOCK. */
3902 gdb::optional
<block_enum
> block_index
;
3903 /* The kind of symbol we're looking for. */
3905 /* The list of CUs from the index entry of the symbol,
3906 or NULL if not found. */
3908 /* The next element in VEC to look at. */
3910 /* The number of elements in VEC, or zero if there is no match. */
3912 /* Have we seen a global version of the symbol?
3913 If so we can ignore all further global instances.
3914 This is to work around gold/15646, inefficient gold-generated
3919 /* Initialize the index symtab iterator ITER. */
3922 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3923 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3924 gdb::optional
<block_enum
> block_index
,
3928 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3929 iter
->block_index
= block_index
;
3930 iter
->domain
= domain
;
3932 iter
->global_seen
= 0;
3934 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3936 /* index is NULL if OBJF_READNOW. */
3937 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3938 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3946 /* Return the next matching CU or NULL if there are no more. */
3948 static struct dwarf2_per_cu_data
*
3949 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3951 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3953 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3955 offset_type cu_index_and_attrs
=
3956 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3957 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3958 gdb_index_symbol_kind symbol_kind
=
3959 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3960 /* Only check the symbol attributes if they're present.
3961 Indices prior to version 7 don't record them,
3962 and indices >= 7 may elide them for certain symbols
3963 (gold does this). */
3965 (dwarf2_per_objfile
->index_table
->version
>= 7
3966 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
3968 /* Don't crash on bad data. */
3969 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
3970 + dwarf2_per_objfile
->all_type_units
.size ()))
3972 complaint (_(".gdb_index entry has bad CU index"
3974 objfile_name (dwarf2_per_objfile
->objfile
));
3978 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
3980 /* Skip if already read in. */
3981 if (per_cu
->v
.quick
->compunit_symtab
)
3984 /* Check static vs global. */
3987 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
3989 if (iter
->block_index
.has_value ())
3991 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
3993 if (is_static
!= want_static
)
3997 /* Work around gold/15646. */
3998 if (!is_static
&& iter
->global_seen
)
4001 iter
->global_seen
= 1;
4004 /* Only check the symbol's kind if it has one. */
4007 switch (iter
->domain
)
4010 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4011 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4012 /* Some types are also in VAR_DOMAIN. */
4013 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4017 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4021 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4036 static struct compunit_symtab
*
4037 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4038 const char *name
, domain_enum domain
)
4040 struct compunit_symtab
*stab_best
= NULL
;
4041 struct dwarf2_per_objfile
*dwarf2_per_objfile
4042 = get_dwarf2_per_objfile (objfile
);
4044 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4046 struct dw2_symtab_iterator iter
;
4047 struct dwarf2_per_cu_data
*per_cu
;
4049 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4051 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4053 struct symbol
*sym
, *with_opaque
= NULL
;
4054 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4055 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4056 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4058 sym
= block_find_symbol (block
, name
, domain
,
4059 block_find_non_opaque_type_preferred
,
4062 /* Some caution must be observed with overloaded functions
4063 and methods, since the index will not contain any overload
4064 information (but NAME might contain it). */
4067 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4069 if (with_opaque
!= NULL
4070 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4073 /* Keep looking through other CUs. */
4080 dw2_print_stats (struct objfile
*objfile
)
4082 struct dwarf2_per_objfile
*dwarf2_per_objfile
4083 = get_dwarf2_per_objfile (objfile
);
4084 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4085 + dwarf2_per_objfile
->all_type_units
.size ());
4088 for (int i
= 0; i
< total
; ++i
)
4090 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4092 if (!per_cu
->v
.quick
->compunit_symtab
)
4095 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4096 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4099 /* This dumps minimal information about the index.
4100 It is called via "mt print objfiles".
4101 One use is to verify .gdb_index has been loaded by the
4102 gdb.dwarf2/gdb-index.exp testcase. */
4105 dw2_dump (struct objfile
*objfile
)
4107 struct dwarf2_per_objfile
*dwarf2_per_objfile
4108 = get_dwarf2_per_objfile (objfile
);
4110 gdb_assert (dwarf2_per_objfile
->using_index
);
4111 printf_filtered (".gdb_index:");
4112 if (dwarf2_per_objfile
->index_table
!= NULL
)
4114 printf_filtered (" version %d\n",
4115 dwarf2_per_objfile
->index_table
->version
);
4118 printf_filtered (" faked for \"readnow\"\n");
4119 printf_filtered ("\n");
4123 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4124 const char *func_name
)
4126 struct dwarf2_per_objfile
*dwarf2_per_objfile
4127 = get_dwarf2_per_objfile (objfile
);
4129 struct dw2_symtab_iterator iter
;
4130 struct dwarf2_per_cu_data
*per_cu
;
4132 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4134 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4135 dw2_instantiate_symtab (per_cu
, false);
4140 dw2_expand_all_symtabs (struct objfile
*objfile
)
4142 struct dwarf2_per_objfile
*dwarf2_per_objfile
4143 = get_dwarf2_per_objfile (objfile
);
4144 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4145 + dwarf2_per_objfile
->all_type_units
.size ());
4147 for (int i
= 0; i
< total_units
; ++i
)
4149 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4151 /* We don't want to directly expand a partial CU, because if we
4152 read it with the wrong language, then assertion failures can
4153 be triggered later on. See PR symtab/23010. So, tell
4154 dw2_instantiate_symtab to skip partial CUs -- any important
4155 partial CU will be read via DW_TAG_imported_unit anyway. */
4156 dw2_instantiate_symtab (per_cu
, true);
4161 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4162 const char *fullname
)
4164 struct dwarf2_per_objfile
*dwarf2_per_objfile
4165 = get_dwarf2_per_objfile (objfile
);
4167 /* We don't need to consider type units here.
4168 This is only called for examining code, e.g. expand_line_sal.
4169 There can be an order of magnitude (or more) more type units
4170 than comp units, and we avoid them if we can. */
4172 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4174 /* We only need to look at symtabs not already expanded. */
4175 if (per_cu
->v
.quick
->compunit_symtab
)
4178 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4179 if (file_data
== NULL
)
4182 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4184 const char *this_fullname
= file_data
->file_names
[j
];
4186 if (filename_cmp (this_fullname
, fullname
) == 0)
4188 dw2_instantiate_symtab (per_cu
, false);
4196 dw2_map_matching_symbols
4197 (struct objfile
*objfile
,
4198 const lookup_name_info
&name
, domain_enum domain
,
4200 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4201 symbol_compare_ftype
*ordered_compare
)
4203 /* Currently unimplemented; used for Ada. The function can be called if the
4204 current language is Ada for a non-Ada objfile using GNU index. As Ada
4205 does not look for non-Ada symbols this function should just return. */
4208 /* Starting from a search name, return the string that finds the upper
4209 bound of all strings that start with SEARCH_NAME in a sorted name
4210 list. Returns the empty string to indicate that the upper bound is
4211 the end of the list. */
4214 make_sort_after_prefix_name (const char *search_name
)
4216 /* When looking to complete "func", we find the upper bound of all
4217 symbols that start with "func" by looking for where we'd insert
4218 the closest string that would follow "func" in lexicographical
4219 order. Usually, that's "func"-with-last-character-incremented,
4220 i.e. "fund". Mind non-ASCII characters, though. Usually those
4221 will be UTF-8 multi-byte sequences, but we can't be certain.
4222 Especially mind the 0xff character, which is a valid character in
4223 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4224 rule out compilers allowing it in identifiers. Note that
4225 conveniently, strcmp/strcasecmp are specified to compare
4226 characters interpreted as unsigned char. So what we do is treat
4227 the whole string as a base 256 number composed of a sequence of
4228 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4229 to 0, and carries 1 to the following more-significant position.
4230 If the very first character in SEARCH_NAME ends up incremented
4231 and carries/overflows, then the upper bound is the end of the
4232 list. The string after the empty string is also the empty
4235 Some examples of this operation:
4237 SEARCH_NAME => "+1" RESULT
4241 "\xff" "a" "\xff" => "\xff" "b"
4246 Then, with these symbols for example:
4252 completing "func" looks for symbols between "func" and
4253 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4254 which finds "func" and "func1", but not "fund".
4258 funcÿ (Latin1 'ÿ' [0xff])
4262 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4263 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4267 ÿÿ (Latin1 'ÿ' [0xff])
4270 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4271 the end of the list.
4273 std::string after
= search_name
;
4274 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4276 if (!after
.empty ())
4277 after
.back () = (unsigned char) after
.back () + 1;
4281 /* See declaration. */
4283 std::pair
<std::vector
<name_component
>::const_iterator
,
4284 std::vector
<name_component
>::const_iterator
>
4285 mapped_index_base::find_name_components_bounds
4286 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4289 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4291 const char *lang_name
4292 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4294 /* Comparison function object for lower_bound that matches against a
4295 given symbol name. */
4296 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4299 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4300 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4301 return name_cmp (elem_name
, name
) < 0;
4304 /* Comparison function object for upper_bound that matches against a
4305 given symbol name. */
4306 auto lookup_compare_upper
= [&] (const char *name
,
4307 const name_component
&elem
)
4309 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4310 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4311 return name_cmp (name
, elem_name
) < 0;
4314 auto begin
= this->name_components
.begin ();
4315 auto end
= this->name_components
.end ();
4317 /* Find the lower bound. */
4320 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4323 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4326 /* Find the upper bound. */
4329 if (lookup_name_without_params
.completion_mode ())
4331 /* In completion mode, we want UPPER to point past all
4332 symbols names that have the same prefix. I.e., with
4333 these symbols, and completing "func":
4335 function << lower bound
4337 other_function << upper bound
4339 We find the upper bound by looking for the insertion
4340 point of "func"-with-last-character-incremented,
4342 std::string after
= make_sort_after_prefix_name (lang_name
);
4345 return std::lower_bound (lower
, end
, after
.c_str (),
4346 lookup_compare_lower
);
4349 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4352 return {lower
, upper
};
4355 /* See declaration. */
4358 mapped_index_base::build_name_components ()
4360 if (!this->name_components
.empty ())
4363 this->name_components_casing
= case_sensitivity
;
4365 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4367 /* The code below only knows how to break apart components of C++
4368 symbol names (and other languages that use '::' as
4369 namespace/module separator) and Ada symbol names. */
4370 auto count
= this->symbol_name_count ();
4371 for (offset_type idx
= 0; idx
< count
; idx
++)
4373 if (this->symbol_name_slot_invalid (idx
))
4376 const char *name
= this->symbol_name_at (idx
);
4378 /* Add each name component to the name component table. */
4379 unsigned int previous_len
= 0;
4381 if (strstr (name
, "::") != nullptr)
4383 for (unsigned int current_len
= cp_find_first_component (name
);
4384 name
[current_len
] != '\0';
4385 current_len
+= cp_find_first_component (name
+ current_len
))
4387 gdb_assert (name
[current_len
] == ':');
4388 this->name_components
.push_back ({previous_len
, idx
});
4389 /* Skip the '::'. */
4391 previous_len
= current_len
;
4396 /* Handle the Ada encoded (aka mangled) form here. */
4397 for (const char *iter
= strstr (name
, "__");
4399 iter
= strstr (iter
, "__"))
4401 this->name_components
.push_back ({previous_len
, idx
});
4403 previous_len
= iter
- name
;
4407 this->name_components
.push_back ({previous_len
, idx
});
4410 /* Sort name_components elements by name. */
4411 auto name_comp_compare
= [&] (const name_component
&left
,
4412 const name_component
&right
)
4414 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4415 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4417 const char *left_name
= left_qualified
+ left
.name_offset
;
4418 const char *right_name
= right_qualified
+ right
.name_offset
;
4420 return name_cmp (left_name
, right_name
) < 0;
4423 std::sort (this->name_components
.begin (),
4424 this->name_components
.end (),
4428 /* Helper for dw2_expand_symtabs_matching that works with a
4429 mapped_index_base instead of the containing objfile. This is split
4430 to a separate function in order to be able to unit test the
4431 name_components matching using a mock mapped_index_base. For each
4432 symbol name that matches, calls MATCH_CALLBACK, passing it the
4433 symbol's index in the mapped_index_base symbol table. */
4436 dw2_expand_symtabs_matching_symbol
4437 (mapped_index_base
&index
,
4438 const lookup_name_info
&lookup_name_in
,
4439 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4440 enum search_domain kind
,
4441 gdb::function_view
<bool (offset_type
)> match_callback
)
4443 lookup_name_info lookup_name_without_params
4444 = lookup_name_in
.make_ignore_params ();
4446 /* Build the symbol name component sorted vector, if we haven't
4448 index
.build_name_components ();
4450 /* The same symbol may appear more than once in the range though.
4451 E.g., if we're looking for symbols that complete "w", and we have
4452 a symbol named "w1::w2", we'll find the two name components for
4453 that same symbol in the range. To be sure we only call the
4454 callback once per symbol, we first collect the symbol name
4455 indexes that matched in a temporary vector and ignore
4457 std::vector
<offset_type
> matches
;
4459 struct name_and_matcher
4461 symbol_name_matcher_ftype
*matcher
;
4462 const std::string
&name
;
4464 bool operator== (const name_and_matcher
&other
) const
4466 return matcher
== other
.matcher
&& name
== other
.name
;
4470 /* A vector holding all the different symbol name matchers, for all
4472 std::vector
<name_and_matcher
> matchers
;
4474 for (int i
= 0; i
< nr_languages
; i
++)
4476 enum language lang_e
= (enum language
) i
;
4478 const language_defn
*lang
= language_def (lang_e
);
4479 symbol_name_matcher_ftype
*name_matcher
4480 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4482 name_and_matcher key
{
4484 lookup_name_without_params
.language_lookup_name (lang_e
)
4487 /* Don't insert the same comparison routine more than once.
4488 Note that we do this linear walk. This is not a problem in
4489 practice because the number of supported languages is
4491 if (std::find (matchers
.begin (), matchers
.end (), key
)
4494 matchers
.push_back (std::move (key
));
4497 = index
.find_name_components_bounds (lookup_name_without_params
,
4500 /* Now for each symbol name in range, check to see if we have a name
4501 match, and if so, call the MATCH_CALLBACK callback. */
4503 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4505 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4507 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4508 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4511 matches
.push_back (bounds
.first
->idx
);
4515 std::sort (matches
.begin (), matches
.end ());
4517 /* Finally call the callback, once per match. */
4519 for (offset_type idx
: matches
)
4523 if (!match_callback (idx
))
4529 /* Above we use a type wider than idx's for 'prev', since 0 and
4530 (offset_type)-1 are both possible values. */
4531 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4536 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4538 /* A mock .gdb_index/.debug_names-like name index table, enough to
4539 exercise dw2_expand_symtabs_matching_symbol, which works with the
4540 mapped_index_base interface. Builds an index from the symbol list
4541 passed as parameter to the constructor. */
4542 class mock_mapped_index
: public mapped_index_base
4545 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4546 : m_symbol_table (symbols
)
4549 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4551 /* Return the number of names in the symbol table. */
4552 size_t symbol_name_count () const override
4554 return m_symbol_table
.size ();
4557 /* Get the name of the symbol at IDX in the symbol table. */
4558 const char *symbol_name_at (offset_type idx
) const override
4560 return m_symbol_table
[idx
];
4564 gdb::array_view
<const char *> m_symbol_table
;
4567 /* Convenience function that converts a NULL pointer to a "<null>"
4568 string, to pass to print routines. */
4571 string_or_null (const char *str
)
4573 return str
!= NULL
? str
: "<null>";
4576 /* Check if a lookup_name_info built from
4577 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4578 index. EXPECTED_LIST is the list of expected matches, in expected
4579 matching order. If no match expected, then an empty list is
4580 specified. Returns true on success. On failure prints a warning
4581 indicating the file:line that failed, and returns false. */
4584 check_match (const char *file
, int line
,
4585 mock_mapped_index
&mock_index
,
4586 const char *name
, symbol_name_match_type match_type
,
4587 bool completion_mode
,
4588 std::initializer_list
<const char *> expected_list
)
4590 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4592 bool matched
= true;
4594 auto mismatch
= [&] (const char *expected_str
,
4597 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4598 "expected=\"%s\", got=\"%s\"\n"),
4600 (match_type
== symbol_name_match_type::FULL
4602 name
, string_or_null (expected_str
), string_or_null (got
));
4606 auto expected_it
= expected_list
.begin ();
4607 auto expected_end
= expected_list
.end ();
4609 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4611 [&] (offset_type idx
)
4613 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4614 const char *expected_str
4615 = expected_it
== expected_end
? NULL
: *expected_it
++;
4617 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4618 mismatch (expected_str
, matched_name
);
4622 const char *expected_str
4623 = expected_it
== expected_end
? NULL
: *expected_it
++;
4624 if (expected_str
!= NULL
)
4625 mismatch (expected_str
, NULL
);
4630 /* The symbols added to the mock mapped_index for testing (in
4632 static const char *test_symbols
[] = {
4641 "ns2::tmpl<int>::foo2",
4642 "(anonymous namespace)::A::B::C",
4644 /* These are used to check that the increment-last-char in the
4645 matching algorithm for completion doesn't match "t1_fund" when
4646 completing "t1_func". */
4652 /* A UTF-8 name with multi-byte sequences to make sure that
4653 cp-name-parser understands this as a single identifier ("função"
4654 is "function" in PT). */
4657 /* \377 (0xff) is Latin1 'ÿ'. */
4660 /* \377 (0xff) is Latin1 'ÿ'. */
4664 /* A name with all sorts of complications. Starts with "z" to make
4665 it easier for the completion tests below. */
4666 #define Z_SYM_NAME \
4667 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4668 "::tuple<(anonymous namespace)::ui*, " \
4669 "std::default_delete<(anonymous namespace)::ui>, void>"
4674 /* Returns true if the mapped_index_base::find_name_component_bounds
4675 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4676 in completion mode. */
4679 check_find_bounds_finds (mapped_index_base
&index
,
4680 const char *search_name
,
4681 gdb::array_view
<const char *> expected_syms
)
4683 lookup_name_info
lookup_name (search_name
,
4684 symbol_name_match_type::FULL
, true);
4686 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4689 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4690 if (distance
!= expected_syms
.size ())
4693 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4695 auto nc_elem
= bounds
.first
+ exp_elem
;
4696 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4697 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4704 /* Test the lower-level mapped_index::find_name_component_bounds
4708 test_mapped_index_find_name_component_bounds ()
4710 mock_mapped_index
mock_index (test_symbols
);
4712 mock_index
.build_name_components ();
4714 /* Test the lower-level mapped_index::find_name_component_bounds
4715 method in completion mode. */
4717 static const char *expected_syms
[] = {
4722 SELF_CHECK (check_find_bounds_finds (mock_index
,
4723 "t1_func", expected_syms
));
4726 /* Check that the increment-last-char in the name matching algorithm
4727 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4729 static const char *expected_syms1
[] = {
4733 SELF_CHECK (check_find_bounds_finds (mock_index
,
4734 "\377", expected_syms1
));
4736 static const char *expected_syms2
[] = {
4739 SELF_CHECK (check_find_bounds_finds (mock_index
,
4740 "\377\377", expected_syms2
));
4744 /* Test dw2_expand_symtabs_matching_symbol. */
4747 test_dw2_expand_symtabs_matching_symbol ()
4749 mock_mapped_index
mock_index (test_symbols
);
4751 /* We let all tests run until the end even if some fails, for debug
4753 bool any_mismatch
= false;
4755 /* Create the expected symbols list (an initializer_list). Needed
4756 because lists have commas, and we need to pass them to CHECK,
4757 which is a macro. */
4758 #define EXPECT(...) { __VA_ARGS__ }
4760 /* Wrapper for check_match that passes down the current
4761 __FILE__/__LINE__. */
4762 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4763 any_mismatch |= !check_match (__FILE__, __LINE__, \
4765 NAME, MATCH_TYPE, COMPLETION_MODE, \
4768 /* Identity checks. */
4769 for (const char *sym
: test_symbols
)
4771 /* Should be able to match all existing symbols. */
4772 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4775 /* Should be able to match all existing symbols with
4777 std::string with_params
= std::string (sym
) + "(int)";
4778 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4781 /* Should be able to match all existing symbols with
4782 parameters and qualifiers. */
4783 with_params
= std::string (sym
) + " ( int ) const";
4784 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4787 /* This should really find sym, but cp-name-parser.y doesn't
4788 know about lvalue/rvalue qualifiers yet. */
4789 with_params
= std::string (sym
) + " ( int ) &&";
4790 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4794 /* Check that the name matching algorithm for completion doesn't get
4795 confused with Latin1 'ÿ' / 0xff. */
4797 static const char str
[] = "\377";
4798 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4799 EXPECT ("\377", "\377\377123"));
4802 /* Check that the increment-last-char in the matching algorithm for
4803 completion doesn't match "t1_fund" when completing "t1_func". */
4805 static const char str
[] = "t1_func";
4806 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4807 EXPECT ("t1_func", "t1_func1"));
4810 /* Check that completion mode works at each prefix of the expected
4813 static const char str
[] = "function(int)";
4814 size_t len
= strlen (str
);
4817 for (size_t i
= 1; i
< len
; i
++)
4819 lookup
.assign (str
, i
);
4820 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4821 EXPECT ("function"));
4825 /* While "w" is a prefix of both components, the match function
4826 should still only be called once. */
4828 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4830 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4834 /* Same, with a "complicated" symbol. */
4836 static const char str
[] = Z_SYM_NAME
;
4837 size_t len
= strlen (str
);
4840 for (size_t i
= 1; i
< len
; i
++)
4842 lookup
.assign (str
, i
);
4843 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4844 EXPECT (Z_SYM_NAME
));
4848 /* In FULL mode, an incomplete symbol doesn't match. */
4850 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4854 /* A complete symbol with parameters matches any overload, since the
4855 index has no overload info. */
4857 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4858 EXPECT ("std::zfunction", "std::zfunction2"));
4859 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4860 EXPECT ("std::zfunction", "std::zfunction2"));
4861 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4862 EXPECT ("std::zfunction", "std::zfunction2"));
4865 /* Check that whitespace is ignored appropriately. A symbol with a
4866 template argument list. */
4868 static const char expected
[] = "ns::foo<int>";
4869 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4871 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4875 /* Check that whitespace is ignored appropriately. A symbol with a
4876 template argument list that includes a pointer. */
4878 static const char expected
[] = "ns::foo<char*>";
4879 /* Try both completion and non-completion modes. */
4880 static const bool completion_mode
[2] = {false, true};
4881 for (size_t i
= 0; i
< 2; i
++)
4883 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4884 completion_mode
[i
], EXPECT (expected
));
4885 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4886 completion_mode
[i
], EXPECT (expected
));
4888 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4889 completion_mode
[i
], EXPECT (expected
));
4890 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4891 completion_mode
[i
], EXPECT (expected
));
4896 /* Check method qualifiers are ignored. */
4897 static const char expected
[] = "ns::foo<char*>";
4898 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4899 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4900 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4901 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4902 CHECK_MATCH ("foo < char * > ( int ) const",
4903 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4904 CHECK_MATCH ("foo < char * > ( int ) &&",
4905 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4908 /* Test lookup names that don't match anything. */
4910 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4913 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4917 /* Some wild matching tests, exercising "(anonymous namespace)",
4918 which should not be confused with a parameter list. */
4920 static const char *syms
[] = {
4924 "A :: B :: C ( int )",
4929 for (const char *s
: syms
)
4931 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4932 EXPECT ("(anonymous namespace)::A::B::C"));
4937 static const char expected
[] = "ns2::tmpl<int>::foo2";
4938 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4940 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4944 SELF_CHECK (!any_mismatch
);
4953 test_mapped_index_find_name_component_bounds ();
4954 test_dw2_expand_symtabs_matching_symbol ();
4957 }} // namespace selftests::dw2_expand_symtabs_matching
4959 #endif /* GDB_SELF_TEST */
4961 /* If FILE_MATCHER is NULL or if PER_CU has
4962 dwarf2_per_cu_quick_data::MARK set (see
4963 dw_expand_symtabs_matching_file_matcher), expand the CU and call
4964 EXPANSION_NOTIFY on it. */
4967 dw2_expand_symtabs_matching_one
4968 (struct dwarf2_per_cu_data
*per_cu
,
4969 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4970 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
4972 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
4974 bool symtab_was_null
4975 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
4977 dw2_instantiate_symtab (per_cu
, false);
4979 if (expansion_notify
!= NULL
4981 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
4982 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
4986 /* Helper for dw2_expand_matching symtabs. Called on each symbol
4987 matched, to expand corresponding CUs that were marked. IDX is the
4988 index of the symbol name that matched. */
4991 dw2_expand_marked_cus
4992 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
4993 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
4994 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
4997 offset_type
*vec
, vec_len
, vec_idx
;
4998 bool global_seen
= false;
4999 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5001 vec
= (offset_type
*) (index
.constant_pool
5002 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5003 vec_len
= MAYBE_SWAP (vec
[0]);
5004 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5006 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5007 /* This value is only valid for index versions >= 7. */
5008 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5009 gdb_index_symbol_kind symbol_kind
=
5010 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5011 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5012 /* Only check the symbol attributes if they're present.
5013 Indices prior to version 7 don't record them,
5014 and indices >= 7 may elide them for certain symbols
5015 (gold does this). */
5018 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5020 /* Work around gold/15646. */
5023 if (!is_static
&& global_seen
)
5029 /* Only check the symbol's kind if it has one. */
5034 case VARIABLES_DOMAIN
:
5035 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5038 case FUNCTIONS_DOMAIN
:
5039 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5043 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5051 /* Don't crash on bad data. */
5052 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5053 + dwarf2_per_objfile
->all_type_units
.size ()))
5055 complaint (_(".gdb_index entry has bad CU index"
5057 objfile_name (dwarf2_per_objfile
->objfile
));
5061 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5062 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5067 /* If FILE_MATCHER is non-NULL, set all the
5068 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5069 that match FILE_MATCHER. */
5072 dw_expand_symtabs_matching_file_matcher
5073 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5074 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5076 if (file_matcher
== NULL
)
5079 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5081 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5083 NULL
, xcalloc
, xfree
));
5084 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5086 NULL
, xcalloc
, xfree
));
5088 /* The rule is CUs specify all the files, including those used by
5089 any TU, so there's no need to scan TUs here. */
5091 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5095 per_cu
->v
.quick
->mark
= 0;
5097 /* We only need to look at symtabs not already expanded. */
5098 if (per_cu
->v
.quick
->compunit_symtab
)
5101 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5102 if (file_data
== NULL
)
5105 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5107 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5109 per_cu
->v
.quick
->mark
= 1;
5113 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5115 const char *this_real_name
;
5117 if (file_matcher (file_data
->file_names
[j
], false))
5119 per_cu
->v
.quick
->mark
= 1;
5123 /* Before we invoke realpath, which can get expensive when many
5124 files are involved, do a quick comparison of the basenames. */
5125 if (!basenames_may_differ
5126 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5130 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5131 if (file_matcher (this_real_name
, false))
5133 per_cu
->v
.quick
->mark
= 1;
5138 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5139 ? visited_found
.get ()
5140 : visited_not_found
.get (),
5147 dw2_expand_symtabs_matching
5148 (struct objfile
*objfile
,
5149 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5150 const lookup_name_info
&lookup_name
,
5151 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5152 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5153 enum search_domain kind
)
5155 struct dwarf2_per_objfile
*dwarf2_per_objfile
5156 = get_dwarf2_per_objfile (objfile
);
5158 /* index_table is NULL if OBJF_READNOW. */
5159 if (!dwarf2_per_objfile
->index_table
)
5162 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5164 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5166 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5168 kind
, [&] (offset_type idx
)
5170 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5171 expansion_notify
, kind
);
5176 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5179 static struct compunit_symtab
*
5180 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5185 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5186 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5189 if (cust
->includes
== NULL
)
5192 for (i
= 0; cust
->includes
[i
]; ++i
)
5194 struct compunit_symtab
*s
= cust
->includes
[i
];
5196 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5204 static struct compunit_symtab
*
5205 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5206 struct bound_minimal_symbol msymbol
,
5208 struct obj_section
*section
,
5211 struct dwarf2_per_cu_data
*data
;
5212 struct compunit_symtab
*result
;
5214 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5217 CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
5218 SECT_OFF_TEXT (objfile
));
5219 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5220 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5224 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5225 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5226 paddress (get_objfile_arch (objfile
), pc
));
5229 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5232 gdb_assert (result
!= NULL
);
5237 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5238 void *data
, int need_fullname
)
5240 struct dwarf2_per_objfile
*dwarf2_per_objfile
5241 = get_dwarf2_per_objfile (objfile
);
5243 if (!dwarf2_per_objfile
->filenames_cache
)
5245 dwarf2_per_objfile
->filenames_cache
.emplace ();
5247 htab_up
visited (htab_create_alloc (10,
5248 htab_hash_pointer
, htab_eq_pointer
,
5249 NULL
, xcalloc
, xfree
));
5251 /* The rule is CUs specify all the files, including those used
5252 by any TU, so there's no need to scan TUs here. We can
5253 ignore file names coming from already-expanded CUs. */
5255 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5257 if (per_cu
->v
.quick
->compunit_symtab
)
5259 void **slot
= htab_find_slot (visited
.get (),
5260 per_cu
->v
.quick
->file_names
,
5263 *slot
= per_cu
->v
.quick
->file_names
;
5267 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5269 /* We only need to look at symtabs not already expanded. */
5270 if (per_cu
->v
.quick
->compunit_symtab
)
5273 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5274 if (file_data
== NULL
)
5277 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5280 /* Already visited. */
5285 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5287 const char *filename
= file_data
->file_names
[j
];
5288 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5293 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5295 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5298 this_real_name
= gdb_realpath (filename
);
5299 (*fun
) (filename
, this_real_name
.get (), data
);
5304 dw2_has_symbols (struct objfile
*objfile
)
5309 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5312 dw2_find_last_source_symtab
,
5313 dw2_forget_cached_source_info
,
5314 dw2_map_symtabs_matching_filename
,
5318 dw2_expand_symtabs_for_function
,
5319 dw2_expand_all_symtabs
,
5320 dw2_expand_symtabs_with_fullname
,
5321 dw2_map_matching_symbols
,
5322 dw2_expand_symtabs_matching
,
5323 dw2_find_pc_sect_compunit_symtab
,
5325 dw2_map_symbol_filenames
5328 /* DWARF-5 debug_names reader. */
5330 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5331 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5333 /* A helper function that reads the .debug_names section in SECTION
5334 and fills in MAP. FILENAME is the name of the file containing the
5335 section; it is used for error reporting.
5337 Returns true if all went well, false otherwise. */
5340 read_debug_names_from_section (struct objfile
*objfile
,
5341 const char *filename
,
5342 struct dwarf2_section_info
*section
,
5343 mapped_debug_names
&map
)
5345 if (dwarf2_section_empty_p (section
))
5348 /* Older elfutils strip versions could keep the section in the main
5349 executable while splitting it for the separate debug info file. */
5350 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5353 dwarf2_read_section (objfile
, section
);
5355 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5357 const gdb_byte
*addr
= section
->buffer
;
5359 bfd
*const abfd
= get_section_bfd_owner (section
);
5361 unsigned int bytes_read
;
5362 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5365 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5366 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5367 if (bytes_read
+ length
!= section
->size
)
5369 /* There may be multiple per-CU indices. */
5370 warning (_("Section .debug_names in %s length %s does not match "
5371 "section length %s, ignoring .debug_names."),
5372 filename
, plongest (bytes_read
+ length
),
5373 pulongest (section
->size
));
5377 /* The version number. */
5378 uint16_t version
= read_2_bytes (abfd
, addr
);
5382 warning (_("Section .debug_names in %s has unsupported version %d, "
5383 "ignoring .debug_names."),
5389 uint16_t padding
= read_2_bytes (abfd
, addr
);
5393 warning (_("Section .debug_names in %s has unsupported padding %d, "
5394 "ignoring .debug_names."),
5399 /* comp_unit_count - The number of CUs in the CU list. */
5400 map
.cu_count
= read_4_bytes (abfd
, addr
);
5403 /* local_type_unit_count - The number of TUs in the local TU
5405 map
.tu_count
= read_4_bytes (abfd
, addr
);
5408 /* foreign_type_unit_count - The number of TUs in the foreign TU
5410 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5412 if (foreign_tu_count
!= 0)
5414 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5415 "ignoring .debug_names."),
5416 filename
, static_cast<unsigned long> (foreign_tu_count
));
5420 /* bucket_count - The number of hash buckets in the hash lookup
5422 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5425 /* name_count - The number of unique names in the index. */
5426 map
.name_count
= read_4_bytes (abfd
, addr
);
5429 /* abbrev_table_size - The size in bytes of the abbreviations
5431 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5434 /* augmentation_string_size - The size in bytes of the augmentation
5435 string. This value is rounded up to a multiple of 4. */
5436 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5438 map
.augmentation_is_gdb
= ((augmentation_string_size
5439 == sizeof (dwarf5_augmentation
))
5440 && memcmp (addr
, dwarf5_augmentation
,
5441 sizeof (dwarf5_augmentation
)) == 0);
5442 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5443 addr
+= augmentation_string_size
;
5446 map
.cu_table_reordered
= addr
;
5447 addr
+= map
.cu_count
* map
.offset_size
;
5449 /* List of Local TUs */
5450 map
.tu_table_reordered
= addr
;
5451 addr
+= map
.tu_count
* map
.offset_size
;
5453 /* Hash Lookup Table */
5454 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5455 addr
+= map
.bucket_count
* 4;
5456 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5457 addr
+= map
.name_count
* 4;
5460 map
.name_table_string_offs_reordered
= addr
;
5461 addr
+= map
.name_count
* map
.offset_size
;
5462 map
.name_table_entry_offs_reordered
= addr
;
5463 addr
+= map
.name_count
* map
.offset_size
;
5465 const gdb_byte
*abbrev_table_start
= addr
;
5468 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5473 const auto insertpair
5474 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5475 if (!insertpair
.second
)
5477 warning (_("Section .debug_names in %s has duplicate index %s, "
5478 "ignoring .debug_names."),
5479 filename
, pulongest (index_num
));
5482 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5483 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5488 mapped_debug_names::index_val::attr attr
;
5489 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5491 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5493 if (attr
.form
== DW_FORM_implicit_const
)
5495 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5499 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5501 indexval
.attr_vec
.push_back (std::move (attr
));
5504 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5506 warning (_("Section .debug_names in %s has abbreviation_table "
5507 "of size %s vs. written as %u, ignoring .debug_names."),
5508 filename
, plongest (addr
- abbrev_table_start
),
5512 map
.entry_pool
= addr
;
5517 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5521 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5522 const mapped_debug_names
&map
,
5523 dwarf2_section_info
§ion
,
5526 sect_offset sect_off_prev
;
5527 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5529 sect_offset sect_off_next
;
5530 if (i
< map
.cu_count
)
5533 = (sect_offset
) (extract_unsigned_integer
5534 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5536 map
.dwarf5_byte_order
));
5539 sect_off_next
= (sect_offset
) section
.size
;
5542 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5543 dwarf2_per_cu_data
*per_cu
5544 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5545 sect_off_prev
, length
);
5546 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5548 sect_off_prev
= sect_off_next
;
5552 /* Read the CU list from the mapped index, and use it to create all
5553 the CU objects for this dwarf2_per_objfile. */
5556 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5557 const mapped_debug_names
&map
,
5558 const mapped_debug_names
&dwz_map
)
5560 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5561 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5563 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5564 dwarf2_per_objfile
->info
,
5565 false /* is_dwz */);
5567 if (dwz_map
.cu_count
== 0)
5570 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5571 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5575 /* Read .debug_names. If everything went ok, initialize the "quick"
5576 elements of all the CUs and return true. Otherwise, return false. */
5579 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5581 std::unique_ptr
<mapped_debug_names
> map
5582 (new mapped_debug_names (dwarf2_per_objfile
));
5583 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5584 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5586 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5587 &dwarf2_per_objfile
->debug_names
,
5591 /* Don't use the index if it's empty. */
5592 if (map
->name_count
== 0)
5595 /* If there is a .dwz file, read it so we can get its CU list as
5597 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5600 if (!read_debug_names_from_section (objfile
,
5601 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5602 &dwz
->debug_names
, dwz_map
))
5604 warning (_("could not read '.debug_names' section from %s; skipping"),
5605 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5610 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5612 if (map
->tu_count
!= 0)
5614 /* We can only handle a single .debug_types when we have an
5616 if (dwarf2_per_objfile
->types
.size () != 1)
5619 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5621 create_signatured_type_table_from_debug_names
5622 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5625 create_addrmap_from_aranges (dwarf2_per_objfile
,
5626 &dwarf2_per_objfile
->debug_aranges
);
5628 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5629 dwarf2_per_objfile
->using_index
= 1;
5630 dwarf2_per_objfile
->quick_file_names_table
=
5631 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5636 /* Type used to manage iterating over all CUs looking for a symbol for
5639 class dw2_debug_names_iterator
5642 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5643 gdb::optional
<block_enum
> block_index
,
5646 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5647 m_addr (find_vec_in_debug_names (map
, name
))
5650 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5651 search_domain search
, uint32_t namei
)
5654 m_addr (find_vec_in_debug_names (map
, namei
))
5657 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5658 block_enum block_index
, domain_enum domain
,
5660 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5661 m_addr (find_vec_in_debug_names (map
, namei
))
5664 /* Return the next matching CU or NULL if there are no more. */
5665 dwarf2_per_cu_data
*next ();
5668 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5670 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5673 /* The internalized form of .debug_names. */
5674 const mapped_debug_names
&m_map
;
5676 /* If set, only look for symbols that match that block. Valid values are
5677 GLOBAL_BLOCK and STATIC_BLOCK. */
5678 const gdb::optional
<block_enum
> m_block_index
;
5680 /* The kind of symbol we're looking for. */
5681 const domain_enum m_domain
= UNDEF_DOMAIN
;
5682 const search_domain m_search
= ALL_DOMAIN
;
5684 /* The list of CUs from the index entry of the symbol, or NULL if
5686 const gdb_byte
*m_addr
;
5690 mapped_debug_names::namei_to_name (uint32_t namei
) const
5692 const ULONGEST namei_string_offs
5693 = extract_unsigned_integer ((name_table_string_offs_reordered
5694 + namei
* offset_size
),
5697 return read_indirect_string_at_offset
5698 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5701 /* Find a slot in .debug_names for the object named NAME. If NAME is
5702 found, return pointer to its pool data. If NAME cannot be found,
5706 dw2_debug_names_iterator::find_vec_in_debug_names
5707 (const mapped_debug_names
&map
, const char *name
)
5709 int (*cmp
) (const char *, const char *);
5711 gdb::unique_xmalloc_ptr
<char> without_params
;
5712 if (current_language
->la_language
== language_cplus
5713 || current_language
->la_language
== language_fortran
5714 || current_language
->la_language
== language_d
)
5716 /* NAME is already canonical. Drop any qualifiers as
5717 .debug_names does not contain any. */
5719 if (strchr (name
, '(') != NULL
)
5721 without_params
= cp_remove_params (name
);
5722 if (without_params
!= NULL
)
5723 name
= without_params
.get ();
5727 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5729 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5731 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5732 (map
.bucket_table_reordered
5733 + (full_hash
% map
.bucket_count
)), 4,
5734 map
.dwarf5_byte_order
);
5738 if (namei
>= map
.name_count
)
5740 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5742 namei
, map
.name_count
,
5743 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5749 const uint32_t namei_full_hash
5750 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5751 (map
.hash_table_reordered
+ namei
), 4,
5752 map
.dwarf5_byte_order
);
5753 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5756 if (full_hash
== namei_full_hash
)
5758 const char *const namei_string
= map
.namei_to_name (namei
);
5760 #if 0 /* An expensive sanity check. */
5761 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5763 complaint (_("Wrong .debug_names hash for string at index %u "
5765 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5770 if (cmp (namei_string
, name
) == 0)
5772 const ULONGEST namei_entry_offs
5773 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5774 + namei
* map
.offset_size
),
5775 map
.offset_size
, map
.dwarf5_byte_order
);
5776 return map
.entry_pool
+ namei_entry_offs
;
5781 if (namei
>= map
.name_count
)
5787 dw2_debug_names_iterator::find_vec_in_debug_names
5788 (const mapped_debug_names
&map
, uint32_t namei
)
5790 if (namei
>= map
.name_count
)
5792 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5794 namei
, map
.name_count
,
5795 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5799 const ULONGEST namei_entry_offs
5800 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5801 + namei
* map
.offset_size
),
5802 map
.offset_size
, map
.dwarf5_byte_order
);
5803 return map
.entry_pool
+ namei_entry_offs
;
5806 /* See dw2_debug_names_iterator. */
5808 dwarf2_per_cu_data
*
5809 dw2_debug_names_iterator::next ()
5814 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5815 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5816 bfd
*const abfd
= objfile
->obfd
;
5820 unsigned int bytes_read
;
5821 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5822 m_addr
+= bytes_read
;
5826 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5827 if (indexval_it
== m_map
.abbrev_map
.cend ())
5829 complaint (_("Wrong .debug_names undefined abbrev code %s "
5831 pulongest (abbrev
), objfile_name (objfile
));
5834 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5835 enum class symbol_linkage
{
5839 } symbol_linkage_
= symbol_linkage::unknown
;
5840 dwarf2_per_cu_data
*per_cu
= NULL
;
5841 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5846 case DW_FORM_implicit_const
:
5847 ull
= attr
.implicit_const
;
5849 case DW_FORM_flag_present
:
5853 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5854 m_addr
+= bytes_read
;
5857 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5858 dwarf_form_name (attr
.form
),
5859 objfile_name (objfile
));
5862 switch (attr
.dw_idx
)
5864 case DW_IDX_compile_unit
:
5865 /* Don't crash on bad data. */
5866 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5868 complaint (_(".debug_names entry has bad CU index %s"
5871 objfile_name (dwarf2_per_objfile
->objfile
));
5874 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5876 case DW_IDX_type_unit
:
5877 /* Don't crash on bad data. */
5878 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5880 complaint (_(".debug_names entry has bad TU index %s"
5883 objfile_name (dwarf2_per_objfile
->objfile
));
5886 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5888 case DW_IDX_GNU_internal
:
5889 if (!m_map
.augmentation_is_gdb
)
5891 symbol_linkage_
= symbol_linkage::static_
;
5893 case DW_IDX_GNU_external
:
5894 if (!m_map
.augmentation_is_gdb
)
5896 symbol_linkage_
= symbol_linkage::extern_
;
5901 /* Skip if already read in. */
5902 if (per_cu
->v
.quick
->compunit_symtab
)
5905 /* Check static vs global. */
5906 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5908 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5909 const bool symbol_is_static
=
5910 symbol_linkage_
== symbol_linkage::static_
;
5911 if (want_static
!= symbol_is_static
)
5915 /* Match dw2_symtab_iter_next, symbol_kind
5916 and debug_names::psymbol_tag. */
5920 switch (indexval
.dwarf_tag
)
5922 case DW_TAG_variable
:
5923 case DW_TAG_subprogram
:
5924 /* Some types are also in VAR_DOMAIN. */
5925 case DW_TAG_typedef
:
5926 case DW_TAG_structure_type
:
5933 switch (indexval
.dwarf_tag
)
5935 case DW_TAG_typedef
:
5936 case DW_TAG_structure_type
:
5943 switch (indexval
.dwarf_tag
)
5946 case DW_TAG_variable
:
5956 /* Match dw2_expand_symtabs_matching, symbol_kind and
5957 debug_names::psymbol_tag. */
5960 case VARIABLES_DOMAIN
:
5961 switch (indexval
.dwarf_tag
)
5963 case DW_TAG_variable
:
5969 case FUNCTIONS_DOMAIN
:
5970 switch (indexval
.dwarf_tag
)
5972 case DW_TAG_subprogram
:
5979 switch (indexval
.dwarf_tag
)
5981 case DW_TAG_typedef
:
5982 case DW_TAG_structure_type
:
5995 static struct compunit_symtab
*
5996 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
5997 const char *name
, domain_enum domain
)
5999 struct dwarf2_per_objfile
*dwarf2_per_objfile
6000 = get_dwarf2_per_objfile (objfile
);
6002 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6005 /* index is NULL if OBJF_READNOW. */
6008 const auto &map
= *mapp
;
6010 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6012 struct compunit_symtab
*stab_best
= NULL
;
6013 struct dwarf2_per_cu_data
*per_cu
;
6014 while ((per_cu
= iter
.next ()) != NULL
)
6016 struct symbol
*sym
, *with_opaque
= NULL
;
6017 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6018 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6019 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6021 sym
= block_find_symbol (block
, name
, domain
,
6022 block_find_non_opaque_type_preferred
,
6025 /* Some caution must be observed with overloaded functions and
6026 methods, since the index will not contain any overload
6027 information (but NAME might contain it). */
6030 && strcmp_iw (SYMBOL_SEARCH_NAME (sym
), name
) == 0)
6032 if (with_opaque
!= NULL
6033 && strcmp_iw (SYMBOL_SEARCH_NAME (with_opaque
), name
) == 0)
6036 /* Keep looking through other CUs. */
6042 /* This dumps minimal information about .debug_names. It is called
6043 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6044 uses this to verify that .debug_names has been loaded. */
6047 dw2_debug_names_dump (struct objfile
*objfile
)
6049 struct dwarf2_per_objfile
*dwarf2_per_objfile
6050 = get_dwarf2_per_objfile (objfile
);
6052 gdb_assert (dwarf2_per_objfile
->using_index
);
6053 printf_filtered (".debug_names:");
6054 if (dwarf2_per_objfile
->debug_names_table
)
6055 printf_filtered (" exists\n");
6057 printf_filtered (" faked for \"readnow\"\n");
6058 printf_filtered ("\n");
6062 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6063 const char *func_name
)
6065 struct dwarf2_per_objfile
*dwarf2_per_objfile
6066 = get_dwarf2_per_objfile (objfile
);
6068 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6069 if (dwarf2_per_objfile
->debug_names_table
)
6071 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6073 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6075 struct dwarf2_per_cu_data
*per_cu
;
6076 while ((per_cu
= iter
.next ()) != NULL
)
6077 dw2_instantiate_symtab (per_cu
, false);
6082 dw2_debug_names_map_matching_symbols
6083 (struct objfile
*objfile
,
6084 const lookup_name_info
&name
, domain_enum domain
,
6086 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6087 symbol_compare_ftype
*ordered_compare
)
6089 struct dwarf2_per_objfile
*dwarf2_per_objfile
6090 = get_dwarf2_per_objfile (objfile
);
6092 /* debug_names_table is NULL if OBJF_READNOW. */
6093 if (!dwarf2_per_objfile
->debug_names_table
)
6096 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6097 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6099 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6100 auto matcher
= [&] (const char *symname
)
6102 if (ordered_compare
== nullptr)
6104 return ordered_compare (symname
, match_name
) == 0;
6107 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6108 [&] (offset_type namei
)
6110 /* The name was matched, now expand corresponding CUs that were
6112 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6114 struct dwarf2_per_cu_data
*per_cu
;
6115 while ((per_cu
= iter
.next ()) != NULL
)
6116 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6120 /* It's a shame we couldn't do this inside the
6121 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6122 that have already been expanded. Instead, this loop matches what
6123 the psymtab code does. */
6124 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6126 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6127 if (cust
!= nullptr)
6129 const struct block
*block
6130 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6131 if (!iterate_over_symbols_terminated (block
, name
,
6139 dw2_debug_names_expand_symtabs_matching
6140 (struct objfile
*objfile
,
6141 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6142 const lookup_name_info
&lookup_name
,
6143 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6144 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6145 enum search_domain kind
)
6147 struct dwarf2_per_objfile
*dwarf2_per_objfile
6148 = get_dwarf2_per_objfile (objfile
);
6150 /* debug_names_table is NULL if OBJF_READNOW. */
6151 if (!dwarf2_per_objfile
->debug_names_table
)
6154 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6156 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6158 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6160 kind
, [&] (offset_type namei
)
6162 /* The name was matched, now expand corresponding CUs that were
6164 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6166 struct dwarf2_per_cu_data
*per_cu
;
6167 while ((per_cu
= iter
.next ()) != NULL
)
6168 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6174 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6177 dw2_find_last_source_symtab
,
6178 dw2_forget_cached_source_info
,
6179 dw2_map_symtabs_matching_filename
,
6180 dw2_debug_names_lookup_symbol
,
6182 dw2_debug_names_dump
,
6183 dw2_debug_names_expand_symtabs_for_function
,
6184 dw2_expand_all_symtabs
,
6185 dw2_expand_symtabs_with_fullname
,
6186 dw2_debug_names_map_matching_symbols
,
6187 dw2_debug_names_expand_symtabs_matching
,
6188 dw2_find_pc_sect_compunit_symtab
,
6190 dw2_map_symbol_filenames
6193 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6194 to either a dwarf2_per_objfile or dwz_file object. */
6196 template <typename T
>
6197 static gdb::array_view
<const gdb_byte
>
6198 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6200 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6202 if (dwarf2_section_empty_p (section
))
6205 /* Older elfutils strip versions could keep the section in the main
6206 executable while splitting it for the separate debug info file. */
6207 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6210 dwarf2_read_section (obj
, section
);
6212 /* dwarf2_section_info::size is a bfd_size_type, while
6213 gdb::array_view works with size_t. On 32-bit hosts, with
6214 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6215 is 32-bit. So we need an explicit narrowing conversion here.
6216 This is fine, because it's impossible to allocate or mmap an
6217 array/buffer larger than what size_t can represent. */
6218 return gdb::make_array_view (section
->buffer
, section
->size
);
6221 /* Lookup the index cache for the contents of the index associated to
6224 static gdb::array_view
<const gdb_byte
>
6225 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6227 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6228 if (build_id
== nullptr)
6231 return global_index_cache
.lookup_gdb_index (build_id
,
6232 &dwarf2_obj
->index_cache_res
);
6235 /* Same as the above, but for DWZ. */
6237 static gdb::array_view
<const gdb_byte
>
6238 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6240 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6241 if (build_id
== nullptr)
6244 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6247 /* See symfile.h. */
6250 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6252 struct dwarf2_per_objfile
*dwarf2_per_objfile
6253 = get_dwarf2_per_objfile (objfile
);
6255 /* If we're about to read full symbols, don't bother with the
6256 indices. In this case we also don't care if some other debug
6257 format is making psymtabs, because they are all about to be
6259 if ((objfile
->flags
& OBJF_READNOW
))
6261 dwarf2_per_objfile
->using_index
= 1;
6262 create_all_comp_units (dwarf2_per_objfile
);
6263 create_all_type_units (dwarf2_per_objfile
);
6264 dwarf2_per_objfile
->quick_file_names_table
6265 = create_quick_file_names_table
6266 (dwarf2_per_objfile
->all_comp_units
.size ());
6268 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6269 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6271 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6273 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6274 struct dwarf2_per_cu_quick_data
);
6277 /* Return 1 so that gdb sees the "quick" functions. However,
6278 these functions will be no-ops because we will have expanded
6280 *index_kind
= dw_index_kind::GDB_INDEX
;
6284 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6286 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6290 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6291 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6292 get_gdb_index_contents_from_section
<dwz_file
>))
6294 *index_kind
= dw_index_kind::GDB_INDEX
;
6298 /* ... otherwise, try to find the index in the index cache. */
6299 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6300 get_gdb_index_contents_from_cache
,
6301 get_gdb_index_contents_from_cache_dwz
))
6303 global_index_cache
.hit ();
6304 *index_kind
= dw_index_kind::GDB_INDEX
;
6308 global_index_cache
.miss ();
6314 /* Build a partial symbol table. */
6317 dwarf2_build_psymtabs (struct objfile
*objfile
)
6319 struct dwarf2_per_objfile
*dwarf2_per_objfile
6320 = get_dwarf2_per_objfile (objfile
);
6322 init_psymbol_list (objfile
, 1024);
6326 /* This isn't really ideal: all the data we allocate on the
6327 objfile's obstack is still uselessly kept around. However,
6328 freeing it seems unsafe. */
6329 psymtab_discarder
psymtabs (objfile
);
6330 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6333 /* (maybe) store an index in the cache. */
6334 global_index_cache
.store (dwarf2_per_objfile
);
6336 catch (const gdb_exception_error
&except
)
6338 exception_print (gdb_stderr
, except
);
6342 /* Return the total length of the CU described by HEADER. */
6345 get_cu_length (const struct comp_unit_head
*header
)
6347 return header
->initial_length_size
+ header
->length
;
6350 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6353 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6355 sect_offset bottom
= cu_header
->sect_off
;
6356 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6358 return sect_off
>= bottom
&& sect_off
< top
;
6361 /* Find the base address of the compilation unit for range lists and
6362 location lists. It will normally be specified by DW_AT_low_pc.
6363 In DWARF-3 draft 4, the base address could be overridden by
6364 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6365 compilation units with discontinuous ranges. */
6368 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6370 struct attribute
*attr
;
6373 cu
->base_address
= 0;
6375 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6378 cu
->base_address
= attr_value_as_address (attr
);
6383 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6386 cu
->base_address
= attr_value_as_address (attr
);
6392 /* Read in the comp unit header information from the debug_info at info_ptr.
6393 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6394 NOTE: This leaves members offset, first_die_offset to be filled in
6397 static const gdb_byte
*
6398 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6399 const gdb_byte
*info_ptr
,
6400 struct dwarf2_section_info
*section
,
6401 rcuh_kind section_kind
)
6404 unsigned int bytes_read
;
6405 const char *filename
= get_section_file_name (section
);
6406 bfd
*abfd
= get_section_bfd_owner (section
);
6408 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6409 cu_header
->initial_length_size
= bytes_read
;
6410 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6411 info_ptr
+= bytes_read
;
6412 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6413 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6414 error (_("Dwarf Error: wrong version in compilation unit header "
6415 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6416 cu_header
->version
, filename
);
6418 if (cu_header
->version
< 5)
6419 switch (section_kind
)
6421 case rcuh_kind::COMPILE
:
6422 cu_header
->unit_type
= DW_UT_compile
;
6424 case rcuh_kind::TYPE
:
6425 cu_header
->unit_type
= DW_UT_type
;
6428 internal_error (__FILE__
, __LINE__
,
6429 _("read_comp_unit_head: invalid section_kind"));
6433 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6434 (read_1_byte (abfd
, info_ptr
));
6436 switch (cu_header
->unit_type
)
6440 case DW_UT_skeleton
:
6441 case DW_UT_split_compile
:
6442 if (section_kind
!= rcuh_kind::COMPILE
)
6443 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6444 "(is %s, should be %s) [in module %s]"),
6445 dwarf_unit_type_name (cu_header
->unit_type
),
6446 dwarf_unit_type_name (DW_UT_type
), filename
);
6449 case DW_UT_split_type
:
6450 section_kind
= rcuh_kind::TYPE
;
6453 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6454 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6455 "[in module %s]"), cu_header
->unit_type
,
6456 dwarf_unit_type_name (DW_UT_compile
),
6457 dwarf_unit_type_name (DW_UT_skeleton
),
6458 dwarf_unit_type_name (DW_UT_split_compile
),
6459 dwarf_unit_type_name (DW_UT_type
),
6460 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6463 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6466 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6469 info_ptr
+= bytes_read
;
6470 if (cu_header
->version
< 5)
6472 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6475 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6476 if (signed_addr
< 0)
6477 internal_error (__FILE__
, __LINE__
,
6478 _("read_comp_unit_head: dwarf from non elf file"));
6479 cu_header
->signed_addr_p
= signed_addr
;
6481 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6482 || cu_header
->unit_type
== DW_UT_skeleton
6483 || cu_header
->unit_type
== DW_UT_split_compile
;
6485 if (header_has_signature
)
6487 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6491 if (section_kind
== rcuh_kind::TYPE
)
6493 LONGEST type_offset
;
6494 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6495 info_ptr
+= bytes_read
;
6496 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6497 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6498 error (_("Dwarf Error: Too big type_offset in compilation unit "
6499 "header (is %s) [in module %s]"), plongest (type_offset
),
6506 /* Helper function that returns the proper abbrev section for
6509 static struct dwarf2_section_info
*
6510 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6512 struct dwarf2_section_info
*abbrev
;
6513 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6515 if (this_cu
->is_dwz
)
6516 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6518 abbrev
= &dwarf2_per_objfile
->abbrev
;
6523 /* Subroutine of read_and_check_comp_unit_head and
6524 read_and_check_type_unit_head to simplify them.
6525 Perform various error checking on the header. */
6528 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6529 struct comp_unit_head
*header
,
6530 struct dwarf2_section_info
*section
,
6531 struct dwarf2_section_info
*abbrev_section
)
6533 const char *filename
= get_section_file_name (section
);
6535 if (to_underlying (header
->abbrev_sect_off
)
6536 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6537 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6538 "(offset %s + 6) [in module %s]"),
6539 sect_offset_str (header
->abbrev_sect_off
),
6540 sect_offset_str (header
->sect_off
),
6543 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6544 avoid potential 32-bit overflow. */
6545 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6547 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6548 "(offset %s + 0) [in module %s]"),
6549 header
->length
, sect_offset_str (header
->sect_off
),
6553 /* Read in a CU/TU header and perform some basic error checking.
6554 The contents of the header are stored in HEADER.
6555 The result is a pointer to the start of the first DIE. */
6557 static const gdb_byte
*
6558 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6559 struct comp_unit_head
*header
,
6560 struct dwarf2_section_info
*section
,
6561 struct dwarf2_section_info
*abbrev_section
,
6562 const gdb_byte
*info_ptr
,
6563 rcuh_kind section_kind
)
6565 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6567 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6569 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6571 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6573 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6579 /* Fetch the abbreviation table offset from a comp or type unit header. */
6582 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6583 struct dwarf2_section_info
*section
,
6584 sect_offset sect_off
)
6586 bfd
*abfd
= get_section_bfd_owner (section
);
6587 const gdb_byte
*info_ptr
;
6588 unsigned int initial_length_size
, offset_size
;
6591 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6592 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6593 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6594 offset_size
= initial_length_size
== 4 ? 4 : 8;
6595 info_ptr
+= initial_length_size
;
6597 version
= read_2_bytes (abfd
, info_ptr
);
6601 /* Skip unit type and address size. */
6605 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6608 /* Allocate a new partial symtab for file named NAME and mark this new
6609 partial symtab as being an include of PST. */
6612 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6613 struct objfile
*objfile
)
6615 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6617 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6619 /* It shares objfile->objfile_obstack. */
6620 subpst
->dirname
= pst
->dirname
;
6623 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6624 subpst
->dependencies
[0] = pst
;
6625 subpst
->number_of_dependencies
= 1;
6627 subpst
->read_symtab
= pst
->read_symtab
;
6629 /* No private part is necessary for include psymtabs. This property
6630 can be used to differentiate between such include psymtabs and
6631 the regular ones. */
6632 subpst
->read_symtab_private
= NULL
;
6635 /* Read the Line Number Program data and extract the list of files
6636 included by the source file represented by PST. Build an include
6637 partial symtab for each of these included files. */
6640 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6641 struct die_info
*die
,
6642 struct partial_symtab
*pst
)
6645 struct attribute
*attr
;
6647 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6649 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6651 return; /* No linetable, so no includes. */
6653 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6654 that we pass in the raw text_low here; that is ok because we're
6655 only decoding the line table to make include partial symtabs, and
6656 so the addresses aren't really used. */
6657 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6658 pst
->raw_text_low (), 1);
6662 hash_signatured_type (const void *item
)
6664 const struct signatured_type
*sig_type
6665 = (const struct signatured_type
*) item
;
6667 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6668 return sig_type
->signature
;
6672 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6674 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6675 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6677 return lhs
->signature
== rhs
->signature
;
6680 /* Allocate a hash table for signatured types. */
6683 allocate_signatured_type_table (struct objfile
*objfile
)
6685 return htab_create_alloc_ex (41,
6686 hash_signatured_type
,
6689 &objfile
->objfile_obstack
,
6690 hashtab_obstack_allocate
,
6691 dummy_obstack_deallocate
);
6694 /* A helper function to add a signatured type CU to a table. */
6697 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6699 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6700 std::vector
<signatured_type
*> *all_type_units
6701 = (std::vector
<signatured_type
*> *) datum
;
6703 all_type_units
->push_back (sigt
);
6708 /* A helper for create_debug_types_hash_table. Read types from SECTION
6709 and fill them into TYPES_HTAB. It will process only type units,
6710 therefore DW_UT_type. */
6713 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6714 struct dwo_file
*dwo_file
,
6715 dwarf2_section_info
*section
, htab_t
&types_htab
,
6716 rcuh_kind section_kind
)
6718 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6719 struct dwarf2_section_info
*abbrev_section
;
6721 const gdb_byte
*info_ptr
, *end_ptr
;
6723 abbrev_section
= (dwo_file
!= NULL
6724 ? &dwo_file
->sections
.abbrev
6725 : &dwarf2_per_objfile
->abbrev
);
6727 if (dwarf_read_debug
)
6728 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6729 get_section_name (section
),
6730 get_section_file_name (abbrev_section
));
6732 dwarf2_read_section (objfile
, section
);
6733 info_ptr
= section
->buffer
;
6735 if (info_ptr
== NULL
)
6738 /* We can't set abfd until now because the section may be empty or
6739 not present, in which case the bfd is unknown. */
6740 abfd
= get_section_bfd_owner (section
);
6742 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6743 because we don't need to read any dies: the signature is in the
6746 end_ptr
= info_ptr
+ section
->size
;
6747 while (info_ptr
< end_ptr
)
6749 struct signatured_type
*sig_type
;
6750 struct dwo_unit
*dwo_tu
;
6752 const gdb_byte
*ptr
= info_ptr
;
6753 struct comp_unit_head header
;
6754 unsigned int length
;
6756 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6758 /* Initialize it due to a false compiler warning. */
6759 header
.signature
= -1;
6760 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6762 /* We need to read the type's signature in order to build the hash
6763 table, but we don't need anything else just yet. */
6765 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6766 abbrev_section
, ptr
, section_kind
);
6768 length
= get_cu_length (&header
);
6770 /* Skip dummy type units. */
6771 if (ptr
>= info_ptr
+ length
6772 || peek_abbrev_code (abfd
, ptr
) == 0
6773 || header
.unit_type
!= DW_UT_type
)
6779 if (types_htab
== NULL
)
6782 types_htab
= allocate_dwo_unit_table (objfile
);
6784 types_htab
= allocate_signatured_type_table (objfile
);
6790 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6792 dwo_tu
->dwo_file
= dwo_file
;
6793 dwo_tu
->signature
= header
.signature
;
6794 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6795 dwo_tu
->section
= section
;
6796 dwo_tu
->sect_off
= sect_off
;
6797 dwo_tu
->length
= length
;
6801 /* N.B.: type_offset is not usable if this type uses a DWO file.
6802 The real type_offset is in the DWO file. */
6804 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6805 struct signatured_type
);
6806 sig_type
->signature
= header
.signature
;
6807 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6808 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6809 sig_type
->per_cu
.is_debug_types
= 1;
6810 sig_type
->per_cu
.section
= section
;
6811 sig_type
->per_cu
.sect_off
= sect_off
;
6812 sig_type
->per_cu
.length
= length
;
6815 slot
= htab_find_slot (types_htab
,
6816 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6818 gdb_assert (slot
!= NULL
);
6821 sect_offset dup_sect_off
;
6825 const struct dwo_unit
*dup_tu
6826 = (const struct dwo_unit
*) *slot
;
6828 dup_sect_off
= dup_tu
->sect_off
;
6832 const struct signatured_type
*dup_tu
6833 = (const struct signatured_type
*) *slot
;
6835 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6838 complaint (_("debug type entry at offset %s is duplicate to"
6839 " the entry at offset %s, signature %s"),
6840 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6841 hex_string (header
.signature
));
6843 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6845 if (dwarf_read_debug
> 1)
6846 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6847 sect_offset_str (sect_off
),
6848 hex_string (header
.signature
));
6854 /* Create the hash table of all entries in the .debug_types
6855 (or .debug_types.dwo) section(s).
6856 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6857 otherwise it is NULL.
6859 The result is a pointer to the hash table or NULL if there are no types.
6861 Note: This function processes DWO files only, not DWP files. */
6864 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6865 struct dwo_file
*dwo_file
,
6866 gdb::array_view
<dwarf2_section_info
> type_sections
,
6869 for (dwarf2_section_info
§ion
: type_sections
)
6870 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6871 types_htab
, rcuh_kind::TYPE
);
6874 /* Create the hash table of all entries in the .debug_types section,
6875 and initialize all_type_units.
6876 The result is zero if there is an error (e.g. missing .debug_types section),
6877 otherwise non-zero. */
6880 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6882 htab_t types_htab
= NULL
;
6884 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6885 &dwarf2_per_objfile
->info
, types_htab
,
6886 rcuh_kind::COMPILE
);
6887 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6888 dwarf2_per_objfile
->types
, types_htab
);
6889 if (types_htab
== NULL
)
6891 dwarf2_per_objfile
->signatured_types
= NULL
;
6895 dwarf2_per_objfile
->signatured_types
= types_htab
;
6897 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6898 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6900 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6901 &dwarf2_per_objfile
->all_type_units
);
6906 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6907 If SLOT is non-NULL, it is the entry to use in the hash table.
6908 Otherwise we find one. */
6910 static struct signatured_type
*
6911 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6914 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6916 if (dwarf2_per_objfile
->all_type_units
.size ()
6917 == dwarf2_per_objfile
->all_type_units
.capacity ())
6918 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6920 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6921 struct signatured_type
);
6923 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6924 sig_type
->signature
= sig
;
6925 sig_type
->per_cu
.is_debug_types
= 1;
6926 if (dwarf2_per_objfile
->using_index
)
6928 sig_type
->per_cu
.v
.quick
=
6929 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6930 struct dwarf2_per_cu_quick_data
);
6935 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6938 gdb_assert (*slot
== NULL
);
6940 /* The rest of sig_type must be filled in by the caller. */
6944 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
6945 Fill in SIG_ENTRY with DWO_ENTRY. */
6948 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6949 struct signatured_type
*sig_entry
,
6950 struct dwo_unit
*dwo_entry
)
6952 /* Make sure we're not clobbering something we don't expect to. */
6953 gdb_assert (! sig_entry
->per_cu
.queued
);
6954 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
6955 if (dwarf2_per_objfile
->using_index
)
6957 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
6958 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
6961 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
6962 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
6963 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
6964 gdb_assert (sig_entry
->type_unit_group
== NULL
);
6965 gdb_assert (sig_entry
->dwo_unit
== NULL
);
6967 sig_entry
->per_cu
.section
= dwo_entry
->section
;
6968 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
6969 sig_entry
->per_cu
.length
= dwo_entry
->length
;
6970 sig_entry
->per_cu
.reading_dwo_directly
= 1;
6971 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6972 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
6973 sig_entry
->dwo_unit
= dwo_entry
;
6976 /* Subroutine of lookup_signatured_type.
6977 If we haven't read the TU yet, create the signatured_type data structure
6978 for a TU to be read in directly from a DWO file, bypassing the stub.
6979 This is the "Stay in DWO Optimization": When there is no DWP file and we're
6980 using .gdb_index, then when reading a CU we want to stay in the DWO file
6981 containing that CU. Otherwise we could end up reading several other DWO
6982 files (due to comdat folding) to process the transitive closure of all the
6983 mentioned TUs, and that can be slow. The current DWO file will have every
6984 type signature that it needs.
6985 We only do this for .gdb_index because in the psymtab case we already have
6986 to read all the DWOs to build the type unit groups. */
6988 static struct signatured_type
*
6989 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
6991 struct dwarf2_per_objfile
*dwarf2_per_objfile
6992 = cu
->per_cu
->dwarf2_per_objfile
;
6993 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6994 struct dwo_file
*dwo_file
;
6995 struct dwo_unit find_dwo_entry
, *dwo_entry
;
6996 struct signatured_type find_sig_entry
, *sig_entry
;
6999 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7001 /* If TU skeletons have been removed then we may not have read in any
7003 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7005 dwarf2_per_objfile
->signatured_types
7006 = allocate_signatured_type_table (objfile
);
7009 /* We only ever need to read in one copy of a signatured type.
7010 Use the global signatured_types array to do our own comdat-folding
7011 of types. If this is the first time we're reading this TU, and
7012 the TU has an entry in .gdb_index, replace the recorded data from
7013 .gdb_index with this TU. */
7015 find_sig_entry
.signature
= sig
;
7016 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7017 &find_sig_entry
, INSERT
);
7018 sig_entry
= (struct signatured_type
*) *slot
;
7020 /* We can get here with the TU already read, *or* in the process of being
7021 read. Don't reassign the global entry to point to this DWO if that's
7022 the case. Also note that if the TU is already being read, it may not
7023 have come from a DWO, the program may be a mix of Fission-compiled
7024 code and non-Fission-compiled code. */
7026 /* Have we already tried to read this TU?
7027 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7028 needn't exist in the global table yet). */
7029 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7032 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7033 dwo_unit of the TU itself. */
7034 dwo_file
= cu
->dwo_unit
->dwo_file
;
7036 /* Ok, this is the first time we're reading this TU. */
7037 if (dwo_file
->tus
== NULL
)
7039 find_dwo_entry
.signature
= sig
;
7040 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7041 if (dwo_entry
== NULL
)
7044 /* If the global table doesn't have an entry for this TU, add one. */
7045 if (sig_entry
== NULL
)
7046 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7048 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7049 sig_entry
->per_cu
.tu_read
= 1;
7053 /* Subroutine of lookup_signatured_type.
7054 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7055 then try the DWP file. If the TU stub (skeleton) has been removed then
7056 it won't be in .gdb_index. */
7058 static struct signatured_type
*
7059 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7061 struct dwarf2_per_objfile
*dwarf2_per_objfile
7062 = cu
->per_cu
->dwarf2_per_objfile
;
7063 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7064 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7065 struct dwo_unit
*dwo_entry
;
7066 struct signatured_type find_sig_entry
, *sig_entry
;
7069 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7070 gdb_assert (dwp_file
!= NULL
);
7072 /* If TU skeletons have been removed then we may not have read in any
7074 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7076 dwarf2_per_objfile
->signatured_types
7077 = allocate_signatured_type_table (objfile
);
7080 find_sig_entry
.signature
= sig
;
7081 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7082 &find_sig_entry
, INSERT
);
7083 sig_entry
= (struct signatured_type
*) *slot
;
7085 /* Have we already tried to read this TU?
7086 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7087 needn't exist in the global table yet). */
7088 if (sig_entry
!= NULL
)
7091 if (dwp_file
->tus
== NULL
)
7093 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7094 sig
, 1 /* is_debug_types */);
7095 if (dwo_entry
== NULL
)
7098 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7099 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7104 /* Lookup a signature based type for DW_FORM_ref_sig8.
7105 Returns NULL if signature SIG is not present in the table.
7106 It is up to the caller to complain about this. */
7108 static struct signatured_type
*
7109 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7111 struct dwarf2_per_objfile
*dwarf2_per_objfile
7112 = cu
->per_cu
->dwarf2_per_objfile
;
7115 && dwarf2_per_objfile
->using_index
)
7117 /* We're in a DWO/DWP file, and we're using .gdb_index.
7118 These cases require special processing. */
7119 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7120 return lookup_dwo_signatured_type (cu
, sig
);
7122 return lookup_dwp_signatured_type (cu
, sig
);
7126 struct signatured_type find_entry
, *entry
;
7128 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7130 find_entry
.signature
= sig
;
7131 entry
= ((struct signatured_type
*)
7132 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7137 /* Low level DIE reading support. */
7139 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7142 init_cu_die_reader (struct die_reader_specs
*reader
,
7143 struct dwarf2_cu
*cu
,
7144 struct dwarf2_section_info
*section
,
7145 struct dwo_file
*dwo_file
,
7146 struct abbrev_table
*abbrev_table
)
7148 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7149 reader
->abfd
= get_section_bfd_owner (section
);
7151 reader
->dwo_file
= dwo_file
;
7152 reader
->die_section
= section
;
7153 reader
->buffer
= section
->buffer
;
7154 reader
->buffer_end
= section
->buffer
+ section
->size
;
7155 reader
->comp_dir
= NULL
;
7156 reader
->abbrev_table
= abbrev_table
;
7159 /* Subroutine of init_cutu_and_read_dies to simplify it.
7160 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7161 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7164 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7165 from it to the DIE in the DWO. If NULL we are skipping the stub.
7166 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7167 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7168 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7169 STUB_COMP_DIR may be non-NULL.
7170 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7171 are filled in with the info of the DIE from the DWO file.
7172 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7173 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7174 kept around for at least as long as *RESULT_READER.
7176 The result is non-zero if a valid (non-dummy) DIE was found. */
7179 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7180 struct dwo_unit
*dwo_unit
,
7181 struct die_info
*stub_comp_unit_die
,
7182 const char *stub_comp_dir
,
7183 struct die_reader_specs
*result_reader
,
7184 const gdb_byte
**result_info_ptr
,
7185 struct die_info
**result_comp_unit_die
,
7186 int *result_has_children
,
7187 abbrev_table_up
*result_dwo_abbrev_table
)
7189 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7191 struct dwarf2_cu
*cu
= this_cu
->cu
;
7193 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7194 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7195 int i
,num_extra_attrs
;
7196 struct dwarf2_section_info
*dwo_abbrev_section
;
7197 struct attribute
*attr
;
7198 struct die_info
*comp_unit_die
;
7200 /* At most one of these may be provided. */
7201 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7203 /* These attributes aren't processed until later:
7204 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7205 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7206 referenced later. However, these attributes are found in the stub
7207 which we won't have later. In order to not impose this complication
7208 on the rest of the code, we read them here and copy them to the
7217 if (stub_comp_unit_die
!= NULL
)
7219 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7221 if (! this_cu
->is_debug_types
)
7222 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7223 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7224 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7225 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7226 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7228 /* There should be a DW_AT_addr_base attribute here (if needed).
7229 We need the value before we can process DW_FORM_GNU_addr_index
7230 or DW_FORM_addrx. */
7232 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_addr_base
, cu
);
7234 cu
->addr_base
= DW_UNSND (attr
);
7236 /* There should be a DW_AT_ranges_base attribute here (if needed).
7237 We need the value before we can process DW_AT_ranges. */
7238 cu
->ranges_base
= 0;
7239 attr
= dwarf2_attr (stub_comp_unit_die
, DW_AT_GNU_ranges_base
, cu
);
7241 cu
->ranges_base
= DW_UNSND (attr
);
7243 else if (stub_comp_dir
!= NULL
)
7245 /* Reconstruct the comp_dir attribute to simplify the code below. */
7246 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7247 comp_dir
->name
= DW_AT_comp_dir
;
7248 comp_dir
->form
= DW_FORM_string
;
7249 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7250 DW_STRING (comp_dir
) = stub_comp_dir
;
7253 /* Set up for reading the DWO CU/TU. */
7254 cu
->dwo_unit
= dwo_unit
;
7255 dwarf2_section_info
*section
= dwo_unit
->section
;
7256 dwarf2_read_section (objfile
, section
);
7257 abfd
= get_section_bfd_owner (section
);
7258 begin_info_ptr
= info_ptr
= (section
->buffer
7259 + to_underlying (dwo_unit
->sect_off
));
7260 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7262 if (this_cu
->is_debug_types
)
7264 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7266 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7267 &cu
->header
, section
,
7269 info_ptr
, rcuh_kind::TYPE
);
7270 /* This is not an assert because it can be caused by bad debug info. */
7271 if (sig_type
->signature
!= cu
->header
.signature
)
7273 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7274 " TU at offset %s [in module %s]"),
7275 hex_string (sig_type
->signature
),
7276 hex_string (cu
->header
.signature
),
7277 sect_offset_str (dwo_unit
->sect_off
),
7278 bfd_get_filename (abfd
));
7280 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7281 /* For DWOs coming from DWP files, we don't know the CU length
7282 nor the type's offset in the TU until now. */
7283 dwo_unit
->length
= get_cu_length (&cu
->header
);
7284 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7286 /* Establish the type offset that can be used to lookup the type.
7287 For DWO files, we don't know it until now. */
7288 sig_type
->type_offset_in_section
7289 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7293 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7294 &cu
->header
, section
,
7296 info_ptr
, rcuh_kind::COMPILE
);
7297 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7298 /* For DWOs coming from DWP files, we don't know the CU length
7300 dwo_unit
->length
= get_cu_length (&cu
->header
);
7303 *result_dwo_abbrev_table
7304 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7305 cu
->header
.abbrev_sect_off
);
7306 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7307 result_dwo_abbrev_table
->get ());
7309 /* Read in the die, but leave space to copy over the attributes
7310 from the stub. This has the benefit of simplifying the rest of
7311 the code - all the work to maintain the illusion of a single
7312 DW_TAG_{compile,type}_unit DIE is done here. */
7313 num_extra_attrs
= ((stmt_list
!= NULL
)
7317 + (comp_dir
!= NULL
));
7318 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7319 result_has_children
, num_extra_attrs
);
7321 /* Copy over the attributes from the stub to the DIE we just read in. */
7322 comp_unit_die
= *result_comp_unit_die
;
7323 i
= comp_unit_die
->num_attrs
;
7324 if (stmt_list
!= NULL
)
7325 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7327 comp_unit_die
->attrs
[i
++] = *low_pc
;
7328 if (high_pc
!= NULL
)
7329 comp_unit_die
->attrs
[i
++] = *high_pc
;
7331 comp_unit_die
->attrs
[i
++] = *ranges
;
7332 if (comp_dir
!= NULL
)
7333 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7334 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7336 if (dwarf_die_debug
)
7338 fprintf_unfiltered (gdb_stdlog
,
7339 "Read die from %s@0x%x of %s:\n",
7340 get_section_name (section
),
7341 (unsigned) (begin_info_ptr
- section
->buffer
),
7342 bfd_get_filename (abfd
));
7343 dump_die (comp_unit_die
, dwarf_die_debug
);
7346 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7347 TUs by skipping the stub and going directly to the entry in the DWO file.
7348 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7349 to get it via circuitous means. Blech. */
7350 if (comp_dir
!= NULL
)
7351 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7353 /* Skip dummy compilation units. */
7354 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7355 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7358 *result_info_ptr
= info_ptr
;
7362 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7363 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7364 signature is part of the header. */
7365 static gdb::optional
<ULONGEST
>
7366 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7368 if (cu
->header
.version
>= 5)
7369 return cu
->header
.signature
;
7370 struct attribute
*attr
;
7371 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7372 if (attr
== nullptr)
7373 return gdb::optional
<ULONGEST
> ();
7374 return DW_UNSND (attr
);
7377 /* Subroutine of init_cutu_and_read_dies to simplify it.
7378 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7379 Returns NULL if the specified DWO unit cannot be found. */
7381 static struct dwo_unit
*
7382 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7383 struct die_info
*comp_unit_die
)
7385 struct dwarf2_cu
*cu
= this_cu
->cu
;
7386 struct dwo_unit
*dwo_unit
;
7387 const char *comp_dir
, *dwo_name
;
7389 gdb_assert (cu
!= NULL
);
7391 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7392 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7393 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7395 if (this_cu
->is_debug_types
)
7397 struct signatured_type
*sig_type
;
7399 /* Since this_cu is the first member of struct signatured_type,
7400 we can go from a pointer to one to a pointer to the other. */
7401 sig_type
= (struct signatured_type
*) this_cu
;
7402 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7406 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7407 if (!signature
.has_value ())
7408 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7410 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7411 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7418 /* Subroutine of init_cutu_and_read_dies to simplify it.
7419 See it for a description of the parameters.
7420 Read a TU directly from a DWO file, bypassing the stub. */
7423 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7424 int use_existing_cu
, int keep
,
7425 die_reader_func_ftype
*die_reader_func
,
7428 std::unique_ptr
<dwarf2_cu
> new_cu
;
7429 struct signatured_type
*sig_type
;
7430 struct die_reader_specs reader
;
7431 const gdb_byte
*info_ptr
;
7432 struct die_info
*comp_unit_die
;
7434 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7436 /* Verify we can do the following downcast, and that we have the
7438 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7439 sig_type
= (struct signatured_type
*) this_cu
;
7440 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7442 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7444 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7445 /* There's no need to do the rereading_dwo_cu handling that
7446 init_cutu_and_read_dies does since we don't read the stub. */
7450 /* If !use_existing_cu, this_cu->cu must be NULL. */
7451 gdb_assert (this_cu
->cu
== NULL
);
7452 new_cu
.reset (new dwarf2_cu (this_cu
));
7455 /* A future optimization, if needed, would be to use an existing
7456 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7457 could share abbrev tables. */
7459 /* The abbreviation table used by READER, this must live at least as long as
7461 abbrev_table_up dwo_abbrev_table
;
7463 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7464 NULL
/* stub_comp_unit_die */,
7465 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7467 &comp_unit_die
, &has_children
,
7468 &dwo_abbrev_table
) == 0)
7474 /* All the "real" work is done here. */
7475 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7477 /* This duplicates the code in init_cutu_and_read_dies,
7478 but the alternative is making the latter more complex.
7479 This function is only for the special case of using DWO files directly:
7480 no point in overly complicating the general case just to handle this. */
7481 if (new_cu
!= NULL
&& keep
)
7483 /* Link this CU into read_in_chain. */
7484 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7485 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7486 /* The chain owns it now. */
7491 /* Initialize a CU (or TU) and read its DIEs.
7492 If the CU defers to a DWO file, read the DWO file as well.
7494 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7495 Otherwise the table specified in the comp unit header is read in and used.
7496 This is an optimization for when we already have the abbrev table.
7498 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7499 Otherwise, a new CU is allocated with xmalloc.
7501 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7502 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7504 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7505 linker) then DIE_READER_FUNC will not get called. */
7508 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7509 struct abbrev_table
*abbrev_table
,
7510 int use_existing_cu
, int keep
,
7512 die_reader_func_ftype
*die_reader_func
,
7515 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7516 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7517 struct dwarf2_section_info
*section
= this_cu
->section
;
7518 bfd
*abfd
= get_section_bfd_owner (section
);
7519 struct dwarf2_cu
*cu
;
7520 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7521 struct die_reader_specs reader
;
7522 struct die_info
*comp_unit_die
;
7524 struct signatured_type
*sig_type
= NULL
;
7525 struct dwarf2_section_info
*abbrev_section
;
7526 /* Non-zero if CU currently points to a DWO file and we need to
7527 reread it. When this happens we need to reread the skeleton die
7528 before we can reread the DWO file (this only applies to CUs, not TUs). */
7529 int rereading_dwo_cu
= 0;
7531 if (dwarf_die_debug
)
7532 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7533 this_cu
->is_debug_types
? "type" : "comp",
7534 sect_offset_str (this_cu
->sect_off
));
7536 if (use_existing_cu
)
7539 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7540 file (instead of going through the stub), short-circuit all of this. */
7541 if (this_cu
->reading_dwo_directly
)
7543 /* Narrow down the scope of possibilities to have to understand. */
7544 gdb_assert (this_cu
->is_debug_types
);
7545 gdb_assert (abbrev_table
== NULL
);
7546 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7547 die_reader_func
, data
);
7551 /* This is cheap if the section is already read in. */
7552 dwarf2_read_section (objfile
, section
);
7554 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7556 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7558 std::unique_ptr
<dwarf2_cu
> new_cu
;
7559 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7562 /* If this CU is from a DWO file we need to start over, we need to
7563 refetch the attributes from the skeleton CU.
7564 This could be optimized by retrieving those attributes from when we
7565 were here the first time: the previous comp_unit_die was stored in
7566 comp_unit_obstack. But there's no data yet that we need this
7568 if (cu
->dwo_unit
!= NULL
)
7569 rereading_dwo_cu
= 1;
7573 /* If !use_existing_cu, this_cu->cu must be NULL. */
7574 gdb_assert (this_cu
->cu
== NULL
);
7575 new_cu
.reset (new dwarf2_cu (this_cu
));
7579 /* Get the header. */
7580 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7582 /* We already have the header, there's no need to read it in again. */
7583 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7587 if (this_cu
->is_debug_types
)
7589 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7590 &cu
->header
, section
,
7591 abbrev_section
, info_ptr
,
7594 /* Since per_cu is the first member of struct signatured_type,
7595 we can go from a pointer to one to a pointer to the other. */
7596 sig_type
= (struct signatured_type
*) this_cu
;
7597 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7598 gdb_assert (sig_type
->type_offset_in_tu
7599 == cu
->header
.type_cu_offset_in_tu
);
7600 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7602 /* LENGTH has not been set yet for type units if we're
7603 using .gdb_index. */
7604 this_cu
->length
= get_cu_length (&cu
->header
);
7606 /* Establish the type offset that can be used to lookup the type. */
7607 sig_type
->type_offset_in_section
=
7608 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7610 this_cu
->dwarf_version
= cu
->header
.version
;
7614 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7615 &cu
->header
, section
,
7618 rcuh_kind::COMPILE
);
7620 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7621 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7622 this_cu
->dwarf_version
= cu
->header
.version
;
7626 /* Skip dummy compilation units. */
7627 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7628 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7631 /* If we don't have them yet, read the abbrevs for this compilation unit.
7632 And if we need to read them now, make sure they're freed when we're
7633 done (own the table through ABBREV_TABLE_HOLDER). */
7634 abbrev_table_up abbrev_table_holder
;
7635 if (abbrev_table
!= NULL
)
7636 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7640 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7641 cu
->header
.abbrev_sect_off
);
7642 abbrev_table
= abbrev_table_holder
.get ();
7645 /* Read the top level CU/TU die. */
7646 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7647 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7649 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7652 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7653 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7654 table from the DWO file and pass the ownership over to us. It will be
7655 referenced from READER, so we must make sure to free it after we're done
7658 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7659 DWO CU, that this test will fail (the attribute will not be present). */
7660 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7661 abbrev_table_up dwo_abbrev_table
;
7662 if (dwo_name
!= nullptr)
7664 struct dwo_unit
*dwo_unit
;
7665 struct die_info
*dwo_comp_unit_die
;
7669 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7670 " has children (offset %s) [in module %s]"),
7671 sect_offset_str (this_cu
->sect_off
),
7672 bfd_get_filename (abfd
));
7674 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7675 if (dwo_unit
!= NULL
)
7677 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7678 comp_unit_die
, NULL
,
7680 &dwo_comp_unit_die
, &has_children
,
7681 &dwo_abbrev_table
) == 0)
7686 comp_unit_die
= dwo_comp_unit_die
;
7690 /* Yikes, we couldn't find the rest of the DIE, we only have
7691 the stub. A complaint has already been logged. There's
7692 not much more we can do except pass on the stub DIE to
7693 die_reader_func. We don't want to throw an error on bad
7698 /* All of the above is setup for this call. Yikes. */
7699 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7701 /* Done, clean up. */
7702 if (new_cu
!= NULL
&& keep
)
7704 /* Link this CU into read_in_chain. */
7705 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7706 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7707 /* The chain owns it now. */
7712 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name if present.
7713 DWO_FILE, if non-NULL, is the DWO file to read (the caller is assumed
7714 to have already done the lookup to find the DWO file).
7716 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7717 THIS_CU->is_debug_types, but nothing else.
7719 We fill in THIS_CU->length.
7721 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7722 linker) then DIE_READER_FUNC will not get called.
7724 THIS_CU->cu is always freed when done.
7725 This is done in order to not leave THIS_CU->cu in a state where we have
7726 to care whether it refers to the "main" CU or the DWO CU. */
7729 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7730 struct dwo_file
*dwo_file
,
7731 die_reader_func_ftype
*die_reader_func
,
7734 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7735 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7736 struct dwarf2_section_info
*section
= this_cu
->section
;
7737 bfd
*abfd
= get_section_bfd_owner (section
);
7738 struct dwarf2_section_info
*abbrev_section
;
7739 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7740 struct die_reader_specs reader
;
7741 struct die_info
*comp_unit_die
;
7744 if (dwarf_die_debug
)
7745 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7746 this_cu
->is_debug_types
? "type" : "comp",
7747 sect_offset_str (this_cu
->sect_off
));
7749 gdb_assert (this_cu
->cu
== NULL
);
7751 abbrev_section
= (dwo_file
!= NULL
7752 ? &dwo_file
->sections
.abbrev
7753 : get_abbrev_section_for_cu (this_cu
));
7755 /* This is cheap if the section is already read in. */
7756 dwarf2_read_section (objfile
, section
);
7758 struct dwarf2_cu
cu (this_cu
);
7760 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7761 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7762 &cu
.header
, section
,
7763 abbrev_section
, info_ptr
,
7764 (this_cu
->is_debug_types
7766 : rcuh_kind::COMPILE
));
7768 this_cu
->length
= get_cu_length (&cu
.header
);
7770 /* Skip dummy compilation units. */
7771 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7772 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7775 abbrev_table_up abbrev_table
7776 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7777 cu
.header
.abbrev_sect_off
);
7779 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7780 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7782 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7785 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and
7786 does not lookup the specified DWO file.
7787 This cannot be used to read DWO files.
7789 THIS_CU->cu is always freed when done.
7790 This is done in order to not leave THIS_CU->cu in a state where we have
7791 to care whether it refers to the "main" CU or the DWO CU.
7792 We can revisit this if the data shows there's a performance issue. */
7795 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7796 die_reader_func_ftype
*die_reader_func
,
7799 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, die_reader_func
, data
);
7802 /* Type Unit Groups.
7804 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7805 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7806 so that all types coming from the same compilation (.o file) are grouped
7807 together. A future step could be to put the types in the same symtab as
7808 the CU the types ultimately came from. */
7811 hash_type_unit_group (const void *item
)
7813 const struct type_unit_group
*tu_group
7814 = (const struct type_unit_group
*) item
;
7816 return hash_stmt_list_entry (&tu_group
->hash
);
7820 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7822 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7823 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7825 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7828 /* Allocate a hash table for type unit groups. */
7831 allocate_type_unit_groups_table (struct objfile
*objfile
)
7833 return htab_create_alloc_ex (3,
7834 hash_type_unit_group
,
7837 &objfile
->objfile_obstack
,
7838 hashtab_obstack_allocate
,
7839 dummy_obstack_deallocate
);
7842 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7843 partial symtabs. We combine several TUs per psymtab to not let the size
7844 of any one psymtab grow too big. */
7845 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7846 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7848 /* Helper routine for get_type_unit_group.
7849 Create the type_unit_group object used to hold one or more TUs. */
7851 static struct type_unit_group
*
7852 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7854 struct dwarf2_per_objfile
*dwarf2_per_objfile
7855 = cu
->per_cu
->dwarf2_per_objfile
;
7856 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7857 struct dwarf2_per_cu_data
*per_cu
;
7858 struct type_unit_group
*tu_group
;
7860 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7861 struct type_unit_group
);
7862 per_cu
= &tu_group
->per_cu
;
7863 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7865 if (dwarf2_per_objfile
->using_index
)
7867 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7868 struct dwarf2_per_cu_quick_data
);
7872 unsigned int line_offset
= to_underlying (line_offset_struct
);
7873 struct partial_symtab
*pst
;
7876 /* Give the symtab a useful name for debug purposes. */
7877 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7878 name
= string_printf ("<type_units_%d>",
7879 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7881 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7883 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7887 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7888 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7893 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7894 STMT_LIST is a DW_AT_stmt_list attribute. */
7896 static struct type_unit_group
*
7897 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7899 struct dwarf2_per_objfile
*dwarf2_per_objfile
7900 = cu
->per_cu
->dwarf2_per_objfile
;
7901 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7902 struct type_unit_group
*tu_group
;
7904 unsigned int line_offset
;
7905 struct type_unit_group type_unit_group_for_lookup
;
7907 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7909 dwarf2_per_objfile
->type_unit_groups
=
7910 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7913 /* Do we need to create a new group, or can we use an existing one? */
7917 line_offset
= DW_UNSND (stmt_list
);
7918 ++tu_stats
->nr_symtab_sharers
;
7922 /* Ugh, no stmt_list. Rare, but we have to handle it.
7923 We can do various things here like create one group per TU or
7924 spread them over multiple groups to split up the expansion work.
7925 To avoid worst case scenarios (too many groups or too large groups)
7926 we, umm, group them in bunches. */
7927 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7928 | (tu_stats
->nr_stmt_less_type_units
7929 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7930 ++tu_stats
->nr_stmt_less_type_units
;
7933 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7934 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7935 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7936 &type_unit_group_for_lookup
, INSERT
);
7939 tu_group
= (struct type_unit_group
*) *slot
;
7940 gdb_assert (tu_group
!= NULL
);
7944 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
7945 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
7947 ++tu_stats
->nr_symtabs
;
7953 /* Partial symbol tables. */
7955 /* Create a psymtab named NAME and assign it to PER_CU.
7957 The caller must fill in the following details:
7958 dirname, textlow, texthigh. */
7960 static struct partial_symtab
*
7961 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
7963 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
7964 struct partial_symtab
*pst
;
7966 pst
= start_psymtab_common (objfile
, name
, 0);
7968 pst
->psymtabs_addrmap_supported
= 1;
7970 /* This is the glue that links PST into GDB's symbol API. */
7971 pst
->read_symtab_private
= per_cu
;
7972 pst
->read_symtab
= dwarf2_read_symtab
;
7973 per_cu
->v
.psymtab
= pst
;
7978 /* The DATA object passed to process_psymtab_comp_unit_reader has this
7981 struct process_psymtab_comp_unit_data
7983 /* True if we are reading a DW_TAG_partial_unit. */
7985 int want_partial_unit
;
7987 /* The "pretend" language that is used if the CU doesn't declare a
7990 enum language pretend_language
;
7993 /* die_reader_func for process_psymtab_comp_unit. */
7996 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
7997 const gdb_byte
*info_ptr
,
7998 struct die_info
*comp_unit_die
,
8002 struct dwarf2_cu
*cu
= reader
->cu
;
8003 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8004 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8005 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8007 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8008 struct partial_symtab
*pst
;
8009 enum pc_bounds_kind cu_bounds_kind
;
8010 const char *filename
;
8011 struct process_psymtab_comp_unit_data
*info
8012 = (struct process_psymtab_comp_unit_data
*) data
;
8014 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8017 gdb_assert (! per_cu
->is_debug_types
);
8019 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8021 /* Allocate a new partial symbol table structure. */
8022 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8023 if (filename
== NULL
)
8026 pst
= create_partial_symtab (per_cu
, filename
);
8028 /* This must be done before calling dwarf2_build_include_psymtabs. */
8029 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8031 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8033 dwarf2_find_base_address (comp_unit_die
, cu
);
8035 /* Possibly set the default values of LOWPC and HIGHPC from
8037 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8038 &best_highpc
, cu
, pst
);
8039 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8042 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8045 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8047 /* Store the contiguous range if it is not empty; it can be
8048 empty for CUs with no code. */
8049 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8053 /* Check if comp unit has_children.
8054 If so, read the rest of the partial symbols from this comp unit.
8055 If not, there's no more debug_info for this comp unit. */
8058 struct partial_die_info
*first_die
;
8059 CORE_ADDR lowpc
, highpc
;
8061 lowpc
= ((CORE_ADDR
) -1);
8062 highpc
= ((CORE_ADDR
) 0);
8064 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8066 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8067 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8069 /* If we didn't find a lowpc, set it to highpc to avoid
8070 complaints from `maint check'. */
8071 if (lowpc
== ((CORE_ADDR
) -1))
8074 /* If the compilation unit didn't have an explicit address range,
8075 then use the information extracted from its child dies. */
8076 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8079 best_highpc
= highpc
;
8082 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8083 best_lowpc
+ baseaddr
)
8085 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8086 best_highpc
+ baseaddr
)
8089 end_psymtab_common (objfile
, pst
);
8091 if (!cu
->per_cu
->imported_symtabs_empty ())
8094 int len
= cu
->per_cu
->imported_symtabs_size ();
8096 /* Fill in 'dependencies' here; we fill in 'users' in a
8098 pst
->number_of_dependencies
= len
;
8100 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8101 for (i
= 0; i
< len
; ++i
)
8103 pst
->dependencies
[i
]
8104 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8107 cu
->per_cu
->imported_symtabs_free ();
8110 /* Get the list of files included in the current compilation unit,
8111 and build a psymtab for each of them. */
8112 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8114 if (dwarf_read_debug
)
8115 fprintf_unfiltered (gdb_stdlog
,
8116 "Psymtab for %s unit @%s: %s - %s"
8117 ", %d global, %d static syms\n",
8118 per_cu
->is_debug_types
? "type" : "comp",
8119 sect_offset_str (per_cu
->sect_off
),
8120 paddress (gdbarch
, pst
->text_low (objfile
)),
8121 paddress (gdbarch
, pst
->text_high (objfile
)),
8122 pst
->n_global_syms
, pst
->n_static_syms
);
8125 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8126 Process compilation unit THIS_CU for a psymtab. */
8129 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8130 int want_partial_unit
,
8131 enum language pretend_language
)
8133 /* If this compilation unit was already read in, free the
8134 cached copy in order to read it in again. This is
8135 necessary because we skipped some symbols when we first
8136 read in the compilation unit (see load_partial_dies).
8137 This problem could be avoided, but the benefit is unclear. */
8138 if (this_cu
->cu
!= NULL
)
8139 free_one_cached_comp_unit (this_cu
);
8141 if (this_cu
->is_debug_types
)
8142 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8143 build_type_psymtabs_reader
, NULL
);
8146 process_psymtab_comp_unit_data info
;
8147 info
.want_partial_unit
= want_partial_unit
;
8148 info
.pretend_language
= pretend_language
;
8149 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8150 process_psymtab_comp_unit_reader
, &info
);
8153 /* Age out any secondary CUs. */
8154 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8157 /* Reader function for build_type_psymtabs. */
8160 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8161 const gdb_byte
*info_ptr
,
8162 struct die_info
*type_unit_die
,
8166 struct dwarf2_per_objfile
*dwarf2_per_objfile
8167 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8168 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8169 struct dwarf2_cu
*cu
= reader
->cu
;
8170 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8171 struct signatured_type
*sig_type
;
8172 struct type_unit_group
*tu_group
;
8173 struct attribute
*attr
;
8174 struct partial_die_info
*first_die
;
8175 CORE_ADDR lowpc
, highpc
;
8176 struct partial_symtab
*pst
;
8178 gdb_assert (data
== NULL
);
8179 gdb_assert (per_cu
->is_debug_types
);
8180 sig_type
= (struct signatured_type
*) per_cu
;
8185 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8186 tu_group
= get_type_unit_group (cu
, attr
);
8188 if (tu_group
->tus
== nullptr)
8189 tu_group
->tus
= new std::vector
<signatured_type
*>;
8190 tu_group
->tus
->push_back (sig_type
);
8192 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8193 pst
= create_partial_symtab (per_cu
, "");
8196 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8198 lowpc
= (CORE_ADDR
) -1;
8199 highpc
= (CORE_ADDR
) 0;
8200 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8202 end_psymtab_common (objfile
, pst
);
8205 /* Struct used to sort TUs by their abbreviation table offset. */
8207 struct tu_abbrev_offset
8209 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8210 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8213 signatured_type
*sig_type
;
8214 sect_offset abbrev_offset
;
8217 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8220 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8221 const struct tu_abbrev_offset
&b
)
8223 return a
.abbrev_offset
< b
.abbrev_offset
;
8226 /* Efficiently read all the type units.
8227 This does the bulk of the work for build_type_psymtabs.
8229 The efficiency is because we sort TUs by the abbrev table they use and
8230 only read each abbrev table once. In one program there are 200K TUs
8231 sharing 8K abbrev tables.
8233 The main purpose of this function is to support building the
8234 dwarf2_per_objfile->type_unit_groups table.
8235 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8236 can collapse the search space by grouping them by stmt_list.
8237 The savings can be significant, in the same program from above the 200K TUs
8238 share 8K stmt_list tables.
8240 FUNC is expected to call get_type_unit_group, which will create the
8241 struct type_unit_group if necessary and add it to
8242 dwarf2_per_objfile->type_unit_groups. */
8245 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8247 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8248 abbrev_table_up abbrev_table
;
8249 sect_offset abbrev_offset
;
8251 /* It's up to the caller to not call us multiple times. */
8252 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8254 if (dwarf2_per_objfile
->all_type_units
.empty ())
8257 /* TUs typically share abbrev tables, and there can be way more TUs than
8258 abbrev tables. Sort by abbrev table to reduce the number of times we
8259 read each abbrev table in.
8260 Alternatives are to punt or to maintain a cache of abbrev tables.
8261 This is simpler and efficient enough for now.
8263 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8264 symtab to use). Typically TUs with the same abbrev offset have the same
8265 stmt_list value too so in practice this should work well.
8267 The basic algorithm here is:
8269 sort TUs by abbrev table
8270 for each TU with same abbrev table:
8271 read abbrev table if first user
8272 read TU top level DIE
8273 [IWBN if DWO skeletons had DW_AT_stmt_list]
8276 if (dwarf_read_debug
)
8277 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8279 /* Sort in a separate table to maintain the order of all_type_units
8280 for .gdb_index: TU indices directly index all_type_units. */
8281 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8282 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8284 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8285 sorted_by_abbrev
.emplace_back
8286 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8287 sig_type
->per_cu
.section
,
8288 sig_type
->per_cu
.sect_off
));
8290 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8291 sort_tu_by_abbrev_offset
);
8293 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8295 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8297 /* Switch to the next abbrev table if necessary. */
8298 if (abbrev_table
== NULL
8299 || tu
.abbrev_offset
!= abbrev_offset
)
8301 abbrev_offset
= tu
.abbrev_offset
;
8303 abbrev_table_read_table (dwarf2_per_objfile
,
8304 &dwarf2_per_objfile
->abbrev
,
8306 ++tu_stats
->nr_uniq_abbrev_tables
;
8309 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8310 0, 0, false, build_type_psymtabs_reader
, NULL
);
8314 /* Print collected type unit statistics. */
8317 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8319 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8321 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8322 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8323 dwarf2_per_objfile
->all_type_units
.size ());
8324 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8325 tu_stats
->nr_uniq_abbrev_tables
);
8326 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8327 tu_stats
->nr_symtabs
);
8328 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8329 tu_stats
->nr_symtab_sharers
);
8330 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8331 tu_stats
->nr_stmt_less_type_units
);
8332 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8333 tu_stats
->nr_all_type_units_reallocs
);
8336 /* Traversal function for build_type_psymtabs. */
8339 build_type_psymtab_dependencies (void **slot
, void *info
)
8341 struct dwarf2_per_objfile
*dwarf2_per_objfile
8342 = (struct dwarf2_per_objfile
*) info
;
8343 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8344 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8345 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8346 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8347 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8350 gdb_assert (len
> 0);
8351 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8353 pst
->number_of_dependencies
= len
;
8354 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8355 for (i
= 0; i
< len
; ++i
)
8357 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8358 gdb_assert (iter
->per_cu
.is_debug_types
);
8359 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8360 iter
->type_unit_group
= tu_group
;
8363 delete tu_group
->tus
;
8364 tu_group
->tus
= nullptr;
8369 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8370 Build partial symbol tables for the .debug_types comp-units. */
8373 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8375 if (! create_all_type_units (dwarf2_per_objfile
))
8378 build_type_psymtabs_1 (dwarf2_per_objfile
);
8381 /* Traversal function for process_skeletonless_type_unit.
8382 Read a TU in a DWO file and build partial symbols for it. */
8385 process_skeletonless_type_unit (void **slot
, void *info
)
8387 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8388 struct dwarf2_per_objfile
*dwarf2_per_objfile
8389 = (struct dwarf2_per_objfile
*) info
;
8390 struct signatured_type find_entry
, *entry
;
8392 /* If this TU doesn't exist in the global table, add it and read it in. */
8394 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8396 dwarf2_per_objfile
->signatured_types
8397 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8400 find_entry
.signature
= dwo_unit
->signature
;
8401 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8403 /* If we've already seen this type there's nothing to do. What's happening
8404 is we're doing our own version of comdat-folding here. */
8408 /* This does the job that create_all_type_units would have done for
8410 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8411 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8414 /* This does the job that build_type_psymtabs_1 would have done. */
8415 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8416 build_type_psymtabs_reader
, NULL
);
8421 /* Traversal function for process_skeletonless_type_units. */
8424 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8426 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8428 if (dwo_file
->tus
!= NULL
)
8430 htab_traverse_noresize (dwo_file
->tus
,
8431 process_skeletonless_type_unit
, info
);
8437 /* Scan all TUs of DWO files, verifying we've processed them.
8438 This is needed in case a TU was emitted without its skeleton.
8439 Note: This can't be done until we know what all the DWO files are. */
8442 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8444 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8445 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8446 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8448 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8449 process_dwo_file_for_skeletonless_type_units
,
8450 dwarf2_per_objfile
);
8454 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8457 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8459 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8461 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8466 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8468 /* Set the 'user' field only if it is not already set. */
8469 if (pst
->dependencies
[j
]->user
== NULL
)
8470 pst
->dependencies
[j
]->user
= pst
;
8475 /* Build the partial symbol table by doing a quick pass through the
8476 .debug_info and .debug_abbrev sections. */
8479 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8481 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8483 if (dwarf_read_debug
)
8485 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8486 objfile_name (objfile
));
8489 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8491 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8493 /* Any cached compilation units will be linked by the per-objfile
8494 read_in_chain. Make sure to free them when we're done. */
8495 free_cached_comp_units
freer (dwarf2_per_objfile
);
8497 build_type_psymtabs (dwarf2_per_objfile
);
8499 create_all_comp_units (dwarf2_per_objfile
);
8501 /* Create a temporary address map on a temporary obstack. We later
8502 copy this to the final obstack. */
8503 auto_obstack temp_obstack
;
8505 scoped_restore save_psymtabs_addrmap
8506 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8507 addrmap_create_mutable (&temp_obstack
));
8509 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8510 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8512 /* This has to wait until we read the CUs, we need the list of DWOs. */
8513 process_skeletonless_type_units (dwarf2_per_objfile
);
8515 /* Now that all TUs have been processed we can fill in the dependencies. */
8516 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8518 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8519 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8522 if (dwarf_read_debug
)
8523 print_tu_stats (dwarf2_per_objfile
);
8525 set_partial_user (dwarf2_per_objfile
);
8527 objfile
->partial_symtabs
->psymtabs_addrmap
8528 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8529 objfile
->partial_symtabs
->obstack ());
8530 /* At this point we want to keep the address map. */
8531 save_psymtabs_addrmap
.release ();
8533 if (dwarf_read_debug
)
8534 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8535 objfile_name (objfile
));
8538 /* die_reader_func for load_partial_comp_unit. */
8541 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8542 const gdb_byte
*info_ptr
,
8543 struct die_info
*comp_unit_die
,
8547 struct dwarf2_cu
*cu
= reader
->cu
;
8549 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8551 /* Check if comp unit has_children.
8552 If so, read the rest of the partial symbols from this comp unit.
8553 If not, there's no more debug_info for this comp unit. */
8555 load_partial_dies (reader
, info_ptr
, 0);
8558 /* Load the partial DIEs for a secondary CU into memory.
8559 This is also used when rereading a primary CU with load_all_dies. */
8562 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8564 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8565 load_partial_comp_unit_reader
, NULL
);
8569 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8570 struct dwarf2_section_info
*section
,
8571 struct dwarf2_section_info
*abbrev_section
,
8572 unsigned int is_dwz
)
8574 const gdb_byte
*info_ptr
;
8575 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8577 if (dwarf_read_debug
)
8578 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8579 get_section_name (section
),
8580 get_section_file_name (section
));
8582 dwarf2_read_section (objfile
, section
);
8584 info_ptr
= section
->buffer
;
8586 while (info_ptr
< section
->buffer
+ section
->size
)
8588 struct dwarf2_per_cu_data
*this_cu
;
8590 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8592 comp_unit_head cu_header
;
8593 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8594 abbrev_section
, info_ptr
,
8595 rcuh_kind::COMPILE
);
8597 /* Save the compilation unit for later lookup. */
8598 if (cu_header
.unit_type
!= DW_UT_type
)
8600 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8601 struct dwarf2_per_cu_data
);
8602 memset (this_cu
, 0, sizeof (*this_cu
));
8606 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8607 struct signatured_type
);
8608 memset (sig_type
, 0, sizeof (*sig_type
));
8609 sig_type
->signature
= cu_header
.signature
;
8610 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8611 this_cu
= &sig_type
->per_cu
;
8613 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8614 this_cu
->sect_off
= sect_off
;
8615 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8616 this_cu
->is_dwz
= is_dwz
;
8617 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8618 this_cu
->section
= section
;
8620 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8622 info_ptr
= info_ptr
+ this_cu
->length
;
8626 /* Create a list of all compilation units in OBJFILE.
8627 This is only done for -readnow and building partial symtabs. */
8630 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8632 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8633 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8634 &dwarf2_per_objfile
->abbrev
, 0);
8636 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8638 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8642 /* Process all loaded DIEs for compilation unit CU, starting at
8643 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8644 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8645 DW_AT_ranges). See the comments of add_partial_subprogram on how
8646 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8649 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8650 CORE_ADDR
*highpc
, int set_addrmap
,
8651 struct dwarf2_cu
*cu
)
8653 struct partial_die_info
*pdi
;
8655 /* Now, march along the PDI's, descending into ones which have
8656 interesting children but skipping the children of the other ones,
8657 until we reach the end of the compilation unit. */
8665 /* Anonymous namespaces or modules have no name but have interesting
8666 children, so we need to look at them. Ditto for anonymous
8669 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8670 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8671 || pdi
->tag
== DW_TAG_imported_unit
8672 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8676 case DW_TAG_subprogram
:
8677 case DW_TAG_inlined_subroutine
:
8678 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8680 case DW_TAG_constant
:
8681 case DW_TAG_variable
:
8682 case DW_TAG_typedef
:
8683 case DW_TAG_union_type
:
8684 if (!pdi
->is_declaration
)
8686 add_partial_symbol (pdi
, cu
);
8689 case DW_TAG_class_type
:
8690 case DW_TAG_interface_type
:
8691 case DW_TAG_structure_type
:
8692 if (!pdi
->is_declaration
)
8694 add_partial_symbol (pdi
, cu
);
8696 if ((cu
->language
== language_rust
8697 || cu
->language
== language_cplus
) && pdi
->has_children
)
8698 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8701 case DW_TAG_enumeration_type
:
8702 if (!pdi
->is_declaration
)
8703 add_partial_enumeration (pdi
, cu
);
8705 case DW_TAG_base_type
:
8706 case DW_TAG_subrange_type
:
8707 /* File scope base type definitions are added to the partial
8709 add_partial_symbol (pdi
, cu
);
8711 case DW_TAG_namespace
:
8712 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8715 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8717 case DW_TAG_imported_unit
:
8719 struct dwarf2_per_cu_data
*per_cu
;
8721 /* For now we don't handle imported units in type units. */
8722 if (cu
->per_cu
->is_debug_types
)
8724 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8725 " supported in type units [in module %s]"),
8726 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8729 per_cu
= dwarf2_find_containing_comp_unit
8730 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8731 cu
->per_cu
->dwarf2_per_objfile
);
8733 /* Go read the partial unit, if needed. */
8734 if (per_cu
->v
.psymtab
== NULL
)
8735 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8737 cu
->per_cu
->imported_symtabs_push (per_cu
);
8740 case DW_TAG_imported_declaration
:
8741 add_partial_symbol (pdi
, cu
);
8748 /* If the die has a sibling, skip to the sibling. */
8750 pdi
= pdi
->die_sibling
;
8754 /* Functions used to compute the fully scoped name of a partial DIE.
8756 Normally, this is simple. For C++, the parent DIE's fully scoped
8757 name is concatenated with "::" and the partial DIE's name.
8758 Enumerators are an exception; they use the scope of their parent
8759 enumeration type, i.e. the name of the enumeration type is not
8760 prepended to the enumerator.
8762 There are two complexities. One is DW_AT_specification; in this
8763 case "parent" means the parent of the target of the specification,
8764 instead of the direct parent of the DIE. The other is compilers
8765 which do not emit DW_TAG_namespace; in this case we try to guess
8766 the fully qualified name of structure types from their members'
8767 linkage names. This must be done using the DIE's children rather
8768 than the children of any DW_AT_specification target. We only need
8769 to do this for structures at the top level, i.e. if the target of
8770 any DW_AT_specification (if any; otherwise the DIE itself) does not
8773 /* Compute the scope prefix associated with PDI's parent, in
8774 compilation unit CU. The result will be allocated on CU's
8775 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8776 field. NULL is returned if no prefix is necessary. */
8778 partial_die_parent_scope (struct partial_die_info
*pdi
,
8779 struct dwarf2_cu
*cu
)
8781 const char *grandparent_scope
;
8782 struct partial_die_info
*parent
, *real_pdi
;
8784 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8785 then this means the parent of the specification DIE. */
8788 while (real_pdi
->has_specification
)
8790 auto res
= find_partial_die (real_pdi
->spec_offset
,
8791 real_pdi
->spec_is_dwz
, cu
);
8796 parent
= real_pdi
->die_parent
;
8800 if (parent
->scope_set
)
8801 return parent
->scope
;
8805 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8807 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8808 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8809 Work around this problem here. */
8810 if (cu
->language
== language_cplus
8811 && parent
->tag
== DW_TAG_namespace
8812 && strcmp (parent
->name
, "::") == 0
8813 && grandparent_scope
== NULL
)
8815 parent
->scope
= NULL
;
8816 parent
->scope_set
= 1;
8820 /* Nested subroutines in Fortran get a prefix. */
8821 if (pdi
->tag
== DW_TAG_enumerator
)
8822 /* Enumerators should not get the name of the enumeration as a prefix. */
8823 parent
->scope
= grandparent_scope
;
8824 else if (parent
->tag
== DW_TAG_namespace
8825 || parent
->tag
== DW_TAG_module
8826 || parent
->tag
== DW_TAG_structure_type
8827 || parent
->tag
== DW_TAG_class_type
8828 || parent
->tag
== DW_TAG_interface_type
8829 || parent
->tag
== DW_TAG_union_type
8830 || parent
->tag
== DW_TAG_enumeration_type
8831 || (cu
->language
== language_fortran
8832 && parent
->tag
== DW_TAG_subprogram
8833 && pdi
->tag
== DW_TAG_subprogram
))
8835 if (grandparent_scope
== NULL
)
8836 parent
->scope
= parent
->name
;
8838 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8840 parent
->name
, 0, cu
);
8844 /* FIXME drow/2004-04-01: What should we be doing with
8845 function-local names? For partial symbols, we should probably be
8847 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8848 dwarf_tag_name (parent
->tag
),
8849 sect_offset_str (pdi
->sect_off
));
8850 parent
->scope
= grandparent_scope
;
8853 parent
->scope_set
= 1;
8854 return parent
->scope
;
8857 /* Return the fully scoped name associated with PDI, from compilation unit
8858 CU. The result will be allocated with malloc. */
8861 partial_die_full_name (struct partial_die_info
*pdi
,
8862 struct dwarf2_cu
*cu
)
8864 const char *parent_scope
;
8866 /* If this is a template instantiation, we can not work out the
8867 template arguments from partial DIEs. So, unfortunately, we have
8868 to go through the full DIEs. At least any work we do building
8869 types here will be reused if full symbols are loaded later. */
8870 if (pdi
->has_template_arguments
)
8874 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8876 struct die_info
*die
;
8877 struct attribute attr
;
8878 struct dwarf2_cu
*ref_cu
= cu
;
8880 /* DW_FORM_ref_addr is using section offset. */
8881 attr
.name
= (enum dwarf_attribute
) 0;
8882 attr
.form
= DW_FORM_ref_addr
;
8883 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8884 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8886 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8890 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8891 if (parent_scope
== NULL
)
8894 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
8898 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8900 struct dwarf2_per_objfile
*dwarf2_per_objfile
8901 = cu
->per_cu
->dwarf2_per_objfile
;
8902 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8903 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8905 const char *actual_name
= NULL
;
8907 char *built_actual_name
;
8909 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8911 built_actual_name
= partial_die_full_name (pdi
, cu
);
8912 if (built_actual_name
!= NULL
)
8913 actual_name
= built_actual_name
;
8915 if (actual_name
== NULL
)
8916 actual_name
= pdi
->name
;
8920 case DW_TAG_inlined_subroutine
:
8921 case DW_TAG_subprogram
:
8922 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8924 if (pdi
->is_external
8925 || cu
->language
== language_ada
8926 || (cu
->language
== language_fortran
8927 && pdi
->die_parent
!= NULL
8928 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8930 /* Normally, only "external" DIEs are part of the global scope.
8931 But in Ada and Fortran, we want to be able to access nested
8932 procedures globally. So all Ada and Fortran subprograms are
8933 stored in the global scope. */
8934 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8935 built_actual_name
!= NULL
,
8936 VAR_DOMAIN
, LOC_BLOCK
,
8937 SECT_OFF_TEXT (objfile
),
8938 psymbol_placement::GLOBAL
,
8940 cu
->language
, objfile
);
8944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8945 built_actual_name
!= NULL
,
8946 VAR_DOMAIN
, LOC_BLOCK
,
8947 SECT_OFF_TEXT (objfile
),
8948 psymbol_placement::STATIC
,
8949 addr
, cu
->language
, objfile
);
8952 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8953 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8955 case DW_TAG_constant
:
8956 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8957 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8958 -1, (pdi
->is_external
8959 ? psymbol_placement::GLOBAL
8960 : psymbol_placement::STATIC
),
8961 0, cu
->language
, objfile
);
8963 case DW_TAG_variable
:
8965 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
8969 && !dwarf2_per_objfile
->has_section_at_zero
)
8971 /* A global or static variable may also have been stripped
8972 out by the linker if unused, in which case its address
8973 will be nullified; do not add such variables into partial
8974 symbol table then. */
8976 else if (pdi
->is_external
)
8979 Don't enter into the minimal symbol tables as there is
8980 a minimal symbol table entry from the ELF symbols already.
8981 Enter into partial symbol table if it has a location
8982 descriptor or a type.
8983 If the location descriptor is missing, new_symbol will create
8984 a LOC_UNRESOLVED symbol, the address of the variable will then
8985 be determined from the minimal symbol table whenever the variable
8987 The address for the partial symbol table entry is not
8988 used by GDB, but it comes in handy for debugging partial symbol
8991 if (pdi
->d
.locdesc
|| pdi
->has_type
)
8992 add_psymbol_to_list (actual_name
, strlen (actual_name
),
8993 built_actual_name
!= NULL
,
8994 VAR_DOMAIN
, LOC_STATIC
,
8995 SECT_OFF_TEXT (objfile
),
8996 psymbol_placement::GLOBAL
,
8997 addr
, cu
->language
, objfile
);
9001 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9003 /* Static Variable. Skip symbols whose value we cannot know (those
9004 without location descriptors or constant values). */
9005 if (!has_loc
&& !pdi
->has_const_value
)
9007 xfree (built_actual_name
);
9011 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9012 built_actual_name
!= NULL
,
9013 VAR_DOMAIN
, LOC_STATIC
,
9014 SECT_OFF_TEXT (objfile
),
9015 psymbol_placement::STATIC
,
9017 cu
->language
, objfile
);
9020 case DW_TAG_typedef
:
9021 case DW_TAG_base_type
:
9022 case DW_TAG_subrange_type
:
9023 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9024 built_actual_name
!= NULL
,
9025 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9026 psymbol_placement::STATIC
,
9027 0, cu
->language
, objfile
);
9029 case DW_TAG_imported_declaration
:
9030 case DW_TAG_namespace
:
9031 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9032 built_actual_name
!= NULL
,
9033 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9034 psymbol_placement::GLOBAL
,
9035 0, cu
->language
, objfile
);
9038 /* With Fortran 77 there might be a "BLOCK DATA" module
9039 available without any name. If so, we skip the module as it
9040 doesn't bring any value. */
9041 if (actual_name
!= nullptr)
9042 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9043 built_actual_name
!= NULL
,
9044 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9045 psymbol_placement::GLOBAL
,
9046 0, cu
->language
, objfile
);
9048 case DW_TAG_class_type
:
9049 case DW_TAG_interface_type
:
9050 case DW_TAG_structure_type
:
9051 case DW_TAG_union_type
:
9052 case DW_TAG_enumeration_type
:
9053 /* Skip external references. The DWARF standard says in the section
9054 about "Structure, Union, and Class Type Entries": "An incomplete
9055 structure, union or class type is represented by a structure,
9056 union or class entry that does not have a byte size attribute
9057 and that has a DW_AT_declaration attribute." */
9058 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9060 xfree (built_actual_name
);
9064 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9065 static vs. global. */
9066 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9067 built_actual_name
!= NULL
,
9068 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9069 cu
->language
== language_cplus
9070 ? psymbol_placement::GLOBAL
9071 : psymbol_placement::STATIC
,
9072 0, cu
->language
, objfile
);
9075 case DW_TAG_enumerator
:
9076 add_psymbol_to_list (actual_name
, strlen (actual_name
),
9077 built_actual_name
!= NULL
,
9078 VAR_DOMAIN
, LOC_CONST
, -1,
9079 cu
->language
== language_cplus
9080 ? psymbol_placement::GLOBAL
9081 : psymbol_placement::STATIC
,
9082 0, cu
->language
, objfile
);
9088 xfree (built_actual_name
);
9091 /* Read a partial die corresponding to a namespace; also, add a symbol
9092 corresponding to that namespace to the symbol table. NAMESPACE is
9093 the name of the enclosing namespace. */
9096 add_partial_namespace (struct partial_die_info
*pdi
,
9097 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9098 int set_addrmap
, struct dwarf2_cu
*cu
)
9100 /* Add a symbol for the namespace. */
9102 add_partial_symbol (pdi
, cu
);
9104 /* Now scan partial symbols in that namespace. */
9106 if (pdi
->has_children
)
9107 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9110 /* Read a partial die corresponding to a Fortran module. */
9113 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9114 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9116 /* Add a symbol for the namespace. */
9118 add_partial_symbol (pdi
, cu
);
9120 /* Now scan partial symbols in that module. */
9122 if (pdi
->has_children
)
9123 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9126 /* Read a partial die corresponding to a subprogram or an inlined
9127 subprogram and create a partial symbol for that subprogram.
9128 When the CU language allows it, this routine also defines a partial
9129 symbol for each nested subprogram that this subprogram contains.
9130 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9131 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9133 PDI may also be a lexical block, in which case we simply search
9134 recursively for subprograms defined inside that lexical block.
9135 Again, this is only performed when the CU language allows this
9136 type of definitions. */
9139 add_partial_subprogram (struct partial_die_info
*pdi
,
9140 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9141 int set_addrmap
, struct dwarf2_cu
*cu
)
9143 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9145 if (pdi
->has_pc_info
)
9147 if (pdi
->lowpc
< *lowpc
)
9148 *lowpc
= pdi
->lowpc
;
9149 if (pdi
->highpc
> *highpc
)
9150 *highpc
= pdi
->highpc
;
9153 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9154 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9156 CORE_ADDR this_highpc
;
9157 CORE_ADDR this_lowpc
;
9159 baseaddr
= ANOFFSET (objfile
->section_offsets
,
9160 SECT_OFF_TEXT (objfile
));
9162 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9163 pdi
->lowpc
+ baseaddr
)
9166 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9167 pdi
->highpc
+ baseaddr
)
9169 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9170 this_lowpc
, this_highpc
- 1,
9171 cu
->per_cu
->v
.psymtab
);
9175 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9177 if (!pdi
->is_declaration
)
9178 /* Ignore subprogram DIEs that do not have a name, they are
9179 illegal. Do not emit a complaint at this point, we will
9180 do so when we convert this psymtab into a symtab. */
9182 add_partial_symbol (pdi
, cu
);
9186 if (! pdi
->has_children
)
9189 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9191 pdi
= pdi
->die_child
;
9195 if (pdi
->tag
== DW_TAG_subprogram
9196 || pdi
->tag
== DW_TAG_inlined_subroutine
9197 || pdi
->tag
== DW_TAG_lexical_block
)
9198 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9199 pdi
= pdi
->die_sibling
;
9204 /* Read a partial die corresponding to an enumeration type. */
9207 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9208 struct dwarf2_cu
*cu
)
9210 struct partial_die_info
*pdi
;
9212 if (enum_pdi
->name
!= NULL
)
9213 add_partial_symbol (enum_pdi
, cu
);
9215 pdi
= enum_pdi
->die_child
;
9218 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9219 complaint (_("malformed enumerator DIE ignored"));
9221 add_partial_symbol (pdi
, cu
);
9222 pdi
= pdi
->die_sibling
;
9226 /* Return the initial uleb128 in the die at INFO_PTR. */
9229 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9231 unsigned int bytes_read
;
9233 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9236 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9237 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9239 Return the corresponding abbrev, or NULL if the number is zero (indicating
9240 an empty DIE). In either case *BYTES_READ will be set to the length of
9241 the initial number. */
9243 static struct abbrev_info
*
9244 peek_die_abbrev (const die_reader_specs
&reader
,
9245 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9247 dwarf2_cu
*cu
= reader
.cu
;
9248 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9249 unsigned int abbrev_number
9250 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9252 if (abbrev_number
== 0)
9255 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9258 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9259 " at offset %s [in module %s]"),
9260 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9261 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9267 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9268 Returns a pointer to the end of a series of DIEs, terminated by an empty
9269 DIE. Any children of the skipped DIEs will also be skipped. */
9271 static const gdb_byte
*
9272 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9276 unsigned int bytes_read
;
9277 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9280 return info_ptr
+ bytes_read
;
9282 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9286 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9287 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9288 abbrev corresponding to that skipped uleb128 should be passed in
9289 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9292 static const gdb_byte
*
9293 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9294 struct abbrev_info
*abbrev
)
9296 unsigned int bytes_read
;
9297 struct attribute attr
;
9298 bfd
*abfd
= reader
->abfd
;
9299 struct dwarf2_cu
*cu
= reader
->cu
;
9300 const gdb_byte
*buffer
= reader
->buffer
;
9301 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9302 unsigned int form
, i
;
9304 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9306 /* The only abbrev we care about is DW_AT_sibling. */
9307 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9309 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
);
9310 if (attr
.form
== DW_FORM_ref_addr
)
9311 complaint (_("ignoring absolute DW_AT_sibling"));
9314 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9315 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9317 if (sibling_ptr
< info_ptr
)
9318 complaint (_("DW_AT_sibling points backwards"));
9319 else if (sibling_ptr
> reader
->buffer_end
)
9320 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9326 /* If it isn't DW_AT_sibling, skip this attribute. */
9327 form
= abbrev
->attrs
[i
].form
;
9331 case DW_FORM_ref_addr
:
9332 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9333 and later it is offset sized. */
9334 if (cu
->header
.version
== 2)
9335 info_ptr
+= cu
->header
.addr_size
;
9337 info_ptr
+= cu
->header
.offset_size
;
9339 case DW_FORM_GNU_ref_alt
:
9340 info_ptr
+= cu
->header
.offset_size
;
9343 info_ptr
+= cu
->header
.addr_size
;
9351 case DW_FORM_flag_present
:
9352 case DW_FORM_implicit_const
:
9369 case DW_FORM_ref_sig8
:
9372 case DW_FORM_data16
:
9375 case DW_FORM_string
:
9376 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9377 info_ptr
+= bytes_read
;
9379 case DW_FORM_sec_offset
:
9381 case DW_FORM_GNU_strp_alt
:
9382 info_ptr
+= cu
->header
.offset_size
;
9384 case DW_FORM_exprloc
:
9386 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9387 info_ptr
+= bytes_read
;
9389 case DW_FORM_block1
:
9390 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9392 case DW_FORM_block2
:
9393 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9395 case DW_FORM_block4
:
9396 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9402 case DW_FORM_ref_udata
:
9403 case DW_FORM_GNU_addr_index
:
9404 case DW_FORM_GNU_str_index
:
9405 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9407 case DW_FORM_indirect
:
9408 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9409 info_ptr
+= bytes_read
;
9410 /* We need to continue parsing from here, so just go back to
9412 goto skip_attribute
;
9415 error (_("Dwarf Error: Cannot handle %s "
9416 "in DWARF reader [in module %s]"),
9417 dwarf_form_name (form
),
9418 bfd_get_filename (abfd
));
9422 if (abbrev
->has_children
)
9423 return skip_children (reader
, info_ptr
);
9428 /* Locate ORIG_PDI's sibling.
9429 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9431 static const gdb_byte
*
9432 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9433 struct partial_die_info
*orig_pdi
,
9434 const gdb_byte
*info_ptr
)
9436 /* Do we know the sibling already? */
9438 if (orig_pdi
->sibling
)
9439 return orig_pdi
->sibling
;
9441 /* Are there any children to deal with? */
9443 if (!orig_pdi
->has_children
)
9446 /* Skip the children the long way. */
9448 return skip_children (reader
, info_ptr
);
9451 /* Expand this partial symbol table into a full symbol table. SELF is
9455 dwarf2_read_symtab (struct partial_symtab
*self
,
9456 struct objfile
*objfile
)
9458 struct dwarf2_per_objfile
*dwarf2_per_objfile
9459 = get_dwarf2_per_objfile (objfile
);
9463 warning (_("bug: psymtab for %s is already read in."),
9470 printf_filtered (_("Reading in symbols for %s..."),
9472 gdb_flush (gdb_stdout
);
9475 /* If this psymtab is constructed from a debug-only objfile, the
9476 has_section_at_zero flag will not necessarily be correct. We
9477 can get the correct value for this flag by looking at the data
9478 associated with the (presumably stripped) associated objfile. */
9479 if (objfile
->separate_debug_objfile_backlink
)
9481 struct dwarf2_per_objfile
*dpo_backlink
9482 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9484 dwarf2_per_objfile
->has_section_at_zero
9485 = dpo_backlink
->has_section_at_zero
;
9488 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9490 psymtab_to_symtab_1 (self
);
9492 /* Finish up the debug error message. */
9494 printf_filtered (_("done.\n"));
9497 process_cu_includes (dwarf2_per_objfile
);
9500 /* Reading in full CUs. */
9502 /* Add PER_CU to the queue. */
9505 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9506 enum language pretend_language
)
9508 struct dwarf2_queue_item
*item
;
9511 item
= XNEW (struct dwarf2_queue_item
);
9512 item
->per_cu
= per_cu
;
9513 item
->pretend_language
= pretend_language
;
9516 if (dwarf2_queue
== NULL
)
9517 dwarf2_queue
= item
;
9519 dwarf2_queue_tail
->next
= item
;
9521 dwarf2_queue_tail
= item
;
9524 /* If PER_CU is not yet queued, add it to the queue.
9525 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9527 The result is non-zero if PER_CU was queued, otherwise the result is zero
9528 meaning either PER_CU is already queued or it is already loaded.
9530 N.B. There is an invariant here that if a CU is queued then it is loaded.
9531 The caller is required to load PER_CU if we return non-zero. */
9534 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9535 struct dwarf2_per_cu_data
*per_cu
,
9536 enum language pretend_language
)
9538 /* We may arrive here during partial symbol reading, if we need full
9539 DIEs to process an unusual case (e.g. template arguments). Do
9540 not queue PER_CU, just tell our caller to load its DIEs. */
9541 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9543 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9548 /* Mark the dependence relation so that we don't flush PER_CU
9550 if (dependent_cu
!= NULL
)
9551 dwarf2_add_dependence (dependent_cu
, per_cu
);
9553 /* If it's already on the queue, we have nothing to do. */
9557 /* If the compilation unit is already loaded, just mark it as
9559 if (per_cu
->cu
!= NULL
)
9561 per_cu
->cu
->last_used
= 0;
9565 /* Add it to the queue. */
9566 queue_comp_unit (per_cu
, pretend_language
);
9571 /* Process the queue. */
9574 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9576 struct dwarf2_queue_item
*item
, *next_item
;
9578 if (dwarf_read_debug
)
9580 fprintf_unfiltered (gdb_stdlog
,
9581 "Expanding one or more symtabs of objfile %s ...\n",
9582 objfile_name (dwarf2_per_objfile
->objfile
));
9585 /* The queue starts out with one item, but following a DIE reference
9586 may load a new CU, adding it to the end of the queue. */
9587 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9589 if ((dwarf2_per_objfile
->using_index
9590 ? !item
->per_cu
->v
.quick
->compunit_symtab
9591 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9592 /* Skip dummy CUs. */
9593 && item
->per_cu
->cu
!= NULL
)
9595 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9596 unsigned int debug_print_threshold
;
9599 if (per_cu
->is_debug_types
)
9601 struct signatured_type
*sig_type
=
9602 (struct signatured_type
*) per_cu
;
9604 sprintf (buf
, "TU %s at offset %s",
9605 hex_string (sig_type
->signature
),
9606 sect_offset_str (per_cu
->sect_off
));
9607 /* There can be 100s of TUs.
9608 Only print them in verbose mode. */
9609 debug_print_threshold
= 2;
9613 sprintf (buf
, "CU at offset %s",
9614 sect_offset_str (per_cu
->sect_off
));
9615 debug_print_threshold
= 1;
9618 if (dwarf_read_debug
>= debug_print_threshold
)
9619 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9621 if (per_cu
->is_debug_types
)
9622 process_full_type_unit (per_cu
, item
->pretend_language
);
9624 process_full_comp_unit (per_cu
, item
->pretend_language
);
9626 if (dwarf_read_debug
>= debug_print_threshold
)
9627 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9630 item
->per_cu
->queued
= 0;
9631 next_item
= item
->next
;
9635 dwarf2_queue_tail
= NULL
;
9637 if (dwarf_read_debug
)
9639 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9640 objfile_name (dwarf2_per_objfile
->objfile
));
9644 /* Read in full symbols for PST, and anything it depends on. */
9647 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9649 struct dwarf2_per_cu_data
*per_cu
;
9655 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9656 if (!pst
->dependencies
[i
]->readin
9657 && pst
->dependencies
[i
]->user
== NULL
)
9659 /* Inform about additional files that need to be read in. */
9662 /* FIXME: i18n: Need to make this a single string. */
9663 fputs_filtered (" ", gdb_stdout
);
9665 fputs_filtered ("and ", gdb_stdout
);
9667 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9668 wrap_here (""); /* Flush output. */
9669 gdb_flush (gdb_stdout
);
9671 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9674 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9678 /* It's an include file, no symbols to read for it.
9679 Everything is in the parent symtab. */
9684 dw2_do_instantiate_symtab (per_cu
, false);
9687 /* Trivial hash function for die_info: the hash value of a DIE
9688 is its offset in .debug_info for this objfile. */
9691 die_hash (const void *item
)
9693 const struct die_info
*die
= (const struct die_info
*) item
;
9695 return to_underlying (die
->sect_off
);
9698 /* Trivial comparison function for die_info structures: two DIEs
9699 are equal if they have the same offset. */
9702 die_eq (const void *item_lhs
, const void *item_rhs
)
9704 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9705 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9707 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9710 /* die_reader_func for load_full_comp_unit.
9711 This is identical to read_signatured_type_reader,
9712 but is kept separate for now. */
9715 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9716 const gdb_byte
*info_ptr
,
9717 struct die_info
*comp_unit_die
,
9721 struct dwarf2_cu
*cu
= reader
->cu
;
9722 enum language
*language_ptr
= (enum language
*) data
;
9724 gdb_assert (cu
->die_hash
== NULL
);
9726 htab_create_alloc_ex (cu
->header
.length
/ 12,
9730 &cu
->comp_unit_obstack
,
9731 hashtab_obstack_allocate
,
9732 dummy_obstack_deallocate
);
9735 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9736 &info_ptr
, comp_unit_die
);
9737 cu
->dies
= comp_unit_die
;
9738 /* comp_unit_die is not stored in die_hash, no need. */
9740 /* We try not to read any attributes in this function, because not
9741 all CUs needed for references have been loaded yet, and symbol
9742 table processing isn't initialized. But we have to set the CU language,
9743 or we won't be able to build types correctly.
9744 Similarly, if we do not read the producer, we can not apply
9745 producer-specific interpretation. */
9746 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9749 /* Load the DIEs associated with PER_CU into memory. */
9752 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9754 enum language pretend_language
)
9756 gdb_assert (! this_cu
->is_debug_types
);
9758 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9759 load_full_comp_unit_reader
, &pretend_language
);
9762 /* Add a DIE to the delayed physname list. */
9765 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9766 const char *name
, struct die_info
*die
,
9767 struct dwarf2_cu
*cu
)
9769 struct delayed_method_info mi
;
9771 mi
.fnfield_index
= fnfield_index
;
9775 cu
->method_list
.push_back (mi
);
9778 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9779 "const" / "volatile". If so, decrements LEN by the length of the
9780 modifier and return true. Otherwise return false. */
9784 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9786 size_t mod_len
= sizeof (mod
) - 1;
9787 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9795 /* Compute the physnames of any methods on the CU's method list.
9797 The computation of method physnames is delayed in order to avoid the
9798 (bad) condition that one of the method's formal parameters is of an as yet
9802 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9804 /* Only C++ delays computing physnames. */
9805 if (cu
->method_list
.empty ())
9807 gdb_assert (cu
->language
== language_cplus
);
9809 for (const delayed_method_info
&mi
: cu
->method_list
)
9811 const char *physname
;
9812 struct fn_fieldlist
*fn_flp
9813 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9814 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9815 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9816 = physname
? physname
: "";
9818 /* Since there's no tag to indicate whether a method is a
9819 const/volatile overload, extract that information out of the
9821 if (physname
!= NULL
)
9823 size_t len
= strlen (physname
);
9827 if (physname
[len
] == ')') /* shortcut */
9829 else if (check_modifier (physname
, len
, " const"))
9830 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9831 else if (check_modifier (physname
, len
, " volatile"))
9832 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9839 /* The list is no longer needed. */
9840 cu
->method_list
.clear ();
9843 /* Go objects should be embedded in a DW_TAG_module DIE,
9844 and it's not clear if/how imported objects will appear.
9845 To keep Go support simple until that's worked out,
9846 go back through what we've read and create something usable.
9847 We could do this while processing each DIE, and feels kinda cleaner,
9848 but that way is more invasive.
9849 This is to, for example, allow the user to type "p var" or "b main"
9850 without having to specify the package name, and allow lookups
9851 of module.object to work in contexts that use the expression
9855 fixup_go_packaging (struct dwarf2_cu
*cu
)
9857 char *package_name
= NULL
;
9858 struct pending
*list
;
9861 for (list
= *cu
->get_builder ()->get_global_symbols ();
9865 for (i
= 0; i
< list
->nsyms
; ++i
)
9867 struct symbol
*sym
= list
->symbol
[i
];
9869 if (SYMBOL_LANGUAGE (sym
) == language_go
9870 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9872 char *this_package_name
= go_symbol_package_name (sym
);
9874 if (this_package_name
== NULL
)
9876 if (package_name
== NULL
)
9877 package_name
= this_package_name
;
9880 struct objfile
*objfile
9881 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9882 if (strcmp (package_name
, this_package_name
) != 0)
9883 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9884 (symbol_symtab (sym
) != NULL
9885 ? symtab_to_filename_for_display
9886 (symbol_symtab (sym
))
9887 : objfile_name (objfile
)),
9888 this_package_name
, package_name
);
9889 xfree (this_package_name
);
9895 if (package_name
!= NULL
)
9897 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9898 const char *saved_package_name
9899 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
);
9900 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9901 saved_package_name
);
9904 sym
= allocate_symbol (objfile
);
9905 SYMBOL_SET_LANGUAGE (sym
, language_go
, &objfile
->objfile_obstack
);
9906 SYMBOL_SET_NAMES (sym
, saved_package_name
,
9907 strlen (saved_package_name
), 0, objfile
);
9908 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9909 e.g., "main" finds the "main" module and not C's main(). */
9910 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9911 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9912 SYMBOL_TYPE (sym
) = type
;
9914 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9916 xfree (package_name
);
9920 /* Allocate a fully-qualified name consisting of the two parts on the
9924 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9926 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9929 /* A helper that allocates a struct discriminant_info to attach to a
9932 static struct discriminant_info
*
9933 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9936 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9937 gdb_assert (discriminant_index
== -1
9938 || (discriminant_index
>= 0
9939 && discriminant_index
< TYPE_NFIELDS (type
)));
9940 gdb_assert (default_index
== -1
9941 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9943 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9945 struct discriminant_info
*disc
9946 = ((struct discriminant_info
*)
9948 offsetof (struct discriminant_info
, discriminants
)
9949 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9950 disc
->default_index
= default_index
;
9951 disc
->discriminant_index
= discriminant_index
;
9953 struct dynamic_prop prop
;
9954 prop
.kind
= PROP_UNDEFINED
;
9955 prop
.data
.baton
= disc
;
9957 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9962 /* Some versions of rustc emitted enums in an unusual way.
9964 Ordinary enums were emitted as unions. The first element of each
9965 structure in the union was named "RUST$ENUM$DISR". This element
9966 held the discriminant.
9968 These versions of Rust also implemented the "non-zero"
9969 optimization. When the enum had two values, and one is empty and
9970 the other holds a pointer that cannot be zero, the pointer is used
9971 as the discriminant, with a zero value meaning the empty variant.
9972 Here, the union's first member is of the form
9973 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9974 where the fieldnos are the indices of the fields that should be
9975 traversed in order to find the field (which may be several fields deep)
9976 and the variantname is the name of the variant of the case when the
9979 This function recognizes whether TYPE is of one of these forms,
9980 and, if so, smashes it to be a variant type. */
9983 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9985 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9987 /* We don't need to deal with empty enums. */
9988 if (TYPE_NFIELDS (type
) == 0)
9991 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9992 if (TYPE_NFIELDS (type
) == 1
9993 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9995 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
9997 /* Decode the field name to find the offset of the
9999 ULONGEST bit_offset
= 0;
10000 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10001 while (name
[0] >= '0' && name
[0] <= '9')
10004 unsigned long index
= strtoul (name
, &tail
, 10);
10007 || index
>= TYPE_NFIELDS (field_type
)
10008 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10009 != FIELD_LOC_KIND_BITPOS
))
10011 complaint (_("Could not parse Rust enum encoding string \"%s\""
10013 TYPE_FIELD_NAME (type
, 0),
10014 objfile_name (objfile
));
10019 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10020 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10023 /* Make a union to hold the variants. */
10024 struct type
*union_type
= alloc_type (objfile
);
10025 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10026 TYPE_NFIELDS (union_type
) = 3;
10027 TYPE_FIELDS (union_type
)
10028 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10029 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10030 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10032 /* Put the discriminant must at index 0. */
10033 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10034 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10035 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10036 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10038 /* The order of fields doesn't really matter, so put the real
10039 field at index 1 and the data-less field at index 2. */
10040 struct discriminant_info
*disc
10041 = alloc_discriminant_info (union_type
, 0, 1);
10042 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10043 TYPE_FIELD_NAME (union_type
, 1)
10044 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10045 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10046 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10047 TYPE_FIELD_NAME (union_type
, 1));
10049 const char *dataless_name
10050 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10052 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10054 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10055 /* NAME points into the original discriminant name, which
10056 already has the correct lifetime. */
10057 TYPE_FIELD_NAME (union_type
, 2) = name
;
10058 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10059 disc
->discriminants
[2] = 0;
10061 /* Smash this type to be a structure type. We have to do this
10062 because the type has already been recorded. */
10063 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10064 TYPE_NFIELDS (type
) = 1;
10066 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10068 /* Install the variant part. */
10069 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10070 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10071 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10073 /* A union with a single anonymous field is probably an old-style
10074 univariant enum. */
10075 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10077 /* Smash this type to be a structure type. We have to do this
10078 because the type has already been recorded. */
10079 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10081 /* Make a union to hold the variants. */
10082 struct type
*union_type
= alloc_type (objfile
);
10083 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10084 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10085 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10086 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10087 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10089 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10090 const char *variant_name
10091 = rust_last_path_segment (TYPE_NAME (field_type
));
10092 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10093 TYPE_NAME (field_type
)
10094 = rust_fully_qualify (&objfile
->objfile_obstack
,
10095 TYPE_NAME (type
), variant_name
);
10097 /* Install the union in the outer struct type. */
10098 TYPE_NFIELDS (type
) = 1;
10100 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10101 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10102 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10103 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10105 alloc_discriminant_info (union_type
, -1, 0);
10109 struct type
*disr_type
= nullptr;
10110 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10112 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10114 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10116 /* All fields of a true enum will be structs. */
10119 else if (TYPE_NFIELDS (disr_type
) == 0)
10121 /* Could be data-less variant, so keep going. */
10122 disr_type
= nullptr;
10124 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10125 "RUST$ENUM$DISR") != 0)
10127 /* Not a Rust enum. */
10137 /* If we got here without a discriminant, then it's probably
10139 if (disr_type
== nullptr)
10142 /* Smash this type to be a structure type. We have to do this
10143 because the type has already been recorded. */
10144 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10146 /* Make a union to hold the variants. */
10147 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10148 struct type
*union_type
= alloc_type (objfile
);
10149 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10150 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10151 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10152 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10153 TYPE_FIELDS (union_type
)
10154 = (struct field
*) TYPE_ZALLOC (union_type
,
10155 (TYPE_NFIELDS (union_type
)
10156 * sizeof (struct field
)));
10158 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10159 TYPE_NFIELDS (type
) * sizeof (struct field
));
10161 /* Install the discriminant at index 0 in the union. */
10162 TYPE_FIELD (union_type
, 0) = *disr_field
;
10163 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10164 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10166 /* Install the union in the outer struct type. */
10167 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10168 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10169 TYPE_NFIELDS (type
) = 1;
10171 /* Set the size and offset of the union type. */
10172 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10174 /* We need a way to find the correct discriminant given a
10175 variant name. For convenience we build a map here. */
10176 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10177 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10178 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10180 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10183 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10184 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10188 int n_fields
= TYPE_NFIELDS (union_type
);
10189 struct discriminant_info
*disc
10190 = alloc_discriminant_info (union_type
, 0, -1);
10191 /* Skip the discriminant here. */
10192 for (int i
= 1; i
< n_fields
; ++i
)
10194 /* Find the final word in the name of this variant's type.
10195 That name can be used to look up the correct
10197 const char *variant_name
10198 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10201 auto iter
= discriminant_map
.find (variant_name
);
10202 if (iter
!= discriminant_map
.end ())
10203 disc
->discriminants
[i
] = iter
->second
;
10205 /* Remove the discriminant field, if it exists. */
10206 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10207 if (TYPE_NFIELDS (sub_type
) > 0)
10209 --TYPE_NFIELDS (sub_type
);
10210 ++TYPE_FIELDS (sub_type
);
10212 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10213 TYPE_NAME (sub_type
)
10214 = rust_fully_qualify (&objfile
->objfile_obstack
,
10215 TYPE_NAME (type
), variant_name
);
10220 /* Rewrite some Rust unions to be structures with variants parts. */
10223 rust_union_quirks (struct dwarf2_cu
*cu
)
10225 gdb_assert (cu
->language
== language_rust
);
10226 for (type
*type_
: cu
->rust_unions
)
10227 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10228 /* We don't need this any more. */
10229 cu
->rust_unions
.clear ();
10232 /* Return the symtab for PER_CU. This works properly regardless of
10233 whether we're using the index or psymtabs. */
10235 static struct compunit_symtab
*
10236 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10238 return (per_cu
->dwarf2_per_objfile
->using_index
10239 ? per_cu
->v
.quick
->compunit_symtab
10240 : per_cu
->v
.psymtab
->compunit_symtab
);
10243 /* A helper function for computing the list of all symbol tables
10244 included by PER_CU. */
10247 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10248 htab_t all_children
, htab_t all_type_symtabs
,
10249 struct dwarf2_per_cu_data
*per_cu
,
10250 struct compunit_symtab
*immediate_parent
)
10253 struct compunit_symtab
*cust
;
10255 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10258 /* This inclusion and its children have been processed. */
10263 /* Only add a CU if it has a symbol table. */
10264 cust
= get_compunit_symtab (per_cu
);
10267 /* If this is a type unit only add its symbol table if we haven't
10268 seen it yet (type unit per_cu's can share symtabs). */
10269 if (per_cu
->is_debug_types
)
10271 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10275 result
->push_back (cust
);
10276 if (cust
->user
== NULL
)
10277 cust
->user
= immediate_parent
;
10282 result
->push_back (cust
);
10283 if (cust
->user
== NULL
)
10284 cust
->user
= immediate_parent
;
10288 if (!per_cu
->imported_symtabs_empty ())
10289 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10291 recursively_compute_inclusions (result
, all_children
,
10292 all_type_symtabs
, ptr
, cust
);
10296 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10300 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10302 gdb_assert (! per_cu
->is_debug_types
);
10304 if (!per_cu
->imported_symtabs_empty ())
10307 std::vector
<compunit_symtab
*> result_symtabs
;
10308 htab_t all_children
, all_type_symtabs
;
10309 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10311 /* If we don't have a symtab, we can just skip this case. */
10315 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10316 NULL
, xcalloc
, xfree
);
10317 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10318 NULL
, xcalloc
, xfree
);
10320 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10322 recursively_compute_inclusions (&result_symtabs
, all_children
,
10323 all_type_symtabs
, ptr
, cust
);
10326 /* Now we have a transitive closure of all the included symtabs. */
10327 len
= result_symtabs
.size ();
10329 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10330 struct compunit_symtab
*, len
+ 1);
10331 memcpy (cust
->includes
, result_symtabs
.data (),
10332 len
* sizeof (compunit_symtab
*));
10333 cust
->includes
[len
] = NULL
;
10335 htab_delete (all_children
);
10336 htab_delete (all_type_symtabs
);
10340 /* Compute the 'includes' field for the symtabs of all the CUs we just
10344 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10346 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10348 if (! iter
->is_debug_types
)
10349 compute_compunit_symtab_includes (iter
);
10352 dwarf2_per_objfile
->just_read_cus
.clear ();
10355 /* Generate full symbol information for PER_CU, whose DIEs have
10356 already been loaded into memory. */
10359 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10360 enum language pretend_language
)
10362 struct dwarf2_cu
*cu
= per_cu
->cu
;
10363 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10364 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10365 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10366 CORE_ADDR lowpc
, highpc
;
10367 struct compunit_symtab
*cust
;
10368 CORE_ADDR baseaddr
;
10369 struct block
*static_block
;
10372 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10374 /* Clear the list here in case something was left over. */
10375 cu
->method_list
.clear ();
10377 cu
->language
= pretend_language
;
10378 cu
->language_defn
= language_def (cu
->language
);
10380 /* Do line number decoding in read_file_scope () */
10381 process_die (cu
->dies
, cu
);
10383 /* For now fudge the Go package. */
10384 if (cu
->language
== language_go
)
10385 fixup_go_packaging (cu
);
10387 /* Now that we have processed all the DIEs in the CU, all the types
10388 should be complete, and it should now be safe to compute all of the
10390 compute_delayed_physnames (cu
);
10392 if (cu
->language
== language_rust
)
10393 rust_union_quirks (cu
);
10395 /* Some compilers don't define a DW_AT_high_pc attribute for the
10396 compilation unit. If the DW_AT_high_pc is missing, synthesize
10397 it, by scanning the DIE's below the compilation unit. */
10398 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10400 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10401 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10403 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10404 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10405 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10406 addrmap to help ensure it has an accurate map of pc values belonging to
10408 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10410 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10411 SECT_OFF_TEXT (objfile
),
10416 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10418 /* Set symtab language to language from DW_AT_language. If the
10419 compilation is from a C file generated by language preprocessors, do
10420 not set the language if it was already deduced by start_subfile. */
10421 if (!(cu
->language
== language_c
10422 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10423 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10425 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10426 produce DW_AT_location with location lists but it can be possibly
10427 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10428 there were bugs in prologue debug info, fixed later in GCC-4.5
10429 by "unwind info for epilogues" patch (which is not directly related).
10431 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10432 needed, it would be wrong due to missing DW_AT_producer there.
10434 Still one can confuse GDB by using non-standard GCC compilation
10435 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10437 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10438 cust
->locations_valid
= 1;
10440 if (gcc_4_minor
>= 5)
10441 cust
->epilogue_unwind_valid
= 1;
10443 cust
->call_site_htab
= cu
->call_site_htab
;
10446 if (dwarf2_per_objfile
->using_index
)
10447 per_cu
->v
.quick
->compunit_symtab
= cust
;
10450 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10451 pst
->compunit_symtab
= cust
;
10455 /* Push it for inclusion processing later. */
10456 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10458 /* Not needed any more. */
10459 cu
->reset_builder ();
10462 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10463 already been loaded into memory. */
10466 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10467 enum language pretend_language
)
10469 struct dwarf2_cu
*cu
= per_cu
->cu
;
10470 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10472 struct compunit_symtab
*cust
;
10473 struct signatured_type
*sig_type
;
10475 gdb_assert (per_cu
->is_debug_types
);
10476 sig_type
= (struct signatured_type
*) per_cu
;
10478 /* Clear the list here in case something was left over. */
10479 cu
->method_list
.clear ();
10481 cu
->language
= pretend_language
;
10482 cu
->language_defn
= language_def (cu
->language
);
10484 /* The symbol tables are set up in read_type_unit_scope. */
10485 process_die (cu
->dies
, cu
);
10487 /* For now fudge the Go package. */
10488 if (cu
->language
== language_go
)
10489 fixup_go_packaging (cu
);
10491 /* Now that we have processed all the DIEs in the CU, all the types
10492 should be complete, and it should now be safe to compute all of the
10494 compute_delayed_physnames (cu
);
10496 if (cu
->language
== language_rust
)
10497 rust_union_quirks (cu
);
10499 /* TUs share symbol tables.
10500 If this is the first TU to use this symtab, complete the construction
10501 of it with end_expandable_symtab. Otherwise, complete the addition of
10502 this TU's symbols to the existing symtab. */
10503 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10505 buildsym_compunit
*builder
= cu
->get_builder ();
10506 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10507 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10511 /* Set symtab language to language from DW_AT_language. If the
10512 compilation is from a C file generated by language preprocessors,
10513 do not set the language if it was already deduced by
10515 if (!(cu
->language
== language_c
10516 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10517 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10522 cu
->get_builder ()->augment_type_symtab ();
10523 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10526 if (dwarf2_per_objfile
->using_index
)
10527 per_cu
->v
.quick
->compunit_symtab
= cust
;
10530 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10531 pst
->compunit_symtab
= cust
;
10535 /* Not needed any more. */
10536 cu
->reset_builder ();
10539 /* Process an imported unit DIE. */
10542 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10544 struct attribute
*attr
;
10546 /* For now we don't handle imported units in type units. */
10547 if (cu
->per_cu
->is_debug_types
)
10549 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10550 " supported in type units [in module %s]"),
10551 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10554 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10557 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10558 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10559 dwarf2_per_cu_data
*per_cu
10560 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10561 cu
->per_cu
->dwarf2_per_objfile
);
10563 /* If necessary, add it to the queue and load its DIEs. */
10564 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10565 load_full_comp_unit (per_cu
, false, cu
->language
);
10567 cu
->per_cu
->imported_symtabs_push (per_cu
);
10571 /* RAII object that represents a process_die scope: i.e.,
10572 starts/finishes processing a DIE. */
10573 class process_die_scope
10576 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10577 : m_die (die
), m_cu (cu
)
10579 /* We should only be processing DIEs not already in process. */
10580 gdb_assert (!m_die
->in_process
);
10581 m_die
->in_process
= true;
10584 ~process_die_scope ()
10586 m_die
->in_process
= false;
10588 /* If we're done processing the DIE for the CU that owns the line
10589 header, we don't need the line header anymore. */
10590 if (m_cu
->line_header_die_owner
== m_die
)
10592 delete m_cu
->line_header
;
10593 m_cu
->line_header
= NULL
;
10594 m_cu
->line_header_die_owner
= NULL
;
10603 /* Process a die and its children. */
10606 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10608 process_die_scope
scope (die
, cu
);
10612 case DW_TAG_padding
:
10614 case DW_TAG_compile_unit
:
10615 case DW_TAG_partial_unit
:
10616 read_file_scope (die
, cu
);
10618 case DW_TAG_type_unit
:
10619 read_type_unit_scope (die
, cu
);
10621 case DW_TAG_subprogram
:
10622 /* Nested subprograms in Fortran get a prefix. */
10623 if (cu
->language
== language_fortran
10624 && die
->parent
!= NULL
10625 && die
->parent
->tag
== DW_TAG_subprogram
)
10626 cu
->processing_has_namespace_info
= true;
10627 /* Fall through. */
10628 case DW_TAG_inlined_subroutine
:
10629 read_func_scope (die
, cu
);
10631 case DW_TAG_lexical_block
:
10632 case DW_TAG_try_block
:
10633 case DW_TAG_catch_block
:
10634 read_lexical_block_scope (die
, cu
);
10636 case DW_TAG_call_site
:
10637 case DW_TAG_GNU_call_site
:
10638 read_call_site_scope (die
, cu
);
10640 case DW_TAG_class_type
:
10641 case DW_TAG_interface_type
:
10642 case DW_TAG_structure_type
:
10643 case DW_TAG_union_type
:
10644 process_structure_scope (die
, cu
);
10646 case DW_TAG_enumeration_type
:
10647 process_enumeration_scope (die
, cu
);
10650 /* These dies have a type, but processing them does not create
10651 a symbol or recurse to process the children. Therefore we can
10652 read them on-demand through read_type_die. */
10653 case DW_TAG_subroutine_type
:
10654 case DW_TAG_set_type
:
10655 case DW_TAG_array_type
:
10656 case DW_TAG_pointer_type
:
10657 case DW_TAG_ptr_to_member_type
:
10658 case DW_TAG_reference_type
:
10659 case DW_TAG_rvalue_reference_type
:
10660 case DW_TAG_string_type
:
10663 case DW_TAG_base_type
:
10664 case DW_TAG_subrange_type
:
10665 case DW_TAG_typedef
:
10666 /* Add a typedef symbol for the type definition, if it has a
10668 new_symbol (die
, read_type_die (die
, cu
), cu
);
10670 case DW_TAG_common_block
:
10671 read_common_block (die
, cu
);
10673 case DW_TAG_common_inclusion
:
10675 case DW_TAG_namespace
:
10676 cu
->processing_has_namespace_info
= true;
10677 read_namespace (die
, cu
);
10679 case DW_TAG_module
:
10680 cu
->processing_has_namespace_info
= true;
10681 read_module (die
, cu
);
10683 case DW_TAG_imported_declaration
:
10684 cu
->processing_has_namespace_info
= true;
10685 if (read_namespace_alias (die
, cu
))
10687 /* The declaration is not a global namespace alias. */
10688 /* Fall through. */
10689 case DW_TAG_imported_module
:
10690 cu
->processing_has_namespace_info
= true;
10691 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10692 || cu
->language
!= language_fortran
))
10693 complaint (_("Tag '%s' has unexpected children"),
10694 dwarf_tag_name (die
->tag
));
10695 read_import_statement (die
, cu
);
10698 case DW_TAG_imported_unit
:
10699 process_imported_unit_die (die
, cu
);
10702 case DW_TAG_variable
:
10703 read_variable (die
, cu
);
10707 new_symbol (die
, NULL
, cu
);
10712 /* DWARF name computation. */
10714 /* A helper function for dwarf2_compute_name which determines whether DIE
10715 needs to have the name of the scope prepended to the name listed in the
10719 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10721 struct attribute
*attr
;
10725 case DW_TAG_namespace
:
10726 case DW_TAG_typedef
:
10727 case DW_TAG_class_type
:
10728 case DW_TAG_interface_type
:
10729 case DW_TAG_structure_type
:
10730 case DW_TAG_union_type
:
10731 case DW_TAG_enumeration_type
:
10732 case DW_TAG_enumerator
:
10733 case DW_TAG_subprogram
:
10734 case DW_TAG_inlined_subroutine
:
10735 case DW_TAG_member
:
10736 case DW_TAG_imported_declaration
:
10739 case DW_TAG_variable
:
10740 case DW_TAG_constant
:
10741 /* We only need to prefix "globally" visible variables. These include
10742 any variable marked with DW_AT_external or any variable that
10743 lives in a namespace. [Variables in anonymous namespaces
10744 require prefixing, but they are not DW_AT_external.] */
10746 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10748 struct dwarf2_cu
*spec_cu
= cu
;
10750 return die_needs_namespace (die_specification (die
, &spec_cu
),
10754 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10755 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10756 && die
->parent
->tag
!= DW_TAG_module
)
10758 /* A variable in a lexical block of some kind does not need a
10759 namespace, even though in C++ such variables may be external
10760 and have a mangled name. */
10761 if (die
->parent
->tag
== DW_TAG_lexical_block
10762 || die
->parent
->tag
== DW_TAG_try_block
10763 || die
->parent
->tag
== DW_TAG_catch_block
10764 || die
->parent
->tag
== DW_TAG_subprogram
)
10773 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10774 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10775 defined for the given DIE. */
10777 static struct attribute
*
10778 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10780 struct attribute
*attr
;
10782 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10784 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10789 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10790 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10791 defined for the given DIE. */
10793 static const char *
10794 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10796 const char *linkage_name
;
10798 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10799 if (linkage_name
== NULL
)
10800 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10802 return linkage_name
;
10805 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10806 compute the physname for the object, which include a method's:
10807 - formal parameters (C++),
10808 - receiver type (Go),
10810 The term "physname" is a bit confusing.
10811 For C++, for example, it is the demangled name.
10812 For Go, for example, it's the mangled name.
10814 For Ada, return the DIE's linkage name rather than the fully qualified
10815 name. PHYSNAME is ignored..
10817 The result is allocated on the objfile_obstack and canonicalized. */
10819 static const char *
10820 dwarf2_compute_name (const char *name
,
10821 struct die_info
*die
, struct dwarf2_cu
*cu
,
10824 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10827 name
= dwarf2_name (die
, cu
);
10829 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10830 but otherwise compute it by typename_concat inside GDB.
10831 FIXME: Actually this is not really true, or at least not always true.
10832 It's all very confusing. SYMBOL_SET_NAMES doesn't try to demangle
10833 Fortran names because there is no mangling standard. So new_symbol
10834 will set the demangled name to the result of dwarf2_full_name, and it is
10835 the demangled name that GDB uses if it exists. */
10836 if (cu
->language
== language_ada
10837 || (cu
->language
== language_fortran
&& physname
))
10839 /* For Ada unit, we prefer the linkage name over the name, as
10840 the former contains the exported name, which the user expects
10841 to be able to reference. Ideally, we want the user to be able
10842 to reference this entity using either natural or linkage name,
10843 but we haven't started looking at this enhancement yet. */
10844 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10846 if (linkage_name
!= NULL
)
10847 return linkage_name
;
10850 /* These are the only languages we know how to qualify names in. */
10852 && (cu
->language
== language_cplus
10853 || cu
->language
== language_fortran
|| cu
->language
== language_d
10854 || cu
->language
== language_rust
))
10856 if (die_needs_namespace (die
, cu
))
10858 const char *prefix
;
10859 const char *canonical_name
= NULL
;
10863 prefix
= determine_prefix (die
, cu
);
10864 if (*prefix
!= '\0')
10866 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
10869 buf
.puts (prefixed_name
);
10870 xfree (prefixed_name
);
10875 /* Template parameters may be specified in the DIE's DW_AT_name, or
10876 as children with DW_TAG_template_type_param or
10877 DW_TAG_value_type_param. If the latter, add them to the name
10878 here. If the name already has template parameters, then
10879 skip this step; some versions of GCC emit both, and
10880 it is more efficient to use the pre-computed name.
10882 Something to keep in mind about this process: it is very
10883 unlikely, or in some cases downright impossible, to produce
10884 something that will match the mangled name of a function.
10885 If the definition of the function has the same debug info,
10886 we should be able to match up with it anyway. But fallbacks
10887 using the minimal symbol, for instance to find a method
10888 implemented in a stripped copy of libstdc++, will not work.
10889 If we do not have debug info for the definition, we will have to
10890 match them up some other way.
10892 When we do name matching there is a related problem with function
10893 templates; two instantiated function templates are allowed to
10894 differ only by their return types, which we do not add here. */
10896 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10898 struct attribute
*attr
;
10899 struct die_info
*child
;
10902 die
->building_fullname
= 1;
10904 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10908 const gdb_byte
*bytes
;
10909 struct dwarf2_locexpr_baton
*baton
;
10912 if (child
->tag
!= DW_TAG_template_type_param
10913 && child
->tag
!= DW_TAG_template_value_param
)
10924 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10927 complaint (_("template parameter missing DW_AT_type"));
10928 buf
.puts ("UNKNOWN_TYPE");
10931 type
= die_type (child
, cu
);
10933 if (child
->tag
== DW_TAG_template_type_param
)
10935 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10936 &type_print_raw_options
);
10940 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10943 complaint (_("template parameter missing "
10944 "DW_AT_const_value"));
10945 buf
.puts ("UNKNOWN_VALUE");
10949 dwarf2_const_value_attr (attr
, type
, name
,
10950 &cu
->comp_unit_obstack
, cu
,
10951 &value
, &bytes
, &baton
);
10953 if (TYPE_NOSIGN (type
))
10954 /* GDB prints characters as NUMBER 'CHAR'. If that's
10955 changed, this can use value_print instead. */
10956 c_printchar (value
, type
, &buf
);
10959 struct value_print_options opts
;
10962 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10966 else if (bytes
!= NULL
)
10968 v
= allocate_value (type
);
10969 memcpy (value_contents_writeable (v
), bytes
,
10970 TYPE_LENGTH (type
));
10973 v
= value_from_longest (type
, value
);
10975 /* Specify decimal so that we do not depend on
10977 get_formatted_print_options (&opts
, 'd');
10979 value_print (v
, &buf
, &opts
);
10984 die
->building_fullname
= 0;
10988 /* Close the argument list, with a space if necessary
10989 (nested templates). */
10990 if (!buf
.empty () && buf
.string ().back () == '>')
10997 /* For C++ methods, append formal parameter type
10998 information, if PHYSNAME. */
11000 if (physname
&& die
->tag
== DW_TAG_subprogram
11001 && cu
->language
== language_cplus
)
11003 struct type
*type
= read_type_die (die
, cu
);
11005 c_type_print_args (type
, &buf
, 1, cu
->language
,
11006 &type_print_raw_options
);
11008 if (cu
->language
== language_cplus
)
11010 /* Assume that an artificial first parameter is
11011 "this", but do not crash if it is not. RealView
11012 marks unnamed (and thus unused) parameters as
11013 artificial; there is no way to differentiate
11015 if (TYPE_NFIELDS (type
) > 0
11016 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11017 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11018 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11020 buf
.puts (" const");
11024 const std::string
&intermediate_name
= buf
.string ();
11026 if (cu
->language
== language_cplus
)
11028 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11029 &objfile
->per_bfd
->storage_obstack
);
11031 /* If we only computed INTERMEDIATE_NAME, or if
11032 INTERMEDIATE_NAME is already canonical, then we need to
11033 copy it to the appropriate obstack. */
11034 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11035 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11036 intermediate_name
);
11038 name
= canonical_name
;
11045 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11046 If scope qualifiers are appropriate they will be added. The result
11047 will be allocated on the storage_obstack, or NULL if the DIE does
11048 not have a name. NAME may either be from a previous call to
11049 dwarf2_name or NULL.
11051 The output string will be canonicalized (if C++). */
11053 static const char *
11054 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11056 return dwarf2_compute_name (name
, die
, cu
, 0);
11059 /* Construct a physname for the given DIE in CU. NAME may either be
11060 from a previous call to dwarf2_name or NULL. The result will be
11061 allocated on the objfile_objstack or NULL if the DIE does not have a
11064 The output string will be canonicalized (if C++). */
11066 static const char *
11067 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11069 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11070 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11073 /* In this case dwarf2_compute_name is just a shortcut not building anything
11075 if (!die_needs_namespace (die
, cu
))
11076 return dwarf2_compute_name (name
, die
, cu
, 1);
11078 mangled
= dw2_linkage_name (die
, cu
);
11080 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11081 See https://github.com/rust-lang/rust/issues/32925. */
11082 if (cu
->language
== language_rust
&& mangled
!= NULL
11083 && strchr (mangled
, '{') != NULL
)
11086 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11088 gdb::unique_xmalloc_ptr
<char> demangled
;
11089 if (mangled
!= NULL
)
11092 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11094 /* Do nothing (do not demangle the symbol name). */
11096 else if (cu
->language
== language_go
)
11098 /* This is a lie, but we already lie to the caller new_symbol.
11099 new_symbol assumes we return the mangled name.
11100 This just undoes that lie until things are cleaned up. */
11104 /* Use DMGL_RET_DROP for C++ template functions to suppress
11105 their return type. It is easier for GDB users to search
11106 for such functions as `name(params)' than `long name(params)'.
11107 In such case the minimal symbol names do not match the full
11108 symbol names but for template functions there is never a need
11109 to look up their definition from their declaration so
11110 the only disadvantage remains the minimal symbol variant
11111 `long name(params)' does not have the proper inferior type. */
11112 demangled
.reset (gdb_demangle (mangled
,
11113 (DMGL_PARAMS
| DMGL_ANSI
11114 | DMGL_RET_DROP
)));
11117 canon
= demangled
.get ();
11125 if (canon
== NULL
|| check_physname
)
11127 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11129 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11131 /* It may not mean a bug in GDB. The compiler could also
11132 compute DW_AT_linkage_name incorrectly. But in such case
11133 GDB would need to be bug-to-bug compatible. */
11135 complaint (_("Computed physname <%s> does not match demangled <%s> "
11136 "(from linkage <%s>) - DIE at %s [in module %s]"),
11137 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11138 objfile_name (objfile
));
11140 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11141 is available here - over computed PHYSNAME. It is safer
11142 against both buggy GDB and buggy compilers. */
11156 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11161 /* Inspect DIE in CU for a namespace alias. If one exists, record
11162 a new symbol for it.
11164 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11167 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11169 struct attribute
*attr
;
11171 /* If the die does not have a name, this is not a namespace
11173 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11177 struct die_info
*d
= die
;
11178 struct dwarf2_cu
*imported_cu
= cu
;
11180 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11181 keep inspecting DIEs until we hit the underlying import. */
11182 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11183 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11185 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11189 d
= follow_die_ref (d
, attr
, &imported_cu
);
11190 if (d
->tag
!= DW_TAG_imported_declaration
)
11194 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11196 complaint (_("DIE at %s has too many recursively imported "
11197 "declarations"), sect_offset_str (d
->sect_off
));
11204 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11206 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11207 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11209 /* This declaration is a global namespace alias. Add
11210 a symbol for it whose type is the aliased namespace. */
11211 new_symbol (die
, type
, cu
);
11220 /* Return the using directives repository (global or local?) to use in the
11221 current context for CU.
11223 For Ada, imported declarations can materialize renamings, which *may* be
11224 global. However it is impossible (for now?) in DWARF to distinguish
11225 "external" imported declarations and "static" ones. As all imported
11226 declarations seem to be static in all other languages, make them all CU-wide
11227 global only in Ada. */
11229 static struct using_direct
**
11230 using_directives (struct dwarf2_cu
*cu
)
11232 if (cu
->language
== language_ada
11233 && cu
->get_builder ()->outermost_context_p ())
11234 return cu
->get_builder ()->get_global_using_directives ();
11236 return cu
->get_builder ()->get_local_using_directives ();
11239 /* Read the import statement specified by the given die and record it. */
11242 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11244 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11245 struct attribute
*import_attr
;
11246 struct die_info
*imported_die
, *child_die
;
11247 struct dwarf2_cu
*imported_cu
;
11248 const char *imported_name
;
11249 const char *imported_name_prefix
;
11250 const char *canonical_name
;
11251 const char *import_alias
;
11252 const char *imported_declaration
= NULL
;
11253 const char *import_prefix
;
11254 std::vector
<const char *> excludes
;
11256 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11257 if (import_attr
== NULL
)
11259 complaint (_("Tag '%s' has no DW_AT_import"),
11260 dwarf_tag_name (die
->tag
));
11265 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11266 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11267 if (imported_name
== NULL
)
11269 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11271 The import in the following code:
11285 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11286 <52> DW_AT_decl_file : 1
11287 <53> DW_AT_decl_line : 6
11288 <54> DW_AT_import : <0x75>
11289 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11290 <59> DW_AT_name : B
11291 <5b> DW_AT_decl_file : 1
11292 <5c> DW_AT_decl_line : 2
11293 <5d> DW_AT_type : <0x6e>
11295 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11296 <76> DW_AT_byte_size : 4
11297 <77> DW_AT_encoding : 5 (signed)
11299 imports the wrong die ( 0x75 instead of 0x58 ).
11300 This case will be ignored until the gcc bug is fixed. */
11304 /* Figure out the local name after import. */
11305 import_alias
= dwarf2_name (die
, cu
);
11307 /* Figure out where the statement is being imported to. */
11308 import_prefix
= determine_prefix (die
, cu
);
11310 /* Figure out what the scope of the imported die is and prepend it
11311 to the name of the imported die. */
11312 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11314 if (imported_die
->tag
!= DW_TAG_namespace
11315 && imported_die
->tag
!= DW_TAG_module
)
11317 imported_declaration
= imported_name
;
11318 canonical_name
= imported_name_prefix
;
11320 else if (strlen (imported_name_prefix
) > 0)
11321 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11322 imported_name_prefix
,
11323 (cu
->language
== language_d
? "." : "::"),
11324 imported_name
, (char *) NULL
);
11326 canonical_name
= imported_name
;
11328 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11329 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11330 child_die
= sibling_die (child_die
))
11332 /* DWARF-4: A Fortran use statement with a “rename list” may be
11333 represented by an imported module entry with an import attribute
11334 referring to the module and owned entries corresponding to those
11335 entities that are renamed as part of being imported. */
11337 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11339 complaint (_("child DW_TAG_imported_declaration expected "
11340 "- DIE at %s [in module %s]"),
11341 sect_offset_str (child_die
->sect_off
),
11342 objfile_name (objfile
));
11346 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11347 if (import_attr
== NULL
)
11349 complaint (_("Tag '%s' has no DW_AT_import"),
11350 dwarf_tag_name (child_die
->tag
));
11355 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11357 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11358 if (imported_name
== NULL
)
11360 complaint (_("child DW_TAG_imported_declaration has unknown "
11361 "imported name - DIE at %s [in module %s]"),
11362 sect_offset_str (child_die
->sect_off
),
11363 objfile_name (objfile
));
11367 excludes
.push_back (imported_name
);
11369 process_die (child_die
, cu
);
11372 add_using_directive (using_directives (cu
),
11376 imported_declaration
,
11379 &objfile
->objfile_obstack
);
11382 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11383 types, but gives them a size of zero. Starting with version 14,
11384 ICC is compatible with GCC. */
11387 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11389 if (!cu
->checked_producer
)
11390 check_producer (cu
);
11392 return cu
->producer_is_icc_lt_14
;
11395 /* ICC generates a DW_AT_type for C void functions. This was observed on
11396 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11397 which says that void functions should not have a DW_AT_type. */
11400 producer_is_icc (struct dwarf2_cu
*cu
)
11402 if (!cu
->checked_producer
)
11403 check_producer (cu
);
11405 return cu
->producer_is_icc
;
11408 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11409 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11410 this, it was first present in GCC release 4.3.0. */
11413 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11415 if (!cu
->checked_producer
)
11416 check_producer (cu
);
11418 return cu
->producer_is_gcc_lt_4_3
;
11421 static file_and_directory
11422 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11424 file_and_directory res
;
11426 /* Find the filename. Do not use dwarf2_name here, since the filename
11427 is not a source language identifier. */
11428 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11429 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11431 if (res
.comp_dir
== NULL
11432 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11433 && IS_ABSOLUTE_PATH (res
.name
))
11435 res
.comp_dir_storage
= ldirname (res
.name
);
11436 if (!res
.comp_dir_storage
.empty ())
11437 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11439 if (res
.comp_dir
!= NULL
)
11441 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11442 directory, get rid of it. */
11443 const char *cp
= strchr (res
.comp_dir
, ':');
11445 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11446 res
.comp_dir
= cp
+ 1;
11449 if (res
.name
== NULL
)
11450 res
.name
= "<unknown>";
11455 /* Handle DW_AT_stmt_list for a compilation unit.
11456 DIE is the DW_TAG_compile_unit die for CU.
11457 COMP_DIR is the compilation directory. LOWPC is passed to
11458 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11461 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11462 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11464 struct dwarf2_per_objfile
*dwarf2_per_objfile
11465 = cu
->per_cu
->dwarf2_per_objfile
;
11466 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11467 struct attribute
*attr
;
11468 struct line_header line_header_local
;
11469 hashval_t line_header_local_hash
;
11471 int decode_mapping
;
11473 gdb_assert (! cu
->per_cu
->is_debug_types
);
11475 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11479 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11481 /* The line header hash table is only created if needed (it exists to
11482 prevent redundant reading of the line table for partial_units).
11483 If we're given a partial_unit, we'll need it. If we're given a
11484 compile_unit, then use the line header hash table if it's already
11485 created, but don't create one just yet. */
11487 if (dwarf2_per_objfile
->line_header_hash
== NULL
11488 && die
->tag
== DW_TAG_partial_unit
)
11490 dwarf2_per_objfile
->line_header_hash
11491 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11492 line_header_eq_voidp
,
11493 free_line_header_voidp
,
11494 &objfile
->objfile_obstack
,
11495 hashtab_obstack_allocate
,
11496 dummy_obstack_deallocate
);
11499 line_header_local
.sect_off
= line_offset
;
11500 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11501 line_header_local_hash
= line_header_hash (&line_header_local
);
11502 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11504 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11505 &line_header_local
,
11506 line_header_local_hash
, NO_INSERT
);
11508 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11509 is not present in *SLOT (since if there is something in *SLOT then
11510 it will be for a partial_unit). */
11511 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11513 gdb_assert (*slot
!= NULL
);
11514 cu
->line_header
= (struct line_header
*) *slot
;
11519 /* dwarf_decode_line_header does not yet provide sufficient information.
11520 We always have to call also dwarf_decode_lines for it. */
11521 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11525 cu
->line_header
= lh
.release ();
11526 cu
->line_header_die_owner
= die
;
11528 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11532 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11533 &line_header_local
,
11534 line_header_local_hash
, INSERT
);
11535 gdb_assert (slot
!= NULL
);
11537 if (slot
!= NULL
&& *slot
== NULL
)
11539 /* This newly decoded line number information unit will be owned
11540 by line_header_hash hash table. */
11541 *slot
= cu
->line_header
;
11542 cu
->line_header_die_owner
= NULL
;
11546 /* We cannot free any current entry in (*slot) as that struct line_header
11547 may be already used by multiple CUs. Create only temporary decoded
11548 line_header for this CU - it may happen at most once for each line
11549 number information unit. And if we're not using line_header_hash
11550 then this is what we want as well. */
11551 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11553 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11554 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11559 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11562 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11564 struct dwarf2_per_objfile
*dwarf2_per_objfile
11565 = cu
->per_cu
->dwarf2_per_objfile
;
11566 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11567 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11568 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11569 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11570 struct attribute
*attr
;
11571 struct die_info
*child_die
;
11572 CORE_ADDR baseaddr
;
11574 prepare_one_comp_unit (cu
, die
, cu
->language
);
11575 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
11577 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11579 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11580 from finish_block. */
11581 if (lowpc
== ((CORE_ADDR
) -1))
11583 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11585 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11587 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11588 standardised yet. As a workaround for the language detection we fall
11589 back to the DW_AT_producer string. */
11590 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11591 cu
->language
= language_opencl
;
11593 /* Similar hack for Go. */
11594 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11595 set_cu_language (DW_LANG_Go
, cu
);
11597 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11599 /* Decode line number information if present. We do this before
11600 processing child DIEs, so that the line header table is available
11601 for DW_AT_decl_file. */
11602 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11604 /* Process all dies in compilation unit. */
11605 if (die
->child
!= NULL
)
11607 child_die
= die
->child
;
11608 while (child_die
&& child_die
->tag
)
11610 process_die (child_die
, cu
);
11611 child_die
= sibling_die (child_die
);
11615 /* Decode macro information, if present. Dwarf 2 macro information
11616 refers to information in the line number info statement program
11617 header, so we can only read it if we've read the header
11619 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11621 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11622 if (attr
&& cu
->line_header
)
11624 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11625 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11627 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11631 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11632 if (attr
&& cu
->line_header
)
11634 unsigned int macro_offset
= DW_UNSND (attr
);
11636 dwarf_decode_macros (cu
, macro_offset
, 0);
11642 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11644 struct type_unit_group
*tu_group
;
11646 struct attribute
*attr
;
11648 struct signatured_type
*sig_type
;
11650 gdb_assert (per_cu
->is_debug_types
);
11651 sig_type
= (struct signatured_type
*) per_cu
;
11653 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11655 /* If we're using .gdb_index (includes -readnow) then
11656 per_cu->type_unit_group may not have been set up yet. */
11657 if (sig_type
->type_unit_group
== NULL
)
11658 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11659 tu_group
= sig_type
->type_unit_group
;
11661 /* If we've already processed this stmt_list there's no real need to
11662 do it again, we could fake it and just recreate the part we need
11663 (file name,index -> symtab mapping). If data shows this optimization
11664 is useful we can do it then. */
11665 first_time
= tu_group
->compunit_symtab
== NULL
;
11667 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11672 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11673 lh
= dwarf_decode_line_header (line_offset
, this);
11678 start_symtab ("", NULL
, 0);
11681 gdb_assert (tu_group
->symtabs
== NULL
);
11682 gdb_assert (m_builder
== nullptr);
11683 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11684 m_builder
.reset (new struct buildsym_compunit
11685 (COMPUNIT_OBJFILE (cust
), "",
11686 COMPUNIT_DIRNAME (cust
),
11687 compunit_language (cust
),
11693 line_header
= lh
.release ();
11694 line_header_die_owner
= die
;
11698 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11700 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11701 still initializing it, and our caller (a few levels up)
11702 process_full_type_unit still needs to know if this is the first
11705 tu_group
->num_symtabs
= line_header
->file_names
.size ();
11706 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11707 line_header
->file_names
.size ());
11709 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11711 file_entry
&fe
= line_header
->file_names
[i
];
11713 dwarf2_start_subfile (this, fe
.name
,
11714 fe
.include_dir (line_header
));
11715 buildsym_compunit
*b
= get_builder ();
11716 if (b
->get_current_subfile ()->symtab
== NULL
)
11718 /* NOTE: start_subfile will recognize when it's been
11719 passed a file it has already seen. So we can't
11720 assume there's a simple mapping from
11721 cu->line_header->file_names to subfiles, plus
11722 cu->line_header->file_names may contain dups. */
11723 b
->get_current_subfile ()->symtab
11724 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11727 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11728 tu_group
->symtabs
[i
] = fe
.symtab
;
11733 gdb_assert (m_builder
== nullptr);
11734 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11735 m_builder
.reset (new struct buildsym_compunit
11736 (COMPUNIT_OBJFILE (cust
), "",
11737 COMPUNIT_DIRNAME (cust
),
11738 compunit_language (cust
),
11741 for (i
= 0; i
< line_header
->file_names
.size (); ++i
)
11743 file_entry
&fe
= line_header
->file_names
[i
];
11745 fe
.symtab
= tu_group
->symtabs
[i
];
11749 /* The main symtab is allocated last. Type units don't have DW_AT_name
11750 so they don't have a "real" (so to speak) symtab anyway.
11751 There is later code that will assign the main symtab to all symbols
11752 that don't have one. We need to handle the case of a symbol with a
11753 missing symtab (DW_AT_decl_file) anyway. */
11756 /* Process DW_TAG_type_unit.
11757 For TUs we want to skip the first top level sibling if it's not the
11758 actual type being defined by this TU. In this case the first top
11759 level sibling is there to provide context only. */
11762 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11764 struct die_info
*child_die
;
11766 prepare_one_comp_unit (cu
, die
, language_minimal
);
11768 /* Initialize (or reinitialize) the machinery for building symtabs.
11769 We do this before processing child DIEs, so that the line header table
11770 is available for DW_AT_decl_file. */
11771 cu
->setup_type_unit_groups (die
);
11773 if (die
->child
!= NULL
)
11775 child_die
= die
->child
;
11776 while (child_die
&& child_die
->tag
)
11778 process_die (child_die
, cu
);
11779 child_die
= sibling_die (child_die
);
11786 http://gcc.gnu.org/wiki/DebugFission
11787 http://gcc.gnu.org/wiki/DebugFissionDWP
11789 To simplify handling of both DWO files ("object" files with the DWARF info)
11790 and DWP files (a file with the DWOs packaged up into one file), we treat
11791 DWP files as having a collection of virtual DWO files. */
11794 hash_dwo_file (const void *item
)
11796 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11799 hash
= htab_hash_string (dwo_file
->dwo_name
);
11800 if (dwo_file
->comp_dir
!= NULL
)
11801 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11806 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11808 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11809 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11811 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11813 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11814 return lhs
->comp_dir
== rhs
->comp_dir
;
11815 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11818 /* Allocate a hash table for DWO files. */
11821 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11823 auto delete_dwo_file
= [] (void *item
)
11825 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11830 return htab_up (htab_create_alloc_ex (41,
11834 &objfile
->objfile_obstack
,
11835 hashtab_obstack_allocate
,
11836 dummy_obstack_deallocate
));
11839 /* Lookup DWO file DWO_NAME. */
11842 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11843 const char *dwo_name
,
11844 const char *comp_dir
)
11846 struct dwo_file find_entry
;
11849 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11850 dwarf2_per_objfile
->dwo_files
11851 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11853 find_entry
.dwo_name
= dwo_name
;
11854 find_entry
.comp_dir
= comp_dir
;
11855 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11862 hash_dwo_unit (const void *item
)
11864 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11866 /* This drops the top 32 bits of the id, but is ok for a hash. */
11867 return dwo_unit
->signature
;
11871 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11873 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11874 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11876 /* The signature is assumed to be unique within the DWO file.
11877 So while object file CU dwo_id's always have the value zero,
11878 that's OK, assuming each object file DWO file has only one CU,
11879 and that's the rule for now. */
11880 return lhs
->signature
== rhs
->signature
;
11883 /* Allocate a hash table for DWO CUs,TUs.
11884 There is one of these tables for each of CUs,TUs for each DWO file. */
11887 allocate_dwo_unit_table (struct objfile
*objfile
)
11889 /* Start out with a pretty small number.
11890 Generally DWO files contain only one CU and maybe some TUs. */
11891 return htab_create_alloc_ex (3,
11895 &objfile
->objfile_obstack
,
11896 hashtab_obstack_allocate
,
11897 dummy_obstack_deallocate
);
11900 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11902 struct create_dwo_cu_data
11904 struct dwo_file
*dwo_file
;
11905 struct dwo_unit dwo_unit
;
11908 /* die_reader_func for create_dwo_cu. */
11911 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11912 const gdb_byte
*info_ptr
,
11913 struct die_info
*comp_unit_die
,
11917 struct dwarf2_cu
*cu
= reader
->cu
;
11918 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11919 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11920 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11921 struct dwo_file
*dwo_file
= data
->dwo_file
;
11922 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
11924 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11925 if (!signature
.has_value ())
11927 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11928 " its dwo_id [in module %s]"),
11929 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11933 dwo_unit
->dwo_file
= dwo_file
;
11934 dwo_unit
->signature
= *signature
;
11935 dwo_unit
->section
= section
;
11936 dwo_unit
->sect_off
= sect_off
;
11937 dwo_unit
->length
= cu
->per_cu
->length
;
11939 if (dwarf_read_debug
)
11940 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11941 sect_offset_str (sect_off
),
11942 hex_string (dwo_unit
->signature
));
11945 /* Create the dwo_units for the CUs in a DWO_FILE.
11946 Note: This function processes DWO files only, not DWP files. */
11949 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11950 struct dwo_file
&dwo_file
, dwarf2_section_info
§ion
,
11953 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11954 const gdb_byte
*info_ptr
, *end_ptr
;
11956 dwarf2_read_section (objfile
, §ion
);
11957 info_ptr
= section
.buffer
;
11959 if (info_ptr
== NULL
)
11962 if (dwarf_read_debug
)
11964 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11965 get_section_name (§ion
),
11966 get_section_file_name (§ion
));
11969 end_ptr
= info_ptr
+ section
.size
;
11970 while (info_ptr
< end_ptr
)
11972 struct dwarf2_per_cu_data per_cu
;
11973 struct create_dwo_cu_data create_dwo_cu_data
;
11974 struct dwo_unit
*dwo_unit
;
11976 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11978 memset (&create_dwo_cu_data
.dwo_unit
, 0,
11979 sizeof (create_dwo_cu_data
.dwo_unit
));
11980 memset (&per_cu
, 0, sizeof (per_cu
));
11981 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11982 per_cu
.is_debug_types
= 0;
11983 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11984 per_cu
.section
= §ion
;
11985 create_dwo_cu_data
.dwo_file
= &dwo_file
;
11987 init_cutu_and_read_dies_no_follow (
11988 &per_cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
11989 info_ptr
+= per_cu
.length
;
11991 // If the unit could not be parsed, skip it.
11992 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
11995 if (cus_htab
== NULL
)
11996 cus_htab
= allocate_dwo_unit_table (objfile
);
11998 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11999 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12000 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12001 gdb_assert (slot
!= NULL
);
12004 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12005 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12007 complaint (_("debug cu entry at offset %s is duplicate to"
12008 " the entry at offset %s, signature %s"),
12009 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12010 hex_string (dwo_unit
->signature
));
12012 *slot
= (void *)dwo_unit
;
12016 /* DWP file .debug_{cu,tu}_index section format:
12017 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12021 Both index sections have the same format, and serve to map a 64-bit
12022 signature to a set of section numbers. Each section begins with a header,
12023 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12024 indexes, and a pool of 32-bit section numbers. The index sections will be
12025 aligned at 8-byte boundaries in the file.
12027 The index section header consists of:
12029 V, 32 bit version number
12031 N, 32 bit number of compilation units or type units in the index
12032 M, 32 bit number of slots in the hash table
12034 Numbers are recorded using the byte order of the application binary.
12036 The hash table begins at offset 16 in the section, and consists of an array
12037 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12038 order of the application binary). Unused slots in the hash table are 0.
12039 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12041 The parallel table begins immediately after the hash table
12042 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12043 array of 32-bit indexes (using the byte order of the application binary),
12044 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12045 table contains a 32-bit index into the pool of section numbers. For unused
12046 hash table slots, the corresponding entry in the parallel table will be 0.
12048 The pool of section numbers begins immediately following the hash table
12049 (at offset 16 + 12 * M from the beginning of the section). The pool of
12050 section numbers consists of an array of 32-bit words (using the byte order
12051 of the application binary). Each item in the array is indexed starting
12052 from 0. The hash table entry provides the index of the first section
12053 number in the set. Additional section numbers in the set follow, and the
12054 set is terminated by a 0 entry (section number 0 is not used in ELF).
12056 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12057 section must be the first entry in the set, and the .debug_abbrev.dwo must
12058 be the second entry. Other members of the set may follow in any order.
12064 DWP Version 2 combines all the .debug_info, etc. sections into one,
12065 and the entries in the index tables are now offsets into these sections.
12066 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12069 Index Section Contents:
12071 Hash Table of Signatures dwp_hash_table.hash_table
12072 Parallel Table of Indices dwp_hash_table.unit_table
12073 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12074 Table of Section Sizes dwp_hash_table.v2.sizes
12076 The index section header consists of:
12078 V, 32 bit version number
12079 L, 32 bit number of columns in the table of section offsets
12080 N, 32 bit number of compilation units or type units in the index
12081 M, 32 bit number of slots in the hash table
12083 Numbers are recorded using the byte order of the application binary.
12085 The hash table has the same format as version 1.
12086 The parallel table of indices has the same format as version 1,
12087 except that the entries are origin-1 indices into the table of sections
12088 offsets and the table of section sizes.
12090 The table of offsets begins immediately following the parallel table
12091 (at offset 16 + 12 * M from the beginning of the section). The table is
12092 a two-dimensional array of 32-bit words (using the byte order of the
12093 application binary), with L columns and N+1 rows, in row-major order.
12094 Each row in the array is indexed starting from 0. The first row provides
12095 a key to the remaining rows: each column in this row provides an identifier
12096 for a debug section, and the offsets in the same column of subsequent rows
12097 refer to that section. The section identifiers are:
12099 DW_SECT_INFO 1 .debug_info.dwo
12100 DW_SECT_TYPES 2 .debug_types.dwo
12101 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12102 DW_SECT_LINE 4 .debug_line.dwo
12103 DW_SECT_LOC 5 .debug_loc.dwo
12104 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12105 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12106 DW_SECT_MACRO 8 .debug_macro.dwo
12108 The offsets provided by the CU and TU index sections are the base offsets
12109 for the contributions made by each CU or TU to the corresponding section
12110 in the package file. Each CU and TU header contains an abbrev_offset
12111 field, used to find the abbreviations table for that CU or TU within the
12112 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12113 be interpreted as relative to the base offset given in the index section.
12114 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12115 should be interpreted as relative to the base offset for .debug_line.dwo,
12116 and offsets into other debug sections obtained from DWARF attributes should
12117 also be interpreted as relative to the corresponding base offset.
12119 The table of sizes begins immediately following the table of offsets.
12120 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12121 with L columns and N rows, in row-major order. Each row in the array is
12122 indexed starting from 1 (row 0 is shared by the two tables).
12126 Hash table lookup is handled the same in version 1 and 2:
12128 We assume that N and M will not exceed 2^32 - 1.
12129 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12131 Given a 64-bit compilation unit signature or a type signature S, an entry
12132 in the hash table is located as follows:
12134 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12135 the low-order k bits all set to 1.
12137 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12139 3) If the hash table entry at index H matches the signature, use that
12140 entry. If the hash table entry at index H is unused (all zeroes),
12141 terminate the search: the signature is not present in the table.
12143 4) Let H = (H + H') modulo M. Repeat at Step 3.
12145 Because M > N and H' and M are relatively prime, the search is guaranteed
12146 to stop at an unused slot or find the match. */
12148 /* Create a hash table to map DWO IDs to their CU/TU entry in
12149 .debug_{info,types}.dwo in DWP_FILE.
12150 Returns NULL if there isn't one.
12151 Note: This function processes DWP files only, not DWO files. */
12153 static struct dwp_hash_table
*
12154 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12155 struct dwp_file
*dwp_file
, int is_debug_types
)
12157 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12158 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12159 const gdb_byte
*index_ptr
, *index_end
;
12160 struct dwarf2_section_info
*index
;
12161 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12162 struct dwp_hash_table
*htab
;
12164 if (is_debug_types
)
12165 index
= &dwp_file
->sections
.tu_index
;
12167 index
= &dwp_file
->sections
.cu_index
;
12169 if (dwarf2_section_empty_p (index
))
12171 dwarf2_read_section (objfile
, index
);
12173 index_ptr
= index
->buffer
;
12174 index_end
= index_ptr
+ index
->size
;
12176 version
= read_4_bytes (dbfd
, index_ptr
);
12179 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12183 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12185 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12188 if (version
!= 1 && version
!= 2)
12190 error (_("Dwarf Error: unsupported DWP file version (%s)"
12191 " [in module %s]"),
12192 pulongest (version
), dwp_file
->name
);
12194 if (nr_slots
!= (nr_slots
& -nr_slots
))
12196 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12197 " is not power of 2 [in module %s]"),
12198 pulongest (nr_slots
), dwp_file
->name
);
12201 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12202 htab
->version
= version
;
12203 htab
->nr_columns
= nr_columns
;
12204 htab
->nr_units
= nr_units
;
12205 htab
->nr_slots
= nr_slots
;
12206 htab
->hash_table
= index_ptr
;
12207 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12209 /* Exit early if the table is empty. */
12210 if (nr_slots
== 0 || nr_units
== 0
12211 || (version
== 2 && nr_columns
== 0))
12213 /* All must be zero. */
12214 if (nr_slots
!= 0 || nr_units
!= 0
12215 || (version
== 2 && nr_columns
!= 0))
12217 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12218 " all zero [in modules %s]"),
12226 htab
->section_pool
.v1
.indices
=
12227 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12228 /* It's harder to decide whether the section is too small in v1.
12229 V1 is deprecated anyway so we punt. */
12233 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12234 int *ids
= htab
->section_pool
.v2
.section_ids
;
12235 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12236 /* Reverse map for error checking. */
12237 int ids_seen
[DW_SECT_MAX
+ 1];
12240 if (nr_columns
< 2)
12242 error (_("Dwarf Error: bad DWP hash table, too few columns"
12243 " in section table [in module %s]"),
12246 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12248 error (_("Dwarf Error: bad DWP hash table, too many columns"
12249 " in section table [in module %s]"),
12252 memset (ids
, 255, sizeof_ids
);
12253 memset (ids_seen
, 255, sizeof (ids_seen
));
12254 for (i
= 0; i
< nr_columns
; ++i
)
12256 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12258 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12260 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12261 " in section table [in module %s]"),
12262 id
, dwp_file
->name
);
12264 if (ids_seen
[id
] != -1)
12266 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12267 " id %d in section table [in module %s]"),
12268 id
, dwp_file
->name
);
12273 /* Must have exactly one info or types section. */
12274 if (((ids_seen
[DW_SECT_INFO
] != -1)
12275 + (ids_seen
[DW_SECT_TYPES
] != -1))
12278 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12279 " DWO info/types section [in module %s]"),
12282 /* Must have an abbrev section. */
12283 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12285 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12286 " section [in module %s]"),
12289 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12290 htab
->section_pool
.v2
.sizes
=
12291 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12292 * nr_units
* nr_columns
);
12293 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12294 * nr_units
* nr_columns
))
12297 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12298 " [in module %s]"),
12306 /* Update SECTIONS with the data from SECTP.
12308 This function is like the other "locate" section routines that are
12309 passed to bfd_map_over_sections, but in this context the sections to
12310 read comes from the DWP V1 hash table, not the full ELF section table.
12312 The result is non-zero for success, or zero if an error was found. */
12315 locate_v1_virtual_dwo_sections (asection
*sectp
,
12316 struct virtual_v1_dwo_sections
*sections
)
12318 const struct dwop_section_names
*names
= &dwop_section_names
;
12320 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12322 /* There can be only one. */
12323 if (sections
->abbrev
.s
.section
!= NULL
)
12325 sections
->abbrev
.s
.section
= sectp
;
12326 sections
->abbrev
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12329 || section_is_p (sectp
->name
, &names
->types_dwo
))
12331 /* There can be only one. */
12332 if (sections
->info_or_types
.s
.section
!= NULL
)
12334 sections
->info_or_types
.s
.section
= sectp
;
12335 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12337 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12339 /* There can be only one. */
12340 if (sections
->line
.s
.section
!= NULL
)
12342 sections
->line
.s
.section
= sectp
;
12343 sections
->line
.size
= bfd_section_size (sectp
);
12345 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12347 /* There can be only one. */
12348 if (sections
->loc
.s
.section
!= NULL
)
12350 sections
->loc
.s
.section
= sectp
;
12351 sections
->loc
.size
= bfd_section_size (sectp
);
12353 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12355 /* There can be only one. */
12356 if (sections
->macinfo
.s
.section
!= NULL
)
12358 sections
->macinfo
.s
.section
= sectp
;
12359 sections
->macinfo
.size
= bfd_section_size (sectp
);
12361 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12363 /* There can be only one. */
12364 if (sections
->macro
.s
.section
!= NULL
)
12366 sections
->macro
.s
.section
= sectp
;
12367 sections
->macro
.size
= bfd_section_size (sectp
);
12369 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12371 /* There can be only one. */
12372 if (sections
->str_offsets
.s
.section
!= NULL
)
12374 sections
->str_offsets
.s
.section
= sectp
;
12375 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12379 /* No other kind of section is valid. */
12386 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12387 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12388 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12389 This is for DWP version 1 files. */
12391 static struct dwo_unit
*
12392 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12393 struct dwp_file
*dwp_file
,
12394 uint32_t unit_index
,
12395 const char *comp_dir
,
12396 ULONGEST signature
, int is_debug_types
)
12398 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12399 const struct dwp_hash_table
*dwp_htab
=
12400 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12401 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12402 const char *kind
= is_debug_types
? "TU" : "CU";
12403 struct dwo_file
*dwo_file
;
12404 struct dwo_unit
*dwo_unit
;
12405 struct virtual_v1_dwo_sections sections
;
12406 void **dwo_file_slot
;
12409 gdb_assert (dwp_file
->version
== 1);
12411 if (dwarf_read_debug
)
12413 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12415 pulongest (unit_index
), hex_string (signature
),
12419 /* Fetch the sections of this DWO unit.
12420 Put a limit on the number of sections we look for so that bad data
12421 doesn't cause us to loop forever. */
12423 #define MAX_NR_V1_DWO_SECTIONS \
12424 (1 /* .debug_info or .debug_types */ \
12425 + 1 /* .debug_abbrev */ \
12426 + 1 /* .debug_line */ \
12427 + 1 /* .debug_loc */ \
12428 + 1 /* .debug_str_offsets */ \
12429 + 1 /* .debug_macro or .debug_macinfo */ \
12430 + 1 /* trailing zero */)
12432 memset (§ions
, 0, sizeof (sections
));
12434 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12437 uint32_t section_nr
=
12438 read_4_bytes (dbfd
,
12439 dwp_htab
->section_pool
.v1
.indices
12440 + (unit_index
+ i
) * sizeof (uint32_t));
12442 if (section_nr
== 0)
12444 if (section_nr
>= dwp_file
->num_sections
)
12446 error (_("Dwarf Error: bad DWP hash table, section number too large"
12447 " [in module %s]"),
12451 sectp
= dwp_file
->elf_sections
[section_nr
];
12452 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12454 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12455 " [in module %s]"),
12461 || dwarf2_section_empty_p (§ions
.info_or_types
)
12462 || dwarf2_section_empty_p (§ions
.abbrev
))
12464 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12465 " [in module %s]"),
12468 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12470 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12471 " [in module %s]"),
12475 /* It's easier for the rest of the code if we fake a struct dwo_file and
12476 have dwo_unit "live" in that. At least for now.
12478 The DWP file can be made up of a random collection of CUs and TUs.
12479 However, for each CU + set of TUs that came from the same original DWO
12480 file, we can combine them back into a virtual DWO file to save space
12481 (fewer struct dwo_file objects to allocate). Remember that for really
12482 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12484 std::string virtual_dwo_name
=
12485 string_printf ("virtual-dwo/%d-%d-%d-%d",
12486 get_section_id (§ions
.abbrev
),
12487 get_section_id (§ions
.line
),
12488 get_section_id (§ions
.loc
),
12489 get_section_id (§ions
.str_offsets
));
12490 /* Can we use an existing virtual DWO file? */
12491 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12492 virtual_dwo_name
.c_str (),
12494 /* Create one if necessary. */
12495 if (*dwo_file_slot
== NULL
)
12497 if (dwarf_read_debug
)
12499 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12500 virtual_dwo_name
.c_str ());
12502 dwo_file
= new struct dwo_file
;
12503 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12505 dwo_file
->comp_dir
= comp_dir
;
12506 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12507 dwo_file
->sections
.line
= sections
.line
;
12508 dwo_file
->sections
.loc
= sections
.loc
;
12509 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12510 dwo_file
->sections
.macro
= sections
.macro
;
12511 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12512 /* The "str" section is global to the entire DWP file. */
12513 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12514 /* The info or types section is assigned below to dwo_unit,
12515 there's no need to record it in dwo_file.
12516 Also, we can't simply record type sections in dwo_file because
12517 we record a pointer into the vector in dwo_unit. As we collect more
12518 types we'll grow the vector and eventually have to reallocate space
12519 for it, invalidating all copies of pointers into the previous
12521 *dwo_file_slot
= dwo_file
;
12525 if (dwarf_read_debug
)
12527 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12528 virtual_dwo_name
.c_str ());
12530 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12533 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12534 dwo_unit
->dwo_file
= dwo_file
;
12535 dwo_unit
->signature
= signature
;
12536 dwo_unit
->section
=
12537 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12538 *dwo_unit
->section
= sections
.info_or_types
;
12539 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12544 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12545 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12546 piece within that section used by a TU/CU, return a virtual section
12547 of just that piece. */
12549 static struct dwarf2_section_info
12550 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12551 struct dwarf2_section_info
*section
,
12552 bfd_size_type offset
, bfd_size_type size
)
12554 struct dwarf2_section_info result
;
12557 gdb_assert (section
!= NULL
);
12558 gdb_assert (!section
->is_virtual
);
12560 memset (&result
, 0, sizeof (result
));
12561 result
.s
.containing_section
= section
;
12562 result
.is_virtual
= true;
12567 sectp
= get_section_bfd_section (section
);
12569 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12570 bounds of the real section. This is a pretty-rare event, so just
12571 flag an error (easier) instead of a warning and trying to cope. */
12573 || offset
+ size
> bfd_section_size (sectp
))
12575 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12576 " in section %s [in module %s]"),
12577 sectp
? bfd_section_name (sectp
) : "<unknown>",
12578 objfile_name (dwarf2_per_objfile
->objfile
));
12581 result
.virtual_offset
= offset
;
12582 result
.size
= size
;
12586 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12587 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12588 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12589 This is for DWP version 2 files. */
12591 static struct dwo_unit
*
12592 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12593 struct dwp_file
*dwp_file
,
12594 uint32_t unit_index
,
12595 const char *comp_dir
,
12596 ULONGEST signature
, int is_debug_types
)
12598 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12599 const struct dwp_hash_table
*dwp_htab
=
12600 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12601 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12602 const char *kind
= is_debug_types
? "TU" : "CU";
12603 struct dwo_file
*dwo_file
;
12604 struct dwo_unit
*dwo_unit
;
12605 struct virtual_v2_dwo_sections sections
;
12606 void **dwo_file_slot
;
12609 gdb_assert (dwp_file
->version
== 2);
12611 if (dwarf_read_debug
)
12613 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12615 pulongest (unit_index
), hex_string (signature
),
12619 /* Fetch the section offsets of this DWO unit. */
12621 memset (§ions
, 0, sizeof (sections
));
12623 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12625 uint32_t offset
= read_4_bytes (dbfd
,
12626 dwp_htab
->section_pool
.v2
.offsets
12627 + (((unit_index
- 1) * dwp_htab
->nr_columns
12629 * sizeof (uint32_t)));
12630 uint32_t size
= read_4_bytes (dbfd
,
12631 dwp_htab
->section_pool
.v2
.sizes
12632 + (((unit_index
- 1) * dwp_htab
->nr_columns
12634 * sizeof (uint32_t)));
12636 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12639 case DW_SECT_TYPES
:
12640 sections
.info_or_types_offset
= offset
;
12641 sections
.info_or_types_size
= size
;
12643 case DW_SECT_ABBREV
:
12644 sections
.abbrev_offset
= offset
;
12645 sections
.abbrev_size
= size
;
12648 sections
.line_offset
= offset
;
12649 sections
.line_size
= size
;
12652 sections
.loc_offset
= offset
;
12653 sections
.loc_size
= size
;
12655 case DW_SECT_STR_OFFSETS
:
12656 sections
.str_offsets_offset
= offset
;
12657 sections
.str_offsets_size
= size
;
12659 case DW_SECT_MACINFO
:
12660 sections
.macinfo_offset
= offset
;
12661 sections
.macinfo_size
= size
;
12663 case DW_SECT_MACRO
:
12664 sections
.macro_offset
= offset
;
12665 sections
.macro_size
= size
;
12670 /* It's easier for the rest of the code if we fake a struct dwo_file and
12671 have dwo_unit "live" in that. At least for now.
12673 The DWP file can be made up of a random collection of CUs and TUs.
12674 However, for each CU + set of TUs that came from the same original DWO
12675 file, we can combine them back into a virtual DWO file to save space
12676 (fewer struct dwo_file objects to allocate). Remember that for really
12677 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12679 std::string virtual_dwo_name
=
12680 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12681 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12682 (long) (sections
.line_size
? sections
.line_offset
: 0),
12683 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12684 (long) (sections
.str_offsets_size
12685 ? sections
.str_offsets_offset
: 0));
12686 /* Can we use an existing virtual DWO file? */
12687 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12688 virtual_dwo_name
.c_str (),
12690 /* Create one if necessary. */
12691 if (*dwo_file_slot
== NULL
)
12693 if (dwarf_read_debug
)
12695 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12696 virtual_dwo_name
.c_str ());
12698 dwo_file
= new struct dwo_file
;
12699 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12701 dwo_file
->comp_dir
= comp_dir
;
12702 dwo_file
->sections
.abbrev
=
12703 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12704 sections
.abbrev_offset
, sections
.abbrev_size
);
12705 dwo_file
->sections
.line
=
12706 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12707 sections
.line_offset
, sections
.line_size
);
12708 dwo_file
->sections
.loc
=
12709 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12710 sections
.loc_offset
, sections
.loc_size
);
12711 dwo_file
->sections
.macinfo
=
12712 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12713 sections
.macinfo_offset
, sections
.macinfo_size
);
12714 dwo_file
->sections
.macro
=
12715 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12716 sections
.macro_offset
, sections
.macro_size
);
12717 dwo_file
->sections
.str_offsets
=
12718 create_dwp_v2_section (dwarf2_per_objfile
,
12719 &dwp_file
->sections
.str_offsets
,
12720 sections
.str_offsets_offset
,
12721 sections
.str_offsets_size
);
12722 /* The "str" section is global to the entire DWP file. */
12723 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12724 /* The info or types section is assigned below to dwo_unit,
12725 there's no need to record it in dwo_file.
12726 Also, we can't simply record type sections in dwo_file because
12727 we record a pointer into the vector in dwo_unit. As we collect more
12728 types we'll grow the vector and eventually have to reallocate space
12729 for it, invalidating all copies of pointers into the previous
12731 *dwo_file_slot
= dwo_file
;
12735 if (dwarf_read_debug
)
12737 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12738 virtual_dwo_name
.c_str ());
12740 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12743 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12744 dwo_unit
->dwo_file
= dwo_file
;
12745 dwo_unit
->signature
= signature
;
12746 dwo_unit
->section
=
12747 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12748 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12750 ? &dwp_file
->sections
.types
12751 : &dwp_file
->sections
.info
,
12752 sections
.info_or_types_offset
,
12753 sections
.info_or_types_size
);
12754 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12759 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12760 Returns NULL if the signature isn't found. */
12762 static struct dwo_unit
*
12763 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12764 struct dwp_file
*dwp_file
, const char *comp_dir
,
12765 ULONGEST signature
, int is_debug_types
)
12767 const struct dwp_hash_table
*dwp_htab
=
12768 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12769 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12770 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12771 uint32_t hash
= signature
& mask
;
12772 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12775 struct dwo_unit find_dwo_cu
;
12777 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12778 find_dwo_cu
.signature
= signature
;
12779 slot
= htab_find_slot (is_debug_types
12780 ? dwp_file
->loaded_tus
12781 : dwp_file
->loaded_cus
,
12782 &find_dwo_cu
, INSERT
);
12785 return (struct dwo_unit
*) *slot
;
12787 /* Use a for loop so that we don't loop forever on bad debug info. */
12788 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12790 ULONGEST signature_in_table
;
12792 signature_in_table
=
12793 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12794 if (signature_in_table
== signature
)
12796 uint32_t unit_index
=
12797 read_4_bytes (dbfd
,
12798 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12800 if (dwp_file
->version
== 1)
12802 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12803 dwp_file
, unit_index
,
12804 comp_dir
, signature
,
12809 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12810 dwp_file
, unit_index
,
12811 comp_dir
, signature
,
12814 return (struct dwo_unit
*) *slot
;
12816 if (signature_in_table
== 0)
12818 hash
= (hash
+ hash2
) & mask
;
12821 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12822 " [in module %s]"),
12826 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12827 Open the file specified by FILE_NAME and hand it off to BFD for
12828 preliminary analysis. Return a newly initialized bfd *, which
12829 includes a canonicalized copy of FILE_NAME.
12830 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12831 SEARCH_CWD is true if the current directory is to be searched.
12832 It will be searched before debug-file-directory.
12833 If successful, the file is added to the bfd include table of the
12834 objfile's bfd (see gdb_bfd_record_inclusion).
12835 If unable to find/open the file, return NULL.
12836 NOTE: This function is derived from symfile_bfd_open. */
12838 static gdb_bfd_ref_ptr
12839 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12840 const char *file_name
, int is_dwp
, int search_cwd
)
12843 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12844 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12845 to debug_file_directory. */
12846 const char *search_path
;
12847 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12849 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12852 if (*debug_file_directory
!= '\0')
12854 search_path_holder
.reset (concat (".", dirname_separator_string
,
12855 debug_file_directory
,
12857 search_path
= search_path_holder
.get ();
12863 search_path
= debug_file_directory
;
12865 openp_flags flags
= OPF_RETURN_REALPATH
;
12867 flags
|= OPF_SEARCH_IN_PATH
;
12869 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12870 desc
= openp (search_path
, flags
, file_name
,
12871 O_RDONLY
| O_BINARY
, &absolute_name
);
12875 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12877 if (sym_bfd
== NULL
)
12879 bfd_set_cacheable (sym_bfd
.get (), 1);
12881 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12884 /* Success. Record the bfd as having been included by the objfile's bfd.
12885 This is important because things like demangled_names_hash lives in the
12886 objfile's per_bfd space and may have references to things like symbol
12887 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12888 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12893 /* Try to open DWO file FILE_NAME.
12894 COMP_DIR is the DW_AT_comp_dir attribute.
12895 The result is the bfd handle of the file.
12896 If there is a problem finding or opening the file, return NULL.
12897 Upon success, the canonicalized path of the file is stored in the bfd,
12898 same as symfile_bfd_open. */
12900 static gdb_bfd_ref_ptr
12901 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12902 const char *file_name
, const char *comp_dir
)
12904 if (IS_ABSOLUTE_PATH (file_name
))
12905 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12906 0 /*is_dwp*/, 0 /*search_cwd*/);
12908 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12910 if (comp_dir
!= NULL
)
12912 char *path_to_try
= concat (comp_dir
, SLASH_STRING
,
12913 file_name
, (char *) NULL
);
12915 /* NOTE: If comp_dir is a relative path, this will also try the
12916 search path, which seems useful. */
12917 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12920 1 /*search_cwd*/));
12921 xfree (path_to_try
);
12926 /* That didn't work, try debug-file-directory, which, despite its name,
12927 is a list of paths. */
12929 if (*debug_file_directory
== '\0')
12932 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12933 0 /*is_dwp*/, 1 /*search_cwd*/);
12936 /* This function is mapped across the sections and remembers the offset and
12937 size of each of the DWO debugging sections we are interested in. */
12940 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12942 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12943 const struct dwop_section_names
*names
= &dwop_section_names
;
12945 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12947 dwo_sections
->abbrev
.s
.section
= sectp
;
12948 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12950 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12952 dwo_sections
->info
.s
.section
= sectp
;
12953 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12955 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12957 dwo_sections
->line
.s
.section
= sectp
;
12958 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12960 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12962 dwo_sections
->loc
.s
.section
= sectp
;
12963 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12965 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12967 dwo_sections
->macinfo
.s
.section
= sectp
;
12968 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12970 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12972 dwo_sections
->macro
.s
.section
= sectp
;
12973 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12975 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12977 dwo_sections
->str
.s
.section
= sectp
;
12978 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12980 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12982 dwo_sections
->str_offsets
.s
.section
= sectp
;
12983 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12985 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12987 struct dwarf2_section_info type_section
;
12989 memset (&type_section
, 0, sizeof (type_section
));
12990 type_section
.s
.section
= sectp
;
12991 type_section
.size
= bfd_section_size (sectp
);
12992 dwo_sections
->types
.push_back (type_section
);
12996 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12997 by PER_CU. This is for the non-DWP case.
12998 The result is NULL if DWO_NAME can't be found. */
13000 static struct dwo_file
*
13001 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13002 const char *dwo_name
, const char *comp_dir
)
13004 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13006 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13009 if (dwarf_read_debug
)
13010 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13014 dwo_file_up
dwo_file (new struct dwo_file
);
13015 dwo_file
->dwo_name
= dwo_name
;
13016 dwo_file
->comp_dir
= comp_dir
;
13017 dwo_file
->dbfd
= std::move (dbfd
);
13019 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13020 &dwo_file
->sections
);
13022 create_cus_hash_table (dwarf2_per_objfile
, *dwo_file
, dwo_file
->sections
.info
,
13025 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13026 dwo_file
->sections
.types
, dwo_file
->tus
);
13028 if (dwarf_read_debug
)
13029 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13031 return dwo_file
.release ();
13034 /* This function is mapped across the sections and remembers the offset and
13035 size of each of the DWP debugging sections common to version 1 and 2 that
13036 we are interested in. */
13039 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13040 void *dwp_file_ptr
)
13042 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13043 const struct dwop_section_names
*names
= &dwop_section_names
;
13044 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13046 /* Record the ELF section number for later lookup: this is what the
13047 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13048 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13049 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13051 /* Look for specific sections that we need. */
13052 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13054 dwp_file
->sections
.str
.s
.section
= sectp
;
13055 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13057 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13059 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13060 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13062 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13064 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13065 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13069 /* This function is mapped across the sections and remembers the offset and
13070 size of each of the DWP version 2 debugging sections that we are interested
13071 in. This is split into a separate function because we don't know if we
13072 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13075 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13077 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13078 const struct dwop_section_names
*names
= &dwop_section_names
;
13079 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13081 /* Record the ELF section number for later lookup: this is what the
13082 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13083 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13084 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13086 /* Look for specific sections that we need. */
13087 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13089 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13090 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13092 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13094 dwp_file
->sections
.info
.s
.section
= sectp
;
13095 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13097 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13099 dwp_file
->sections
.line
.s
.section
= sectp
;
13100 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13102 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13104 dwp_file
->sections
.loc
.s
.section
= sectp
;
13105 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13107 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13109 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13110 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13112 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13114 dwp_file
->sections
.macro
.s
.section
= sectp
;
13115 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13117 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13119 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13120 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13122 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13124 dwp_file
->sections
.types
.s
.section
= sectp
;
13125 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13129 /* Hash function for dwp_file loaded CUs/TUs. */
13132 hash_dwp_loaded_cutus (const void *item
)
13134 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13136 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13137 return dwo_unit
->signature
;
13140 /* Equality function for dwp_file loaded CUs/TUs. */
13143 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13145 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13146 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13148 return dua
->signature
== dub
->signature
;
13151 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13154 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13156 return htab_create_alloc_ex (3,
13157 hash_dwp_loaded_cutus
,
13158 eq_dwp_loaded_cutus
,
13160 &objfile
->objfile_obstack
,
13161 hashtab_obstack_allocate
,
13162 dummy_obstack_deallocate
);
13165 /* Try to open DWP file FILE_NAME.
13166 The result is the bfd handle of the file.
13167 If there is a problem finding or opening the file, return NULL.
13168 Upon success, the canonicalized path of the file is stored in the bfd,
13169 same as symfile_bfd_open. */
13171 static gdb_bfd_ref_ptr
13172 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13173 const char *file_name
)
13175 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13177 1 /*search_cwd*/));
13181 /* Work around upstream bug 15652.
13182 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13183 [Whether that's a "bug" is debatable, but it is getting in our way.]
13184 We have no real idea where the dwp file is, because gdb's realpath-ing
13185 of the executable's path may have discarded the needed info.
13186 [IWBN if the dwp file name was recorded in the executable, akin to
13187 .gnu_debuglink, but that doesn't exist yet.]
13188 Strip the directory from FILE_NAME and search again. */
13189 if (*debug_file_directory
!= '\0')
13191 /* Don't implicitly search the current directory here.
13192 If the user wants to search "." to handle this case,
13193 it must be added to debug-file-directory. */
13194 return try_open_dwop_file (dwarf2_per_objfile
,
13195 lbasename (file_name
), 1 /*is_dwp*/,
13202 /* Initialize the use of the DWP file for the current objfile.
13203 By convention the name of the DWP file is ${objfile}.dwp.
13204 The result is NULL if it can't be found. */
13206 static std::unique_ptr
<struct dwp_file
>
13207 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13209 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13211 /* Try to find first .dwp for the binary file before any symbolic links
13214 /* If the objfile is a debug file, find the name of the real binary
13215 file and get the name of dwp file from there. */
13216 std::string dwp_name
;
13217 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13219 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13220 const char *backlink_basename
= lbasename (backlink
->original_name
);
13222 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13225 dwp_name
= objfile
->original_name
;
13227 dwp_name
+= ".dwp";
13229 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13231 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13233 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13234 dwp_name
= objfile_name (objfile
);
13235 dwp_name
+= ".dwp";
13236 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13241 if (dwarf_read_debug
)
13242 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13243 return std::unique_ptr
<dwp_file
> ();
13246 const char *name
= bfd_get_filename (dbfd
.get ());
13247 std::unique_ptr
<struct dwp_file
> dwp_file
13248 (new struct dwp_file (name
, std::move (dbfd
)));
13250 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13251 dwp_file
->elf_sections
=
13252 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13253 dwp_file
->num_sections
, asection
*);
13255 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13256 dwarf2_locate_common_dwp_sections
,
13259 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13262 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13265 /* The DWP file version is stored in the hash table. Oh well. */
13266 if (dwp_file
->cus
&& dwp_file
->tus
13267 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13269 /* Technically speaking, we should try to limp along, but this is
13270 pretty bizarre. We use pulongest here because that's the established
13271 portability solution (e.g, we cannot use %u for uint32_t). */
13272 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13273 " TU version %s [in DWP file %s]"),
13274 pulongest (dwp_file
->cus
->version
),
13275 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13279 dwp_file
->version
= dwp_file
->cus
->version
;
13280 else if (dwp_file
->tus
)
13281 dwp_file
->version
= dwp_file
->tus
->version
;
13283 dwp_file
->version
= 2;
13285 if (dwp_file
->version
== 2)
13286 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13287 dwarf2_locate_v2_dwp_sections
,
13290 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13291 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13293 if (dwarf_read_debug
)
13295 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13296 fprintf_unfiltered (gdb_stdlog
,
13297 " %s CUs, %s TUs\n",
13298 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13299 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13305 /* Wrapper around open_and_init_dwp_file, only open it once. */
13307 static struct dwp_file
*
13308 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13310 if (! dwarf2_per_objfile
->dwp_checked
)
13312 dwarf2_per_objfile
->dwp_file
13313 = open_and_init_dwp_file (dwarf2_per_objfile
);
13314 dwarf2_per_objfile
->dwp_checked
= 1;
13316 return dwarf2_per_objfile
->dwp_file
.get ();
13319 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13320 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13321 or in the DWP file for the objfile, referenced by THIS_UNIT.
13322 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13323 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13325 This is called, for example, when wanting to read a variable with a
13326 complex location. Therefore we don't want to do file i/o for every call.
13327 Therefore we don't want to look for a DWO file on every call.
13328 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13329 then we check if we've already seen DWO_NAME, and only THEN do we check
13332 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13333 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13335 static struct dwo_unit
*
13336 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13337 const char *dwo_name
, const char *comp_dir
,
13338 ULONGEST signature
, int is_debug_types
)
13340 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13341 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13342 const char *kind
= is_debug_types
? "TU" : "CU";
13343 void **dwo_file_slot
;
13344 struct dwo_file
*dwo_file
;
13345 struct dwp_file
*dwp_file
;
13347 /* First see if there's a DWP file.
13348 If we have a DWP file but didn't find the DWO inside it, don't
13349 look for the original DWO file. It makes gdb behave differently
13350 depending on whether one is debugging in the build tree. */
13352 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13353 if (dwp_file
!= NULL
)
13355 const struct dwp_hash_table
*dwp_htab
=
13356 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13358 if (dwp_htab
!= NULL
)
13360 struct dwo_unit
*dwo_cutu
=
13361 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13362 signature
, is_debug_types
);
13364 if (dwo_cutu
!= NULL
)
13366 if (dwarf_read_debug
)
13368 fprintf_unfiltered (gdb_stdlog
,
13369 "Virtual DWO %s %s found: @%s\n",
13370 kind
, hex_string (signature
),
13371 host_address_to_string (dwo_cutu
));
13379 /* No DWP file, look for the DWO file. */
13381 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13382 dwo_name
, comp_dir
);
13383 if (*dwo_file_slot
== NULL
)
13385 /* Read in the file and build a table of the CUs/TUs it contains. */
13386 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13388 /* NOTE: This will be NULL if unable to open the file. */
13389 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13391 if (dwo_file
!= NULL
)
13393 struct dwo_unit
*dwo_cutu
= NULL
;
13395 if (is_debug_types
&& dwo_file
->tus
)
13397 struct dwo_unit find_dwo_cutu
;
13399 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13400 find_dwo_cutu
.signature
= signature
;
13402 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13404 else if (!is_debug_types
&& dwo_file
->cus
)
13406 struct dwo_unit find_dwo_cutu
;
13408 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13409 find_dwo_cutu
.signature
= signature
;
13410 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13414 if (dwo_cutu
!= NULL
)
13416 if (dwarf_read_debug
)
13418 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13419 kind
, dwo_name
, hex_string (signature
),
13420 host_address_to_string (dwo_cutu
));
13427 /* We didn't find it. This could mean a dwo_id mismatch, or
13428 someone deleted the DWO/DWP file, or the search path isn't set up
13429 correctly to find the file. */
13431 if (dwarf_read_debug
)
13433 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13434 kind
, dwo_name
, hex_string (signature
));
13437 /* This is a warning and not a complaint because it can be caused by
13438 pilot error (e.g., user accidentally deleting the DWO). */
13440 /* Print the name of the DWP file if we looked there, helps the user
13441 better diagnose the problem. */
13442 std::string dwp_text
;
13444 if (dwp_file
!= NULL
)
13445 dwp_text
= string_printf (" [in DWP file %s]",
13446 lbasename (dwp_file
->name
));
13448 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13449 " [in module %s]"),
13450 kind
, dwo_name
, hex_string (signature
),
13452 this_unit
->is_debug_types
? "TU" : "CU",
13453 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13458 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13459 See lookup_dwo_cutu_unit for details. */
13461 static struct dwo_unit
*
13462 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13463 const char *dwo_name
, const char *comp_dir
,
13464 ULONGEST signature
)
13466 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13469 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13470 See lookup_dwo_cutu_unit for details. */
13472 static struct dwo_unit
*
13473 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13474 const char *dwo_name
, const char *comp_dir
)
13476 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13479 /* Traversal function for queue_and_load_all_dwo_tus. */
13482 queue_and_load_dwo_tu (void **slot
, void *info
)
13484 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13485 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13486 ULONGEST signature
= dwo_unit
->signature
;
13487 struct signatured_type
*sig_type
=
13488 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13490 if (sig_type
!= NULL
)
13492 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13494 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13495 a real dependency of PER_CU on SIG_TYPE. That is detected later
13496 while processing PER_CU. */
13497 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13498 load_full_type_unit (sig_cu
);
13499 per_cu
->imported_symtabs_push (sig_cu
);
13505 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13506 The DWO may have the only definition of the type, though it may not be
13507 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13508 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13511 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13513 struct dwo_unit
*dwo_unit
;
13514 struct dwo_file
*dwo_file
;
13516 gdb_assert (!per_cu
->is_debug_types
);
13517 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13518 gdb_assert (per_cu
->cu
!= NULL
);
13520 dwo_unit
= per_cu
->cu
->dwo_unit
;
13521 gdb_assert (dwo_unit
!= NULL
);
13523 dwo_file
= dwo_unit
->dwo_file
;
13524 if (dwo_file
->tus
!= NULL
)
13525 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13528 /* Read in various DIEs. */
13530 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13531 Inherit only the children of the DW_AT_abstract_origin DIE not being
13532 already referenced by DW_AT_abstract_origin from the children of the
13536 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13538 struct die_info
*child_die
;
13539 sect_offset
*offsetp
;
13540 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13541 struct die_info
*origin_die
;
13542 /* Iterator of the ORIGIN_DIE children. */
13543 struct die_info
*origin_child_die
;
13544 struct attribute
*attr
;
13545 struct dwarf2_cu
*origin_cu
;
13546 struct pending
**origin_previous_list_in_scope
;
13548 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13552 /* Note that following die references may follow to a die in a
13556 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13558 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13560 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13561 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13563 if (die
->tag
!= origin_die
->tag
13564 && !(die
->tag
== DW_TAG_inlined_subroutine
13565 && origin_die
->tag
== DW_TAG_subprogram
))
13566 complaint (_("DIE %s and its abstract origin %s have different tags"),
13567 sect_offset_str (die
->sect_off
),
13568 sect_offset_str (origin_die
->sect_off
));
13570 std::vector
<sect_offset
> offsets
;
13572 for (child_die
= die
->child
;
13573 child_die
&& child_die
->tag
;
13574 child_die
= sibling_die (child_die
))
13576 struct die_info
*child_origin_die
;
13577 struct dwarf2_cu
*child_origin_cu
;
13579 /* We are trying to process concrete instance entries:
13580 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13581 it's not relevant to our analysis here. i.e. detecting DIEs that are
13582 present in the abstract instance but not referenced in the concrete
13584 if (child_die
->tag
== DW_TAG_call_site
13585 || child_die
->tag
== DW_TAG_GNU_call_site
)
13588 /* For each CHILD_DIE, find the corresponding child of
13589 ORIGIN_DIE. If there is more than one layer of
13590 DW_AT_abstract_origin, follow them all; there shouldn't be,
13591 but GCC versions at least through 4.4 generate this (GCC PR
13593 child_origin_die
= child_die
;
13594 child_origin_cu
= cu
;
13597 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13601 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13605 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13606 counterpart may exist. */
13607 if (child_origin_die
!= child_die
)
13609 if (child_die
->tag
!= child_origin_die
->tag
13610 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13611 && child_origin_die
->tag
== DW_TAG_subprogram
))
13612 complaint (_("Child DIE %s and its abstract origin %s have "
13614 sect_offset_str (child_die
->sect_off
),
13615 sect_offset_str (child_origin_die
->sect_off
));
13616 if (child_origin_die
->parent
!= origin_die
)
13617 complaint (_("Child DIE %s and its abstract origin %s have "
13618 "different parents"),
13619 sect_offset_str (child_die
->sect_off
),
13620 sect_offset_str (child_origin_die
->sect_off
));
13622 offsets
.push_back (child_origin_die
->sect_off
);
13625 std::sort (offsets
.begin (), offsets
.end ());
13626 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13627 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13628 if (offsetp
[-1] == *offsetp
)
13629 complaint (_("Multiple children of DIE %s refer "
13630 "to DIE %s as their abstract origin"),
13631 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13633 offsetp
= offsets
.data ();
13634 origin_child_die
= origin_die
->child
;
13635 while (origin_child_die
&& origin_child_die
->tag
)
13637 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13638 while (offsetp
< offsets_end
13639 && *offsetp
< origin_child_die
->sect_off
)
13641 if (offsetp
>= offsets_end
13642 || *offsetp
> origin_child_die
->sect_off
)
13644 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13645 Check whether we're already processing ORIGIN_CHILD_DIE.
13646 This can happen with mutually referenced abstract_origins.
13648 if (!origin_child_die
->in_process
)
13649 process_die (origin_child_die
, origin_cu
);
13651 origin_child_die
= sibling_die (origin_child_die
);
13653 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13657 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13661 struct context_stack
*newobj
;
13664 struct die_info
*child_die
;
13665 struct attribute
*attr
, *call_line
, *call_file
;
13667 CORE_ADDR baseaddr
;
13668 struct block
*block
;
13669 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13670 std::vector
<struct symbol
*> template_args
;
13671 struct template_symbol
*templ_func
= NULL
;
13675 /* If we do not have call site information, we can't show the
13676 caller of this inlined function. That's too confusing, so
13677 only use the scope for local variables. */
13678 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13679 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13680 if (call_line
== NULL
|| call_file
== NULL
)
13682 read_lexical_block_scope (die
, cu
);
13687 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13689 name
= dwarf2_name (die
, cu
);
13691 /* Ignore functions with missing or empty names. These are actually
13692 illegal according to the DWARF standard. */
13695 complaint (_("missing name for subprogram DIE at %s"),
13696 sect_offset_str (die
->sect_off
));
13700 /* Ignore functions with missing or invalid low and high pc attributes. */
13701 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13702 <= PC_BOUNDS_INVALID
)
13704 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13705 if (!attr
|| !DW_UNSND (attr
))
13706 complaint (_("cannot get low and high bounds "
13707 "for subprogram DIE at %s"),
13708 sect_offset_str (die
->sect_off
));
13712 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13713 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13715 /* If we have any template arguments, then we must allocate a
13716 different sort of symbol. */
13717 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13719 if (child_die
->tag
== DW_TAG_template_type_param
13720 || child_die
->tag
== DW_TAG_template_value_param
)
13722 templ_func
= allocate_template_symbol (objfile
);
13723 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13728 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13729 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13730 (struct symbol
*) templ_func
);
13732 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13733 set_objfile_main_name (objfile
, SYMBOL_LINKAGE_NAME (newobj
->name
),
13736 /* If there is a location expression for DW_AT_frame_base, record
13738 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13740 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13742 /* If there is a location for the static link, record it. */
13743 newobj
->static_link
= NULL
;
13744 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13747 newobj
->static_link
13748 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13749 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13750 dwarf2_per_cu_addr_type (cu
->per_cu
));
13753 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13755 if (die
->child
!= NULL
)
13757 child_die
= die
->child
;
13758 while (child_die
&& child_die
->tag
)
13760 if (child_die
->tag
== DW_TAG_template_type_param
13761 || child_die
->tag
== DW_TAG_template_value_param
)
13763 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13766 template_args
.push_back (arg
);
13769 process_die (child_die
, cu
);
13770 child_die
= sibling_die (child_die
);
13774 inherit_abstract_dies (die
, cu
);
13776 /* If we have a DW_AT_specification, we might need to import using
13777 directives from the context of the specification DIE. See the
13778 comment in determine_prefix. */
13779 if (cu
->language
== language_cplus
13780 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13782 struct dwarf2_cu
*spec_cu
= cu
;
13783 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13787 child_die
= spec_die
->child
;
13788 while (child_die
&& child_die
->tag
)
13790 if (child_die
->tag
== DW_TAG_imported_module
)
13791 process_die (child_die
, spec_cu
);
13792 child_die
= sibling_die (child_die
);
13795 /* In some cases, GCC generates specification DIEs that
13796 themselves contain DW_AT_specification attributes. */
13797 spec_die
= die_specification (spec_die
, &spec_cu
);
13801 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13802 /* Make a block for the local symbols within. */
13803 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13804 cstk
.static_link
, lowpc
, highpc
);
13806 /* For C++, set the block's scope. */
13807 if ((cu
->language
== language_cplus
13808 || cu
->language
== language_fortran
13809 || cu
->language
== language_d
13810 || cu
->language
== language_rust
)
13811 && cu
->processing_has_namespace_info
)
13812 block_set_scope (block
, determine_prefix (die
, cu
),
13813 &objfile
->objfile_obstack
);
13815 /* If we have address ranges, record them. */
13816 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13818 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13820 /* Attach template arguments to function. */
13821 if (!template_args
.empty ())
13823 gdb_assert (templ_func
!= NULL
);
13825 templ_func
->n_template_arguments
= template_args
.size ();
13826 templ_func
->template_arguments
13827 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13828 templ_func
->n_template_arguments
);
13829 memcpy (templ_func
->template_arguments
,
13830 template_args
.data (),
13831 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13833 /* Make sure that the symtab is set on the new symbols. Even
13834 though they don't appear in this symtab directly, other parts
13835 of gdb assume that symbols do, and this is reasonably
13837 for (symbol
*sym
: template_args
)
13838 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13841 /* In C++, we can have functions nested inside functions (e.g., when
13842 a function declares a class that has methods). This means that
13843 when we finish processing a function scope, we may need to go
13844 back to building a containing block's symbol lists. */
13845 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13846 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13848 /* If we've finished processing a top-level function, subsequent
13849 symbols go in the file symbol list. */
13850 if (cu
->get_builder ()->outermost_context_p ())
13851 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13854 /* Process all the DIES contained within a lexical block scope. Start
13855 a new scope, process the dies, and then close the scope. */
13858 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13860 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13861 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13862 CORE_ADDR lowpc
, highpc
;
13863 struct die_info
*child_die
;
13864 CORE_ADDR baseaddr
;
13866 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13868 /* Ignore blocks with missing or invalid low and high pc attributes. */
13869 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13870 as multiple lexical blocks? Handling children in a sane way would
13871 be nasty. Might be easier to properly extend generic blocks to
13872 describe ranges. */
13873 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13875 case PC_BOUNDS_NOT_PRESENT
:
13876 /* DW_TAG_lexical_block has no attributes, process its children as if
13877 there was no wrapping by that DW_TAG_lexical_block.
13878 GCC does no longer produces such DWARF since GCC r224161. */
13879 for (child_die
= die
->child
;
13880 child_die
!= NULL
&& child_die
->tag
;
13881 child_die
= sibling_die (child_die
))
13882 process_die (child_die
, cu
);
13884 case PC_BOUNDS_INVALID
:
13887 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13888 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13890 cu
->get_builder ()->push_context (0, lowpc
);
13891 if (die
->child
!= NULL
)
13893 child_die
= die
->child
;
13894 while (child_die
&& child_die
->tag
)
13896 process_die (child_die
, cu
);
13897 child_die
= sibling_die (child_die
);
13900 inherit_abstract_dies (die
, cu
);
13901 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13903 if (*cu
->get_builder ()->get_local_symbols () != NULL
13904 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13906 struct block
*block
13907 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13908 cstk
.start_addr
, highpc
);
13910 /* Note that recording ranges after traversing children, as we
13911 do here, means that recording a parent's ranges entails
13912 walking across all its children's ranges as they appear in
13913 the address map, which is quadratic behavior.
13915 It would be nicer to record the parent's ranges before
13916 traversing its children, simply overriding whatever you find
13917 there. But since we don't even decide whether to create a
13918 block until after we've traversed its children, that's hard
13920 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13922 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13923 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13926 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13929 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13931 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13932 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13933 CORE_ADDR pc
, baseaddr
;
13934 struct attribute
*attr
;
13935 struct call_site
*call_site
, call_site_local
;
13938 struct die_info
*child_die
;
13940 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13942 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13945 /* This was a pre-DWARF-5 GNU extension alias
13946 for DW_AT_call_return_pc. */
13947 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13951 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13952 "DIE %s [in module %s]"),
13953 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13956 pc
= attr_value_as_address (attr
) + baseaddr
;
13957 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13959 if (cu
->call_site_htab
== NULL
)
13960 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13961 NULL
, &objfile
->objfile_obstack
,
13962 hashtab_obstack_allocate
, NULL
);
13963 call_site_local
.pc
= pc
;
13964 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13967 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13968 "DIE %s [in module %s]"),
13969 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13970 objfile_name (objfile
));
13974 /* Count parameters at the caller. */
13977 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13978 child_die
= sibling_die (child_die
))
13980 if (child_die
->tag
!= DW_TAG_call_site_parameter
13981 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13983 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13984 "DW_TAG_call_site child DIE %s [in module %s]"),
13985 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13986 objfile_name (objfile
));
13994 = ((struct call_site
*)
13995 obstack_alloc (&objfile
->objfile_obstack
,
13996 sizeof (*call_site
)
13997 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13999 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14000 call_site
->pc
= pc
;
14002 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14003 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14005 struct die_info
*func_die
;
14007 /* Skip also over DW_TAG_inlined_subroutine. */
14008 for (func_die
= die
->parent
;
14009 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14010 && func_die
->tag
!= DW_TAG_subroutine_type
;
14011 func_die
= func_die
->parent
);
14013 /* DW_AT_call_all_calls is a superset
14014 of DW_AT_call_all_tail_calls. */
14016 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14017 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14018 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14019 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14021 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14022 not complete. But keep CALL_SITE for look ups via call_site_htab,
14023 both the initial caller containing the real return address PC and
14024 the final callee containing the current PC of a chain of tail
14025 calls do not need to have the tail call list complete. But any
14026 function candidate for a virtual tail call frame searched via
14027 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14028 determined unambiguously. */
14032 struct type
*func_type
= NULL
;
14035 func_type
= get_die_type (func_die
, cu
);
14036 if (func_type
!= NULL
)
14038 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14040 /* Enlist this call site to the function. */
14041 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14042 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14045 complaint (_("Cannot find function owning DW_TAG_call_site "
14046 "DIE %s [in module %s]"),
14047 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14051 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14053 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14055 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14058 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14059 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14061 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14062 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14063 /* Keep NULL DWARF_BLOCK. */;
14064 else if (attr_form_is_block (attr
))
14066 struct dwarf2_locexpr_baton
*dlbaton
;
14068 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14069 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14070 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14071 dlbaton
->per_cu
= cu
->per_cu
;
14073 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14075 else if (attr_form_is_ref (attr
))
14077 struct dwarf2_cu
*target_cu
= cu
;
14078 struct die_info
*target_die
;
14080 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14081 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14082 if (die_is_declaration (target_die
, target_cu
))
14084 const char *target_physname
;
14086 /* Prefer the mangled name; otherwise compute the demangled one. */
14087 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14088 if (target_physname
== NULL
)
14089 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14090 if (target_physname
== NULL
)
14091 complaint (_("DW_AT_call_target target DIE has invalid "
14092 "physname, for referencing DIE %s [in module %s]"),
14093 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14095 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14101 /* DW_AT_entry_pc should be preferred. */
14102 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14103 <= PC_BOUNDS_INVALID
)
14104 complaint (_("DW_AT_call_target target DIE has invalid "
14105 "low pc, for referencing DIE %s [in module %s]"),
14106 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14109 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14110 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14115 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14116 "block nor reference, for DIE %s [in module %s]"),
14117 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14119 call_site
->per_cu
= cu
->per_cu
;
14121 for (child_die
= die
->child
;
14122 child_die
&& child_die
->tag
;
14123 child_die
= sibling_die (child_die
))
14125 struct call_site_parameter
*parameter
;
14126 struct attribute
*loc
, *origin
;
14128 if (child_die
->tag
!= DW_TAG_call_site_parameter
14129 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14131 /* Already printed the complaint above. */
14135 gdb_assert (call_site
->parameter_count
< nparams
);
14136 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14138 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14139 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14140 register is contained in DW_AT_call_value. */
14142 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14143 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14144 if (origin
== NULL
)
14146 /* This was a pre-DWARF-5 GNU extension alias
14147 for DW_AT_call_parameter. */
14148 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14150 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14152 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14154 sect_offset sect_off
14155 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14156 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14158 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14159 binding can be done only inside one CU. Such referenced DIE
14160 therefore cannot be even moved to DW_TAG_partial_unit. */
14161 complaint (_("DW_AT_call_parameter offset is not in CU for "
14162 "DW_TAG_call_site child DIE %s [in module %s]"),
14163 sect_offset_str (child_die
->sect_off
),
14164 objfile_name (objfile
));
14167 parameter
->u
.param_cu_off
14168 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14170 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14172 complaint (_("No DW_FORM_block* DW_AT_location for "
14173 "DW_TAG_call_site child DIE %s [in module %s]"),
14174 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14179 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14180 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14181 if (parameter
->u
.dwarf_reg
!= -1)
14182 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14183 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14184 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14185 ¶meter
->u
.fb_offset
))
14186 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14189 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14190 "for DW_FORM_block* DW_AT_location is supported for "
14191 "DW_TAG_call_site child DIE %s "
14193 sect_offset_str (child_die
->sect_off
),
14194 objfile_name (objfile
));
14199 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14201 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14202 if (!attr_form_is_block (attr
))
14204 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14205 "DW_TAG_call_site child DIE %s [in module %s]"),
14206 sect_offset_str (child_die
->sect_off
),
14207 objfile_name (objfile
));
14210 parameter
->value
= DW_BLOCK (attr
)->data
;
14211 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14213 /* Parameters are not pre-cleared by memset above. */
14214 parameter
->data_value
= NULL
;
14215 parameter
->data_value_size
= 0;
14216 call_site
->parameter_count
++;
14218 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14220 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14223 if (!attr_form_is_block (attr
))
14224 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14225 "DW_TAG_call_site child DIE %s [in module %s]"),
14226 sect_offset_str (child_die
->sect_off
),
14227 objfile_name (objfile
));
14230 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14231 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14237 /* Helper function for read_variable. If DIE represents a virtual
14238 table, then return the type of the concrete object that is
14239 associated with the virtual table. Otherwise, return NULL. */
14241 static struct type
*
14242 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14244 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14248 /* Find the type DIE. */
14249 struct die_info
*type_die
= NULL
;
14250 struct dwarf2_cu
*type_cu
= cu
;
14252 if (attr_form_is_ref (attr
))
14253 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14254 if (type_die
== NULL
)
14257 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14259 return die_containing_type (type_die
, type_cu
);
14262 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14265 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14267 struct rust_vtable_symbol
*storage
= NULL
;
14269 if (cu
->language
== language_rust
)
14271 struct type
*containing_type
= rust_containing_type (die
, cu
);
14273 if (containing_type
!= NULL
)
14275 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14277 storage
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
14278 struct rust_vtable_symbol
);
14279 initialize_objfile_symbol (storage
);
14280 storage
->concrete_type
= containing_type
;
14281 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14285 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14286 struct attribute
*abstract_origin
14287 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14288 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14289 if (res
== NULL
&& loc
&& abstract_origin
)
14291 /* We have a variable without a name, but with a location and an abstract
14292 origin. This may be a concrete instance of an abstract variable
14293 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14295 struct dwarf2_cu
*origin_cu
= cu
;
14296 struct die_info
*origin_die
14297 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14298 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14299 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14303 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14304 reading .debug_rnglists.
14305 Callback's type should be:
14306 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14307 Return true if the attributes are present and valid, otherwise,
14310 template <typename Callback
>
14312 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14313 Callback
&&callback
)
14315 struct dwarf2_per_objfile
*dwarf2_per_objfile
14316 = cu
->per_cu
->dwarf2_per_objfile
;
14317 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14318 bfd
*obfd
= objfile
->obfd
;
14319 /* Base address selection entry. */
14322 const gdb_byte
*buffer
;
14323 CORE_ADDR baseaddr
;
14324 bool overflow
= false;
14326 found_base
= cu
->base_known
;
14327 base
= cu
->base_address
;
14329 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14330 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14332 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14336 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14338 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14342 /* Initialize it due to a false compiler warning. */
14343 CORE_ADDR range_beginning
= 0, range_end
= 0;
14344 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14345 + dwarf2_per_objfile
->rnglists
.size
);
14346 unsigned int bytes_read
;
14348 if (buffer
== buf_end
)
14353 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14356 case DW_RLE_end_of_list
:
14358 case DW_RLE_base_address
:
14359 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14364 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14366 buffer
+= bytes_read
;
14368 case DW_RLE_start_length
:
14369 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14374 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14375 buffer
+= bytes_read
;
14376 range_end
= (range_beginning
14377 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14378 buffer
+= bytes_read
;
14379 if (buffer
> buf_end
)
14385 case DW_RLE_offset_pair
:
14386 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14387 buffer
+= bytes_read
;
14388 if (buffer
> buf_end
)
14393 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14394 buffer
+= bytes_read
;
14395 if (buffer
> buf_end
)
14401 case DW_RLE_start_end
:
14402 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14407 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14408 buffer
+= bytes_read
;
14409 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14410 buffer
+= bytes_read
;
14413 complaint (_("Invalid .debug_rnglists data (no base address)"));
14416 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14418 if (rlet
== DW_RLE_base_address
)
14423 /* We have no valid base address for the ranges
14425 complaint (_("Invalid .debug_rnglists data (no base address)"));
14429 if (range_beginning
> range_end
)
14431 /* Inverted range entries are invalid. */
14432 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14436 /* Empty range entries have no effect. */
14437 if (range_beginning
== range_end
)
14440 range_beginning
+= base
;
14443 /* A not-uncommon case of bad debug info.
14444 Don't pollute the addrmap with bad data. */
14445 if (range_beginning
+ baseaddr
== 0
14446 && !dwarf2_per_objfile
->has_section_at_zero
)
14448 complaint (_(".debug_rnglists entry has start address of zero"
14449 " [in module %s]"), objfile_name (objfile
));
14453 callback (range_beginning
, range_end
);
14458 complaint (_("Offset %d is not terminated "
14459 "for DW_AT_ranges attribute"),
14467 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14468 Callback's type should be:
14469 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14470 Return 1 if the attributes are present and valid, otherwise, return 0. */
14472 template <typename Callback
>
14474 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14475 Callback
&&callback
)
14477 struct dwarf2_per_objfile
*dwarf2_per_objfile
14478 = cu
->per_cu
->dwarf2_per_objfile
;
14479 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14480 struct comp_unit_head
*cu_header
= &cu
->header
;
14481 bfd
*obfd
= objfile
->obfd
;
14482 unsigned int addr_size
= cu_header
->addr_size
;
14483 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14484 /* Base address selection entry. */
14487 unsigned int dummy
;
14488 const gdb_byte
*buffer
;
14489 CORE_ADDR baseaddr
;
14491 if (cu_header
->version
>= 5)
14492 return dwarf2_rnglists_process (offset
, cu
, callback
);
14494 found_base
= cu
->base_known
;
14495 base
= cu
->base_address
;
14497 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14498 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14500 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14504 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14506 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14510 CORE_ADDR range_beginning
, range_end
;
14512 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14513 buffer
+= addr_size
;
14514 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14515 buffer
+= addr_size
;
14516 offset
+= 2 * addr_size
;
14518 /* An end of list marker is a pair of zero addresses. */
14519 if (range_beginning
== 0 && range_end
== 0)
14520 /* Found the end of list entry. */
14523 /* Each base address selection entry is a pair of 2 values.
14524 The first is the largest possible address, the second is
14525 the base address. Check for a base address here. */
14526 if ((range_beginning
& mask
) == mask
)
14528 /* If we found the largest possible address, then we already
14529 have the base address in range_end. */
14537 /* We have no valid base address for the ranges
14539 complaint (_("Invalid .debug_ranges data (no base address)"));
14543 if (range_beginning
> range_end
)
14545 /* Inverted range entries are invalid. */
14546 complaint (_("Invalid .debug_ranges data (inverted range)"));
14550 /* Empty range entries have no effect. */
14551 if (range_beginning
== range_end
)
14554 range_beginning
+= base
;
14557 /* A not-uncommon case of bad debug info.
14558 Don't pollute the addrmap with bad data. */
14559 if (range_beginning
+ baseaddr
== 0
14560 && !dwarf2_per_objfile
->has_section_at_zero
)
14562 complaint (_(".debug_ranges entry has start address of zero"
14563 " [in module %s]"), objfile_name (objfile
));
14567 callback (range_beginning
, range_end
);
14573 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14574 Return 1 if the attributes are present and valid, otherwise, return 0.
14575 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14578 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14579 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14580 struct partial_symtab
*ranges_pst
)
14582 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14583 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14584 const CORE_ADDR baseaddr
= ANOFFSET (objfile
->section_offsets
,
14585 SECT_OFF_TEXT (objfile
));
14588 CORE_ADDR high
= 0;
14591 retval
= dwarf2_ranges_process (offset
, cu
,
14592 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14594 if (ranges_pst
!= NULL
)
14599 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14600 range_beginning
+ baseaddr
)
14602 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14603 range_end
+ baseaddr
)
14605 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14606 lowpc
, highpc
- 1, ranges_pst
);
14609 /* FIXME: This is recording everything as a low-high
14610 segment of consecutive addresses. We should have a
14611 data structure for discontiguous block ranges
14615 low
= range_beginning
;
14621 if (range_beginning
< low
)
14622 low
= range_beginning
;
14623 if (range_end
> high
)
14631 /* If the first entry is an end-of-list marker, the range
14632 describes an empty scope, i.e. no instructions. */
14638 *high_return
= high
;
14642 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14643 definition for the return value. *LOWPC and *HIGHPC are set iff
14644 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14646 static enum pc_bounds_kind
14647 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14648 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14649 struct partial_symtab
*pst
)
14651 struct dwarf2_per_objfile
*dwarf2_per_objfile
14652 = cu
->per_cu
->dwarf2_per_objfile
;
14653 struct attribute
*attr
;
14654 struct attribute
*attr_high
;
14656 CORE_ADDR high
= 0;
14657 enum pc_bounds_kind ret
;
14659 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14662 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14665 low
= attr_value_as_address (attr
);
14666 high
= attr_value_as_address (attr_high
);
14667 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14671 /* Found high w/o low attribute. */
14672 return PC_BOUNDS_INVALID
;
14674 /* Found consecutive range of addresses. */
14675 ret
= PC_BOUNDS_HIGH_LOW
;
14679 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14682 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14683 We take advantage of the fact that DW_AT_ranges does not appear
14684 in DW_TAG_compile_unit of DWO files. */
14685 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14686 unsigned int ranges_offset
= (DW_UNSND (attr
)
14687 + (need_ranges_base
14691 /* Value of the DW_AT_ranges attribute is the offset in the
14692 .debug_ranges section. */
14693 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14694 return PC_BOUNDS_INVALID
;
14695 /* Found discontinuous range of addresses. */
14696 ret
= PC_BOUNDS_RANGES
;
14699 return PC_BOUNDS_NOT_PRESENT
;
14702 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14704 return PC_BOUNDS_INVALID
;
14706 /* When using the GNU linker, .gnu.linkonce. sections are used to
14707 eliminate duplicate copies of functions and vtables and such.
14708 The linker will arbitrarily choose one and discard the others.
14709 The AT_*_pc values for such functions refer to local labels in
14710 these sections. If the section from that file was discarded, the
14711 labels are not in the output, so the relocs get a value of 0.
14712 If this is a discarded function, mark the pc bounds as invalid,
14713 so that GDB will ignore it. */
14714 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14715 return PC_BOUNDS_INVALID
;
14723 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14724 its low and high PC addresses. Do nothing if these addresses could not
14725 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14726 and HIGHPC to the high address if greater than HIGHPC. */
14729 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14730 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14731 struct dwarf2_cu
*cu
)
14733 CORE_ADDR low
, high
;
14734 struct die_info
*child
= die
->child
;
14736 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14738 *lowpc
= std::min (*lowpc
, low
);
14739 *highpc
= std::max (*highpc
, high
);
14742 /* If the language does not allow nested subprograms (either inside
14743 subprograms or lexical blocks), we're done. */
14744 if (cu
->language
!= language_ada
)
14747 /* Check all the children of the given DIE. If it contains nested
14748 subprograms, then check their pc bounds. Likewise, we need to
14749 check lexical blocks as well, as they may also contain subprogram
14751 while (child
&& child
->tag
)
14753 if (child
->tag
== DW_TAG_subprogram
14754 || child
->tag
== DW_TAG_lexical_block
)
14755 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14756 child
= sibling_die (child
);
14760 /* Get the low and high pc's represented by the scope DIE, and store
14761 them in *LOWPC and *HIGHPC. If the correct values can't be
14762 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14765 get_scope_pc_bounds (struct die_info
*die
,
14766 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14767 struct dwarf2_cu
*cu
)
14769 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14770 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14771 CORE_ADDR current_low
, current_high
;
14773 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14774 >= PC_BOUNDS_RANGES
)
14776 best_low
= current_low
;
14777 best_high
= current_high
;
14781 struct die_info
*child
= die
->child
;
14783 while (child
&& child
->tag
)
14785 switch (child
->tag
) {
14786 case DW_TAG_subprogram
:
14787 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14789 case DW_TAG_namespace
:
14790 case DW_TAG_module
:
14791 /* FIXME: carlton/2004-01-16: Should we do this for
14792 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14793 that current GCC's always emit the DIEs corresponding
14794 to definitions of methods of classes as children of a
14795 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14796 the DIEs giving the declarations, which could be
14797 anywhere). But I don't see any reason why the
14798 standards says that they have to be there. */
14799 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14801 if (current_low
!= ((CORE_ADDR
) -1))
14803 best_low
= std::min (best_low
, current_low
);
14804 best_high
= std::max (best_high
, current_high
);
14812 child
= sibling_die (child
);
14817 *highpc
= best_high
;
14820 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14824 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14825 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14827 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14828 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14829 struct attribute
*attr
;
14830 struct attribute
*attr_high
;
14832 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14835 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14838 CORE_ADDR low
= attr_value_as_address (attr
);
14839 CORE_ADDR high
= attr_value_as_address (attr_high
);
14841 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14844 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14845 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14846 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14850 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14853 /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton.
14854 We take advantage of the fact that DW_AT_ranges does not appear
14855 in DW_TAG_compile_unit of DWO files. */
14856 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14858 /* The value of the DW_AT_ranges attribute is the offset of the
14859 address range list in the .debug_ranges section. */
14860 unsigned long offset
= (DW_UNSND (attr
)
14861 + (need_ranges_base
? cu
->ranges_base
: 0));
14863 std::vector
<blockrange
> blockvec
;
14864 dwarf2_ranges_process (offset
, cu
,
14865 [&] (CORE_ADDR start
, CORE_ADDR end
)
14869 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14870 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14871 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14872 blockvec
.emplace_back (start
, end
);
14875 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14879 /* Check whether the producer field indicates either of GCC < 4.6, or the
14880 Intel C/C++ compiler, and cache the result in CU. */
14883 check_producer (struct dwarf2_cu
*cu
)
14887 if (cu
->producer
== NULL
)
14889 /* For unknown compilers expect their behavior is DWARF version
14892 GCC started to support .debug_types sections by -gdwarf-4 since
14893 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14894 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14895 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14896 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14898 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14900 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14901 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14903 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14905 cu
->producer_is_icc
= true;
14906 cu
->producer_is_icc_lt_14
= major
< 14;
14908 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14909 cu
->producer_is_codewarrior
= true;
14912 /* For other non-GCC compilers, expect their behavior is DWARF version
14916 cu
->checked_producer
= true;
14919 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14920 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14921 during 4.6.0 experimental. */
14924 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14926 if (!cu
->checked_producer
)
14927 check_producer (cu
);
14929 return cu
->producer_is_gxx_lt_4_6
;
14933 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14934 with incorrect is_stmt attributes. */
14937 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14939 if (!cu
->checked_producer
)
14940 check_producer (cu
);
14942 return cu
->producer_is_codewarrior
;
14945 /* Return the default accessibility type if it is not overriden by
14946 DW_AT_accessibility. */
14948 static enum dwarf_access_attribute
14949 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14951 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14953 /* The default DWARF 2 accessibility for members is public, the default
14954 accessibility for inheritance is private. */
14956 if (die
->tag
!= DW_TAG_inheritance
)
14957 return DW_ACCESS_public
;
14959 return DW_ACCESS_private
;
14963 /* DWARF 3+ defines the default accessibility a different way. The same
14964 rules apply now for DW_TAG_inheritance as for the members and it only
14965 depends on the container kind. */
14967 if (die
->parent
->tag
== DW_TAG_class_type
)
14968 return DW_ACCESS_private
;
14970 return DW_ACCESS_public
;
14974 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14975 offset. If the attribute was not found return 0, otherwise return
14976 1. If it was found but could not properly be handled, set *OFFSET
14980 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14983 struct attribute
*attr
;
14985 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14990 /* Note that we do not check for a section offset first here.
14991 This is because DW_AT_data_member_location is new in DWARF 4,
14992 so if we see it, we can assume that a constant form is really
14993 a constant and not a section offset. */
14994 if (attr_form_is_constant (attr
))
14995 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14996 else if (attr_form_is_section_offset (attr
))
14997 dwarf2_complex_location_expr_complaint ();
14998 else if (attr_form_is_block (attr
))
14999 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15001 dwarf2_complex_location_expr_complaint ();
15009 /* Add an aggregate field to the field list. */
15012 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15013 struct dwarf2_cu
*cu
)
15015 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15016 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15017 struct nextfield
*new_field
;
15018 struct attribute
*attr
;
15020 const char *fieldname
= "";
15022 if (die
->tag
== DW_TAG_inheritance
)
15024 fip
->baseclasses
.emplace_back ();
15025 new_field
= &fip
->baseclasses
.back ();
15029 fip
->fields
.emplace_back ();
15030 new_field
= &fip
->fields
.back ();
15035 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15037 new_field
->accessibility
= DW_UNSND (attr
);
15039 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15040 if (new_field
->accessibility
!= DW_ACCESS_public
)
15041 fip
->non_public_fields
= 1;
15043 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15045 new_field
->virtuality
= DW_UNSND (attr
);
15047 new_field
->virtuality
= DW_VIRTUALITY_none
;
15049 fp
= &new_field
->field
;
15051 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15055 /* Data member other than a C++ static data member. */
15057 /* Get type of field. */
15058 fp
->type
= die_type (die
, cu
);
15060 SET_FIELD_BITPOS (*fp
, 0);
15062 /* Get bit size of field (zero if none). */
15063 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15066 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15070 FIELD_BITSIZE (*fp
) = 0;
15073 /* Get bit offset of field. */
15074 if (handle_data_member_location (die
, cu
, &offset
))
15075 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15076 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15079 if (gdbarch_bits_big_endian (gdbarch
))
15081 /* For big endian bits, the DW_AT_bit_offset gives the
15082 additional bit offset from the MSB of the containing
15083 anonymous object to the MSB of the field. We don't
15084 have to do anything special since we don't need to
15085 know the size of the anonymous object. */
15086 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15090 /* For little endian bits, compute the bit offset to the
15091 MSB of the anonymous object, subtract off the number of
15092 bits from the MSB of the field to the MSB of the
15093 object, and then subtract off the number of bits of
15094 the field itself. The result is the bit offset of
15095 the LSB of the field. */
15096 int anonymous_size
;
15097 int bit_offset
= DW_UNSND (attr
);
15099 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15102 /* The size of the anonymous object containing
15103 the bit field is explicit, so use the
15104 indicated size (in bytes). */
15105 anonymous_size
= DW_UNSND (attr
);
15109 /* The size of the anonymous object containing
15110 the bit field must be inferred from the type
15111 attribute of the data member containing the
15113 anonymous_size
= TYPE_LENGTH (fp
->type
);
15115 SET_FIELD_BITPOS (*fp
,
15116 (FIELD_BITPOS (*fp
)
15117 + anonymous_size
* bits_per_byte
15118 - bit_offset
- FIELD_BITSIZE (*fp
)));
15121 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15123 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15124 + dwarf2_get_attr_constant_value (attr
, 0)));
15126 /* Get name of field. */
15127 fieldname
= dwarf2_name (die
, cu
);
15128 if (fieldname
== NULL
)
15131 /* The name is already allocated along with this objfile, so we don't
15132 need to duplicate it for the type. */
15133 fp
->name
= fieldname
;
15135 /* Change accessibility for artificial fields (e.g. virtual table
15136 pointer or virtual base class pointer) to private. */
15137 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15139 FIELD_ARTIFICIAL (*fp
) = 1;
15140 new_field
->accessibility
= DW_ACCESS_private
;
15141 fip
->non_public_fields
= 1;
15144 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15146 /* C++ static member. */
15148 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15149 is a declaration, but all versions of G++ as of this writing
15150 (so through at least 3.2.1) incorrectly generate
15151 DW_TAG_variable tags. */
15153 const char *physname
;
15155 /* Get name of field. */
15156 fieldname
= dwarf2_name (die
, cu
);
15157 if (fieldname
== NULL
)
15160 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15162 /* Only create a symbol if this is an external value.
15163 new_symbol checks this and puts the value in the global symbol
15164 table, which we want. If it is not external, new_symbol
15165 will try to put the value in cu->list_in_scope which is wrong. */
15166 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15168 /* A static const member, not much different than an enum as far as
15169 we're concerned, except that we can support more types. */
15170 new_symbol (die
, NULL
, cu
);
15173 /* Get physical name. */
15174 physname
= dwarf2_physname (fieldname
, die
, cu
);
15176 /* The name is already allocated along with this objfile, so we don't
15177 need to duplicate it for the type. */
15178 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15179 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15180 FIELD_NAME (*fp
) = fieldname
;
15182 else if (die
->tag
== DW_TAG_inheritance
)
15186 /* C++ base class field. */
15187 if (handle_data_member_location (die
, cu
, &offset
))
15188 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15189 FIELD_BITSIZE (*fp
) = 0;
15190 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15191 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15193 else if (die
->tag
== DW_TAG_variant_part
)
15195 /* process_structure_scope will treat this DIE as a union. */
15196 process_structure_scope (die
, cu
);
15198 /* The variant part is relative to the start of the enclosing
15200 SET_FIELD_BITPOS (*fp
, 0);
15201 fp
->type
= get_die_type (die
, cu
);
15202 fp
->artificial
= 1;
15203 fp
->name
= "<<variant>>";
15205 /* Normally a DW_TAG_variant_part won't have a size, but our
15206 representation requires one, so set it to the maximum of the
15208 if (TYPE_LENGTH (fp
->type
) == 0)
15211 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15212 if (TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)) > max
)
15213 max
= TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
));
15214 TYPE_LENGTH (fp
->type
) = max
;
15218 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15221 /* Can the type given by DIE define another type? */
15224 type_can_define_types (const struct die_info
*die
)
15228 case DW_TAG_typedef
:
15229 case DW_TAG_class_type
:
15230 case DW_TAG_structure_type
:
15231 case DW_TAG_union_type
:
15232 case DW_TAG_enumeration_type
:
15240 /* Add a type definition defined in the scope of the FIP's class. */
15243 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15244 struct dwarf2_cu
*cu
)
15246 struct decl_field fp
;
15247 memset (&fp
, 0, sizeof (fp
));
15249 gdb_assert (type_can_define_types (die
));
15251 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15252 fp
.name
= dwarf2_name (die
, cu
);
15253 fp
.type
= read_type_die (die
, cu
);
15255 /* Save accessibility. */
15256 enum dwarf_access_attribute accessibility
;
15257 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15259 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15261 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15262 switch (accessibility
)
15264 case DW_ACCESS_public
:
15265 /* The assumed value if neither private nor protected. */
15267 case DW_ACCESS_private
:
15270 case DW_ACCESS_protected
:
15271 fp
.is_protected
= 1;
15274 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15277 if (die
->tag
== DW_TAG_typedef
)
15278 fip
->typedef_field_list
.push_back (fp
);
15280 fip
->nested_types_list
.push_back (fp
);
15283 /* Create the vector of fields, and attach it to the type. */
15286 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15287 struct dwarf2_cu
*cu
)
15289 int nfields
= fip
->nfields
;
15291 /* Record the field count, allocate space for the array of fields,
15292 and create blank accessibility bitfields if necessary. */
15293 TYPE_NFIELDS (type
) = nfields
;
15294 TYPE_FIELDS (type
) = (struct field
*)
15295 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15297 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15299 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15301 TYPE_FIELD_PRIVATE_BITS (type
) =
15302 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15303 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15305 TYPE_FIELD_PROTECTED_BITS (type
) =
15306 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15307 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15309 TYPE_FIELD_IGNORE_BITS (type
) =
15310 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15311 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15314 /* If the type has baseclasses, allocate and clear a bit vector for
15315 TYPE_FIELD_VIRTUAL_BITS. */
15316 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15318 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15319 unsigned char *pointer
;
15321 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15322 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15323 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15324 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15325 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15328 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15330 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15332 for (int index
= 0; index
< nfields
; ++index
)
15334 struct nextfield
&field
= fip
->fields
[index
];
15336 if (field
.variant
.is_discriminant
)
15337 di
->discriminant_index
= index
;
15338 else if (field
.variant
.default_branch
)
15339 di
->default_index
= index
;
15341 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15345 /* Copy the saved-up fields into the field vector. */
15346 for (int i
= 0; i
< nfields
; ++i
)
15348 struct nextfield
&field
15349 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15350 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15352 TYPE_FIELD (type
, i
) = field
.field
;
15353 switch (field
.accessibility
)
15355 case DW_ACCESS_private
:
15356 if (cu
->language
!= language_ada
)
15357 SET_TYPE_FIELD_PRIVATE (type
, i
);
15360 case DW_ACCESS_protected
:
15361 if (cu
->language
!= language_ada
)
15362 SET_TYPE_FIELD_PROTECTED (type
, i
);
15365 case DW_ACCESS_public
:
15369 /* Unknown accessibility. Complain and treat it as public. */
15371 complaint (_("unsupported accessibility %d"),
15372 field
.accessibility
);
15376 if (i
< fip
->baseclasses
.size ())
15378 switch (field
.virtuality
)
15380 case DW_VIRTUALITY_virtual
:
15381 case DW_VIRTUALITY_pure_virtual
:
15382 if (cu
->language
== language_ada
)
15383 error (_("unexpected virtuality in component of Ada type"));
15384 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15391 /* Return true if this member function is a constructor, false
15395 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15397 const char *fieldname
;
15398 const char *type_name
;
15401 if (die
->parent
== NULL
)
15404 if (die
->parent
->tag
!= DW_TAG_structure_type
15405 && die
->parent
->tag
!= DW_TAG_union_type
15406 && die
->parent
->tag
!= DW_TAG_class_type
)
15409 fieldname
= dwarf2_name (die
, cu
);
15410 type_name
= dwarf2_name (die
->parent
, cu
);
15411 if (fieldname
== NULL
|| type_name
== NULL
)
15414 len
= strlen (fieldname
);
15415 return (strncmp (fieldname
, type_name
, len
) == 0
15416 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15419 /* Add a member function to the proper fieldlist. */
15422 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15423 struct type
*type
, struct dwarf2_cu
*cu
)
15425 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15426 struct attribute
*attr
;
15428 struct fnfieldlist
*flp
= nullptr;
15429 struct fn_field
*fnp
;
15430 const char *fieldname
;
15431 struct type
*this_type
;
15432 enum dwarf_access_attribute accessibility
;
15434 if (cu
->language
== language_ada
)
15435 error (_("unexpected member function in Ada type"));
15437 /* Get name of member function. */
15438 fieldname
= dwarf2_name (die
, cu
);
15439 if (fieldname
== NULL
)
15442 /* Look up member function name in fieldlist. */
15443 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15445 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15447 flp
= &fip
->fnfieldlists
[i
];
15452 /* Create a new fnfieldlist if necessary. */
15453 if (flp
== nullptr)
15455 fip
->fnfieldlists
.emplace_back ();
15456 flp
= &fip
->fnfieldlists
.back ();
15457 flp
->name
= fieldname
;
15458 i
= fip
->fnfieldlists
.size () - 1;
15461 /* Create a new member function field and add it to the vector of
15463 flp
->fnfields
.emplace_back ();
15464 fnp
= &flp
->fnfields
.back ();
15466 /* Delay processing of the physname until later. */
15467 if (cu
->language
== language_cplus
)
15468 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15472 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15473 fnp
->physname
= physname
? physname
: "";
15476 fnp
->type
= alloc_type (objfile
);
15477 this_type
= read_type_die (die
, cu
);
15478 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15480 int nparams
= TYPE_NFIELDS (this_type
);
15482 /* TYPE is the domain of this method, and THIS_TYPE is the type
15483 of the method itself (TYPE_CODE_METHOD). */
15484 smash_to_method_type (fnp
->type
, type
,
15485 TYPE_TARGET_TYPE (this_type
),
15486 TYPE_FIELDS (this_type
),
15487 TYPE_NFIELDS (this_type
),
15488 TYPE_VARARGS (this_type
));
15490 /* Handle static member functions.
15491 Dwarf2 has no clean way to discern C++ static and non-static
15492 member functions. G++ helps GDB by marking the first
15493 parameter for non-static member functions (which is the this
15494 pointer) as artificial. We obtain this information from
15495 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15496 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15497 fnp
->voffset
= VOFFSET_STATIC
;
15500 complaint (_("member function type missing for '%s'"),
15501 dwarf2_full_name (fieldname
, die
, cu
));
15503 /* Get fcontext from DW_AT_containing_type if present. */
15504 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15505 fnp
->fcontext
= die_containing_type (die
, cu
);
15507 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15508 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15510 /* Get accessibility. */
15511 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15513 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15515 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15516 switch (accessibility
)
15518 case DW_ACCESS_private
:
15519 fnp
->is_private
= 1;
15521 case DW_ACCESS_protected
:
15522 fnp
->is_protected
= 1;
15526 /* Check for artificial methods. */
15527 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15528 if (attr
&& DW_UNSND (attr
) != 0)
15529 fnp
->is_artificial
= 1;
15531 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15533 /* Get index in virtual function table if it is a virtual member
15534 function. For older versions of GCC, this is an offset in the
15535 appropriate virtual table, as specified by DW_AT_containing_type.
15536 For everyone else, it is an expression to be evaluated relative
15537 to the object address. */
15539 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15542 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15544 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15546 /* Old-style GCC. */
15547 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15549 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15550 || (DW_BLOCK (attr
)->size
> 1
15551 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15552 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15554 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15555 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15556 dwarf2_complex_location_expr_complaint ();
15558 fnp
->voffset
/= cu
->header
.addr_size
;
15562 dwarf2_complex_location_expr_complaint ();
15564 if (!fnp
->fcontext
)
15566 /* If there is no `this' field and no DW_AT_containing_type,
15567 we cannot actually find a base class context for the
15569 if (TYPE_NFIELDS (this_type
) == 0
15570 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15572 complaint (_("cannot determine context for virtual member "
15573 "function \"%s\" (offset %s)"),
15574 fieldname
, sect_offset_str (die
->sect_off
));
15579 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15583 else if (attr_form_is_section_offset (attr
))
15585 dwarf2_complex_location_expr_complaint ();
15589 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15595 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15596 if (attr
&& DW_UNSND (attr
))
15598 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15599 complaint (_("Member function \"%s\" (offset %s) is virtual "
15600 "but the vtable offset is not specified"),
15601 fieldname
, sect_offset_str (die
->sect_off
));
15602 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15603 TYPE_CPLUS_DYNAMIC (type
) = 1;
15608 /* Create the vector of member function fields, and attach it to the type. */
15611 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15612 struct dwarf2_cu
*cu
)
15614 if (cu
->language
== language_ada
)
15615 error (_("unexpected member functions in Ada type"));
15617 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15618 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15620 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15622 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15624 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15625 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15627 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15628 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15629 fn_flp
->fn_fields
= (struct fn_field
*)
15630 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15632 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15633 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15636 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15639 /* Returns non-zero if NAME is the name of a vtable member in CU's
15640 language, zero otherwise. */
15642 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15644 static const char vptr
[] = "_vptr";
15646 /* Look for the C++ form of the vtable. */
15647 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15653 /* GCC outputs unnamed structures that are really pointers to member
15654 functions, with the ABI-specified layout. If TYPE describes
15655 such a structure, smash it into a member function type.
15657 GCC shouldn't do this; it should just output pointer to member DIEs.
15658 This is GCC PR debug/28767. */
15661 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15663 struct type
*pfn_type
, *self_type
, *new_type
;
15665 /* Check for a structure with no name and two children. */
15666 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15669 /* Check for __pfn and __delta members. */
15670 if (TYPE_FIELD_NAME (type
, 0) == NULL
15671 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15672 || TYPE_FIELD_NAME (type
, 1) == NULL
15673 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15676 /* Find the type of the method. */
15677 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15678 if (pfn_type
== NULL
15679 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15680 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15683 /* Look for the "this" argument. */
15684 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15685 if (TYPE_NFIELDS (pfn_type
) == 0
15686 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15687 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15690 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15691 new_type
= alloc_type (objfile
);
15692 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15693 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15694 TYPE_VARARGS (pfn_type
));
15695 smash_to_methodptr_type (type
, new_type
);
15698 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15699 appropriate error checking and issuing complaints if there is a
15703 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15705 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15707 if (attr
== nullptr)
15710 if (!attr_form_is_constant (attr
))
15712 complaint (_("DW_AT_alignment must have constant form"
15713 " - DIE at %s [in module %s]"),
15714 sect_offset_str (die
->sect_off
),
15715 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15720 if (attr
->form
== DW_FORM_sdata
)
15722 LONGEST val
= DW_SND (attr
);
15725 complaint (_("DW_AT_alignment value must not be negative"
15726 " - DIE at %s [in module %s]"),
15727 sect_offset_str (die
->sect_off
),
15728 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15734 align
= DW_UNSND (attr
);
15738 complaint (_("DW_AT_alignment value must not be zero"
15739 " - DIE at %s [in module %s]"),
15740 sect_offset_str (die
->sect_off
),
15741 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15744 if ((align
& (align
- 1)) != 0)
15746 complaint (_("DW_AT_alignment value must be a power of 2"
15747 " - DIE at %s [in module %s]"),
15748 sect_offset_str (die
->sect_off
),
15749 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15756 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15757 the alignment for TYPE. */
15760 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15763 if (!set_type_align (type
, get_alignment (cu
, die
)))
15764 complaint (_("DW_AT_alignment value too large"
15765 " - DIE at %s [in module %s]"),
15766 sect_offset_str (die
->sect_off
),
15767 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15770 /* Called when we find the DIE that starts a structure or union scope
15771 (definition) to create a type for the structure or union. Fill in
15772 the type's name and general properties; the members will not be
15773 processed until process_structure_scope. A symbol table entry for
15774 the type will also not be done until process_structure_scope (assuming
15775 the type has a name).
15777 NOTE: we need to call these functions regardless of whether or not the
15778 DIE has a DW_AT_name attribute, since it might be an anonymous
15779 structure or union. This gets the type entered into our set of
15780 user defined types. */
15782 static struct type
*
15783 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15785 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15787 struct attribute
*attr
;
15790 /* If the definition of this type lives in .debug_types, read that type.
15791 Don't follow DW_AT_specification though, that will take us back up
15792 the chain and we want to go down. */
15793 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15796 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15798 /* The type's CU may not be the same as CU.
15799 Ensure TYPE is recorded with CU in die_type_hash. */
15800 return set_die_type (die
, type
, cu
);
15803 type
= alloc_type (objfile
);
15804 INIT_CPLUS_SPECIFIC (type
);
15806 name
= dwarf2_name (die
, cu
);
15809 if (cu
->language
== language_cplus
15810 || cu
->language
== language_d
15811 || cu
->language
== language_rust
)
15813 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15815 /* dwarf2_full_name might have already finished building the DIE's
15816 type. If so, there is no need to continue. */
15817 if (get_die_type (die
, cu
) != NULL
)
15818 return get_die_type (die
, cu
);
15820 TYPE_NAME (type
) = full_name
;
15824 /* The name is already allocated along with this objfile, so
15825 we don't need to duplicate it for the type. */
15826 TYPE_NAME (type
) = name
;
15830 if (die
->tag
== DW_TAG_structure_type
)
15832 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15834 else if (die
->tag
== DW_TAG_union_type
)
15836 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15838 else if (die
->tag
== DW_TAG_variant_part
)
15840 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15841 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15845 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15848 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15849 TYPE_DECLARED_CLASS (type
) = 1;
15851 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15854 if (attr_form_is_constant (attr
))
15855 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15858 /* For the moment, dynamic type sizes are not supported
15859 by GDB's struct type. The actual size is determined
15860 on-demand when resolving the type of a given object,
15861 so set the type's length to zero for now. Otherwise,
15862 we record an expression as the length, and that expression
15863 could lead to a very large value, which could eventually
15864 lead to us trying to allocate that much memory when creating
15865 a value of that type. */
15866 TYPE_LENGTH (type
) = 0;
15871 TYPE_LENGTH (type
) = 0;
15874 maybe_set_alignment (cu
, die
, type
);
15876 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15878 /* ICC<14 does not output the required DW_AT_declaration on
15879 incomplete types, but gives them a size of zero. */
15880 TYPE_STUB (type
) = 1;
15883 TYPE_STUB_SUPPORTED (type
) = 1;
15885 if (die_is_declaration (die
, cu
))
15886 TYPE_STUB (type
) = 1;
15887 else if (attr
== NULL
&& die
->child
== NULL
15888 && producer_is_realview (cu
->producer
))
15889 /* RealView does not output the required DW_AT_declaration
15890 on incomplete types. */
15891 TYPE_STUB (type
) = 1;
15893 /* We need to add the type field to the die immediately so we don't
15894 infinitely recurse when dealing with pointers to the structure
15895 type within the structure itself. */
15896 set_die_type (die
, type
, cu
);
15898 /* set_die_type should be already done. */
15899 set_descriptive_type (type
, die
, cu
);
15904 /* A helper for process_structure_scope that handles a single member
15908 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15909 struct field_info
*fi
,
15910 std::vector
<struct symbol
*> *template_args
,
15911 struct dwarf2_cu
*cu
)
15913 if (child_die
->tag
== DW_TAG_member
15914 || child_die
->tag
== DW_TAG_variable
15915 || child_die
->tag
== DW_TAG_variant_part
)
15917 /* NOTE: carlton/2002-11-05: A C++ static data member
15918 should be a DW_TAG_member that is a declaration, but
15919 all versions of G++ as of this writing (so through at
15920 least 3.2.1) incorrectly generate DW_TAG_variable
15921 tags for them instead. */
15922 dwarf2_add_field (fi
, child_die
, cu
);
15924 else if (child_die
->tag
== DW_TAG_subprogram
)
15926 /* Rust doesn't have member functions in the C++ sense.
15927 However, it does emit ordinary functions as children
15928 of a struct DIE. */
15929 if (cu
->language
== language_rust
)
15930 read_func_scope (child_die
, cu
);
15933 /* C++ member function. */
15934 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
15937 else if (child_die
->tag
== DW_TAG_inheritance
)
15939 /* C++ base class field. */
15940 dwarf2_add_field (fi
, child_die
, cu
);
15942 else if (type_can_define_types (child_die
))
15943 dwarf2_add_type_defn (fi
, child_die
, cu
);
15944 else if (child_die
->tag
== DW_TAG_template_type_param
15945 || child_die
->tag
== DW_TAG_template_value_param
)
15947 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
15950 template_args
->push_back (arg
);
15952 else if (child_die
->tag
== DW_TAG_variant
)
15954 /* In a variant we want to get the discriminant and also add a
15955 field for our sole member child. */
15956 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
15958 for (die_info
*variant_child
= child_die
->child
;
15959 variant_child
!= NULL
;
15960 variant_child
= sibling_die (variant_child
))
15962 if (variant_child
->tag
== DW_TAG_member
)
15964 handle_struct_member_die (variant_child
, type
, fi
,
15965 template_args
, cu
);
15966 /* Only handle the one. */
15971 /* We don't handle this but we might as well report it if we see
15973 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
15974 complaint (_("DW_AT_discr_list is not supported yet"
15975 " - DIE at %s [in module %s]"),
15976 sect_offset_str (child_die
->sect_off
),
15977 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15979 /* The first field was just added, so we can stash the
15980 discriminant there. */
15981 gdb_assert (!fi
->fields
.empty ());
15983 fi
->fields
.back ().variant
.default_branch
= true;
15985 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
15989 /* Finish creating a structure or union type, including filling in
15990 its members and creating a symbol for it. */
15993 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
15995 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15996 struct die_info
*child_die
;
15999 type
= get_die_type (die
, cu
);
16001 type
= read_structure_type (die
, cu
);
16003 /* When reading a DW_TAG_variant_part, we need to notice when we
16004 read the discriminant member, so we can record it later in the
16005 discriminant_info. */
16006 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16007 sect_offset discr_offset
;
16008 bool has_template_parameters
= false;
16010 if (is_variant_part
)
16012 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16015 /* Maybe it's a univariant form, an extension we support.
16016 In this case arrange not to check the offset. */
16017 is_variant_part
= false;
16019 else if (attr_form_is_ref (discr
))
16021 struct dwarf2_cu
*target_cu
= cu
;
16022 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16024 discr_offset
= target_die
->sect_off
;
16028 complaint (_("DW_AT_discr does not have DIE reference form"
16029 " - DIE at %s [in module %s]"),
16030 sect_offset_str (die
->sect_off
),
16031 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16032 is_variant_part
= false;
16036 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16038 struct field_info fi
;
16039 std::vector
<struct symbol
*> template_args
;
16041 child_die
= die
->child
;
16043 while (child_die
&& child_die
->tag
)
16045 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16047 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16048 fi
.fields
.back ().variant
.is_discriminant
= true;
16050 child_die
= sibling_die (child_die
);
16053 /* Attach template arguments to type. */
16054 if (!template_args
.empty ())
16056 has_template_parameters
= true;
16057 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16058 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16059 TYPE_TEMPLATE_ARGUMENTS (type
)
16060 = XOBNEWVEC (&objfile
->objfile_obstack
,
16062 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16063 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16064 template_args
.data (),
16065 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16066 * sizeof (struct symbol
*)));
16069 /* Attach fields and member functions to the type. */
16071 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16072 if (!fi
.fnfieldlists
.empty ())
16074 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16076 /* Get the type which refers to the base class (possibly this
16077 class itself) which contains the vtable pointer for the current
16078 class from the DW_AT_containing_type attribute. This use of
16079 DW_AT_containing_type is a GNU extension. */
16081 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16083 struct type
*t
= die_containing_type (die
, cu
);
16085 set_type_vptr_basetype (type
, t
);
16090 /* Our own class provides vtbl ptr. */
16091 for (i
= TYPE_NFIELDS (t
) - 1;
16092 i
>= TYPE_N_BASECLASSES (t
);
16095 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16097 if (is_vtable_name (fieldname
, cu
))
16099 set_type_vptr_fieldno (type
, i
);
16104 /* Complain if virtual function table field not found. */
16105 if (i
< TYPE_N_BASECLASSES (t
))
16106 complaint (_("virtual function table pointer "
16107 "not found when defining class '%s'"),
16108 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16112 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16115 else if (cu
->producer
16116 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16118 /* The IBM XLC compiler does not provide direct indication
16119 of the containing type, but the vtable pointer is
16120 always named __vfp. */
16124 for (i
= TYPE_NFIELDS (type
) - 1;
16125 i
>= TYPE_N_BASECLASSES (type
);
16128 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16130 set_type_vptr_fieldno (type
, i
);
16131 set_type_vptr_basetype (type
, type
);
16138 /* Copy fi.typedef_field_list linked list elements content into the
16139 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16140 if (!fi
.typedef_field_list
.empty ())
16142 int count
= fi
.typedef_field_list
.size ();
16144 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16145 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16146 = ((struct decl_field
*)
16148 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16149 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16151 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16152 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16155 /* Copy fi.nested_types_list linked list elements content into the
16156 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16157 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16159 int count
= fi
.nested_types_list
.size ();
16161 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16162 TYPE_NESTED_TYPES_ARRAY (type
)
16163 = ((struct decl_field
*)
16164 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16165 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16167 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16168 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16172 quirk_gcc_member_function_pointer (type
, objfile
);
16173 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16174 cu
->rust_unions
.push_back (type
);
16176 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16177 snapshots) has been known to create a die giving a declaration
16178 for a class that has, as a child, a die giving a definition for a
16179 nested class. So we have to process our children even if the
16180 current die is a declaration. Normally, of course, a declaration
16181 won't have any children at all. */
16183 child_die
= die
->child
;
16185 while (child_die
!= NULL
&& child_die
->tag
)
16187 if (child_die
->tag
== DW_TAG_member
16188 || child_die
->tag
== DW_TAG_variable
16189 || child_die
->tag
== DW_TAG_inheritance
16190 || child_die
->tag
== DW_TAG_template_value_param
16191 || child_die
->tag
== DW_TAG_template_type_param
)
16196 process_die (child_die
, cu
);
16198 child_die
= sibling_die (child_die
);
16201 /* Do not consider external references. According to the DWARF standard,
16202 these DIEs are identified by the fact that they have no byte_size
16203 attribute, and a declaration attribute. */
16204 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16205 || !die_is_declaration (die
, cu
))
16207 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16209 if (has_template_parameters
)
16211 struct symtab
*symtab
;
16212 if (sym
!= nullptr)
16213 symtab
= symbol_symtab (sym
);
16214 else if (cu
->line_header
!= nullptr)
16216 /* Any related symtab will do. */
16218 = cu
->line_header
->file_name_at (file_name_index (1))->symtab
;
16223 complaint (_("could not find suitable "
16224 "symtab for template parameter"
16225 " - DIE at %s [in module %s]"),
16226 sect_offset_str (die
->sect_off
),
16227 objfile_name (objfile
));
16230 if (symtab
!= nullptr)
16232 /* Make sure that the symtab is set on the new symbols.
16233 Even though they don't appear in this symtab directly,
16234 other parts of gdb assume that symbols do, and this is
16235 reasonably true. */
16236 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16237 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16243 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16244 update TYPE using some information only available in DIE's children. */
16247 update_enumeration_type_from_children (struct die_info
*die
,
16249 struct dwarf2_cu
*cu
)
16251 struct die_info
*child_die
;
16252 int unsigned_enum
= 1;
16256 auto_obstack obstack
;
16258 for (child_die
= die
->child
;
16259 child_die
!= NULL
&& child_die
->tag
;
16260 child_die
= sibling_die (child_die
))
16262 struct attribute
*attr
;
16264 const gdb_byte
*bytes
;
16265 struct dwarf2_locexpr_baton
*baton
;
16268 if (child_die
->tag
!= DW_TAG_enumerator
)
16271 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16275 name
= dwarf2_name (child_die
, cu
);
16277 name
= "<anonymous enumerator>";
16279 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16280 &value
, &bytes
, &baton
);
16286 else if ((mask
& value
) != 0)
16291 /* If we already know that the enum type is neither unsigned, nor
16292 a flag type, no need to look at the rest of the enumerates. */
16293 if (!unsigned_enum
&& !flag_enum
)
16298 TYPE_UNSIGNED (type
) = 1;
16300 TYPE_FLAG_ENUM (type
) = 1;
16303 /* Given a DW_AT_enumeration_type die, set its type. We do not
16304 complete the type's fields yet, or create any symbols. */
16306 static struct type
*
16307 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16309 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16311 struct attribute
*attr
;
16314 /* If the definition of this type lives in .debug_types, read that type.
16315 Don't follow DW_AT_specification though, that will take us back up
16316 the chain and we want to go down. */
16317 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16320 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16322 /* The type's CU may not be the same as CU.
16323 Ensure TYPE is recorded with CU in die_type_hash. */
16324 return set_die_type (die
, type
, cu
);
16327 type
= alloc_type (objfile
);
16329 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16330 name
= dwarf2_full_name (NULL
, die
, cu
);
16332 TYPE_NAME (type
) = name
;
16334 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16337 struct type
*underlying_type
= die_type (die
, cu
);
16339 TYPE_TARGET_TYPE (type
) = underlying_type
;
16342 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16345 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16349 TYPE_LENGTH (type
) = 0;
16352 maybe_set_alignment (cu
, die
, type
);
16354 /* The enumeration DIE can be incomplete. In Ada, any type can be
16355 declared as private in the package spec, and then defined only
16356 inside the package body. Such types are known as Taft Amendment
16357 Types. When another package uses such a type, an incomplete DIE
16358 may be generated by the compiler. */
16359 if (die_is_declaration (die
, cu
))
16360 TYPE_STUB (type
) = 1;
16362 /* Finish the creation of this type by using the enum's children.
16363 We must call this even when the underlying type has been provided
16364 so that we can determine if we're looking at a "flag" enum. */
16365 update_enumeration_type_from_children (die
, type
, cu
);
16367 /* If this type has an underlying type that is not a stub, then we
16368 may use its attributes. We always use the "unsigned" attribute
16369 in this situation, because ordinarily we guess whether the type
16370 is unsigned -- but the guess can be wrong and the underlying type
16371 can tell us the reality. However, we defer to a local size
16372 attribute if one exists, because this lets the compiler override
16373 the underlying type if needed. */
16374 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16376 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16377 if (TYPE_LENGTH (type
) == 0)
16378 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16379 if (TYPE_RAW_ALIGN (type
) == 0
16380 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16381 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16384 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16386 return set_die_type (die
, type
, cu
);
16389 /* Given a pointer to a die which begins an enumeration, process all
16390 the dies that define the members of the enumeration, and create the
16391 symbol for the enumeration type.
16393 NOTE: We reverse the order of the element list. */
16396 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16398 struct type
*this_type
;
16400 this_type
= get_die_type (die
, cu
);
16401 if (this_type
== NULL
)
16402 this_type
= read_enumeration_type (die
, cu
);
16404 if (die
->child
!= NULL
)
16406 struct die_info
*child_die
;
16407 struct symbol
*sym
;
16408 struct field
*fields
= NULL
;
16409 int num_fields
= 0;
16412 child_die
= die
->child
;
16413 while (child_die
&& child_die
->tag
)
16415 if (child_die
->tag
!= DW_TAG_enumerator
)
16417 process_die (child_die
, cu
);
16421 name
= dwarf2_name (child_die
, cu
);
16424 sym
= new_symbol (child_die
, this_type
, cu
);
16426 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
16428 fields
= (struct field
*)
16430 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
16431 * sizeof (struct field
));
16434 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
16435 FIELD_TYPE (fields
[num_fields
]) = NULL
;
16436 SET_FIELD_ENUMVAL (fields
[num_fields
], SYMBOL_VALUE (sym
));
16437 FIELD_BITSIZE (fields
[num_fields
]) = 0;
16443 child_die
= sibling_die (child_die
);
16448 TYPE_NFIELDS (this_type
) = num_fields
;
16449 TYPE_FIELDS (this_type
) = (struct field
*)
16450 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
16451 memcpy (TYPE_FIELDS (this_type
), fields
,
16452 sizeof (struct field
) * num_fields
);
16457 /* If we are reading an enum from a .debug_types unit, and the enum
16458 is a declaration, and the enum is not the signatured type in the
16459 unit, then we do not want to add a symbol for it. Adding a
16460 symbol would in some cases obscure the true definition of the
16461 enum, giving users an incomplete type when the definition is
16462 actually available. Note that we do not want to do this for all
16463 enums which are just declarations, because C++0x allows forward
16464 enum declarations. */
16465 if (cu
->per_cu
->is_debug_types
16466 && die_is_declaration (die
, cu
))
16468 struct signatured_type
*sig_type
;
16470 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16471 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16472 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16476 new_symbol (die
, this_type
, cu
);
16479 /* Extract all information from a DW_TAG_array_type DIE and put it in
16480 the DIE's type field. For now, this only handles one dimensional
16483 static struct type
*
16484 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16486 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16487 struct die_info
*child_die
;
16489 struct type
*element_type
, *range_type
, *index_type
;
16490 struct attribute
*attr
;
16492 struct dynamic_prop
*byte_stride_prop
= NULL
;
16493 unsigned int bit_stride
= 0;
16495 element_type
= die_type (die
, cu
);
16497 /* The die_type call above may have already set the type for this DIE. */
16498 type
= get_die_type (die
, cu
);
16502 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16506 struct type
*prop_type
16507 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16510 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16511 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16515 complaint (_("unable to read array DW_AT_byte_stride "
16516 " - DIE at %s [in module %s]"),
16517 sect_offset_str (die
->sect_off
),
16518 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16519 /* Ignore this attribute. We will likely not be able to print
16520 arrays of this type correctly, but there is little we can do
16521 to help if we cannot read the attribute's value. */
16522 byte_stride_prop
= NULL
;
16526 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16528 bit_stride
= DW_UNSND (attr
);
16530 /* Irix 6.2 native cc creates array types without children for
16531 arrays with unspecified length. */
16532 if (die
->child
== NULL
)
16534 index_type
= objfile_type (objfile
)->builtin_int
;
16535 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16536 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16537 byte_stride_prop
, bit_stride
);
16538 return set_die_type (die
, type
, cu
);
16541 std::vector
<struct type
*> range_types
;
16542 child_die
= die
->child
;
16543 while (child_die
&& child_die
->tag
)
16545 if (child_die
->tag
== DW_TAG_subrange_type
)
16547 struct type
*child_type
= read_type_die (child_die
, cu
);
16549 if (child_type
!= NULL
)
16551 /* The range type was succesfully read. Save it for the
16552 array type creation. */
16553 range_types
.push_back (child_type
);
16556 child_die
= sibling_die (child_die
);
16559 /* Dwarf2 dimensions are output from left to right, create the
16560 necessary array types in backwards order. */
16562 type
= element_type
;
16564 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16568 while (i
< range_types
.size ())
16569 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16570 byte_stride_prop
, bit_stride
);
16574 size_t ndim
= range_types
.size ();
16576 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16577 byte_stride_prop
, bit_stride
);
16580 /* Understand Dwarf2 support for vector types (like they occur on
16581 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16582 array type. This is not part of the Dwarf2/3 standard yet, but a
16583 custom vendor extension. The main difference between a regular
16584 array and the vector variant is that vectors are passed by value
16586 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16588 make_vector_type (type
);
16590 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16591 implementation may choose to implement triple vectors using this
16593 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16596 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16597 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16599 complaint (_("DW_AT_byte_size for array type smaller "
16600 "than the total size of elements"));
16603 name
= dwarf2_name (die
, cu
);
16605 TYPE_NAME (type
) = name
;
16607 maybe_set_alignment (cu
, die
, type
);
16609 /* Install the type in the die. */
16610 set_die_type (die
, type
, cu
);
16612 /* set_die_type should be already done. */
16613 set_descriptive_type (type
, die
, cu
);
16618 static enum dwarf_array_dim_ordering
16619 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16621 struct attribute
*attr
;
16623 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16626 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16628 /* GNU F77 is a special case, as at 08/2004 array type info is the
16629 opposite order to the dwarf2 specification, but data is still
16630 laid out as per normal fortran.
16632 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16633 version checking. */
16635 if (cu
->language
== language_fortran
16636 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16638 return DW_ORD_row_major
;
16641 switch (cu
->language_defn
->la_array_ordering
)
16643 case array_column_major
:
16644 return DW_ORD_col_major
;
16645 case array_row_major
:
16647 return DW_ORD_row_major
;
16651 /* Extract all information from a DW_TAG_set_type DIE and put it in
16652 the DIE's type field. */
16654 static struct type
*
16655 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16657 struct type
*domain_type
, *set_type
;
16658 struct attribute
*attr
;
16660 domain_type
= die_type (die
, cu
);
16662 /* The die_type call above may have already set the type for this DIE. */
16663 set_type
= get_die_type (die
, cu
);
16667 set_type
= create_set_type (NULL
, domain_type
);
16669 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16671 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16673 maybe_set_alignment (cu
, die
, set_type
);
16675 return set_die_type (die
, set_type
, cu
);
16678 /* A helper for read_common_block that creates a locexpr baton.
16679 SYM is the symbol which we are marking as computed.
16680 COMMON_DIE is the DIE for the common block.
16681 COMMON_LOC is the location expression attribute for the common
16683 MEMBER_LOC is the location expression attribute for the particular
16684 member of the common block that we are processing.
16685 CU is the CU from which the above come. */
16688 mark_common_block_symbol_computed (struct symbol
*sym
,
16689 struct die_info
*common_die
,
16690 struct attribute
*common_loc
,
16691 struct attribute
*member_loc
,
16692 struct dwarf2_cu
*cu
)
16694 struct dwarf2_per_objfile
*dwarf2_per_objfile
16695 = cu
->per_cu
->dwarf2_per_objfile
;
16696 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16697 struct dwarf2_locexpr_baton
*baton
;
16699 unsigned int cu_off
;
16700 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16701 LONGEST offset
= 0;
16703 gdb_assert (common_loc
&& member_loc
);
16704 gdb_assert (attr_form_is_block (common_loc
));
16705 gdb_assert (attr_form_is_block (member_loc
)
16706 || attr_form_is_constant (member_loc
));
16708 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16709 baton
->per_cu
= cu
->per_cu
;
16710 gdb_assert (baton
->per_cu
);
16712 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16714 if (attr_form_is_constant (member_loc
))
16716 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16717 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16720 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16722 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16725 *ptr
++ = DW_OP_call4
;
16726 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16727 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16730 if (attr_form_is_constant (member_loc
))
16732 *ptr
++ = DW_OP_addr
;
16733 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16734 ptr
+= cu
->header
.addr_size
;
16738 /* We have to copy the data here, because DW_OP_call4 will only
16739 use a DW_AT_location attribute. */
16740 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16741 ptr
+= DW_BLOCK (member_loc
)->size
;
16744 *ptr
++ = DW_OP_plus
;
16745 gdb_assert (ptr
- baton
->data
== baton
->size
);
16747 SYMBOL_LOCATION_BATON (sym
) = baton
;
16748 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16751 /* Create appropriate locally-scoped variables for all the
16752 DW_TAG_common_block entries. Also create a struct common_block
16753 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16754 is used to sepate the common blocks name namespace from regular
16758 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16760 struct attribute
*attr
;
16762 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16765 /* Support the .debug_loc offsets. */
16766 if (attr_form_is_block (attr
))
16770 else if (attr_form_is_section_offset (attr
))
16772 dwarf2_complex_location_expr_complaint ();
16777 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16778 "common block member");
16783 if (die
->child
!= NULL
)
16785 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16786 struct die_info
*child_die
;
16787 size_t n_entries
= 0, size
;
16788 struct common_block
*common_block
;
16789 struct symbol
*sym
;
16791 for (child_die
= die
->child
;
16792 child_die
&& child_die
->tag
;
16793 child_die
= sibling_die (child_die
))
16796 size
= (sizeof (struct common_block
)
16797 + (n_entries
- 1) * sizeof (struct symbol
*));
16799 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16801 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16802 common_block
->n_entries
= 0;
16804 for (child_die
= die
->child
;
16805 child_die
&& child_die
->tag
;
16806 child_die
= sibling_die (child_die
))
16808 /* Create the symbol in the DW_TAG_common_block block in the current
16810 sym
= new_symbol (child_die
, NULL
, cu
);
16813 struct attribute
*member_loc
;
16815 common_block
->contents
[common_block
->n_entries
++] = sym
;
16817 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16821 /* GDB has handled this for a long time, but it is
16822 not specified by DWARF. It seems to have been
16823 emitted by gfortran at least as recently as:
16824 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16825 complaint (_("Variable in common block has "
16826 "DW_AT_data_member_location "
16827 "- DIE at %s [in module %s]"),
16828 sect_offset_str (child_die
->sect_off
),
16829 objfile_name (objfile
));
16831 if (attr_form_is_section_offset (member_loc
))
16832 dwarf2_complex_location_expr_complaint ();
16833 else if (attr_form_is_constant (member_loc
)
16834 || attr_form_is_block (member_loc
))
16837 mark_common_block_symbol_computed (sym
, die
, attr
,
16841 dwarf2_complex_location_expr_complaint ();
16846 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16847 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16851 /* Create a type for a C++ namespace. */
16853 static struct type
*
16854 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16856 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16857 const char *previous_prefix
, *name
;
16861 /* For extensions, reuse the type of the original namespace. */
16862 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16864 struct die_info
*ext_die
;
16865 struct dwarf2_cu
*ext_cu
= cu
;
16867 ext_die
= dwarf2_extension (die
, &ext_cu
);
16868 type
= read_type_die (ext_die
, ext_cu
);
16870 /* EXT_CU may not be the same as CU.
16871 Ensure TYPE is recorded with CU in die_type_hash. */
16872 return set_die_type (die
, type
, cu
);
16875 name
= namespace_name (die
, &is_anonymous
, cu
);
16877 /* Now build the name of the current namespace. */
16879 previous_prefix
= determine_prefix (die
, cu
);
16880 if (previous_prefix
[0] != '\0')
16881 name
= typename_concat (&objfile
->objfile_obstack
,
16882 previous_prefix
, name
, 0, cu
);
16884 /* Create the type. */
16885 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16887 return set_die_type (die
, type
, cu
);
16890 /* Read a namespace scope. */
16893 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16895 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16898 /* Add a symbol associated to this if we haven't seen the namespace
16899 before. Also, add a using directive if it's an anonymous
16902 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16906 type
= read_type_die (die
, cu
);
16907 new_symbol (die
, type
, cu
);
16909 namespace_name (die
, &is_anonymous
, cu
);
16912 const char *previous_prefix
= determine_prefix (die
, cu
);
16914 std::vector
<const char *> excludes
;
16915 add_using_directive (using_directives (cu
),
16916 previous_prefix
, TYPE_NAME (type
), NULL
,
16917 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16921 if (die
->child
!= NULL
)
16923 struct die_info
*child_die
= die
->child
;
16925 while (child_die
&& child_die
->tag
)
16927 process_die (child_die
, cu
);
16928 child_die
= sibling_die (child_die
);
16933 /* Read a Fortran module as type. This DIE can be only a declaration used for
16934 imported module. Still we need that type as local Fortran "use ... only"
16935 declaration imports depend on the created type in determine_prefix. */
16937 static struct type
*
16938 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16940 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16941 const char *module_name
;
16944 module_name
= dwarf2_name (die
, cu
);
16945 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
16947 return set_die_type (die
, type
, cu
);
16950 /* Read a Fortran module. */
16953 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
16955 struct die_info
*child_die
= die
->child
;
16958 type
= read_type_die (die
, cu
);
16959 new_symbol (die
, type
, cu
);
16961 while (child_die
&& child_die
->tag
)
16963 process_die (child_die
, cu
);
16964 child_die
= sibling_die (child_die
);
16968 /* Return the name of the namespace represented by DIE. Set
16969 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
16972 static const char *
16973 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
16975 struct die_info
*current_die
;
16976 const char *name
= NULL
;
16978 /* Loop through the extensions until we find a name. */
16980 for (current_die
= die
;
16981 current_die
!= NULL
;
16982 current_die
= dwarf2_extension (die
, &cu
))
16984 /* We don't use dwarf2_name here so that we can detect the absence
16985 of a name -> anonymous namespace. */
16986 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
16992 /* Is it an anonymous namespace? */
16994 *is_anonymous
= (name
== NULL
);
16996 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17001 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17002 the user defined type vector. */
17004 static struct type
*
17005 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17007 struct gdbarch
*gdbarch
17008 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17009 struct comp_unit_head
*cu_header
= &cu
->header
;
17011 struct attribute
*attr_byte_size
;
17012 struct attribute
*attr_address_class
;
17013 int byte_size
, addr_class
;
17014 struct type
*target_type
;
17016 target_type
= die_type (die
, cu
);
17018 /* The die_type call above may have already set the type for this DIE. */
17019 type
= get_die_type (die
, cu
);
17023 type
= lookup_pointer_type (target_type
);
17025 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17026 if (attr_byte_size
)
17027 byte_size
= DW_UNSND (attr_byte_size
);
17029 byte_size
= cu_header
->addr_size
;
17031 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17032 if (attr_address_class
)
17033 addr_class
= DW_UNSND (attr_address_class
);
17035 addr_class
= DW_ADDR_none
;
17037 ULONGEST alignment
= get_alignment (cu
, die
);
17039 /* If the pointer size, alignment, or address class is different
17040 than the default, create a type variant marked as such and set
17041 the length accordingly. */
17042 if (TYPE_LENGTH (type
) != byte_size
17043 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17044 && alignment
!= TYPE_RAW_ALIGN (type
))
17045 || addr_class
!= DW_ADDR_none
)
17047 if (gdbarch_address_class_type_flags_p (gdbarch
))
17051 type_flags
= gdbarch_address_class_type_flags
17052 (gdbarch
, byte_size
, addr_class
);
17053 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17055 type
= make_type_with_address_space (type
, type_flags
);
17057 else if (TYPE_LENGTH (type
) != byte_size
)
17059 complaint (_("invalid pointer size %d"), byte_size
);
17061 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17063 complaint (_("Invalid DW_AT_alignment"
17064 " - DIE at %s [in module %s]"),
17065 sect_offset_str (die
->sect_off
),
17066 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17070 /* Should we also complain about unhandled address classes? */
17074 TYPE_LENGTH (type
) = byte_size
;
17075 set_type_align (type
, alignment
);
17076 return set_die_type (die
, type
, cu
);
17079 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17080 the user defined type vector. */
17082 static struct type
*
17083 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17086 struct type
*to_type
;
17087 struct type
*domain
;
17089 to_type
= die_type (die
, cu
);
17090 domain
= die_containing_type (die
, cu
);
17092 /* The calls above may have already set the type for this DIE. */
17093 type
= get_die_type (die
, cu
);
17097 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17098 type
= lookup_methodptr_type (to_type
);
17099 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17101 struct type
*new_type
17102 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17104 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17105 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17106 TYPE_VARARGS (to_type
));
17107 type
= lookup_methodptr_type (new_type
);
17110 type
= lookup_memberptr_type (to_type
, domain
);
17112 return set_die_type (die
, type
, cu
);
17115 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17116 the user defined type vector. */
17118 static struct type
*
17119 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17120 enum type_code refcode
)
17122 struct comp_unit_head
*cu_header
= &cu
->header
;
17123 struct type
*type
, *target_type
;
17124 struct attribute
*attr
;
17126 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17128 target_type
= die_type (die
, cu
);
17130 /* The die_type call above may have already set the type for this DIE. */
17131 type
= get_die_type (die
, cu
);
17135 type
= lookup_reference_type (target_type
, refcode
);
17136 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17139 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17143 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17145 maybe_set_alignment (cu
, die
, type
);
17146 return set_die_type (die
, type
, cu
);
17149 /* Add the given cv-qualifiers to the element type of the array. GCC
17150 outputs DWARF type qualifiers that apply to an array, not the
17151 element type. But GDB relies on the array element type to carry
17152 the cv-qualifiers. This mimics section 6.7.3 of the C99
17155 static struct type
*
17156 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17157 struct type
*base_type
, int cnst
, int voltl
)
17159 struct type
*el_type
, *inner_array
;
17161 base_type
= copy_type (base_type
);
17162 inner_array
= base_type
;
17164 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17166 TYPE_TARGET_TYPE (inner_array
) =
17167 copy_type (TYPE_TARGET_TYPE (inner_array
));
17168 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17171 el_type
= TYPE_TARGET_TYPE (inner_array
);
17172 cnst
|= TYPE_CONST (el_type
);
17173 voltl
|= TYPE_VOLATILE (el_type
);
17174 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17176 return set_die_type (die
, base_type
, cu
);
17179 static struct type
*
17180 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17182 struct type
*base_type
, *cv_type
;
17184 base_type
= die_type (die
, cu
);
17186 /* The die_type call above may have already set the type for this DIE. */
17187 cv_type
= get_die_type (die
, cu
);
17191 /* In case the const qualifier is applied to an array type, the element type
17192 is so qualified, not the array type (section 6.7.3 of C99). */
17193 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17194 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17196 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17197 return set_die_type (die
, cv_type
, cu
);
17200 static struct type
*
17201 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17203 struct type
*base_type
, *cv_type
;
17205 base_type
= die_type (die
, cu
);
17207 /* The die_type call above may have already set the type for this DIE. */
17208 cv_type
= get_die_type (die
, cu
);
17212 /* In case the volatile qualifier is applied to an array type, the
17213 element type is so qualified, not the array type (section 6.7.3
17215 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17216 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17218 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17219 return set_die_type (die
, cv_type
, cu
);
17222 /* Handle DW_TAG_restrict_type. */
17224 static struct type
*
17225 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17227 struct type
*base_type
, *cv_type
;
17229 base_type
= die_type (die
, cu
);
17231 /* The die_type call above may have already set the type for this DIE. */
17232 cv_type
= get_die_type (die
, cu
);
17236 cv_type
= make_restrict_type (base_type
);
17237 return set_die_type (die
, cv_type
, cu
);
17240 /* Handle DW_TAG_atomic_type. */
17242 static struct type
*
17243 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17245 struct type
*base_type
, *cv_type
;
17247 base_type
= die_type (die
, cu
);
17249 /* The die_type call above may have already set the type for this DIE. */
17250 cv_type
= get_die_type (die
, cu
);
17254 cv_type
= make_atomic_type (base_type
);
17255 return set_die_type (die
, cv_type
, cu
);
17258 /* Extract all information from a DW_TAG_string_type DIE and add to
17259 the user defined type vector. It isn't really a user defined type,
17260 but it behaves like one, with other DIE's using an AT_user_def_type
17261 attribute to reference it. */
17263 static struct type
*
17264 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17266 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17267 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17268 struct type
*type
, *range_type
, *index_type
, *char_type
;
17269 struct attribute
*attr
;
17270 unsigned int length
;
17272 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17275 length
= DW_UNSND (attr
);
17279 /* Check for the DW_AT_byte_size attribute. */
17280 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17283 length
= DW_UNSND (attr
);
17291 index_type
= objfile_type (objfile
)->builtin_int
;
17292 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17293 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17294 type
= create_string_type (NULL
, char_type
, range_type
);
17296 return set_die_type (die
, type
, cu
);
17299 /* Assuming that DIE corresponds to a function, returns nonzero
17300 if the function is prototyped. */
17303 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17305 struct attribute
*attr
;
17307 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17308 if (attr
&& (DW_UNSND (attr
) != 0))
17311 /* The DWARF standard implies that the DW_AT_prototyped attribute
17312 is only meaninful for C, but the concept also extends to other
17313 languages that allow unprototyped functions (Eg: Objective C).
17314 For all other languages, assume that functions are always
17316 if (cu
->language
!= language_c
17317 && cu
->language
!= language_objc
17318 && cu
->language
!= language_opencl
)
17321 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17322 prototyped and unprototyped functions; default to prototyped,
17323 since that is more common in modern code (and RealView warns
17324 about unprototyped functions). */
17325 if (producer_is_realview (cu
->producer
))
17331 /* Handle DIES due to C code like:
17335 int (*funcp)(int a, long l);
17339 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17341 static struct type
*
17342 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17344 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17345 struct type
*type
; /* Type that this function returns. */
17346 struct type
*ftype
; /* Function that returns above type. */
17347 struct attribute
*attr
;
17349 type
= die_type (die
, cu
);
17351 /* The die_type call above may have already set the type for this DIE. */
17352 ftype
= get_die_type (die
, cu
);
17356 ftype
= lookup_function_type (type
);
17358 if (prototyped_function_p (die
, cu
))
17359 TYPE_PROTOTYPED (ftype
) = 1;
17361 /* Store the calling convention in the type if it's available in
17362 the subroutine die. Otherwise set the calling convention to
17363 the default value DW_CC_normal. */
17364 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17366 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
17367 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17368 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17370 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17372 /* Record whether the function returns normally to its caller or not
17373 if the DWARF producer set that information. */
17374 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17375 if (attr
&& (DW_UNSND (attr
) != 0))
17376 TYPE_NO_RETURN (ftype
) = 1;
17378 /* We need to add the subroutine type to the die immediately so
17379 we don't infinitely recurse when dealing with parameters
17380 declared as the same subroutine type. */
17381 set_die_type (die
, ftype
, cu
);
17383 if (die
->child
!= NULL
)
17385 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17386 struct die_info
*child_die
;
17387 int nparams
, iparams
;
17389 /* Count the number of parameters.
17390 FIXME: GDB currently ignores vararg functions, but knows about
17391 vararg member functions. */
17393 child_die
= die
->child
;
17394 while (child_die
&& child_die
->tag
)
17396 if (child_die
->tag
== DW_TAG_formal_parameter
)
17398 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17399 TYPE_VARARGS (ftype
) = 1;
17400 child_die
= sibling_die (child_die
);
17403 /* Allocate storage for parameters and fill them in. */
17404 TYPE_NFIELDS (ftype
) = nparams
;
17405 TYPE_FIELDS (ftype
) = (struct field
*)
17406 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17408 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17409 even if we error out during the parameters reading below. */
17410 for (iparams
= 0; iparams
< nparams
; iparams
++)
17411 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17414 child_die
= die
->child
;
17415 while (child_die
&& child_die
->tag
)
17417 if (child_die
->tag
== DW_TAG_formal_parameter
)
17419 struct type
*arg_type
;
17421 /* DWARF version 2 has no clean way to discern C++
17422 static and non-static member functions. G++ helps
17423 GDB by marking the first parameter for non-static
17424 member functions (which is the this pointer) as
17425 artificial. We pass this information to
17426 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17428 DWARF version 3 added DW_AT_object_pointer, which GCC
17429 4.5 does not yet generate. */
17430 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17432 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17434 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17435 arg_type
= die_type (child_die
, cu
);
17437 /* RealView does not mark THIS as const, which the testsuite
17438 expects. GCC marks THIS as const in method definitions,
17439 but not in the class specifications (GCC PR 43053). */
17440 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17441 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17444 struct dwarf2_cu
*arg_cu
= cu
;
17445 const char *name
= dwarf2_name (child_die
, cu
);
17447 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17450 /* If the compiler emits this, use it. */
17451 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17454 else if (name
&& strcmp (name
, "this") == 0)
17455 /* Function definitions will have the argument names. */
17457 else if (name
== NULL
&& iparams
== 0)
17458 /* Declarations may not have the names, so like
17459 elsewhere in GDB, assume an artificial first
17460 argument is "this". */
17464 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17468 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17471 child_die
= sibling_die (child_die
);
17478 static struct type
*
17479 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17481 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17482 const char *name
= NULL
;
17483 struct type
*this_type
, *target_type
;
17485 name
= dwarf2_full_name (NULL
, die
, cu
);
17486 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17487 TYPE_TARGET_STUB (this_type
) = 1;
17488 set_die_type (die
, this_type
, cu
);
17489 target_type
= die_type (die
, cu
);
17490 if (target_type
!= this_type
)
17491 TYPE_TARGET_TYPE (this_type
) = target_type
;
17494 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17495 spec and cause infinite loops in GDB. */
17496 complaint (_("Self-referential DW_TAG_typedef "
17497 "- DIE at %s [in module %s]"),
17498 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17499 TYPE_TARGET_TYPE (this_type
) = NULL
;
17504 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17505 (which may be different from NAME) to the architecture back-end to allow
17506 it to guess the correct format if necessary. */
17508 static struct type
*
17509 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17510 const char *name_hint
)
17512 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17513 const struct floatformat
**format
;
17516 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17518 type
= init_float_type (objfile
, bits
, name
, format
);
17520 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17525 /* Allocate an integer type of size BITS and name NAME. */
17527 static struct type
*
17528 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17529 int bits
, int unsigned_p
, const char *name
)
17533 /* Versions of Intel's C Compiler generate an integer type called "void"
17534 instead of using DW_TAG_unspecified_type. This has been seen on
17535 at least versions 14, 17, and 18. */
17536 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17537 && strcmp (name
, "void") == 0)
17538 type
= objfile_type (objfile
)->builtin_void
;
17540 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17545 /* Initialise and return a floating point type of size BITS suitable for
17546 use as a component of a complex number. The NAME_HINT is passed through
17547 when initialising the floating point type and is the name of the complex
17550 As DWARF doesn't currently provide an explicit name for the components
17551 of a complex number, but it can be helpful to have these components
17552 named, we try to select a suitable name based on the size of the
17554 static struct type
*
17555 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17556 struct objfile
*objfile
,
17557 int bits
, const char *name_hint
)
17559 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17560 struct type
*tt
= nullptr;
17562 /* Try to find a suitable floating point builtin type of size BITS.
17563 We're going to use the name of this type as the name for the complex
17564 target type that we are about to create. */
17565 switch (cu
->language
)
17567 case language_fortran
:
17571 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17574 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17576 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17578 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17586 tt
= builtin_type (gdbarch
)->builtin_float
;
17589 tt
= builtin_type (gdbarch
)->builtin_double
;
17591 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17593 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17599 /* If the type we found doesn't match the size we were looking for, then
17600 pretend we didn't find a type at all, the complex target type we
17601 create will then be nameless. */
17602 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17605 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17606 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
);
17609 /* Find a representation of a given base type and install
17610 it in the TYPE field of the die. */
17612 static struct type
*
17613 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17615 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17617 struct attribute
*attr
;
17618 int encoding
= 0, bits
= 0;
17621 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17624 encoding
= DW_UNSND (attr
);
17626 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17629 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17631 name
= dwarf2_name (die
, cu
);
17634 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17639 case DW_ATE_address
:
17640 /* Turn DW_ATE_address into a void * pointer. */
17641 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17642 type
= init_pointer_type (objfile
, bits
, name
, type
);
17644 case DW_ATE_boolean
:
17645 type
= init_boolean_type (objfile
, bits
, 1, name
);
17647 case DW_ATE_complex_float
:
17648 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
);
17649 type
= init_complex_type (objfile
, name
, type
);
17651 case DW_ATE_decimal_float
:
17652 type
= init_decfloat_type (objfile
, bits
, name
);
17655 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
);
17657 case DW_ATE_signed
:
17658 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17660 case DW_ATE_unsigned
:
17661 if (cu
->language
== language_fortran
17663 && startswith (name
, "character("))
17664 type
= init_character_type (objfile
, bits
, 1, name
);
17666 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17668 case DW_ATE_signed_char
:
17669 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17670 || cu
->language
== language_pascal
17671 || cu
->language
== language_fortran
)
17672 type
= init_character_type (objfile
, bits
, 0, name
);
17674 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17676 case DW_ATE_unsigned_char
:
17677 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17678 || cu
->language
== language_pascal
17679 || cu
->language
== language_fortran
17680 || cu
->language
== language_rust
)
17681 type
= init_character_type (objfile
, bits
, 1, name
);
17683 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17687 gdbarch
*arch
= get_objfile_arch (objfile
);
17690 type
= builtin_type (arch
)->builtin_char16
;
17691 else if (bits
== 32)
17692 type
= builtin_type (arch
)->builtin_char32
;
17695 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17697 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17699 return set_die_type (die
, type
, cu
);
17704 complaint (_("unsupported DW_AT_encoding: '%s'"),
17705 dwarf_type_encoding_name (encoding
));
17706 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17710 if (name
&& strcmp (name
, "char") == 0)
17711 TYPE_NOSIGN (type
) = 1;
17713 maybe_set_alignment (cu
, die
, type
);
17715 return set_die_type (die
, type
, cu
);
17718 /* Parse dwarf attribute if it's a block, reference or constant and put the
17719 resulting value of the attribute into struct bound_prop.
17720 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17723 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17724 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17725 struct type
*default_type
)
17727 struct dwarf2_property_baton
*baton
;
17728 struct obstack
*obstack
17729 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17731 gdb_assert (default_type
!= NULL
);
17733 if (attr
== NULL
|| prop
== NULL
)
17736 if (attr_form_is_block (attr
))
17738 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17739 baton
->property_type
= default_type
;
17740 baton
->locexpr
.per_cu
= cu
->per_cu
;
17741 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17742 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17743 baton
->locexpr
.is_reference
= false;
17744 prop
->data
.baton
= baton
;
17745 prop
->kind
= PROP_LOCEXPR
;
17746 gdb_assert (prop
->data
.baton
!= NULL
);
17748 else if (attr_form_is_ref (attr
))
17750 struct dwarf2_cu
*target_cu
= cu
;
17751 struct die_info
*target_die
;
17752 struct attribute
*target_attr
;
17754 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17755 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17756 if (target_attr
== NULL
)
17757 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17759 if (target_attr
== NULL
)
17762 switch (target_attr
->name
)
17764 case DW_AT_location
:
17765 if (attr_form_is_section_offset (target_attr
))
17767 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17768 baton
->property_type
= die_type (target_die
, target_cu
);
17769 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17770 prop
->data
.baton
= baton
;
17771 prop
->kind
= PROP_LOCLIST
;
17772 gdb_assert (prop
->data
.baton
!= NULL
);
17774 else if (attr_form_is_block (target_attr
))
17776 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17777 baton
->property_type
= die_type (target_die
, target_cu
);
17778 baton
->locexpr
.per_cu
= cu
->per_cu
;
17779 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17780 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17781 baton
->locexpr
.is_reference
= true;
17782 prop
->data
.baton
= baton
;
17783 prop
->kind
= PROP_LOCEXPR
;
17784 gdb_assert (prop
->data
.baton
!= NULL
);
17788 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17789 "dynamic property");
17793 case DW_AT_data_member_location
:
17797 if (!handle_data_member_location (target_die
, target_cu
,
17801 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17802 baton
->property_type
= read_type_die (target_die
->parent
,
17804 baton
->offset_info
.offset
= offset
;
17805 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17806 prop
->data
.baton
= baton
;
17807 prop
->kind
= PROP_ADDR_OFFSET
;
17812 else if (attr_form_is_constant (attr
))
17814 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17815 prop
->kind
= PROP_CONST
;
17819 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17820 dwarf2_name (die
, cu
));
17827 /* Find an integer type the same size as the address size given in the
17828 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
17829 is unsigned or not. */
17831 static struct type
*
17832 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
17835 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17836 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
17837 struct type
*int_type
;
17839 /* Helper macro to examine the various builtin types. */
17840 #define TRY_TYPE(F) \
17841 int_type = (unsigned_p \
17842 ? objfile_type (objfile)->builtin_unsigned_ ## F \
17843 : objfile_type (objfile)->builtin_ ## F); \
17844 if (int_type != NULL && TYPE_LENGTH (int_type) == addr_size) \
17851 TRY_TYPE (long_long
);
17855 gdb_assert_not_reached ("unable to find suitable integer type");
17858 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
17859 present (which is valid) then compute the default type based on the
17860 compilation units address size. */
17862 static struct type
*
17863 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17865 struct type
*index_type
= die_type (die
, cu
);
17867 /* Dwarf-2 specifications explicitly allows to create subrange types
17868 without specifying a base type.
17869 In that case, the base type must be set to the type of
17870 the lower bound, upper bound or count, in that order, if any of these
17871 three attributes references an object that has a type.
17872 If no base type is found, the Dwarf-2 specifications say that
17873 a signed integer type of size equal to the size of an address should
17875 For the following C code: `extern char gdb_int [];'
17876 GCC produces an empty range DIE.
17877 FIXME: muller/2010-05-28: Possible references to object for low bound,
17878 high bound or count are not yet handled by this code. */
17879 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
17880 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
17885 /* Read the given DW_AT_subrange DIE. */
17887 static struct type
*
17888 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17890 struct type
*base_type
, *orig_base_type
;
17891 struct type
*range_type
;
17892 struct attribute
*attr
;
17893 struct dynamic_prop low
, high
;
17894 int low_default_is_valid
;
17895 int high_bound_is_count
= 0;
17897 ULONGEST negative_mask
;
17899 orig_base_type
= read_subrange_index_type (die
, cu
);
17901 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
17902 whereas the real type might be. So, we use ORIG_BASE_TYPE when
17903 creating the range type, but we use the result of check_typedef
17904 when examining properties of the type. */
17905 base_type
= check_typedef (orig_base_type
);
17907 /* The die_type call above may have already set the type for this DIE. */
17908 range_type
= get_die_type (die
, cu
);
17912 low
.kind
= PROP_CONST
;
17913 high
.kind
= PROP_CONST
;
17914 high
.data
.const_val
= 0;
17916 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
17917 omitting DW_AT_lower_bound. */
17918 switch (cu
->language
)
17921 case language_cplus
:
17922 low
.data
.const_val
= 0;
17923 low_default_is_valid
= 1;
17925 case language_fortran
:
17926 low
.data
.const_val
= 1;
17927 low_default_is_valid
= 1;
17930 case language_objc
:
17931 case language_rust
:
17932 low
.data
.const_val
= 0;
17933 low_default_is_valid
= (cu
->header
.version
>= 4);
17937 case language_pascal
:
17938 low
.data
.const_val
= 1;
17939 low_default_is_valid
= (cu
->header
.version
>= 4);
17942 low
.data
.const_val
= 0;
17943 low_default_is_valid
= 0;
17947 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
17949 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
17950 else if (!low_default_is_valid
)
17951 complaint (_("Missing DW_AT_lower_bound "
17952 "- DIE at %s [in module %s]"),
17953 sect_offset_str (die
->sect_off
),
17954 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17956 struct attribute
*attr_ub
, *attr_count
;
17957 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
17958 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17960 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
17961 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
17963 /* If bounds are constant do the final calculation here. */
17964 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
17965 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
17967 high_bound_is_count
= 1;
17971 if (attr_ub
!= NULL
)
17972 complaint (_("Unresolved DW_AT_upper_bound "
17973 "- DIE at %s [in module %s]"),
17974 sect_offset_str (die
->sect_off
),
17975 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17976 if (attr_count
!= NULL
)
17977 complaint (_("Unresolved DW_AT_count "
17978 "- DIE at %s [in module %s]"),
17979 sect_offset_str (die
->sect_off
),
17980 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17985 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
17986 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
17987 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
17989 /* Normally, the DWARF producers are expected to use a signed
17990 constant form (Eg. DW_FORM_sdata) to express negative bounds.
17991 But this is unfortunately not always the case, as witnessed
17992 with GCC, for instance, where the ambiguous DW_FORM_dataN form
17993 is used instead. To work around that ambiguity, we treat
17994 the bounds as signed, and thus sign-extend their values, when
17995 the base type is signed. */
17997 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
17998 if (low
.kind
== PROP_CONST
17999 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18000 low
.data
.const_val
|= negative_mask
;
18001 if (high
.kind
== PROP_CONST
18002 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18003 high
.data
.const_val
|= negative_mask
;
18005 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18007 if (high_bound_is_count
)
18008 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18010 /* Ada expects an empty array on no boundary attributes. */
18011 if (attr
== NULL
&& cu
->language
!= language_ada
)
18012 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18014 name
= dwarf2_name (die
, cu
);
18016 TYPE_NAME (range_type
) = name
;
18018 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18020 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18022 maybe_set_alignment (cu
, die
, range_type
);
18024 set_die_type (die
, range_type
, cu
);
18026 /* set_die_type should be already done. */
18027 set_descriptive_type (range_type
, die
, cu
);
18032 static struct type
*
18033 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18037 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18039 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18041 /* In Ada, an unspecified type is typically used when the description
18042 of the type is defered to a different unit. When encountering
18043 such a type, we treat it as a stub, and try to resolve it later on,
18045 if (cu
->language
== language_ada
)
18046 TYPE_STUB (type
) = 1;
18048 return set_die_type (die
, type
, cu
);
18051 /* Read a single die and all its descendents. Set the die's sibling
18052 field to NULL; set other fields in the die correctly, and set all
18053 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18054 location of the info_ptr after reading all of those dies. PARENT
18055 is the parent of the die in question. */
18057 static struct die_info
*
18058 read_die_and_children (const struct die_reader_specs
*reader
,
18059 const gdb_byte
*info_ptr
,
18060 const gdb_byte
**new_info_ptr
,
18061 struct die_info
*parent
)
18063 struct die_info
*die
;
18064 const gdb_byte
*cur_ptr
;
18067 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18070 *new_info_ptr
= cur_ptr
;
18073 store_in_ref_table (die
, reader
->cu
);
18076 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18080 *new_info_ptr
= cur_ptr
;
18083 die
->sibling
= NULL
;
18084 die
->parent
= parent
;
18088 /* Read a die, all of its descendents, and all of its siblings; set
18089 all of the fields of all of the dies correctly. Arguments are as
18090 in read_die_and_children. */
18092 static struct die_info
*
18093 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18094 const gdb_byte
*info_ptr
,
18095 const gdb_byte
**new_info_ptr
,
18096 struct die_info
*parent
)
18098 struct die_info
*first_die
, *last_sibling
;
18099 const gdb_byte
*cur_ptr
;
18101 cur_ptr
= info_ptr
;
18102 first_die
= last_sibling
= NULL
;
18106 struct die_info
*die
18107 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18111 *new_info_ptr
= cur_ptr
;
18118 last_sibling
->sibling
= die
;
18120 last_sibling
= die
;
18124 /* Read a die, all of its descendents, and all of its siblings; set
18125 all of the fields of all of the dies correctly. Arguments are as
18126 in read_die_and_children.
18127 This the main entry point for reading a DIE and all its children. */
18129 static struct die_info
*
18130 read_die_and_siblings (const struct die_reader_specs
*reader
,
18131 const gdb_byte
*info_ptr
,
18132 const gdb_byte
**new_info_ptr
,
18133 struct die_info
*parent
)
18135 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18136 new_info_ptr
, parent
);
18138 if (dwarf_die_debug
)
18140 fprintf_unfiltered (gdb_stdlog
,
18141 "Read die from %s@0x%x of %s:\n",
18142 get_section_name (reader
->die_section
),
18143 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18144 bfd_get_filename (reader
->abfd
));
18145 dump_die (die
, dwarf_die_debug
);
18151 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18153 The caller is responsible for filling in the extra attributes
18154 and updating (*DIEP)->num_attrs.
18155 Set DIEP to point to a newly allocated die with its information,
18156 except for its child, sibling, and parent fields.
18157 Set HAS_CHILDREN to tell whether the die has children or not. */
18159 static const gdb_byte
*
18160 read_full_die_1 (const struct die_reader_specs
*reader
,
18161 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18162 int *has_children
, int num_extra_attrs
)
18164 unsigned int abbrev_number
, bytes_read
, i
;
18165 struct abbrev_info
*abbrev
;
18166 struct die_info
*die
;
18167 struct dwarf2_cu
*cu
= reader
->cu
;
18168 bfd
*abfd
= reader
->abfd
;
18170 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18171 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18172 info_ptr
+= bytes_read
;
18173 if (!abbrev_number
)
18180 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18182 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18184 bfd_get_filename (abfd
));
18186 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18187 die
->sect_off
= sect_off
;
18188 die
->tag
= abbrev
->tag
;
18189 die
->abbrev
= abbrev_number
;
18191 /* Make the result usable.
18192 The caller needs to update num_attrs after adding the extra
18194 die
->num_attrs
= abbrev
->num_attrs
;
18196 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18197 info_ptr
= read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18201 *has_children
= abbrev
->has_children
;
18205 /* Read a die and all its attributes.
18206 Set DIEP to point to a newly allocated die with its information,
18207 except for its child, sibling, and parent fields.
18208 Set HAS_CHILDREN to tell whether the die has children or not. */
18210 static const gdb_byte
*
18211 read_full_die (const struct die_reader_specs
*reader
,
18212 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18215 const gdb_byte
*result
;
18217 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18219 if (dwarf_die_debug
)
18221 fprintf_unfiltered (gdb_stdlog
,
18222 "Read die from %s@0x%x of %s:\n",
18223 get_section_name (reader
->die_section
),
18224 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18225 bfd_get_filename (reader
->abfd
));
18226 dump_die (*diep
, dwarf_die_debug
);
18232 /* Abbreviation tables.
18234 In DWARF version 2, the description of the debugging information is
18235 stored in a separate .debug_abbrev section. Before we read any
18236 dies from a section we read in all abbreviations and install them
18237 in a hash table. */
18239 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18241 struct abbrev_info
*
18242 abbrev_table::alloc_abbrev ()
18244 struct abbrev_info
*abbrev
;
18246 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18247 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18252 /* Add an abbreviation to the table. */
18255 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18256 struct abbrev_info
*abbrev
)
18258 unsigned int hash_number
;
18260 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18261 abbrev
->next
= m_abbrevs
[hash_number
];
18262 m_abbrevs
[hash_number
] = abbrev
;
18265 /* Look up an abbrev in the table.
18266 Returns NULL if the abbrev is not found. */
18268 struct abbrev_info
*
18269 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18271 unsigned int hash_number
;
18272 struct abbrev_info
*abbrev
;
18274 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18275 abbrev
= m_abbrevs
[hash_number
];
18279 if (abbrev
->number
== abbrev_number
)
18281 abbrev
= abbrev
->next
;
18286 /* Read in an abbrev table. */
18288 static abbrev_table_up
18289 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18290 struct dwarf2_section_info
*section
,
18291 sect_offset sect_off
)
18293 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18294 bfd
*abfd
= get_section_bfd_owner (section
);
18295 const gdb_byte
*abbrev_ptr
;
18296 struct abbrev_info
*cur_abbrev
;
18297 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18298 unsigned int abbrev_form
;
18299 struct attr_abbrev
*cur_attrs
;
18300 unsigned int allocated_attrs
;
18302 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18304 dwarf2_read_section (objfile
, section
);
18305 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18306 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18307 abbrev_ptr
+= bytes_read
;
18309 allocated_attrs
= ATTR_ALLOC_CHUNK
;
18310 cur_attrs
= XNEWVEC (struct attr_abbrev
, allocated_attrs
);
18312 /* Loop until we reach an abbrev number of 0. */
18313 while (abbrev_number
)
18315 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18317 /* read in abbrev header */
18318 cur_abbrev
->number
= abbrev_number
;
18320 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18321 abbrev_ptr
+= bytes_read
;
18322 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18325 /* now read in declarations */
18328 LONGEST implicit_const
;
18330 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18331 abbrev_ptr
+= bytes_read
;
18332 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18333 abbrev_ptr
+= bytes_read
;
18334 if (abbrev_form
== DW_FORM_implicit_const
)
18336 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18338 abbrev_ptr
+= bytes_read
;
18342 /* Initialize it due to a false compiler warning. */
18343 implicit_const
= -1;
18346 if (abbrev_name
== 0)
18349 if (cur_abbrev
->num_attrs
== allocated_attrs
)
18351 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
18353 = XRESIZEVEC (struct attr_abbrev
, cur_attrs
, allocated_attrs
);
18356 cur_attrs
[cur_abbrev
->num_attrs
].name
18357 = (enum dwarf_attribute
) abbrev_name
;
18358 cur_attrs
[cur_abbrev
->num_attrs
].form
18359 = (enum dwarf_form
) abbrev_form
;
18360 cur_attrs
[cur_abbrev
->num_attrs
].implicit_const
= implicit_const
;
18361 ++cur_abbrev
->num_attrs
;
18364 cur_abbrev
->attrs
=
18365 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18366 cur_abbrev
->num_attrs
);
18367 memcpy (cur_abbrev
->attrs
, cur_attrs
,
18368 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18370 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18372 /* Get next abbreviation.
18373 Under Irix6 the abbreviations for a compilation unit are not
18374 always properly terminated with an abbrev number of 0.
18375 Exit loop if we encounter an abbreviation which we have
18376 already read (which means we are about to read the abbreviations
18377 for the next compile unit) or if the end of the abbreviation
18378 table is reached. */
18379 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18381 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18382 abbrev_ptr
+= bytes_read
;
18383 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18388 return abbrev_table
;
18391 /* Returns nonzero if TAG represents a type that we might generate a partial
18395 is_type_tag_for_partial (int tag
)
18400 /* Some types that would be reasonable to generate partial symbols for,
18401 that we don't at present. */
18402 case DW_TAG_array_type
:
18403 case DW_TAG_file_type
:
18404 case DW_TAG_ptr_to_member_type
:
18405 case DW_TAG_set_type
:
18406 case DW_TAG_string_type
:
18407 case DW_TAG_subroutine_type
:
18409 case DW_TAG_base_type
:
18410 case DW_TAG_class_type
:
18411 case DW_TAG_interface_type
:
18412 case DW_TAG_enumeration_type
:
18413 case DW_TAG_structure_type
:
18414 case DW_TAG_subrange_type
:
18415 case DW_TAG_typedef
:
18416 case DW_TAG_union_type
:
18423 /* Load all DIEs that are interesting for partial symbols into memory. */
18425 static struct partial_die_info
*
18426 load_partial_dies (const struct die_reader_specs
*reader
,
18427 const gdb_byte
*info_ptr
, int building_psymtab
)
18429 struct dwarf2_cu
*cu
= reader
->cu
;
18430 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18431 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18432 unsigned int bytes_read
;
18433 unsigned int load_all
= 0;
18434 int nesting_level
= 1;
18439 gdb_assert (cu
->per_cu
!= NULL
);
18440 if (cu
->per_cu
->load_all_dies
)
18444 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18448 &cu
->comp_unit_obstack
,
18449 hashtab_obstack_allocate
,
18450 dummy_obstack_deallocate
);
18454 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18456 /* A NULL abbrev means the end of a series of children. */
18457 if (abbrev
== NULL
)
18459 if (--nesting_level
== 0)
18462 info_ptr
+= bytes_read
;
18463 last_die
= parent_die
;
18464 parent_die
= parent_die
->die_parent
;
18468 /* Check for template arguments. We never save these; if
18469 they're seen, we just mark the parent, and go on our way. */
18470 if (parent_die
!= NULL
18471 && cu
->language
== language_cplus
18472 && (abbrev
->tag
== DW_TAG_template_type_param
18473 || abbrev
->tag
== DW_TAG_template_value_param
))
18475 parent_die
->has_template_arguments
= 1;
18479 /* We don't need a partial DIE for the template argument. */
18480 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18485 /* We only recurse into c++ subprograms looking for template arguments.
18486 Skip their other children. */
18488 && cu
->language
== language_cplus
18489 && parent_die
!= NULL
18490 && parent_die
->tag
== DW_TAG_subprogram
)
18492 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18496 /* Check whether this DIE is interesting enough to save. Normally
18497 we would not be interested in members here, but there may be
18498 later variables referencing them via DW_AT_specification (for
18499 static members). */
18501 && !is_type_tag_for_partial (abbrev
->tag
)
18502 && abbrev
->tag
!= DW_TAG_constant
18503 && abbrev
->tag
!= DW_TAG_enumerator
18504 && abbrev
->tag
!= DW_TAG_subprogram
18505 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18506 && abbrev
->tag
!= DW_TAG_lexical_block
18507 && abbrev
->tag
!= DW_TAG_variable
18508 && abbrev
->tag
!= DW_TAG_namespace
18509 && abbrev
->tag
!= DW_TAG_module
18510 && abbrev
->tag
!= DW_TAG_member
18511 && abbrev
->tag
!= DW_TAG_imported_unit
18512 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18514 /* Otherwise we skip to the next sibling, if any. */
18515 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18519 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18522 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18524 /* This two-pass algorithm for processing partial symbols has a
18525 high cost in cache pressure. Thus, handle some simple cases
18526 here which cover the majority of C partial symbols. DIEs
18527 which neither have specification tags in them, nor could have
18528 specification tags elsewhere pointing at them, can simply be
18529 processed and discarded.
18531 This segment is also optional; scan_partial_symbols and
18532 add_partial_symbol will handle these DIEs if we chain
18533 them in normally. When compilers which do not emit large
18534 quantities of duplicate debug information are more common,
18535 this code can probably be removed. */
18537 /* Any complete simple types at the top level (pretty much all
18538 of them, for a language without namespaces), can be processed
18540 if (parent_die
== NULL
18541 && pdi
.has_specification
== 0
18542 && pdi
.is_declaration
== 0
18543 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18544 || pdi
.tag
== DW_TAG_base_type
18545 || pdi
.tag
== DW_TAG_subrange_type
))
18547 if (building_psymtab
&& pdi
.name
!= NULL
)
18548 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18549 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18550 psymbol_placement::STATIC
,
18551 0, cu
->language
, objfile
);
18552 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18556 /* The exception for DW_TAG_typedef with has_children above is
18557 a workaround of GCC PR debug/47510. In the case of this complaint
18558 type_name_or_error will error on such types later.
18560 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18561 it could not find the child DIEs referenced later, this is checked
18562 above. In correct DWARF DW_TAG_typedef should have no children. */
18564 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18565 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18566 "- DIE at %s [in module %s]"),
18567 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18569 /* If we're at the second level, and we're an enumerator, and
18570 our parent has no specification (meaning possibly lives in a
18571 namespace elsewhere), then we can add the partial symbol now
18572 instead of queueing it. */
18573 if (pdi
.tag
== DW_TAG_enumerator
18574 && parent_die
!= NULL
18575 && parent_die
->die_parent
== NULL
18576 && parent_die
->tag
== DW_TAG_enumeration_type
18577 && parent_die
->has_specification
== 0)
18579 if (pdi
.name
== NULL
)
18580 complaint (_("malformed enumerator DIE ignored"));
18581 else if (building_psymtab
)
18582 add_psymbol_to_list (pdi
.name
, strlen (pdi
.name
), false,
18583 VAR_DOMAIN
, LOC_CONST
, -1,
18584 cu
->language
== language_cplus
18585 ? psymbol_placement::GLOBAL
18586 : psymbol_placement::STATIC
,
18587 0, cu
->language
, objfile
);
18589 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18593 struct partial_die_info
*part_die
18594 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18596 /* We'll save this DIE so link it in. */
18597 part_die
->die_parent
= parent_die
;
18598 part_die
->die_sibling
= NULL
;
18599 part_die
->die_child
= NULL
;
18601 if (last_die
&& last_die
== parent_die
)
18602 last_die
->die_child
= part_die
;
18604 last_die
->die_sibling
= part_die
;
18606 last_die
= part_die
;
18608 if (first_die
== NULL
)
18609 first_die
= part_die
;
18611 /* Maybe add the DIE to the hash table. Not all DIEs that we
18612 find interesting need to be in the hash table, because we
18613 also have the parent/sibling/child chains; only those that we
18614 might refer to by offset later during partial symbol reading.
18616 For now this means things that might have be the target of a
18617 DW_AT_specification, DW_AT_abstract_origin, or
18618 DW_AT_extension. DW_AT_extension will refer only to
18619 namespaces; DW_AT_abstract_origin refers to functions (and
18620 many things under the function DIE, but we do not recurse
18621 into function DIEs during partial symbol reading) and
18622 possibly variables as well; DW_AT_specification refers to
18623 declarations. Declarations ought to have the DW_AT_declaration
18624 flag. It happens that GCC forgets to put it in sometimes, but
18625 only for functions, not for types.
18627 Adding more things than necessary to the hash table is harmless
18628 except for the performance cost. Adding too few will result in
18629 wasted time in find_partial_die, when we reread the compilation
18630 unit with load_all_dies set. */
18633 || abbrev
->tag
== DW_TAG_constant
18634 || abbrev
->tag
== DW_TAG_subprogram
18635 || abbrev
->tag
== DW_TAG_variable
18636 || abbrev
->tag
== DW_TAG_namespace
18637 || part_die
->is_declaration
)
18641 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18642 to_underlying (part_die
->sect_off
),
18647 /* For some DIEs we want to follow their children (if any). For C
18648 we have no reason to follow the children of structures; for other
18649 languages we have to, so that we can get at method physnames
18650 to infer fully qualified class names, for DW_AT_specification,
18651 and for C++ template arguments. For C++, we also look one level
18652 inside functions to find template arguments (if the name of the
18653 function does not already contain the template arguments).
18655 For Ada and Fortran, we need to scan the children of subprograms
18656 and lexical blocks as well because these languages allow the
18657 definition of nested entities that could be interesting for the
18658 debugger, such as nested subprograms for instance. */
18659 if (last_die
->has_children
18661 || last_die
->tag
== DW_TAG_namespace
18662 || last_die
->tag
== DW_TAG_module
18663 || last_die
->tag
== DW_TAG_enumeration_type
18664 || (cu
->language
== language_cplus
18665 && last_die
->tag
== DW_TAG_subprogram
18666 && (last_die
->name
== NULL
18667 || strchr (last_die
->name
, '<') == NULL
))
18668 || (cu
->language
!= language_c
18669 && (last_die
->tag
== DW_TAG_class_type
18670 || last_die
->tag
== DW_TAG_interface_type
18671 || last_die
->tag
== DW_TAG_structure_type
18672 || last_die
->tag
== DW_TAG_union_type
))
18673 || ((cu
->language
== language_ada
18674 || cu
->language
== language_fortran
)
18675 && (last_die
->tag
== DW_TAG_subprogram
18676 || last_die
->tag
== DW_TAG_lexical_block
))))
18679 parent_die
= last_die
;
18683 /* Otherwise we skip to the next sibling, if any. */
18684 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18686 /* Back to the top, do it again. */
18690 partial_die_info::partial_die_info (sect_offset sect_off_
,
18691 struct abbrev_info
*abbrev
)
18692 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18696 /* Read a minimal amount of information into the minimal die structure.
18697 INFO_PTR should point just after the initial uleb128 of a DIE. */
18700 partial_die_info::read (const struct die_reader_specs
*reader
,
18701 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18703 struct dwarf2_cu
*cu
= reader
->cu
;
18704 struct dwarf2_per_objfile
*dwarf2_per_objfile
18705 = cu
->per_cu
->dwarf2_per_objfile
;
18707 int has_low_pc_attr
= 0;
18708 int has_high_pc_attr
= 0;
18709 int high_pc_relative
= 0;
18711 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18713 struct attribute attr
;
18715 info_ptr
= read_attribute (reader
, &attr
, &abbrev
.attrs
[i
], info_ptr
);
18717 /* Store the data if it is of an attribute we want to keep in a
18718 partial symbol table. */
18724 case DW_TAG_compile_unit
:
18725 case DW_TAG_partial_unit
:
18726 case DW_TAG_type_unit
:
18727 /* Compilation units have a DW_AT_name that is a filename, not
18728 a source language identifier. */
18729 case DW_TAG_enumeration_type
:
18730 case DW_TAG_enumerator
:
18731 /* These tags always have simple identifiers already; no need
18732 to canonicalize them. */
18733 name
= DW_STRING (&attr
);
18737 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18740 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18741 &objfile
->per_bfd
->storage_obstack
);
18746 case DW_AT_linkage_name
:
18747 case DW_AT_MIPS_linkage_name
:
18748 /* Note that both forms of linkage name might appear. We
18749 assume they will be the same, and we only store the last
18751 linkage_name
= DW_STRING (&attr
);
18754 has_low_pc_attr
= 1;
18755 lowpc
= attr_value_as_address (&attr
);
18757 case DW_AT_high_pc
:
18758 has_high_pc_attr
= 1;
18759 highpc
= attr_value_as_address (&attr
);
18760 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18761 high_pc_relative
= 1;
18763 case DW_AT_location
:
18764 /* Support the .debug_loc offsets. */
18765 if (attr_form_is_block (&attr
))
18767 d
.locdesc
= DW_BLOCK (&attr
);
18769 else if (attr_form_is_section_offset (&attr
))
18771 dwarf2_complex_location_expr_complaint ();
18775 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18776 "partial symbol information");
18779 case DW_AT_external
:
18780 is_external
= DW_UNSND (&attr
);
18782 case DW_AT_declaration
:
18783 is_declaration
= DW_UNSND (&attr
);
18788 case DW_AT_abstract_origin
:
18789 case DW_AT_specification
:
18790 case DW_AT_extension
:
18791 has_specification
= 1;
18792 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
18793 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18794 || cu
->per_cu
->is_dwz
);
18796 case DW_AT_sibling
:
18797 /* Ignore absolute siblings, they might point outside of
18798 the current compile unit. */
18799 if (attr
.form
== DW_FORM_ref_addr
)
18800 complaint (_("ignoring absolute DW_AT_sibling"));
18803 const gdb_byte
*buffer
= reader
->buffer
;
18804 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
18805 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
18807 if (sibling_ptr
< info_ptr
)
18808 complaint (_("DW_AT_sibling points backwards"));
18809 else if (sibling_ptr
> reader
->buffer_end
)
18810 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
18812 sibling
= sibling_ptr
;
18815 case DW_AT_byte_size
:
18818 case DW_AT_const_value
:
18819 has_const_value
= 1;
18821 case DW_AT_calling_convention
:
18822 /* DWARF doesn't provide a way to identify a program's source-level
18823 entry point. DW_AT_calling_convention attributes are only meant
18824 to describe functions' calling conventions.
18826 However, because it's a necessary piece of information in
18827 Fortran, and before DWARF 4 DW_CC_program was the only
18828 piece of debugging information whose definition refers to
18829 a 'main program' at all, several compilers marked Fortran
18830 main programs with DW_CC_program --- even when those
18831 functions use the standard calling conventions.
18833 Although DWARF now specifies a way to provide this
18834 information, we support this practice for backward
18836 if (DW_UNSND (&attr
) == DW_CC_program
18837 && cu
->language
== language_fortran
)
18838 main_subprogram
= 1;
18841 if (DW_UNSND (&attr
) == DW_INL_inlined
18842 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
18843 may_be_inlined
= 1;
18847 if (tag
== DW_TAG_imported_unit
)
18849 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
18850 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
18851 || cu
->per_cu
->is_dwz
);
18855 case DW_AT_main_subprogram
:
18856 main_subprogram
= DW_UNSND (&attr
);
18861 /* It would be nice to reuse dwarf2_get_pc_bounds here,
18862 but that requires a full DIE, so instead we just
18864 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
18865 unsigned int ranges_offset
= (DW_UNSND (&attr
)
18866 + (need_ranges_base
18870 /* Value of the DW_AT_ranges attribute is the offset in the
18871 .debug_ranges section. */
18872 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
18883 /* For Ada, if both the name and the linkage name appear, we prefer
18884 the latter. This lets "catch exception" work better, regardless
18885 of the order in which the name and linkage name were emitted.
18886 Really, though, this is just a workaround for the fact that gdb
18887 doesn't store both the name and the linkage name. */
18888 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
18889 name
= linkage_name
;
18891 if (high_pc_relative
)
18894 if (has_low_pc_attr
&& has_high_pc_attr
)
18896 /* When using the GNU linker, .gnu.linkonce. sections are used to
18897 eliminate duplicate copies of functions and vtables and such.
18898 The linker will arbitrarily choose one and discard the others.
18899 The AT_*_pc values for such functions refer to local labels in
18900 these sections. If the section from that file was discarded, the
18901 labels are not in the output, so the relocs get a value of 0.
18902 If this is a discarded function, mark the pc bounds as invalid,
18903 so that GDB will ignore it. */
18904 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
18906 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18907 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18909 complaint (_("DW_AT_low_pc %s is zero "
18910 "for DIE at %s [in module %s]"),
18911 paddress (gdbarch
, lowpc
),
18912 sect_offset_str (sect_off
),
18913 objfile_name (objfile
));
18915 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
18916 else if (lowpc
>= highpc
)
18918 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18919 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
18921 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
18922 "for DIE at %s [in module %s]"),
18923 paddress (gdbarch
, lowpc
),
18924 paddress (gdbarch
, highpc
),
18925 sect_offset_str (sect_off
),
18926 objfile_name (objfile
));
18935 /* Find a cached partial DIE at OFFSET in CU. */
18937 struct partial_die_info
*
18938 dwarf2_cu::find_partial_die (sect_offset sect_off
)
18940 struct partial_die_info
*lookup_die
= NULL
;
18941 struct partial_die_info
part_die (sect_off
);
18943 lookup_die
= ((struct partial_die_info
*)
18944 htab_find_with_hash (partial_dies
, &part_die
,
18945 to_underlying (sect_off
)));
18950 /* Find a partial DIE at OFFSET, which may or may not be in CU,
18951 except in the case of .debug_types DIEs which do not reference
18952 outside their CU (they do however referencing other types via
18953 DW_FORM_ref_sig8). */
18955 static const struct cu_partial_die_info
18956 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
18958 struct dwarf2_per_objfile
*dwarf2_per_objfile
18959 = cu
->per_cu
->dwarf2_per_objfile
;
18960 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18961 struct dwarf2_per_cu_data
*per_cu
= NULL
;
18962 struct partial_die_info
*pd
= NULL
;
18964 if (offset_in_dwz
== cu
->per_cu
->is_dwz
18965 && offset_in_cu_p (&cu
->header
, sect_off
))
18967 pd
= cu
->find_partial_die (sect_off
);
18970 /* We missed recording what we needed.
18971 Load all dies and try again. */
18972 per_cu
= cu
->per_cu
;
18976 /* TUs don't reference other CUs/TUs (except via type signatures). */
18977 if (cu
->per_cu
->is_debug_types
)
18979 error (_("Dwarf Error: Type Unit at offset %s contains"
18980 " external reference to offset %s [in module %s].\n"),
18981 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
18982 bfd_get_filename (objfile
->obfd
));
18984 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
18985 dwarf2_per_objfile
);
18987 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
18988 load_partial_comp_unit (per_cu
);
18990 per_cu
->cu
->last_used
= 0;
18991 pd
= per_cu
->cu
->find_partial_die (sect_off
);
18994 /* If we didn't find it, and not all dies have been loaded,
18995 load them all and try again. */
18997 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
18999 per_cu
->load_all_dies
= 1;
19001 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19002 THIS_CU->cu may already be in use. So we can't just free it and
19003 replace its DIEs with the ones we read in. Instead, we leave those
19004 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19005 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19007 load_partial_comp_unit (per_cu
);
19009 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19013 internal_error (__FILE__
, __LINE__
,
19014 _("could not find partial DIE %s "
19015 "in cache [from module %s]\n"),
19016 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19017 return { per_cu
->cu
, pd
};
19020 /* See if we can figure out if the class lives in a namespace. We do
19021 this by looking for a member function; its demangled name will
19022 contain namespace info, if there is any. */
19025 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19026 struct dwarf2_cu
*cu
)
19028 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19029 what template types look like, because the demangler
19030 frequently doesn't give the same name as the debug info. We
19031 could fix this by only using the demangled name to get the
19032 prefix (but see comment in read_structure_type). */
19034 struct partial_die_info
*real_pdi
;
19035 struct partial_die_info
*child_pdi
;
19037 /* If this DIE (this DIE's specification, if any) has a parent, then
19038 we should not do this. We'll prepend the parent's fully qualified
19039 name when we create the partial symbol. */
19041 real_pdi
= struct_pdi
;
19042 while (real_pdi
->has_specification
)
19044 auto res
= find_partial_die (real_pdi
->spec_offset
,
19045 real_pdi
->spec_is_dwz
, cu
);
19046 real_pdi
= res
.pdi
;
19050 if (real_pdi
->die_parent
!= NULL
)
19053 for (child_pdi
= struct_pdi
->die_child
;
19055 child_pdi
= child_pdi
->die_sibling
)
19057 if (child_pdi
->tag
== DW_TAG_subprogram
19058 && child_pdi
->linkage_name
!= NULL
)
19060 char *actual_class_name
19061 = language_class_name_from_physname (cu
->language_defn
,
19062 child_pdi
->linkage_name
);
19063 if (actual_class_name
!= NULL
)
19065 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19067 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19068 actual_class_name
);
19069 xfree (actual_class_name
);
19077 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19079 /* Once we've fixed up a die, there's no point in doing so again.
19080 This also avoids a memory leak if we were to call
19081 guess_partial_die_structure_name multiple times. */
19085 /* If we found a reference attribute and the DIE has no name, try
19086 to find a name in the referred to DIE. */
19088 if (name
== NULL
&& has_specification
)
19090 struct partial_die_info
*spec_die
;
19092 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19093 spec_die
= res
.pdi
;
19096 spec_die
->fixup (cu
);
19098 if (spec_die
->name
)
19100 name
= spec_die
->name
;
19102 /* Copy DW_AT_external attribute if it is set. */
19103 if (spec_die
->is_external
)
19104 is_external
= spec_die
->is_external
;
19108 /* Set default names for some unnamed DIEs. */
19110 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19111 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19113 /* If there is no parent die to provide a namespace, and there are
19114 children, see if we can determine the namespace from their linkage
19116 if (cu
->language
== language_cplus
19117 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19118 && die_parent
== NULL
19120 && (tag
== DW_TAG_class_type
19121 || tag
== DW_TAG_structure_type
19122 || tag
== DW_TAG_union_type
))
19123 guess_partial_die_structure_name (this, cu
);
19125 /* GCC might emit a nameless struct or union that has a linkage
19126 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19128 && (tag
== DW_TAG_class_type
19129 || tag
== DW_TAG_interface_type
19130 || tag
== DW_TAG_structure_type
19131 || tag
== DW_TAG_union_type
)
19132 && linkage_name
!= NULL
)
19136 demangled
= gdb_demangle (linkage_name
, DMGL_TYPES
);
19141 /* Strip any leading namespaces/classes, keep only the base name.
19142 DW_AT_name for named DIEs does not contain the prefixes. */
19143 base
= strrchr (demangled
, ':');
19144 if (base
&& base
> demangled
&& base
[-1] == ':')
19149 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19150 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19158 /* Read an attribute value described by an attribute form. */
19160 static const gdb_byte
*
19161 read_attribute_value (const struct die_reader_specs
*reader
,
19162 struct attribute
*attr
, unsigned form
,
19163 LONGEST implicit_const
, const gdb_byte
*info_ptr
)
19165 struct dwarf2_cu
*cu
= reader
->cu
;
19166 struct dwarf2_per_objfile
*dwarf2_per_objfile
19167 = cu
->per_cu
->dwarf2_per_objfile
;
19168 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19169 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19170 bfd
*abfd
= reader
->abfd
;
19171 struct comp_unit_head
*cu_header
= &cu
->header
;
19172 unsigned int bytes_read
;
19173 struct dwarf_block
*blk
;
19175 attr
->form
= (enum dwarf_form
) form
;
19178 case DW_FORM_ref_addr
:
19179 if (cu
->header
.version
== 2)
19180 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19182 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19183 &cu
->header
, &bytes_read
);
19184 info_ptr
+= bytes_read
;
19186 case DW_FORM_GNU_ref_alt
:
19187 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19188 info_ptr
+= bytes_read
;
19191 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19192 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19193 info_ptr
+= bytes_read
;
19195 case DW_FORM_block2
:
19196 blk
= dwarf_alloc_block (cu
);
19197 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19199 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19200 info_ptr
+= blk
->size
;
19201 DW_BLOCK (attr
) = blk
;
19203 case DW_FORM_block4
:
19204 blk
= dwarf_alloc_block (cu
);
19205 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19207 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19208 info_ptr
+= blk
->size
;
19209 DW_BLOCK (attr
) = blk
;
19211 case DW_FORM_data2
:
19212 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19215 case DW_FORM_data4
:
19216 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19219 case DW_FORM_data8
:
19220 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19223 case DW_FORM_data16
:
19224 blk
= dwarf_alloc_block (cu
);
19226 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19228 DW_BLOCK (attr
) = blk
;
19230 case DW_FORM_sec_offset
:
19231 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19232 info_ptr
+= bytes_read
;
19234 case DW_FORM_string
:
19235 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19236 DW_STRING_IS_CANONICAL (attr
) = 0;
19237 info_ptr
+= bytes_read
;
19240 if (!cu
->per_cu
->is_dwz
)
19242 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19243 abfd
, info_ptr
, cu_header
,
19245 DW_STRING_IS_CANONICAL (attr
) = 0;
19246 info_ptr
+= bytes_read
;
19250 case DW_FORM_line_strp
:
19251 if (!cu
->per_cu
->is_dwz
)
19253 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19255 cu_header
, &bytes_read
);
19256 DW_STRING_IS_CANONICAL (attr
) = 0;
19257 info_ptr
+= bytes_read
;
19261 case DW_FORM_GNU_strp_alt
:
19263 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19264 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19267 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19269 DW_STRING_IS_CANONICAL (attr
) = 0;
19270 info_ptr
+= bytes_read
;
19273 case DW_FORM_exprloc
:
19274 case DW_FORM_block
:
19275 blk
= dwarf_alloc_block (cu
);
19276 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19277 info_ptr
+= bytes_read
;
19278 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19279 info_ptr
+= blk
->size
;
19280 DW_BLOCK (attr
) = blk
;
19282 case DW_FORM_block1
:
19283 blk
= dwarf_alloc_block (cu
);
19284 blk
->size
= read_1_byte (abfd
, info_ptr
);
19286 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19287 info_ptr
+= blk
->size
;
19288 DW_BLOCK (attr
) = blk
;
19290 case DW_FORM_data1
:
19291 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19295 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19298 case DW_FORM_flag_present
:
19299 DW_UNSND (attr
) = 1;
19301 case DW_FORM_sdata
:
19302 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19303 info_ptr
+= bytes_read
;
19305 case DW_FORM_udata
:
19306 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19307 info_ptr
+= bytes_read
;
19310 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19311 + read_1_byte (abfd
, info_ptr
));
19315 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19316 + read_2_bytes (abfd
, info_ptr
));
19320 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19321 + read_4_bytes (abfd
, info_ptr
));
19325 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19326 + read_8_bytes (abfd
, info_ptr
));
19329 case DW_FORM_ref_sig8
:
19330 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19333 case DW_FORM_ref_udata
:
19334 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19335 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19336 info_ptr
+= bytes_read
;
19338 case DW_FORM_indirect
:
19339 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19340 info_ptr
+= bytes_read
;
19341 if (form
== DW_FORM_implicit_const
)
19343 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19344 info_ptr
+= bytes_read
;
19346 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19349 case DW_FORM_implicit_const
:
19350 DW_SND (attr
) = implicit_const
;
19352 case DW_FORM_addrx
:
19353 case DW_FORM_GNU_addr_index
:
19354 if (reader
->dwo_file
== NULL
)
19356 /* For now flag a hard error.
19357 Later we can turn this into a complaint. */
19358 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19359 dwarf_form_name (form
),
19360 bfd_get_filename (abfd
));
19362 DW_ADDR (attr
) = read_addr_index_from_leb128 (cu
, info_ptr
, &bytes_read
);
19363 info_ptr
+= bytes_read
;
19366 case DW_FORM_strx1
:
19367 case DW_FORM_strx2
:
19368 case DW_FORM_strx3
:
19369 case DW_FORM_strx4
:
19370 case DW_FORM_GNU_str_index
:
19371 if (reader
->dwo_file
== NULL
)
19373 /* For now flag a hard error.
19374 Later we can turn this into a complaint if warranted. */
19375 error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"),
19376 dwarf_form_name (form
),
19377 bfd_get_filename (abfd
));
19380 ULONGEST str_index
;
19381 if (form
== DW_FORM_strx1
)
19383 str_index
= read_1_byte (abfd
, info_ptr
);
19386 else if (form
== DW_FORM_strx2
)
19388 str_index
= read_2_bytes (abfd
, info_ptr
);
19391 else if (form
== DW_FORM_strx3
)
19393 str_index
= read_3_bytes (abfd
, info_ptr
);
19396 else if (form
== DW_FORM_strx4
)
19398 str_index
= read_4_bytes (abfd
, info_ptr
);
19403 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19404 info_ptr
+= bytes_read
;
19406 DW_STRING (attr
) = read_str_index (reader
, str_index
);
19407 DW_STRING_IS_CANONICAL (attr
) = 0;
19411 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19412 dwarf_form_name (form
),
19413 bfd_get_filename (abfd
));
19417 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19418 attr
->form
= DW_FORM_GNU_ref_alt
;
19420 /* We have seen instances where the compiler tried to emit a byte
19421 size attribute of -1 which ended up being encoded as an unsigned
19422 0xffffffff. Although 0xffffffff is technically a valid size value,
19423 an object of this size seems pretty unlikely so we can relatively
19424 safely treat these cases as if the size attribute was invalid and
19425 treat them as zero by default. */
19426 if (attr
->name
== DW_AT_byte_size
19427 && form
== DW_FORM_data4
19428 && DW_UNSND (attr
) >= 0xffffffff)
19431 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19432 hex_string (DW_UNSND (attr
)));
19433 DW_UNSND (attr
) = 0;
19439 /* Read an attribute described by an abbreviated attribute. */
19441 static const gdb_byte
*
19442 read_attribute (const struct die_reader_specs
*reader
,
19443 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19444 const gdb_byte
*info_ptr
)
19446 attr
->name
= abbrev
->name
;
19447 return read_attribute_value (reader
, attr
, abbrev
->form
,
19448 abbrev
->implicit_const
, info_ptr
);
19451 /* Read dwarf information from a buffer. */
19453 static unsigned int
19454 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19456 return bfd_get_8 (abfd
, buf
);
19460 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19462 return bfd_get_signed_8 (abfd
, buf
);
19465 static unsigned int
19466 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19468 return bfd_get_16 (abfd
, buf
);
19472 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19474 return bfd_get_signed_16 (abfd
, buf
);
19477 static unsigned int
19478 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19480 unsigned int result
= 0;
19481 for (int i
= 0; i
< 3; ++i
)
19483 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19485 result
|= ((unsigned int) byte
<< (i
* 8));
19490 static unsigned int
19491 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19493 return bfd_get_32 (abfd
, buf
);
19497 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19499 return bfd_get_signed_32 (abfd
, buf
);
19503 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19505 return bfd_get_64 (abfd
, buf
);
19509 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19510 unsigned int *bytes_read
)
19512 struct comp_unit_head
*cu_header
= &cu
->header
;
19513 CORE_ADDR retval
= 0;
19515 if (cu_header
->signed_addr_p
)
19517 switch (cu_header
->addr_size
)
19520 retval
= bfd_get_signed_16 (abfd
, buf
);
19523 retval
= bfd_get_signed_32 (abfd
, buf
);
19526 retval
= bfd_get_signed_64 (abfd
, buf
);
19529 internal_error (__FILE__
, __LINE__
,
19530 _("read_address: bad switch, signed [in module %s]"),
19531 bfd_get_filename (abfd
));
19536 switch (cu_header
->addr_size
)
19539 retval
= bfd_get_16 (abfd
, buf
);
19542 retval
= bfd_get_32 (abfd
, buf
);
19545 retval
= bfd_get_64 (abfd
, buf
);
19548 internal_error (__FILE__
, __LINE__
,
19549 _("read_address: bad switch, "
19550 "unsigned [in module %s]"),
19551 bfd_get_filename (abfd
));
19555 *bytes_read
= cu_header
->addr_size
;
19559 /* Read the initial length from a section. The (draft) DWARF 3
19560 specification allows the initial length to take up either 4 bytes
19561 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19562 bytes describe the length and all offsets will be 8 bytes in length
19565 An older, non-standard 64-bit format is also handled by this
19566 function. The older format in question stores the initial length
19567 as an 8-byte quantity without an escape value. Lengths greater
19568 than 2^32 aren't very common which means that the initial 4 bytes
19569 is almost always zero. Since a length value of zero doesn't make
19570 sense for the 32-bit format, this initial zero can be considered to
19571 be an escape value which indicates the presence of the older 64-bit
19572 format. As written, the code can't detect (old format) lengths
19573 greater than 4GB. If it becomes necessary to handle lengths
19574 somewhat larger than 4GB, we could allow other small values (such
19575 as the non-sensical values of 1, 2, and 3) to also be used as
19576 escape values indicating the presence of the old format.
19578 The value returned via bytes_read should be used to increment the
19579 relevant pointer after calling read_initial_length().
19581 [ Note: read_initial_length() and read_offset() are based on the
19582 document entitled "DWARF Debugging Information Format", revision
19583 3, draft 8, dated November 19, 2001. This document was obtained
19586 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19588 This document is only a draft and is subject to change. (So beware.)
19590 Details regarding the older, non-standard 64-bit format were
19591 determined empirically by examining 64-bit ELF files produced by
19592 the SGI toolchain on an IRIX 6.5 machine.
19594 - Kevin, July 16, 2002
19598 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19600 LONGEST length
= bfd_get_32 (abfd
, buf
);
19602 if (length
== 0xffffffff)
19604 length
= bfd_get_64 (abfd
, buf
+ 4);
19607 else if (length
== 0)
19609 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19610 length
= bfd_get_64 (abfd
, buf
);
19621 /* Cover function for read_initial_length.
19622 Returns the length of the object at BUF, and stores the size of the
19623 initial length in *BYTES_READ and stores the size that offsets will be in
19625 If the initial length size is not equivalent to that specified in
19626 CU_HEADER then issue a complaint.
19627 This is useful when reading non-comp-unit headers. */
19630 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19631 const struct comp_unit_head
*cu_header
,
19632 unsigned int *bytes_read
,
19633 unsigned int *offset_size
)
19635 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19637 gdb_assert (cu_header
->initial_length_size
== 4
19638 || cu_header
->initial_length_size
== 8
19639 || cu_header
->initial_length_size
== 12);
19641 if (cu_header
->initial_length_size
!= *bytes_read
)
19642 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19644 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19648 /* Read an offset from the data stream. The size of the offset is
19649 given by cu_header->offset_size. */
19652 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19653 const struct comp_unit_head
*cu_header
,
19654 unsigned int *bytes_read
)
19656 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19658 *bytes_read
= cu_header
->offset_size
;
19662 /* Read an offset from the data stream. */
19665 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19667 LONGEST retval
= 0;
19669 switch (offset_size
)
19672 retval
= bfd_get_32 (abfd
, buf
);
19675 retval
= bfd_get_64 (abfd
, buf
);
19678 internal_error (__FILE__
, __LINE__
,
19679 _("read_offset_1: bad switch [in module %s]"),
19680 bfd_get_filename (abfd
));
19686 static const gdb_byte
*
19687 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19689 /* If the size of a host char is 8 bits, we can return a pointer
19690 to the buffer, otherwise we have to copy the data to a buffer
19691 allocated on the temporary obstack. */
19692 gdb_assert (HOST_CHAR_BIT
== 8);
19696 static const char *
19697 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19698 unsigned int *bytes_read_ptr
)
19700 /* If the size of a host char is 8 bits, we can return a pointer
19701 to the string, otherwise we have to copy the string to a buffer
19702 allocated on the temporary obstack. */
19703 gdb_assert (HOST_CHAR_BIT
== 8);
19706 *bytes_read_ptr
= 1;
19709 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19710 return (const char *) buf
;
19713 /* Return pointer to string at section SECT offset STR_OFFSET with error
19714 reporting strings FORM_NAME and SECT_NAME. */
19716 static const char *
19717 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19718 bfd
*abfd
, LONGEST str_offset
,
19719 struct dwarf2_section_info
*sect
,
19720 const char *form_name
,
19721 const char *sect_name
)
19723 dwarf2_read_section (objfile
, sect
);
19724 if (sect
->buffer
== NULL
)
19725 error (_("%s used without %s section [in module %s]"),
19726 form_name
, sect_name
, bfd_get_filename (abfd
));
19727 if (str_offset
>= sect
->size
)
19728 error (_("%s pointing outside of %s section [in module %s]"),
19729 form_name
, sect_name
, bfd_get_filename (abfd
));
19730 gdb_assert (HOST_CHAR_BIT
== 8);
19731 if (sect
->buffer
[str_offset
] == '\0')
19733 return (const char *) (sect
->buffer
+ str_offset
);
19736 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19738 static const char *
19739 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19740 bfd
*abfd
, LONGEST str_offset
)
19742 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19744 &dwarf2_per_objfile
->str
,
19745 "DW_FORM_strp", ".debug_str");
19748 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
19750 static const char *
19751 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19752 bfd
*abfd
, LONGEST str_offset
)
19754 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19756 &dwarf2_per_objfile
->line_str
,
19757 "DW_FORM_line_strp",
19758 ".debug_line_str");
19761 /* Read a string at offset STR_OFFSET in the .debug_str section from
19762 the .dwz file DWZ. Throw an error if the offset is too large. If
19763 the string consists of a single NUL byte, return NULL; otherwise
19764 return a pointer to the string. */
19766 static const char *
19767 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
19768 LONGEST str_offset
)
19770 dwarf2_read_section (objfile
, &dwz
->str
);
19772 if (dwz
->str
.buffer
== NULL
)
19773 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
19774 "section [in module %s]"),
19775 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19776 if (str_offset
>= dwz
->str
.size
)
19777 error (_("DW_FORM_GNU_strp_alt pointing outside of "
19778 ".debug_str section [in module %s]"),
19779 bfd_get_filename (dwz
->dwz_bfd
.get ()));
19780 gdb_assert (HOST_CHAR_BIT
== 8);
19781 if (dwz
->str
.buffer
[str_offset
] == '\0')
19783 return (const char *) (dwz
->str
.buffer
+ str_offset
);
19786 /* Return pointer to string at .debug_str offset as read from BUF.
19787 BUF is assumed to be in a compilation unit described by CU_HEADER.
19788 Return *BYTES_READ_PTR count of bytes read from BUF. */
19790 static const char *
19791 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
19792 const gdb_byte
*buf
,
19793 const struct comp_unit_head
*cu_header
,
19794 unsigned int *bytes_read_ptr
)
19796 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19798 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
19801 /* Return pointer to string at .debug_line_str offset as read from BUF.
19802 BUF is assumed to be in a compilation unit described by CU_HEADER.
19803 Return *BYTES_READ_PTR count of bytes read from BUF. */
19805 static const char *
19806 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19807 bfd
*abfd
, const gdb_byte
*buf
,
19808 const struct comp_unit_head
*cu_header
,
19809 unsigned int *bytes_read_ptr
)
19811 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
19813 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
19818 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19819 unsigned int *bytes_read_ptr
)
19822 unsigned int num_read
;
19824 unsigned char byte
;
19831 byte
= bfd_get_8 (abfd
, buf
);
19834 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19835 if ((byte
& 128) == 0)
19841 *bytes_read_ptr
= num_read
;
19846 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
19847 unsigned int *bytes_read_ptr
)
19850 int shift
, num_read
;
19851 unsigned char byte
;
19858 byte
= bfd_get_8 (abfd
, buf
);
19861 result
|= ((ULONGEST
) (byte
& 127) << shift
);
19863 if ((byte
& 128) == 0)
19868 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
19869 result
|= -(((ULONGEST
) 1) << shift
);
19870 *bytes_read_ptr
= num_read
;
19874 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
19875 ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero.
19876 ADDR_SIZE is the size of addresses from the CU header. */
19879 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19880 unsigned int addr_index
, ULONGEST addr_base
, int addr_size
)
19882 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19883 bfd
*abfd
= objfile
->obfd
;
19884 const gdb_byte
*info_ptr
;
19886 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
19887 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
19888 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
19889 objfile_name (objfile
));
19890 if (addr_base
+ addr_index
* addr_size
>= dwarf2_per_objfile
->addr
.size
)
19891 error (_("DW_FORM_addr_index pointing outside of "
19892 ".debug_addr section [in module %s]"),
19893 objfile_name (objfile
));
19894 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
19895 + addr_base
+ addr_index
* addr_size
);
19896 if (addr_size
== 4)
19897 return bfd_get_32 (abfd
, info_ptr
);
19899 return bfd_get_64 (abfd
, info_ptr
);
19902 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
19905 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
19907 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
19908 cu
->addr_base
, cu
->header
.addr_size
);
19911 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
19914 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
19915 unsigned int *bytes_read
)
19917 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
19918 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
19920 return read_addr_index (cu
, addr_index
);
19923 /* Data structure to pass results from dwarf2_read_addr_index_reader
19924 back to dwarf2_read_addr_index. */
19926 struct dwarf2_read_addr_index_data
19928 ULONGEST addr_base
;
19932 /* die_reader_func for dwarf2_read_addr_index. */
19935 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
19936 const gdb_byte
*info_ptr
,
19937 struct die_info
*comp_unit_die
,
19941 struct dwarf2_cu
*cu
= reader
->cu
;
19942 struct dwarf2_read_addr_index_data
*aidata
=
19943 (struct dwarf2_read_addr_index_data
*) data
;
19945 aidata
->addr_base
= cu
->addr_base
;
19946 aidata
->addr_size
= cu
->header
.addr_size
;
19949 /* Given an index in .debug_addr, fetch the value.
19950 NOTE: This can be called during dwarf expression evaluation,
19951 long after the debug information has been read, and thus per_cu->cu
19952 may no longer exist. */
19955 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
19956 unsigned int addr_index
)
19958 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
19959 struct dwarf2_cu
*cu
= per_cu
->cu
;
19960 ULONGEST addr_base
;
19963 /* We need addr_base and addr_size.
19964 If we don't have PER_CU->cu, we have to get it.
19965 Nasty, but the alternative is storing the needed info in PER_CU,
19966 which at this point doesn't seem justified: it's not clear how frequently
19967 it would get used and it would increase the size of every PER_CU.
19968 Entry points like dwarf2_per_cu_addr_size do a similar thing
19969 so we're not in uncharted territory here.
19970 Alas we need to be a bit more complicated as addr_base is contained
19973 We don't need to read the entire CU(/TU).
19974 We just need the header and top level die.
19976 IWBN to use the aging mechanism to let us lazily later discard the CU.
19977 For now we skip this optimization. */
19981 addr_base
= cu
->addr_base
;
19982 addr_size
= cu
->header
.addr_size
;
19986 struct dwarf2_read_addr_index_data aidata
;
19988 /* Note: We can't use init_cutu_and_read_dies_simple here,
19989 we need addr_base. */
19990 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
19991 dwarf2_read_addr_index_reader
, &aidata
);
19992 addr_base
= aidata
.addr_base
;
19993 addr_size
= aidata
.addr_size
;
19996 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20000 /* Given a DW_FORM_GNU_str_index or DW_FORM_strx, fetch the string.
20001 This is only used by the Fission support. */
20003 static const char *
20004 read_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20006 struct dwarf2_cu
*cu
= reader
->cu
;
20007 struct dwarf2_per_objfile
*dwarf2_per_objfile
20008 = cu
->per_cu
->dwarf2_per_objfile
;
20009 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20010 const char *objf_name
= objfile_name (objfile
);
20011 bfd
*abfd
= objfile
->obfd
;
20012 struct dwarf2_section_info
*str_section
= &reader
->dwo_file
->sections
.str
;
20013 struct dwarf2_section_info
*str_offsets_section
=
20014 &reader
->dwo_file
->sections
.str_offsets
;
20015 const gdb_byte
*info_ptr
;
20016 ULONGEST str_offset
;
20017 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20019 dwarf2_read_section (objfile
, str_section
);
20020 dwarf2_read_section (objfile
, str_offsets_section
);
20021 if (str_section
->buffer
== NULL
)
20022 error (_("%s used without .debug_str.dwo section"
20023 " in CU at offset %s [in module %s]"),
20024 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20025 if (str_offsets_section
->buffer
== NULL
)
20026 error (_("%s used without .debug_str_offsets.dwo section"
20027 " in CU at offset %s [in module %s]"),
20028 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20029 if (str_index
* cu
->header
.offset_size
>= str_offsets_section
->size
)
20030 error (_("%s pointing outside of .debug_str_offsets.dwo"
20031 " section in CU at offset %s [in module %s]"),
20032 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20033 info_ptr
= (str_offsets_section
->buffer
20034 + str_index
* cu
->header
.offset_size
);
20035 if (cu
->header
.offset_size
== 4)
20036 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20038 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20039 if (str_offset
>= str_section
->size
)
20040 error (_("Offset from %s pointing outside of"
20041 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20042 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20043 return (const char *) (str_section
->buffer
+ str_offset
);
20046 /* Return the length of an LEB128 number in BUF. */
20049 leb128_size (const gdb_byte
*buf
)
20051 const gdb_byte
*begin
= buf
;
20057 if ((byte
& 128) == 0)
20058 return buf
- begin
;
20063 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20072 cu
->language
= language_c
;
20075 case DW_LANG_C_plus_plus
:
20076 case DW_LANG_C_plus_plus_11
:
20077 case DW_LANG_C_plus_plus_14
:
20078 cu
->language
= language_cplus
;
20081 cu
->language
= language_d
;
20083 case DW_LANG_Fortran77
:
20084 case DW_LANG_Fortran90
:
20085 case DW_LANG_Fortran95
:
20086 case DW_LANG_Fortran03
:
20087 case DW_LANG_Fortran08
:
20088 cu
->language
= language_fortran
;
20091 cu
->language
= language_go
;
20093 case DW_LANG_Mips_Assembler
:
20094 cu
->language
= language_asm
;
20096 case DW_LANG_Ada83
:
20097 case DW_LANG_Ada95
:
20098 cu
->language
= language_ada
;
20100 case DW_LANG_Modula2
:
20101 cu
->language
= language_m2
;
20103 case DW_LANG_Pascal83
:
20104 cu
->language
= language_pascal
;
20107 cu
->language
= language_objc
;
20110 case DW_LANG_Rust_old
:
20111 cu
->language
= language_rust
;
20113 case DW_LANG_Cobol74
:
20114 case DW_LANG_Cobol85
:
20116 cu
->language
= language_minimal
;
20119 cu
->language_defn
= language_def (cu
->language
);
20122 /* Return the named attribute or NULL if not there. */
20124 static struct attribute
*
20125 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20130 struct attribute
*spec
= NULL
;
20132 for (i
= 0; i
< die
->num_attrs
; ++i
)
20134 if (die
->attrs
[i
].name
== name
)
20135 return &die
->attrs
[i
];
20136 if (die
->attrs
[i
].name
== DW_AT_specification
20137 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20138 spec
= &die
->attrs
[i
];
20144 die
= follow_die_ref (die
, spec
, &cu
);
20150 /* Return the named attribute or NULL if not there,
20151 but do not follow DW_AT_specification, etc.
20152 This is for use in contexts where we're reading .debug_types dies.
20153 Following DW_AT_specification, DW_AT_abstract_origin will take us
20154 back up the chain, and we want to go down. */
20156 static struct attribute
*
20157 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20161 for (i
= 0; i
< die
->num_attrs
; ++i
)
20162 if (die
->attrs
[i
].name
== name
)
20163 return &die
->attrs
[i
];
20168 /* Return the string associated with a string-typed attribute, or NULL if it
20169 is either not found or is of an incorrect type. */
20171 static const char *
20172 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20174 struct attribute
*attr
;
20175 const char *str
= NULL
;
20177 attr
= dwarf2_attr (die
, name
, cu
);
20181 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20182 || attr
->form
== DW_FORM_string
20183 || attr
->form
== DW_FORM_strx
20184 || attr
->form
== DW_FORM_strx1
20185 || attr
->form
== DW_FORM_strx2
20186 || attr
->form
== DW_FORM_strx3
20187 || attr
->form
== DW_FORM_strx4
20188 || attr
->form
== DW_FORM_GNU_str_index
20189 || attr
->form
== DW_FORM_GNU_strp_alt
)
20190 str
= DW_STRING (attr
);
20192 complaint (_("string type expected for attribute %s for "
20193 "DIE at %s in module %s"),
20194 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20195 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20201 /* Return the dwo name or NULL if not present. If present, it is in either
20202 DW_AT_GNU_dwo_name or DW_AT_dwo_name atrribute. */
20203 static const char *
20204 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20206 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20207 if (dwo_name
== nullptr)
20208 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20212 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20213 and holds a non-zero value. This function should only be used for
20214 DW_FORM_flag or DW_FORM_flag_present attributes. */
20217 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20219 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20221 return (attr
&& DW_UNSND (attr
));
20225 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20227 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20228 which value is non-zero. However, we have to be careful with
20229 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20230 (via dwarf2_flag_true_p) follows this attribute. So we may
20231 end up accidently finding a declaration attribute that belongs
20232 to a different DIE referenced by the specification attribute,
20233 even though the given DIE does not have a declaration attribute. */
20234 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20235 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20238 /* Return the die giving the specification for DIE, if there is
20239 one. *SPEC_CU is the CU containing DIE on input, and the CU
20240 containing the return value on output. If there is no
20241 specification, but there is an abstract origin, that is
20244 static struct die_info
*
20245 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20247 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20250 if (spec_attr
== NULL
)
20251 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20253 if (spec_attr
== NULL
)
20256 return follow_die_ref (die
, spec_attr
, spec_cu
);
20259 /* Stub for free_line_header to match void * callback types. */
20262 free_line_header_voidp (void *arg
)
20264 struct line_header
*lh
= (struct line_header
*) arg
;
20270 line_header::add_include_dir (const char *include_dir
)
20272 if (dwarf_line_debug
>= 2)
20273 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20274 include_dirs
.size () + 1, include_dir
);
20276 include_dirs
.push_back (include_dir
);
20280 line_header::add_file_name (const char *name
,
20282 unsigned int mod_time
,
20283 unsigned int length
)
20285 if (dwarf_line_debug
>= 2)
20286 fprintf_unfiltered (gdb_stdlog
, "Adding file %u: %s\n",
20287 (unsigned) file_names
.size () + 1, name
);
20289 file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20292 /* A convenience function to find the proper .debug_line section for a CU. */
20294 static struct dwarf2_section_info
*
20295 get_debug_line_section (struct dwarf2_cu
*cu
)
20297 struct dwarf2_section_info
*section
;
20298 struct dwarf2_per_objfile
*dwarf2_per_objfile
20299 = cu
->per_cu
->dwarf2_per_objfile
;
20301 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20303 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20304 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20305 else if (cu
->per_cu
->is_dwz
)
20307 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20309 section
= &dwz
->line
;
20312 section
= &dwarf2_per_objfile
->line
;
20317 /* Read directory or file name entry format, starting with byte of
20318 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20319 entries count and the entries themselves in the described entry
20323 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20324 bfd
*abfd
, const gdb_byte
**bufp
,
20325 struct line_header
*lh
,
20326 const struct comp_unit_head
*cu_header
,
20327 void (*callback
) (struct line_header
*lh
,
20330 unsigned int mod_time
,
20331 unsigned int length
))
20333 gdb_byte format_count
, formati
;
20334 ULONGEST data_count
, datai
;
20335 const gdb_byte
*buf
= *bufp
;
20336 const gdb_byte
*format_header_data
;
20337 unsigned int bytes_read
;
20339 format_count
= read_1_byte (abfd
, buf
);
20341 format_header_data
= buf
;
20342 for (formati
= 0; formati
< format_count
; formati
++)
20344 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20346 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20350 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20352 for (datai
= 0; datai
< data_count
; datai
++)
20354 const gdb_byte
*format
= format_header_data
;
20355 struct file_entry fe
;
20357 for (formati
= 0; formati
< format_count
; formati
++)
20359 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20360 format
+= bytes_read
;
20362 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20363 format
+= bytes_read
;
20365 gdb::optional
<const char *> string
;
20366 gdb::optional
<unsigned int> uint
;
20370 case DW_FORM_string
:
20371 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20375 case DW_FORM_line_strp
:
20376 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20383 case DW_FORM_data1
:
20384 uint
.emplace (read_1_byte (abfd
, buf
));
20388 case DW_FORM_data2
:
20389 uint
.emplace (read_2_bytes (abfd
, buf
));
20393 case DW_FORM_data4
:
20394 uint
.emplace (read_4_bytes (abfd
, buf
));
20398 case DW_FORM_data8
:
20399 uint
.emplace (read_8_bytes (abfd
, buf
));
20403 case DW_FORM_udata
:
20404 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20408 case DW_FORM_block
:
20409 /* It is valid only for DW_LNCT_timestamp which is ignored by
20414 switch (content_type
)
20417 if (string
.has_value ())
20420 case DW_LNCT_directory_index
:
20421 if (uint
.has_value ())
20422 fe
.d_index
= (dir_index
) *uint
;
20424 case DW_LNCT_timestamp
:
20425 if (uint
.has_value ())
20426 fe
.mod_time
= *uint
;
20429 if (uint
.has_value ())
20435 complaint (_("Unknown format content type %s"),
20436 pulongest (content_type
));
20440 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20446 /* Read the statement program header starting at OFFSET in
20447 .debug_line, or .debug_line.dwo. Return a pointer
20448 to a struct line_header, allocated using xmalloc.
20449 Returns NULL if there is a problem reading the header, e.g., if it
20450 has a version we don't understand.
20452 NOTE: the strings in the include directory and file name tables of
20453 the returned object point into the dwarf line section buffer,
20454 and must not be freed. */
20456 static line_header_up
20457 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20459 const gdb_byte
*line_ptr
;
20460 unsigned int bytes_read
, offset_size
;
20462 const char *cur_dir
, *cur_file
;
20463 struct dwarf2_section_info
*section
;
20465 struct dwarf2_per_objfile
*dwarf2_per_objfile
20466 = cu
->per_cu
->dwarf2_per_objfile
;
20468 section
= get_debug_line_section (cu
);
20469 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20470 if (section
->buffer
== NULL
)
20472 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20473 complaint (_("missing .debug_line.dwo section"));
20475 complaint (_("missing .debug_line section"));
20479 /* We can't do this until we know the section is non-empty.
20480 Only then do we know we have such a section. */
20481 abfd
= get_section_bfd_owner (section
);
20483 /* Make sure that at least there's room for the total_length field.
20484 That could be 12 bytes long, but we're just going to fudge that. */
20485 if (to_underlying (sect_off
) + 4 >= section
->size
)
20487 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20491 line_header_up
lh (new line_header ());
20493 lh
->sect_off
= sect_off
;
20494 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20496 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20498 /* Read in the header. */
20500 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20501 &bytes_read
, &offset_size
);
20502 line_ptr
+= bytes_read
;
20503 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20505 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20508 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
20509 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20511 if (lh
->version
> 5)
20513 /* This is a version we don't understand. The format could have
20514 changed in ways we don't handle properly so just punt. */
20515 complaint (_("unsupported version in .debug_line section"));
20518 if (lh
->version
>= 5)
20520 gdb_byte segment_selector_size
;
20522 /* Skip address size. */
20523 read_1_byte (abfd
, line_ptr
);
20526 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20528 if (segment_selector_size
!= 0)
20530 complaint (_("unsupported segment selector size %u "
20531 "in .debug_line section"),
20532 segment_selector_size
);
20536 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20537 line_ptr
+= offset_size
;
20538 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20540 if (lh
->version
>= 4)
20542 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20546 lh
->maximum_ops_per_instruction
= 1;
20548 if (lh
->maximum_ops_per_instruction
== 0)
20550 lh
->maximum_ops_per_instruction
= 1;
20551 complaint (_("invalid maximum_ops_per_instruction "
20552 "in `.debug_line' section"));
20555 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20557 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20559 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20561 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20563 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20565 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20566 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20568 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20572 if (lh
->version
>= 5)
20574 /* Read directory table. */
20575 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20577 [] (struct line_header
*header
, const char *name
,
20578 dir_index d_index
, unsigned int mod_time
,
20579 unsigned int length
)
20581 header
->add_include_dir (name
);
20584 /* Read file name table. */
20585 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20587 [] (struct line_header
*header
, const char *name
,
20588 dir_index d_index
, unsigned int mod_time
,
20589 unsigned int length
)
20591 header
->add_file_name (name
, d_index
, mod_time
, length
);
20596 /* Read directory table. */
20597 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20599 line_ptr
+= bytes_read
;
20600 lh
->add_include_dir (cur_dir
);
20602 line_ptr
+= bytes_read
;
20604 /* Read file name table. */
20605 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20607 unsigned int mod_time
, length
;
20610 line_ptr
+= bytes_read
;
20611 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20612 line_ptr
+= bytes_read
;
20613 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20614 line_ptr
+= bytes_read
;
20615 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20616 line_ptr
+= bytes_read
;
20618 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20620 line_ptr
+= bytes_read
;
20622 lh
->statement_program_start
= line_ptr
;
20624 if (line_ptr
> (section
->buffer
+ section
->size
))
20625 complaint (_("line number info header doesn't "
20626 "fit in `.debug_line' section"));
20631 /* Subroutine of dwarf_decode_lines to simplify it.
20632 Return the file name of the psymtab for included file FILE_INDEX
20633 in line header LH of PST.
20634 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20635 If space for the result is malloc'd, *NAME_HOLDER will be set.
20636 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20638 static const char *
20639 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
20640 const struct partial_symtab
*pst
,
20641 const char *comp_dir
,
20642 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20644 const file_entry
&fe
= lh
->file_names
[file_index
];
20645 const char *include_name
= fe
.name
;
20646 const char *include_name_to_compare
= include_name
;
20647 const char *pst_filename
;
20650 const char *dir_name
= fe
.include_dir (lh
);
20652 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20653 if (!IS_ABSOLUTE_PATH (include_name
)
20654 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20656 /* Avoid creating a duplicate psymtab for PST.
20657 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20658 Before we do the comparison, however, we need to account
20659 for DIR_NAME and COMP_DIR.
20660 First prepend dir_name (if non-NULL). If we still don't
20661 have an absolute path prepend comp_dir (if non-NULL).
20662 However, the directory we record in the include-file's
20663 psymtab does not contain COMP_DIR (to match the
20664 corresponding symtab(s)).
20669 bash$ gcc -g ./hello.c
20670 include_name = "hello.c"
20672 DW_AT_comp_dir = comp_dir = "/tmp"
20673 DW_AT_name = "./hello.c"
20677 if (dir_name
!= NULL
)
20679 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20680 include_name
, (char *) NULL
));
20681 include_name
= name_holder
->get ();
20682 include_name_to_compare
= include_name
;
20684 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20686 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20687 include_name
, (char *) NULL
));
20688 include_name_to_compare
= hold_compare
.get ();
20692 pst_filename
= pst
->filename
;
20693 gdb::unique_xmalloc_ptr
<char> copied_name
;
20694 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20696 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20697 pst_filename
, (char *) NULL
));
20698 pst_filename
= copied_name
.get ();
20701 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20705 return include_name
;
20708 /* State machine to track the state of the line number program. */
20710 class lnp_state_machine
20713 /* Initialize a machine state for the start of a line number
20715 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20716 bool record_lines_p
);
20718 file_entry
*current_file ()
20720 /* lh->file_names is 0-based, but the file name numbers in the
20721 statement program are 1-based. */
20722 return m_line_header
->file_name_at (m_file
);
20725 /* Record the line in the state machine. END_SEQUENCE is true if
20726 we're processing the end of a sequence. */
20727 void record_line (bool end_sequence
);
20729 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
20730 nop-out rest of the lines in this sequence. */
20731 void check_line_address (struct dwarf2_cu
*cu
,
20732 const gdb_byte
*line_ptr
,
20733 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
20735 void handle_set_discriminator (unsigned int discriminator
)
20737 m_discriminator
= discriminator
;
20738 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
20741 /* Handle DW_LNE_set_address. */
20742 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
20745 address
+= baseaddr
;
20746 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
20749 /* Handle DW_LNS_advance_pc. */
20750 void handle_advance_pc (CORE_ADDR adjust
);
20752 /* Handle a special opcode. */
20753 void handle_special_opcode (unsigned char op_code
);
20755 /* Handle DW_LNS_advance_line. */
20756 void handle_advance_line (int line_delta
)
20758 advance_line (line_delta
);
20761 /* Handle DW_LNS_set_file. */
20762 void handle_set_file (file_name_index file
);
20764 /* Handle DW_LNS_negate_stmt. */
20765 void handle_negate_stmt ()
20767 m_is_stmt
= !m_is_stmt
;
20770 /* Handle DW_LNS_const_add_pc. */
20771 void handle_const_add_pc ();
20773 /* Handle DW_LNS_fixed_advance_pc. */
20774 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
20776 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20780 /* Handle DW_LNS_copy. */
20781 void handle_copy ()
20783 record_line (false);
20784 m_discriminator
= 0;
20787 /* Handle DW_LNE_end_sequence. */
20788 void handle_end_sequence ()
20790 m_currently_recording_lines
= true;
20794 /* Advance the line by LINE_DELTA. */
20795 void advance_line (int line_delta
)
20797 m_line
+= line_delta
;
20799 if (line_delta
!= 0)
20800 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20803 struct dwarf2_cu
*m_cu
;
20805 gdbarch
*m_gdbarch
;
20807 /* True if we're recording lines.
20808 Otherwise we're building partial symtabs and are just interested in
20809 finding include files mentioned by the line number program. */
20810 bool m_record_lines_p
;
20812 /* The line number header. */
20813 line_header
*m_line_header
;
20815 /* These are part of the standard DWARF line number state machine,
20816 and initialized according to the DWARF spec. */
20818 unsigned char m_op_index
= 0;
20819 /* The line table index (1-based) of the current file. */
20820 file_name_index m_file
= (file_name_index
) 1;
20821 unsigned int m_line
= 1;
20823 /* These are initialized in the constructor. */
20825 CORE_ADDR m_address
;
20827 unsigned int m_discriminator
;
20829 /* Additional bits of state we need to track. */
20831 /* The last file that we called dwarf2_start_subfile for.
20832 This is only used for TLLs. */
20833 unsigned int m_last_file
= 0;
20834 /* The last file a line number was recorded for. */
20835 struct subfile
*m_last_subfile
= NULL
;
20837 /* When true, record the lines we decode. */
20838 bool m_currently_recording_lines
= false;
20840 /* The last line number that was recorded, used to coalesce
20841 consecutive entries for the same line. This can happen, for
20842 example, when discriminators are present. PR 17276. */
20843 unsigned int m_last_line
= 0;
20844 bool m_line_has_non_zero_discriminator
= false;
20848 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
20850 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
20851 / m_line_header
->maximum_ops_per_instruction
)
20852 * m_line_header
->minimum_instruction_length
);
20853 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20854 m_op_index
= ((m_op_index
+ adjust
)
20855 % m_line_header
->maximum_ops_per_instruction
);
20859 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
20861 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
20862 CORE_ADDR addr_adj
= (((m_op_index
20863 + (adj_opcode
/ m_line_header
->line_range
))
20864 / m_line_header
->maximum_ops_per_instruction
)
20865 * m_line_header
->minimum_instruction_length
);
20866 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20867 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
20868 % m_line_header
->maximum_ops_per_instruction
);
20870 int line_delta
= (m_line_header
->line_base
20871 + (adj_opcode
% m_line_header
->line_range
));
20872 advance_line (line_delta
);
20873 record_line (false);
20874 m_discriminator
= 0;
20878 lnp_state_machine::handle_set_file (file_name_index file
)
20882 const file_entry
*fe
= current_file ();
20884 dwarf2_debug_line_missing_file_complaint ();
20885 else if (m_record_lines_p
)
20887 const char *dir
= fe
->include_dir (m_line_header
);
20889 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
20890 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
20891 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
20896 lnp_state_machine::handle_const_add_pc ()
20899 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
20902 = (((m_op_index
+ adjust
)
20903 / m_line_header
->maximum_ops_per_instruction
)
20904 * m_line_header
->minimum_instruction_length
);
20906 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
20907 m_op_index
= ((m_op_index
+ adjust
)
20908 % m_line_header
->maximum_ops_per_instruction
);
20911 /* Return non-zero if we should add LINE to the line number table.
20912 LINE is the line to add, LAST_LINE is the last line that was added,
20913 LAST_SUBFILE is the subfile for LAST_LINE.
20914 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
20915 had a non-zero discriminator.
20917 We have to be careful in the presence of discriminators.
20918 E.g., for this line:
20920 for (i = 0; i < 100000; i++);
20922 clang can emit four line number entries for that one line,
20923 each with a different discriminator.
20924 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
20926 However, we want gdb to coalesce all four entries into one.
20927 Otherwise the user could stepi into the middle of the line and
20928 gdb would get confused about whether the pc really was in the
20929 middle of the line.
20931 Things are further complicated by the fact that two consecutive
20932 line number entries for the same line is a heuristic used by gcc
20933 to denote the end of the prologue. So we can't just discard duplicate
20934 entries, we have to be selective about it. The heuristic we use is
20935 that we only collapse consecutive entries for the same line if at least
20936 one of those entries has a non-zero discriminator. PR 17276.
20938 Note: Addresses in the line number state machine can never go backwards
20939 within one sequence, thus this coalescing is ok. */
20942 dwarf_record_line_p (struct dwarf2_cu
*cu
,
20943 unsigned int line
, unsigned int last_line
,
20944 int line_has_non_zero_discriminator
,
20945 struct subfile
*last_subfile
)
20947 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
20949 if (line
!= last_line
)
20951 /* Same line for the same file that we've seen already.
20952 As a last check, for pr 17276, only record the line if the line
20953 has never had a non-zero discriminator. */
20954 if (!line_has_non_zero_discriminator
)
20959 /* Use the CU's builder to record line number LINE beginning at
20960 address ADDRESS in the line table of subfile SUBFILE. */
20963 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20964 unsigned int line
, CORE_ADDR address
,
20965 struct dwarf2_cu
*cu
)
20967 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
20969 if (dwarf_line_debug
)
20971 fprintf_unfiltered (gdb_stdlog
,
20972 "Recording line %u, file %s, address %s\n",
20973 line
, lbasename (subfile
->name
),
20974 paddress (gdbarch
, address
));
20978 cu
->get_builder ()->record_line (subfile
, line
, addr
);
20981 /* Subroutine of dwarf_decode_lines_1 to simplify it.
20982 Mark the end of a set of line number records.
20983 The arguments are the same as for dwarf_record_line_1.
20984 If SUBFILE is NULL the request is ignored. */
20987 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
20988 CORE_ADDR address
, struct dwarf2_cu
*cu
)
20990 if (subfile
== NULL
)
20993 if (dwarf_line_debug
)
20995 fprintf_unfiltered (gdb_stdlog
,
20996 "Finishing current line, file %s, address %s\n",
20997 lbasename (subfile
->name
),
20998 paddress (gdbarch
, address
));
21001 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21005 lnp_state_machine::record_line (bool end_sequence
)
21007 if (dwarf_line_debug
)
21009 fprintf_unfiltered (gdb_stdlog
,
21010 "Processing actual line %u: file %u,"
21011 " address %s, is_stmt %u, discrim %u\n",
21012 m_line
, to_underlying (m_file
),
21013 paddress (m_gdbarch
, m_address
),
21014 m_is_stmt
, m_discriminator
);
21017 file_entry
*fe
= current_file ();
21020 dwarf2_debug_line_missing_file_complaint ();
21021 /* For now we ignore lines not starting on an instruction boundary.
21022 But not when processing end_sequence for compatibility with the
21023 previous version of the code. */
21024 else if (m_op_index
== 0 || end_sequence
)
21026 fe
->included_p
= 1;
21027 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21029 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21032 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21033 m_currently_recording_lines
? m_cu
: nullptr);
21038 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21039 m_line_has_non_zero_discriminator
,
21042 buildsym_compunit
*builder
= m_cu
->get_builder ();
21043 dwarf_record_line_1 (m_gdbarch
,
21044 builder
->get_current_subfile (),
21046 m_currently_recording_lines
? m_cu
: nullptr);
21048 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21049 m_last_line
= m_line
;
21055 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21056 line_header
*lh
, bool record_lines_p
)
21060 m_record_lines_p
= record_lines_p
;
21061 m_line_header
= lh
;
21063 m_currently_recording_lines
= true;
21065 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21066 was a line entry for it so that the backend has a chance to adjust it
21067 and also record it in case it needs it. This is currently used by MIPS
21068 code, cf. `mips_adjust_dwarf2_line'. */
21069 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21070 m_is_stmt
= lh
->default_is_stmt
;
21071 m_discriminator
= 0;
21075 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21076 const gdb_byte
*line_ptr
,
21077 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21079 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21080 the pc range of the CU. However, we restrict the test to only ADDRESS
21081 values of zero to preserve GDB's previous behaviour which is to handle
21082 the specific case of a function being GC'd by the linker. */
21084 if (address
== 0 && address
< unrelocated_lowpc
)
21086 /* This line table is for a function which has been
21087 GCd by the linker. Ignore it. PR gdb/12528 */
21089 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21090 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21092 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21093 line_offset
, objfile_name (objfile
));
21094 m_currently_recording_lines
= false;
21095 /* Note: m_currently_recording_lines is left as false until we see
21096 DW_LNE_end_sequence. */
21100 /* Subroutine of dwarf_decode_lines to simplify it.
21101 Process the line number information in LH.
21102 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21103 program in order to set included_p for every referenced header. */
21106 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21107 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21109 const gdb_byte
*line_ptr
, *extended_end
;
21110 const gdb_byte
*line_end
;
21111 unsigned int bytes_read
, extended_len
;
21112 unsigned char op_code
, extended_op
;
21113 CORE_ADDR baseaddr
;
21114 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21115 bfd
*abfd
= objfile
->obfd
;
21116 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21117 /* True if we're recording line info (as opposed to building partial
21118 symtabs and just interested in finding include files mentioned by
21119 the line number program). */
21120 bool record_lines_p
= !decode_for_pst_p
;
21122 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21124 line_ptr
= lh
->statement_program_start
;
21125 line_end
= lh
->statement_program_end
;
21127 /* Read the statement sequences until there's nothing left. */
21128 while (line_ptr
< line_end
)
21130 /* The DWARF line number program state machine. Reset the state
21131 machine at the start of each sequence. */
21132 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21133 bool end_sequence
= false;
21135 if (record_lines_p
)
21137 /* Start a subfile for the current file of the state
21139 const file_entry
*fe
= state_machine
.current_file ();
21142 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21145 /* Decode the table. */
21146 while (line_ptr
< line_end
&& !end_sequence
)
21148 op_code
= read_1_byte (abfd
, line_ptr
);
21151 if (op_code
>= lh
->opcode_base
)
21153 /* Special opcode. */
21154 state_machine
.handle_special_opcode (op_code
);
21156 else switch (op_code
)
21158 case DW_LNS_extended_op
:
21159 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21161 line_ptr
+= bytes_read
;
21162 extended_end
= line_ptr
+ extended_len
;
21163 extended_op
= read_1_byte (abfd
, line_ptr
);
21165 switch (extended_op
)
21167 case DW_LNE_end_sequence
:
21168 state_machine
.handle_end_sequence ();
21169 end_sequence
= true;
21171 case DW_LNE_set_address
:
21174 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21175 line_ptr
+= bytes_read
;
21177 state_machine
.check_line_address (cu
, line_ptr
,
21178 lowpc
- baseaddr
, address
);
21179 state_machine
.handle_set_address (baseaddr
, address
);
21182 case DW_LNE_define_file
:
21184 const char *cur_file
;
21185 unsigned int mod_time
, length
;
21188 cur_file
= read_direct_string (abfd
, line_ptr
,
21190 line_ptr
+= bytes_read
;
21191 dindex
= (dir_index
)
21192 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21193 line_ptr
+= bytes_read
;
21195 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21196 line_ptr
+= bytes_read
;
21198 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21199 line_ptr
+= bytes_read
;
21200 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21203 case DW_LNE_set_discriminator
:
21205 /* The discriminator is not interesting to the
21206 debugger; just ignore it. We still need to
21207 check its value though:
21208 if there are consecutive entries for the same
21209 (non-prologue) line we want to coalesce them.
21212 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21213 line_ptr
+= bytes_read
;
21215 state_machine
.handle_set_discriminator (discr
);
21219 complaint (_("mangled .debug_line section"));
21222 /* Make sure that we parsed the extended op correctly. If e.g.
21223 we expected a different address size than the producer used,
21224 we may have read the wrong number of bytes. */
21225 if (line_ptr
!= extended_end
)
21227 complaint (_("mangled .debug_line section"));
21232 state_machine
.handle_copy ();
21234 case DW_LNS_advance_pc
:
21237 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21238 line_ptr
+= bytes_read
;
21240 state_machine
.handle_advance_pc (adjust
);
21243 case DW_LNS_advance_line
:
21246 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21247 line_ptr
+= bytes_read
;
21249 state_machine
.handle_advance_line (line_delta
);
21252 case DW_LNS_set_file
:
21254 file_name_index file
21255 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21257 line_ptr
+= bytes_read
;
21259 state_machine
.handle_set_file (file
);
21262 case DW_LNS_set_column
:
21263 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21264 line_ptr
+= bytes_read
;
21266 case DW_LNS_negate_stmt
:
21267 state_machine
.handle_negate_stmt ();
21269 case DW_LNS_set_basic_block
:
21271 /* Add to the address register of the state machine the
21272 address increment value corresponding to special opcode
21273 255. I.e., this value is scaled by the minimum
21274 instruction length since special opcode 255 would have
21275 scaled the increment. */
21276 case DW_LNS_const_add_pc
:
21277 state_machine
.handle_const_add_pc ();
21279 case DW_LNS_fixed_advance_pc
:
21281 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21284 state_machine
.handle_fixed_advance_pc (addr_adj
);
21289 /* Unknown standard opcode, ignore it. */
21292 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21294 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21295 line_ptr
+= bytes_read
;
21302 dwarf2_debug_line_missing_end_sequence_complaint ();
21304 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21305 in which case we still finish recording the last line). */
21306 state_machine
.record_line (true);
21310 /* Decode the Line Number Program (LNP) for the given line_header
21311 structure and CU. The actual information extracted and the type
21312 of structures created from the LNP depends on the value of PST.
21314 1. If PST is NULL, then this procedure uses the data from the program
21315 to create all necessary symbol tables, and their linetables.
21317 2. If PST is not NULL, this procedure reads the program to determine
21318 the list of files included by the unit represented by PST, and
21319 builds all the associated partial symbol tables.
21321 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21322 It is used for relative paths in the line table.
21323 NOTE: When processing partial symtabs (pst != NULL),
21324 comp_dir == pst->dirname.
21326 NOTE: It is important that psymtabs have the same file name (via strcmp)
21327 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21328 symtab we don't use it in the name of the psymtabs we create.
21329 E.g. expand_line_sal requires this when finding psymtabs to expand.
21330 A good testcase for this is mb-inline.exp.
21332 LOWPC is the lowest address in CU (or 0 if not known).
21334 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21335 for its PC<->lines mapping information. Otherwise only the filename
21336 table is read in. */
21339 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21340 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21341 CORE_ADDR lowpc
, int decode_mapping
)
21343 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21344 const int decode_for_pst_p
= (pst
!= NULL
);
21346 if (decode_mapping
)
21347 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21349 if (decode_for_pst_p
)
21353 /* Now that we're done scanning the Line Header Program, we can
21354 create the psymtab of each included file. */
21355 for (file_index
= 0; file_index
< lh
->file_names
.size (); file_index
++)
21356 if (lh
->file_names
[file_index
].included_p
== 1)
21358 gdb::unique_xmalloc_ptr
<char> name_holder
;
21359 const char *include_name
=
21360 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
,
21362 if (include_name
!= NULL
)
21363 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21368 /* Make sure a symtab is created for every file, even files
21369 which contain only variables (i.e. no code with associated
21371 buildsym_compunit
*builder
= cu
->get_builder ();
21372 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21375 for (i
= 0; i
< lh
->file_names
.size (); i
++)
21377 file_entry
&fe
= lh
->file_names
[i
];
21379 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21381 if (builder
->get_current_subfile ()->symtab
== NULL
)
21383 builder
->get_current_subfile ()->symtab
21384 = allocate_symtab (cust
,
21385 builder
->get_current_subfile ()->name
);
21387 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21392 /* Start a subfile for DWARF. FILENAME is the name of the file and
21393 DIRNAME the name of the source directory which contains FILENAME
21394 or NULL if not known.
21395 This routine tries to keep line numbers from identical absolute and
21396 relative file names in a common subfile.
21398 Using the `list' example from the GDB testsuite, which resides in
21399 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21400 of /srcdir/list0.c yields the following debugging information for list0.c:
21402 DW_AT_name: /srcdir/list0.c
21403 DW_AT_comp_dir: /compdir
21404 files.files[0].name: list0.h
21405 files.files[0].dir: /srcdir
21406 files.files[1].name: list0.c
21407 files.files[1].dir: /srcdir
21409 The line number information for list0.c has to end up in a single
21410 subfile, so that `break /srcdir/list0.c:1' works as expected.
21411 start_subfile will ensure that this happens provided that we pass the
21412 concatenation of files.files[1].dir and files.files[1].name as the
21416 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21417 const char *dirname
)
21421 /* In order not to lose the line information directory,
21422 we concatenate it to the filename when it makes sense.
21423 Note that the Dwarf3 standard says (speaking of filenames in line
21424 information): ``The directory index is ignored for file names
21425 that represent full path names''. Thus ignoring dirname in the
21426 `else' branch below isn't an issue. */
21428 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21430 copy
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
21434 cu
->get_builder ()->start_subfile (filename
);
21440 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21441 buildsym_compunit constructor. */
21443 struct compunit_symtab
*
21444 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21447 gdb_assert (m_builder
== nullptr);
21449 m_builder
.reset (new struct buildsym_compunit
21450 (per_cu
->dwarf2_per_objfile
->objfile
,
21451 name
, comp_dir
, language
, low_pc
));
21453 list_in_scope
= get_builder ()->get_file_symbols ();
21455 get_builder ()->record_debugformat ("DWARF 2");
21456 get_builder ()->record_producer (producer
);
21458 processing_has_namespace_info
= false;
21460 return get_builder ()->get_compunit_symtab ();
21464 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21465 struct dwarf2_cu
*cu
)
21467 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21468 struct comp_unit_head
*cu_header
= &cu
->header
;
21470 /* NOTE drow/2003-01-30: There used to be a comment and some special
21471 code here to turn a symbol with DW_AT_external and a
21472 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21473 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21474 with some versions of binutils) where shared libraries could have
21475 relocations against symbols in their debug information - the
21476 minimal symbol would have the right address, but the debug info
21477 would not. It's no longer necessary, because we will explicitly
21478 apply relocations when we read in the debug information now. */
21480 /* A DW_AT_location attribute with no contents indicates that a
21481 variable has been optimized away. */
21482 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21484 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21488 /* Handle one degenerate form of location expression specially, to
21489 preserve GDB's previous behavior when section offsets are
21490 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21491 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21493 if (attr_form_is_block (attr
)
21494 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21495 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21496 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21497 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21498 && (DW_BLOCK (attr
)->size
21499 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21501 unsigned int dummy
;
21503 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21504 SET_SYMBOL_VALUE_ADDRESS (sym
,
21505 read_address (objfile
->obfd
,
21506 DW_BLOCK (attr
)->data
+ 1,
21509 SET_SYMBOL_VALUE_ADDRESS
21510 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21512 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21513 fixup_symbol_section (sym
, objfile
);
21514 SET_SYMBOL_VALUE_ADDRESS (sym
,
21515 SYMBOL_VALUE_ADDRESS (sym
)
21516 + ANOFFSET (objfile
->section_offsets
,
21517 SYMBOL_SECTION (sym
)));
21521 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21522 expression evaluator, and use LOC_COMPUTED only when necessary
21523 (i.e. when the value of a register or memory location is
21524 referenced, or a thread-local block, etc.). Then again, it might
21525 not be worthwhile. I'm assuming that it isn't unless performance
21526 or memory numbers show me otherwise. */
21528 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21530 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21531 cu
->has_loclist
= true;
21534 /* Given a pointer to a DWARF information entry, figure out if we need
21535 to make a symbol table entry for it, and if so, create a new entry
21536 and return a pointer to it.
21537 If TYPE is NULL, determine symbol type from the die, otherwise
21538 used the passed type.
21539 If SPACE is not NULL, use it to hold the new symbol. If it is
21540 NULL, allocate a new symbol on the objfile's obstack. */
21542 static struct symbol
*
21543 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21544 struct symbol
*space
)
21546 struct dwarf2_per_objfile
*dwarf2_per_objfile
21547 = cu
->per_cu
->dwarf2_per_objfile
;
21548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21549 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21550 struct symbol
*sym
= NULL
;
21552 struct attribute
*attr
= NULL
;
21553 struct attribute
*attr2
= NULL
;
21554 CORE_ADDR baseaddr
;
21555 struct pending
**list_to_add
= NULL
;
21557 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21559 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
21561 name
= dwarf2_name (die
, cu
);
21564 const char *linkagename
;
21565 int suppress_add
= 0;
21570 sym
= allocate_symbol (objfile
);
21571 OBJSTAT (objfile
, n_syms
++);
21573 /* Cache this symbol's name and the name's demangled form (if any). */
21574 SYMBOL_SET_LANGUAGE (sym
, cu
->language
, &objfile
->objfile_obstack
);
21575 linkagename
= dwarf2_physname (name
, die
, cu
);
21576 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
21578 /* Fortran does not have mangling standard and the mangling does differ
21579 between gfortran, iFort etc. */
21580 if (cu
->language
== language_fortran
21581 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
21582 symbol_set_demangled_name (&(sym
->ginfo
),
21583 dwarf2_full_name (name
, die
, cu
),
21586 /* Default assumptions.
21587 Use the passed type or decode it from the die. */
21588 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21589 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21591 SYMBOL_TYPE (sym
) = type
;
21593 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21594 attr
= dwarf2_attr (die
,
21595 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21599 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21602 attr
= dwarf2_attr (die
,
21603 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21607 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21608 struct file_entry
*fe
;
21610 if (cu
->line_header
!= NULL
)
21611 fe
= cu
->line_header
->file_name_at (file_index
);
21616 complaint (_("file index out of range"));
21618 symbol_set_symtab (sym
, fe
->symtab
);
21624 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21629 addr
= attr_value_as_address (attr
);
21630 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21631 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21633 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21634 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21635 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21636 add_symbol_to_list (sym
, cu
->list_in_scope
);
21638 case DW_TAG_subprogram
:
21639 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21641 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21642 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21643 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21644 || cu
->language
== language_ada
21645 || cu
->language
== language_fortran
)
21647 /* Subprograms marked external are stored as a global symbol.
21648 Ada and Fortran subprograms, whether marked external or
21649 not, are always stored as a global symbol, because we want
21650 to be able to access them globally. For instance, we want
21651 to be able to break on a nested subprogram without having
21652 to specify the context. */
21653 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21657 list_to_add
= cu
->list_in_scope
;
21660 case DW_TAG_inlined_subroutine
:
21661 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21663 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21664 SYMBOL_INLINED (sym
) = 1;
21665 list_to_add
= cu
->list_in_scope
;
21667 case DW_TAG_template_value_param
:
21669 /* Fall through. */
21670 case DW_TAG_constant
:
21671 case DW_TAG_variable
:
21672 case DW_TAG_member
:
21673 /* Compilation with minimal debug info may result in
21674 variables with missing type entries. Change the
21675 misleading `void' type to something sensible. */
21676 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21677 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21679 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21680 /* In the case of DW_TAG_member, we should only be called for
21681 static const members. */
21682 if (die
->tag
== DW_TAG_member
)
21684 /* dwarf2_add_field uses die_is_declaration,
21685 so we do the same. */
21686 gdb_assert (die_is_declaration (die
, cu
));
21691 dwarf2_const_value (attr
, sym
, cu
);
21692 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21695 if (attr2
&& (DW_UNSND (attr2
) != 0))
21696 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21698 list_to_add
= cu
->list_in_scope
;
21702 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21705 var_decode_location (attr
, sym
, cu
);
21706 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21708 /* Fortran explicitly imports any global symbols to the local
21709 scope by DW_TAG_common_block. */
21710 if (cu
->language
== language_fortran
&& die
->parent
21711 && die
->parent
->tag
== DW_TAG_common_block
)
21714 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21715 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21716 && !dwarf2_per_objfile
->has_section_at_zero
)
21718 /* When a static variable is eliminated by the linker,
21719 the corresponding debug information is not stripped
21720 out, but the variable address is set to null;
21721 do not add such variables into symbol table. */
21723 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21725 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21726 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21727 && dwarf2_per_objfile
->can_copy
)
21729 /* A global static variable might be subject to
21730 copy relocation. We first check for a local
21731 minsym, though, because maybe the symbol was
21732 marked hidden, in which case this would not
21734 bound_minimal_symbol found
21735 = (lookup_minimal_symbol_linkage
21736 (SYMBOL_LINKAGE_NAME (sym
), objfile
));
21737 if (found
.minsym
!= nullptr)
21738 sym
->maybe_copied
= 1;
21741 /* A variable with DW_AT_external is never static,
21742 but it may be block-scoped. */
21744 = ((cu
->list_in_scope
21745 == cu
->get_builder ()->get_file_symbols ())
21746 ? cu
->get_builder ()->get_global_symbols ()
21747 : cu
->list_in_scope
);
21750 list_to_add
= cu
->list_in_scope
;
21754 /* We do not know the address of this symbol.
21755 If it is an external symbol and we have type information
21756 for it, enter the symbol as a LOC_UNRESOLVED symbol.
21757 The address of the variable will then be determined from
21758 the minimal symbol table whenever the variable is
21760 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21762 /* Fortran explicitly imports any global symbols to the local
21763 scope by DW_TAG_common_block. */
21764 if (cu
->language
== language_fortran
&& die
->parent
21765 && die
->parent
->tag
== DW_TAG_common_block
)
21767 /* SYMBOL_CLASS doesn't matter here because
21768 read_common_block is going to reset it. */
21770 list_to_add
= cu
->list_in_scope
;
21772 else if (attr2
&& (DW_UNSND (attr2
) != 0)
21773 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
21775 /* A variable with DW_AT_external is never static, but it
21776 may be block-scoped. */
21778 = ((cu
->list_in_scope
21779 == cu
->get_builder ()->get_file_symbols ())
21780 ? cu
->get_builder ()->get_global_symbols ()
21781 : cu
->list_in_scope
);
21783 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
21785 else if (!die_is_declaration (die
, cu
))
21787 /* Use the default LOC_OPTIMIZED_OUT class. */
21788 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
21790 list_to_add
= cu
->list_in_scope
;
21794 case DW_TAG_formal_parameter
:
21796 /* If we are inside a function, mark this as an argument. If
21797 not, we might be looking at an argument to an inlined function
21798 when we do not have enough information to show inlined frames;
21799 pretend it's a local variable in that case so that the user can
21801 struct context_stack
*curr
21802 = cu
->get_builder ()->get_current_context_stack ();
21803 if (curr
!= nullptr && curr
->name
!= nullptr)
21804 SYMBOL_IS_ARGUMENT (sym
) = 1;
21805 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21808 var_decode_location (attr
, sym
, cu
);
21810 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21813 dwarf2_const_value (attr
, sym
, cu
);
21816 list_to_add
= cu
->list_in_scope
;
21819 case DW_TAG_unspecified_parameters
:
21820 /* From varargs functions; gdb doesn't seem to have any
21821 interest in this information, so just ignore it for now.
21824 case DW_TAG_template_type_param
:
21826 /* Fall through. */
21827 case DW_TAG_class_type
:
21828 case DW_TAG_interface_type
:
21829 case DW_TAG_structure_type
:
21830 case DW_TAG_union_type
:
21831 case DW_TAG_set_type
:
21832 case DW_TAG_enumeration_type
:
21833 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21834 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
21837 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
21838 really ever be static objects: otherwise, if you try
21839 to, say, break of a class's method and you're in a file
21840 which doesn't mention that class, it won't work unless
21841 the check for all static symbols in lookup_symbol_aux
21842 saves you. See the OtherFileClass tests in
21843 gdb.c++/namespace.exp. */
21847 buildsym_compunit
*builder
= cu
->get_builder ();
21849 = (cu
->list_in_scope
== builder
->get_file_symbols ()
21850 && cu
->language
== language_cplus
21851 ? builder
->get_global_symbols ()
21852 : cu
->list_in_scope
);
21854 /* The semantics of C++ state that "struct foo {
21855 ... }" also defines a typedef for "foo". */
21856 if (cu
->language
== language_cplus
21857 || cu
->language
== language_ada
21858 || cu
->language
== language_d
21859 || cu
->language
== language_rust
)
21861 /* The symbol's name is already allocated along
21862 with this objfile, so we don't need to
21863 duplicate it for the type. */
21864 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
21865 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
21870 case DW_TAG_typedef
:
21871 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21872 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21873 list_to_add
= cu
->list_in_scope
;
21875 case DW_TAG_base_type
:
21876 case DW_TAG_subrange_type
:
21877 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21878 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21879 list_to_add
= cu
->list_in_scope
;
21881 case DW_TAG_enumerator
:
21882 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21885 dwarf2_const_value (attr
, sym
, cu
);
21888 /* NOTE: carlton/2003-11-10: See comment above in the
21889 DW_TAG_class_type, etc. block. */
21892 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
21893 && cu
->language
== language_cplus
21894 ? cu
->get_builder ()->get_global_symbols ()
21895 : cu
->list_in_scope
);
21898 case DW_TAG_imported_declaration
:
21899 case DW_TAG_namespace
:
21900 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21901 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21903 case DW_TAG_module
:
21904 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
21905 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
21906 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21908 case DW_TAG_common_block
:
21909 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
21910 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
21911 add_symbol_to_list (sym
, cu
->list_in_scope
);
21914 /* Not a tag we recognize. Hopefully we aren't processing
21915 trash data, but since we must specifically ignore things
21916 we don't recognize, there is nothing else we should do at
21918 complaint (_("unsupported tag: '%s'"),
21919 dwarf_tag_name (die
->tag
));
21925 sym
->hash_next
= objfile
->template_symbols
;
21926 objfile
->template_symbols
= sym
;
21927 list_to_add
= NULL
;
21930 if (list_to_add
!= NULL
)
21931 add_symbol_to_list (sym
, list_to_add
);
21933 /* For the benefit of old versions of GCC, check for anonymous
21934 namespaces based on the demangled name. */
21935 if (!cu
->processing_has_namespace_info
21936 && cu
->language
== language_cplus
)
21937 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
21942 /* Given an attr with a DW_FORM_dataN value in host byte order,
21943 zero-extend it as appropriate for the symbol's type. The DWARF
21944 standard (v4) is not entirely clear about the meaning of using
21945 DW_FORM_dataN for a constant with a signed type, where the type is
21946 wider than the data. The conclusion of a discussion on the DWARF
21947 list was that this is unspecified. We choose to always zero-extend
21948 because that is the interpretation long in use by GCC. */
21951 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
21952 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
21954 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21955 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
21956 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
21957 LONGEST l
= DW_UNSND (attr
);
21959 if (bits
< sizeof (*value
) * 8)
21961 l
&= ((LONGEST
) 1 << bits
) - 1;
21964 else if (bits
== sizeof (*value
) * 8)
21968 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
21969 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
21976 /* Read a constant value from an attribute. Either set *VALUE, or if
21977 the value does not fit in *VALUE, set *BYTES - either already
21978 allocated on the objfile obstack, or newly allocated on OBSTACK,
21979 or, set *BATON, if we translated the constant to a location
21983 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
21984 const char *name
, struct obstack
*obstack
,
21985 struct dwarf2_cu
*cu
,
21986 LONGEST
*value
, const gdb_byte
**bytes
,
21987 struct dwarf2_locexpr_baton
**baton
)
21989 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21990 struct comp_unit_head
*cu_header
= &cu
->header
;
21991 struct dwarf_block
*blk
;
21992 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
21993 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
21999 switch (attr
->form
)
22002 case DW_FORM_addrx
:
22003 case DW_FORM_GNU_addr_index
:
22007 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22008 dwarf2_const_value_length_mismatch_complaint (name
,
22009 cu_header
->addr_size
,
22010 TYPE_LENGTH (type
));
22011 /* Symbols of this form are reasonably rare, so we just
22012 piggyback on the existing location code rather than writing
22013 a new implementation of symbol_computed_ops. */
22014 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22015 (*baton
)->per_cu
= cu
->per_cu
;
22016 gdb_assert ((*baton
)->per_cu
);
22018 (*baton
)->size
= 2 + cu_header
->addr_size
;
22019 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22020 (*baton
)->data
= data
;
22022 data
[0] = DW_OP_addr
;
22023 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22024 byte_order
, DW_ADDR (attr
));
22025 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22028 case DW_FORM_string
:
22031 case DW_FORM_GNU_str_index
:
22032 case DW_FORM_GNU_strp_alt
:
22033 /* DW_STRING is already allocated on the objfile obstack, point
22035 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22037 case DW_FORM_block1
:
22038 case DW_FORM_block2
:
22039 case DW_FORM_block4
:
22040 case DW_FORM_block
:
22041 case DW_FORM_exprloc
:
22042 case DW_FORM_data16
:
22043 blk
= DW_BLOCK (attr
);
22044 if (TYPE_LENGTH (type
) != blk
->size
)
22045 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22046 TYPE_LENGTH (type
));
22047 *bytes
= blk
->data
;
22050 /* The DW_AT_const_value attributes are supposed to carry the
22051 symbol's value "represented as it would be on the target
22052 architecture." By the time we get here, it's already been
22053 converted to host endianness, so we just need to sign- or
22054 zero-extend it as appropriate. */
22055 case DW_FORM_data1
:
22056 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22058 case DW_FORM_data2
:
22059 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22061 case DW_FORM_data4
:
22062 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22064 case DW_FORM_data8
:
22065 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22068 case DW_FORM_sdata
:
22069 case DW_FORM_implicit_const
:
22070 *value
= DW_SND (attr
);
22073 case DW_FORM_udata
:
22074 *value
= DW_UNSND (attr
);
22078 complaint (_("unsupported const value attribute form: '%s'"),
22079 dwarf_form_name (attr
->form
));
22086 /* Copy constant value from an attribute to a symbol. */
22089 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22090 struct dwarf2_cu
*cu
)
22092 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22094 const gdb_byte
*bytes
;
22095 struct dwarf2_locexpr_baton
*baton
;
22097 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22098 SYMBOL_PRINT_NAME (sym
),
22099 &objfile
->objfile_obstack
, cu
,
22100 &value
, &bytes
, &baton
);
22104 SYMBOL_LOCATION_BATON (sym
) = baton
;
22105 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22107 else if (bytes
!= NULL
)
22109 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22110 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22114 SYMBOL_VALUE (sym
) = value
;
22115 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22119 /* Return the type of the die in question using its DW_AT_type attribute. */
22121 static struct type
*
22122 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22124 struct attribute
*type_attr
;
22126 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22129 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22130 /* A missing DW_AT_type represents a void type. */
22131 return objfile_type (objfile
)->builtin_void
;
22134 return lookup_die_type (die
, type_attr
, cu
);
22137 /* True iff CU's producer generates GNAT Ada auxiliary information
22138 that allows to find parallel types through that information instead
22139 of having to do expensive parallel lookups by type name. */
22142 need_gnat_info (struct dwarf2_cu
*cu
)
22144 /* Assume that the Ada compiler was GNAT, which always produces
22145 the auxiliary information. */
22146 return (cu
->language
== language_ada
);
22149 /* Return the auxiliary type of the die in question using its
22150 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22151 attribute is not present. */
22153 static struct type
*
22154 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22156 struct attribute
*type_attr
;
22158 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22162 return lookup_die_type (die
, type_attr
, cu
);
22165 /* If DIE has a descriptive_type attribute, then set the TYPE's
22166 descriptive type accordingly. */
22169 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22170 struct dwarf2_cu
*cu
)
22172 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22174 if (descriptive_type
)
22176 ALLOCATE_GNAT_AUX_TYPE (type
);
22177 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22181 /* Return the containing type of the die in question using its
22182 DW_AT_containing_type attribute. */
22184 static struct type
*
22185 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22187 struct attribute
*type_attr
;
22188 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22190 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22192 error (_("Dwarf Error: Problem turning containing type into gdb type "
22193 "[in module %s]"), objfile_name (objfile
));
22195 return lookup_die_type (die
, type_attr
, cu
);
22198 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22200 static struct type
*
22201 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22203 struct dwarf2_per_objfile
*dwarf2_per_objfile
22204 = cu
->per_cu
->dwarf2_per_objfile
;
22205 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22208 std::string message
22209 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22210 objfile_name (objfile
),
22211 sect_offset_str (cu
->header
.sect_off
),
22212 sect_offset_str (die
->sect_off
));
22213 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22215 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22218 /* Look up the type of DIE in CU using its type attribute ATTR.
22219 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22220 DW_AT_containing_type.
22221 If there is no type substitute an error marker. */
22223 static struct type
*
22224 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22225 struct dwarf2_cu
*cu
)
22227 struct dwarf2_per_objfile
*dwarf2_per_objfile
22228 = cu
->per_cu
->dwarf2_per_objfile
;
22229 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22230 struct type
*this_type
;
22232 gdb_assert (attr
->name
== DW_AT_type
22233 || attr
->name
== DW_AT_GNAT_descriptive_type
22234 || attr
->name
== DW_AT_containing_type
);
22236 /* First see if we have it cached. */
22238 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22240 struct dwarf2_per_cu_data
*per_cu
;
22241 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22243 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22244 dwarf2_per_objfile
);
22245 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22247 else if (attr_form_is_ref (attr
))
22249 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22251 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22253 else if (attr
->form
== DW_FORM_ref_sig8
)
22255 ULONGEST signature
= DW_SIGNATURE (attr
);
22257 return get_signatured_type (die
, signature
, cu
);
22261 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22262 " at %s [in module %s]"),
22263 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22264 objfile_name (objfile
));
22265 return build_error_marker_type (cu
, die
);
22268 /* If not cached we need to read it in. */
22270 if (this_type
== NULL
)
22272 struct die_info
*type_die
= NULL
;
22273 struct dwarf2_cu
*type_cu
= cu
;
22275 if (attr_form_is_ref (attr
))
22276 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22277 if (type_die
== NULL
)
22278 return build_error_marker_type (cu
, die
);
22279 /* If we find the type now, it's probably because the type came
22280 from an inter-CU reference and the type's CU got expanded before
22282 this_type
= read_type_die (type_die
, type_cu
);
22285 /* If we still don't have a type use an error marker. */
22287 if (this_type
== NULL
)
22288 return build_error_marker_type (cu
, die
);
22293 /* Return the type in DIE, CU.
22294 Returns NULL for invalid types.
22296 This first does a lookup in die_type_hash,
22297 and only reads the die in if necessary.
22299 NOTE: This can be called when reading in partial or full symbols. */
22301 static struct type
*
22302 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22304 struct type
*this_type
;
22306 this_type
= get_die_type (die
, cu
);
22310 return read_type_die_1 (die
, cu
);
22313 /* Read the type in DIE, CU.
22314 Returns NULL for invalid types. */
22316 static struct type
*
22317 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22319 struct type
*this_type
= NULL
;
22323 case DW_TAG_class_type
:
22324 case DW_TAG_interface_type
:
22325 case DW_TAG_structure_type
:
22326 case DW_TAG_union_type
:
22327 this_type
= read_structure_type (die
, cu
);
22329 case DW_TAG_enumeration_type
:
22330 this_type
= read_enumeration_type (die
, cu
);
22332 case DW_TAG_subprogram
:
22333 case DW_TAG_subroutine_type
:
22334 case DW_TAG_inlined_subroutine
:
22335 this_type
= read_subroutine_type (die
, cu
);
22337 case DW_TAG_array_type
:
22338 this_type
= read_array_type (die
, cu
);
22340 case DW_TAG_set_type
:
22341 this_type
= read_set_type (die
, cu
);
22343 case DW_TAG_pointer_type
:
22344 this_type
= read_tag_pointer_type (die
, cu
);
22346 case DW_TAG_ptr_to_member_type
:
22347 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22349 case DW_TAG_reference_type
:
22350 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22352 case DW_TAG_rvalue_reference_type
:
22353 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22355 case DW_TAG_const_type
:
22356 this_type
= read_tag_const_type (die
, cu
);
22358 case DW_TAG_volatile_type
:
22359 this_type
= read_tag_volatile_type (die
, cu
);
22361 case DW_TAG_restrict_type
:
22362 this_type
= read_tag_restrict_type (die
, cu
);
22364 case DW_TAG_string_type
:
22365 this_type
= read_tag_string_type (die
, cu
);
22367 case DW_TAG_typedef
:
22368 this_type
= read_typedef (die
, cu
);
22370 case DW_TAG_subrange_type
:
22371 this_type
= read_subrange_type (die
, cu
);
22373 case DW_TAG_base_type
:
22374 this_type
= read_base_type (die
, cu
);
22376 case DW_TAG_unspecified_type
:
22377 this_type
= read_unspecified_type (die
, cu
);
22379 case DW_TAG_namespace
:
22380 this_type
= read_namespace_type (die
, cu
);
22382 case DW_TAG_module
:
22383 this_type
= read_module_type (die
, cu
);
22385 case DW_TAG_atomic_type
:
22386 this_type
= read_tag_atomic_type (die
, cu
);
22389 complaint (_("unexpected tag in read_type_die: '%s'"),
22390 dwarf_tag_name (die
->tag
));
22397 /* See if we can figure out if the class lives in a namespace. We do
22398 this by looking for a member function; its demangled name will
22399 contain namespace info, if there is any.
22400 Return the computed name or NULL.
22401 Space for the result is allocated on the objfile's obstack.
22402 This is the full-die version of guess_partial_die_structure_name.
22403 In this case we know DIE has no useful parent. */
22406 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22408 struct die_info
*spec_die
;
22409 struct dwarf2_cu
*spec_cu
;
22410 struct die_info
*child
;
22411 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22414 spec_die
= die_specification (die
, &spec_cu
);
22415 if (spec_die
!= NULL
)
22421 for (child
= die
->child
;
22423 child
= child
->sibling
)
22425 if (child
->tag
== DW_TAG_subprogram
)
22427 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22429 if (linkage_name
!= NULL
)
22432 = language_class_name_from_physname (cu
->language_defn
,
22436 if (actual_name
!= NULL
)
22438 const char *die_name
= dwarf2_name (die
, cu
);
22440 if (die_name
!= NULL
22441 && strcmp (die_name
, actual_name
) != 0)
22443 /* Strip off the class name from the full name.
22444 We want the prefix. */
22445 int die_name_len
= strlen (die_name
);
22446 int actual_name_len
= strlen (actual_name
);
22448 /* Test for '::' as a sanity check. */
22449 if (actual_name_len
> die_name_len
+ 2
22450 && actual_name
[actual_name_len
22451 - die_name_len
- 1] == ':')
22452 name
= obstack_strndup (
22453 &objfile
->per_bfd
->storage_obstack
,
22454 actual_name
, actual_name_len
- die_name_len
- 2);
22457 xfree (actual_name
);
22466 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22467 prefix part in such case. See
22468 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22470 static const char *
22471 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22473 struct attribute
*attr
;
22476 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22477 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22480 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22483 attr
= dw2_linkage_name_attr (die
, cu
);
22484 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22487 /* dwarf2_name had to be already called. */
22488 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22490 /* Strip the base name, keep any leading namespaces/classes. */
22491 base
= strrchr (DW_STRING (attr
), ':');
22492 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22495 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22496 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22498 &base
[-1] - DW_STRING (attr
));
22501 /* Return the name of the namespace/class that DIE is defined within,
22502 or "" if we can't tell. The caller should not xfree the result.
22504 For example, if we're within the method foo() in the following
22514 then determine_prefix on foo's die will return "N::C". */
22516 static const char *
22517 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22519 struct dwarf2_per_objfile
*dwarf2_per_objfile
22520 = cu
->per_cu
->dwarf2_per_objfile
;
22521 struct die_info
*parent
, *spec_die
;
22522 struct dwarf2_cu
*spec_cu
;
22523 struct type
*parent_type
;
22524 const char *retval
;
22526 if (cu
->language
!= language_cplus
22527 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22528 && cu
->language
!= language_rust
)
22531 retval
= anonymous_struct_prefix (die
, cu
);
22535 /* We have to be careful in the presence of DW_AT_specification.
22536 For example, with GCC 3.4, given the code
22540 // Definition of N::foo.
22544 then we'll have a tree of DIEs like this:
22546 1: DW_TAG_compile_unit
22547 2: DW_TAG_namespace // N
22548 3: DW_TAG_subprogram // declaration of N::foo
22549 4: DW_TAG_subprogram // definition of N::foo
22550 DW_AT_specification // refers to die #3
22552 Thus, when processing die #4, we have to pretend that we're in
22553 the context of its DW_AT_specification, namely the contex of die
22556 spec_die
= die_specification (die
, &spec_cu
);
22557 if (spec_die
== NULL
)
22558 parent
= die
->parent
;
22561 parent
= spec_die
->parent
;
22565 if (parent
== NULL
)
22567 else if (parent
->building_fullname
)
22570 const char *parent_name
;
22572 /* It has been seen on RealView 2.2 built binaries,
22573 DW_TAG_template_type_param types actually _defined_ as
22574 children of the parent class:
22577 template class <class Enum> Class{};
22578 Class<enum E> class_e;
22580 1: DW_TAG_class_type (Class)
22581 2: DW_TAG_enumeration_type (E)
22582 3: DW_TAG_enumerator (enum1:0)
22583 3: DW_TAG_enumerator (enum2:1)
22585 2: DW_TAG_template_type_param
22586 DW_AT_type DW_FORM_ref_udata (E)
22588 Besides being broken debug info, it can put GDB into an
22589 infinite loop. Consider:
22591 When we're building the full name for Class<E>, we'll start
22592 at Class, and go look over its template type parameters,
22593 finding E. We'll then try to build the full name of E, and
22594 reach here. We're now trying to build the full name of E,
22595 and look over the parent DIE for containing scope. In the
22596 broken case, if we followed the parent DIE of E, we'd again
22597 find Class, and once again go look at its template type
22598 arguments, etc., etc. Simply don't consider such parent die
22599 as source-level parent of this die (it can't be, the language
22600 doesn't allow it), and break the loop here. */
22601 name
= dwarf2_name (die
, cu
);
22602 parent_name
= dwarf2_name (parent
, cu
);
22603 complaint (_("template param type '%s' defined within parent '%s'"),
22604 name
? name
: "<unknown>",
22605 parent_name
? parent_name
: "<unknown>");
22609 switch (parent
->tag
)
22611 case DW_TAG_namespace
:
22612 parent_type
= read_type_die (parent
, cu
);
22613 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22614 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22615 Work around this problem here. */
22616 if (cu
->language
== language_cplus
22617 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22619 /* We give a name to even anonymous namespaces. */
22620 return TYPE_NAME (parent_type
);
22621 case DW_TAG_class_type
:
22622 case DW_TAG_interface_type
:
22623 case DW_TAG_structure_type
:
22624 case DW_TAG_union_type
:
22625 case DW_TAG_module
:
22626 parent_type
= read_type_die (parent
, cu
);
22627 if (TYPE_NAME (parent_type
) != NULL
)
22628 return TYPE_NAME (parent_type
);
22630 /* An anonymous structure is only allowed non-static data
22631 members; no typedefs, no member functions, et cetera.
22632 So it does not need a prefix. */
22634 case DW_TAG_compile_unit
:
22635 case DW_TAG_partial_unit
:
22636 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22637 if (cu
->language
== language_cplus
22638 && !dwarf2_per_objfile
->types
.empty ()
22639 && die
->child
!= NULL
22640 && (die
->tag
== DW_TAG_class_type
22641 || die
->tag
== DW_TAG_structure_type
22642 || die
->tag
== DW_TAG_union_type
))
22644 char *name
= guess_full_die_structure_name (die
, cu
);
22649 case DW_TAG_subprogram
:
22650 /* Nested subroutines in Fortran get a prefix with the name
22651 of the parent's subroutine. */
22652 if (cu
->language
== language_fortran
)
22654 if ((die
->tag
== DW_TAG_subprogram
)
22655 && (dwarf2_name (parent
, cu
) != NULL
))
22656 return dwarf2_name (parent
, cu
);
22658 return determine_prefix (parent
, cu
);
22659 case DW_TAG_enumeration_type
:
22660 parent_type
= read_type_die (parent
, cu
);
22661 if (TYPE_DECLARED_CLASS (parent_type
))
22663 if (TYPE_NAME (parent_type
) != NULL
)
22664 return TYPE_NAME (parent_type
);
22667 /* Fall through. */
22669 return determine_prefix (parent
, cu
);
22673 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22674 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22675 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22676 an obconcat, otherwise allocate storage for the result. The CU argument is
22677 used to determine the language and hence, the appropriate separator. */
22679 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22682 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22683 int physname
, struct dwarf2_cu
*cu
)
22685 const char *lead
= "";
22688 if (suffix
== NULL
|| suffix
[0] == '\0'
22689 || prefix
== NULL
|| prefix
[0] == '\0')
22691 else if (cu
->language
== language_d
)
22693 /* For D, the 'main' function could be defined in any module, but it
22694 should never be prefixed. */
22695 if (strcmp (suffix
, "D main") == 0)
22703 else if (cu
->language
== language_fortran
&& physname
)
22705 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22706 DW_AT_MIPS_linkage_name is preferred and used instead. */
22714 if (prefix
== NULL
)
22716 if (suffix
== NULL
)
22723 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22725 strcpy (retval
, lead
);
22726 strcat (retval
, prefix
);
22727 strcat (retval
, sep
);
22728 strcat (retval
, suffix
);
22733 /* We have an obstack. */
22734 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
22738 /* Return sibling of die, NULL if no sibling. */
22740 static struct die_info
*
22741 sibling_die (struct die_info
*die
)
22743 return die
->sibling
;
22746 /* Get name of a die, return NULL if not found. */
22748 static const char *
22749 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
22750 struct obstack
*obstack
)
22752 if (name
&& cu
->language
== language_cplus
)
22754 std::string canon_name
= cp_canonicalize_string (name
);
22756 if (!canon_name
.empty ())
22758 if (canon_name
!= name
)
22759 name
= obstack_strdup (obstack
, canon_name
);
22766 /* Get name of a die, return NULL if not found.
22767 Anonymous namespaces are converted to their magic string. */
22769 static const char *
22770 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22772 struct attribute
*attr
;
22773 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22775 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
22776 if ((!attr
|| !DW_STRING (attr
))
22777 && die
->tag
!= DW_TAG_namespace
22778 && die
->tag
!= DW_TAG_class_type
22779 && die
->tag
!= DW_TAG_interface_type
22780 && die
->tag
!= DW_TAG_structure_type
22781 && die
->tag
!= DW_TAG_union_type
)
22786 case DW_TAG_compile_unit
:
22787 case DW_TAG_partial_unit
:
22788 /* Compilation units have a DW_AT_name that is a filename, not
22789 a source language identifier. */
22790 case DW_TAG_enumeration_type
:
22791 case DW_TAG_enumerator
:
22792 /* These tags always have simple identifiers already; no need
22793 to canonicalize them. */
22794 return DW_STRING (attr
);
22796 case DW_TAG_namespace
:
22797 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
22798 return DW_STRING (attr
);
22799 return CP_ANONYMOUS_NAMESPACE_STR
;
22801 case DW_TAG_class_type
:
22802 case DW_TAG_interface_type
:
22803 case DW_TAG_structure_type
:
22804 case DW_TAG_union_type
:
22805 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
22806 structures or unions. These were of the form "._%d" in GCC 4.1,
22807 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
22808 and GCC 4.4. We work around this problem by ignoring these. */
22809 if (attr
&& DW_STRING (attr
)
22810 && (startswith (DW_STRING (attr
), "._")
22811 || startswith (DW_STRING (attr
), "<anonymous")))
22814 /* GCC might emit a nameless typedef that has a linkage name. See
22815 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22816 if (!attr
|| DW_STRING (attr
) == NULL
)
22818 char *demangled
= NULL
;
22820 attr
= dw2_linkage_name_attr (die
, cu
);
22821 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22824 /* Avoid demangling DW_STRING (attr) the second time on a second
22825 call for the same DIE. */
22826 if (!DW_STRING_IS_CANONICAL (attr
))
22827 demangled
= gdb_demangle (DW_STRING (attr
), DMGL_TYPES
);
22833 /* FIXME: we already did this for the partial symbol... */
22835 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
22837 DW_STRING_IS_CANONICAL (attr
) = 1;
22840 /* Strip any leading namespaces/classes, keep only the base name.
22841 DW_AT_name for named DIEs does not contain the prefixes. */
22842 base
= strrchr (DW_STRING (attr
), ':');
22843 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
22846 return DW_STRING (attr
);
22855 if (!DW_STRING_IS_CANONICAL (attr
))
22858 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
22859 &objfile
->per_bfd
->storage_obstack
);
22860 DW_STRING_IS_CANONICAL (attr
) = 1;
22862 return DW_STRING (attr
);
22865 /* Return the die that this die in an extension of, or NULL if there
22866 is none. *EXT_CU is the CU containing DIE on input, and the CU
22867 containing the return value on output. */
22869 static struct die_info
*
22870 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
22872 struct attribute
*attr
;
22874 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
22878 return follow_die_ref (die
, attr
, ext_cu
);
22881 /* A convenience function that returns an "unknown" DWARF name,
22882 including the value of V. STR is the name of the entity being
22883 printed, e.g., "TAG". */
22885 static const char *
22886 dwarf_unknown (const char *str
, unsigned v
)
22888 char *cell
= get_print_cell ();
22889 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
22893 /* Convert a DIE tag into its string name. */
22895 static const char *
22896 dwarf_tag_name (unsigned tag
)
22898 const char *name
= get_DW_TAG_name (tag
);
22901 return dwarf_unknown ("TAG", tag
);
22906 /* Convert a DWARF attribute code into its string name. */
22908 static const char *
22909 dwarf_attr_name (unsigned attr
)
22913 #ifdef MIPS /* collides with DW_AT_HP_block_index */
22914 if (attr
== DW_AT_MIPS_fde
)
22915 return "DW_AT_MIPS_fde";
22917 if (attr
== DW_AT_HP_block_index
)
22918 return "DW_AT_HP_block_index";
22921 name
= get_DW_AT_name (attr
);
22924 return dwarf_unknown ("AT", attr
);
22929 /* Convert a unit type to corresponding DW_UT name. */
22931 static const char *
22932 dwarf_unit_type_name (int unit_type
) {
22936 return "DW_UT_compile (0x01)";
22938 return "DW_UT_type (0x02)";
22940 return "DW_UT_partial (0x03)";
22942 return "DW_UT_skeleton (0x04)";
22944 return "DW_UT_split_compile (0x05)";
22946 return "DW_UT_split_type (0x06)";
22948 return "DW_UT_lo_user (0x80)";
22950 return "DW_UT_hi_user (0xff)";
22956 /* Convert a DWARF value form code into its string name. */
22958 static const char *
22959 dwarf_form_name (unsigned form
)
22961 const char *name
= get_DW_FORM_name (form
);
22964 return dwarf_unknown ("FORM", form
);
22969 static const char *
22970 dwarf_bool_name (unsigned mybool
)
22978 /* Convert a DWARF type code into its string name. */
22980 static const char *
22981 dwarf_type_encoding_name (unsigned enc
)
22983 const char *name
= get_DW_ATE_name (enc
);
22986 return dwarf_unknown ("ATE", enc
);
22992 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
22996 print_spaces (indent
, f
);
22997 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
22998 dwarf_tag_name (die
->tag
), die
->abbrev
,
22999 sect_offset_str (die
->sect_off
));
23001 if (die
->parent
!= NULL
)
23003 print_spaces (indent
, f
);
23004 fprintf_unfiltered (f
, " parent at offset: %s\n",
23005 sect_offset_str (die
->parent
->sect_off
));
23008 print_spaces (indent
, f
);
23009 fprintf_unfiltered (f
, " has children: %s\n",
23010 dwarf_bool_name (die
->child
!= NULL
));
23012 print_spaces (indent
, f
);
23013 fprintf_unfiltered (f
, " attributes:\n");
23015 for (i
= 0; i
< die
->num_attrs
; ++i
)
23017 print_spaces (indent
, f
);
23018 fprintf_unfiltered (f
, " %s (%s) ",
23019 dwarf_attr_name (die
->attrs
[i
].name
),
23020 dwarf_form_name (die
->attrs
[i
].form
));
23022 switch (die
->attrs
[i
].form
)
23025 case DW_FORM_addrx
:
23026 case DW_FORM_GNU_addr_index
:
23027 fprintf_unfiltered (f
, "address: ");
23028 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23030 case DW_FORM_block2
:
23031 case DW_FORM_block4
:
23032 case DW_FORM_block
:
23033 case DW_FORM_block1
:
23034 fprintf_unfiltered (f
, "block: size %s",
23035 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23037 case DW_FORM_exprloc
:
23038 fprintf_unfiltered (f
, "expression: size %s",
23039 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23041 case DW_FORM_data16
:
23042 fprintf_unfiltered (f
, "constant of 16 bytes");
23044 case DW_FORM_ref_addr
:
23045 fprintf_unfiltered (f
, "ref address: ");
23046 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23048 case DW_FORM_GNU_ref_alt
:
23049 fprintf_unfiltered (f
, "alt ref address: ");
23050 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23056 case DW_FORM_ref_udata
:
23057 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23058 (long) (DW_UNSND (&die
->attrs
[i
])));
23060 case DW_FORM_data1
:
23061 case DW_FORM_data2
:
23062 case DW_FORM_data4
:
23063 case DW_FORM_data8
:
23064 case DW_FORM_udata
:
23065 case DW_FORM_sdata
:
23066 fprintf_unfiltered (f
, "constant: %s",
23067 pulongest (DW_UNSND (&die
->attrs
[i
])));
23069 case DW_FORM_sec_offset
:
23070 fprintf_unfiltered (f
, "section offset: %s",
23071 pulongest (DW_UNSND (&die
->attrs
[i
])));
23073 case DW_FORM_ref_sig8
:
23074 fprintf_unfiltered (f
, "signature: %s",
23075 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23077 case DW_FORM_string
:
23079 case DW_FORM_line_strp
:
23081 case DW_FORM_GNU_str_index
:
23082 case DW_FORM_GNU_strp_alt
:
23083 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23084 DW_STRING (&die
->attrs
[i
])
23085 ? DW_STRING (&die
->attrs
[i
]) : "",
23086 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23089 if (DW_UNSND (&die
->attrs
[i
]))
23090 fprintf_unfiltered (f
, "flag: TRUE");
23092 fprintf_unfiltered (f
, "flag: FALSE");
23094 case DW_FORM_flag_present
:
23095 fprintf_unfiltered (f
, "flag: TRUE");
23097 case DW_FORM_indirect
:
23098 /* The reader will have reduced the indirect form to
23099 the "base form" so this form should not occur. */
23100 fprintf_unfiltered (f
,
23101 "unexpected attribute form: DW_FORM_indirect");
23103 case DW_FORM_implicit_const
:
23104 fprintf_unfiltered (f
, "constant: %s",
23105 plongest (DW_SND (&die
->attrs
[i
])));
23108 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23109 die
->attrs
[i
].form
);
23112 fprintf_unfiltered (f
, "\n");
23117 dump_die_for_error (struct die_info
*die
)
23119 dump_die_shallow (gdb_stderr
, 0, die
);
23123 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23125 int indent
= level
* 4;
23127 gdb_assert (die
!= NULL
);
23129 if (level
>= max_level
)
23132 dump_die_shallow (f
, indent
, die
);
23134 if (die
->child
!= NULL
)
23136 print_spaces (indent
, f
);
23137 fprintf_unfiltered (f
, " Children:");
23138 if (level
+ 1 < max_level
)
23140 fprintf_unfiltered (f
, "\n");
23141 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23145 fprintf_unfiltered (f
,
23146 " [not printed, max nesting level reached]\n");
23150 if (die
->sibling
!= NULL
&& level
> 0)
23152 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23156 /* This is called from the pdie macro in gdbinit.in.
23157 It's not static so gcc will keep a copy callable from gdb. */
23160 dump_die (struct die_info
*die
, int max_level
)
23162 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23166 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23170 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23171 to_underlying (die
->sect_off
),
23177 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23181 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23183 if (attr_form_is_ref (attr
))
23184 return (sect_offset
) DW_UNSND (attr
);
23186 complaint (_("unsupported die ref attribute form: '%s'"),
23187 dwarf_form_name (attr
->form
));
23191 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23192 * the value held by the attribute is not constant. */
23195 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23197 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23198 return DW_SND (attr
);
23199 else if (attr
->form
== DW_FORM_udata
23200 || attr
->form
== DW_FORM_data1
23201 || attr
->form
== DW_FORM_data2
23202 || attr
->form
== DW_FORM_data4
23203 || attr
->form
== DW_FORM_data8
)
23204 return DW_UNSND (attr
);
23207 /* For DW_FORM_data16 see attr_form_is_constant. */
23208 complaint (_("Attribute value is not a constant (%s)"),
23209 dwarf_form_name (attr
->form
));
23210 return default_value
;
23214 /* Follow reference or signature attribute ATTR of SRC_DIE.
23215 On entry *REF_CU is the CU of SRC_DIE.
23216 On exit *REF_CU is the CU of the result. */
23218 static struct die_info
*
23219 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23220 struct dwarf2_cu
**ref_cu
)
23222 struct die_info
*die
;
23224 if (attr_form_is_ref (attr
))
23225 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23226 else if (attr
->form
== DW_FORM_ref_sig8
)
23227 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23230 dump_die_for_error (src_die
);
23231 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23232 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23238 /* Follow reference OFFSET.
23239 On entry *REF_CU is the CU of the source die referencing OFFSET.
23240 On exit *REF_CU is the CU of the result.
23241 Returns NULL if OFFSET is invalid. */
23243 static struct die_info
*
23244 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23245 struct dwarf2_cu
**ref_cu
)
23247 struct die_info temp_die
;
23248 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23249 struct dwarf2_per_objfile
*dwarf2_per_objfile
23250 = cu
->per_cu
->dwarf2_per_objfile
;
23252 gdb_assert (cu
->per_cu
!= NULL
);
23256 if (cu
->per_cu
->is_debug_types
)
23258 /* .debug_types CUs cannot reference anything outside their CU.
23259 If they need to, they have to reference a signatured type via
23260 DW_FORM_ref_sig8. */
23261 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23264 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23265 || !offset_in_cu_p (&cu
->header
, sect_off
))
23267 struct dwarf2_per_cu_data
*per_cu
;
23269 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23270 dwarf2_per_objfile
);
23272 /* If necessary, add it to the queue and load its DIEs. */
23273 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23274 load_full_comp_unit (per_cu
, false, cu
->language
);
23276 target_cu
= per_cu
->cu
;
23278 else if (cu
->dies
== NULL
)
23280 /* We're loading full DIEs during partial symbol reading. */
23281 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23282 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23285 *ref_cu
= target_cu
;
23286 temp_die
.sect_off
= sect_off
;
23288 if (target_cu
!= cu
)
23289 target_cu
->ancestor
= cu
;
23291 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23293 to_underlying (sect_off
));
23296 /* Follow reference attribute ATTR of SRC_DIE.
23297 On entry *REF_CU is the CU of SRC_DIE.
23298 On exit *REF_CU is the CU of the result. */
23300 static struct die_info
*
23301 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23302 struct dwarf2_cu
**ref_cu
)
23304 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23305 struct dwarf2_cu
*cu
= *ref_cu
;
23306 struct die_info
*die
;
23308 die
= follow_die_offset (sect_off
,
23309 (attr
->form
== DW_FORM_GNU_ref_alt
23310 || cu
->per_cu
->is_dwz
),
23313 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23314 "at %s [in module %s]"),
23315 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23316 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23321 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23322 Returned value is intended for DW_OP_call*. Returned
23323 dwarf2_locexpr_baton->data has lifetime of
23324 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23326 struct dwarf2_locexpr_baton
23327 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23328 struct dwarf2_per_cu_data
*per_cu
,
23329 CORE_ADDR (*get_frame_pc
) (void *baton
),
23330 void *baton
, bool resolve_abstract_p
)
23332 struct dwarf2_cu
*cu
;
23333 struct die_info
*die
;
23334 struct attribute
*attr
;
23335 struct dwarf2_locexpr_baton retval
;
23336 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23337 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23339 if (per_cu
->cu
== NULL
)
23340 load_cu (per_cu
, false);
23344 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23345 Instead just throw an error, not much else we can do. */
23346 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23347 sect_offset_str (sect_off
), objfile_name (objfile
));
23350 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23352 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23353 sect_offset_str (sect_off
), objfile_name (objfile
));
23355 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23356 if (!attr
&& resolve_abstract_p
23357 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23358 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23360 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23362 = ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
23363 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23365 for (const auto &cand_off
23366 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23368 struct dwarf2_cu
*cand_cu
= cu
;
23369 struct die_info
*cand
23370 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23373 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23376 CORE_ADDR pc_low
, pc_high
;
23377 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23378 if (pc_low
== ((CORE_ADDR
) -1))
23380 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23381 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23382 if (!(pc_low
<= pc
&& pc
< pc_high
))
23386 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23393 /* DWARF: "If there is no such attribute, then there is no effect.".
23394 DATA is ignored if SIZE is 0. */
23396 retval
.data
= NULL
;
23399 else if (attr_form_is_section_offset (attr
))
23401 struct dwarf2_loclist_baton loclist_baton
;
23402 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23405 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23407 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23409 retval
.size
= size
;
23413 if (!attr_form_is_block (attr
))
23414 error (_("Dwarf Error: DIE at %s referenced in module %s "
23415 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23416 sect_offset_str (sect_off
), objfile_name (objfile
));
23418 retval
.data
= DW_BLOCK (attr
)->data
;
23419 retval
.size
= DW_BLOCK (attr
)->size
;
23421 retval
.per_cu
= cu
->per_cu
;
23423 age_cached_comp_units (dwarf2_per_objfile
);
23428 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23431 struct dwarf2_locexpr_baton
23432 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23433 struct dwarf2_per_cu_data
*per_cu
,
23434 CORE_ADDR (*get_frame_pc
) (void *baton
),
23437 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23439 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23442 /* Write a constant of a given type as target-ordered bytes into
23445 static const gdb_byte
*
23446 write_constant_as_bytes (struct obstack
*obstack
,
23447 enum bfd_endian byte_order
,
23454 *len
= TYPE_LENGTH (type
);
23455 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23456 store_unsigned_integer (result
, *len
, byte_order
, value
);
23461 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23462 pointer to the constant bytes and set LEN to the length of the
23463 data. If memory is needed, allocate it on OBSTACK. If the DIE
23464 does not have a DW_AT_const_value, return NULL. */
23467 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23468 struct dwarf2_per_cu_data
*per_cu
,
23469 struct obstack
*obstack
,
23472 struct dwarf2_cu
*cu
;
23473 struct die_info
*die
;
23474 struct attribute
*attr
;
23475 const gdb_byte
*result
= NULL
;
23478 enum bfd_endian byte_order
;
23479 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23481 if (per_cu
->cu
== NULL
)
23482 load_cu (per_cu
, false);
23486 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23487 Instead just throw an error, not much else we can do. */
23488 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23489 sect_offset_str (sect_off
), objfile_name (objfile
));
23492 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23494 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23495 sect_offset_str (sect_off
), objfile_name (objfile
));
23497 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23501 byte_order
= (bfd_big_endian (objfile
->obfd
)
23502 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23504 switch (attr
->form
)
23507 case DW_FORM_addrx
:
23508 case DW_FORM_GNU_addr_index
:
23512 *len
= cu
->header
.addr_size
;
23513 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23514 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23518 case DW_FORM_string
:
23521 case DW_FORM_GNU_str_index
:
23522 case DW_FORM_GNU_strp_alt
:
23523 /* DW_STRING is already allocated on the objfile obstack, point
23525 result
= (const gdb_byte
*) DW_STRING (attr
);
23526 *len
= strlen (DW_STRING (attr
));
23528 case DW_FORM_block1
:
23529 case DW_FORM_block2
:
23530 case DW_FORM_block4
:
23531 case DW_FORM_block
:
23532 case DW_FORM_exprloc
:
23533 case DW_FORM_data16
:
23534 result
= DW_BLOCK (attr
)->data
;
23535 *len
= DW_BLOCK (attr
)->size
;
23538 /* The DW_AT_const_value attributes are supposed to carry the
23539 symbol's value "represented as it would be on the target
23540 architecture." By the time we get here, it's already been
23541 converted to host endianness, so we just need to sign- or
23542 zero-extend it as appropriate. */
23543 case DW_FORM_data1
:
23544 type
= die_type (die
, cu
);
23545 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23546 if (result
== NULL
)
23547 result
= write_constant_as_bytes (obstack
, byte_order
,
23550 case DW_FORM_data2
:
23551 type
= die_type (die
, cu
);
23552 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23553 if (result
== NULL
)
23554 result
= write_constant_as_bytes (obstack
, byte_order
,
23557 case DW_FORM_data4
:
23558 type
= die_type (die
, cu
);
23559 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23560 if (result
== NULL
)
23561 result
= write_constant_as_bytes (obstack
, byte_order
,
23564 case DW_FORM_data8
:
23565 type
= die_type (die
, cu
);
23566 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23567 if (result
== NULL
)
23568 result
= write_constant_as_bytes (obstack
, byte_order
,
23572 case DW_FORM_sdata
:
23573 case DW_FORM_implicit_const
:
23574 type
= die_type (die
, cu
);
23575 result
= write_constant_as_bytes (obstack
, byte_order
,
23576 type
, DW_SND (attr
), len
);
23579 case DW_FORM_udata
:
23580 type
= die_type (die
, cu
);
23581 result
= write_constant_as_bytes (obstack
, byte_order
,
23582 type
, DW_UNSND (attr
), len
);
23586 complaint (_("unsupported const value attribute form: '%s'"),
23587 dwarf_form_name (attr
->form
));
23594 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23595 valid type for this die is found. */
23598 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23599 struct dwarf2_per_cu_data
*per_cu
)
23601 struct dwarf2_cu
*cu
;
23602 struct die_info
*die
;
23604 if (per_cu
->cu
== NULL
)
23605 load_cu (per_cu
, false);
23610 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23614 return die_type (die
, cu
);
23617 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23621 dwarf2_get_die_type (cu_offset die_offset
,
23622 struct dwarf2_per_cu_data
*per_cu
)
23624 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23625 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23628 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23629 On entry *REF_CU is the CU of SRC_DIE.
23630 On exit *REF_CU is the CU of the result.
23631 Returns NULL if the referenced DIE isn't found. */
23633 static struct die_info
*
23634 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23635 struct dwarf2_cu
**ref_cu
)
23637 struct die_info temp_die
;
23638 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23639 struct die_info
*die
;
23641 /* While it might be nice to assert sig_type->type == NULL here,
23642 we can get here for DW_AT_imported_declaration where we need
23643 the DIE not the type. */
23645 /* If necessary, add it to the queue and load its DIEs. */
23647 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23648 read_signatured_type (sig_type
);
23650 sig_cu
= sig_type
->per_cu
.cu
;
23651 gdb_assert (sig_cu
!= NULL
);
23652 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23653 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23654 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23655 to_underlying (temp_die
.sect_off
));
23658 struct dwarf2_per_objfile
*dwarf2_per_objfile
23659 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23661 /* For .gdb_index version 7 keep track of included TUs.
23662 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23663 if (dwarf2_per_objfile
->index_table
!= NULL
23664 && dwarf2_per_objfile
->index_table
->version
<= 7)
23666 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23671 sig_cu
->ancestor
= cu
;
23679 /* Follow signatured type referenced by ATTR in SRC_DIE.
23680 On entry *REF_CU is the CU of SRC_DIE.
23681 On exit *REF_CU is the CU of the result.
23682 The result is the DIE of the type.
23683 If the referenced type cannot be found an error is thrown. */
23685 static struct die_info
*
23686 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23687 struct dwarf2_cu
**ref_cu
)
23689 ULONGEST signature
= DW_SIGNATURE (attr
);
23690 struct signatured_type
*sig_type
;
23691 struct die_info
*die
;
23693 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23695 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23696 /* sig_type will be NULL if the signatured type is missing from
23698 if (sig_type
== NULL
)
23700 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23701 " from DIE at %s [in module %s]"),
23702 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23703 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23706 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23709 dump_die_for_error (src_die
);
23710 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23711 " from DIE at %s [in module %s]"),
23712 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23713 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23719 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23720 reading in and processing the type unit if necessary. */
23722 static struct type
*
23723 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23724 struct dwarf2_cu
*cu
)
23726 struct dwarf2_per_objfile
*dwarf2_per_objfile
23727 = cu
->per_cu
->dwarf2_per_objfile
;
23728 struct signatured_type
*sig_type
;
23729 struct dwarf2_cu
*type_cu
;
23730 struct die_info
*type_die
;
23733 sig_type
= lookup_signatured_type (cu
, signature
);
23734 /* sig_type will be NULL if the signatured type is missing from
23736 if (sig_type
== NULL
)
23738 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23739 " from DIE at %s [in module %s]"),
23740 hex_string (signature
), sect_offset_str (die
->sect_off
),
23741 objfile_name (dwarf2_per_objfile
->objfile
));
23742 return build_error_marker_type (cu
, die
);
23745 /* If we already know the type we're done. */
23746 if (sig_type
->type
!= NULL
)
23747 return sig_type
->type
;
23750 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
23751 if (type_die
!= NULL
)
23753 /* N.B. We need to call get_die_type to ensure only one type for this DIE
23754 is created. This is important, for example, because for c++ classes
23755 we need TYPE_NAME set which is only done by new_symbol. Blech. */
23756 type
= read_type_die (type_die
, type_cu
);
23759 complaint (_("Dwarf Error: Cannot build signatured type %s"
23760 " referenced from DIE at %s [in module %s]"),
23761 hex_string (signature
), sect_offset_str (die
->sect_off
),
23762 objfile_name (dwarf2_per_objfile
->objfile
));
23763 type
= build_error_marker_type (cu
, die
);
23768 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23769 " from DIE at %s [in module %s]"),
23770 hex_string (signature
), sect_offset_str (die
->sect_off
),
23771 objfile_name (dwarf2_per_objfile
->objfile
));
23772 type
= build_error_marker_type (cu
, die
);
23774 sig_type
->type
= type
;
23779 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
23780 reading in and processing the type unit if necessary. */
23782 static struct type
*
23783 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
23784 struct dwarf2_cu
*cu
) /* ARI: editCase function */
23786 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
23787 if (attr_form_is_ref (attr
))
23789 struct dwarf2_cu
*type_cu
= cu
;
23790 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
23792 return read_type_die (type_die
, type_cu
);
23794 else if (attr
->form
== DW_FORM_ref_sig8
)
23796 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
23800 struct dwarf2_per_objfile
*dwarf2_per_objfile
23801 = cu
->per_cu
->dwarf2_per_objfile
;
23803 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
23804 " at %s [in module %s]"),
23805 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
23806 objfile_name (dwarf2_per_objfile
->objfile
));
23807 return build_error_marker_type (cu
, die
);
23811 /* Load the DIEs associated with type unit PER_CU into memory. */
23814 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
23816 struct signatured_type
*sig_type
;
23818 /* Caller is responsible for ensuring type_unit_groups don't get here. */
23819 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
23821 /* We have the per_cu, but we need the signatured_type.
23822 Fortunately this is an easy translation. */
23823 gdb_assert (per_cu
->is_debug_types
);
23824 sig_type
= (struct signatured_type
*) per_cu
;
23826 gdb_assert (per_cu
->cu
== NULL
);
23828 read_signatured_type (sig_type
);
23830 gdb_assert (per_cu
->cu
!= NULL
);
23833 /* die_reader_func for read_signatured_type.
23834 This is identical to load_full_comp_unit_reader,
23835 but is kept separate for now. */
23838 read_signatured_type_reader (const struct die_reader_specs
*reader
,
23839 const gdb_byte
*info_ptr
,
23840 struct die_info
*comp_unit_die
,
23844 struct dwarf2_cu
*cu
= reader
->cu
;
23846 gdb_assert (cu
->die_hash
== NULL
);
23848 htab_create_alloc_ex (cu
->header
.length
/ 12,
23852 &cu
->comp_unit_obstack
,
23853 hashtab_obstack_allocate
,
23854 dummy_obstack_deallocate
);
23857 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
23858 &info_ptr
, comp_unit_die
);
23859 cu
->dies
= comp_unit_die
;
23860 /* comp_unit_die is not stored in die_hash, no need. */
23862 /* We try not to read any attributes in this function, because not
23863 all CUs needed for references have been loaded yet, and symbol
23864 table processing isn't initialized. But we have to set the CU language,
23865 or we won't be able to build types correctly.
23866 Similarly, if we do not read the producer, we can not apply
23867 producer-specific interpretation. */
23868 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
23871 /* Read in a signatured type and build its CU and DIEs.
23872 If the type is a stub for the real type in a DWO file,
23873 read in the real type from the DWO file as well. */
23876 read_signatured_type (struct signatured_type
*sig_type
)
23878 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
23880 gdb_assert (per_cu
->is_debug_types
);
23881 gdb_assert (per_cu
->cu
== NULL
);
23883 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
23884 read_signatured_type_reader
, NULL
);
23885 sig_type
->per_cu
.tu_read
= 1;
23888 /* Decode simple location descriptions.
23889 Given a pointer to a dwarf block that defines a location, compute
23890 the location and return the value.
23892 NOTE drow/2003-11-18: This function is called in two situations
23893 now: for the address of static or global variables (partial symbols
23894 only) and for offsets into structures which are expected to be
23895 (more or less) constant. The partial symbol case should go away,
23896 and only the constant case should remain. That will let this
23897 function complain more accurately. A few special modes are allowed
23898 without complaint for global variables (for instance, global
23899 register values and thread-local values).
23901 A location description containing no operations indicates that the
23902 object is optimized out. The return value is 0 for that case.
23903 FIXME drow/2003-11-16: No callers check for this case any more; soon all
23904 callers will only want a very basic result and this can become a
23907 Note that stack[0] is unused except as a default error return. */
23910 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
23912 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23914 size_t size
= blk
->size
;
23915 const gdb_byte
*data
= blk
->data
;
23916 CORE_ADDR stack
[64];
23918 unsigned int bytes_read
, unsnd
;
23924 stack
[++stacki
] = 0;
23963 stack
[++stacki
] = op
- DW_OP_lit0
;
23998 stack
[++stacki
] = op
- DW_OP_reg0
;
24000 dwarf2_complex_location_expr_complaint ();
24004 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24006 stack
[++stacki
] = unsnd
;
24008 dwarf2_complex_location_expr_complaint ();
24012 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24017 case DW_OP_const1u
:
24018 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24022 case DW_OP_const1s
:
24023 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24027 case DW_OP_const2u
:
24028 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24032 case DW_OP_const2s
:
24033 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24037 case DW_OP_const4u
:
24038 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24042 case DW_OP_const4s
:
24043 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24047 case DW_OP_const8u
:
24048 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24053 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24059 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24064 stack
[stacki
+ 1] = stack
[stacki
];
24069 stack
[stacki
- 1] += stack
[stacki
];
24073 case DW_OP_plus_uconst
:
24074 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24080 stack
[stacki
- 1] -= stack
[stacki
];
24085 /* If we're not the last op, then we definitely can't encode
24086 this using GDB's address_class enum. This is valid for partial
24087 global symbols, although the variable's address will be bogus
24090 dwarf2_complex_location_expr_complaint ();
24093 case DW_OP_GNU_push_tls_address
:
24094 case DW_OP_form_tls_address
:
24095 /* The top of the stack has the offset from the beginning
24096 of the thread control block at which the variable is located. */
24097 /* Nothing should follow this operator, so the top of stack would
24099 /* This is valid for partial global symbols, but the variable's
24100 address will be bogus in the psymtab. Make it always at least
24101 non-zero to not look as a variable garbage collected by linker
24102 which have DW_OP_addr 0. */
24104 dwarf2_complex_location_expr_complaint ();
24108 case DW_OP_GNU_uninit
:
24112 case DW_OP_GNU_addr_index
:
24113 case DW_OP_GNU_const_index
:
24114 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24121 const char *name
= get_DW_OP_name (op
);
24124 complaint (_("unsupported stack op: '%s'"),
24127 complaint (_("unsupported stack op: '%02x'"),
24131 return (stack
[stacki
]);
24134 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24135 outside of the allocated space. Also enforce minimum>0. */
24136 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24138 complaint (_("location description stack overflow"));
24144 complaint (_("location description stack underflow"));
24148 return (stack
[stacki
]);
24151 /* memory allocation interface */
24153 static struct dwarf_block
*
24154 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24156 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24159 static struct die_info
*
24160 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24162 struct die_info
*die
;
24163 size_t size
= sizeof (struct die_info
);
24166 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24168 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24169 memset (die
, 0, sizeof (struct die_info
));
24174 /* Macro support. */
24176 /* Return file name relative to the compilation directory of file number I in
24177 *LH's file name table. The result is allocated using xmalloc; the caller is
24178 responsible for freeing it. */
24181 file_file_name (int file
, struct line_header
*lh
)
24183 /* Is the file number a valid index into the line header's file name
24184 table? Remember that file numbers start with one, not zero. */
24185 if (1 <= file
&& file
<= lh
->file_names
.size ())
24187 const file_entry
&fe
= lh
->file_names
[file
- 1];
24189 if (!IS_ABSOLUTE_PATH (fe
.name
))
24191 const char *dir
= fe
.include_dir (lh
);
24193 return concat (dir
, SLASH_STRING
, fe
.name
, (char *) NULL
);
24195 return xstrdup (fe
.name
);
24199 /* The compiler produced a bogus file number. We can at least
24200 record the macro definitions made in the file, even if we
24201 won't be able to find the file by name. */
24202 char fake_name
[80];
24204 xsnprintf (fake_name
, sizeof (fake_name
),
24205 "<bad macro file number %d>", file
);
24207 complaint (_("bad file number in macro information (%d)"),
24210 return xstrdup (fake_name
);
24214 /* Return the full name of file number I in *LH's file name table.
24215 Use COMP_DIR as the name of the current directory of the
24216 compilation. The result is allocated using xmalloc; the caller is
24217 responsible for freeing it. */
24219 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24221 /* Is the file number a valid index into the line header's file name
24222 table? Remember that file numbers start with one, not zero. */
24223 if (1 <= file
&& file
<= lh
->file_names
.size ())
24225 char *relative
= file_file_name (file
, lh
);
24227 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24229 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24230 relative
, (char *) NULL
);
24233 return file_file_name (file
, lh
);
24237 static struct macro_source_file
*
24238 macro_start_file (struct dwarf2_cu
*cu
,
24239 int file
, int line
,
24240 struct macro_source_file
*current_file
,
24241 struct line_header
*lh
)
24243 /* File name relative to the compilation directory of this source file. */
24244 char *file_name
= file_file_name (file
, lh
);
24246 if (! current_file
)
24248 /* Note: We don't create a macro table for this compilation unit
24249 at all until we actually get a filename. */
24250 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24252 /* If we have no current file, then this must be the start_file
24253 directive for the compilation unit's main source file. */
24254 current_file
= macro_set_main (macro_table
, file_name
);
24255 macro_define_special (macro_table
);
24258 current_file
= macro_include (current_file
, line
, file_name
);
24262 return current_file
;
24265 static const char *
24266 consume_improper_spaces (const char *p
, const char *body
)
24270 complaint (_("macro definition contains spaces "
24271 "in formal argument list:\n`%s'"),
24283 parse_macro_definition (struct macro_source_file
*file
, int line
,
24288 /* The body string takes one of two forms. For object-like macro
24289 definitions, it should be:
24291 <macro name> " " <definition>
24293 For function-like macro definitions, it should be:
24295 <macro name> "() " <definition>
24297 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24299 Spaces may appear only where explicitly indicated, and in the
24302 The Dwarf 2 spec says that an object-like macro's name is always
24303 followed by a space, but versions of GCC around March 2002 omit
24304 the space when the macro's definition is the empty string.
24306 The Dwarf 2 spec says that there should be no spaces between the
24307 formal arguments in a function-like macro's formal argument list,
24308 but versions of GCC around March 2002 include spaces after the
24312 /* Find the extent of the macro name. The macro name is terminated
24313 by either a space or null character (for an object-like macro) or
24314 an opening paren (for a function-like macro). */
24315 for (p
= body
; *p
; p
++)
24316 if (*p
== ' ' || *p
== '(')
24319 if (*p
== ' ' || *p
== '\0')
24321 /* It's an object-like macro. */
24322 int name_len
= p
- body
;
24323 char *name
= savestring (body
, name_len
);
24324 const char *replacement
;
24327 replacement
= body
+ name_len
+ 1;
24330 dwarf2_macro_malformed_definition_complaint (body
);
24331 replacement
= body
+ name_len
;
24334 macro_define_object (file
, line
, name
, replacement
);
24338 else if (*p
== '(')
24340 /* It's a function-like macro. */
24341 char *name
= savestring (body
, p
- body
);
24344 char **argv
= XNEWVEC (char *, argv_size
);
24348 p
= consume_improper_spaces (p
, body
);
24350 /* Parse the formal argument list. */
24351 while (*p
&& *p
!= ')')
24353 /* Find the extent of the current argument name. */
24354 const char *arg_start
= p
;
24356 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24359 if (! *p
|| p
== arg_start
)
24360 dwarf2_macro_malformed_definition_complaint (body
);
24363 /* Make sure argv has room for the new argument. */
24364 if (argc
>= argv_size
)
24367 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24370 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24373 p
= consume_improper_spaces (p
, body
);
24375 /* Consume the comma, if present. */
24380 p
= consume_improper_spaces (p
, body
);
24389 /* Perfectly formed definition, no complaints. */
24390 macro_define_function (file
, line
, name
,
24391 argc
, (const char **) argv
,
24393 else if (*p
== '\0')
24395 /* Complain, but do define it. */
24396 dwarf2_macro_malformed_definition_complaint (body
);
24397 macro_define_function (file
, line
, name
,
24398 argc
, (const char **) argv
,
24402 /* Just complain. */
24403 dwarf2_macro_malformed_definition_complaint (body
);
24406 /* Just complain. */
24407 dwarf2_macro_malformed_definition_complaint (body
);
24413 for (i
= 0; i
< argc
; i
++)
24419 dwarf2_macro_malformed_definition_complaint (body
);
24422 /* Skip some bytes from BYTES according to the form given in FORM.
24423 Returns the new pointer. */
24425 static const gdb_byte
*
24426 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24427 enum dwarf_form form
,
24428 unsigned int offset_size
,
24429 struct dwarf2_section_info
*section
)
24431 unsigned int bytes_read
;
24435 case DW_FORM_data1
:
24440 case DW_FORM_data2
:
24444 case DW_FORM_data4
:
24448 case DW_FORM_data8
:
24452 case DW_FORM_data16
:
24456 case DW_FORM_string
:
24457 read_direct_string (abfd
, bytes
, &bytes_read
);
24458 bytes
+= bytes_read
;
24461 case DW_FORM_sec_offset
:
24463 case DW_FORM_GNU_strp_alt
:
24464 bytes
+= offset_size
;
24467 case DW_FORM_block
:
24468 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24469 bytes
+= bytes_read
;
24472 case DW_FORM_block1
:
24473 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24475 case DW_FORM_block2
:
24476 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24478 case DW_FORM_block4
:
24479 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24482 case DW_FORM_addrx
:
24483 case DW_FORM_sdata
:
24485 case DW_FORM_udata
:
24486 case DW_FORM_GNU_addr_index
:
24487 case DW_FORM_GNU_str_index
:
24488 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24491 dwarf2_section_buffer_overflow_complaint (section
);
24496 case DW_FORM_implicit_const
:
24501 complaint (_("invalid form 0x%x in `%s'"),
24502 form
, get_section_name (section
));
24510 /* A helper for dwarf_decode_macros that handles skipping an unknown
24511 opcode. Returns an updated pointer to the macro data buffer; or,
24512 on error, issues a complaint and returns NULL. */
24514 static const gdb_byte
*
24515 skip_unknown_opcode (unsigned int opcode
,
24516 const gdb_byte
**opcode_definitions
,
24517 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24519 unsigned int offset_size
,
24520 struct dwarf2_section_info
*section
)
24522 unsigned int bytes_read
, i
;
24524 const gdb_byte
*defn
;
24526 if (opcode_definitions
[opcode
] == NULL
)
24528 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24533 defn
= opcode_definitions
[opcode
];
24534 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24535 defn
+= bytes_read
;
24537 for (i
= 0; i
< arg
; ++i
)
24539 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24540 (enum dwarf_form
) defn
[i
], offset_size
,
24542 if (mac_ptr
== NULL
)
24544 /* skip_form_bytes already issued the complaint. */
24552 /* A helper function which parses the header of a macro section.
24553 If the macro section is the extended (for now called "GNU") type,
24554 then this updates *OFFSET_SIZE. Returns a pointer to just after
24555 the header, or issues a complaint and returns NULL on error. */
24557 static const gdb_byte
*
24558 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24560 const gdb_byte
*mac_ptr
,
24561 unsigned int *offset_size
,
24562 int section_is_gnu
)
24564 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24566 if (section_is_gnu
)
24568 unsigned int version
, flags
;
24570 version
= read_2_bytes (abfd
, mac_ptr
);
24571 if (version
!= 4 && version
!= 5)
24573 complaint (_("unrecognized version `%d' in .debug_macro section"),
24579 flags
= read_1_byte (abfd
, mac_ptr
);
24581 *offset_size
= (flags
& 1) ? 8 : 4;
24583 if ((flags
& 2) != 0)
24584 /* We don't need the line table offset. */
24585 mac_ptr
+= *offset_size
;
24587 /* Vendor opcode descriptions. */
24588 if ((flags
& 4) != 0)
24590 unsigned int i
, count
;
24592 count
= read_1_byte (abfd
, mac_ptr
);
24594 for (i
= 0; i
< count
; ++i
)
24596 unsigned int opcode
, bytes_read
;
24599 opcode
= read_1_byte (abfd
, mac_ptr
);
24601 opcode_definitions
[opcode
] = mac_ptr
;
24602 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24603 mac_ptr
+= bytes_read
;
24612 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24613 including DW_MACRO_import. */
24616 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24618 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24619 struct macro_source_file
*current_file
,
24620 struct line_header
*lh
,
24621 struct dwarf2_section_info
*section
,
24622 int section_is_gnu
, int section_is_dwz
,
24623 unsigned int offset_size
,
24624 htab_t include_hash
)
24626 struct dwarf2_per_objfile
*dwarf2_per_objfile
24627 = cu
->per_cu
->dwarf2_per_objfile
;
24628 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24629 enum dwarf_macro_record_type macinfo_type
;
24630 int at_commandline
;
24631 const gdb_byte
*opcode_definitions
[256];
24633 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24634 &offset_size
, section_is_gnu
);
24635 if (mac_ptr
== NULL
)
24637 /* We already issued a complaint. */
24641 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24642 GDB is still reading the definitions from command line. First
24643 DW_MACINFO_start_file will need to be ignored as it was already executed
24644 to create CURRENT_FILE for the main source holding also the command line
24645 definitions. On first met DW_MACINFO_start_file this flag is reset to
24646 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24648 at_commandline
= 1;
24652 /* Do we at least have room for a macinfo type byte? */
24653 if (mac_ptr
>= mac_end
)
24655 dwarf2_section_buffer_overflow_complaint (section
);
24659 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24662 /* Note that we rely on the fact that the corresponding GNU and
24663 DWARF constants are the same. */
24665 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24666 switch (macinfo_type
)
24668 /* A zero macinfo type indicates the end of the macro
24673 case DW_MACRO_define
:
24674 case DW_MACRO_undef
:
24675 case DW_MACRO_define_strp
:
24676 case DW_MACRO_undef_strp
:
24677 case DW_MACRO_define_sup
:
24678 case DW_MACRO_undef_sup
:
24680 unsigned int bytes_read
;
24685 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24686 mac_ptr
+= bytes_read
;
24688 if (macinfo_type
== DW_MACRO_define
24689 || macinfo_type
== DW_MACRO_undef
)
24691 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24692 mac_ptr
+= bytes_read
;
24696 LONGEST str_offset
;
24698 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24699 mac_ptr
+= offset_size
;
24701 if (macinfo_type
== DW_MACRO_define_sup
24702 || macinfo_type
== DW_MACRO_undef_sup
24705 struct dwz_file
*dwz
24706 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24708 body
= read_indirect_string_from_dwz (objfile
,
24712 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24716 is_define
= (macinfo_type
== DW_MACRO_define
24717 || macinfo_type
== DW_MACRO_define_strp
24718 || macinfo_type
== DW_MACRO_define_sup
);
24719 if (! current_file
)
24721 /* DWARF violation as no main source is present. */
24722 complaint (_("debug info with no main source gives macro %s "
24724 is_define
? _("definition") : _("undefinition"),
24728 if ((line
== 0 && !at_commandline
)
24729 || (line
!= 0 && at_commandline
))
24730 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24731 at_commandline
? _("command-line") : _("in-file"),
24732 is_define
? _("definition") : _("undefinition"),
24733 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24737 /* Fedora's rpm-build's "debugedit" binary
24738 corrupted .debug_macro sections.
24741 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24742 complaint (_("debug info gives %s invalid macro %s "
24743 "without body (corrupted?) at line %d "
24745 at_commandline
? _("command-line") : _("in-file"),
24746 is_define
? _("definition") : _("undefinition"),
24747 line
, current_file
->filename
);
24749 else if (is_define
)
24750 parse_macro_definition (current_file
, line
, body
);
24753 gdb_assert (macinfo_type
== DW_MACRO_undef
24754 || macinfo_type
== DW_MACRO_undef_strp
24755 || macinfo_type
== DW_MACRO_undef_sup
);
24756 macro_undef (current_file
, line
, body
);
24761 case DW_MACRO_start_file
:
24763 unsigned int bytes_read
;
24766 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24767 mac_ptr
+= bytes_read
;
24768 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24769 mac_ptr
+= bytes_read
;
24771 if ((line
== 0 && !at_commandline
)
24772 || (line
!= 0 && at_commandline
))
24773 complaint (_("debug info gives source %d included "
24774 "from %s at %s line %d"),
24775 file
, at_commandline
? _("command-line") : _("file"),
24776 line
== 0 ? _("zero") : _("non-zero"), line
);
24778 if (at_commandline
)
24780 /* This DW_MACRO_start_file was executed in the
24782 at_commandline
= 0;
24785 current_file
= macro_start_file (cu
, file
, line
, current_file
,
24790 case DW_MACRO_end_file
:
24791 if (! current_file
)
24792 complaint (_("macro debug info has an unmatched "
24793 "`close_file' directive"));
24796 current_file
= current_file
->included_by
;
24797 if (! current_file
)
24799 enum dwarf_macro_record_type next_type
;
24801 /* GCC circa March 2002 doesn't produce the zero
24802 type byte marking the end of the compilation
24803 unit. Complain if it's not there, but exit no
24806 /* Do we at least have room for a macinfo type byte? */
24807 if (mac_ptr
>= mac_end
)
24809 dwarf2_section_buffer_overflow_complaint (section
);
24813 /* We don't increment mac_ptr here, so this is just
24816 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
24818 if (next_type
!= 0)
24819 complaint (_("no terminating 0-type entry for "
24820 "macros in `.debug_macinfo' section"));
24827 case DW_MACRO_import
:
24828 case DW_MACRO_import_sup
:
24832 bfd
*include_bfd
= abfd
;
24833 struct dwarf2_section_info
*include_section
= section
;
24834 const gdb_byte
*include_mac_end
= mac_end
;
24835 int is_dwz
= section_is_dwz
;
24836 const gdb_byte
*new_mac_ptr
;
24838 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24839 mac_ptr
+= offset_size
;
24841 if (macinfo_type
== DW_MACRO_import_sup
)
24843 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
24845 dwarf2_read_section (objfile
, &dwz
->macro
);
24847 include_section
= &dwz
->macro
;
24848 include_bfd
= get_section_bfd_owner (include_section
);
24849 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
24853 new_mac_ptr
= include_section
->buffer
+ offset
;
24854 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
24858 /* This has actually happened; see
24859 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
24860 complaint (_("recursive DW_MACRO_import in "
24861 ".debug_macro section"));
24865 *slot
= (void *) new_mac_ptr
;
24867 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
24868 include_mac_end
, current_file
, lh
,
24869 section
, section_is_gnu
, is_dwz
,
24870 offset_size
, include_hash
);
24872 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
24877 case DW_MACINFO_vendor_ext
:
24878 if (!section_is_gnu
)
24880 unsigned int bytes_read
;
24882 /* This reads the constant, but since we don't recognize
24883 any vendor extensions, we ignore it. */
24884 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24885 mac_ptr
+= bytes_read
;
24886 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24887 mac_ptr
+= bytes_read
;
24889 /* We don't recognize any vendor extensions. */
24895 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
24896 mac_ptr
, mac_end
, abfd
, offset_size
,
24898 if (mac_ptr
== NULL
)
24903 } while (macinfo_type
!= 0);
24907 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
24908 int section_is_gnu
)
24910 struct dwarf2_per_objfile
*dwarf2_per_objfile
24911 = cu
->per_cu
->dwarf2_per_objfile
;
24912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24913 struct line_header
*lh
= cu
->line_header
;
24915 const gdb_byte
*mac_ptr
, *mac_end
;
24916 struct macro_source_file
*current_file
= 0;
24917 enum dwarf_macro_record_type macinfo_type
;
24918 unsigned int offset_size
= cu
->header
.offset_size
;
24919 const gdb_byte
*opcode_definitions
[256];
24921 struct dwarf2_section_info
*section
;
24922 const char *section_name
;
24924 if (cu
->dwo_unit
!= NULL
)
24926 if (section_is_gnu
)
24928 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
24929 section_name
= ".debug_macro.dwo";
24933 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
24934 section_name
= ".debug_macinfo.dwo";
24939 if (section_is_gnu
)
24941 section
= &dwarf2_per_objfile
->macro
;
24942 section_name
= ".debug_macro";
24946 section
= &dwarf2_per_objfile
->macinfo
;
24947 section_name
= ".debug_macinfo";
24951 dwarf2_read_section (objfile
, section
);
24952 if (section
->buffer
== NULL
)
24954 complaint (_("missing %s section"), section_name
);
24957 abfd
= get_section_bfd_owner (section
);
24959 /* First pass: Find the name of the base filename.
24960 This filename is needed in order to process all macros whose definition
24961 (or undefinition) comes from the command line. These macros are defined
24962 before the first DW_MACINFO_start_file entry, and yet still need to be
24963 associated to the base file.
24965 To determine the base file name, we scan the macro definitions until we
24966 reach the first DW_MACINFO_start_file entry. We then initialize
24967 CURRENT_FILE accordingly so that any macro definition found before the
24968 first DW_MACINFO_start_file can still be associated to the base file. */
24970 mac_ptr
= section
->buffer
+ offset
;
24971 mac_end
= section
->buffer
+ section
->size
;
24973 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24974 &offset_size
, section_is_gnu
);
24975 if (mac_ptr
== NULL
)
24977 /* We already issued a complaint. */
24983 /* Do we at least have room for a macinfo type byte? */
24984 if (mac_ptr
>= mac_end
)
24986 /* Complaint is printed during the second pass as GDB will probably
24987 stop the first pass earlier upon finding
24988 DW_MACINFO_start_file. */
24992 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24995 /* Note that we rely on the fact that the corresponding GNU and
24996 DWARF constants are the same. */
24998 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24999 switch (macinfo_type
)
25001 /* A zero macinfo type indicates the end of the macro
25006 case DW_MACRO_define
:
25007 case DW_MACRO_undef
:
25008 /* Only skip the data by MAC_PTR. */
25010 unsigned int bytes_read
;
25012 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25013 mac_ptr
+= bytes_read
;
25014 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25015 mac_ptr
+= bytes_read
;
25019 case DW_MACRO_start_file
:
25021 unsigned int bytes_read
;
25024 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25025 mac_ptr
+= bytes_read
;
25026 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25027 mac_ptr
+= bytes_read
;
25029 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25033 case DW_MACRO_end_file
:
25034 /* No data to skip by MAC_PTR. */
25037 case DW_MACRO_define_strp
:
25038 case DW_MACRO_undef_strp
:
25039 case DW_MACRO_define_sup
:
25040 case DW_MACRO_undef_sup
:
25042 unsigned int bytes_read
;
25044 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25045 mac_ptr
+= bytes_read
;
25046 mac_ptr
+= offset_size
;
25050 case DW_MACRO_import
:
25051 case DW_MACRO_import_sup
:
25052 /* Note that, according to the spec, a transparent include
25053 chain cannot call DW_MACRO_start_file. So, we can just
25054 skip this opcode. */
25055 mac_ptr
+= offset_size
;
25058 case DW_MACINFO_vendor_ext
:
25059 /* Only skip the data by MAC_PTR. */
25060 if (!section_is_gnu
)
25062 unsigned int bytes_read
;
25064 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25065 mac_ptr
+= bytes_read
;
25066 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25067 mac_ptr
+= bytes_read
;
25072 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25073 mac_ptr
, mac_end
, abfd
, offset_size
,
25075 if (mac_ptr
== NULL
)
25080 } while (macinfo_type
!= 0 && current_file
== NULL
);
25082 /* Second pass: Process all entries.
25084 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25085 command-line macro definitions/undefinitions. This flag is unset when we
25086 reach the first DW_MACINFO_start_file entry. */
25088 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25090 NULL
, xcalloc
, xfree
));
25091 mac_ptr
= section
->buffer
+ offset
;
25092 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25093 *slot
= (void *) mac_ptr
;
25094 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25095 current_file
, lh
, section
,
25096 section_is_gnu
, 0, offset_size
,
25097 include_hash
.get ());
25100 /* Check if the attribute's form is a DW_FORM_block*
25101 if so return true else false. */
25104 attr_form_is_block (const struct attribute
*attr
)
25106 return (attr
== NULL
? 0 :
25107 attr
->form
== DW_FORM_block1
25108 || attr
->form
== DW_FORM_block2
25109 || attr
->form
== DW_FORM_block4
25110 || attr
->form
== DW_FORM_block
25111 || attr
->form
== DW_FORM_exprloc
);
25114 /* Return non-zero if ATTR's value is a section offset --- classes
25115 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25116 You may use DW_UNSND (attr) to retrieve such offsets.
25118 Section 7.5.4, "Attribute Encodings", explains that no attribute
25119 may have a value that belongs to more than one of these classes; it
25120 would be ambiguous if we did, because we use the same forms for all
25124 attr_form_is_section_offset (const struct attribute
*attr
)
25126 return (attr
->form
== DW_FORM_data4
25127 || attr
->form
== DW_FORM_data8
25128 || attr
->form
== DW_FORM_sec_offset
);
25131 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25132 zero otherwise. When this function returns true, you can apply
25133 dwarf2_get_attr_constant_value to it.
25135 However, note that for some attributes you must check
25136 attr_form_is_section_offset before using this test. DW_FORM_data4
25137 and DW_FORM_data8 are members of both the constant class, and of
25138 the classes that contain offsets into other debug sections
25139 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25140 that, if an attribute's can be either a constant or one of the
25141 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25142 taken as section offsets, not constants.
25144 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25145 cannot handle that. */
25148 attr_form_is_constant (const struct attribute
*attr
)
25150 switch (attr
->form
)
25152 case DW_FORM_sdata
:
25153 case DW_FORM_udata
:
25154 case DW_FORM_data1
:
25155 case DW_FORM_data2
:
25156 case DW_FORM_data4
:
25157 case DW_FORM_data8
:
25158 case DW_FORM_implicit_const
:
25166 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25167 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25170 attr_form_is_ref (const struct attribute
*attr
)
25172 switch (attr
->form
)
25174 case DW_FORM_ref_addr
:
25179 case DW_FORM_ref_udata
:
25180 case DW_FORM_GNU_ref_alt
:
25187 /* Return the .debug_loc section to use for CU.
25188 For DWO files use .debug_loc.dwo. */
25190 static struct dwarf2_section_info
*
25191 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25193 struct dwarf2_per_objfile
*dwarf2_per_objfile
25194 = cu
->per_cu
->dwarf2_per_objfile
;
25198 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25200 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25202 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25203 : &dwarf2_per_objfile
->loc
);
25206 /* A helper function that fills in a dwarf2_loclist_baton. */
25209 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25210 struct dwarf2_loclist_baton
*baton
,
25211 const struct attribute
*attr
)
25213 struct dwarf2_per_objfile
*dwarf2_per_objfile
25214 = cu
->per_cu
->dwarf2_per_objfile
;
25215 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25217 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25219 baton
->per_cu
= cu
->per_cu
;
25220 gdb_assert (baton
->per_cu
);
25221 /* We don't know how long the location list is, but make sure we
25222 don't run off the edge of the section. */
25223 baton
->size
= section
->size
- DW_UNSND (attr
);
25224 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25225 baton
->base_address
= cu
->base_address
;
25226 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25230 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25231 struct dwarf2_cu
*cu
, int is_block
)
25233 struct dwarf2_per_objfile
*dwarf2_per_objfile
25234 = cu
->per_cu
->dwarf2_per_objfile
;
25235 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25236 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25238 if (attr_form_is_section_offset (attr
)
25239 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25240 the section. If so, fall through to the complaint in the
25242 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25244 struct dwarf2_loclist_baton
*baton
;
25246 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25248 fill_in_loclist_baton (cu
, baton
, attr
);
25250 if (cu
->base_known
== 0)
25251 complaint (_("Location list used without "
25252 "specifying the CU base address."));
25254 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25255 ? dwarf2_loclist_block_index
25256 : dwarf2_loclist_index
);
25257 SYMBOL_LOCATION_BATON (sym
) = baton
;
25261 struct dwarf2_locexpr_baton
*baton
;
25263 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25264 baton
->per_cu
= cu
->per_cu
;
25265 gdb_assert (baton
->per_cu
);
25267 if (attr_form_is_block (attr
))
25269 /* Note that we're just copying the block's data pointer
25270 here, not the actual data. We're still pointing into the
25271 info_buffer for SYM's objfile; right now we never release
25272 that buffer, but when we do clean up properly this may
25274 baton
->size
= DW_BLOCK (attr
)->size
;
25275 baton
->data
= DW_BLOCK (attr
)->data
;
25279 dwarf2_invalid_attrib_class_complaint ("location description",
25280 SYMBOL_NATURAL_NAME (sym
));
25284 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25285 ? dwarf2_locexpr_block_index
25286 : dwarf2_locexpr_index
);
25287 SYMBOL_LOCATION_BATON (sym
) = baton
;
25291 /* Return the OBJFILE associated with the compilation unit CU. If CU
25292 came from a separate debuginfo file, then the master objfile is
25296 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25298 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25300 /* Return the master objfile, so that we can report and look up the
25301 correct file containing this variable. */
25302 if (objfile
->separate_debug_objfile_backlink
)
25303 objfile
= objfile
->separate_debug_objfile_backlink
;
25308 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25309 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25310 CU_HEADERP first. */
25312 static const struct comp_unit_head
*
25313 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25314 struct dwarf2_per_cu_data
*per_cu
)
25316 const gdb_byte
*info_ptr
;
25319 return &per_cu
->cu
->header
;
25321 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25323 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25324 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25325 rcuh_kind::COMPILE
);
25330 /* Return the address size given in the compilation unit header for CU. */
25333 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25335 struct comp_unit_head cu_header_local
;
25336 const struct comp_unit_head
*cu_headerp
;
25338 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25340 return cu_headerp
->addr_size
;
25343 /* Return the offset size given in the compilation unit header for CU. */
25346 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25348 struct comp_unit_head cu_header_local
;
25349 const struct comp_unit_head
*cu_headerp
;
25351 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25353 return cu_headerp
->offset_size
;
25356 /* See its dwarf2loc.h declaration. */
25359 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25361 struct comp_unit_head cu_header_local
;
25362 const struct comp_unit_head
*cu_headerp
;
25364 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25366 if (cu_headerp
->version
== 2)
25367 return cu_headerp
->addr_size
;
25369 return cu_headerp
->offset_size
;
25372 /* Return the text offset of the CU. The returned offset comes from
25373 this CU's objfile. If this objfile came from a separate debuginfo
25374 file, then the offset may be different from the corresponding
25375 offset in the parent objfile. */
25378 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25380 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25382 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
25385 /* Return a type that is a generic pointer type, the size of which matches
25386 the address size given in the compilation unit header for PER_CU. */
25387 static struct type
*
25388 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25390 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25391 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25392 struct type
*addr_type
= lookup_pointer_type (void_type
);
25393 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25395 if (TYPE_LENGTH (addr_type
) == addr_size
)
25399 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25403 /* Return DWARF version number of PER_CU. */
25406 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25408 return per_cu
->dwarf_version
;
25411 /* Locate the .debug_info compilation unit from CU's objfile which contains
25412 the DIE at OFFSET. Raises an error on failure. */
25414 static struct dwarf2_per_cu_data
*
25415 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25416 unsigned int offset_in_dwz
,
25417 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25419 struct dwarf2_per_cu_data
*this_cu
;
25423 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25426 struct dwarf2_per_cu_data
*mid_cu
;
25427 int mid
= low
+ (high
- low
) / 2;
25429 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25430 if (mid_cu
->is_dwz
> offset_in_dwz
25431 || (mid_cu
->is_dwz
== offset_in_dwz
25432 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25437 gdb_assert (low
== high
);
25438 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25439 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25441 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25442 error (_("Dwarf Error: could not find partial DIE containing "
25443 "offset %s [in module %s]"),
25444 sect_offset_str (sect_off
),
25445 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25447 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25449 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25453 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25454 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25455 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25456 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25461 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25463 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25464 : per_cu (per_cu_
),
25466 has_loclist (false),
25467 checked_producer (false),
25468 producer_is_gxx_lt_4_6 (false),
25469 producer_is_gcc_lt_4_3 (false),
25470 producer_is_icc (false),
25471 producer_is_icc_lt_14 (false),
25472 producer_is_codewarrior (false),
25473 processing_has_namespace_info (false)
25478 /* Destroy a dwarf2_cu. */
25480 dwarf2_cu::~dwarf2_cu ()
25485 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25488 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25489 enum language pretend_language
)
25491 struct attribute
*attr
;
25493 /* Set the language we're debugging. */
25494 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25496 set_cu_language (DW_UNSND (attr
), cu
);
25499 cu
->language
= pretend_language
;
25500 cu
->language_defn
= language_def (cu
->language
);
25503 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25506 /* Increase the age counter on each cached compilation unit, and free
25507 any that are too old. */
25510 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25512 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25514 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25515 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25516 while (per_cu
!= NULL
)
25518 per_cu
->cu
->last_used
++;
25519 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25520 dwarf2_mark (per_cu
->cu
);
25521 per_cu
= per_cu
->cu
->read_in_chain
;
25524 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25525 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25526 while (per_cu
!= NULL
)
25528 struct dwarf2_per_cu_data
*next_cu
;
25530 next_cu
= per_cu
->cu
->read_in_chain
;
25532 if (!per_cu
->cu
->mark
)
25535 *last_chain
= next_cu
;
25538 last_chain
= &per_cu
->cu
->read_in_chain
;
25544 /* Remove a single compilation unit from the cache. */
25547 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25549 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25550 struct dwarf2_per_objfile
*dwarf2_per_objfile
25551 = target_per_cu
->dwarf2_per_objfile
;
25553 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25554 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25555 while (per_cu
!= NULL
)
25557 struct dwarf2_per_cu_data
*next_cu
;
25559 next_cu
= per_cu
->cu
->read_in_chain
;
25561 if (per_cu
== target_per_cu
)
25565 *last_chain
= next_cu
;
25569 last_chain
= &per_cu
->cu
->read_in_chain
;
25575 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25576 We store these in a hash table separate from the DIEs, and preserve them
25577 when the DIEs are flushed out of cache.
25579 The CU "per_cu" pointer is needed because offset alone is not enough to
25580 uniquely identify the type. A file may have multiple .debug_types sections,
25581 or the type may come from a DWO file. Furthermore, while it's more logical
25582 to use per_cu->section+offset, with Fission the section with the data is in
25583 the DWO file but we don't know that section at the point we need it.
25584 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25585 because we can enter the lookup routine, get_die_type_at_offset, from
25586 outside this file, and thus won't necessarily have PER_CU->cu.
25587 Fortunately, PER_CU is stable for the life of the objfile. */
25589 struct dwarf2_per_cu_offset_and_type
25591 const struct dwarf2_per_cu_data
*per_cu
;
25592 sect_offset sect_off
;
25596 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25599 per_cu_offset_and_type_hash (const void *item
)
25601 const struct dwarf2_per_cu_offset_and_type
*ofs
25602 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25604 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25607 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25610 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25612 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25613 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25614 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25615 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25617 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25618 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25621 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25622 table if necessary. For convenience, return TYPE.
25624 The DIEs reading must have careful ordering to:
25625 * Not cause infite loops trying to read in DIEs as a prerequisite for
25626 reading current DIE.
25627 * Not trying to dereference contents of still incompletely read in types
25628 while reading in other DIEs.
25629 * Enable referencing still incompletely read in types just by a pointer to
25630 the type without accessing its fields.
25632 Therefore caller should follow these rules:
25633 * Try to fetch any prerequisite types we may need to build this DIE type
25634 before building the type and calling set_die_type.
25635 * After building type call set_die_type for current DIE as soon as
25636 possible before fetching more types to complete the current type.
25637 * Make the type as complete as possible before fetching more types. */
25639 static struct type
*
25640 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25642 struct dwarf2_per_objfile
*dwarf2_per_objfile
25643 = cu
->per_cu
->dwarf2_per_objfile
;
25644 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25646 struct attribute
*attr
;
25647 struct dynamic_prop prop
;
25649 /* For Ada types, make sure that the gnat-specific data is always
25650 initialized (if not already set). There are a few types where
25651 we should not be doing so, because the type-specific area is
25652 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25653 where the type-specific area is used to store the floatformat).
25654 But this is not a problem, because the gnat-specific information
25655 is actually not needed for these types. */
25656 if (need_gnat_info (cu
)
25657 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25658 && TYPE_CODE (type
) != TYPE_CODE_FLT
25659 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25660 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25661 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25662 && !HAVE_GNAT_AUX_INFO (type
))
25663 INIT_GNAT_SPECIFIC (type
);
25665 /* Read DW_AT_allocated and set in type. */
25666 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25667 if (attr_form_is_block (attr
))
25669 struct type
*prop_type
25670 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25671 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25672 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25674 else if (attr
!= NULL
)
25676 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25677 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25678 sect_offset_str (die
->sect_off
));
25681 /* Read DW_AT_associated and set in type. */
25682 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25683 if (attr_form_is_block (attr
))
25685 struct type
*prop_type
25686 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25687 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25688 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25690 else if (attr
!= NULL
)
25692 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25693 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25694 sect_offset_str (die
->sect_off
));
25697 /* Read DW_AT_data_location and set in type. */
25698 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25699 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25700 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25701 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25703 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25705 dwarf2_per_objfile
->die_type_hash
=
25706 htab_create_alloc_ex (127,
25707 per_cu_offset_and_type_hash
,
25708 per_cu_offset_and_type_eq
,
25710 &objfile
->objfile_obstack
,
25711 hashtab_obstack_allocate
,
25712 dummy_obstack_deallocate
);
25715 ofs
.per_cu
= cu
->per_cu
;
25716 ofs
.sect_off
= die
->sect_off
;
25718 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25719 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25721 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25722 sect_offset_str (die
->sect_off
));
25723 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25724 struct dwarf2_per_cu_offset_and_type
);
25729 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25730 or return NULL if the die does not have a saved type. */
25732 static struct type
*
25733 get_die_type_at_offset (sect_offset sect_off
,
25734 struct dwarf2_per_cu_data
*per_cu
)
25736 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25737 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25739 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25742 ofs
.per_cu
= per_cu
;
25743 ofs
.sect_off
= sect_off
;
25744 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
25745 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
25752 /* Look up the type for DIE in CU in die_type_hash,
25753 or return NULL if DIE does not have a saved type. */
25755 static struct type
*
25756 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
25758 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
25761 /* Add a dependence relationship from CU to REF_PER_CU. */
25764 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
25765 struct dwarf2_per_cu_data
*ref_per_cu
)
25769 if (cu
->dependencies
== NULL
)
25771 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
25772 NULL
, &cu
->comp_unit_obstack
,
25773 hashtab_obstack_allocate
,
25774 dummy_obstack_deallocate
);
25776 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
25778 *slot
= ref_per_cu
;
25781 /* Subroutine of dwarf2_mark to pass to htab_traverse.
25782 Set the mark field in every compilation unit in the
25783 cache that we must keep because we are keeping CU. */
25786 dwarf2_mark_helper (void **slot
, void *data
)
25788 struct dwarf2_per_cu_data
*per_cu
;
25790 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
25792 /* cu->dependencies references may not yet have been ever read if QUIT aborts
25793 reading of the chain. As such dependencies remain valid it is not much
25794 useful to track and undo them during QUIT cleanups. */
25795 if (per_cu
->cu
== NULL
)
25798 if (per_cu
->cu
->mark
)
25800 per_cu
->cu
->mark
= true;
25802 if (per_cu
->cu
->dependencies
!= NULL
)
25803 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25808 /* Set the mark field in CU and in every other compilation unit in the
25809 cache that we must keep because we are keeping CU. */
25812 dwarf2_mark (struct dwarf2_cu
*cu
)
25817 if (cu
->dependencies
!= NULL
)
25818 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
25822 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
25826 per_cu
->cu
->mark
= false;
25827 per_cu
= per_cu
->cu
->read_in_chain
;
25831 /* Trivial hash function for partial_die_info: the hash value of a DIE
25832 is its offset in .debug_info for this objfile. */
25835 partial_die_hash (const void *item
)
25837 const struct partial_die_info
*part_die
25838 = (const struct partial_die_info
*) item
;
25840 return to_underlying (part_die
->sect_off
);
25843 /* Trivial comparison function for partial_die_info structures: two DIEs
25844 are equal if they have the same offset. */
25847 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
25849 const struct partial_die_info
*part_die_lhs
25850 = (const struct partial_die_info
*) item_lhs
;
25851 const struct partial_die_info
*part_die_rhs
25852 = (const struct partial_die_info
*) item_rhs
;
25854 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
25857 struct cmd_list_element
*set_dwarf_cmdlist
;
25858 struct cmd_list_element
*show_dwarf_cmdlist
;
25861 set_dwarf_cmd (const char *args
, int from_tty
)
25863 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
25868 show_dwarf_cmd (const char *args
, int from_tty
)
25870 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
25873 bool dwarf_always_disassemble
;
25876 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
25877 struct cmd_list_element
*c
, const char *value
)
25879 fprintf_filtered (file
,
25880 _("Whether to always disassemble "
25881 "DWARF expressions is %s.\n"),
25886 show_check_physname (struct ui_file
*file
, int from_tty
,
25887 struct cmd_list_element
*c
, const char *value
)
25889 fprintf_filtered (file
,
25890 _("Whether to check \"physname\" is %s.\n"),
25895 _initialize_dwarf2_read (void)
25897 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
25898 Set DWARF specific variables.\n\
25899 Configure DWARF variables such as the cache size."),
25900 &set_dwarf_cmdlist
, "maintenance set dwarf ",
25901 0/*allow-unknown*/, &maintenance_set_cmdlist
);
25903 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
25904 Show DWARF specific variables.\n\
25905 Show DWARF variables such as the cache size."),
25906 &show_dwarf_cmdlist
, "maintenance show dwarf ",
25907 0/*allow-unknown*/, &maintenance_show_cmdlist
);
25909 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
25910 &dwarf_max_cache_age
, _("\
25911 Set the upper bound on the age of cached DWARF compilation units."), _("\
25912 Show the upper bound on the age of cached DWARF compilation units."), _("\
25913 A higher limit means that cached compilation units will be stored\n\
25914 in memory longer, and more total memory will be used. Zero disables\n\
25915 caching, which can slow down startup."),
25917 show_dwarf_max_cache_age
,
25918 &set_dwarf_cmdlist
,
25919 &show_dwarf_cmdlist
);
25921 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
25922 &dwarf_always_disassemble
, _("\
25923 Set whether `info address' always disassembles DWARF expressions."), _("\
25924 Show whether `info address' always disassembles DWARF expressions."), _("\
25925 When enabled, DWARF expressions are always printed in an assembly-like\n\
25926 syntax. When disabled, expressions will be printed in a more\n\
25927 conversational style, when possible."),
25929 show_dwarf_always_disassemble
,
25930 &set_dwarf_cmdlist
,
25931 &show_dwarf_cmdlist
);
25933 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
25934 Set debugging of the DWARF reader."), _("\
25935 Show debugging of the DWARF reader."), _("\
25936 When enabled (non-zero), debugging messages are printed during DWARF\n\
25937 reading and symtab expansion. A value of 1 (one) provides basic\n\
25938 information. A value greater than 1 provides more verbose information."),
25941 &setdebuglist
, &showdebuglist
);
25943 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
25944 Set debugging of the DWARF DIE reader."), _("\
25945 Show debugging of the DWARF DIE reader."), _("\
25946 When enabled (non-zero), DIEs are dumped after they are read in.\n\
25947 The value is the maximum depth to print."),
25950 &setdebuglist
, &showdebuglist
);
25952 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
25953 Set debugging of the dwarf line reader."), _("\
25954 Show debugging of the dwarf line reader."), _("\
25955 When enabled (non-zero), line number entries are dumped as they are read in.\n\
25956 A value of 1 (one) provides basic information.\n\
25957 A value greater than 1 provides more verbose information."),
25960 &setdebuglist
, &showdebuglist
);
25962 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
25963 Set cross-checking of \"physname\" code against demangler."), _("\
25964 Show cross-checking of \"physname\" code against demangler."), _("\
25965 When enabled, GDB's internal \"physname\" code is checked against\n\
25967 NULL
, show_check_physname
,
25968 &setdebuglist
, &showdebuglist
);
25970 add_setshow_boolean_cmd ("use-deprecated-index-sections",
25971 no_class
, &use_deprecated_index_sections
, _("\
25972 Set whether to use deprecated gdb_index sections."), _("\
25973 Show whether to use deprecated gdb_index sections."), _("\
25974 When enabled, deprecated .gdb_index sections are used anyway.\n\
25975 Normally they are ignored either because of a missing feature or\n\
25976 performance issue.\n\
25977 Warning: This option must be enabled before gdb reads the file."),
25980 &setlist
, &showlist
);
25982 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25983 &dwarf2_locexpr_funcs
);
25984 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
25985 &dwarf2_loclist_funcs
);
25987 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25988 &dwarf2_block_frame_base_locexpr_funcs
);
25989 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
25990 &dwarf2_block_frame_base_loclist_funcs
);
25993 selftests::register_test ("dw2_expand_symtabs_matching",
25994 selftests::dw2_expand_symtabs_matching::run_test
);