1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994-2020 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /* FIXME: Various die-reading functions need to be more careful with
28 reading off the end of the section.
29 E.g., load_partial_dies, read_partial_die. */
32 #include "dwarf2read.h"
33 #include "dwarf-index-cache.h"
34 #include "dwarf-index-common.h"
43 #include "gdb-demangle.h"
44 #include "filenames.h" /* for DOSish file names */
47 #include "complaints.h"
48 #include "dwarf2expr.h"
49 #include "dwarf2loc.h"
50 #include "cp-support.h"
56 #include "typeprint.h"
61 #include "gdbcore.h" /* for gnutarget */
62 #include "gdb/gdb-index.h"
67 #include "namespace.h"
68 #include "gdbsupport/function-view.h"
69 #include "gdbsupport/gdb_optional.h"
70 #include "gdbsupport/underlying.h"
71 #include "gdbsupport/hash_enum.h"
72 #include "filename-seen-cache.h"
76 #include <unordered_map>
77 #include "gdbsupport/selftest.h"
78 #include "rust-lang.h"
79 #include "gdbsupport/pathstuff.h"
81 /* When == 1, print basic high level tracing messages.
82 When > 1, be more verbose.
83 This is in contrast to the low level DIE reading of dwarf_die_debug. */
84 static unsigned int dwarf_read_debug
= 0;
86 /* When non-zero, dump DIEs after they are read in. */
87 static unsigned int dwarf_die_debug
= 0;
89 /* When non-zero, dump line number entries as they are read in. */
90 static unsigned int dwarf_line_debug
= 0;
92 /* When true, cross-check physname against demangler. */
93 static bool check_physname
= false;
95 /* When true, do not reject deprecated .gdb_index sections. */
96 static bool use_deprecated_index_sections
= false;
98 static const struct objfile_key
<dwarf2_per_objfile
> dwarf2_objfile_data_key
;
100 /* The "aclass" indices for various kinds of computed DWARF symbols. */
102 static int dwarf2_locexpr_index
;
103 static int dwarf2_loclist_index
;
104 static int dwarf2_locexpr_block_index
;
105 static int dwarf2_loclist_block_index
;
107 /* An index into a (C++) symbol name component in a symbol name as
108 recorded in the mapped_index's symbol table. For each C++ symbol
109 in the symbol table, we record one entry for the start of each
110 component in the symbol in a table of name components, and then
111 sort the table, in order to be able to binary search symbol names,
112 ignoring leading namespaces, both completion and regular look up.
113 For example, for symbol "A::B::C", we'll have an entry that points
114 to "A::B::C", another that points to "B::C", and another for "C".
115 Note that function symbols in GDB index have no parameter
116 information, just the function/method names. You can convert a
117 name_component to a "const char *" using the
118 'mapped_index::symbol_name_at(offset_type)' method. */
120 struct name_component
122 /* Offset in the symbol name where the component starts. Stored as
123 a (32-bit) offset instead of a pointer to save memory and improve
124 locality on 64-bit architectures. */
125 offset_type name_offset
;
127 /* The symbol's index in the symbol and constant pool tables of a
132 /* Base class containing bits shared by both .gdb_index and
133 .debug_name indexes. */
135 struct mapped_index_base
137 mapped_index_base () = default;
138 DISABLE_COPY_AND_ASSIGN (mapped_index_base
);
140 /* The name_component table (a sorted vector). See name_component's
141 description above. */
142 std::vector
<name_component
> name_components
;
144 /* How NAME_COMPONENTS is sorted. */
145 enum case_sensitivity name_components_casing
;
147 /* Return the number of names in the symbol table. */
148 virtual size_t symbol_name_count () const = 0;
150 /* Get the name of the symbol at IDX in the symbol table. */
151 virtual const char *symbol_name_at (offset_type idx
) const = 0;
153 /* Return whether the name at IDX in the symbol table should be
155 virtual bool symbol_name_slot_invalid (offset_type idx
) const
160 /* Build the symbol name component sorted vector, if we haven't
162 void build_name_components ();
164 /* Returns the lower (inclusive) and upper (exclusive) bounds of the
165 possible matches for LN_NO_PARAMS in the name component
167 std::pair
<std::vector
<name_component
>::const_iterator
,
168 std::vector
<name_component
>::const_iterator
>
169 find_name_components_bounds (const lookup_name_info
&ln_no_params
,
170 enum language lang
) const;
172 /* Prevent deleting/destroying via a base class pointer. */
174 ~mapped_index_base() = default;
177 /* A description of the mapped index. The file format is described in
178 a comment by the code that writes the index. */
179 struct mapped_index final
: public mapped_index_base
181 /* A slot/bucket in the symbol table hash. */
182 struct symbol_table_slot
184 const offset_type name
;
185 const offset_type vec
;
188 /* Index data format version. */
191 /* The address table data. */
192 gdb::array_view
<const gdb_byte
> address_table
;
194 /* The symbol table, implemented as a hash table. */
195 gdb::array_view
<symbol_table_slot
> symbol_table
;
197 /* A pointer to the constant pool. */
198 const char *constant_pool
= nullptr;
200 bool symbol_name_slot_invalid (offset_type idx
) const override
202 const auto &bucket
= this->symbol_table
[idx
];
203 return bucket
.name
== 0 && bucket
.vec
== 0;
206 /* Convenience method to get at the name of the symbol at IDX in the
208 const char *symbol_name_at (offset_type idx
) const override
209 { return this->constant_pool
+ MAYBE_SWAP (this->symbol_table
[idx
].name
); }
211 size_t symbol_name_count () const override
212 { return this->symbol_table
.size (); }
215 /* A description of the mapped .debug_names.
216 Uninitialized map has CU_COUNT 0. */
217 struct mapped_debug_names final
: public mapped_index_base
219 mapped_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile_
)
220 : dwarf2_per_objfile (dwarf2_per_objfile_
)
223 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
224 bfd_endian dwarf5_byte_order
;
225 bool dwarf5_is_dwarf64
;
226 bool augmentation_is_gdb
;
228 uint32_t cu_count
= 0;
229 uint32_t tu_count
, bucket_count
, name_count
;
230 const gdb_byte
*cu_table_reordered
, *tu_table_reordered
;
231 const uint32_t *bucket_table_reordered
, *hash_table_reordered
;
232 const gdb_byte
*name_table_string_offs_reordered
;
233 const gdb_byte
*name_table_entry_offs_reordered
;
234 const gdb_byte
*entry_pool
;
241 /* Attribute name DW_IDX_*. */
244 /* Attribute form DW_FORM_*. */
247 /* Value if FORM is DW_FORM_implicit_const. */
248 LONGEST implicit_const
;
250 std::vector
<attr
> attr_vec
;
253 std::unordered_map
<ULONGEST
, index_val
> abbrev_map
;
255 const char *namei_to_name (uint32_t namei
) const;
257 /* Implementation of the mapped_index_base virtual interface, for
258 the name_components cache. */
260 const char *symbol_name_at (offset_type idx
) const override
261 { return namei_to_name (idx
); }
263 size_t symbol_name_count () const override
264 { return this->name_count
; }
267 /* See dwarf2read.h. */
270 get_dwarf2_per_objfile (struct objfile
*objfile
)
272 return dwarf2_objfile_data_key
.get (objfile
);
275 /* Default names of the debugging sections. */
277 /* Note that if the debugging section has been compressed, it might
278 have a name like .zdebug_info. */
280 static const struct dwarf2_debug_sections dwarf2_elf_names
=
282 { ".debug_info", ".zdebug_info" },
283 { ".debug_abbrev", ".zdebug_abbrev" },
284 { ".debug_line", ".zdebug_line" },
285 { ".debug_loc", ".zdebug_loc" },
286 { ".debug_loclists", ".zdebug_loclists" },
287 { ".debug_macinfo", ".zdebug_macinfo" },
288 { ".debug_macro", ".zdebug_macro" },
289 { ".debug_str", ".zdebug_str" },
290 { ".debug_str_offsets", ".zdebug_str_offsets" },
291 { ".debug_line_str", ".zdebug_line_str" },
292 { ".debug_ranges", ".zdebug_ranges" },
293 { ".debug_rnglists", ".zdebug_rnglists" },
294 { ".debug_types", ".zdebug_types" },
295 { ".debug_addr", ".zdebug_addr" },
296 { ".debug_frame", ".zdebug_frame" },
297 { ".eh_frame", NULL
},
298 { ".gdb_index", ".zgdb_index" },
299 { ".debug_names", ".zdebug_names" },
300 { ".debug_aranges", ".zdebug_aranges" },
304 /* List of DWO/DWP sections. */
306 static const struct dwop_section_names
308 struct dwarf2_section_names abbrev_dwo
;
309 struct dwarf2_section_names info_dwo
;
310 struct dwarf2_section_names line_dwo
;
311 struct dwarf2_section_names loc_dwo
;
312 struct dwarf2_section_names loclists_dwo
;
313 struct dwarf2_section_names macinfo_dwo
;
314 struct dwarf2_section_names macro_dwo
;
315 struct dwarf2_section_names str_dwo
;
316 struct dwarf2_section_names str_offsets_dwo
;
317 struct dwarf2_section_names types_dwo
;
318 struct dwarf2_section_names cu_index
;
319 struct dwarf2_section_names tu_index
;
323 { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" },
324 { ".debug_info.dwo", ".zdebug_info.dwo" },
325 { ".debug_line.dwo", ".zdebug_line.dwo" },
326 { ".debug_loc.dwo", ".zdebug_loc.dwo" },
327 { ".debug_loclists.dwo", ".zdebug_loclists.dwo" },
328 { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" },
329 { ".debug_macro.dwo", ".zdebug_macro.dwo" },
330 { ".debug_str.dwo", ".zdebug_str.dwo" },
331 { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" },
332 { ".debug_types.dwo", ".zdebug_types.dwo" },
333 { ".debug_cu_index", ".zdebug_cu_index" },
334 { ".debug_tu_index", ".zdebug_tu_index" },
337 /* local data types */
339 /* The data in a compilation unit header, after target2host
340 translation, looks like this. */
341 struct comp_unit_head
345 unsigned char addr_size
;
346 unsigned char signed_addr_p
;
347 sect_offset abbrev_sect_off
;
349 /* Size of file offsets; either 4 or 8. */
350 unsigned int offset_size
;
352 /* Size of the length field; either 4 or 12. */
353 unsigned int initial_length_size
;
355 enum dwarf_unit_type unit_type
;
357 /* Offset to the first byte of this compilation unit header in the
358 .debug_info section, for resolving relative reference dies. */
359 sect_offset sect_off
;
361 /* Offset to first die in this cu from the start of the cu.
362 This will be the first byte following the compilation unit header. */
363 cu_offset first_die_cu_offset
;
366 /* 64-bit signature of this unit. For type units, it denotes the signature of
367 the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
368 Also used in DWARF 5, to denote the dwo id when the unit type is
369 DW_UT_skeleton or DW_UT_split_compile. */
372 /* For types, offset in the type's DIE of the type defined by this TU. */
373 cu_offset type_cu_offset_in_tu
;
376 /* Type used for delaying computation of method physnames.
377 See comments for compute_delayed_physnames. */
378 struct delayed_method_info
380 /* The type to which the method is attached, i.e., its parent class. */
383 /* The index of the method in the type's function fieldlists. */
386 /* The index of the method in the fieldlist. */
389 /* The name of the DIE. */
392 /* The DIE associated with this method. */
393 struct die_info
*die
;
396 /* Internal state when decoding a particular compilation unit. */
399 explicit dwarf2_cu (struct dwarf2_per_cu_data
*per_cu
);
402 DISABLE_COPY_AND_ASSIGN (dwarf2_cu
);
404 /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope.
405 Create the set of symtabs used by this TU, or if this TU is sharing
406 symtabs with another TU and the symtabs have already been created
407 then restore those symtabs in the line header.
408 We don't need the pc/line-number mapping for type units. */
409 void setup_type_unit_groups (struct die_info
*die
);
411 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
412 buildsym_compunit constructor. */
413 struct compunit_symtab
*start_symtab (const char *name
,
414 const char *comp_dir
,
417 /* Reset the builder. */
418 void reset_builder () { m_builder
.reset (); }
420 /* The header of the compilation unit. */
421 struct comp_unit_head header
{};
423 /* Base address of this compilation unit. */
424 CORE_ADDR base_address
= 0;
426 /* Non-zero if base_address has been set. */
429 /* The language we are debugging. */
430 enum language language
= language_unknown
;
431 const struct language_defn
*language_defn
= nullptr;
433 const char *producer
= nullptr;
436 /* The symtab builder for this CU. This is only non-NULL when full
437 symbols are being read. */
438 std::unique_ptr
<buildsym_compunit
> m_builder
;
441 /* The generic symbol table building routines have separate lists for
442 file scope symbols and all all other scopes (local scopes). So
443 we need to select the right one to pass to add_symbol_to_list().
444 We do it by keeping a pointer to the correct list in list_in_scope.
446 FIXME: The original dwarf code just treated the file scope as the
447 first local scope, and all other local scopes as nested local
448 scopes, and worked fine. Check to see if we really need to
449 distinguish these in buildsym.c. */
450 struct pending
**list_in_scope
= nullptr;
452 /* Hash table holding all the loaded partial DIEs
453 with partial_die->offset.SECT_OFF as hash. */
454 htab_t partial_dies
= nullptr;
456 /* Storage for things with the same lifetime as this read-in compilation
457 unit, including partial DIEs. */
458 auto_obstack comp_unit_obstack
;
460 /* When multiple dwarf2_cu structures are living in memory, this field
461 chains them all together, so that they can be released efficiently.
462 We will probably also want a generation counter so that most-recently-used
463 compilation units are cached... */
464 struct dwarf2_per_cu_data
*read_in_chain
= nullptr;
466 /* Backlink to our per_cu entry. */
467 struct dwarf2_per_cu_data
*per_cu
;
469 /* How many compilation units ago was this CU last referenced? */
472 /* A hash table of DIE cu_offset for following references with
473 die_info->offset.sect_off as hash. */
474 htab_t die_hash
= nullptr;
476 /* Full DIEs if read in. */
477 struct die_info
*dies
= nullptr;
479 /* A set of pointers to dwarf2_per_cu_data objects for compilation
480 units referenced by this one. Only set during full symbol processing;
481 partial symbol tables do not have dependencies. */
482 htab_t dependencies
= nullptr;
484 /* Header data from the line table, during full symbol processing. */
485 struct line_header
*line_header
= nullptr;
486 /* Non-NULL if LINE_HEADER is owned by this DWARF_CU. Otherwise,
487 it's owned by dwarf2_per_objfile::line_header_hash. If non-NULL,
488 this is the DW_TAG_compile_unit die for this CU. We'll hold on
489 to the line header as long as this DIE is being processed. See
490 process_die_scope. */
491 die_info
*line_header_die_owner
= nullptr;
493 /* A list of methods which need to have physnames computed
494 after all type information has been read. */
495 std::vector
<delayed_method_info
> method_list
;
497 /* To be copied to symtab->call_site_htab. */
498 htab_t call_site_htab
= nullptr;
500 /* Non-NULL if this CU came from a DWO file.
501 There is an invariant here that is important to remember:
502 Except for attributes copied from the top level DIE in the "main"
503 (or "stub") file in preparation for reading the DWO file
504 (e.g., DW_AT_addr_base), we KISS: there is only *one* CU.
505 Either there isn't a DWO file (in which case this is NULL and the point
506 is moot), or there is and either we're not going to read it (in which
507 case this is NULL) or there is and we are reading it (in which case this
509 struct dwo_unit
*dwo_unit
= nullptr;
511 /* The DW_AT_addr_base (DW_AT_GNU_addr_base) attribute if present.
512 Note this value comes from the Fission stub CU/TU's DIE. */
513 gdb::optional
<ULONGEST
> addr_base
;
515 /* The DW_AT_rnglists_base attribute if present.
516 Note this value comes from the Fission stub CU/TU's DIE.
517 Also note that the value is zero in the non-DWO case so this value can
518 be used without needing to know whether DWO files are in use or not.
519 N.B. This does not apply to DW_AT_ranges appearing in
520 DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever
521 DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then
522 DW_AT_rnglists_base *would* have to be applied, and we'd have to care
523 whether the DW_AT_ranges attribute came from the skeleton or DWO. */
524 ULONGEST ranges_base
= 0;
526 /* When reading debug info generated by older versions of rustc, we
527 have to rewrite some union types to be struct types with a
528 variant part. This rewriting must be done after the CU is fully
529 read in, because otherwise at the point of rewriting some struct
530 type might not have been fully processed. So, we keep a list of
531 all such types here and process them after expansion. */
532 std::vector
<struct type
*> rust_unions
;
534 /* The DW_AT_str_offsets_base attribute if present. For DWARF 4 version DWO
535 files, the value is implicitly zero. For DWARF 5 version DWO files, the
536 value is often implicit and is the size of the header of
537 .debug_str_offsets section (8 or 4, depending on the address size). */
538 gdb::optional
<ULONGEST
> str_offsets_base
;
540 /* Mark used when releasing cached dies. */
543 /* This CU references .debug_loc. See the symtab->locations_valid field.
544 This test is imperfect as there may exist optimized debug code not using
545 any location list and still facing inlining issues if handled as
546 unoptimized code. For a future better test see GCC PR other/32998. */
547 bool has_loclist
: 1;
549 /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is true
550 if all the producer_is_* fields are valid. This information is cached
551 because profiling CU expansion showed excessive time spent in
552 producer_is_gxx_lt_4_6. */
553 bool checked_producer
: 1;
554 bool producer_is_gxx_lt_4_6
: 1;
555 bool producer_is_gcc_lt_4_3
: 1;
556 bool producer_is_icc
: 1;
557 bool producer_is_icc_lt_14
: 1;
558 bool producer_is_codewarrior
: 1;
560 /* When true, the file that we're processing is known to have
561 debugging info for C++ namespaces. GCC 3.3.x did not produce
562 this information, but later versions do. */
564 bool processing_has_namespace_info
: 1;
566 struct partial_die_info
*find_partial_die (sect_offset sect_off
);
568 /* If this CU was inherited by another CU (via specification,
569 abstract_origin, etc), this is the ancestor CU. */
572 /* Get the buildsym_compunit for this CU. */
573 buildsym_compunit
*get_builder ()
575 /* If this CU has a builder associated with it, use that. */
576 if (m_builder
!= nullptr)
577 return m_builder
.get ();
579 /* Otherwise, search ancestors for a valid builder. */
580 if (ancestor
!= nullptr)
581 return ancestor
->get_builder ();
587 /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list.
588 This includes type_unit_group and quick_file_names. */
590 struct stmt_list_hash
592 /* The DWO unit this table is from or NULL if there is none. */
593 struct dwo_unit
*dwo_unit
;
595 /* Offset in .debug_line or .debug_line.dwo. */
596 sect_offset line_sect_off
;
599 /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to
600 an object of this type. */
602 struct type_unit_group
604 /* dwarf2read.c's main "handle" on a TU symtab.
605 To simplify things we create an artificial CU that "includes" all the
606 type units using this stmt_list so that the rest of the code still has
607 a "per_cu" handle on the symtab.
608 This PER_CU is recognized by having no section. */
609 #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->section == NULL)
610 struct dwarf2_per_cu_data per_cu
;
612 /* The TUs that share this DW_AT_stmt_list entry.
613 This is added to while parsing type units to build partial symtabs,
614 and is deleted afterwards and not used again. */
615 std::vector
<signatured_type
*> *tus
;
617 /* The compunit symtab.
618 Type units in a group needn't all be defined in the same source file,
619 so we create an essentially anonymous symtab as the compunit symtab. */
620 struct compunit_symtab
*compunit_symtab
;
622 /* The data used to construct the hash key. */
623 struct stmt_list_hash hash
;
625 /* The number of symtabs from the line header.
626 The value here must match line_header.num_file_names. */
627 unsigned int num_symtabs
;
629 /* The symbol tables for this TU (obtained from the files listed in
631 WARNING: The order of entries here must match the order of entries
632 in the line header. After the first TU using this type_unit_group, the
633 line header for the subsequent TUs is recreated from this. This is done
634 because we need to use the same symtabs for each TU using the same
635 DW_AT_stmt_list value. Also note that symtabs may be repeated here,
636 there's no guarantee the line header doesn't have duplicate entries. */
637 struct symtab
**symtabs
;
640 /* These sections are what may appear in a (real or virtual) DWO file. */
644 struct dwarf2_section_info abbrev
;
645 struct dwarf2_section_info line
;
646 struct dwarf2_section_info loc
;
647 struct dwarf2_section_info loclists
;
648 struct dwarf2_section_info macinfo
;
649 struct dwarf2_section_info macro
;
650 struct dwarf2_section_info str
;
651 struct dwarf2_section_info str_offsets
;
652 /* In the case of a virtual DWO file, these two are unused. */
653 struct dwarf2_section_info info
;
654 std::vector
<dwarf2_section_info
> types
;
657 /* CUs/TUs in DWP/DWO files. */
661 /* Backlink to the containing struct dwo_file. */
662 struct dwo_file
*dwo_file
;
664 /* The "id" that distinguishes this CU/TU.
665 .debug_info calls this "dwo_id", .debug_types calls this "signature".
666 Since signatures came first, we stick with it for consistency. */
669 /* The section this CU/TU lives in, in the DWO file. */
670 struct dwarf2_section_info
*section
;
672 /* Same as dwarf2_per_cu_data:{sect_off,length} but in the DWO section. */
673 sect_offset sect_off
;
676 /* For types, offset in the type's DIE of the type defined by this TU. */
677 cu_offset type_offset_in_tu
;
680 /* include/dwarf2.h defines the DWP section codes.
681 It defines a max value but it doesn't define a min value, which we
682 use for error checking, so provide one. */
684 enum dwp_v2_section_ids
689 /* Data for one DWO file.
691 This includes virtual DWO files (a virtual DWO file is a DWO file as it
692 appears in a DWP file). DWP files don't really have DWO files per se -
693 comdat folding of types "loses" the DWO file they came from, and from
694 a high level view DWP files appear to contain a mass of random types.
695 However, to maintain consistency with the non-DWP case we pretend DWP
696 files contain virtual DWO files, and we assign each TU with one virtual
697 DWO file (generally based on the line and abbrev section offsets -
698 a heuristic that seems to work in practice). */
702 dwo_file () = default;
703 DISABLE_COPY_AND_ASSIGN (dwo_file
);
705 /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
706 For virtual DWO files the name is constructed from the section offsets
707 of abbrev,line,loc,str_offsets so that we combine virtual DWO files
708 from related CU+TUs. */
709 const char *dwo_name
= nullptr;
711 /* The DW_AT_comp_dir attribute. */
712 const char *comp_dir
= nullptr;
714 /* The bfd, when the file is open. Otherwise this is NULL.
715 This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
716 gdb_bfd_ref_ptr dbfd
;
718 /* The sections that make up this DWO file.
719 Remember that for virtual DWO files in DWP V2, these are virtual
720 sections (for lack of a better name). */
721 struct dwo_sections sections
{};
723 /* The CUs in the file.
724 Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
725 an extension to handle LLVM's Link Time Optimization output (where
726 multiple source files may be compiled into a single object/dwo pair). */
729 /* Table of TUs in the file.
730 Each element is a struct dwo_unit. */
734 /* These sections are what may appear in a DWP file. */
738 /* These are used by both DWP version 1 and 2. */
739 struct dwarf2_section_info str
;
740 struct dwarf2_section_info cu_index
;
741 struct dwarf2_section_info tu_index
;
743 /* These are only used by DWP version 2 files.
744 In DWP version 1 the .debug_info.dwo, .debug_types.dwo, and other
745 sections are referenced by section number, and are not recorded here.
746 In DWP version 2 there is at most one copy of all these sections, each
747 section being (effectively) comprised of the concatenation of all of the
748 individual sections that exist in the version 1 format.
749 To keep the code simple we treat each of these concatenated pieces as a
750 section itself (a virtual section?). */
751 struct dwarf2_section_info abbrev
;
752 struct dwarf2_section_info info
;
753 struct dwarf2_section_info line
;
754 struct dwarf2_section_info loc
;
755 struct dwarf2_section_info macinfo
;
756 struct dwarf2_section_info macro
;
757 struct dwarf2_section_info str_offsets
;
758 struct dwarf2_section_info types
;
761 /* These sections are what may appear in a virtual DWO file in DWP version 1.
762 A virtual DWO file is a DWO file as it appears in a DWP file. */
764 struct virtual_v1_dwo_sections
766 struct dwarf2_section_info abbrev
;
767 struct dwarf2_section_info line
;
768 struct dwarf2_section_info loc
;
769 struct dwarf2_section_info macinfo
;
770 struct dwarf2_section_info macro
;
771 struct dwarf2_section_info str_offsets
;
772 /* Each DWP hash table entry records one CU or one TU.
773 That is recorded here, and copied to dwo_unit.section. */
774 struct dwarf2_section_info info_or_types
;
777 /* Similar to virtual_v1_dwo_sections, but for DWP version 2.
778 In version 2, the sections of the DWO files are concatenated together
779 and stored in one section of that name. Thus each ELF section contains
780 several "virtual" sections. */
782 struct virtual_v2_dwo_sections
784 bfd_size_type abbrev_offset
;
785 bfd_size_type abbrev_size
;
787 bfd_size_type line_offset
;
788 bfd_size_type line_size
;
790 bfd_size_type loc_offset
;
791 bfd_size_type loc_size
;
793 bfd_size_type macinfo_offset
;
794 bfd_size_type macinfo_size
;
796 bfd_size_type macro_offset
;
797 bfd_size_type macro_size
;
799 bfd_size_type str_offsets_offset
;
800 bfd_size_type str_offsets_size
;
802 /* Each DWP hash table entry records one CU or one TU.
803 That is recorded here, and copied to dwo_unit.section. */
804 bfd_size_type info_or_types_offset
;
805 bfd_size_type info_or_types_size
;
808 /* Contents of DWP hash tables. */
810 struct dwp_hash_table
812 uint32_t version
, nr_columns
;
813 uint32_t nr_units
, nr_slots
;
814 const gdb_byte
*hash_table
, *unit_table
;
819 const gdb_byte
*indices
;
823 /* This is indexed by column number and gives the id of the section
825 #define MAX_NR_V2_DWO_SECTIONS \
826 (1 /* .debug_info or .debug_types */ \
827 + 1 /* .debug_abbrev */ \
828 + 1 /* .debug_line */ \
829 + 1 /* .debug_loc */ \
830 + 1 /* .debug_str_offsets */ \
831 + 1 /* .debug_macro or .debug_macinfo */)
832 int section_ids
[MAX_NR_V2_DWO_SECTIONS
];
833 const gdb_byte
*offsets
;
834 const gdb_byte
*sizes
;
839 /* Data for one DWP file. */
843 dwp_file (const char *name_
, gdb_bfd_ref_ptr
&&abfd
)
845 dbfd (std::move (abfd
))
849 /* Name of the file. */
852 /* File format version. */
856 gdb_bfd_ref_ptr dbfd
;
858 /* Section info for this file. */
859 struct dwp_sections sections
{};
861 /* Table of CUs in the file. */
862 const struct dwp_hash_table
*cus
= nullptr;
864 /* Table of TUs in the file. */
865 const struct dwp_hash_table
*tus
= nullptr;
867 /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */
868 htab_t loaded_cus
{};
869 htab_t loaded_tus
{};
871 /* Table to map ELF section numbers to their sections.
872 This is only needed for the DWP V1 file format. */
873 unsigned int num_sections
= 0;
874 asection
**elf_sections
= nullptr;
877 /* Struct used to pass misc. parameters to read_die_and_children, et
878 al. which are used for both .debug_info and .debug_types dies.
879 All parameters here are unchanging for the life of the call. This
880 struct exists to abstract away the constant parameters of die reading. */
882 struct die_reader_specs
884 /* The bfd of die_section. */
887 /* The CU of the DIE we are parsing. */
888 struct dwarf2_cu
*cu
;
890 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
891 struct dwo_file
*dwo_file
;
893 /* The section the die comes from.
894 This is either .debug_info or .debug_types, or the .dwo variants. */
895 struct dwarf2_section_info
*die_section
;
897 /* die_section->buffer. */
898 const gdb_byte
*buffer
;
900 /* The end of the buffer. */
901 const gdb_byte
*buffer_end
;
903 /* The value of the DW_AT_comp_dir attribute. */
904 const char *comp_dir
;
906 /* The abbreviation table to use when reading the DIEs. */
907 struct abbrev_table
*abbrev_table
;
910 /* Type of function passed to init_cutu_and_read_dies, et.al. */
911 typedef void (die_reader_func_ftype
) (const struct die_reader_specs
*reader
,
912 const gdb_byte
*info_ptr
,
913 struct die_info
*comp_unit_die
,
917 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
919 typedef int dir_index
;
921 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
923 typedef int file_name_index
;
927 file_entry () = default;
929 file_entry (const char *name_
, dir_index d_index_
,
930 unsigned int mod_time_
, unsigned int length_
)
933 mod_time (mod_time_
),
937 /* Return the include directory at D_INDEX stored in LH. Returns
938 NULL if D_INDEX is out of bounds. */
939 const char *include_dir (const line_header
*lh
) const;
941 /* The file name. Note this is an observing pointer. The memory is
942 owned by debug_line_buffer. */
945 /* The directory index (1-based). */
946 dir_index d_index
{};
948 unsigned int mod_time
{};
950 unsigned int length
{};
952 /* True if referenced by the Line Number Program. */
955 /* The associated symbol table, if any. */
956 struct symtab
*symtab
{};
959 /* The line number information for a compilation unit (found in the
960 .debug_line section) begins with a "statement program header",
961 which contains the following information. */
968 /* Add an entry to the include directory table. */
969 void add_include_dir (const char *include_dir
);
971 /* Add an entry to the file name table. */
972 void add_file_name (const char *name
, dir_index d_index
,
973 unsigned int mod_time
, unsigned int length
);
975 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
976 Returns NULL if INDEX is out of bounds. */
977 const char *include_dir_at (dir_index index
) const
983 vec_index
= index
- 1;
984 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
986 return m_include_dirs
[vec_index
];
989 bool is_valid_file_index (int file_index
)
992 return 0 <= file_index
&& file_index
< file_names_size ();
993 return 1 <= file_index
&& file_index
<= file_names_size ();
996 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
997 Returns NULL if INDEX is out of bounds. */
998 file_entry
*file_name_at (file_name_index index
)
1004 vec_index
= index
- 1;
1005 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1007 return &m_file_names
[vec_index
];
1010 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1011 this method should only be used to iterate through all file entries in an
1012 index-agnostic manner. */
1013 std::vector
<file_entry
> &file_names ()
1014 { return m_file_names
; }
1016 /* Offset of line number information in .debug_line section. */
1017 sect_offset sect_off
{};
1019 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1020 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1022 unsigned int total_length
{};
1023 unsigned short version
{};
1024 unsigned int header_length
{};
1025 unsigned char minimum_instruction_length
{};
1026 unsigned char maximum_ops_per_instruction
{};
1027 unsigned char default_is_stmt
{};
1029 unsigned char line_range
{};
1030 unsigned char opcode_base
{};
1032 /* standard_opcode_lengths[i] is the number of operands for the
1033 standard opcode whose value is i. This means that
1034 standard_opcode_lengths[0] is unused, and the last meaningful
1035 element is standard_opcode_lengths[opcode_base - 1]. */
1036 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1038 int file_names_size ()
1039 { return m_file_names
.size(); }
1041 /* The start and end of the statement program following this
1042 header. These point into dwarf2_per_objfile->line_buffer. */
1043 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1046 /* The include_directories table. Note these are observing
1047 pointers. The memory is owned by debug_line_buffer. */
1048 std::vector
<const char *> m_include_dirs
;
1050 /* The file_names table. This is private because the meaning of indexes
1051 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1052 before, and is 0 in DWARF 5 and later). So the client should use
1053 file_name_at method for access. */
1054 std::vector
<file_entry
> m_file_names
;
1057 typedef std::unique_ptr
<line_header
> line_header_up
;
1060 file_entry::include_dir (const line_header
*lh
) const
1062 return lh
->include_dir_at (d_index
);
1065 /* When we construct a partial symbol table entry we only
1066 need this much information. */
1067 struct partial_die_info
: public allocate_on_obstack
1069 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1071 /* Disable assign but still keep copy ctor, which is needed
1072 load_partial_dies. */
1073 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1075 /* Adjust the partial die before generating a symbol for it. This
1076 function may set the is_external flag or change the DIE's
1078 void fixup (struct dwarf2_cu
*cu
);
1080 /* Read a minimal amount of information into the minimal die
1082 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1083 const struct abbrev_info
&abbrev
,
1084 const gdb_byte
*info_ptr
);
1086 /* Offset of this DIE. */
1087 const sect_offset sect_off
;
1089 /* DWARF-2 tag for this DIE. */
1090 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1092 /* Assorted flags describing the data found in this DIE. */
1093 const unsigned int has_children
: 1;
1095 unsigned int is_external
: 1;
1096 unsigned int is_declaration
: 1;
1097 unsigned int has_type
: 1;
1098 unsigned int has_specification
: 1;
1099 unsigned int has_pc_info
: 1;
1100 unsigned int may_be_inlined
: 1;
1102 /* This DIE has been marked DW_AT_main_subprogram. */
1103 unsigned int main_subprogram
: 1;
1105 /* Flag set if the SCOPE field of this structure has been
1107 unsigned int scope_set
: 1;
1109 /* Flag set if the DIE has a byte_size attribute. */
1110 unsigned int has_byte_size
: 1;
1112 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1113 unsigned int has_const_value
: 1;
1115 /* Flag set if any of the DIE's children are template arguments. */
1116 unsigned int has_template_arguments
: 1;
1118 /* Flag set if fixup has been called on this die. */
1119 unsigned int fixup_called
: 1;
1121 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1122 unsigned int is_dwz
: 1;
1124 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1125 unsigned int spec_is_dwz
: 1;
1127 /* The name of this DIE. Normally the value of DW_AT_name, but
1128 sometimes a default name for unnamed DIEs. */
1129 const char *name
= nullptr;
1131 /* The linkage name, if present. */
1132 const char *linkage_name
= nullptr;
1134 /* The scope to prepend to our children. This is generally
1135 allocated on the comp_unit_obstack, so will disappear
1136 when this compilation unit leaves the cache. */
1137 const char *scope
= nullptr;
1139 /* Some data associated with the partial DIE. The tag determines
1140 which field is live. */
1143 /* The location description associated with this DIE, if any. */
1144 struct dwarf_block
*locdesc
;
1145 /* The offset of an import, for DW_TAG_imported_unit. */
1146 sect_offset sect_off
;
1149 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1150 CORE_ADDR lowpc
= 0;
1151 CORE_ADDR highpc
= 0;
1153 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1154 DW_AT_sibling, if any. */
1155 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1156 could return DW_AT_sibling values to its caller load_partial_dies. */
1157 const gdb_byte
*sibling
= nullptr;
1159 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1160 DW_AT_specification (or DW_AT_abstract_origin or
1161 DW_AT_extension). */
1162 sect_offset spec_offset
{};
1164 /* Pointers to this DIE's parent, first child, and next sibling,
1166 struct partial_die_info
*die_parent
= nullptr;
1167 struct partial_die_info
*die_child
= nullptr;
1168 struct partial_die_info
*die_sibling
= nullptr;
1170 friend struct partial_die_info
*
1171 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1174 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1175 partial_die_info (sect_offset sect_off
)
1176 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1180 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1182 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1187 has_specification
= 0;
1190 main_subprogram
= 0;
1193 has_const_value
= 0;
1194 has_template_arguments
= 0;
1201 /* This data structure holds the information of an abbrev. */
1204 unsigned int number
; /* number identifying abbrev */
1205 enum dwarf_tag tag
; /* dwarf tag */
1206 unsigned short has_children
; /* boolean */
1207 unsigned short num_attrs
; /* number of attributes */
1208 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1209 struct abbrev_info
*next
; /* next in chain */
1214 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1215 ENUM_BITFIELD(dwarf_form
) form
: 16;
1217 /* It is valid only if FORM is DW_FORM_implicit_const. */
1218 LONGEST implicit_const
;
1221 /* Size of abbrev_table.abbrev_hash_table. */
1222 #define ABBREV_HASH_SIZE 121
1224 /* Top level data structure to contain an abbreviation table. */
1228 explicit abbrev_table (sect_offset off
)
1232 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1233 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1236 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1238 /* Allocate space for a struct abbrev_info object in
1240 struct abbrev_info
*alloc_abbrev ();
1242 /* Add an abbreviation to the table. */
1243 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1245 /* Look up an abbrev in the table.
1246 Returns NULL if the abbrev is not found. */
1248 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1251 /* Where the abbrev table came from.
1252 This is used as a sanity check when the table is used. */
1253 const sect_offset sect_off
;
1255 /* Storage for the abbrev table. */
1256 auto_obstack abbrev_obstack
;
1260 /* Hash table of abbrevs.
1261 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1262 It could be statically allocated, but the previous code didn't so we
1264 struct abbrev_info
**m_abbrevs
;
1267 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
1269 /* Attributes have a name and a value. */
1272 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1273 ENUM_BITFIELD(dwarf_form
) form
: 15;
1275 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1276 field should be in u.str (existing only for DW_STRING) but it is kept
1277 here for better struct attribute alignment. */
1278 unsigned int string_is_canonical
: 1;
1283 struct dwarf_block
*blk
;
1292 /* This data structure holds a complete die structure. */
1295 /* DWARF-2 tag for this DIE. */
1296 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1298 /* Number of attributes */
1299 unsigned char num_attrs
;
1301 /* True if we're presently building the full type name for the
1302 type derived from this DIE. */
1303 unsigned char building_fullname
: 1;
1305 /* True if this die is in process. PR 16581. */
1306 unsigned char in_process
: 1;
1309 unsigned int abbrev
;
1311 /* Offset in .debug_info or .debug_types section. */
1312 sect_offset sect_off
;
1314 /* The dies in a compilation unit form an n-ary tree. PARENT
1315 points to this die's parent; CHILD points to the first child of
1316 this node; and all the children of a given node are chained
1317 together via their SIBLING fields. */
1318 struct die_info
*child
; /* Its first child, if any. */
1319 struct die_info
*sibling
; /* Its next sibling, if any. */
1320 struct die_info
*parent
; /* Its parent, if any. */
1322 /* An array of attributes, with NUM_ATTRS elements. There may be
1323 zero, but it's not common and zero-sized arrays are not
1324 sufficiently portable C. */
1325 struct attribute attrs
[1];
1328 /* Get at parts of an attribute structure. */
1330 #define DW_STRING(attr) ((attr)->u.str)
1331 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1332 #define DW_UNSND(attr) ((attr)->u.unsnd)
1333 #define DW_BLOCK(attr) ((attr)->u.blk)
1334 #define DW_SND(attr) ((attr)->u.snd)
1335 #define DW_ADDR(attr) ((attr)->u.addr)
1336 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1338 /* Blocks are a bunch of untyped bytes. */
1343 /* Valid only if SIZE is not zero. */
1344 const gdb_byte
*data
;
1347 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1348 but this would require a corresponding change in unpack_field_as_long
1350 static int bits_per_byte
= 8;
1352 /* When reading a variant or variant part, we track a bit more
1353 information about the field, and store it in an object of this
1356 struct variant_field
1358 /* If we see a DW_TAG_variant, then this will be the discriminant
1360 ULONGEST discriminant_value
;
1361 /* If we see a DW_TAG_variant, then this will be set if this is the
1363 bool default_branch
;
1364 /* While reading a DW_TAG_variant_part, this will be set if this
1365 field is the discriminant. */
1366 bool is_discriminant
;
1371 int accessibility
= 0;
1373 /* Extra information to describe a variant or variant part. */
1374 struct variant_field variant
{};
1375 struct field field
{};
1380 const char *name
= nullptr;
1381 std::vector
<struct fn_field
> fnfields
;
1384 /* The routines that read and process dies for a C struct or C++ class
1385 pass lists of data member fields and lists of member function fields
1386 in an instance of a field_info structure, as defined below. */
1389 /* List of data member and baseclasses fields. */
1390 std::vector
<struct nextfield
> fields
;
1391 std::vector
<struct nextfield
> baseclasses
;
1393 /* Number of fields (including baseclasses). */
1396 /* Set if the accessibility of one of the fields is not public. */
1397 int non_public_fields
= 0;
1399 /* Member function fieldlist array, contains name of possibly overloaded
1400 member function, number of overloaded member functions and a pointer
1401 to the head of the member function field chain. */
1402 std::vector
<struct fnfieldlist
> fnfieldlists
;
1404 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1405 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1406 std::vector
<struct decl_field
> typedef_field_list
;
1408 /* Nested types defined by this class and the number of elements in this
1410 std::vector
<struct decl_field
> nested_types_list
;
1413 /* One item on the queue of compilation units to read in full symbols
1415 struct dwarf2_queue_item
1417 struct dwarf2_per_cu_data
*per_cu
;
1418 enum language pretend_language
;
1419 struct dwarf2_queue_item
*next
;
1422 /* The current queue. */
1423 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1425 /* Loaded secondary compilation units are kept in memory until they
1426 have not been referenced for the processing of this many
1427 compilation units. Set this to zero to disable caching. Cache
1428 sizes of up to at least twenty will improve startup time for
1429 typical inter-CU-reference binaries, at an obvious memory cost. */
1430 static int dwarf_max_cache_age
= 5;
1432 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1433 struct cmd_list_element
*c
, const char *value
)
1435 fprintf_filtered (file
, _("The upper bound on the age of cached "
1436 "DWARF compilation units is %s.\n"),
1440 /* local function prototypes */
1442 static const char *get_section_name (const struct dwarf2_section_info
*);
1444 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1446 static void dwarf2_find_base_address (struct die_info
*die
,
1447 struct dwarf2_cu
*cu
);
1449 static struct partial_symtab
*create_partial_symtab
1450 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1452 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1453 const gdb_byte
*info_ptr
,
1454 struct die_info
*type_unit_die
,
1455 int has_children
, void *data
);
1457 static void dwarf2_build_psymtabs_hard
1458 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1460 static void scan_partial_symbols (struct partial_die_info
*,
1461 CORE_ADDR
*, CORE_ADDR
*,
1462 int, struct dwarf2_cu
*);
1464 static void add_partial_symbol (struct partial_die_info
*,
1465 struct dwarf2_cu
*);
1467 static void add_partial_namespace (struct partial_die_info
*pdi
,
1468 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1469 int set_addrmap
, struct dwarf2_cu
*cu
);
1471 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1472 CORE_ADDR
*highpc
, int set_addrmap
,
1473 struct dwarf2_cu
*cu
);
1475 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1476 struct dwarf2_cu
*cu
);
1478 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1479 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1480 int need_pc
, struct dwarf2_cu
*cu
);
1482 static void dwarf2_read_symtab (struct partial_symtab
*,
1485 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1487 static abbrev_table_up abbrev_table_read_table
1488 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1491 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1493 static struct partial_die_info
*load_partial_dies
1494 (const struct die_reader_specs
*, const gdb_byte
*, int);
1496 /* A pair of partial_die_info and compilation unit. */
1497 struct cu_partial_die_info
1499 /* The compilation unit of the partial_die_info. */
1500 struct dwarf2_cu
*cu
;
1501 /* A partial_die_info. */
1502 struct partial_die_info
*pdi
;
1504 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1510 cu_partial_die_info () = delete;
1513 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1514 struct dwarf2_cu
*);
1516 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1517 struct attribute
*, struct attr_abbrev
*,
1518 const gdb_byte
*, bool *need_reprocess
);
1520 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1521 struct attribute
*attr
);
1523 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1525 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1527 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1529 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1531 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1532 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1534 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1536 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1538 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1541 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1543 static LONGEST read_checked_initial_length_and_offset
1544 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1545 unsigned int *, unsigned int *);
1547 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1548 const struct comp_unit_head
*,
1551 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1553 static sect_offset read_abbrev_offset
1554 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1555 struct dwarf2_section_info
*, sect_offset
);
1557 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1559 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1561 static const char *read_indirect_string
1562 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1563 const struct comp_unit_head
*, unsigned int *);
1565 static const char *read_indirect_line_string
1566 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1567 const struct comp_unit_head
*, unsigned int *);
1569 static const char *read_indirect_string_at_offset
1570 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1571 LONGEST str_offset
);
1573 static const char *read_indirect_string_from_dwz
1574 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1576 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1578 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1582 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1583 ULONGEST str_index
);
1585 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1586 ULONGEST str_index
);
1588 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1590 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1591 struct dwarf2_cu
*);
1593 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1596 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1597 struct dwarf2_cu
*cu
);
1599 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1601 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1602 struct dwarf2_cu
*cu
);
1604 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1606 static struct die_info
*die_specification (struct die_info
*die
,
1607 struct dwarf2_cu
**);
1609 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1610 struct dwarf2_cu
*cu
);
1612 static void dwarf_decode_lines (struct line_header
*, const char *,
1613 struct dwarf2_cu
*, struct partial_symtab
*,
1614 CORE_ADDR
, int decode_mapping
);
1616 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1619 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1620 struct dwarf2_cu
*, struct symbol
* = NULL
);
1622 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1623 struct dwarf2_cu
*);
1625 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1628 struct obstack
*obstack
,
1629 struct dwarf2_cu
*cu
, LONGEST
*value
,
1630 const gdb_byte
**bytes
,
1631 struct dwarf2_locexpr_baton
**baton
);
1633 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1635 static int need_gnat_info (struct dwarf2_cu
*);
1637 static struct type
*die_descriptive_type (struct die_info
*,
1638 struct dwarf2_cu
*);
1640 static void set_descriptive_type (struct type
*, struct die_info
*,
1641 struct dwarf2_cu
*);
1643 static struct type
*die_containing_type (struct die_info
*,
1644 struct dwarf2_cu
*);
1646 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1647 struct dwarf2_cu
*);
1649 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1651 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1653 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1655 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1656 const char *suffix
, int physname
,
1657 struct dwarf2_cu
*cu
);
1659 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1661 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1663 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1665 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1667 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1669 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1671 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1672 struct dwarf2_cu
*, struct partial_symtab
*);
1674 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1675 values. Keep the items ordered with increasing constraints compliance. */
1678 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1679 PC_BOUNDS_NOT_PRESENT
,
1681 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1682 were present but they do not form a valid range of PC addresses. */
1685 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1688 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1692 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1693 CORE_ADDR
*, CORE_ADDR
*,
1695 struct partial_symtab
*);
1697 static void get_scope_pc_bounds (struct die_info
*,
1698 CORE_ADDR
*, CORE_ADDR
*,
1699 struct dwarf2_cu
*);
1701 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1702 CORE_ADDR
, struct dwarf2_cu
*);
1704 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1705 struct dwarf2_cu
*);
1707 static void dwarf2_attach_fields_to_type (struct field_info
*,
1708 struct type
*, struct dwarf2_cu
*);
1710 static void dwarf2_add_member_fn (struct field_info
*,
1711 struct die_info
*, struct type
*,
1712 struct dwarf2_cu
*);
1714 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1716 struct dwarf2_cu
*);
1718 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1720 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1722 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1724 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1726 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1728 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1730 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1732 static struct type
*read_module_type (struct die_info
*die
,
1733 struct dwarf2_cu
*cu
);
1735 static const char *namespace_name (struct die_info
*die
,
1736 int *is_anonymous
, struct dwarf2_cu
*);
1738 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1740 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1742 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1743 struct dwarf2_cu
*);
1745 static struct die_info
*read_die_and_siblings_1
1746 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1749 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1750 const gdb_byte
*info_ptr
,
1751 const gdb_byte
**new_info_ptr
,
1752 struct die_info
*parent
);
1754 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1755 struct die_info
**, const gdb_byte
*,
1758 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1759 struct die_info
**, const gdb_byte
*,
1762 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1764 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1767 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1769 static const char *dwarf2_full_name (const char *name
,
1770 struct die_info
*die
,
1771 struct dwarf2_cu
*cu
);
1773 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1774 struct dwarf2_cu
*cu
);
1776 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1777 struct dwarf2_cu
**);
1779 static const char *dwarf_tag_name (unsigned int);
1781 static const char *dwarf_attr_name (unsigned int);
1783 static const char *dwarf_unit_type_name (int unit_type
);
1785 static const char *dwarf_form_name (unsigned int);
1787 static const char *dwarf_bool_name (unsigned int);
1789 static const char *dwarf_type_encoding_name (unsigned int);
1791 static struct die_info
*sibling_die (struct die_info
*);
1793 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1795 static void dump_die_for_error (struct die_info
*);
1797 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1800 /*static*/ void dump_die (struct die_info
*, int max_level
);
1802 static void store_in_ref_table (struct die_info
*,
1803 struct dwarf2_cu
*);
1805 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1807 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1809 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1810 const struct attribute
*,
1811 struct dwarf2_cu
**);
1813 static struct die_info
*follow_die_ref (struct die_info
*,
1814 const struct attribute
*,
1815 struct dwarf2_cu
**);
1817 static struct die_info
*follow_die_sig (struct die_info
*,
1818 const struct attribute
*,
1819 struct dwarf2_cu
**);
1821 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1822 struct dwarf2_cu
*);
1824 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1825 const struct attribute
*,
1826 struct dwarf2_cu
*);
1828 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1830 static void read_signatured_type (struct signatured_type
*);
1832 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1833 struct die_info
*die
, struct dwarf2_cu
*cu
,
1834 struct dynamic_prop
*prop
, struct type
*type
);
1836 /* memory allocation interface */
1838 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1840 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1842 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1844 static int attr_form_is_block (const struct attribute
*);
1846 static int attr_form_is_section_offset (const struct attribute
*);
1848 static int attr_form_is_constant (const struct attribute
*);
1850 static int attr_form_is_ref (const struct attribute
*);
1852 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1853 struct dwarf2_loclist_baton
*baton
,
1854 const struct attribute
*attr
);
1856 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1858 struct dwarf2_cu
*cu
,
1861 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1862 const gdb_byte
*info_ptr
,
1863 struct abbrev_info
*abbrev
);
1865 static hashval_t
partial_die_hash (const void *item
);
1867 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1869 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1870 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1871 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1873 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1874 struct die_info
*comp_unit_die
,
1875 enum language pretend_language
);
1877 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1879 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1881 static struct type
*set_die_type (struct die_info
*, struct type
*,
1882 struct dwarf2_cu
*);
1884 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1886 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1888 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1891 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1894 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1897 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1898 struct dwarf2_per_cu_data
*);
1900 static void dwarf2_mark (struct dwarf2_cu
*);
1902 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1904 static struct type
*get_die_type_at_offset (sect_offset
,
1905 struct dwarf2_per_cu_data
*);
1907 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1909 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1910 enum language pretend_language
);
1912 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1914 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1915 static struct type
*dwarf2_per_cu_addr_sized_int_type
1916 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1917 static struct type
*dwarf2_per_cu_int_type
1918 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1921 /* Class, the destructor of which frees all allocated queue entries. This
1922 will only have work to do if an error was thrown while processing the
1923 dwarf. If no error was thrown then the queue entries should have all
1924 been processed, and freed, as we went along. */
1926 class dwarf2_queue_guard
1929 dwarf2_queue_guard () = default;
1931 /* Free any entries remaining on the queue. There should only be
1932 entries left if we hit an error while processing the dwarf. */
1933 ~dwarf2_queue_guard ()
1935 struct dwarf2_queue_item
*item
, *last
;
1937 item
= dwarf2_queue
;
1940 /* Anything still marked queued is likely to be in an
1941 inconsistent state, so discard it. */
1942 if (item
->per_cu
->queued
)
1944 if (item
->per_cu
->cu
!= NULL
)
1945 free_one_cached_comp_unit (item
->per_cu
);
1946 item
->per_cu
->queued
= 0;
1954 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1958 /* The return type of find_file_and_directory. Note, the enclosed
1959 string pointers are only valid while this object is valid. */
1961 struct file_and_directory
1963 /* The filename. This is never NULL. */
1966 /* The compilation directory. NULL if not known. If we needed to
1967 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1968 points directly to the DW_AT_comp_dir string attribute owned by
1969 the obstack that owns the DIE. */
1970 const char *comp_dir
;
1972 /* If we needed to build a new string for comp_dir, this is what
1973 owns the storage. */
1974 std::string comp_dir_storage
;
1977 static file_and_directory
find_file_and_directory (struct die_info
*die
,
1978 struct dwarf2_cu
*cu
);
1980 static char *file_full_name (int file
, struct line_header
*lh
,
1981 const char *comp_dir
);
1983 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
1984 enum class rcuh_kind
{ COMPILE
, TYPE
};
1986 static const gdb_byte
*read_and_check_comp_unit_head
1987 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
1988 struct comp_unit_head
*header
,
1989 struct dwarf2_section_info
*section
,
1990 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
1991 rcuh_kind section_kind
);
1993 static void init_cutu_and_read_dies
1994 (struct dwarf2_per_cu_data
*this_cu
, struct abbrev_table
*abbrev_table
,
1995 int use_existing_cu
, int keep
, bool skip_partial
,
1996 die_reader_func_ftype
*die_reader_func
, void *data
);
1998 static void init_cutu_and_read_dies_simple
1999 (struct dwarf2_per_cu_data
*this_cu
,
2000 die_reader_func_ftype
*die_reader_func
, void *data
);
2002 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2004 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2006 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2007 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2008 struct dwp_file
*dwp_file
, const char *comp_dir
,
2009 ULONGEST signature
, int is_debug_types
);
2011 static struct dwp_file
*get_dwp_file
2012 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2014 static struct dwo_unit
*lookup_dwo_comp_unit
2015 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2017 static struct dwo_unit
*lookup_dwo_type_unit
2018 (struct signatured_type
*, const char *, const char *);
2020 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2022 /* A unique pointer to a dwo_file. */
2024 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2026 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2028 static void check_producer (struct dwarf2_cu
*cu
);
2030 static void free_line_header_voidp (void *arg
);
2032 /* Various complaints about symbol reading that don't abort the process. */
2035 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2037 complaint (_("statement list doesn't fit in .debug_line section"));
2041 dwarf2_debug_line_missing_file_complaint (void)
2043 complaint (_(".debug_line section has line data without a file"));
2047 dwarf2_debug_line_missing_end_sequence_complaint (void)
2049 complaint (_(".debug_line section has line "
2050 "program sequence without an end"));
2054 dwarf2_complex_location_expr_complaint (void)
2056 complaint (_("location expression too complex"));
2060 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2063 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2068 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2070 complaint (_("debug info runs off end of %s section"
2072 get_section_name (section
),
2073 get_section_file_name (section
));
2077 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2079 complaint (_("macro debug info contains a "
2080 "malformed macro definition:\n`%s'"),
2085 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2087 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2091 /* Hash function for line_header_hash. */
2094 line_header_hash (const struct line_header
*ofs
)
2096 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2099 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2102 line_header_hash_voidp (const void *item
)
2104 const struct line_header
*ofs
= (const struct line_header
*) item
;
2106 return line_header_hash (ofs
);
2109 /* Equality function for line_header_hash. */
2112 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2114 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2115 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2117 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2118 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2123 /* Read the given attribute value as an address, taking the attribute's
2124 form into account. */
2127 attr_value_as_address (struct attribute
*attr
)
2131 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2132 && attr
->form
!= DW_FORM_GNU_addr_index
)
2134 /* Aside from a few clearly defined exceptions, attributes that
2135 contain an address must always be in DW_FORM_addr form.
2136 Unfortunately, some compilers happen to be violating this
2137 requirement by encoding addresses using other forms, such
2138 as DW_FORM_data4 for example. For those broken compilers,
2139 we try to do our best, without any guarantee of success,
2140 to interpret the address correctly. It would also be nice
2141 to generate a complaint, but that would require us to maintain
2142 a list of legitimate cases where a non-address form is allowed,
2143 as well as update callers to pass in at least the CU's DWARF
2144 version. This is more overhead than what we're willing to
2145 expand for a pretty rare case. */
2146 addr
= DW_UNSND (attr
);
2149 addr
= DW_ADDR (attr
);
2154 /* See declaration. */
2156 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2157 const dwarf2_debug_sections
*names
,
2159 : objfile (objfile_
),
2160 can_copy (can_copy_
)
2163 names
= &dwarf2_elf_names
;
2165 bfd
*obfd
= objfile
->obfd
;
2167 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2168 locate_sections (obfd
, sec
, *names
);
2171 dwarf2_per_objfile::~dwarf2_per_objfile ()
2173 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2174 free_cached_comp_units ();
2176 if (quick_file_names_table
)
2177 htab_delete (quick_file_names_table
);
2179 if (line_header_hash
)
2180 htab_delete (line_header_hash
);
2182 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2183 per_cu
->imported_symtabs_free ();
2185 for (signatured_type
*sig_type
: all_type_units
)
2186 sig_type
->per_cu
.imported_symtabs_free ();
2188 /* Everything else should be on the objfile obstack. */
2191 /* See declaration. */
2194 dwarf2_per_objfile::free_cached_comp_units ()
2196 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2197 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2198 while (per_cu
!= NULL
)
2200 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2203 *last_chain
= next_cu
;
2208 /* A helper class that calls free_cached_comp_units on
2211 class free_cached_comp_units
2215 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2216 : m_per_objfile (per_objfile
)
2220 ~free_cached_comp_units ()
2222 m_per_objfile
->free_cached_comp_units ();
2225 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2229 dwarf2_per_objfile
*m_per_objfile
;
2232 /* Try to locate the sections we need for DWARF 2 debugging
2233 information and return true if we have enough to do something.
2234 NAMES points to the dwarf2 section names, or is NULL if the standard
2235 ELF names are used. CAN_COPY is true for formats where symbol
2236 interposition is possible and so symbol values must follow copy
2237 relocation rules. */
2240 dwarf2_has_info (struct objfile
*objfile
,
2241 const struct dwarf2_debug_sections
*names
,
2244 if (objfile
->flags
& OBJF_READNEVER
)
2247 struct dwarf2_per_objfile
*dwarf2_per_objfile
2248 = get_dwarf2_per_objfile (objfile
);
2250 if (dwarf2_per_objfile
== NULL
)
2251 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2255 return (!dwarf2_per_objfile
->info
.is_virtual
2256 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2257 && !dwarf2_per_objfile
->abbrev
.is_virtual
2258 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2261 /* Return the containing section of virtual section SECTION. */
2263 static struct dwarf2_section_info
*
2264 get_containing_section (const struct dwarf2_section_info
*section
)
2266 gdb_assert (section
->is_virtual
);
2267 return section
->s
.containing_section
;
2270 /* Return the bfd owner of SECTION. */
2273 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2275 if (section
->is_virtual
)
2277 section
= get_containing_section (section
);
2278 gdb_assert (!section
->is_virtual
);
2280 return section
->s
.section
->owner
;
2283 /* Return the bfd section of SECTION.
2284 Returns NULL if the section is not present. */
2287 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2289 if (section
->is_virtual
)
2291 section
= get_containing_section (section
);
2292 gdb_assert (!section
->is_virtual
);
2294 return section
->s
.section
;
2297 /* Return the name of SECTION. */
2300 get_section_name (const struct dwarf2_section_info
*section
)
2302 asection
*sectp
= get_section_bfd_section (section
);
2304 gdb_assert (sectp
!= NULL
);
2305 return bfd_section_name (sectp
);
2308 /* Return the name of the file SECTION is in. */
2311 get_section_file_name (const struct dwarf2_section_info
*section
)
2313 bfd
*abfd
= get_section_bfd_owner (section
);
2315 return bfd_get_filename (abfd
);
2318 /* Return the id of SECTION.
2319 Returns 0 if SECTION doesn't exist. */
2322 get_section_id (const struct dwarf2_section_info
*section
)
2324 asection
*sectp
= get_section_bfd_section (section
);
2331 /* Return the flags of SECTION.
2332 SECTION (or containing section if this is a virtual section) must exist. */
2335 get_section_flags (const struct dwarf2_section_info
*section
)
2337 asection
*sectp
= get_section_bfd_section (section
);
2339 gdb_assert (sectp
!= NULL
);
2340 return bfd_section_flags (sectp
);
2343 /* When loading sections, we look either for uncompressed section or for
2344 compressed section names. */
2347 section_is_p (const char *section_name
,
2348 const struct dwarf2_section_names
*names
)
2350 if (names
->normal
!= NULL
2351 && strcmp (section_name
, names
->normal
) == 0)
2353 if (names
->compressed
!= NULL
2354 && strcmp (section_name
, names
->compressed
) == 0)
2359 /* See declaration. */
2362 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2363 const dwarf2_debug_sections
&names
)
2365 flagword aflag
= bfd_section_flags (sectp
);
2367 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2370 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2371 > bfd_get_file_size (abfd
))
2373 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2374 warning (_("Discarding section %s which has a section size (%s"
2375 ") larger than the file size [in module %s]"),
2376 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2377 bfd_get_filename (abfd
));
2379 else if (section_is_p (sectp
->name
, &names
.info
))
2381 this->info
.s
.section
= sectp
;
2382 this->info
.size
= bfd_section_size (sectp
);
2384 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2386 this->abbrev
.s
.section
= sectp
;
2387 this->abbrev
.size
= bfd_section_size (sectp
);
2389 else if (section_is_p (sectp
->name
, &names
.line
))
2391 this->line
.s
.section
= sectp
;
2392 this->line
.size
= bfd_section_size (sectp
);
2394 else if (section_is_p (sectp
->name
, &names
.loc
))
2396 this->loc
.s
.section
= sectp
;
2397 this->loc
.size
= bfd_section_size (sectp
);
2399 else if (section_is_p (sectp
->name
, &names
.loclists
))
2401 this->loclists
.s
.section
= sectp
;
2402 this->loclists
.size
= bfd_section_size (sectp
);
2404 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2406 this->macinfo
.s
.section
= sectp
;
2407 this->macinfo
.size
= bfd_section_size (sectp
);
2409 else if (section_is_p (sectp
->name
, &names
.macro
))
2411 this->macro
.s
.section
= sectp
;
2412 this->macro
.size
= bfd_section_size (sectp
);
2414 else if (section_is_p (sectp
->name
, &names
.str
))
2416 this->str
.s
.section
= sectp
;
2417 this->str
.size
= bfd_section_size (sectp
);
2419 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2421 this->str_offsets
.s
.section
= sectp
;
2422 this->str_offsets
.size
= bfd_section_size (sectp
);
2424 else if (section_is_p (sectp
->name
, &names
.line_str
))
2426 this->line_str
.s
.section
= sectp
;
2427 this->line_str
.size
= bfd_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.addr
))
2431 this->addr
.s
.section
= sectp
;
2432 this->addr
.size
= bfd_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.frame
))
2436 this->frame
.s
.section
= sectp
;
2437 this->frame
.size
= bfd_section_size (sectp
);
2439 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2441 this->eh_frame
.s
.section
= sectp
;
2442 this->eh_frame
.size
= bfd_section_size (sectp
);
2444 else if (section_is_p (sectp
->name
, &names
.ranges
))
2446 this->ranges
.s
.section
= sectp
;
2447 this->ranges
.size
= bfd_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2451 this->rnglists
.s
.section
= sectp
;
2452 this->rnglists
.size
= bfd_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &names
.types
))
2456 struct dwarf2_section_info type_section
;
2458 memset (&type_section
, 0, sizeof (type_section
));
2459 type_section
.s
.section
= sectp
;
2460 type_section
.size
= bfd_section_size (sectp
);
2462 this->types
.push_back (type_section
);
2464 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2466 this->gdb_index
.s
.section
= sectp
;
2467 this->gdb_index
.size
= bfd_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2471 this->debug_names
.s
.section
= sectp
;
2472 this->debug_names
.size
= bfd_section_size (sectp
);
2474 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2476 this->debug_aranges
.s
.section
= sectp
;
2477 this->debug_aranges
.size
= bfd_section_size (sectp
);
2480 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2481 && bfd_section_vma (sectp
) == 0)
2482 this->has_section_at_zero
= true;
2485 /* A helper function that decides whether a section is empty,
2489 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2491 if (section
->is_virtual
)
2492 return section
->size
== 0;
2493 return section
->s
.section
== NULL
|| section
->size
== 0;
2496 /* See dwarf2read.h. */
2499 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2503 gdb_byte
*buf
, *retbuf
;
2507 info
->buffer
= NULL
;
2508 info
->readin
= true;
2510 if (dwarf2_section_empty_p (info
))
2513 sectp
= get_section_bfd_section (info
);
2515 /* If this is a virtual section we need to read in the real one first. */
2516 if (info
->is_virtual
)
2518 struct dwarf2_section_info
*containing_section
=
2519 get_containing_section (info
);
2521 gdb_assert (sectp
!= NULL
);
2522 if ((sectp
->flags
& SEC_RELOC
) != 0)
2524 error (_("Dwarf Error: DWP format V2 with relocations is not"
2525 " supported in section %s [in module %s]"),
2526 get_section_name (info
), get_section_file_name (info
));
2528 dwarf2_read_section (objfile
, containing_section
);
2529 /* Other code should have already caught virtual sections that don't
2531 gdb_assert (info
->virtual_offset
+ info
->size
2532 <= containing_section
->size
);
2533 /* If the real section is empty or there was a problem reading the
2534 section we shouldn't get here. */
2535 gdb_assert (containing_section
->buffer
!= NULL
);
2536 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2540 /* If the section has relocations, we must read it ourselves.
2541 Otherwise we attach it to the BFD. */
2542 if ((sectp
->flags
& SEC_RELOC
) == 0)
2544 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2548 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2551 /* When debugging .o files, we may need to apply relocations; see
2552 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2553 We never compress sections in .o files, so we only need to
2554 try this when the section is not compressed. */
2555 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2558 info
->buffer
= retbuf
;
2562 abfd
= get_section_bfd_owner (info
);
2563 gdb_assert (abfd
!= NULL
);
2565 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2566 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2568 error (_("Dwarf Error: Can't read DWARF data"
2569 " in section %s [in module %s]"),
2570 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2574 /* A helper function that returns the size of a section in a safe way.
2575 If you are positive that the section has been read before using the
2576 size, then it is safe to refer to the dwarf2_section_info object's
2577 "size" field directly. In other cases, you must call this
2578 function, because for compressed sections the size field is not set
2579 correctly until the section has been read. */
2581 static bfd_size_type
2582 dwarf2_section_size (struct objfile
*objfile
,
2583 struct dwarf2_section_info
*info
)
2586 dwarf2_read_section (objfile
, info
);
2590 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2594 dwarf2_get_section_info (struct objfile
*objfile
,
2595 enum dwarf2_section_enum sect
,
2596 asection
**sectp
, const gdb_byte
**bufp
,
2597 bfd_size_type
*sizep
)
2599 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2600 struct dwarf2_section_info
*info
;
2602 /* We may see an objfile without any DWARF, in which case we just
2613 case DWARF2_DEBUG_FRAME
:
2614 info
= &data
->frame
;
2616 case DWARF2_EH_FRAME
:
2617 info
= &data
->eh_frame
;
2620 gdb_assert_not_reached ("unexpected section");
2623 dwarf2_read_section (objfile
, info
);
2625 *sectp
= get_section_bfd_section (info
);
2626 *bufp
= info
->buffer
;
2627 *sizep
= info
->size
;
2630 /* A helper function to find the sections for a .dwz file. */
2633 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2635 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2637 /* Note that we only support the standard ELF names, because .dwz
2638 is ELF-only (at the time of writing). */
2639 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2641 dwz_file
->abbrev
.s
.section
= sectp
;
2642 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2644 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2646 dwz_file
->info
.s
.section
= sectp
;
2647 dwz_file
->info
.size
= bfd_section_size (sectp
);
2649 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2651 dwz_file
->str
.s
.section
= sectp
;
2652 dwz_file
->str
.size
= bfd_section_size (sectp
);
2654 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2656 dwz_file
->line
.s
.section
= sectp
;
2657 dwz_file
->line
.size
= bfd_section_size (sectp
);
2659 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2661 dwz_file
->macro
.s
.section
= sectp
;
2662 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2664 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2666 dwz_file
->gdb_index
.s
.section
= sectp
;
2667 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2669 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2671 dwz_file
->debug_names
.s
.section
= sectp
;
2672 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2676 /* See dwarf2read.h. */
2679 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2681 const char *filename
;
2682 bfd_size_type buildid_len_arg
;
2686 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2687 return dwarf2_per_objfile
->dwz_file
.get ();
2689 bfd_set_error (bfd_error_no_error
);
2690 gdb::unique_xmalloc_ptr
<char> data
2691 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2692 &buildid_len_arg
, &buildid
));
2695 if (bfd_get_error () == bfd_error_no_error
)
2697 error (_("could not read '.gnu_debugaltlink' section: %s"),
2698 bfd_errmsg (bfd_get_error ()));
2701 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2703 buildid_len
= (size_t) buildid_len_arg
;
2705 filename
= data
.get ();
2707 std::string abs_storage
;
2708 if (!IS_ABSOLUTE_PATH (filename
))
2710 gdb::unique_xmalloc_ptr
<char> abs
2711 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2713 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2714 filename
= abs_storage
.c_str ();
2717 /* First try the file name given in the section. If that doesn't
2718 work, try to use the build-id instead. */
2719 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2720 if (dwz_bfd
!= NULL
)
2722 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2723 dwz_bfd
.reset (nullptr);
2726 if (dwz_bfd
== NULL
)
2727 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2729 if (dwz_bfd
== NULL
)
2730 error (_("could not find '.gnu_debugaltlink' file for %s"),
2731 objfile_name (dwarf2_per_objfile
->objfile
));
2733 std::unique_ptr
<struct dwz_file
> result
2734 (new struct dwz_file (std::move (dwz_bfd
)));
2736 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2739 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2740 result
->dwz_bfd
.get ());
2741 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2742 return dwarf2_per_objfile
->dwz_file
.get ();
2745 /* DWARF quick_symbols_functions support. */
2747 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2748 unique line tables, so we maintain a separate table of all .debug_line
2749 derived entries to support the sharing.
2750 All the quick functions need is the list of file names. We discard the
2751 line_header when we're done and don't need to record it here. */
2752 struct quick_file_names
2754 /* The data used to construct the hash key. */
2755 struct stmt_list_hash hash
;
2757 /* The number of entries in file_names, real_names. */
2758 unsigned int num_file_names
;
2760 /* The file names from the line table, after being run through
2762 const char **file_names
;
2764 /* The file names from the line table after being run through
2765 gdb_realpath. These are computed lazily. */
2766 const char **real_names
;
2769 /* When using the index (and thus not using psymtabs), each CU has an
2770 object of this type. This is used to hold information needed by
2771 the various "quick" methods. */
2772 struct dwarf2_per_cu_quick_data
2774 /* The file table. This can be NULL if there was no file table
2775 or it's currently not read in.
2776 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2777 struct quick_file_names
*file_names
;
2779 /* The corresponding symbol table. This is NULL if symbols for this
2780 CU have not yet been read. */
2781 struct compunit_symtab
*compunit_symtab
;
2783 /* A temporary mark bit used when iterating over all CUs in
2784 expand_symtabs_matching. */
2785 unsigned int mark
: 1;
2787 /* True if we've tried to read the file table and found there isn't one.
2788 There will be no point in trying to read it again next time. */
2789 unsigned int no_file_data
: 1;
2792 /* Utility hash function for a stmt_list_hash. */
2795 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2799 if (stmt_list_hash
->dwo_unit
!= NULL
)
2800 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2801 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2805 /* Utility equality function for a stmt_list_hash. */
2808 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2809 const struct stmt_list_hash
*rhs
)
2811 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2813 if (lhs
->dwo_unit
!= NULL
2814 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2817 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2820 /* Hash function for a quick_file_names. */
2823 hash_file_name_entry (const void *e
)
2825 const struct quick_file_names
*file_data
2826 = (const struct quick_file_names
*) e
;
2828 return hash_stmt_list_entry (&file_data
->hash
);
2831 /* Equality function for a quick_file_names. */
2834 eq_file_name_entry (const void *a
, const void *b
)
2836 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2837 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2839 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2842 /* Delete function for a quick_file_names. */
2845 delete_file_name_entry (void *e
)
2847 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2850 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2852 xfree ((void*) file_data
->file_names
[i
]);
2853 if (file_data
->real_names
)
2854 xfree ((void*) file_data
->real_names
[i
]);
2857 /* The space for the struct itself lives on objfile_obstack,
2858 so we don't free it here. */
2861 /* Create a quick_file_names hash table. */
2864 create_quick_file_names_table (unsigned int nr_initial_entries
)
2866 return htab_create_alloc (nr_initial_entries
,
2867 hash_file_name_entry
, eq_file_name_entry
,
2868 delete_file_name_entry
, xcalloc
, xfree
);
2871 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2872 have to be created afterwards. You should call age_cached_comp_units after
2873 processing PER_CU->CU. dw2_setup must have been already called. */
2876 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2878 if (per_cu
->is_debug_types
)
2879 load_full_type_unit (per_cu
);
2881 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2883 if (per_cu
->cu
== NULL
)
2884 return; /* Dummy CU. */
2886 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2889 /* Read in the symbols for PER_CU. */
2892 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2894 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2896 /* Skip type_unit_groups, reading the type units they contain
2897 is handled elsewhere. */
2898 if (IS_TYPE_UNIT_GROUP (per_cu
))
2901 /* The destructor of dwarf2_queue_guard frees any entries left on
2902 the queue. After this point we're guaranteed to leave this function
2903 with the dwarf queue empty. */
2904 dwarf2_queue_guard q_guard
;
2906 if (dwarf2_per_objfile
->using_index
2907 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2908 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2910 queue_comp_unit (per_cu
, language_minimal
);
2911 load_cu (per_cu
, skip_partial
);
2913 /* If we just loaded a CU from a DWO, and we're working with an index
2914 that may badly handle TUs, load all the TUs in that DWO as well.
2915 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2916 if (!per_cu
->is_debug_types
2917 && per_cu
->cu
!= NULL
2918 && per_cu
->cu
->dwo_unit
!= NULL
2919 && dwarf2_per_objfile
->index_table
!= NULL
2920 && dwarf2_per_objfile
->index_table
->version
<= 7
2921 /* DWP files aren't supported yet. */
2922 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2923 queue_and_load_all_dwo_tus (per_cu
);
2926 process_queue (dwarf2_per_objfile
);
2928 /* Age the cache, releasing compilation units that have not
2929 been used recently. */
2930 age_cached_comp_units (dwarf2_per_objfile
);
2933 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2934 the objfile from which this CU came. Returns the resulting symbol
2937 static struct compunit_symtab
*
2938 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2940 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2942 gdb_assert (dwarf2_per_objfile
->using_index
);
2943 if (!per_cu
->v
.quick
->compunit_symtab
)
2945 free_cached_comp_units
freer (dwarf2_per_objfile
);
2946 scoped_restore decrementer
= increment_reading_symtab ();
2947 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2948 process_cu_includes (dwarf2_per_objfile
);
2951 return per_cu
->v
.quick
->compunit_symtab
;
2954 /* See declaration. */
2956 dwarf2_per_cu_data
*
2957 dwarf2_per_objfile::get_cutu (int index
)
2959 if (index
>= this->all_comp_units
.size ())
2961 index
-= this->all_comp_units
.size ();
2962 gdb_assert (index
< this->all_type_units
.size ());
2963 return &this->all_type_units
[index
]->per_cu
;
2966 return this->all_comp_units
[index
];
2969 /* See declaration. */
2971 dwarf2_per_cu_data
*
2972 dwarf2_per_objfile::get_cu (int index
)
2974 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2976 return this->all_comp_units
[index
];
2979 /* See declaration. */
2982 dwarf2_per_objfile::get_tu (int index
)
2984 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
2986 return this->all_type_units
[index
];
2989 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
2990 objfile_obstack, and constructed with the specified field
2993 static dwarf2_per_cu_data
*
2994 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2995 struct dwarf2_section_info
*section
,
2997 sect_offset sect_off
, ULONGEST length
)
2999 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3000 dwarf2_per_cu_data
*the_cu
3001 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3002 struct dwarf2_per_cu_data
);
3003 the_cu
->sect_off
= sect_off
;
3004 the_cu
->length
= length
;
3005 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3006 the_cu
->section
= section
;
3007 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3008 struct dwarf2_per_cu_quick_data
);
3009 the_cu
->is_dwz
= is_dwz
;
3013 /* A helper for create_cus_from_index that handles a given list of
3017 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3018 const gdb_byte
*cu_list
, offset_type n_elements
,
3019 struct dwarf2_section_info
*section
,
3022 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3024 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3026 sect_offset sect_off
3027 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3028 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3031 dwarf2_per_cu_data
*per_cu
3032 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3034 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3038 /* Read the CU list from the mapped index, and use it to create all
3039 the CU objects for this objfile. */
3042 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3043 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3044 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3046 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3047 dwarf2_per_objfile
->all_comp_units
.reserve
3048 ((cu_list_elements
+ dwz_elements
) / 2);
3050 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3051 &dwarf2_per_objfile
->info
, 0);
3053 if (dwz_elements
== 0)
3056 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3057 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3061 /* Create the signatured type hash table from the index. */
3064 create_signatured_type_table_from_index
3065 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3066 struct dwarf2_section_info
*section
,
3067 const gdb_byte
*bytes
,
3068 offset_type elements
)
3070 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3072 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3073 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3075 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3077 for (offset_type i
= 0; i
< elements
; i
+= 3)
3079 struct signatured_type
*sig_type
;
3082 cu_offset type_offset_in_tu
;
3084 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3085 sect_offset sect_off
3086 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3088 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3090 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3093 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3094 struct signatured_type
);
3095 sig_type
->signature
= signature
;
3096 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3097 sig_type
->per_cu
.is_debug_types
= 1;
3098 sig_type
->per_cu
.section
= section
;
3099 sig_type
->per_cu
.sect_off
= sect_off
;
3100 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3101 sig_type
->per_cu
.v
.quick
3102 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3103 struct dwarf2_per_cu_quick_data
);
3105 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3108 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3111 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3114 /* Create the signatured type hash table from .debug_names. */
3117 create_signatured_type_table_from_debug_names
3118 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3119 const mapped_debug_names
&map
,
3120 struct dwarf2_section_info
*section
,
3121 struct dwarf2_section_info
*abbrev_section
)
3123 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3125 dwarf2_read_section (objfile
, section
);
3126 dwarf2_read_section (objfile
, abbrev_section
);
3128 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3129 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3131 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3133 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3135 struct signatured_type
*sig_type
;
3138 sect_offset sect_off
3139 = (sect_offset
) (extract_unsigned_integer
3140 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3142 map
.dwarf5_byte_order
));
3144 comp_unit_head cu_header
;
3145 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3147 section
->buffer
+ to_underlying (sect_off
),
3150 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3151 struct signatured_type
);
3152 sig_type
->signature
= cu_header
.signature
;
3153 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3154 sig_type
->per_cu
.is_debug_types
= 1;
3155 sig_type
->per_cu
.section
= section
;
3156 sig_type
->per_cu
.sect_off
= sect_off
;
3157 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3158 sig_type
->per_cu
.v
.quick
3159 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3160 struct dwarf2_per_cu_quick_data
);
3162 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3165 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3168 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3171 /* Read the address map data from the mapped index, and use it to
3172 populate the objfile's psymtabs_addrmap. */
3175 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3176 struct mapped_index
*index
)
3178 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3179 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3180 const gdb_byte
*iter
, *end
;
3181 struct addrmap
*mutable_map
;
3184 auto_obstack temp_obstack
;
3186 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3188 iter
= index
->address_table
.data ();
3189 end
= iter
+ index
->address_table
.size ();
3191 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3195 ULONGEST hi
, lo
, cu_index
;
3196 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3198 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3200 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3205 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3206 hex_string (lo
), hex_string (hi
));
3210 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3212 complaint (_(".gdb_index address table has invalid CU number %u"),
3213 (unsigned) cu_index
);
3217 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3218 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3219 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3220 dwarf2_per_objfile
->get_cu (cu_index
));
3223 objfile
->partial_symtabs
->psymtabs_addrmap
3224 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3227 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3228 populate the objfile's psymtabs_addrmap. */
3231 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3232 struct dwarf2_section_info
*section
)
3234 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3235 bfd
*abfd
= objfile
->obfd
;
3236 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3237 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
3239 auto_obstack temp_obstack
;
3240 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3242 std::unordered_map
<sect_offset
,
3243 dwarf2_per_cu_data
*,
3244 gdb::hash_enum
<sect_offset
>>
3245 debug_info_offset_to_per_cu
;
3246 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3248 const auto insertpair
3249 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3250 if (!insertpair
.second
)
3252 warning (_("Section .debug_aranges in %s has duplicate "
3253 "debug_info_offset %s, ignoring .debug_aranges."),
3254 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3259 dwarf2_read_section (objfile
, section
);
3261 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3263 const gdb_byte
*addr
= section
->buffer
;
3265 while (addr
< section
->buffer
+ section
->size
)
3267 const gdb_byte
*const entry_addr
= addr
;
3268 unsigned int bytes_read
;
3270 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3274 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3275 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3276 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3277 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3279 warning (_("Section .debug_aranges in %s entry at offset %s "
3280 "length %s exceeds section length %s, "
3281 "ignoring .debug_aranges."),
3282 objfile_name (objfile
),
3283 plongest (entry_addr
- section
->buffer
),
3284 plongest (bytes_read
+ entry_length
),
3285 pulongest (section
->size
));
3289 /* The version number. */
3290 const uint16_t version
= read_2_bytes (abfd
, addr
);
3294 warning (_("Section .debug_aranges in %s entry at offset %s "
3295 "has unsupported version %d, ignoring .debug_aranges."),
3296 objfile_name (objfile
),
3297 plongest (entry_addr
- section
->buffer
), version
);
3301 const uint64_t debug_info_offset
3302 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3303 addr
+= offset_size
;
3304 const auto per_cu_it
3305 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3306 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3308 warning (_("Section .debug_aranges in %s entry at offset %s "
3309 "debug_info_offset %s does not exists, "
3310 "ignoring .debug_aranges."),
3311 objfile_name (objfile
),
3312 plongest (entry_addr
- section
->buffer
),
3313 pulongest (debug_info_offset
));
3316 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3318 const uint8_t address_size
= *addr
++;
3319 if (address_size
< 1 || address_size
> 8)
3321 warning (_("Section .debug_aranges in %s entry at offset %s "
3322 "address_size %u is invalid, ignoring .debug_aranges."),
3323 objfile_name (objfile
),
3324 plongest (entry_addr
- section
->buffer
), address_size
);
3328 const uint8_t segment_selector_size
= *addr
++;
3329 if (segment_selector_size
!= 0)
3331 warning (_("Section .debug_aranges in %s entry at offset %s "
3332 "segment_selector_size %u is not supported, "
3333 "ignoring .debug_aranges."),
3334 objfile_name (objfile
),
3335 plongest (entry_addr
- section
->buffer
),
3336 segment_selector_size
);
3340 /* Must pad to an alignment boundary that is twice the address
3341 size. It is undocumented by the DWARF standard but GCC does
3343 for (size_t padding
= ((-(addr
- section
->buffer
))
3344 & (2 * address_size
- 1));
3345 padding
> 0; padding
--)
3348 warning (_("Section .debug_aranges in %s entry at offset %s "
3349 "padding is not zero, ignoring .debug_aranges."),
3350 objfile_name (objfile
),
3351 plongest (entry_addr
- section
->buffer
));
3357 if (addr
+ 2 * address_size
> entry_end
)
3359 warning (_("Section .debug_aranges in %s entry at offset %s "
3360 "address list is not properly terminated, "
3361 "ignoring .debug_aranges."),
3362 objfile_name (objfile
),
3363 plongest (entry_addr
- section
->buffer
));
3366 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3368 addr
+= address_size
;
3369 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3371 addr
+= address_size
;
3372 if (start
== 0 && length
== 0)
3374 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3376 /* Symbol was eliminated due to a COMDAT group. */
3379 ULONGEST end
= start
+ length
;
3380 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3382 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3384 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3388 objfile
->partial_symtabs
->psymtabs_addrmap
3389 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3392 /* Find a slot in the mapped index INDEX for the object named NAME.
3393 If NAME is found, set *VEC_OUT to point to the CU vector in the
3394 constant pool and return true. If NAME cannot be found, return
3398 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3399 offset_type
**vec_out
)
3402 offset_type slot
, step
;
3403 int (*cmp
) (const char *, const char *);
3405 gdb::unique_xmalloc_ptr
<char> without_params
;
3406 if (current_language
->la_language
== language_cplus
3407 || current_language
->la_language
== language_fortran
3408 || current_language
->la_language
== language_d
)
3410 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3413 if (strchr (name
, '(') != NULL
)
3415 without_params
= cp_remove_params (name
);
3417 if (without_params
!= NULL
)
3418 name
= without_params
.get ();
3422 /* Index version 4 did not support case insensitive searches. But the
3423 indices for case insensitive languages are built in lowercase, therefore
3424 simulate our NAME being searched is also lowercased. */
3425 hash
= mapped_index_string_hash ((index
->version
== 4
3426 && case_sensitivity
== case_sensitive_off
3427 ? 5 : index
->version
),
3430 slot
= hash
& (index
->symbol_table
.size () - 1);
3431 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3432 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3438 const auto &bucket
= index
->symbol_table
[slot
];
3439 if (bucket
.name
== 0 && bucket
.vec
== 0)
3442 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3443 if (!cmp (name
, str
))
3445 *vec_out
= (offset_type
*) (index
->constant_pool
3446 + MAYBE_SWAP (bucket
.vec
));
3450 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3454 /* A helper function that reads the .gdb_index from BUFFER and fills
3455 in MAP. FILENAME is the name of the file containing the data;
3456 it is used for error reporting. DEPRECATED_OK is true if it is
3457 ok to use deprecated sections.
3459 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3460 out parameters that are filled in with information about the CU and
3461 TU lists in the section.
3463 Returns true if all went well, false otherwise. */
3466 read_gdb_index_from_buffer (struct objfile
*objfile
,
3467 const char *filename
,
3469 gdb::array_view
<const gdb_byte
> buffer
,
3470 struct mapped_index
*map
,
3471 const gdb_byte
**cu_list
,
3472 offset_type
*cu_list_elements
,
3473 const gdb_byte
**types_list
,
3474 offset_type
*types_list_elements
)
3476 const gdb_byte
*addr
= &buffer
[0];
3478 /* Version check. */
3479 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3480 /* Versions earlier than 3 emitted every copy of a psymbol. This
3481 causes the index to behave very poorly for certain requests. Version 3
3482 contained incomplete addrmap. So, it seems better to just ignore such
3486 static int warning_printed
= 0;
3487 if (!warning_printed
)
3489 warning (_("Skipping obsolete .gdb_index section in %s."),
3491 warning_printed
= 1;
3495 /* Index version 4 uses a different hash function than index version
3498 Versions earlier than 6 did not emit psymbols for inlined
3499 functions. Using these files will cause GDB not to be able to
3500 set breakpoints on inlined functions by name, so we ignore these
3501 indices unless the user has done
3502 "set use-deprecated-index-sections on". */
3503 if (version
< 6 && !deprecated_ok
)
3505 static int warning_printed
= 0;
3506 if (!warning_printed
)
3509 Skipping deprecated .gdb_index section in %s.\n\
3510 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3511 to use the section anyway."),
3513 warning_printed
= 1;
3517 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3518 of the TU (for symbols coming from TUs),
3519 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3520 Plus gold-generated indices can have duplicate entries for global symbols,
3521 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3522 These are just performance bugs, and we can't distinguish gdb-generated
3523 indices from gold-generated ones, so issue no warning here. */
3525 /* Indexes with higher version than the one supported by GDB may be no
3526 longer backward compatible. */
3530 map
->version
= version
;
3532 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3535 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3536 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3540 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3541 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3542 - MAYBE_SWAP (metadata
[i
]))
3546 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3547 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3549 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3552 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3553 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3555 = gdb::array_view
<mapped_index::symbol_table_slot
>
3556 ((mapped_index::symbol_table_slot
*) symbol_table
,
3557 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3560 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3565 /* Callback types for dwarf2_read_gdb_index. */
3567 typedef gdb::function_view
3568 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3569 get_gdb_index_contents_ftype
;
3570 typedef gdb::function_view
3571 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3572 get_gdb_index_contents_dwz_ftype
;
3574 /* Read .gdb_index. If everything went ok, initialize the "quick"
3575 elements of all the CUs and return 1. Otherwise, return 0. */
3578 dwarf2_read_gdb_index
3579 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3580 get_gdb_index_contents_ftype get_gdb_index_contents
,
3581 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3583 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3584 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3585 struct dwz_file
*dwz
;
3586 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3588 gdb::array_view
<const gdb_byte
> main_index_contents
3589 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3591 if (main_index_contents
.empty ())
3594 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3595 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3596 use_deprecated_index_sections
,
3597 main_index_contents
, map
.get (), &cu_list
,
3598 &cu_list_elements
, &types_list
,
3599 &types_list_elements
))
3602 /* Don't use the index if it's empty. */
3603 if (map
->symbol_table
.empty ())
3606 /* If there is a .dwz file, read it so we can get its CU list as
3608 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3611 struct mapped_index dwz_map
;
3612 const gdb_byte
*dwz_types_ignore
;
3613 offset_type dwz_types_elements_ignore
;
3615 gdb::array_view
<const gdb_byte
> dwz_index_content
3616 = get_gdb_index_contents_dwz (objfile
, dwz
);
3618 if (dwz_index_content
.empty ())
3621 if (!read_gdb_index_from_buffer (objfile
,
3622 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3623 1, dwz_index_content
, &dwz_map
,
3624 &dwz_list
, &dwz_list_elements
,
3626 &dwz_types_elements_ignore
))
3628 warning (_("could not read '.gdb_index' section from %s; skipping"),
3629 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3634 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3635 dwz_list
, dwz_list_elements
);
3637 if (types_list_elements
)
3639 /* We can only handle a single .debug_types when we have an
3641 if (dwarf2_per_objfile
->types
.size () != 1)
3644 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3646 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3647 types_list
, types_list_elements
);
3650 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3652 dwarf2_per_objfile
->index_table
= std::move (map
);
3653 dwarf2_per_objfile
->using_index
= 1;
3654 dwarf2_per_objfile
->quick_file_names_table
=
3655 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3660 /* die_reader_func for dw2_get_file_names. */
3663 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3664 const gdb_byte
*info_ptr
,
3665 struct die_info
*comp_unit_die
,
3669 struct dwarf2_cu
*cu
= reader
->cu
;
3670 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3671 struct dwarf2_per_objfile
*dwarf2_per_objfile
3672 = cu
->per_cu
->dwarf2_per_objfile
;
3673 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3674 struct dwarf2_per_cu_data
*lh_cu
;
3675 struct attribute
*attr
;
3677 struct quick_file_names
*qfn
;
3679 gdb_assert (! this_cu
->is_debug_types
);
3681 /* Our callers never want to match partial units -- instead they
3682 will match the enclosing full CU. */
3683 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3685 this_cu
->v
.quick
->no_file_data
= 1;
3693 sect_offset line_offset
{};
3695 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3696 if (attr
!= nullptr)
3698 struct quick_file_names find_entry
;
3700 line_offset
= (sect_offset
) DW_UNSND (attr
);
3702 /* We may have already read in this line header (TU line header sharing).
3703 If we have we're done. */
3704 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3705 find_entry
.hash
.line_sect_off
= line_offset
;
3706 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3707 &find_entry
, INSERT
);
3710 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3714 lh
= dwarf_decode_line_header (line_offset
, cu
);
3718 lh_cu
->v
.quick
->no_file_data
= 1;
3722 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3723 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3724 qfn
->hash
.line_sect_off
= line_offset
;
3725 gdb_assert (slot
!= NULL
);
3728 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3731 if (strcmp (fnd
.name
, "<unknown>") != 0)
3734 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3736 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3738 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3739 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3740 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3741 qfn
->real_names
= NULL
;
3743 lh_cu
->v
.quick
->file_names
= qfn
;
3746 /* A helper for the "quick" functions which attempts to read the line
3747 table for THIS_CU. */
3749 static struct quick_file_names
*
3750 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3752 /* This should never be called for TUs. */
3753 gdb_assert (! this_cu
->is_debug_types
);
3754 /* Nor type unit groups. */
3755 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3757 if (this_cu
->v
.quick
->file_names
!= NULL
)
3758 return this_cu
->v
.quick
->file_names
;
3759 /* If we know there is no line data, no point in looking again. */
3760 if (this_cu
->v
.quick
->no_file_data
)
3763 init_cutu_and_read_dies_simple (this_cu
, dw2_get_file_names_reader
, NULL
);
3765 if (this_cu
->v
.quick
->no_file_data
)
3767 return this_cu
->v
.quick
->file_names
;
3770 /* A helper for the "quick" functions which computes and caches the
3771 real path for a given file name from the line table. */
3774 dw2_get_real_path (struct objfile
*objfile
,
3775 struct quick_file_names
*qfn
, int index
)
3777 if (qfn
->real_names
== NULL
)
3778 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3779 qfn
->num_file_names
, const char *);
3781 if (qfn
->real_names
[index
] == NULL
)
3782 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3784 return qfn
->real_names
[index
];
3787 static struct symtab
*
3788 dw2_find_last_source_symtab (struct objfile
*objfile
)
3790 struct dwarf2_per_objfile
*dwarf2_per_objfile
3791 = get_dwarf2_per_objfile (objfile
);
3792 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3793 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3798 return compunit_primary_filetab (cust
);
3801 /* Traversal function for dw2_forget_cached_source_info. */
3804 dw2_free_cached_file_names (void **slot
, void *info
)
3806 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3808 if (file_data
->real_names
)
3812 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3814 xfree ((void*) file_data
->real_names
[i
]);
3815 file_data
->real_names
[i
] = NULL
;
3823 dw2_forget_cached_source_info (struct objfile
*objfile
)
3825 struct dwarf2_per_objfile
*dwarf2_per_objfile
3826 = get_dwarf2_per_objfile (objfile
);
3828 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3829 dw2_free_cached_file_names
, NULL
);
3832 /* Helper function for dw2_map_symtabs_matching_filename that expands
3833 the symtabs and calls the iterator. */
3836 dw2_map_expand_apply (struct objfile
*objfile
,
3837 struct dwarf2_per_cu_data
*per_cu
,
3838 const char *name
, const char *real_path
,
3839 gdb::function_view
<bool (symtab
*)> callback
)
3841 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3843 /* Don't visit already-expanded CUs. */
3844 if (per_cu
->v
.quick
->compunit_symtab
)
3847 /* This may expand more than one symtab, and we want to iterate over
3849 dw2_instantiate_symtab (per_cu
, false);
3851 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3852 last_made
, callback
);
3855 /* Implementation of the map_symtabs_matching_filename method. */
3858 dw2_map_symtabs_matching_filename
3859 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3860 gdb::function_view
<bool (symtab
*)> callback
)
3862 const char *name_basename
= lbasename (name
);
3863 struct dwarf2_per_objfile
*dwarf2_per_objfile
3864 = get_dwarf2_per_objfile (objfile
);
3866 /* The rule is CUs specify all the files, including those used by
3867 any TU, so there's no need to scan TUs here. */
3869 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3871 /* We only need to look at symtabs not already expanded. */
3872 if (per_cu
->v
.quick
->compunit_symtab
)
3875 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3876 if (file_data
== NULL
)
3879 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3881 const char *this_name
= file_data
->file_names
[j
];
3882 const char *this_real_name
;
3884 if (compare_filenames_for_search (this_name
, name
))
3886 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3892 /* Before we invoke realpath, which can get expensive when many
3893 files are involved, do a quick comparison of the basenames. */
3894 if (! basenames_may_differ
3895 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3898 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3899 if (compare_filenames_for_search (this_real_name
, name
))
3901 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3907 if (real_path
!= NULL
)
3909 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3910 gdb_assert (IS_ABSOLUTE_PATH (name
));
3911 if (this_real_name
!= NULL
3912 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3914 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3926 /* Struct used to manage iterating over all CUs looking for a symbol. */
3928 struct dw2_symtab_iterator
3930 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3931 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3932 /* If set, only look for symbols that match that block. Valid values are
3933 GLOBAL_BLOCK and STATIC_BLOCK. */
3934 gdb::optional
<block_enum
> block_index
;
3935 /* The kind of symbol we're looking for. */
3937 /* The list of CUs from the index entry of the symbol,
3938 or NULL if not found. */
3940 /* The next element in VEC to look at. */
3942 /* The number of elements in VEC, or zero if there is no match. */
3944 /* Have we seen a global version of the symbol?
3945 If so we can ignore all further global instances.
3946 This is to work around gold/15646, inefficient gold-generated
3951 /* Initialize the index symtab iterator ITER. */
3954 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3955 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3956 gdb::optional
<block_enum
> block_index
,
3960 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3961 iter
->block_index
= block_index
;
3962 iter
->domain
= domain
;
3964 iter
->global_seen
= 0;
3966 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3968 /* index is NULL if OBJF_READNOW. */
3969 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3970 iter
->length
= MAYBE_SWAP (*iter
->vec
);
3978 /* Return the next matching CU or NULL if there are no more. */
3980 static struct dwarf2_per_cu_data
*
3981 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
3983 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
3985 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
3987 offset_type cu_index_and_attrs
=
3988 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
3989 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
3990 gdb_index_symbol_kind symbol_kind
=
3991 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
3992 /* Only check the symbol attributes if they're present.
3993 Indices prior to version 7 don't record them,
3994 and indices >= 7 may elide them for certain symbols
3995 (gold does this). */
3997 (dwarf2_per_objfile
->index_table
->version
>= 7
3998 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4000 /* Don't crash on bad data. */
4001 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4002 + dwarf2_per_objfile
->all_type_units
.size ()))
4004 complaint (_(".gdb_index entry has bad CU index"
4006 objfile_name (dwarf2_per_objfile
->objfile
));
4010 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4012 /* Skip if already read in. */
4013 if (per_cu
->v
.quick
->compunit_symtab
)
4016 /* Check static vs global. */
4019 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4021 if (iter
->block_index
.has_value ())
4023 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4025 if (is_static
!= want_static
)
4029 /* Work around gold/15646. */
4030 if (!is_static
&& iter
->global_seen
)
4033 iter
->global_seen
= 1;
4036 /* Only check the symbol's kind if it has one. */
4039 switch (iter
->domain
)
4042 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4043 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4044 /* Some types are also in VAR_DOMAIN. */
4045 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4049 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4053 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4057 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4072 static struct compunit_symtab
*
4073 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4074 const char *name
, domain_enum domain
)
4076 struct compunit_symtab
*stab_best
= NULL
;
4077 struct dwarf2_per_objfile
*dwarf2_per_objfile
4078 = get_dwarf2_per_objfile (objfile
);
4080 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4082 struct dw2_symtab_iterator iter
;
4083 struct dwarf2_per_cu_data
*per_cu
;
4085 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4087 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4089 struct symbol
*sym
, *with_opaque
= NULL
;
4090 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4091 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4092 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4094 sym
= block_find_symbol (block
, name
, domain
,
4095 block_find_non_opaque_type_preferred
,
4098 /* Some caution must be observed with overloaded functions
4099 and methods, since the index will not contain any overload
4100 information (but NAME might contain it). */
4103 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4105 if (with_opaque
!= NULL
4106 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4109 /* Keep looking through other CUs. */
4116 dw2_print_stats (struct objfile
*objfile
)
4118 struct dwarf2_per_objfile
*dwarf2_per_objfile
4119 = get_dwarf2_per_objfile (objfile
);
4120 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4121 + dwarf2_per_objfile
->all_type_units
.size ());
4124 for (int i
= 0; i
< total
; ++i
)
4126 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4128 if (!per_cu
->v
.quick
->compunit_symtab
)
4131 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4132 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4135 /* This dumps minimal information about the index.
4136 It is called via "mt print objfiles".
4137 One use is to verify .gdb_index has been loaded by the
4138 gdb.dwarf2/gdb-index.exp testcase. */
4141 dw2_dump (struct objfile
*objfile
)
4143 struct dwarf2_per_objfile
*dwarf2_per_objfile
4144 = get_dwarf2_per_objfile (objfile
);
4146 gdb_assert (dwarf2_per_objfile
->using_index
);
4147 printf_filtered (".gdb_index:");
4148 if (dwarf2_per_objfile
->index_table
!= NULL
)
4150 printf_filtered (" version %d\n",
4151 dwarf2_per_objfile
->index_table
->version
);
4154 printf_filtered (" faked for \"readnow\"\n");
4155 printf_filtered ("\n");
4159 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4160 const char *func_name
)
4162 struct dwarf2_per_objfile
*dwarf2_per_objfile
4163 = get_dwarf2_per_objfile (objfile
);
4165 struct dw2_symtab_iterator iter
;
4166 struct dwarf2_per_cu_data
*per_cu
;
4168 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4170 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4171 dw2_instantiate_symtab (per_cu
, false);
4176 dw2_expand_all_symtabs (struct objfile
*objfile
)
4178 struct dwarf2_per_objfile
*dwarf2_per_objfile
4179 = get_dwarf2_per_objfile (objfile
);
4180 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4181 + dwarf2_per_objfile
->all_type_units
.size ());
4183 for (int i
= 0; i
< total_units
; ++i
)
4185 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4187 /* We don't want to directly expand a partial CU, because if we
4188 read it with the wrong language, then assertion failures can
4189 be triggered later on. See PR symtab/23010. So, tell
4190 dw2_instantiate_symtab to skip partial CUs -- any important
4191 partial CU will be read via DW_TAG_imported_unit anyway. */
4192 dw2_instantiate_symtab (per_cu
, true);
4197 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4198 const char *fullname
)
4200 struct dwarf2_per_objfile
*dwarf2_per_objfile
4201 = get_dwarf2_per_objfile (objfile
);
4203 /* We don't need to consider type units here.
4204 This is only called for examining code, e.g. expand_line_sal.
4205 There can be an order of magnitude (or more) more type units
4206 than comp units, and we avoid them if we can. */
4208 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4210 /* We only need to look at symtabs not already expanded. */
4211 if (per_cu
->v
.quick
->compunit_symtab
)
4214 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4215 if (file_data
== NULL
)
4218 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4220 const char *this_fullname
= file_data
->file_names
[j
];
4222 if (filename_cmp (this_fullname
, fullname
) == 0)
4224 dw2_instantiate_symtab (per_cu
, false);
4232 dw2_map_matching_symbols
4233 (struct objfile
*objfile
,
4234 const lookup_name_info
&name
, domain_enum domain
,
4236 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4237 symbol_compare_ftype
*ordered_compare
)
4239 /* Currently unimplemented; used for Ada. The function can be called if the
4240 current language is Ada for a non-Ada objfile using GNU index. As Ada
4241 does not look for non-Ada symbols this function should just return. */
4244 /* Starting from a search name, return the string that finds the upper
4245 bound of all strings that start with SEARCH_NAME in a sorted name
4246 list. Returns the empty string to indicate that the upper bound is
4247 the end of the list. */
4250 make_sort_after_prefix_name (const char *search_name
)
4252 /* When looking to complete "func", we find the upper bound of all
4253 symbols that start with "func" by looking for where we'd insert
4254 the closest string that would follow "func" in lexicographical
4255 order. Usually, that's "func"-with-last-character-incremented,
4256 i.e. "fund". Mind non-ASCII characters, though. Usually those
4257 will be UTF-8 multi-byte sequences, but we can't be certain.
4258 Especially mind the 0xff character, which is a valid character in
4259 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4260 rule out compilers allowing it in identifiers. Note that
4261 conveniently, strcmp/strcasecmp are specified to compare
4262 characters interpreted as unsigned char. So what we do is treat
4263 the whole string as a base 256 number composed of a sequence of
4264 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4265 to 0, and carries 1 to the following more-significant position.
4266 If the very first character in SEARCH_NAME ends up incremented
4267 and carries/overflows, then the upper bound is the end of the
4268 list. The string after the empty string is also the empty
4271 Some examples of this operation:
4273 SEARCH_NAME => "+1" RESULT
4277 "\xff" "a" "\xff" => "\xff" "b"
4282 Then, with these symbols for example:
4288 completing "func" looks for symbols between "func" and
4289 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4290 which finds "func" and "func1", but not "fund".
4294 funcÿ (Latin1 'ÿ' [0xff])
4298 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4299 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4303 ÿÿ (Latin1 'ÿ' [0xff])
4306 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4307 the end of the list.
4309 std::string after
= search_name
;
4310 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4312 if (!after
.empty ())
4313 after
.back () = (unsigned char) after
.back () + 1;
4317 /* See declaration. */
4319 std::pair
<std::vector
<name_component
>::const_iterator
,
4320 std::vector
<name_component
>::const_iterator
>
4321 mapped_index_base::find_name_components_bounds
4322 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4325 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4327 const char *lang_name
4328 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4330 /* Comparison function object for lower_bound that matches against a
4331 given symbol name. */
4332 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4335 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4336 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4337 return name_cmp (elem_name
, name
) < 0;
4340 /* Comparison function object for upper_bound that matches against a
4341 given symbol name. */
4342 auto lookup_compare_upper
= [&] (const char *name
,
4343 const name_component
&elem
)
4345 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4346 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4347 return name_cmp (name
, elem_name
) < 0;
4350 auto begin
= this->name_components
.begin ();
4351 auto end
= this->name_components
.end ();
4353 /* Find the lower bound. */
4356 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4359 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4362 /* Find the upper bound. */
4365 if (lookup_name_without_params
.completion_mode ())
4367 /* In completion mode, we want UPPER to point past all
4368 symbols names that have the same prefix. I.e., with
4369 these symbols, and completing "func":
4371 function << lower bound
4373 other_function << upper bound
4375 We find the upper bound by looking for the insertion
4376 point of "func"-with-last-character-incremented,
4378 std::string after
= make_sort_after_prefix_name (lang_name
);
4381 return std::lower_bound (lower
, end
, after
.c_str (),
4382 lookup_compare_lower
);
4385 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4388 return {lower
, upper
};
4391 /* See declaration. */
4394 mapped_index_base::build_name_components ()
4396 if (!this->name_components
.empty ())
4399 this->name_components_casing
= case_sensitivity
;
4401 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4403 /* The code below only knows how to break apart components of C++
4404 symbol names (and other languages that use '::' as
4405 namespace/module separator) and Ada symbol names. */
4406 auto count
= this->symbol_name_count ();
4407 for (offset_type idx
= 0; idx
< count
; idx
++)
4409 if (this->symbol_name_slot_invalid (idx
))
4412 const char *name
= this->symbol_name_at (idx
);
4414 /* Add each name component to the name component table. */
4415 unsigned int previous_len
= 0;
4417 if (strstr (name
, "::") != nullptr)
4419 for (unsigned int current_len
= cp_find_first_component (name
);
4420 name
[current_len
] != '\0';
4421 current_len
+= cp_find_first_component (name
+ current_len
))
4423 gdb_assert (name
[current_len
] == ':');
4424 this->name_components
.push_back ({previous_len
, idx
});
4425 /* Skip the '::'. */
4427 previous_len
= current_len
;
4432 /* Handle the Ada encoded (aka mangled) form here. */
4433 for (const char *iter
= strstr (name
, "__");
4435 iter
= strstr (iter
, "__"))
4437 this->name_components
.push_back ({previous_len
, idx
});
4439 previous_len
= iter
- name
;
4443 this->name_components
.push_back ({previous_len
, idx
});
4446 /* Sort name_components elements by name. */
4447 auto name_comp_compare
= [&] (const name_component
&left
,
4448 const name_component
&right
)
4450 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4451 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4453 const char *left_name
= left_qualified
+ left
.name_offset
;
4454 const char *right_name
= right_qualified
+ right
.name_offset
;
4456 return name_cmp (left_name
, right_name
) < 0;
4459 std::sort (this->name_components
.begin (),
4460 this->name_components
.end (),
4464 /* Helper for dw2_expand_symtabs_matching that works with a
4465 mapped_index_base instead of the containing objfile. This is split
4466 to a separate function in order to be able to unit test the
4467 name_components matching using a mock mapped_index_base. For each
4468 symbol name that matches, calls MATCH_CALLBACK, passing it the
4469 symbol's index in the mapped_index_base symbol table. */
4472 dw2_expand_symtabs_matching_symbol
4473 (mapped_index_base
&index
,
4474 const lookup_name_info
&lookup_name_in
,
4475 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4476 enum search_domain kind
,
4477 gdb::function_view
<bool (offset_type
)> match_callback
)
4479 lookup_name_info lookup_name_without_params
4480 = lookup_name_in
.make_ignore_params ();
4482 /* Build the symbol name component sorted vector, if we haven't
4484 index
.build_name_components ();
4486 /* The same symbol may appear more than once in the range though.
4487 E.g., if we're looking for symbols that complete "w", and we have
4488 a symbol named "w1::w2", we'll find the two name components for
4489 that same symbol in the range. To be sure we only call the
4490 callback once per symbol, we first collect the symbol name
4491 indexes that matched in a temporary vector and ignore
4493 std::vector
<offset_type
> matches
;
4495 struct name_and_matcher
4497 symbol_name_matcher_ftype
*matcher
;
4498 const std::string
&name
;
4500 bool operator== (const name_and_matcher
&other
) const
4502 return matcher
== other
.matcher
&& name
== other
.name
;
4506 /* A vector holding all the different symbol name matchers, for all
4508 std::vector
<name_and_matcher
> matchers
;
4510 for (int i
= 0; i
< nr_languages
; i
++)
4512 enum language lang_e
= (enum language
) i
;
4514 const language_defn
*lang
= language_def (lang_e
);
4515 symbol_name_matcher_ftype
*name_matcher
4516 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4518 name_and_matcher key
{
4520 lookup_name_without_params
.language_lookup_name (lang_e
)
4523 /* Don't insert the same comparison routine more than once.
4524 Note that we do this linear walk. This is not a problem in
4525 practice because the number of supported languages is
4527 if (std::find (matchers
.begin (), matchers
.end (), key
)
4530 matchers
.push_back (std::move (key
));
4533 = index
.find_name_components_bounds (lookup_name_without_params
,
4536 /* Now for each symbol name in range, check to see if we have a name
4537 match, and if so, call the MATCH_CALLBACK callback. */
4539 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4541 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4543 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4544 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4547 matches
.push_back (bounds
.first
->idx
);
4551 std::sort (matches
.begin (), matches
.end ());
4553 /* Finally call the callback, once per match. */
4555 for (offset_type idx
: matches
)
4559 if (!match_callback (idx
))
4565 /* Above we use a type wider than idx's for 'prev', since 0 and
4566 (offset_type)-1 are both possible values. */
4567 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4572 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4574 /* A mock .gdb_index/.debug_names-like name index table, enough to
4575 exercise dw2_expand_symtabs_matching_symbol, which works with the
4576 mapped_index_base interface. Builds an index from the symbol list
4577 passed as parameter to the constructor. */
4578 class mock_mapped_index
: public mapped_index_base
4581 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4582 : m_symbol_table (symbols
)
4585 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4587 /* Return the number of names in the symbol table. */
4588 size_t symbol_name_count () const override
4590 return m_symbol_table
.size ();
4593 /* Get the name of the symbol at IDX in the symbol table. */
4594 const char *symbol_name_at (offset_type idx
) const override
4596 return m_symbol_table
[idx
];
4600 gdb::array_view
<const char *> m_symbol_table
;
4603 /* Convenience function that converts a NULL pointer to a "<null>"
4604 string, to pass to print routines. */
4607 string_or_null (const char *str
)
4609 return str
!= NULL
? str
: "<null>";
4612 /* Check if a lookup_name_info built from
4613 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4614 index. EXPECTED_LIST is the list of expected matches, in expected
4615 matching order. If no match expected, then an empty list is
4616 specified. Returns true on success. On failure prints a warning
4617 indicating the file:line that failed, and returns false. */
4620 check_match (const char *file
, int line
,
4621 mock_mapped_index
&mock_index
,
4622 const char *name
, symbol_name_match_type match_type
,
4623 bool completion_mode
,
4624 std::initializer_list
<const char *> expected_list
)
4626 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4628 bool matched
= true;
4630 auto mismatch
= [&] (const char *expected_str
,
4633 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4634 "expected=\"%s\", got=\"%s\"\n"),
4636 (match_type
== symbol_name_match_type::FULL
4638 name
, string_or_null (expected_str
), string_or_null (got
));
4642 auto expected_it
= expected_list
.begin ();
4643 auto expected_end
= expected_list
.end ();
4645 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4647 [&] (offset_type idx
)
4649 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4650 const char *expected_str
4651 = expected_it
== expected_end
? NULL
: *expected_it
++;
4653 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4654 mismatch (expected_str
, matched_name
);
4658 const char *expected_str
4659 = expected_it
== expected_end
? NULL
: *expected_it
++;
4660 if (expected_str
!= NULL
)
4661 mismatch (expected_str
, NULL
);
4666 /* The symbols added to the mock mapped_index for testing (in
4668 static const char *test_symbols
[] = {
4677 "ns2::tmpl<int>::foo2",
4678 "(anonymous namespace)::A::B::C",
4680 /* These are used to check that the increment-last-char in the
4681 matching algorithm for completion doesn't match "t1_fund" when
4682 completing "t1_func". */
4688 /* A UTF-8 name with multi-byte sequences to make sure that
4689 cp-name-parser understands this as a single identifier ("função"
4690 is "function" in PT). */
4693 /* \377 (0xff) is Latin1 'ÿ'. */
4696 /* \377 (0xff) is Latin1 'ÿ'. */
4700 /* A name with all sorts of complications. Starts with "z" to make
4701 it easier for the completion tests below. */
4702 #define Z_SYM_NAME \
4703 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4704 "::tuple<(anonymous namespace)::ui*, " \
4705 "std::default_delete<(anonymous namespace)::ui>, void>"
4710 /* Returns true if the mapped_index_base::find_name_component_bounds
4711 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4712 in completion mode. */
4715 check_find_bounds_finds (mapped_index_base
&index
,
4716 const char *search_name
,
4717 gdb::array_view
<const char *> expected_syms
)
4719 lookup_name_info
lookup_name (search_name
,
4720 symbol_name_match_type::FULL
, true);
4722 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4725 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4726 if (distance
!= expected_syms
.size ())
4729 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4731 auto nc_elem
= bounds
.first
+ exp_elem
;
4732 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4733 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4740 /* Test the lower-level mapped_index::find_name_component_bounds
4744 test_mapped_index_find_name_component_bounds ()
4746 mock_mapped_index
mock_index (test_symbols
);
4748 mock_index
.build_name_components ();
4750 /* Test the lower-level mapped_index::find_name_component_bounds
4751 method in completion mode. */
4753 static const char *expected_syms
[] = {
4758 SELF_CHECK (check_find_bounds_finds (mock_index
,
4759 "t1_func", expected_syms
));
4762 /* Check that the increment-last-char in the name matching algorithm
4763 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4765 static const char *expected_syms1
[] = {
4769 SELF_CHECK (check_find_bounds_finds (mock_index
,
4770 "\377", expected_syms1
));
4772 static const char *expected_syms2
[] = {
4775 SELF_CHECK (check_find_bounds_finds (mock_index
,
4776 "\377\377", expected_syms2
));
4780 /* Test dw2_expand_symtabs_matching_symbol. */
4783 test_dw2_expand_symtabs_matching_symbol ()
4785 mock_mapped_index
mock_index (test_symbols
);
4787 /* We let all tests run until the end even if some fails, for debug
4789 bool any_mismatch
= false;
4791 /* Create the expected symbols list (an initializer_list). Needed
4792 because lists have commas, and we need to pass them to CHECK,
4793 which is a macro. */
4794 #define EXPECT(...) { __VA_ARGS__ }
4796 /* Wrapper for check_match that passes down the current
4797 __FILE__/__LINE__. */
4798 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4799 any_mismatch |= !check_match (__FILE__, __LINE__, \
4801 NAME, MATCH_TYPE, COMPLETION_MODE, \
4804 /* Identity checks. */
4805 for (const char *sym
: test_symbols
)
4807 /* Should be able to match all existing symbols. */
4808 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4811 /* Should be able to match all existing symbols with
4813 std::string with_params
= std::string (sym
) + "(int)";
4814 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4817 /* Should be able to match all existing symbols with
4818 parameters and qualifiers. */
4819 with_params
= std::string (sym
) + " ( int ) const";
4820 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4823 /* This should really find sym, but cp-name-parser.y doesn't
4824 know about lvalue/rvalue qualifiers yet. */
4825 with_params
= std::string (sym
) + " ( int ) &&";
4826 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4830 /* Check that the name matching algorithm for completion doesn't get
4831 confused with Latin1 'ÿ' / 0xff. */
4833 static const char str
[] = "\377";
4834 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4835 EXPECT ("\377", "\377\377123"));
4838 /* Check that the increment-last-char in the matching algorithm for
4839 completion doesn't match "t1_fund" when completing "t1_func". */
4841 static const char str
[] = "t1_func";
4842 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4843 EXPECT ("t1_func", "t1_func1"));
4846 /* Check that completion mode works at each prefix of the expected
4849 static const char str
[] = "function(int)";
4850 size_t len
= strlen (str
);
4853 for (size_t i
= 1; i
< len
; i
++)
4855 lookup
.assign (str
, i
);
4856 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4857 EXPECT ("function"));
4861 /* While "w" is a prefix of both components, the match function
4862 should still only be called once. */
4864 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4866 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4870 /* Same, with a "complicated" symbol. */
4872 static const char str
[] = Z_SYM_NAME
;
4873 size_t len
= strlen (str
);
4876 for (size_t i
= 1; i
< len
; i
++)
4878 lookup
.assign (str
, i
);
4879 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4880 EXPECT (Z_SYM_NAME
));
4884 /* In FULL mode, an incomplete symbol doesn't match. */
4886 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4890 /* A complete symbol with parameters matches any overload, since the
4891 index has no overload info. */
4893 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4894 EXPECT ("std::zfunction", "std::zfunction2"));
4895 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4896 EXPECT ("std::zfunction", "std::zfunction2"));
4897 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4898 EXPECT ("std::zfunction", "std::zfunction2"));
4901 /* Check that whitespace is ignored appropriately. A symbol with a
4902 template argument list. */
4904 static const char expected
[] = "ns::foo<int>";
4905 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4907 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4911 /* Check that whitespace is ignored appropriately. A symbol with a
4912 template argument list that includes a pointer. */
4914 static const char expected
[] = "ns::foo<char*>";
4915 /* Try both completion and non-completion modes. */
4916 static const bool completion_mode
[2] = {false, true};
4917 for (size_t i
= 0; i
< 2; i
++)
4919 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4920 completion_mode
[i
], EXPECT (expected
));
4921 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4922 completion_mode
[i
], EXPECT (expected
));
4924 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4925 completion_mode
[i
], EXPECT (expected
));
4926 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4927 completion_mode
[i
], EXPECT (expected
));
4932 /* Check method qualifiers are ignored. */
4933 static const char expected
[] = "ns::foo<char*>";
4934 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4935 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4936 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4937 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4938 CHECK_MATCH ("foo < char * > ( int ) const",
4939 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4940 CHECK_MATCH ("foo < char * > ( int ) &&",
4941 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4944 /* Test lookup names that don't match anything. */
4946 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4949 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4953 /* Some wild matching tests, exercising "(anonymous namespace)",
4954 which should not be confused with a parameter list. */
4956 static const char *syms
[] = {
4960 "A :: B :: C ( int )",
4965 for (const char *s
: syms
)
4967 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4968 EXPECT ("(anonymous namespace)::A::B::C"));
4973 static const char expected
[] = "ns2::tmpl<int>::foo2";
4974 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4976 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
4980 SELF_CHECK (!any_mismatch
);
4989 test_mapped_index_find_name_component_bounds ();
4990 test_dw2_expand_symtabs_matching_symbol ();
4993 }} // namespace selftests::dw2_expand_symtabs_matching
4995 #endif /* GDB_SELF_TEST */
4997 /* If FILE_MATCHER is NULL or if PER_CU has
4998 dwarf2_per_cu_quick_data::MARK set (see
4999 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5000 EXPANSION_NOTIFY on it. */
5003 dw2_expand_symtabs_matching_one
5004 (struct dwarf2_per_cu_data
*per_cu
,
5005 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5006 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5008 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5010 bool symtab_was_null
5011 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5013 dw2_instantiate_symtab (per_cu
, false);
5015 if (expansion_notify
!= NULL
5017 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5018 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5022 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5023 matched, to expand corresponding CUs that were marked. IDX is the
5024 index of the symbol name that matched. */
5027 dw2_expand_marked_cus
5028 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5029 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5030 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5033 offset_type
*vec
, vec_len
, vec_idx
;
5034 bool global_seen
= false;
5035 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5037 vec
= (offset_type
*) (index
.constant_pool
5038 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5039 vec_len
= MAYBE_SWAP (vec
[0]);
5040 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5042 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5043 /* This value is only valid for index versions >= 7. */
5044 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5045 gdb_index_symbol_kind symbol_kind
=
5046 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5047 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5048 /* Only check the symbol attributes if they're present.
5049 Indices prior to version 7 don't record them,
5050 and indices >= 7 may elide them for certain symbols
5051 (gold does this). */
5054 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5056 /* Work around gold/15646. */
5059 if (!is_static
&& global_seen
)
5065 /* Only check the symbol's kind if it has one. */
5070 case VARIABLES_DOMAIN
:
5071 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5074 case FUNCTIONS_DOMAIN
:
5075 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5079 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5082 case MODULES_DOMAIN
:
5083 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5091 /* Don't crash on bad data. */
5092 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5093 + dwarf2_per_objfile
->all_type_units
.size ()))
5095 complaint (_(".gdb_index entry has bad CU index"
5097 objfile_name (dwarf2_per_objfile
->objfile
));
5101 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5102 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5107 /* If FILE_MATCHER is non-NULL, set all the
5108 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5109 that match FILE_MATCHER. */
5112 dw_expand_symtabs_matching_file_matcher
5113 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5114 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5116 if (file_matcher
== NULL
)
5119 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5121 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5123 NULL
, xcalloc
, xfree
));
5124 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5126 NULL
, xcalloc
, xfree
));
5128 /* The rule is CUs specify all the files, including those used by
5129 any TU, so there's no need to scan TUs here. */
5131 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5135 per_cu
->v
.quick
->mark
= 0;
5137 /* We only need to look at symtabs not already expanded. */
5138 if (per_cu
->v
.quick
->compunit_symtab
)
5141 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5142 if (file_data
== NULL
)
5145 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5147 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5149 per_cu
->v
.quick
->mark
= 1;
5153 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5155 const char *this_real_name
;
5157 if (file_matcher (file_data
->file_names
[j
], false))
5159 per_cu
->v
.quick
->mark
= 1;
5163 /* Before we invoke realpath, which can get expensive when many
5164 files are involved, do a quick comparison of the basenames. */
5165 if (!basenames_may_differ
5166 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5170 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5171 if (file_matcher (this_real_name
, false))
5173 per_cu
->v
.quick
->mark
= 1;
5178 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5179 ? visited_found
.get ()
5180 : visited_not_found
.get (),
5187 dw2_expand_symtabs_matching
5188 (struct objfile
*objfile
,
5189 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5190 const lookup_name_info
&lookup_name
,
5191 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5192 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5193 enum search_domain kind
)
5195 struct dwarf2_per_objfile
*dwarf2_per_objfile
5196 = get_dwarf2_per_objfile (objfile
);
5198 /* index_table is NULL if OBJF_READNOW. */
5199 if (!dwarf2_per_objfile
->index_table
)
5202 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5204 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5206 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5208 kind
, [&] (offset_type idx
)
5210 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5211 expansion_notify
, kind
);
5216 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5219 static struct compunit_symtab
*
5220 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5225 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5226 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5229 if (cust
->includes
== NULL
)
5232 for (i
= 0; cust
->includes
[i
]; ++i
)
5234 struct compunit_symtab
*s
= cust
->includes
[i
];
5236 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5244 static struct compunit_symtab
*
5245 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5246 struct bound_minimal_symbol msymbol
,
5248 struct obj_section
*section
,
5251 struct dwarf2_per_cu_data
*data
;
5252 struct compunit_symtab
*result
;
5254 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5257 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
5258 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5259 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5263 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5264 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5265 paddress (get_objfile_arch (objfile
), pc
));
5268 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5271 gdb_assert (result
!= NULL
);
5276 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5277 void *data
, int need_fullname
)
5279 struct dwarf2_per_objfile
*dwarf2_per_objfile
5280 = get_dwarf2_per_objfile (objfile
);
5282 if (!dwarf2_per_objfile
->filenames_cache
)
5284 dwarf2_per_objfile
->filenames_cache
.emplace ();
5286 htab_up
visited (htab_create_alloc (10,
5287 htab_hash_pointer
, htab_eq_pointer
,
5288 NULL
, xcalloc
, xfree
));
5290 /* The rule is CUs specify all the files, including those used
5291 by any TU, so there's no need to scan TUs here. We can
5292 ignore file names coming from already-expanded CUs. */
5294 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5296 if (per_cu
->v
.quick
->compunit_symtab
)
5298 void **slot
= htab_find_slot (visited
.get (),
5299 per_cu
->v
.quick
->file_names
,
5302 *slot
= per_cu
->v
.quick
->file_names
;
5306 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5308 /* We only need to look at symtabs not already expanded. */
5309 if (per_cu
->v
.quick
->compunit_symtab
)
5312 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5313 if (file_data
== NULL
)
5316 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5319 /* Already visited. */
5324 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5326 const char *filename
= file_data
->file_names
[j
];
5327 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5332 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5334 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5337 this_real_name
= gdb_realpath (filename
);
5338 (*fun
) (filename
, this_real_name
.get (), data
);
5343 dw2_has_symbols (struct objfile
*objfile
)
5348 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5351 dw2_find_last_source_symtab
,
5352 dw2_forget_cached_source_info
,
5353 dw2_map_symtabs_matching_filename
,
5357 dw2_expand_symtabs_for_function
,
5358 dw2_expand_all_symtabs
,
5359 dw2_expand_symtabs_with_fullname
,
5360 dw2_map_matching_symbols
,
5361 dw2_expand_symtabs_matching
,
5362 dw2_find_pc_sect_compunit_symtab
,
5364 dw2_map_symbol_filenames
5367 /* DWARF-5 debug_names reader. */
5369 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5370 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5372 /* A helper function that reads the .debug_names section in SECTION
5373 and fills in MAP. FILENAME is the name of the file containing the
5374 section; it is used for error reporting.
5376 Returns true if all went well, false otherwise. */
5379 read_debug_names_from_section (struct objfile
*objfile
,
5380 const char *filename
,
5381 struct dwarf2_section_info
*section
,
5382 mapped_debug_names
&map
)
5384 if (dwarf2_section_empty_p (section
))
5387 /* Older elfutils strip versions could keep the section in the main
5388 executable while splitting it for the separate debug info file. */
5389 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5392 dwarf2_read_section (objfile
, section
);
5394 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5396 const gdb_byte
*addr
= section
->buffer
;
5398 bfd
*const abfd
= get_section_bfd_owner (section
);
5400 unsigned int bytes_read
;
5401 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5404 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5405 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5406 if (bytes_read
+ length
!= section
->size
)
5408 /* There may be multiple per-CU indices. */
5409 warning (_("Section .debug_names in %s length %s does not match "
5410 "section length %s, ignoring .debug_names."),
5411 filename
, plongest (bytes_read
+ length
),
5412 pulongest (section
->size
));
5416 /* The version number. */
5417 uint16_t version
= read_2_bytes (abfd
, addr
);
5421 warning (_("Section .debug_names in %s has unsupported version %d, "
5422 "ignoring .debug_names."),
5428 uint16_t padding
= read_2_bytes (abfd
, addr
);
5432 warning (_("Section .debug_names in %s has unsupported padding %d, "
5433 "ignoring .debug_names."),
5438 /* comp_unit_count - The number of CUs in the CU list. */
5439 map
.cu_count
= read_4_bytes (abfd
, addr
);
5442 /* local_type_unit_count - The number of TUs in the local TU
5444 map
.tu_count
= read_4_bytes (abfd
, addr
);
5447 /* foreign_type_unit_count - The number of TUs in the foreign TU
5449 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5451 if (foreign_tu_count
!= 0)
5453 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5454 "ignoring .debug_names."),
5455 filename
, static_cast<unsigned long> (foreign_tu_count
));
5459 /* bucket_count - The number of hash buckets in the hash lookup
5461 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5464 /* name_count - The number of unique names in the index. */
5465 map
.name_count
= read_4_bytes (abfd
, addr
);
5468 /* abbrev_table_size - The size in bytes of the abbreviations
5470 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5473 /* augmentation_string_size - The size in bytes of the augmentation
5474 string. This value is rounded up to a multiple of 4. */
5475 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5477 map
.augmentation_is_gdb
= ((augmentation_string_size
5478 == sizeof (dwarf5_augmentation
))
5479 && memcmp (addr
, dwarf5_augmentation
,
5480 sizeof (dwarf5_augmentation
)) == 0);
5481 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5482 addr
+= augmentation_string_size
;
5485 map
.cu_table_reordered
= addr
;
5486 addr
+= map
.cu_count
* map
.offset_size
;
5488 /* List of Local TUs */
5489 map
.tu_table_reordered
= addr
;
5490 addr
+= map
.tu_count
* map
.offset_size
;
5492 /* Hash Lookup Table */
5493 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5494 addr
+= map
.bucket_count
* 4;
5495 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5496 addr
+= map
.name_count
* 4;
5499 map
.name_table_string_offs_reordered
= addr
;
5500 addr
+= map
.name_count
* map
.offset_size
;
5501 map
.name_table_entry_offs_reordered
= addr
;
5502 addr
+= map
.name_count
* map
.offset_size
;
5504 const gdb_byte
*abbrev_table_start
= addr
;
5507 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5512 const auto insertpair
5513 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5514 if (!insertpair
.second
)
5516 warning (_("Section .debug_names in %s has duplicate index %s, "
5517 "ignoring .debug_names."),
5518 filename
, pulongest (index_num
));
5521 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5522 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5527 mapped_debug_names::index_val::attr attr
;
5528 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5530 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5532 if (attr
.form
== DW_FORM_implicit_const
)
5534 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5538 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5540 indexval
.attr_vec
.push_back (std::move (attr
));
5543 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5545 warning (_("Section .debug_names in %s has abbreviation_table "
5546 "of size %s vs. written as %u, ignoring .debug_names."),
5547 filename
, plongest (addr
- abbrev_table_start
),
5551 map
.entry_pool
= addr
;
5556 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5560 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5561 const mapped_debug_names
&map
,
5562 dwarf2_section_info
§ion
,
5565 sect_offset sect_off_prev
;
5566 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5568 sect_offset sect_off_next
;
5569 if (i
< map
.cu_count
)
5572 = (sect_offset
) (extract_unsigned_integer
5573 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5575 map
.dwarf5_byte_order
));
5578 sect_off_next
= (sect_offset
) section
.size
;
5581 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5582 dwarf2_per_cu_data
*per_cu
5583 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5584 sect_off_prev
, length
);
5585 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5587 sect_off_prev
= sect_off_next
;
5591 /* Read the CU list from the mapped index, and use it to create all
5592 the CU objects for this dwarf2_per_objfile. */
5595 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5596 const mapped_debug_names
&map
,
5597 const mapped_debug_names
&dwz_map
)
5599 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5600 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5602 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5603 dwarf2_per_objfile
->info
,
5604 false /* is_dwz */);
5606 if (dwz_map
.cu_count
== 0)
5609 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5610 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5614 /* Read .debug_names. If everything went ok, initialize the "quick"
5615 elements of all the CUs and return true. Otherwise, return false. */
5618 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5620 std::unique_ptr
<mapped_debug_names
> map
5621 (new mapped_debug_names (dwarf2_per_objfile
));
5622 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5623 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5625 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5626 &dwarf2_per_objfile
->debug_names
,
5630 /* Don't use the index if it's empty. */
5631 if (map
->name_count
== 0)
5634 /* If there is a .dwz file, read it so we can get its CU list as
5636 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5639 if (!read_debug_names_from_section (objfile
,
5640 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5641 &dwz
->debug_names
, dwz_map
))
5643 warning (_("could not read '.debug_names' section from %s; skipping"),
5644 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5649 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5651 if (map
->tu_count
!= 0)
5653 /* We can only handle a single .debug_types when we have an
5655 if (dwarf2_per_objfile
->types
.size () != 1)
5658 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5660 create_signatured_type_table_from_debug_names
5661 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5664 create_addrmap_from_aranges (dwarf2_per_objfile
,
5665 &dwarf2_per_objfile
->debug_aranges
);
5667 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5668 dwarf2_per_objfile
->using_index
= 1;
5669 dwarf2_per_objfile
->quick_file_names_table
=
5670 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5675 /* Type used to manage iterating over all CUs looking for a symbol for
5678 class dw2_debug_names_iterator
5681 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5682 gdb::optional
<block_enum
> block_index
,
5685 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5686 m_addr (find_vec_in_debug_names (map
, name
))
5689 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5690 search_domain search
, uint32_t namei
)
5693 m_addr (find_vec_in_debug_names (map
, namei
))
5696 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5697 block_enum block_index
, domain_enum domain
,
5699 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5700 m_addr (find_vec_in_debug_names (map
, namei
))
5703 /* Return the next matching CU or NULL if there are no more. */
5704 dwarf2_per_cu_data
*next ();
5707 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5709 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5712 /* The internalized form of .debug_names. */
5713 const mapped_debug_names
&m_map
;
5715 /* If set, only look for symbols that match that block. Valid values are
5716 GLOBAL_BLOCK and STATIC_BLOCK. */
5717 const gdb::optional
<block_enum
> m_block_index
;
5719 /* The kind of symbol we're looking for. */
5720 const domain_enum m_domain
= UNDEF_DOMAIN
;
5721 const search_domain m_search
= ALL_DOMAIN
;
5723 /* The list of CUs from the index entry of the symbol, or NULL if
5725 const gdb_byte
*m_addr
;
5729 mapped_debug_names::namei_to_name (uint32_t namei
) const
5731 const ULONGEST namei_string_offs
5732 = extract_unsigned_integer ((name_table_string_offs_reordered
5733 + namei
* offset_size
),
5736 return read_indirect_string_at_offset
5737 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5740 /* Find a slot in .debug_names for the object named NAME. If NAME is
5741 found, return pointer to its pool data. If NAME cannot be found,
5745 dw2_debug_names_iterator::find_vec_in_debug_names
5746 (const mapped_debug_names
&map
, const char *name
)
5748 int (*cmp
) (const char *, const char *);
5750 gdb::unique_xmalloc_ptr
<char> without_params
;
5751 if (current_language
->la_language
== language_cplus
5752 || current_language
->la_language
== language_fortran
5753 || current_language
->la_language
== language_d
)
5755 /* NAME is already canonical. Drop any qualifiers as
5756 .debug_names does not contain any. */
5758 if (strchr (name
, '(') != NULL
)
5760 without_params
= cp_remove_params (name
);
5761 if (without_params
!= NULL
)
5762 name
= without_params
.get ();
5766 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5768 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5770 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5771 (map
.bucket_table_reordered
5772 + (full_hash
% map
.bucket_count
)), 4,
5773 map
.dwarf5_byte_order
);
5777 if (namei
>= map
.name_count
)
5779 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5781 namei
, map
.name_count
,
5782 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5788 const uint32_t namei_full_hash
5789 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5790 (map
.hash_table_reordered
+ namei
), 4,
5791 map
.dwarf5_byte_order
);
5792 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5795 if (full_hash
== namei_full_hash
)
5797 const char *const namei_string
= map
.namei_to_name (namei
);
5799 #if 0 /* An expensive sanity check. */
5800 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5802 complaint (_("Wrong .debug_names hash for string at index %u "
5804 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5809 if (cmp (namei_string
, name
) == 0)
5811 const ULONGEST namei_entry_offs
5812 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5813 + namei
* map
.offset_size
),
5814 map
.offset_size
, map
.dwarf5_byte_order
);
5815 return map
.entry_pool
+ namei_entry_offs
;
5820 if (namei
>= map
.name_count
)
5826 dw2_debug_names_iterator::find_vec_in_debug_names
5827 (const mapped_debug_names
&map
, uint32_t namei
)
5829 if (namei
>= map
.name_count
)
5831 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5833 namei
, map
.name_count
,
5834 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5838 const ULONGEST namei_entry_offs
5839 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5840 + namei
* map
.offset_size
),
5841 map
.offset_size
, map
.dwarf5_byte_order
);
5842 return map
.entry_pool
+ namei_entry_offs
;
5845 /* See dw2_debug_names_iterator. */
5847 dwarf2_per_cu_data
*
5848 dw2_debug_names_iterator::next ()
5853 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5854 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5855 bfd
*const abfd
= objfile
->obfd
;
5859 unsigned int bytes_read
;
5860 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5861 m_addr
+= bytes_read
;
5865 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5866 if (indexval_it
== m_map
.abbrev_map
.cend ())
5868 complaint (_("Wrong .debug_names undefined abbrev code %s "
5870 pulongest (abbrev
), objfile_name (objfile
));
5873 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5874 enum class symbol_linkage
{
5878 } symbol_linkage_
= symbol_linkage::unknown
;
5879 dwarf2_per_cu_data
*per_cu
= NULL
;
5880 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5885 case DW_FORM_implicit_const
:
5886 ull
= attr
.implicit_const
;
5888 case DW_FORM_flag_present
:
5892 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5893 m_addr
+= bytes_read
;
5896 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5897 dwarf_form_name (attr
.form
),
5898 objfile_name (objfile
));
5901 switch (attr
.dw_idx
)
5903 case DW_IDX_compile_unit
:
5904 /* Don't crash on bad data. */
5905 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5907 complaint (_(".debug_names entry has bad CU index %s"
5910 objfile_name (dwarf2_per_objfile
->objfile
));
5913 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5915 case DW_IDX_type_unit
:
5916 /* Don't crash on bad data. */
5917 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5919 complaint (_(".debug_names entry has bad TU index %s"
5922 objfile_name (dwarf2_per_objfile
->objfile
));
5925 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5927 case DW_IDX_GNU_internal
:
5928 if (!m_map
.augmentation_is_gdb
)
5930 symbol_linkage_
= symbol_linkage::static_
;
5932 case DW_IDX_GNU_external
:
5933 if (!m_map
.augmentation_is_gdb
)
5935 symbol_linkage_
= symbol_linkage::extern_
;
5940 /* Skip if already read in. */
5941 if (per_cu
->v
.quick
->compunit_symtab
)
5944 /* Check static vs global. */
5945 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5947 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5948 const bool symbol_is_static
=
5949 symbol_linkage_
== symbol_linkage::static_
;
5950 if (want_static
!= symbol_is_static
)
5954 /* Match dw2_symtab_iter_next, symbol_kind
5955 and debug_names::psymbol_tag. */
5959 switch (indexval
.dwarf_tag
)
5961 case DW_TAG_variable
:
5962 case DW_TAG_subprogram
:
5963 /* Some types are also in VAR_DOMAIN. */
5964 case DW_TAG_typedef
:
5965 case DW_TAG_structure_type
:
5972 switch (indexval
.dwarf_tag
)
5974 case DW_TAG_typedef
:
5975 case DW_TAG_structure_type
:
5982 switch (indexval
.dwarf_tag
)
5985 case DW_TAG_variable
:
5992 switch (indexval
.dwarf_tag
)
6004 /* Match dw2_expand_symtabs_matching, symbol_kind and
6005 debug_names::psymbol_tag. */
6008 case VARIABLES_DOMAIN
:
6009 switch (indexval
.dwarf_tag
)
6011 case DW_TAG_variable
:
6017 case FUNCTIONS_DOMAIN
:
6018 switch (indexval
.dwarf_tag
)
6020 case DW_TAG_subprogram
:
6027 switch (indexval
.dwarf_tag
)
6029 case DW_TAG_typedef
:
6030 case DW_TAG_structure_type
:
6036 case MODULES_DOMAIN
:
6037 switch (indexval
.dwarf_tag
)
6051 static struct compunit_symtab
*
6052 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6053 const char *name
, domain_enum domain
)
6055 struct dwarf2_per_objfile
*dwarf2_per_objfile
6056 = get_dwarf2_per_objfile (objfile
);
6058 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6061 /* index is NULL if OBJF_READNOW. */
6064 const auto &map
= *mapp
;
6066 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6068 struct compunit_symtab
*stab_best
= NULL
;
6069 struct dwarf2_per_cu_data
*per_cu
;
6070 while ((per_cu
= iter
.next ()) != NULL
)
6072 struct symbol
*sym
, *with_opaque
= NULL
;
6073 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6074 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6075 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6077 sym
= block_find_symbol (block
, name
, domain
,
6078 block_find_non_opaque_type_preferred
,
6081 /* Some caution must be observed with overloaded functions and
6082 methods, since the index will not contain any overload
6083 information (but NAME might contain it). */
6086 && strcmp_iw (sym
->search_name (), name
) == 0)
6088 if (with_opaque
!= NULL
6089 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6092 /* Keep looking through other CUs. */
6098 /* This dumps minimal information about .debug_names. It is called
6099 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6100 uses this to verify that .debug_names has been loaded. */
6103 dw2_debug_names_dump (struct objfile
*objfile
)
6105 struct dwarf2_per_objfile
*dwarf2_per_objfile
6106 = get_dwarf2_per_objfile (objfile
);
6108 gdb_assert (dwarf2_per_objfile
->using_index
);
6109 printf_filtered (".debug_names:");
6110 if (dwarf2_per_objfile
->debug_names_table
)
6111 printf_filtered (" exists\n");
6113 printf_filtered (" faked for \"readnow\"\n");
6114 printf_filtered ("\n");
6118 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6119 const char *func_name
)
6121 struct dwarf2_per_objfile
*dwarf2_per_objfile
6122 = get_dwarf2_per_objfile (objfile
);
6124 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6125 if (dwarf2_per_objfile
->debug_names_table
)
6127 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6129 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6131 struct dwarf2_per_cu_data
*per_cu
;
6132 while ((per_cu
= iter
.next ()) != NULL
)
6133 dw2_instantiate_symtab (per_cu
, false);
6138 dw2_debug_names_map_matching_symbols
6139 (struct objfile
*objfile
,
6140 const lookup_name_info
&name
, domain_enum domain
,
6142 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6143 symbol_compare_ftype
*ordered_compare
)
6145 struct dwarf2_per_objfile
*dwarf2_per_objfile
6146 = get_dwarf2_per_objfile (objfile
);
6148 /* debug_names_table is NULL if OBJF_READNOW. */
6149 if (!dwarf2_per_objfile
->debug_names_table
)
6152 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6153 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6155 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6156 auto matcher
= [&] (const char *symname
)
6158 if (ordered_compare
== nullptr)
6160 return ordered_compare (symname
, match_name
) == 0;
6163 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6164 [&] (offset_type namei
)
6166 /* The name was matched, now expand corresponding CUs that were
6168 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6170 struct dwarf2_per_cu_data
*per_cu
;
6171 while ((per_cu
= iter
.next ()) != NULL
)
6172 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6176 /* It's a shame we couldn't do this inside the
6177 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6178 that have already been expanded. Instead, this loop matches what
6179 the psymtab code does. */
6180 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6182 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6183 if (cust
!= nullptr)
6185 const struct block
*block
6186 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6187 if (!iterate_over_symbols_terminated (block
, name
,
6195 dw2_debug_names_expand_symtabs_matching
6196 (struct objfile
*objfile
,
6197 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6198 const lookup_name_info
&lookup_name
,
6199 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6200 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6201 enum search_domain kind
)
6203 struct dwarf2_per_objfile
*dwarf2_per_objfile
6204 = get_dwarf2_per_objfile (objfile
);
6206 /* debug_names_table is NULL if OBJF_READNOW. */
6207 if (!dwarf2_per_objfile
->debug_names_table
)
6210 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6212 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6214 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6216 kind
, [&] (offset_type namei
)
6218 /* The name was matched, now expand corresponding CUs that were
6220 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6222 struct dwarf2_per_cu_data
*per_cu
;
6223 while ((per_cu
= iter
.next ()) != NULL
)
6224 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6230 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6233 dw2_find_last_source_symtab
,
6234 dw2_forget_cached_source_info
,
6235 dw2_map_symtabs_matching_filename
,
6236 dw2_debug_names_lookup_symbol
,
6238 dw2_debug_names_dump
,
6239 dw2_debug_names_expand_symtabs_for_function
,
6240 dw2_expand_all_symtabs
,
6241 dw2_expand_symtabs_with_fullname
,
6242 dw2_debug_names_map_matching_symbols
,
6243 dw2_debug_names_expand_symtabs_matching
,
6244 dw2_find_pc_sect_compunit_symtab
,
6246 dw2_map_symbol_filenames
6249 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6250 to either a dwarf2_per_objfile or dwz_file object. */
6252 template <typename T
>
6253 static gdb::array_view
<const gdb_byte
>
6254 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6256 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6258 if (dwarf2_section_empty_p (section
))
6261 /* Older elfutils strip versions could keep the section in the main
6262 executable while splitting it for the separate debug info file. */
6263 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6266 dwarf2_read_section (obj
, section
);
6268 /* dwarf2_section_info::size is a bfd_size_type, while
6269 gdb::array_view works with size_t. On 32-bit hosts, with
6270 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6271 is 32-bit. So we need an explicit narrowing conversion here.
6272 This is fine, because it's impossible to allocate or mmap an
6273 array/buffer larger than what size_t can represent. */
6274 return gdb::make_array_view (section
->buffer
, section
->size
);
6277 /* Lookup the index cache for the contents of the index associated to
6280 static gdb::array_view
<const gdb_byte
>
6281 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6283 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6284 if (build_id
== nullptr)
6287 return global_index_cache
.lookup_gdb_index (build_id
,
6288 &dwarf2_obj
->index_cache_res
);
6291 /* Same as the above, but for DWZ. */
6293 static gdb::array_view
<const gdb_byte
>
6294 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6296 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6297 if (build_id
== nullptr)
6300 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6303 /* See symfile.h. */
6306 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6308 struct dwarf2_per_objfile
*dwarf2_per_objfile
6309 = get_dwarf2_per_objfile (objfile
);
6311 /* If we're about to read full symbols, don't bother with the
6312 indices. In this case we also don't care if some other debug
6313 format is making psymtabs, because they are all about to be
6315 if ((objfile
->flags
& OBJF_READNOW
))
6317 dwarf2_per_objfile
->using_index
= 1;
6318 create_all_comp_units (dwarf2_per_objfile
);
6319 create_all_type_units (dwarf2_per_objfile
);
6320 dwarf2_per_objfile
->quick_file_names_table
6321 = create_quick_file_names_table
6322 (dwarf2_per_objfile
->all_comp_units
.size ());
6324 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6325 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6327 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6329 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6330 struct dwarf2_per_cu_quick_data
);
6333 /* Return 1 so that gdb sees the "quick" functions. However,
6334 these functions will be no-ops because we will have expanded
6336 *index_kind
= dw_index_kind::GDB_INDEX
;
6340 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6342 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6346 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6347 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6348 get_gdb_index_contents_from_section
<dwz_file
>))
6350 *index_kind
= dw_index_kind::GDB_INDEX
;
6354 /* ... otherwise, try to find the index in the index cache. */
6355 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6356 get_gdb_index_contents_from_cache
,
6357 get_gdb_index_contents_from_cache_dwz
))
6359 global_index_cache
.hit ();
6360 *index_kind
= dw_index_kind::GDB_INDEX
;
6364 global_index_cache
.miss ();
6370 /* Build a partial symbol table. */
6373 dwarf2_build_psymtabs (struct objfile
*objfile
)
6375 struct dwarf2_per_objfile
*dwarf2_per_objfile
6376 = get_dwarf2_per_objfile (objfile
);
6378 init_psymbol_list (objfile
, 1024);
6382 /* This isn't really ideal: all the data we allocate on the
6383 objfile's obstack is still uselessly kept around. However,
6384 freeing it seems unsafe. */
6385 psymtab_discarder
psymtabs (objfile
);
6386 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6389 /* (maybe) store an index in the cache. */
6390 global_index_cache
.store (dwarf2_per_objfile
);
6392 catch (const gdb_exception_error
&except
)
6394 exception_print (gdb_stderr
, except
);
6398 /* Return the total length of the CU described by HEADER. */
6401 get_cu_length (const struct comp_unit_head
*header
)
6403 return header
->initial_length_size
+ header
->length
;
6406 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6409 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6411 sect_offset bottom
= cu_header
->sect_off
;
6412 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6414 return sect_off
>= bottom
&& sect_off
< top
;
6417 /* Find the base address of the compilation unit for range lists and
6418 location lists. It will normally be specified by DW_AT_low_pc.
6419 In DWARF-3 draft 4, the base address could be overridden by
6420 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6421 compilation units with discontinuous ranges. */
6424 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6426 struct attribute
*attr
;
6429 cu
->base_address
= 0;
6431 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6432 if (attr
!= nullptr)
6434 cu
->base_address
= attr_value_as_address (attr
);
6439 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6440 if (attr
!= nullptr)
6442 cu
->base_address
= attr_value_as_address (attr
);
6448 /* Read in the comp unit header information from the debug_info at info_ptr.
6449 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6450 NOTE: This leaves members offset, first_die_offset to be filled in
6453 static const gdb_byte
*
6454 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6455 const gdb_byte
*info_ptr
,
6456 struct dwarf2_section_info
*section
,
6457 rcuh_kind section_kind
)
6460 unsigned int bytes_read
;
6461 const char *filename
= get_section_file_name (section
);
6462 bfd
*abfd
= get_section_bfd_owner (section
);
6464 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6465 cu_header
->initial_length_size
= bytes_read
;
6466 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6467 info_ptr
+= bytes_read
;
6468 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6469 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6470 error (_("Dwarf Error: wrong version in compilation unit header "
6471 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6472 cu_header
->version
, filename
);
6474 if (cu_header
->version
< 5)
6475 switch (section_kind
)
6477 case rcuh_kind::COMPILE
:
6478 cu_header
->unit_type
= DW_UT_compile
;
6480 case rcuh_kind::TYPE
:
6481 cu_header
->unit_type
= DW_UT_type
;
6484 internal_error (__FILE__
, __LINE__
,
6485 _("read_comp_unit_head: invalid section_kind"));
6489 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6490 (read_1_byte (abfd
, info_ptr
));
6492 switch (cu_header
->unit_type
)
6496 case DW_UT_skeleton
:
6497 case DW_UT_split_compile
:
6498 if (section_kind
!= rcuh_kind::COMPILE
)
6499 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6500 "(is %s, should be %s) [in module %s]"),
6501 dwarf_unit_type_name (cu_header
->unit_type
),
6502 dwarf_unit_type_name (DW_UT_type
), filename
);
6505 case DW_UT_split_type
:
6506 section_kind
= rcuh_kind::TYPE
;
6509 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6510 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6511 "[in module %s]"), cu_header
->unit_type
,
6512 dwarf_unit_type_name (DW_UT_compile
),
6513 dwarf_unit_type_name (DW_UT_skeleton
),
6514 dwarf_unit_type_name (DW_UT_split_compile
),
6515 dwarf_unit_type_name (DW_UT_type
),
6516 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6519 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6522 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6525 info_ptr
+= bytes_read
;
6526 if (cu_header
->version
< 5)
6528 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6531 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6532 if (signed_addr
< 0)
6533 internal_error (__FILE__
, __LINE__
,
6534 _("read_comp_unit_head: dwarf from non elf file"));
6535 cu_header
->signed_addr_p
= signed_addr
;
6537 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6538 || cu_header
->unit_type
== DW_UT_skeleton
6539 || cu_header
->unit_type
== DW_UT_split_compile
;
6541 if (header_has_signature
)
6543 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6547 if (section_kind
== rcuh_kind::TYPE
)
6549 LONGEST type_offset
;
6550 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6551 info_ptr
+= bytes_read
;
6552 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6553 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6554 error (_("Dwarf Error: Too big type_offset in compilation unit "
6555 "header (is %s) [in module %s]"), plongest (type_offset
),
6562 /* Helper function that returns the proper abbrev section for
6565 static struct dwarf2_section_info
*
6566 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6568 struct dwarf2_section_info
*abbrev
;
6569 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6571 if (this_cu
->is_dwz
)
6572 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6574 abbrev
= &dwarf2_per_objfile
->abbrev
;
6579 /* Subroutine of read_and_check_comp_unit_head and
6580 read_and_check_type_unit_head to simplify them.
6581 Perform various error checking on the header. */
6584 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6585 struct comp_unit_head
*header
,
6586 struct dwarf2_section_info
*section
,
6587 struct dwarf2_section_info
*abbrev_section
)
6589 const char *filename
= get_section_file_name (section
);
6591 if (to_underlying (header
->abbrev_sect_off
)
6592 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6593 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6594 "(offset %s + 6) [in module %s]"),
6595 sect_offset_str (header
->abbrev_sect_off
),
6596 sect_offset_str (header
->sect_off
),
6599 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6600 avoid potential 32-bit overflow. */
6601 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6603 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6604 "(offset %s + 0) [in module %s]"),
6605 header
->length
, sect_offset_str (header
->sect_off
),
6609 /* Read in a CU/TU header and perform some basic error checking.
6610 The contents of the header are stored in HEADER.
6611 The result is a pointer to the start of the first DIE. */
6613 static const gdb_byte
*
6614 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6615 struct comp_unit_head
*header
,
6616 struct dwarf2_section_info
*section
,
6617 struct dwarf2_section_info
*abbrev_section
,
6618 const gdb_byte
*info_ptr
,
6619 rcuh_kind section_kind
)
6621 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6623 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6625 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6627 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6629 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6635 /* Fetch the abbreviation table offset from a comp or type unit header. */
6638 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6639 struct dwarf2_section_info
*section
,
6640 sect_offset sect_off
)
6642 bfd
*abfd
= get_section_bfd_owner (section
);
6643 const gdb_byte
*info_ptr
;
6644 unsigned int initial_length_size
, offset_size
;
6647 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6648 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6649 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6650 offset_size
= initial_length_size
== 4 ? 4 : 8;
6651 info_ptr
+= initial_length_size
;
6653 version
= read_2_bytes (abfd
, info_ptr
);
6657 /* Skip unit type and address size. */
6661 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6664 /* Allocate a new partial symtab for file named NAME and mark this new
6665 partial symtab as being an include of PST. */
6668 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6669 struct objfile
*objfile
)
6671 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
6673 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6675 /* It shares objfile->objfile_obstack. */
6676 subpst
->dirname
= pst
->dirname
;
6679 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6680 subpst
->dependencies
[0] = pst
;
6681 subpst
->number_of_dependencies
= 1;
6683 subpst
->read_symtab
= pst
->read_symtab
;
6685 /* No private part is necessary for include psymtabs. This property
6686 can be used to differentiate between such include psymtabs and
6687 the regular ones. */
6688 subpst
->read_symtab_private
= NULL
;
6691 /* Read the Line Number Program data and extract the list of files
6692 included by the source file represented by PST. Build an include
6693 partial symtab for each of these included files. */
6696 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6697 struct die_info
*die
,
6698 struct partial_symtab
*pst
)
6701 struct attribute
*attr
;
6703 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6704 if (attr
!= nullptr)
6705 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6707 return; /* No linetable, so no includes. */
6709 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6710 that we pass in the raw text_low here; that is ok because we're
6711 only decoding the line table to make include partial symtabs, and
6712 so the addresses aren't really used. */
6713 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6714 pst
->raw_text_low (), 1);
6718 hash_signatured_type (const void *item
)
6720 const struct signatured_type
*sig_type
6721 = (const struct signatured_type
*) item
;
6723 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6724 return sig_type
->signature
;
6728 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6730 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6731 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6733 return lhs
->signature
== rhs
->signature
;
6736 /* Allocate a hash table for signatured types. */
6739 allocate_signatured_type_table (struct objfile
*objfile
)
6741 return htab_create_alloc_ex (41,
6742 hash_signatured_type
,
6745 &objfile
->objfile_obstack
,
6746 hashtab_obstack_allocate
,
6747 dummy_obstack_deallocate
);
6750 /* A helper function to add a signatured type CU to a table. */
6753 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6755 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6756 std::vector
<signatured_type
*> *all_type_units
6757 = (std::vector
<signatured_type
*> *) datum
;
6759 all_type_units
->push_back (sigt
);
6764 /* A helper for create_debug_types_hash_table. Read types from SECTION
6765 and fill them into TYPES_HTAB. It will process only type units,
6766 therefore DW_UT_type. */
6769 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6770 struct dwo_file
*dwo_file
,
6771 dwarf2_section_info
*section
, htab_t
&types_htab
,
6772 rcuh_kind section_kind
)
6774 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6775 struct dwarf2_section_info
*abbrev_section
;
6777 const gdb_byte
*info_ptr
, *end_ptr
;
6779 abbrev_section
= (dwo_file
!= NULL
6780 ? &dwo_file
->sections
.abbrev
6781 : &dwarf2_per_objfile
->abbrev
);
6783 if (dwarf_read_debug
)
6784 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6785 get_section_name (section
),
6786 get_section_file_name (abbrev_section
));
6788 dwarf2_read_section (objfile
, section
);
6789 info_ptr
= section
->buffer
;
6791 if (info_ptr
== NULL
)
6794 /* We can't set abfd until now because the section may be empty or
6795 not present, in which case the bfd is unknown. */
6796 abfd
= get_section_bfd_owner (section
);
6798 /* We don't use init_cutu_and_read_dies_simple, or some such, here
6799 because we don't need to read any dies: the signature is in the
6802 end_ptr
= info_ptr
+ section
->size
;
6803 while (info_ptr
< end_ptr
)
6805 struct signatured_type
*sig_type
;
6806 struct dwo_unit
*dwo_tu
;
6808 const gdb_byte
*ptr
= info_ptr
;
6809 struct comp_unit_head header
;
6810 unsigned int length
;
6812 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6814 /* Initialize it due to a false compiler warning. */
6815 header
.signature
= -1;
6816 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6818 /* We need to read the type's signature in order to build the hash
6819 table, but we don't need anything else just yet. */
6821 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6822 abbrev_section
, ptr
, section_kind
);
6824 length
= get_cu_length (&header
);
6826 /* Skip dummy type units. */
6827 if (ptr
>= info_ptr
+ length
6828 || peek_abbrev_code (abfd
, ptr
) == 0
6829 || header
.unit_type
!= DW_UT_type
)
6835 if (types_htab
== NULL
)
6838 types_htab
= allocate_dwo_unit_table (objfile
);
6840 types_htab
= allocate_signatured_type_table (objfile
);
6846 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6848 dwo_tu
->dwo_file
= dwo_file
;
6849 dwo_tu
->signature
= header
.signature
;
6850 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6851 dwo_tu
->section
= section
;
6852 dwo_tu
->sect_off
= sect_off
;
6853 dwo_tu
->length
= length
;
6857 /* N.B.: type_offset is not usable if this type uses a DWO file.
6858 The real type_offset is in the DWO file. */
6860 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6861 struct signatured_type
);
6862 sig_type
->signature
= header
.signature
;
6863 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6864 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6865 sig_type
->per_cu
.is_debug_types
= 1;
6866 sig_type
->per_cu
.section
= section
;
6867 sig_type
->per_cu
.sect_off
= sect_off
;
6868 sig_type
->per_cu
.length
= length
;
6871 slot
= htab_find_slot (types_htab
,
6872 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6874 gdb_assert (slot
!= NULL
);
6877 sect_offset dup_sect_off
;
6881 const struct dwo_unit
*dup_tu
6882 = (const struct dwo_unit
*) *slot
;
6884 dup_sect_off
= dup_tu
->sect_off
;
6888 const struct signatured_type
*dup_tu
6889 = (const struct signatured_type
*) *slot
;
6891 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6894 complaint (_("debug type entry at offset %s is duplicate to"
6895 " the entry at offset %s, signature %s"),
6896 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6897 hex_string (header
.signature
));
6899 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6901 if (dwarf_read_debug
> 1)
6902 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6903 sect_offset_str (sect_off
),
6904 hex_string (header
.signature
));
6910 /* Create the hash table of all entries in the .debug_types
6911 (or .debug_types.dwo) section(s).
6912 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6913 otherwise it is NULL.
6915 The result is a pointer to the hash table or NULL if there are no types.
6917 Note: This function processes DWO files only, not DWP files. */
6920 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6921 struct dwo_file
*dwo_file
,
6922 gdb::array_view
<dwarf2_section_info
> type_sections
,
6925 for (dwarf2_section_info
§ion
: type_sections
)
6926 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6927 types_htab
, rcuh_kind::TYPE
);
6930 /* Create the hash table of all entries in the .debug_types section,
6931 and initialize all_type_units.
6932 The result is zero if there is an error (e.g. missing .debug_types section),
6933 otherwise non-zero. */
6936 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6938 htab_t types_htab
= NULL
;
6940 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6941 &dwarf2_per_objfile
->info
, types_htab
,
6942 rcuh_kind::COMPILE
);
6943 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6944 dwarf2_per_objfile
->types
, types_htab
);
6945 if (types_htab
== NULL
)
6947 dwarf2_per_objfile
->signatured_types
= NULL
;
6951 dwarf2_per_objfile
->signatured_types
= types_htab
;
6953 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6954 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6956 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6957 &dwarf2_per_objfile
->all_type_units
);
6962 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6963 If SLOT is non-NULL, it is the entry to use in the hash table.
6964 Otherwise we find one. */
6966 static struct signatured_type
*
6967 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6970 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6972 if (dwarf2_per_objfile
->all_type_units
.size ()
6973 == dwarf2_per_objfile
->all_type_units
.capacity ())
6974 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6976 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6977 struct signatured_type
);
6979 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6980 sig_type
->signature
= sig
;
6981 sig_type
->per_cu
.is_debug_types
= 1;
6982 if (dwarf2_per_objfile
->using_index
)
6984 sig_type
->per_cu
.v
.quick
=
6985 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6986 struct dwarf2_per_cu_quick_data
);
6991 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
6994 gdb_assert (*slot
== NULL
);
6996 /* The rest of sig_type must be filled in by the caller. */
7000 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7001 Fill in SIG_ENTRY with DWO_ENTRY. */
7004 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7005 struct signatured_type
*sig_entry
,
7006 struct dwo_unit
*dwo_entry
)
7008 /* Make sure we're not clobbering something we don't expect to. */
7009 gdb_assert (! sig_entry
->per_cu
.queued
);
7010 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7011 if (dwarf2_per_objfile
->using_index
)
7013 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7014 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7017 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7018 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7019 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7020 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7021 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7023 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7024 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7025 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7026 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7027 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7028 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7029 sig_entry
->dwo_unit
= dwo_entry
;
7032 /* Subroutine of lookup_signatured_type.
7033 If we haven't read the TU yet, create the signatured_type data structure
7034 for a TU to be read in directly from a DWO file, bypassing the stub.
7035 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7036 using .gdb_index, then when reading a CU we want to stay in the DWO file
7037 containing that CU. Otherwise we could end up reading several other DWO
7038 files (due to comdat folding) to process the transitive closure of all the
7039 mentioned TUs, and that can be slow. The current DWO file will have every
7040 type signature that it needs.
7041 We only do this for .gdb_index because in the psymtab case we already have
7042 to read all the DWOs to build the type unit groups. */
7044 static struct signatured_type
*
7045 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7047 struct dwarf2_per_objfile
*dwarf2_per_objfile
7048 = cu
->per_cu
->dwarf2_per_objfile
;
7049 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7050 struct dwo_file
*dwo_file
;
7051 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7052 struct signatured_type find_sig_entry
, *sig_entry
;
7055 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7057 /* If TU skeletons have been removed then we may not have read in any
7059 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7061 dwarf2_per_objfile
->signatured_types
7062 = allocate_signatured_type_table (objfile
);
7065 /* We only ever need to read in one copy of a signatured type.
7066 Use the global signatured_types array to do our own comdat-folding
7067 of types. If this is the first time we're reading this TU, and
7068 the TU has an entry in .gdb_index, replace the recorded data from
7069 .gdb_index with this TU. */
7071 find_sig_entry
.signature
= sig
;
7072 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7073 &find_sig_entry
, INSERT
);
7074 sig_entry
= (struct signatured_type
*) *slot
;
7076 /* We can get here with the TU already read, *or* in the process of being
7077 read. Don't reassign the global entry to point to this DWO if that's
7078 the case. Also note that if the TU is already being read, it may not
7079 have come from a DWO, the program may be a mix of Fission-compiled
7080 code and non-Fission-compiled code. */
7082 /* Have we already tried to read this TU?
7083 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7084 needn't exist in the global table yet). */
7085 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7088 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7089 dwo_unit of the TU itself. */
7090 dwo_file
= cu
->dwo_unit
->dwo_file
;
7092 /* Ok, this is the first time we're reading this TU. */
7093 if (dwo_file
->tus
== NULL
)
7095 find_dwo_entry
.signature
= sig
;
7096 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7097 if (dwo_entry
== NULL
)
7100 /* If the global table doesn't have an entry for this TU, add one. */
7101 if (sig_entry
== NULL
)
7102 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7104 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7105 sig_entry
->per_cu
.tu_read
= 1;
7109 /* Subroutine of lookup_signatured_type.
7110 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7111 then try the DWP file. If the TU stub (skeleton) has been removed then
7112 it won't be in .gdb_index. */
7114 static struct signatured_type
*
7115 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7117 struct dwarf2_per_objfile
*dwarf2_per_objfile
7118 = cu
->per_cu
->dwarf2_per_objfile
;
7119 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7120 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7121 struct dwo_unit
*dwo_entry
;
7122 struct signatured_type find_sig_entry
, *sig_entry
;
7125 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7126 gdb_assert (dwp_file
!= NULL
);
7128 /* If TU skeletons have been removed then we may not have read in any
7130 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7132 dwarf2_per_objfile
->signatured_types
7133 = allocate_signatured_type_table (objfile
);
7136 find_sig_entry
.signature
= sig
;
7137 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7138 &find_sig_entry
, INSERT
);
7139 sig_entry
= (struct signatured_type
*) *slot
;
7141 /* Have we already tried to read this TU?
7142 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7143 needn't exist in the global table yet). */
7144 if (sig_entry
!= NULL
)
7147 if (dwp_file
->tus
== NULL
)
7149 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7150 sig
, 1 /* is_debug_types */);
7151 if (dwo_entry
== NULL
)
7154 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7155 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7160 /* Lookup a signature based type for DW_FORM_ref_sig8.
7161 Returns NULL if signature SIG is not present in the table.
7162 It is up to the caller to complain about this. */
7164 static struct signatured_type
*
7165 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7167 struct dwarf2_per_objfile
*dwarf2_per_objfile
7168 = cu
->per_cu
->dwarf2_per_objfile
;
7171 && dwarf2_per_objfile
->using_index
)
7173 /* We're in a DWO/DWP file, and we're using .gdb_index.
7174 These cases require special processing. */
7175 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7176 return lookup_dwo_signatured_type (cu
, sig
);
7178 return lookup_dwp_signatured_type (cu
, sig
);
7182 struct signatured_type find_entry
, *entry
;
7184 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7186 find_entry
.signature
= sig
;
7187 entry
= ((struct signatured_type
*)
7188 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7193 /* Return the address base of the compile unit, which, if exists, is stored
7194 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7195 static gdb::optional
<ULONGEST
>
7196 lookup_addr_base (struct die_info
*comp_unit_die
)
7198 struct attribute
*attr
;
7199 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7200 if (attr
== nullptr)
7201 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7202 if (attr
== nullptr)
7203 return gdb::optional
<ULONGEST
> ();
7204 return DW_UNSND (attr
);
7207 /* Return range lists base of the compile unit, which, if exists, is stored
7208 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7210 lookup_ranges_base (struct die_info
*comp_unit_die
)
7212 struct attribute
*attr
;
7213 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7214 if (attr
== nullptr)
7215 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7216 if (attr
== nullptr)
7218 return DW_UNSND (attr
);
7221 /* Low level DIE reading support. */
7223 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7226 init_cu_die_reader (struct die_reader_specs
*reader
,
7227 struct dwarf2_cu
*cu
,
7228 struct dwarf2_section_info
*section
,
7229 struct dwo_file
*dwo_file
,
7230 struct abbrev_table
*abbrev_table
)
7232 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7233 reader
->abfd
= get_section_bfd_owner (section
);
7235 reader
->dwo_file
= dwo_file
;
7236 reader
->die_section
= section
;
7237 reader
->buffer
= section
->buffer
;
7238 reader
->buffer_end
= section
->buffer
+ section
->size
;
7239 reader
->comp_dir
= NULL
;
7240 reader
->abbrev_table
= abbrev_table
;
7243 /* Subroutine of init_cutu_and_read_dies to simplify it.
7244 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7245 There's just a lot of work to do, and init_cutu_and_read_dies is big enough
7248 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7249 from it to the DIE in the DWO. If NULL we are skipping the stub.
7250 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7251 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7252 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7253 STUB_COMP_DIR may be non-NULL.
7254 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7255 are filled in with the info of the DIE from the DWO file.
7256 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7257 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7258 kept around for at least as long as *RESULT_READER.
7260 The result is non-zero if a valid (non-dummy) DIE was found. */
7263 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7264 struct dwo_unit
*dwo_unit
,
7265 struct die_info
*stub_comp_unit_die
,
7266 const char *stub_comp_dir
,
7267 struct die_reader_specs
*result_reader
,
7268 const gdb_byte
**result_info_ptr
,
7269 struct die_info
**result_comp_unit_die
,
7270 int *result_has_children
,
7271 abbrev_table_up
*result_dwo_abbrev_table
)
7273 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7274 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7275 struct dwarf2_cu
*cu
= this_cu
->cu
;
7277 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7278 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7279 int i
,num_extra_attrs
;
7280 struct dwarf2_section_info
*dwo_abbrev_section
;
7281 struct die_info
*comp_unit_die
;
7283 /* At most one of these may be provided. */
7284 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7286 /* These attributes aren't processed until later:
7287 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7288 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7289 referenced later. However, these attributes are found in the stub
7290 which we won't have later. In order to not impose this complication
7291 on the rest of the code, we read them here and copy them to the
7300 if (stub_comp_unit_die
!= NULL
)
7302 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7304 if (! this_cu
->is_debug_types
)
7305 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7306 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7307 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7308 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7309 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7311 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7313 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7314 here (if needed). We need the value before we can process
7316 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7318 else if (stub_comp_dir
!= NULL
)
7320 /* Reconstruct the comp_dir attribute to simplify the code below. */
7321 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7322 comp_dir
->name
= DW_AT_comp_dir
;
7323 comp_dir
->form
= DW_FORM_string
;
7324 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7325 DW_STRING (comp_dir
) = stub_comp_dir
;
7328 /* Set up for reading the DWO CU/TU. */
7329 cu
->dwo_unit
= dwo_unit
;
7330 dwarf2_section_info
*section
= dwo_unit
->section
;
7331 dwarf2_read_section (objfile
, section
);
7332 abfd
= get_section_bfd_owner (section
);
7333 begin_info_ptr
= info_ptr
= (section
->buffer
7334 + to_underlying (dwo_unit
->sect_off
));
7335 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7337 if (this_cu
->is_debug_types
)
7339 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7341 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7342 &cu
->header
, section
,
7344 info_ptr
, rcuh_kind::TYPE
);
7345 /* This is not an assert because it can be caused by bad debug info. */
7346 if (sig_type
->signature
!= cu
->header
.signature
)
7348 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7349 " TU at offset %s [in module %s]"),
7350 hex_string (sig_type
->signature
),
7351 hex_string (cu
->header
.signature
),
7352 sect_offset_str (dwo_unit
->sect_off
),
7353 bfd_get_filename (abfd
));
7355 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7356 /* For DWOs coming from DWP files, we don't know the CU length
7357 nor the type's offset in the TU until now. */
7358 dwo_unit
->length
= get_cu_length (&cu
->header
);
7359 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7361 /* Establish the type offset that can be used to lookup the type.
7362 For DWO files, we don't know it until now. */
7363 sig_type
->type_offset_in_section
7364 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7368 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7369 &cu
->header
, section
,
7371 info_ptr
, rcuh_kind::COMPILE
);
7372 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7373 /* For DWOs coming from DWP files, we don't know the CU length
7375 dwo_unit
->length
= get_cu_length (&cu
->header
);
7378 *result_dwo_abbrev_table
7379 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7380 cu
->header
.abbrev_sect_off
);
7381 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7382 result_dwo_abbrev_table
->get ());
7384 /* Read in the die, but leave space to copy over the attributes
7385 from the stub. This has the benefit of simplifying the rest of
7386 the code - all the work to maintain the illusion of a single
7387 DW_TAG_{compile,type}_unit DIE is done here. */
7388 num_extra_attrs
= ((stmt_list
!= NULL
)
7392 + (comp_dir
!= NULL
));
7393 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7394 result_has_children
, num_extra_attrs
);
7396 /* Copy over the attributes from the stub to the DIE we just read in. */
7397 comp_unit_die
= *result_comp_unit_die
;
7398 i
= comp_unit_die
->num_attrs
;
7399 if (stmt_list
!= NULL
)
7400 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7402 comp_unit_die
->attrs
[i
++] = *low_pc
;
7403 if (high_pc
!= NULL
)
7404 comp_unit_die
->attrs
[i
++] = *high_pc
;
7406 comp_unit_die
->attrs
[i
++] = *ranges
;
7407 if (comp_dir
!= NULL
)
7408 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7409 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7411 if (dwarf_die_debug
)
7413 fprintf_unfiltered (gdb_stdlog
,
7414 "Read die from %s@0x%x of %s:\n",
7415 get_section_name (section
),
7416 (unsigned) (begin_info_ptr
- section
->buffer
),
7417 bfd_get_filename (abfd
));
7418 dump_die (comp_unit_die
, dwarf_die_debug
);
7421 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7422 TUs by skipping the stub and going directly to the entry in the DWO file.
7423 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7424 to get it via circuitous means. Blech. */
7425 if (comp_dir
!= NULL
)
7426 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7428 /* Skip dummy compilation units. */
7429 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7430 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7433 *result_info_ptr
= info_ptr
;
7437 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7438 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7439 signature is part of the header. */
7440 static gdb::optional
<ULONGEST
>
7441 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7443 if (cu
->header
.version
>= 5)
7444 return cu
->header
.signature
;
7445 struct attribute
*attr
;
7446 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7447 if (attr
== nullptr)
7448 return gdb::optional
<ULONGEST
> ();
7449 return DW_UNSND (attr
);
7452 /* Subroutine of init_cutu_and_read_dies to simplify it.
7453 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7454 Returns NULL if the specified DWO unit cannot be found. */
7456 static struct dwo_unit
*
7457 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7458 struct die_info
*comp_unit_die
)
7460 struct dwarf2_cu
*cu
= this_cu
->cu
;
7461 struct dwo_unit
*dwo_unit
;
7462 const char *comp_dir
, *dwo_name
;
7464 gdb_assert (cu
!= NULL
);
7466 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7467 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7468 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7470 if (this_cu
->is_debug_types
)
7472 struct signatured_type
*sig_type
;
7474 /* Since this_cu is the first member of struct signatured_type,
7475 we can go from a pointer to one to a pointer to the other. */
7476 sig_type
= (struct signatured_type
*) this_cu
;
7477 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7481 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7482 if (!signature
.has_value ())
7483 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7485 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7486 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7493 /* Subroutine of init_cutu_and_read_dies to simplify it.
7494 See it for a description of the parameters.
7495 Read a TU directly from a DWO file, bypassing the stub. */
7498 init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7499 int use_existing_cu
, int keep
,
7500 die_reader_func_ftype
*die_reader_func
,
7503 std::unique_ptr
<dwarf2_cu
> new_cu
;
7504 struct signatured_type
*sig_type
;
7505 struct die_reader_specs reader
;
7506 const gdb_byte
*info_ptr
;
7507 struct die_info
*comp_unit_die
;
7509 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7511 /* Verify we can do the following downcast, and that we have the
7513 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7514 sig_type
= (struct signatured_type
*) this_cu
;
7515 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7517 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7519 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7520 /* There's no need to do the rereading_dwo_cu handling that
7521 init_cutu_and_read_dies does since we don't read the stub. */
7525 /* If !use_existing_cu, this_cu->cu must be NULL. */
7526 gdb_assert (this_cu
->cu
== NULL
);
7527 new_cu
.reset (new dwarf2_cu (this_cu
));
7530 /* A future optimization, if needed, would be to use an existing
7531 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7532 could share abbrev tables. */
7534 /* The abbreviation table used by READER, this must live at least as long as
7536 abbrev_table_up dwo_abbrev_table
;
7538 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7539 NULL
/* stub_comp_unit_die */,
7540 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7542 &comp_unit_die
, &has_children
,
7543 &dwo_abbrev_table
) == 0)
7549 /* All the "real" work is done here. */
7550 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7552 /* This duplicates the code in init_cutu_and_read_dies,
7553 but the alternative is making the latter more complex.
7554 This function is only for the special case of using DWO files directly:
7555 no point in overly complicating the general case just to handle this. */
7556 if (new_cu
!= NULL
&& keep
)
7558 /* Link this CU into read_in_chain. */
7559 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7560 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7561 /* The chain owns it now. */
7566 /* Initialize a CU (or TU) and read its DIEs.
7567 If the CU defers to a DWO file, read the DWO file as well.
7569 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7570 Otherwise the table specified in the comp unit header is read in and used.
7571 This is an optimization for when we already have the abbrev table.
7573 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7574 Otherwise, a new CU is allocated with xmalloc.
7576 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7577 read_in_chain. Otherwise the dwarf2_cu data is freed at the end.
7579 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7580 linker) then DIE_READER_FUNC will not get called. */
7583 init_cutu_and_read_dies (struct dwarf2_per_cu_data
*this_cu
,
7584 struct abbrev_table
*abbrev_table
,
7585 int use_existing_cu
, int keep
,
7587 die_reader_func_ftype
*die_reader_func
,
7590 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7591 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7592 struct dwarf2_section_info
*section
= this_cu
->section
;
7593 bfd
*abfd
= get_section_bfd_owner (section
);
7594 struct dwarf2_cu
*cu
;
7595 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7596 struct die_reader_specs reader
;
7597 struct die_info
*comp_unit_die
;
7599 struct signatured_type
*sig_type
= NULL
;
7600 struct dwarf2_section_info
*abbrev_section
;
7601 /* Non-zero if CU currently points to a DWO file and we need to
7602 reread it. When this happens we need to reread the skeleton die
7603 before we can reread the DWO file (this only applies to CUs, not TUs). */
7604 int rereading_dwo_cu
= 0;
7606 if (dwarf_die_debug
)
7607 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7608 this_cu
->is_debug_types
? "type" : "comp",
7609 sect_offset_str (this_cu
->sect_off
));
7611 if (use_existing_cu
)
7614 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7615 file (instead of going through the stub), short-circuit all of this. */
7616 if (this_cu
->reading_dwo_directly
)
7618 /* Narrow down the scope of possibilities to have to understand. */
7619 gdb_assert (this_cu
->is_debug_types
);
7620 gdb_assert (abbrev_table
== NULL
);
7621 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
,
7622 die_reader_func
, data
);
7626 /* This is cheap if the section is already read in. */
7627 dwarf2_read_section (objfile
, section
);
7629 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7631 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7633 std::unique_ptr
<dwarf2_cu
> new_cu
;
7634 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7637 /* If this CU is from a DWO file we need to start over, we need to
7638 refetch the attributes from the skeleton CU.
7639 This could be optimized by retrieving those attributes from when we
7640 were here the first time: the previous comp_unit_die was stored in
7641 comp_unit_obstack. But there's no data yet that we need this
7643 if (cu
->dwo_unit
!= NULL
)
7644 rereading_dwo_cu
= 1;
7648 /* If !use_existing_cu, this_cu->cu must be NULL. */
7649 gdb_assert (this_cu
->cu
== NULL
);
7650 new_cu
.reset (new dwarf2_cu (this_cu
));
7654 /* Get the header. */
7655 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7657 /* We already have the header, there's no need to read it in again. */
7658 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7662 if (this_cu
->is_debug_types
)
7664 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7665 &cu
->header
, section
,
7666 abbrev_section
, info_ptr
,
7669 /* Since per_cu is the first member of struct signatured_type,
7670 we can go from a pointer to one to a pointer to the other. */
7671 sig_type
= (struct signatured_type
*) this_cu
;
7672 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7673 gdb_assert (sig_type
->type_offset_in_tu
7674 == cu
->header
.type_cu_offset_in_tu
);
7675 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7677 /* LENGTH has not been set yet for type units if we're
7678 using .gdb_index. */
7679 this_cu
->length
= get_cu_length (&cu
->header
);
7681 /* Establish the type offset that can be used to lookup the type. */
7682 sig_type
->type_offset_in_section
=
7683 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7685 this_cu
->dwarf_version
= cu
->header
.version
;
7689 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7690 &cu
->header
, section
,
7693 rcuh_kind::COMPILE
);
7695 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7696 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7697 this_cu
->dwarf_version
= cu
->header
.version
;
7701 /* Skip dummy compilation units. */
7702 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7703 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7706 /* If we don't have them yet, read the abbrevs for this compilation unit.
7707 And if we need to read them now, make sure they're freed when we're
7708 done (own the table through ABBREV_TABLE_HOLDER). */
7709 abbrev_table_up abbrev_table_holder
;
7710 if (abbrev_table
!= NULL
)
7711 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7715 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7716 cu
->header
.abbrev_sect_off
);
7717 abbrev_table
= abbrev_table_holder
.get ();
7720 /* Read the top level CU/TU die. */
7721 init_cu_die_reader (&reader
, cu
, section
, NULL
, abbrev_table
);
7722 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7724 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7727 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7728 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7729 table from the DWO file and pass the ownership over to us. It will be
7730 referenced from READER, so we must make sure to free it after we're done
7733 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7734 DWO CU, that this test will fail (the attribute will not be present). */
7735 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7736 abbrev_table_up dwo_abbrev_table
;
7737 if (dwo_name
!= nullptr)
7739 struct dwo_unit
*dwo_unit
;
7740 struct die_info
*dwo_comp_unit_die
;
7744 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7745 " has children (offset %s) [in module %s]"),
7746 sect_offset_str (this_cu
->sect_off
),
7747 bfd_get_filename (abfd
));
7749 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
);
7750 if (dwo_unit
!= NULL
)
7752 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7753 comp_unit_die
, NULL
,
7755 &dwo_comp_unit_die
, &has_children
,
7756 &dwo_abbrev_table
) == 0)
7761 comp_unit_die
= dwo_comp_unit_die
;
7765 /* Yikes, we couldn't find the rest of the DIE, we only have
7766 the stub. A complaint has already been logged. There's
7767 not much more we can do except pass on the stub DIE to
7768 die_reader_func. We don't want to throw an error on bad
7773 /* All of the above is setup for this call. Yikes. */
7774 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7776 /* Done, clean up. */
7777 if (new_cu
!= NULL
&& keep
)
7779 /* Link this CU into read_in_chain. */
7780 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7781 dwarf2_per_objfile
->read_in_chain
= this_cu
;
7782 /* The chain owns it now. */
7787 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7788 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7789 assumed to have already done the lookup to find the DWO file).
7791 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7792 THIS_CU->is_debug_types, but nothing else.
7794 We fill in THIS_CU->length.
7796 WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental
7797 linker) then DIE_READER_FUNC will not get called.
7799 THIS_CU->cu is always freed when done.
7800 This is done in order to not leave THIS_CU->cu in a state where we have
7801 to care whether it refers to the "main" CU or the DWO CU.
7803 When parent_cu is passed, it is used to provide a default value for
7804 str_offsets_base and addr_base from the parent. */
7807 init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data
*this_cu
,
7808 struct dwarf2_cu
*parent_cu
,
7809 struct dwo_file
*dwo_file
,
7810 die_reader_func_ftype
*die_reader_func
,
7813 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7814 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7815 struct dwarf2_section_info
*section
= this_cu
->section
;
7816 bfd
*abfd
= get_section_bfd_owner (section
);
7817 struct dwarf2_section_info
*abbrev_section
;
7818 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7819 struct die_reader_specs reader
;
7820 struct die_info
*comp_unit_die
;
7823 if (dwarf_die_debug
)
7824 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7825 this_cu
->is_debug_types
? "type" : "comp",
7826 sect_offset_str (this_cu
->sect_off
));
7828 gdb_assert (this_cu
->cu
== NULL
);
7830 abbrev_section
= (dwo_file
!= NULL
7831 ? &dwo_file
->sections
.abbrev
7832 : get_abbrev_section_for_cu (this_cu
));
7834 /* This is cheap if the section is already read in. */
7835 dwarf2_read_section (objfile
, section
);
7837 struct dwarf2_cu
cu (this_cu
);
7839 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7840 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7841 &cu
.header
, section
,
7842 abbrev_section
, info_ptr
,
7843 (this_cu
->is_debug_types
7845 : rcuh_kind::COMPILE
));
7847 if (parent_cu
!= nullptr)
7849 cu
.str_offsets_base
= parent_cu
->str_offsets_base
;
7850 cu
.addr_base
= parent_cu
->addr_base
;
7852 this_cu
->length
= get_cu_length (&cu
.header
);
7854 /* Skip dummy compilation units. */
7855 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7856 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7859 abbrev_table_up abbrev_table
7860 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7861 cu
.header
.abbrev_sect_off
);
7863 init_cu_die_reader (&reader
, &cu
, section
, dwo_file
, abbrev_table
.get ());
7864 info_ptr
= read_full_die (&reader
, &comp_unit_die
, info_ptr
, &has_children
);
7866 die_reader_func (&reader
, info_ptr
, comp_unit_die
, has_children
, data
);
7869 /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name
7870 (DW_AT_dwo_name) and does not lookup the specified DWO file.
7871 This cannot be used to read DWO files.
7873 THIS_CU->cu is always freed when done.
7874 This is done in order to not leave THIS_CU->cu in a state where we have
7875 to care whether it refers to the "main" CU or the DWO CU.
7876 We can revisit this if the data shows there's a performance issue. */
7879 init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data
*this_cu
,
7880 die_reader_func_ftype
*die_reader_func
,
7883 init_cutu_and_read_dies_no_follow (this_cu
, NULL
, NULL
, die_reader_func
, data
);
7886 /* Type Unit Groups.
7888 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7889 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7890 so that all types coming from the same compilation (.o file) are grouped
7891 together. A future step could be to put the types in the same symtab as
7892 the CU the types ultimately came from. */
7895 hash_type_unit_group (const void *item
)
7897 const struct type_unit_group
*tu_group
7898 = (const struct type_unit_group
*) item
;
7900 return hash_stmt_list_entry (&tu_group
->hash
);
7904 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7906 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7907 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7909 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7912 /* Allocate a hash table for type unit groups. */
7915 allocate_type_unit_groups_table (struct objfile
*objfile
)
7917 return htab_create_alloc_ex (3,
7918 hash_type_unit_group
,
7921 &objfile
->objfile_obstack
,
7922 hashtab_obstack_allocate
,
7923 dummy_obstack_deallocate
);
7926 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7927 partial symtabs. We combine several TUs per psymtab to not let the size
7928 of any one psymtab grow too big. */
7929 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7930 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7932 /* Helper routine for get_type_unit_group.
7933 Create the type_unit_group object used to hold one or more TUs. */
7935 static struct type_unit_group
*
7936 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7938 struct dwarf2_per_objfile
*dwarf2_per_objfile
7939 = cu
->per_cu
->dwarf2_per_objfile
;
7940 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7941 struct dwarf2_per_cu_data
*per_cu
;
7942 struct type_unit_group
*tu_group
;
7944 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7945 struct type_unit_group
);
7946 per_cu
= &tu_group
->per_cu
;
7947 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7949 if (dwarf2_per_objfile
->using_index
)
7951 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7952 struct dwarf2_per_cu_quick_data
);
7956 unsigned int line_offset
= to_underlying (line_offset_struct
);
7957 struct partial_symtab
*pst
;
7960 /* Give the symtab a useful name for debug purposes. */
7961 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7962 name
= string_printf ("<type_units_%d>",
7963 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7965 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7967 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7971 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7972 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7977 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7978 STMT_LIST is a DW_AT_stmt_list attribute. */
7980 static struct type_unit_group
*
7981 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7983 struct dwarf2_per_objfile
*dwarf2_per_objfile
7984 = cu
->per_cu
->dwarf2_per_objfile
;
7985 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7986 struct type_unit_group
*tu_group
;
7988 unsigned int line_offset
;
7989 struct type_unit_group type_unit_group_for_lookup
;
7991 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7993 dwarf2_per_objfile
->type_unit_groups
=
7994 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7997 /* Do we need to create a new group, or can we use an existing one? */
8001 line_offset
= DW_UNSND (stmt_list
);
8002 ++tu_stats
->nr_symtab_sharers
;
8006 /* Ugh, no stmt_list. Rare, but we have to handle it.
8007 We can do various things here like create one group per TU or
8008 spread them over multiple groups to split up the expansion work.
8009 To avoid worst case scenarios (too many groups or too large groups)
8010 we, umm, group them in bunches. */
8011 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
8012 | (tu_stats
->nr_stmt_less_type_units
8013 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
8014 ++tu_stats
->nr_stmt_less_type_units
;
8017 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
8018 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
8019 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8020 &type_unit_group_for_lookup
, INSERT
);
8023 tu_group
= (struct type_unit_group
*) *slot
;
8024 gdb_assert (tu_group
!= NULL
);
8028 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8029 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8031 ++tu_stats
->nr_symtabs
;
8037 /* Partial symbol tables. */
8039 /* Create a psymtab named NAME and assign it to PER_CU.
8041 The caller must fill in the following details:
8042 dirname, textlow, texthigh. */
8044 static struct partial_symtab
*
8045 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8047 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8048 struct partial_symtab
*pst
;
8050 pst
= start_psymtab_common (objfile
, name
, 0);
8052 pst
->psymtabs_addrmap_supported
= 1;
8054 /* This is the glue that links PST into GDB's symbol API. */
8055 pst
->read_symtab_private
= per_cu
;
8056 pst
->read_symtab
= dwarf2_read_symtab
;
8057 per_cu
->v
.psymtab
= pst
;
8062 /* The DATA object passed to process_psymtab_comp_unit_reader has this
8065 struct process_psymtab_comp_unit_data
8067 /* True if we are reading a DW_TAG_partial_unit. */
8069 int want_partial_unit
;
8071 /* The "pretend" language that is used if the CU doesn't declare a
8074 enum language pretend_language
;
8077 /* die_reader_func for process_psymtab_comp_unit. */
8080 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8081 const gdb_byte
*info_ptr
,
8082 struct die_info
*comp_unit_die
,
8086 struct dwarf2_cu
*cu
= reader
->cu
;
8087 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8088 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8089 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8091 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8092 struct partial_symtab
*pst
;
8093 enum pc_bounds_kind cu_bounds_kind
;
8094 const char *filename
;
8095 struct process_psymtab_comp_unit_data
*info
8096 = (struct process_psymtab_comp_unit_data
*) data
;
8098 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !info
->want_partial_unit
)
8101 gdb_assert (! per_cu
->is_debug_types
);
8103 prepare_one_comp_unit (cu
, comp_unit_die
, info
->pretend_language
);
8105 /* Allocate a new partial symbol table structure. */
8106 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8107 if (filename
== NULL
)
8110 pst
= create_partial_symtab (per_cu
, filename
);
8112 /* This must be done before calling dwarf2_build_include_psymtabs. */
8113 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8115 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8117 dwarf2_find_base_address (comp_unit_die
, cu
);
8119 /* Possibly set the default values of LOWPC and HIGHPC from
8121 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8122 &best_highpc
, cu
, pst
);
8123 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8126 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8129 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8131 /* Store the contiguous range if it is not empty; it can be
8132 empty for CUs with no code. */
8133 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8137 /* Check if comp unit has_children.
8138 If so, read the rest of the partial symbols from this comp unit.
8139 If not, there's no more debug_info for this comp unit. */
8142 struct partial_die_info
*first_die
;
8143 CORE_ADDR lowpc
, highpc
;
8145 lowpc
= ((CORE_ADDR
) -1);
8146 highpc
= ((CORE_ADDR
) 0);
8148 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8150 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8151 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8153 /* If we didn't find a lowpc, set it to highpc to avoid
8154 complaints from `maint check'. */
8155 if (lowpc
== ((CORE_ADDR
) -1))
8158 /* If the compilation unit didn't have an explicit address range,
8159 then use the information extracted from its child dies. */
8160 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8163 best_highpc
= highpc
;
8166 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8167 best_lowpc
+ baseaddr
)
8169 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8170 best_highpc
+ baseaddr
)
8173 end_psymtab_common (objfile
, pst
);
8175 if (!cu
->per_cu
->imported_symtabs_empty ())
8178 int len
= cu
->per_cu
->imported_symtabs_size ();
8180 /* Fill in 'dependencies' here; we fill in 'users' in a
8182 pst
->number_of_dependencies
= len
;
8184 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8185 for (i
= 0; i
< len
; ++i
)
8187 pst
->dependencies
[i
]
8188 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8191 cu
->per_cu
->imported_symtabs_free ();
8194 /* Get the list of files included in the current compilation unit,
8195 and build a psymtab for each of them. */
8196 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8198 if (dwarf_read_debug
)
8199 fprintf_unfiltered (gdb_stdlog
,
8200 "Psymtab for %s unit @%s: %s - %s"
8201 ", %d global, %d static syms\n",
8202 per_cu
->is_debug_types
? "type" : "comp",
8203 sect_offset_str (per_cu
->sect_off
),
8204 paddress (gdbarch
, pst
->text_low (objfile
)),
8205 paddress (gdbarch
, pst
->text_high (objfile
)),
8206 pst
->n_global_syms
, pst
->n_static_syms
);
8209 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8210 Process compilation unit THIS_CU for a psymtab. */
8213 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8214 int want_partial_unit
,
8215 enum language pretend_language
)
8217 /* If this compilation unit was already read in, free the
8218 cached copy in order to read it in again. This is
8219 necessary because we skipped some symbols when we first
8220 read in the compilation unit (see load_partial_dies).
8221 This problem could be avoided, but the benefit is unclear. */
8222 if (this_cu
->cu
!= NULL
)
8223 free_one_cached_comp_unit (this_cu
);
8225 if (this_cu
->is_debug_types
)
8226 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8227 build_type_psymtabs_reader
, NULL
);
8230 process_psymtab_comp_unit_data info
;
8231 info
.want_partial_unit
= want_partial_unit
;
8232 info
.pretend_language
= pretend_language
;
8233 init_cutu_and_read_dies (this_cu
, NULL
, 0, 0, false,
8234 process_psymtab_comp_unit_reader
, &info
);
8237 /* Age out any secondary CUs. */
8238 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8241 /* Reader function for build_type_psymtabs. */
8244 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8245 const gdb_byte
*info_ptr
,
8246 struct die_info
*type_unit_die
,
8250 struct dwarf2_per_objfile
*dwarf2_per_objfile
8251 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8252 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8253 struct dwarf2_cu
*cu
= reader
->cu
;
8254 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8255 struct signatured_type
*sig_type
;
8256 struct type_unit_group
*tu_group
;
8257 struct attribute
*attr
;
8258 struct partial_die_info
*first_die
;
8259 CORE_ADDR lowpc
, highpc
;
8260 struct partial_symtab
*pst
;
8262 gdb_assert (data
== NULL
);
8263 gdb_assert (per_cu
->is_debug_types
);
8264 sig_type
= (struct signatured_type
*) per_cu
;
8269 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8270 tu_group
= get_type_unit_group (cu
, attr
);
8272 if (tu_group
->tus
== nullptr)
8273 tu_group
->tus
= new std::vector
<signatured_type
*>;
8274 tu_group
->tus
->push_back (sig_type
);
8276 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8277 pst
= create_partial_symtab (per_cu
, "");
8280 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8282 lowpc
= (CORE_ADDR
) -1;
8283 highpc
= (CORE_ADDR
) 0;
8284 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8286 end_psymtab_common (objfile
, pst
);
8289 /* Struct used to sort TUs by their abbreviation table offset. */
8291 struct tu_abbrev_offset
8293 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8294 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8297 signatured_type
*sig_type
;
8298 sect_offset abbrev_offset
;
8301 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8304 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8305 const struct tu_abbrev_offset
&b
)
8307 return a
.abbrev_offset
< b
.abbrev_offset
;
8310 /* Efficiently read all the type units.
8311 This does the bulk of the work for build_type_psymtabs.
8313 The efficiency is because we sort TUs by the abbrev table they use and
8314 only read each abbrev table once. In one program there are 200K TUs
8315 sharing 8K abbrev tables.
8317 The main purpose of this function is to support building the
8318 dwarf2_per_objfile->type_unit_groups table.
8319 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8320 can collapse the search space by grouping them by stmt_list.
8321 The savings can be significant, in the same program from above the 200K TUs
8322 share 8K stmt_list tables.
8324 FUNC is expected to call get_type_unit_group, which will create the
8325 struct type_unit_group if necessary and add it to
8326 dwarf2_per_objfile->type_unit_groups. */
8329 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8331 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8332 abbrev_table_up abbrev_table
;
8333 sect_offset abbrev_offset
;
8335 /* It's up to the caller to not call us multiple times. */
8336 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8338 if (dwarf2_per_objfile
->all_type_units
.empty ())
8341 /* TUs typically share abbrev tables, and there can be way more TUs than
8342 abbrev tables. Sort by abbrev table to reduce the number of times we
8343 read each abbrev table in.
8344 Alternatives are to punt or to maintain a cache of abbrev tables.
8345 This is simpler and efficient enough for now.
8347 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8348 symtab to use). Typically TUs with the same abbrev offset have the same
8349 stmt_list value too so in practice this should work well.
8351 The basic algorithm here is:
8353 sort TUs by abbrev table
8354 for each TU with same abbrev table:
8355 read abbrev table if first user
8356 read TU top level DIE
8357 [IWBN if DWO skeletons had DW_AT_stmt_list]
8360 if (dwarf_read_debug
)
8361 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8363 /* Sort in a separate table to maintain the order of all_type_units
8364 for .gdb_index: TU indices directly index all_type_units. */
8365 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8366 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8368 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8369 sorted_by_abbrev
.emplace_back
8370 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8371 sig_type
->per_cu
.section
,
8372 sig_type
->per_cu
.sect_off
));
8374 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8375 sort_tu_by_abbrev_offset
);
8377 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8379 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8381 /* Switch to the next abbrev table if necessary. */
8382 if (abbrev_table
== NULL
8383 || tu
.abbrev_offset
!= abbrev_offset
)
8385 abbrev_offset
= tu
.abbrev_offset
;
8387 abbrev_table_read_table (dwarf2_per_objfile
,
8388 &dwarf2_per_objfile
->abbrev
,
8390 ++tu_stats
->nr_uniq_abbrev_tables
;
8393 init_cutu_and_read_dies (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8394 0, 0, false, build_type_psymtabs_reader
, NULL
);
8398 /* Print collected type unit statistics. */
8401 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8403 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8405 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8406 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8407 dwarf2_per_objfile
->all_type_units
.size ());
8408 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8409 tu_stats
->nr_uniq_abbrev_tables
);
8410 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8411 tu_stats
->nr_symtabs
);
8412 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8413 tu_stats
->nr_symtab_sharers
);
8414 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8415 tu_stats
->nr_stmt_less_type_units
);
8416 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8417 tu_stats
->nr_all_type_units_reallocs
);
8420 /* Traversal function for build_type_psymtabs. */
8423 build_type_psymtab_dependencies (void **slot
, void *info
)
8425 struct dwarf2_per_objfile
*dwarf2_per_objfile
8426 = (struct dwarf2_per_objfile
*) info
;
8427 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8428 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8429 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8430 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8431 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8434 gdb_assert (len
> 0);
8435 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8437 pst
->number_of_dependencies
= len
;
8438 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8439 for (i
= 0; i
< len
; ++i
)
8441 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8442 gdb_assert (iter
->per_cu
.is_debug_types
);
8443 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8444 iter
->type_unit_group
= tu_group
;
8447 delete tu_group
->tus
;
8448 tu_group
->tus
= nullptr;
8453 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8454 Build partial symbol tables for the .debug_types comp-units. */
8457 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8459 if (! create_all_type_units (dwarf2_per_objfile
))
8462 build_type_psymtabs_1 (dwarf2_per_objfile
);
8465 /* Traversal function for process_skeletonless_type_unit.
8466 Read a TU in a DWO file and build partial symbols for it. */
8469 process_skeletonless_type_unit (void **slot
, void *info
)
8471 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8472 struct dwarf2_per_objfile
*dwarf2_per_objfile
8473 = (struct dwarf2_per_objfile
*) info
;
8474 struct signatured_type find_entry
, *entry
;
8476 /* If this TU doesn't exist in the global table, add it and read it in. */
8478 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8480 dwarf2_per_objfile
->signatured_types
8481 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8484 find_entry
.signature
= dwo_unit
->signature
;
8485 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8487 /* If we've already seen this type there's nothing to do. What's happening
8488 is we're doing our own version of comdat-folding here. */
8492 /* This does the job that create_all_type_units would have done for
8494 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8495 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8498 /* This does the job that build_type_psymtabs_1 would have done. */
8499 init_cutu_and_read_dies (&entry
->per_cu
, NULL
, 0, 0, false,
8500 build_type_psymtabs_reader
, NULL
);
8505 /* Traversal function for process_skeletonless_type_units. */
8508 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8510 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8512 if (dwo_file
->tus
!= NULL
)
8514 htab_traverse_noresize (dwo_file
->tus
,
8515 process_skeletonless_type_unit
, info
);
8521 /* Scan all TUs of DWO files, verifying we've processed them.
8522 This is needed in case a TU was emitted without its skeleton.
8523 Note: This can't be done until we know what all the DWO files are. */
8526 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8528 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8529 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8530 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8532 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8533 process_dwo_file_for_skeletonless_type_units
,
8534 dwarf2_per_objfile
);
8538 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8541 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8543 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8545 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8550 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8552 /* Set the 'user' field only if it is not already set. */
8553 if (pst
->dependencies
[j
]->user
== NULL
)
8554 pst
->dependencies
[j
]->user
= pst
;
8559 /* Build the partial symbol table by doing a quick pass through the
8560 .debug_info and .debug_abbrev sections. */
8563 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8565 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8567 if (dwarf_read_debug
)
8569 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8570 objfile_name (objfile
));
8573 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8575 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8577 /* Any cached compilation units will be linked by the per-objfile
8578 read_in_chain. Make sure to free them when we're done. */
8579 free_cached_comp_units
freer (dwarf2_per_objfile
);
8581 build_type_psymtabs (dwarf2_per_objfile
);
8583 create_all_comp_units (dwarf2_per_objfile
);
8585 /* Create a temporary address map on a temporary obstack. We later
8586 copy this to the final obstack. */
8587 auto_obstack temp_obstack
;
8589 scoped_restore save_psymtabs_addrmap
8590 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8591 addrmap_create_mutable (&temp_obstack
));
8593 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8594 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8596 /* This has to wait until we read the CUs, we need the list of DWOs. */
8597 process_skeletonless_type_units (dwarf2_per_objfile
);
8599 /* Now that all TUs have been processed we can fill in the dependencies. */
8600 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8602 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8603 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8606 if (dwarf_read_debug
)
8607 print_tu_stats (dwarf2_per_objfile
);
8609 set_partial_user (dwarf2_per_objfile
);
8611 objfile
->partial_symtabs
->psymtabs_addrmap
8612 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8613 objfile
->partial_symtabs
->obstack ());
8614 /* At this point we want to keep the address map. */
8615 save_psymtabs_addrmap
.release ();
8617 if (dwarf_read_debug
)
8618 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8619 objfile_name (objfile
));
8622 /* die_reader_func for load_partial_comp_unit. */
8625 load_partial_comp_unit_reader (const struct die_reader_specs
*reader
,
8626 const gdb_byte
*info_ptr
,
8627 struct die_info
*comp_unit_die
,
8631 struct dwarf2_cu
*cu
= reader
->cu
;
8633 prepare_one_comp_unit (cu
, comp_unit_die
, language_minimal
);
8635 /* Check if comp unit has_children.
8636 If so, read the rest of the partial symbols from this comp unit.
8637 If not, there's no more debug_info for this comp unit. */
8639 load_partial_dies (reader
, info_ptr
, 0);
8642 /* Load the partial DIEs for a secondary CU into memory.
8643 This is also used when rereading a primary CU with load_all_dies. */
8646 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8648 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, false,
8649 load_partial_comp_unit_reader
, NULL
);
8653 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8654 struct dwarf2_section_info
*section
,
8655 struct dwarf2_section_info
*abbrev_section
,
8656 unsigned int is_dwz
)
8658 const gdb_byte
*info_ptr
;
8659 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8661 if (dwarf_read_debug
)
8662 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8663 get_section_name (section
),
8664 get_section_file_name (section
));
8666 dwarf2_read_section (objfile
, section
);
8668 info_ptr
= section
->buffer
;
8670 while (info_ptr
< section
->buffer
+ section
->size
)
8672 struct dwarf2_per_cu_data
*this_cu
;
8674 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8676 comp_unit_head cu_header
;
8677 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8678 abbrev_section
, info_ptr
,
8679 rcuh_kind::COMPILE
);
8681 /* Save the compilation unit for later lookup. */
8682 if (cu_header
.unit_type
!= DW_UT_type
)
8684 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8685 struct dwarf2_per_cu_data
);
8686 memset (this_cu
, 0, sizeof (*this_cu
));
8690 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8691 struct signatured_type
);
8692 memset (sig_type
, 0, sizeof (*sig_type
));
8693 sig_type
->signature
= cu_header
.signature
;
8694 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8695 this_cu
= &sig_type
->per_cu
;
8697 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8698 this_cu
->sect_off
= sect_off
;
8699 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8700 this_cu
->is_dwz
= is_dwz
;
8701 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8702 this_cu
->section
= section
;
8704 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8706 info_ptr
= info_ptr
+ this_cu
->length
;
8710 /* Create a list of all compilation units in OBJFILE.
8711 This is only done for -readnow and building partial symtabs. */
8714 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8716 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8717 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8718 &dwarf2_per_objfile
->abbrev
, 0);
8720 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8722 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8726 /* Process all loaded DIEs for compilation unit CU, starting at
8727 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8728 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8729 DW_AT_ranges). See the comments of add_partial_subprogram on how
8730 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8733 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8734 CORE_ADDR
*highpc
, int set_addrmap
,
8735 struct dwarf2_cu
*cu
)
8737 struct partial_die_info
*pdi
;
8739 /* Now, march along the PDI's, descending into ones which have
8740 interesting children but skipping the children of the other ones,
8741 until we reach the end of the compilation unit. */
8749 /* Anonymous namespaces or modules have no name but have interesting
8750 children, so we need to look at them. Ditto for anonymous
8753 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8754 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8755 || pdi
->tag
== DW_TAG_imported_unit
8756 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8760 case DW_TAG_subprogram
:
8761 case DW_TAG_inlined_subroutine
:
8762 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8764 case DW_TAG_constant
:
8765 case DW_TAG_variable
:
8766 case DW_TAG_typedef
:
8767 case DW_TAG_union_type
:
8768 if (!pdi
->is_declaration
)
8770 add_partial_symbol (pdi
, cu
);
8773 case DW_TAG_class_type
:
8774 case DW_TAG_interface_type
:
8775 case DW_TAG_structure_type
:
8776 if (!pdi
->is_declaration
)
8778 add_partial_symbol (pdi
, cu
);
8780 if ((cu
->language
== language_rust
8781 || cu
->language
== language_cplus
) && pdi
->has_children
)
8782 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8785 case DW_TAG_enumeration_type
:
8786 if (!pdi
->is_declaration
)
8787 add_partial_enumeration (pdi
, cu
);
8789 case DW_TAG_base_type
:
8790 case DW_TAG_subrange_type
:
8791 /* File scope base type definitions are added to the partial
8793 add_partial_symbol (pdi
, cu
);
8795 case DW_TAG_namespace
:
8796 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8799 if (!pdi
->is_declaration
)
8800 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8802 case DW_TAG_imported_unit
:
8804 struct dwarf2_per_cu_data
*per_cu
;
8806 /* For now we don't handle imported units in type units. */
8807 if (cu
->per_cu
->is_debug_types
)
8809 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8810 " supported in type units [in module %s]"),
8811 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8814 per_cu
= dwarf2_find_containing_comp_unit
8815 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8816 cu
->per_cu
->dwarf2_per_objfile
);
8818 /* Go read the partial unit, if needed. */
8819 if (per_cu
->v
.psymtab
== NULL
)
8820 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8822 cu
->per_cu
->imported_symtabs_push (per_cu
);
8825 case DW_TAG_imported_declaration
:
8826 add_partial_symbol (pdi
, cu
);
8833 /* If the die has a sibling, skip to the sibling. */
8835 pdi
= pdi
->die_sibling
;
8839 /* Functions used to compute the fully scoped name of a partial DIE.
8841 Normally, this is simple. For C++, the parent DIE's fully scoped
8842 name is concatenated with "::" and the partial DIE's name.
8843 Enumerators are an exception; they use the scope of their parent
8844 enumeration type, i.e. the name of the enumeration type is not
8845 prepended to the enumerator.
8847 There are two complexities. One is DW_AT_specification; in this
8848 case "parent" means the parent of the target of the specification,
8849 instead of the direct parent of the DIE. The other is compilers
8850 which do not emit DW_TAG_namespace; in this case we try to guess
8851 the fully qualified name of structure types from their members'
8852 linkage names. This must be done using the DIE's children rather
8853 than the children of any DW_AT_specification target. We only need
8854 to do this for structures at the top level, i.e. if the target of
8855 any DW_AT_specification (if any; otherwise the DIE itself) does not
8858 /* Compute the scope prefix associated with PDI's parent, in
8859 compilation unit CU. The result will be allocated on CU's
8860 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8861 field. NULL is returned if no prefix is necessary. */
8863 partial_die_parent_scope (struct partial_die_info
*pdi
,
8864 struct dwarf2_cu
*cu
)
8866 const char *grandparent_scope
;
8867 struct partial_die_info
*parent
, *real_pdi
;
8869 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8870 then this means the parent of the specification DIE. */
8873 while (real_pdi
->has_specification
)
8875 auto res
= find_partial_die (real_pdi
->spec_offset
,
8876 real_pdi
->spec_is_dwz
, cu
);
8881 parent
= real_pdi
->die_parent
;
8885 if (parent
->scope_set
)
8886 return parent
->scope
;
8890 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8892 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8893 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8894 Work around this problem here. */
8895 if (cu
->language
== language_cplus
8896 && parent
->tag
== DW_TAG_namespace
8897 && strcmp (parent
->name
, "::") == 0
8898 && grandparent_scope
== NULL
)
8900 parent
->scope
= NULL
;
8901 parent
->scope_set
= 1;
8905 /* Nested subroutines in Fortran get a prefix. */
8906 if (pdi
->tag
== DW_TAG_enumerator
)
8907 /* Enumerators should not get the name of the enumeration as a prefix. */
8908 parent
->scope
= grandparent_scope
;
8909 else if (parent
->tag
== DW_TAG_namespace
8910 || parent
->tag
== DW_TAG_module
8911 || parent
->tag
== DW_TAG_structure_type
8912 || parent
->tag
== DW_TAG_class_type
8913 || parent
->tag
== DW_TAG_interface_type
8914 || parent
->tag
== DW_TAG_union_type
8915 || parent
->tag
== DW_TAG_enumeration_type
8916 || (cu
->language
== language_fortran
8917 && parent
->tag
== DW_TAG_subprogram
8918 && pdi
->tag
== DW_TAG_subprogram
))
8920 if (grandparent_scope
== NULL
)
8921 parent
->scope
= parent
->name
;
8923 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8925 parent
->name
, 0, cu
);
8929 /* FIXME drow/2004-04-01: What should we be doing with
8930 function-local names? For partial symbols, we should probably be
8932 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8933 dwarf_tag_name (parent
->tag
),
8934 sect_offset_str (pdi
->sect_off
));
8935 parent
->scope
= grandparent_scope
;
8938 parent
->scope_set
= 1;
8939 return parent
->scope
;
8942 /* Return the fully scoped name associated with PDI, from compilation unit
8943 CU. The result will be allocated with malloc. */
8945 static gdb::unique_xmalloc_ptr
<char>
8946 partial_die_full_name (struct partial_die_info
*pdi
,
8947 struct dwarf2_cu
*cu
)
8949 const char *parent_scope
;
8951 /* If this is a template instantiation, we can not work out the
8952 template arguments from partial DIEs. So, unfortunately, we have
8953 to go through the full DIEs. At least any work we do building
8954 types here will be reused if full symbols are loaded later. */
8955 if (pdi
->has_template_arguments
)
8959 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8961 struct die_info
*die
;
8962 struct attribute attr
;
8963 struct dwarf2_cu
*ref_cu
= cu
;
8965 /* DW_FORM_ref_addr is using section offset. */
8966 attr
.name
= (enum dwarf_attribute
) 0;
8967 attr
.form
= DW_FORM_ref_addr
;
8968 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8969 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8971 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8975 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8976 if (parent_scope
== NULL
)
8979 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8984 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8986 struct dwarf2_per_objfile
*dwarf2_per_objfile
8987 = cu
->per_cu
->dwarf2_per_objfile
;
8988 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8989 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8991 const char *actual_name
= NULL
;
8994 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
8996 gdb::unique_xmalloc_ptr
<char> built_actual_name
8997 = partial_die_full_name (pdi
, cu
);
8998 if (built_actual_name
!= NULL
)
8999 actual_name
= built_actual_name
.get ();
9001 if (actual_name
== NULL
)
9002 actual_name
= pdi
->name
;
9006 case DW_TAG_inlined_subroutine
:
9007 case DW_TAG_subprogram
:
9008 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
9010 if (pdi
->is_external
9011 || cu
->language
== language_ada
9012 || (cu
->language
== language_fortran
9013 && pdi
->die_parent
!= NULL
9014 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
9016 /* Normally, only "external" DIEs are part of the global scope.
9017 But in Ada and Fortran, we want to be able to access nested
9018 procedures globally. So all Ada and Fortran subprograms are
9019 stored in the global scope. */
9020 add_psymbol_to_list (actual_name
,
9021 built_actual_name
!= NULL
,
9022 VAR_DOMAIN
, LOC_BLOCK
,
9023 SECT_OFF_TEXT (objfile
),
9024 psymbol_placement::GLOBAL
,
9026 cu
->language
, objfile
);
9030 add_psymbol_to_list (actual_name
,
9031 built_actual_name
!= NULL
,
9032 VAR_DOMAIN
, LOC_BLOCK
,
9033 SECT_OFF_TEXT (objfile
),
9034 psymbol_placement::STATIC
,
9035 addr
, cu
->language
, objfile
);
9038 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9039 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9041 case DW_TAG_constant
:
9042 add_psymbol_to_list (actual_name
,
9043 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9044 -1, (pdi
->is_external
9045 ? psymbol_placement::GLOBAL
9046 : psymbol_placement::STATIC
),
9047 0, cu
->language
, objfile
);
9049 case DW_TAG_variable
:
9051 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9055 && !dwarf2_per_objfile
->has_section_at_zero
)
9057 /* A global or static variable may also have been stripped
9058 out by the linker if unused, in which case its address
9059 will be nullified; do not add such variables into partial
9060 symbol table then. */
9062 else if (pdi
->is_external
)
9065 Don't enter into the minimal symbol tables as there is
9066 a minimal symbol table entry from the ELF symbols already.
9067 Enter into partial symbol table if it has a location
9068 descriptor or a type.
9069 If the location descriptor is missing, new_symbol will create
9070 a LOC_UNRESOLVED symbol, the address of the variable will then
9071 be determined from the minimal symbol table whenever the variable
9073 The address for the partial symbol table entry is not
9074 used by GDB, but it comes in handy for debugging partial symbol
9077 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9078 add_psymbol_to_list (actual_name
,
9079 built_actual_name
!= NULL
,
9080 VAR_DOMAIN
, LOC_STATIC
,
9081 SECT_OFF_TEXT (objfile
),
9082 psymbol_placement::GLOBAL
,
9083 addr
, cu
->language
, objfile
);
9087 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9089 /* Static Variable. Skip symbols whose value we cannot know (those
9090 without location descriptors or constant values). */
9091 if (!has_loc
&& !pdi
->has_const_value
)
9094 add_psymbol_to_list (actual_name
,
9095 built_actual_name
!= NULL
,
9096 VAR_DOMAIN
, LOC_STATIC
,
9097 SECT_OFF_TEXT (objfile
),
9098 psymbol_placement::STATIC
,
9100 cu
->language
, objfile
);
9103 case DW_TAG_typedef
:
9104 case DW_TAG_base_type
:
9105 case DW_TAG_subrange_type
:
9106 add_psymbol_to_list (actual_name
,
9107 built_actual_name
!= NULL
,
9108 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9109 psymbol_placement::STATIC
,
9110 0, cu
->language
, objfile
);
9112 case DW_TAG_imported_declaration
:
9113 case DW_TAG_namespace
:
9114 add_psymbol_to_list (actual_name
,
9115 built_actual_name
!= NULL
,
9116 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9117 psymbol_placement::GLOBAL
,
9118 0, cu
->language
, objfile
);
9121 /* With Fortran 77 there might be a "BLOCK DATA" module
9122 available without any name. If so, we skip the module as it
9123 doesn't bring any value. */
9124 if (actual_name
!= nullptr)
9125 add_psymbol_to_list (actual_name
,
9126 built_actual_name
!= NULL
,
9127 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9128 psymbol_placement::GLOBAL
,
9129 0, cu
->language
, objfile
);
9131 case DW_TAG_class_type
:
9132 case DW_TAG_interface_type
:
9133 case DW_TAG_structure_type
:
9134 case DW_TAG_union_type
:
9135 case DW_TAG_enumeration_type
:
9136 /* Skip external references. The DWARF standard says in the section
9137 about "Structure, Union, and Class Type Entries": "An incomplete
9138 structure, union or class type is represented by a structure,
9139 union or class entry that does not have a byte size attribute
9140 and that has a DW_AT_declaration attribute." */
9141 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9144 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9145 static vs. global. */
9146 add_psymbol_to_list (actual_name
,
9147 built_actual_name
!= NULL
,
9148 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9149 cu
->language
== language_cplus
9150 ? psymbol_placement::GLOBAL
9151 : psymbol_placement::STATIC
,
9152 0, cu
->language
, objfile
);
9155 case DW_TAG_enumerator
:
9156 add_psymbol_to_list (actual_name
,
9157 built_actual_name
!= NULL
,
9158 VAR_DOMAIN
, LOC_CONST
, -1,
9159 cu
->language
== language_cplus
9160 ? psymbol_placement::GLOBAL
9161 : psymbol_placement::STATIC
,
9162 0, cu
->language
, objfile
);
9169 /* Read a partial die corresponding to a namespace; also, add a symbol
9170 corresponding to that namespace to the symbol table. NAMESPACE is
9171 the name of the enclosing namespace. */
9174 add_partial_namespace (struct partial_die_info
*pdi
,
9175 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9176 int set_addrmap
, struct dwarf2_cu
*cu
)
9178 /* Add a symbol for the namespace. */
9180 add_partial_symbol (pdi
, cu
);
9182 /* Now scan partial symbols in that namespace. */
9184 if (pdi
->has_children
)
9185 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9188 /* Read a partial die corresponding to a Fortran module. */
9191 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9192 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9194 /* Add a symbol for the namespace. */
9196 add_partial_symbol (pdi
, cu
);
9198 /* Now scan partial symbols in that module. */
9200 if (pdi
->has_children
)
9201 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9204 /* Read a partial die corresponding to a subprogram or an inlined
9205 subprogram and create a partial symbol for that subprogram.
9206 When the CU language allows it, this routine also defines a partial
9207 symbol for each nested subprogram that this subprogram contains.
9208 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9209 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9211 PDI may also be a lexical block, in which case we simply search
9212 recursively for subprograms defined inside that lexical block.
9213 Again, this is only performed when the CU language allows this
9214 type of definitions. */
9217 add_partial_subprogram (struct partial_die_info
*pdi
,
9218 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9219 int set_addrmap
, struct dwarf2_cu
*cu
)
9221 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9223 if (pdi
->has_pc_info
)
9225 if (pdi
->lowpc
< *lowpc
)
9226 *lowpc
= pdi
->lowpc
;
9227 if (pdi
->highpc
> *highpc
)
9228 *highpc
= pdi
->highpc
;
9231 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9232 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9234 CORE_ADDR this_highpc
;
9235 CORE_ADDR this_lowpc
;
9237 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
9239 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9240 pdi
->lowpc
+ baseaddr
)
9243 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9244 pdi
->highpc
+ baseaddr
)
9246 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9247 this_lowpc
, this_highpc
- 1,
9248 cu
->per_cu
->v
.psymtab
);
9252 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9254 if (!pdi
->is_declaration
)
9255 /* Ignore subprogram DIEs that do not have a name, they are
9256 illegal. Do not emit a complaint at this point, we will
9257 do so when we convert this psymtab into a symtab. */
9259 add_partial_symbol (pdi
, cu
);
9263 if (! pdi
->has_children
)
9266 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9268 pdi
= pdi
->die_child
;
9272 if (pdi
->tag
== DW_TAG_subprogram
9273 || pdi
->tag
== DW_TAG_inlined_subroutine
9274 || pdi
->tag
== DW_TAG_lexical_block
)
9275 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9276 pdi
= pdi
->die_sibling
;
9281 /* Read a partial die corresponding to an enumeration type. */
9284 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9285 struct dwarf2_cu
*cu
)
9287 struct partial_die_info
*pdi
;
9289 if (enum_pdi
->name
!= NULL
)
9290 add_partial_symbol (enum_pdi
, cu
);
9292 pdi
= enum_pdi
->die_child
;
9295 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9296 complaint (_("malformed enumerator DIE ignored"));
9298 add_partial_symbol (pdi
, cu
);
9299 pdi
= pdi
->die_sibling
;
9303 /* Return the initial uleb128 in the die at INFO_PTR. */
9306 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9308 unsigned int bytes_read
;
9310 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9313 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9314 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9316 Return the corresponding abbrev, or NULL if the number is zero (indicating
9317 an empty DIE). In either case *BYTES_READ will be set to the length of
9318 the initial number. */
9320 static struct abbrev_info
*
9321 peek_die_abbrev (const die_reader_specs
&reader
,
9322 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9324 dwarf2_cu
*cu
= reader
.cu
;
9325 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9326 unsigned int abbrev_number
9327 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9329 if (abbrev_number
== 0)
9332 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9335 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9336 " at offset %s [in module %s]"),
9337 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9338 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9344 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9345 Returns a pointer to the end of a series of DIEs, terminated by an empty
9346 DIE. Any children of the skipped DIEs will also be skipped. */
9348 static const gdb_byte
*
9349 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9353 unsigned int bytes_read
;
9354 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9357 return info_ptr
+ bytes_read
;
9359 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9363 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9364 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9365 abbrev corresponding to that skipped uleb128 should be passed in
9366 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9369 static const gdb_byte
*
9370 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9371 struct abbrev_info
*abbrev
)
9373 unsigned int bytes_read
;
9374 struct attribute attr
;
9375 bfd
*abfd
= reader
->abfd
;
9376 struct dwarf2_cu
*cu
= reader
->cu
;
9377 const gdb_byte
*buffer
= reader
->buffer
;
9378 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9379 unsigned int form
, i
;
9381 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9383 /* The only abbrev we care about is DW_AT_sibling. */
9384 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9387 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9389 if (attr
.form
== DW_FORM_ref_addr
)
9390 complaint (_("ignoring absolute DW_AT_sibling"));
9393 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9394 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9396 if (sibling_ptr
< info_ptr
)
9397 complaint (_("DW_AT_sibling points backwards"));
9398 else if (sibling_ptr
> reader
->buffer_end
)
9399 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9405 /* If it isn't DW_AT_sibling, skip this attribute. */
9406 form
= abbrev
->attrs
[i
].form
;
9410 case DW_FORM_ref_addr
:
9411 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9412 and later it is offset sized. */
9413 if (cu
->header
.version
== 2)
9414 info_ptr
+= cu
->header
.addr_size
;
9416 info_ptr
+= cu
->header
.offset_size
;
9418 case DW_FORM_GNU_ref_alt
:
9419 info_ptr
+= cu
->header
.offset_size
;
9422 info_ptr
+= cu
->header
.addr_size
;
9430 case DW_FORM_flag_present
:
9431 case DW_FORM_implicit_const
:
9448 case DW_FORM_ref_sig8
:
9451 case DW_FORM_data16
:
9454 case DW_FORM_string
:
9455 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9456 info_ptr
+= bytes_read
;
9458 case DW_FORM_sec_offset
:
9460 case DW_FORM_GNU_strp_alt
:
9461 info_ptr
+= cu
->header
.offset_size
;
9463 case DW_FORM_exprloc
:
9465 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9466 info_ptr
+= bytes_read
;
9468 case DW_FORM_block1
:
9469 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9471 case DW_FORM_block2
:
9472 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9474 case DW_FORM_block4
:
9475 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9481 case DW_FORM_ref_udata
:
9482 case DW_FORM_GNU_addr_index
:
9483 case DW_FORM_GNU_str_index
:
9484 case DW_FORM_rnglistx
:
9485 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9487 case DW_FORM_indirect
:
9488 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9489 info_ptr
+= bytes_read
;
9490 /* We need to continue parsing from here, so just go back to
9492 goto skip_attribute
;
9495 error (_("Dwarf Error: Cannot handle %s "
9496 "in DWARF reader [in module %s]"),
9497 dwarf_form_name (form
),
9498 bfd_get_filename (abfd
));
9502 if (abbrev
->has_children
)
9503 return skip_children (reader
, info_ptr
);
9508 /* Locate ORIG_PDI's sibling.
9509 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9511 static const gdb_byte
*
9512 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9513 struct partial_die_info
*orig_pdi
,
9514 const gdb_byte
*info_ptr
)
9516 /* Do we know the sibling already? */
9518 if (orig_pdi
->sibling
)
9519 return orig_pdi
->sibling
;
9521 /* Are there any children to deal with? */
9523 if (!orig_pdi
->has_children
)
9526 /* Skip the children the long way. */
9528 return skip_children (reader
, info_ptr
);
9531 /* Expand this partial symbol table into a full symbol table. SELF is
9535 dwarf2_read_symtab (struct partial_symtab
*self
,
9536 struct objfile
*objfile
)
9538 struct dwarf2_per_objfile
*dwarf2_per_objfile
9539 = get_dwarf2_per_objfile (objfile
);
9543 warning (_("bug: psymtab for %s is already read in."),
9550 printf_filtered (_("Reading in symbols for %s..."),
9552 gdb_flush (gdb_stdout
);
9555 /* If this psymtab is constructed from a debug-only objfile, the
9556 has_section_at_zero flag will not necessarily be correct. We
9557 can get the correct value for this flag by looking at the data
9558 associated with the (presumably stripped) associated objfile. */
9559 if (objfile
->separate_debug_objfile_backlink
)
9561 struct dwarf2_per_objfile
*dpo_backlink
9562 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9564 dwarf2_per_objfile
->has_section_at_zero
9565 = dpo_backlink
->has_section_at_zero
;
9568 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9570 psymtab_to_symtab_1 (self
);
9572 /* Finish up the debug error message. */
9574 printf_filtered (_("done.\n"));
9577 process_cu_includes (dwarf2_per_objfile
);
9580 /* Reading in full CUs. */
9582 /* Add PER_CU to the queue. */
9585 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9586 enum language pretend_language
)
9588 struct dwarf2_queue_item
*item
;
9591 item
= XNEW (struct dwarf2_queue_item
);
9592 item
->per_cu
= per_cu
;
9593 item
->pretend_language
= pretend_language
;
9596 if (dwarf2_queue
== NULL
)
9597 dwarf2_queue
= item
;
9599 dwarf2_queue_tail
->next
= item
;
9601 dwarf2_queue_tail
= item
;
9604 /* If PER_CU is not yet queued, add it to the queue.
9605 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9607 The result is non-zero if PER_CU was queued, otherwise the result is zero
9608 meaning either PER_CU is already queued or it is already loaded.
9610 N.B. There is an invariant here that if a CU is queued then it is loaded.
9611 The caller is required to load PER_CU if we return non-zero. */
9614 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9615 struct dwarf2_per_cu_data
*per_cu
,
9616 enum language pretend_language
)
9618 /* We may arrive here during partial symbol reading, if we need full
9619 DIEs to process an unusual case (e.g. template arguments). Do
9620 not queue PER_CU, just tell our caller to load its DIEs. */
9621 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9623 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9628 /* Mark the dependence relation so that we don't flush PER_CU
9630 if (dependent_cu
!= NULL
)
9631 dwarf2_add_dependence (dependent_cu
, per_cu
);
9633 /* If it's already on the queue, we have nothing to do. */
9637 /* If the compilation unit is already loaded, just mark it as
9639 if (per_cu
->cu
!= NULL
)
9641 per_cu
->cu
->last_used
= 0;
9645 /* Add it to the queue. */
9646 queue_comp_unit (per_cu
, pretend_language
);
9651 /* Process the queue. */
9654 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9656 struct dwarf2_queue_item
*item
, *next_item
;
9658 if (dwarf_read_debug
)
9660 fprintf_unfiltered (gdb_stdlog
,
9661 "Expanding one or more symtabs of objfile %s ...\n",
9662 objfile_name (dwarf2_per_objfile
->objfile
));
9665 /* The queue starts out with one item, but following a DIE reference
9666 may load a new CU, adding it to the end of the queue. */
9667 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9669 if ((dwarf2_per_objfile
->using_index
9670 ? !item
->per_cu
->v
.quick
->compunit_symtab
9671 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9672 /* Skip dummy CUs. */
9673 && item
->per_cu
->cu
!= NULL
)
9675 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9676 unsigned int debug_print_threshold
;
9679 if (per_cu
->is_debug_types
)
9681 struct signatured_type
*sig_type
=
9682 (struct signatured_type
*) per_cu
;
9684 sprintf (buf
, "TU %s at offset %s",
9685 hex_string (sig_type
->signature
),
9686 sect_offset_str (per_cu
->sect_off
));
9687 /* There can be 100s of TUs.
9688 Only print them in verbose mode. */
9689 debug_print_threshold
= 2;
9693 sprintf (buf
, "CU at offset %s",
9694 sect_offset_str (per_cu
->sect_off
));
9695 debug_print_threshold
= 1;
9698 if (dwarf_read_debug
>= debug_print_threshold
)
9699 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9701 if (per_cu
->is_debug_types
)
9702 process_full_type_unit (per_cu
, item
->pretend_language
);
9704 process_full_comp_unit (per_cu
, item
->pretend_language
);
9706 if (dwarf_read_debug
>= debug_print_threshold
)
9707 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9710 item
->per_cu
->queued
= 0;
9711 next_item
= item
->next
;
9715 dwarf2_queue_tail
= NULL
;
9717 if (dwarf_read_debug
)
9719 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9720 objfile_name (dwarf2_per_objfile
->objfile
));
9724 /* Read in full symbols for PST, and anything it depends on. */
9727 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9729 struct dwarf2_per_cu_data
*per_cu
;
9735 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9736 if (!pst
->dependencies
[i
]->readin
9737 && pst
->dependencies
[i
]->user
== NULL
)
9739 /* Inform about additional files that need to be read in. */
9742 /* FIXME: i18n: Need to make this a single string. */
9743 fputs_filtered (" ", gdb_stdout
);
9745 fputs_filtered ("and ", gdb_stdout
);
9747 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9748 wrap_here (""); /* Flush output. */
9749 gdb_flush (gdb_stdout
);
9751 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9754 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9758 /* It's an include file, no symbols to read for it.
9759 Everything is in the parent symtab. */
9764 dw2_do_instantiate_symtab (per_cu
, false);
9767 /* Trivial hash function for die_info: the hash value of a DIE
9768 is its offset in .debug_info for this objfile. */
9771 die_hash (const void *item
)
9773 const struct die_info
*die
= (const struct die_info
*) item
;
9775 return to_underlying (die
->sect_off
);
9778 /* Trivial comparison function for die_info structures: two DIEs
9779 are equal if they have the same offset. */
9782 die_eq (const void *item_lhs
, const void *item_rhs
)
9784 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9785 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9787 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9790 /* die_reader_func for load_full_comp_unit.
9791 This is identical to read_signatured_type_reader,
9792 but is kept separate for now. */
9795 load_full_comp_unit_reader (const struct die_reader_specs
*reader
,
9796 const gdb_byte
*info_ptr
,
9797 struct die_info
*comp_unit_die
,
9801 struct dwarf2_cu
*cu
= reader
->cu
;
9802 enum language
*language_ptr
= (enum language
*) data
;
9804 gdb_assert (cu
->die_hash
== NULL
);
9806 htab_create_alloc_ex (cu
->header
.length
/ 12,
9810 &cu
->comp_unit_obstack
,
9811 hashtab_obstack_allocate
,
9812 dummy_obstack_deallocate
);
9815 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
9816 &info_ptr
, comp_unit_die
);
9817 cu
->dies
= comp_unit_die
;
9818 /* comp_unit_die is not stored in die_hash, no need. */
9820 /* We try not to read any attributes in this function, because not
9821 all CUs needed for references have been loaded yet, and symbol
9822 table processing isn't initialized. But we have to set the CU language,
9823 or we won't be able to build types correctly.
9824 Similarly, if we do not read the producer, we can not apply
9825 producer-specific interpretation. */
9826 prepare_one_comp_unit (cu
, cu
->dies
, *language_ptr
);
9829 /* Load the DIEs associated with PER_CU into memory. */
9832 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9834 enum language pretend_language
)
9836 gdb_assert (! this_cu
->is_debug_types
);
9838 init_cutu_and_read_dies (this_cu
, NULL
, 1, 1, skip_partial
,
9839 load_full_comp_unit_reader
, &pretend_language
);
9842 /* Add a DIE to the delayed physname list. */
9845 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9846 const char *name
, struct die_info
*die
,
9847 struct dwarf2_cu
*cu
)
9849 struct delayed_method_info mi
;
9851 mi
.fnfield_index
= fnfield_index
;
9855 cu
->method_list
.push_back (mi
);
9858 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9859 "const" / "volatile". If so, decrements LEN by the length of the
9860 modifier and return true. Otherwise return false. */
9864 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9866 size_t mod_len
= sizeof (mod
) - 1;
9867 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9875 /* Compute the physnames of any methods on the CU's method list.
9877 The computation of method physnames is delayed in order to avoid the
9878 (bad) condition that one of the method's formal parameters is of an as yet
9882 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9884 /* Only C++ delays computing physnames. */
9885 if (cu
->method_list
.empty ())
9887 gdb_assert (cu
->language
== language_cplus
);
9889 for (const delayed_method_info
&mi
: cu
->method_list
)
9891 const char *physname
;
9892 struct fn_fieldlist
*fn_flp
9893 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9894 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9895 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9896 = physname
? physname
: "";
9898 /* Since there's no tag to indicate whether a method is a
9899 const/volatile overload, extract that information out of the
9901 if (physname
!= NULL
)
9903 size_t len
= strlen (physname
);
9907 if (physname
[len
] == ')') /* shortcut */
9909 else if (check_modifier (physname
, len
, " const"))
9910 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9911 else if (check_modifier (physname
, len
, " volatile"))
9912 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9919 /* The list is no longer needed. */
9920 cu
->method_list
.clear ();
9923 /* Go objects should be embedded in a DW_TAG_module DIE,
9924 and it's not clear if/how imported objects will appear.
9925 To keep Go support simple until that's worked out,
9926 go back through what we've read and create something usable.
9927 We could do this while processing each DIE, and feels kinda cleaner,
9928 but that way is more invasive.
9929 This is to, for example, allow the user to type "p var" or "b main"
9930 without having to specify the package name, and allow lookups
9931 of module.object to work in contexts that use the expression
9935 fixup_go_packaging (struct dwarf2_cu
*cu
)
9937 gdb::unique_xmalloc_ptr
<char> package_name
;
9938 struct pending
*list
;
9941 for (list
= *cu
->get_builder ()->get_global_symbols ();
9945 for (i
= 0; i
< list
->nsyms
; ++i
)
9947 struct symbol
*sym
= list
->symbol
[i
];
9949 if (sym
->language () == language_go
9950 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9952 gdb::unique_xmalloc_ptr
<char> this_package_name
9953 (go_symbol_package_name (sym
));
9955 if (this_package_name
== NULL
)
9957 if (package_name
== NULL
)
9958 package_name
= std::move (this_package_name
);
9961 struct objfile
*objfile
9962 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9963 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9964 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9965 (symbol_symtab (sym
) != NULL
9966 ? symtab_to_filename_for_display
9967 (symbol_symtab (sym
))
9968 : objfile_name (objfile
)),
9969 this_package_name
.get (), package_name
.get ());
9975 if (package_name
!= NULL
)
9977 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9978 const char *saved_package_name
9979 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9980 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9981 saved_package_name
);
9984 sym
= allocate_symbol (objfile
);
9985 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9986 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9987 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9988 e.g., "main" finds the "main" module and not C's main(). */
9989 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9990 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9991 SYMBOL_TYPE (sym
) = type
;
9993 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9997 /* Allocate a fully-qualified name consisting of the two parts on the
10000 static const char *
10001 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
10003 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
10006 /* A helper that allocates a struct discriminant_info to attach to a
10009 static struct discriminant_info
*
10010 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
10013 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10014 gdb_assert (discriminant_index
== -1
10015 || (discriminant_index
>= 0
10016 && discriminant_index
< TYPE_NFIELDS (type
)));
10017 gdb_assert (default_index
== -1
10018 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
10020 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
10022 struct discriminant_info
*disc
10023 = ((struct discriminant_info
*)
10025 offsetof (struct discriminant_info
, discriminants
)
10026 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
10027 disc
->default_index
= default_index
;
10028 disc
->discriminant_index
= discriminant_index
;
10030 struct dynamic_prop prop
;
10031 prop
.kind
= PROP_UNDEFINED
;
10032 prop
.data
.baton
= disc
;
10034 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
10039 /* Some versions of rustc emitted enums in an unusual way.
10041 Ordinary enums were emitted as unions. The first element of each
10042 structure in the union was named "RUST$ENUM$DISR". This element
10043 held the discriminant.
10045 These versions of Rust also implemented the "non-zero"
10046 optimization. When the enum had two values, and one is empty and
10047 the other holds a pointer that cannot be zero, the pointer is used
10048 as the discriminant, with a zero value meaning the empty variant.
10049 Here, the union's first member is of the form
10050 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10051 where the fieldnos are the indices of the fields that should be
10052 traversed in order to find the field (which may be several fields deep)
10053 and the variantname is the name of the variant of the case when the
10056 This function recognizes whether TYPE is of one of these forms,
10057 and, if so, smashes it to be a variant type. */
10060 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10062 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10064 /* We don't need to deal with empty enums. */
10065 if (TYPE_NFIELDS (type
) == 0)
10068 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10069 if (TYPE_NFIELDS (type
) == 1
10070 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10072 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10074 /* Decode the field name to find the offset of the
10076 ULONGEST bit_offset
= 0;
10077 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10078 while (name
[0] >= '0' && name
[0] <= '9')
10081 unsigned long index
= strtoul (name
, &tail
, 10);
10084 || index
>= TYPE_NFIELDS (field_type
)
10085 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10086 != FIELD_LOC_KIND_BITPOS
))
10088 complaint (_("Could not parse Rust enum encoding string \"%s\""
10090 TYPE_FIELD_NAME (type
, 0),
10091 objfile_name (objfile
));
10096 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10097 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10100 /* Make a union to hold the variants. */
10101 struct type
*union_type
= alloc_type (objfile
);
10102 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10103 TYPE_NFIELDS (union_type
) = 3;
10104 TYPE_FIELDS (union_type
)
10105 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10106 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10107 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10109 /* Put the discriminant must at index 0. */
10110 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10111 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10112 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10113 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10115 /* The order of fields doesn't really matter, so put the real
10116 field at index 1 and the data-less field at index 2. */
10117 struct discriminant_info
*disc
10118 = alloc_discriminant_info (union_type
, 0, 1);
10119 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10120 TYPE_FIELD_NAME (union_type
, 1)
10121 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10122 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10123 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10124 TYPE_FIELD_NAME (union_type
, 1));
10126 const char *dataless_name
10127 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10129 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10131 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10132 /* NAME points into the original discriminant name, which
10133 already has the correct lifetime. */
10134 TYPE_FIELD_NAME (union_type
, 2) = name
;
10135 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10136 disc
->discriminants
[2] = 0;
10138 /* Smash this type to be a structure type. We have to do this
10139 because the type has already been recorded. */
10140 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10141 TYPE_NFIELDS (type
) = 1;
10143 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10145 /* Install the variant part. */
10146 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10147 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10148 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10150 /* A union with a single anonymous field is probably an old-style
10151 univariant enum. */
10152 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10154 /* Smash this type to be a structure type. We have to do this
10155 because the type has already been recorded. */
10156 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10158 /* Make a union to hold the variants. */
10159 struct type
*union_type
= alloc_type (objfile
);
10160 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10161 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10162 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10163 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10164 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10166 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10167 const char *variant_name
10168 = rust_last_path_segment (TYPE_NAME (field_type
));
10169 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10170 TYPE_NAME (field_type
)
10171 = rust_fully_qualify (&objfile
->objfile_obstack
,
10172 TYPE_NAME (type
), variant_name
);
10174 /* Install the union in the outer struct type. */
10175 TYPE_NFIELDS (type
) = 1;
10177 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10178 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10179 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10180 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10182 alloc_discriminant_info (union_type
, -1, 0);
10186 struct type
*disr_type
= nullptr;
10187 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10189 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10191 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10193 /* All fields of a true enum will be structs. */
10196 else if (TYPE_NFIELDS (disr_type
) == 0)
10198 /* Could be data-less variant, so keep going. */
10199 disr_type
= nullptr;
10201 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10202 "RUST$ENUM$DISR") != 0)
10204 /* Not a Rust enum. */
10214 /* If we got here without a discriminant, then it's probably
10216 if (disr_type
== nullptr)
10219 /* Smash this type to be a structure type. We have to do this
10220 because the type has already been recorded. */
10221 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10223 /* Make a union to hold the variants. */
10224 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10225 struct type
*union_type
= alloc_type (objfile
);
10226 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10227 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10228 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10229 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10230 TYPE_FIELDS (union_type
)
10231 = (struct field
*) TYPE_ZALLOC (union_type
,
10232 (TYPE_NFIELDS (union_type
)
10233 * sizeof (struct field
)));
10235 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10236 TYPE_NFIELDS (type
) * sizeof (struct field
));
10238 /* Install the discriminant at index 0 in the union. */
10239 TYPE_FIELD (union_type
, 0) = *disr_field
;
10240 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10241 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10243 /* Install the union in the outer struct type. */
10244 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10245 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10246 TYPE_NFIELDS (type
) = 1;
10248 /* Set the size and offset of the union type. */
10249 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10251 /* We need a way to find the correct discriminant given a
10252 variant name. For convenience we build a map here. */
10253 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10254 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10255 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10257 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10260 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10261 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10265 int n_fields
= TYPE_NFIELDS (union_type
);
10266 struct discriminant_info
*disc
10267 = alloc_discriminant_info (union_type
, 0, -1);
10268 /* Skip the discriminant here. */
10269 for (int i
= 1; i
< n_fields
; ++i
)
10271 /* Find the final word in the name of this variant's type.
10272 That name can be used to look up the correct
10274 const char *variant_name
10275 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10278 auto iter
= discriminant_map
.find (variant_name
);
10279 if (iter
!= discriminant_map
.end ())
10280 disc
->discriminants
[i
] = iter
->second
;
10282 /* Remove the discriminant field, if it exists. */
10283 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10284 if (TYPE_NFIELDS (sub_type
) > 0)
10286 --TYPE_NFIELDS (sub_type
);
10287 ++TYPE_FIELDS (sub_type
);
10289 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10290 TYPE_NAME (sub_type
)
10291 = rust_fully_qualify (&objfile
->objfile_obstack
,
10292 TYPE_NAME (type
), variant_name
);
10297 /* Rewrite some Rust unions to be structures with variants parts. */
10300 rust_union_quirks (struct dwarf2_cu
*cu
)
10302 gdb_assert (cu
->language
== language_rust
);
10303 for (type
*type_
: cu
->rust_unions
)
10304 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10305 /* We don't need this any more. */
10306 cu
->rust_unions
.clear ();
10309 /* Return the symtab for PER_CU. This works properly regardless of
10310 whether we're using the index or psymtabs. */
10312 static struct compunit_symtab
*
10313 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10315 return (per_cu
->dwarf2_per_objfile
->using_index
10316 ? per_cu
->v
.quick
->compunit_symtab
10317 : per_cu
->v
.psymtab
->compunit_symtab
);
10320 /* A helper function for computing the list of all symbol tables
10321 included by PER_CU. */
10324 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10325 htab_t all_children
, htab_t all_type_symtabs
,
10326 struct dwarf2_per_cu_data
*per_cu
,
10327 struct compunit_symtab
*immediate_parent
)
10330 struct compunit_symtab
*cust
;
10332 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10335 /* This inclusion and its children have been processed. */
10340 /* Only add a CU if it has a symbol table. */
10341 cust
= get_compunit_symtab (per_cu
);
10344 /* If this is a type unit only add its symbol table if we haven't
10345 seen it yet (type unit per_cu's can share symtabs). */
10346 if (per_cu
->is_debug_types
)
10348 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10352 result
->push_back (cust
);
10353 if (cust
->user
== NULL
)
10354 cust
->user
= immediate_parent
;
10359 result
->push_back (cust
);
10360 if (cust
->user
== NULL
)
10361 cust
->user
= immediate_parent
;
10365 if (!per_cu
->imported_symtabs_empty ())
10366 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10368 recursively_compute_inclusions (result
, all_children
,
10369 all_type_symtabs
, ptr
, cust
);
10373 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10377 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10379 gdb_assert (! per_cu
->is_debug_types
);
10381 if (!per_cu
->imported_symtabs_empty ())
10384 std::vector
<compunit_symtab
*> result_symtabs
;
10385 htab_t all_children
, all_type_symtabs
;
10386 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10388 /* If we don't have a symtab, we can just skip this case. */
10392 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10393 NULL
, xcalloc
, xfree
);
10394 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10395 NULL
, xcalloc
, xfree
);
10397 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10399 recursively_compute_inclusions (&result_symtabs
, all_children
,
10400 all_type_symtabs
, ptr
, cust
);
10403 /* Now we have a transitive closure of all the included symtabs. */
10404 len
= result_symtabs
.size ();
10406 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10407 struct compunit_symtab
*, len
+ 1);
10408 memcpy (cust
->includes
, result_symtabs
.data (),
10409 len
* sizeof (compunit_symtab
*));
10410 cust
->includes
[len
] = NULL
;
10412 htab_delete (all_children
);
10413 htab_delete (all_type_symtabs
);
10417 /* Compute the 'includes' field for the symtabs of all the CUs we just
10421 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10423 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10425 if (! iter
->is_debug_types
)
10426 compute_compunit_symtab_includes (iter
);
10429 dwarf2_per_objfile
->just_read_cus
.clear ();
10432 /* Generate full symbol information for PER_CU, whose DIEs have
10433 already been loaded into memory. */
10436 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10437 enum language pretend_language
)
10439 struct dwarf2_cu
*cu
= per_cu
->cu
;
10440 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10441 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10442 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10443 CORE_ADDR lowpc
, highpc
;
10444 struct compunit_symtab
*cust
;
10445 CORE_ADDR baseaddr
;
10446 struct block
*static_block
;
10449 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
10451 /* Clear the list here in case something was left over. */
10452 cu
->method_list
.clear ();
10454 cu
->language
= pretend_language
;
10455 cu
->language_defn
= language_def (cu
->language
);
10457 /* Do line number decoding in read_file_scope () */
10458 process_die (cu
->dies
, cu
);
10460 /* For now fudge the Go package. */
10461 if (cu
->language
== language_go
)
10462 fixup_go_packaging (cu
);
10464 /* Now that we have processed all the DIEs in the CU, all the types
10465 should be complete, and it should now be safe to compute all of the
10467 compute_delayed_physnames (cu
);
10469 if (cu
->language
== language_rust
)
10470 rust_union_quirks (cu
);
10472 /* Some compilers don't define a DW_AT_high_pc attribute for the
10473 compilation unit. If the DW_AT_high_pc is missing, synthesize
10474 it, by scanning the DIE's below the compilation unit. */
10475 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10477 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10478 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10480 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10481 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10482 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10483 addrmap to help ensure it has an accurate map of pc values belonging to
10485 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10487 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10488 SECT_OFF_TEXT (objfile
),
10493 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10495 /* Set symtab language to language from DW_AT_language. If the
10496 compilation is from a C file generated by language preprocessors, do
10497 not set the language if it was already deduced by start_subfile. */
10498 if (!(cu
->language
== language_c
10499 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10500 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10502 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10503 produce DW_AT_location with location lists but it can be possibly
10504 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10505 there were bugs in prologue debug info, fixed later in GCC-4.5
10506 by "unwind info for epilogues" patch (which is not directly related).
10508 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10509 needed, it would be wrong due to missing DW_AT_producer there.
10511 Still one can confuse GDB by using non-standard GCC compilation
10512 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10514 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10515 cust
->locations_valid
= 1;
10517 if (gcc_4_minor
>= 5)
10518 cust
->epilogue_unwind_valid
= 1;
10520 cust
->call_site_htab
= cu
->call_site_htab
;
10523 if (dwarf2_per_objfile
->using_index
)
10524 per_cu
->v
.quick
->compunit_symtab
= cust
;
10527 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10528 pst
->compunit_symtab
= cust
;
10532 /* Push it for inclusion processing later. */
10533 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10535 /* Not needed any more. */
10536 cu
->reset_builder ();
10539 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10540 already been loaded into memory. */
10543 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10544 enum language pretend_language
)
10546 struct dwarf2_cu
*cu
= per_cu
->cu
;
10547 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10548 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10549 struct compunit_symtab
*cust
;
10550 struct signatured_type
*sig_type
;
10552 gdb_assert (per_cu
->is_debug_types
);
10553 sig_type
= (struct signatured_type
*) per_cu
;
10555 /* Clear the list here in case something was left over. */
10556 cu
->method_list
.clear ();
10558 cu
->language
= pretend_language
;
10559 cu
->language_defn
= language_def (cu
->language
);
10561 /* The symbol tables are set up in read_type_unit_scope. */
10562 process_die (cu
->dies
, cu
);
10564 /* For now fudge the Go package. */
10565 if (cu
->language
== language_go
)
10566 fixup_go_packaging (cu
);
10568 /* Now that we have processed all the DIEs in the CU, all the types
10569 should be complete, and it should now be safe to compute all of the
10571 compute_delayed_physnames (cu
);
10573 if (cu
->language
== language_rust
)
10574 rust_union_quirks (cu
);
10576 /* TUs share symbol tables.
10577 If this is the first TU to use this symtab, complete the construction
10578 of it with end_expandable_symtab. Otherwise, complete the addition of
10579 this TU's symbols to the existing symtab. */
10580 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10582 buildsym_compunit
*builder
= cu
->get_builder ();
10583 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10584 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10588 /* Set symtab language to language from DW_AT_language. If the
10589 compilation is from a C file generated by language preprocessors,
10590 do not set the language if it was already deduced by
10592 if (!(cu
->language
== language_c
10593 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10594 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10599 cu
->get_builder ()->augment_type_symtab ();
10600 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10603 if (dwarf2_per_objfile
->using_index
)
10604 per_cu
->v
.quick
->compunit_symtab
= cust
;
10607 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10608 pst
->compunit_symtab
= cust
;
10612 /* Not needed any more. */
10613 cu
->reset_builder ();
10616 /* Process an imported unit DIE. */
10619 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10621 struct attribute
*attr
;
10623 /* For now we don't handle imported units in type units. */
10624 if (cu
->per_cu
->is_debug_types
)
10626 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10627 " supported in type units [in module %s]"),
10628 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10631 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10634 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10635 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10636 dwarf2_per_cu_data
*per_cu
10637 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10638 cu
->per_cu
->dwarf2_per_objfile
);
10640 /* If necessary, add it to the queue and load its DIEs. */
10641 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10642 load_full_comp_unit (per_cu
, false, cu
->language
);
10644 cu
->per_cu
->imported_symtabs_push (per_cu
);
10648 /* RAII object that represents a process_die scope: i.e.,
10649 starts/finishes processing a DIE. */
10650 class process_die_scope
10653 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10654 : m_die (die
), m_cu (cu
)
10656 /* We should only be processing DIEs not already in process. */
10657 gdb_assert (!m_die
->in_process
);
10658 m_die
->in_process
= true;
10661 ~process_die_scope ()
10663 m_die
->in_process
= false;
10665 /* If we're done processing the DIE for the CU that owns the line
10666 header, we don't need the line header anymore. */
10667 if (m_cu
->line_header_die_owner
== m_die
)
10669 delete m_cu
->line_header
;
10670 m_cu
->line_header
= NULL
;
10671 m_cu
->line_header_die_owner
= NULL
;
10680 /* Process a die and its children. */
10683 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10685 process_die_scope
scope (die
, cu
);
10689 case DW_TAG_padding
:
10691 case DW_TAG_compile_unit
:
10692 case DW_TAG_partial_unit
:
10693 read_file_scope (die
, cu
);
10695 case DW_TAG_type_unit
:
10696 read_type_unit_scope (die
, cu
);
10698 case DW_TAG_subprogram
:
10699 /* Nested subprograms in Fortran get a prefix. */
10700 if (cu
->language
== language_fortran
10701 && die
->parent
!= NULL
10702 && die
->parent
->tag
== DW_TAG_subprogram
)
10703 cu
->processing_has_namespace_info
= true;
10704 /* Fall through. */
10705 case DW_TAG_inlined_subroutine
:
10706 read_func_scope (die
, cu
);
10708 case DW_TAG_lexical_block
:
10709 case DW_TAG_try_block
:
10710 case DW_TAG_catch_block
:
10711 read_lexical_block_scope (die
, cu
);
10713 case DW_TAG_call_site
:
10714 case DW_TAG_GNU_call_site
:
10715 read_call_site_scope (die
, cu
);
10717 case DW_TAG_class_type
:
10718 case DW_TAG_interface_type
:
10719 case DW_TAG_structure_type
:
10720 case DW_TAG_union_type
:
10721 process_structure_scope (die
, cu
);
10723 case DW_TAG_enumeration_type
:
10724 process_enumeration_scope (die
, cu
);
10727 /* These dies have a type, but processing them does not create
10728 a symbol or recurse to process the children. Therefore we can
10729 read them on-demand through read_type_die. */
10730 case DW_TAG_subroutine_type
:
10731 case DW_TAG_set_type
:
10732 case DW_TAG_array_type
:
10733 case DW_TAG_pointer_type
:
10734 case DW_TAG_ptr_to_member_type
:
10735 case DW_TAG_reference_type
:
10736 case DW_TAG_rvalue_reference_type
:
10737 case DW_TAG_string_type
:
10740 case DW_TAG_base_type
:
10741 case DW_TAG_subrange_type
:
10742 case DW_TAG_typedef
:
10743 /* Add a typedef symbol for the type definition, if it has a
10745 new_symbol (die
, read_type_die (die
, cu
), cu
);
10747 case DW_TAG_common_block
:
10748 read_common_block (die
, cu
);
10750 case DW_TAG_common_inclusion
:
10752 case DW_TAG_namespace
:
10753 cu
->processing_has_namespace_info
= true;
10754 read_namespace (die
, cu
);
10756 case DW_TAG_module
:
10757 cu
->processing_has_namespace_info
= true;
10758 read_module (die
, cu
);
10760 case DW_TAG_imported_declaration
:
10761 cu
->processing_has_namespace_info
= true;
10762 if (read_namespace_alias (die
, cu
))
10764 /* The declaration is not a global namespace alias. */
10765 /* Fall through. */
10766 case DW_TAG_imported_module
:
10767 cu
->processing_has_namespace_info
= true;
10768 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10769 || cu
->language
!= language_fortran
))
10770 complaint (_("Tag '%s' has unexpected children"),
10771 dwarf_tag_name (die
->tag
));
10772 read_import_statement (die
, cu
);
10775 case DW_TAG_imported_unit
:
10776 process_imported_unit_die (die
, cu
);
10779 case DW_TAG_variable
:
10780 read_variable (die
, cu
);
10784 new_symbol (die
, NULL
, cu
);
10789 /* DWARF name computation. */
10791 /* A helper function for dwarf2_compute_name which determines whether DIE
10792 needs to have the name of the scope prepended to the name listed in the
10796 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10798 struct attribute
*attr
;
10802 case DW_TAG_namespace
:
10803 case DW_TAG_typedef
:
10804 case DW_TAG_class_type
:
10805 case DW_TAG_interface_type
:
10806 case DW_TAG_structure_type
:
10807 case DW_TAG_union_type
:
10808 case DW_TAG_enumeration_type
:
10809 case DW_TAG_enumerator
:
10810 case DW_TAG_subprogram
:
10811 case DW_TAG_inlined_subroutine
:
10812 case DW_TAG_member
:
10813 case DW_TAG_imported_declaration
:
10816 case DW_TAG_variable
:
10817 case DW_TAG_constant
:
10818 /* We only need to prefix "globally" visible variables. These include
10819 any variable marked with DW_AT_external or any variable that
10820 lives in a namespace. [Variables in anonymous namespaces
10821 require prefixing, but they are not DW_AT_external.] */
10823 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10825 struct dwarf2_cu
*spec_cu
= cu
;
10827 return die_needs_namespace (die_specification (die
, &spec_cu
),
10831 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10832 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10833 && die
->parent
->tag
!= DW_TAG_module
)
10835 /* A variable in a lexical block of some kind does not need a
10836 namespace, even though in C++ such variables may be external
10837 and have a mangled name. */
10838 if (die
->parent
->tag
== DW_TAG_lexical_block
10839 || die
->parent
->tag
== DW_TAG_try_block
10840 || die
->parent
->tag
== DW_TAG_catch_block
10841 || die
->parent
->tag
== DW_TAG_subprogram
)
10850 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10851 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10852 defined for the given DIE. */
10854 static struct attribute
*
10855 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10857 struct attribute
*attr
;
10859 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10861 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10866 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10867 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10868 defined for the given DIE. */
10870 static const char *
10871 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10873 const char *linkage_name
;
10875 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10876 if (linkage_name
== NULL
)
10877 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10879 return linkage_name
;
10882 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10883 compute the physname for the object, which include a method's:
10884 - formal parameters (C++),
10885 - receiver type (Go),
10887 The term "physname" is a bit confusing.
10888 For C++, for example, it is the demangled name.
10889 For Go, for example, it's the mangled name.
10891 For Ada, return the DIE's linkage name rather than the fully qualified
10892 name. PHYSNAME is ignored..
10894 The result is allocated on the objfile_obstack and canonicalized. */
10896 static const char *
10897 dwarf2_compute_name (const char *name
,
10898 struct die_info
*die
, struct dwarf2_cu
*cu
,
10901 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10904 name
= dwarf2_name (die
, cu
);
10906 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10907 but otherwise compute it by typename_concat inside GDB.
10908 FIXME: Actually this is not really true, or at least not always true.
10909 It's all very confusing. compute_and_set_names doesn't try to demangle
10910 Fortran names because there is no mangling standard. So new_symbol
10911 will set the demangled name to the result of dwarf2_full_name, and it is
10912 the demangled name that GDB uses if it exists. */
10913 if (cu
->language
== language_ada
10914 || (cu
->language
== language_fortran
&& physname
))
10916 /* For Ada unit, we prefer the linkage name over the name, as
10917 the former contains the exported name, which the user expects
10918 to be able to reference. Ideally, we want the user to be able
10919 to reference this entity using either natural or linkage name,
10920 but we haven't started looking at this enhancement yet. */
10921 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10923 if (linkage_name
!= NULL
)
10924 return linkage_name
;
10927 /* These are the only languages we know how to qualify names in. */
10929 && (cu
->language
== language_cplus
10930 || cu
->language
== language_fortran
|| cu
->language
== language_d
10931 || cu
->language
== language_rust
))
10933 if (die_needs_namespace (die
, cu
))
10935 const char *prefix
;
10936 const char *canonical_name
= NULL
;
10940 prefix
= determine_prefix (die
, cu
);
10941 if (*prefix
!= '\0')
10943 gdb::unique_xmalloc_ptr
<char> prefixed_name
10944 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10946 buf
.puts (prefixed_name
.get ());
10951 /* Template parameters may be specified in the DIE's DW_AT_name, or
10952 as children with DW_TAG_template_type_param or
10953 DW_TAG_value_type_param. If the latter, add them to the name
10954 here. If the name already has template parameters, then
10955 skip this step; some versions of GCC emit both, and
10956 it is more efficient to use the pre-computed name.
10958 Something to keep in mind about this process: it is very
10959 unlikely, or in some cases downright impossible, to produce
10960 something that will match the mangled name of a function.
10961 If the definition of the function has the same debug info,
10962 we should be able to match up with it anyway. But fallbacks
10963 using the minimal symbol, for instance to find a method
10964 implemented in a stripped copy of libstdc++, will not work.
10965 If we do not have debug info for the definition, we will have to
10966 match them up some other way.
10968 When we do name matching there is a related problem with function
10969 templates; two instantiated function templates are allowed to
10970 differ only by their return types, which we do not add here. */
10972 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10974 struct attribute
*attr
;
10975 struct die_info
*child
;
10978 die
->building_fullname
= 1;
10980 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10984 const gdb_byte
*bytes
;
10985 struct dwarf2_locexpr_baton
*baton
;
10988 if (child
->tag
!= DW_TAG_template_type_param
10989 && child
->tag
!= DW_TAG_template_value_param
)
11000 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
11003 complaint (_("template parameter missing DW_AT_type"));
11004 buf
.puts ("UNKNOWN_TYPE");
11007 type
= die_type (child
, cu
);
11009 if (child
->tag
== DW_TAG_template_type_param
)
11011 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
11012 &type_print_raw_options
);
11016 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
11019 complaint (_("template parameter missing "
11020 "DW_AT_const_value"));
11021 buf
.puts ("UNKNOWN_VALUE");
11025 dwarf2_const_value_attr (attr
, type
, name
,
11026 &cu
->comp_unit_obstack
, cu
,
11027 &value
, &bytes
, &baton
);
11029 if (TYPE_NOSIGN (type
))
11030 /* GDB prints characters as NUMBER 'CHAR'. If that's
11031 changed, this can use value_print instead. */
11032 c_printchar (value
, type
, &buf
);
11035 struct value_print_options opts
;
11038 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
11042 else if (bytes
!= NULL
)
11044 v
= allocate_value (type
);
11045 memcpy (value_contents_writeable (v
), bytes
,
11046 TYPE_LENGTH (type
));
11049 v
= value_from_longest (type
, value
);
11051 /* Specify decimal so that we do not depend on
11053 get_formatted_print_options (&opts
, 'd');
11055 value_print (v
, &buf
, &opts
);
11060 die
->building_fullname
= 0;
11064 /* Close the argument list, with a space if necessary
11065 (nested templates). */
11066 if (!buf
.empty () && buf
.string ().back () == '>')
11073 /* For C++ methods, append formal parameter type
11074 information, if PHYSNAME. */
11076 if (physname
&& die
->tag
== DW_TAG_subprogram
11077 && cu
->language
== language_cplus
)
11079 struct type
*type
= read_type_die (die
, cu
);
11081 c_type_print_args (type
, &buf
, 1, cu
->language
,
11082 &type_print_raw_options
);
11084 if (cu
->language
== language_cplus
)
11086 /* Assume that an artificial first parameter is
11087 "this", but do not crash if it is not. RealView
11088 marks unnamed (and thus unused) parameters as
11089 artificial; there is no way to differentiate
11091 if (TYPE_NFIELDS (type
) > 0
11092 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11093 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11094 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11096 buf
.puts (" const");
11100 const std::string
&intermediate_name
= buf
.string ();
11102 if (cu
->language
== language_cplus
)
11104 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11105 &objfile
->per_bfd
->storage_obstack
);
11107 /* If we only computed INTERMEDIATE_NAME, or if
11108 INTERMEDIATE_NAME is already canonical, then we need to
11109 copy it to the appropriate obstack. */
11110 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11111 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11112 intermediate_name
);
11114 name
= canonical_name
;
11121 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11122 If scope qualifiers are appropriate they will be added. The result
11123 will be allocated on the storage_obstack, or NULL if the DIE does
11124 not have a name. NAME may either be from a previous call to
11125 dwarf2_name or NULL.
11127 The output string will be canonicalized (if C++). */
11129 static const char *
11130 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11132 return dwarf2_compute_name (name
, die
, cu
, 0);
11135 /* Construct a physname for the given DIE in CU. NAME may either be
11136 from a previous call to dwarf2_name or NULL. The result will be
11137 allocated on the objfile_objstack or NULL if the DIE does not have a
11140 The output string will be canonicalized (if C++). */
11142 static const char *
11143 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11145 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11146 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11149 /* In this case dwarf2_compute_name is just a shortcut not building anything
11151 if (!die_needs_namespace (die
, cu
))
11152 return dwarf2_compute_name (name
, die
, cu
, 1);
11154 mangled
= dw2_linkage_name (die
, cu
);
11156 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11157 See https://github.com/rust-lang/rust/issues/32925. */
11158 if (cu
->language
== language_rust
&& mangled
!= NULL
11159 && strchr (mangled
, '{') != NULL
)
11162 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11164 gdb::unique_xmalloc_ptr
<char> demangled
;
11165 if (mangled
!= NULL
)
11168 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11170 /* Do nothing (do not demangle the symbol name). */
11172 else if (cu
->language
== language_go
)
11174 /* This is a lie, but we already lie to the caller new_symbol.
11175 new_symbol assumes we return the mangled name.
11176 This just undoes that lie until things are cleaned up. */
11180 /* Use DMGL_RET_DROP for C++ template functions to suppress
11181 their return type. It is easier for GDB users to search
11182 for such functions as `name(params)' than `long name(params)'.
11183 In such case the minimal symbol names do not match the full
11184 symbol names but for template functions there is never a need
11185 to look up their definition from their declaration so
11186 the only disadvantage remains the minimal symbol variant
11187 `long name(params)' does not have the proper inferior type. */
11188 demangled
.reset (gdb_demangle (mangled
,
11189 (DMGL_PARAMS
| DMGL_ANSI
11190 | DMGL_RET_DROP
)));
11193 canon
= demangled
.get ();
11201 if (canon
== NULL
|| check_physname
)
11203 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11205 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11207 /* It may not mean a bug in GDB. The compiler could also
11208 compute DW_AT_linkage_name incorrectly. But in such case
11209 GDB would need to be bug-to-bug compatible. */
11211 complaint (_("Computed physname <%s> does not match demangled <%s> "
11212 "(from linkage <%s>) - DIE at %s [in module %s]"),
11213 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11214 objfile_name (objfile
));
11216 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11217 is available here - over computed PHYSNAME. It is safer
11218 against both buggy GDB and buggy compilers. */
11232 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11237 /* Inspect DIE in CU for a namespace alias. If one exists, record
11238 a new symbol for it.
11240 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11243 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11245 struct attribute
*attr
;
11247 /* If the die does not have a name, this is not a namespace
11249 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11253 struct die_info
*d
= die
;
11254 struct dwarf2_cu
*imported_cu
= cu
;
11256 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11257 keep inspecting DIEs until we hit the underlying import. */
11258 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11259 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11261 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11265 d
= follow_die_ref (d
, attr
, &imported_cu
);
11266 if (d
->tag
!= DW_TAG_imported_declaration
)
11270 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11272 complaint (_("DIE at %s has too many recursively imported "
11273 "declarations"), sect_offset_str (d
->sect_off
));
11280 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11282 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11283 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11285 /* This declaration is a global namespace alias. Add
11286 a symbol for it whose type is the aliased namespace. */
11287 new_symbol (die
, type
, cu
);
11296 /* Return the using directives repository (global or local?) to use in the
11297 current context for CU.
11299 For Ada, imported declarations can materialize renamings, which *may* be
11300 global. However it is impossible (for now?) in DWARF to distinguish
11301 "external" imported declarations and "static" ones. As all imported
11302 declarations seem to be static in all other languages, make them all CU-wide
11303 global only in Ada. */
11305 static struct using_direct
**
11306 using_directives (struct dwarf2_cu
*cu
)
11308 if (cu
->language
== language_ada
11309 && cu
->get_builder ()->outermost_context_p ())
11310 return cu
->get_builder ()->get_global_using_directives ();
11312 return cu
->get_builder ()->get_local_using_directives ();
11315 /* Read the import statement specified by the given die and record it. */
11318 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11320 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11321 struct attribute
*import_attr
;
11322 struct die_info
*imported_die
, *child_die
;
11323 struct dwarf2_cu
*imported_cu
;
11324 const char *imported_name
;
11325 const char *imported_name_prefix
;
11326 const char *canonical_name
;
11327 const char *import_alias
;
11328 const char *imported_declaration
= NULL
;
11329 const char *import_prefix
;
11330 std::vector
<const char *> excludes
;
11332 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11333 if (import_attr
== NULL
)
11335 complaint (_("Tag '%s' has no DW_AT_import"),
11336 dwarf_tag_name (die
->tag
));
11341 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11342 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11343 if (imported_name
== NULL
)
11345 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11347 The import in the following code:
11361 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11362 <52> DW_AT_decl_file : 1
11363 <53> DW_AT_decl_line : 6
11364 <54> DW_AT_import : <0x75>
11365 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11366 <59> DW_AT_name : B
11367 <5b> DW_AT_decl_file : 1
11368 <5c> DW_AT_decl_line : 2
11369 <5d> DW_AT_type : <0x6e>
11371 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11372 <76> DW_AT_byte_size : 4
11373 <77> DW_AT_encoding : 5 (signed)
11375 imports the wrong die ( 0x75 instead of 0x58 ).
11376 This case will be ignored until the gcc bug is fixed. */
11380 /* Figure out the local name after import. */
11381 import_alias
= dwarf2_name (die
, cu
);
11383 /* Figure out where the statement is being imported to. */
11384 import_prefix
= determine_prefix (die
, cu
);
11386 /* Figure out what the scope of the imported die is and prepend it
11387 to the name of the imported die. */
11388 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11390 if (imported_die
->tag
!= DW_TAG_namespace
11391 && imported_die
->tag
!= DW_TAG_module
)
11393 imported_declaration
= imported_name
;
11394 canonical_name
= imported_name_prefix
;
11396 else if (strlen (imported_name_prefix
) > 0)
11397 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11398 imported_name_prefix
,
11399 (cu
->language
== language_d
? "." : "::"),
11400 imported_name
, (char *) NULL
);
11402 canonical_name
= imported_name
;
11404 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11405 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11406 child_die
= sibling_die (child_die
))
11408 /* DWARF-4: A Fortran use statement with a “rename list” may be
11409 represented by an imported module entry with an import attribute
11410 referring to the module and owned entries corresponding to those
11411 entities that are renamed as part of being imported. */
11413 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11415 complaint (_("child DW_TAG_imported_declaration expected "
11416 "- DIE at %s [in module %s]"),
11417 sect_offset_str (child_die
->sect_off
),
11418 objfile_name (objfile
));
11422 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11423 if (import_attr
== NULL
)
11425 complaint (_("Tag '%s' has no DW_AT_import"),
11426 dwarf_tag_name (child_die
->tag
));
11431 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11433 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11434 if (imported_name
== NULL
)
11436 complaint (_("child DW_TAG_imported_declaration has unknown "
11437 "imported name - DIE at %s [in module %s]"),
11438 sect_offset_str (child_die
->sect_off
),
11439 objfile_name (objfile
));
11443 excludes
.push_back (imported_name
);
11445 process_die (child_die
, cu
);
11448 add_using_directive (using_directives (cu
),
11452 imported_declaration
,
11455 &objfile
->objfile_obstack
);
11458 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11459 types, but gives them a size of zero. Starting with version 14,
11460 ICC is compatible with GCC. */
11463 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11465 if (!cu
->checked_producer
)
11466 check_producer (cu
);
11468 return cu
->producer_is_icc_lt_14
;
11471 /* ICC generates a DW_AT_type for C void functions. This was observed on
11472 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11473 which says that void functions should not have a DW_AT_type. */
11476 producer_is_icc (struct dwarf2_cu
*cu
)
11478 if (!cu
->checked_producer
)
11479 check_producer (cu
);
11481 return cu
->producer_is_icc
;
11484 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11485 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11486 this, it was first present in GCC release 4.3.0. */
11489 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11491 if (!cu
->checked_producer
)
11492 check_producer (cu
);
11494 return cu
->producer_is_gcc_lt_4_3
;
11497 static file_and_directory
11498 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11500 file_and_directory res
;
11502 /* Find the filename. Do not use dwarf2_name here, since the filename
11503 is not a source language identifier. */
11504 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11505 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11507 if (res
.comp_dir
== NULL
11508 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11509 && IS_ABSOLUTE_PATH (res
.name
))
11511 res
.comp_dir_storage
= ldirname (res
.name
);
11512 if (!res
.comp_dir_storage
.empty ())
11513 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11515 if (res
.comp_dir
!= NULL
)
11517 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11518 directory, get rid of it. */
11519 const char *cp
= strchr (res
.comp_dir
, ':');
11521 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11522 res
.comp_dir
= cp
+ 1;
11525 if (res
.name
== NULL
)
11526 res
.name
= "<unknown>";
11531 /* Handle DW_AT_stmt_list for a compilation unit.
11532 DIE is the DW_TAG_compile_unit die for CU.
11533 COMP_DIR is the compilation directory. LOWPC is passed to
11534 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11537 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11538 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11540 struct dwarf2_per_objfile
*dwarf2_per_objfile
11541 = cu
->per_cu
->dwarf2_per_objfile
;
11542 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11543 struct attribute
*attr
;
11544 struct line_header line_header_local
;
11545 hashval_t line_header_local_hash
;
11547 int decode_mapping
;
11549 gdb_assert (! cu
->per_cu
->is_debug_types
);
11551 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11555 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11557 /* The line header hash table is only created if needed (it exists to
11558 prevent redundant reading of the line table for partial_units).
11559 If we're given a partial_unit, we'll need it. If we're given a
11560 compile_unit, then use the line header hash table if it's already
11561 created, but don't create one just yet. */
11563 if (dwarf2_per_objfile
->line_header_hash
== NULL
11564 && die
->tag
== DW_TAG_partial_unit
)
11566 dwarf2_per_objfile
->line_header_hash
11567 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11568 line_header_eq_voidp
,
11569 free_line_header_voidp
,
11570 &objfile
->objfile_obstack
,
11571 hashtab_obstack_allocate
,
11572 dummy_obstack_deallocate
);
11575 line_header_local
.sect_off
= line_offset
;
11576 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11577 line_header_local_hash
= line_header_hash (&line_header_local
);
11578 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11580 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11581 &line_header_local
,
11582 line_header_local_hash
, NO_INSERT
);
11584 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11585 is not present in *SLOT (since if there is something in *SLOT then
11586 it will be for a partial_unit). */
11587 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11589 gdb_assert (*slot
!= NULL
);
11590 cu
->line_header
= (struct line_header
*) *slot
;
11595 /* dwarf_decode_line_header does not yet provide sufficient information.
11596 We always have to call also dwarf_decode_lines for it. */
11597 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11601 cu
->line_header
= lh
.release ();
11602 cu
->line_header_die_owner
= die
;
11604 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11608 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11609 &line_header_local
,
11610 line_header_local_hash
, INSERT
);
11611 gdb_assert (slot
!= NULL
);
11613 if (slot
!= NULL
&& *slot
== NULL
)
11615 /* This newly decoded line number information unit will be owned
11616 by line_header_hash hash table. */
11617 *slot
= cu
->line_header
;
11618 cu
->line_header_die_owner
= NULL
;
11622 /* We cannot free any current entry in (*slot) as that struct line_header
11623 may be already used by multiple CUs. Create only temporary decoded
11624 line_header for this CU - it may happen at most once for each line
11625 number information unit. And if we're not using line_header_hash
11626 then this is what we want as well. */
11627 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11629 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11630 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11635 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11638 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11640 struct dwarf2_per_objfile
*dwarf2_per_objfile
11641 = cu
->per_cu
->dwarf2_per_objfile
;
11642 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11643 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11644 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11645 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11646 struct attribute
*attr
;
11647 struct die_info
*child_die
;
11648 CORE_ADDR baseaddr
;
11650 prepare_one_comp_unit (cu
, die
, cu
->language
);
11651 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
11653 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11655 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11656 from finish_block. */
11657 if (lowpc
== ((CORE_ADDR
) -1))
11659 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11661 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11663 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11664 standardised yet. As a workaround for the language detection we fall
11665 back to the DW_AT_producer string. */
11666 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11667 cu
->language
= language_opencl
;
11669 /* Similar hack for Go. */
11670 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11671 set_cu_language (DW_LANG_Go
, cu
);
11673 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11675 /* Decode line number information if present. We do this before
11676 processing child DIEs, so that the line header table is available
11677 for DW_AT_decl_file. */
11678 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11680 /* Process all dies in compilation unit. */
11681 if (die
->child
!= NULL
)
11683 child_die
= die
->child
;
11684 while (child_die
&& child_die
->tag
)
11686 process_die (child_die
, cu
);
11687 child_die
= sibling_die (child_die
);
11691 /* Decode macro information, if present. Dwarf 2 macro information
11692 refers to information in the line number info statement program
11693 header, so we can only read it if we've read the header
11695 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11697 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11698 if (attr
&& cu
->line_header
)
11700 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11701 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11703 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11707 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11708 if (attr
&& cu
->line_header
)
11710 unsigned int macro_offset
= DW_UNSND (attr
);
11712 dwarf_decode_macros (cu
, macro_offset
, 0);
11718 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11720 struct type_unit_group
*tu_group
;
11722 struct attribute
*attr
;
11724 struct signatured_type
*sig_type
;
11726 gdb_assert (per_cu
->is_debug_types
);
11727 sig_type
= (struct signatured_type
*) per_cu
;
11729 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11731 /* If we're using .gdb_index (includes -readnow) then
11732 per_cu->type_unit_group may not have been set up yet. */
11733 if (sig_type
->type_unit_group
== NULL
)
11734 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11735 tu_group
= sig_type
->type_unit_group
;
11737 /* If we've already processed this stmt_list there's no real need to
11738 do it again, we could fake it and just recreate the part we need
11739 (file name,index -> symtab mapping). If data shows this optimization
11740 is useful we can do it then. */
11741 first_time
= tu_group
->compunit_symtab
== NULL
;
11743 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11748 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11749 lh
= dwarf_decode_line_header (line_offset
, this);
11754 start_symtab ("", NULL
, 0);
11757 gdb_assert (tu_group
->symtabs
== NULL
);
11758 gdb_assert (m_builder
== nullptr);
11759 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11760 m_builder
.reset (new struct buildsym_compunit
11761 (COMPUNIT_OBJFILE (cust
), "",
11762 COMPUNIT_DIRNAME (cust
),
11763 compunit_language (cust
),
11769 line_header
= lh
.release ();
11770 line_header_die_owner
= die
;
11774 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11776 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11777 still initializing it, and our caller (a few levels up)
11778 process_full_type_unit still needs to know if this is the first
11781 tu_group
->num_symtabs
= line_header
->file_names_size ();
11782 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11783 line_header
->file_names_size ());
11785 auto &file_names
= line_header
->file_names ();
11786 for (i
= 0; i
< file_names
.size (); ++i
)
11788 file_entry
&fe
= file_names
[i
];
11789 dwarf2_start_subfile (this, fe
.name
,
11790 fe
.include_dir (line_header
));
11791 buildsym_compunit
*b
= get_builder ();
11792 if (b
->get_current_subfile ()->symtab
== NULL
)
11794 /* NOTE: start_subfile will recognize when it's been
11795 passed a file it has already seen. So we can't
11796 assume there's a simple mapping from
11797 cu->line_header->file_names to subfiles, plus
11798 cu->line_header->file_names may contain dups. */
11799 b
->get_current_subfile ()->symtab
11800 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11803 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11804 tu_group
->symtabs
[i
] = fe
.symtab
;
11809 gdb_assert (m_builder
== nullptr);
11810 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11811 m_builder
.reset (new struct buildsym_compunit
11812 (COMPUNIT_OBJFILE (cust
), "",
11813 COMPUNIT_DIRNAME (cust
),
11814 compunit_language (cust
),
11817 auto &file_names
= line_header
->file_names ();
11818 for (i
= 0; i
< file_names
.size (); ++i
)
11820 file_entry
&fe
= file_names
[i
];
11821 fe
.symtab
= tu_group
->symtabs
[i
];
11825 /* The main symtab is allocated last. Type units don't have DW_AT_name
11826 so they don't have a "real" (so to speak) symtab anyway.
11827 There is later code that will assign the main symtab to all symbols
11828 that don't have one. We need to handle the case of a symbol with a
11829 missing symtab (DW_AT_decl_file) anyway. */
11832 /* Process DW_TAG_type_unit.
11833 For TUs we want to skip the first top level sibling if it's not the
11834 actual type being defined by this TU. In this case the first top
11835 level sibling is there to provide context only. */
11838 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11840 struct die_info
*child_die
;
11842 prepare_one_comp_unit (cu
, die
, language_minimal
);
11844 /* Initialize (or reinitialize) the machinery for building symtabs.
11845 We do this before processing child DIEs, so that the line header table
11846 is available for DW_AT_decl_file. */
11847 cu
->setup_type_unit_groups (die
);
11849 if (die
->child
!= NULL
)
11851 child_die
= die
->child
;
11852 while (child_die
&& child_die
->tag
)
11854 process_die (child_die
, cu
);
11855 child_die
= sibling_die (child_die
);
11862 http://gcc.gnu.org/wiki/DebugFission
11863 http://gcc.gnu.org/wiki/DebugFissionDWP
11865 To simplify handling of both DWO files ("object" files with the DWARF info)
11866 and DWP files (a file with the DWOs packaged up into one file), we treat
11867 DWP files as having a collection of virtual DWO files. */
11870 hash_dwo_file (const void *item
)
11872 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11875 hash
= htab_hash_string (dwo_file
->dwo_name
);
11876 if (dwo_file
->comp_dir
!= NULL
)
11877 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11882 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11884 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11885 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11887 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11889 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11890 return lhs
->comp_dir
== rhs
->comp_dir
;
11891 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11894 /* Allocate a hash table for DWO files. */
11897 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11899 auto delete_dwo_file
= [] (void *item
)
11901 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11906 return htab_up (htab_create_alloc_ex (41,
11910 &objfile
->objfile_obstack
,
11911 hashtab_obstack_allocate
,
11912 dummy_obstack_deallocate
));
11915 /* Lookup DWO file DWO_NAME. */
11918 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11919 const char *dwo_name
,
11920 const char *comp_dir
)
11922 struct dwo_file find_entry
;
11925 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11926 dwarf2_per_objfile
->dwo_files
11927 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11929 find_entry
.dwo_name
= dwo_name
;
11930 find_entry
.comp_dir
= comp_dir
;
11931 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11938 hash_dwo_unit (const void *item
)
11940 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11942 /* This drops the top 32 bits of the id, but is ok for a hash. */
11943 return dwo_unit
->signature
;
11947 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11949 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11950 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11952 /* The signature is assumed to be unique within the DWO file.
11953 So while object file CU dwo_id's always have the value zero,
11954 that's OK, assuming each object file DWO file has only one CU,
11955 and that's the rule for now. */
11956 return lhs
->signature
== rhs
->signature
;
11959 /* Allocate a hash table for DWO CUs,TUs.
11960 There is one of these tables for each of CUs,TUs for each DWO file. */
11963 allocate_dwo_unit_table (struct objfile
*objfile
)
11965 /* Start out with a pretty small number.
11966 Generally DWO files contain only one CU and maybe some TUs. */
11967 return htab_create_alloc_ex (3,
11971 &objfile
->objfile_obstack
,
11972 hashtab_obstack_allocate
,
11973 dummy_obstack_deallocate
);
11976 /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */
11978 struct create_dwo_cu_data
11980 struct dwo_file
*dwo_file
;
11981 struct dwo_unit dwo_unit
;
11984 /* die_reader_func for create_dwo_cu. */
11987 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11988 const gdb_byte
*info_ptr
,
11989 struct die_info
*comp_unit_die
,
11993 struct dwarf2_cu
*cu
= reader
->cu
;
11994 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11995 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11996 struct create_dwo_cu_data
*data
= (struct create_dwo_cu_data
*) datap
;
11997 struct dwo_file
*dwo_file
= data
->dwo_file
;
11998 struct dwo_unit
*dwo_unit
= &data
->dwo_unit
;
12000 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
12001 if (!signature
.has_value ())
12003 complaint (_("Dwarf Error: debug entry at offset %s is missing"
12004 " its dwo_id [in module %s]"),
12005 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
12009 dwo_unit
->dwo_file
= dwo_file
;
12010 dwo_unit
->signature
= *signature
;
12011 dwo_unit
->section
= section
;
12012 dwo_unit
->sect_off
= sect_off
;
12013 dwo_unit
->length
= cu
->per_cu
->length
;
12015 if (dwarf_read_debug
)
12016 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
12017 sect_offset_str (sect_off
),
12018 hex_string (dwo_unit
->signature
));
12021 /* Create the dwo_units for the CUs in a DWO_FILE.
12022 Note: This function processes DWO files only, not DWP files. */
12025 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12026 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
12027 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
12029 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12030 const gdb_byte
*info_ptr
, *end_ptr
;
12032 dwarf2_read_section (objfile
, §ion
);
12033 info_ptr
= section
.buffer
;
12035 if (info_ptr
== NULL
)
12038 if (dwarf_read_debug
)
12040 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
12041 get_section_name (§ion
),
12042 get_section_file_name (§ion
));
12045 end_ptr
= info_ptr
+ section
.size
;
12046 while (info_ptr
< end_ptr
)
12048 struct dwarf2_per_cu_data per_cu
;
12049 struct create_dwo_cu_data create_dwo_cu_data
;
12050 struct dwo_unit
*dwo_unit
;
12052 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
12054 memset (&create_dwo_cu_data
.dwo_unit
, 0,
12055 sizeof (create_dwo_cu_data
.dwo_unit
));
12056 memset (&per_cu
, 0, sizeof (per_cu
));
12057 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
12058 per_cu
.is_debug_types
= 0;
12059 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12060 per_cu
.section
= §ion
;
12061 create_dwo_cu_data
.dwo_file
= &dwo_file
;
12063 init_cutu_and_read_dies_no_follow (
12064 &per_cu
, cu
, &dwo_file
, create_dwo_cu_reader
, &create_dwo_cu_data
);
12065 info_ptr
+= per_cu
.length
;
12067 // If the unit could not be parsed, skip it.
12068 if (create_dwo_cu_data
.dwo_unit
.dwo_file
== NULL
)
12071 if (cus_htab
== NULL
)
12072 cus_htab
= allocate_dwo_unit_table (objfile
);
12074 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12075 *dwo_unit
= create_dwo_cu_data
.dwo_unit
;
12076 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12077 gdb_assert (slot
!= NULL
);
12080 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12081 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12083 complaint (_("debug cu entry at offset %s is duplicate to"
12084 " the entry at offset %s, signature %s"),
12085 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12086 hex_string (dwo_unit
->signature
));
12088 *slot
= (void *)dwo_unit
;
12092 /* DWP file .debug_{cu,tu}_index section format:
12093 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12097 Both index sections have the same format, and serve to map a 64-bit
12098 signature to a set of section numbers. Each section begins with a header,
12099 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12100 indexes, and a pool of 32-bit section numbers. The index sections will be
12101 aligned at 8-byte boundaries in the file.
12103 The index section header consists of:
12105 V, 32 bit version number
12107 N, 32 bit number of compilation units or type units in the index
12108 M, 32 bit number of slots in the hash table
12110 Numbers are recorded using the byte order of the application binary.
12112 The hash table begins at offset 16 in the section, and consists of an array
12113 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12114 order of the application binary). Unused slots in the hash table are 0.
12115 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12117 The parallel table begins immediately after the hash table
12118 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12119 array of 32-bit indexes (using the byte order of the application binary),
12120 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12121 table contains a 32-bit index into the pool of section numbers. For unused
12122 hash table slots, the corresponding entry in the parallel table will be 0.
12124 The pool of section numbers begins immediately following the hash table
12125 (at offset 16 + 12 * M from the beginning of the section). The pool of
12126 section numbers consists of an array of 32-bit words (using the byte order
12127 of the application binary). Each item in the array is indexed starting
12128 from 0. The hash table entry provides the index of the first section
12129 number in the set. Additional section numbers in the set follow, and the
12130 set is terminated by a 0 entry (section number 0 is not used in ELF).
12132 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12133 section must be the first entry in the set, and the .debug_abbrev.dwo must
12134 be the second entry. Other members of the set may follow in any order.
12140 DWP Version 2 combines all the .debug_info, etc. sections into one,
12141 and the entries in the index tables are now offsets into these sections.
12142 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12145 Index Section Contents:
12147 Hash Table of Signatures dwp_hash_table.hash_table
12148 Parallel Table of Indices dwp_hash_table.unit_table
12149 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12150 Table of Section Sizes dwp_hash_table.v2.sizes
12152 The index section header consists of:
12154 V, 32 bit version number
12155 L, 32 bit number of columns in the table of section offsets
12156 N, 32 bit number of compilation units or type units in the index
12157 M, 32 bit number of slots in the hash table
12159 Numbers are recorded using the byte order of the application binary.
12161 The hash table has the same format as version 1.
12162 The parallel table of indices has the same format as version 1,
12163 except that the entries are origin-1 indices into the table of sections
12164 offsets and the table of section sizes.
12166 The table of offsets begins immediately following the parallel table
12167 (at offset 16 + 12 * M from the beginning of the section). The table is
12168 a two-dimensional array of 32-bit words (using the byte order of the
12169 application binary), with L columns and N+1 rows, in row-major order.
12170 Each row in the array is indexed starting from 0. The first row provides
12171 a key to the remaining rows: each column in this row provides an identifier
12172 for a debug section, and the offsets in the same column of subsequent rows
12173 refer to that section. The section identifiers are:
12175 DW_SECT_INFO 1 .debug_info.dwo
12176 DW_SECT_TYPES 2 .debug_types.dwo
12177 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12178 DW_SECT_LINE 4 .debug_line.dwo
12179 DW_SECT_LOC 5 .debug_loc.dwo
12180 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12181 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12182 DW_SECT_MACRO 8 .debug_macro.dwo
12184 The offsets provided by the CU and TU index sections are the base offsets
12185 for the contributions made by each CU or TU to the corresponding section
12186 in the package file. Each CU and TU header contains an abbrev_offset
12187 field, used to find the abbreviations table for that CU or TU within the
12188 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12189 be interpreted as relative to the base offset given in the index section.
12190 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12191 should be interpreted as relative to the base offset for .debug_line.dwo,
12192 and offsets into other debug sections obtained from DWARF attributes should
12193 also be interpreted as relative to the corresponding base offset.
12195 The table of sizes begins immediately following the table of offsets.
12196 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12197 with L columns and N rows, in row-major order. Each row in the array is
12198 indexed starting from 1 (row 0 is shared by the two tables).
12202 Hash table lookup is handled the same in version 1 and 2:
12204 We assume that N and M will not exceed 2^32 - 1.
12205 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12207 Given a 64-bit compilation unit signature or a type signature S, an entry
12208 in the hash table is located as follows:
12210 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12211 the low-order k bits all set to 1.
12213 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12215 3) If the hash table entry at index H matches the signature, use that
12216 entry. If the hash table entry at index H is unused (all zeroes),
12217 terminate the search: the signature is not present in the table.
12219 4) Let H = (H + H') modulo M. Repeat at Step 3.
12221 Because M > N and H' and M are relatively prime, the search is guaranteed
12222 to stop at an unused slot or find the match. */
12224 /* Create a hash table to map DWO IDs to their CU/TU entry in
12225 .debug_{info,types}.dwo in DWP_FILE.
12226 Returns NULL if there isn't one.
12227 Note: This function processes DWP files only, not DWO files. */
12229 static struct dwp_hash_table
*
12230 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12231 struct dwp_file
*dwp_file
, int is_debug_types
)
12233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12234 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12235 const gdb_byte
*index_ptr
, *index_end
;
12236 struct dwarf2_section_info
*index
;
12237 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12238 struct dwp_hash_table
*htab
;
12240 if (is_debug_types
)
12241 index
= &dwp_file
->sections
.tu_index
;
12243 index
= &dwp_file
->sections
.cu_index
;
12245 if (dwarf2_section_empty_p (index
))
12247 dwarf2_read_section (objfile
, index
);
12249 index_ptr
= index
->buffer
;
12250 index_end
= index_ptr
+ index
->size
;
12252 version
= read_4_bytes (dbfd
, index_ptr
);
12255 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12259 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12261 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12264 if (version
!= 1 && version
!= 2)
12266 error (_("Dwarf Error: unsupported DWP file version (%s)"
12267 " [in module %s]"),
12268 pulongest (version
), dwp_file
->name
);
12270 if (nr_slots
!= (nr_slots
& -nr_slots
))
12272 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12273 " is not power of 2 [in module %s]"),
12274 pulongest (nr_slots
), dwp_file
->name
);
12277 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12278 htab
->version
= version
;
12279 htab
->nr_columns
= nr_columns
;
12280 htab
->nr_units
= nr_units
;
12281 htab
->nr_slots
= nr_slots
;
12282 htab
->hash_table
= index_ptr
;
12283 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12285 /* Exit early if the table is empty. */
12286 if (nr_slots
== 0 || nr_units
== 0
12287 || (version
== 2 && nr_columns
== 0))
12289 /* All must be zero. */
12290 if (nr_slots
!= 0 || nr_units
!= 0
12291 || (version
== 2 && nr_columns
!= 0))
12293 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12294 " all zero [in modules %s]"),
12302 htab
->section_pool
.v1
.indices
=
12303 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12304 /* It's harder to decide whether the section is too small in v1.
12305 V1 is deprecated anyway so we punt. */
12309 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12310 int *ids
= htab
->section_pool
.v2
.section_ids
;
12311 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12312 /* Reverse map for error checking. */
12313 int ids_seen
[DW_SECT_MAX
+ 1];
12316 if (nr_columns
< 2)
12318 error (_("Dwarf Error: bad DWP hash table, too few columns"
12319 " in section table [in module %s]"),
12322 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12324 error (_("Dwarf Error: bad DWP hash table, too many columns"
12325 " in section table [in module %s]"),
12328 memset (ids
, 255, sizeof_ids
);
12329 memset (ids_seen
, 255, sizeof (ids_seen
));
12330 for (i
= 0; i
< nr_columns
; ++i
)
12332 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12334 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12336 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12337 " in section table [in module %s]"),
12338 id
, dwp_file
->name
);
12340 if (ids_seen
[id
] != -1)
12342 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12343 " id %d in section table [in module %s]"),
12344 id
, dwp_file
->name
);
12349 /* Must have exactly one info or types section. */
12350 if (((ids_seen
[DW_SECT_INFO
] != -1)
12351 + (ids_seen
[DW_SECT_TYPES
] != -1))
12354 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12355 " DWO info/types section [in module %s]"),
12358 /* Must have an abbrev section. */
12359 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12361 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12362 " section [in module %s]"),
12365 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12366 htab
->section_pool
.v2
.sizes
=
12367 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12368 * nr_units
* nr_columns
);
12369 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12370 * nr_units
* nr_columns
))
12373 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12374 " [in module %s]"),
12382 /* Update SECTIONS with the data from SECTP.
12384 This function is like the other "locate" section routines that are
12385 passed to bfd_map_over_sections, but in this context the sections to
12386 read comes from the DWP V1 hash table, not the full ELF section table.
12388 The result is non-zero for success, or zero if an error was found. */
12391 locate_v1_virtual_dwo_sections (asection
*sectp
,
12392 struct virtual_v1_dwo_sections
*sections
)
12394 const struct dwop_section_names
*names
= &dwop_section_names
;
12396 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12398 /* There can be only one. */
12399 if (sections
->abbrev
.s
.section
!= NULL
)
12401 sections
->abbrev
.s
.section
= sectp
;
12402 sections
->abbrev
.size
= bfd_section_size (sectp
);
12404 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12405 || section_is_p (sectp
->name
, &names
->types_dwo
))
12407 /* There can be only one. */
12408 if (sections
->info_or_types
.s
.section
!= NULL
)
12410 sections
->info_or_types
.s
.section
= sectp
;
12411 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12413 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12415 /* There can be only one. */
12416 if (sections
->line
.s
.section
!= NULL
)
12418 sections
->line
.s
.section
= sectp
;
12419 sections
->line
.size
= bfd_section_size (sectp
);
12421 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12423 /* There can be only one. */
12424 if (sections
->loc
.s
.section
!= NULL
)
12426 sections
->loc
.s
.section
= sectp
;
12427 sections
->loc
.size
= bfd_section_size (sectp
);
12429 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12431 /* There can be only one. */
12432 if (sections
->macinfo
.s
.section
!= NULL
)
12434 sections
->macinfo
.s
.section
= sectp
;
12435 sections
->macinfo
.size
= bfd_section_size (sectp
);
12437 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12439 /* There can be only one. */
12440 if (sections
->macro
.s
.section
!= NULL
)
12442 sections
->macro
.s
.section
= sectp
;
12443 sections
->macro
.size
= bfd_section_size (sectp
);
12445 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12447 /* There can be only one. */
12448 if (sections
->str_offsets
.s
.section
!= NULL
)
12450 sections
->str_offsets
.s
.section
= sectp
;
12451 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12455 /* No other kind of section is valid. */
12462 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12463 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12464 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12465 This is for DWP version 1 files. */
12467 static struct dwo_unit
*
12468 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12469 struct dwp_file
*dwp_file
,
12470 uint32_t unit_index
,
12471 const char *comp_dir
,
12472 ULONGEST signature
, int is_debug_types
)
12474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12475 const struct dwp_hash_table
*dwp_htab
=
12476 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12477 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12478 const char *kind
= is_debug_types
? "TU" : "CU";
12479 struct dwo_file
*dwo_file
;
12480 struct dwo_unit
*dwo_unit
;
12481 struct virtual_v1_dwo_sections sections
;
12482 void **dwo_file_slot
;
12485 gdb_assert (dwp_file
->version
== 1);
12487 if (dwarf_read_debug
)
12489 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12491 pulongest (unit_index
), hex_string (signature
),
12495 /* Fetch the sections of this DWO unit.
12496 Put a limit on the number of sections we look for so that bad data
12497 doesn't cause us to loop forever. */
12499 #define MAX_NR_V1_DWO_SECTIONS \
12500 (1 /* .debug_info or .debug_types */ \
12501 + 1 /* .debug_abbrev */ \
12502 + 1 /* .debug_line */ \
12503 + 1 /* .debug_loc */ \
12504 + 1 /* .debug_str_offsets */ \
12505 + 1 /* .debug_macro or .debug_macinfo */ \
12506 + 1 /* trailing zero */)
12508 memset (§ions
, 0, sizeof (sections
));
12510 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12513 uint32_t section_nr
=
12514 read_4_bytes (dbfd
,
12515 dwp_htab
->section_pool
.v1
.indices
12516 + (unit_index
+ i
) * sizeof (uint32_t));
12518 if (section_nr
== 0)
12520 if (section_nr
>= dwp_file
->num_sections
)
12522 error (_("Dwarf Error: bad DWP hash table, section number too large"
12523 " [in module %s]"),
12527 sectp
= dwp_file
->elf_sections
[section_nr
];
12528 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12530 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12531 " [in module %s]"),
12537 || dwarf2_section_empty_p (§ions
.info_or_types
)
12538 || dwarf2_section_empty_p (§ions
.abbrev
))
12540 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12541 " [in module %s]"),
12544 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12546 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12547 " [in module %s]"),
12551 /* It's easier for the rest of the code if we fake a struct dwo_file and
12552 have dwo_unit "live" in that. At least for now.
12554 The DWP file can be made up of a random collection of CUs and TUs.
12555 However, for each CU + set of TUs that came from the same original DWO
12556 file, we can combine them back into a virtual DWO file to save space
12557 (fewer struct dwo_file objects to allocate). Remember that for really
12558 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12560 std::string virtual_dwo_name
=
12561 string_printf ("virtual-dwo/%d-%d-%d-%d",
12562 get_section_id (§ions
.abbrev
),
12563 get_section_id (§ions
.line
),
12564 get_section_id (§ions
.loc
),
12565 get_section_id (§ions
.str_offsets
));
12566 /* Can we use an existing virtual DWO file? */
12567 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12568 virtual_dwo_name
.c_str (),
12570 /* Create one if necessary. */
12571 if (*dwo_file_slot
== NULL
)
12573 if (dwarf_read_debug
)
12575 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12576 virtual_dwo_name
.c_str ());
12578 dwo_file
= new struct dwo_file
;
12579 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12581 dwo_file
->comp_dir
= comp_dir
;
12582 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12583 dwo_file
->sections
.line
= sections
.line
;
12584 dwo_file
->sections
.loc
= sections
.loc
;
12585 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12586 dwo_file
->sections
.macro
= sections
.macro
;
12587 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12588 /* The "str" section is global to the entire DWP file. */
12589 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12590 /* The info or types section is assigned below to dwo_unit,
12591 there's no need to record it in dwo_file.
12592 Also, we can't simply record type sections in dwo_file because
12593 we record a pointer into the vector in dwo_unit. As we collect more
12594 types we'll grow the vector and eventually have to reallocate space
12595 for it, invalidating all copies of pointers into the previous
12597 *dwo_file_slot
= dwo_file
;
12601 if (dwarf_read_debug
)
12603 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12604 virtual_dwo_name
.c_str ());
12606 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12609 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12610 dwo_unit
->dwo_file
= dwo_file
;
12611 dwo_unit
->signature
= signature
;
12612 dwo_unit
->section
=
12613 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12614 *dwo_unit
->section
= sections
.info_or_types
;
12615 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12620 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12621 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12622 piece within that section used by a TU/CU, return a virtual section
12623 of just that piece. */
12625 static struct dwarf2_section_info
12626 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12627 struct dwarf2_section_info
*section
,
12628 bfd_size_type offset
, bfd_size_type size
)
12630 struct dwarf2_section_info result
;
12633 gdb_assert (section
!= NULL
);
12634 gdb_assert (!section
->is_virtual
);
12636 memset (&result
, 0, sizeof (result
));
12637 result
.s
.containing_section
= section
;
12638 result
.is_virtual
= true;
12643 sectp
= get_section_bfd_section (section
);
12645 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12646 bounds of the real section. This is a pretty-rare event, so just
12647 flag an error (easier) instead of a warning and trying to cope. */
12649 || offset
+ size
> bfd_section_size (sectp
))
12651 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12652 " in section %s [in module %s]"),
12653 sectp
? bfd_section_name (sectp
) : "<unknown>",
12654 objfile_name (dwarf2_per_objfile
->objfile
));
12657 result
.virtual_offset
= offset
;
12658 result
.size
= size
;
12662 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12663 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12664 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12665 This is for DWP version 2 files. */
12667 static struct dwo_unit
*
12668 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12669 struct dwp_file
*dwp_file
,
12670 uint32_t unit_index
,
12671 const char *comp_dir
,
12672 ULONGEST signature
, int is_debug_types
)
12674 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12675 const struct dwp_hash_table
*dwp_htab
=
12676 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12677 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12678 const char *kind
= is_debug_types
? "TU" : "CU";
12679 struct dwo_file
*dwo_file
;
12680 struct dwo_unit
*dwo_unit
;
12681 struct virtual_v2_dwo_sections sections
;
12682 void **dwo_file_slot
;
12685 gdb_assert (dwp_file
->version
== 2);
12687 if (dwarf_read_debug
)
12689 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12691 pulongest (unit_index
), hex_string (signature
),
12695 /* Fetch the section offsets of this DWO unit. */
12697 memset (§ions
, 0, sizeof (sections
));
12699 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12701 uint32_t offset
= read_4_bytes (dbfd
,
12702 dwp_htab
->section_pool
.v2
.offsets
12703 + (((unit_index
- 1) * dwp_htab
->nr_columns
12705 * sizeof (uint32_t)));
12706 uint32_t size
= read_4_bytes (dbfd
,
12707 dwp_htab
->section_pool
.v2
.sizes
12708 + (((unit_index
- 1) * dwp_htab
->nr_columns
12710 * sizeof (uint32_t)));
12712 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12715 case DW_SECT_TYPES
:
12716 sections
.info_or_types_offset
= offset
;
12717 sections
.info_or_types_size
= size
;
12719 case DW_SECT_ABBREV
:
12720 sections
.abbrev_offset
= offset
;
12721 sections
.abbrev_size
= size
;
12724 sections
.line_offset
= offset
;
12725 sections
.line_size
= size
;
12728 sections
.loc_offset
= offset
;
12729 sections
.loc_size
= size
;
12731 case DW_SECT_STR_OFFSETS
:
12732 sections
.str_offsets_offset
= offset
;
12733 sections
.str_offsets_size
= size
;
12735 case DW_SECT_MACINFO
:
12736 sections
.macinfo_offset
= offset
;
12737 sections
.macinfo_size
= size
;
12739 case DW_SECT_MACRO
:
12740 sections
.macro_offset
= offset
;
12741 sections
.macro_size
= size
;
12746 /* It's easier for the rest of the code if we fake a struct dwo_file and
12747 have dwo_unit "live" in that. At least for now.
12749 The DWP file can be made up of a random collection of CUs and TUs.
12750 However, for each CU + set of TUs that came from the same original DWO
12751 file, we can combine them back into a virtual DWO file to save space
12752 (fewer struct dwo_file objects to allocate). Remember that for really
12753 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12755 std::string virtual_dwo_name
=
12756 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12757 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12758 (long) (sections
.line_size
? sections
.line_offset
: 0),
12759 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12760 (long) (sections
.str_offsets_size
12761 ? sections
.str_offsets_offset
: 0));
12762 /* Can we use an existing virtual DWO file? */
12763 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12764 virtual_dwo_name
.c_str (),
12766 /* Create one if necessary. */
12767 if (*dwo_file_slot
== NULL
)
12769 if (dwarf_read_debug
)
12771 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12772 virtual_dwo_name
.c_str ());
12774 dwo_file
= new struct dwo_file
;
12775 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12777 dwo_file
->comp_dir
= comp_dir
;
12778 dwo_file
->sections
.abbrev
=
12779 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12780 sections
.abbrev_offset
, sections
.abbrev_size
);
12781 dwo_file
->sections
.line
=
12782 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12783 sections
.line_offset
, sections
.line_size
);
12784 dwo_file
->sections
.loc
=
12785 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12786 sections
.loc_offset
, sections
.loc_size
);
12787 dwo_file
->sections
.macinfo
=
12788 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12789 sections
.macinfo_offset
, sections
.macinfo_size
);
12790 dwo_file
->sections
.macro
=
12791 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12792 sections
.macro_offset
, sections
.macro_size
);
12793 dwo_file
->sections
.str_offsets
=
12794 create_dwp_v2_section (dwarf2_per_objfile
,
12795 &dwp_file
->sections
.str_offsets
,
12796 sections
.str_offsets_offset
,
12797 sections
.str_offsets_size
);
12798 /* The "str" section is global to the entire DWP file. */
12799 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12800 /* The info or types section is assigned below to dwo_unit,
12801 there's no need to record it in dwo_file.
12802 Also, we can't simply record type sections in dwo_file because
12803 we record a pointer into the vector in dwo_unit. As we collect more
12804 types we'll grow the vector and eventually have to reallocate space
12805 for it, invalidating all copies of pointers into the previous
12807 *dwo_file_slot
= dwo_file
;
12811 if (dwarf_read_debug
)
12813 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12814 virtual_dwo_name
.c_str ());
12816 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12819 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12820 dwo_unit
->dwo_file
= dwo_file
;
12821 dwo_unit
->signature
= signature
;
12822 dwo_unit
->section
=
12823 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12824 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12826 ? &dwp_file
->sections
.types
12827 : &dwp_file
->sections
.info
,
12828 sections
.info_or_types_offset
,
12829 sections
.info_or_types_size
);
12830 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12835 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12836 Returns NULL if the signature isn't found. */
12838 static struct dwo_unit
*
12839 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12840 struct dwp_file
*dwp_file
, const char *comp_dir
,
12841 ULONGEST signature
, int is_debug_types
)
12843 const struct dwp_hash_table
*dwp_htab
=
12844 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12845 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12846 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12847 uint32_t hash
= signature
& mask
;
12848 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12851 struct dwo_unit find_dwo_cu
;
12853 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12854 find_dwo_cu
.signature
= signature
;
12855 slot
= htab_find_slot (is_debug_types
12856 ? dwp_file
->loaded_tus
12857 : dwp_file
->loaded_cus
,
12858 &find_dwo_cu
, INSERT
);
12861 return (struct dwo_unit
*) *slot
;
12863 /* Use a for loop so that we don't loop forever on bad debug info. */
12864 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12866 ULONGEST signature_in_table
;
12868 signature_in_table
=
12869 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12870 if (signature_in_table
== signature
)
12872 uint32_t unit_index
=
12873 read_4_bytes (dbfd
,
12874 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12876 if (dwp_file
->version
== 1)
12878 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12879 dwp_file
, unit_index
,
12880 comp_dir
, signature
,
12885 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12886 dwp_file
, unit_index
,
12887 comp_dir
, signature
,
12890 return (struct dwo_unit
*) *slot
;
12892 if (signature_in_table
== 0)
12894 hash
= (hash
+ hash2
) & mask
;
12897 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12898 " [in module %s]"),
12902 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12903 Open the file specified by FILE_NAME and hand it off to BFD for
12904 preliminary analysis. Return a newly initialized bfd *, which
12905 includes a canonicalized copy of FILE_NAME.
12906 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12907 SEARCH_CWD is true if the current directory is to be searched.
12908 It will be searched before debug-file-directory.
12909 If successful, the file is added to the bfd include table of the
12910 objfile's bfd (see gdb_bfd_record_inclusion).
12911 If unable to find/open the file, return NULL.
12912 NOTE: This function is derived from symfile_bfd_open. */
12914 static gdb_bfd_ref_ptr
12915 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12916 const char *file_name
, int is_dwp
, int search_cwd
)
12919 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12920 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12921 to debug_file_directory. */
12922 const char *search_path
;
12923 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12925 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12928 if (*debug_file_directory
!= '\0')
12930 search_path_holder
.reset (concat (".", dirname_separator_string
,
12931 debug_file_directory
,
12933 search_path
= search_path_holder
.get ();
12939 search_path
= debug_file_directory
;
12941 openp_flags flags
= OPF_RETURN_REALPATH
;
12943 flags
|= OPF_SEARCH_IN_PATH
;
12945 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12946 desc
= openp (search_path
, flags
, file_name
,
12947 O_RDONLY
| O_BINARY
, &absolute_name
);
12951 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12953 if (sym_bfd
== NULL
)
12955 bfd_set_cacheable (sym_bfd
.get (), 1);
12957 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12960 /* Success. Record the bfd as having been included by the objfile's bfd.
12961 This is important because things like demangled_names_hash lives in the
12962 objfile's per_bfd space and may have references to things like symbol
12963 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12964 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12969 /* Try to open DWO file FILE_NAME.
12970 COMP_DIR is the DW_AT_comp_dir attribute.
12971 The result is the bfd handle of the file.
12972 If there is a problem finding or opening the file, return NULL.
12973 Upon success, the canonicalized path of the file is stored in the bfd,
12974 same as symfile_bfd_open. */
12976 static gdb_bfd_ref_ptr
12977 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12978 const char *file_name
, const char *comp_dir
)
12980 if (IS_ABSOLUTE_PATH (file_name
))
12981 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12982 0 /*is_dwp*/, 0 /*search_cwd*/);
12984 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12986 if (comp_dir
!= NULL
)
12988 gdb::unique_xmalloc_ptr
<char> path_to_try
12989 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12991 /* NOTE: If comp_dir is a relative path, this will also try the
12992 search path, which seems useful. */
12993 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12994 path_to_try
.get (),
12996 1 /*search_cwd*/));
13001 /* That didn't work, try debug-file-directory, which, despite its name,
13002 is a list of paths. */
13004 if (*debug_file_directory
== '\0')
13007 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13008 0 /*is_dwp*/, 1 /*search_cwd*/);
13011 /* This function is mapped across the sections and remembers the offset and
13012 size of each of the DWO debugging sections we are interested in. */
13015 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
13017 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
13018 const struct dwop_section_names
*names
= &dwop_section_names
;
13020 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13022 dwo_sections
->abbrev
.s
.section
= sectp
;
13023 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
13025 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13027 dwo_sections
->info
.s
.section
= sectp
;
13028 dwo_sections
->info
.size
= bfd_section_size (sectp
);
13030 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13032 dwo_sections
->line
.s
.section
= sectp
;
13033 dwo_sections
->line
.size
= bfd_section_size (sectp
);
13035 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13037 dwo_sections
->loc
.s
.section
= sectp
;
13038 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
13040 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13042 dwo_sections
->macinfo
.s
.section
= sectp
;
13043 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
13045 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13047 dwo_sections
->macro
.s
.section
= sectp
;
13048 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
13050 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
13052 dwo_sections
->str
.s
.section
= sectp
;
13053 dwo_sections
->str
.size
= bfd_section_size (sectp
);
13055 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13057 dwo_sections
->str_offsets
.s
.section
= sectp
;
13058 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13060 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13062 struct dwarf2_section_info type_section
;
13064 memset (&type_section
, 0, sizeof (type_section
));
13065 type_section
.s
.section
= sectp
;
13066 type_section
.size
= bfd_section_size (sectp
);
13067 dwo_sections
->types
.push_back (type_section
);
13071 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13072 by PER_CU. This is for the non-DWP case.
13073 The result is NULL if DWO_NAME can't be found. */
13075 static struct dwo_file
*
13076 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13077 const char *dwo_name
, const char *comp_dir
)
13079 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13081 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13084 if (dwarf_read_debug
)
13085 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13089 dwo_file_up
dwo_file (new struct dwo_file
);
13090 dwo_file
->dwo_name
= dwo_name
;
13091 dwo_file
->comp_dir
= comp_dir
;
13092 dwo_file
->dbfd
= std::move (dbfd
);
13094 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13095 &dwo_file
->sections
);
13097 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
13098 dwo_file
->sections
.info
, dwo_file
->cus
);
13100 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13101 dwo_file
->sections
.types
, dwo_file
->tus
);
13103 if (dwarf_read_debug
)
13104 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13106 return dwo_file
.release ();
13109 /* This function is mapped across the sections and remembers the offset and
13110 size of each of the DWP debugging sections common to version 1 and 2 that
13111 we are interested in. */
13114 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13115 void *dwp_file_ptr
)
13117 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13118 const struct dwop_section_names
*names
= &dwop_section_names
;
13119 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13121 /* Record the ELF section number for later lookup: this is what the
13122 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13123 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13124 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13126 /* Look for specific sections that we need. */
13127 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13129 dwp_file
->sections
.str
.s
.section
= sectp
;
13130 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13132 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13134 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13135 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13137 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13139 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13140 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13144 /* This function is mapped across the sections and remembers the offset and
13145 size of each of the DWP version 2 debugging sections that we are interested
13146 in. This is split into a separate function because we don't know if we
13147 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13150 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13152 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13153 const struct dwop_section_names
*names
= &dwop_section_names
;
13154 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13156 /* Record the ELF section number for later lookup: this is what the
13157 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13158 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13159 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13161 /* Look for specific sections that we need. */
13162 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13164 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13165 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13167 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13169 dwp_file
->sections
.info
.s
.section
= sectp
;
13170 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13172 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13174 dwp_file
->sections
.line
.s
.section
= sectp
;
13175 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13177 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13179 dwp_file
->sections
.loc
.s
.section
= sectp
;
13180 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13182 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13184 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13185 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13187 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13189 dwp_file
->sections
.macro
.s
.section
= sectp
;
13190 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13192 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13194 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13195 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13197 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13199 dwp_file
->sections
.types
.s
.section
= sectp
;
13200 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13204 /* Hash function for dwp_file loaded CUs/TUs. */
13207 hash_dwp_loaded_cutus (const void *item
)
13209 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13211 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13212 return dwo_unit
->signature
;
13215 /* Equality function for dwp_file loaded CUs/TUs. */
13218 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13220 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13221 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13223 return dua
->signature
== dub
->signature
;
13226 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13229 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13231 return htab_create_alloc_ex (3,
13232 hash_dwp_loaded_cutus
,
13233 eq_dwp_loaded_cutus
,
13235 &objfile
->objfile_obstack
,
13236 hashtab_obstack_allocate
,
13237 dummy_obstack_deallocate
);
13240 /* Try to open DWP file FILE_NAME.
13241 The result is the bfd handle of the file.
13242 If there is a problem finding or opening the file, return NULL.
13243 Upon success, the canonicalized path of the file is stored in the bfd,
13244 same as symfile_bfd_open. */
13246 static gdb_bfd_ref_ptr
13247 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13248 const char *file_name
)
13250 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13252 1 /*search_cwd*/));
13256 /* Work around upstream bug 15652.
13257 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13258 [Whether that's a "bug" is debatable, but it is getting in our way.]
13259 We have no real idea where the dwp file is, because gdb's realpath-ing
13260 of the executable's path may have discarded the needed info.
13261 [IWBN if the dwp file name was recorded in the executable, akin to
13262 .gnu_debuglink, but that doesn't exist yet.]
13263 Strip the directory from FILE_NAME and search again. */
13264 if (*debug_file_directory
!= '\0')
13266 /* Don't implicitly search the current directory here.
13267 If the user wants to search "." to handle this case,
13268 it must be added to debug-file-directory. */
13269 return try_open_dwop_file (dwarf2_per_objfile
,
13270 lbasename (file_name
), 1 /*is_dwp*/,
13277 /* Initialize the use of the DWP file for the current objfile.
13278 By convention the name of the DWP file is ${objfile}.dwp.
13279 The result is NULL if it can't be found. */
13281 static std::unique_ptr
<struct dwp_file
>
13282 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13284 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13286 /* Try to find first .dwp for the binary file before any symbolic links
13289 /* If the objfile is a debug file, find the name of the real binary
13290 file and get the name of dwp file from there. */
13291 std::string dwp_name
;
13292 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13294 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13295 const char *backlink_basename
= lbasename (backlink
->original_name
);
13297 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13300 dwp_name
= objfile
->original_name
;
13302 dwp_name
+= ".dwp";
13304 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13306 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13308 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13309 dwp_name
= objfile_name (objfile
);
13310 dwp_name
+= ".dwp";
13311 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13316 if (dwarf_read_debug
)
13317 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13318 return std::unique_ptr
<dwp_file
> ();
13321 const char *name
= bfd_get_filename (dbfd
.get ());
13322 std::unique_ptr
<struct dwp_file
> dwp_file
13323 (new struct dwp_file (name
, std::move (dbfd
)));
13325 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13326 dwp_file
->elf_sections
=
13327 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13328 dwp_file
->num_sections
, asection
*);
13330 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13331 dwarf2_locate_common_dwp_sections
,
13334 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13337 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13340 /* The DWP file version is stored in the hash table. Oh well. */
13341 if (dwp_file
->cus
&& dwp_file
->tus
13342 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13344 /* Technically speaking, we should try to limp along, but this is
13345 pretty bizarre. We use pulongest here because that's the established
13346 portability solution (e.g, we cannot use %u for uint32_t). */
13347 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13348 " TU version %s [in DWP file %s]"),
13349 pulongest (dwp_file
->cus
->version
),
13350 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13354 dwp_file
->version
= dwp_file
->cus
->version
;
13355 else if (dwp_file
->tus
)
13356 dwp_file
->version
= dwp_file
->tus
->version
;
13358 dwp_file
->version
= 2;
13360 if (dwp_file
->version
== 2)
13361 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13362 dwarf2_locate_v2_dwp_sections
,
13365 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13366 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13368 if (dwarf_read_debug
)
13370 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13371 fprintf_unfiltered (gdb_stdlog
,
13372 " %s CUs, %s TUs\n",
13373 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13374 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13380 /* Wrapper around open_and_init_dwp_file, only open it once. */
13382 static struct dwp_file
*
13383 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13385 if (! dwarf2_per_objfile
->dwp_checked
)
13387 dwarf2_per_objfile
->dwp_file
13388 = open_and_init_dwp_file (dwarf2_per_objfile
);
13389 dwarf2_per_objfile
->dwp_checked
= 1;
13391 return dwarf2_per_objfile
->dwp_file
.get ();
13394 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13395 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13396 or in the DWP file for the objfile, referenced by THIS_UNIT.
13397 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13398 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13400 This is called, for example, when wanting to read a variable with a
13401 complex location. Therefore we don't want to do file i/o for every call.
13402 Therefore we don't want to look for a DWO file on every call.
13403 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13404 then we check if we've already seen DWO_NAME, and only THEN do we check
13407 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13408 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13410 static struct dwo_unit
*
13411 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13412 const char *dwo_name
, const char *comp_dir
,
13413 ULONGEST signature
, int is_debug_types
)
13415 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13416 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13417 const char *kind
= is_debug_types
? "TU" : "CU";
13418 void **dwo_file_slot
;
13419 struct dwo_file
*dwo_file
;
13420 struct dwp_file
*dwp_file
;
13422 /* First see if there's a DWP file.
13423 If we have a DWP file but didn't find the DWO inside it, don't
13424 look for the original DWO file. It makes gdb behave differently
13425 depending on whether one is debugging in the build tree. */
13427 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13428 if (dwp_file
!= NULL
)
13430 const struct dwp_hash_table
*dwp_htab
=
13431 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13433 if (dwp_htab
!= NULL
)
13435 struct dwo_unit
*dwo_cutu
=
13436 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13437 signature
, is_debug_types
);
13439 if (dwo_cutu
!= NULL
)
13441 if (dwarf_read_debug
)
13443 fprintf_unfiltered (gdb_stdlog
,
13444 "Virtual DWO %s %s found: @%s\n",
13445 kind
, hex_string (signature
),
13446 host_address_to_string (dwo_cutu
));
13454 /* No DWP file, look for the DWO file. */
13456 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13457 dwo_name
, comp_dir
);
13458 if (*dwo_file_slot
== NULL
)
13460 /* Read in the file and build a table of the CUs/TUs it contains. */
13461 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13463 /* NOTE: This will be NULL if unable to open the file. */
13464 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13466 if (dwo_file
!= NULL
)
13468 struct dwo_unit
*dwo_cutu
= NULL
;
13470 if (is_debug_types
&& dwo_file
->tus
)
13472 struct dwo_unit find_dwo_cutu
;
13474 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13475 find_dwo_cutu
.signature
= signature
;
13477 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13479 else if (!is_debug_types
&& dwo_file
->cus
)
13481 struct dwo_unit find_dwo_cutu
;
13483 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13484 find_dwo_cutu
.signature
= signature
;
13485 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13489 if (dwo_cutu
!= NULL
)
13491 if (dwarf_read_debug
)
13493 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13494 kind
, dwo_name
, hex_string (signature
),
13495 host_address_to_string (dwo_cutu
));
13502 /* We didn't find it. This could mean a dwo_id mismatch, or
13503 someone deleted the DWO/DWP file, or the search path isn't set up
13504 correctly to find the file. */
13506 if (dwarf_read_debug
)
13508 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13509 kind
, dwo_name
, hex_string (signature
));
13512 /* This is a warning and not a complaint because it can be caused by
13513 pilot error (e.g., user accidentally deleting the DWO). */
13515 /* Print the name of the DWP file if we looked there, helps the user
13516 better diagnose the problem. */
13517 std::string dwp_text
;
13519 if (dwp_file
!= NULL
)
13520 dwp_text
= string_printf (" [in DWP file %s]",
13521 lbasename (dwp_file
->name
));
13523 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13524 " [in module %s]"),
13525 kind
, dwo_name
, hex_string (signature
),
13527 this_unit
->is_debug_types
? "TU" : "CU",
13528 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13533 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13534 See lookup_dwo_cutu_unit for details. */
13536 static struct dwo_unit
*
13537 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13538 const char *dwo_name
, const char *comp_dir
,
13539 ULONGEST signature
)
13541 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13544 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13545 See lookup_dwo_cutu_unit for details. */
13547 static struct dwo_unit
*
13548 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13549 const char *dwo_name
, const char *comp_dir
)
13551 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13554 /* Traversal function for queue_and_load_all_dwo_tus. */
13557 queue_and_load_dwo_tu (void **slot
, void *info
)
13559 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13560 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13561 ULONGEST signature
= dwo_unit
->signature
;
13562 struct signatured_type
*sig_type
=
13563 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13565 if (sig_type
!= NULL
)
13567 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13569 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13570 a real dependency of PER_CU on SIG_TYPE. That is detected later
13571 while processing PER_CU. */
13572 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13573 load_full_type_unit (sig_cu
);
13574 per_cu
->imported_symtabs_push (sig_cu
);
13580 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13581 The DWO may have the only definition of the type, though it may not be
13582 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13583 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13586 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13588 struct dwo_unit
*dwo_unit
;
13589 struct dwo_file
*dwo_file
;
13591 gdb_assert (!per_cu
->is_debug_types
);
13592 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13593 gdb_assert (per_cu
->cu
!= NULL
);
13595 dwo_unit
= per_cu
->cu
->dwo_unit
;
13596 gdb_assert (dwo_unit
!= NULL
);
13598 dwo_file
= dwo_unit
->dwo_file
;
13599 if (dwo_file
->tus
!= NULL
)
13600 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13603 /* Read in various DIEs. */
13605 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13606 Inherit only the children of the DW_AT_abstract_origin DIE not being
13607 already referenced by DW_AT_abstract_origin from the children of the
13611 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13613 struct die_info
*child_die
;
13614 sect_offset
*offsetp
;
13615 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13616 struct die_info
*origin_die
;
13617 /* Iterator of the ORIGIN_DIE children. */
13618 struct die_info
*origin_child_die
;
13619 struct attribute
*attr
;
13620 struct dwarf2_cu
*origin_cu
;
13621 struct pending
**origin_previous_list_in_scope
;
13623 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13627 /* Note that following die references may follow to a die in a
13631 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13633 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13635 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13636 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13638 if (die
->tag
!= origin_die
->tag
13639 && !(die
->tag
== DW_TAG_inlined_subroutine
13640 && origin_die
->tag
== DW_TAG_subprogram
))
13641 complaint (_("DIE %s and its abstract origin %s have different tags"),
13642 sect_offset_str (die
->sect_off
),
13643 sect_offset_str (origin_die
->sect_off
));
13645 std::vector
<sect_offset
> offsets
;
13647 for (child_die
= die
->child
;
13648 child_die
&& child_die
->tag
;
13649 child_die
= sibling_die (child_die
))
13651 struct die_info
*child_origin_die
;
13652 struct dwarf2_cu
*child_origin_cu
;
13654 /* We are trying to process concrete instance entries:
13655 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13656 it's not relevant to our analysis here. i.e. detecting DIEs that are
13657 present in the abstract instance but not referenced in the concrete
13659 if (child_die
->tag
== DW_TAG_call_site
13660 || child_die
->tag
== DW_TAG_GNU_call_site
)
13663 /* For each CHILD_DIE, find the corresponding child of
13664 ORIGIN_DIE. If there is more than one layer of
13665 DW_AT_abstract_origin, follow them all; there shouldn't be,
13666 but GCC versions at least through 4.4 generate this (GCC PR
13668 child_origin_die
= child_die
;
13669 child_origin_cu
= cu
;
13672 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13676 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13680 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13681 counterpart may exist. */
13682 if (child_origin_die
!= child_die
)
13684 if (child_die
->tag
!= child_origin_die
->tag
13685 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13686 && child_origin_die
->tag
== DW_TAG_subprogram
))
13687 complaint (_("Child DIE %s and its abstract origin %s have "
13689 sect_offset_str (child_die
->sect_off
),
13690 sect_offset_str (child_origin_die
->sect_off
));
13691 if (child_origin_die
->parent
!= origin_die
)
13692 complaint (_("Child DIE %s and its abstract origin %s have "
13693 "different parents"),
13694 sect_offset_str (child_die
->sect_off
),
13695 sect_offset_str (child_origin_die
->sect_off
));
13697 offsets
.push_back (child_origin_die
->sect_off
);
13700 std::sort (offsets
.begin (), offsets
.end ());
13701 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13702 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13703 if (offsetp
[-1] == *offsetp
)
13704 complaint (_("Multiple children of DIE %s refer "
13705 "to DIE %s as their abstract origin"),
13706 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13708 offsetp
= offsets
.data ();
13709 origin_child_die
= origin_die
->child
;
13710 while (origin_child_die
&& origin_child_die
->tag
)
13712 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13713 while (offsetp
< offsets_end
13714 && *offsetp
< origin_child_die
->sect_off
)
13716 if (offsetp
>= offsets_end
13717 || *offsetp
> origin_child_die
->sect_off
)
13719 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13720 Check whether we're already processing ORIGIN_CHILD_DIE.
13721 This can happen with mutually referenced abstract_origins.
13723 if (!origin_child_die
->in_process
)
13724 process_die (origin_child_die
, origin_cu
);
13726 origin_child_die
= sibling_die (origin_child_die
);
13728 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13730 if (cu
!= origin_cu
)
13731 compute_delayed_physnames (origin_cu
);
13735 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13737 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13738 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13739 struct context_stack
*newobj
;
13742 struct die_info
*child_die
;
13743 struct attribute
*attr
, *call_line
, *call_file
;
13745 CORE_ADDR baseaddr
;
13746 struct block
*block
;
13747 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13748 std::vector
<struct symbol
*> template_args
;
13749 struct template_symbol
*templ_func
= NULL
;
13753 /* If we do not have call site information, we can't show the
13754 caller of this inlined function. That's too confusing, so
13755 only use the scope for local variables. */
13756 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13757 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13758 if (call_line
== NULL
|| call_file
== NULL
)
13760 read_lexical_block_scope (die
, cu
);
13765 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13767 name
= dwarf2_name (die
, cu
);
13769 /* Ignore functions with missing or empty names. These are actually
13770 illegal according to the DWARF standard. */
13773 complaint (_("missing name for subprogram DIE at %s"),
13774 sect_offset_str (die
->sect_off
));
13778 /* Ignore functions with missing or invalid low and high pc attributes. */
13779 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13780 <= PC_BOUNDS_INVALID
)
13782 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13783 if (!attr
|| !DW_UNSND (attr
))
13784 complaint (_("cannot get low and high bounds "
13785 "for subprogram DIE at %s"),
13786 sect_offset_str (die
->sect_off
));
13790 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13791 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13793 /* If we have any template arguments, then we must allocate a
13794 different sort of symbol. */
13795 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13797 if (child_die
->tag
== DW_TAG_template_type_param
13798 || child_die
->tag
== DW_TAG_template_value_param
)
13800 templ_func
= allocate_template_symbol (objfile
);
13801 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13806 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13807 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13808 (struct symbol
*) templ_func
);
13810 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13811 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13814 /* If there is a location expression for DW_AT_frame_base, record
13816 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13817 if (attr
!= nullptr)
13818 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13820 /* If there is a location for the static link, record it. */
13821 newobj
->static_link
= NULL
;
13822 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13823 if (attr
!= nullptr)
13825 newobj
->static_link
13826 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13827 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13828 dwarf2_per_cu_addr_type (cu
->per_cu
));
13831 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13833 if (die
->child
!= NULL
)
13835 child_die
= die
->child
;
13836 while (child_die
&& child_die
->tag
)
13838 if (child_die
->tag
== DW_TAG_template_type_param
13839 || child_die
->tag
== DW_TAG_template_value_param
)
13841 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13844 template_args
.push_back (arg
);
13847 process_die (child_die
, cu
);
13848 child_die
= sibling_die (child_die
);
13852 inherit_abstract_dies (die
, cu
);
13854 /* If we have a DW_AT_specification, we might need to import using
13855 directives from the context of the specification DIE. See the
13856 comment in determine_prefix. */
13857 if (cu
->language
== language_cplus
13858 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13860 struct dwarf2_cu
*spec_cu
= cu
;
13861 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13865 child_die
= spec_die
->child
;
13866 while (child_die
&& child_die
->tag
)
13868 if (child_die
->tag
== DW_TAG_imported_module
)
13869 process_die (child_die
, spec_cu
);
13870 child_die
= sibling_die (child_die
);
13873 /* In some cases, GCC generates specification DIEs that
13874 themselves contain DW_AT_specification attributes. */
13875 spec_die
= die_specification (spec_die
, &spec_cu
);
13879 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13880 /* Make a block for the local symbols within. */
13881 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13882 cstk
.static_link
, lowpc
, highpc
);
13884 /* For C++, set the block's scope. */
13885 if ((cu
->language
== language_cplus
13886 || cu
->language
== language_fortran
13887 || cu
->language
== language_d
13888 || cu
->language
== language_rust
)
13889 && cu
->processing_has_namespace_info
)
13890 block_set_scope (block
, determine_prefix (die
, cu
),
13891 &objfile
->objfile_obstack
);
13893 /* If we have address ranges, record them. */
13894 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13896 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13898 /* Attach template arguments to function. */
13899 if (!template_args
.empty ())
13901 gdb_assert (templ_func
!= NULL
);
13903 templ_func
->n_template_arguments
= template_args
.size ();
13904 templ_func
->template_arguments
13905 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13906 templ_func
->n_template_arguments
);
13907 memcpy (templ_func
->template_arguments
,
13908 template_args
.data (),
13909 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13911 /* Make sure that the symtab is set on the new symbols. Even
13912 though they don't appear in this symtab directly, other parts
13913 of gdb assume that symbols do, and this is reasonably
13915 for (symbol
*sym
: template_args
)
13916 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13919 /* In C++, we can have functions nested inside functions (e.g., when
13920 a function declares a class that has methods). This means that
13921 when we finish processing a function scope, we may need to go
13922 back to building a containing block's symbol lists. */
13923 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13924 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13926 /* If we've finished processing a top-level function, subsequent
13927 symbols go in the file symbol list. */
13928 if (cu
->get_builder ()->outermost_context_p ())
13929 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13932 /* Process all the DIES contained within a lexical block scope. Start
13933 a new scope, process the dies, and then close the scope. */
13936 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13938 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13939 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13940 CORE_ADDR lowpc
, highpc
;
13941 struct die_info
*child_die
;
13942 CORE_ADDR baseaddr
;
13944 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
13946 /* Ignore blocks with missing or invalid low and high pc attributes. */
13947 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13948 as multiple lexical blocks? Handling children in a sane way would
13949 be nasty. Might be easier to properly extend generic blocks to
13950 describe ranges. */
13951 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13953 case PC_BOUNDS_NOT_PRESENT
:
13954 /* DW_TAG_lexical_block has no attributes, process its children as if
13955 there was no wrapping by that DW_TAG_lexical_block.
13956 GCC does no longer produces such DWARF since GCC r224161. */
13957 for (child_die
= die
->child
;
13958 child_die
!= NULL
&& child_die
->tag
;
13959 child_die
= sibling_die (child_die
))
13960 process_die (child_die
, cu
);
13962 case PC_BOUNDS_INVALID
:
13965 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13966 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13968 cu
->get_builder ()->push_context (0, lowpc
);
13969 if (die
->child
!= NULL
)
13971 child_die
= die
->child
;
13972 while (child_die
&& child_die
->tag
)
13974 process_die (child_die
, cu
);
13975 child_die
= sibling_die (child_die
);
13978 inherit_abstract_dies (die
, cu
);
13979 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13981 if (*cu
->get_builder ()->get_local_symbols () != NULL
13982 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13984 struct block
*block
13985 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13986 cstk
.start_addr
, highpc
);
13988 /* Note that recording ranges after traversing children, as we
13989 do here, means that recording a parent's ranges entails
13990 walking across all its children's ranges as they appear in
13991 the address map, which is quadratic behavior.
13993 It would be nicer to record the parent's ranges before
13994 traversing its children, simply overriding whatever you find
13995 there. But since we don't even decide whether to create a
13996 block until after we've traversed its children, that's hard
13998 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
14000 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
14001 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
14004 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
14007 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
14009 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14010 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14011 CORE_ADDR pc
, baseaddr
;
14012 struct attribute
*attr
;
14013 struct call_site
*call_site
, call_site_local
;
14016 struct die_info
*child_die
;
14018 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14020 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
14023 /* This was a pre-DWARF-5 GNU extension alias
14024 for DW_AT_call_return_pc. */
14025 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14029 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
14030 "DIE %s [in module %s]"),
14031 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14034 pc
= attr_value_as_address (attr
) + baseaddr
;
14035 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
14037 if (cu
->call_site_htab
== NULL
)
14038 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
14039 NULL
, &objfile
->objfile_obstack
,
14040 hashtab_obstack_allocate
, NULL
);
14041 call_site_local
.pc
= pc
;
14042 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
14045 complaint (_("Duplicate PC %s for DW_TAG_call_site "
14046 "DIE %s [in module %s]"),
14047 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
14048 objfile_name (objfile
));
14052 /* Count parameters at the caller. */
14055 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
14056 child_die
= sibling_die (child_die
))
14058 if (child_die
->tag
!= DW_TAG_call_site_parameter
14059 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14061 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14062 "DW_TAG_call_site child DIE %s [in module %s]"),
14063 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14064 objfile_name (objfile
));
14072 = ((struct call_site
*)
14073 obstack_alloc (&objfile
->objfile_obstack
,
14074 sizeof (*call_site
)
14075 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14077 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14078 call_site
->pc
= pc
;
14080 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14081 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14083 struct die_info
*func_die
;
14085 /* Skip also over DW_TAG_inlined_subroutine. */
14086 for (func_die
= die
->parent
;
14087 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14088 && func_die
->tag
!= DW_TAG_subroutine_type
;
14089 func_die
= func_die
->parent
);
14091 /* DW_AT_call_all_calls is a superset
14092 of DW_AT_call_all_tail_calls. */
14094 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14095 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14096 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14097 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14099 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14100 not complete. But keep CALL_SITE for look ups via call_site_htab,
14101 both the initial caller containing the real return address PC and
14102 the final callee containing the current PC of a chain of tail
14103 calls do not need to have the tail call list complete. But any
14104 function candidate for a virtual tail call frame searched via
14105 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14106 determined unambiguously. */
14110 struct type
*func_type
= NULL
;
14113 func_type
= get_die_type (func_die
, cu
);
14114 if (func_type
!= NULL
)
14116 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14118 /* Enlist this call site to the function. */
14119 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14120 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14123 complaint (_("Cannot find function owning DW_TAG_call_site "
14124 "DIE %s [in module %s]"),
14125 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14129 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14131 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14133 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14136 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14137 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14139 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14140 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14141 /* Keep NULL DWARF_BLOCK. */;
14142 else if (attr_form_is_block (attr
))
14144 struct dwarf2_locexpr_baton
*dlbaton
;
14146 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14147 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14148 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14149 dlbaton
->per_cu
= cu
->per_cu
;
14151 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14153 else if (attr_form_is_ref (attr
))
14155 struct dwarf2_cu
*target_cu
= cu
;
14156 struct die_info
*target_die
;
14158 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14159 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14160 if (die_is_declaration (target_die
, target_cu
))
14162 const char *target_physname
;
14164 /* Prefer the mangled name; otherwise compute the demangled one. */
14165 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14166 if (target_physname
== NULL
)
14167 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14168 if (target_physname
== NULL
)
14169 complaint (_("DW_AT_call_target target DIE has invalid "
14170 "physname, for referencing DIE %s [in module %s]"),
14171 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14173 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14179 /* DW_AT_entry_pc should be preferred. */
14180 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14181 <= PC_BOUNDS_INVALID
)
14182 complaint (_("DW_AT_call_target target DIE has invalid "
14183 "low pc, for referencing DIE %s [in module %s]"),
14184 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14187 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14188 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14193 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14194 "block nor reference, for DIE %s [in module %s]"),
14195 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14197 call_site
->per_cu
= cu
->per_cu
;
14199 for (child_die
= die
->child
;
14200 child_die
&& child_die
->tag
;
14201 child_die
= sibling_die (child_die
))
14203 struct call_site_parameter
*parameter
;
14204 struct attribute
*loc
, *origin
;
14206 if (child_die
->tag
!= DW_TAG_call_site_parameter
14207 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14209 /* Already printed the complaint above. */
14213 gdb_assert (call_site
->parameter_count
< nparams
);
14214 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14216 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14217 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14218 register is contained in DW_AT_call_value. */
14220 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14221 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14222 if (origin
== NULL
)
14224 /* This was a pre-DWARF-5 GNU extension alias
14225 for DW_AT_call_parameter. */
14226 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14228 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14230 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14232 sect_offset sect_off
14233 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14234 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14236 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14237 binding can be done only inside one CU. Such referenced DIE
14238 therefore cannot be even moved to DW_TAG_partial_unit. */
14239 complaint (_("DW_AT_call_parameter offset is not in CU for "
14240 "DW_TAG_call_site child DIE %s [in module %s]"),
14241 sect_offset_str (child_die
->sect_off
),
14242 objfile_name (objfile
));
14245 parameter
->u
.param_cu_off
14246 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14248 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14250 complaint (_("No DW_FORM_block* DW_AT_location for "
14251 "DW_TAG_call_site child DIE %s [in module %s]"),
14252 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14257 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14258 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14259 if (parameter
->u
.dwarf_reg
!= -1)
14260 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14261 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14262 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14263 ¶meter
->u
.fb_offset
))
14264 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14267 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14268 "for DW_FORM_block* DW_AT_location is supported for "
14269 "DW_TAG_call_site child DIE %s "
14271 sect_offset_str (child_die
->sect_off
),
14272 objfile_name (objfile
));
14277 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14279 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14280 if (!attr_form_is_block (attr
))
14282 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14283 "DW_TAG_call_site child DIE %s [in module %s]"),
14284 sect_offset_str (child_die
->sect_off
),
14285 objfile_name (objfile
));
14288 parameter
->value
= DW_BLOCK (attr
)->data
;
14289 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14291 /* Parameters are not pre-cleared by memset above. */
14292 parameter
->data_value
= NULL
;
14293 parameter
->data_value_size
= 0;
14294 call_site
->parameter_count
++;
14296 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14298 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14299 if (attr
!= nullptr)
14301 if (!attr_form_is_block (attr
))
14302 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14303 "DW_TAG_call_site child DIE %s [in module %s]"),
14304 sect_offset_str (child_die
->sect_off
),
14305 objfile_name (objfile
));
14308 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14309 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14315 /* Helper function for read_variable. If DIE represents a virtual
14316 table, then return the type of the concrete object that is
14317 associated with the virtual table. Otherwise, return NULL. */
14319 static struct type
*
14320 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14322 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14326 /* Find the type DIE. */
14327 struct die_info
*type_die
= NULL
;
14328 struct dwarf2_cu
*type_cu
= cu
;
14330 if (attr_form_is_ref (attr
))
14331 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14332 if (type_die
== NULL
)
14335 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14337 return die_containing_type (type_die
, type_cu
);
14340 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14343 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14345 struct rust_vtable_symbol
*storage
= NULL
;
14347 if (cu
->language
== language_rust
)
14349 struct type
*containing_type
= rust_containing_type (die
, cu
);
14351 if (containing_type
!= NULL
)
14353 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14355 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14356 initialize_objfile_symbol (storage
);
14357 storage
->concrete_type
= containing_type
;
14358 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14362 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14363 struct attribute
*abstract_origin
14364 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14365 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14366 if (res
== NULL
&& loc
&& abstract_origin
)
14368 /* We have a variable without a name, but with a location and an abstract
14369 origin. This may be a concrete instance of an abstract variable
14370 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14372 struct dwarf2_cu
*origin_cu
= cu
;
14373 struct die_info
*origin_die
14374 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14375 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14376 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14380 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14381 reading .debug_rnglists.
14382 Callback's type should be:
14383 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14384 Return true if the attributes are present and valid, otherwise,
14387 template <typename Callback
>
14389 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14390 Callback
&&callback
)
14392 struct dwarf2_per_objfile
*dwarf2_per_objfile
14393 = cu
->per_cu
->dwarf2_per_objfile
;
14394 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14395 bfd
*obfd
= objfile
->obfd
;
14396 /* Base address selection entry. */
14399 const gdb_byte
*buffer
;
14400 CORE_ADDR baseaddr
;
14401 bool overflow
= false;
14403 found_base
= cu
->base_known
;
14404 base
= cu
->base_address
;
14406 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14407 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14409 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14413 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14415 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14419 /* Initialize it due to a false compiler warning. */
14420 CORE_ADDR range_beginning
= 0, range_end
= 0;
14421 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14422 + dwarf2_per_objfile
->rnglists
.size
);
14423 unsigned int bytes_read
;
14425 if (buffer
== buf_end
)
14430 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14433 case DW_RLE_end_of_list
:
14435 case DW_RLE_base_address
:
14436 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14441 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14443 buffer
+= bytes_read
;
14445 case DW_RLE_start_length
:
14446 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14451 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14452 buffer
+= bytes_read
;
14453 range_end
= (range_beginning
14454 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14455 buffer
+= bytes_read
;
14456 if (buffer
> buf_end
)
14462 case DW_RLE_offset_pair
:
14463 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14464 buffer
+= bytes_read
;
14465 if (buffer
> buf_end
)
14470 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14471 buffer
+= bytes_read
;
14472 if (buffer
> buf_end
)
14478 case DW_RLE_start_end
:
14479 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14484 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14485 buffer
+= bytes_read
;
14486 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14487 buffer
+= bytes_read
;
14490 complaint (_("Invalid .debug_rnglists data (no base address)"));
14493 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14495 if (rlet
== DW_RLE_base_address
)
14500 /* We have no valid base address for the ranges
14502 complaint (_("Invalid .debug_rnglists data (no base address)"));
14506 if (range_beginning
> range_end
)
14508 /* Inverted range entries are invalid. */
14509 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14513 /* Empty range entries have no effect. */
14514 if (range_beginning
== range_end
)
14517 range_beginning
+= base
;
14520 /* A not-uncommon case of bad debug info.
14521 Don't pollute the addrmap with bad data. */
14522 if (range_beginning
+ baseaddr
== 0
14523 && !dwarf2_per_objfile
->has_section_at_zero
)
14525 complaint (_(".debug_rnglists entry has start address of zero"
14526 " [in module %s]"), objfile_name (objfile
));
14530 callback (range_beginning
, range_end
);
14535 complaint (_("Offset %d is not terminated "
14536 "for DW_AT_ranges attribute"),
14544 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14545 Callback's type should be:
14546 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14547 Return 1 if the attributes are present and valid, otherwise, return 0. */
14549 template <typename Callback
>
14551 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14552 Callback
&&callback
)
14554 struct dwarf2_per_objfile
*dwarf2_per_objfile
14555 = cu
->per_cu
->dwarf2_per_objfile
;
14556 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14557 struct comp_unit_head
*cu_header
= &cu
->header
;
14558 bfd
*obfd
= objfile
->obfd
;
14559 unsigned int addr_size
= cu_header
->addr_size
;
14560 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14561 /* Base address selection entry. */
14564 unsigned int dummy
;
14565 const gdb_byte
*buffer
;
14566 CORE_ADDR baseaddr
;
14568 if (cu_header
->version
>= 5)
14569 return dwarf2_rnglists_process (offset
, cu
, callback
);
14571 found_base
= cu
->base_known
;
14572 base
= cu
->base_address
;
14574 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14575 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14577 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14581 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14583 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14587 CORE_ADDR range_beginning
, range_end
;
14589 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14590 buffer
+= addr_size
;
14591 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14592 buffer
+= addr_size
;
14593 offset
+= 2 * addr_size
;
14595 /* An end of list marker is a pair of zero addresses. */
14596 if (range_beginning
== 0 && range_end
== 0)
14597 /* Found the end of list entry. */
14600 /* Each base address selection entry is a pair of 2 values.
14601 The first is the largest possible address, the second is
14602 the base address. Check for a base address here. */
14603 if ((range_beginning
& mask
) == mask
)
14605 /* If we found the largest possible address, then we already
14606 have the base address in range_end. */
14614 /* We have no valid base address for the ranges
14616 complaint (_("Invalid .debug_ranges data (no base address)"));
14620 if (range_beginning
> range_end
)
14622 /* Inverted range entries are invalid. */
14623 complaint (_("Invalid .debug_ranges data (inverted range)"));
14627 /* Empty range entries have no effect. */
14628 if (range_beginning
== range_end
)
14631 range_beginning
+= base
;
14634 /* A not-uncommon case of bad debug info.
14635 Don't pollute the addrmap with bad data. */
14636 if (range_beginning
+ baseaddr
== 0
14637 && !dwarf2_per_objfile
->has_section_at_zero
)
14639 complaint (_(".debug_ranges entry has start address of zero"
14640 " [in module %s]"), objfile_name (objfile
));
14644 callback (range_beginning
, range_end
);
14650 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14651 Return 1 if the attributes are present and valid, otherwise, return 0.
14652 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14655 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14656 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14657 struct partial_symtab
*ranges_pst
)
14659 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14660 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14661 const CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
14664 CORE_ADDR high
= 0;
14667 retval
= dwarf2_ranges_process (offset
, cu
,
14668 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14670 if (ranges_pst
!= NULL
)
14675 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14676 range_beginning
+ baseaddr
)
14678 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14679 range_end
+ baseaddr
)
14681 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14682 lowpc
, highpc
- 1, ranges_pst
);
14685 /* FIXME: This is recording everything as a low-high
14686 segment of consecutive addresses. We should have a
14687 data structure for discontiguous block ranges
14691 low
= range_beginning
;
14697 if (range_beginning
< low
)
14698 low
= range_beginning
;
14699 if (range_end
> high
)
14707 /* If the first entry is an end-of-list marker, the range
14708 describes an empty scope, i.e. no instructions. */
14714 *high_return
= high
;
14718 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14719 definition for the return value. *LOWPC and *HIGHPC are set iff
14720 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14722 static enum pc_bounds_kind
14723 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14724 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14725 struct partial_symtab
*pst
)
14727 struct dwarf2_per_objfile
*dwarf2_per_objfile
14728 = cu
->per_cu
->dwarf2_per_objfile
;
14729 struct attribute
*attr
;
14730 struct attribute
*attr_high
;
14732 CORE_ADDR high
= 0;
14733 enum pc_bounds_kind ret
;
14735 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14738 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14739 if (attr
!= nullptr)
14741 low
= attr_value_as_address (attr
);
14742 high
= attr_value_as_address (attr_high
);
14743 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14747 /* Found high w/o low attribute. */
14748 return PC_BOUNDS_INVALID
;
14750 /* Found consecutive range of addresses. */
14751 ret
= PC_BOUNDS_HIGH_LOW
;
14755 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14758 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14759 We take advantage of the fact that DW_AT_ranges does not appear
14760 in DW_TAG_compile_unit of DWO files. */
14761 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14762 unsigned int ranges_offset
= (DW_UNSND (attr
)
14763 + (need_ranges_base
14767 /* Value of the DW_AT_ranges attribute is the offset in the
14768 .debug_ranges section. */
14769 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14770 return PC_BOUNDS_INVALID
;
14771 /* Found discontinuous range of addresses. */
14772 ret
= PC_BOUNDS_RANGES
;
14775 return PC_BOUNDS_NOT_PRESENT
;
14778 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14780 return PC_BOUNDS_INVALID
;
14782 /* When using the GNU linker, .gnu.linkonce. sections are used to
14783 eliminate duplicate copies of functions and vtables and such.
14784 The linker will arbitrarily choose one and discard the others.
14785 The AT_*_pc values for such functions refer to local labels in
14786 these sections. If the section from that file was discarded, the
14787 labels are not in the output, so the relocs get a value of 0.
14788 If this is a discarded function, mark the pc bounds as invalid,
14789 so that GDB will ignore it. */
14790 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14791 return PC_BOUNDS_INVALID
;
14799 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14800 its low and high PC addresses. Do nothing if these addresses could not
14801 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14802 and HIGHPC to the high address if greater than HIGHPC. */
14805 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14806 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14807 struct dwarf2_cu
*cu
)
14809 CORE_ADDR low
, high
;
14810 struct die_info
*child
= die
->child
;
14812 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14814 *lowpc
= std::min (*lowpc
, low
);
14815 *highpc
= std::max (*highpc
, high
);
14818 /* If the language does not allow nested subprograms (either inside
14819 subprograms or lexical blocks), we're done. */
14820 if (cu
->language
!= language_ada
)
14823 /* Check all the children of the given DIE. If it contains nested
14824 subprograms, then check their pc bounds. Likewise, we need to
14825 check lexical blocks as well, as they may also contain subprogram
14827 while (child
&& child
->tag
)
14829 if (child
->tag
== DW_TAG_subprogram
14830 || child
->tag
== DW_TAG_lexical_block
)
14831 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14832 child
= sibling_die (child
);
14836 /* Get the low and high pc's represented by the scope DIE, and store
14837 them in *LOWPC and *HIGHPC. If the correct values can't be
14838 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14841 get_scope_pc_bounds (struct die_info
*die
,
14842 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14843 struct dwarf2_cu
*cu
)
14845 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14846 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14847 CORE_ADDR current_low
, current_high
;
14849 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14850 >= PC_BOUNDS_RANGES
)
14852 best_low
= current_low
;
14853 best_high
= current_high
;
14857 struct die_info
*child
= die
->child
;
14859 while (child
&& child
->tag
)
14861 switch (child
->tag
) {
14862 case DW_TAG_subprogram
:
14863 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14865 case DW_TAG_namespace
:
14866 case DW_TAG_module
:
14867 /* FIXME: carlton/2004-01-16: Should we do this for
14868 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14869 that current GCC's always emit the DIEs corresponding
14870 to definitions of methods of classes as children of a
14871 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14872 the DIEs giving the declarations, which could be
14873 anywhere). But I don't see any reason why the
14874 standards says that they have to be there. */
14875 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14877 if (current_low
!= ((CORE_ADDR
) -1))
14879 best_low
= std::min (best_low
, current_low
);
14880 best_high
= std::max (best_high
, current_high
);
14888 child
= sibling_die (child
);
14893 *highpc
= best_high
;
14896 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14900 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14901 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14904 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14905 struct attribute
*attr
;
14906 struct attribute
*attr_high
;
14908 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14911 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14912 if (attr
!= nullptr)
14914 CORE_ADDR low
= attr_value_as_address (attr
);
14915 CORE_ADDR high
= attr_value_as_address (attr_high
);
14917 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14920 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14921 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14922 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14926 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14927 if (attr
!= nullptr)
14929 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14930 We take advantage of the fact that DW_AT_ranges does not appear
14931 in DW_TAG_compile_unit of DWO files. */
14932 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14934 /* The value of the DW_AT_ranges attribute is the offset of the
14935 address range list in the .debug_ranges section. */
14936 unsigned long offset
= (DW_UNSND (attr
)
14937 + (need_ranges_base
? cu
->ranges_base
: 0));
14939 std::vector
<blockrange
> blockvec
;
14940 dwarf2_ranges_process (offset
, cu
,
14941 [&] (CORE_ADDR start
, CORE_ADDR end
)
14945 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14946 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14947 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14948 blockvec
.emplace_back (start
, end
);
14951 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14955 /* Check whether the producer field indicates either of GCC < 4.6, or the
14956 Intel C/C++ compiler, and cache the result in CU. */
14959 check_producer (struct dwarf2_cu
*cu
)
14963 if (cu
->producer
== NULL
)
14965 /* For unknown compilers expect their behavior is DWARF version
14968 GCC started to support .debug_types sections by -gdwarf-4 since
14969 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14970 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14971 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14972 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14974 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14976 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14977 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14979 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14981 cu
->producer_is_icc
= true;
14982 cu
->producer_is_icc_lt_14
= major
< 14;
14984 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14985 cu
->producer_is_codewarrior
= true;
14988 /* For other non-GCC compilers, expect their behavior is DWARF version
14992 cu
->checked_producer
= true;
14995 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14996 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14997 during 4.6.0 experimental. */
15000 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
15002 if (!cu
->checked_producer
)
15003 check_producer (cu
);
15005 return cu
->producer_is_gxx_lt_4_6
;
15009 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
15010 with incorrect is_stmt attributes. */
15013 producer_is_codewarrior (struct dwarf2_cu
*cu
)
15015 if (!cu
->checked_producer
)
15016 check_producer (cu
);
15018 return cu
->producer_is_codewarrior
;
15021 /* Return the default accessibility type if it is not overridden by
15022 DW_AT_accessibility. */
15024 static enum dwarf_access_attribute
15025 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
15027 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
15029 /* The default DWARF 2 accessibility for members is public, the default
15030 accessibility for inheritance is private. */
15032 if (die
->tag
!= DW_TAG_inheritance
)
15033 return DW_ACCESS_public
;
15035 return DW_ACCESS_private
;
15039 /* DWARF 3+ defines the default accessibility a different way. The same
15040 rules apply now for DW_TAG_inheritance as for the members and it only
15041 depends on the container kind. */
15043 if (die
->parent
->tag
== DW_TAG_class_type
)
15044 return DW_ACCESS_private
;
15046 return DW_ACCESS_public
;
15050 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
15051 offset. If the attribute was not found return 0, otherwise return
15052 1. If it was found but could not properly be handled, set *OFFSET
15056 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15059 struct attribute
*attr
;
15061 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15066 /* Note that we do not check for a section offset first here.
15067 This is because DW_AT_data_member_location is new in DWARF 4,
15068 so if we see it, we can assume that a constant form is really
15069 a constant and not a section offset. */
15070 if (attr_form_is_constant (attr
))
15071 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15072 else if (attr_form_is_section_offset (attr
))
15073 dwarf2_complex_location_expr_complaint ();
15074 else if (attr_form_is_block (attr
))
15075 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15077 dwarf2_complex_location_expr_complaint ();
15085 /* Add an aggregate field to the field list. */
15088 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15089 struct dwarf2_cu
*cu
)
15091 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15092 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15093 struct nextfield
*new_field
;
15094 struct attribute
*attr
;
15096 const char *fieldname
= "";
15098 if (die
->tag
== DW_TAG_inheritance
)
15100 fip
->baseclasses
.emplace_back ();
15101 new_field
= &fip
->baseclasses
.back ();
15105 fip
->fields
.emplace_back ();
15106 new_field
= &fip
->fields
.back ();
15111 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15112 if (attr
!= nullptr)
15113 new_field
->accessibility
= DW_UNSND (attr
);
15115 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15116 if (new_field
->accessibility
!= DW_ACCESS_public
)
15117 fip
->non_public_fields
= 1;
15119 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15120 if (attr
!= nullptr)
15121 new_field
->virtuality
= DW_UNSND (attr
);
15123 new_field
->virtuality
= DW_VIRTUALITY_none
;
15125 fp
= &new_field
->field
;
15127 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15131 /* Data member other than a C++ static data member. */
15133 /* Get type of field. */
15134 fp
->type
= die_type (die
, cu
);
15136 SET_FIELD_BITPOS (*fp
, 0);
15138 /* Get bit size of field (zero if none). */
15139 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15140 if (attr
!= nullptr)
15142 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15146 FIELD_BITSIZE (*fp
) = 0;
15149 /* Get bit offset of field. */
15150 if (handle_data_member_location (die
, cu
, &offset
))
15151 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15152 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15153 if (attr
!= nullptr)
15155 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15157 /* For big endian bits, the DW_AT_bit_offset gives the
15158 additional bit offset from the MSB of the containing
15159 anonymous object to the MSB of the field. We don't
15160 have to do anything special since we don't need to
15161 know the size of the anonymous object. */
15162 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15166 /* For little endian bits, compute the bit offset to the
15167 MSB of the anonymous object, subtract off the number of
15168 bits from the MSB of the field to the MSB of the
15169 object, and then subtract off the number of bits of
15170 the field itself. The result is the bit offset of
15171 the LSB of the field. */
15172 int anonymous_size
;
15173 int bit_offset
= DW_UNSND (attr
);
15175 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15176 if (attr
!= nullptr)
15178 /* The size of the anonymous object containing
15179 the bit field is explicit, so use the
15180 indicated size (in bytes). */
15181 anonymous_size
= DW_UNSND (attr
);
15185 /* The size of the anonymous object containing
15186 the bit field must be inferred from the type
15187 attribute of the data member containing the
15189 anonymous_size
= TYPE_LENGTH (fp
->type
);
15191 SET_FIELD_BITPOS (*fp
,
15192 (FIELD_BITPOS (*fp
)
15193 + anonymous_size
* bits_per_byte
15194 - bit_offset
- FIELD_BITSIZE (*fp
)));
15197 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15199 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15200 + dwarf2_get_attr_constant_value (attr
, 0)));
15202 /* Get name of field. */
15203 fieldname
= dwarf2_name (die
, cu
);
15204 if (fieldname
== NULL
)
15207 /* The name is already allocated along with this objfile, so we don't
15208 need to duplicate it for the type. */
15209 fp
->name
= fieldname
;
15211 /* Change accessibility for artificial fields (e.g. virtual table
15212 pointer or virtual base class pointer) to private. */
15213 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15215 FIELD_ARTIFICIAL (*fp
) = 1;
15216 new_field
->accessibility
= DW_ACCESS_private
;
15217 fip
->non_public_fields
= 1;
15220 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15222 /* C++ static member. */
15224 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15225 is a declaration, but all versions of G++ as of this writing
15226 (so through at least 3.2.1) incorrectly generate
15227 DW_TAG_variable tags. */
15229 const char *physname
;
15231 /* Get name of field. */
15232 fieldname
= dwarf2_name (die
, cu
);
15233 if (fieldname
== NULL
)
15236 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15238 /* Only create a symbol if this is an external value.
15239 new_symbol checks this and puts the value in the global symbol
15240 table, which we want. If it is not external, new_symbol
15241 will try to put the value in cu->list_in_scope which is wrong. */
15242 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15244 /* A static const member, not much different than an enum as far as
15245 we're concerned, except that we can support more types. */
15246 new_symbol (die
, NULL
, cu
);
15249 /* Get physical name. */
15250 physname
= dwarf2_physname (fieldname
, die
, cu
);
15252 /* The name is already allocated along with this objfile, so we don't
15253 need to duplicate it for the type. */
15254 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15255 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15256 FIELD_NAME (*fp
) = fieldname
;
15258 else if (die
->tag
== DW_TAG_inheritance
)
15262 /* C++ base class field. */
15263 if (handle_data_member_location (die
, cu
, &offset
))
15264 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15265 FIELD_BITSIZE (*fp
) = 0;
15266 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15267 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15269 else if (die
->tag
== DW_TAG_variant_part
)
15271 /* process_structure_scope will treat this DIE as a union. */
15272 process_structure_scope (die
, cu
);
15274 /* The variant part is relative to the start of the enclosing
15276 SET_FIELD_BITPOS (*fp
, 0);
15277 fp
->type
= get_die_type (die
, cu
);
15278 fp
->artificial
= 1;
15279 fp
->name
= "<<variant>>";
15281 /* Normally a DW_TAG_variant_part won't have a size, but our
15282 representation requires one, so set it to the maximum of the
15283 child sizes, being sure to account for the offset at which
15284 each child is seen. */
15285 if (TYPE_LENGTH (fp
->type
) == 0)
15288 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15290 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15291 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15295 TYPE_LENGTH (fp
->type
) = max
;
15299 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15302 /* Can the type given by DIE define another type? */
15305 type_can_define_types (const struct die_info
*die
)
15309 case DW_TAG_typedef
:
15310 case DW_TAG_class_type
:
15311 case DW_TAG_structure_type
:
15312 case DW_TAG_union_type
:
15313 case DW_TAG_enumeration_type
:
15321 /* Add a type definition defined in the scope of the FIP's class. */
15324 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15325 struct dwarf2_cu
*cu
)
15327 struct decl_field fp
;
15328 memset (&fp
, 0, sizeof (fp
));
15330 gdb_assert (type_can_define_types (die
));
15332 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15333 fp
.name
= dwarf2_name (die
, cu
);
15334 fp
.type
= read_type_die (die
, cu
);
15336 /* Save accessibility. */
15337 enum dwarf_access_attribute accessibility
;
15338 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15340 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15342 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15343 switch (accessibility
)
15345 case DW_ACCESS_public
:
15346 /* The assumed value if neither private nor protected. */
15348 case DW_ACCESS_private
:
15351 case DW_ACCESS_protected
:
15352 fp
.is_protected
= 1;
15355 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15358 if (die
->tag
== DW_TAG_typedef
)
15359 fip
->typedef_field_list
.push_back (fp
);
15361 fip
->nested_types_list
.push_back (fp
);
15364 /* Create the vector of fields, and attach it to the type. */
15367 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15368 struct dwarf2_cu
*cu
)
15370 int nfields
= fip
->nfields
;
15372 /* Record the field count, allocate space for the array of fields,
15373 and create blank accessibility bitfields if necessary. */
15374 TYPE_NFIELDS (type
) = nfields
;
15375 TYPE_FIELDS (type
) = (struct field
*)
15376 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15378 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15380 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15382 TYPE_FIELD_PRIVATE_BITS (type
) =
15383 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15384 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15386 TYPE_FIELD_PROTECTED_BITS (type
) =
15387 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15388 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15390 TYPE_FIELD_IGNORE_BITS (type
) =
15391 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15392 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15395 /* If the type has baseclasses, allocate and clear a bit vector for
15396 TYPE_FIELD_VIRTUAL_BITS. */
15397 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15399 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15400 unsigned char *pointer
;
15402 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15403 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15404 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15405 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15406 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15409 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15411 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15413 for (int index
= 0; index
< nfields
; ++index
)
15415 struct nextfield
&field
= fip
->fields
[index
];
15417 if (field
.variant
.is_discriminant
)
15418 di
->discriminant_index
= index
;
15419 else if (field
.variant
.default_branch
)
15420 di
->default_index
= index
;
15422 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15426 /* Copy the saved-up fields into the field vector. */
15427 for (int i
= 0; i
< nfields
; ++i
)
15429 struct nextfield
&field
15430 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15431 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15433 TYPE_FIELD (type
, i
) = field
.field
;
15434 switch (field
.accessibility
)
15436 case DW_ACCESS_private
:
15437 if (cu
->language
!= language_ada
)
15438 SET_TYPE_FIELD_PRIVATE (type
, i
);
15441 case DW_ACCESS_protected
:
15442 if (cu
->language
!= language_ada
)
15443 SET_TYPE_FIELD_PROTECTED (type
, i
);
15446 case DW_ACCESS_public
:
15450 /* Unknown accessibility. Complain and treat it as public. */
15452 complaint (_("unsupported accessibility %d"),
15453 field
.accessibility
);
15457 if (i
< fip
->baseclasses
.size ())
15459 switch (field
.virtuality
)
15461 case DW_VIRTUALITY_virtual
:
15462 case DW_VIRTUALITY_pure_virtual
:
15463 if (cu
->language
== language_ada
)
15464 error (_("unexpected virtuality in component of Ada type"));
15465 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15472 /* Return true if this member function is a constructor, false
15476 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15478 const char *fieldname
;
15479 const char *type_name
;
15482 if (die
->parent
== NULL
)
15485 if (die
->parent
->tag
!= DW_TAG_structure_type
15486 && die
->parent
->tag
!= DW_TAG_union_type
15487 && die
->parent
->tag
!= DW_TAG_class_type
)
15490 fieldname
= dwarf2_name (die
, cu
);
15491 type_name
= dwarf2_name (die
->parent
, cu
);
15492 if (fieldname
== NULL
|| type_name
== NULL
)
15495 len
= strlen (fieldname
);
15496 return (strncmp (fieldname
, type_name
, len
) == 0
15497 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15500 /* Check if the given VALUE is a recognized enum
15501 dwarf_defaulted_attribute constant according to DWARF5 spec,
15505 is_valid_DW_AT_defaulted (ULONGEST value
)
15509 case DW_DEFAULTED_no
:
15510 case DW_DEFAULTED_in_class
:
15511 case DW_DEFAULTED_out_of_class
:
15515 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15519 /* Add a member function to the proper fieldlist. */
15522 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15523 struct type
*type
, struct dwarf2_cu
*cu
)
15525 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15526 struct attribute
*attr
;
15528 struct fnfieldlist
*flp
= nullptr;
15529 struct fn_field
*fnp
;
15530 const char *fieldname
;
15531 struct type
*this_type
;
15532 enum dwarf_access_attribute accessibility
;
15534 if (cu
->language
== language_ada
)
15535 error (_("unexpected member function in Ada type"));
15537 /* Get name of member function. */
15538 fieldname
= dwarf2_name (die
, cu
);
15539 if (fieldname
== NULL
)
15542 /* Look up member function name in fieldlist. */
15543 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15545 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15547 flp
= &fip
->fnfieldlists
[i
];
15552 /* Create a new fnfieldlist if necessary. */
15553 if (flp
== nullptr)
15555 fip
->fnfieldlists
.emplace_back ();
15556 flp
= &fip
->fnfieldlists
.back ();
15557 flp
->name
= fieldname
;
15558 i
= fip
->fnfieldlists
.size () - 1;
15561 /* Create a new member function field and add it to the vector of
15563 flp
->fnfields
.emplace_back ();
15564 fnp
= &flp
->fnfields
.back ();
15566 /* Delay processing of the physname until later. */
15567 if (cu
->language
== language_cplus
)
15568 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15572 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15573 fnp
->physname
= physname
? physname
: "";
15576 fnp
->type
= alloc_type (objfile
);
15577 this_type
= read_type_die (die
, cu
);
15578 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15580 int nparams
= TYPE_NFIELDS (this_type
);
15582 /* TYPE is the domain of this method, and THIS_TYPE is the type
15583 of the method itself (TYPE_CODE_METHOD). */
15584 smash_to_method_type (fnp
->type
, type
,
15585 TYPE_TARGET_TYPE (this_type
),
15586 TYPE_FIELDS (this_type
),
15587 TYPE_NFIELDS (this_type
),
15588 TYPE_VARARGS (this_type
));
15590 /* Handle static member functions.
15591 Dwarf2 has no clean way to discern C++ static and non-static
15592 member functions. G++ helps GDB by marking the first
15593 parameter for non-static member functions (which is the this
15594 pointer) as artificial. We obtain this information from
15595 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15596 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15597 fnp
->voffset
= VOFFSET_STATIC
;
15600 complaint (_("member function type missing for '%s'"),
15601 dwarf2_full_name (fieldname
, die
, cu
));
15603 /* Get fcontext from DW_AT_containing_type if present. */
15604 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15605 fnp
->fcontext
= die_containing_type (die
, cu
);
15607 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15608 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15610 /* Get accessibility. */
15611 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15612 if (attr
!= nullptr)
15613 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15615 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15616 switch (accessibility
)
15618 case DW_ACCESS_private
:
15619 fnp
->is_private
= 1;
15621 case DW_ACCESS_protected
:
15622 fnp
->is_protected
= 1;
15626 /* Check for artificial methods. */
15627 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15628 if (attr
&& DW_UNSND (attr
) != 0)
15629 fnp
->is_artificial
= 1;
15631 /* Check for defaulted methods. */
15632 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15633 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15634 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15636 /* Check for deleted methods. */
15637 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15638 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15639 fnp
->is_deleted
= 1;
15641 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15643 /* Get index in virtual function table if it is a virtual member
15644 function. For older versions of GCC, this is an offset in the
15645 appropriate virtual table, as specified by DW_AT_containing_type.
15646 For everyone else, it is an expression to be evaluated relative
15647 to the object address. */
15649 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15650 if (attr
!= nullptr)
15652 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15654 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15656 /* Old-style GCC. */
15657 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15659 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15660 || (DW_BLOCK (attr
)->size
> 1
15661 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15662 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15664 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15665 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15666 dwarf2_complex_location_expr_complaint ();
15668 fnp
->voffset
/= cu
->header
.addr_size
;
15672 dwarf2_complex_location_expr_complaint ();
15674 if (!fnp
->fcontext
)
15676 /* If there is no `this' field and no DW_AT_containing_type,
15677 we cannot actually find a base class context for the
15679 if (TYPE_NFIELDS (this_type
) == 0
15680 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15682 complaint (_("cannot determine context for virtual member "
15683 "function \"%s\" (offset %s)"),
15684 fieldname
, sect_offset_str (die
->sect_off
));
15689 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15693 else if (attr_form_is_section_offset (attr
))
15695 dwarf2_complex_location_expr_complaint ();
15699 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15705 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15706 if (attr
&& DW_UNSND (attr
))
15708 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15709 complaint (_("Member function \"%s\" (offset %s) is virtual "
15710 "but the vtable offset is not specified"),
15711 fieldname
, sect_offset_str (die
->sect_off
));
15712 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15713 TYPE_CPLUS_DYNAMIC (type
) = 1;
15718 /* Create the vector of member function fields, and attach it to the type. */
15721 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15722 struct dwarf2_cu
*cu
)
15724 if (cu
->language
== language_ada
)
15725 error (_("unexpected member functions in Ada type"));
15727 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15728 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15730 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15732 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15734 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15735 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15737 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15738 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15739 fn_flp
->fn_fields
= (struct fn_field
*)
15740 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15742 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15743 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15746 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15749 /* Returns non-zero if NAME is the name of a vtable member in CU's
15750 language, zero otherwise. */
15752 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15754 static const char vptr
[] = "_vptr";
15756 /* Look for the C++ form of the vtable. */
15757 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15763 /* GCC outputs unnamed structures that are really pointers to member
15764 functions, with the ABI-specified layout. If TYPE describes
15765 such a structure, smash it into a member function type.
15767 GCC shouldn't do this; it should just output pointer to member DIEs.
15768 This is GCC PR debug/28767. */
15771 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15773 struct type
*pfn_type
, *self_type
, *new_type
;
15775 /* Check for a structure with no name and two children. */
15776 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15779 /* Check for __pfn and __delta members. */
15780 if (TYPE_FIELD_NAME (type
, 0) == NULL
15781 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15782 || TYPE_FIELD_NAME (type
, 1) == NULL
15783 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15786 /* Find the type of the method. */
15787 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15788 if (pfn_type
== NULL
15789 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15790 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15793 /* Look for the "this" argument. */
15794 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15795 if (TYPE_NFIELDS (pfn_type
) == 0
15796 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15797 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15800 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15801 new_type
= alloc_type (objfile
);
15802 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15803 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15804 TYPE_VARARGS (pfn_type
));
15805 smash_to_methodptr_type (type
, new_type
);
15808 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15809 appropriate error checking and issuing complaints if there is a
15813 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15815 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15817 if (attr
== nullptr)
15820 if (!attr_form_is_constant (attr
))
15822 complaint (_("DW_AT_alignment must have constant form"
15823 " - DIE at %s [in module %s]"),
15824 sect_offset_str (die
->sect_off
),
15825 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15830 if (attr
->form
== DW_FORM_sdata
)
15832 LONGEST val
= DW_SND (attr
);
15835 complaint (_("DW_AT_alignment value must not be negative"
15836 " - DIE at %s [in module %s]"),
15837 sect_offset_str (die
->sect_off
),
15838 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15844 align
= DW_UNSND (attr
);
15848 complaint (_("DW_AT_alignment value must not be zero"
15849 " - DIE at %s [in module %s]"),
15850 sect_offset_str (die
->sect_off
),
15851 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15854 if ((align
& (align
- 1)) != 0)
15856 complaint (_("DW_AT_alignment value must be a power of 2"
15857 " - DIE at %s [in module %s]"),
15858 sect_offset_str (die
->sect_off
),
15859 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15866 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15867 the alignment for TYPE. */
15870 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15873 if (!set_type_align (type
, get_alignment (cu
, die
)))
15874 complaint (_("DW_AT_alignment value too large"
15875 " - DIE at %s [in module %s]"),
15876 sect_offset_str (die
->sect_off
),
15877 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15880 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15881 constant for a type, according to DWARF5 spec, Table 5.5. */
15884 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15889 case DW_CC_pass_by_reference
:
15890 case DW_CC_pass_by_value
:
15894 complaint (_("unrecognized DW_AT_calling_convention value "
15895 "(%s) for a type"), pulongest (value
));
15900 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15901 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15902 also according to GNU-specific values (see include/dwarf2.h). */
15905 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15910 case DW_CC_program
:
15914 case DW_CC_GNU_renesas_sh
:
15915 case DW_CC_GNU_borland_fastcall_i386
:
15916 case DW_CC_GDB_IBM_OpenCL
:
15920 complaint (_("unrecognized DW_AT_calling_convention value "
15921 "(%s) for a subroutine"), pulongest (value
));
15926 /* Called when we find the DIE that starts a structure or union scope
15927 (definition) to create a type for the structure or union. Fill in
15928 the type's name and general properties; the members will not be
15929 processed until process_structure_scope. A symbol table entry for
15930 the type will also not be done until process_structure_scope (assuming
15931 the type has a name).
15933 NOTE: we need to call these functions regardless of whether or not the
15934 DIE has a DW_AT_name attribute, since it might be an anonymous
15935 structure or union. This gets the type entered into our set of
15936 user defined types. */
15938 static struct type
*
15939 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15941 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15943 struct attribute
*attr
;
15946 /* If the definition of this type lives in .debug_types, read that type.
15947 Don't follow DW_AT_specification though, that will take us back up
15948 the chain and we want to go down. */
15949 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15950 if (attr
!= nullptr)
15952 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15954 /* The type's CU may not be the same as CU.
15955 Ensure TYPE is recorded with CU in die_type_hash. */
15956 return set_die_type (die
, type
, cu
);
15959 type
= alloc_type (objfile
);
15960 INIT_CPLUS_SPECIFIC (type
);
15962 name
= dwarf2_name (die
, cu
);
15965 if (cu
->language
== language_cplus
15966 || cu
->language
== language_d
15967 || cu
->language
== language_rust
)
15969 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15971 /* dwarf2_full_name might have already finished building the DIE's
15972 type. If so, there is no need to continue. */
15973 if (get_die_type (die
, cu
) != NULL
)
15974 return get_die_type (die
, cu
);
15976 TYPE_NAME (type
) = full_name
;
15980 /* The name is already allocated along with this objfile, so
15981 we don't need to duplicate it for the type. */
15982 TYPE_NAME (type
) = name
;
15986 if (die
->tag
== DW_TAG_structure_type
)
15988 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15990 else if (die
->tag
== DW_TAG_union_type
)
15992 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15994 else if (die
->tag
== DW_TAG_variant_part
)
15996 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15997 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
16001 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
16004 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
16005 TYPE_DECLARED_CLASS (type
) = 1;
16007 /* Store the calling convention in the type if it's available in
16008 the die. Otherwise the calling convention remains set to
16009 the default value DW_CC_normal. */
16010 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
16011 if (attr
!= nullptr
16012 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
16014 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16015 TYPE_CPLUS_CALLING_CONVENTION (type
)
16016 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
16019 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16020 if (attr
!= nullptr)
16022 if (attr_form_is_constant (attr
))
16023 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16026 /* For the moment, dynamic type sizes are not supported
16027 by GDB's struct type. The actual size is determined
16028 on-demand when resolving the type of a given object,
16029 so set the type's length to zero for now. Otherwise,
16030 we record an expression as the length, and that expression
16031 could lead to a very large value, which could eventually
16032 lead to us trying to allocate that much memory when creating
16033 a value of that type. */
16034 TYPE_LENGTH (type
) = 0;
16039 TYPE_LENGTH (type
) = 0;
16042 maybe_set_alignment (cu
, die
, type
);
16044 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
16046 /* ICC<14 does not output the required DW_AT_declaration on
16047 incomplete types, but gives them a size of zero. */
16048 TYPE_STUB (type
) = 1;
16051 TYPE_STUB_SUPPORTED (type
) = 1;
16053 if (die_is_declaration (die
, cu
))
16054 TYPE_STUB (type
) = 1;
16055 else if (attr
== NULL
&& die
->child
== NULL
16056 && producer_is_realview (cu
->producer
))
16057 /* RealView does not output the required DW_AT_declaration
16058 on incomplete types. */
16059 TYPE_STUB (type
) = 1;
16061 /* We need to add the type field to the die immediately so we don't
16062 infinitely recurse when dealing with pointers to the structure
16063 type within the structure itself. */
16064 set_die_type (die
, type
, cu
);
16066 /* set_die_type should be already done. */
16067 set_descriptive_type (type
, die
, cu
);
16072 /* A helper for process_structure_scope that handles a single member
16076 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16077 struct field_info
*fi
,
16078 std::vector
<struct symbol
*> *template_args
,
16079 struct dwarf2_cu
*cu
)
16081 if (child_die
->tag
== DW_TAG_member
16082 || child_die
->tag
== DW_TAG_variable
16083 || child_die
->tag
== DW_TAG_variant_part
)
16085 /* NOTE: carlton/2002-11-05: A C++ static data member
16086 should be a DW_TAG_member that is a declaration, but
16087 all versions of G++ as of this writing (so through at
16088 least 3.2.1) incorrectly generate DW_TAG_variable
16089 tags for them instead. */
16090 dwarf2_add_field (fi
, child_die
, cu
);
16092 else if (child_die
->tag
== DW_TAG_subprogram
)
16094 /* Rust doesn't have member functions in the C++ sense.
16095 However, it does emit ordinary functions as children
16096 of a struct DIE. */
16097 if (cu
->language
== language_rust
)
16098 read_func_scope (child_die
, cu
);
16101 /* C++ member function. */
16102 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16105 else if (child_die
->tag
== DW_TAG_inheritance
)
16107 /* C++ base class field. */
16108 dwarf2_add_field (fi
, child_die
, cu
);
16110 else if (type_can_define_types (child_die
))
16111 dwarf2_add_type_defn (fi
, child_die
, cu
);
16112 else if (child_die
->tag
== DW_TAG_template_type_param
16113 || child_die
->tag
== DW_TAG_template_value_param
)
16115 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16118 template_args
->push_back (arg
);
16120 else if (child_die
->tag
== DW_TAG_variant
)
16122 /* In a variant we want to get the discriminant and also add a
16123 field for our sole member child. */
16124 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16126 for (die_info
*variant_child
= child_die
->child
;
16127 variant_child
!= NULL
;
16128 variant_child
= sibling_die (variant_child
))
16130 if (variant_child
->tag
== DW_TAG_member
)
16132 handle_struct_member_die (variant_child
, type
, fi
,
16133 template_args
, cu
);
16134 /* Only handle the one. */
16139 /* We don't handle this but we might as well report it if we see
16141 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16142 complaint (_("DW_AT_discr_list is not supported yet"
16143 " - DIE at %s [in module %s]"),
16144 sect_offset_str (child_die
->sect_off
),
16145 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16147 /* The first field was just added, so we can stash the
16148 discriminant there. */
16149 gdb_assert (!fi
->fields
.empty ());
16151 fi
->fields
.back ().variant
.default_branch
= true;
16153 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16157 /* Finish creating a structure or union type, including filling in
16158 its members and creating a symbol for it. */
16161 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16163 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16164 struct die_info
*child_die
;
16167 type
= get_die_type (die
, cu
);
16169 type
= read_structure_type (die
, cu
);
16171 /* When reading a DW_TAG_variant_part, we need to notice when we
16172 read the discriminant member, so we can record it later in the
16173 discriminant_info. */
16174 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16175 sect_offset discr_offset
{};
16176 bool has_template_parameters
= false;
16178 if (is_variant_part
)
16180 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16183 /* Maybe it's a univariant form, an extension we support.
16184 In this case arrange not to check the offset. */
16185 is_variant_part
= false;
16187 else if (attr_form_is_ref (discr
))
16189 struct dwarf2_cu
*target_cu
= cu
;
16190 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16192 discr_offset
= target_die
->sect_off
;
16196 complaint (_("DW_AT_discr does not have DIE reference form"
16197 " - DIE at %s [in module %s]"),
16198 sect_offset_str (die
->sect_off
),
16199 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16200 is_variant_part
= false;
16204 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16206 struct field_info fi
;
16207 std::vector
<struct symbol
*> template_args
;
16209 child_die
= die
->child
;
16211 while (child_die
&& child_die
->tag
)
16213 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16215 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16216 fi
.fields
.back ().variant
.is_discriminant
= true;
16218 child_die
= sibling_die (child_die
);
16221 /* Attach template arguments to type. */
16222 if (!template_args
.empty ())
16224 has_template_parameters
= true;
16225 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16226 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16227 TYPE_TEMPLATE_ARGUMENTS (type
)
16228 = XOBNEWVEC (&objfile
->objfile_obstack
,
16230 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16231 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16232 template_args
.data (),
16233 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16234 * sizeof (struct symbol
*)));
16237 /* Attach fields and member functions to the type. */
16239 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16240 if (!fi
.fnfieldlists
.empty ())
16242 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16244 /* Get the type which refers to the base class (possibly this
16245 class itself) which contains the vtable pointer for the current
16246 class from the DW_AT_containing_type attribute. This use of
16247 DW_AT_containing_type is a GNU extension. */
16249 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16251 struct type
*t
= die_containing_type (die
, cu
);
16253 set_type_vptr_basetype (type
, t
);
16258 /* Our own class provides vtbl ptr. */
16259 for (i
= TYPE_NFIELDS (t
) - 1;
16260 i
>= TYPE_N_BASECLASSES (t
);
16263 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16265 if (is_vtable_name (fieldname
, cu
))
16267 set_type_vptr_fieldno (type
, i
);
16272 /* Complain if virtual function table field not found. */
16273 if (i
< TYPE_N_BASECLASSES (t
))
16274 complaint (_("virtual function table pointer "
16275 "not found when defining class '%s'"),
16276 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16280 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16283 else if (cu
->producer
16284 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16286 /* The IBM XLC compiler does not provide direct indication
16287 of the containing type, but the vtable pointer is
16288 always named __vfp. */
16292 for (i
= TYPE_NFIELDS (type
) - 1;
16293 i
>= TYPE_N_BASECLASSES (type
);
16296 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16298 set_type_vptr_fieldno (type
, i
);
16299 set_type_vptr_basetype (type
, type
);
16306 /* Copy fi.typedef_field_list linked list elements content into the
16307 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16308 if (!fi
.typedef_field_list
.empty ())
16310 int count
= fi
.typedef_field_list
.size ();
16312 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16313 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16314 = ((struct decl_field
*)
16316 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16317 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16319 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16320 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16323 /* Copy fi.nested_types_list linked list elements content into the
16324 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16325 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16327 int count
= fi
.nested_types_list
.size ();
16329 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16330 TYPE_NESTED_TYPES_ARRAY (type
)
16331 = ((struct decl_field
*)
16332 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16333 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16335 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16336 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16340 quirk_gcc_member_function_pointer (type
, objfile
);
16341 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16342 cu
->rust_unions
.push_back (type
);
16344 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16345 snapshots) has been known to create a die giving a declaration
16346 for a class that has, as a child, a die giving a definition for a
16347 nested class. So we have to process our children even if the
16348 current die is a declaration. Normally, of course, a declaration
16349 won't have any children at all. */
16351 child_die
= die
->child
;
16353 while (child_die
!= NULL
&& child_die
->tag
)
16355 if (child_die
->tag
== DW_TAG_member
16356 || child_die
->tag
== DW_TAG_variable
16357 || child_die
->tag
== DW_TAG_inheritance
16358 || child_die
->tag
== DW_TAG_template_value_param
16359 || child_die
->tag
== DW_TAG_template_type_param
)
16364 process_die (child_die
, cu
);
16366 child_die
= sibling_die (child_die
);
16369 /* Do not consider external references. According to the DWARF standard,
16370 these DIEs are identified by the fact that they have no byte_size
16371 attribute, and a declaration attribute. */
16372 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16373 || !die_is_declaration (die
, cu
))
16375 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16377 if (has_template_parameters
)
16379 struct symtab
*symtab
;
16380 if (sym
!= nullptr)
16381 symtab
= symbol_symtab (sym
);
16382 else if (cu
->line_header
!= nullptr)
16384 /* Any related symtab will do. */
16386 = cu
->line_header
->file_names ()[0].symtab
;
16391 complaint (_("could not find suitable "
16392 "symtab for template parameter"
16393 " - DIE at %s [in module %s]"),
16394 sect_offset_str (die
->sect_off
),
16395 objfile_name (objfile
));
16398 if (symtab
!= nullptr)
16400 /* Make sure that the symtab is set on the new symbols.
16401 Even though they don't appear in this symtab directly,
16402 other parts of gdb assume that symbols do, and this is
16403 reasonably true. */
16404 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16405 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16411 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16412 update TYPE using some information only available in DIE's children. */
16415 update_enumeration_type_from_children (struct die_info
*die
,
16417 struct dwarf2_cu
*cu
)
16419 struct die_info
*child_die
;
16420 int unsigned_enum
= 1;
16424 auto_obstack obstack
;
16426 for (child_die
= die
->child
;
16427 child_die
!= NULL
&& child_die
->tag
;
16428 child_die
= sibling_die (child_die
))
16430 struct attribute
*attr
;
16432 const gdb_byte
*bytes
;
16433 struct dwarf2_locexpr_baton
*baton
;
16436 if (child_die
->tag
!= DW_TAG_enumerator
)
16439 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16443 name
= dwarf2_name (child_die
, cu
);
16445 name
= "<anonymous enumerator>";
16447 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16448 &value
, &bytes
, &baton
);
16454 else if ((mask
& value
) != 0)
16459 /* If we already know that the enum type is neither unsigned, nor
16460 a flag type, no need to look at the rest of the enumerates. */
16461 if (!unsigned_enum
&& !flag_enum
)
16466 TYPE_UNSIGNED (type
) = 1;
16468 TYPE_FLAG_ENUM (type
) = 1;
16471 /* Given a DW_AT_enumeration_type die, set its type. We do not
16472 complete the type's fields yet, or create any symbols. */
16474 static struct type
*
16475 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16477 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16479 struct attribute
*attr
;
16482 /* If the definition of this type lives in .debug_types, read that type.
16483 Don't follow DW_AT_specification though, that will take us back up
16484 the chain and we want to go down. */
16485 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16486 if (attr
!= nullptr)
16488 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16490 /* The type's CU may not be the same as CU.
16491 Ensure TYPE is recorded with CU in die_type_hash. */
16492 return set_die_type (die
, type
, cu
);
16495 type
= alloc_type (objfile
);
16497 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16498 name
= dwarf2_full_name (NULL
, die
, cu
);
16500 TYPE_NAME (type
) = name
;
16502 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16505 struct type
*underlying_type
= die_type (die
, cu
);
16507 TYPE_TARGET_TYPE (type
) = underlying_type
;
16510 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16511 if (attr
!= nullptr)
16513 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16517 TYPE_LENGTH (type
) = 0;
16520 maybe_set_alignment (cu
, die
, type
);
16522 /* The enumeration DIE can be incomplete. In Ada, any type can be
16523 declared as private in the package spec, and then defined only
16524 inside the package body. Such types are known as Taft Amendment
16525 Types. When another package uses such a type, an incomplete DIE
16526 may be generated by the compiler. */
16527 if (die_is_declaration (die
, cu
))
16528 TYPE_STUB (type
) = 1;
16530 /* Finish the creation of this type by using the enum's children.
16531 We must call this even when the underlying type has been provided
16532 so that we can determine if we're looking at a "flag" enum. */
16533 update_enumeration_type_from_children (die
, type
, cu
);
16535 /* If this type has an underlying type that is not a stub, then we
16536 may use its attributes. We always use the "unsigned" attribute
16537 in this situation, because ordinarily we guess whether the type
16538 is unsigned -- but the guess can be wrong and the underlying type
16539 can tell us the reality. However, we defer to a local size
16540 attribute if one exists, because this lets the compiler override
16541 the underlying type if needed. */
16542 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16544 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16545 if (TYPE_LENGTH (type
) == 0)
16546 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16547 if (TYPE_RAW_ALIGN (type
) == 0
16548 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16549 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16552 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16554 return set_die_type (die
, type
, cu
);
16557 /* Given a pointer to a die which begins an enumeration, process all
16558 the dies that define the members of the enumeration, and create the
16559 symbol for the enumeration type.
16561 NOTE: We reverse the order of the element list. */
16564 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16566 struct type
*this_type
;
16568 this_type
= get_die_type (die
, cu
);
16569 if (this_type
== NULL
)
16570 this_type
= read_enumeration_type (die
, cu
);
16572 if (die
->child
!= NULL
)
16574 struct die_info
*child_die
;
16575 struct symbol
*sym
;
16576 std::vector
<struct field
> fields
;
16579 child_die
= die
->child
;
16580 while (child_die
&& child_die
->tag
)
16582 if (child_die
->tag
!= DW_TAG_enumerator
)
16584 process_die (child_die
, cu
);
16588 name
= dwarf2_name (child_die
, cu
);
16591 sym
= new_symbol (child_die
, this_type
, cu
);
16593 fields
.emplace_back ();
16594 struct field
&field
= fields
.back ();
16596 FIELD_NAME (field
) = sym
->linkage_name ();
16597 FIELD_TYPE (field
) = NULL
;
16598 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16599 FIELD_BITSIZE (field
) = 0;
16603 child_die
= sibling_die (child_die
);
16606 if (!fields
.empty ())
16608 TYPE_NFIELDS (this_type
) = fields
.size ();
16609 TYPE_FIELDS (this_type
) = (struct field
*)
16610 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16611 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16612 sizeof (struct field
) * fields
.size ());
16616 /* If we are reading an enum from a .debug_types unit, and the enum
16617 is a declaration, and the enum is not the signatured type in the
16618 unit, then we do not want to add a symbol for it. Adding a
16619 symbol would in some cases obscure the true definition of the
16620 enum, giving users an incomplete type when the definition is
16621 actually available. Note that we do not want to do this for all
16622 enums which are just declarations, because C++0x allows forward
16623 enum declarations. */
16624 if (cu
->per_cu
->is_debug_types
16625 && die_is_declaration (die
, cu
))
16627 struct signatured_type
*sig_type
;
16629 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16630 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16631 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16635 new_symbol (die
, this_type
, cu
);
16638 /* Extract all information from a DW_TAG_array_type DIE and put it in
16639 the DIE's type field. For now, this only handles one dimensional
16642 static struct type
*
16643 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16645 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16646 struct die_info
*child_die
;
16648 struct type
*element_type
, *range_type
, *index_type
;
16649 struct attribute
*attr
;
16651 struct dynamic_prop
*byte_stride_prop
= NULL
;
16652 unsigned int bit_stride
= 0;
16654 element_type
= die_type (die
, cu
);
16656 /* The die_type call above may have already set the type for this DIE. */
16657 type
= get_die_type (die
, cu
);
16661 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16665 struct type
*prop_type
16666 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16669 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16670 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16674 complaint (_("unable to read array DW_AT_byte_stride "
16675 " - DIE at %s [in module %s]"),
16676 sect_offset_str (die
->sect_off
),
16677 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16678 /* Ignore this attribute. We will likely not be able to print
16679 arrays of this type correctly, but there is little we can do
16680 to help if we cannot read the attribute's value. */
16681 byte_stride_prop
= NULL
;
16685 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16687 bit_stride
= DW_UNSND (attr
);
16689 /* Irix 6.2 native cc creates array types without children for
16690 arrays with unspecified length. */
16691 if (die
->child
== NULL
)
16693 index_type
= objfile_type (objfile
)->builtin_int
;
16694 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16695 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16696 byte_stride_prop
, bit_stride
);
16697 return set_die_type (die
, type
, cu
);
16700 std::vector
<struct type
*> range_types
;
16701 child_die
= die
->child
;
16702 while (child_die
&& child_die
->tag
)
16704 if (child_die
->tag
== DW_TAG_subrange_type
)
16706 struct type
*child_type
= read_type_die (child_die
, cu
);
16708 if (child_type
!= NULL
)
16710 /* The range type was succesfully read. Save it for the
16711 array type creation. */
16712 range_types
.push_back (child_type
);
16715 child_die
= sibling_die (child_die
);
16718 /* Dwarf2 dimensions are output from left to right, create the
16719 necessary array types in backwards order. */
16721 type
= element_type
;
16723 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16727 while (i
< range_types
.size ())
16728 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16729 byte_stride_prop
, bit_stride
);
16733 size_t ndim
= range_types
.size ();
16735 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16736 byte_stride_prop
, bit_stride
);
16739 /* Understand Dwarf2 support for vector types (like they occur on
16740 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16741 array type. This is not part of the Dwarf2/3 standard yet, but a
16742 custom vendor extension. The main difference between a regular
16743 array and the vector variant is that vectors are passed by value
16745 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16746 if (attr
!= nullptr)
16747 make_vector_type (type
);
16749 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16750 implementation may choose to implement triple vectors using this
16752 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16753 if (attr
!= nullptr)
16755 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16756 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16758 complaint (_("DW_AT_byte_size for array type smaller "
16759 "than the total size of elements"));
16762 name
= dwarf2_name (die
, cu
);
16764 TYPE_NAME (type
) = name
;
16766 maybe_set_alignment (cu
, die
, type
);
16768 /* Install the type in the die. */
16769 set_die_type (die
, type
, cu
);
16771 /* set_die_type should be already done. */
16772 set_descriptive_type (type
, die
, cu
);
16777 static enum dwarf_array_dim_ordering
16778 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16780 struct attribute
*attr
;
16782 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16784 if (attr
!= nullptr)
16785 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16787 /* GNU F77 is a special case, as at 08/2004 array type info is the
16788 opposite order to the dwarf2 specification, but data is still
16789 laid out as per normal fortran.
16791 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16792 version checking. */
16794 if (cu
->language
== language_fortran
16795 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16797 return DW_ORD_row_major
;
16800 switch (cu
->language_defn
->la_array_ordering
)
16802 case array_column_major
:
16803 return DW_ORD_col_major
;
16804 case array_row_major
:
16806 return DW_ORD_row_major
;
16810 /* Extract all information from a DW_TAG_set_type DIE and put it in
16811 the DIE's type field. */
16813 static struct type
*
16814 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16816 struct type
*domain_type
, *set_type
;
16817 struct attribute
*attr
;
16819 domain_type
= die_type (die
, cu
);
16821 /* The die_type call above may have already set the type for this DIE. */
16822 set_type
= get_die_type (die
, cu
);
16826 set_type
= create_set_type (NULL
, domain_type
);
16828 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16829 if (attr
!= nullptr)
16830 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16832 maybe_set_alignment (cu
, die
, set_type
);
16834 return set_die_type (die
, set_type
, cu
);
16837 /* A helper for read_common_block that creates a locexpr baton.
16838 SYM is the symbol which we are marking as computed.
16839 COMMON_DIE is the DIE for the common block.
16840 COMMON_LOC is the location expression attribute for the common
16842 MEMBER_LOC is the location expression attribute for the particular
16843 member of the common block that we are processing.
16844 CU is the CU from which the above come. */
16847 mark_common_block_symbol_computed (struct symbol
*sym
,
16848 struct die_info
*common_die
,
16849 struct attribute
*common_loc
,
16850 struct attribute
*member_loc
,
16851 struct dwarf2_cu
*cu
)
16853 struct dwarf2_per_objfile
*dwarf2_per_objfile
16854 = cu
->per_cu
->dwarf2_per_objfile
;
16855 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16856 struct dwarf2_locexpr_baton
*baton
;
16858 unsigned int cu_off
;
16859 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16860 LONGEST offset
= 0;
16862 gdb_assert (common_loc
&& member_loc
);
16863 gdb_assert (attr_form_is_block (common_loc
));
16864 gdb_assert (attr_form_is_block (member_loc
)
16865 || attr_form_is_constant (member_loc
));
16867 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16868 baton
->per_cu
= cu
->per_cu
;
16869 gdb_assert (baton
->per_cu
);
16871 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16873 if (attr_form_is_constant (member_loc
))
16875 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16876 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16879 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16881 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16884 *ptr
++ = DW_OP_call4
;
16885 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16886 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16889 if (attr_form_is_constant (member_loc
))
16891 *ptr
++ = DW_OP_addr
;
16892 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16893 ptr
+= cu
->header
.addr_size
;
16897 /* We have to copy the data here, because DW_OP_call4 will only
16898 use a DW_AT_location attribute. */
16899 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16900 ptr
+= DW_BLOCK (member_loc
)->size
;
16903 *ptr
++ = DW_OP_plus
;
16904 gdb_assert (ptr
- baton
->data
== baton
->size
);
16906 SYMBOL_LOCATION_BATON (sym
) = baton
;
16907 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16910 /* Create appropriate locally-scoped variables for all the
16911 DW_TAG_common_block entries. Also create a struct common_block
16912 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16913 is used to separate the common blocks name namespace from regular
16917 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16919 struct attribute
*attr
;
16921 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16922 if (attr
!= nullptr)
16924 /* Support the .debug_loc offsets. */
16925 if (attr_form_is_block (attr
))
16929 else if (attr_form_is_section_offset (attr
))
16931 dwarf2_complex_location_expr_complaint ();
16936 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16937 "common block member");
16942 if (die
->child
!= NULL
)
16944 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16945 struct die_info
*child_die
;
16946 size_t n_entries
= 0, size
;
16947 struct common_block
*common_block
;
16948 struct symbol
*sym
;
16950 for (child_die
= die
->child
;
16951 child_die
&& child_die
->tag
;
16952 child_die
= sibling_die (child_die
))
16955 size
= (sizeof (struct common_block
)
16956 + (n_entries
- 1) * sizeof (struct symbol
*));
16958 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16960 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16961 common_block
->n_entries
= 0;
16963 for (child_die
= die
->child
;
16964 child_die
&& child_die
->tag
;
16965 child_die
= sibling_die (child_die
))
16967 /* Create the symbol in the DW_TAG_common_block block in the current
16969 sym
= new_symbol (child_die
, NULL
, cu
);
16972 struct attribute
*member_loc
;
16974 common_block
->contents
[common_block
->n_entries
++] = sym
;
16976 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16980 /* GDB has handled this for a long time, but it is
16981 not specified by DWARF. It seems to have been
16982 emitted by gfortran at least as recently as:
16983 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16984 complaint (_("Variable in common block has "
16985 "DW_AT_data_member_location "
16986 "- DIE at %s [in module %s]"),
16987 sect_offset_str (child_die
->sect_off
),
16988 objfile_name (objfile
));
16990 if (attr_form_is_section_offset (member_loc
))
16991 dwarf2_complex_location_expr_complaint ();
16992 else if (attr_form_is_constant (member_loc
)
16993 || attr_form_is_block (member_loc
))
16995 if (attr
!= nullptr)
16996 mark_common_block_symbol_computed (sym
, die
, attr
,
17000 dwarf2_complex_location_expr_complaint ();
17005 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
17006 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
17010 /* Create a type for a C++ namespace. */
17012 static struct type
*
17013 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17015 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17016 const char *previous_prefix
, *name
;
17020 /* For extensions, reuse the type of the original namespace. */
17021 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
17023 struct die_info
*ext_die
;
17024 struct dwarf2_cu
*ext_cu
= cu
;
17026 ext_die
= dwarf2_extension (die
, &ext_cu
);
17027 type
= read_type_die (ext_die
, ext_cu
);
17029 /* EXT_CU may not be the same as CU.
17030 Ensure TYPE is recorded with CU in die_type_hash. */
17031 return set_die_type (die
, type
, cu
);
17034 name
= namespace_name (die
, &is_anonymous
, cu
);
17036 /* Now build the name of the current namespace. */
17038 previous_prefix
= determine_prefix (die
, cu
);
17039 if (previous_prefix
[0] != '\0')
17040 name
= typename_concat (&objfile
->objfile_obstack
,
17041 previous_prefix
, name
, 0, cu
);
17043 /* Create the type. */
17044 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
17046 return set_die_type (die
, type
, cu
);
17049 /* Read a namespace scope. */
17052 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
17054 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17057 /* Add a symbol associated to this if we haven't seen the namespace
17058 before. Also, add a using directive if it's an anonymous
17061 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17065 type
= read_type_die (die
, cu
);
17066 new_symbol (die
, type
, cu
);
17068 namespace_name (die
, &is_anonymous
, cu
);
17071 const char *previous_prefix
= determine_prefix (die
, cu
);
17073 std::vector
<const char *> excludes
;
17074 add_using_directive (using_directives (cu
),
17075 previous_prefix
, TYPE_NAME (type
), NULL
,
17076 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17080 if (die
->child
!= NULL
)
17082 struct die_info
*child_die
= die
->child
;
17084 while (child_die
&& child_die
->tag
)
17086 process_die (child_die
, cu
);
17087 child_die
= sibling_die (child_die
);
17092 /* Read a Fortran module as type. This DIE can be only a declaration used for
17093 imported module. Still we need that type as local Fortran "use ... only"
17094 declaration imports depend on the created type in determine_prefix. */
17096 static struct type
*
17097 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17099 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17100 const char *module_name
;
17103 module_name
= dwarf2_name (die
, cu
);
17104 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17106 return set_die_type (die
, type
, cu
);
17109 /* Read a Fortran module. */
17112 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17114 struct die_info
*child_die
= die
->child
;
17117 type
= read_type_die (die
, cu
);
17118 new_symbol (die
, type
, cu
);
17120 while (child_die
&& child_die
->tag
)
17122 process_die (child_die
, cu
);
17123 child_die
= sibling_die (child_die
);
17127 /* Return the name of the namespace represented by DIE. Set
17128 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17131 static const char *
17132 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17134 struct die_info
*current_die
;
17135 const char *name
= NULL
;
17137 /* Loop through the extensions until we find a name. */
17139 for (current_die
= die
;
17140 current_die
!= NULL
;
17141 current_die
= dwarf2_extension (die
, &cu
))
17143 /* We don't use dwarf2_name here so that we can detect the absence
17144 of a name -> anonymous namespace. */
17145 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17151 /* Is it an anonymous namespace? */
17153 *is_anonymous
= (name
== NULL
);
17155 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17160 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17161 the user defined type vector. */
17163 static struct type
*
17164 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17166 struct gdbarch
*gdbarch
17167 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17168 struct comp_unit_head
*cu_header
= &cu
->header
;
17170 struct attribute
*attr_byte_size
;
17171 struct attribute
*attr_address_class
;
17172 int byte_size
, addr_class
;
17173 struct type
*target_type
;
17175 target_type
= die_type (die
, cu
);
17177 /* The die_type call above may have already set the type for this DIE. */
17178 type
= get_die_type (die
, cu
);
17182 type
= lookup_pointer_type (target_type
);
17184 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17185 if (attr_byte_size
)
17186 byte_size
= DW_UNSND (attr_byte_size
);
17188 byte_size
= cu_header
->addr_size
;
17190 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17191 if (attr_address_class
)
17192 addr_class
= DW_UNSND (attr_address_class
);
17194 addr_class
= DW_ADDR_none
;
17196 ULONGEST alignment
= get_alignment (cu
, die
);
17198 /* If the pointer size, alignment, or address class is different
17199 than the default, create a type variant marked as such and set
17200 the length accordingly. */
17201 if (TYPE_LENGTH (type
) != byte_size
17202 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17203 && alignment
!= TYPE_RAW_ALIGN (type
))
17204 || addr_class
!= DW_ADDR_none
)
17206 if (gdbarch_address_class_type_flags_p (gdbarch
))
17210 type_flags
= gdbarch_address_class_type_flags
17211 (gdbarch
, byte_size
, addr_class
);
17212 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17214 type
= make_type_with_address_space (type
, type_flags
);
17216 else if (TYPE_LENGTH (type
) != byte_size
)
17218 complaint (_("invalid pointer size %d"), byte_size
);
17220 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17222 complaint (_("Invalid DW_AT_alignment"
17223 " - DIE at %s [in module %s]"),
17224 sect_offset_str (die
->sect_off
),
17225 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17229 /* Should we also complain about unhandled address classes? */
17233 TYPE_LENGTH (type
) = byte_size
;
17234 set_type_align (type
, alignment
);
17235 return set_die_type (die
, type
, cu
);
17238 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17239 the user defined type vector. */
17241 static struct type
*
17242 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17245 struct type
*to_type
;
17246 struct type
*domain
;
17248 to_type
= die_type (die
, cu
);
17249 domain
= die_containing_type (die
, cu
);
17251 /* The calls above may have already set the type for this DIE. */
17252 type
= get_die_type (die
, cu
);
17256 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17257 type
= lookup_methodptr_type (to_type
);
17258 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17260 struct type
*new_type
17261 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17263 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17264 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17265 TYPE_VARARGS (to_type
));
17266 type
= lookup_methodptr_type (new_type
);
17269 type
= lookup_memberptr_type (to_type
, domain
);
17271 return set_die_type (die
, type
, cu
);
17274 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17275 the user defined type vector. */
17277 static struct type
*
17278 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17279 enum type_code refcode
)
17281 struct comp_unit_head
*cu_header
= &cu
->header
;
17282 struct type
*type
, *target_type
;
17283 struct attribute
*attr
;
17285 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17287 target_type
= die_type (die
, cu
);
17289 /* The die_type call above may have already set the type for this DIE. */
17290 type
= get_die_type (die
, cu
);
17294 type
= lookup_reference_type (target_type
, refcode
);
17295 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17296 if (attr
!= nullptr)
17298 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17302 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17304 maybe_set_alignment (cu
, die
, type
);
17305 return set_die_type (die
, type
, cu
);
17308 /* Add the given cv-qualifiers to the element type of the array. GCC
17309 outputs DWARF type qualifiers that apply to an array, not the
17310 element type. But GDB relies on the array element type to carry
17311 the cv-qualifiers. This mimics section 6.7.3 of the C99
17314 static struct type
*
17315 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17316 struct type
*base_type
, int cnst
, int voltl
)
17318 struct type
*el_type
, *inner_array
;
17320 base_type
= copy_type (base_type
);
17321 inner_array
= base_type
;
17323 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17325 TYPE_TARGET_TYPE (inner_array
) =
17326 copy_type (TYPE_TARGET_TYPE (inner_array
));
17327 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17330 el_type
= TYPE_TARGET_TYPE (inner_array
);
17331 cnst
|= TYPE_CONST (el_type
);
17332 voltl
|= TYPE_VOLATILE (el_type
);
17333 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17335 return set_die_type (die
, base_type
, cu
);
17338 static struct type
*
17339 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17341 struct type
*base_type
, *cv_type
;
17343 base_type
= die_type (die
, cu
);
17345 /* The die_type call above may have already set the type for this DIE. */
17346 cv_type
= get_die_type (die
, cu
);
17350 /* In case the const qualifier is applied to an array type, the element type
17351 is so qualified, not the array type (section 6.7.3 of C99). */
17352 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17353 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17355 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17356 return set_die_type (die
, cv_type
, cu
);
17359 static struct type
*
17360 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17362 struct type
*base_type
, *cv_type
;
17364 base_type
= die_type (die
, cu
);
17366 /* The die_type call above may have already set the type for this DIE. */
17367 cv_type
= get_die_type (die
, cu
);
17371 /* In case the volatile qualifier is applied to an array type, the
17372 element type is so qualified, not the array type (section 6.7.3
17374 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17375 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17377 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17378 return set_die_type (die
, cv_type
, cu
);
17381 /* Handle DW_TAG_restrict_type. */
17383 static struct type
*
17384 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17386 struct type
*base_type
, *cv_type
;
17388 base_type
= die_type (die
, cu
);
17390 /* The die_type call above may have already set the type for this DIE. */
17391 cv_type
= get_die_type (die
, cu
);
17395 cv_type
= make_restrict_type (base_type
);
17396 return set_die_type (die
, cv_type
, cu
);
17399 /* Handle DW_TAG_atomic_type. */
17401 static struct type
*
17402 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17404 struct type
*base_type
, *cv_type
;
17406 base_type
= die_type (die
, cu
);
17408 /* The die_type call above may have already set the type for this DIE. */
17409 cv_type
= get_die_type (die
, cu
);
17413 cv_type
= make_atomic_type (base_type
);
17414 return set_die_type (die
, cv_type
, cu
);
17417 /* Extract all information from a DW_TAG_string_type DIE and add to
17418 the user defined type vector. It isn't really a user defined type,
17419 but it behaves like one, with other DIE's using an AT_user_def_type
17420 attribute to reference it. */
17422 static struct type
*
17423 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17425 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17426 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17427 struct type
*type
, *range_type
, *index_type
, *char_type
;
17428 struct attribute
*attr
;
17429 struct dynamic_prop prop
;
17430 bool length_is_constant
= true;
17433 /* There are a couple of places where bit sizes might be made use of
17434 when parsing a DW_TAG_string_type, however, no producer that we know
17435 of make use of these. Handling bit sizes that are a multiple of the
17436 byte size is easy enough, but what about other bit sizes? Lets deal
17437 with that problem when we have to. Warn about these attributes being
17438 unsupported, then parse the type and ignore them like we always
17440 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17441 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17443 static bool warning_printed
= false;
17444 if (!warning_printed
)
17446 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17447 "currently supported on DW_TAG_string_type."));
17448 warning_printed
= true;
17452 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17453 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17455 /* The string length describes the location at which the length of
17456 the string can be found. The size of the length field can be
17457 specified with one of the attributes below. */
17458 struct type
*prop_type
;
17459 struct attribute
*len
17460 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17461 if (len
== nullptr)
17462 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17463 if (len
!= nullptr && attr_form_is_constant (len
))
17465 /* Pass 0 as the default as we know this attribute is constant
17466 and the default value will not be returned. */
17467 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17468 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17472 /* If the size is not specified then we assume it is the size of
17473 an address on this target. */
17474 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17477 /* Convert the attribute into a dynamic property. */
17478 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17481 length_is_constant
= false;
17483 else if (attr
!= nullptr)
17485 /* This DW_AT_string_length just contains the length with no
17486 indirection. There's no need to create a dynamic property in this
17487 case. Pass 0 for the default value as we know it will not be
17488 returned in this case. */
17489 length
= dwarf2_get_attr_constant_value (attr
, 0);
17491 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17493 /* We don't currently support non-constant byte sizes for strings. */
17494 length
= dwarf2_get_attr_constant_value (attr
, 1);
17498 /* Use 1 as a fallback length if we have nothing else. */
17502 index_type
= objfile_type (objfile
)->builtin_int
;
17503 if (length_is_constant
)
17504 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17507 struct dynamic_prop low_bound
;
17509 low_bound
.kind
= PROP_CONST
;
17510 low_bound
.data
.const_val
= 1;
17511 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17513 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17514 type
= create_string_type (NULL
, char_type
, range_type
);
17516 return set_die_type (die
, type
, cu
);
17519 /* Assuming that DIE corresponds to a function, returns nonzero
17520 if the function is prototyped. */
17523 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17525 struct attribute
*attr
;
17527 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17528 if (attr
&& (DW_UNSND (attr
) != 0))
17531 /* The DWARF standard implies that the DW_AT_prototyped attribute
17532 is only meaningful for C, but the concept also extends to other
17533 languages that allow unprototyped functions (Eg: Objective C).
17534 For all other languages, assume that functions are always
17536 if (cu
->language
!= language_c
17537 && cu
->language
!= language_objc
17538 && cu
->language
!= language_opencl
)
17541 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17542 prototyped and unprototyped functions; default to prototyped,
17543 since that is more common in modern code (and RealView warns
17544 about unprototyped functions). */
17545 if (producer_is_realview (cu
->producer
))
17551 /* Handle DIES due to C code like:
17555 int (*funcp)(int a, long l);
17559 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17561 static struct type
*
17562 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17564 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17565 struct type
*type
; /* Type that this function returns. */
17566 struct type
*ftype
; /* Function that returns above type. */
17567 struct attribute
*attr
;
17569 type
= die_type (die
, cu
);
17571 /* The die_type call above may have already set the type for this DIE. */
17572 ftype
= get_die_type (die
, cu
);
17576 ftype
= lookup_function_type (type
);
17578 if (prototyped_function_p (die
, cu
))
17579 TYPE_PROTOTYPED (ftype
) = 1;
17581 /* Store the calling convention in the type if it's available in
17582 the subroutine die. Otherwise set the calling convention to
17583 the default value DW_CC_normal. */
17584 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17585 if (attr
!= nullptr
17586 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17587 TYPE_CALLING_CONVENTION (ftype
)
17588 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17589 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17590 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17592 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17594 /* Record whether the function returns normally to its caller or not
17595 if the DWARF producer set that information. */
17596 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17597 if (attr
&& (DW_UNSND (attr
) != 0))
17598 TYPE_NO_RETURN (ftype
) = 1;
17600 /* We need to add the subroutine type to the die immediately so
17601 we don't infinitely recurse when dealing with parameters
17602 declared as the same subroutine type. */
17603 set_die_type (die
, ftype
, cu
);
17605 if (die
->child
!= NULL
)
17607 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17608 struct die_info
*child_die
;
17609 int nparams
, iparams
;
17611 /* Count the number of parameters.
17612 FIXME: GDB currently ignores vararg functions, but knows about
17613 vararg member functions. */
17615 child_die
= die
->child
;
17616 while (child_die
&& child_die
->tag
)
17618 if (child_die
->tag
== DW_TAG_formal_parameter
)
17620 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17621 TYPE_VARARGS (ftype
) = 1;
17622 child_die
= sibling_die (child_die
);
17625 /* Allocate storage for parameters and fill them in. */
17626 TYPE_NFIELDS (ftype
) = nparams
;
17627 TYPE_FIELDS (ftype
) = (struct field
*)
17628 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17630 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17631 even if we error out during the parameters reading below. */
17632 for (iparams
= 0; iparams
< nparams
; iparams
++)
17633 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17636 child_die
= die
->child
;
17637 while (child_die
&& child_die
->tag
)
17639 if (child_die
->tag
== DW_TAG_formal_parameter
)
17641 struct type
*arg_type
;
17643 /* DWARF version 2 has no clean way to discern C++
17644 static and non-static member functions. G++ helps
17645 GDB by marking the first parameter for non-static
17646 member functions (which is the this pointer) as
17647 artificial. We pass this information to
17648 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17650 DWARF version 3 added DW_AT_object_pointer, which GCC
17651 4.5 does not yet generate. */
17652 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17653 if (attr
!= nullptr)
17654 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17656 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17657 arg_type
= die_type (child_die
, cu
);
17659 /* RealView does not mark THIS as const, which the testsuite
17660 expects. GCC marks THIS as const in method definitions,
17661 but not in the class specifications (GCC PR 43053). */
17662 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17663 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17666 struct dwarf2_cu
*arg_cu
= cu
;
17667 const char *name
= dwarf2_name (child_die
, cu
);
17669 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17670 if (attr
!= nullptr)
17672 /* If the compiler emits this, use it. */
17673 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17676 else if (name
&& strcmp (name
, "this") == 0)
17677 /* Function definitions will have the argument names. */
17679 else if (name
== NULL
&& iparams
== 0)
17680 /* Declarations may not have the names, so like
17681 elsewhere in GDB, assume an artificial first
17682 argument is "this". */
17686 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17690 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17693 child_die
= sibling_die (child_die
);
17700 static struct type
*
17701 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17703 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17704 const char *name
= NULL
;
17705 struct type
*this_type
, *target_type
;
17707 name
= dwarf2_full_name (NULL
, die
, cu
);
17708 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17709 TYPE_TARGET_STUB (this_type
) = 1;
17710 set_die_type (die
, this_type
, cu
);
17711 target_type
= die_type (die
, cu
);
17712 if (target_type
!= this_type
)
17713 TYPE_TARGET_TYPE (this_type
) = target_type
;
17716 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17717 spec and cause infinite loops in GDB. */
17718 complaint (_("Self-referential DW_TAG_typedef "
17719 "- DIE at %s [in module %s]"),
17720 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17721 TYPE_TARGET_TYPE (this_type
) = NULL
;
17726 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17727 (which may be different from NAME) to the architecture back-end to allow
17728 it to guess the correct format if necessary. */
17730 static struct type
*
17731 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17732 const char *name_hint
, enum bfd_endian byte_order
)
17734 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17735 const struct floatformat
**format
;
17738 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17740 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17742 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17747 /* Allocate an integer type of size BITS and name NAME. */
17749 static struct type
*
17750 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17751 int bits
, int unsigned_p
, const char *name
)
17755 /* Versions of Intel's C Compiler generate an integer type called "void"
17756 instead of using DW_TAG_unspecified_type. This has been seen on
17757 at least versions 14, 17, and 18. */
17758 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17759 && strcmp (name
, "void") == 0)
17760 type
= objfile_type (objfile
)->builtin_void
;
17762 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17767 /* Initialise and return a floating point type of size BITS suitable for
17768 use as a component of a complex number. The NAME_HINT is passed through
17769 when initialising the floating point type and is the name of the complex
17772 As DWARF doesn't currently provide an explicit name for the components
17773 of a complex number, but it can be helpful to have these components
17774 named, we try to select a suitable name based on the size of the
17776 static struct type
*
17777 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17778 struct objfile
*objfile
,
17779 int bits
, const char *name_hint
,
17780 enum bfd_endian byte_order
)
17782 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17783 struct type
*tt
= nullptr;
17785 /* Try to find a suitable floating point builtin type of size BITS.
17786 We're going to use the name of this type as the name for the complex
17787 target type that we are about to create. */
17788 switch (cu
->language
)
17790 case language_fortran
:
17794 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17797 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17799 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17801 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17809 tt
= builtin_type (gdbarch
)->builtin_float
;
17812 tt
= builtin_type (gdbarch
)->builtin_double
;
17814 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17816 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17822 /* If the type we found doesn't match the size we were looking for, then
17823 pretend we didn't find a type at all, the complex target type we
17824 create will then be nameless. */
17825 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17828 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17829 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17832 /* Find a representation of a given base type and install
17833 it in the TYPE field of the die. */
17835 static struct type
*
17836 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17838 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17840 struct attribute
*attr
;
17841 int encoding
= 0, bits
= 0;
17845 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17846 if (attr
!= nullptr)
17847 encoding
= DW_UNSND (attr
);
17848 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17849 if (attr
!= nullptr)
17850 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17851 name
= dwarf2_name (die
, cu
);
17853 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17855 arch
= get_objfile_arch (objfile
);
17856 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17858 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17861 int endianity
= DW_UNSND (attr
);
17866 byte_order
= BFD_ENDIAN_BIG
;
17868 case DW_END_little
:
17869 byte_order
= BFD_ENDIAN_LITTLE
;
17872 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17879 case DW_ATE_address
:
17880 /* Turn DW_ATE_address into a void * pointer. */
17881 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17882 type
= init_pointer_type (objfile
, bits
, name
, type
);
17884 case DW_ATE_boolean
:
17885 type
= init_boolean_type (objfile
, bits
, 1, name
);
17887 case DW_ATE_complex_float
:
17888 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17890 type
= init_complex_type (objfile
, name
, type
);
17892 case DW_ATE_decimal_float
:
17893 type
= init_decfloat_type (objfile
, bits
, name
);
17896 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17898 case DW_ATE_signed
:
17899 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17901 case DW_ATE_unsigned
:
17902 if (cu
->language
== language_fortran
17904 && startswith (name
, "character("))
17905 type
= init_character_type (objfile
, bits
, 1, name
);
17907 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17909 case DW_ATE_signed_char
:
17910 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17911 || cu
->language
== language_pascal
17912 || cu
->language
== language_fortran
)
17913 type
= init_character_type (objfile
, bits
, 0, name
);
17915 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17917 case DW_ATE_unsigned_char
:
17918 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17919 || cu
->language
== language_pascal
17920 || cu
->language
== language_fortran
17921 || cu
->language
== language_rust
)
17922 type
= init_character_type (objfile
, bits
, 1, name
);
17924 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17929 type
= builtin_type (arch
)->builtin_char16
;
17930 else if (bits
== 32)
17931 type
= builtin_type (arch
)->builtin_char32
;
17934 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17936 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17938 return set_die_type (die
, type
, cu
);
17943 complaint (_("unsupported DW_AT_encoding: '%s'"),
17944 dwarf_type_encoding_name (encoding
));
17945 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17949 if (name
&& strcmp (name
, "char") == 0)
17950 TYPE_NOSIGN (type
) = 1;
17952 maybe_set_alignment (cu
, die
, type
);
17954 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17956 return set_die_type (die
, type
, cu
);
17959 /* Parse dwarf attribute if it's a block, reference or constant and put the
17960 resulting value of the attribute into struct bound_prop.
17961 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17964 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17965 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17966 struct type
*default_type
)
17968 struct dwarf2_property_baton
*baton
;
17969 struct obstack
*obstack
17970 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17972 gdb_assert (default_type
!= NULL
);
17974 if (attr
== NULL
|| prop
== NULL
)
17977 if (attr_form_is_block (attr
))
17979 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17980 baton
->property_type
= default_type
;
17981 baton
->locexpr
.per_cu
= cu
->per_cu
;
17982 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17983 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17984 switch (attr
->name
)
17986 case DW_AT_string_length
:
17987 baton
->locexpr
.is_reference
= true;
17990 baton
->locexpr
.is_reference
= false;
17993 prop
->data
.baton
= baton
;
17994 prop
->kind
= PROP_LOCEXPR
;
17995 gdb_assert (prop
->data
.baton
!= NULL
);
17997 else if (attr_form_is_ref (attr
))
17999 struct dwarf2_cu
*target_cu
= cu
;
18000 struct die_info
*target_die
;
18001 struct attribute
*target_attr
;
18003 target_die
= follow_die_ref (die
, attr
, &target_cu
);
18004 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
18005 if (target_attr
== NULL
)
18006 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
18008 if (target_attr
== NULL
)
18011 switch (target_attr
->name
)
18013 case DW_AT_location
:
18014 if (attr_form_is_section_offset (target_attr
))
18016 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18017 baton
->property_type
= die_type (target_die
, target_cu
);
18018 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
18019 prop
->data
.baton
= baton
;
18020 prop
->kind
= PROP_LOCLIST
;
18021 gdb_assert (prop
->data
.baton
!= NULL
);
18023 else if (attr_form_is_block (target_attr
))
18025 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18026 baton
->property_type
= die_type (target_die
, target_cu
);
18027 baton
->locexpr
.per_cu
= cu
->per_cu
;
18028 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
18029 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
18030 baton
->locexpr
.is_reference
= true;
18031 prop
->data
.baton
= baton
;
18032 prop
->kind
= PROP_LOCEXPR
;
18033 gdb_assert (prop
->data
.baton
!= NULL
);
18037 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
18038 "dynamic property");
18042 case DW_AT_data_member_location
:
18046 if (!handle_data_member_location (target_die
, target_cu
,
18050 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
18051 baton
->property_type
= read_type_die (target_die
->parent
,
18053 baton
->offset_info
.offset
= offset
;
18054 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
18055 prop
->data
.baton
= baton
;
18056 prop
->kind
= PROP_ADDR_OFFSET
;
18061 else if (attr_form_is_constant (attr
))
18063 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18064 prop
->kind
= PROP_CONST
;
18068 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18069 dwarf2_name (die
, cu
));
18076 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18077 UNSIGNED_P controls if the integer is unsigned or not. */
18079 static struct type
*
18080 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18081 int size_in_bytes
, bool unsigned_p
)
18083 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18084 struct type
*int_type
;
18086 /* Helper macro to examine the various builtin types. */
18087 #define TRY_TYPE(F) \
18088 int_type = (unsigned_p \
18089 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18090 : objfile_type (objfile)->builtin_ ## F); \
18091 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18098 TRY_TYPE (long_long
);
18102 gdb_assert_not_reached ("unable to find suitable integer type");
18105 /* Find an integer type the same size as the address size given in the
18106 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18107 is unsigned or not. */
18109 static struct type
*
18110 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18113 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18114 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18117 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18118 present (which is valid) then compute the default type based on the
18119 compilation units address size. */
18121 static struct type
*
18122 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18124 struct type
*index_type
= die_type (die
, cu
);
18126 /* Dwarf-2 specifications explicitly allows to create subrange types
18127 without specifying a base type.
18128 In that case, the base type must be set to the type of
18129 the lower bound, upper bound or count, in that order, if any of these
18130 three attributes references an object that has a type.
18131 If no base type is found, the Dwarf-2 specifications say that
18132 a signed integer type of size equal to the size of an address should
18134 For the following C code: `extern char gdb_int [];'
18135 GCC produces an empty range DIE.
18136 FIXME: muller/2010-05-28: Possible references to object for low bound,
18137 high bound or count are not yet handled by this code. */
18138 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18139 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18144 /* Read the given DW_AT_subrange DIE. */
18146 static struct type
*
18147 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18149 struct type
*base_type
, *orig_base_type
;
18150 struct type
*range_type
;
18151 struct attribute
*attr
;
18152 struct dynamic_prop low
, high
;
18153 int low_default_is_valid
;
18154 int high_bound_is_count
= 0;
18156 ULONGEST negative_mask
;
18158 orig_base_type
= read_subrange_index_type (die
, cu
);
18160 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18161 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18162 creating the range type, but we use the result of check_typedef
18163 when examining properties of the type. */
18164 base_type
= check_typedef (orig_base_type
);
18166 /* The die_type call above may have already set the type for this DIE. */
18167 range_type
= get_die_type (die
, cu
);
18171 low
.kind
= PROP_CONST
;
18172 high
.kind
= PROP_CONST
;
18173 high
.data
.const_val
= 0;
18175 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18176 omitting DW_AT_lower_bound. */
18177 switch (cu
->language
)
18180 case language_cplus
:
18181 low
.data
.const_val
= 0;
18182 low_default_is_valid
= 1;
18184 case language_fortran
:
18185 low
.data
.const_val
= 1;
18186 low_default_is_valid
= 1;
18189 case language_objc
:
18190 case language_rust
:
18191 low
.data
.const_val
= 0;
18192 low_default_is_valid
= (cu
->header
.version
>= 4);
18196 case language_pascal
:
18197 low
.data
.const_val
= 1;
18198 low_default_is_valid
= (cu
->header
.version
>= 4);
18201 low
.data
.const_val
= 0;
18202 low_default_is_valid
= 0;
18206 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18207 if (attr
!= nullptr)
18208 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18209 else if (!low_default_is_valid
)
18210 complaint (_("Missing DW_AT_lower_bound "
18211 "- DIE at %s [in module %s]"),
18212 sect_offset_str (die
->sect_off
),
18213 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18215 struct attribute
*attr_ub
, *attr_count
;
18216 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18217 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18219 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18220 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18222 /* If bounds are constant do the final calculation here. */
18223 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18224 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18226 high_bound_is_count
= 1;
18230 if (attr_ub
!= NULL
)
18231 complaint (_("Unresolved DW_AT_upper_bound "
18232 "- DIE at %s [in module %s]"),
18233 sect_offset_str (die
->sect_off
),
18234 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18235 if (attr_count
!= NULL
)
18236 complaint (_("Unresolved DW_AT_count "
18237 "- DIE at %s [in module %s]"),
18238 sect_offset_str (die
->sect_off
),
18239 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18244 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18245 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18246 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18248 /* Normally, the DWARF producers are expected to use a signed
18249 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18250 But this is unfortunately not always the case, as witnessed
18251 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18252 is used instead. To work around that ambiguity, we treat
18253 the bounds as signed, and thus sign-extend their values, when
18254 the base type is signed. */
18256 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18257 if (low
.kind
== PROP_CONST
18258 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18259 low
.data
.const_val
|= negative_mask
;
18260 if (high
.kind
== PROP_CONST
18261 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18262 high
.data
.const_val
|= negative_mask
;
18264 /* Check for bit and byte strides. */
18265 struct dynamic_prop byte_stride_prop
;
18266 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18267 if (attr_byte_stride
!= nullptr)
18269 struct type
*prop_type
18270 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18271 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18275 struct dynamic_prop bit_stride_prop
;
18276 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18277 if (attr_bit_stride
!= nullptr)
18279 /* It only makes sense to have either a bit or byte stride. */
18280 if (attr_byte_stride
!= nullptr)
18282 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18283 "- DIE at %s [in module %s]"),
18284 sect_offset_str (die
->sect_off
),
18285 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18286 attr_bit_stride
= nullptr;
18290 struct type
*prop_type
18291 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18292 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18297 if (attr_byte_stride
!= nullptr
18298 || attr_bit_stride
!= nullptr)
18300 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18301 struct dynamic_prop
*stride
18302 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18305 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18306 &high
, bias
, stride
, byte_stride_p
);
18309 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18311 if (high_bound_is_count
)
18312 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18314 /* Ada expects an empty array on no boundary attributes. */
18315 if (attr
== NULL
&& cu
->language
!= language_ada
)
18316 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18318 name
= dwarf2_name (die
, cu
);
18320 TYPE_NAME (range_type
) = name
;
18322 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18323 if (attr
!= nullptr)
18324 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18326 maybe_set_alignment (cu
, die
, range_type
);
18328 set_die_type (die
, range_type
, cu
);
18330 /* set_die_type should be already done. */
18331 set_descriptive_type (range_type
, die
, cu
);
18336 static struct type
*
18337 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18341 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18343 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18345 /* In Ada, an unspecified type is typically used when the description
18346 of the type is deferred to a different unit. When encountering
18347 such a type, we treat it as a stub, and try to resolve it later on,
18349 if (cu
->language
== language_ada
)
18350 TYPE_STUB (type
) = 1;
18352 return set_die_type (die
, type
, cu
);
18355 /* Read a single die and all its descendents. Set the die's sibling
18356 field to NULL; set other fields in the die correctly, and set all
18357 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18358 location of the info_ptr after reading all of those dies. PARENT
18359 is the parent of the die in question. */
18361 static struct die_info
*
18362 read_die_and_children (const struct die_reader_specs
*reader
,
18363 const gdb_byte
*info_ptr
,
18364 const gdb_byte
**new_info_ptr
,
18365 struct die_info
*parent
)
18367 struct die_info
*die
;
18368 const gdb_byte
*cur_ptr
;
18371 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18374 *new_info_ptr
= cur_ptr
;
18377 store_in_ref_table (die
, reader
->cu
);
18380 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18384 *new_info_ptr
= cur_ptr
;
18387 die
->sibling
= NULL
;
18388 die
->parent
= parent
;
18392 /* Read a die, all of its descendents, and all of its siblings; set
18393 all of the fields of all of the dies correctly. Arguments are as
18394 in read_die_and_children. */
18396 static struct die_info
*
18397 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18398 const gdb_byte
*info_ptr
,
18399 const gdb_byte
**new_info_ptr
,
18400 struct die_info
*parent
)
18402 struct die_info
*first_die
, *last_sibling
;
18403 const gdb_byte
*cur_ptr
;
18405 cur_ptr
= info_ptr
;
18406 first_die
= last_sibling
= NULL
;
18410 struct die_info
*die
18411 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18415 *new_info_ptr
= cur_ptr
;
18422 last_sibling
->sibling
= die
;
18424 last_sibling
= die
;
18428 /* Read a die, all of its descendents, and all of its siblings; set
18429 all of the fields of all of the dies correctly. Arguments are as
18430 in read_die_and_children.
18431 This the main entry point for reading a DIE and all its children. */
18433 static struct die_info
*
18434 read_die_and_siblings (const struct die_reader_specs
*reader
,
18435 const gdb_byte
*info_ptr
,
18436 const gdb_byte
**new_info_ptr
,
18437 struct die_info
*parent
)
18439 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18440 new_info_ptr
, parent
);
18442 if (dwarf_die_debug
)
18444 fprintf_unfiltered (gdb_stdlog
,
18445 "Read die from %s@0x%x of %s:\n",
18446 get_section_name (reader
->die_section
),
18447 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18448 bfd_get_filename (reader
->abfd
));
18449 dump_die (die
, dwarf_die_debug
);
18455 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18457 The caller is responsible for filling in the extra attributes
18458 and updating (*DIEP)->num_attrs.
18459 Set DIEP to point to a newly allocated die with its information,
18460 except for its child, sibling, and parent fields.
18461 Set HAS_CHILDREN to tell whether the die has children or not. */
18463 static const gdb_byte
*
18464 read_full_die_1 (const struct die_reader_specs
*reader
,
18465 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18466 int *has_children
, int num_extra_attrs
)
18468 unsigned int abbrev_number
, bytes_read
, i
;
18469 struct abbrev_info
*abbrev
;
18470 struct die_info
*die
;
18471 struct dwarf2_cu
*cu
= reader
->cu
;
18472 bfd
*abfd
= reader
->abfd
;
18474 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18475 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18476 info_ptr
+= bytes_read
;
18477 if (!abbrev_number
)
18484 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18486 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18488 bfd_get_filename (abfd
));
18490 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18491 die
->sect_off
= sect_off
;
18492 die
->tag
= abbrev
->tag
;
18493 die
->abbrev
= abbrev_number
;
18495 /* Make the result usable.
18496 The caller needs to update num_attrs after adding the extra
18498 die
->num_attrs
= abbrev
->num_attrs
;
18500 std::vector
<int> indexes_that_need_reprocess
;
18501 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18503 bool need_reprocess
;
18505 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18506 info_ptr
, &need_reprocess
);
18507 if (need_reprocess
)
18508 indexes_that_need_reprocess
.push_back (i
);
18511 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18512 if (attr
!= nullptr)
18513 cu
->str_offsets_base
= DW_UNSND (attr
);
18515 auto maybe_addr_base
= lookup_addr_base(die
);
18516 if (maybe_addr_base
.has_value ())
18517 cu
->addr_base
= *maybe_addr_base
;
18518 for (int index
: indexes_that_need_reprocess
)
18519 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18521 *has_children
= abbrev
->has_children
;
18525 /* Read a die and all its attributes.
18526 Set DIEP to point to a newly allocated die with its information,
18527 except for its child, sibling, and parent fields.
18528 Set HAS_CHILDREN to tell whether the die has children or not. */
18530 static const gdb_byte
*
18531 read_full_die (const struct die_reader_specs
*reader
,
18532 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18535 const gdb_byte
*result
;
18537 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18539 if (dwarf_die_debug
)
18541 fprintf_unfiltered (gdb_stdlog
,
18542 "Read die from %s@0x%x of %s:\n",
18543 get_section_name (reader
->die_section
),
18544 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18545 bfd_get_filename (reader
->abfd
));
18546 dump_die (*diep
, dwarf_die_debug
);
18552 /* Abbreviation tables.
18554 In DWARF version 2, the description of the debugging information is
18555 stored in a separate .debug_abbrev section. Before we read any
18556 dies from a section we read in all abbreviations and install them
18557 in a hash table. */
18559 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18561 struct abbrev_info
*
18562 abbrev_table::alloc_abbrev ()
18564 struct abbrev_info
*abbrev
;
18566 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18567 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18572 /* Add an abbreviation to the table. */
18575 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18576 struct abbrev_info
*abbrev
)
18578 unsigned int hash_number
;
18580 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18581 abbrev
->next
= m_abbrevs
[hash_number
];
18582 m_abbrevs
[hash_number
] = abbrev
;
18585 /* Look up an abbrev in the table.
18586 Returns NULL if the abbrev is not found. */
18588 struct abbrev_info
*
18589 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18591 unsigned int hash_number
;
18592 struct abbrev_info
*abbrev
;
18594 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18595 abbrev
= m_abbrevs
[hash_number
];
18599 if (abbrev
->number
== abbrev_number
)
18601 abbrev
= abbrev
->next
;
18606 /* Read in an abbrev table. */
18608 static abbrev_table_up
18609 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18610 struct dwarf2_section_info
*section
,
18611 sect_offset sect_off
)
18613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18614 bfd
*abfd
= get_section_bfd_owner (section
);
18615 const gdb_byte
*abbrev_ptr
;
18616 struct abbrev_info
*cur_abbrev
;
18617 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18618 unsigned int abbrev_form
;
18619 std::vector
<struct attr_abbrev
> cur_attrs
;
18621 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18623 dwarf2_read_section (objfile
, section
);
18624 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18625 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18626 abbrev_ptr
+= bytes_read
;
18628 /* Loop until we reach an abbrev number of 0. */
18629 while (abbrev_number
)
18631 cur_attrs
.clear ();
18632 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18634 /* read in abbrev header */
18635 cur_abbrev
->number
= abbrev_number
;
18637 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18638 abbrev_ptr
+= bytes_read
;
18639 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18642 /* now read in declarations */
18645 LONGEST implicit_const
;
18647 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18648 abbrev_ptr
+= bytes_read
;
18649 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18650 abbrev_ptr
+= bytes_read
;
18651 if (abbrev_form
== DW_FORM_implicit_const
)
18653 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18655 abbrev_ptr
+= bytes_read
;
18659 /* Initialize it due to a false compiler warning. */
18660 implicit_const
= -1;
18663 if (abbrev_name
== 0)
18666 cur_attrs
.emplace_back ();
18667 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18668 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18669 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18670 cur_attr
.implicit_const
= implicit_const
;
18671 ++cur_abbrev
->num_attrs
;
18674 cur_abbrev
->attrs
=
18675 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18676 cur_abbrev
->num_attrs
);
18677 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18678 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18680 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18682 /* Get next abbreviation.
18683 Under Irix6 the abbreviations for a compilation unit are not
18684 always properly terminated with an abbrev number of 0.
18685 Exit loop if we encounter an abbreviation which we have
18686 already read (which means we are about to read the abbreviations
18687 for the next compile unit) or if the end of the abbreviation
18688 table is reached. */
18689 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18691 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18692 abbrev_ptr
+= bytes_read
;
18693 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18697 return abbrev_table
;
18700 /* Returns nonzero if TAG represents a type that we might generate a partial
18704 is_type_tag_for_partial (int tag
)
18709 /* Some types that would be reasonable to generate partial symbols for,
18710 that we don't at present. */
18711 case DW_TAG_array_type
:
18712 case DW_TAG_file_type
:
18713 case DW_TAG_ptr_to_member_type
:
18714 case DW_TAG_set_type
:
18715 case DW_TAG_string_type
:
18716 case DW_TAG_subroutine_type
:
18718 case DW_TAG_base_type
:
18719 case DW_TAG_class_type
:
18720 case DW_TAG_interface_type
:
18721 case DW_TAG_enumeration_type
:
18722 case DW_TAG_structure_type
:
18723 case DW_TAG_subrange_type
:
18724 case DW_TAG_typedef
:
18725 case DW_TAG_union_type
:
18732 /* Load all DIEs that are interesting for partial symbols into memory. */
18734 static struct partial_die_info
*
18735 load_partial_dies (const struct die_reader_specs
*reader
,
18736 const gdb_byte
*info_ptr
, int building_psymtab
)
18738 struct dwarf2_cu
*cu
= reader
->cu
;
18739 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18740 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18741 unsigned int bytes_read
;
18742 unsigned int load_all
= 0;
18743 int nesting_level
= 1;
18748 gdb_assert (cu
->per_cu
!= NULL
);
18749 if (cu
->per_cu
->load_all_dies
)
18753 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18757 &cu
->comp_unit_obstack
,
18758 hashtab_obstack_allocate
,
18759 dummy_obstack_deallocate
);
18763 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18765 /* A NULL abbrev means the end of a series of children. */
18766 if (abbrev
== NULL
)
18768 if (--nesting_level
== 0)
18771 info_ptr
+= bytes_read
;
18772 last_die
= parent_die
;
18773 parent_die
= parent_die
->die_parent
;
18777 /* Check for template arguments. We never save these; if
18778 they're seen, we just mark the parent, and go on our way. */
18779 if (parent_die
!= NULL
18780 && cu
->language
== language_cplus
18781 && (abbrev
->tag
== DW_TAG_template_type_param
18782 || abbrev
->tag
== DW_TAG_template_value_param
))
18784 parent_die
->has_template_arguments
= 1;
18788 /* We don't need a partial DIE for the template argument. */
18789 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18794 /* We only recurse into c++ subprograms looking for template arguments.
18795 Skip their other children. */
18797 && cu
->language
== language_cplus
18798 && parent_die
!= NULL
18799 && parent_die
->tag
== DW_TAG_subprogram
)
18801 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18805 /* Check whether this DIE is interesting enough to save. Normally
18806 we would not be interested in members here, but there may be
18807 later variables referencing them via DW_AT_specification (for
18808 static members). */
18810 && !is_type_tag_for_partial (abbrev
->tag
)
18811 && abbrev
->tag
!= DW_TAG_constant
18812 && abbrev
->tag
!= DW_TAG_enumerator
18813 && abbrev
->tag
!= DW_TAG_subprogram
18814 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18815 && abbrev
->tag
!= DW_TAG_lexical_block
18816 && abbrev
->tag
!= DW_TAG_variable
18817 && abbrev
->tag
!= DW_TAG_namespace
18818 && abbrev
->tag
!= DW_TAG_module
18819 && abbrev
->tag
!= DW_TAG_member
18820 && abbrev
->tag
!= DW_TAG_imported_unit
18821 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18823 /* Otherwise we skip to the next sibling, if any. */
18824 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18828 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18831 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18833 /* This two-pass algorithm for processing partial symbols has a
18834 high cost in cache pressure. Thus, handle some simple cases
18835 here which cover the majority of C partial symbols. DIEs
18836 which neither have specification tags in them, nor could have
18837 specification tags elsewhere pointing at them, can simply be
18838 processed and discarded.
18840 This segment is also optional; scan_partial_symbols and
18841 add_partial_symbol will handle these DIEs if we chain
18842 them in normally. When compilers which do not emit large
18843 quantities of duplicate debug information are more common,
18844 this code can probably be removed. */
18846 /* Any complete simple types at the top level (pretty much all
18847 of them, for a language without namespaces), can be processed
18849 if (parent_die
== NULL
18850 && pdi
.has_specification
== 0
18851 && pdi
.is_declaration
== 0
18852 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18853 || pdi
.tag
== DW_TAG_base_type
18854 || pdi
.tag
== DW_TAG_subrange_type
))
18856 if (building_psymtab
&& pdi
.name
!= NULL
)
18857 add_psymbol_to_list (pdi
.name
, false,
18858 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18859 psymbol_placement::STATIC
,
18860 0, cu
->language
, objfile
);
18861 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18865 /* The exception for DW_TAG_typedef with has_children above is
18866 a workaround of GCC PR debug/47510. In the case of this complaint
18867 type_name_or_error will error on such types later.
18869 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18870 it could not find the child DIEs referenced later, this is checked
18871 above. In correct DWARF DW_TAG_typedef should have no children. */
18873 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18874 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18875 "- DIE at %s [in module %s]"),
18876 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18878 /* If we're at the second level, and we're an enumerator, and
18879 our parent has no specification (meaning possibly lives in a
18880 namespace elsewhere), then we can add the partial symbol now
18881 instead of queueing it. */
18882 if (pdi
.tag
== DW_TAG_enumerator
18883 && parent_die
!= NULL
18884 && parent_die
->die_parent
== NULL
18885 && parent_die
->tag
== DW_TAG_enumeration_type
18886 && parent_die
->has_specification
== 0)
18888 if (pdi
.name
== NULL
)
18889 complaint (_("malformed enumerator DIE ignored"));
18890 else if (building_psymtab
)
18891 add_psymbol_to_list (pdi
.name
, false,
18892 VAR_DOMAIN
, LOC_CONST
, -1,
18893 cu
->language
== language_cplus
18894 ? psymbol_placement::GLOBAL
18895 : psymbol_placement::STATIC
,
18896 0, cu
->language
, objfile
);
18898 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18902 struct partial_die_info
*part_die
18903 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18905 /* We'll save this DIE so link it in. */
18906 part_die
->die_parent
= parent_die
;
18907 part_die
->die_sibling
= NULL
;
18908 part_die
->die_child
= NULL
;
18910 if (last_die
&& last_die
== parent_die
)
18911 last_die
->die_child
= part_die
;
18913 last_die
->die_sibling
= part_die
;
18915 last_die
= part_die
;
18917 if (first_die
== NULL
)
18918 first_die
= part_die
;
18920 /* Maybe add the DIE to the hash table. Not all DIEs that we
18921 find interesting need to be in the hash table, because we
18922 also have the parent/sibling/child chains; only those that we
18923 might refer to by offset later during partial symbol reading.
18925 For now this means things that might have be the target of a
18926 DW_AT_specification, DW_AT_abstract_origin, or
18927 DW_AT_extension. DW_AT_extension will refer only to
18928 namespaces; DW_AT_abstract_origin refers to functions (and
18929 many things under the function DIE, but we do not recurse
18930 into function DIEs during partial symbol reading) and
18931 possibly variables as well; DW_AT_specification refers to
18932 declarations. Declarations ought to have the DW_AT_declaration
18933 flag. It happens that GCC forgets to put it in sometimes, but
18934 only for functions, not for types.
18936 Adding more things than necessary to the hash table is harmless
18937 except for the performance cost. Adding too few will result in
18938 wasted time in find_partial_die, when we reread the compilation
18939 unit with load_all_dies set. */
18942 || abbrev
->tag
== DW_TAG_constant
18943 || abbrev
->tag
== DW_TAG_subprogram
18944 || abbrev
->tag
== DW_TAG_variable
18945 || abbrev
->tag
== DW_TAG_namespace
18946 || part_die
->is_declaration
)
18950 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18951 to_underlying (part_die
->sect_off
),
18956 /* For some DIEs we want to follow their children (if any). For C
18957 we have no reason to follow the children of structures; for other
18958 languages we have to, so that we can get at method physnames
18959 to infer fully qualified class names, for DW_AT_specification,
18960 and for C++ template arguments. For C++, we also look one level
18961 inside functions to find template arguments (if the name of the
18962 function does not already contain the template arguments).
18964 For Ada and Fortran, we need to scan the children of subprograms
18965 and lexical blocks as well because these languages allow the
18966 definition of nested entities that could be interesting for the
18967 debugger, such as nested subprograms for instance. */
18968 if (last_die
->has_children
18970 || last_die
->tag
== DW_TAG_namespace
18971 || last_die
->tag
== DW_TAG_module
18972 || last_die
->tag
== DW_TAG_enumeration_type
18973 || (cu
->language
== language_cplus
18974 && last_die
->tag
== DW_TAG_subprogram
18975 && (last_die
->name
== NULL
18976 || strchr (last_die
->name
, '<') == NULL
))
18977 || (cu
->language
!= language_c
18978 && (last_die
->tag
== DW_TAG_class_type
18979 || last_die
->tag
== DW_TAG_interface_type
18980 || last_die
->tag
== DW_TAG_structure_type
18981 || last_die
->tag
== DW_TAG_union_type
))
18982 || ((cu
->language
== language_ada
18983 || cu
->language
== language_fortran
)
18984 && (last_die
->tag
== DW_TAG_subprogram
18985 || last_die
->tag
== DW_TAG_lexical_block
))))
18988 parent_die
= last_die
;
18992 /* Otherwise we skip to the next sibling, if any. */
18993 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18995 /* Back to the top, do it again. */
18999 partial_die_info::partial_die_info (sect_offset sect_off_
,
19000 struct abbrev_info
*abbrev
)
19001 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
19005 /* Read a minimal amount of information into the minimal die structure.
19006 INFO_PTR should point just after the initial uleb128 of a DIE. */
19009 partial_die_info::read (const struct die_reader_specs
*reader
,
19010 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
19012 struct dwarf2_cu
*cu
= reader
->cu
;
19013 struct dwarf2_per_objfile
*dwarf2_per_objfile
19014 = cu
->per_cu
->dwarf2_per_objfile
;
19016 int has_low_pc_attr
= 0;
19017 int has_high_pc_attr
= 0;
19018 int high_pc_relative
= 0;
19020 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
19021 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
19023 bool need_reprocess
;
19024 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
19025 info_ptr
, &need_reprocess
);
19026 /* String and address offsets that need to do the reprocessing have
19027 already been read at this point, so there is no need to wait until
19028 the loop terminates to do the reprocessing. */
19029 if (need_reprocess
)
19030 read_attribute_reprocess (reader
, &attr_vec
[i
]);
19031 attribute
&attr
= attr_vec
[i
];
19032 /* Store the data if it is of an attribute we want to keep in a
19033 partial symbol table. */
19039 case DW_TAG_compile_unit
:
19040 case DW_TAG_partial_unit
:
19041 case DW_TAG_type_unit
:
19042 /* Compilation units have a DW_AT_name that is a filename, not
19043 a source language identifier. */
19044 case DW_TAG_enumeration_type
:
19045 case DW_TAG_enumerator
:
19046 /* These tags always have simple identifiers already; no need
19047 to canonicalize them. */
19048 name
= DW_STRING (&attr
);
19052 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19055 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
19056 &objfile
->per_bfd
->storage_obstack
);
19061 case DW_AT_linkage_name
:
19062 case DW_AT_MIPS_linkage_name
:
19063 /* Note that both forms of linkage name might appear. We
19064 assume they will be the same, and we only store the last
19066 linkage_name
= DW_STRING (&attr
);
19069 has_low_pc_attr
= 1;
19070 lowpc
= attr_value_as_address (&attr
);
19072 case DW_AT_high_pc
:
19073 has_high_pc_attr
= 1;
19074 highpc
= attr_value_as_address (&attr
);
19075 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19076 high_pc_relative
= 1;
19078 case DW_AT_location
:
19079 /* Support the .debug_loc offsets. */
19080 if (attr_form_is_block (&attr
))
19082 d
.locdesc
= DW_BLOCK (&attr
);
19084 else if (attr_form_is_section_offset (&attr
))
19086 dwarf2_complex_location_expr_complaint ();
19090 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19091 "partial symbol information");
19094 case DW_AT_external
:
19095 is_external
= DW_UNSND (&attr
);
19097 case DW_AT_declaration
:
19098 is_declaration
= DW_UNSND (&attr
);
19103 case DW_AT_abstract_origin
:
19104 case DW_AT_specification
:
19105 case DW_AT_extension
:
19106 has_specification
= 1;
19107 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19108 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19109 || cu
->per_cu
->is_dwz
);
19111 case DW_AT_sibling
:
19112 /* Ignore absolute siblings, they might point outside of
19113 the current compile unit. */
19114 if (attr
.form
== DW_FORM_ref_addr
)
19115 complaint (_("ignoring absolute DW_AT_sibling"));
19118 const gdb_byte
*buffer
= reader
->buffer
;
19119 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19120 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19122 if (sibling_ptr
< info_ptr
)
19123 complaint (_("DW_AT_sibling points backwards"));
19124 else if (sibling_ptr
> reader
->buffer_end
)
19125 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19127 sibling
= sibling_ptr
;
19130 case DW_AT_byte_size
:
19133 case DW_AT_const_value
:
19134 has_const_value
= 1;
19136 case DW_AT_calling_convention
:
19137 /* DWARF doesn't provide a way to identify a program's source-level
19138 entry point. DW_AT_calling_convention attributes are only meant
19139 to describe functions' calling conventions.
19141 However, because it's a necessary piece of information in
19142 Fortran, and before DWARF 4 DW_CC_program was the only
19143 piece of debugging information whose definition refers to
19144 a 'main program' at all, several compilers marked Fortran
19145 main programs with DW_CC_program --- even when those
19146 functions use the standard calling conventions.
19148 Although DWARF now specifies a way to provide this
19149 information, we support this practice for backward
19151 if (DW_UNSND (&attr
) == DW_CC_program
19152 && cu
->language
== language_fortran
)
19153 main_subprogram
= 1;
19156 if (DW_UNSND (&attr
) == DW_INL_inlined
19157 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19158 may_be_inlined
= 1;
19162 if (tag
== DW_TAG_imported_unit
)
19164 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19165 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19166 || cu
->per_cu
->is_dwz
);
19170 case DW_AT_main_subprogram
:
19171 main_subprogram
= DW_UNSND (&attr
);
19176 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19177 but that requires a full DIE, so instead we just
19179 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19180 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19181 + (need_ranges_base
19185 /* Value of the DW_AT_ranges attribute is the offset in the
19186 .debug_ranges section. */
19187 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19198 /* For Ada, if both the name and the linkage name appear, we prefer
19199 the latter. This lets "catch exception" work better, regardless
19200 of the order in which the name and linkage name were emitted.
19201 Really, though, this is just a workaround for the fact that gdb
19202 doesn't store both the name and the linkage name. */
19203 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19204 name
= linkage_name
;
19206 if (high_pc_relative
)
19209 if (has_low_pc_attr
&& has_high_pc_attr
)
19211 /* When using the GNU linker, .gnu.linkonce. sections are used to
19212 eliminate duplicate copies of functions and vtables and such.
19213 The linker will arbitrarily choose one and discard the others.
19214 The AT_*_pc values for such functions refer to local labels in
19215 these sections. If the section from that file was discarded, the
19216 labels are not in the output, so the relocs get a value of 0.
19217 If this is a discarded function, mark the pc bounds as invalid,
19218 so that GDB will ignore it. */
19219 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19221 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19222 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19224 complaint (_("DW_AT_low_pc %s is zero "
19225 "for DIE at %s [in module %s]"),
19226 paddress (gdbarch
, lowpc
),
19227 sect_offset_str (sect_off
),
19228 objfile_name (objfile
));
19230 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19231 else if (lowpc
>= highpc
)
19233 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19234 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19236 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19237 "for DIE at %s [in module %s]"),
19238 paddress (gdbarch
, lowpc
),
19239 paddress (gdbarch
, highpc
),
19240 sect_offset_str (sect_off
),
19241 objfile_name (objfile
));
19250 /* Find a cached partial DIE at OFFSET in CU. */
19252 struct partial_die_info
*
19253 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19255 struct partial_die_info
*lookup_die
= NULL
;
19256 struct partial_die_info
part_die (sect_off
);
19258 lookup_die
= ((struct partial_die_info
*)
19259 htab_find_with_hash (partial_dies
, &part_die
,
19260 to_underlying (sect_off
)));
19265 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19266 except in the case of .debug_types DIEs which do not reference
19267 outside their CU (they do however referencing other types via
19268 DW_FORM_ref_sig8). */
19270 static const struct cu_partial_die_info
19271 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19273 struct dwarf2_per_objfile
*dwarf2_per_objfile
19274 = cu
->per_cu
->dwarf2_per_objfile
;
19275 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19276 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19277 struct partial_die_info
*pd
= NULL
;
19279 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19280 && offset_in_cu_p (&cu
->header
, sect_off
))
19282 pd
= cu
->find_partial_die (sect_off
);
19285 /* We missed recording what we needed.
19286 Load all dies and try again. */
19287 per_cu
= cu
->per_cu
;
19291 /* TUs don't reference other CUs/TUs (except via type signatures). */
19292 if (cu
->per_cu
->is_debug_types
)
19294 error (_("Dwarf Error: Type Unit at offset %s contains"
19295 " external reference to offset %s [in module %s].\n"),
19296 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19297 bfd_get_filename (objfile
->obfd
));
19299 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19300 dwarf2_per_objfile
);
19302 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19303 load_partial_comp_unit (per_cu
);
19305 per_cu
->cu
->last_used
= 0;
19306 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19309 /* If we didn't find it, and not all dies have been loaded,
19310 load them all and try again. */
19312 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19314 per_cu
->load_all_dies
= 1;
19316 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19317 THIS_CU->cu may already be in use. So we can't just free it and
19318 replace its DIEs with the ones we read in. Instead, we leave those
19319 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19320 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19322 load_partial_comp_unit (per_cu
);
19324 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19328 internal_error (__FILE__
, __LINE__
,
19329 _("could not find partial DIE %s "
19330 "in cache [from module %s]\n"),
19331 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19332 return { per_cu
->cu
, pd
};
19335 /* See if we can figure out if the class lives in a namespace. We do
19336 this by looking for a member function; its demangled name will
19337 contain namespace info, if there is any. */
19340 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19341 struct dwarf2_cu
*cu
)
19343 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19344 what template types look like, because the demangler
19345 frequently doesn't give the same name as the debug info. We
19346 could fix this by only using the demangled name to get the
19347 prefix (but see comment in read_structure_type). */
19349 struct partial_die_info
*real_pdi
;
19350 struct partial_die_info
*child_pdi
;
19352 /* If this DIE (this DIE's specification, if any) has a parent, then
19353 we should not do this. We'll prepend the parent's fully qualified
19354 name when we create the partial symbol. */
19356 real_pdi
= struct_pdi
;
19357 while (real_pdi
->has_specification
)
19359 auto res
= find_partial_die (real_pdi
->spec_offset
,
19360 real_pdi
->spec_is_dwz
, cu
);
19361 real_pdi
= res
.pdi
;
19365 if (real_pdi
->die_parent
!= NULL
)
19368 for (child_pdi
= struct_pdi
->die_child
;
19370 child_pdi
= child_pdi
->die_sibling
)
19372 if (child_pdi
->tag
== DW_TAG_subprogram
19373 && child_pdi
->linkage_name
!= NULL
)
19375 gdb::unique_xmalloc_ptr
<char> actual_class_name
19376 (language_class_name_from_physname (cu
->language_defn
,
19377 child_pdi
->linkage_name
));
19378 if (actual_class_name
!= NULL
)
19380 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19382 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19383 actual_class_name
.get ());
19391 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19393 /* Once we've fixed up a die, there's no point in doing so again.
19394 This also avoids a memory leak if we were to call
19395 guess_partial_die_structure_name multiple times. */
19399 /* If we found a reference attribute and the DIE has no name, try
19400 to find a name in the referred to DIE. */
19402 if (name
== NULL
&& has_specification
)
19404 struct partial_die_info
*spec_die
;
19406 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19407 spec_die
= res
.pdi
;
19410 spec_die
->fixup (cu
);
19412 if (spec_die
->name
)
19414 name
= spec_die
->name
;
19416 /* Copy DW_AT_external attribute if it is set. */
19417 if (spec_die
->is_external
)
19418 is_external
= spec_die
->is_external
;
19422 /* Set default names for some unnamed DIEs. */
19424 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19425 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19427 /* If there is no parent die to provide a namespace, and there are
19428 children, see if we can determine the namespace from their linkage
19430 if (cu
->language
== language_cplus
19431 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19432 && die_parent
== NULL
19434 && (tag
== DW_TAG_class_type
19435 || tag
== DW_TAG_structure_type
19436 || tag
== DW_TAG_union_type
))
19437 guess_partial_die_structure_name (this, cu
);
19439 /* GCC might emit a nameless struct or union that has a linkage
19440 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19442 && (tag
== DW_TAG_class_type
19443 || tag
== DW_TAG_interface_type
19444 || tag
== DW_TAG_structure_type
19445 || tag
== DW_TAG_union_type
)
19446 && linkage_name
!= NULL
)
19448 gdb::unique_xmalloc_ptr
<char> demangled
19449 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19450 if (demangled
!= nullptr)
19454 /* Strip any leading namespaces/classes, keep only the base name.
19455 DW_AT_name for named DIEs does not contain the prefixes. */
19456 base
= strrchr (demangled
.get (), ':');
19457 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19460 base
= demangled
.get ();
19462 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19463 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19470 /* Process the attributes that had to be skipped in the first round. These
19471 attributes are the ones that need str_offsets_base or addr_base attributes.
19472 They could not have been processed in the first round, because at the time
19473 the values of str_offsets_base or addr_base may not have been known. */
19474 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19475 struct attribute
*attr
)
19477 struct dwarf2_cu
*cu
= reader
->cu
;
19478 switch (attr
->form
)
19480 case DW_FORM_addrx
:
19481 case DW_FORM_GNU_addr_index
:
19482 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19485 case DW_FORM_strx1
:
19486 case DW_FORM_strx2
:
19487 case DW_FORM_strx3
:
19488 case DW_FORM_strx4
:
19489 case DW_FORM_GNU_str_index
:
19491 unsigned int str_index
= DW_UNSND (attr
);
19492 if (reader
->dwo_file
!= NULL
)
19494 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19495 DW_STRING_IS_CANONICAL (attr
) = 0;
19499 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19500 DW_STRING_IS_CANONICAL (attr
) = 0;
19505 gdb_assert_not_reached (_("Unexpected DWARF form."));
19509 /* Read an attribute value described by an attribute form. */
19511 static const gdb_byte
*
19512 read_attribute_value (const struct die_reader_specs
*reader
,
19513 struct attribute
*attr
, unsigned form
,
19514 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19515 bool *need_reprocess
)
19517 struct dwarf2_cu
*cu
= reader
->cu
;
19518 struct dwarf2_per_objfile
*dwarf2_per_objfile
19519 = cu
->per_cu
->dwarf2_per_objfile
;
19520 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19521 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19522 bfd
*abfd
= reader
->abfd
;
19523 struct comp_unit_head
*cu_header
= &cu
->header
;
19524 unsigned int bytes_read
;
19525 struct dwarf_block
*blk
;
19526 *need_reprocess
= false;
19528 attr
->form
= (enum dwarf_form
) form
;
19531 case DW_FORM_ref_addr
:
19532 if (cu
->header
.version
== 2)
19533 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19535 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19536 &cu
->header
, &bytes_read
);
19537 info_ptr
+= bytes_read
;
19539 case DW_FORM_GNU_ref_alt
:
19540 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19541 info_ptr
+= bytes_read
;
19544 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19545 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19546 info_ptr
+= bytes_read
;
19548 case DW_FORM_block2
:
19549 blk
= dwarf_alloc_block (cu
);
19550 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19552 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19553 info_ptr
+= blk
->size
;
19554 DW_BLOCK (attr
) = blk
;
19556 case DW_FORM_block4
:
19557 blk
= dwarf_alloc_block (cu
);
19558 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19560 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19561 info_ptr
+= blk
->size
;
19562 DW_BLOCK (attr
) = blk
;
19564 case DW_FORM_data2
:
19565 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19568 case DW_FORM_data4
:
19569 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19572 case DW_FORM_data8
:
19573 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19576 case DW_FORM_data16
:
19577 blk
= dwarf_alloc_block (cu
);
19579 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19581 DW_BLOCK (attr
) = blk
;
19583 case DW_FORM_sec_offset
:
19584 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19585 info_ptr
+= bytes_read
;
19587 case DW_FORM_string
:
19588 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19589 DW_STRING_IS_CANONICAL (attr
) = 0;
19590 info_ptr
+= bytes_read
;
19593 if (!cu
->per_cu
->is_dwz
)
19595 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19596 abfd
, info_ptr
, cu_header
,
19598 DW_STRING_IS_CANONICAL (attr
) = 0;
19599 info_ptr
+= bytes_read
;
19603 case DW_FORM_line_strp
:
19604 if (!cu
->per_cu
->is_dwz
)
19606 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19608 cu_header
, &bytes_read
);
19609 DW_STRING_IS_CANONICAL (attr
) = 0;
19610 info_ptr
+= bytes_read
;
19614 case DW_FORM_GNU_strp_alt
:
19616 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19617 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19620 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19622 DW_STRING_IS_CANONICAL (attr
) = 0;
19623 info_ptr
+= bytes_read
;
19626 case DW_FORM_exprloc
:
19627 case DW_FORM_block
:
19628 blk
= dwarf_alloc_block (cu
);
19629 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19630 info_ptr
+= bytes_read
;
19631 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19632 info_ptr
+= blk
->size
;
19633 DW_BLOCK (attr
) = blk
;
19635 case DW_FORM_block1
:
19636 blk
= dwarf_alloc_block (cu
);
19637 blk
->size
= read_1_byte (abfd
, info_ptr
);
19639 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19640 info_ptr
+= blk
->size
;
19641 DW_BLOCK (attr
) = blk
;
19643 case DW_FORM_data1
:
19644 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19648 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19651 case DW_FORM_flag_present
:
19652 DW_UNSND (attr
) = 1;
19654 case DW_FORM_sdata
:
19655 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19656 info_ptr
+= bytes_read
;
19658 case DW_FORM_udata
:
19659 case DW_FORM_rnglistx
:
19660 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19661 info_ptr
+= bytes_read
;
19664 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19665 + read_1_byte (abfd
, info_ptr
));
19669 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19670 + read_2_bytes (abfd
, info_ptr
));
19674 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19675 + read_4_bytes (abfd
, info_ptr
));
19679 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19680 + read_8_bytes (abfd
, info_ptr
));
19683 case DW_FORM_ref_sig8
:
19684 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19687 case DW_FORM_ref_udata
:
19688 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19689 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19690 info_ptr
+= bytes_read
;
19692 case DW_FORM_indirect
:
19693 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19694 info_ptr
+= bytes_read
;
19695 if (form
== DW_FORM_implicit_const
)
19697 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19698 info_ptr
+= bytes_read
;
19700 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19701 info_ptr
, need_reprocess
);
19703 case DW_FORM_implicit_const
:
19704 DW_SND (attr
) = implicit_const
;
19706 case DW_FORM_addrx
:
19707 case DW_FORM_GNU_addr_index
:
19708 *need_reprocess
= true;
19709 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19710 info_ptr
+= bytes_read
;
19713 case DW_FORM_strx1
:
19714 case DW_FORM_strx2
:
19715 case DW_FORM_strx3
:
19716 case DW_FORM_strx4
:
19717 case DW_FORM_GNU_str_index
:
19719 ULONGEST str_index
;
19720 if (form
== DW_FORM_strx1
)
19722 str_index
= read_1_byte (abfd
, info_ptr
);
19725 else if (form
== DW_FORM_strx2
)
19727 str_index
= read_2_bytes (abfd
, info_ptr
);
19730 else if (form
== DW_FORM_strx3
)
19732 str_index
= read_3_bytes (abfd
, info_ptr
);
19735 else if (form
== DW_FORM_strx4
)
19737 str_index
= read_4_bytes (abfd
, info_ptr
);
19742 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19743 info_ptr
+= bytes_read
;
19745 *need_reprocess
= true;
19746 DW_UNSND (attr
) = str_index
;
19750 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19751 dwarf_form_name (form
),
19752 bfd_get_filename (abfd
));
19756 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19757 attr
->form
= DW_FORM_GNU_ref_alt
;
19759 /* We have seen instances where the compiler tried to emit a byte
19760 size attribute of -1 which ended up being encoded as an unsigned
19761 0xffffffff. Although 0xffffffff is technically a valid size value,
19762 an object of this size seems pretty unlikely so we can relatively
19763 safely treat these cases as if the size attribute was invalid and
19764 treat them as zero by default. */
19765 if (attr
->name
== DW_AT_byte_size
19766 && form
== DW_FORM_data4
19767 && DW_UNSND (attr
) >= 0xffffffff)
19770 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19771 hex_string (DW_UNSND (attr
)));
19772 DW_UNSND (attr
) = 0;
19778 /* Read an attribute described by an abbreviated attribute. */
19780 static const gdb_byte
*
19781 read_attribute (const struct die_reader_specs
*reader
,
19782 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19783 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19785 attr
->name
= abbrev
->name
;
19786 return read_attribute_value (reader
, attr
, abbrev
->form
,
19787 abbrev
->implicit_const
, info_ptr
,
19791 /* Read dwarf information from a buffer. */
19793 static unsigned int
19794 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19796 return bfd_get_8 (abfd
, buf
);
19800 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19802 return bfd_get_signed_8 (abfd
, buf
);
19805 static unsigned int
19806 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19808 return bfd_get_16 (abfd
, buf
);
19812 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19814 return bfd_get_signed_16 (abfd
, buf
);
19817 static unsigned int
19818 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19820 unsigned int result
= 0;
19821 for (int i
= 0; i
< 3; ++i
)
19823 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19825 result
|= ((unsigned int) byte
<< (i
* 8));
19830 static unsigned int
19831 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19833 return bfd_get_32 (abfd
, buf
);
19837 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19839 return bfd_get_signed_32 (abfd
, buf
);
19843 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19845 return bfd_get_64 (abfd
, buf
);
19849 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19850 unsigned int *bytes_read
)
19852 struct comp_unit_head
*cu_header
= &cu
->header
;
19853 CORE_ADDR retval
= 0;
19855 if (cu_header
->signed_addr_p
)
19857 switch (cu_header
->addr_size
)
19860 retval
= bfd_get_signed_16 (abfd
, buf
);
19863 retval
= bfd_get_signed_32 (abfd
, buf
);
19866 retval
= bfd_get_signed_64 (abfd
, buf
);
19869 internal_error (__FILE__
, __LINE__
,
19870 _("read_address: bad switch, signed [in module %s]"),
19871 bfd_get_filename (abfd
));
19876 switch (cu_header
->addr_size
)
19879 retval
= bfd_get_16 (abfd
, buf
);
19882 retval
= bfd_get_32 (abfd
, buf
);
19885 retval
= bfd_get_64 (abfd
, buf
);
19888 internal_error (__FILE__
, __LINE__
,
19889 _("read_address: bad switch, "
19890 "unsigned [in module %s]"),
19891 bfd_get_filename (abfd
));
19895 *bytes_read
= cu_header
->addr_size
;
19899 /* Read the initial length from a section. The (draft) DWARF 3
19900 specification allows the initial length to take up either 4 bytes
19901 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19902 bytes describe the length and all offsets will be 8 bytes in length
19905 An older, non-standard 64-bit format is also handled by this
19906 function. The older format in question stores the initial length
19907 as an 8-byte quantity without an escape value. Lengths greater
19908 than 2^32 aren't very common which means that the initial 4 bytes
19909 is almost always zero. Since a length value of zero doesn't make
19910 sense for the 32-bit format, this initial zero can be considered to
19911 be an escape value which indicates the presence of the older 64-bit
19912 format. As written, the code can't detect (old format) lengths
19913 greater than 4GB. If it becomes necessary to handle lengths
19914 somewhat larger than 4GB, we could allow other small values (such
19915 as the non-sensical values of 1, 2, and 3) to also be used as
19916 escape values indicating the presence of the old format.
19918 The value returned via bytes_read should be used to increment the
19919 relevant pointer after calling read_initial_length().
19921 [ Note: read_initial_length() and read_offset() are based on the
19922 document entitled "DWARF Debugging Information Format", revision
19923 3, draft 8, dated November 19, 2001. This document was obtained
19926 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19928 This document is only a draft and is subject to change. (So beware.)
19930 Details regarding the older, non-standard 64-bit format were
19931 determined empirically by examining 64-bit ELF files produced by
19932 the SGI toolchain on an IRIX 6.5 machine.
19934 - Kevin, July 16, 2002
19938 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19940 LONGEST length
= bfd_get_32 (abfd
, buf
);
19942 if (length
== 0xffffffff)
19944 length
= bfd_get_64 (abfd
, buf
+ 4);
19947 else if (length
== 0)
19949 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19950 length
= bfd_get_64 (abfd
, buf
);
19961 /* Cover function for read_initial_length.
19962 Returns the length of the object at BUF, and stores the size of the
19963 initial length in *BYTES_READ and stores the size that offsets will be in
19965 If the initial length size is not equivalent to that specified in
19966 CU_HEADER then issue a complaint.
19967 This is useful when reading non-comp-unit headers. */
19970 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19971 const struct comp_unit_head
*cu_header
,
19972 unsigned int *bytes_read
,
19973 unsigned int *offset_size
)
19975 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19977 gdb_assert (cu_header
->initial_length_size
== 4
19978 || cu_header
->initial_length_size
== 8
19979 || cu_header
->initial_length_size
== 12);
19981 if (cu_header
->initial_length_size
!= *bytes_read
)
19982 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19984 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19988 /* Read an offset from the data stream. The size of the offset is
19989 given by cu_header->offset_size. */
19992 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19993 const struct comp_unit_head
*cu_header
,
19994 unsigned int *bytes_read
)
19996 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19998 *bytes_read
= cu_header
->offset_size
;
20002 /* Read an offset from the data stream. */
20005 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
20007 LONGEST retval
= 0;
20009 switch (offset_size
)
20012 retval
= bfd_get_32 (abfd
, buf
);
20015 retval
= bfd_get_64 (abfd
, buf
);
20018 internal_error (__FILE__
, __LINE__
,
20019 _("read_offset_1: bad switch [in module %s]"),
20020 bfd_get_filename (abfd
));
20026 static const gdb_byte
*
20027 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
20029 /* If the size of a host char is 8 bits, we can return a pointer
20030 to the buffer, otherwise we have to copy the data to a buffer
20031 allocated on the temporary obstack. */
20032 gdb_assert (HOST_CHAR_BIT
== 8);
20036 static const char *
20037 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
20038 unsigned int *bytes_read_ptr
)
20040 /* If the size of a host char is 8 bits, we can return a pointer
20041 to the string, otherwise we have to copy the string to a buffer
20042 allocated on the temporary obstack. */
20043 gdb_assert (HOST_CHAR_BIT
== 8);
20046 *bytes_read_ptr
= 1;
20049 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
20050 return (const char *) buf
;
20053 /* Return pointer to string at section SECT offset STR_OFFSET with error
20054 reporting strings FORM_NAME and SECT_NAME. */
20056 static const char *
20057 read_indirect_string_at_offset_from (struct objfile
*objfile
,
20058 bfd
*abfd
, LONGEST str_offset
,
20059 struct dwarf2_section_info
*sect
,
20060 const char *form_name
,
20061 const char *sect_name
)
20063 dwarf2_read_section (objfile
, sect
);
20064 if (sect
->buffer
== NULL
)
20065 error (_("%s used without %s section [in module %s]"),
20066 form_name
, sect_name
, bfd_get_filename (abfd
));
20067 if (str_offset
>= sect
->size
)
20068 error (_("%s pointing outside of %s section [in module %s]"),
20069 form_name
, sect_name
, bfd_get_filename (abfd
));
20070 gdb_assert (HOST_CHAR_BIT
== 8);
20071 if (sect
->buffer
[str_offset
] == '\0')
20073 return (const char *) (sect
->buffer
+ str_offset
);
20076 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20078 static const char *
20079 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20080 bfd
*abfd
, LONGEST str_offset
)
20082 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20084 &dwarf2_per_objfile
->str
,
20085 "DW_FORM_strp", ".debug_str");
20088 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
20090 static const char *
20091 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20092 bfd
*abfd
, LONGEST str_offset
)
20094 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20096 &dwarf2_per_objfile
->line_str
,
20097 "DW_FORM_line_strp",
20098 ".debug_line_str");
20101 /* Read a string at offset STR_OFFSET in the .debug_str section from
20102 the .dwz file DWZ. Throw an error if the offset is too large. If
20103 the string consists of a single NUL byte, return NULL; otherwise
20104 return a pointer to the string. */
20106 static const char *
20107 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20108 LONGEST str_offset
)
20110 dwarf2_read_section (objfile
, &dwz
->str
);
20112 if (dwz
->str
.buffer
== NULL
)
20113 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20114 "section [in module %s]"),
20115 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20116 if (str_offset
>= dwz
->str
.size
)
20117 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20118 ".debug_str section [in module %s]"),
20119 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20120 gdb_assert (HOST_CHAR_BIT
== 8);
20121 if (dwz
->str
.buffer
[str_offset
] == '\0')
20123 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20126 /* Return pointer to string at .debug_str offset as read from BUF.
20127 BUF is assumed to be in a compilation unit described by CU_HEADER.
20128 Return *BYTES_READ_PTR count of bytes read from BUF. */
20130 static const char *
20131 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20132 const gdb_byte
*buf
,
20133 const struct comp_unit_head
*cu_header
,
20134 unsigned int *bytes_read_ptr
)
20136 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20138 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20141 /* Return pointer to string at .debug_line_str offset as read from BUF.
20142 BUF is assumed to be in a compilation unit described by CU_HEADER.
20143 Return *BYTES_READ_PTR count of bytes read from BUF. */
20145 static const char *
20146 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20147 bfd
*abfd
, const gdb_byte
*buf
,
20148 const struct comp_unit_head
*cu_header
,
20149 unsigned int *bytes_read_ptr
)
20151 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20153 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20158 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20159 unsigned int *bytes_read_ptr
)
20162 unsigned int num_read
;
20164 unsigned char byte
;
20171 byte
= bfd_get_8 (abfd
, buf
);
20174 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20175 if ((byte
& 128) == 0)
20181 *bytes_read_ptr
= num_read
;
20186 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20187 unsigned int *bytes_read_ptr
)
20190 int shift
, num_read
;
20191 unsigned char byte
;
20198 byte
= bfd_get_8 (abfd
, buf
);
20201 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20203 if ((byte
& 128) == 0)
20208 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20209 result
|= -(((ULONGEST
) 1) << shift
);
20210 *bytes_read_ptr
= num_read
;
20214 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20215 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20216 ADDR_SIZE is the size of addresses from the CU header. */
20219 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20220 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
20223 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20224 bfd
*abfd
= objfile
->obfd
;
20225 const gdb_byte
*info_ptr
;
20226 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20228 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20229 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20230 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20231 objfile_name (objfile
));
20232 if (addr_base_or_zero
+ addr_index
* addr_size
20233 >= dwarf2_per_objfile
->addr
.size
)
20234 error (_("DW_FORM_addr_index pointing outside of "
20235 ".debug_addr section [in module %s]"),
20236 objfile_name (objfile
));
20237 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20238 + addr_base_or_zero
+ addr_index
* addr_size
);
20239 if (addr_size
== 4)
20240 return bfd_get_32 (abfd
, info_ptr
);
20242 return bfd_get_64 (abfd
, info_ptr
);
20245 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20248 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20250 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20251 cu
->addr_base
, cu
->header
.addr_size
);
20254 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20257 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20258 unsigned int *bytes_read
)
20260 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20261 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20263 return read_addr_index (cu
, addr_index
);
20266 /* Data structure to pass results from dwarf2_read_addr_index_reader
20267 back to dwarf2_read_addr_index. */
20269 struct dwarf2_read_addr_index_data
20271 gdb::optional
<ULONGEST
> addr_base
;
20275 /* die_reader_func for dwarf2_read_addr_index. */
20278 dwarf2_read_addr_index_reader (const struct die_reader_specs
*reader
,
20279 const gdb_byte
*info_ptr
,
20280 struct die_info
*comp_unit_die
,
20284 struct dwarf2_cu
*cu
= reader
->cu
;
20285 struct dwarf2_read_addr_index_data
*aidata
=
20286 (struct dwarf2_read_addr_index_data
*) data
;
20288 aidata
->addr_base
= cu
->addr_base
;
20289 aidata
->addr_size
= cu
->header
.addr_size
;
20292 /* Given an index in .debug_addr, fetch the value.
20293 NOTE: This can be called during dwarf expression evaluation,
20294 long after the debug information has been read, and thus per_cu->cu
20295 may no longer exist. */
20298 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20299 unsigned int addr_index
)
20301 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20302 struct dwarf2_cu
*cu
= per_cu
->cu
;
20303 gdb::optional
<ULONGEST
> addr_base
;
20306 /* We need addr_base and addr_size.
20307 If we don't have PER_CU->cu, we have to get it.
20308 Nasty, but the alternative is storing the needed info in PER_CU,
20309 which at this point doesn't seem justified: it's not clear how frequently
20310 it would get used and it would increase the size of every PER_CU.
20311 Entry points like dwarf2_per_cu_addr_size do a similar thing
20312 so we're not in uncharted territory here.
20313 Alas we need to be a bit more complicated as addr_base is contained
20316 We don't need to read the entire CU(/TU).
20317 We just need the header and top level die.
20319 IWBN to use the aging mechanism to let us lazily later discard the CU.
20320 For now we skip this optimization. */
20324 addr_base
= cu
->addr_base
;
20325 addr_size
= cu
->header
.addr_size
;
20329 struct dwarf2_read_addr_index_data aidata
;
20331 /* Note: We can't use init_cutu_and_read_dies_simple here,
20332 we need addr_base. */
20333 init_cutu_and_read_dies (per_cu
, NULL
, 0, 0, false,
20334 dwarf2_read_addr_index_reader
, &aidata
);
20335 addr_base
= aidata
.addr_base
;
20336 addr_size
= aidata
.addr_size
;
20339 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20343 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20344 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20347 static const char *
20348 read_str_index (struct dwarf2_cu
*cu
,
20349 struct dwarf2_section_info
*str_section
,
20350 struct dwarf2_section_info
*str_offsets_section
,
20351 ULONGEST str_offsets_base
, ULONGEST str_index
)
20353 struct dwarf2_per_objfile
*dwarf2_per_objfile
20354 = cu
->per_cu
->dwarf2_per_objfile
;
20355 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20356 const char *objf_name
= objfile_name (objfile
);
20357 bfd
*abfd
= objfile
->obfd
;
20358 const gdb_byte
*info_ptr
;
20359 ULONGEST str_offset
;
20360 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20362 dwarf2_read_section (objfile
, str_section
);
20363 dwarf2_read_section (objfile
, str_offsets_section
);
20364 if (str_section
->buffer
== NULL
)
20365 error (_("%s used without %s section"
20366 " in CU at offset %s [in module %s]"),
20367 form_name
, get_section_name (str_section
),
20368 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20369 if (str_offsets_section
->buffer
== NULL
)
20370 error (_("%s used without %s section"
20371 " in CU at offset %s [in module %s]"),
20372 form_name
, get_section_name (str_section
),
20373 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20374 info_ptr
= (str_offsets_section
->buffer
20376 + str_index
* cu
->header
.offset_size
);
20377 if (cu
->header
.offset_size
== 4)
20378 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20380 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20381 if (str_offset
>= str_section
->size
)
20382 error (_("Offset from %s pointing outside of"
20383 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20384 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20385 return (const char *) (str_section
->buffer
+ str_offset
);
20388 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20390 static const char *
20391 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20393 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20394 ? reader
->cu
->header
.addr_size
: 0;
20395 return read_str_index (reader
->cu
,
20396 &reader
->dwo_file
->sections
.str
,
20397 &reader
->dwo_file
->sections
.str_offsets
,
20398 str_offsets_base
, str_index
);
20401 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20403 static const char *
20404 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20406 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20407 const char *objf_name
= objfile_name (objfile
);
20408 static const char form_name
[] = "DW_FORM_GNU_str_index";
20409 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20411 if (!cu
->str_offsets_base
.has_value ())
20412 error (_("%s used in Fission stub without %s"
20413 " in CU at offset 0x%lx [in module %s]"),
20414 form_name
, str_offsets_attr_name
,
20415 (long) cu
->header
.offset_size
, objf_name
);
20417 return read_str_index (cu
,
20418 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20419 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20420 *cu
->str_offsets_base
, str_index
);
20423 /* Return the length of an LEB128 number in BUF. */
20426 leb128_size (const gdb_byte
*buf
)
20428 const gdb_byte
*begin
= buf
;
20434 if ((byte
& 128) == 0)
20435 return buf
- begin
;
20440 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20449 cu
->language
= language_c
;
20452 case DW_LANG_C_plus_plus
:
20453 case DW_LANG_C_plus_plus_11
:
20454 case DW_LANG_C_plus_plus_14
:
20455 cu
->language
= language_cplus
;
20458 cu
->language
= language_d
;
20460 case DW_LANG_Fortran77
:
20461 case DW_LANG_Fortran90
:
20462 case DW_LANG_Fortran95
:
20463 case DW_LANG_Fortran03
:
20464 case DW_LANG_Fortran08
:
20465 cu
->language
= language_fortran
;
20468 cu
->language
= language_go
;
20470 case DW_LANG_Mips_Assembler
:
20471 cu
->language
= language_asm
;
20473 case DW_LANG_Ada83
:
20474 case DW_LANG_Ada95
:
20475 cu
->language
= language_ada
;
20477 case DW_LANG_Modula2
:
20478 cu
->language
= language_m2
;
20480 case DW_LANG_Pascal83
:
20481 cu
->language
= language_pascal
;
20484 cu
->language
= language_objc
;
20487 case DW_LANG_Rust_old
:
20488 cu
->language
= language_rust
;
20490 case DW_LANG_Cobol74
:
20491 case DW_LANG_Cobol85
:
20493 cu
->language
= language_minimal
;
20496 cu
->language_defn
= language_def (cu
->language
);
20499 /* Return the named attribute or NULL if not there. */
20501 static struct attribute
*
20502 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20507 struct attribute
*spec
= NULL
;
20509 for (i
= 0; i
< die
->num_attrs
; ++i
)
20511 if (die
->attrs
[i
].name
== name
)
20512 return &die
->attrs
[i
];
20513 if (die
->attrs
[i
].name
== DW_AT_specification
20514 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20515 spec
= &die
->attrs
[i
];
20521 die
= follow_die_ref (die
, spec
, &cu
);
20527 /* Return the named attribute or NULL if not there,
20528 but do not follow DW_AT_specification, etc.
20529 This is for use in contexts where we're reading .debug_types dies.
20530 Following DW_AT_specification, DW_AT_abstract_origin will take us
20531 back up the chain, and we want to go down. */
20533 static struct attribute
*
20534 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20538 for (i
= 0; i
< die
->num_attrs
; ++i
)
20539 if (die
->attrs
[i
].name
== name
)
20540 return &die
->attrs
[i
];
20545 /* Return the string associated with a string-typed attribute, or NULL if it
20546 is either not found or is of an incorrect type. */
20548 static const char *
20549 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20551 struct attribute
*attr
;
20552 const char *str
= NULL
;
20554 attr
= dwarf2_attr (die
, name
, cu
);
20558 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20559 || attr
->form
== DW_FORM_string
20560 || attr
->form
== DW_FORM_strx
20561 || attr
->form
== DW_FORM_strx1
20562 || attr
->form
== DW_FORM_strx2
20563 || attr
->form
== DW_FORM_strx3
20564 || attr
->form
== DW_FORM_strx4
20565 || attr
->form
== DW_FORM_GNU_str_index
20566 || attr
->form
== DW_FORM_GNU_strp_alt
)
20567 str
= DW_STRING (attr
);
20569 complaint (_("string type expected for attribute %s for "
20570 "DIE at %s in module %s"),
20571 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20572 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20578 /* Return the dwo name or NULL if not present. If present, it is in either
20579 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20580 static const char *
20581 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20583 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20584 if (dwo_name
== nullptr)
20585 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20589 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20590 and holds a non-zero value. This function should only be used for
20591 DW_FORM_flag or DW_FORM_flag_present attributes. */
20594 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20596 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20598 return (attr
&& DW_UNSND (attr
));
20602 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20604 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20605 which value is non-zero. However, we have to be careful with
20606 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20607 (via dwarf2_flag_true_p) follows this attribute. So we may
20608 end up accidently finding a declaration attribute that belongs
20609 to a different DIE referenced by the specification attribute,
20610 even though the given DIE does not have a declaration attribute. */
20611 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20612 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20615 /* Return the die giving the specification for DIE, if there is
20616 one. *SPEC_CU is the CU containing DIE on input, and the CU
20617 containing the return value on output. If there is no
20618 specification, but there is an abstract origin, that is
20621 static struct die_info
*
20622 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20624 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20627 if (spec_attr
== NULL
)
20628 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20630 if (spec_attr
== NULL
)
20633 return follow_die_ref (die
, spec_attr
, spec_cu
);
20636 /* Stub for free_line_header to match void * callback types. */
20639 free_line_header_voidp (void *arg
)
20641 struct line_header
*lh
= (struct line_header
*) arg
;
20647 line_header::add_include_dir (const char *include_dir
)
20649 if (dwarf_line_debug
>= 2)
20653 new_size
= m_include_dirs
.size ();
20655 new_size
= m_include_dirs
.size () + 1;
20656 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20657 new_size
, include_dir
);
20659 m_include_dirs
.push_back (include_dir
);
20663 line_header::add_file_name (const char *name
,
20665 unsigned int mod_time
,
20666 unsigned int length
)
20668 if (dwarf_line_debug
>= 2)
20672 new_size
= file_names_size ();
20674 new_size
= file_names_size () + 1;
20675 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20678 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20681 /* A convenience function to find the proper .debug_line section for a CU. */
20683 static struct dwarf2_section_info
*
20684 get_debug_line_section (struct dwarf2_cu
*cu
)
20686 struct dwarf2_section_info
*section
;
20687 struct dwarf2_per_objfile
*dwarf2_per_objfile
20688 = cu
->per_cu
->dwarf2_per_objfile
;
20690 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20692 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20693 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20694 else if (cu
->per_cu
->is_dwz
)
20696 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20698 section
= &dwz
->line
;
20701 section
= &dwarf2_per_objfile
->line
;
20706 /* Read directory or file name entry format, starting with byte of
20707 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20708 entries count and the entries themselves in the described entry
20712 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20713 bfd
*abfd
, const gdb_byte
**bufp
,
20714 struct line_header
*lh
,
20715 const struct comp_unit_head
*cu_header
,
20716 void (*callback
) (struct line_header
*lh
,
20719 unsigned int mod_time
,
20720 unsigned int length
))
20722 gdb_byte format_count
, formati
;
20723 ULONGEST data_count
, datai
;
20724 const gdb_byte
*buf
= *bufp
;
20725 const gdb_byte
*format_header_data
;
20726 unsigned int bytes_read
;
20728 format_count
= read_1_byte (abfd
, buf
);
20730 format_header_data
= buf
;
20731 for (formati
= 0; formati
< format_count
; formati
++)
20733 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20735 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20739 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20741 for (datai
= 0; datai
< data_count
; datai
++)
20743 const gdb_byte
*format
= format_header_data
;
20744 struct file_entry fe
;
20746 for (formati
= 0; formati
< format_count
; formati
++)
20748 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20749 format
+= bytes_read
;
20751 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20752 format
+= bytes_read
;
20754 gdb::optional
<const char *> string
;
20755 gdb::optional
<unsigned int> uint
;
20759 case DW_FORM_string
:
20760 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20764 case DW_FORM_line_strp
:
20765 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20772 case DW_FORM_data1
:
20773 uint
.emplace (read_1_byte (abfd
, buf
));
20777 case DW_FORM_data2
:
20778 uint
.emplace (read_2_bytes (abfd
, buf
));
20782 case DW_FORM_data4
:
20783 uint
.emplace (read_4_bytes (abfd
, buf
));
20787 case DW_FORM_data8
:
20788 uint
.emplace (read_8_bytes (abfd
, buf
));
20792 case DW_FORM_data16
:
20793 /* This is used for MD5, but file_entry does not record MD5s. */
20797 case DW_FORM_udata
:
20798 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20802 case DW_FORM_block
:
20803 /* It is valid only for DW_LNCT_timestamp which is ignored by
20808 switch (content_type
)
20811 if (string
.has_value ())
20814 case DW_LNCT_directory_index
:
20815 if (uint
.has_value ())
20816 fe
.d_index
= (dir_index
) *uint
;
20818 case DW_LNCT_timestamp
:
20819 if (uint
.has_value ())
20820 fe
.mod_time
= *uint
;
20823 if (uint
.has_value ())
20829 complaint (_("Unknown format content type %s"),
20830 pulongest (content_type
));
20834 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20840 /* Read the statement program header starting at OFFSET in
20841 .debug_line, or .debug_line.dwo. Return a pointer
20842 to a struct line_header, allocated using xmalloc.
20843 Returns NULL if there is a problem reading the header, e.g., if it
20844 has a version we don't understand.
20846 NOTE: the strings in the include directory and file name tables of
20847 the returned object point into the dwarf line section buffer,
20848 and must not be freed. */
20850 static line_header_up
20851 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20853 const gdb_byte
*line_ptr
;
20854 unsigned int bytes_read
, offset_size
;
20856 const char *cur_dir
, *cur_file
;
20857 struct dwarf2_section_info
*section
;
20859 struct dwarf2_per_objfile
*dwarf2_per_objfile
20860 = cu
->per_cu
->dwarf2_per_objfile
;
20862 section
= get_debug_line_section (cu
);
20863 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20864 if (section
->buffer
== NULL
)
20866 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20867 complaint (_("missing .debug_line.dwo section"));
20869 complaint (_("missing .debug_line section"));
20873 /* We can't do this until we know the section is non-empty.
20874 Only then do we know we have such a section. */
20875 abfd
= get_section_bfd_owner (section
);
20877 /* Make sure that at least there's room for the total_length field.
20878 That could be 12 bytes long, but we're just going to fudge that. */
20879 if (to_underlying (sect_off
) + 4 >= section
->size
)
20881 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20885 line_header_up
lh (new line_header ());
20887 lh
->sect_off
= sect_off
;
20888 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20890 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20892 /* Read in the header. */
20894 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20895 &bytes_read
, &offset_size
);
20896 line_ptr
+= bytes_read
;
20898 const gdb_byte
*start_here
= line_ptr
;
20900 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20902 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20905 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20906 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20908 if (lh
->version
> 5)
20910 /* This is a version we don't understand. The format could have
20911 changed in ways we don't handle properly so just punt. */
20912 complaint (_("unsupported version in .debug_line section"));
20915 if (lh
->version
>= 5)
20917 gdb_byte segment_selector_size
;
20919 /* Skip address size. */
20920 read_1_byte (abfd
, line_ptr
);
20923 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20925 if (segment_selector_size
!= 0)
20927 complaint (_("unsupported segment selector size %u "
20928 "in .debug_line section"),
20929 segment_selector_size
);
20933 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20934 line_ptr
+= offset_size
;
20935 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20936 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20938 if (lh
->version
>= 4)
20940 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20944 lh
->maximum_ops_per_instruction
= 1;
20946 if (lh
->maximum_ops_per_instruction
== 0)
20948 lh
->maximum_ops_per_instruction
= 1;
20949 complaint (_("invalid maximum_ops_per_instruction "
20950 "in `.debug_line' section"));
20953 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20955 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20957 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20959 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20961 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20963 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20964 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20966 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20970 if (lh
->version
>= 5)
20972 /* Read directory table. */
20973 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20975 [] (struct line_header
*header
, const char *name
,
20976 dir_index d_index
, unsigned int mod_time
,
20977 unsigned int length
)
20979 header
->add_include_dir (name
);
20982 /* Read file name table. */
20983 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20985 [] (struct line_header
*header
, const char *name
,
20986 dir_index d_index
, unsigned int mod_time
,
20987 unsigned int length
)
20989 header
->add_file_name (name
, d_index
, mod_time
, length
);
20994 /* Read directory table. */
20995 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20997 line_ptr
+= bytes_read
;
20998 lh
->add_include_dir (cur_dir
);
21000 line_ptr
+= bytes_read
;
21002 /* Read file name table. */
21003 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
21005 unsigned int mod_time
, length
;
21008 line_ptr
+= bytes_read
;
21009 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21010 line_ptr
+= bytes_read
;
21011 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21012 line_ptr
+= bytes_read
;
21013 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21014 line_ptr
+= bytes_read
;
21016 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
21018 line_ptr
+= bytes_read
;
21021 if (line_ptr
> (section
->buffer
+ section
->size
))
21022 complaint (_("line number info header doesn't "
21023 "fit in `.debug_line' section"));
21028 /* Subroutine of dwarf_decode_lines to simplify it.
21029 Return the file name of the psymtab for the given file_entry.
21030 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21031 If space for the result is malloc'd, *NAME_HOLDER will be set.
21032 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
21034 static const char *
21035 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
21036 const struct partial_symtab
*pst
,
21037 const char *comp_dir
,
21038 gdb::unique_xmalloc_ptr
<char> *name_holder
)
21040 const char *include_name
= fe
.name
;
21041 const char *include_name_to_compare
= include_name
;
21042 const char *pst_filename
;
21045 const char *dir_name
= fe
.include_dir (lh
);
21047 gdb::unique_xmalloc_ptr
<char> hold_compare
;
21048 if (!IS_ABSOLUTE_PATH (include_name
)
21049 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
21051 /* Avoid creating a duplicate psymtab for PST.
21052 We do this by comparing INCLUDE_NAME and PST_FILENAME.
21053 Before we do the comparison, however, we need to account
21054 for DIR_NAME and COMP_DIR.
21055 First prepend dir_name (if non-NULL). If we still don't
21056 have an absolute path prepend comp_dir (if non-NULL).
21057 However, the directory we record in the include-file's
21058 psymtab does not contain COMP_DIR (to match the
21059 corresponding symtab(s)).
21064 bash$ gcc -g ./hello.c
21065 include_name = "hello.c"
21067 DW_AT_comp_dir = comp_dir = "/tmp"
21068 DW_AT_name = "./hello.c"
21072 if (dir_name
!= NULL
)
21074 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
21075 include_name
, (char *) NULL
));
21076 include_name
= name_holder
->get ();
21077 include_name_to_compare
= include_name
;
21079 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
21081 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
21082 include_name
, (char *) NULL
));
21083 include_name_to_compare
= hold_compare
.get ();
21087 pst_filename
= pst
->filename
;
21088 gdb::unique_xmalloc_ptr
<char> copied_name
;
21089 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21091 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21092 pst_filename
, (char *) NULL
));
21093 pst_filename
= copied_name
.get ();
21096 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21100 return include_name
;
21103 /* State machine to track the state of the line number program. */
21105 class lnp_state_machine
21108 /* Initialize a machine state for the start of a line number
21110 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21111 bool record_lines_p
);
21113 file_entry
*current_file ()
21115 /* lh->file_names is 0-based, but the file name numbers in the
21116 statement program are 1-based. */
21117 return m_line_header
->file_name_at (m_file
);
21120 /* Record the line in the state machine. END_SEQUENCE is true if
21121 we're processing the end of a sequence. */
21122 void record_line (bool end_sequence
);
21124 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
21125 nop-out rest of the lines in this sequence. */
21126 void check_line_address (struct dwarf2_cu
*cu
,
21127 const gdb_byte
*line_ptr
,
21128 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21130 void handle_set_discriminator (unsigned int discriminator
)
21132 m_discriminator
= discriminator
;
21133 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21136 /* Handle DW_LNE_set_address. */
21137 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21140 address
+= baseaddr
;
21141 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21144 /* Handle DW_LNS_advance_pc. */
21145 void handle_advance_pc (CORE_ADDR adjust
);
21147 /* Handle a special opcode. */
21148 void handle_special_opcode (unsigned char op_code
);
21150 /* Handle DW_LNS_advance_line. */
21151 void handle_advance_line (int line_delta
)
21153 advance_line (line_delta
);
21156 /* Handle DW_LNS_set_file. */
21157 void handle_set_file (file_name_index file
);
21159 /* Handle DW_LNS_negate_stmt. */
21160 void handle_negate_stmt ()
21162 m_is_stmt
= !m_is_stmt
;
21165 /* Handle DW_LNS_const_add_pc. */
21166 void handle_const_add_pc ();
21168 /* Handle DW_LNS_fixed_advance_pc. */
21169 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21171 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21175 /* Handle DW_LNS_copy. */
21176 void handle_copy ()
21178 record_line (false);
21179 m_discriminator
= 0;
21182 /* Handle DW_LNE_end_sequence. */
21183 void handle_end_sequence ()
21185 m_currently_recording_lines
= true;
21189 /* Advance the line by LINE_DELTA. */
21190 void advance_line (int line_delta
)
21192 m_line
+= line_delta
;
21194 if (line_delta
!= 0)
21195 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21198 struct dwarf2_cu
*m_cu
;
21200 gdbarch
*m_gdbarch
;
21202 /* True if we're recording lines.
21203 Otherwise we're building partial symtabs and are just interested in
21204 finding include files mentioned by the line number program. */
21205 bool m_record_lines_p
;
21207 /* The line number header. */
21208 line_header
*m_line_header
;
21210 /* These are part of the standard DWARF line number state machine,
21211 and initialized according to the DWARF spec. */
21213 unsigned char m_op_index
= 0;
21214 /* The line table index of the current file. */
21215 file_name_index m_file
= 1;
21216 unsigned int m_line
= 1;
21218 /* These are initialized in the constructor. */
21220 CORE_ADDR m_address
;
21222 unsigned int m_discriminator
;
21224 /* Additional bits of state we need to track. */
21226 /* The last file that we called dwarf2_start_subfile for.
21227 This is only used for TLLs. */
21228 unsigned int m_last_file
= 0;
21229 /* The last file a line number was recorded for. */
21230 struct subfile
*m_last_subfile
= NULL
;
21232 /* When true, record the lines we decode. */
21233 bool m_currently_recording_lines
= false;
21235 /* The last line number that was recorded, used to coalesce
21236 consecutive entries for the same line. This can happen, for
21237 example, when discriminators are present. PR 17276. */
21238 unsigned int m_last_line
= 0;
21239 bool m_line_has_non_zero_discriminator
= false;
21243 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21245 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21246 / m_line_header
->maximum_ops_per_instruction
)
21247 * m_line_header
->minimum_instruction_length
);
21248 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21249 m_op_index
= ((m_op_index
+ adjust
)
21250 % m_line_header
->maximum_ops_per_instruction
);
21254 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21256 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21257 CORE_ADDR addr_adj
= (((m_op_index
21258 + (adj_opcode
/ m_line_header
->line_range
))
21259 / m_line_header
->maximum_ops_per_instruction
)
21260 * m_line_header
->minimum_instruction_length
);
21261 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21262 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21263 % m_line_header
->maximum_ops_per_instruction
);
21265 int line_delta
= (m_line_header
->line_base
21266 + (adj_opcode
% m_line_header
->line_range
));
21267 advance_line (line_delta
);
21268 record_line (false);
21269 m_discriminator
= 0;
21273 lnp_state_machine::handle_set_file (file_name_index file
)
21277 const file_entry
*fe
= current_file ();
21279 dwarf2_debug_line_missing_file_complaint ();
21280 else if (m_record_lines_p
)
21282 const char *dir
= fe
->include_dir (m_line_header
);
21284 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21285 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21286 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21291 lnp_state_machine::handle_const_add_pc ()
21294 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21297 = (((m_op_index
+ adjust
)
21298 / m_line_header
->maximum_ops_per_instruction
)
21299 * m_line_header
->minimum_instruction_length
);
21301 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21302 m_op_index
= ((m_op_index
+ adjust
)
21303 % m_line_header
->maximum_ops_per_instruction
);
21306 /* Return non-zero if we should add LINE to the line number table.
21307 LINE is the line to add, LAST_LINE is the last line that was added,
21308 LAST_SUBFILE is the subfile for LAST_LINE.
21309 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21310 had a non-zero discriminator.
21312 We have to be careful in the presence of discriminators.
21313 E.g., for this line:
21315 for (i = 0; i < 100000; i++);
21317 clang can emit four line number entries for that one line,
21318 each with a different discriminator.
21319 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21321 However, we want gdb to coalesce all four entries into one.
21322 Otherwise the user could stepi into the middle of the line and
21323 gdb would get confused about whether the pc really was in the
21324 middle of the line.
21326 Things are further complicated by the fact that two consecutive
21327 line number entries for the same line is a heuristic used by gcc
21328 to denote the end of the prologue. So we can't just discard duplicate
21329 entries, we have to be selective about it. The heuristic we use is
21330 that we only collapse consecutive entries for the same line if at least
21331 one of those entries has a non-zero discriminator. PR 17276.
21333 Note: Addresses in the line number state machine can never go backwards
21334 within one sequence, thus this coalescing is ok. */
21337 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21338 unsigned int line
, unsigned int last_line
,
21339 int line_has_non_zero_discriminator
,
21340 struct subfile
*last_subfile
)
21342 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21344 if (line
!= last_line
)
21346 /* Same line for the same file that we've seen already.
21347 As a last check, for pr 17276, only record the line if the line
21348 has never had a non-zero discriminator. */
21349 if (!line_has_non_zero_discriminator
)
21354 /* Use the CU's builder to record line number LINE beginning at
21355 address ADDRESS in the line table of subfile SUBFILE. */
21358 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21359 unsigned int line
, CORE_ADDR address
,
21360 struct dwarf2_cu
*cu
)
21362 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21364 if (dwarf_line_debug
)
21366 fprintf_unfiltered (gdb_stdlog
,
21367 "Recording line %u, file %s, address %s\n",
21368 line
, lbasename (subfile
->name
),
21369 paddress (gdbarch
, address
));
21373 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21376 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21377 Mark the end of a set of line number records.
21378 The arguments are the same as for dwarf_record_line_1.
21379 If SUBFILE is NULL the request is ignored. */
21382 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21383 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21385 if (subfile
== NULL
)
21388 if (dwarf_line_debug
)
21390 fprintf_unfiltered (gdb_stdlog
,
21391 "Finishing current line, file %s, address %s\n",
21392 lbasename (subfile
->name
),
21393 paddress (gdbarch
, address
));
21396 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21400 lnp_state_machine::record_line (bool end_sequence
)
21402 if (dwarf_line_debug
)
21404 fprintf_unfiltered (gdb_stdlog
,
21405 "Processing actual line %u: file %u,"
21406 " address %s, is_stmt %u, discrim %u\n",
21408 paddress (m_gdbarch
, m_address
),
21409 m_is_stmt
, m_discriminator
);
21412 file_entry
*fe
= current_file ();
21415 dwarf2_debug_line_missing_file_complaint ();
21416 /* For now we ignore lines not starting on an instruction boundary.
21417 But not when processing end_sequence for compatibility with the
21418 previous version of the code. */
21419 else if (m_op_index
== 0 || end_sequence
)
21421 fe
->included_p
= 1;
21422 if (m_record_lines_p
&& (producer_is_codewarrior (m_cu
) || m_is_stmt
))
21424 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21427 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21428 m_currently_recording_lines
? m_cu
: nullptr);
21433 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21434 m_line_has_non_zero_discriminator
,
21437 buildsym_compunit
*builder
= m_cu
->get_builder ();
21438 dwarf_record_line_1 (m_gdbarch
,
21439 builder
->get_current_subfile (),
21441 m_currently_recording_lines
? m_cu
: nullptr);
21443 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21444 m_last_line
= m_line
;
21450 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21451 line_header
*lh
, bool record_lines_p
)
21455 m_record_lines_p
= record_lines_p
;
21456 m_line_header
= lh
;
21458 m_currently_recording_lines
= true;
21460 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21461 was a line entry for it so that the backend has a chance to adjust it
21462 and also record it in case it needs it. This is currently used by MIPS
21463 code, cf. `mips_adjust_dwarf2_line'. */
21464 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21465 m_is_stmt
= lh
->default_is_stmt
;
21466 m_discriminator
= 0;
21470 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21471 const gdb_byte
*line_ptr
,
21472 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21474 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21475 the pc range of the CU. However, we restrict the test to only ADDRESS
21476 values of zero to preserve GDB's previous behaviour which is to handle
21477 the specific case of a function being GC'd by the linker. */
21479 if (address
== 0 && address
< unrelocated_lowpc
)
21481 /* This line table is for a function which has been
21482 GCd by the linker. Ignore it. PR gdb/12528 */
21484 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21485 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21487 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21488 line_offset
, objfile_name (objfile
));
21489 m_currently_recording_lines
= false;
21490 /* Note: m_currently_recording_lines is left as false until we see
21491 DW_LNE_end_sequence. */
21495 /* Subroutine of dwarf_decode_lines to simplify it.
21496 Process the line number information in LH.
21497 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21498 program in order to set included_p for every referenced header. */
21501 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21502 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21504 const gdb_byte
*line_ptr
, *extended_end
;
21505 const gdb_byte
*line_end
;
21506 unsigned int bytes_read
, extended_len
;
21507 unsigned char op_code
, extended_op
;
21508 CORE_ADDR baseaddr
;
21509 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21510 bfd
*abfd
= objfile
->obfd
;
21511 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21512 /* True if we're recording line info (as opposed to building partial
21513 symtabs and just interested in finding include files mentioned by
21514 the line number program). */
21515 bool record_lines_p
= !decode_for_pst_p
;
21517 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21519 line_ptr
= lh
->statement_program_start
;
21520 line_end
= lh
->statement_program_end
;
21522 /* Read the statement sequences until there's nothing left. */
21523 while (line_ptr
< line_end
)
21525 /* The DWARF line number program state machine. Reset the state
21526 machine at the start of each sequence. */
21527 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21528 bool end_sequence
= false;
21530 if (record_lines_p
)
21532 /* Start a subfile for the current file of the state
21534 const file_entry
*fe
= state_machine
.current_file ();
21537 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21540 /* Decode the table. */
21541 while (line_ptr
< line_end
&& !end_sequence
)
21543 op_code
= read_1_byte (abfd
, line_ptr
);
21546 if (op_code
>= lh
->opcode_base
)
21548 /* Special opcode. */
21549 state_machine
.handle_special_opcode (op_code
);
21551 else switch (op_code
)
21553 case DW_LNS_extended_op
:
21554 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21556 line_ptr
+= bytes_read
;
21557 extended_end
= line_ptr
+ extended_len
;
21558 extended_op
= read_1_byte (abfd
, line_ptr
);
21560 switch (extended_op
)
21562 case DW_LNE_end_sequence
:
21563 state_machine
.handle_end_sequence ();
21564 end_sequence
= true;
21566 case DW_LNE_set_address
:
21569 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21570 line_ptr
+= bytes_read
;
21572 state_machine
.check_line_address (cu
, line_ptr
,
21573 lowpc
- baseaddr
, address
);
21574 state_machine
.handle_set_address (baseaddr
, address
);
21577 case DW_LNE_define_file
:
21579 const char *cur_file
;
21580 unsigned int mod_time
, length
;
21583 cur_file
= read_direct_string (abfd
, line_ptr
,
21585 line_ptr
+= bytes_read
;
21586 dindex
= (dir_index
)
21587 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21588 line_ptr
+= bytes_read
;
21590 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21591 line_ptr
+= bytes_read
;
21593 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21594 line_ptr
+= bytes_read
;
21595 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21598 case DW_LNE_set_discriminator
:
21600 /* The discriminator is not interesting to the
21601 debugger; just ignore it. We still need to
21602 check its value though:
21603 if there are consecutive entries for the same
21604 (non-prologue) line we want to coalesce them.
21607 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21608 line_ptr
+= bytes_read
;
21610 state_machine
.handle_set_discriminator (discr
);
21614 complaint (_("mangled .debug_line section"));
21617 /* Make sure that we parsed the extended op correctly. If e.g.
21618 we expected a different address size than the producer used,
21619 we may have read the wrong number of bytes. */
21620 if (line_ptr
!= extended_end
)
21622 complaint (_("mangled .debug_line section"));
21627 state_machine
.handle_copy ();
21629 case DW_LNS_advance_pc
:
21632 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21633 line_ptr
+= bytes_read
;
21635 state_machine
.handle_advance_pc (adjust
);
21638 case DW_LNS_advance_line
:
21641 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21642 line_ptr
+= bytes_read
;
21644 state_machine
.handle_advance_line (line_delta
);
21647 case DW_LNS_set_file
:
21649 file_name_index file
21650 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21652 line_ptr
+= bytes_read
;
21654 state_machine
.handle_set_file (file
);
21657 case DW_LNS_set_column
:
21658 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21659 line_ptr
+= bytes_read
;
21661 case DW_LNS_negate_stmt
:
21662 state_machine
.handle_negate_stmt ();
21664 case DW_LNS_set_basic_block
:
21666 /* Add to the address register of the state machine the
21667 address increment value corresponding to special opcode
21668 255. I.e., this value is scaled by the minimum
21669 instruction length since special opcode 255 would have
21670 scaled the increment. */
21671 case DW_LNS_const_add_pc
:
21672 state_machine
.handle_const_add_pc ();
21674 case DW_LNS_fixed_advance_pc
:
21676 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21679 state_machine
.handle_fixed_advance_pc (addr_adj
);
21684 /* Unknown standard opcode, ignore it. */
21687 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21689 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21690 line_ptr
+= bytes_read
;
21697 dwarf2_debug_line_missing_end_sequence_complaint ();
21699 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21700 in which case we still finish recording the last line). */
21701 state_machine
.record_line (true);
21705 /* Decode the Line Number Program (LNP) for the given line_header
21706 structure and CU. The actual information extracted and the type
21707 of structures created from the LNP depends on the value of PST.
21709 1. If PST is NULL, then this procedure uses the data from the program
21710 to create all necessary symbol tables, and their linetables.
21712 2. If PST is not NULL, this procedure reads the program to determine
21713 the list of files included by the unit represented by PST, and
21714 builds all the associated partial symbol tables.
21716 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21717 It is used for relative paths in the line table.
21718 NOTE: When processing partial symtabs (pst != NULL),
21719 comp_dir == pst->dirname.
21721 NOTE: It is important that psymtabs have the same file name (via strcmp)
21722 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21723 symtab we don't use it in the name of the psymtabs we create.
21724 E.g. expand_line_sal requires this when finding psymtabs to expand.
21725 A good testcase for this is mb-inline.exp.
21727 LOWPC is the lowest address in CU (or 0 if not known).
21729 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21730 for its PC<->lines mapping information. Otherwise only the filename
21731 table is read in. */
21734 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21735 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21736 CORE_ADDR lowpc
, int decode_mapping
)
21738 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21739 const int decode_for_pst_p
= (pst
!= NULL
);
21741 if (decode_mapping
)
21742 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21744 if (decode_for_pst_p
)
21746 /* Now that we're done scanning the Line Header Program, we can
21747 create the psymtab of each included file. */
21748 for (auto &file_entry
: lh
->file_names ())
21749 if (file_entry
.included_p
== 1)
21751 gdb::unique_xmalloc_ptr
<char> name_holder
;
21752 const char *include_name
=
21753 psymtab_include_file_name (lh
, file_entry
, pst
,
21754 comp_dir
, &name_holder
);
21755 if (include_name
!= NULL
)
21756 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21761 /* Make sure a symtab is created for every file, even files
21762 which contain only variables (i.e. no code with associated
21764 buildsym_compunit
*builder
= cu
->get_builder ();
21765 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21767 for (auto &fe
: lh
->file_names ())
21769 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21770 if (builder
->get_current_subfile ()->symtab
== NULL
)
21772 builder
->get_current_subfile ()->symtab
21773 = allocate_symtab (cust
,
21774 builder
->get_current_subfile ()->name
);
21776 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21781 /* Start a subfile for DWARF. FILENAME is the name of the file and
21782 DIRNAME the name of the source directory which contains FILENAME
21783 or NULL if not known.
21784 This routine tries to keep line numbers from identical absolute and
21785 relative file names in a common subfile.
21787 Using the `list' example from the GDB testsuite, which resides in
21788 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21789 of /srcdir/list0.c yields the following debugging information for list0.c:
21791 DW_AT_name: /srcdir/list0.c
21792 DW_AT_comp_dir: /compdir
21793 files.files[0].name: list0.h
21794 files.files[0].dir: /srcdir
21795 files.files[1].name: list0.c
21796 files.files[1].dir: /srcdir
21798 The line number information for list0.c has to end up in a single
21799 subfile, so that `break /srcdir/list0.c:1' works as expected.
21800 start_subfile will ensure that this happens provided that we pass the
21801 concatenation of files.files[1].dir and files.files[1].name as the
21805 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21806 const char *dirname
)
21808 gdb::unique_xmalloc_ptr
<char> copy
;
21810 /* In order not to lose the line information directory,
21811 we concatenate it to the filename when it makes sense.
21812 Note that the Dwarf3 standard says (speaking of filenames in line
21813 information): ``The directory index is ignored for file names
21814 that represent full path names''. Thus ignoring dirname in the
21815 `else' branch below isn't an issue. */
21817 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21819 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21820 filename
= copy
.get ();
21823 cu
->get_builder ()->start_subfile (filename
);
21826 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21827 buildsym_compunit constructor. */
21829 struct compunit_symtab
*
21830 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21833 gdb_assert (m_builder
== nullptr);
21835 m_builder
.reset (new struct buildsym_compunit
21836 (per_cu
->dwarf2_per_objfile
->objfile
,
21837 name
, comp_dir
, language
, low_pc
));
21839 list_in_scope
= get_builder ()->get_file_symbols ();
21841 get_builder ()->record_debugformat ("DWARF 2");
21842 get_builder ()->record_producer (producer
);
21844 processing_has_namespace_info
= false;
21846 return get_builder ()->get_compunit_symtab ();
21850 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21851 struct dwarf2_cu
*cu
)
21853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21854 struct comp_unit_head
*cu_header
= &cu
->header
;
21856 /* NOTE drow/2003-01-30: There used to be a comment and some special
21857 code here to turn a symbol with DW_AT_external and a
21858 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21859 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21860 with some versions of binutils) where shared libraries could have
21861 relocations against symbols in their debug information - the
21862 minimal symbol would have the right address, but the debug info
21863 would not. It's no longer necessary, because we will explicitly
21864 apply relocations when we read in the debug information now. */
21866 /* A DW_AT_location attribute with no contents indicates that a
21867 variable has been optimized away. */
21868 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21870 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21874 /* Handle one degenerate form of location expression specially, to
21875 preserve GDB's previous behavior when section offsets are
21876 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21877 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21879 if (attr_form_is_block (attr
)
21880 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21881 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21882 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21883 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21884 && (DW_BLOCK (attr
)->size
21885 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21887 unsigned int dummy
;
21889 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21890 SET_SYMBOL_VALUE_ADDRESS (sym
,
21891 read_address (objfile
->obfd
,
21892 DW_BLOCK (attr
)->data
+ 1,
21895 SET_SYMBOL_VALUE_ADDRESS
21896 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21898 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21899 fixup_symbol_section (sym
, objfile
);
21900 SET_SYMBOL_VALUE_ADDRESS
21902 SYMBOL_VALUE_ADDRESS (sym
)
21903 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21907 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21908 expression evaluator, and use LOC_COMPUTED only when necessary
21909 (i.e. when the value of a register or memory location is
21910 referenced, or a thread-local block, etc.). Then again, it might
21911 not be worthwhile. I'm assuming that it isn't unless performance
21912 or memory numbers show me otherwise. */
21914 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21916 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21917 cu
->has_loclist
= true;
21920 /* Given a pointer to a DWARF information entry, figure out if we need
21921 to make a symbol table entry for it, and if so, create a new entry
21922 and return a pointer to it.
21923 If TYPE is NULL, determine symbol type from the die, otherwise
21924 used the passed type.
21925 If SPACE is not NULL, use it to hold the new symbol. If it is
21926 NULL, allocate a new symbol on the objfile's obstack. */
21928 static struct symbol
*
21929 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21930 struct symbol
*space
)
21932 struct dwarf2_per_objfile
*dwarf2_per_objfile
21933 = cu
->per_cu
->dwarf2_per_objfile
;
21934 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21935 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21936 struct symbol
*sym
= NULL
;
21938 struct attribute
*attr
= NULL
;
21939 struct attribute
*attr2
= NULL
;
21940 CORE_ADDR baseaddr
;
21941 struct pending
**list_to_add
= NULL
;
21943 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21945 baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
21947 name
= dwarf2_name (die
, cu
);
21950 const char *linkagename
;
21951 int suppress_add
= 0;
21956 sym
= allocate_symbol (objfile
);
21957 OBJSTAT (objfile
, n_syms
++);
21959 /* Cache this symbol's name and the name's demangled form (if any). */
21960 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21961 linkagename
= dwarf2_physname (name
, die
, cu
);
21962 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21964 /* Fortran does not have mangling standard and the mangling does differ
21965 between gfortran, iFort etc. */
21966 if (cu
->language
== language_fortran
21967 && symbol_get_demangled_name (sym
) == NULL
)
21968 symbol_set_demangled_name (sym
,
21969 dwarf2_full_name (name
, die
, cu
),
21972 /* Default assumptions.
21973 Use the passed type or decode it from the die. */
21974 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21975 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21977 SYMBOL_TYPE (sym
) = type
;
21979 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21980 attr
= dwarf2_attr (die
,
21981 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21983 if (attr
!= nullptr)
21985 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21988 attr
= dwarf2_attr (die
,
21989 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21991 if (attr
!= nullptr)
21993 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21994 struct file_entry
*fe
;
21996 if (cu
->line_header
!= NULL
)
21997 fe
= cu
->line_header
->file_name_at (file_index
);
22002 complaint (_("file index out of range"));
22004 symbol_set_symtab (sym
, fe
->symtab
);
22010 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
22011 if (attr
!= nullptr)
22015 addr
= attr_value_as_address (attr
);
22016 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
22017 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
22019 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
22020 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
22021 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
22022 add_symbol_to_list (sym
, cu
->list_in_scope
);
22024 case DW_TAG_subprogram
:
22025 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22027 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22028 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22029 if ((attr2
&& (DW_UNSND (attr2
) != 0))
22030 || cu
->language
== language_ada
22031 || cu
->language
== language_fortran
)
22033 /* Subprograms marked external are stored as a global symbol.
22034 Ada and Fortran subprograms, whether marked external or
22035 not, are always stored as a global symbol, because we want
22036 to be able to access them globally. For instance, we want
22037 to be able to break on a nested subprogram without having
22038 to specify the context. */
22039 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22043 list_to_add
= cu
->list_in_scope
;
22046 case DW_TAG_inlined_subroutine
:
22047 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
22049 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
22050 SYMBOL_INLINED (sym
) = 1;
22051 list_to_add
= cu
->list_in_scope
;
22053 case DW_TAG_template_value_param
:
22055 /* Fall through. */
22056 case DW_TAG_constant
:
22057 case DW_TAG_variable
:
22058 case DW_TAG_member
:
22059 /* Compilation with minimal debug info may result in
22060 variables with missing type entries. Change the
22061 misleading `void' type to something sensible. */
22062 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
22063 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
22065 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22066 /* In the case of DW_TAG_member, we should only be called for
22067 static const members. */
22068 if (die
->tag
== DW_TAG_member
)
22070 /* dwarf2_add_field uses die_is_declaration,
22071 so we do the same. */
22072 gdb_assert (die_is_declaration (die
, cu
));
22075 if (attr
!= nullptr)
22077 dwarf2_const_value (attr
, sym
, cu
);
22078 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22081 if (attr2
&& (DW_UNSND (attr2
) != 0))
22082 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22084 list_to_add
= cu
->list_in_scope
;
22088 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22089 if (attr
!= nullptr)
22091 var_decode_location (attr
, sym
, cu
);
22092 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22094 /* Fortran explicitly imports any global symbols to the local
22095 scope by DW_TAG_common_block. */
22096 if (cu
->language
== language_fortran
&& die
->parent
22097 && die
->parent
->tag
== DW_TAG_common_block
)
22100 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22101 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22102 && !dwarf2_per_objfile
->has_section_at_zero
)
22104 /* When a static variable is eliminated by the linker,
22105 the corresponding debug information is not stripped
22106 out, but the variable address is set to null;
22107 do not add such variables into symbol table. */
22109 else if (attr2
&& (DW_UNSND (attr2
) != 0))
22111 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22112 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22113 && dwarf2_per_objfile
->can_copy
)
22115 /* A global static variable might be subject to
22116 copy relocation. We first check for a local
22117 minsym, though, because maybe the symbol was
22118 marked hidden, in which case this would not
22120 bound_minimal_symbol found
22121 = (lookup_minimal_symbol_linkage
22122 (sym
->linkage_name (), objfile
));
22123 if (found
.minsym
!= nullptr)
22124 sym
->maybe_copied
= 1;
22127 /* A variable with DW_AT_external is never static,
22128 but it may be block-scoped. */
22130 = ((cu
->list_in_scope
22131 == cu
->get_builder ()->get_file_symbols ())
22132 ? cu
->get_builder ()->get_global_symbols ()
22133 : cu
->list_in_scope
);
22136 list_to_add
= cu
->list_in_scope
;
22140 /* We do not know the address of this symbol.
22141 If it is an external symbol and we have type information
22142 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22143 The address of the variable will then be determined from
22144 the minimal symbol table whenever the variable is
22146 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22148 /* Fortran explicitly imports any global symbols to the local
22149 scope by DW_TAG_common_block. */
22150 if (cu
->language
== language_fortran
&& die
->parent
22151 && die
->parent
->tag
== DW_TAG_common_block
)
22153 /* SYMBOL_CLASS doesn't matter here because
22154 read_common_block is going to reset it. */
22156 list_to_add
= cu
->list_in_scope
;
22158 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22159 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22161 /* A variable with DW_AT_external is never static, but it
22162 may be block-scoped. */
22164 = ((cu
->list_in_scope
22165 == cu
->get_builder ()->get_file_symbols ())
22166 ? cu
->get_builder ()->get_global_symbols ()
22167 : cu
->list_in_scope
);
22169 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22171 else if (!die_is_declaration (die
, cu
))
22173 /* Use the default LOC_OPTIMIZED_OUT class. */
22174 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22176 list_to_add
= cu
->list_in_scope
;
22180 case DW_TAG_formal_parameter
:
22182 /* If we are inside a function, mark this as an argument. If
22183 not, we might be looking at an argument to an inlined function
22184 when we do not have enough information to show inlined frames;
22185 pretend it's a local variable in that case so that the user can
22187 struct context_stack
*curr
22188 = cu
->get_builder ()->get_current_context_stack ();
22189 if (curr
!= nullptr && curr
->name
!= nullptr)
22190 SYMBOL_IS_ARGUMENT (sym
) = 1;
22191 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22192 if (attr
!= nullptr)
22194 var_decode_location (attr
, sym
, cu
);
22196 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22197 if (attr
!= nullptr)
22199 dwarf2_const_value (attr
, sym
, cu
);
22202 list_to_add
= cu
->list_in_scope
;
22205 case DW_TAG_unspecified_parameters
:
22206 /* From varargs functions; gdb doesn't seem to have any
22207 interest in this information, so just ignore it for now.
22210 case DW_TAG_template_type_param
:
22212 /* Fall through. */
22213 case DW_TAG_class_type
:
22214 case DW_TAG_interface_type
:
22215 case DW_TAG_structure_type
:
22216 case DW_TAG_union_type
:
22217 case DW_TAG_set_type
:
22218 case DW_TAG_enumeration_type
:
22219 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22220 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22223 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22224 really ever be static objects: otherwise, if you try
22225 to, say, break of a class's method and you're in a file
22226 which doesn't mention that class, it won't work unless
22227 the check for all static symbols in lookup_symbol_aux
22228 saves you. See the OtherFileClass tests in
22229 gdb.c++/namespace.exp. */
22233 buildsym_compunit
*builder
= cu
->get_builder ();
22235 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22236 && cu
->language
== language_cplus
22237 ? builder
->get_global_symbols ()
22238 : cu
->list_in_scope
);
22240 /* The semantics of C++ state that "struct foo {
22241 ... }" also defines a typedef for "foo". */
22242 if (cu
->language
== language_cplus
22243 || cu
->language
== language_ada
22244 || cu
->language
== language_d
22245 || cu
->language
== language_rust
)
22247 /* The symbol's name is already allocated along
22248 with this objfile, so we don't need to
22249 duplicate it for the type. */
22250 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22251 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22256 case DW_TAG_typedef
:
22257 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22258 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22259 list_to_add
= cu
->list_in_scope
;
22261 case DW_TAG_base_type
:
22262 case DW_TAG_subrange_type
:
22263 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22264 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22265 list_to_add
= cu
->list_in_scope
;
22267 case DW_TAG_enumerator
:
22268 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22269 if (attr
!= nullptr)
22271 dwarf2_const_value (attr
, sym
, cu
);
22274 /* NOTE: carlton/2003-11-10: See comment above in the
22275 DW_TAG_class_type, etc. block. */
22278 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22279 && cu
->language
== language_cplus
22280 ? cu
->get_builder ()->get_global_symbols ()
22281 : cu
->list_in_scope
);
22284 case DW_TAG_imported_declaration
:
22285 case DW_TAG_namespace
:
22286 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22287 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22289 case DW_TAG_module
:
22290 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22291 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22292 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22294 case DW_TAG_common_block
:
22295 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22296 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22297 add_symbol_to_list (sym
, cu
->list_in_scope
);
22300 /* Not a tag we recognize. Hopefully we aren't processing
22301 trash data, but since we must specifically ignore things
22302 we don't recognize, there is nothing else we should do at
22304 complaint (_("unsupported tag: '%s'"),
22305 dwarf_tag_name (die
->tag
));
22311 sym
->hash_next
= objfile
->template_symbols
;
22312 objfile
->template_symbols
= sym
;
22313 list_to_add
= NULL
;
22316 if (list_to_add
!= NULL
)
22317 add_symbol_to_list (sym
, list_to_add
);
22319 /* For the benefit of old versions of GCC, check for anonymous
22320 namespaces based on the demangled name. */
22321 if (!cu
->processing_has_namespace_info
22322 && cu
->language
== language_cplus
)
22323 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22328 /* Given an attr with a DW_FORM_dataN value in host byte order,
22329 zero-extend it as appropriate for the symbol's type. The DWARF
22330 standard (v4) is not entirely clear about the meaning of using
22331 DW_FORM_dataN for a constant with a signed type, where the type is
22332 wider than the data. The conclusion of a discussion on the DWARF
22333 list was that this is unspecified. We choose to always zero-extend
22334 because that is the interpretation long in use by GCC. */
22337 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22338 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22340 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22341 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22342 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22343 LONGEST l
= DW_UNSND (attr
);
22345 if (bits
< sizeof (*value
) * 8)
22347 l
&= ((LONGEST
) 1 << bits
) - 1;
22350 else if (bits
== sizeof (*value
) * 8)
22354 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22355 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22362 /* Read a constant value from an attribute. Either set *VALUE, or if
22363 the value does not fit in *VALUE, set *BYTES - either already
22364 allocated on the objfile obstack, or newly allocated on OBSTACK,
22365 or, set *BATON, if we translated the constant to a location
22369 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22370 const char *name
, struct obstack
*obstack
,
22371 struct dwarf2_cu
*cu
,
22372 LONGEST
*value
, const gdb_byte
**bytes
,
22373 struct dwarf2_locexpr_baton
**baton
)
22375 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22376 struct comp_unit_head
*cu_header
= &cu
->header
;
22377 struct dwarf_block
*blk
;
22378 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22379 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22385 switch (attr
->form
)
22388 case DW_FORM_addrx
:
22389 case DW_FORM_GNU_addr_index
:
22393 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22394 dwarf2_const_value_length_mismatch_complaint (name
,
22395 cu_header
->addr_size
,
22396 TYPE_LENGTH (type
));
22397 /* Symbols of this form are reasonably rare, so we just
22398 piggyback on the existing location code rather than writing
22399 a new implementation of symbol_computed_ops. */
22400 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22401 (*baton
)->per_cu
= cu
->per_cu
;
22402 gdb_assert ((*baton
)->per_cu
);
22404 (*baton
)->size
= 2 + cu_header
->addr_size
;
22405 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22406 (*baton
)->data
= data
;
22408 data
[0] = DW_OP_addr
;
22409 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22410 byte_order
, DW_ADDR (attr
));
22411 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22414 case DW_FORM_string
:
22417 case DW_FORM_GNU_str_index
:
22418 case DW_FORM_GNU_strp_alt
:
22419 /* DW_STRING is already allocated on the objfile obstack, point
22421 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22423 case DW_FORM_block1
:
22424 case DW_FORM_block2
:
22425 case DW_FORM_block4
:
22426 case DW_FORM_block
:
22427 case DW_FORM_exprloc
:
22428 case DW_FORM_data16
:
22429 blk
= DW_BLOCK (attr
);
22430 if (TYPE_LENGTH (type
) != blk
->size
)
22431 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22432 TYPE_LENGTH (type
));
22433 *bytes
= blk
->data
;
22436 /* The DW_AT_const_value attributes are supposed to carry the
22437 symbol's value "represented as it would be on the target
22438 architecture." By the time we get here, it's already been
22439 converted to host endianness, so we just need to sign- or
22440 zero-extend it as appropriate. */
22441 case DW_FORM_data1
:
22442 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22444 case DW_FORM_data2
:
22445 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22447 case DW_FORM_data4
:
22448 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22450 case DW_FORM_data8
:
22451 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22454 case DW_FORM_sdata
:
22455 case DW_FORM_implicit_const
:
22456 *value
= DW_SND (attr
);
22459 case DW_FORM_udata
:
22460 *value
= DW_UNSND (attr
);
22464 complaint (_("unsupported const value attribute form: '%s'"),
22465 dwarf_form_name (attr
->form
));
22472 /* Copy constant value from an attribute to a symbol. */
22475 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22476 struct dwarf2_cu
*cu
)
22478 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22480 const gdb_byte
*bytes
;
22481 struct dwarf2_locexpr_baton
*baton
;
22483 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22484 sym
->print_name (),
22485 &objfile
->objfile_obstack
, cu
,
22486 &value
, &bytes
, &baton
);
22490 SYMBOL_LOCATION_BATON (sym
) = baton
;
22491 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22493 else if (bytes
!= NULL
)
22495 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22496 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22500 SYMBOL_VALUE (sym
) = value
;
22501 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22505 /* Return the type of the die in question using its DW_AT_type attribute. */
22507 static struct type
*
22508 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22510 struct attribute
*type_attr
;
22512 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22515 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22516 /* A missing DW_AT_type represents a void type. */
22517 return objfile_type (objfile
)->builtin_void
;
22520 return lookup_die_type (die
, type_attr
, cu
);
22523 /* True iff CU's producer generates GNAT Ada auxiliary information
22524 that allows to find parallel types through that information instead
22525 of having to do expensive parallel lookups by type name. */
22528 need_gnat_info (struct dwarf2_cu
*cu
)
22530 /* Assume that the Ada compiler was GNAT, which always produces
22531 the auxiliary information. */
22532 return (cu
->language
== language_ada
);
22535 /* Return the auxiliary type of the die in question using its
22536 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22537 attribute is not present. */
22539 static struct type
*
22540 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22542 struct attribute
*type_attr
;
22544 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22548 return lookup_die_type (die
, type_attr
, cu
);
22551 /* If DIE has a descriptive_type attribute, then set the TYPE's
22552 descriptive type accordingly. */
22555 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22556 struct dwarf2_cu
*cu
)
22558 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22560 if (descriptive_type
)
22562 ALLOCATE_GNAT_AUX_TYPE (type
);
22563 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22567 /* Return the containing type of the die in question using its
22568 DW_AT_containing_type attribute. */
22570 static struct type
*
22571 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22573 struct attribute
*type_attr
;
22574 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22576 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22578 error (_("Dwarf Error: Problem turning containing type into gdb type "
22579 "[in module %s]"), objfile_name (objfile
));
22581 return lookup_die_type (die
, type_attr
, cu
);
22584 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22586 static struct type
*
22587 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22589 struct dwarf2_per_objfile
*dwarf2_per_objfile
22590 = cu
->per_cu
->dwarf2_per_objfile
;
22591 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22594 std::string message
22595 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22596 objfile_name (objfile
),
22597 sect_offset_str (cu
->header
.sect_off
),
22598 sect_offset_str (die
->sect_off
));
22599 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22601 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22604 /* Look up the type of DIE in CU using its type attribute ATTR.
22605 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22606 DW_AT_containing_type.
22607 If there is no type substitute an error marker. */
22609 static struct type
*
22610 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22611 struct dwarf2_cu
*cu
)
22613 struct dwarf2_per_objfile
*dwarf2_per_objfile
22614 = cu
->per_cu
->dwarf2_per_objfile
;
22615 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22616 struct type
*this_type
;
22618 gdb_assert (attr
->name
== DW_AT_type
22619 || attr
->name
== DW_AT_GNAT_descriptive_type
22620 || attr
->name
== DW_AT_containing_type
);
22622 /* First see if we have it cached. */
22624 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22626 struct dwarf2_per_cu_data
*per_cu
;
22627 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22629 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22630 dwarf2_per_objfile
);
22631 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22633 else if (attr_form_is_ref (attr
))
22635 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22637 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22639 else if (attr
->form
== DW_FORM_ref_sig8
)
22641 ULONGEST signature
= DW_SIGNATURE (attr
);
22643 return get_signatured_type (die
, signature
, cu
);
22647 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22648 " at %s [in module %s]"),
22649 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22650 objfile_name (objfile
));
22651 return build_error_marker_type (cu
, die
);
22654 /* If not cached we need to read it in. */
22656 if (this_type
== NULL
)
22658 struct die_info
*type_die
= NULL
;
22659 struct dwarf2_cu
*type_cu
= cu
;
22661 if (attr_form_is_ref (attr
))
22662 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22663 if (type_die
== NULL
)
22664 return build_error_marker_type (cu
, die
);
22665 /* If we find the type now, it's probably because the type came
22666 from an inter-CU reference and the type's CU got expanded before
22668 this_type
= read_type_die (type_die
, type_cu
);
22671 /* If we still don't have a type use an error marker. */
22673 if (this_type
== NULL
)
22674 return build_error_marker_type (cu
, die
);
22679 /* Return the type in DIE, CU.
22680 Returns NULL for invalid types.
22682 This first does a lookup in die_type_hash,
22683 and only reads the die in if necessary.
22685 NOTE: This can be called when reading in partial or full symbols. */
22687 static struct type
*
22688 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22690 struct type
*this_type
;
22692 this_type
= get_die_type (die
, cu
);
22696 return read_type_die_1 (die
, cu
);
22699 /* Read the type in DIE, CU.
22700 Returns NULL for invalid types. */
22702 static struct type
*
22703 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22705 struct type
*this_type
= NULL
;
22709 case DW_TAG_class_type
:
22710 case DW_TAG_interface_type
:
22711 case DW_TAG_structure_type
:
22712 case DW_TAG_union_type
:
22713 this_type
= read_structure_type (die
, cu
);
22715 case DW_TAG_enumeration_type
:
22716 this_type
= read_enumeration_type (die
, cu
);
22718 case DW_TAG_subprogram
:
22719 case DW_TAG_subroutine_type
:
22720 case DW_TAG_inlined_subroutine
:
22721 this_type
= read_subroutine_type (die
, cu
);
22723 case DW_TAG_array_type
:
22724 this_type
= read_array_type (die
, cu
);
22726 case DW_TAG_set_type
:
22727 this_type
= read_set_type (die
, cu
);
22729 case DW_TAG_pointer_type
:
22730 this_type
= read_tag_pointer_type (die
, cu
);
22732 case DW_TAG_ptr_to_member_type
:
22733 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22735 case DW_TAG_reference_type
:
22736 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22738 case DW_TAG_rvalue_reference_type
:
22739 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22741 case DW_TAG_const_type
:
22742 this_type
= read_tag_const_type (die
, cu
);
22744 case DW_TAG_volatile_type
:
22745 this_type
= read_tag_volatile_type (die
, cu
);
22747 case DW_TAG_restrict_type
:
22748 this_type
= read_tag_restrict_type (die
, cu
);
22750 case DW_TAG_string_type
:
22751 this_type
= read_tag_string_type (die
, cu
);
22753 case DW_TAG_typedef
:
22754 this_type
= read_typedef (die
, cu
);
22756 case DW_TAG_subrange_type
:
22757 this_type
= read_subrange_type (die
, cu
);
22759 case DW_TAG_base_type
:
22760 this_type
= read_base_type (die
, cu
);
22762 case DW_TAG_unspecified_type
:
22763 this_type
= read_unspecified_type (die
, cu
);
22765 case DW_TAG_namespace
:
22766 this_type
= read_namespace_type (die
, cu
);
22768 case DW_TAG_module
:
22769 this_type
= read_module_type (die
, cu
);
22771 case DW_TAG_atomic_type
:
22772 this_type
= read_tag_atomic_type (die
, cu
);
22775 complaint (_("unexpected tag in read_type_die: '%s'"),
22776 dwarf_tag_name (die
->tag
));
22783 /* See if we can figure out if the class lives in a namespace. We do
22784 this by looking for a member function; its demangled name will
22785 contain namespace info, if there is any.
22786 Return the computed name or NULL.
22787 Space for the result is allocated on the objfile's obstack.
22788 This is the full-die version of guess_partial_die_structure_name.
22789 In this case we know DIE has no useful parent. */
22791 static const char *
22792 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22794 struct die_info
*spec_die
;
22795 struct dwarf2_cu
*spec_cu
;
22796 struct die_info
*child
;
22797 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22800 spec_die
= die_specification (die
, &spec_cu
);
22801 if (spec_die
!= NULL
)
22807 for (child
= die
->child
;
22809 child
= child
->sibling
)
22811 if (child
->tag
== DW_TAG_subprogram
)
22813 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22815 if (linkage_name
!= NULL
)
22817 gdb::unique_xmalloc_ptr
<char> actual_name
22818 (language_class_name_from_physname (cu
->language_defn
,
22820 const char *name
= NULL
;
22822 if (actual_name
!= NULL
)
22824 const char *die_name
= dwarf2_name (die
, cu
);
22826 if (die_name
!= NULL
22827 && strcmp (die_name
, actual_name
.get ()) != 0)
22829 /* Strip off the class name from the full name.
22830 We want the prefix. */
22831 int die_name_len
= strlen (die_name
);
22832 int actual_name_len
= strlen (actual_name
.get ());
22833 const char *ptr
= actual_name
.get ();
22835 /* Test for '::' as a sanity check. */
22836 if (actual_name_len
> die_name_len
+ 2
22837 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22838 name
= obstack_strndup (
22839 &objfile
->per_bfd
->storage_obstack
,
22840 ptr
, actual_name_len
- die_name_len
- 2);
22851 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22852 prefix part in such case. See
22853 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22855 static const char *
22856 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22858 struct attribute
*attr
;
22861 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22862 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22865 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22868 attr
= dw2_linkage_name_attr (die
, cu
);
22869 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22872 /* dwarf2_name had to be already called. */
22873 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22875 /* Strip the base name, keep any leading namespaces/classes. */
22876 base
= strrchr (DW_STRING (attr
), ':');
22877 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22881 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22883 &base
[-1] - DW_STRING (attr
));
22886 /* Return the name of the namespace/class that DIE is defined within,
22887 or "" if we can't tell. The caller should not xfree the result.
22889 For example, if we're within the method foo() in the following
22899 then determine_prefix on foo's die will return "N::C". */
22901 static const char *
22902 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22904 struct dwarf2_per_objfile
*dwarf2_per_objfile
22905 = cu
->per_cu
->dwarf2_per_objfile
;
22906 struct die_info
*parent
, *spec_die
;
22907 struct dwarf2_cu
*spec_cu
;
22908 struct type
*parent_type
;
22909 const char *retval
;
22911 if (cu
->language
!= language_cplus
22912 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22913 && cu
->language
!= language_rust
)
22916 retval
= anonymous_struct_prefix (die
, cu
);
22920 /* We have to be careful in the presence of DW_AT_specification.
22921 For example, with GCC 3.4, given the code
22925 // Definition of N::foo.
22929 then we'll have a tree of DIEs like this:
22931 1: DW_TAG_compile_unit
22932 2: DW_TAG_namespace // N
22933 3: DW_TAG_subprogram // declaration of N::foo
22934 4: DW_TAG_subprogram // definition of N::foo
22935 DW_AT_specification // refers to die #3
22937 Thus, when processing die #4, we have to pretend that we're in
22938 the context of its DW_AT_specification, namely the contex of die
22941 spec_die
= die_specification (die
, &spec_cu
);
22942 if (spec_die
== NULL
)
22943 parent
= die
->parent
;
22946 parent
= spec_die
->parent
;
22950 if (parent
== NULL
)
22952 else if (parent
->building_fullname
)
22955 const char *parent_name
;
22957 /* It has been seen on RealView 2.2 built binaries,
22958 DW_TAG_template_type_param types actually _defined_ as
22959 children of the parent class:
22962 template class <class Enum> Class{};
22963 Class<enum E> class_e;
22965 1: DW_TAG_class_type (Class)
22966 2: DW_TAG_enumeration_type (E)
22967 3: DW_TAG_enumerator (enum1:0)
22968 3: DW_TAG_enumerator (enum2:1)
22970 2: DW_TAG_template_type_param
22971 DW_AT_type DW_FORM_ref_udata (E)
22973 Besides being broken debug info, it can put GDB into an
22974 infinite loop. Consider:
22976 When we're building the full name for Class<E>, we'll start
22977 at Class, and go look over its template type parameters,
22978 finding E. We'll then try to build the full name of E, and
22979 reach here. We're now trying to build the full name of E,
22980 and look over the parent DIE for containing scope. In the
22981 broken case, if we followed the parent DIE of E, we'd again
22982 find Class, and once again go look at its template type
22983 arguments, etc., etc. Simply don't consider such parent die
22984 as source-level parent of this die (it can't be, the language
22985 doesn't allow it), and break the loop here. */
22986 name
= dwarf2_name (die
, cu
);
22987 parent_name
= dwarf2_name (parent
, cu
);
22988 complaint (_("template param type '%s' defined within parent '%s'"),
22989 name
? name
: "<unknown>",
22990 parent_name
? parent_name
: "<unknown>");
22994 switch (parent
->tag
)
22996 case DW_TAG_namespace
:
22997 parent_type
= read_type_die (parent
, cu
);
22998 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22999 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
23000 Work around this problem here. */
23001 if (cu
->language
== language_cplus
23002 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
23004 /* We give a name to even anonymous namespaces. */
23005 return TYPE_NAME (parent_type
);
23006 case DW_TAG_class_type
:
23007 case DW_TAG_interface_type
:
23008 case DW_TAG_structure_type
:
23009 case DW_TAG_union_type
:
23010 case DW_TAG_module
:
23011 parent_type
= read_type_die (parent
, cu
);
23012 if (TYPE_NAME (parent_type
) != NULL
)
23013 return TYPE_NAME (parent_type
);
23015 /* An anonymous structure is only allowed non-static data
23016 members; no typedefs, no member functions, et cetera.
23017 So it does not need a prefix. */
23019 case DW_TAG_compile_unit
:
23020 case DW_TAG_partial_unit
:
23021 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
23022 if (cu
->language
== language_cplus
23023 && !dwarf2_per_objfile
->types
.empty ()
23024 && die
->child
!= NULL
23025 && (die
->tag
== DW_TAG_class_type
23026 || die
->tag
== DW_TAG_structure_type
23027 || die
->tag
== DW_TAG_union_type
))
23029 const char *name
= guess_full_die_structure_name (die
, cu
);
23034 case DW_TAG_subprogram
:
23035 /* Nested subroutines in Fortran get a prefix with the name
23036 of the parent's subroutine. */
23037 if (cu
->language
== language_fortran
)
23039 if ((die
->tag
== DW_TAG_subprogram
)
23040 && (dwarf2_name (parent
, cu
) != NULL
))
23041 return dwarf2_name (parent
, cu
);
23043 return determine_prefix (parent
, cu
);
23044 case DW_TAG_enumeration_type
:
23045 parent_type
= read_type_die (parent
, cu
);
23046 if (TYPE_DECLARED_CLASS (parent_type
))
23048 if (TYPE_NAME (parent_type
) != NULL
)
23049 return TYPE_NAME (parent_type
);
23052 /* Fall through. */
23054 return determine_prefix (parent
, cu
);
23058 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
23059 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
23060 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
23061 an obconcat, otherwise allocate storage for the result. The CU argument is
23062 used to determine the language and hence, the appropriate separator. */
23064 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
23067 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
23068 int physname
, struct dwarf2_cu
*cu
)
23070 const char *lead
= "";
23073 if (suffix
== NULL
|| suffix
[0] == '\0'
23074 || prefix
== NULL
|| prefix
[0] == '\0')
23076 else if (cu
->language
== language_d
)
23078 /* For D, the 'main' function could be defined in any module, but it
23079 should never be prefixed. */
23080 if (strcmp (suffix
, "D main") == 0)
23088 else if (cu
->language
== language_fortran
&& physname
)
23090 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23091 DW_AT_MIPS_linkage_name is preferred and used instead. */
23099 if (prefix
== NULL
)
23101 if (suffix
== NULL
)
23108 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23110 strcpy (retval
, lead
);
23111 strcat (retval
, prefix
);
23112 strcat (retval
, sep
);
23113 strcat (retval
, suffix
);
23118 /* We have an obstack. */
23119 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23123 /* Return sibling of die, NULL if no sibling. */
23125 static struct die_info
*
23126 sibling_die (struct die_info
*die
)
23128 return die
->sibling
;
23131 /* Get name of a die, return NULL if not found. */
23133 static const char *
23134 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23135 struct obstack
*obstack
)
23137 if (name
&& cu
->language
== language_cplus
)
23139 std::string canon_name
= cp_canonicalize_string (name
);
23141 if (!canon_name
.empty ())
23143 if (canon_name
!= name
)
23144 name
= obstack_strdup (obstack
, canon_name
);
23151 /* Get name of a die, return NULL if not found.
23152 Anonymous namespaces are converted to their magic string. */
23154 static const char *
23155 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23157 struct attribute
*attr
;
23158 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23160 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23161 if ((!attr
|| !DW_STRING (attr
))
23162 && die
->tag
!= DW_TAG_namespace
23163 && die
->tag
!= DW_TAG_class_type
23164 && die
->tag
!= DW_TAG_interface_type
23165 && die
->tag
!= DW_TAG_structure_type
23166 && die
->tag
!= DW_TAG_union_type
)
23171 case DW_TAG_compile_unit
:
23172 case DW_TAG_partial_unit
:
23173 /* Compilation units have a DW_AT_name that is a filename, not
23174 a source language identifier. */
23175 case DW_TAG_enumeration_type
:
23176 case DW_TAG_enumerator
:
23177 /* These tags always have simple identifiers already; no need
23178 to canonicalize them. */
23179 return DW_STRING (attr
);
23181 case DW_TAG_namespace
:
23182 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23183 return DW_STRING (attr
);
23184 return CP_ANONYMOUS_NAMESPACE_STR
;
23186 case DW_TAG_class_type
:
23187 case DW_TAG_interface_type
:
23188 case DW_TAG_structure_type
:
23189 case DW_TAG_union_type
:
23190 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23191 structures or unions. These were of the form "._%d" in GCC 4.1,
23192 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23193 and GCC 4.4. We work around this problem by ignoring these. */
23194 if (attr
&& DW_STRING (attr
)
23195 && (startswith (DW_STRING (attr
), "._")
23196 || startswith (DW_STRING (attr
), "<anonymous")))
23199 /* GCC might emit a nameless typedef that has a linkage name. See
23200 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23201 if (!attr
|| DW_STRING (attr
) == NULL
)
23203 attr
= dw2_linkage_name_attr (die
, cu
);
23204 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23207 /* Avoid demangling DW_STRING (attr) the second time on a second
23208 call for the same DIE. */
23209 if (!DW_STRING_IS_CANONICAL (attr
))
23211 gdb::unique_xmalloc_ptr
<char> demangled
23212 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23216 /* FIXME: we already did this for the partial symbol... */
23218 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23220 DW_STRING_IS_CANONICAL (attr
) = 1;
23222 /* Strip any leading namespaces/classes, keep only the base name.
23223 DW_AT_name for named DIEs does not contain the prefixes. */
23224 base
= strrchr (DW_STRING (attr
), ':');
23225 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23228 return DW_STRING (attr
);
23237 if (!DW_STRING_IS_CANONICAL (attr
))
23240 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23241 &objfile
->per_bfd
->storage_obstack
);
23242 DW_STRING_IS_CANONICAL (attr
) = 1;
23244 return DW_STRING (attr
);
23247 /* Return the die that this die in an extension of, or NULL if there
23248 is none. *EXT_CU is the CU containing DIE on input, and the CU
23249 containing the return value on output. */
23251 static struct die_info
*
23252 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23254 struct attribute
*attr
;
23256 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23260 return follow_die_ref (die
, attr
, ext_cu
);
23263 /* A convenience function that returns an "unknown" DWARF name,
23264 including the value of V. STR is the name of the entity being
23265 printed, e.g., "TAG". */
23267 static const char *
23268 dwarf_unknown (const char *str
, unsigned v
)
23270 char *cell
= get_print_cell ();
23271 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23275 /* Convert a DIE tag into its string name. */
23277 static const char *
23278 dwarf_tag_name (unsigned tag
)
23280 const char *name
= get_DW_TAG_name (tag
);
23283 return dwarf_unknown ("TAG", tag
);
23288 /* Convert a DWARF attribute code into its string name. */
23290 static const char *
23291 dwarf_attr_name (unsigned attr
)
23295 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23296 if (attr
== DW_AT_MIPS_fde
)
23297 return "DW_AT_MIPS_fde";
23299 if (attr
== DW_AT_HP_block_index
)
23300 return "DW_AT_HP_block_index";
23303 name
= get_DW_AT_name (attr
);
23306 return dwarf_unknown ("AT", attr
);
23311 /* Convert a unit type to corresponding DW_UT name. */
23313 static const char *
23314 dwarf_unit_type_name (int unit_type
) {
23318 return "DW_UT_compile (0x01)";
23320 return "DW_UT_type (0x02)";
23322 return "DW_UT_partial (0x03)";
23324 return "DW_UT_skeleton (0x04)";
23326 return "DW_UT_split_compile (0x05)";
23328 return "DW_UT_split_type (0x06)";
23330 return "DW_UT_lo_user (0x80)";
23332 return "DW_UT_hi_user (0xff)";
23338 /* Convert a DWARF value form code into its string name. */
23340 static const char *
23341 dwarf_form_name (unsigned form
)
23343 const char *name
= get_DW_FORM_name (form
);
23346 return dwarf_unknown ("FORM", form
);
23351 static const char *
23352 dwarf_bool_name (unsigned mybool
)
23360 /* Convert a DWARF type code into its string name. */
23362 static const char *
23363 dwarf_type_encoding_name (unsigned enc
)
23365 const char *name
= get_DW_ATE_name (enc
);
23368 return dwarf_unknown ("ATE", enc
);
23374 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23378 print_spaces (indent
, f
);
23379 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23380 dwarf_tag_name (die
->tag
), die
->abbrev
,
23381 sect_offset_str (die
->sect_off
));
23383 if (die
->parent
!= NULL
)
23385 print_spaces (indent
, f
);
23386 fprintf_unfiltered (f
, " parent at offset: %s\n",
23387 sect_offset_str (die
->parent
->sect_off
));
23390 print_spaces (indent
, f
);
23391 fprintf_unfiltered (f
, " has children: %s\n",
23392 dwarf_bool_name (die
->child
!= NULL
));
23394 print_spaces (indent
, f
);
23395 fprintf_unfiltered (f
, " attributes:\n");
23397 for (i
= 0; i
< die
->num_attrs
; ++i
)
23399 print_spaces (indent
, f
);
23400 fprintf_unfiltered (f
, " %s (%s) ",
23401 dwarf_attr_name (die
->attrs
[i
].name
),
23402 dwarf_form_name (die
->attrs
[i
].form
));
23404 switch (die
->attrs
[i
].form
)
23407 case DW_FORM_addrx
:
23408 case DW_FORM_GNU_addr_index
:
23409 fprintf_unfiltered (f
, "address: ");
23410 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23412 case DW_FORM_block2
:
23413 case DW_FORM_block4
:
23414 case DW_FORM_block
:
23415 case DW_FORM_block1
:
23416 fprintf_unfiltered (f
, "block: size %s",
23417 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23419 case DW_FORM_exprloc
:
23420 fprintf_unfiltered (f
, "expression: size %s",
23421 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23423 case DW_FORM_data16
:
23424 fprintf_unfiltered (f
, "constant of 16 bytes");
23426 case DW_FORM_ref_addr
:
23427 fprintf_unfiltered (f
, "ref address: ");
23428 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23430 case DW_FORM_GNU_ref_alt
:
23431 fprintf_unfiltered (f
, "alt ref address: ");
23432 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23438 case DW_FORM_ref_udata
:
23439 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23440 (long) (DW_UNSND (&die
->attrs
[i
])));
23442 case DW_FORM_data1
:
23443 case DW_FORM_data2
:
23444 case DW_FORM_data4
:
23445 case DW_FORM_data8
:
23446 case DW_FORM_udata
:
23447 case DW_FORM_sdata
:
23448 fprintf_unfiltered (f
, "constant: %s",
23449 pulongest (DW_UNSND (&die
->attrs
[i
])));
23451 case DW_FORM_sec_offset
:
23452 fprintf_unfiltered (f
, "section offset: %s",
23453 pulongest (DW_UNSND (&die
->attrs
[i
])));
23455 case DW_FORM_ref_sig8
:
23456 fprintf_unfiltered (f
, "signature: %s",
23457 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23459 case DW_FORM_string
:
23461 case DW_FORM_line_strp
:
23463 case DW_FORM_GNU_str_index
:
23464 case DW_FORM_GNU_strp_alt
:
23465 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23466 DW_STRING (&die
->attrs
[i
])
23467 ? DW_STRING (&die
->attrs
[i
]) : "",
23468 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23471 if (DW_UNSND (&die
->attrs
[i
]))
23472 fprintf_unfiltered (f
, "flag: TRUE");
23474 fprintf_unfiltered (f
, "flag: FALSE");
23476 case DW_FORM_flag_present
:
23477 fprintf_unfiltered (f
, "flag: TRUE");
23479 case DW_FORM_indirect
:
23480 /* The reader will have reduced the indirect form to
23481 the "base form" so this form should not occur. */
23482 fprintf_unfiltered (f
,
23483 "unexpected attribute form: DW_FORM_indirect");
23485 case DW_FORM_implicit_const
:
23486 fprintf_unfiltered (f
, "constant: %s",
23487 plongest (DW_SND (&die
->attrs
[i
])));
23490 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23491 die
->attrs
[i
].form
);
23494 fprintf_unfiltered (f
, "\n");
23499 dump_die_for_error (struct die_info
*die
)
23501 dump_die_shallow (gdb_stderr
, 0, die
);
23505 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23507 int indent
= level
* 4;
23509 gdb_assert (die
!= NULL
);
23511 if (level
>= max_level
)
23514 dump_die_shallow (f
, indent
, die
);
23516 if (die
->child
!= NULL
)
23518 print_spaces (indent
, f
);
23519 fprintf_unfiltered (f
, " Children:");
23520 if (level
+ 1 < max_level
)
23522 fprintf_unfiltered (f
, "\n");
23523 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23527 fprintf_unfiltered (f
,
23528 " [not printed, max nesting level reached]\n");
23532 if (die
->sibling
!= NULL
&& level
> 0)
23534 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23538 /* This is called from the pdie macro in gdbinit.in.
23539 It's not static so gcc will keep a copy callable from gdb. */
23542 dump_die (struct die_info
*die
, int max_level
)
23544 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23548 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23552 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23553 to_underlying (die
->sect_off
),
23559 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23563 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23565 if (attr_form_is_ref (attr
))
23566 return (sect_offset
) DW_UNSND (attr
);
23568 complaint (_("unsupported die ref attribute form: '%s'"),
23569 dwarf_form_name (attr
->form
));
23573 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23574 * the value held by the attribute is not constant. */
23577 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23579 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23580 return DW_SND (attr
);
23581 else if (attr
->form
== DW_FORM_udata
23582 || attr
->form
== DW_FORM_data1
23583 || attr
->form
== DW_FORM_data2
23584 || attr
->form
== DW_FORM_data4
23585 || attr
->form
== DW_FORM_data8
)
23586 return DW_UNSND (attr
);
23589 /* For DW_FORM_data16 see attr_form_is_constant. */
23590 complaint (_("Attribute value is not a constant (%s)"),
23591 dwarf_form_name (attr
->form
));
23592 return default_value
;
23596 /* Follow reference or signature attribute ATTR of SRC_DIE.
23597 On entry *REF_CU is the CU of SRC_DIE.
23598 On exit *REF_CU is the CU of the result. */
23600 static struct die_info
*
23601 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23602 struct dwarf2_cu
**ref_cu
)
23604 struct die_info
*die
;
23606 if (attr_form_is_ref (attr
))
23607 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23608 else if (attr
->form
== DW_FORM_ref_sig8
)
23609 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23612 dump_die_for_error (src_die
);
23613 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23614 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23620 /* Follow reference OFFSET.
23621 On entry *REF_CU is the CU of the source die referencing OFFSET.
23622 On exit *REF_CU is the CU of the result.
23623 Returns NULL if OFFSET is invalid. */
23625 static struct die_info
*
23626 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23627 struct dwarf2_cu
**ref_cu
)
23629 struct die_info temp_die
;
23630 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23631 struct dwarf2_per_objfile
*dwarf2_per_objfile
23632 = cu
->per_cu
->dwarf2_per_objfile
;
23634 gdb_assert (cu
->per_cu
!= NULL
);
23638 if (cu
->per_cu
->is_debug_types
)
23640 /* .debug_types CUs cannot reference anything outside their CU.
23641 If they need to, they have to reference a signatured type via
23642 DW_FORM_ref_sig8. */
23643 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23646 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23647 || !offset_in_cu_p (&cu
->header
, sect_off
))
23649 struct dwarf2_per_cu_data
*per_cu
;
23651 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23652 dwarf2_per_objfile
);
23654 /* If necessary, add it to the queue and load its DIEs. */
23655 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23656 load_full_comp_unit (per_cu
, false, cu
->language
);
23658 target_cu
= per_cu
->cu
;
23660 else if (cu
->dies
== NULL
)
23662 /* We're loading full DIEs during partial symbol reading. */
23663 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23664 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23667 *ref_cu
= target_cu
;
23668 temp_die
.sect_off
= sect_off
;
23670 if (target_cu
!= cu
)
23671 target_cu
->ancestor
= cu
;
23673 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23675 to_underlying (sect_off
));
23678 /* Follow reference attribute ATTR of SRC_DIE.
23679 On entry *REF_CU is the CU of SRC_DIE.
23680 On exit *REF_CU is the CU of the result. */
23682 static struct die_info
*
23683 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23684 struct dwarf2_cu
**ref_cu
)
23686 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23687 struct dwarf2_cu
*cu
= *ref_cu
;
23688 struct die_info
*die
;
23690 die
= follow_die_offset (sect_off
,
23691 (attr
->form
== DW_FORM_GNU_ref_alt
23692 || cu
->per_cu
->is_dwz
),
23695 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23696 "at %s [in module %s]"),
23697 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23698 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23703 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23704 Returned value is intended for DW_OP_call*. Returned
23705 dwarf2_locexpr_baton->data has lifetime of
23706 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23708 struct dwarf2_locexpr_baton
23709 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23710 struct dwarf2_per_cu_data
*per_cu
,
23711 CORE_ADDR (*get_frame_pc
) (void *baton
),
23712 void *baton
, bool resolve_abstract_p
)
23714 struct dwarf2_cu
*cu
;
23715 struct die_info
*die
;
23716 struct attribute
*attr
;
23717 struct dwarf2_locexpr_baton retval
;
23718 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23719 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23721 if (per_cu
->cu
== NULL
)
23722 load_cu (per_cu
, false);
23726 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23727 Instead just throw an error, not much else we can do. */
23728 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23729 sect_offset_str (sect_off
), objfile_name (objfile
));
23732 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23734 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23735 sect_offset_str (sect_off
), objfile_name (objfile
));
23737 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23738 if (!attr
&& resolve_abstract_p
23739 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23740 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23742 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23743 CORE_ADDR baseaddr
= objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
23744 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23746 for (const auto &cand_off
23747 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23749 struct dwarf2_cu
*cand_cu
= cu
;
23750 struct die_info
*cand
23751 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23754 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23757 CORE_ADDR pc_low
, pc_high
;
23758 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23759 if (pc_low
== ((CORE_ADDR
) -1))
23761 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23762 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23763 if (!(pc_low
<= pc
&& pc
< pc_high
))
23767 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23774 /* DWARF: "If there is no such attribute, then there is no effect.".
23775 DATA is ignored if SIZE is 0. */
23777 retval
.data
= NULL
;
23780 else if (attr_form_is_section_offset (attr
))
23782 struct dwarf2_loclist_baton loclist_baton
;
23783 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23786 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23788 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23790 retval
.size
= size
;
23794 if (!attr_form_is_block (attr
))
23795 error (_("Dwarf Error: DIE at %s referenced in module %s "
23796 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23797 sect_offset_str (sect_off
), objfile_name (objfile
));
23799 retval
.data
= DW_BLOCK (attr
)->data
;
23800 retval
.size
= DW_BLOCK (attr
)->size
;
23802 retval
.per_cu
= cu
->per_cu
;
23804 age_cached_comp_units (dwarf2_per_objfile
);
23809 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23812 struct dwarf2_locexpr_baton
23813 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23814 struct dwarf2_per_cu_data
*per_cu
,
23815 CORE_ADDR (*get_frame_pc
) (void *baton
),
23818 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23820 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23823 /* Write a constant of a given type as target-ordered bytes into
23826 static const gdb_byte
*
23827 write_constant_as_bytes (struct obstack
*obstack
,
23828 enum bfd_endian byte_order
,
23835 *len
= TYPE_LENGTH (type
);
23836 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23837 store_unsigned_integer (result
, *len
, byte_order
, value
);
23842 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23843 pointer to the constant bytes and set LEN to the length of the
23844 data. If memory is needed, allocate it on OBSTACK. If the DIE
23845 does not have a DW_AT_const_value, return NULL. */
23848 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23849 struct dwarf2_per_cu_data
*per_cu
,
23850 struct obstack
*obstack
,
23853 struct dwarf2_cu
*cu
;
23854 struct die_info
*die
;
23855 struct attribute
*attr
;
23856 const gdb_byte
*result
= NULL
;
23859 enum bfd_endian byte_order
;
23860 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23862 if (per_cu
->cu
== NULL
)
23863 load_cu (per_cu
, false);
23867 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23868 Instead just throw an error, not much else we can do. */
23869 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23870 sect_offset_str (sect_off
), objfile_name (objfile
));
23873 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23875 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23876 sect_offset_str (sect_off
), objfile_name (objfile
));
23878 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23882 byte_order
= (bfd_big_endian (objfile
->obfd
)
23883 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23885 switch (attr
->form
)
23888 case DW_FORM_addrx
:
23889 case DW_FORM_GNU_addr_index
:
23893 *len
= cu
->header
.addr_size
;
23894 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23895 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23899 case DW_FORM_string
:
23902 case DW_FORM_GNU_str_index
:
23903 case DW_FORM_GNU_strp_alt
:
23904 /* DW_STRING is already allocated on the objfile obstack, point
23906 result
= (const gdb_byte
*) DW_STRING (attr
);
23907 *len
= strlen (DW_STRING (attr
));
23909 case DW_FORM_block1
:
23910 case DW_FORM_block2
:
23911 case DW_FORM_block4
:
23912 case DW_FORM_block
:
23913 case DW_FORM_exprloc
:
23914 case DW_FORM_data16
:
23915 result
= DW_BLOCK (attr
)->data
;
23916 *len
= DW_BLOCK (attr
)->size
;
23919 /* The DW_AT_const_value attributes are supposed to carry the
23920 symbol's value "represented as it would be on the target
23921 architecture." By the time we get here, it's already been
23922 converted to host endianness, so we just need to sign- or
23923 zero-extend it as appropriate. */
23924 case DW_FORM_data1
:
23925 type
= die_type (die
, cu
);
23926 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23927 if (result
== NULL
)
23928 result
= write_constant_as_bytes (obstack
, byte_order
,
23931 case DW_FORM_data2
:
23932 type
= die_type (die
, cu
);
23933 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23934 if (result
== NULL
)
23935 result
= write_constant_as_bytes (obstack
, byte_order
,
23938 case DW_FORM_data4
:
23939 type
= die_type (die
, cu
);
23940 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23941 if (result
== NULL
)
23942 result
= write_constant_as_bytes (obstack
, byte_order
,
23945 case DW_FORM_data8
:
23946 type
= die_type (die
, cu
);
23947 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23948 if (result
== NULL
)
23949 result
= write_constant_as_bytes (obstack
, byte_order
,
23953 case DW_FORM_sdata
:
23954 case DW_FORM_implicit_const
:
23955 type
= die_type (die
, cu
);
23956 result
= write_constant_as_bytes (obstack
, byte_order
,
23957 type
, DW_SND (attr
), len
);
23960 case DW_FORM_udata
:
23961 type
= die_type (die
, cu
);
23962 result
= write_constant_as_bytes (obstack
, byte_order
,
23963 type
, DW_UNSND (attr
), len
);
23967 complaint (_("unsupported const value attribute form: '%s'"),
23968 dwarf_form_name (attr
->form
));
23975 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23976 valid type for this die is found. */
23979 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23980 struct dwarf2_per_cu_data
*per_cu
)
23982 struct dwarf2_cu
*cu
;
23983 struct die_info
*die
;
23985 if (per_cu
->cu
== NULL
)
23986 load_cu (per_cu
, false);
23991 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23995 return die_type (die
, cu
);
23998 /* Return the type of the DIE at DIE_OFFSET in the CU named by
24002 dwarf2_get_die_type (cu_offset die_offset
,
24003 struct dwarf2_per_cu_data
*per_cu
)
24005 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
24006 return get_die_type_at_offset (die_offset_sect
, per_cu
);
24009 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
24010 On entry *REF_CU is the CU of SRC_DIE.
24011 On exit *REF_CU is the CU of the result.
24012 Returns NULL if the referenced DIE isn't found. */
24014 static struct die_info
*
24015 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
24016 struct dwarf2_cu
**ref_cu
)
24018 struct die_info temp_die
;
24019 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
24020 struct die_info
*die
;
24022 /* While it might be nice to assert sig_type->type == NULL here,
24023 we can get here for DW_AT_imported_declaration where we need
24024 the DIE not the type. */
24026 /* If necessary, add it to the queue and load its DIEs. */
24028 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
24029 read_signatured_type (sig_type
);
24031 sig_cu
= sig_type
->per_cu
.cu
;
24032 gdb_assert (sig_cu
!= NULL
);
24033 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
24034 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
24035 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
24036 to_underlying (temp_die
.sect_off
));
24039 struct dwarf2_per_objfile
*dwarf2_per_objfile
24040 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
24042 /* For .gdb_index version 7 keep track of included TUs.
24043 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
24044 if (dwarf2_per_objfile
->index_table
!= NULL
24045 && dwarf2_per_objfile
->index_table
->version
<= 7)
24047 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
24052 sig_cu
->ancestor
= cu
;
24060 /* Follow signatured type referenced by ATTR in SRC_DIE.
24061 On entry *REF_CU is the CU of SRC_DIE.
24062 On exit *REF_CU is the CU of the result.
24063 The result is the DIE of the type.
24064 If the referenced type cannot be found an error is thrown. */
24066 static struct die_info
*
24067 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
24068 struct dwarf2_cu
**ref_cu
)
24070 ULONGEST signature
= DW_SIGNATURE (attr
);
24071 struct signatured_type
*sig_type
;
24072 struct die_info
*die
;
24074 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
24076 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
24077 /* sig_type will be NULL if the signatured type is missing from
24079 if (sig_type
== NULL
)
24081 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24082 " from DIE at %s [in module %s]"),
24083 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24084 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24087 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24090 dump_die_for_error (src_die
);
24091 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24092 " from DIE at %s [in module %s]"),
24093 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24094 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24100 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24101 reading in and processing the type unit if necessary. */
24103 static struct type
*
24104 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24105 struct dwarf2_cu
*cu
)
24107 struct dwarf2_per_objfile
*dwarf2_per_objfile
24108 = cu
->per_cu
->dwarf2_per_objfile
;
24109 struct signatured_type
*sig_type
;
24110 struct dwarf2_cu
*type_cu
;
24111 struct die_info
*type_die
;
24114 sig_type
= lookup_signatured_type (cu
, signature
);
24115 /* sig_type will be NULL if the signatured type is missing from
24117 if (sig_type
== NULL
)
24119 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24120 " from DIE at %s [in module %s]"),
24121 hex_string (signature
), sect_offset_str (die
->sect_off
),
24122 objfile_name (dwarf2_per_objfile
->objfile
));
24123 return build_error_marker_type (cu
, die
);
24126 /* If we already know the type we're done. */
24127 if (sig_type
->type
!= NULL
)
24128 return sig_type
->type
;
24131 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24132 if (type_die
!= NULL
)
24134 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24135 is created. This is important, for example, because for c++ classes
24136 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24137 type
= read_type_die (type_die
, type_cu
);
24140 complaint (_("Dwarf Error: Cannot build signatured type %s"
24141 " referenced from DIE at %s [in module %s]"),
24142 hex_string (signature
), sect_offset_str (die
->sect_off
),
24143 objfile_name (dwarf2_per_objfile
->objfile
));
24144 type
= build_error_marker_type (cu
, die
);
24149 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24150 " from DIE at %s [in module %s]"),
24151 hex_string (signature
), sect_offset_str (die
->sect_off
),
24152 objfile_name (dwarf2_per_objfile
->objfile
));
24153 type
= build_error_marker_type (cu
, die
);
24155 sig_type
->type
= type
;
24160 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24161 reading in and processing the type unit if necessary. */
24163 static struct type
*
24164 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24165 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24167 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24168 if (attr_form_is_ref (attr
))
24170 struct dwarf2_cu
*type_cu
= cu
;
24171 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24173 return read_type_die (type_die
, type_cu
);
24175 else if (attr
->form
== DW_FORM_ref_sig8
)
24177 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24181 struct dwarf2_per_objfile
*dwarf2_per_objfile
24182 = cu
->per_cu
->dwarf2_per_objfile
;
24184 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24185 " at %s [in module %s]"),
24186 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24187 objfile_name (dwarf2_per_objfile
->objfile
));
24188 return build_error_marker_type (cu
, die
);
24192 /* Load the DIEs associated with type unit PER_CU into memory. */
24195 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24197 struct signatured_type
*sig_type
;
24199 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24200 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24202 /* We have the per_cu, but we need the signatured_type.
24203 Fortunately this is an easy translation. */
24204 gdb_assert (per_cu
->is_debug_types
);
24205 sig_type
= (struct signatured_type
*) per_cu
;
24207 gdb_assert (per_cu
->cu
== NULL
);
24209 read_signatured_type (sig_type
);
24211 gdb_assert (per_cu
->cu
!= NULL
);
24214 /* die_reader_func for read_signatured_type.
24215 This is identical to load_full_comp_unit_reader,
24216 but is kept separate for now. */
24219 read_signatured_type_reader (const struct die_reader_specs
*reader
,
24220 const gdb_byte
*info_ptr
,
24221 struct die_info
*comp_unit_die
,
24225 struct dwarf2_cu
*cu
= reader
->cu
;
24227 gdb_assert (cu
->die_hash
== NULL
);
24229 htab_create_alloc_ex (cu
->header
.length
/ 12,
24233 &cu
->comp_unit_obstack
,
24234 hashtab_obstack_allocate
,
24235 dummy_obstack_deallocate
);
24238 comp_unit_die
->child
= read_die_and_siblings (reader
, info_ptr
,
24239 &info_ptr
, comp_unit_die
);
24240 cu
->dies
= comp_unit_die
;
24241 /* comp_unit_die is not stored in die_hash, no need. */
24243 /* We try not to read any attributes in this function, because not
24244 all CUs needed for references have been loaded yet, and symbol
24245 table processing isn't initialized. But we have to set the CU language,
24246 or we won't be able to build types correctly.
24247 Similarly, if we do not read the producer, we can not apply
24248 producer-specific interpretation. */
24249 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24252 /* Read in a signatured type and build its CU and DIEs.
24253 If the type is a stub for the real type in a DWO file,
24254 read in the real type from the DWO file as well. */
24257 read_signatured_type (struct signatured_type
*sig_type
)
24259 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24261 gdb_assert (per_cu
->is_debug_types
);
24262 gdb_assert (per_cu
->cu
== NULL
);
24264 init_cutu_and_read_dies (per_cu
, NULL
, 0, 1, false,
24265 read_signatured_type_reader
, NULL
);
24266 sig_type
->per_cu
.tu_read
= 1;
24269 /* Decode simple location descriptions.
24270 Given a pointer to a dwarf block that defines a location, compute
24271 the location and return the value.
24273 NOTE drow/2003-11-18: This function is called in two situations
24274 now: for the address of static or global variables (partial symbols
24275 only) and for offsets into structures which are expected to be
24276 (more or less) constant. The partial symbol case should go away,
24277 and only the constant case should remain. That will let this
24278 function complain more accurately. A few special modes are allowed
24279 without complaint for global variables (for instance, global
24280 register values and thread-local values).
24282 A location description containing no operations indicates that the
24283 object is optimized out. The return value is 0 for that case.
24284 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24285 callers will only want a very basic result and this can become a
24288 Note that stack[0] is unused except as a default error return. */
24291 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24293 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24295 size_t size
= blk
->size
;
24296 const gdb_byte
*data
= blk
->data
;
24297 CORE_ADDR stack
[64];
24299 unsigned int bytes_read
, unsnd
;
24305 stack
[++stacki
] = 0;
24344 stack
[++stacki
] = op
- DW_OP_lit0
;
24379 stack
[++stacki
] = op
- DW_OP_reg0
;
24381 dwarf2_complex_location_expr_complaint ();
24385 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24387 stack
[++stacki
] = unsnd
;
24389 dwarf2_complex_location_expr_complaint ();
24393 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24398 case DW_OP_const1u
:
24399 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24403 case DW_OP_const1s
:
24404 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24408 case DW_OP_const2u
:
24409 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24413 case DW_OP_const2s
:
24414 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24418 case DW_OP_const4u
:
24419 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24423 case DW_OP_const4s
:
24424 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24428 case DW_OP_const8u
:
24429 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24434 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24440 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24445 stack
[stacki
+ 1] = stack
[stacki
];
24450 stack
[stacki
- 1] += stack
[stacki
];
24454 case DW_OP_plus_uconst
:
24455 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24461 stack
[stacki
- 1] -= stack
[stacki
];
24466 /* If we're not the last op, then we definitely can't encode
24467 this using GDB's address_class enum. This is valid for partial
24468 global symbols, although the variable's address will be bogus
24471 dwarf2_complex_location_expr_complaint ();
24474 case DW_OP_GNU_push_tls_address
:
24475 case DW_OP_form_tls_address
:
24476 /* The top of the stack has the offset from the beginning
24477 of the thread control block at which the variable is located. */
24478 /* Nothing should follow this operator, so the top of stack would
24480 /* This is valid for partial global symbols, but the variable's
24481 address will be bogus in the psymtab. Make it always at least
24482 non-zero to not look as a variable garbage collected by linker
24483 which have DW_OP_addr 0. */
24485 dwarf2_complex_location_expr_complaint ();
24489 case DW_OP_GNU_uninit
:
24493 case DW_OP_GNU_addr_index
:
24494 case DW_OP_GNU_const_index
:
24495 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24502 const char *name
= get_DW_OP_name (op
);
24505 complaint (_("unsupported stack op: '%s'"),
24508 complaint (_("unsupported stack op: '%02x'"),
24512 return (stack
[stacki
]);
24515 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24516 outside of the allocated space. Also enforce minimum>0. */
24517 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24519 complaint (_("location description stack overflow"));
24525 complaint (_("location description stack underflow"));
24529 return (stack
[stacki
]);
24532 /* memory allocation interface */
24534 static struct dwarf_block
*
24535 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24537 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24540 static struct die_info
*
24541 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24543 struct die_info
*die
;
24544 size_t size
= sizeof (struct die_info
);
24547 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24549 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24550 memset (die
, 0, sizeof (struct die_info
));
24555 /* Macro support. */
24557 /* Return file name relative to the compilation directory of file number I in
24558 *LH's file name table. The result is allocated using xmalloc; the caller is
24559 responsible for freeing it. */
24562 file_file_name (int file
, struct line_header
*lh
)
24564 /* Is the file number a valid index into the line header's file name
24565 table? Remember that file numbers start with one, not zero. */
24566 if (lh
->is_valid_file_index (file
))
24568 const file_entry
*fe
= lh
->file_name_at (file
);
24570 if (!IS_ABSOLUTE_PATH (fe
->name
))
24572 const char *dir
= fe
->include_dir (lh
);
24574 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24576 return xstrdup (fe
->name
);
24580 /* The compiler produced a bogus file number. We can at least
24581 record the macro definitions made in the file, even if we
24582 won't be able to find the file by name. */
24583 char fake_name
[80];
24585 xsnprintf (fake_name
, sizeof (fake_name
),
24586 "<bad macro file number %d>", file
);
24588 complaint (_("bad file number in macro information (%d)"),
24591 return xstrdup (fake_name
);
24595 /* Return the full name of file number I in *LH's file name table.
24596 Use COMP_DIR as the name of the current directory of the
24597 compilation. The result is allocated using xmalloc; the caller is
24598 responsible for freeing it. */
24600 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24602 /* Is the file number a valid index into the line header's file name
24603 table? Remember that file numbers start with one, not zero. */
24604 if (lh
->is_valid_file_index (file
))
24606 char *relative
= file_file_name (file
, lh
);
24608 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24610 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24611 relative
, (char *) NULL
);
24614 return file_file_name (file
, lh
);
24618 static struct macro_source_file
*
24619 macro_start_file (struct dwarf2_cu
*cu
,
24620 int file
, int line
,
24621 struct macro_source_file
*current_file
,
24622 struct line_header
*lh
)
24624 /* File name relative to the compilation directory of this source file. */
24625 char *file_name
= file_file_name (file
, lh
);
24627 if (! current_file
)
24629 /* Note: We don't create a macro table for this compilation unit
24630 at all until we actually get a filename. */
24631 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24633 /* If we have no current file, then this must be the start_file
24634 directive for the compilation unit's main source file. */
24635 current_file
= macro_set_main (macro_table
, file_name
);
24636 macro_define_special (macro_table
);
24639 current_file
= macro_include (current_file
, line
, file_name
);
24643 return current_file
;
24646 static const char *
24647 consume_improper_spaces (const char *p
, const char *body
)
24651 complaint (_("macro definition contains spaces "
24652 "in formal argument list:\n`%s'"),
24664 parse_macro_definition (struct macro_source_file
*file
, int line
,
24669 /* The body string takes one of two forms. For object-like macro
24670 definitions, it should be:
24672 <macro name> " " <definition>
24674 For function-like macro definitions, it should be:
24676 <macro name> "() " <definition>
24678 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24680 Spaces may appear only where explicitly indicated, and in the
24683 The Dwarf 2 spec says that an object-like macro's name is always
24684 followed by a space, but versions of GCC around March 2002 omit
24685 the space when the macro's definition is the empty string.
24687 The Dwarf 2 spec says that there should be no spaces between the
24688 formal arguments in a function-like macro's formal argument list,
24689 but versions of GCC around March 2002 include spaces after the
24693 /* Find the extent of the macro name. The macro name is terminated
24694 by either a space or null character (for an object-like macro) or
24695 an opening paren (for a function-like macro). */
24696 for (p
= body
; *p
; p
++)
24697 if (*p
== ' ' || *p
== '(')
24700 if (*p
== ' ' || *p
== '\0')
24702 /* It's an object-like macro. */
24703 int name_len
= p
- body
;
24704 std::string
name (body
, name_len
);
24705 const char *replacement
;
24708 replacement
= body
+ name_len
+ 1;
24711 dwarf2_macro_malformed_definition_complaint (body
);
24712 replacement
= body
+ name_len
;
24715 macro_define_object (file
, line
, name
.c_str (), replacement
);
24717 else if (*p
== '(')
24719 /* It's a function-like macro. */
24720 std::string
name (body
, p
- body
);
24723 char **argv
= XNEWVEC (char *, argv_size
);
24727 p
= consume_improper_spaces (p
, body
);
24729 /* Parse the formal argument list. */
24730 while (*p
&& *p
!= ')')
24732 /* Find the extent of the current argument name. */
24733 const char *arg_start
= p
;
24735 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24738 if (! *p
|| p
== arg_start
)
24739 dwarf2_macro_malformed_definition_complaint (body
);
24742 /* Make sure argv has room for the new argument. */
24743 if (argc
>= argv_size
)
24746 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24749 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24752 p
= consume_improper_spaces (p
, body
);
24754 /* Consume the comma, if present. */
24759 p
= consume_improper_spaces (p
, body
);
24768 /* Perfectly formed definition, no complaints. */
24769 macro_define_function (file
, line
, name
.c_str (),
24770 argc
, (const char **) argv
,
24772 else if (*p
== '\0')
24774 /* Complain, but do define it. */
24775 dwarf2_macro_malformed_definition_complaint (body
);
24776 macro_define_function (file
, line
, name
.c_str (),
24777 argc
, (const char **) argv
,
24781 /* Just complain. */
24782 dwarf2_macro_malformed_definition_complaint (body
);
24785 /* Just complain. */
24786 dwarf2_macro_malformed_definition_complaint (body
);
24791 for (i
= 0; i
< argc
; i
++)
24797 dwarf2_macro_malformed_definition_complaint (body
);
24800 /* Skip some bytes from BYTES according to the form given in FORM.
24801 Returns the new pointer. */
24803 static const gdb_byte
*
24804 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24805 enum dwarf_form form
,
24806 unsigned int offset_size
,
24807 struct dwarf2_section_info
*section
)
24809 unsigned int bytes_read
;
24813 case DW_FORM_data1
:
24818 case DW_FORM_data2
:
24822 case DW_FORM_data4
:
24826 case DW_FORM_data8
:
24830 case DW_FORM_data16
:
24834 case DW_FORM_string
:
24835 read_direct_string (abfd
, bytes
, &bytes_read
);
24836 bytes
+= bytes_read
;
24839 case DW_FORM_sec_offset
:
24841 case DW_FORM_GNU_strp_alt
:
24842 bytes
+= offset_size
;
24845 case DW_FORM_block
:
24846 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24847 bytes
+= bytes_read
;
24850 case DW_FORM_block1
:
24851 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24853 case DW_FORM_block2
:
24854 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24856 case DW_FORM_block4
:
24857 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24860 case DW_FORM_addrx
:
24861 case DW_FORM_sdata
:
24863 case DW_FORM_udata
:
24864 case DW_FORM_GNU_addr_index
:
24865 case DW_FORM_GNU_str_index
:
24866 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24869 dwarf2_section_buffer_overflow_complaint (section
);
24874 case DW_FORM_implicit_const
:
24879 complaint (_("invalid form 0x%x in `%s'"),
24880 form
, get_section_name (section
));
24888 /* A helper for dwarf_decode_macros that handles skipping an unknown
24889 opcode. Returns an updated pointer to the macro data buffer; or,
24890 on error, issues a complaint and returns NULL. */
24892 static const gdb_byte
*
24893 skip_unknown_opcode (unsigned int opcode
,
24894 const gdb_byte
**opcode_definitions
,
24895 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24897 unsigned int offset_size
,
24898 struct dwarf2_section_info
*section
)
24900 unsigned int bytes_read
, i
;
24902 const gdb_byte
*defn
;
24904 if (opcode_definitions
[opcode
] == NULL
)
24906 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24911 defn
= opcode_definitions
[opcode
];
24912 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24913 defn
+= bytes_read
;
24915 for (i
= 0; i
< arg
; ++i
)
24917 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24918 (enum dwarf_form
) defn
[i
], offset_size
,
24920 if (mac_ptr
== NULL
)
24922 /* skip_form_bytes already issued the complaint. */
24930 /* A helper function which parses the header of a macro section.
24931 If the macro section is the extended (for now called "GNU") type,
24932 then this updates *OFFSET_SIZE. Returns a pointer to just after
24933 the header, or issues a complaint and returns NULL on error. */
24935 static const gdb_byte
*
24936 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24938 const gdb_byte
*mac_ptr
,
24939 unsigned int *offset_size
,
24940 int section_is_gnu
)
24942 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24944 if (section_is_gnu
)
24946 unsigned int version
, flags
;
24948 version
= read_2_bytes (abfd
, mac_ptr
);
24949 if (version
!= 4 && version
!= 5)
24951 complaint (_("unrecognized version `%d' in .debug_macro section"),
24957 flags
= read_1_byte (abfd
, mac_ptr
);
24959 *offset_size
= (flags
& 1) ? 8 : 4;
24961 if ((flags
& 2) != 0)
24962 /* We don't need the line table offset. */
24963 mac_ptr
+= *offset_size
;
24965 /* Vendor opcode descriptions. */
24966 if ((flags
& 4) != 0)
24968 unsigned int i
, count
;
24970 count
= read_1_byte (abfd
, mac_ptr
);
24972 for (i
= 0; i
< count
; ++i
)
24974 unsigned int opcode
, bytes_read
;
24977 opcode
= read_1_byte (abfd
, mac_ptr
);
24979 opcode_definitions
[opcode
] = mac_ptr
;
24980 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24981 mac_ptr
+= bytes_read
;
24990 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24991 including DW_MACRO_import. */
24994 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24996 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24997 struct macro_source_file
*current_file
,
24998 struct line_header
*lh
,
24999 struct dwarf2_section_info
*section
,
25000 int section_is_gnu
, int section_is_dwz
,
25001 unsigned int offset_size
,
25002 htab_t include_hash
)
25004 struct dwarf2_per_objfile
*dwarf2_per_objfile
25005 = cu
->per_cu
->dwarf2_per_objfile
;
25006 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25007 enum dwarf_macro_record_type macinfo_type
;
25008 int at_commandline
;
25009 const gdb_byte
*opcode_definitions
[256];
25011 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25012 &offset_size
, section_is_gnu
);
25013 if (mac_ptr
== NULL
)
25015 /* We already issued a complaint. */
25019 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
25020 GDB is still reading the definitions from command line. First
25021 DW_MACINFO_start_file will need to be ignored as it was already executed
25022 to create CURRENT_FILE for the main source holding also the command line
25023 definitions. On first met DW_MACINFO_start_file this flag is reset to
25024 normally execute all the remaining DW_MACINFO_start_file macinfos. */
25026 at_commandline
= 1;
25030 /* Do we at least have room for a macinfo type byte? */
25031 if (mac_ptr
>= mac_end
)
25033 dwarf2_section_buffer_overflow_complaint (section
);
25037 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25040 /* Note that we rely on the fact that the corresponding GNU and
25041 DWARF constants are the same. */
25043 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25044 switch (macinfo_type
)
25046 /* A zero macinfo type indicates the end of the macro
25051 case DW_MACRO_define
:
25052 case DW_MACRO_undef
:
25053 case DW_MACRO_define_strp
:
25054 case DW_MACRO_undef_strp
:
25055 case DW_MACRO_define_sup
:
25056 case DW_MACRO_undef_sup
:
25058 unsigned int bytes_read
;
25063 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25064 mac_ptr
+= bytes_read
;
25066 if (macinfo_type
== DW_MACRO_define
25067 || macinfo_type
== DW_MACRO_undef
)
25069 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25070 mac_ptr
+= bytes_read
;
25074 LONGEST str_offset
;
25076 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25077 mac_ptr
+= offset_size
;
25079 if (macinfo_type
== DW_MACRO_define_sup
25080 || macinfo_type
== DW_MACRO_undef_sup
25083 struct dwz_file
*dwz
25084 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
25086 body
= read_indirect_string_from_dwz (objfile
,
25090 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
25094 is_define
= (macinfo_type
== DW_MACRO_define
25095 || macinfo_type
== DW_MACRO_define_strp
25096 || macinfo_type
== DW_MACRO_define_sup
);
25097 if (! current_file
)
25099 /* DWARF violation as no main source is present. */
25100 complaint (_("debug info with no main source gives macro %s "
25102 is_define
? _("definition") : _("undefinition"),
25106 if ((line
== 0 && !at_commandline
)
25107 || (line
!= 0 && at_commandline
))
25108 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
25109 at_commandline
? _("command-line") : _("in-file"),
25110 is_define
? _("definition") : _("undefinition"),
25111 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
25115 /* Fedora's rpm-build's "debugedit" binary
25116 corrupted .debug_macro sections.
25119 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
25120 complaint (_("debug info gives %s invalid macro %s "
25121 "without body (corrupted?) at line %d "
25123 at_commandline
? _("command-line") : _("in-file"),
25124 is_define
? _("definition") : _("undefinition"),
25125 line
, current_file
->filename
);
25127 else if (is_define
)
25128 parse_macro_definition (current_file
, line
, body
);
25131 gdb_assert (macinfo_type
== DW_MACRO_undef
25132 || macinfo_type
== DW_MACRO_undef_strp
25133 || macinfo_type
== DW_MACRO_undef_sup
);
25134 macro_undef (current_file
, line
, body
);
25139 case DW_MACRO_start_file
:
25141 unsigned int bytes_read
;
25144 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25145 mac_ptr
+= bytes_read
;
25146 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25147 mac_ptr
+= bytes_read
;
25149 if ((line
== 0 && !at_commandline
)
25150 || (line
!= 0 && at_commandline
))
25151 complaint (_("debug info gives source %d included "
25152 "from %s at %s line %d"),
25153 file
, at_commandline
? _("command-line") : _("file"),
25154 line
== 0 ? _("zero") : _("non-zero"), line
);
25156 if (at_commandline
)
25158 /* This DW_MACRO_start_file was executed in the
25160 at_commandline
= 0;
25163 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25168 case DW_MACRO_end_file
:
25169 if (! current_file
)
25170 complaint (_("macro debug info has an unmatched "
25171 "`close_file' directive"));
25174 current_file
= current_file
->included_by
;
25175 if (! current_file
)
25177 enum dwarf_macro_record_type next_type
;
25179 /* GCC circa March 2002 doesn't produce the zero
25180 type byte marking the end of the compilation
25181 unit. Complain if it's not there, but exit no
25184 /* Do we at least have room for a macinfo type byte? */
25185 if (mac_ptr
>= mac_end
)
25187 dwarf2_section_buffer_overflow_complaint (section
);
25191 /* We don't increment mac_ptr here, so this is just
25194 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25196 if (next_type
!= 0)
25197 complaint (_("no terminating 0-type entry for "
25198 "macros in `.debug_macinfo' section"));
25205 case DW_MACRO_import
:
25206 case DW_MACRO_import_sup
:
25210 bfd
*include_bfd
= abfd
;
25211 struct dwarf2_section_info
*include_section
= section
;
25212 const gdb_byte
*include_mac_end
= mac_end
;
25213 int is_dwz
= section_is_dwz
;
25214 const gdb_byte
*new_mac_ptr
;
25216 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25217 mac_ptr
+= offset_size
;
25219 if (macinfo_type
== DW_MACRO_import_sup
)
25221 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25223 dwarf2_read_section (objfile
, &dwz
->macro
);
25225 include_section
= &dwz
->macro
;
25226 include_bfd
= get_section_bfd_owner (include_section
);
25227 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25231 new_mac_ptr
= include_section
->buffer
+ offset
;
25232 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25236 /* This has actually happened; see
25237 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25238 complaint (_("recursive DW_MACRO_import in "
25239 ".debug_macro section"));
25243 *slot
= (void *) new_mac_ptr
;
25245 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25246 include_mac_end
, current_file
, lh
,
25247 section
, section_is_gnu
, is_dwz
,
25248 offset_size
, include_hash
);
25250 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25255 case DW_MACINFO_vendor_ext
:
25256 if (!section_is_gnu
)
25258 unsigned int bytes_read
;
25260 /* This reads the constant, but since we don't recognize
25261 any vendor extensions, we ignore it. */
25262 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25263 mac_ptr
+= bytes_read
;
25264 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25265 mac_ptr
+= bytes_read
;
25267 /* We don't recognize any vendor extensions. */
25273 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25274 mac_ptr
, mac_end
, abfd
, offset_size
,
25276 if (mac_ptr
== NULL
)
25281 } while (macinfo_type
!= 0);
25285 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25286 int section_is_gnu
)
25288 struct dwarf2_per_objfile
*dwarf2_per_objfile
25289 = cu
->per_cu
->dwarf2_per_objfile
;
25290 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25291 struct line_header
*lh
= cu
->line_header
;
25293 const gdb_byte
*mac_ptr
, *mac_end
;
25294 struct macro_source_file
*current_file
= 0;
25295 enum dwarf_macro_record_type macinfo_type
;
25296 unsigned int offset_size
= cu
->header
.offset_size
;
25297 const gdb_byte
*opcode_definitions
[256];
25299 struct dwarf2_section_info
*section
;
25300 const char *section_name
;
25302 if (cu
->dwo_unit
!= NULL
)
25304 if (section_is_gnu
)
25306 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25307 section_name
= ".debug_macro.dwo";
25311 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25312 section_name
= ".debug_macinfo.dwo";
25317 if (section_is_gnu
)
25319 section
= &dwarf2_per_objfile
->macro
;
25320 section_name
= ".debug_macro";
25324 section
= &dwarf2_per_objfile
->macinfo
;
25325 section_name
= ".debug_macinfo";
25329 dwarf2_read_section (objfile
, section
);
25330 if (section
->buffer
== NULL
)
25332 complaint (_("missing %s section"), section_name
);
25335 abfd
= get_section_bfd_owner (section
);
25337 /* First pass: Find the name of the base filename.
25338 This filename is needed in order to process all macros whose definition
25339 (or undefinition) comes from the command line. These macros are defined
25340 before the first DW_MACINFO_start_file entry, and yet still need to be
25341 associated to the base file.
25343 To determine the base file name, we scan the macro definitions until we
25344 reach the first DW_MACINFO_start_file entry. We then initialize
25345 CURRENT_FILE accordingly so that any macro definition found before the
25346 first DW_MACINFO_start_file can still be associated to the base file. */
25348 mac_ptr
= section
->buffer
+ offset
;
25349 mac_end
= section
->buffer
+ section
->size
;
25351 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25352 &offset_size
, section_is_gnu
);
25353 if (mac_ptr
== NULL
)
25355 /* We already issued a complaint. */
25361 /* Do we at least have room for a macinfo type byte? */
25362 if (mac_ptr
>= mac_end
)
25364 /* Complaint is printed during the second pass as GDB will probably
25365 stop the first pass earlier upon finding
25366 DW_MACINFO_start_file. */
25370 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25373 /* Note that we rely on the fact that the corresponding GNU and
25374 DWARF constants are the same. */
25376 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25377 switch (macinfo_type
)
25379 /* A zero macinfo type indicates the end of the macro
25384 case DW_MACRO_define
:
25385 case DW_MACRO_undef
:
25386 /* Only skip the data by MAC_PTR. */
25388 unsigned int bytes_read
;
25390 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25391 mac_ptr
+= bytes_read
;
25392 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25393 mac_ptr
+= bytes_read
;
25397 case DW_MACRO_start_file
:
25399 unsigned int bytes_read
;
25402 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25403 mac_ptr
+= bytes_read
;
25404 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25405 mac_ptr
+= bytes_read
;
25407 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25411 case DW_MACRO_end_file
:
25412 /* No data to skip by MAC_PTR. */
25415 case DW_MACRO_define_strp
:
25416 case DW_MACRO_undef_strp
:
25417 case DW_MACRO_define_sup
:
25418 case DW_MACRO_undef_sup
:
25420 unsigned int bytes_read
;
25422 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25423 mac_ptr
+= bytes_read
;
25424 mac_ptr
+= offset_size
;
25428 case DW_MACRO_import
:
25429 case DW_MACRO_import_sup
:
25430 /* Note that, according to the spec, a transparent include
25431 chain cannot call DW_MACRO_start_file. So, we can just
25432 skip this opcode. */
25433 mac_ptr
+= offset_size
;
25436 case DW_MACINFO_vendor_ext
:
25437 /* Only skip the data by MAC_PTR. */
25438 if (!section_is_gnu
)
25440 unsigned int bytes_read
;
25442 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25443 mac_ptr
+= bytes_read
;
25444 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25445 mac_ptr
+= bytes_read
;
25450 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25451 mac_ptr
, mac_end
, abfd
, offset_size
,
25453 if (mac_ptr
== NULL
)
25458 } while (macinfo_type
!= 0 && current_file
== NULL
);
25460 /* Second pass: Process all entries.
25462 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25463 command-line macro definitions/undefinitions. This flag is unset when we
25464 reach the first DW_MACINFO_start_file entry. */
25466 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25468 NULL
, xcalloc
, xfree
));
25469 mac_ptr
= section
->buffer
+ offset
;
25470 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25471 *slot
= (void *) mac_ptr
;
25472 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25473 current_file
, lh
, section
,
25474 section_is_gnu
, 0, offset_size
,
25475 include_hash
.get ());
25478 /* Check if the attribute's form is a DW_FORM_block*
25479 if so return true else false. */
25482 attr_form_is_block (const struct attribute
*attr
)
25484 return (attr
== NULL
? 0 :
25485 attr
->form
== DW_FORM_block1
25486 || attr
->form
== DW_FORM_block2
25487 || attr
->form
== DW_FORM_block4
25488 || attr
->form
== DW_FORM_block
25489 || attr
->form
== DW_FORM_exprloc
);
25492 /* Return non-zero if ATTR's value is a section offset --- classes
25493 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25494 You may use DW_UNSND (attr) to retrieve such offsets.
25496 Section 7.5.4, "Attribute Encodings", explains that no attribute
25497 may have a value that belongs to more than one of these classes; it
25498 would be ambiguous if we did, because we use the same forms for all
25502 attr_form_is_section_offset (const struct attribute
*attr
)
25504 return (attr
->form
== DW_FORM_data4
25505 || attr
->form
== DW_FORM_data8
25506 || attr
->form
== DW_FORM_sec_offset
);
25509 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25510 zero otherwise. When this function returns true, you can apply
25511 dwarf2_get_attr_constant_value to it.
25513 However, note that for some attributes you must check
25514 attr_form_is_section_offset before using this test. DW_FORM_data4
25515 and DW_FORM_data8 are members of both the constant class, and of
25516 the classes that contain offsets into other debug sections
25517 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25518 that, if an attribute's can be either a constant or one of the
25519 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25520 taken as section offsets, not constants.
25522 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25523 cannot handle that. */
25526 attr_form_is_constant (const struct attribute
*attr
)
25528 switch (attr
->form
)
25530 case DW_FORM_sdata
:
25531 case DW_FORM_udata
:
25532 case DW_FORM_data1
:
25533 case DW_FORM_data2
:
25534 case DW_FORM_data4
:
25535 case DW_FORM_data8
:
25536 case DW_FORM_implicit_const
:
25544 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25545 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25548 attr_form_is_ref (const struct attribute
*attr
)
25550 switch (attr
->form
)
25552 case DW_FORM_ref_addr
:
25557 case DW_FORM_ref_udata
:
25558 case DW_FORM_GNU_ref_alt
:
25565 /* Return the .debug_loc section to use for CU.
25566 For DWO files use .debug_loc.dwo. */
25568 static struct dwarf2_section_info
*
25569 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25571 struct dwarf2_per_objfile
*dwarf2_per_objfile
25572 = cu
->per_cu
->dwarf2_per_objfile
;
25576 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25578 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25580 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25581 : &dwarf2_per_objfile
->loc
);
25584 /* A helper function that fills in a dwarf2_loclist_baton. */
25587 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25588 struct dwarf2_loclist_baton
*baton
,
25589 const struct attribute
*attr
)
25591 struct dwarf2_per_objfile
*dwarf2_per_objfile
25592 = cu
->per_cu
->dwarf2_per_objfile
;
25593 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25595 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25597 baton
->per_cu
= cu
->per_cu
;
25598 gdb_assert (baton
->per_cu
);
25599 /* We don't know how long the location list is, but make sure we
25600 don't run off the edge of the section. */
25601 baton
->size
= section
->size
- DW_UNSND (attr
);
25602 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25603 baton
->base_address
= cu
->base_address
;
25604 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25608 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25609 struct dwarf2_cu
*cu
, int is_block
)
25611 struct dwarf2_per_objfile
*dwarf2_per_objfile
25612 = cu
->per_cu
->dwarf2_per_objfile
;
25613 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25614 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25616 if (attr_form_is_section_offset (attr
)
25617 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25618 the section. If so, fall through to the complaint in the
25620 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25622 struct dwarf2_loclist_baton
*baton
;
25624 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25626 fill_in_loclist_baton (cu
, baton
, attr
);
25628 if (cu
->base_known
== 0)
25629 complaint (_("Location list used without "
25630 "specifying the CU base address."));
25632 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25633 ? dwarf2_loclist_block_index
25634 : dwarf2_loclist_index
);
25635 SYMBOL_LOCATION_BATON (sym
) = baton
;
25639 struct dwarf2_locexpr_baton
*baton
;
25641 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25642 baton
->per_cu
= cu
->per_cu
;
25643 gdb_assert (baton
->per_cu
);
25645 if (attr_form_is_block (attr
))
25647 /* Note that we're just copying the block's data pointer
25648 here, not the actual data. We're still pointing into the
25649 info_buffer for SYM's objfile; right now we never release
25650 that buffer, but when we do clean up properly this may
25652 baton
->size
= DW_BLOCK (attr
)->size
;
25653 baton
->data
= DW_BLOCK (attr
)->data
;
25657 dwarf2_invalid_attrib_class_complaint ("location description",
25658 sym
->natural_name ());
25662 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25663 ? dwarf2_locexpr_block_index
25664 : dwarf2_locexpr_index
);
25665 SYMBOL_LOCATION_BATON (sym
) = baton
;
25669 /* Return the OBJFILE associated with the compilation unit CU. If CU
25670 came from a separate debuginfo file, then the master objfile is
25674 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25676 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25678 /* Return the master objfile, so that we can report and look up the
25679 correct file containing this variable. */
25680 if (objfile
->separate_debug_objfile_backlink
)
25681 objfile
= objfile
->separate_debug_objfile_backlink
;
25686 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25687 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25688 CU_HEADERP first. */
25690 static const struct comp_unit_head
*
25691 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25692 struct dwarf2_per_cu_data
*per_cu
)
25694 const gdb_byte
*info_ptr
;
25697 return &per_cu
->cu
->header
;
25699 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25701 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25702 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25703 rcuh_kind::COMPILE
);
25708 /* Return the address size given in the compilation unit header for CU. */
25711 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25713 struct comp_unit_head cu_header_local
;
25714 const struct comp_unit_head
*cu_headerp
;
25716 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25718 return cu_headerp
->addr_size
;
25721 /* Return the offset size given in the compilation unit header for CU. */
25724 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25726 struct comp_unit_head cu_header_local
;
25727 const struct comp_unit_head
*cu_headerp
;
25729 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25731 return cu_headerp
->offset_size
;
25734 /* See its dwarf2loc.h declaration. */
25737 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25739 struct comp_unit_head cu_header_local
;
25740 const struct comp_unit_head
*cu_headerp
;
25742 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25744 if (cu_headerp
->version
== 2)
25745 return cu_headerp
->addr_size
;
25747 return cu_headerp
->offset_size
;
25750 /* Return the text offset of the CU. The returned offset comes from
25751 this CU's objfile. If this objfile came from a separate debuginfo
25752 file, then the offset may be different from the corresponding
25753 offset in the parent objfile. */
25756 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25758 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25760 return objfile
->section_offsets
[SECT_OFF_TEXT (objfile
)];
25763 /* Return a type that is a generic pointer type, the size of which matches
25764 the address size given in the compilation unit header for PER_CU. */
25765 static struct type
*
25766 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25768 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25769 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25770 struct type
*addr_type
= lookup_pointer_type (void_type
);
25771 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25773 if (TYPE_LENGTH (addr_type
) == addr_size
)
25777 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25781 /* Return DWARF version number of PER_CU. */
25784 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25786 return per_cu
->dwarf_version
;
25789 /* Locate the .debug_info compilation unit from CU's objfile which contains
25790 the DIE at OFFSET. Raises an error on failure. */
25792 static struct dwarf2_per_cu_data
*
25793 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25794 unsigned int offset_in_dwz
,
25795 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25797 struct dwarf2_per_cu_data
*this_cu
;
25801 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25804 struct dwarf2_per_cu_data
*mid_cu
;
25805 int mid
= low
+ (high
- low
) / 2;
25807 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25808 if (mid_cu
->is_dwz
> offset_in_dwz
25809 || (mid_cu
->is_dwz
== offset_in_dwz
25810 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25815 gdb_assert (low
== high
);
25816 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25817 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25819 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25820 error (_("Dwarf Error: could not find partial DIE containing "
25821 "offset %s [in module %s]"),
25822 sect_offset_str (sect_off
),
25823 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25825 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25827 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25831 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25832 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25833 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25834 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25839 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25841 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25842 : per_cu (per_cu_
),
25844 has_loclist (false),
25845 checked_producer (false),
25846 producer_is_gxx_lt_4_6 (false),
25847 producer_is_gcc_lt_4_3 (false),
25848 producer_is_icc (false),
25849 producer_is_icc_lt_14 (false),
25850 producer_is_codewarrior (false),
25851 processing_has_namespace_info (false)
25856 /* Destroy a dwarf2_cu. */
25858 dwarf2_cu::~dwarf2_cu ()
25863 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25866 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25867 enum language pretend_language
)
25869 struct attribute
*attr
;
25871 /* Set the language we're debugging. */
25872 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25873 if (attr
!= nullptr)
25874 set_cu_language (DW_UNSND (attr
), cu
);
25877 cu
->language
= pretend_language
;
25878 cu
->language_defn
= language_def (cu
->language
);
25881 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25884 /* Increase the age counter on each cached compilation unit, and free
25885 any that are too old. */
25888 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25890 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25892 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25893 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25894 while (per_cu
!= NULL
)
25896 per_cu
->cu
->last_used
++;
25897 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25898 dwarf2_mark (per_cu
->cu
);
25899 per_cu
= per_cu
->cu
->read_in_chain
;
25902 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25903 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25904 while (per_cu
!= NULL
)
25906 struct dwarf2_per_cu_data
*next_cu
;
25908 next_cu
= per_cu
->cu
->read_in_chain
;
25910 if (!per_cu
->cu
->mark
)
25913 *last_chain
= next_cu
;
25916 last_chain
= &per_cu
->cu
->read_in_chain
;
25922 /* Remove a single compilation unit from the cache. */
25925 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25927 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25928 struct dwarf2_per_objfile
*dwarf2_per_objfile
25929 = target_per_cu
->dwarf2_per_objfile
;
25931 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25932 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25933 while (per_cu
!= NULL
)
25935 struct dwarf2_per_cu_data
*next_cu
;
25937 next_cu
= per_cu
->cu
->read_in_chain
;
25939 if (per_cu
== target_per_cu
)
25943 *last_chain
= next_cu
;
25947 last_chain
= &per_cu
->cu
->read_in_chain
;
25953 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25954 We store these in a hash table separate from the DIEs, and preserve them
25955 when the DIEs are flushed out of cache.
25957 The CU "per_cu" pointer is needed because offset alone is not enough to
25958 uniquely identify the type. A file may have multiple .debug_types sections,
25959 or the type may come from a DWO file. Furthermore, while it's more logical
25960 to use per_cu->section+offset, with Fission the section with the data is in
25961 the DWO file but we don't know that section at the point we need it.
25962 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25963 because we can enter the lookup routine, get_die_type_at_offset, from
25964 outside this file, and thus won't necessarily have PER_CU->cu.
25965 Fortunately, PER_CU is stable for the life of the objfile. */
25967 struct dwarf2_per_cu_offset_and_type
25969 const struct dwarf2_per_cu_data
*per_cu
;
25970 sect_offset sect_off
;
25974 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25977 per_cu_offset_and_type_hash (const void *item
)
25979 const struct dwarf2_per_cu_offset_and_type
*ofs
25980 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25982 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25985 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25988 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25990 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25991 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25992 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25993 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25995 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25996 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25999 /* Set the type associated with DIE to TYPE. Save it in CU's hash
26000 table if necessary. For convenience, return TYPE.
26002 The DIEs reading must have careful ordering to:
26003 * Not cause infinite loops trying to read in DIEs as a prerequisite for
26004 reading current DIE.
26005 * Not trying to dereference contents of still incompletely read in types
26006 while reading in other DIEs.
26007 * Enable referencing still incompletely read in types just by a pointer to
26008 the type without accessing its fields.
26010 Therefore caller should follow these rules:
26011 * Try to fetch any prerequisite types we may need to build this DIE type
26012 before building the type and calling set_die_type.
26013 * After building type call set_die_type for current DIE as soon as
26014 possible before fetching more types to complete the current type.
26015 * Make the type as complete as possible before fetching more types. */
26017 static struct type
*
26018 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
26020 struct dwarf2_per_objfile
*dwarf2_per_objfile
26021 = cu
->per_cu
->dwarf2_per_objfile
;
26022 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
26023 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
26024 struct attribute
*attr
;
26025 struct dynamic_prop prop
;
26027 /* For Ada types, make sure that the gnat-specific data is always
26028 initialized (if not already set). There are a few types where
26029 we should not be doing so, because the type-specific area is
26030 already used to hold some other piece of info (eg: TYPE_CODE_FLT
26031 where the type-specific area is used to store the floatformat).
26032 But this is not a problem, because the gnat-specific information
26033 is actually not needed for these types. */
26034 if (need_gnat_info (cu
)
26035 && TYPE_CODE (type
) != TYPE_CODE_FUNC
26036 && TYPE_CODE (type
) != TYPE_CODE_FLT
26037 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
26038 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
26039 && TYPE_CODE (type
) != TYPE_CODE_METHOD
26040 && !HAVE_GNAT_AUX_INFO (type
))
26041 INIT_GNAT_SPECIFIC (type
);
26043 /* Read DW_AT_allocated and set in type. */
26044 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
26045 if (attr_form_is_block (attr
))
26047 struct type
*prop_type
26048 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
26049 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
26050 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
26052 else if (attr
!= NULL
)
26054 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
26055 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
26056 sect_offset_str (die
->sect_off
));
26059 /* Read DW_AT_associated and set in type. */
26060 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
26061 if (attr_form_is_block (attr
))
26063 struct type
*prop_type
26064 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
26065 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
26066 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
26068 else if (attr
!= NULL
)
26070 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
26071 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
26072 sect_offset_str (die
->sect_off
));
26075 /* Read DW_AT_data_location and set in type. */
26076 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
26077 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
26078 dwarf2_per_cu_addr_type (cu
->per_cu
)))
26079 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
26081 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26083 dwarf2_per_objfile
->die_type_hash
=
26084 htab_create_alloc_ex (127,
26085 per_cu_offset_and_type_hash
,
26086 per_cu_offset_and_type_eq
,
26088 &objfile
->objfile_obstack
,
26089 hashtab_obstack_allocate
,
26090 dummy_obstack_deallocate
);
26093 ofs
.per_cu
= cu
->per_cu
;
26094 ofs
.sect_off
= die
->sect_off
;
26096 slot
= (struct dwarf2_per_cu_offset_and_type
**)
26097 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
26099 complaint (_("A problem internal to GDB: DIE %s has type already set"),
26100 sect_offset_str (die
->sect_off
));
26101 *slot
= XOBNEW (&objfile
->objfile_obstack
,
26102 struct dwarf2_per_cu_offset_and_type
);
26107 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
26108 or return NULL if the die does not have a saved type. */
26110 static struct type
*
26111 get_die_type_at_offset (sect_offset sect_off
,
26112 struct dwarf2_per_cu_data
*per_cu
)
26114 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
26115 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
26117 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26120 ofs
.per_cu
= per_cu
;
26121 ofs
.sect_off
= sect_off
;
26122 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26123 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
26130 /* Look up the type for DIE in CU in die_type_hash,
26131 or return NULL if DIE does not have a saved type. */
26133 static struct type
*
26134 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26136 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26139 /* Add a dependence relationship from CU to REF_PER_CU. */
26142 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26143 struct dwarf2_per_cu_data
*ref_per_cu
)
26147 if (cu
->dependencies
== NULL
)
26149 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26150 NULL
, &cu
->comp_unit_obstack
,
26151 hashtab_obstack_allocate
,
26152 dummy_obstack_deallocate
);
26154 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26156 *slot
= ref_per_cu
;
26159 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26160 Set the mark field in every compilation unit in the
26161 cache that we must keep because we are keeping CU. */
26164 dwarf2_mark_helper (void **slot
, void *data
)
26166 struct dwarf2_per_cu_data
*per_cu
;
26168 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26170 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26171 reading of the chain. As such dependencies remain valid it is not much
26172 useful to track and undo them during QUIT cleanups. */
26173 if (per_cu
->cu
== NULL
)
26176 if (per_cu
->cu
->mark
)
26178 per_cu
->cu
->mark
= true;
26180 if (per_cu
->cu
->dependencies
!= NULL
)
26181 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26186 /* Set the mark field in CU and in every other compilation unit in the
26187 cache that we must keep because we are keeping CU. */
26190 dwarf2_mark (struct dwarf2_cu
*cu
)
26195 if (cu
->dependencies
!= NULL
)
26196 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26200 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26204 per_cu
->cu
->mark
= false;
26205 per_cu
= per_cu
->cu
->read_in_chain
;
26209 /* Trivial hash function for partial_die_info: the hash value of a DIE
26210 is its offset in .debug_info for this objfile. */
26213 partial_die_hash (const void *item
)
26215 const struct partial_die_info
*part_die
26216 = (const struct partial_die_info
*) item
;
26218 return to_underlying (part_die
->sect_off
);
26221 /* Trivial comparison function for partial_die_info structures: two DIEs
26222 are equal if they have the same offset. */
26225 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26227 const struct partial_die_info
*part_die_lhs
26228 = (const struct partial_die_info
*) item_lhs
;
26229 const struct partial_die_info
*part_die_rhs
26230 = (const struct partial_die_info
*) item_rhs
;
26232 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26235 struct cmd_list_element
*set_dwarf_cmdlist
;
26236 struct cmd_list_element
*show_dwarf_cmdlist
;
26239 set_dwarf_cmd (const char *args
, int from_tty
)
26241 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26246 show_dwarf_cmd (const char *args
, int from_tty
)
26248 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26251 bool dwarf_always_disassemble
;
26254 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26255 struct cmd_list_element
*c
, const char *value
)
26257 fprintf_filtered (file
,
26258 _("Whether to always disassemble "
26259 "DWARF expressions is %s.\n"),
26264 show_check_physname (struct ui_file
*file
, int from_tty
,
26265 struct cmd_list_element
*c
, const char *value
)
26267 fprintf_filtered (file
,
26268 _("Whether to check \"physname\" is %s.\n"),
26272 void _initialize_dwarf2_read ();
26274 _initialize_dwarf2_read ()
26276 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26277 Set DWARF specific variables.\n\
26278 Configure DWARF variables such as the cache size."),
26279 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26280 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26282 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26283 Show DWARF specific variables.\n\
26284 Show DWARF variables such as the cache size."),
26285 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26286 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26288 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26289 &dwarf_max_cache_age
, _("\
26290 Set the upper bound on the age of cached DWARF compilation units."), _("\
26291 Show the upper bound on the age of cached DWARF compilation units."), _("\
26292 A higher limit means that cached compilation units will be stored\n\
26293 in memory longer, and more total memory will be used. Zero disables\n\
26294 caching, which can slow down startup."),
26296 show_dwarf_max_cache_age
,
26297 &set_dwarf_cmdlist
,
26298 &show_dwarf_cmdlist
);
26300 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26301 &dwarf_always_disassemble
, _("\
26302 Set whether `info address' always disassembles DWARF expressions."), _("\
26303 Show whether `info address' always disassembles DWARF expressions."), _("\
26304 When enabled, DWARF expressions are always printed in an assembly-like\n\
26305 syntax. When disabled, expressions will be printed in a more\n\
26306 conversational style, when possible."),
26308 show_dwarf_always_disassemble
,
26309 &set_dwarf_cmdlist
,
26310 &show_dwarf_cmdlist
);
26312 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26313 Set debugging of the DWARF reader."), _("\
26314 Show debugging of the DWARF reader."), _("\
26315 When enabled (non-zero), debugging messages are printed during DWARF\n\
26316 reading and symtab expansion. A value of 1 (one) provides basic\n\
26317 information. A value greater than 1 provides more verbose information."),
26320 &setdebuglist
, &showdebuglist
);
26322 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26323 Set debugging of the DWARF DIE reader."), _("\
26324 Show debugging of the DWARF DIE reader."), _("\
26325 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26326 The value is the maximum depth to print."),
26329 &setdebuglist
, &showdebuglist
);
26331 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26332 Set debugging of the dwarf line reader."), _("\
26333 Show debugging of the dwarf line reader."), _("\
26334 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26335 A value of 1 (one) provides basic information.\n\
26336 A value greater than 1 provides more verbose information."),
26339 &setdebuglist
, &showdebuglist
);
26341 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26342 Set cross-checking of \"physname\" code against demangler."), _("\
26343 Show cross-checking of \"physname\" code against demangler."), _("\
26344 When enabled, GDB's internal \"physname\" code is checked against\n\
26346 NULL
, show_check_physname
,
26347 &setdebuglist
, &showdebuglist
);
26349 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26350 no_class
, &use_deprecated_index_sections
, _("\
26351 Set whether to use deprecated gdb_index sections."), _("\
26352 Show whether to use deprecated gdb_index sections."), _("\
26353 When enabled, deprecated .gdb_index sections are used anyway.\n\
26354 Normally they are ignored either because of a missing feature or\n\
26355 performance issue.\n\
26356 Warning: This option must be enabled before gdb reads the file."),
26359 &setlist
, &showlist
);
26361 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26362 &dwarf2_locexpr_funcs
);
26363 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26364 &dwarf2_loclist_funcs
);
26366 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26367 &dwarf2_block_frame_base_locexpr_funcs
);
26368 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26369 &dwarf2_block_frame_base_loclist_funcs
);
26372 selftests::register_test ("dw2_expand_symtabs_matching",
26373 selftests::dw2_expand_symtabs_matching::run_test
);