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;
878 typedef std::unique_ptr
<struct abbrev_table
> abbrev_table_up
;
880 /* Struct used to pass misc. parameters to read_die_and_children, et
881 al. which are used for both .debug_info and .debug_types dies.
882 All parameters here are unchanging for the life of the call. This
883 struct exists to abstract away the constant parameters of die reading. */
885 struct die_reader_specs
887 /* The bfd of die_section. */
890 /* The CU of the DIE we are parsing. */
891 struct dwarf2_cu
*cu
;
893 /* Non-NULL if reading a DWO file (including one packaged into a DWP). */
894 struct dwo_file
*dwo_file
;
896 /* The section the die comes from.
897 This is either .debug_info or .debug_types, or the .dwo variants. */
898 struct dwarf2_section_info
*die_section
;
900 /* die_section->buffer. */
901 const gdb_byte
*buffer
;
903 /* The end of the buffer. */
904 const gdb_byte
*buffer_end
;
906 /* The value of the DW_AT_comp_dir attribute. */
907 const char *comp_dir
;
909 /* The abbreviation table to use when reading the DIEs. */
910 struct abbrev_table
*abbrev_table
;
913 /* A subclass of die_reader_specs that holds storage and has complex
914 constructor and destructor behavior. */
916 class cutu_reader
: public die_reader_specs
920 cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
921 struct abbrev_table
*abbrev_table
,
922 int use_existing_cu
, int keep
,
925 explicit cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
926 struct dwarf2_cu
*parent_cu
= nullptr,
927 struct dwo_file
*dwo_file
= nullptr);
931 DISABLE_COPY_AND_ASSIGN (cutu_reader
);
933 const gdb_byte
*info_ptr
= nullptr;
934 struct die_info
*comp_unit_die
= nullptr;
935 int has_children
= 0;
936 bool dummy_p
= false;
939 void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
940 int use_existing_cu
, int keep
);
942 struct dwarf2_per_cu_data
*m_this_cu
;
944 std::unique_ptr
<dwarf2_cu
> m_new_cu
;
946 /* The ordinary abbreviation table. */
947 abbrev_table_up m_abbrev_table_holder
;
949 /* The DWO abbreviation table. */
950 abbrev_table_up m_dwo_abbrev_table
;
953 /* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
955 typedef int dir_index
;
957 /* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
959 typedef int file_name_index
;
963 file_entry () = default;
965 file_entry (const char *name_
, dir_index d_index_
,
966 unsigned int mod_time_
, unsigned int length_
)
969 mod_time (mod_time_
),
973 /* Return the include directory at D_INDEX stored in LH. Returns
974 NULL if D_INDEX is out of bounds. */
975 const char *include_dir (const line_header
*lh
) const;
977 /* The file name. Note this is an observing pointer. The memory is
978 owned by debug_line_buffer. */
981 /* The directory index (1-based). */
982 dir_index d_index
{};
984 unsigned int mod_time
{};
986 unsigned int length
{};
988 /* True if referenced by the Line Number Program. */
991 /* The associated symbol table, if any. */
992 struct symtab
*symtab
{};
995 /* The line number information for a compilation unit (found in the
996 .debug_line section) begins with a "statement program header",
997 which contains the following information. */
1004 /* Add an entry to the include directory table. */
1005 void add_include_dir (const char *include_dir
);
1007 /* Add an entry to the file name table. */
1008 void add_file_name (const char *name
, dir_index d_index
,
1009 unsigned int mod_time
, unsigned int length
);
1011 /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
1012 Returns NULL if INDEX is out of bounds. */
1013 const char *include_dir_at (dir_index index
) const
1019 vec_index
= index
- 1;
1020 if (vec_index
< 0 || vec_index
>= m_include_dirs
.size ())
1022 return m_include_dirs
[vec_index
];
1025 bool is_valid_file_index (int file_index
)
1028 return 0 <= file_index
&& file_index
< file_names_size ();
1029 return 1 <= file_index
&& file_index
<= file_names_size ();
1032 /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
1033 Returns NULL if INDEX is out of bounds. */
1034 file_entry
*file_name_at (file_name_index index
)
1040 vec_index
= index
- 1;
1041 if (vec_index
< 0 || vec_index
>= m_file_names
.size ())
1043 return &m_file_names
[vec_index
];
1046 /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
1047 this method should only be used to iterate through all file entries in an
1048 index-agnostic manner. */
1049 std::vector
<file_entry
> &file_names ()
1050 { return m_file_names
; }
1052 /* Offset of line number information in .debug_line section. */
1053 sect_offset sect_off
{};
1055 /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile. */
1056 unsigned offset_in_dwz
: 1; /* Can't initialize bitfields in-class. */
1058 unsigned int total_length
{};
1059 unsigned short version
{};
1060 unsigned int header_length
{};
1061 unsigned char minimum_instruction_length
{};
1062 unsigned char maximum_ops_per_instruction
{};
1063 unsigned char default_is_stmt
{};
1065 unsigned char line_range
{};
1066 unsigned char opcode_base
{};
1068 /* standard_opcode_lengths[i] is the number of operands for the
1069 standard opcode whose value is i. This means that
1070 standard_opcode_lengths[0] is unused, and the last meaningful
1071 element is standard_opcode_lengths[opcode_base - 1]. */
1072 std::unique_ptr
<unsigned char[]> standard_opcode_lengths
;
1074 int file_names_size ()
1075 { return m_file_names
.size(); }
1077 /* The start and end of the statement program following this
1078 header. These point into dwarf2_per_objfile->line_buffer. */
1079 const gdb_byte
*statement_program_start
{}, *statement_program_end
{};
1082 /* The include_directories table. Note these are observing
1083 pointers. The memory is owned by debug_line_buffer. */
1084 std::vector
<const char *> m_include_dirs
;
1086 /* The file_names table. This is private because the meaning of indexes
1087 differs among DWARF versions (The first valid index is 1 in DWARF 4 and
1088 before, and is 0 in DWARF 5 and later). So the client should use
1089 file_name_at method for access. */
1090 std::vector
<file_entry
> m_file_names
;
1093 typedef std::unique_ptr
<line_header
> line_header_up
;
1096 file_entry::include_dir (const line_header
*lh
) const
1098 return lh
->include_dir_at (d_index
);
1101 /* When we construct a partial symbol table entry we only
1102 need this much information. */
1103 struct partial_die_info
: public allocate_on_obstack
1105 partial_die_info (sect_offset sect_off
, struct abbrev_info
*abbrev
);
1107 /* Disable assign but still keep copy ctor, which is needed
1108 load_partial_dies. */
1109 partial_die_info
& operator=(const partial_die_info
& rhs
) = delete;
1111 /* Adjust the partial die before generating a symbol for it. This
1112 function may set the is_external flag or change the DIE's
1114 void fixup (struct dwarf2_cu
*cu
);
1116 /* Read a minimal amount of information into the minimal die
1118 const gdb_byte
*read (const struct die_reader_specs
*reader
,
1119 const struct abbrev_info
&abbrev
,
1120 const gdb_byte
*info_ptr
);
1122 /* Offset of this DIE. */
1123 const sect_offset sect_off
;
1125 /* DWARF-2 tag for this DIE. */
1126 const ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1128 /* Assorted flags describing the data found in this DIE. */
1129 const unsigned int has_children
: 1;
1131 unsigned int is_external
: 1;
1132 unsigned int is_declaration
: 1;
1133 unsigned int has_type
: 1;
1134 unsigned int has_specification
: 1;
1135 unsigned int has_pc_info
: 1;
1136 unsigned int may_be_inlined
: 1;
1138 /* This DIE has been marked DW_AT_main_subprogram. */
1139 unsigned int main_subprogram
: 1;
1141 /* Flag set if the SCOPE field of this structure has been
1143 unsigned int scope_set
: 1;
1145 /* Flag set if the DIE has a byte_size attribute. */
1146 unsigned int has_byte_size
: 1;
1148 /* Flag set if the DIE has a DW_AT_const_value attribute. */
1149 unsigned int has_const_value
: 1;
1151 /* Flag set if any of the DIE's children are template arguments. */
1152 unsigned int has_template_arguments
: 1;
1154 /* Flag set if fixup has been called on this die. */
1155 unsigned int fixup_called
: 1;
1157 /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */
1158 unsigned int is_dwz
: 1;
1160 /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */
1161 unsigned int spec_is_dwz
: 1;
1163 /* The name of this DIE. Normally the value of DW_AT_name, but
1164 sometimes a default name for unnamed DIEs. */
1165 const char *name
= nullptr;
1167 /* The linkage name, if present. */
1168 const char *linkage_name
= nullptr;
1170 /* The scope to prepend to our children. This is generally
1171 allocated on the comp_unit_obstack, so will disappear
1172 when this compilation unit leaves the cache. */
1173 const char *scope
= nullptr;
1175 /* Some data associated with the partial DIE. The tag determines
1176 which field is live. */
1179 /* The location description associated with this DIE, if any. */
1180 struct dwarf_block
*locdesc
;
1181 /* The offset of an import, for DW_TAG_imported_unit. */
1182 sect_offset sect_off
;
1185 /* If HAS_PC_INFO, the PC range associated with this DIE. */
1186 CORE_ADDR lowpc
= 0;
1187 CORE_ADDR highpc
= 0;
1189 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
1190 DW_AT_sibling, if any. */
1191 /* NOTE: This member isn't strictly necessary, partial_die_info::read
1192 could return DW_AT_sibling values to its caller load_partial_dies. */
1193 const gdb_byte
*sibling
= nullptr;
1195 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
1196 DW_AT_specification (or DW_AT_abstract_origin or
1197 DW_AT_extension). */
1198 sect_offset spec_offset
{};
1200 /* Pointers to this DIE's parent, first child, and next sibling,
1202 struct partial_die_info
*die_parent
= nullptr;
1203 struct partial_die_info
*die_child
= nullptr;
1204 struct partial_die_info
*die_sibling
= nullptr;
1206 friend struct partial_die_info
*
1207 dwarf2_cu::find_partial_die (sect_offset sect_off
);
1210 /* Only need to do look up in dwarf2_cu::find_partial_die. */
1211 partial_die_info (sect_offset sect_off
)
1212 : partial_die_info (sect_off
, DW_TAG_padding
, 0)
1216 partial_die_info (sect_offset sect_off_
, enum dwarf_tag tag_
,
1218 : sect_off (sect_off_
), tag (tag_
), has_children (has_children_
)
1223 has_specification
= 0;
1226 main_subprogram
= 0;
1229 has_const_value
= 0;
1230 has_template_arguments
= 0;
1237 /* This data structure holds the information of an abbrev. */
1240 unsigned int number
; /* number identifying abbrev */
1241 enum dwarf_tag tag
; /* dwarf tag */
1242 unsigned short has_children
; /* boolean */
1243 unsigned short num_attrs
; /* number of attributes */
1244 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
1245 struct abbrev_info
*next
; /* next in chain */
1250 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1251 ENUM_BITFIELD(dwarf_form
) form
: 16;
1253 /* It is valid only if FORM is DW_FORM_implicit_const. */
1254 LONGEST implicit_const
;
1257 /* Size of abbrev_table.abbrev_hash_table. */
1258 #define ABBREV_HASH_SIZE 121
1260 /* Top level data structure to contain an abbreviation table. */
1264 explicit abbrev_table (sect_offset off
)
1268 XOBNEWVEC (&abbrev_obstack
, struct abbrev_info
*, ABBREV_HASH_SIZE
);
1269 memset (m_abbrevs
, 0, ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
1272 DISABLE_COPY_AND_ASSIGN (abbrev_table
);
1274 /* Allocate space for a struct abbrev_info object in
1276 struct abbrev_info
*alloc_abbrev ();
1278 /* Add an abbreviation to the table. */
1279 void add_abbrev (unsigned int abbrev_number
, struct abbrev_info
*abbrev
);
1281 /* Look up an abbrev in the table.
1282 Returns NULL if the abbrev is not found. */
1284 struct abbrev_info
*lookup_abbrev (unsigned int abbrev_number
);
1287 /* Where the abbrev table came from.
1288 This is used as a sanity check when the table is used. */
1289 const sect_offset sect_off
;
1291 /* Storage for the abbrev table. */
1292 auto_obstack abbrev_obstack
;
1296 /* Hash table of abbrevs.
1297 This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
1298 It could be statically allocated, but the previous code didn't so we
1300 struct abbrev_info
**m_abbrevs
;
1303 /* Attributes have a name and a value. */
1306 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
1307 ENUM_BITFIELD(dwarf_form
) form
: 15;
1309 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
1310 field should be in u.str (existing only for DW_STRING) but it is kept
1311 here for better struct attribute alignment. */
1312 unsigned int string_is_canonical
: 1;
1317 struct dwarf_block
*blk
;
1326 /* This data structure holds a complete die structure. */
1329 /* DWARF-2 tag for this DIE. */
1330 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
1332 /* Number of attributes */
1333 unsigned char num_attrs
;
1335 /* True if we're presently building the full type name for the
1336 type derived from this DIE. */
1337 unsigned char building_fullname
: 1;
1339 /* True if this die is in process. PR 16581. */
1340 unsigned char in_process
: 1;
1343 unsigned int abbrev
;
1345 /* Offset in .debug_info or .debug_types section. */
1346 sect_offset sect_off
;
1348 /* The dies in a compilation unit form an n-ary tree. PARENT
1349 points to this die's parent; CHILD points to the first child of
1350 this node; and all the children of a given node are chained
1351 together via their SIBLING fields. */
1352 struct die_info
*child
; /* Its first child, if any. */
1353 struct die_info
*sibling
; /* Its next sibling, if any. */
1354 struct die_info
*parent
; /* Its parent, if any. */
1356 /* An array of attributes, with NUM_ATTRS elements. There may be
1357 zero, but it's not common and zero-sized arrays are not
1358 sufficiently portable C. */
1359 struct attribute attrs
[1];
1362 /* Get at parts of an attribute structure. */
1364 #define DW_STRING(attr) ((attr)->u.str)
1365 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
1366 #define DW_UNSND(attr) ((attr)->u.unsnd)
1367 #define DW_BLOCK(attr) ((attr)->u.blk)
1368 #define DW_SND(attr) ((attr)->u.snd)
1369 #define DW_ADDR(attr) ((attr)->u.addr)
1370 #define DW_SIGNATURE(attr) ((attr)->u.signature)
1372 /* Blocks are a bunch of untyped bytes. */
1377 /* Valid only if SIZE is not zero. */
1378 const gdb_byte
*data
;
1381 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
1382 but this would require a corresponding change in unpack_field_as_long
1384 static int bits_per_byte
= 8;
1386 /* When reading a variant or variant part, we track a bit more
1387 information about the field, and store it in an object of this
1390 struct variant_field
1392 /* If we see a DW_TAG_variant, then this will be the discriminant
1394 ULONGEST discriminant_value
;
1395 /* If we see a DW_TAG_variant, then this will be set if this is the
1397 bool default_branch
;
1398 /* While reading a DW_TAG_variant_part, this will be set if this
1399 field is the discriminant. */
1400 bool is_discriminant
;
1405 int accessibility
= 0;
1407 /* Extra information to describe a variant or variant part. */
1408 struct variant_field variant
{};
1409 struct field field
{};
1414 const char *name
= nullptr;
1415 std::vector
<struct fn_field
> fnfields
;
1418 /* The routines that read and process dies for a C struct or C++ class
1419 pass lists of data member fields and lists of member function fields
1420 in an instance of a field_info structure, as defined below. */
1423 /* List of data member and baseclasses fields. */
1424 std::vector
<struct nextfield
> fields
;
1425 std::vector
<struct nextfield
> baseclasses
;
1427 /* Number of fields (including baseclasses). */
1430 /* Set if the accessibility of one of the fields is not public. */
1431 int non_public_fields
= 0;
1433 /* Member function fieldlist array, contains name of possibly overloaded
1434 member function, number of overloaded member functions and a pointer
1435 to the head of the member function field chain. */
1436 std::vector
<struct fnfieldlist
> fnfieldlists
;
1438 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
1439 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
1440 std::vector
<struct decl_field
> typedef_field_list
;
1442 /* Nested types defined by this class and the number of elements in this
1444 std::vector
<struct decl_field
> nested_types_list
;
1447 /* One item on the queue of compilation units to read in full symbols
1449 struct dwarf2_queue_item
1451 struct dwarf2_per_cu_data
*per_cu
;
1452 enum language pretend_language
;
1453 struct dwarf2_queue_item
*next
;
1456 /* The current queue. */
1457 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
1459 /* Loaded secondary compilation units are kept in memory until they
1460 have not been referenced for the processing of this many
1461 compilation units. Set this to zero to disable caching. Cache
1462 sizes of up to at least twenty will improve startup time for
1463 typical inter-CU-reference binaries, at an obvious memory cost. */
1464 static int dwarf_max_cache_age
= 5;
1466 show_dwarf_max_cache_age (struct ui_file
*file
, int from_tty
,
1467 struct cmd_list_element
*c
, const char *value
)
1469 fprintf_filtered (file
, _("The upper bound on the age of cached "
1470 "DWARF compilation units is %s.\n"),
1474 /* local function prototypes */
1476 static const char *get_section_name (const struct dwarf2_section_info
*);
1478 static const char *get_section_file_name (const struct dwarf2_section_info
*);
1480 static void dwarf2_find_base_address (struct die_info
*die
,
1481 struct dwarf2_cu
*cu
);
1483 static dwarf2_psymtab
*create_partial_symtab
1484 (struct dwarf2_per_cu_data
*per_cu
, const char *name
);
1486 static void build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
1487 const gdb_byte
*info_ptr
,
1488 struct die_info
*type_unit_die
,
1491 static void dwarf2_build_psymtabs_hard
1492 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1494 static void scan_partial_symbols (struct partial_die_info
*,
1495 CORE_ADDR
*, CORE_ADDR
*,
1496 int, struct dwarf2_cu
*);
1498 static void add_partial_symbol (struct partial_die_info
*,
1499 struct dwarf2_cu
*);
1501 static void add_partial_namespace (struct partial_die_info
*pdi
,
1502 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1503 int set_addrmap
, struct dwarf2_cu
*cu
);
1505 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
1506 CORE_ADDR
*highpc
, int set_addrmap
,
1507 struct dwarf2_cu
*cu
);
1509 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
1510 struct dwarf2_cu
*cu
);
1512 static void add_partial_subprogram (struct partial_die_info
*pdi
,
1513 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1514 int need_pc
, struct dwarf2_cu
*cu
);
1516 static abbrev_table_up abbrev_table_read_table
1517 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1520 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1522 static struct partial_die_info
*load_partial_dies
1523 (const struct die_reader_specs
*, const gdb_byte
*, int);
1525 /* A pair of partial_die_info and compilation unit. */
1526 struct cu_partial_die_info
1528 /* The compilation unit of the partial_die_info. */
1529 struct dwarf2_cu
*cu
;
1530 /* A partial_die_info. */
1531 struct partial_die_info
*pdi
;
1533 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1539 cu_partial_die_info () = delete;
1542 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1543 struct dwarf2_cu
*);
1545 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1546 struct attribute
*, struct attr_abbrev
*,
1547 const gdb_byte
*, bool *need_reprocess
);
1549 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1550 struct attribute
*attr
);
1552 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1554 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1556 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1558 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1560 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1561 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1563 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1565 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1567 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1570 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1572 static LONGEST read_checked_initial_length_and_offset
1573 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1574 unsigned int *, unsigned int *);
1576 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1577 const struct comp_unit_head
*,
1580 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1582 static sect_offset read_abbrev_offset
1583 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1584 struct dwarf2_section_info
*, sect_offset
);
1586 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1588 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1590 static const char *read_indirect_string
1591 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1592 const struct comp_unit_head
*, unsigned int *);
1594 static const char *read_indirect_line_string
1595 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1596 const struct comp_unit_head
*, unsigned int *);
1598 static const char *read_indirect_string_at_offset
1599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1600 LONGEST str_offset
);
1602 static const char *read_indirect_string_from_dwz
1603 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1605 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1607 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1611 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1612 ULONGEST str_index
);
1614 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1615 ULONGEST str_index
);
1617 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1619 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1620 struct dwarf2_cu
*);
1622 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1625 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1626 struct dwarf2_cu
*cu
);
1628 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1630 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1631 struct dwarf2_cu
*cu
);
1633 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1635 static struct die_info
*die_specification (struct die_info
*die
,
1636 struct dwarf2_cu
**);
1638 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1639 struct dwarf2_cu
*cu
);
1641 static void dwarf_decode_lines (struct line_header
*, const char *,
1642 struct dwarf2_cu
*, dwarf2_psymtab
*,
1643 CORE_ADDR
, int decode_mapping
);
1645 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1648 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1649 struct dwarf2_cu
*, struct symbol
* = NULL
);
1651 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1652 struct dwarf2_cu
*);
1654 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1657 struct obstack
*obstack
,
1658 struct dwarf2_cu
*cu
, LONGEST
*value
,
1659 const gdb_byte
**bytes
,
1660 struct dwarf2_locexpr_baton
**baton
);
1662 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1664 static int need_gnat_info (struct dwarf2_cu
*);
1666 static struct type
*die_descriptive_type (struct die_info
*,
1667 struct dwarf2_cu
*);
1669 static void set_descriptive_type (struct type
*, struct die_info
*,
1670 struct dwarf2_cu
*);
1672 static struct type
*die_containing_type (struct die_info
*,
1673 struct dwarf2_cu
*);
1675 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1676 struct dwarf2_cu
*);
1678 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1680 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1682 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1684 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1685 const char *suffix
, int physname
,
1686 struct dwarf2_cu
*cu
);
1688 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1690 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1692 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1694 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1696 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1698 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1700 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1701 struct dwarf2_cu
*, dwarf2_psymtab
*);
1703 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1704 values. Keep the items ordered with increasing constraints compliance. */
1707 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1708 PC_BOUNDS_NOT_PRESENT
,
1710 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1711 were present but they do not form a valid range of PC addresses. */
1714 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1717 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1721 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1722 CORE_ADDR
*, CORE_ADDR
*,
1726 static void get_scope_pc_bounds (struct die_info
*,
1727 CORE_ADDR
*, CORE_ADDR
*,
1728 struct dwarf2_cu
*);
1730 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1731 CORE_ADDR
, struct dwarf2_cu
*);
1733 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1734 struct dwarf2_cu
*);
1736 static void dwarf2_attach_fields_to_type (struct field_info
*,
1737 struct type
*, struct dwarf2_cu
*);
1739 static void dwarf2_add_member_fn (struct field_info
*,
1740 struct die_info
*, struct type
*,
1741 struct dwarf2_cu
*);
1743 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1745 struct dwarf2_cu
*);
1747 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1749 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1751 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1753 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1755 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1757 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1759 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1761 static struct type
*read_module_type (struct die_info
*die
,
1762 struct dwarf2_cu
*cu
);
1764 static const char *namespace_name (struct die_info
*die
,
1765 int *is_anonymous
, struct dwarf2_cu
*);
1767 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1769 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1771 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1772 struct dwarf2_cu
*);
1774 static struct die_info
*read_die_and_siblings_1
1775 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1778 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1779 const gdb_byte
*info_ptr
,
1780 const gdb_byte
**new_info_ptr
,
1781 struct die_info
*parent
);
1783 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1784 struct die_info
**, const gdb_byte
*,
1787 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1788 struct die_info
**, const gdb_byte
*,
1791 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1793 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1796 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1798 static const char *dwarf2_full_name (const char *name
,
1799 struct die_info
*die
,
1800 struct dwarf2_cu
*cu
);
1802 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1803 struct dwarf2_cu
*cu
);
1805 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1806 struct dwarf2_cu
**);
1808 static const char *dwarf_tag_name (unsigned int);
1810 static const char *dwarf_attr_name (unsigned int);
1812 static const char *dwarf_unit_type_name (int unit_type
);
1814 static const char *dwarf_form_name (unsigned int);
1816 static const char *dwarf_bool_name (unsigned int);
1818 static const char *dwarf_type_encoding_name (unsigned int);
1820 static struct die_info
*sibling_die (struct die_info
*);
1822 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1824 static void dump_die_for_error (struct die_info
*);
1826 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1829 /*static*/ void dump_die (struct die_info
*, int max_level
);
1831 static void store_in_ref_table (struct die_info
*,
1832 struct dwarf2_cu
*);
1834 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1836 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1838 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1839 const struct attribute
*,
1840 struct dwarf2_cu
**);
1842 static struct die_info
*follow_die_ref (struct die_info
*,
1843 const struct attribute
*,
1844 struct dwarf2_cu
**);
1846 static struct die_info
*follow_die_sig (struct die_info
*,
1847 const struct attribute
*,
1848 struct dwarf2_cu
**);
1850 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1851 struct dwarf2_cu
*);
1853 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1854 const struct attribute
*,
1855 struct dwarf2_cu
*);
1857 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1859 static void read_signatured_type (struct signatured_type
*);
1861 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1862 struct die_info
*die
, struct dwarf2_cu
*cu
,
1863 struct dynamic_prop
*prop
, struct type
*type
);
1865 /* memory allocation interface */
1867 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1869 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1871 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1873 static int attr_form_is_block (const struct attribute
*);
1875 static int attr_form_is_section_offset (const struct attribute
*);
1877 static int attr_form_is_constant (const struct attribute
*);
1879 static int attr_form_is_ref (const struct attribute
*);
1881 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1882 struct dwarf2_loclist_baton
*baton
,
1883 const struct attribute
*attr
);
1885 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1887 struct dwarf2_cu
*cu
,
1890 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1891 const gdb_byte
*info_ptr
,
1892 struct abbrev_info
*abbrev
);
1894 static hashval_t
partial_die_hash (const void *item
);
1896 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1898 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1899 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1900 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1902 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1903 struct die_info
*comp_unit_die
,
1904 enum language pretend_language
);
1906 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1908 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1910 static struct type
*set_die_type (struct die_info
*, struct type
*,
1911 struct dwarf2_cu
*);
1913 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1915 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1917 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1920 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1923 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1926 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1927 struct dwarf2_per_cu_data
*);
1929 static void dwarf2_mark (struct dwarf2_cu
*);
1931 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1933 static struct type
*get_die_type_at_offset (sect_offset
,
1934 struct dwarf2_per_cu_data
*);
1936 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1938 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1939 enum language pretend_language
);
1941 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1943 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1944 static struct type
*dwarf2_per_cu_addr_sized_int_type
1945 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1946 static struct type
*dwarf2_per_cu_int_type
1947 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1950 /* Class, the destructor of which frees all allocated queue entries. This
1951 will only have work to do if an error was thrown while processing the
1952 dwarf. If no error was thrown then the queue entries should have all
1953 been processed, and freed, as we went along. */
1955 class dwarf2_queue_guard
1958 dwarf2_queue_guard () = default;
1960 /* Free any entries remaining on the queue. There should only be
1961 entries left if we hit an error while processing the dwarf. */
1962 ~dwarf2_queue_guard ()
1964 struct dwarf2_queue_item
*item
, *last
;
1966 item
= dwarf2_queue
;
1969 /* Anything still marked queued is likely to be in an
1970 inconsistent state, so discard it. */
1971 if (item
->per_cu
->queued
)
1973 if (item
->per_cu
->cu
!= NULL
)
1974 free_one_cached_comp_unit (item
->per_cu
);
1975 item
->per_cu
->queued
= 0;
1983 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1987 /* The return type of find_file_and_directory. Note, the enclosed
1988 string pointers are only valid while this object is valid. */
1990 struct file_and_directory
1992 /* The filename. This is never NULL. */
1995 /* The compilation directory. NULL if not known. If we needed to
1996 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
1997 points directly to the DW_AT_comp_dir string attribute owned by
1998 the obstack that owns the DIE. */
1999 const char *comp_dir
;
2001 /* If we needed to build a new string for comp_dir, this is what
2002 owns the storage. */
2003 std::string comp_dir_storage
;
2006 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2007 struct dwarf2_cu
*cu
);
2009 static char *file_full_name (int file
, struct line_header
*lh
,
2010 const char *comp_dir
);
2012 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2013 enum class rcuh_kind
{ COMPILE
, TYPE
};
2015 static const gdb_byte
*read_and_check_comp_unit_head
2016 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2017 struct comp_unit_head
*header
,
2018 struct dwarf2_section_info
*section
,
2019 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2020 rcuh_kind section_kind
);
2022 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2024 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2026 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2027 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2028 struct dwp_file
*dwp_file
, const char *comp_dir
,
2029 ULONGEST signature
, int is_debug_types
);
2031 static struct dwp_file
*get_dwp_file
2032 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2034 static struct dwo_unit
*lookup_dwo_comp_unit
2035 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2037 static struct dwo_unit
*lookup_dwo_type_unit
2038 (struct signatured_type
*, const char *, const char *);
2040 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2042 /* A unique pointer to a dwo_file. */
2044 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2046 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2048 static void check_producer (struct dwarf2_cu
*cu
);
2050 static void free_line_header_voidp (void *arg
);
2052 /* Various complaints about symbol reading that don't abort the process. */
2055 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2057 complaint (_("statement list doesn't fit in .debug_line section"));
2061 dwarf2_debug_line_missing_file_complaint (void)
2063 complaint (_(".debug_line section has line data without a file"));
2067 dwarf2_debug_line_missing_end_sequence_complaint (void)
2069 complaint (_(".debug_line section has line "
2070 "program sequence without an end"));
2074 dwarf2_complex_location_expr_complaint (void)
2076 complaint (_("location expression too complex"));
2080 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2083 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2088 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2090 complaint (_("debug info runs off end of %s section"
2092 get_section_name (section
),
2093 get_section_file_name (section
));
2097 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2099 complaint (_("macro debug info contains a "
2100 "malformed macro definition:\n`%s'"),
2105 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2107 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2111 /* Hash function for line_header_hash. */
2114 line_header_hash (const struct line_header
*ofs
)
2116 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2119 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2122 line_header_hash_voidp (const void *item
)
2124 const struct line_header
*ofs
= (const struct line_header
*) item
;
2126 return line_header_hash (ofs
);
2129 /* Equality function for line_header_hash. */
2132 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2134 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2135 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2137 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2138 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2143 /* Read the given attribute value as an address, taking the attribute's
2144 form into account. */
2147 attr_value_as_address (struct attribute
*attr
)
2151 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2152 && attr
->form
!= DW_FORM_GNU_addr_index
)
2154 /* Aside from a few clearly defined exceptions, attributes that
2155 contain an address must always be in DW_FORM_addr form.
2156 Unfortunately, some compilers happen to be violating this
2157 requirement by encoding addresses using other forms, such
2158 as DW_FORM_data4 for example. For those broken compilers,
2159 we try to do our best, without any guarantee of success,
2160 to interpret the address correctly. It would also be nice
2161 to generate a complaint, but that would require us to maintain
2162 a list of legitimate cases where a non-address form is allowed,
2163 as well as update callers to pass in at least the CU's DWARF
2164 version. This is more overhead than what we're willing to
2165 expand for a pretty rare case. */
2166 addr
= DW_UNSND (attr
);
2169 addr
= DW_ADDR (attr
);
2174 /* See declaration. */
2176 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2177 const dwarf2_debug_sections
*names
,
2179 : objfile (objfile_
),
2180 can_copy (can_copy_
)
2183 names
= &dwarf2_elf_names
;
2185 bfd
*obfd
= objfile
->obfd
;
2187 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2188 locate_sections (obfd
, sec
, *names
);
2191 dwarf2_per_objfile::~dwarf2_per_objfile ()
2193 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2194 free_cached_comp_units ();
2196 if (quick_file_names_table
)
2197 htab_delete (quick_file_names_table
);
2199 if (line_header_hash
)
2200 htab_delete (line_header_hash
);
2202 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2203 per_cu
->imported_symtabs_free ();
2205 for (signatured_type
*sig_type
: all_type_units
)
2206 sig_type
->per_cu
.imported_symtabs_free ();
2208 /* Everything else should be on the objfile obstack. */
2211 /* See declaration. */
2214 dwarf2_per_objfile::free_cached_comp_units ()
2216 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2217 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2218 while (per_cu
!= NULL
)
2220 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2223 *last_chain
= next_cu
;
2228 /* A helper class that calls free_cached_comp_units on
2231 class free_cached_comp_units
2235 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2236 : m_per_objfile (per_objfile
)
2240 ~free_cached_comp_units ()
2242 m_per_objfile
->free_cached_comp_units ();
2245 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2249 dwarf2_per_objfile
*m_per_objfile
;
2252 /* Try to locate the sections we need for DWARF 2 debugging
2253 information and return true if we have enough to do something.
2254 NAMES points to the dwarf2 section names, or is NULL if the standard
2255 ELF names are used. CAN_COPY is true for formats where symbol
2256 interposition is possible and so symbol values must follow copy
2257 relocation rules. */
2260 dwarf2_has_info (struct objfile
*objfile
,
2261 const struct dwarf2_debug_sections
*names
,
2264 if (objfile
->flags
& OBJF_READNEVER
)
2267 struct dwarf2_per_objfile
*dwarf2_per_objfile
2268 = get_dwarf2_per_objfile (objfile
);
2270 if (dwarf2_per_objfile
== NULL
)
2271 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2275 return (!dwarf2_per_objfile
->info
.is_virtual
2276 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2277 && !dwarf2_per_objfile
->abbrev
.is_virtual
2278 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2281 /* Return the containing section of virtual section SECTION. */
2283 static struct dwarf2_section_info
*
2284 get_containing_section (const struct dwarf2_section_info
*section
)
2286 gdb_assert (section
->is_virtual
);
2287 return section
->s
.containing_section
;
2290 /* Return the bfd owner of SECTION. */
2293 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2295 if (section
->is_virtual
)
2297 section
= get_containing_section (section
);
2298 gdb_assert (!section
->is_virtual
);
2300 return section
->s
.section
->owner
;
2303 /* Return the bfd section of SECTION.
2304 Returns NULL if the section is not present. */
2307 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2309 if (section
->is_virtual
)
2311 section
= get_containing_section (section
);
2312 gdb_assert (!section
->is_virtual
);
2314 return section
->s
.section
;
2317 /* Return the name of SECTION. */
2320 get_section_name (const struct dwarf2_section_info
*section
)
2322 asection
*sectp
= get_section_bfd_section (section
);
2324 gdb_assert (sectp
!= NULL
);
2325 return bfd_section_name (sectp
);
2328 /* Return the name of the file SECTION is in. */
2331 get_section_file_name (const struct dwarf2_section_info
*section
)
2333 bfd
*abfd
= get_section_bfd_owner (section
);
2335 return bfd_get_filename (abfd
);
2338 /* Return the id of SECTION.
2339 Returns 0 if SECTION doesn't exist. */
2342 get_section_id (const struct dwarf2_section_info
*section
)
2344 asection
*sectp
= get_section_bfd_section (section
);
2351 /* Return the flags of SECTION.
2352 SECTION (or containing section if this is a virtual section) must exist. */
2355 get_section_flags (const struct dwarf2_section_info
*section
)
2357 asection
*sectp
= get_section_bfd_section (section
);
2359 gdb_assert (sectp
!= NULL
);
2360 return bfd_section_flags (sectp
);
2363 /* When loading sections, we look either for uncompressed section or for
2364 compressed section names. */
2367 section_is_p (const char *section_name
,
2368 const struct dwarf2_section_names
*names
)
2370 if (names
->normal
!= NULL
2371 && strcmp (section_name
, names
->normal
) == 0)
2373 if (names
->compressed
!= NULL
2374 && strcmp (section_name
, names
->compressed
) == 0)
2379 /* See declaration. */
2382 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2383 const dwarf2_debug_sections
&names
)
2385 flagword aflag
= bfd_section_flags (sectp
);
2387 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2390 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2391 > bfd_get_file_size (abfd
))
2393 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2394 warning (_("Discarding section %s which has a section size (%s"
2395 ") larger than the file size [in module %s]"),
2396 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2397 bfd_get_filename (abfd
));
2399 else if (section_is_p (sectp
->name
, &names
.info
))
2401 this->info
.s
.section
= sectp
;
2402 this->info
.size
= bfd_section_size (sectp
);
2404 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2406 this->abbrev
.s
.section
= sectp
;
2407 this->abbrev
.size
= bfd_section_size (sectp
);
2409 else if (section_is_p (sectp
->name
, &names
.line
))
2411 this->line
.s
.section
= sectp
;
2412 this->line
.size
= bfd_section_size (sectp
);
2414 else if (section_is_p (sectp
->name
, &names
.loc
))
2416 this->loc
.s
.section
= sectp
;
2417 this->loc
.size
= bfd_section_size (sectp
);
2419 else if (section_is_p (sectp
->name
, &names
.loclists
))
2421 this->loclists
.s
.section
= sectp
;
2422 this->loclists
.size
= bfd_section_size (sectp
);
2424 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2426 this->macinfo
.s
.section
= sectp
;
2427 this->macinfo
.size
= bfd_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.macro
))
2431 this->macro
.s
.section
= sectp
;
2432 this->macro
.size
= bfd_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.str
))
2436 this->str
.s
.section
= sectp
;
2437 this->str
.size
= bfd_section_size (sectp
);
2439 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2441 this->str_offsets
.s
.section
= sectp
;
2442 this->str_offsets
.size
= bfd_section_size (sectp
);
2444 else if (section_is_p (sectp
->name
, &names
.line_str
))
2446 this->line_str
.s
.section
= sectp
;
2447 this->line_str
.size
= bfd_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &names
.addr
))
2451 this->addr
.s
.section
= sectp
;
2452 this->addr
.size
= bfd_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &names
.frame
))
2456 this->frame
.s
.section
= sectp
;
2457 this->frame
.size
= bfd_section_size (sectp
);
2459 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2461 this->eh_frame
.s
.section
= sectp
;
2462 this->eh_frame
.size
= bfd_section_size (sectp
);
2464 else if (section_is_p (sectp
->name
, &names
.ranges
))
2466 this->ranges
.s
.section
= sectp
;
2467 this->ranges
.size
= bfd_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2471 this->rnglists
.s
.section
= sectp
;
2472 this->rnglists
.size
= bfd_section_size (sectp
);
2474 else if (section_is_p (sectp
->name
, &names
.types
))
2476 struct dwarf2_section_info type_section
;
2478 memset (&type_section
, 0, sizeof (type_section
));
2479 type_section
.s
.section
= sectp
;
2480 type_section
.size
= bfd_section_size (sectp
);
2482 this->types
.push_back (type_section
);
2484 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2486 this->gdb_index
.s
.section
= sectp
;
2487 this->gdb_index
.size
= bfd_section_size (sectp
);
2489 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2491 this->debug_names
.s
.section
= sectp
;
2492 this->debug_names
.size
= bfd_section_size (sectp
);
2494 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2496 this->debug_aranges
.s
.section
= sectp
;
2497 this->debug_aranges
.size
= bfd_section_size (sectp
);
2500 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2501 && bfd_section_vma (sectp
) == 0)
2502 this->has_section_at_zero
= true;
2505 /* A helper function that decides whether a section is empty,
2509 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2511 if (section
->is_virtual
)
2512 return section
->size
== 0;
2513 return section
->s
.section
== NULL
|| section
->size
== 0;
2516 /* See dwarf2read.h. */
2519 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2523 gdb_byte
*buf
, *retbuf
;
2527 info
->buffer
= NULL
;
2528 info
->readin
= true;
2530 if (dwarf2_section_empty_p (info
))
2533 sectp
= get_section_bfd_section (info
);
2535 /* If this is a virtual section we need to read in the real one first. */
2536 if (info
->is_virtual
)
2538 struct dwarf2_section_info
*containing_section
=
2539 get_containing_section (info
);
2541 gdb_assert (sectp
!= NULL
);
2542 if ((sectp
->flags
& SEC_RELOC
) != 0)
2544 error (_("Dwarf Error: DWP format V2 with relocations is not"
2545 " supported in section %s [in module %s]"),
2546 get_section_name (info
), get_section_file_name (info
));
2548 dwarf2_read_section (objfile
, containing_section
);
2549 /* Other code should have already caught virtual sections that don't
2551 gdb_assert (info
->virtual_offset
+ info
->size
2552 <= containing_section
->size
);
2553 /* If the real section is empty or there was a problem reading the
2554 section we shouldn't get here. */
2555 gdb_assert (containing_section
->buffer
!= NULL
);
2556 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2560 /* If the section has relocations, we must read it ourselves.
2561 Otherwise we attach it to the BFD. */
2562 if ((sectp
->flags
& SEC_RELOC
) == 0)
2564 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2568 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2571 /* When debugging .o files, we may need to apply relocations; see
2572 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2573 We never compress sections in .o files, so we only need to
2574 try this when the section is not compressed. */
2575 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2578 info
->buffer
= retbuf
;
2582 abfd
= get_section_bfd_owner (info
);
2583 gdb_assert (abfd
!= NULL
);
2585 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2586 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2588 error (_("Dwarf Error: Can't read DWARF data"
2589 " in section %s [in module %s]"),
2590 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2594 /* A helper function that returns the size of a section in a safe way.
2595 If you are positive that the section has been read before using the
2596 size, then it is safe to refer to the dwarf2_section_info object's
2597 "size" field directly. In other cases, you must call this
2598 function, because for compressed sections the size field is not set
2599 correctly until the section has been read. */
2601 static bfd_size_type
2602 dwarf2_section_size (struct objfile
*objfile
,
2603 struct dwarf2_section_info
*info
)
2606 dwarf2_read_section (objfile
, info
);
2610 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2614 dwarf2_get_section_info (struct objfile
*objfile
,
2615 enum dwarf2_section_enum sect
,
2616 asection
**sectp
, const gdb_byte
**bufp
,
2617 bfd_size_type
*sizep
)
2619 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2620 struct dwarf2_section_info
*info
;
2622 /* We may see an objfile without any DWARF, in which case we just
2633 case DWARF2_DEBUG_FRAME
:
2634 info
= &data
->frame
;
2636 case DWARF2_EH_FRAME
:
2637 info
= &data
->eh_frame
;
2640 gdb_assert_not_reached ("unexpected section");
2643 dwarf2_read_section (objfile
, info
);
2645 *sectp
= get_section_bfd_section (info
);
2646 *bufp
= info
->buffer
;
2647 *sizep
= info
->size
;
2650 /* A helper function to find the sections for a .dwz file. */
2653 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2655 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2657 /* Note that we only support the standard ELF names, because .dwz
2658 is ELF-only (at the time of writing). */
2659 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2661 dwz_file
->abbrev
.s
.section
= sectp
;
2662 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2664 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2666 dwz_file
->info
.s
.section
= sectp
;
2667 dwz_file
->info
.size
= bfd_section_size (sectp
);
2669 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2671 dwz_file
->str
.s
.section
= sectp
;
2672 dwz_file
->str
.size
= bfd_section_size (sectp
);
2674 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2676 dwz_file
->line
.s
.section
= sectp
;
2677 dwz_file
->line
.size
= bfd_section_size (sectp
);
2679 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2681 dwz_file
->macro
.s
.section
= sectp
;
2682 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2684 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2686 dwz_file
->gdb_index
.s
.section
= sectp
;
2687 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2689 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2691 dwz_file
->debug_names
.s
.section
= sectp
;
2692 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2696 /* See dwarf2read.h. */
2699 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2701 const char *filename
;
2702 bfd_size_type buildid_len_arg
;
2706 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2707 return dwarf2_per_objfile
->dwz_file
.get ();
2709 bfd_set_error (bfd_error_no_error
);
2710 gdb::unique_xmalloc_ptr
<char> data
2711 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2712 &buildid_len_arg
, &buildid
));
2715 if (bfd_get_error () == bfd_error_no_error
)
2717 error (_("could not read '.gnu_debugaltlink' section: %s"),
2718 bfd_errmsg (bfd_get_error ()));
2721 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2723 buildid_len
= (size_t) buildid_len_arg
;
2725 filename
= data
.get ();
2727 std::string abs_storage
;
2728 if (!IS_ABSOLUTE_PATH (filename
))
2730 gdb::unique_xmalloc_ptr
<char> abs
2731 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2733 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2734 filename
= abs_storage
.c_str ();
2737 /* First try the file name given in the section. If that doesn't
2738 work, try to use the build-id instead. */
2739 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2740 if (dwz_bfd
!= NULL
)
2742 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2743 dwz_bfd
.reset (nullptr);
2746 if (dwz_bfd
== NULL
)
2747 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2749 if (dwz_bfd
== NULL
)
2750 error (_("could not find '.gnu_debugaltlink' file for %s"),
2751 objfile_name (dwarf2_per_objfile
->objfile
));
2753 std::unique_ptr
<struct dwz_file
> result
2754 (new struct dwz_file (std::move (dwz_bfd
)));
2756 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2759 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2760 result
->dwz_bfd
.get ());
2761 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2762 return dwarf2_per_objfile
->dwz_file
.get ();
2765 /* DWARF quick_symbols_functions support. */
2767 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2768 unique line tables, so we maintain a separate table of all .debug_line
2769 derived entries to support the sharing.
2770 All the quick functions need is the list of file names. We discard the
2771 line_header when we're done and don't need to record it here. */
2772 struct quick_file_names
2774 /* The data used to construct the hash key. */
2775 struct stmt_list_hash hash
;
2777 /* The number of entries in file_names, real_names. */
2778 unsigned int num_file_names
;
2780 /* The file names from the line table, after being run through
2782 const char **file_names
;
2784 /* The file names from the line table after being run through
2785 gdb_realpath. These are computed lazily. */
2786 const char **real_names
;
2789 /* When using the index (and thus not using psymtabs), each CU has an
2790 object of this type. This is used to hold information needed by
2791 the various "quick" methods. */
2792 struct dwarf2_per_cu_quick_data
2794 /* The file table. This can be NULL if there was no file table
2795 or it's currently not read in.
2796 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2797 struct quick_file_names
*file_names
;
2799 /* The corresponding symbol table. This is NULL if symbols for this
2800 CU have not yet been read. */
2801 struct compunit_symtab
*compunit_symtab
;
2803 /* A temporary mark bit used when iterating over all CUs in
2804 expand_symtabs_matching. */
2805 unsigned int mark
: 1;
2807 /* True if we've tried to read the file table and found there isn't one.
2808 There will be no point in trying to read it again next time. */
2809 unsigned int no_file_data
: 1;
2812 /* Utility hash function for a stmt_list_hash. */
2815 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2819 if (stmt_list_hash
->dwo_unit
!= NULL
)
2820 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2821 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2825 /* Utility equality function for a stmt_list_hash. */
2828 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2829 const struct stmt_list_hash
*rhs
)
2831 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2833 if (lhs
->dwo_unit
!= NULL
2834 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2837 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2840 /* Hash function for a quick_file_names. */
2843 hash_file_name_entry (const void *e
)
2845 const struct quick_file_names
*file_data
2846 = (const struct quick_file_names
*) e
;
2848 return hash_stmt_list_entry (&file_data
->hash
);
2851 /* Equality function for a quick_file_names. */
2854 eq_file_name_entry (const void *a
, const void *b
)
2856 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2857 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2859 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2862 /* Delete function for a quick_file_names. */
2865 delete_file_name_entry (void *e
)
2867 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2870 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2872 xfree ((void*) file_data
->file_names
[i
]);
2873 if (file_data
->real_names
)
2874 xfree ((void*) file_data
->real_names
[i
]);
2877 /* The space for the struct itself lives on objfile_obstack,
2878 so we don't free it here. */
2881 /* Create a quick_file_names hash table. */
2884 create_quick_file_names_table (unsigned int nr_initial_entries
)
2886 return htab_create_alloc (nr_initial_entries
,
2887 hash_file_name_entry
, eq_file_name_entry
,
2888 delete_file_name_entry
, xcalloc
, xfree
);
2891 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2892 have to be created afterwards. You should call age_cached_comp_units after
2893 processing PER_CU->CU. dw2_setup must have been already called. */
2896 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2898 if (per_cu
->is_debug_types
)
2899 load_full_type_unit (per_cu
);
2901 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2903 if (per_cu
->cu
== NULL
)
2904 return; /* Dummy CU. */
2906 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2909 /* Read in the symbols for PER_CU. */
2912 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2914 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2916 /* Skip type_unit_groups, reading the type units they contain
2917 is handled elsewhere. */
2918 if (IS_TYPE_UNIT_GROUP (per_cu
))
2921 /* The destructor of dwarf2_queue_guard frees any entries left on
2922 the queue. After this point we're guaranteed to leave this function
2923 with the dwarf queue empty. */
2924 dwarf2_queue_guard q_guard
;
2926 if (dwarf2_per_objfile
->using_index
2927 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2928 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2930 queue_comp_unit (per_cu
, language_minimal
);
2931 load_cu (per_cu
, skip_partial
);
2933 /* If we just loaded a CU from a DWO, and we're working with an index
2934 that may badly handle TUs, load all the TUs in that DWO as well.
2935 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2936 if (!per_cu
->is_debug_types
2937 && per_cu
->cu
!= NULL
2938 && per_cu
->cu
->dwo_unit
!= NULL
2939 && dwarf2_per_objfile
->index_table
!= NULL
2940 && dwarf2_per_objfile
->index_table
->version
<= 7
2941 /* DWP files aren't supported yet. */
2942 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2943 queue_and_load_all_dwo_tus (per_cu
);
2946 process_queue (dwarf2_per_objfile
);
2948 /* Age the cache, releasing compilation units that have not
2949 been used recently. */
2950 age_cached_comp_units (dwarf2_per_objfile
);
2953 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2954 the objfile from which this CU came. Returns the resulting symbol
2957 static struct compunit_symtab
*
2958 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2960 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2962 gdb_assert (dwarf2_per_objfile
->using_index
);
2963 if (!per_cu
->v
.quick
->compunit_symtab
)
2965 free_cached_comp_units
freer (dwarf2_per_objfile
);
2966 scoped_restore decrementer
= increment_reading_symtab ();
2967 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2968 process_cu_includes (dwarf2_per_objfile
);
2971 return per_cu
->v
.quick
->compunit_symtab
;
2974 /* See declaration. */
2976 dwarf2_per_cu_data
*
2977 dwarf2_per_objfile::get_cutu (int index
)
2979 if (index
>= this->all_comp_units
.size ())
2981 index
-= this->all_comp_units
.size ();
2982 gdb_assert (index
< this->all_type_units
.size ());
2983 return &this->all_type_units
[index
]->per_cu
;
2986 return this->all_comp_units
[index
];
2989 /* See declaration. */
2991 dwarf2_per_cu_data
*
2992 dwarf2_per_objfile::get_cu (int index
)
2994 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
2996 return this->all_comp_units
[index
];
2999 /* See declaration. */
3002 dwarf2_per_objfile::get_tu (int index
)
3004 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
3006 return this->all_type_units
[index
];
3009 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3010 objfile_obstack, and constructed with the specified field
3013 static dwarf2_per_cu_data
*
3014 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3015 struct dwarf2_section_info
*section
,
3017 sect_offset sect_off
, ULONGEST length
)
3019 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3020 dwarf2_per_cu_data
*the_cu
3021 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3022 struct dwarf2_per_cu_data
);
3023 the_cu
->sect_off
= sect_off
;
3024 the_cu
->length
= length
;
3025 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3026 the_cu
->section
= section
;
3027 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3028 struct dwarf2_per_cu_quick_data
);
3029 the_cu
->is_dwz
= is_dwz
;
3033 /* A helper for create_cus_from_index that handles a given list of
3037 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3038 const gdb_byte
*cu_list
, offset_type n_elements
,
3039 struct dwarf2_section_info
*section
,
3042 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3044 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3046 sect_offset sect_off
3047 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3048 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3051 dwarf2_per_cu_data
*per_cu
3052 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3054 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3058 /* Read the CU list from the mapped index, and use it to create all
3059 the CU objects for this objfile. */
3062 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3063 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3064 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3066 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3067 dwarf2_per_objfile
->all_comp_units
.reserve
3068 ((cu_list_elements
+ dwz_elements
) / 2);
3070 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3071 &dwarf2_per_objfile
->info
, 0);
3073 if (dwz_elements
== 0)
3076 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3077 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3081 /* Create the signatured type hash table from the index. */
3084 create_signatured_type_table_from_index
3085 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3086 struct dwarf2_section_info
*section
,
3087 const gdb_byte
*bytes
,
3088 offset_type elements
)
3090 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3092 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3093 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3095 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3097 for (offset_type i
= 0; i
< elements
; i
+= 3)
3099 struct signatured_type
*sig_type
;
3102 cu_offset type_offset_in_tu
;
3104 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3105 sect_offset sect_off
3106 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3108 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3110 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3113 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3114 struct signatured_type
);
3115 sig_type
->signature
= signature
;
3116 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3117 sig_type
->per_cu
.is_debug_types
= 1;
3118 sig_type
->per_cu
.section
= section
;
3119 sig_type
->per_cu
.sect_off
= sect_off
;
3120 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3121 sig_type
->per_cu
.v
.quick
3122 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3123 struct dwarf2_per_cu_quick_data
);
3125 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3128 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3131 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3134 /* Create the signatured type hash table from .debug_names. */
3137 create_signatured_type_table_from_debug_names
3138 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3139 const mapped_debug_names
&map
,
3140 struct dwarf2_section_info
*section
,
3141 struct dwarf2_section_info
*abbrev_section
)
3143 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3145 dwarf2_read_section (objfile
, section
);
3146 dwarf2_read_section (objfile
, abbrev_section
);
3148 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3149 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3151 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3153 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3155 struct signatured_type
*sig_type
;
3158 sect_offset sect_off
3159 = (sect_offset
) (extract_unsigned_integer
3160 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3162 map
.dwarf5_byte_order
));
3164 comp_unit_head cu_header
;
3165 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3167 section
->buffer
+ to_underlying (sect_off
),
3170 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3171 struct signatured_type
);
3172 sig_type
->signature
= cu_header
.signature
;
3173 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3174 sig_type
->per_cu
.is_debug_types
= 1;
3175 sig_type
->per_cu
.section
= section
;
3176 sig_type
->per_cu
.sect_off
= sect_off
;
3177 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3178 sig_type
->per_cu
.v
.quick
3179 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3180 struct dwarf2_per_cu_quick_data
);
3182 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3185 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3188 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3191 /* Read the address map data from the mapped index, and use it to
3192 populate the objfile's psymtabs_addrmap. */
3195 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3196 struct mapped_index
*index
)
3198 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3199 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3200 const gdb_byte
*iter
, *end
;
3201 struct addrmap
*mutable_map
;
3204 auto_obstack temp_obstack
;
3206 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3208 iter
= index
->address_table
.data ();
3209 end
= iter
+ index
->address_table
.size ();
3211 baseaddr
= objfile
->text_section_offset ();
3215 ULONGEST hi
, lo
, cu_index
;
3216 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3218 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3220 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3225 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3226 hex_string (lo
), hex_string (hi
));
3230 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3232 complaint (_(".gdb_index address table has invalid CU number %u"),
3233 (unsigned) cu_index
);
3237 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3238 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3239 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3240 dwarf2_per_objfile
->get_cu (cu_index
));
3243 objfile
->partial_symtabs
->psymtabs_addrmap
3244 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3247 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3248 populate the objfile's psymtabs_addrmap. */
3251 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3252 struct dwarf2_section_info
*section
)
3254 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3255 bfd
*abfd
= objfile
->obfd
;
3256 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3257 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3259 auto_obstack temp_obstack
;
3260 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3262 std::unordered_map
<sect_offset
,
3263 dwarf2_per_cu_data
*,
3264 gdb::hash_enum
<sect_offset
>>
3265 debug_info_offset_to_per_cu
;
3266 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3268 const auto insertpair
3269 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3270 if (!insertpair
.second
)
3272 warning (_("Section .debug_aranges in %s has duplicate "
3273 "debug_info_offset %s, ignoring .debug_aranges."),
3274 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3279 dwarf2_read_section (objfile
, section
);
3281 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3283 const gdb_byte
*addr
= section
->buffer
;
3285 while (addr
< section
->buffer
+ section
->size
)
3287 const gdb_byte
*const entry_addr
= addr
;
3288 unsigned int bytes_read
;
3290 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3294 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3295 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3296 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3297 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3299 warning (_("Section .debug_aranges in %s entry at offset %s "
3300 "length %s exceeds section length %s, "
3301 "ignoring .debug_aranges."),
3302 objfile_name (objfile
),
3303 plongest (entry_addr
- section
->buffer
),
3304 plongest (bytes_read
+ entry_length
),
3305 pulongest (section
->size
));
3309 /* The version number. */
3310 const uint16_t version
= read_2_bytes (abfd
, addr
);
3314 warning (_("Section .debug_aranges in %s entry at offset %s "
3315 "has unsupported version %d, ignoring .debug_aranges."),
3316 objfile_name (objfile
),
3317 plongest (entry_addr
- section
->buffer
), version
);
3321 const uint64_t debug_info_offset
3322 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3323 addr
+= offset_size
;
3324 const auto per_cu_it
3325 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3326 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3328 warning (_("Section .debug_aranges in %s entry at offset %s "
3329 "debug_info_offset %s does not exists, "
3330 "ignoring .debug_aranges."),
3331 objfile_name (objfile
),
3332 plongest (entry_addr
- section
->buffer
),
3333 pulongest (debug_info_offset
));
3336 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3338 const uint8_t address_size
= *addr
++;
3339 if (address_size
< 1 || address_size
> 8)
3341 warning (_("Section .debug_aranges in %s entry at offset %s "
3342 "address_size %u is invalid, ignoring .debug_aranges."),
3343 objfile_name (objfile
),
3344 plongest (entry_addr
- section
->buffer
), address_size
);
3348 const uint8_t segment_selector_size
= *addr
++;
3349 if (segment_selector_size
!= 0)
3351 warning (_("Section .debug_aranges in %s entry at offset %s "
3352 "segment_selector_size %u is not supported, "
3353 "ignoring .debug_aranges."),
3354 objfile_name (objfile
),
3355 plongest (entry_addr
- section
->buffer
),
3356 segment_selector_size
);
3360 /* Must pad to an alignment boundary that is twice the address
3361 size. It is undocumented by the DWARF standard but GCC does
3363 for (size_t padding
= ((-(addr
- section
->buffer
))
3364 & (2 * address_size
- 1));
3365 padding
> 0; padding
--)
3368 warning (_("Section .debug_aranges in %s entry at offset %s "
3369 "padding is not zero, ignoring .debug_aranges."),
3370 objfile_name (objfile
),
3371 plongest (entry_addr
- section
->buffer
));
3377 if (addr
+ 2 * address_size
> entry_end
)
3379 warning (_("Section .debug_aranges in %s entry at offset %s "
3380 "address list is not properly terminated, "
3381 "ignoring .debug_aranges."),
3382 objfile_name (objfile
),
3383 plongest (entry_addr
- section
->buffer
));
3386 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3388 addr
+= address_size
;
3389 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3391 addr
+= address_size
;
3392 if (start
== 0 && length
== 0)
3394 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3396 /* Symbol was eliminated due to a COMDAT group. */
3399 ULONGEST end
= start
+ length
;
3400 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3402 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3404 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3408 objfile
->partial_symtabs
->psymtabs_addrmap
3409 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3412 /* Find a slot in the mapped index INDEX for the object named NAME.
3413 If NAME is found, set *VEC_OUT to point to the CU vector in the
3414 constant pool and return true. If NAME cannot be found, return
3418 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3419 offset_type
**vec_out
)
3422 offset_type slot
, step
;
3423 int (*cmp
) (const char *, const char *);
3425 gdb::unique_xmalloc_ptr
<char> without_params
;
3426 if (current_language
->la_language
== language_cplus
3427 || current_language
->la_language
== language_fortran
3428 || current_language
->la_language
== language_d
)
3430 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3433 if (strchr (name
, '(') != NULL
)
3435 without_params
= cp_remove_params (name
);
3437 if (without_params
!= NULL
)
3438 name
= without_params
.get ();
3442 /* Index version 4 did not support case insensitive searches. But the
3443 indices for case insensitive languages are built in lowercase, therefore
3444 simulate our NAME being searched is also lowercased. */
3445 hash
= mapped_index_string_hash ((index
->version
== 4
3446 && case_sensitivity
== case_sensitive_off
3447 ? 5 : index
->version
),
3450 slot
= hash
& (index
->symbol_table
.size () - 1);
3451 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3452 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3458 const auto &bucket
= index
->symbol_table
[slot
];
3459 if (bucket
.name
== 0 && bucket
.vec
== 0)
3462 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3463 if (!cmp (name
, str
))
3465 *vec_out
= (offset_type
*) (index
->constant_pool
3466 + MAYBE_SWAP (bucket
.vec
));
3470 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3474 /* A helper function that reads the .gdb_index from BUFFER and fills
3475 in MAP. FILENAME is the name of the file containing the data;
3476 it is used for error reporting. DEPRECATED_OK is true if it is
3477 ok to use deprecated sections.
3479 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3480 out parameters that are filled in with information about the CU and
3481 TU lists in the section.
3483 Returns true if all went well, false otherwise. */
3486 read_gdb_index_from_buffer (struct objfile
*objfile
,
3487 const char *filename
,
3489 gdb::array_view
<const gdb_byte
> buffer
,
3490 struct mapped_index
*map
,
3491 const gdb_byte
**cu_list
,
3492 offset_type
*cu_list_elements
,
3493 const gdb_byte
**types_list
,
3494 offset_type
*types_list_elements
)
3496 const gdb_byte
*addr
= &buffer
[0];
3498 /* Version check. */
3499 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3500 /* Versions earlier than 3 emitted every copy of a psymbol. This
3501 causes the index to behave very poorly for certain requests. Version 3
3502 contained incomplete addrmap. So, it seems better to just ignore such
3506 static int warning_printed
= 0;
3507 if (!warning_printed
)
3509 warning (_("Skipping obsolete .gdb_index section in %s."),
3511 warning_printed
= 1;
3515 /* Index version 4 uses a different hash function than index version
3518 Versions earlier than 6 did not emit psymbols for inlined
3519 functions. Using these files will cause GDB not to be able to
3520 set breakpoints on inlined functions by name, so we ignore these
3521 indices unless the user has done
3522 "set use-deprecated-index-sections on". */
3523 if (version
< 6 && !deprecated_ok
)
3525 static int warning_printed
= 0;
3526 if (!warning_printed
)
3529 Skipping deprecated .gdb_index section in %s.\n\
3530 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3531 to use the section anyway."),
3533 warning_printed
= 1;
3537 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3538 of the TU (for symbols coming from TUs),
3539 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3540 Plus gold-generated indices can have duplicate entries for global symbols,
3541 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3542 These are just performance bugs, and we can't distinguish gdb-generated
3543 indices from gold-generated ones, so issue no warning here. */
3545 /* Indexes with higher version than the one supported by GDB may be no
3546 longer backward compatible. */
3550 map
->version
= version
;
3552 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3555 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3556 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3560 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3561 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3562 - MAYBE_SWAP (metadata
[i
]))
3566 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3567 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3569 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3572 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3573 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3575 = gdb::array_view
<mapped_index::symbol_table_slot
>
3576 ((mapped_index::symbol_table_slot
*) symbol_table
,
3577 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3580 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3585 /* Callback types for dwarf2_read_gdb_index. */
3587 typedef gdb::function_view
3588 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3589 get_gdb_index_contents_ftype
;
3590 typedef gdb::function_view
3591 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3592 get_gdb_index_contents_dwz_ftype
;
3594 /* Read .gdb_index. If everything went ok, initialize the "quick"
3595 elements of all the CUs and return 1. Otherwise, return 0. */
3598 dwarf2_read_gdb_index
3599 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3600 get_gdb_index_contents_ftype get_gdb_index_contents
,
3601 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3603 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3604 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3605 struct dwz_file
*dwz
;
3606 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3608 gdb::array_view
<const gdb_byte
> main_index_contents
3609 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3611 if (main_index_contents
.empty ())
3614 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3615 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3616 use_deprecated_index_sections
,
3617 main_index_contents
, map
.get (), &cu_list
,
3618 &cu_list_elements
, &types_list
,
3619 &types_list_elements
))
3622 /* Don't use the index if it's empty. */
3623 if (map
->symbol_table
.empty ())
3626 /* If there is a .dwz file, read it so we can get its CU list as
3628 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3631 struct mapped_index dwz_map
;
3632 const gdb_byte
*dwz_types_ignore
;
3633 offset_type dwz_types_elements_ignore
;
3635 gdb::array_view
<const gdb_byte
> dwz_index_content
3636 = get_gdb_index_contents_dwz (objfile
, dwz
);
3638 if (dwz_index_content
.empty ())
3641 if (!read_gdb_index_from_buffer (objfile
,
3642 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3643 1, dwz_index_content
, &dwz_map
,
3644 &dwz_list
, &dwz_list_elements
,
3646 &dwz_types_elements_ignore
))
3648 warning (_("could not read '.gdb_index' section from %s; skipping"),
3649 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3654 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3655 dwz_list
, dwz_list_elements
);
3657 if (types_list_elements
)
3659 /* We can only handle a single .debug_types when we have an
3661 if (dwarf2_per_objfile
->types
.size () != 1)
3664 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3666 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3667 types_list
, types_list_elements
);
3670 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3672 dwarf2_per_objfile
->index_table
= std::move (map
);
3673 dwarf2_per_objfile
->using_index
= 1;
3674 dwarf2_per_objfile
->quick_file_names_table
=
3675 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3680 /* die_reader_func for dw2_get_file_names. */
3683 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3684 const gdb_byte
*info_ptr
,
3685 struct die_info
*comp_unit_die
,
3688 struct dwarf2_cu
*cu
= reader
->cu
;
3689 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3690 struct dwarf2_per_objfile
*dwarf2_per_objfile
3691 = cu
->per_cu
->dwarf2_per_objfile
;
3692 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3693 struct dwarf2_per_cu_data
*lh_cu
;
3694 struct attribute
*attr
;
3696 struct quick_file_names
*qfn
;
3698 gdb_assert (! this_cu
->is_debug_types
);
3700 /* Our callers never want to match partial units -- instead they
3701 will match the enclosing full CU. */
3702 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3704 this_cu
->v
.quick
->no_file_data
= 1;
3712 sect_offset line_offset
{};
3714 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3715 if (attr
!= nullptr)
3717 struct quick_file_names find_entry
;
3719 line_offset
= (sect_offset
) DW_UNSND (attr
);
3721 /* We may have already read in this line header (TU line header sharing).
3722 If we have we're done. */
3723 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3724 find_entry
.hash
.line_sect_off
= line_offset
;
3725 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3726 &find_entry
, INSERT
);
3729 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3733 lh
= dwarf_decode_line_header (line_offset
, cu
);
3737 lh_cu
->v
.quick
->no_file_data
= 1;
3741 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3742 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3743 qfn
->hash
.line_sect_off
= line_offset
;
3744 gdb_assert (slot
!= NULL
);
3747 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3750 if (strcmp (fnd
.name
, "<unknown>") != 0)
3753 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3755 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3757 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3758 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3759 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3760 qfn
->real_names
= NULL
;
3762 lh_cu
->v
.quick
->file_names
= qfn
;
3765 /* A helper for the "quick" functions which attempts to read the line
3766 table for THIS_CU. */
3768 static struct quick_file_names
*
3769 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3771 /* This should never be called for TUs. */
3772 gdb_assert (! this_cu
->is_debug_types
);
3773 /* Nor type unit groups. */
3774 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3776 if (this_cu
->v
.quick
->file_names
!= NULL
)
3777 return this_cu
->v
.quick
->file_names
;
3778 /* If we know there is no line data, no point in looking again. */
3779 if (this_cu
->v
.quick
->no_file_data
)
3782 cutu_reader
reader (this_cu
);
3783 if (!reader
.dummy_p
)
3784 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3785 reader
.has_children
);
3787 if (this_cu
->v
.quick
->no_file_data
)
3789 return this_cu
->v
.quick
->file_names
;
3792 /* A helper for the "quick" functions which computes and caches the
3793 real path for a given file name from the line table. */
3796 dw2_get_real_path (struct objfile
*objfile
,
3797 struct quick_file_names
*qfn
, int index
)
3799 if (qfn
->real_names
== NULL
)
3800 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3801 qfn
->num_file_names
, const char *);
3803 if (qfn
->real_names
[index
] == NULL
)
3804 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3806 return qfn
->real_names
[index
];
3809 static struct symtab
*
3810 dw2_find_last_source_symtab (struct objfile
*objfile
)
3812 struct dwarf2_per_objfile
*dwarf2_per_objfile
3813 = get_dwarf2_per_objfile (objfile
);
3814 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3815 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3820 return compunit_primary_filetab (cust
);
3823 /* Traversal function for dw2_forget_cached_source_info. */
3826 dw2_free_cached_file_names (void **slot
, void *info
)
3828 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3830 if (file_data
->real_names
)
3834 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3836 xfree ((void*) file_data
->real_names
[i
]);
3837 file_data
->real_names
[i
] = NULL
;
3845 dw2_forget_cached_source_info (struct objfile
*objfile
)
3847 struct dwarf2_per_objfile
*dwarf2_per_objfile
3848 = get_dwarf2_per_objfile (objfile
);
3850 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3851 dw2_free_cached_file_names
, NULL
);
3854 /* Helper function for dw2_map_symtabs_matching_filename that expands
3855 the symtabs and calls the iterator. */
3858 dw2_map_expand_apply (struct objfile
*objfile
,
3859 struct dwarf2_per_cu_data
*per_cu
,
3860 const char *name
, const char *real_path
,
3861 gdb::function_view
<bool (symtab
*)> callback
)
3863 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3865 /* Don't visit already-expanded CUs. */
3866 if (per_cu
->v
.quick
->compunit_symtab
)
3869 /* This may expand more than one symtab, and we want to iterate over
3871 dw2_instantiate_symtab (per_cu
, false);
3873 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3874 last_made
, callback
);
3877 /* Implementation of the map_symtabs_matching_filename method. */
3880 dw2_map_symtabs_matching_filename
3881 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3882 gdb::function_view
<bool (symtab
*)> callback
)
3884 const char *name_basename
= lbasename (name
);
3885 struct dwarf2_per_objfile
*dwarf2_per_objfile
3886 = get_dwarf2_per_objfile (objfile
);
3888 /* The rule is CUs specify all the files, including those used by
3889 any TU, so there's no need to scan TUs here. */
3891 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3893 /* We only need to look at symtabs not already expanded. */
3894 if (per_cu
->v
.quick
->compunit_symtab
)
3897 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3898 if (file_data
== NULL
)
3901 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3903 const char *this_name
= file_data
->file_names
[j
];
3904 const char *this_real_name
;
3906 if (compare_filenames_for_search (this_name
, name
))
3908 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3914 /* Before we invoke realpath, which can get expensive when many
3915 files are involved, do a quick comparison of the basenames. */
3916 if (! basenames_may_differ
3917 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3920 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3921 if (compare_filenames_for_search (this_real_name
, name
))
3923 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3929 if (real_path
!= NULL
)
3931 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3932 gdb_assert (IS_ABSOLUTE_PATH (name
));
3933 if (this_real_name
!= NULL
3934 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3936 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3948 /* Struct used to manage iterating over all CUs looking for a symbol. */
3950 struct dw2_symtab_iterator
3952 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3953 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3954 /* If set, only look for symbols that match that block. Valid values are
3955 GLOBAL_BLOCK and STATIC_BLOCK. */
3956 gdb::optional
<block_enum
> block_index
;
3957 /* The kind of symbol we're looking for. */
3959 /* The list of CUs from the index entry of the symbol,
3960 or NULL if not found. */
3962 /* The next element in VEC to look at. */
3964 /* The number of elements in VEC, or zero if there is no match. */
3966 /* Have we seen a global version of the symbol?
3967 If so we can ignore all further global instances.
3968 This is to work around gold/15646, inefficient gold-generated
3973 /* Initialize the index symtab iterator ITER. */
3976 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3977 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3978 gdb::optional
<block_enum
> block_index
,
3982 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3983 iter
->block_index
= block_index
;
3984 iter
->domain
= domain
;
3986 iter
->global_seen
= 0;
3988 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3990 /* index is NULL if OBJF_READNOW. */
3991 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3992 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4000 /* Return the next matching CU or NULL if there are no more. */
4002 static struct dwarf2_per_cu_data
*
4003 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4005 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4007 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4009 offset_type cu_index_and_attrs
=
4010 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4011 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4012 gdb_index_symbol_kind symbol_kind
=
4013 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4014 /* Only check the symbol attributes if they're present.
4015 Indices prior to version 7 don't record them,
4016 and indices >= 7 may elide them for certain symbols
4017 (gold does this). */
4019 (dwarf2_per_objfile
->index_table
->version
>= 7
4020 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4022 /* Don't crash on bad data. */
4023 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4024 + dwarf2_per_objfile
->all_type_units
.size ()))
4026 complaint (_(".gdb_index entry has bad CU index"
4028 objfile_name (dwarf2_per_objfile
->objfile
));
4032 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4034 /* Skip if already read in. */
4035 if (per_cu
->v
.quick
->compunit_symtab
)
4038 /* Check static vs global. */
4041 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4043 if (iter
->block_index
.has_value ())
4045 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4047 if (is_static
!= want_static
)
4051 /* Work around gold/15646. */
4052 if (!is_static
&& iter
->global_seen
)
4055 iter
->global_seen
= 1;
4058 /* Only check the symbol's kind if it has one. */
4061 switch (iter
->domain
)
4064 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4065 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4066 /* Some types are also in VAR_DOMAIN. */
4067 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4071 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4075 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4079 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4094 static struct compunit_symtab
*
4095 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4096 const char *name
, domain_enum domain
)
4098 struct compunit_symtab
*stab_best
= NULL
;
4099 struct dwarf2_per_objfile
*dwarf2_per_objfile
4100 = get_dwarf2_per_objfile (objfile
);
4102 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4104 struct dw2_symtab_iterator iter
;
4105 struct dwarf2_per_cu_data
*per_cu
;
4107 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4109 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4111 struct symbol
*sym
, *with_opaque
= NULL
;
4112 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4113 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4114 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4116 sym
= block_find_symbol (block
, name
, domain
,
4117 block_find_non_opaque_type_preferred
,
4120 /* Some caution must be observed with overloaded functions
4121 and methods, since the index will not contain any overload
4122 information (but NAME might contain it). */
4125 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4127 if (with_opaque
!= NULL
4128 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4131 /* Keep looking through other CUs. */
4138 dw2_print_stats (struct objfile
*objfile
)
4140 struct dwarf2_per_objfile
*dwarf2_per_objfile
4141 = get_dwarf2_per_objfile (objfile
);
4142 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4143 + dwarf2_per_objfile
->all_type_units
.size ());
4146 for (int i
= 0; i
< total
; ++i
)
4148 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4150 if (!per_cu
->v
.quick
->compunit_symtab
)
4153 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4154 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4157 /* This dumps minimal information about the index.
4158 It is called via "mt print objfiles".
4159 One use is to verify .gdb_index has been loaded by the
4160 gdb.dwarf2/gdb-index.exp testcase. */
4163 dw2_dump (struct objfile
*objfile
)
4165 struct dwarf2_per_objfile
*dwarf2_per_objfile
4166 = get_dwarf2_per_objfile (objfile
);
4168 gdb_assert (dwarf2_per_objfile
->using_index
);
4169 printf_filtered (".gdb_index:");
4170 if (dwarf2_per_objfile
->index_table
!= NULL
)
4172 printf_filtered (" version %d\n",
4173 dwarf2_per_objfile
->index_table
->version
);
4176 printf_filtered (" faked for \"readnow\"\n");
4177 printf_filtered ("\n");
4181 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4182 const char *func_name
)
4184 struct dwarf2_per_objfile
*dwarf2_per_objfile
4185 = get_dwarf2_per_objfile (objfile
);
4187 struct dw2_symtab_iterator iter
;
4188 struct dwarf2_per_cu_data
*per_cu
;
4190 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4192 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4193 dw2_instantiate_symtab (per_cu
, false);
4198 dw2_expand_all_symtabs (struct objfile
*objfile
)
4200 struct dwarf2_per_objfile
*dwarf2_per_objfile
4201 = get_dwarf2_per_objfile (objfile
);
4202 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4203 + dwarf2_per_objfile
->all_type_units
.size ());
4205 for (int i
= 0; i
< total_units
; ++i
)
4207 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4209 /* We don't want to directly expand a partial CU, because if we
4210 read it with the wrong language, then assertion failures can
4211 be triggered later on. See PR symtab/23010. So, tell
4212 dw2_instantiate_symtab to skip partial CUs -- any important
4213 partial CU will be read via DW_TAG_imported_unit anyway. */
4214 dw2_instantiate_symtab (per_cu
, true);
4219 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4220 const char *fullname
)
4222 struct dwarf2_per_objfile
*dwarf2_per_objfile
4223 = get_dwarf2_per_objfile (objfile
);
4225 /* We don't need to consider type units here.
4226 This is only called for examining code, e.g. expand_line_sal.
4227 There can be an order of magnitude (or more) more type units
4228 than comp units, and we avoid them if we can. */
4230 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4232 /* We only need to look at symtabs not already expanded. */
4233 if (per_cu
->v
.quick
->compunit_symtab
)
4236 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4237 if (file_data
== NULL
)
4240 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4242 const char *this_fullname
= file_data
->file_names
[j
];
4244 if (filename_cmp (this_fullname
, fullname
) == 0)
4246 dw2_instantiate_symtab (per_cu
, false);
4254 dw2_map_matching_symbols
4255 (struct objfile
*objfile
,
4256 const lookup_name_info
&name
, domain_enum domain
,
4258 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4259 symbol_compare_ftype
*ordered_compare
)
4261 /* Currently unimplemented; used for Ada. The function can be called if the
4262 current language is Ada for a non-Ada objfile using GNU index. As Ada
4263 does not look for non-Ada symbols this function should just return. */
4266 /* Starting from a search name, return the string that finds the upper
4267 bound of all strings that start with SEARCH_NAME in a sorted name
4268 list. Returns the empty string to indicate that the upper bound is
4269 the end of the list. */
4272 make_sort_after_prefix_name (const char *search_name
)
4274 /* When looking to complete "func", we find the upper bound of all
4275 symbols that start with "func" by looking for where we'd insert
4276 the closest string that would follow "func" in lexicographical
4277 order. Usually, that's "func"-with-last-character-incremented,
4278 i.e. "fund". Mind non-ASCII characters, though. Usually those
4279 will be UTF-8 multi-byte sequences, but we can't be certain.
4280 Especially mind the 0xff character, which is a valid character in
4281 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4282 rule out compilers allowing it in identifiers. Note that
4283 conveniently, strcmp/strcasecmp are specified to compare
4284 characters interpreted as unsigned char. So what we do is treat
4285 the whole string as a base 256 number composed of a sequence of
4286 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4287 to 0, and carries 1 to the following more-significant position.
4288 If the very first character in SEARCH_NAME ends up incremented
4289 and carries/overflows, then the upper bound is the end of the
4290 list. The string after the empty string is also the empty
4293 Some examples of this operation:
4295 SEARCH_NAME => "+1" RESULT
4299 "\xff" "a" "\xff" => "\xff" "b"
4304 Then, with these symbols for example:
4310 completing "func" looks for symbols between "func" and
4311 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4312 which finds "func" and "func1", but not "fund".
4316 funcÿ (Latin1 'ÿ' [0xff])
4320 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4321 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4325 ÿÿ (Latin1 'ÿ' [0xff])
4328 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4329 the end of the list.
4331 std::string after
= search_name
;
4332 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4334 if (!after
.empty ())
4335 after
.back () = (unsigned char) after
.back () + 1;
4339 /* See declaration. */
4341 std::pair
<std::vector
<name_component
>::const_iterator
,
4342 std::vector
<name_component
>::const_iterator
>
4343 mapped_index_base::find_name_components_bounds
4344 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4347 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4349 const char *lang_name
4350 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4352 /* Comparison function object for lower_bound that matches against a
4353 given symbol name. */
4354 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4357 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4358 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4359 return name_cmp (elem_name
, name
) < 0;
4362 /* Comparison function object for upper_bound that matches against a
4363 given symbol name. */
4364 auto lookup_compare_upper
= [&] (const char *name
,
4365 const name_component
&elem
)
4367 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4368 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4369 return name_cmp (name
, elem_name
) < 0;
4372 auto begin
= this->name_components
.begin ();
4373 auto end
= this->name_components
.end ();
4375 /* Find the lower bound. */
4378 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4381 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4384 /* Find the upper bound. */
4387 if (lookup_name_without_params
.completion_mode ())
4389 /* In completion mode, we want UPPER to point past all
4390 symbols names that have the same prefix. I.e., with
4391 these symbols, and completing "func":
4393 function << lower bound
4395 other_function << upper bound
4397 We find the upper bound by looking for the insertion
4398 point of "func"-with-last-character-incremented,
4400 std::string after
= make_sort_after_prefix_name (lang_name
);
4403 return std::lower_bound (lower
, end
, after
.c_str (),
4404 lookup_compare_lower
);
4407 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4410 return {lower
, upper
};
4413 /* See declaration. */
4416 mapped_index_base::build_name_components ()
4418 if (!this->name_components
.empty ())
4421 this->name_components_casing
= case_sensitivity
;
4423 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4425 /* The code below only knows how to break apart components of C++
4426 symbol names (and other languages that use '::' as
4427 namespace/module separator) and Ada symbol names. */
4428 auto count
= this->symbol_name_count ();
4429 for (offset_type idx
= 0; idx
< count
; idx
++)
4431 if (this->symbol_name_slot_invalid (idx
))
4434 const char *name
= this->symbol_name_at (idx
);
4436 /* Add each name component to the name component table. */
4437 unsigned int previous_len
= 0;
4439 if (strstr (name
, "::") != nullptr)
4441 for (unsigned int current_len
= cp_find_first_component (name
);
4442 name
[current_len
] != '\0';
4443 current_len
+= cp_find_first_component (name
+ current_len
))
4445 gdb_assert (name
[current_len
] == ':');
4446 this->name_components
.push_back ({previous_len
, idx
});
4447 /* Skip the '::'. */
4449 previous_len
= current_len
;
4454 /* Handle the Ada encoded (aka mangled) form here. */
4455 for (const char *iter
= strstr (name
, "__");
4457 iter
= strstr (iter
, "__"))
4459 this->name_components
.push_back ({previous_len
, idx
});
4461 previous_len
= iter
- name
;
4465 this->name_components
.push_back ({previous_len
, idx
});
4468 /* Sort name_components elements by name. */
4469 auto name_comp_compare
= [&] (const name_component
&left
,
4470 const name_component
&right
)
4472 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4473 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4475 const char *left_name
= left_qualified
+ left
.name_offset
;
4476 const char *right_name
= right_qualified
+ right
.name_offset
;
4478 return name_cmp (left_name
, right_name
) < 0;
4481 std::sort (this->name_components
.begin (),
4482 this->name_components
.end (),
4486 /* Helper for dw2_expand_symtabs_matching that works with a
4487 mapped_index_base instead of the containing objfile. This is split
4488 to a separate function in order to be able to unit test the
4489 name_components matching using a mock mapped_index_base. For each
4490 symbol name that matches, calls MATCH_CALLBACK, passing it the
4491 symbol's index in the mapped_index_base symbol table. */
4494 dw2_expand_symtabs_matching_symbol
4495 (mapped_index_base
&index
,
4496 const lookup_name_info
&lookup_name_in
,
4497 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4498 enum search_domain kind
,
4499 gdb::function_view
<bool (offset_type
)> match_callback
)
4501 lookup_name_info lookup_name_without_params
4502 = lookup_name_in
.make_ignore_params ();
4504 /* Build the symbol name component sorted vector, if we haven't
4506 index
.build_name_components ();
4508 /* The same symbol may appear more than once in the range though.
4509 E.g., if we're looking for symbols that complete "w", and we have
4510 a symbol named "w1::w2", we'll find the two name components for
4511 that same symbol in the range. To be sure we only call the
4512 callback once per symbol, we first collect the symbol name
4513 indexes that matched in a temporary vector and ignore
4515 std::vector
<offset_type
> matches
;
4517 struct name_and_matcher
4519 symbol_name_matcher_ftype
*matcher
;
4520 const std::string
&name
;
4522 bool operator== (const name_and_matcher
&other
) const
4524 return matcher
== other
.matcher
&& name
== other
.name
;
4528 /* A vector holding all the different symbol name matchers, for all
4530 std::vector
<name_and_matcher
> matchers
;
4532 for (int i
= 0; i
< nr_languages
; i
++)
4534 enum language lang_e
= (enum language
) i
;
4536 const language_defn
*lang
= language_def (lang_e
);
4537 symbol_name_matcher_ftype
*name_matcher
4538 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4540 name_and_matcher key
{
4542 lookup_name_without_params
.language_lookup_name (lang_e
)
4545 /* Don't insert the same comparison routine more than once.
4546 Note that we do this linear walk. This is not a problem in
4547 practice because the number of supported languages is
4549 if (std::find (matchers
.begin (), matchers
.end (), key
)
4552 matchers
.push_back (std::move (key
));
4555 = index
.find_name_components_bounds (lookup_name_without_params
,
4558 /* Now for each symbol name in range, check to see if we have a name
4559 match, and if so, call the MATCH_CALLBACK callback. */
4561 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4563 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4565 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4566 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4569 matches
.push_back (bounds
.first
->idx
);
4573 std::sort (matches
.begin (), matches
.end ());
4575 /* Finally call the callback, once per match. */
4577 for (offset_type idx
: matches
)
4581 if (!match_callback (idx
))
4587 /* Above we use a type wider than idx's for 'prev', since 0 and
4588 (offset_type)-1 are both possible values. */
4589 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4594 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4596 /* A mock .gdb_index/.debug_names-like name index table, enough to
4597 exercise dw2_expand_symtabs_matching_symbol, which works with the
4598 mapped_index_base interface. Builds an index from the symbol list
4599 passed as parameter to the constructor. */
4600 class mock_mapped_index
: public mapped_index_base
4603 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4604 : m_symbol_table (symbols
)
4607 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4609 /* Return the number of names in the symbol table. */
4610 size_t symbol_name_count () const override
4612 return m_symbol_table
.size ();
4615 /* Get the name of the symbol at IDX in the symbol table. */
4616 const char *symbol_name_at (offset_type idx
) const override
4618 return m_symbol_table
[idx
];
4622 gdb::array_view
<const char *> m_symbol_table
;
4625 /* Convenience function that converts a NULL pointer to a "<null>"
4626 string, to pass to print routines. */
4629 string_or_null (const char *str
)
4631 return str
!= NULL
? str
: "<null>";
4634 /* Check if a lookup_name_info built from
4635 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4636 index. EXPECTED_LIST is the list of expected matches, in expected
4637 matching order. If no match expected, then an empty list is
4638 specified. Returns true on success. On failure prints a warning
4639 indicating the file:line that failed, and returns false. */
4642 check_match (const char *file
, int line
,
4643 mock_mapped_index
&mock_index
,
4644 const char *name
, symbol_name_match_type match_type
,
4645 bool completion_mode
,
4646 std::initializer_list
<const char *> expected_list
)
4648 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4650 bool matched
= true;
4652 auto mismatch
= [&] (const char *expected_str
,
4655 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4656 "expected=\"%s\", got=\"%s\"\n"),
4658 (match_type
== symbol_name_match_type::FULL
4660 name
, string_or_null (expected_str
), string_or_null (got
));
4664 auto expected_it
= expected_list
.begin ();
4665 auto expected_end
= expected_list
.end ();
4667 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4669 [&] (offset_type idx
)
4671 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4672 const char *expected_str
4673 = expected_it
== expected_end
? NULL
: *expected_it
++;
4675 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4676 mismatch (expected_str
, matched_name
);
4680 const char *expected_str
4681 = expected_it
== expected_end
? NULL
: *expected_it
++;
4682 if (expected_str
!= NULL
)
4683 mismatch (expected_str
, NULL
);
4688 /* The symbols added to the mock mapped_index for testing (in
4690 static const char *test_symbols
[] = {
4699 "ns2::tmpl<int>::foo2",
4700 "(anonymous namespace)::A::B::C",
4702 /* These are used to check that the increment-last-char in the
4703 matching algorithm for completion doesn't match "t1_fund" when
4704 completing "t1_func". */
4710 /* A UTF-8 name with multi-byte sequences to make sure that
4711 cp-name-parser understands this as a single identifier ("função"
4712 is "function" in PT). */
4715 /* \377 (0xff) is Latin1 'ÿ'. */
4718 /* \377 (0xff) is Latin1 'ÿ'. */
4722 /* A name with all sorts of complications. Starts with "z" to make
4723 it easier for the completion tests below. */
4724 #define Z_SYM_NAME \
4725 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4726 "::tuple<(anonymous namespace)::ui*, " \
4727 "std::default_delete<(anonymous namespace)::ui>, void>"
4732 /* Returns true if the mapped_index_base::find_name_component_bounds
4733 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4734 in completion mode. */
4737 check_find_bounds_finds (mapped_index_base
&index
,
4738 const char *search_name
,
4739 gdb::array_view
<const char *> expected_syms
)
4741 lookup_name_info
lookup_name (search_name
,
4742 symbol_name_match_type::FULL
, true);
4744 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4747 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4748 if (distance
!= expected_syms
.size ())
4751 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4753 auto nc_elem
= bounds
.first
+ exp_elem
;
4754 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4755 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4762 /* Test the lower-level mapped_index::find_name_component_bounds
4766 test_mapped_index_find_name_component_bounds ()
4768 mock_mapped_index
mock_index (test_symbols
);
4770 mock_index
.build_name_components ();
4772 /* Test the lower-level mapped_index::find_name_component_bounds
4773 method in completion mode. */
4775 static const char *expected_syms
[] = {
4780 SELF_CHECK (check_find_bounds_finds (mock_index
,
4781 "t1_func", expected_syms
));
4784 /* Check that the increment-last-char in the name matching algorithm
4785 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4787 static const char *expected_syms1
[] = {
4791 SELF_CHECK (check_find_bounds_finds (mock_index
,
4792 "\377", expected_syms1
));
4794 static const char *expected_syms2
[] = {
4797 SELF_CHECK (check_find_bounds_finds (mock_index
,
4798 "\377\377", expected_syms2
));
4802 /* Test dw2_expand_symtabs_matching_symbol. */
4805 test_dw2_expand_symtabs_matching_symbol ()
4807 mock_mapped_index
mock_index (test_symbols
);
4809 /* We let all tests run until the end even if some fails, for debug
4811 bool any_mismatch
= false;
4813 /* Create the expected symbols list (an initializer_list). Needed
4814 because lists have commas, and we need to pass them to CHECK,
4815 which is a macro. */
4816 #define EXPECT(...) { __VA_ARGS__ }
4818 /* Wrapper for check_match that passes down the current
4819 __FILE__/__LINE__. */
4820 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4821 any_mismatch |= !check_match (__FILE__, __LINE__, \
4823 NAME, MATCH_TYPE, COMPLETION_MODE, \
4826 /* Identity checks. */
4827 for (const char *sym
: test_symbols
)
4829 /* Should be able to match all existing symbols. */
4830 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4833 /* Should be able to match all existing symbols with
4835 std::string with_params
= std::string (sym
) + "(int)";
4836 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4839 /* Should be able to match all existing symbols with
4840 parameters and qualifiers. */
4841 with_params
= std::string (sym
) + " ( int ) const";
4842 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4845 /* This should really find sym, but cp-name-parser.y doesn't
4846 know about lvalue/rvalue qualifiers yet. */
4847 with_params
= std::string (sym
) + " ( int ) &&";
4848 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4852 /* Check that the name matching algorithm for completion doesn't get
4853 confused with Latin1 'ÿ' / 0xff. */
4855 static const char str
[] = "\377";
4856 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4857 EXPECT ("\377", "\377\377123"));
4860 /* Check that the increment-last-char in the matching algorithm for
4861 completion doesn't match "t1_fund" when completing "t1_func". */
4863 static const char str
[] = "t1_func";
4864 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4865 EXPECT ("t1_func", "t1_func1"));
4868 /* Check that completion mode works at each prefix of the expected
4871 static const char str
[] = "function(int)";
4872 size_t len
= strlen (str
);
4875 for (size_t i
= 1; i
< len
; i
++)
4877 lookup
.assign (str
, i
);
4878 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4879 EXPECT ("function"));
4883 /* While "w" is a prefix of both components, the match function
4884 should still only be called once. */
4886 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4888 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4892 /* Same, with a "complicated" symbol. */
4894 static const char str
[] = Z_SYM_NAME
;
4895 size_t len
= strlen (str
);
4898 for (size_t i
= 1; i
< len
; i
++)
4900 lookup
.assign (str
, i
);
4901 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4902 EXPECT (Z_SYM_NAME
));
4906 /* In FULL mode, an incomplete symbol doesn't match. */
4908 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4912 /* A complete symbol with parameters matches any overload, since the
4913 index has no overload info. */
4915 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4916 EXPECT ("std::zfunction", "std::zfunction2"));
4917 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4918 EXPECT ("std::zfunction", "std::zfunction2"));
4919 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4920 EXPECT ("std::zfunction", "std::zfunction2"));
4923 /* Check that whitespace is ignored appropriately. A symbol with a
4924 template argument list. */
4926 static const char expected
[] = "ns::foo<int>";
4927 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4929 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4933 /* Check that whitespace is ignored appropriately. A symbol with a
4934 template argument list that includes a pointer. */
4936 static const char expected
[] = "ns::foo<char*>";
4937 /* Try both completion and non-completion modes. */
4938 static const bool completion_mode
[2] = {false, true};
4939 for (size_t i
= 0; i
< 2; i
++)
4941 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4942 completion_mode
[i
], EXPECT (expected
));
4943 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4944 completion_mode
[i
], EXPECT (expected
));
4946 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4947 completion_mode
[i
], EXPECT (expected
));
4948 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4949 completion_mode
[i
], EXPECT (expected
));
4954 /* Check method qualifiers are ignored. */
4955 static const char expected
[] = "ns::foo<char*>";
4956 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4957 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4958 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4959 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4960 CHECK_MATCH ("foo < char * > ( int ) const",
4961 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4962 CHECK_MATCH ("foo < char * > ( int ) &&",
4963 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4966 /* Test lookup names that don't match anything. */
4968 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4971 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4975 /* Some wild matching tests, exercising "(anonymous namespace)",
4976 which should not be confused with a parameter list. */
4978 static const char *syms
[] = {
4982 "A :: B :: C ( int )",
4987 for (const char *s
: syms
)
4989 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4990 EXPECT ("(anonymous namespace)::A::B::C"));
4995 static const char expected
[] = "ns2::tmpl<int>::foo2";
4996 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
4998 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5002 SELF_CHECK (!any_mismatch
);
5011 test_mapped_index_find_name_component_bounds ();
5012 test_dw2_expand_symtabs_matching_symbol ();
5015 }} // namespace selftests::dw2_expand_symtabs_matching
5017 #endif /* GDB_SELF_TEST */
5019 /* If FILE_MATCHER is NULL or if PER_CU has
5020 dwarf2_per_cu_quick_data::MARK set (see
5021 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5022 EXPANSION_NOTIFY on it. */
5025 dw2_expand_symtabs_matching_one
5026 (struct dwarf2_per_cu_data
*per_cu
,
5027 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5028 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5030 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5032 bool symtab_was_null
5033 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5035 dw2_instantiate_symtab (per_cu
, false);
5037 if (expansion_notify
!= NULL
5039 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5040 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5044 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5045 matched, to expand corresponding CUs that were marked. IDX is the
5046 index of the symbol name that matched. */
5049 dw2_expand_marked_cus
5050 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5051 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5052 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5055 offset_type
*vec
, vec_len
, vec_idx
;
5056 bool global_seen
= false;
5057 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5059 vec
= (offset_type
*) (index
.constant_pool
5060 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5061 vec_len
= MAYBE_SWAP (vec
[0]);
5062 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5064 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5065 /* This value is only valid for index versions >= 7. */
5066 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5067 gdb_index_symbol_kind symbol_kind
=
5068 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5069 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5070 /* Only check the symbol attributes if they're present.
5071 Indices prior to version 7 don't record them,
5072 and indices >= 7 may elide them for certain symbols
5073 (gold does this). */
5076 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5078 /* Work around gold/15646. */
5081 if (!is_static
&& global_seen
)
5087 /* Only check the symbol's kind if it has one. */
5092 case VARIABLES_DOMAIN
:
5093 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5096 case FUNCTIONS_DOMAIN
:
5097 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5101 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5104 case MODULES_DOMAIN
:
5105 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5113 /* Don't crash on bad data. */
5114 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5115 + dwarf2_per_objfile
->all_type_units
.size ()))
5117 complaint (_(".gdb_index entry has bad CU index"
5119 objfile_name (dwarf2_per_objfile
->objfile
));
5123 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5124 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5129 /* If FILE_MATCHER is non-NULL, set all the
5130 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5131 that match FILE_MATCHER. */
5134 dw_expand_symtabs_matching_file_matcher
5135 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5136 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5138 if (file_matcher
== NULL
)
5141 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5143 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5145 NULL
, xcalloc
, xfree
));
5146 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5148 NULL
, xcalloc
, xfree
));
5150 /* The rule is CUs specify all the files, including those used by
5151 any TU, so there's no need to scan TUs here. */
5153 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5157 per_cu
->v
.quick
->mark
= 0;
5159 /* We only need to look at symtabs not already expanded. */
5160 if (per_cu
->v
.quick
->compunit_symtab
)
5163 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5164 if (file_data
== NULL
)
5167 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5169 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5171 per_cu
->v
.quick
->mark
= 1;
5175 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5177 const char *this_real_name
;
5179 if (file_matcher (file_data
->file_names
[j
], false))
5181 per_cu
->v
.quick
->mark
= 1;
5185 /* Before we invoke realpath, which can get expensive when many
5186 files are involved, do a quick comparison of the basenames. */
5187 if (!basenames_may_differ
5188 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5192 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5193 if (file_matcher (this_real_name
, false))
5195 per_cu
->v
.quick
->mark
= 1;
5200 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5201 ? visited_found
.get ()
5202 : visited_not_found
.get (),
5209 dw2_expand_symtabs_matching
5210 (struct objfile
*objfile
,
5211 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5212 const lookup_name_info
&lookup_name
,
5213 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5214 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5215 enum search_domain kind
)
5217 struct dwarf2_per_objfile
*dwarf2_per_objfile
5218 = get_dwarf2_per_objfile (objfile
);
5220 /* index_table is NULL if OBJF_READNOW. */
5221 if (!dwarf2_per_objfile
->index_table
)
5224 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5226 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5228 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5230 kind
, [&] (offset_type idx
)
5232 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5233 expansion_notify
, kind
);
5238 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5241 static struct compunit_symtab
*
5242 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5247 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5248 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5251 if (cust
->includes
== NULL
)
5254 for (i
= 0; cust
->includes
[i
]; ++i
)
5256 struct compunit_symtab
*s
= cust
->includes
[i
];
5258 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5266 static struct compunit_symtab
*
5267 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5268 struct bound_minimal_symbol msymbol
,
5270 struct obj_section
*section
,
5273 struct dwarf2_per_cu_data
*data
;
5274 struct compunit_symtab
*result
;
5276 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5279 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5280 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5281 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5285 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5286 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5287 paddress (get_objfile_arch (objfile
), pc
));
5290 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5293 gdb_assert (result
!= NULL
);
5298 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5299 void *data
, int need_fullname
)
5301 struct dwarf2_per_objfile
*dwarf2_per_objfile
5302 = get_dwarf2_per_objfile (objfile
);
5304 if (!dwarf2_per_objfile
->filenames_cache
)
5306 dwarf2_per_objfile
->filenames_cache
.emplace ();
5308 htab_up
visited (htab_create_alloc (10,
5309 htab_hash_pointer
, htab_eq_pointer
,
5310 NULL
, xcalloc
, xfree
));
5312 /* The rule is CUs specify all the files, including those used
5313 by any TU, so there's no need to scan TUs here. We can
5314 ignore file names coming from already-expanded CUs. */
5316 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5318 if (per_cu
->v
.quick
->compunit_symtab
)
5320 void **slot
= htab_find_slot (visited
.get (),
5321 per_cu
->v
.quick
->file_names
,
5324 *slot
= per_cu
->v
.quick
->file_names
;
5328 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5330 /* We only need to look at symtabs not already expanded. */
5331 if (per_cu
->v
.quick
->compunit_symtab
)
5334 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5335 if (file_data
== NULL
)
5338 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5341 /* Already visited. */
5346 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5348 const char *filename
= file_data
->file_names
[j
];
5349 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5354 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5356 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5359 this_real_name
= gdb_realpath (filename
);
5360 (*fun
) (filename
, this_real_name
.get (), data
);
5365 dw2_has_symbols (struct objfile
*objfile
)
5370 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5373 dw2_find_last_source_symtab
,
5374 dw2_forget_cached_source_info
,
5375 dw2_map_symtabs_matching_filename
,
5379 dw2_expand_symtabs_for_function
,
5380 dw2_expand_all_symtabs
,
5381 dw2_expand_symtabs_with_fullname
,
5382 dw2_map_matching_symbols
,
5383 dw2_expand_symtabs_matching
,
5384 dw2_find_pc_sect_compunit_symtab
,
5386 dw2_map_symbol_filenames
5389 /* DWARF-5 debug_names reader. */
5391 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5392 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5394 /* A helper function that reads the .debug_names section in SECTION
5395 and fills in MAP. FILENAME is the name of the file containing the
5396 section; it is used for error reporting.
5398 Returns true if all went well, false otherwise. */
5401 read_debug_names_from_section (struct objfile
*objfile
,
5402 const char *filename
,
5403 struct dwarf2_section_info
*section
,
5404 mapped_debug_names
&map
)
5406 if (dwarf2_section_empty_p (section
))
5409 /* Older elfutils strip versions could keep the section in the main
5410 executable while splitting it for the separate debug info file. */
5411 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5414 dwarf2_read_section (objfile
, section
);
5416 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5418 const gdb_byte
*addr
= section
->buffer
;
5420 bfd
*const abfd
= get_section_bfd_owner (section
);
5422 unsigned int bytes_read
;
5423 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5426 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5427 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5428 if (bytes_read
+ length
!= section
->size
)
5430 /* There may be multiple per-CU indices. */
5431 warning (_("Section .debug_names in %s length %s does not match "
5432 "section length %s, ignoring .debug_names."),
5433 filename
, plongest (bytes_read
+ length
),
5434 pulongest (section
->size
));
5438 /* The version number. */
5439 uint16_t version
= read_2_bytes (abfd
, addr
);
5443 warning (_("Section .debug_names in %s has unsupported version %d, "
5444 "ignoring .debug_names."),
5450 uint16_t padding
= read_2_bytes (abfd
, addr
);
5454 warning (_("Section .debug_names in %s has unsupported padding %d, "
5455 "ignoring .debug_names."),
5460 /* comp_unit_count - The number of CUs in the CU list. */
5461 map
.cu_count
= read_4_bytes (abfd
, addr
);
5464 /* local_type_unit_count - The number of TUs in the local TU
5466 map
.tu_count
= read_4_bytes (abfd
, addr
);
5469 /* foreign_type_unit_count - The number of TUs in the foreign TU
5471 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5473 if (foreign_tu_count
!= 0)
5475 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5476 "ignoring .debug_names."),
5477 filename
, static_cast<unsigned long> (foreign_tu_count
));
5481 /* bucket_count - The number of hash buckets in the hash lookup
5483 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5486 /* name_count - The number of unique names in the index. */
5487 map
.name_count
= read_4_bytes (abfd
, addr
);
5490 /* abbrev_table_size - The size in bytes of the abbreviations
5492 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5495 /* augmentation_string_size - The size in bytes of the augmentation
5496 string. This value is rounded up to a multiple of 4. */
5497 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5499 map
.augmentation_is_gdb
= ((augmentation_string_size
5500 == sizeof (dwarf5_augmentation
))
5501 && memcmp (addr
, dwarf5_augmentation
,
5502 sizeof (dwarf5_augmentation
)) == 0);
5503 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5504 addr
+= augmentation_string_size
;
5507 map
.cu_table_reordered
= addr
;
5508 addr
+= map
.cu_count
* map
.offset_size
;
5510 /* List of Local TUs */
5511 map
.tu_table_reordered
= addr
;
5512 addr
+= map
.tu_count
* map
.offset_size
;
5514 /* Hash Lookup Table */
5515 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5516 addr
+= map
.bucket_count
* 4;
5517 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5518 addr
+= map
.name_count
* 4;
5521 map
.name_table_string_offs_reordered
= addr
;
5522 addr
+= map
.name_count
* map
.offset_size
;
5523 map
.name_table_entry_offs_reordered
= addr
;
5524 addr
+= map
.name_count
* map
.offset_size
;
5526 const gdb_byte
*abbrev_table_start
= addr
;
5529 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5534 const auto insertpair
5535 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5536 if (!insertpair
.second
)
5538 warning (_("Section .debug_names in %s has duplicate index %s, "
5539 "ignoring .debug_names."),
5540 filename
, pulongest (index_num
));
5543 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5544 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5549 mapped_debug_names::index_val::attr attr
;
5550 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5552 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5554 if (attr
.form
== DW_FORM_implicit_const
)
5556 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5560 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5562 indexval
.attr_vec
.push_back (std::move (attr
));
5565 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5567 warning (_("Section .debug_names in %s has abbreviation_table "
5568 "of size %s vs. written as %u, ignoring .debug_names."),
5569 filename
, plongest (addr
- abbrev_table_start
),
5573 map
.entry_pool
= addr
;
5578 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5582 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5583 const mapped_debug_names
&map
,
5584 dwarf2_section_info
§ion
,
5587 sect_offset sect_off_prev
;
5588 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5590 sect_offset sect_off_next
;
5591 if (i
< map
.cu_count
)
5594 = (sect_offset
) (extract_unsigned_integer
5595 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5597 map
.dwarf5_byte_order
));
5600 sect_off_next
= (sect_offset
) section
.size
;
5603 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5604 dwarf2_per_cu_data
*per_cu
5605 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5606 sect_off_prev
, length
);
5607 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5609 sect_off_prev
= sect_off_next
;
5613 /* Read the CU list from the mapped index, and use it to create all
5614 the CU objects for this dwarf2_per_objfile. */
5617 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5618 const mapped_debug_names
&map
,
5619 const mapped_debug_names
&dwz_map
)
5621 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5622 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5624 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5625 dwarf2_per_objfile
->info
,
5626 false /* is_dwz */);
5628 if (dwz_map
.cu_count
== 0)
5631 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5632 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5636 /* Read .debug_names. If everything went ok, initialize the "quick"
5637 elements of all the CUs and return true. Otherwise, return false. */
5640 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5642 std::unique_ptr
<mapped_debug_names
> map
5643 (new mapped_debug_names (dwarf2_per_objfile
));
5644 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5645 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5647 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5648 &dwarf2_per_objfile
->debug_names
,
5652 /* Don't use the index if it's empty. */
5653 if (map
->name_count
== 0)
5656 /* If there is a .dwz file, read it so we can get its CU list as
5658 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5661 if (!read_debug_names_from_section (objfile
,
5662 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5663 &dwz
->debug_names
, dwz_map
))
5665 warning (_("could not read '.debug_names' section from %s; skipping"),
5666 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5671 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5673 if (map
->tu_count
!= 0)
5675 /* We can only handle a single .debug_types when we have an
5677 if (dwarf2_per_objfile
->types
.size () != 1)
5680 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5682 create_signatured_type_table_from_debug_names
5683 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5686 create_addrmap_from_aranges (dwarf2_per_objfile
,
5687 &dwarf2_per_objfile
->debug_aranges
);
5689 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5690 dwarf2_per_objfile
->using_index
= 1;
5691 dwarf2_per_objfile
->quick_file_names_table
=
5692 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5697 /* Type used to manage iterating over all CUs looking for a symbol for
5700 class dw2_debug_names_iterator
5703 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5704 gdb::optional
<block_enum
> block_index
,
5707 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5708 m_addr (find_vec_in_debug_names (map
, name
))
5711 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5712 search_domain search
, uint32_t namei
)
5715 m_addr (find_vec_in_debug_names (map
, namei
))
5718 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5719 block_enum block_index
, domain_enum domain
,
5721 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5722 m_addr (find_vec_in_debug_names (map
, namei
))
5725 /* Return the next matching CU or NULL if there are no more. */
5726 dwarf2_per_cu_data
*next ();
5729 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5731 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5734 /* The internalized form of .debug_names. */
5735 const mapped_debug_names
&m_map
;
5737 /* If set, only look for symbols that match that block. Valid values are
5738 GLOBAL_BLOCK and STATIC_BLOCK. */
5739 const gdb::optional
<block_enum
> m_block_index
;
5741 /* The kind of symbol we're looking for. */
5742 const domain_enum m_domain
= UNDEF_DOMAIN
;
5743 const search_domain m_search
= ALL_DOMAIN
;
5745 /* The list of CUs from the index entry of the symbol, or NULL if
5747 const gdb_byte
*m_addr
;
5751 mapped_debug_names::namei_to_name (uint32_t namei
) const
5753 const ULONGEST namei_string_offs
5754 = extract_unsigned_integer ((name_table_string_offs_reordered
5755 + namei
* offset_size
),
5758 return read_indirect_string_at_offset
5759 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5762 /* Find a slot in .debug_names for the object named NAME. If NAME is
5763 found, return pointer to its pool data. If NAME cannot be found,
5767 dw2_debug_names_iterator::find_vec_in_debug_names
5768 (const mapped_debug_names
&map
, const char *name
)
5770 int (*cmp
) (const char *, const char *);
5772 gdb::unique_xmalloc_ptr
<char> without_params
;
5773 if (current_language
->la_language
== language_cplus
5774 || current_language
->la_language
== language_fortran
5775 || current_language
->la_language
== language_d
)
5777 /* NAME is already canonical. Drop any qualifiers as
5778 .debug_names does not contain any. */
5780 if (strchr (name
, '(') != NULL
)
5782 without_params
= cp_remove_params (name
);
5783 if (without_params
!= NULL
)
5784 name
= without_params
.get ();
5788 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5790 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5792 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5793 (map
.bucket_table_reordered
5794 + (full_hash
% map
.bucket_count
)), 4,
5795 map
.dwarf5_byte_order
);
5799 if (namei
>= map
.name_count
)
5801 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5803 namei
, map
.name_count
,
5804 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5810 const uint32_t namei_full_hash
5811 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5812 (map
.hash_table_reordered
+ namei
), 4,
5813 map
.dwarf5_byte_order
);
5814 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5817 if (full_hash
== namei_full_hash
)
5819 const char *const namei_string
= map
.namei_to_name (namei
);
5821 #if 0 /* An expensive sanity check. */
5822 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5824 complaint (_("Wrong .debug_names hash for string at index %u "
5826 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5831 if (cmp (namei_string
, name
) == 0)
5833 const ULONGEST namei_entry_offs
5834 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5835 + namei
* map
.offset_size
),
5836 map
.offset_size
, map
.dwarf5_byte_order
);
5837 return map
.entry_pool
+ namei_entry_offs
;
5842 if (namei
>= map
.name_count
)
5848 dw2_debug_names_iterator::find_vec_in_debug_names
5849 (const mapped_debug_names
&map
, uint32_t namei
)
5851 if (namei
>= map
.name_count
)
5853 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5855 namei
, map
.name_count
,
5856 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5860 const ULONGEST namei_entry_offs
5861 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5862 + namei
* map
.offset_size
),
5863 map
.offset_size
, map
.dwarf5_byte_order
);
5864 return map
.entry_pool
+ namei_entry_offs
;
5867 /* See dw2_debug_names_iterator. */
5869 dwarf2_per_cu_data
*
5870 dw2_debug_names_iterator::next ()
5875 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5876 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5877 bfd
*const abfd
= objfile
->obfd
;
5881 unsigned int bytes_read
;
5882 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5883 m_addr
+= bytes_read
;
5887 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5888 if (indexval_it
== m_map
.abbrev_map
.cend ())
5890 complaint (_("Wrong .debug_names undefined abbrev code %s "
5892 pulongest (abbrev
), objfile_name (objfile
));
5895 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5896 enum class symbol_linkage
{
5900 } symbol_linkage_
= symbol_linkage::unknown
;
5901 dwarf2_per_cu_data
*per_cu
= NULL
;
5902 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5907 case DW_FORM_implicit_const
:
5908 ull
= attr
.implicit_const
;
5910 case DW_FORM_flag_present
:
5914 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5915 m_addr
+= bytes_read
;
5918 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5919 dwarf_form_name (attr
.form
),
5920 objfile_name (objfile
));
5923 switch (attr
.dw_idx
)
5925 case DW_IDX_compile_unit
:
5926 /* Don't crash on bad data. */
5927 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5929 complaint (_(".debug_names entry has bad CU index %s"
5932 objfile_name (dwarf2_per_objfile
->objfile
));
5935 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5937 case DW_IDX_type_unit
:
5938 /* Don't crash on bad data. */
5939 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5941 complaint (_(".debug_names entry has bad TU index %s"
5944 objfile_name (dwarf2_per_objfile
->objfile
));
5947 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5949 case DW_IDX_GNU_internal
:
5950 if (!m_map
.augmentation_is_gdb
)
5952 symbol_linkage_
= symbol_linkage::static_
;
5954 case DW_IDX_GNU_external
:
5955 if (!m_map
.augmentation_is_gdb
)
5957 symbol_linkage_
= symbol_linkage::extern_
;
5962 /* Skip if already read in. */
5963 if (per_cu
->v
.quick
->compunit_symtab
)
5966 /* Check static vs global. */
5967 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5969 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5970 const bool symbol_is_static
=
5971 symbol_linkage_
== symbol_linkage::static_
;
5972 if (want_static
!= symbol_is_static
)
5976 /* Match dw2_symtab_iter_next, symbol_kind
5977 and debug_names::psymbol_tag. */
5981 switch (indexval
.dwarf_tag
)
5983 case DW_TAG_variable
:
5984 case DW_TAG_subprogram
:
5985 /* Some types are also in VAR_DOMAIN. */
5986 case DW_TAG_typedef
:
5987 case DW_TAG_structure_type
:
5994 switch (indexval
.dwarf_tag
)
5996 case DW_TAG_typedef
:
5997 case DW_TAG_structure_type
:
6004 switch (indexval
.dwarf_tag
)
6007 case DW_TAG_variable
:
6014 switch (indexval
.dwarf_tag
)
6026 /* Match dw2_expand_symtabs_matching, symbol_kind and
6027 debug_names::psymbol_tag. */
6030 case VARIABLES_DOMAIN
:
6031 switch (indexval
.dwarf_tag
)
6033 case DW_TAG_variable
:
6039 case FUNCTIONS_DOMAIN
:
6040 switch (indexval
.dwarf_tag
)
6042 case DW_TAG_subprogram
:
6049 switch (indexval
.dwarf_tag
)
6051 case DW_TAG_typedef
:
6052 case DW_TAG_structure_type
:
6058 case MODULES_DOMAIN
:
6059 switch (indexval
.dwarf_tag
)
6073 static struct compunit_symtab
*
6074 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6075 const char *name
, domain_enum domain
)
6077 struct dwarf2_per_objfile
*dwarf2_per_objfile
6078 = get_dwarf2_per_objfile (objfile
);
6080 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6083 /* index is NULL if OBJF_READNOW. */
6086 const auto &map
= *mapp
;
6088 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6090 struct compunit_symtab
*stab_best
= NULL
;
6091 struct dwarf2_per_cu_data
*per_cu
;
6092 while ((per_cu
= iter
.next ()) != NULL
)
6094 struct symbol
*sym
, *with_opaque
= NULL
;
6095 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6096 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6097 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6099 sym
= block_find_symbol (block
, name
, domain
,
6100 block_find_non_opaque_type_preferred
,
6103 /* Some caution must be observed with overloaded functions and
6104 methods, since the index will not contain any overload
6105 information (but NAME might contain it). */
6108 && strcmp_iw (sym
->search_name (), name
) == 0)
6110 if (with_opaque
!= NULL
6111 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6114 /* Keep looking through other CUs. */
6120 /* This dumps minimal information about .debug_names. It is called
6121 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6122 uses this to verify that .debug_names has been loaded. */
6125 dw2_debug_names_dump (struct objfile
*objfile
)
6127 struct dwarf2_per_objfile
*dwarf2_per_objfile
6128 = get_dwarf2_per_objfile (objfile
);
6130 gdb_assert (dwarf2_per_objfile
->using_index
);
6131 printf_filtered (".debug_names:");
6132 if (dwarf2_per_objfile
->debug_names_table
)
6133 printf_filtered (" exists\n");
6135 printf_filtered (" faked for \"readnow\"\n");
6136 printf_filtered ("\n");
6140 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6141 const char *func_name
)
6143 struct dwarf2_per_objfile
*dwarf2_per_objfile
6144 = get_dwarf2_per_objfile (objfile
);
6146 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6147 if (dwarf2_per_objfile
->debug_names_table
)
6149 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6151 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6153 struct dwarf2_per_cu_data
*per_cu
;
6154 while ((per_cu
= iter
.next ()) != NULL
)
6155 dw2_instantiate_symtab (per_cu
, false);
6160 dw2_debug_names_map_matching_symbols
6161 (struct objfile
*objfile
,
6162 const lookup_name_info
&name
, domain_enum domain
,
6164 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6165 symbol_compare_ftype
*ordered_compare
)
6167 struct dwarf2_per_objfile
*dwarf2_per_objfile
6168 = get_dwarf2_per_objfile (objfile
);
6170 /* debug_names_table is NULL if OBJF_READNOW. */
6171 if (!dwarf2_per_objfile
->debug_names_table
)
6174 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6175 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6177 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6178 auto matcher
= [&] (const char *symname
)
6180 if (ordered_compare
== nullptr)
6182 return ordered_compare (symname
, match_name
) == 0;
6185 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6186 [&] (offset_type namei
)
6188 /* The name was matched, now expand corresponding CUs that were
6190 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6192 struct dwarf2_per_cu_data
*per_cu
;
6193 while ((per_cu
= iter
.next ()) != NULL
)
6194 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6198 /* It's a shame we couldn't do this inside the
6199 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6200 that have already been expanded. Instead, this loop matches what
6201 the psymtab code does. */
6202 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6204 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6205 if (cust
!= nullptr)
6207 const struct block
*block
6208 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6209 if (!iterate_over_symbols_terminated (block
, name
,
6217 dw2_debug_names_expand_symtabs_matching
6218 (struct objfile
*objfile
,
6219 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6220 const lookup_name_info
&lookup_name
,
6221 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6222 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6223 enum search_domain kind
)
6225 struct dwarf2_per_objfile
*dwarf2_per_objfile
6226 = get_dwarf2_per_objfile (objfile
);
6228 /* debug_names_table is NULL if OBJF_READNOW. */
6229 if (!dwarf2_per_objfile
->debug_names_table
)
6232 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6234 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6236 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6238 kind
, [&] (offset_type namei
)
6240 /* The name was matched, now expand corresponding CUs that were
6242 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6244 struct dwarf2_per_cu_data
*per_cu
;
6245 while ((per_cu
= iter
.next ()) != NULL
)
6246 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6252 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6255 dw2_find_last_source_symtab
,
6256 dw2_forget_cached_source_info
,
6257 dw2_map_symtabs_matching_filename
,
6258 dw2_debug_names_lookup_symbol
,
6260 dw2_debug_names_dump
,
6261 dw2_debug_names_expand_symtabs_for_function
,
6262 dw2_expand_all_symtabs
,
6263 dw2_expand_symtabs_with_fullname
,
6264 dw2_debug_names_map_matching_symbols
,
6265 dw2_debug_names_expand_symtabs_matching
,
6266 dw2_find_pc_sect_compunit_symtab
,
6268 dw2_map_symbol_filenames
6271 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6272 to either a dwarf2_per_objfile or dwz_file object. */
6274 template <typename T
>
6275 static gdb::array_view
<const gdb_byte
>
6276 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6278 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6280 if (dwarf2_section_empty_p (section
))
6283 /* Older elfutils strip versions could keep the section in the main
6284 executable while splitting it for the separate debug info file. */
6285 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6288 dwarf2_read_section (obj
, section
);
6290 /* dwarf2_section_info::size is a bfd_size_type, while
6291 gdb::array_view works with size_t. On 32-bit hosts, with
6292 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6293 is 32-bit. So we need an explicit narrowing conversion here.
6294 This is fine, because it's impossible to allocate or mmap an
6295 array/buffer larger than what size_t can represent. */
6296 return gdb::make_array_view (section
->buffer
, section
->size
);
6299 /* Lookup the index cache for the contents of the index associated to
6302 static gdb::array_view
<const gdb_byte
>
6303 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6305 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6306 if (build_id
== nullptr)
6309 return global_index_cache
.lookup_gdb_index (build_id
,
6310 &dwarf2_obj
->index_cache_res
);
6313 /* Same as the above, but for DWZ. */
6315 static gdb::array_view
<const gdb_byte
>
6316 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6318 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6319 if (build_id
== nullptr)
6322 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6325 /* See symfile.h. */
6328 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6330 struct dwarf2_per_objfile
*dwarf2_per_objfile
6331 = get_dwarf2_per_objfile (objfile
);
6333 /* If we're about to read full symbols, don't bother with the
6334 indices. In this case we also don't care if some other debug
6335 format is making psymtabs, because they are all about to be
6337 if ((objfile
->flags
& OBJF_READNOW
))
6339 dwarf2_per_objfile
->using_index
= 1;
6340 create_all_comp_units (dwarf2_per_objfile
);
6341 create_all_type_units (dwarf2_per_objfile
);
6342 dwarf2_per_objfile
->quick_file_names_table
6343 = create_quick_file_names_table
6344 (dwarf2_per_objfile
->all_comp_units
.size ());
6346 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6347 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6349 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6351 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6352 struct dwarf2_per_cu_quick_data
);
6355 /* Return 1 so that gdb sees the "quick" functions. However,
6356 these functions will be no-ops because we will have expanded
6358 *index_kind
= dw_index_kind::GDB_INDEX
;
6362 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6364 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6368 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6369 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6370 get_gdb_index_contents_from_section
<dwz_file
>))
6372 *index_kind
= dw_index_kind::GDB_INDEX
;
6376 /* ... otherwise, try to find the index in the index cache. */
6377 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6378 get_gdb_index_contents_from_cache
,
6379 get_gdb_index_contents_from_cache_dwz
))
6381 global_index_cache
.hit ();
6382 *index_kind
= dw_index_kind::GDB_INDEX
;
6386 global_index_cache
.miss ();
6392 /* Build a partial symbol table. */
6395 dwarf2_build_psymtabs (struct objfile
*objfile
)
6397 struct dwarf2_per_objfile
*dwarf2_per_objfile
6398 = get_dwarf2_per_objfile (objfile
);
6400 init_psymbol_list (objfile
, 1024);
6404 /* This isn't really ideal: all the data we allocate on the
6405 objfile's obstack is still uselessly kept around. However,
6406 freeing it seems unsafe. */
6407 psymtab_discarder
psymtabs (objfile
);
6408 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6411 /* (maybe) store an index in the cache. */
6412 global_index_cache
.store (dwarf2_per_objfile
);
6414 catch (const gdb_exception_error
&except
)
6416 exception_print (gdb_stderr
, except
);
6420 /* Return the total length of the CU described by HEADER. */
6423 get_cu_length (const struct comp_unit_head
*header
)
6425 return header
->initial_length_size
+ header
->length
;
6428 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6431 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6433 sect_offset bottom
= cu_header
->sect_off
;
6434 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6436 return sect_off
>= bottom
&& sect_off
< top
;
6439 /* Find the base address of the compilation unit for range lists and
6440 location lists. It will normally be specified by DW_AT_low_pc.
6441 In DWARF-3 draft 4, the base address could be overridden by
6442 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6443 compilation units with discontinuous ranges. */
6446 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6448 struct attribute
*attr
;
6451 cu
->base_address
= 0;
6453 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6454 if (attr
!= nullptr)
6456 cu
->base_address
= attr_value_as_address (attr
);
6461 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6462 if (attr
!= nullptr)
6464 cu
->base_address
= attr_value_as_address (attr
);
6470 /* Read in the comp unit header information from the debug_info at info_ptr.
6471 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6472 NOTE: This leaves members offset, first_die_offset to be filled in
6475 static const gdb_byte
*
6476 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6477 const gdb_byte
*info_ptr
,
6478 struct dwarf2_section_info
*section
,
6479 rcuh_kind section_kind
)
6482 unsigned int bytes_read
;
6483 const char *filename
= get_section_file_name (section
);
6484 bfd
*abfd
= get_section_bfd_owner (section
);
6486 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6487 cu_header
->initial_length_size
= bytes_read
;
6488 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6489 info_ptr
+= bytes_read
;
6490 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6491 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6492 error (_("Dwarf Error: wrong version in compilation unit header "
6493 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6494 cu_header
->version
, filename
);
6496 if (cu_header
->version
< 5)
6497 switch (section_kind
)
6499 case rcuh_kind::COMPILE
:
6500 cu_header
->unit_type
= DW_UT_compile
;
6502 case rcuh_kind::TYPE
:
6503 cu_header
->unit_type
= DW_UT_type
;
6506 internal_error (__FILE__
, __LINE__
,
6507 _("read_comp_unit_head: invalid section_kind"));
6511 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6512 (read_1_byte (abfd
, info_ptr
));
6514 switch (cu_header
->unit_type
)
6518 case DW_UT_skeleton
:
6519 case DW_UT_split_compile
:
6520 if (section_kind
!= rcuh_kind::COMPILE
)
6521 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6522 "(is %s, should be %s) [in module %s]"),
6523 dwarf_unit_type_name (cu_header
->unit_type
),
6524 dwarf_unit_type_name (DW_UT_type
), filename
);
6527 case DW_UT_split_type
:
6528 section_kind
= rcuh_kind::TYPE
;
6531 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6532 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6533 "[in module %s]"), cu_header
->unit_type
,
6534 dwarf_unit_type_name (DW_UT_compile
),
6535 dwarf_unit_type_name (DW_UT_skeleton
),
6536 dwarf_unit_type_name (DW_UT_split_compile
),
6537 dwarf_unit_type_name (DW_UT_type
),
6538 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6541 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6544 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6547 info_ptr
+= bytes_read
;
6548 if (cu_header
->version
< 5)
6550 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6553 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6554 if (signed_addr
< 0)
6555 internal_error (__FILE__
, __LINE__
,
6556 _("read_comp_unit_head: dwarf from non elf file"));
6557 cu_header
->signed_addr_p
= signed_addr
;
6559 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6560 || cu_header
->unit_type
== DW_UT_skeleton
6561 || cu_header
->unit_type
== DW_UT_split_compile
;
6563 if (header_has_signature
)
6565 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6569 if (section_kind
== rcuh_kind::TYPE
)
6571 LONGEST type_offset
;
6572 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6573 info_ptr
+= bytes_read
;
6574 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6575 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6576 error (_("Dwarf Error: Too big type_offset in compilation unit "
6577 "header (is %s) [in module %s]"), plongest (type_offset
),
6584 /* Helper function that returns the proper abbrev section for
6587 static struct dwarf2_section_info
*
6588 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6590 struct dwarf2_section_info
*abbrev
;
6591 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6593 if (this_cu
->is_dwz
)
6594 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6596 abbrev
= &dwarf2_per_objfile
->abbrev
;
6601 /* Subroutine of read_and_check_comp_unit_head and
6602 read_and_check_type_unit_head to simplify them.
6603 Perform various error checking on the header. */
6606 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6607 struct comp_unit_head
*header
,
6608 struct dwarf2_section_info
*section
,
6609 struct dwarf2_section_info
*abbrev_section
)
6611 const char *filename
= get_section_file_name (section
);
6613 if (to_underlying (header
->abbrev_sect_off
)
6614 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6615 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6616 "(offset %s + 6) [in module %s]"),
6617 sect_offset_str (header
->abbrev_sect_off
),
6618 sect_offset_str (header
->sect_off
),
6621 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6622 avoid potential 32-bit overflow. */
6623 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6625 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6626 "(offset %s + 0) [in module %s]"),
6627 header
->length
, sect_offset_str (header
->sect_off
),
6631 /* Read in a CU/TU header and perform some basic error checking.
6632 The contents of the header are stored in HEADER.
6633 The result is a pointer to the start of the first DIE. */
6635 static const gdb_byte
*
6636 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6637 struct comp_unit_head
*header
,
6638 struct dwarf2_section_info
*section
,
6639 struct dwarf2_section_info
*abbrev_section
,
6640 const gdb_byte
*info_ptr
,
6641 rcuh_kind section_kind
)
6643 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6645 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6647 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6649 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6651 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6657 /* Fetch the abbreviation table offset from a comp or type unit header. */
6660 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6661 struct dwarf2_section_info
*section
,
6662 sect_offset sect_off
)
6664 bfd
*abfd
= get_section_bfd_owner (section
);
6665 const gdb_byte
*info_ptr
;
6666 unsigned int initial_length_size
, offset_size
;
6669 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6670 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6671 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6672 offset_size
= initial_length_size
== 4 ? 4 : 8;
6673 info_ptr
+= initial_length_size
;
6675 version
= read_2_bytes (abfd
, info_ptr
);
6679 /* Skip unit type and address size. */
6683 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6686 /* Allocate a new partial symtab for file named NAME and mark this new
6687 partial symtab as being an include of PST. */
6690 dwarf2_create_include_psymtab (const char *name
, dwarf2_psymtab
*pst
,
6691 struct objfile
*objfile
)
6693 dwarf2_psymtab
*subpst
= new dwarf2_psymtab (name
, objfile
);
6695 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6697 /* It shares objfile->objfile_obstack. */
6698 subpst
->dirname
= pst
->dirname
;
6701 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6702 subpst
->dependencies
[0] = pst
;
6703 subpst
->number_of_dependencies
= 1;
6705 /* No private part is necessary for include psymtabs. This property
6706 can be used to differentiate between such include psymtabs and
6707 the regular ones. */
6708 subpst
->per_cu_data
= nullptr;
6711 /* Read the Line Number Program data and extract the list of files
6712 included by the source file represented by PST. Build an include
6713 partial symtab for each of these included files. */
6716 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6717 struct die_info
*die
,
6718 dwarf2_psymtab
*pst
)
6721 struct attribute
*attr
;
6723 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6724 if (attr
!= nullptr)
6725 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6727 return; /* No linetable, so no includes. */
6729 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6730 that we pass in the raw text_low here; that is ok because we're
6731 only decoding the line table to make include partial symtabs, and
6732 so the addresses aren't really used. */
6733 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6734 pst
->raw_text_low (), 1);
6738 hash_signatured_type (const void *item
)
6740 const struct signatured_type
*sig_type
6741 = (const struct signatured_type
*) item
;
6743 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6744 return sig_type
->signature
;
6748 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6750 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6751 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6753 return lhs
->signature
== rhs
->signature
;
6756 /* Allocate a hash table for signatured types. */
6759 allocate_signatured_type_table (struct objfile
*objfile
)
6761 return htab_create_alloc_ex (41,
6762 hash_signatured_type
,
6765 &objfile
->objfile_obstack
,
6766 hashtab_obstack_allocate
,
6767 dummy_obstack_deallocate
);
6770 /* A helper function to add a signatured type CU to a table. */
6773 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6775 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6776 std::vector
<signatured_type
*> *all_type_units
6777 = (std::vector
<signatured_type
*> *) datum
;
6779 all_type_units
->push_back (sigt
);
6784 /* A helper for create_debug_types_hash_table. Read types from SECTION
6785 and fill them into TYPES_HTAB. It will process only type units,
6786 therefore DW_UT_type. */
6789 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6790 struct dwo_file
*dwo_file
,
6791 dwarf2_section_info
*section
, htab_t
&types_htab
,
6792 rcuh_kind section_kind
)
6794 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6795 struct dwarf2_section_info
*abbrev_section
;
6797 const gdb_byte
*info_ptr
, *end_ptr
;
6799 abbrev_section
= (dwo_file
!= NULL
6800 ? &dwo_file
->sections
.abbrev
6801 : &dwarf2_per_objfile
->abbrev
);
6803 if (dwarf_read_debug
)
6804 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6805 get_section_name (section
),
6806 get_section_file_name (abbrev_section
));
6808 dwarf2_read_section (objfile
, section
);
6809 info_ptr
= section
->buffer
;
6811 if (info_ptr
== NULL
)
6814 /* We can't set abfd until now because the section may be empty or
6815 not present, in which case the bfd is unknown. */
6816 abfd
= get_section_bfd_owner (section
);
6818 /* We don't use cutu_reader here because we don't need to read
6819 any dies: the signature is in the header. */
6821 end_ptr
= info_ptr
+ section
->size
;
6822 while (info_ptr
< end_ptr
)
6824 struct signatured_type
*sig_type
;
6825 struct dwo_unit
*dwo_tu
;
6827 const gdb_byte
*ptr
= info_ptr
;
6828 struct comp_unit_head header
;
6829 unsigned int length
;
6831 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6833 /* Initialize it due to a false compiler warning. */
6834 header
.signature
= -1;
6835 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6837 /* We need to read the type's signature in order to build the hash
6838 table, but we don't need anything else just yet. */
6840 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6841 abbrev_section
, ptr
, section_kind
);
6843 length
= get_cu_length (&header
);
6845 /* Skip dummy type units. */
6846 if (ptr
>= info_ptr
+ length
6847 || peek_abbrev_code (abfd
, ptr
) == 0
6848 || header
.unit_type
!= DW_UT_type
)
6854 if (types_htab
== NULL
)
6857 types_htab
= allocate_dwo_unit_table (objfile
);
6859 types_htab
= allocate_signatured_type_table (objfile
);
6865 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6867 dwo_tu
->dwo_file
= dwo_file
;
6868 dwo_tu
->signature
= header
.signature
;
6869 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6870 dwo_tu
->section
= section
;
6871 dwo_tu
->sect_off
= sect_off
;
6872 dwo_tu
->length
= length
;
6876 /* N.B.: type_offset is not usable if this type uses a DWO file.
6877 The real type_offset is in the DWO file. */
6879 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6880 struct signatured_type
);
6881 sig_type
->signature
= header
.signature
;
6882 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6883 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6884 sig_type
->per_cu
.is_debug_types
= 1;
6885 sig_type
->per_cu
.section
= section
;
6886 sig_type
->per_cu
.sect_off
= sect_off
;
6887 sig_type
->per_cu
.length
= length
;
6890 slot
= htab_find_slot (types_htab
,
6891 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6893 gdb_assert (slot
!= NULL
);
6896 sect_offset dup_sect_off
;
6900 const struct dwo_unit
*dup_tu
6901 = (const struct dwo_unit
*) *slot
;
6903 dup_sect_off
= dup_tu
->sect_off
;
6907 const struct signatured_type
*dup_tu
6908 = (const struct signatured_type
*) *slot
;
6910 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6913 complaint (_("debug type entry at offset %s is duplicate to"
6914 " the entry at offset %s, signature %s"),
6915 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6916 hex_string (header
.signature
));
6918 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6920 if (dwarf_read_debug
> 1)
6921 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6922 sect_offset_str (sect_off
),
6923 hex_string (header
.signature
));
6929 /* Create the hash table of all entries in the .debug_types
6930 (or .debug_types.dwo) section(s).
6931 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6932 otherwise it is NULL.
6934 The result is a pointer to the hash table or NULL if there are no types.
6936 Note: This function processes DWO files only, not DWP files. */
6939 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6940 struct dwo_file
*dwo_file
,
6941 gdb::array_view
<dwarf2_section_info
> type_sections
,
6944 for (dwarf2_section_info
§ion
: type_sections
)
6945 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6946 types_htab
, rcuh_kind::TYPE
);
6949 /* Create the hash table of all entries in the .debug_types section,
6950 and initialize all_type_units.
6951 The result is zero if there is an error (e.g. missing .debug_types section),
6952 otherwise non-zero. */
6955 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6957 htab_t types_htab
= NULL
;
6959 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6960 &dwarf2_per_objfile
->info
, types_htab
,
6961 rcuh_kind::COMPILE
);
6962 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6963 dwarf2_per_objfile
->types
, types_htab
);
6964 if (types_htab
== NULL
)
6966 dwarf2_per_objfile
->signatured_types
= NULL
;
6970 dwarf2_per_objfile
->signatured_types
= types_htab
;
6972 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6973 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6975 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6976 &dwarf2_per_objfile
->all_type_units
);
6981 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6982 If SLOT is non-NULL, it is the entry to use in the hash table.
6983 Otherwise we find one. */
6985 static struct signatured_type
*
6986 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6989 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6991 if (dwarf2_per_objfile
->all_type_units
.size ()
6992 == dwarf2_per_objfile
->all_type_units
.capacity ())
6993 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
6995 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6996 struct signatured_type
);
6998 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
6999 sig_type
->signature
= sig
;
7000 sig_type
->per_cu
.is_debug_types
= 1;
7001 if (dwarf2_per_objfile
->using_index
)
7003 sig_type
->per_cu
.v
.quick
=
7004 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7005 struct dwarf2_per_cu_quick_data
);
7010 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7013 gdb_assert (*slot
== NULL
);
7015 /* The rest of sig_type must be filled in by the caller. */
7019 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7020 Fill in SIG_ENTRY with DWO_ENTRY. */
7023 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7024 struct signatured_type
*sig_entry
,
7025 struct dwo_unit
*dwo_entry
)
7027 /* Make sure we're not clobbering something we don't expect to. */
7028 gdb_assert (! sig_entry
->per_cu
.queued
);
7029 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7030 if (dwarf2_per_objfile
->using_index
)
7032 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7033 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7036 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7037 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7038 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7039 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7040 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7042 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7043 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7044 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7045 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7046 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7047 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7048 sig_entry
->dwo_unit
= dwo_entry
;
7051 /* Subroutine of lookup_signatured_type.
7052 If we haven't read the TU yet, create the signatured_type data structure
7053 for a TU to be read in directly from a DWO file, bypassing the stub.
7054 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7055 using .gdb_index, then when reading a CU we want to stay in the DWO file
7056 containing that CU. Otherwise we could end up reading several other DWO
7057 files (due to comdat folding) to process the transitive closure of all the
7058 mentioned TUs, and that can be slow. The current DWO file will have every
7059 type signature that it needs.
7060 We only do this for .gdb_index because in the psymtab case we already have
7061 to read all the DWOs to build the type unit groups. */
7063 static struct signatured_type
*
7064 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7066 struct dwarf2_per_objfile
*dwarf2_per_objfile
7067 = cu
->per_cu
->dwarf2_per_objfile
;
7068 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7069 struct dwo_file
*dwo_file
;
7070 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7071 struct signatured_type find_sig_entry
, *sig_entry
;
7074 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7076 /* If TU skeletons have been removed then we may not have read in any
7078 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7080 dwarf2_per_objfile
->signatured_types
7081 = allocate_signatured_type_table (objfile
);
7084 /* We only ever need to read in one copy of a signatured type.
7085 Use the global signatured_types array to do our own comdat-folding
7086 of types. If this is the first time we're reading this TU, and
7087 the TU has an entry in .gdb_index, replace the recorded data from
7088 .gdb_index with this TU. */
7090 find_sig_entry
.signature
= sig
;
7091 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7092 &find_sig_entry
, INSERT
);
7093 sig_entry
= (struct signatured_type
*) *slot
;
7095 /* We can get here with the TU already read, *or* in the process of being
7096 read. Don't reassign the global entry to point to this DWO if that's
7097 the case. Also note that if the TU is already being read, it may not
7098 have come from a DWO, the program may be a mix of Fission-compiled
7099 code and non-Fission-compiled code. */
7101 /* Have we already tried to read this TU?
7102 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7103 needn't exist in the global table yet). */
7104 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7107 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7108 dwo_unit of the TU itself. */
7109 dwo_file
= cu
->dwo_unit
->dwo_file
;
7111 /* Ok, this is the first time we're reading this TU. */
7112 if (dwo_file
->tus
== NULL
)
7114 find_dwo_entry
.signature
= sig
;
7115 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7116 if (dwo_entry
== NULL
)
7119 /* If the global table doesn't have an entry for this TU, add one. */
7120 if (sig_entry
== NULL
)
7121 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7123 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7124 sig_entry
->per_cu
.tu_read
= 1;
7128 /* Subroutine of lookup_signatured_type.
7129 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7130 then try the DWP file. If the TU stub (skeleton) has been removed then
7131 it won't be in .gdb_index. */
7133 static struct signatured_type
*
7134 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7136 struct dwarf2_per_objfile
*dwarf2_per_objfile
7137 = cu
->per_cu
->dwarf2_per_objfile
;
7138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7139 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7140 struct dwo_unit
*dwo_entry
;
7141 struct signatured_type find_sig_entry
, *sig_entry
;
7144 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7145 gdb_assert (dwp_file
!= NULL
);
7147 /* If TU skeletons have been removed then we may not have read in any
7149 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7151 dwarf2_per_objfile
->signatured_types
7152 = allocate_signatured_type_table (objfile
);
7155 find_sig_entry
.signature
= sig
;
7156 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7157 &find_sig_entry
, INSERT
);
7158 sig_entry
= (struct signatured_type
*) *slot
;
7160 /* Have we already tried to read this TU?
7161 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7162 needn't exist in the global table yet). */
7163 if (sig_entry
!= NULL
)
7166 if (dwp_file
->tus
== NULL
)
7168 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7169 sig
, 1 /* is_debug_types */);
7170 if (dwo_entry
== NULL
)
7173 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7174 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7179 /* Lookup a signature based type for DW_FORM_ref_sig8.
7180 Returns NULL if signature SIG is not present in the table.
7181 It is up to the caller to complain about this. */
7183 static struct signatured_type
*
7184 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7186 struct dwarf2_per_objfile
*dwarf2_per_objfile
7187 = cu
->per_cu
->dwarf2_per_objfile
;
7190 && dwarf2_per_objfile
->using_index
)
7192 /* We're in a DWO/DWP file, and we're using .gdb_index.
7193 These cases require special processing. */
7194 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7195 return lookup_dwo_signatured_type (cu
, sig
);
7197 return lookup_dwp_signatured_type (cu
, sig
);
7201 struct signatured_type find_entry
, *entry
;
7203 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7205 find_entry
.signature
= sig
;
7206 entry
= ((struct signatured_type
*)
7207 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7212 /* Return the address base of the compile unit, which, if exists, is stored
7213 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7214 static gdb::optional
<ULONGEST
>
7215 lookup_addr_base (struct die_info
*comp_unit_die
)
7217 struct attribute
*attr
;
7218 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7219 if (attr
== nullptr)
7220 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7221 if (attr
== nullptr)
7222 return gdb::optional
<ULONGEST
> ();
7223 return DW_UNSND (attr
);
7226 /* Return range lists base of the compile unit, which, if exists, is stored
7227 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7229 lookup_ranges_base (struct die_info
*comp_unit_die
)
7231 struct attribute
*attr
;
7232 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7233 if (attr
== nullptr)
7234 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7235 if (attr
== nullptr)
7237 return DW_UNSND (attr
);
7240 /* Low level DIE reading support. */
7242 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7245 init_cu_die_reader (struct die_reader_specs
*reader
,
7246 struct dwarf2_cu
*cu
,
7247 struct dwarf2_section_info
*section
,
7248 struct dwo_file
*dwo_file
,
7249 struct abbrev_table
*abbrev_table
)
7251 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7252 reader
->abfd
= get_section_bfd_owner (section
);
7254 reader
->dwo_file
= dwo_file
;
7255 reader
->die_section
= section
;
7256 reader
->buffer
= section
->buffer
;
7257 reader
->buffer_end
= section
->buffer
+ section
->size
;
7258 reader
->comp_dir
= NULL
;
7259 reader
->abbrev_table
= abbrev_table
;
7262 /* Subroutine of cutu_reader to simplify it.
7263 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7264 There's just a lot of work to do, and cutu_reader is big enough
7267 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7268 from it to the DIE in the DWO. If NULL we are skipping the stub.
7269 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7270 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7271 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7272 STUB_COMP_DIR may be non-NULL.
7273 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7274 are filled in with the info of the DIE from the DWO file.
7275 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7276 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7277 kept around for at least as long as *RESULT_READER.
7279 The result is non-zero if a valid (non-dummy) DIE was found. */
7282 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7283 struct dwo_unit
*dwo_unit
,
7284 struct die_info
*stub_comp_unit_die
,
7285 const char *stub_comp_dir
,
7286 struct die_reader_specs
*result_reader
,
7287 const gdb_byte
**result_info_ptr
,
7288 struct die_info
**result_comp_unit_die
,
7289 int *result_has_children
,
7290 abbrev_table_up
*result_dwo_abbrev_table
)
7292 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7293 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7294 struct dwarf2_cu
*cu
= this_cu
->cu
;
7296 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7297 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7298 int i
,num_extra_attrs
;
7299 struct dwarf2_section_info
*dwo_abbrev_section
;
7300 struct die_info
*comp_unit_die
;
7302 /* At most one of these may be provided. */
7303 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7305 /* These attributes aren't processed until later:
7306 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7307 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7308 referenced later. However, these attributes are found in the stub
7309 which we won't have later. In order to not impose this complication
7310 on the rest of the code, we read them here and copy them to the
7319 if (stub_comp_unit_die
!= NULL
)
7321 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7323 if (! this_cu
->is_debug_types
)
7324 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7325 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7326 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7327 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7328 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7330 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7332 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7333 here (if needed). We need the value before we can process
7335 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7337 else if (stub_comp_dir
!= NULL
)
7339 /* Reconstruct the comp_dir attribute to simplify the code below. */
7340 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7341 comp_dir
->name
= DW_AT_comp_dir
;
7342 comp_dir
->form
= DW_FORM_string
;
7343 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7344 DW_STRING (comp_dir
) = stub_comp_dir
;
7347 /* Set up for reading the DWO CU/TU. */
7348 cu
->dwo_unit
= dwo_unit
;
7349 dwarf2_section_info
*section
= dwo_unit
->section
;
7350 dwarf2_read_section (objfile
, section
);
7351 abfd
= get_section_bfd_owner (section
);
7352 begin_info_ptr
= info_ptr
= (section
->buffer
7353 + to_underlying (dwo_unit
->sect_off
));
7354 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7356 if (this_cu
->is_debug_types
)
7358 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7360 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7361 &cu
->header
, section
,
7363 info_ptr
, rcuh_kind::TYPE
);
7364 /* This is not an assert because it can be caused by bad debug info. */
7365 if (sig_type
->signature
!= cu
->header
.signature
)
7367 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7368 " TU at offset %s [in module %s]"),
7369 hex_string (sig_type
->signature
),
7370 hex_string (cu
->header
.signature
),
7371 sect_offset_str (dwo_unit
->sect_off
),
7372 bfd_get_filename (abfd
));
7374 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7375 /* For DWOs coming from DWP files, we don't know the CU length
7376 nor the type's offset in the TU until now. */
7377 dwo_unit
->length
= get_cu_length (&cu
->header
);
7378 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7380 /* Establish the type offset that can be used to lookup the type.
7381 For DWO files, we don't know it until now. */
7382 sig_type
->type_offset_in_section
7383 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7387 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7388 &cu
->header
, section
,
7390 info_ptr
, rcuh_kind::COMPILE
);
7391 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7392 /* For DWOs coming from DWP files, we don't know the CU length
7394 dwo_unit
->length
= get_cu_length (&cu
->header
);
7397 *result_dwo_abbrev_table
7398 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7399 cu
->header
.abbrev_sect_off
);
7400 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7401 result_dwo_abbrev_table
->get ());
7403 /* Read in the die, but leave space to copy over the attributes
7404 from the stub. This has the benefit of simplifying the rest of
7405 the code - all the work to maintain the illusion of a single
7406 DW_TAG_{compile,type}_unit DIE is done here. */
7407 num_extra_attrs
= ((stmt_list
!= NULL
)
7411 + (comp_dir
!= NULL
));
7412 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7413 result_has_children
, num_extra_attrs
);
7415 /* Copy over the attributes from the stub to the DIE we just read in. */
7416 comp_unit_die
= *result_comp_unit_die
;
7417 i
= comp_unit_die
->num_attrs
;
7418 if (stmt_list
!= NULL
)
7419 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7421 comp_unit_die
->attrs
[i
++] = *low_pc
;
7422 if (high_pc
!= NULL
)
7423 comp_unit_die
->attrs
[i
++] = *high_pc
;
7425 comp_unit_die
->attrs
[i
++] = *ranges
;
7426 if (comp_dir
!= NULL
)
7427 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7428 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7430 if (dwarf_die_debug
)
7432 fprintf_unfiltered (gdb_stdlog
,
7433 "Read die from %s@0x%x of %s:\n",
7434 get_section_name (section
),
7435 (unsigned) (begin_info_ptr
- section
->buffer
),
7436 bfd_get_filename (abfd
));
7437 dump_die (comp_unit_die
, dwarf_die_debug
);
7440 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7441 TUs by skipping the stub and going directly to the entry in the DWO file.
7442 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7443 to get it via circuitous means. Blech. */
7444 if (comp_dir
!= NULL
)
7445 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7447 /* Skip dummy compilation units. */
7448 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7449 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7452 *result_info_ptr
= info_ptr
;
7456 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7457 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7458 signature is part of the header. */
7459 static gdb::optional
<ULONGEST
>
7460 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7462 if (cu
->header
.version
>= 5)
7463 return cu
->header
.signature
;
7464 struct attribute
*attr
;
7465 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7466 if (attr
== nullptr)
7467 return gdb::optional
<ULONGEST
> ();
7468 return DW_UNSND (attr
);
7471 /* Subroutine of cutu_reader to simplify it.
7472 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7473 Returns NULL if the specified DWO unit cannot be found. */
7475 static struct dwo_unit
*
7476 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7477 struct die_info
*comp_unit_die
,
7478 const char *dwo_name
)
7480 struct dwarf2_cu
*cu
= this_cu
->cu
;
7481 struct dwo_unit
*dwo_unit
;
7482 const char *comp_dir
;
7484 gdb_assert (cu
!= NULL
);
7486 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7487 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7488 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7490 if (this_cu
->is_debug_types
)
7492 struct signatured_type
*sig_type
;
7494 /* Since this_cu is the first member of struct signatured_type,
7495 we can go from a pointer to one to a pointer to the other. */
7496 sig_type
= (struct signatured_type
*) this_cu
;
7497 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7501 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7502 if (!signature
.has_value ())
7503 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7505 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7506 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7513 /* Subroutine of cutu_reader to simplify it.
7514 See it for a description of the parameters.
7515 Read a TU directly from a DWO file, bypassing the stub. */
7518 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7519 int use_existing_cu
, int keep
)
7521 struct signatured_type
*sig_type
;
7522 struct die_reader_specs reader
;
7524 /* Verify we can do the following downcast, and that we have the
7526 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7527 sig_type
= (struct signatured_type
*) this_cu
;
7528 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7530 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7532 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7533 /* There's no need to do the rereading_dwo_cu handling that
7534 cutu_reader does since we don't read the stub. */
7538 /* If !use_existing_cu, this_cu->cu must be NULL. */
7539 gdb_assert (this_cu
->cu
== NULL
);
7540 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7543 /* A future optimization, if needed, would be to use an existing
7544 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7545 could share abbrev tables. */
7547 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7548 NULL
/* stub_comp_unit_die */,
7549 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7551 &comp_unit_die
, &has_children
,
7552 &m_dwo_abbrev_table
) == 0)
7559 /* Initialize a CU (or TU) and read its DIEs.
7560 If the CU defers to a DWO file, read the DWO file as well.
7562 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7563 Otherwise the table specified in the comp unit header is read in and used.
7564 This is an optimization for when we already have the abbrev table.
7566 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7567 Otherwise, a new CU is allocated with xmalloc.
7569 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7570 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7573 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7574 struct abbrev_table
*abbrev_table
,
7575 int use_existing_cu
, int keep
,
7577 : die_reader_specs
{},
7578 m_this_cu (this_cu
),
7581 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7582 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7583 struct dwarf2_section_info
*section
= this_cu
->section
;
7584 bfd
*abfd
= get_section_bfd_owner (section
);
7585 struct dwarf2_cu
*cu
;
7586 const gdb_byte
*begin_info_ptr
;
7587 struct signatured_type
*sig_type
= NULL
;
7588 struct dwarf2_section_info
*abbrev_section
;
7589 /* Non-zero if CU currently points to a DWO file and we need to
7590 reread it. When this happens we need to reread the skeleton die
7591 before we can reread the DWO file (this only applies to CUs, not TUs). */
7592 int rereading_dwo_cu
= 0;
7594 if (dwarf_die_debug
)
7595 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7596 this_cu
->is_debug_types
? "type" : "comp",
7597 sect_offset_str (this_cu
->sect_off
));
7599 if (use_existing_cu
)
7602 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7603 file (instead of going through the stub), short-circuit all of this. */
7604 if (this_cu
->reading_dwo_directly
)
7606 /* Narrow down the scope of possibilities to have to understand. */
7607 gdb_assert (this_cu
->is_debug_types
);
7608 gdb_assert (abbrev_table
== NULL
);
7609 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7613 /* This is cheap if the section is already read in. */
7614 dwarf2_read_section (objfile
, section
);
7616 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7618 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7620 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7623 /* If this CU is from a DWO file we need to start over, we need to
7624 refetch the attributes from the skeleton CU.
7625 This could be optimized by retrieving those attributes from when we
7626 were here the first time: the previous comp_unit_die was stored in
7627 comp_unit_obstack. But there's no data yet that we need this
7629 if (cu
->dwo_unit
!= NULL
)
7630 rereading_dwo_cu
= 1;
7634 /* If !use_existing_cu, this_cu->cu must be NULL. */
7635 gdb_assert (this_cu
->cu
== NULL
);
7636 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7637 cu
= m_new_cu
.get ();
7640 /* Get the header. */
7641 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7643 /* We already have the header, there's no need to read it in again. */
7644 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7648 if (this_cu
->is_debug_types
)
7650 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7651 &cu
->header
, section
,
7652 abbrev_section
, info_ptr
,
7655 /* Since per_cu is the first member of struct signatured_type,
7656 we can go from a pointer to one to a pointer to the other. */
7657 sig_type
= (struct signatured_type
*) this_cu
;
7658 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7659 gdb_assert (sig_type
->type_offset_in_tu
7660 == cu
->header
.type_cu_offset_in_tu
);
7661 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7663 /* LENGTH has not been set yet for type units if we're
7664 using .gdb_index. */
7665 this_cu
->length
= get_cu_length (&cu
->header
);
7667 /* Establish the type offset that can be used to lookup the type. */
7668 sig_type
->type_offset_in_section
=
7669 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7671 this_cu
->dwarf_version
= cu
->header
.version
;
7675 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7676 &cu
->header
, section
,
7679 rcuh_kind::COMPILE
);
7681 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7682 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7683 this_cu
->dwarf_version
= cu
->header
.version
;
7687 /* Skip dummy compilation units. */
7688 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7689 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7695 /* If we don't have them yet, read the abbrevs for this compilation unit.
7696 And if we need to read them now, make sure they're freed when we're
7698 if (abbrev_table
!= NULL
)
7699 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7702 m_abbrev_table_holder
7703 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7704 cu
->header
.abbrev_sect_off
);
7705 abbrev_table
= m_abbrev_table_holder
.get ();
7708 /* Read the top level CU/TU die. */
7709 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7710 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7712 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7718 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7719 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7720 table from the DWO file and pass the ownership over to us. It will be
7721 referenced from READER, so we must make sure to free it after we're done
7724 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7725 DWO CU, that this test will fail (the attribute will not be present). */
7726 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7727 if (dwo_name
!= nullptr)
7729 struct dwo_unit
*dwo_unit
;
7730 struct die_info
*dwo_comp_unit_die
;
7734 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7735 " has children (offset %s) [in module %s]"),
7736 sect_offset_str (this_cu
->sect_off
),
7737 bfd_get_filename (abfd
));
7739 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7740 if (dwo_unit
!= NULL
)
7742 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7743 comp_unit_die
, NULL
,
7745 &dwo_comp_unit_die
, &has_children
,
7746 &m_dwo_abbrev_table
) == 0)
7752 comp_unit_die
= dwo_comp_unit_die
;
7756 /* Yikes, we couldn't find the rest of the DIE, we only have
7757 the stub. A complaint has already been logged. There's
7758 not much more we can do except pass on the stub DIE to
7759 die_reader_func. We don't want to throw an error on bad
7765 cutu_reader::~cutu_reader ()
7767 /* Done, clean up. */
7768 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7770 struct dwarf2_per_objfile
*dwarf2_per_objfile
7771 = m_this_cu
->dwarf2_per_objfile
;
7772 /* Link this CU into read_in_chain. */
7773 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7774 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7775 /* The chain owns it now. */
7776 m_new_cu
.release ();
7780 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7781 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7782 assumed to have already done the lookup to find the DWO file).
7784 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7785 THIS_CU->is_debug_types, but nothing else.
7787 We fill in THIS_CU->length.
7789 THIS_CU->cu is always freed when done.
7790 This is done in order to not leave THIS_CU->cu in a state where we have
7791 to care whether it refers to the "main" CU or the DWO CU.
7793 When parent_cu is passed, it is used to provide a default value for
7794 str_offsets_base and addr_base from the parent. */
7796 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7797 struct dwarf2_cu
*parent_cu
,
7798 struct dwo_file
*dwo_file
)
7799 : die_reader_specs
{},
7802 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7803 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7804 struct dwarf2_section_info
*section
= this_cu
->section
;
7805 bfd
*abfd
= get_section_bfd_owner (section
);
7806 struct dwarf2_section_info
*abbrev_section
;
7807 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7810 if (dwarf_die_debug
)
7811 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7812 this_cu
->is_debug_types
? "type" : "comp",
7813 sect_offset_str (this_cu
->sect_off
));
7815 gdb_assert (this_cu
->cu
== NULL
);
7817 abbrev_section
= (dwo_file
!= NULL
7818 ? &dwo_file
->sections
.abbrev
7819 : get_abbrev_section_for_cu (this_cu
));
7821 /* This is cheap if the section is already read in. */
7822 dwarf2_read_section (objfile
, section
);
7824 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7826 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7827 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7828 &m_new_cu
->header
, section
,
7829 abbrev_section
, info_ptr
,
7830 (this_cu
->is_debug_types
7832 : rcuh_kind::COMPILE
));
7834 if (parent_cu
!= nullptr)
7836 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7837 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7839 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7841 /* Skip dummy compilation units. */
7842 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7843 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7849 m_abbrev_table_holder
7850 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7851 m_new_cu
->header
.abbrev_sect_off
);
7853 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7854 m_abbrev_table_holder
.get ());
7855 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7859 /* Type Unit Groups.
7861 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7862 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7863 so that all types coming from the same compilation (.o file) are grouped
7864 together. A future step could be to put the types in the same symtab as
7865 the CU the types ultimately came from. */
7868 hash_type_unit_group (const void *item
)
7870 const struct type_unit_group
*tu_group
7871 = (const struct type_unit_group
*) item
;
7873 return hash_stmt_list_entry (&tu_group
->hash
);
7877 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7879 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7880 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7882 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7885 /* Allocate a hash table for type unit groups. */
7888 allocate_type_unit_groups_table (struct objfile
*objfile
)
7890 return htab_create_alloc_ex (3,
7891 hash_type_unit_group
,
7894 &objfile
->objfile_obstack
,
7895 hashtab_obstack_allocate
,
7896 dummy_obstack_deallocate
);
7899 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7900 partial symtabs. We combine several TUs per psymtab to not let the size
7901 of any one psymtab grow too big. */
7902 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7903 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7905 /* Helper routine for get_type_unit_group.
7906 Create the type_unit_group object used to hold one or more TUs. */
7908 static struct type_unit_group
*
7909 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7911 struct dwarf2_per_objfile
*dwarf2_per_objfile
7912 = cu
->per_cu
->dwarf2_per_objfile
;
7913 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7914 struct dwarf2_per_cu_data
*per_cu
;
7915 struct type_unit_group
*tu_group
;
7917 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7918 struct type_unit_group
);
7919 per_cu
= &tu_group
->per_cu
;
7920 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7922 if (dwarf2_per_objfile
->using_index
)
7924 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7925 struct dwarf2_per_cu_quick_data
);
7929 unsigned int line_offset
= to_underlying (line_offset_struct
);
7930 dwarf2_psymtab
*pst
;
7933 /* Give the symtab a useful name for debug purposes. */
7934 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7935 name
= string_printf ("<type_units_%d>",
7936 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7938 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7940 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7941 pst
->anonymous
= true;
7944 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7945 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7950 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7951 STMT_LIST is a DW_AT_stmt_list attribute. */
7953 static struct type_unit_group
*
7954 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7956 struct dwarf2_per_objfile
*dwarf2_per_objfile
7957 = cu
->per_cu
->dwarf2_per_objfile
;
7958 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7959 struct type_unit_group
*tu_group
;
7961 unsigned int line_offset
;
7962 struct type_unit_group type_unit_group_for_lookup
;
7964 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7966 dwarf2_per_objfile
->type_unit_groups
=
7967 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7970 /* Do we need to create a new group, or can we use an existing one? */
7974 line_offset
= DW_UNSND (stmt_list
);
7975 ++tu_stats
->nr_symtab_sharers
;
7979 /* Ugh, no stmt_list. Rare, but we have to handle it.
7980 We can do various things here like create one group per TU or
7981 spread them over multiple groups to split up the expansion work.
7982 To avoid worst case scenarios (too many groups or too large groups)
7983 we, umm, group them in bunches. */
7984 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7985 | (tu_stats
->nr_stmt_less_type_units
7986 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7987 ++tu_stats
->nr_stmt_less_type_units
;
7990 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7991 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7992 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
7993 &type_unit_group_for_lookup
, INSERT
);
7996 tu_group
= (struct type_unit_group
*) *slot
;
7997 gdb_assert (tu_group
!= NULL
);
8001 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8002 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8004 ++tu_stats
->nr_symtabs
;
8010 /* Partial symbol tables. */
8012 /* Create a psymtab named NAME and assign it to PER_CU.
8014 The caller must fill in the following details:
8015 dirname, textlow, texthigh. */
8017 static dwarf2_psymtab
*
8018 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8020 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8021 dwarf2_psymtab
*pst
;
8023 pst
= new dwarf2_psymtab (name
, objfile
, 0);
8025 pst
->psymtabs_addrmap_supported
= true;
8027 /* This is the glue that links PST into GDB's symbol API. */
8028 pst
->per_cu_data
= per_cu
;
8029 per_cu
->v
.psymtab
= pst
;
8034 /* DIE reader function for process_psymtab_comp_unit. */
8037 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8038 const gdb_byte
*info_ptr
,
8039 struct die_info
*comp_unit_die
,
8041 int want_partial_unit
,
8042 enum language pretend_language
)
8044 struct dwarf2_cu
*cu
= reader
->cu
;
8045 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8046 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8047 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8049 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8050 dwarf2_psymtab
*pst
;
8051 enum pc_bounds_kind cu_bounds_kind
;
8052 const char *filename
;
8054 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
8057 gdb_assert (! per_cu
->is_debug_types
);
8059 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
8061 /* Allocate a new partial symbol table structure. */
8062 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8063 if (filename
== NULL
)
8066 pst
= create_partial_symtab (per_cu
, filename
);
8068 /* This must be done before calling dwarf2_build_include_psymtabs. */
8069 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8071 baseaddr
= objfile
->text_section_offset ();
8073 dwarf2_find_base_address (comp_unit_die
, cu
);
8075 /* Possibly set the default values of LOWPC and HIGHPC from
8077 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8078 &best_highpc
, cu
, pst
);
8079 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8082 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8085 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8087 /* Store the contiguous range if it is not empty; it can be
8088 empty for CUs with no code. */
8089 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8093 /* Check if comp unit has_children.
8094 If so, read the rest of the partial symbols from this comp unit.
8095 If not, there's no more debug_info for this comp unit. */
8098 struct partial_die_info
*first_die
;
8099 CORE_ADDR lowpc
, highpc
;
8101 lowpc
= ((CORE_ADDR
) -1);
8102 highpc
= ((CORE_ADDR
) 0);
8104 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8106 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8107 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8109 /* If we didn't find a lowpc, set it to highpc to avoid
8110 complaints from `maint check'. */
8111 if (lowpc
== ((CORE_ADDR
) -1))
8114 /* If the compilation unit didn't have an explicit address range,
8115 then use the information extracted from its child dies. */
8116 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8119 best_highpc
= highpc
;
8122 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8123 best_lowpc
+ baseaddr
)
8125 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8126 best_highpc
+ baseaddr
)
8129 end_psymtab_common (objfile
, pst
);
8131 if (!cu
->per_cu
->imported_symtabs_empty ())
8134 int len
= cu
->per_cu
->imported_symtabs_size ();
8136 /* Fill in 'dependencies' here; we fill in 'users' in a
8138 pst
->number_of_dependencies
= len
;
8140 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8141 for (i
= 0; i
< len
; ++i
)
8143 pst
->dependencies
[i
]
8144 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8147 cu
->per_cu
->imported_symtabs_free ();
8150 /* Get the list of files included in the current compilation unit,
8151 and build a psymtab for each of them. */
8152 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8154 if (dwarf_read_debug
)
8155 fprintf_unfiltered (gdb_stdlog
,
8156 "Psymtab for %s unit @%s: %s - %s"
8157 ", %d global, %d static syms\n",
8158 per_cu
->is_debug_types
? "type" : "comp",
8159 sect_offset_str (per_cu
->sect_off
),
8160 paddress (gdbarch
, pst
->text_low (objfile
)),
8161 paddress (gdbarch
, pst
->text_high (objfile
)),
8162 pst
->n_global_syms
, pst
->n_static_syms
);
8165 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8166 Process compilation unit THIS_CU for a psymtab. */
8169 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8170 int want_partial_unit
,
8171 enum language pretend_language
)
8173 /* If this compilation unit was already read in, free the
8174 cached copy in order to read it in again. This is
8175 necessary because we skipped some symbols when we first
8176 read in the compilation unit (see load_partial_dies).
8177 This problem could be avoided, but the benefit is unclear. */
8178 if (this_cu
->cu
!= NULL
)
8179 free_one_cached_comp_unit (this_cu
);
8181 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
8187 else if (this_cu
->is_debug_types
)
8188 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8189 reader
.has_children
);
8191 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
8192 reader
.comp_unit_die
,
8193 reader
.has_children
,
8197 /* Age out any secondary CUs. */
8198 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8201 /* Reader function for build_type_psymtabs. */
8204 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8205 const gdb_byte
*info_ptr
,
8206 struct die_info
*type_unit_die
,
8209 struct dwarf2_per_objfile
*dwarf2_per_objfile
8210 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8211 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8212 struct dwarf2_cu
*cu
= reader
->cu
;
8213 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8214 struct signatured_type
*sig_type
;
8215 struct type_unit_group
*tu_group
;
8216 struct attribute
*attr
;
8217 struct partial_die_info
*first_die
;
8218 CORE_ADDR lowpc
, highpc
;
8219 dwarf2_psymtab
*pst
;
8221 gdb_assert (per_cu
->is_debug_types
);
8222 sig_type
= (struct signatured_type
*) per_cu
;
8227 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8228 tu_group
= get_type_unit_group (cu
, attr
);
8230 if (tu_group
->tus
== nullptr)
8231 tu_group
->tus
= new std::vector
<signatured_type
*>;
8232 tu_group
->tus
->push_back (sig_type
);
8234 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8235 pst
= create_partial_symtab (per_cu
, "");
8236 pst
->anonymous
= true;
8238 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8240 lowpc
= (CORE_ADDR
) -1;
8241 highpc
= (CORE_ADDR
) 0;
8242 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8244 end_psymtab_common (objfile
, pst
);
8247 /* Struct used to sort TUs by their abbreviation table offset. */
8249 struct tu_abbrev_offset
8251 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8252 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8255 signatured_type
*sig_type
;
8256 sect_offset abbrev_offset
;
8259 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8262 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8263 const struct tu_abbrev_offset
&b
)
8265 return a
.abbrev_offset
< b
.abbrev_offset
;
8268 /* Efficiently read all the type units.
8269 This does the bulk of the work for build_type_psymtabs.
8271 The efficiency is because we sort TUs by the abbrev table they use and
8272 only read each abbrev table once. In one program there are 200K TUs
8273 sharing 8K abbrev tables.
8275 The main purpose of this function is to support building the
8276 dwarf2_per_objfile->type_unit_groups table.
8277 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8278 can collapse the search space by grouping them by stmt_list.
8279 The savings can be significant, in the same program from above the 200K TUs
8280 share 8K stmt_list tables.
8282 FUNC is expected to call get_type_unit_group, which will create the
8283 struct type_unit_group if necessary and add it to
8284 dwarf2_per_objfile->type_unit_groups. */
8287 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8289 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8290 abbrev_table_up abbrev_table
;
8291 sect_offset abbrev_offset
;
8293 /* It's up to the caller to not call us multiple times. */
8294 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8296 if (dwarf2_per_objfile
->all_type_units
.empty ())
8299 /* TUs typically share abbrev tables, and there can be way more TUs than
8300 abbrev tables. Sort by abbrev table to reduce the number of times we
8301 read each abbrev table in.
8302 Alternatives are to punt or to maintain a cache of abbrev tables.
8303 This is simpler and efficient enough for now.
8305 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8306 symtab to use). Typically TUs with the same abbrev offset have the same
8307 stmt_list value too so in practice this should work well.
8309 The basic algorithm here is:
8311 sort TUs by abbrev table
8312 for each TU with same abbrev table:
8313 read abbrev table if first user
8314 read TU top level DIE
8315 [IWBN if DWO skeletons had DW_AT_stmt_list]
8318 if (dwarf_read_debug
)
8319 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8321 /* Sort in a separate table to maintain the order of all_type_units
8322 for .gdb_index: TU indices directly index all_type_units. */
8323 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8324 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8326 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8327 sorted_by_abbrev
.emplace_back
8328 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8329 sig_type
->per_cu
.section
,
8330 sig_type
->per_cu
.sect_off
));
8332 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8333 sort_tu_by_abbrev_offset
);
8335 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8337 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8339 /* Switch to the next abbrev table if necessary. */
8340 if (abbrev_table
== NULL
8341 || tu
.abbrev_offset
!= abbrev_offset
)
8343 abbrev_offset
= tu
.abbrev_offset
;
8345 abbrev_table_read_table (dwarf2_per_objfile
,
8346 &dwarf2_per_objfile
->abbrev
,
8348 ++tu_stats
->nr_uniq_abbrev_tables
;
8351 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8353 if (!reader
.dummy_p
)
8354 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8355 reader
.comp_unit_die
,
8356 reader
.has_children
);
8360 /* Print collected type unit statistics. */
8363 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8365 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8367 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8368 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8369 dwarf2_per_objfile
->all_type_units
.size ());
8370 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8371 tu_stats
->nr_uniq_abbrev_tables
);
8372 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8373 tu_stats
->nr_symtabs
);
8374 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8375 tu_stats
->nr_symtab_sharers
);
8376 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8377 tu_stats
->nr_stmt_less_type_units
);
8378 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8379 tu_stats
->nr_all_type_units_reallocs
);
8382 /* Traversal function for build_type_psymtabs. */
8385 build_type_psymtab_dependencies (void **slot
, void *info
)
8387 struct dwarf2_per_objfile
*dwarf2_per_objfile
8388 = (struct dwarf2_per_objfile
*) info
;
8389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8390 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8391 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8392 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8393 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8396 gdb_assert (len
> 0);
8397 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8399 pst
->number_of_dependencies
= len
;
8400 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8401 for (i
= 0; i
< len
; ++i
)
8403 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8404 gdb_assert (iter
->per_cu
.is_debug_types
);
8405 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8406 iter
->type_unit_group
= tu_group
;
8409 delete tu_group
->tus
;
8410 tu_group
->tus
= nullptr;
8415 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8416 Build partial symbol tables for the .debug_types comp-units. */
8419 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8421 if (! create_all_type_units (dwarf2_per_objfile
))
8424 build_type_psymtabs_1 (dwarf2_per_objfile
);
8427 /* Traversal function for process_skeletonless_type_unit.
8428 Read a TU in a DWO file and build partial symbols for it. */
8431 process_skeletonless_type_unit (void **slot
, void *info
)
8433 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8434 struct dwarf2_per_objfile
*dwarf2_per_objfile
8435 = (struct dwarf2_per_objfile
*) info
;
8436 struct signatured_type find_entry
, *entry
;
8438 /* If this TU doesn't exist in the global table, add it and read it in. */
8440 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8442 dwarf2_per_objfile
->signatured_types
8443 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8446 find_entry
.signature
= dwo_unit
->signature
;
8447 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8449 /* If we've already seen this type there's nothing to do. What's happening
8450 is we're doing our own version of comdat-folding here. */
8454 /* This does the job that create_all_type_units would have done for
8456 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8457 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8460 /* This does the job that build_type_psymtabs_1 would have done. */
8461 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8462 if (!reader
.dummy_p
)
8463 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8464 reader
.comp_unit_die
, reader
.has_children
);
8469 /* Traversal function for process_skeletonless_type_units. */
8472 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8474 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8476 if (dwo_file
->tus
!= NULL
)
8478 htab_traverse_noresize (dwo_file
->tus
,
8479 process_skeletonless_type_unit
, info
);
8485 /* Scan all TUs of DWO files, verifying we've processed them.
8486 This is needed in case a TU was emitted without its skeleton.
8487 Note: This can't be done until we know what all the DWO files are. */
8490 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8492 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8493 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8494 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8496 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8497 process_dwo_file_for_skeletonless_type_units
,
8498 dwarf2_per_objfile
);
8502 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8505 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8507 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8509 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
8514 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8516 /* Set the 'user' field only if it is not already set. */
8517 if (pst
->dependencies
[j
]->user
== NULL
)
8518 pst
->dependencies
[j
]->user
= pst
;
8523 /* Build the partial symbol table by doing a quick pass through the
8524 .debug_info and .debug_abbrev sections. */
8527 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8529 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8531 if (dwarf_read_debug
)
8533 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8534 objfile_name (objfile
));
8537 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8539 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8541 /* Any cached compilation units will be linked by the per-objfile
8542 read_in_chain. Make sure to free them when we're done. */
8543 free_cached_comp_units
freer (dwarf2_per_objfile
);
8545 build_type_psymtabs (dwarf2_per_objfile
);
8547 create_all_comp_units (dwarf2_per_objfile
);
8549 /* Create a temporary address map on a temporary obstack. We later
8550 copy this to the final obstack. */
8551 auto_obstack temp_obstack
;
8553 scoped_restore save_psymtabs_addrmap
8554 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8555 addrmap_create_mutable (&temp_obstack
));
8557 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8558 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8560 /* This has to wait until we read the CUs, we need the list of DWOs. */
8561 process_skeletonless_type_units (dwarf2_per_objfile
);
8563 /* Now that all TUs have been processed we can fill in the dependencies. */
8564 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8566 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8567 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8570 if (dwarf_read_debug
)
8571 print_tu_stats (dwarf2_per_objfile
);
8573 set_partial_user (dwarf2_per_objfile
);
8575 objfile
->partial_symtabs
->psymtabs_addrmap
8576 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8577 objfile
->partial_symtabs
->obstack ());
8578 /* At this point we want to keep the address map. */
8579 save_psymtabs_addrmap
.release ();
8581 if (dwarf_read_debug
)
8582 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8583 objfile_name (objfile
));
8586 /* Load the partial DIEs for a secondary CU into memory.
8587 This is also used when rereading a primary CU with load_all_dies. */
8590 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8592 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8594 if (!reader
.dummy_p
)
8596 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8599 /* Check if comp unit has_children.
8600 If so, read the rest of the partial symbols from this comp unit.
8601 If not, there's no more debug_info for this comp unit. */
8602 if (reader
.has_children
)
8603 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8608 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8609 struct dwarf2_section_info
*section
,
8610 struct dwarf2_section_info
*abbrev_section
,
8611 unsigned int is_dwz
)
8613 const gdb_byte
*info_ptr
;
8614 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8616 if (dwarf_read_debug
)
8617 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8618 get_section_name (section
),
8619 get_section_file_name (section
));
8621 dwarf2_read_section (objfile
, section
);
8623 info_ptr
= section
->buffer
;
8625 while (info_ptr
< section
->buffer
+ section
->size
)
8627 struct dwarf2_per_cu_data
*this_cu
;
8629 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8631 comp_unit_head cu_header
;
8632 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8633 abbrev_section
, info_ptr
,
8634 rcuh_kind::COMPILE
);
8636 /* Save the compilation unit for later lookup. */
8637 if (cu_header
.unit_type
!= DW_UT_type
)
8639 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8640 struct dwarf2_per_cu_data
);
8641 memset (this_cu
, 0, sizeof (*this_cu
));
8645 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8646 struct signatured_type
);
8647 memset (sig_type
, 0, sizeof (*sig_type
));
8648 sig_type
->signature
= cu_header
.signature
;
8649 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8650 this_cu
= &sig_type
->per_cu
;
8652 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8653 this_cu
->sect_off
= sect_off
;
8654 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8655 this_cu
->is_dwz
= is_dwz
;
8656 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8657 this_cu
->section
= section
;
8659 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8661 info_ptr
= info_ptr
+ this_cu
->length
;
8665 /* Create a list of all compilation units in OBJFILE.
8666 This is only done for -readnow and building partial symtabs. */
8669 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8671 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8672 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8673 &dwarf2_per_objfile
->abbrev
, 0);
8675 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8677 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8681 /* Process all loaded DIEs for compilation unit CU, starting at
8682 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8683 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8684 DW_AT_ranges). See the comments of add_partial_subprogram on how
8685 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8688 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8689 CORE_ADDR
*highpc
, int set_addrmap
,
8690 struct dwarf2_cu
*cu
)
8692 struct partial_die_info
*pdi
;
8694 /* Now, march along the PDI's, descending into ones which have
8695 interesting children but skipping the children of the other ones,
8696 until we reach the end of the compilation unit. */
8704 /* Anonymous namespaces or modules have no name but have interesting
8705 children, so we need to look at them. Ditto for anonymous
8708 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8709 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8710 || pdi
->tag
== DW_TAG_imported_unit
8711 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8715 case DW_TAG_subprogram
:
8716 case DW_TAG_inlined_subroutine
:
8717 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8719 case DW_TAG_constant
:
8720 case DW_TAG_variable
:
8721 case DW_TAG_typedef
:
8722 case DW_TAG_union_type
:
8723 if (!pdi
->is_declaration
)
8725 add_partial_symbol (pdi
, cu
);
8728 case DW_TAG_class_type
:
8729 case DW_TAG_interface_type
:
8730 case DW_TAG_structure_type
:
8731 if (!pdi
->is_declaration
)
8733 add_partial_symbol (pdi
, cu
);
8735 if ((cu
->language
== language_rust
8736 || cu
->language
== language_cplus
) && pdi
->has_children
)
8737 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8740 case DW_TAG_enumeration_type
:
8741 if (!pdi
->is_declaration
)
8742 add_partial_enumeration (pdi
, cu
);
8744 case DW_TAG_base_type
:
8745 case DW_TAG_subrange_type
:
8746 /* File scope base type definitions are added to the partial
8748 add_partial_symbol (pdi
, cu
);
8750 case DW_TAG_namespace
:
8751 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8754 if (!pdi
->is_declaration
)
8755 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8757 case DW_TAG_imported_unit
:
8759 struct dwarf2_per_cu_data
*per_cu
;
8761 /* For now we don't handle imported units in type units. */
8762 if (cu
->per_cu
->is_debug_types
)
8764 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8765 " supported in type units [in module %s]"),
8766 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8769 per_cu
= dwarf2_find_containing_comp_unit
8770 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8771 cu
->per_cu
->dwarf2_per_objfile
);
8773 /* Go read the partial unit, if needed. */
8774 if (per_cu
->v
.psymtab
== NULL
)
8775 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8777 cu
->per_cu
->imported_symtabs_push (per_cu
);
8780 case DW_TAG_imported_declaration
:
8781 add_partial_symbol (pdi
, cu
);
8788 /* If the die has a sibling, skip to the sibling. */
8790 pdi
= pdi
->die_sibling
;
8794 /* Functions used to compute the fully scoped name of a partial DIE.
8796 Normally, this is simple. For C++, the parent DIE's fully scoped
8797 name is concatenated with "::" and the partial DIE's name.
8798 Enumerators are an exception; they use the scope of their parent
8799 enumeration type, i.e. the name of the enumeration type is not
8800 prepended to the enumerator.
8802 There are two complexities. One is DW_AT_specification; in this
8803 case "parent" means the parent of the target of the specification,
8804 instead of the direct parent of the DIE. The other is compilers
8805 which do not emit DW_TAG_namespace; in this case we try to guess
8806 the fully qualified name of structure types from their members'
8807 linkage names. This must be done using the DIE's children rather
8808 than the children of any DW_AT_specification target. We only need
8809 to do this for structures at the top level, i.e. if the target of
8810 any DW_AT_specification (if any; otherwise the DIE itself) does not
8813 /* Compute the scope prefix associated with PDI's parent, in
8814 compilation unit CU. The result will be allocated on CU's
8815 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8816 field. NULL is returned if no prefix is necessary. */
8818 partial_die_parent_scope (struct partial_die_info
*pdi
,
8819 struct dwarf2_cu
*cu
)
8821 const char *grandparent_scope
;
8822 struct partial_die_info
*parent
, *real_pdi
;
8824 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8825 then this means the parent of the specification DIE. */
8828 while (real_pdi
->has_specification
)
8830 auto res
= find_partial_die (real_pdi
->spec_offset
,
8831 real_pdi
->spec_is_dwz
, cu
);
8836 parent
= real_pdi
->die_parent
;
8840 if (parent
->scope_set
)
8841 return parent
->scope
;
8845 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8847 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8848 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8849 Work around this problem here. */
8850 if (cu
->language
== language_cplus
8851 && parent
->tag
== DW_TAG_namespace
8852 && strcmp (parent
->name
, "::") == 0
8853 && grandparent_scope
== NULL
)
8855 parent
->scope
= NULL
;
8856 parent
->scope_set
= 1;
8860 /* Nested subroutines in Fortran get a prefix. */
8861 if (pdi
->tag
== DW_TAG_enumerator
)
8862 /* Enumerators should not get the name of the enumeration as a prefix. */
8863 parent
->scope
= grandparent_scope
;
8864 else if (parent
->tag
== DW_TAG_namespace
8865 || parent
->tag
== DW_TAG_module
8866 || parent
->tag
== DW_TAG_structure_type
8867 || parent
->tag
== DW_TAG_class_type
8868 || parent
->tag
== DW_TAG_interface_type
8869 || parent
->tag
== DW_TAG_union_type
8870 || parent
->tag
== DW_TAG_enumeration_type
8871 || (cu
->language
== language_fortran
8872 && parent
->tag
== DW_TAG_subprogram
8873 && pdi
->tag
== DW_TAG_subprogram
))
8875 if (grandparent_scope
== NULL
)
8876 parent
->scope
= parent
->name
;
8878 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8880 parent
->name
, 0, cu
);
8884 /* FIXME drow/2004-04-01: What should we be doing with
8885 function-local names? For partial symbols, we should probably be
8887 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8888 dwarf_tag_name (parent
->tag
),
8889 sect_offset_str (pdi
->sect_off
));
8890 parent
->scope
= grandparent_scope
;
8893 parent
->scope_set
= 1;
8894 return parent
->scope
;
8897 /* Return the fully scoped name associated with PDI, from compilation unit
8898 CU. The result will be allocated with malloc. */
8900 static gdb::unique_xmalloc_ptr
<char>
8901 partial_die_full_name (struct partial_die_info
*pdi
,
8902 struct dwarf2_cu
*cu
)
8904 const char *parent_scope
;
8906 /* If this is a template instantiation, we can not work out the
8907 template arguments from partial DIEs. So, unfortunately, we have
8908 to go through the full DIEs. At least any work we do building
8909 types here will be reused if full symbols are loaded later. */
8910 if (pdi
->has_template_arguments
)
8914 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8916 struct die_info
*die
;
8917 struct attribute attr
;
8918 struct dwarf2_cu
*ref_cu
= cu
;
8920 /* DW_FORM_ref_addr is using section offset. */
8921 attr
.name
= (enum dwarf_attribute
) 0;
8922 attr
.form
= DW_FORM_ref_addr
;
8923 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8924 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8926 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8930 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8931 if (parent_scope
== NULL
)
8934 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8939 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8941 struct dwarf2_per_objfile
*dwarf2_per_objfile
8942 = cu
->per_cu
->dwarf2_per_objfile
;
8943 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8944 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8946 const char *actual_name
= NULL
;
8949 baseaddr
= objfile
->text_section_offset ();
8951 gdb::unique_xmalloc_ptr
<char> built_actual_name
8952 = partial_die_full_name (pdi
, cu
);
8953 if (built_actual_name
!= NULL
)
8954 actual_name
= built_actual_name
.get ();
8956 if (actual_name
== NULL
)
8957 actual_name
= pdi
->name
;
8961 case DW_TAG_inlined_subroutine
:
8962 case DW_TAG_subprogram
:
8963 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8965 if (pdi
->is_external
8966 || cu
->language
== language_ada
8967 || (cu
->language
== language_fortran
8968 && pdi
->die_parent
!= NULL
8969 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8971 /* Normally, only "external" DIEs are part of the global scope.
8972 But in Ada and Fortran, we want to be able to access nested
8973 procedures globally. So all Ada and Fortran subprograms are
8974 stored in the global scope. */
8975 add_psymbol_to_list (actual_name
,
8976 built_actual_name
!= NULL
,
8977 VAR_DOMAIN
, LOC_BLOCK
,
8978 SECT_OFF_TEXT (objfile
),
8979 psymbol_placement::GLOBAL
,
8981 cu
->language
, objfile
);
8985 add_psymbol_to_list (actual_name
,
8986 built_actual_name
!= NULL
,
8987 VAR_DOMAIN
, LOC_BLOCK
,
8988 SECT_OFF_TEXT (objfile
),
8989 psymbol_placement::STATIC
,
8990 addr
, cu
->language
, objfile
);
8993 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
8994 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
8996 case DW_TAG_constant
:
8997 add_psymbol_to_list (actual_name
,
8998 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
8999 -1, (pdi
->is_external
9000 ? psymbol_placement::GLOBAL
9001 : psymbol_placement::STATIC
),
9002 0, cu
->language
, objfile
);
9004 case DW_TAG_variable
:
9006 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9010 && !dwarf2_per_objfile
->has_section_at_zero
)
9012 /* A global or static variable may also have been stripped
9013 out by the linker if unused, in which case its address
9014 will be nullified; do not add such variables into partial
9015 symbol table then. */
9017 else if (pdi
->is_external
)
9020 Don't enter into the minimal symbol tables as there is
9021 a minimal symbol table entry from the ELF symbols already.
9022 Enter into partial symbol table if it has a location
9023 descriptor or a type.
9024 If the location descriptor is missing, new_symbol will create
9025 a LOC_UNRESOLVED symbol, the address of the variable will then
9026 be determined from the minimal symbol table whenever the variable
9028 The address for the partial symbol table entry is not
9029 used by GDB, but it comes in handy for debugging partial symbol
9032 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9033 add_psymbol_to_list (actual_name
,
9034 built_actual_name
!= NULL
,
9035 VAR_DOMAIN
, LOC_STATIC
,
9036 SECT_OFF_TEXT (objfile
),
9037 psymbol_placement::GLOBAL
,
9038 addr
, cu
->language
, objfile
);
9042 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9044 /* Static Variable. Skip symbols whose value we cannot know (those
9045 without location descriptors or constant values). */
9046 if (!has_loc
&& !pdi
->has_const_value
)
9049 add_psymbol_to_list (actual_name
,
9050 built_actual_name
!= NULL
,
9051 VAR_DOMAIN
, LOC_STATIC
,
9052 SECT_OFF_TEXT (objfile
),
9053 psymbol_placement::STATIC
,
9055 cu
->language
, objfile
);
9058 case DW_TAG_typedef
:
9059 case DW_TAG_base_type
:
9060 case DW_TAG_subrange_type
:
9061 add_psymbol_to_list (actual_name
,
9062 built_actual_name
!= NULL
,
9063 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9064 psymbol_placement::STATIC
,
9065 0, cu
->language
, objfile
);
9067 case DW_TAG_imported_declaration
:
9068 case DW_TAG_namespace
:
9069 add_psymbol_to_list (actual_name
,
9070 built_actual_name
!= NULL
,
9071 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9072 psymbol_placement::GLOBAL
,
9073 0, cu
->language
, objfile
);
9076 /* With Fortran 77 there might be a "BLOCK DATA" module
9077 available without any name. If so, we skip the module as it
9078 doesn't bring any value. */
9079 if (actual_name
!= nullptr)
9080 add_psymbol_to_list (actual_name
,
9081 built_actual_name
!= NULL
,
9082 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9083 psymbol_placement::GLOBAL
,
9084 0, cu
->language
, objfile
);
9086 case DW_TAG_class_type
:
9087 case DW_TAG_interface_type
:
9088 case DW_TAG_structure_type
:
9089 case DW_TAG_union_type
:
9090 case DW_TAG_enumeration_type
:
9091 /* Skip external references. The DWARF standard says in the section
9092 about "Structure, Union, and Class Type Entries": "An incomplete
9093 structure, union or class type is represented by a structure,
9094 union or class entry that does not have a byte size attribute
9095 and that has a DW_AT_declaration attribute." */
9096 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9099 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9100 static vs. global. */
9101 add_psymbol_to_list (actual_name
,
9102 built_actual_name
!= NULL
,
9103 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9104 cu
->language
== language_cplus
9105 ? psymbol_placement::GLOBAL
9106 : psymbol_placement::STATIC
,
9107 0, cu
->language
, objfile
);
9110 case DW_TAG_enumerator
:
9111 add_psymbol_to_list (actual_name
,
9112 built_actual_name
!= NULL
,
9113 VAR_DOMAIN
, LOC_CONST
, -1,
9114 cu
->language
== language_cplus
9115 ? psymbol_placement::GLOBAL
9116 : psymbol_placement::STATIC
,
9117 0, cu
->language
, objfile
);
9124 /* Read a partial die corresponding to a namespace; also, add a symbol
9125 corresponding to that namespace to the symbol table. NAMESPACE is
9126 the name of the enclosing namespace. */
9129 add_partial_namespace (struct partial_die_info
*pdi
,
9130 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9131 int set_addrmap
, struct dwarf2_cu
*cu
)
9133 /* Add a symbol for the namespace. */
9135 add_partial_symbol (pdi
, cu
);
9137 /* Now scan partial symbols in that namespace. */
9139 if (pdi
->has_children
)
9140 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9143 /* Read a partial die corresponding to a Fortran module. */
9146 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9147 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9149 /* Add a symbol for the namespace. */
9151 add_partial_symbol (pdi
, cu
);
9153 /* Now scan partial symbols in that module. */
9155 if (pdi
->has_children
)
9156 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9159 /* Read a partial die corresponding to a subprogram or an inlined
9160 subprogram and create a partial symbol for that subprogram.
9161 When the CU language allows it, this routine also defines a partial
9162 symbol for each nested subprogram that this subprogram contains.
9163 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9164 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9166 PDI may also be a lexical block, in which case we simply search
9167 recursively for subprograms defined inside that lexical block.
9168 Again, this is only performed when the CU language allows this
9169 type of definitions. */
9172 add_partial_subprogram (struct partial_die_info
*pdi
,
9173 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9174 int set_addrmap
, struct dwarf2_cu
*cu
)
9176 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9178 if (pdi
->has_pc_info
)
9180 if (pdi
->lowpc
< *lowpc
)
9181 *lowpc
= pdi
->lowpc
;
9182 if (pdi
->highpc
> *highpc
)
9183 *highpc
= pdi
->highpc
;
9186 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9187 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9189 CORE_ADDR this_highpc
;
9190 CORE_ADDR this_lowpc
;
9192 baseaddr
= objfile
->text_section_offset ();
9194 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9195 pdi
->lowpc
+ baseaddr
)
9198 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9199 pdi
->highpc
+ baseaddr
)
9201 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9202 this_lowpc
, this_highpc
- 1,
9203 cu
->per_cu
->v
.psymtab
);
9207 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9209 if (!pdi
->is_declaration
)
9210 /* Ignore subprogram DIEs that do not have a name, they are
9211 illegal. Do not emit a complaint at this point, we will
9212 do so when we convert this psymtab into a symtab. */
9214 add_partial_symbol (pdi
, cu
);
9218 if (! pdi
->has_children
)
9221 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9223 pdi
= pdi
->die_child
;
9227 if (pdi
->tag
== DW_TAG_subprogram
9228 || pdi
->tag
== DW_TAG_inlined_subroutine
9229 || pdi
->tag
== DW_TAG_lexical_block
)
9230 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9231 pdi
= pdi
->die_sibling
;
9236 /* Read a partial die corresponding to an enumeration type. */
9239 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9240 struct dwarf2_cu
*cu
)
9242 struct partial_die_info
*pdi
;
9244 if (enum_pdi
->name
!= NULL
)
9245 add_partial_symbol (enum_pdi
, cu
);
9247 pdi
= enum_pdi
->die_child
;
9250 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9251 complaint (_("malformed enumerator DIE ignored"));
9253 add_partial_symbol (pdi
, cu
);
9254 pdi
= pdi
->die_sibling
;
9258 /* Return the initial uleb128 in the die at INFO_PTR. */
9261 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9263 unsigned int bytes_read
;
9265 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9268 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9269 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9271 Return the corresponding abbrev, or NULL if the number is zero (indicating
9272 an empty DIE). In either case *BYTES_READ will be set to the length of
9273 the initial number. */
9275 static struct abbrev_info
*
9276 peek_die_abbrev (const die_reader_specs
&reader
,
9277 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9279 dwarf2_cu
*cu
= reader
.cu
;
9280 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9281 unsigned int abbrev_number
9282 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9284 if (abbrev_number
== 0)
9287 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9290 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9291 " at offset %s [in module %s]"),
9292 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9293 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9299 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9300 Returns a pointer to the end of a series of DIEs, terminated by an empty
9301 DIE. Any children of the skipped DIEs will also be skipped. */
9303 static const gdb_byte
*
9304 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9308 unsigned int bytes_read
;
9309 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9312 return info_ptr
+ bytes_read
;
9314 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9318 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9319 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9320 abbrev corresponding to that skipped uleb128 should be passed in
9321 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9324 static const gdb_byte
*
9325 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9326 struct abbrev_info
*abbrev
)
9328 unsigned int bytes_read
;
9329 struct attribute attr
;
9330 bfd
*abfd
= reader
->abfd
;
9331 struct dwarf2_cu
*cu
= reader
->cu
;
9332 const gdb_byte
*buffer
= reader
->buffer
;
9333 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9334 unsigned int form
, i
;
9336 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9338 /* The only abbrev we care about is DW_AT_sibling. */
9339 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9342 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9344 if (attr
.form
== DW_FORM_ref_addr
)
9345 complaint (_("ignoring absolute DW_AT_sibling"));
9348 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9349 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9351 if (sibling_ptr
< info_ptr
)
9352 complaint (_("DW_AT_sibling points backwards"));
9353 else if (sibling_ptr
> reader
->buffer_end
)
9354 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9360 /* If it isn't DW_AT_sibling, skip this attribute. */
9361 form
= abbrev
->attrs
[i
].form
;
9365 case DW_FORM_ref_addr
:
9366 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9367 and later it is offset sized. */
9368 if (cu
->header
.version
== 2)
9369 info_ptr
+= cu
->header
.addr_size
;
9371 info_ptr
+= cu
->header
.offset_size
;
9373 case DW_FORM_GNU_ref_alt
:
9374 info_ptr
+= cu
->header
.offset_size
;
9377 info_ptr
+= cu
->header
.addr_size
;
9385 case DW_FORM_flag_present
:
9386 case DW_FORM_implicit_const
:
9403 case DW_FORM_ref_sig8
:
9406 case DW_FORM_data16
:
9409 case DW_FORM_string
:
9410 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9411 info_ptr
+= bytes_read
;
9413 case DW_FORM_sec_offset
:
9415 case DW_FORM_GNU_strp_alt
:
9416 info_ptr
+= cu
->header
.offset_size
;
9418 case DW_FORM_exprloc
:
9420 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9421 info_ptr
+= bytes_read
;
9423 case DW_FORM_block1
:
9424 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9426 case DW_FORM_block2
:
9427 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9429 case DW_FORM_block4
:
9430 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9436 case DW_FORM_ref_udata
:
9437 case DW_FORM_GNU_addr_index
:
9438 case DW_FORM_GNU_str_index
:
9439 case DW_FORM_rnglistx
:
9440 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9442 case DW_FORM_indirect
:
9443 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9444 info_ptr
+= bytes_read
;
9445 /* We need to continue parsing from here, so just go back to
9447 goto skip_attribute
;
9450 error (_("Dwarf Error: Cannot handle %s "
9451 "in DWARF reader [in module %s]"),
9452 dwarf_form_name (form
),
9453 bfd_get_filename (abfd
));
9457 if (abbrev
->has_children
)
9458 return skip_children (reader
, info_ptr
);
9463 /* Locate ORIG_PDI's sibling.
9464 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9466 static const gdb_byte
*
9467 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9468 struct partial_die_info
*orig_pdi
,
9469 const gdb_byte
*info_ptr
)
9471 /* Do we know the sibling already? */
9473 if (orig_pdi
->sibling
)
9474 return orig_pdi
->sibling
;
9476 /* Are there any children to deal with? */
9478 if (!orig_pdi
->has_children
)
9481 /* Skip the children the long way. */
9483 return skip_children (reader
, info_ptr
);
9486 /* Expand this partial symbol table into a full symbol table. SELF is
9490 dwarf2_psymtab::read_symtab (struct objfile
*objfile
)
9492 struct dwarf2_per_objfile
*dwarf2_per_objfile
9493 = get_dwarf2_per_objfile (objfile
);
9495 gdb_assert (!readin
);
9496 /* If this psymtab is constructed from a debug-only objfile, the
9497 has_section_at_zero flag will not necessarily be correct. We
9498 can get the correct value for this flag by looking at the data
9499 associated with the (presumably stripped) associated objfile. */
9500 if (objfile
->separate_debug_objfile_backlink
)
9502 struct dwarf2_per_objfile
*dpo_backlink
9503 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9505 dwarf2_per_objfile
->has_section_at_zero
9506 = dpo_backlink
->has_section_at_zero
;
9509 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9511 expand_psymtab (objfile
);
9513 process_cu_includes (dwarf2_per_objfile
);
9516 /* Reading in full CUs. */
9518 /* Add PER_CU to the queue. */
9521 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9522 enum language pretend_language
)
9524 struct dwarf2_queue_item
*item
;
9527 item
= XNEW (struct dwarf2_queue_item
);
9528 item
->per_cu
= per_cu
;
9529 item
->pretend_language
= pretend_language
;
9532 if (dwarf2_queue
== NULL
)
9533 dwarf2_queue
= item
;
9535 dwarf2_queue_tail
->next
= item
;
9537 dwarf2_queue_tail
= item
;
9540 /* If PER_CU is not yet queued, add it to the queue.
9541 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9543 The result is non-zero if PER_CU was queued, otherwise the result is zero
9544 meaning either PER_CU is already queued or it is already loaded.
9546 N.B. There is an invariant here that if a CU is queued then it is loaded.
9547 The caller is required to load PER_CU if we return non-zero. */
9550 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9551 struct dwarf2_per_cu_data
*per_cu
,
9552 enum language pretend_language
)
9554 /* We may arrive here during partial symbol reading, if we need full
9555 DIEs to process an unusual case (e.g. template arguments). Do
9556 not queue PER_CU, just tell our caller to load its DIEs. */
9557 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9559 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9564 /* Mark the dependence relation so that we don't flush PER_CU
9566 if (dependent_cu
!= NULL
)
9567 dwarf2_add_dependence (dependent_cu
, per_cu
);
9569 /* If it's already on the queue, we have nothing to do. */
9573 /* If the compilation unit is already loaded, just mark it as
9575 if (per_cu
->cu
!= NULL
)
9577 per_cu
->cu
->last_used
= 0;
9581 /* Add it to the queue. */
9582 queue_comp_unit (per_cu
, pretend_language
);
9587 /* Process the queue. */
9590 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9592 struct dwarf2_queue_item
*item
, *next_item
;
9594 if (dwarf_read_debug
)
9596 fprintf_unfiltered (gdb_stdlog
,
9597 "Expanding one or more symtabs of objfile %s ...\n",
9598 objfile_name (dwarf2_per_objfile
->objfile
));
9601 /* The queue starts out with one item, but following a DIE reference
9602 may load a new CU, adding it to the end of the queue. */
9603 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9605 if ((dwarf2_per_objfile
->using_index
9606 ? !item
->per_cu
->v
.quick
->compunit_symtab
9607 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9608 /* Skip dummy CUs. */
9609 && item
->per_cu
->cu
!= NULL
)
9611 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9612 unsigned int debug_print_threshold
;
9615 if (per_cu
->is_debug_types
)
9617 struct signatured_type
*sig_type
=
9618 (struct signatured_type
*) per_cu
;
9620 sprintf (buf
, "TU %s at offset %s",
9621 hex_string (sig_type
->signature
),
9622 sect_offset_str (per_cu
->sect_off
));
9623 /* There can be 100s of TUs.
9624 Only print them in verbose mode. */
9625 debug_print_threshold
= 2;
9629 sprintf (buf
, "CU at offset %s",
9630 sect_offset_str (per_cu
->sect_off
));
9631 debug_print_threshold
= 1;
9634 if (dwarf_read_debug
>= debug_print_threshold
)
9635 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9637 if (per_cu
->is_debug_types
)
9638 process_full_type_unit (per_cu
, item
->pretend_language
);
9640 process_full_comp_unit (per_cu
, item
->pretend_language
);
9642 if (dwarf_read_debug
>= debug_print_threshold
)
9643 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9646 item
->per_cu
->queued
= 0;
9647 next_item
= item
->next
;
9651 dwarf2_queue_tail
= NULL
;
9653 if (dwarf_read_debug
)
9655 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9656 objfile_name (dwarf2_per_objfile
->objfile
));
9660 /* Read in full symbols for PST, and anything it depends on. */
9663 dwarf2_psymtab::expand_psymtab (struct objfile
*objfile
)
9665 struct dwarf2_per_cu_data
*per_cu
;
9671 for (i
= 0; i
< number_of_dependencies
; i
++)
9672 if (!dependencies
[i
]->readin
9673 && dependencies
[i
]->user
== NULL
)
9675 /* Inform about additional files that need to be read in. */
9678 /* FIXME: i18n: Need to make this a single string. */
9679 fputs_filtered (" ", gdb_stdout
);
9681 fputs_filtered ("and ", gdb_stdout
);
9683 printf_filtered ("%s...", dependencies
[i
]->filename
);
9684 wrap_here (""); /* Flush output. */
9685 gdb_flush (gdb_stdout
);
9687 dependencies
[i
]->expand_psymtab (objfile
);
9690 per_cu
= per_cu_data
;
9694 /* It's an include file, no symbols to read for it.
9695 Everything is in the parent symtab. */
9700 dw2_do_instantiate_symtab (per_cu
, false);
9703 /* Trivial hash function for die_info: the hash value of a DIE
9704 is its offset in .debug_info for this objfile. */
9707 die_hash (const void *item
)
9709 const struct die_info
*die
= (const struct die_info
*) item
;
9711 return to_underlying (die
->sect_off
);
9714 /* Trivial comparison function for die_info structures: two DIEs
9715 are equal if they have the same offset. */
9718 die_eq (const void *item_lhs
, const void *item_rhs
)
9720 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9721 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9723 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9726 /* Load the DIEs associated with PER_CU into memory. */
9729 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9731 enum language pretend_language
)
9733 gdb_assert (! this_cu
->is_debug_types
);
9735 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9739 struct dwarf2_cu
*cu
= reader
.cu
;
9740 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9742 gdb_assert (cu
->die_hash
== NULL
);
9744 htab_create_alloc_ex (cu
->header
.length
/ 12,
9748 &cu
->comp_unit_obstack
,
9749 hashtab_obstack_allocate
,
9750 dummy_obstack_deallocate
);
9752 if (reader
.has_children
)
9753 reader
.comp_unit_die
->child
9754 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9755 &info_ptr
, reader
.comp_unit_die
);
9756 cu
->dies
= reader
.comp_unit_die
;
9757 /* comp_unit_die is not stored in die_hash, no need. */
9759 /* We try not to read any attributes in this function, because not
9760 all CUs needed for references have been loaded yet, and symbol
9761 table processing isn't initialized. But we have to set the CU language,
9762 or we won't be able to build types correctly.
9763 Similarly, if we do not read the producer, we can not apply
9764 producer-specific interpretation. */
9765 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9768 /* Add a DIE to the delayed physname list. */
9771 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9772 const char *name
, struct die_info
*die
,
9773 struct dwarf2_cu
*cu
)
9775 struct delayed_method_info mi
;
9777 mi
.fnfield_index
= fnfield_index
;
9781 cu
->method_list
.push_back (mi
);
9784 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9785 "const" / "volatile". If so, decrements LEN by the length of the
9786 modifier and return true. Otherwise return false. */
9790 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9792 size_t mod_len
= sizeof (mod
) - 1;
9793 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9801 /* Compute the physnames of any methods on the CU's method list.
9803 The computation of method physnames is delayed in order to avoid the
9804 (bad) condition that one of the method's formal parameters is of an as yet
9808 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9810 /* Only C++ delays computing physnames. */
9811 if (cu
->method_list
.empty ())
9813 gdb_assert (cu
->language
== language_cplus
);
9815 for (const delayed_method_info
&mi
: cu
->method_list
)
9817 const char *physname
;
9818 struct fn_fieldlist
*fn_flp
9819 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9820 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9821 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9822 = physname
? physname
: "";
9824 /* Since there's no tag to indicate whether a method is a
9825 const/volatile overload, extract that information out of the
9827 if (physname
!= NULL
)
9829 size_t len
= strlen (physname
);
9833 if (physname
[len
] == ')') /* shortcut */
9835 else if (check_modifier (physname
, len
, " const"))
9836 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9837 else if (check_modifier (physname
, len
, " volatile"))
9838 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9845 /* The list is no longer needed. */
9846 cu
->method_list
.clear ();
9849 /* Go objects should be embedded in a DW_TAG_module DIE,
9850 and it's not clear if/how imported objects will appear.
9851 To keep Go support simple until that's worked out,
9852 go back through what we've read and create something usable.
9853 We could do this while processing each DIE, and feels kinda cleaner,
9854 but that way is more invasive.
9855 This is to, for example, allow the user to type "p var" or "b main"
9856 without having to specify the package name, and allow lookups
9857 of module.object to work in contexts that use the expression
9861 fixup_go_packaging (struct dwarf2_cu
*cu
)
9863 gdb::unique_xmalloc_ptr
<char> package_name
;
9864 struct pending
*list
;
9867 for (list
= *cu
->get_builder ()->get_global_symbols ();
9871 for (i
= 0; i
< list
->nsyms
; ++i
)
9873 struct symbol
*sym
= list
->symbol
[i
];
9875 if (sym
->language () == language_go
9876 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9878 gdb::unique_xmalloc_ptr
<char> this_package_name
9879 (go_symbol_package_name (sym
));
9881 if (this_package_name
== NULL
)
9883 if (package_name
== NULL
)
9884 package_name
= std::move (this_package_name
);
9887 struct objfile
*objfile
9888 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9889 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9890 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9891 (symbol_symtab (sym
) != NULL
9892 ? symtab_to_filename_for_display
9893 (symbol_symtab (sym
))
9894 : objfile_name (objfile
)),
9895 this_package_name
.get (), package_name
.get ());
9901 if (package_name
!= NULL
)
9903 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9904 const char *saved_package_name
9905 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9906 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9907 saved_package_name
);
9910 sym
= allocate_symbol (objfile
);
9911 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9912 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9913 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9914 e.g., "main" finds the "main" module and not C's main(). */
9915 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9916 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9917 SYMBOL_TYPE (sym
) = type
;
9919 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9923 /* Allocate a fully-qualified name consisting of the two parts on the
9927 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9929 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9932 /* A helper that allocates a struct discriminant_info to attach to a
9935 static struct discriminant_info
*
9936 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9939 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9940 gdb_assert (discriminant_index
== -1
9941 || (discriminant_index
>= 0
9942 && discriminant_index
< TYPE_NFIELDS (type
)));
9943 gdb_assert (default_index
== -1
9944 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9946 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9948 struct discriminant_info
*disc
9949 = ((struct discriminant_info
*)
9951 offsetof (struct discriminant_info
, discriminants
)
9952 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9953 disc
->default_index
= default_index
;
9954 disc
->discriminant_index
= discriminant_index
;
9956 struct dynamic_prop prop
;
9957 prop
.kind
= PROP_UNDEFINED
;
9958 prop
.data
.baton
= disc
;
9960 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9965 /* Some versions of rustc emitted enums in an unusual way.
9967 Ordinary enums were emitted as unions. The first element of each
9968 structure in the union was named "RUST$ENUM$DISR". This element
9969 held the discriminant.
9971 These versions of Rust also implemented the "non-zero"
9972 optimization. When the enum had two values, and one is empty and
9973 the other holds a pointer that cannot be zero, the pointer is used
9974 as the discriminant, with a zero value meaning the empty variant.
9975 Here, the union's first member is of the form
9976 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
9977 where the fieldnos are the indices of the fields that should be
9978 traversed in order to find the field (which may be several fields deep)
9979 and the variantname is the name of the variant of the case when the
9982 This function recognizes whether TYPE is of one of these forms,
9983 and, if so, smashes it to be a variant type. */
9986 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
9988 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9990 /* We don't need to deal with empty enums. */
9991 if (TYPE_NFIELDS (type
) == 0)
9994 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
9995 if (TYPE_NFIELDS (type
) == 1
9996 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
9998 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10000 /* Decode the field name to find the offset of the
10002 ULONGEST bit_offset
= 0;
10003 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10004 while (name
[0] >= '0' && name
[0] <= '9')
10007 unsigned long index
= strtoul (name
, &tail
, 10);
10010 || index
>= TYPE_NFIELDS (field_type
)
10011 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10012 != FIELD_LOC_KIND_BITPOS
))
10014 complaint (_("Could not parse Rust enum encoding string \"%s\""
10016 TYPE_FIELD_NAME (type
, 0),
10017 objfile_name (objfile
));
10022 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10023 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10026 /* Make a union to hold the variants. */
10027 struct type
*union_type
= alloc_type (objfile
);
10028 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10029 TYPE_NFIELDS (union_type
) = 3;
10030 TYPE_FIELDS (union_type
)
10031 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10032 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10033 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10035 /* Put the discriminant must at index 0. */
10036 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10037 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10038 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10039 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10041 /* The order of fields doesn't really matter, so put the real
10042 field at index 1 and the data-less field at index 2. */
10043 struct discriminant_info
*disc
10044 = alloc_discriminant_info (union_type
, 0, 1);
10045 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10046 TYPE_FIELD_NAME (union_type
, 1)
10047 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10048 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10049 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10050 TYPE_FIELD_NAME (union_type
, 1));
10052 const char *dataless_name
10053 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10055 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10057 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10058 /* NAME points into the original discriminant name, which
10059 already has the correct lifetime. */
10060 TYPE_FIELD_NAME (union_type
, 2) = name
;
10061 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10062 disc
->discriminants
[2] = 0;
10064 /* Smash this type to be a structure type. We have to do this
10065 because the type has already been recorded. */
10066 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10067 TYPE_NFIELDS (type
) = 1;
10069 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10071 /* Install the variant part. */
10072 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10073 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10074 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10076 /* A union with a single anonymous field is probably an old-style
10077 univariant enum. */
10078 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10080 /* Smash this type to be a structure type. We have to do this
10081 because the type has already been recorded. */
10082 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10084 /* Make a union to hold the variants. */
10085 struct type
*union_type
= alloc_type (objfile
);
10086 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10087 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10088 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10089 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10090 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10092 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10093 const char *variant_name
10094 = rust_last_path_segment (TYPE_NAME (field_type
));
10095 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10096 TYPE_NAME (field_type
)
10097 = rust_fully_qualify (&objfile
->objfile_obstack
,
10098 TYPE_NAME (type
), variant_name
);
10100 /* Install the union in the outer struct type. */
10101 TYPE_NFIELDS (type
) = 1;
10103 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10104 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10105 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10106 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10108 alloc_discriminant_info (union_type
, -1, 0);
10112 struct type
*disr_type
= nullptr;
10113 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10115 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10117 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10119 /* All fields of a true enum will be structs. */
10122 else if (TYPE_NFIELDS (disr_type
) == 0)
10124 /* Could be data-less variant, so keep going. */
10125 disr_type
= nullptr;
10127 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10128 "RUST$ENUM$DISR") != 0)
10130 /* Not a Rust enum. */
10140 /* If we got here without a discriminant, then it's probably
10142 if (disr_type
== nullptr)
10145 /* Smash this type to be a structure type. We have to do this
10146 because the type has already been recorded. */
10147 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10149 /* Make a union to hold the variants. */
10150 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10151 struct type
*union_type
= alloc_type (objfile
);
10152 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10153 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10154 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10155 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10156 TYPE_FIELDS (union_type
)
10157 = (struct field
*) TYPE_ZALLOC (union_type
,
10158 (TYPE_NFIELDS (union_type
)
10159 * sizeof (struct field
)));
10161 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10162 TYPE_NFIELDS (type
) * sizeof (struct field
));
10164 /* Install the discriminant at index 0 in the union. */
10165 TYPE_FIELD (union_type
, 0) = *disr_field
;
10166 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10167 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10169 /* Install the union in the outer struct type. */
10170 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10171 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10172 TYPE_NFIELDS (type
) = 1;
10174 /* Set the size and offset of the union type. */
10175 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10177 /* We need a way to find the correct discriminant given a
10178 variant name. For convenience we build a map here. */
10179 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10180 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10181 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10183 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10186 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10187 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10191 int n_fields
= TYPE_NFIELDS (union_type
);
10192 struct discriminant_info
*disc
10193 = alloc_discriminant_info (union_type
, 0, -1);
10194 /* Skip the discriminant here. */
10195 for (int i
= 1; i
< n_fields
; ++i
)
10197 /* Find the final word in the name of this variant's type.
10198 That name can be used to look up the correct
10200 const char *variant_name
10201 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10204 auto iter
= discriminant_map
.find (variant_name
);
10205 if (iter
!= discriminant_map
.end ())
10206 disc
->discriminants
[i
] = iter
->second
;
10208 /* Remove the discriminant field, if it exists. */
10209 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10210 if (TYPE_NFIELDS (sub_type
) > 0)
10212 --TYPE_NFIELDS (sub_type
);
10213 ++TYPE_FIELDS (sub_type
);
10215 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10216 TYPE_NAME (sub_type
)
10217 = rust_fully_qualify (&objfile
->objfile_obstack
,
10218 TYPE_NAME (type
), variant_name
);
10223 /* Rewrite some Rust unions to be structures with variants parts. */
10226 rust_union_quirks (struct dwarf2_cu
*cu
)
10228 gdb_assert (cu
->language
== language_rust
);
10229 for (type
*type_
: cu
->rust_unions
)
10230 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10231 /* We don't need this any more. */
10232 cu
->rust_unions
.clear ();
10235 /* Return the symtab for PER_CU. This works properly regardless of
10236 whether we're using the index or psymtabs. */
10238 static struct compunit_symtab
*
10239 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10241 return (per_cu
->dwarf2_per_objfile
->using_index
10242 ? per_cu
->v
.quick
->compunit_symtab
10243 : per_cu
->v
.psymtab
->compunit_symtab
);
10246 /* A helper function for computing the list of all symbol tables
10247 included by PER_CU. */
10250 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10251 htab_t all_children
, htab_t all_type_symtabs
,
10252 struct dwarf2_per_cu_data
*per_cu
,
10253 struct compunit_symtab
*immediate_parent
)
10256 struct compunit_symtab
*cust
;
10258 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10261 /* This inclusion and its children have been processed. */
10266 /* Only add a CU if it has a symbol table. */
10267 cust
= get_compunit_symtab (per_cu
);
10270 /* If this is a type unit only add its symbol table if we haven't
10271 seen it yet (type unit per_cu's can share symtabs). */
10272 if (per_cu
->is_debug_types
)
10274 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10278 result
->push_back (cust
);
10279 if (cust
->user
== NULL
)
10280 cust
->user
= immediate_parent
;
10285 result
->push_back (cust
);
10286 if (cust
->user
== NULL
)
10287 cust
->user
= immediate_parent
;
10291 if (!per_cu
->imported_symtabs_empty ())
10292 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10294 recursively_compute_inclusions (result
, all_children
,
10295 all_type_symtabs
, ptr
, cust
);
10299 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10303 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10305 gdb_assert (! per_cu
->is_debug_types
);
10307 if (!per_cu
->imported_symtabs_empty ())
10310 std::vector
<compunit_symtab
*> result_symtabs
;
10311 htab_t all_children
, all_type_symtabs
;
10312 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10314 /* If we don't have a symtab, we can just skip this case. */
10318 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10319 NULL
, xcalloc
, xfree
);
10320 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10321 NULL
, xcalloc
, xfree
);
10323 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10325 recursively_compute_inclusions (&result_symtabs
, all_children
,
10326 all_type_symtabs
, ptr
, cust
);
10329 /* Now we have a transitive closure of all the included symtabs. */
10330 len
= result_symtabs
.size ();
10332 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10333 struct compunit_symtab
*, len
+ 1);
10334 memcpy (cust
->includes
, result_symtabs
.data (),
10335 len
* sizeof (compunit_symtab
*));
10336 cust
->includes
[len
] = NULL
;
10338 htab_delete (all_children
);
10339 htab_delete (all_type_symtabs
);
10343 /* Compute the 'includes' field for the symtabs of all the CUs we just
10347 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10349 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10351 if (! iter
->is_debug_types
)
10352 compute_compunit_symtab_includes (iter
);
10355 dwarf2_per_objfile
->just_read_cus
.clear ();
10358 /* Generate full symbol information for PER_CU, whose DIEs have
10359 already been loaded into memory. */
10362 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10363 enum language pretend_language
)
10365 struct dwarf2_cu
*cu
= per_cu
->cu
;
10366 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10367 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10368 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10369 CORE_ADDR lowpc
, highpc
;
10370 struct compunit_symtab
*cust
;
10371 CORE_ADDR baseaddr
;
10372 struct block
*static_block
;
10375 baseaddr
= objfile
->text_section_offset ();
10377 /* Clear the list here in case something was left over. */
10378 cu
->method_list
.clear ();
10380 cu
->language
= pretend_language
;
10381 cu
->language_defn
= language_def (cu
->language
);
10383 /* Do line number decoding in read_file_scope () */
10384 process_die (cu
->dies
, cu
);
10386 /* For now fudge the Go package. */
10387 if (cu
->language
== language_go
)
10388 fixup_go_packaging (cu
);
10390 /* Now that we have processed all the DIEs in the CU, all the types
10391 should be complete, and it should now be safe to compute all of the
10393 compute_delayed_physnames (cu
);
10395 if (cu
->language
== language_rust
)
10396 rust_union_quirks (cu
);
10398 /* Some compilers don't define a DW_AT_high_pc attribute for the
10399 compilation unit. If the DW_AT_high_pc is missing, synthesize
10400 it, by scanning the DIE's below the compilation unit. */
10401 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10403 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10404 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10406 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10407 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10408 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10409 addrmap to help ensure it has an accurate map of pc values belonging to
10411 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10413 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10414 SECT_OFF_TEXT (objfile
),
10419 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10421 /* Set symtab language to language from DW_AT_language. If the
10422 compilation is from a C file generated by language preprocessors, do
10423 not set the language if it was already deduced by start_subfile. */
10424 if (!(cu
->language
== language_c
10425 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10426 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10428 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10429 produce DW_AT_location with location lists but it can be possibly
10430 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10431 there were bugs in prologue debug info, fixed later in GCC-4.5
10432 by "unwind info for epilogues" patch (which is not directly related).
10434 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10435 needed, it would be wrong due to missing DW_AT_producer there.
10437 Still one can confuse GDB by using non-standard GCC compilation
10438 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10440 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10441 cust
->locations_valid
= 1;
10443 if (gcc_4_minor
>= 5)
10444 cust
->epilogue_unwind_valid
= 1;
10446 cust
->call_site_htab
= cu
->call_site_htab
;
10449 if (dwarf2_per_objfile
->using_index
)
10450 per_cu
->v
.quick
->compunit_symtab
= cust
;
10453 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10454 pst
->compunit_symtab
= cust
;
10455 pst
->readin
= true;
10458 /* Push it for inclusion processing later. */
10459 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10461 /* Not needed any more. */
10462 cu
->reset_builder ();
10465 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10466 already been loaded into memory. */
10469 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10470 enum language pretend_language
)
10472 struct dwarf2_cu
*cu
= per_cu
->cu
;
10473 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10474 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10475 struct compunit_symtab
*cust
;
10476 struct signatured_type
*sig_type
;
10478 gdb_assert (per_cu
->is_debug_types
);
10479 sig_type
= (struct signatured_type
*) per_cu
;
10481 /* Clear the list here in case something was left over. */
10482 cu
->method_list
.clear ();
10484 cu
->language
= pretend_language
;
10485 cu
->language_defn
= language_def (cu
->language
);
10487 /* The symbol tables are set up in read_type_unit_scope. */
10488 process_die (cu
->dies
, cu
);
10490 /* For now fudge the Go package. */
10491 if (cu
->language
== language_go
)
10492 fixup_go_packaging (cu
);
10494 /* Now that we have processed all the DIEs in the CU, all the types
10495 should be complete, and it should now be safe to compute all of the
10497 compute_delayed_physnames (cu
);
10499 if (cu
->language
== language_rust
)
10500 rust_union_quirks (cu
);
10502 /* TUs share symbol tables.
10503 If this is the first TU to use this symtab, complete the construction
10504 of it with end_expandable_symtab. Otherwise, complete the addition of
10505 this TU's symbols to the existing symtab. */
10506 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10508 buildsym_compunit
*builder
= cu
->get_builder ();
10509 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10510 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10514 /* Set symtab language to language from DW_AT_language. If the
10515 compilation is from a C file generated by language preprocessors,
10516 do not set the language if it was already deduced by
10518 if (!(cu
->language
== language_c
10519 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10520 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10525 cu
->get_builder ()->augment_type_symtab ();
10526 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10529 if (dwarf2_per_objfile
->using_index
)
10530 per_cu
->v
.quick
->compunit_symtab
= cust
;
10533 dwarf2_psymtab
*pst
= per_cu
->v
.psymtab
;
10534 pst
->compunit_symtab
= cust
;
10535 pst
->readin
= true;
10538 /* Not needed any more. */
10539 cu
->reset_builder ();
10542 /* Process an imported unit DIE. */
10545 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10547 struct attribute
*attr
;
10549 /* For now we don't handle imported units in type units. */
10550 if (cu
->per_cu
->is_debug_types
)
10552 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10553 " supported in type units [in module %s]"),
10554 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10557 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10560 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10561 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10562 dwarf2_per_cu_data
*per_cu
10563 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10564 cu
->per_cu
->dwarf2_per_objfile
);
10566 /* If necessary, add it to the queue and load its DIEs. */
10567 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10568 load_full_comp_unit (per_cu
, false, cu
->language
);
10570 cu
->per_cu
->imported_symtabs_push (per_cu
);
10574 /* RAII object that represents a process_die scope: i.e.,
10575 starts/finishes processing a DIE. */
10576 class process_die_scope
10579 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10580 : m_die (die
), m_cu (cu
)
10582 /* We should only be processing DIEs not already in process. */
10583 gdb_assert (!m_die
->in_process
);
10584 m_die
->in_process
= true;
10587 ~process_die_scope ()
10589 m_die
->in_process
= false;
10591 /* If we're done processing the DIE for the CU that owns the line
10592 header, we don't need the line header anymore. */
10593 if (m_cu
->line_header_die_owner
== m_die
)
10595 delete m_cu
->line_header
;
10596 m_cu
->line_header
= NULL
;
10597 m_cu
->line_header_die_owner
= NULL
;
10606 /* Process a die and its children. */
10609 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10611 process_die_scope
scope (die
, cu
);
10615 case DW_TAG_padding
:
10617 case DW_TAG_compile_unit
:
10618 case DW_TAG_partial_unit
:
10619 read_file_scope (die
, cu
);
10621 case DW_TAG_type_unit
:
10622 read_type_unit_scope (die
, cu
);
10624 case DW_TAG_subprogram
:
10625 /* Nested subprograms in Fortran get a prefix. */
10626 if (cu
->language
== language_fortran
10627 && die
->parent
!= NULL
10628 && die
->parent
->tag
== DW_TAG_subprogram
)
10629 cu
->processing_has_namespace_info
= true;
10630 /* Fall through. */
10631 case DW_TAG_inlined_subroutine
:
10632 read_func_scope (die
, cu
);
10634 case DW_TAG_lexical_block
:
10635 case DW_TAG_try_block
:
10636 case DW_TAG_catch_block
:
10637 read_lexical_block_scope (die
, cu
);
10639 case DW_TAG_call_site
:
10640 case DW_TAG_GNU_call_site
:
10641 read_call_site_scope (die
, cu
);
10643 case DW_TAG_class_type
:
10644 case DW_TAG_interface_type
:
10645 case DW_TAG_structure_type
:
10646 case DW_TAG_union_type
:
10647 process_structure_scope (die
, cu
);
10649 case DW_TAG_enumeration_type
:
10650 process_enumeration_scope (die
, cu
);
10653 /* These dies have a type, but processing them does not create
10654 a symbol or recurse to process the children. Therefore we can
10655 read them on-demand through read_type_die. */
10656 case DW_TAG_subroutine_type
:
10657 case DW_TAG_set_type
:
10658 case DW_TAG_array_type
:
10659 case DW_TAG_pointer_type
:
10660 case DW_TAG_ptr_to_member_type
:
10661 case DW_TAG_reference_type
:
10662 case DW_TAG_rvalue_reference_type
:
10663 case DW_TAG_string_type
:
10666 case DW_TAG_base_type
:
10667 case DW_TAG_subrange_type
:
10668 case DW_TAG_typedef
:
10669 /* Add a typedef symbol for the type definition, if it has a
10671 new_symbol (die
, read_type_die (die
, cu
), cu
);
10673 case DW_TAG_common_block
:
10674 read_common_block (die
, cu
);
10676 case DW_TAG_common_inclusion
:
10678 case DW_TAG_namespace
:
10679 cu
->processing_has_namespace_info
= true;
10680 read_namespace (die
, cu
);
10682 case DW_TAG_module
:
10683 cu
->processing_has_namespace_info
= true;
10684 read_module (die
, cu
);
10686 case DW_TAG_imported_declaration
:
10687 cu
->processing_has_namespace_info
= true;
10688 if (read_namespace_alias (die
, cu
))
10690 /* The declaration is not a global namespace alias. */
10691 /* Fall through. */
10692 case DW_TAG_imported_module
:
10693 cu
->processing_has_namespace_info
= true;
10694 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10695 || cu
->language
!= language_fortran
))
10696 complaint (_("Tag '%s' has unexpected children"),
10697 dwarf_tag_name (die
->tag
));
10698 read_import_statement (die
, cu
);
10701 case DW_TAG_imported_unit
:
10702 process_imported_unit_die (die
, cu
);
10705 case DW_TAG_variable
:
10706 read_variable (die
, cu
);
10710 new_symbol (die
, NULL
, cu
);
10715 /* DWARF name computation. */
10717 /* A helper function for dwarf2_compute_name which determines whether DIE
10718 needs to have the name of the scope prepended to the name listed in the
10722 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10724 struct attribute
*attr
;
10728 case DW_TAG_namespace
:
10729 case DW_TAG_typedef
:
10730 case DW_TAG_class_type
:
10731 case DW_TAG_interface_type
:
10732 case DW_TAG_structure_type
:
10733 case DW_TAG_union_type
:
10734 case DW_TAG_enumeration_type
:
10735 case DW_TAG_enumerator
:
10736 case DW_TAG_subprogram
:
10737 case DW_TAG_inlined_subroutine
:
10738 case DW_TAG_member
:
10739 case DW_TAG_imported_declaration
:
10742 case DW_TAG_variable
:
10743 case DW_TAG_constant
:
10744 /* We only need to prefix "globally" visible variables. These include
10745 any variable marked with DW_AT_external or any variable that
10746 lives in a namespace. [Variables in anonymous namespaces
10747 require prefixing, but they are not DW_AT_external.] */
10749 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10751 struct dwarf2_cu
*spec_cu
= cu
;
10753 return die_needs_namespace (die_specification (die
, &spec_cu
),
10757 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10758 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10759 && die
->parent
->tag
!= DW_TAG_module
)
10761 /* A variable in a lexical block of some kind does not need a
10762 namespace, even though in C++ such variables may be external
10763 and have a mangled name. */
10764 if (die
->parent
->tag
== DW_TAG_lexical_block
10765 || die
->parent
->tag
== DW_TAG_try_block
10766 || die
->parent
->tag
== DW_TAG_catch_block
10767 || die
->parent
->tag
== DW_TAG_subprogram
)
10776 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10777 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10778 defined for the given DIE. */
10780 static struct attribute
*
10781 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10783 struct attribute
*attr
;
10785 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10787 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10792 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10793 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10794 defined for the given DIE. */
10796 static const char *
10797 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10799 const char *linkage_name
;
10801 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10802 if (linkage_name
== NULL
)
10803 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10805 return linkage_name
;
10808 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10809 compute the physname for the object, which include a method's:
10810 - formal parameters (C++),
10811 - receiver type (Go),
10813 The term "physname" is a bit confusing.
10814 For C++, for example, it is the demangled name.
10815 For Go, for example, it's the mangled name.
10817 For Ada, return the DIE's linkage name rather than the fully qualified
10818 name. PHYSNAME is ignored..
10820 The result is allocated on the objfile_obstack and canonicalized. */
10822 static const char *
10823 dwarf2_compute_name (const char *name
,
10824 struct die_info
*die
, struct dwarf2_cu
*cu
,
10827 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10830 name
= dwarf2_name (die
, cu
);
10832 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10833 but otherwise compute it by typename_concat inside GDB.
10834 FIXME: Actually this is not really true, or at least not always true.
10835 It's all very confusing. compute_and_set_names doesn't try to demangle
10836 Fortran names because there is no mangling standard. So new_symbol
10837 will set the demangled name to the result of dwarf2_full_name, and it is
10838 the demangled name that GDB uses if it exists. */
10839 if (cu
->language
== language_ada
10840 || (cu
->language
== language_fortran
&& physname
))
10842 /* For Ada unit, we prefer the linkage name over the name, as
10843 the former contains the exported name, which the user expects
10844 to be able to reference. Ideally, we want the user to be able
10845 to reference this entity using either natural or linkage name,
10846 but we haven't started looking at this enhancement yet. */
10847 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10849 if (linkage_name
!= NULL
)
10850 return linkage_name
;
10853 /* These are the only languages we know how to qualify names in. */
10855 && (cu
->language
== language_cplus
10856 || cu
->language
== language_fortran
|| cu
->language
== language_d
10857 || cu
->language
== language_rust
))
10859 if (die_needs_namespace (die
, cu
))
10861 const char *prefix
;
10862 const char *canonical_name
= NULL
;
10866 prefix
= determine_prefix (die
, cu
);
10867 if (*prefix
!= '\0')
10869 gdb::unique_xmalloc_ptr
<char> prefixed_name
10870 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10872 buf
.puts (prefixed_name
.get ());
10877 /* Template parameters may be specified in the DIE's DW_AT_name, or
10878 as children with DW_TAG_template_type_param or
10879 DW_TAG_value_type_param. If the latter, add them to the name
10880 here. If the name already has template parameters, then
10881 skip this step; some versions of GCC emit both, and
10882 it is more efficient to use the pre-computed name.
10884 Something to keep in mind about this process: it is very
10885 unlikely, or in some cases downright impossible, to produce
10886 something that will match the mangled name of a function.
10887 If the definition of the function has the same debug info,
10888 we should be able to match up with it anyway. But fallbacks
10889 using the minimal symbol, for instance to find a method
10890 implemented in a stripped copy of libstdc++, will not work.
10891 If we do not have debug info for the definition, we will have to
10892 match them up some other way.
10894 When we do name matching there is a related problem with function
10895 templates; two instantiated function templates are allowed to
10896 differ only by their return types, which we do not add here. */
10898 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10900 struct attribute
*attr
;
10901 struct die_info
*child
;
10904 die
->building_fullname
= 1;
10906 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10910 const gdb_byte
*bytes
;
10911 struct dwarf2_locexpr_baton
*baton
;
10914 if (child
->tag
!= DW_TAG_template_type_param
10915 && child
->tag
!= DW_TAG_template_value_param
)
10926 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10929 complaint (_("template parameter missing DW_AT_type"));
10930 buf
.puts ("UNKNOWN_TYPE");
10933 type
= die_type (child
, cu
);
10935 if (child
->tag
== DW_TAG_template_type_param
)
10937 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10938 &type_print_raw_options
);
10942 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10945 complaint (_("template parameter missing "
10946 "DW_AT_const_value"));
10947 buf
.puts ("UNKNOWN_VALUE");
10951 dwarf2_const_value_attr (attr
, type
, name
,
10952 &cu
->comp_unit_obstack
, cu
,
10953 &value
, &bytes
, &baton
);
10955 if (TYPE_NOSIGN (type
))
10956 /* GDB prints characters as NUMBER 'CHAR'. If that's
10957 changed, this can use value_print instead. */
10958 c_printchar (value
, type
, &buf
);
10961 struct value_print_options opts
;
10964 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10968 else if (bytes
!= NULL
)
10970 v
= allocate_value (type
);
10971 memcpy (value_contents_writeable (v
), bytes
,
10972 TYPE_LENGTH (type
));
10975 v
= value_from_longest (type
, value
);
10977 /* Specify decimal so that we do not depend on
10979 get_formatted_print_options (&opts
, 'd');
10981 value_print (v
, &buf
, &opts
);
10986 die
->building_fullname
= 0;
10990 /* Close the argument list, with a space if necessary
10991 (nested templates). */
10992 if (!buf
.empty () && buf
.string ().back () == '>')
10999 /* For C++ methods, append formal parameter type
11000 information, if PHYSNAME. */
11002 if (physname
&& die
->tag
== DW_TAG_subprogram
11003 && cu
->language
== language_cplus
)
11005 struct type
*type
= read_type_die (die
, cu
);
11007 c_type_print_args (type
, &buf
, 1, cu
->language
,
11008 &type_print_raw_options
);
11010 if (cu
->language
== language_cplus
)
11012 /* Assume that an artificial first parameter is
11013 "this", but do not crash if it is not. RealView
11014 marks unnamed (and thus unused) parameters as
11015 artificial; there is no way to differentiate
11017 if (TYPE_NFIELDS (type
) > 0
11018 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11019 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11020 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11022 buf
.puts (" const");
11026 const std::string
&intermediate_name
= buf
.string ();
11028 if (cu
->language
== language_cplus
)
11030 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11031 &objfile
->per_bfd
->storage_obstack
);
11033 /* If we only computed INTERMEDIATE_NAME, or if
11034 INTERMEDIATE_NAME is already canonical, then we need to
11035 copy it to the appropriate obstack. */
11036 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11037 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11038 intermediate_name
);
11040 name
= canonical_name
;
11047 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11048 If scope qualifiers are appropriate they will be added. The result
11049 will be allocated on the storage_obstack, or NULL if the DIE does
11050 not have a name. NAME may either be from a previous call to
11051 dwarf2_name or NULL.
11053 The output string will be canonicalized (if C++). */
11055 static const char *
11056 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11058 return dwarf2_compute_name (name
, die
, cu
, 0);
11061 /* Construct a physname for the given DIE in CU. NAME may either be
11062 from a previous call to dwarf2_name or NULL. The result will be
11063 allocated on the objfile_objstack or NULL if the DIE does not have a
11066 The output string will be canonicalized (if C++). */
11068 static const char *
11069 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11072 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11075 /* In this case dwarf2_compute_name is just a shortcut not building anything
11077 if (!die_needs_namespace (die
, cu
))
11078 return dwarf2_compute_name (name
, die
, cu
, 1);
11080 mangled
= dw2_linkage_name (die
, cu
);
11082 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11083 See https://github.com/rust-lang/rust/issues/32925. */
11084 if (cu
->language
== language_rust
&& mangled
!= NULL
11085 && strchr (mangled
, '{') != NULL
)
11088 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11090 gdb::unique_xmalloc_ptr
<char> demangled
;
11091 if (mangled
!= NULL
)
11094 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11096 /* Do nothing (do not demangle the symbol name). */
11098 else if (cu
->language
== language_go
)
11100 /* This is a lie, but we already lie to the caller new_symbol.
11101 new_symbol assumes we return the mangled name.
11102 This just undoes that lie until things are cleaned up. */
11106 /* Use DMGL_RET_DROP for C++ template functions to suppress
11107 their return type. It is easier for GDB users to search
11108 for such functions as `name(params)' than `long name(params)'.
11109 In such case the minimal symbol names do not match the full
11110 symbol names but for template functions there is never a need
11111 to look up their definition from their declaration so
11112 the only disadvantage remains the minimal symbol variant
11113 `long name(params)' does not have the proper inferior type. */
11114 demangled
.reset (gdb_demangle (mangled
,
11115 (DMGL_PARAMS
| DMGL_ANSI
11116 | DMGL_RET_DROP
)));
11119 canon
= demangled
.get ();
11127 if (canon
== NULL
|| check_physname
)
11129 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11131 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11133 /* It may not mean a bug in GDB. The compiler could also
11134 compute DW_AT_linkage_name incorrectly. But in such case
11135 GDB would need to be bug-to-bug compatible. */
11137 complaint (_("Computed physname <%s> does not match demangled <%s> "
11138 "(from linkage <%s>) - DIE at %s [in module %s]"),
11139 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11140 objfile_name (objfile
));
11142 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11143 is available here - over computed PHYSNAME. It is safer
11144 against both buggy GDB and buggy compilers. */
11158 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11163 /* Inspect DIE in CU for a namespace alias. If one exists, record
11164 a new symbol for it.
11166 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11169 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11171 struct attribute
*attr
;
11173 /* If the die does not have a name, this is not a namespace
11175 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11179 struct die_info
*d
= die
;
11180 struct dwarf2_cu
*imported_cu
= cu
;
11182 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11183 keep inspecting DIEs until we hit the underlying import. */
11184 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11185 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11187 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11191 d
= follow_die_ref (d
, attr
, &imported_cu
);
11192 if (d
->tag
!= DW_TAG_imported_declaration
)
11196 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11198 complaint (_("DIE at %s has too many recursively imported "
11199 "declarations"), sect_offset_str (d
->sect_off
));
11206 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11208 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11209 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11211 /* This declaration is a global namespace alias. Add
11212 a symbol for it whose type is the aliased namespace. */
11213 new_symbol (die
, type
, cu
);
11222 /* Return the using directives repository (global or local?) to use in the
11223 current context for CU.
11225 For Ada, imported declarations can materialize renamings, which *may* be
11226 global. However it is impossible (for now?) in DWARF to distinguish
11227 "external" imported declarations and "static" ones. As all imported
11228 declarations seem to be static in all other languages, make them all CU-wide
11229 global only in Ada. */
11231 static struct using_direct
**
11232 using_directives (struct dwarf2_cu
*cu
)
11234 if (cu
->language
== language_ada
11235 && cu
->get_builder ()->outermost_context_p ())
11236 return cu
->get_builder ()->get_global_using_directives ();
11238 return cu
->get_builder ()->get_local_using_directives ();
11241 /* Read the import statement specified by the given die and record it. */
11244 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11246 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11247 struct attribute
*import_attr
;
11248 struct die_info
*imported_die
, *child_die
;
11249 struct dwarf2_cu
*imported_cu
;
11250 const char *imported_name
;
11251 const char *imported_name_prefix
;
11252 const char *canonical_name
;
11253 const char *import_alias
;
11254 const char *imported_declaration
= NULL
;
11255 const char *import_prefix
;
11256 std::vector
<const char *> excludes
;
11258 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11259 if (import_attr
== NULL
)
11261 complaint (_("Tag '%s' has no DW_AT_import"),
11262 dwarf_tag_name (die
->tag
));
11267 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11268 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11269 if (imported_name
== NULL
)
11271 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11273 The import in the following code:
11287 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11288 <52> DW_AT_decl_file : 1
11289 <53> DW_AT_decl_line : 6
11290 <54> DW_AT_import : <0x75>
11291 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11292 <59> DW_AT_name : B
11293 <5b> DW_AT_decl_file : 1
11294 <5c> DW_AT_decl_line : 2
11295 <5d> DW_AT_type : <0x6e>
11297 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11298 <76> DW_AT_byte_size : 4
11299 <77> DW_AT_encoding : 5 (signed)
11301 imports the wrong die ( 0x75 instead of 0x58 ).
11302 This case will be ignored until the gcc bug is fixed. */
11306 /* Figure out the local name after import. */
11307 import_alias
= dwarf2_name (die
, cu
);
11309 /* Figure out where the statement is being imported to. */
11310 import_prefix
= determine_prefix (die
, cu
);
11312 /* Figure out what the scope of the imported die is and prepend it
11313 to the name of the imported die. */
11314 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11316 if (imported_die
->tag
!= DW_TAG_namespace
11317 && imported_die
->tag
!= DW_TAG_module
)
11319 imported_declaration
= imported_name
;
11320 canonical_name
= imported_name_prefix
;
11322 else if (strlen (imported_name_prefix
) > 0)
11323 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11324 imported_name_prefix
,
11325 (cu
->language
== language_d
? "." : "::"),
11326 imported_name
, (char *) NULL
);
11328 canonical_name
= imported_name
;
11330 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11331 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11332 child_die
= sibling_die (child_die
))
11334 /* DWARF-4: A Fortran use statement with a “rename list” may be
11335 represented by an imported module entry with an import attribute
11336 referring to the module and owned entries corresponding to those
11337 entities that are renamed as part of being imported. */
11339 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11341 complaint (_("child DW_TAG_imported_declaration expected "
11342 "- DIE at %s [in module %s]"),
11343 sect_offset_str (child_die
->sect_off
),
11344 objfile_name (objfile
));
11348 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11349 if (import_attr
== NULL
)
11351 complaint (_("Tag '%s' has no DW_AT_import"),
11352 dwarf_tag_name (child_die
->tag
));
11357 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11359 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11360 if (imported_name
== NULL
)
11362 complaint (_("child DW_TAG_imported_declaration has unknown "
11363 "imported name - DIE at %s [in module %s]"),
11364 sect_offset_str (child_die
->sect_off
),
11365 objfile_name (objfile
));
11369 excludes
.push_back (imported_name
);
11371 process_die (child_die
, cu
);
11374 add_using_directive (using_directives (cu
),
11378 imported_declaration
,
11381 &objfile
->objfile_obstack
);
11384 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11385 types, but gives them a size of zero. Starting with version 14,
11386 ICC is compatible with GCC. */
11389 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11391 if (!cu
->checked_producer
)
11392 check_producer (cu
);
11394 return cu
->producer_is_icc_lt_14
;
11397 /* ICC generates a DW_AT_type for C void functions. This was observed on
11398 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11399 which says that void functions should not have a DW_AT_type. */
11402 producer_is_icc (struct dwarf2_cu
*cu
)
11404 if (!cu
->checked_producer
)
11405 check_producer (cu
);
11407 return cu
->producer_is_icc
;
11410 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11411 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11412 this, it was first present in GCC release 4.3.0. */
11415 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11417 if (!cu
->checked_producer
)
11418 check_producer (cu
);
11420 return cu
->producer_is_gcc_lt_4_3
;
11423 static file_and_directory
11424 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11426 file_and_directory res
;
11428 /* Find the filename. Do not use dwarf2_name here, since the filename
11429 is not a source language identifier. */
11430 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11431 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11433 if (res
.comp_dir
== NULL
11434 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11435 && IS_ABSOLUTE_PATH (res
.name
))
11437 res
.comp_dir_storage
= ldirname (res
.name
);
11438 if (!res
.comp_dir_storage
.empty ())
11439 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11441 if (res
.comp_dir
!= NULL
)
11443 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11444 directory, get rid of it. */
11445 const char *cp
= strchr (res
.comp_dir
, ':');
11447 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11448 res
.comp_dir
= cp
+ 1;
11451 if (res
.name
== NULL
)
11452 res
.name
= "<unknown>";
11457 /* Handle DW_AT_stmt_list for a compilation unit.
11458 DIE is the DW_TAG_compile_unit die for CU.
11459 COMP_DIR is the compilation directory. LOWPC is passed to
11460 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11463 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11464 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11466 struct dwarf2_per_objfile
*dwarf2_per_objfile
11467 = cu
->per_cu
->dwarf2_per_objfile
;
11468 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11469 struct attribute
*attr
;
11470 struct line_header line_header_local
;
11471 hashval_t line_header_local_hash
;
11473 int decode_mapping
;
11475 gdb_assert (! cu
->per_cu
->is_debug_types
);
11477 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11481 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11483 /* The line header hash table is only created if needed (it exists to
11484 prevent redundant reading of the line table for partial_units).
11485 If we're given a partial_unit, we'll need it. If we're given a
11486 compile_unit, then use the line header hash table if it's already
11487 created, but don't create one just yet. */
11489 if (dwarf2_per_objfile
->line_header_hash
== NULL
11490 && die
->tag
== DW_TAG_partial_unit
)
11492 dwarf2_per_objfile
->line_header_hash
11493 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11494 line_header_eq_voidp
,
11495 free_line_header_voidp
,
11496 &objfile
->objfile_obstack
,
11497 hashtab_obstack_allocate
,
11498 dummy_obstack_deallocate
);
11501 line_header_local
.sect_off
= line_offset
;
11502 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11503 line_header_local_hash
= line_header_hash (&line_header_local
);
11504 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11506 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11507 &line_header_local
,
11508 line_header_local_hash
, NO_INSERT
);
11510 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11511 is not present in *SLOT (since if there is something in *SLOT then
11512 it will be for a partial_unit). */
11513 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11515 gdb_assert (*slot
!= NULL
);
11516 cu
->line_header
= (struct line_header
*) *slot
;
11521 /* dwarf_decode_line_header does not yet provide sufficient information.
11522 We always have to call also dwarf_decode_lines for it. */
11523 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11527 cu
->line_header
= lh
.release ();
11528 cu
->line_header_die_owner
= die
;
11530 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11534 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11535 &line_header_local
,
11536 line_header_local_hash
, INSERT
);
11537 gdb_assert (slot
!= NULL
);
11539 if (slot
!= NULL
&& *slot
== NULL
)
11541 /* This newly decoded line number information unit will be owned
11542 by line_header_hash hash table. */
11543 *slot
= cu
->line_header
;
11544 cu
->line_header_die_owner
= NULL
;
11548 /* We cannot free any current entry in (*slot) as that struct line_header
11549 may be already used by multiple CUs. Create only temporary decoded
11550 line_header for this CU - it may happen at most once for each line
11551 number information unit. And if we're not using line_header_hash
11552 then this is what we want as well. */
11553 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11555 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11556 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11561 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11564 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11566 struct dwarf2_per_objfile
*dwarf2_per_objfile
11567 = cu
->per_cu
->dwarf2_per_objfile
;
11568 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11569 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11570 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11571 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11572 struct attribute
*attr
;
11573 struct die_info
*child_die
;
11574 CORE_ADDR baseaddr
;
11576 prepare_one_comp_unit (cu
, die
, cu
->language
);
11577 baseaddr
= objfile
->text_section_offset ();
11579 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11581 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11582 from finish_block. */
11583 if (lowpc
== ((CORE_ADDR
) -1))
11585 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11587 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11589 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11590 standardised yet. As a workaround for the language detection we fall
11591 back to the DW_AT_producer string. */
11592 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11593 cu
->language
= language_opencl
;
11595 /* Similar hack for Go. */
11596 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11597 set_cu_language (DW_LANG_Go
, cu
);
11599 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11601 /* Decode line number information if present. We do this before
11602 processing child DIEs, so that the line header table is available
11603 for DW_AT_decl_file. */
11604 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11606 /* Process all dies in compilation unit. */
11607 if (die
->child
!= NULL
)
11609 child_die
= die
->child
;
11610 while (child_die
&& child_die
->tag
)
11612 process_die (child_die
, cu
);
11613 child_die
= sibling_die (child_die
);
11617 /* Decode macro information, if present. Dwarf 2 macro information
11618 refers to information in the line number info statement program
11619 header, so we can only read it if we've read the header
11621 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11623 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11624 if (attr
&& cu
->line_header
)
11626 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11627 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11629 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11633 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11634 if (attr
&& cu
->line_header
)
11636 unsigned int macro_offset
= DW_UNSND (attr
);
11638 dwarf_decode_macros (cu
, macro_offset
, 0);
11644 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11646 struct type_unit_group
*tu_group
;
11648 struct attribute
*attr
;
11650 struct signatured_type
*sig_type
;
11652 gdb_assert (per_cu
->is_debug_types
);
11653 sig_type
= (struct signatured_type
*) per_cu
;
11655 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11657 /* If we're using .gdb_index (includes -readnow) then
11658 per_cu->type_unit_group may not have been set up yet. */
11659 if (sig_type
->type_unit_group
== NULL
)
11660 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11661 tu_group
= sig_type
->type_unit_group
;
11663 /* If we've already processed this stmt_list there's no real need to
11664 do it again, we could fake it and just recreate the part we need
11665 (file name,index -> symtab mapping). If data shows this optimization
11666 is useful we can do it then. */
11667 first_time
= tu_group
->compunit_symtab
== NULL
;
11669 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11674 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11675 lh
= dwarf_decode_line_header (line_offset
, this);
11680 start_symtab ("", NULL
, 0);
11683 gdb_assert (tu_group
->symtabs
== NULL
);
11684 gdb_assert (m_builder
== nullptr);
11685 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11686 m_builder
.reset (new struct buildsym_compunit
11687 (COMPUNIT_OBJFILE (cust
), "",
11688 COMPUNIT_DIRNAME (cust
),
11689 compunit_language (cust
),
11695 line_header
= lh
.release ();
11696 line_header_die_owner
= die
;
11700 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11702 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11703 still initializing it, and our caller (a few levels up)
11704 process_full_type_unit still needs to know if this is the first
11707 tu_group
->num_symtabs
= line_header
->file_names_size ();
11708 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11709 line_header
->file_names_size ());
11711 auto &file_names
= line_header
->file_names ();
11712 for (i
= 0; i
< file_names
.size (); ++i
)
11714 file_entry
&fe
= file_names
[i
];
11715 dwarf2_start_subfile (this, fe
.name
,
11716 fe
.include_dir (line_header
));
11717 buildsym_compunit
*b
= get_builder ();
11718 if (b
->get_current_subfile ()->symtab
== NULL
)
11720 /* NOTE: start_subfile will recognize when it's been
11721 passed a file it has already seen. So we can't
11722 assume there's a simple mapping from
11723 cu->line_header->file_names to subfiles, plus
11724 cu->line_header->file_names may contain dups. */
11725 b
->get_current_subfile ()->symtab
11726 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11729 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11730 tu_group
->symtabs
[i
] = fe
.symtab
;
11735 gdb_assert (m_builder
== nullptr);
11736 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11737 m_builder
.reset (new struct buildsym_compunit
11738 (COMPUNIT_OBJFILE (cust
), "",
11739 COMPUNIT_DIRNAME (cust
),
11740 compunit_language (cust
),
11743 auto &file_names
= line_header
->file_names ();
11744 for (i
= 0; i
< file_names
.size (); ++i
)
11746 file_entry
&fe
= file_names
[i
];
11747 fe
.symtab
= tu_group
->symtabs
[i
];
11751 /* The main symtab is allocated last. Type units don't have DW_AT_name
11752 so they don't have a "real" (so to speak) symtab anyway.
11753 There is later code that will assign the main symtab to all symbols
11754 that don't have one. We need to handle the case of a symbol with a
11755 missing symtab (DW_AT_decl_file) anyway. */
11758 /* Process DW_TAG_type_unit.
11759 For TUs we want to skip the first top level sibling if it's not the
11760 actual type being defined by this TU. In this case the first top
11761 level sibling is there to provide context only. */
11764 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11766 struct die_info
*child_die
;
11768 prepare_one_comp_unit (cu
, die
, language_minimal
);
11770 /* Initialize (or reinitialize) the machinery for building symtabs.
11771 We do this before processing child DIEs, so that the line header table
11772 is available for DW_AT_decl_file. */
11773 cu
->setup_type_unit_groups (die
);
11775 if (die
->child
!= NULL
)
11777 child_die
= die
->child
;
11778 while (child_die
&& child_die
->tag
)
11780 process_die (child_die
, cu
);
11781 child_die
= sibling_die (child_die
);
11788 http://gcc.gnu.org/wiki/DebugFission
11789 http://gcc.gnu.org/wiki/DebugFissionDWP
11791 To simplify handling of both DWO files ("object" files with the DWARF info)
11792 and DWP files (a file with the DWOs packaged up into one file), we treat
11793 DWP files as having a collection of virtual DWO files. */
11796 hash_dwo_file (const void *item
)
11798 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11801 hash
= htab_hash_string (dwo_file
->dwo_name
);
11802 if (dwo_file
->comp_dir
!= NULL
)
11803 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11808 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11810 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11811 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11813 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11815 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11816 return lhs
->comp_dir
== rhs
->comp_dir
;
11817 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11820 /* Allocate a hash table for DWO files. */
11823 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11825 auto delete_dwo_file
= [] (void *item
)
11827 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11832 return htab_up (htab_create_alloc_ex (41,
11836 &objfile
->objfile_obstack
,
11837 hashtab_obstack_allocate
,
11838 dummy_obstack_deallocate
));
11841 /* Lookup DWO file DWO_NAME. */
11844 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11845 const char *dwo_name
,
11846 const char *comp_dir
)
11848 struct dwo_file find_entry
;
11851 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11852 dwarf2_per_objfile
->dwo_files
11853 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11855 find_entry
.dwo_name
= dwo_name
;
11856 find_entry
.comp_dir
= comp_dir
;
11857 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11864 hash_dwo_unit (const void *item
)
11866 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11868 /* This drops the top 32 bits of the id, but is ok for a hash. */
11869 return dwo_unit
->signature
;
11873 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11875 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11876 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11878 /* The signature is assumed to be unique within the DWO file.
11879 So while object file CU dwo_id's always have the value zero,
11880 that's OK, assuming each object file DWO file has only one CU,
11881 and that's the rule for now. */
11882 return lhs
->signature
== rhs
->signature
;
11885 /* Allocate a hash table for DWO CUs,TUs.
11886 There is one of these tables for each of CUs,TUs for each DWO file. */
11889 allocate_dwo_unit_table (struct objfile
*objfile
)
11891 /* Start out with a pretty small number.
11892 Generally DWO files contain only one CU and maybe some TUs. */
11893 return htab_create_alloc_ex (3,
11897 &objfile
->objfile_obstack
,
11898 hashtab_obstack_allocate
,
11899 dummy_obstack_deallocate
);
11902 /* die_reader_func for create_dwo_cu. */
11905 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11906 const gdb_byte
*info_ptr
,
11907 struct die_info
*comp_unit_die
,
11909 struct dwo_file
*dwo_file
,
11910 struct dwo_unit
*dwo_unit
)
11912 struct dwarf2_cu
*cu
= reader
->cu
;
11913 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11914 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11916 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11917 if (!signature
.has_value ())
11919 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11920 " its dwo_id [in module %s]"),
11921 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11925 dwo_unit
->dwo_file
= dwo_file
;
11926 dwo_unit
->signature
= *signature
;
11927 dwo_unit
->section
= section
;
11928 dwo_unit
->sect_off
= sect_off
;
11929 dwo_unit
->length
= cu
->per_cu
->length
;
11931 if (dwarf_read_debug
)
11932 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11933 sect_offset_str (sect_off
),
11934 hex_string (dwo_unit
->signature
));
11937 /* Create the dwo_units for the CUs in a DWO_FILE.
11938 Note: This function processes DWO files only, not DWP files. */
11941 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11942 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11943 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11945 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11946 const gdb_byte
*info_ptr
, *end_ptr
;
11948 dwarf2_read_section (objfile
, §ion
);
11949 info_ptr
= section
.buffer
;
11951 if (info_ptr
== NULL
)
11954 if (dwarf_read_debug
)
11956 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11957 get_section_name (§ion
),
11958 get_section_file_name (§ion
));
11961 end_ptr
= info_ptr
+ section
.size
;
11962 while (info_ptr
< end_ptr
)
11964 struct dwarf2_per_cu_data per_cu
;
11965 struct dwo_unit read_unit
{};
11966 struct dwo_unit
*dwo_unit
;
11968 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11970 memset (&per_cu
, 0, sizeof (per_cu
));
11971 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11972 per_cu
.is_debug_types
= 0;
11973 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
11974 per_cu
.section
= §ion
;
11976 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
11977 if (!reader
.dummy_p
)
11978 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
11979 reader
.has_children
, &dwo_file
, &read_unit
);
11980 info_ptr
+= per_cu
.length
;
11982 // If the unit could not be parsed, skip it.
11983 if (read_unit
.dwo_file
== NULL
)
11986 if (cus_htab
== NULL
)
11987 cus_htab
= allocate_dwo_unit_table (objfile
);
11989 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
11990 *dwo_unit
= read_unit
;
11991 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
11992 gdb_assert (slot
!= NULL
);
11995 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
11996 sect_offset dup_sect_off
= dup_cu
->sect_off
;
11998 complaint (_("debug cu entry at offset %s is duplicate to"
11999 " the entry at offset %s, signature %s"),
12000 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12001 hex_string (dwo_unit
->signature
));
12003 *slot
= (void *)dwo_unit
;
12007 /* DWP file .debug_{cu,tu}_index section format:
12008 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12012 Both index sections have the same format, and serve to map a 64-bit
12013 signature to a set of section numbers. Each section begins with a header,
12014 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12015 indexes, and a pool of 32-bit section numbers. The index sections will be
12016 aligned at 8-byte boundaries in the file.
12018 The index section header consists of:
12020 V, 32 bit version number
12022 N, 32 bit number of compilation units or type units in the index
12023 M, 32 bit number of slots in the hash table
12025 Numbers are recorded using the byte order of the application binary.
12027 The hash table begins at offset 16 in the section, and consists of an array
12028 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12029 order of the application binary). Unused slots in the hash table are 0.
12030 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12032 The parallel table begins immediately after the hash table
12033 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12034 array of 32-bit indexes (using the byte order of the application binary),
12035 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12036 table contains a 32-bit index into the pool of section numbers. For unused
12037 hash table slots, the corresponding entry in the parallel table will be 0.
12039 The pool of section numbers begins immediately following the hash table
12040 (at offset 16 + 12 * M from the beginning of the section). The pool of
12041 section numbers consists of an array of 32-bit words (using the byte order
12042 of the application binary). Each item in the array is indexed starting
12043 from 0. The hash table entry provides the index of the first section
12044 number in the set. Additional section numbers in the set follow, and the
12045 set is terminated by a 0 entry (section number 0 is not used in ELF).
12047 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12048 section must be the first entry in the set, and the .debug_abbrev.dwo must
12049 be the second entry. Other members of the set may follow in any order.
12055 DWP Version 2 combines all the .debug_info, etc. sections into one,
12056 and the entries in the index tables are now offsets into these sections.
12057 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12060 Index Section Contents:
12062 Hash Table of Signatures dwp_hash_table.hash_table
12063 Parallel Table of Indices dwp_hash_table.unit_table
12064 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12065 Table of Section Sizes dwp_hash_table.v2.sizes
12067 The index section header consists of:
12069 V, 32 bit version number
12070 L, 32 bit number of columns in the table of section offsets
12071 N, 32 bit number of compilation units or type units in the index
12072 M, 32 bit number of slots in the hash table
12074 Numbers are recorded using the byte order of the application binary.
12076 The hash table has the same format as version 1.
12077 The parallel table of indices has the same format as version 1,
12078 except that the entries are origin-1 indices into the table of sections
12079 offsets and the table of section sizes.
12081 The table of offsets begins immediately following the parallel table
12082 (at offset 16 + 12 * M from the beginning of the section). The table is
12083 a two-dimensional array of 32-bit words (using the byte order of the
12084 application binary), with L columns and N+1 rows, in row-major order.
12085 Each row in the array is indexed starting from 0. The first row provides
12086 a key to the remaining rows: each column in this row provides an identifier
12087 for a debug section, and the offsets in the same column of subsequent rows
12088 refer to that section. The section identifiers are:
12090 DW_SECT_INFO 1 .debug_info.dwo
12091 DW_SECT_TYPES 2 .debug_types.dwo
12092 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12093 DW_SECT_LINE 4 .debug_line.dwo
12094 DW_SECT_LOC 5 .debug_loc.dwo
12095 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12096 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12097 DW_SECT_MACRO 8 .debug_macro.dwo
12099 The offsets provided by the CU and TU index sections are the base offsets
12100 for the contributions made by each CU or TU to the corresponding section
12101 in the package file. Each CU and TU header contains an abbrev_offset
12102 field, used to find the abbreviations table for that CU or TU within the
12103 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12104 be interpreted as relative to the base offset given in the index section.
12105 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12106 should be interpreted as relative to the base offset for .debug_line.dwo,
12107 and offsets into other debug sections obtained from DWARF attributes should
12108 also be interpreted as relative to the corresponding base offset.
12110 The table of sizes begins immediately following the table of offsets.
12111 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12112 with L columns and N rows, in row-major order. Each row in the array is
12113 indexed starting from 1 (row 0 is shared by the two tables).
12117 Hash table lookup is handled the same in version 1 and 2:
12119 We assume that N and M will not exceed 2^32 - 1.
12120 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12122 Given a 64-bit compilation unit signature or a type signature S, an entry
12123 in the hash table is located as follows:
12125 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12126 the low-order k bits all set to 1.
12128 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12130 3) If the hash table entry at index H matches the signature, use that
12131 entry. If the hash table entry at index H is unused (all zeroes),
12132 terminate the search: the signature is not present in the table.
12134 4) Let H = (H + H') modulo M. Repeat at Step 3.
12136 Because M > N and H' and M are relatively prime, the search is guaranteed
12137 to stop at an unused slot or find the match. */
12139 /* Create a hash table to map DWO IDs to their CU/TU entry in
12140 .debug_{info,types}.dwo in DWP_FILE.
12141 Returns NULL if there isn't one.
12142 Note: This function processes DWP files only, not DWO files. */
12144 static struct dwp_hash_table
*
12145 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12146 struct dwp_file
*dwp_file
, int is_debug_types
)
12148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12149 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12150 const gdb_byte
*index_ptr
, *index_end
;
12151 struct dwarf2_section_info
*index
;
12152 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12153 struct dwp_hash_table
*htab
;
12155 if (is_debug_types
)
12156 index
= &dwp_file
->sections
.tu_index
;
12158 index
= &dwp_file
->sections
.cu_index
;
12160 if (dwarf2_section_empty_p (index
))
12162 dwarf2_read_section (objfile
, index
);
12164 index_ptr
= index
->buffer
;
12165 index_end
= index_ptr
+ index
->size
;
12167 version
= read_4_bytes (dbfd
, index_ptr
);
12170 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12174 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12176 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12179 if (version
!= 1 && version
!= 2)
12181 error (_("Dwarf Error: unsupported DWP file version (%s)"
12182 " [in module %s]"),
12183 pulongest (version
), dwp_file
->name
);
12185 if (nr_slots
!= (nr_slots
& -nr_slots
))
12187 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12188 " is not power of 2 [in module %s]"),
12189 pulongest (nr_slots
), dwp_file
->name
);
12192 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12193 htab
->version
= version
;
12194 htab
->nr_columns
= nr_columns
;
12195 htab
->nr_units
= nr_units
;
12196 htab
->nr_slots
= nr_slots
;
12197 htab
->hash_table
= index_ptr
;
12198 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12200 /* Exit early if the table is empty. */
12201 if (nr_slots
== 0 || nr_units
== 0
12202 || (version
== 2 && nr_columns
== 0))
12204 /* All must be zero. */
12205 if (nr_slots
!= 0 || nr_units
!= 0
12206 || (version
== 2 && nr_columns
!= 0))
12208 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12209 " all zero [in modules %s]"),
12217 htab
->section_pool
.v1
.indices
=
12218 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12219 /* It's harder to decide whether the section is too small in v1.
12220 V1 is deprecated anyway so we punt. */
12224 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12225 int *ids
= htab
->section_pool
.v2
.section_ids
;
12226 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12227 /* Reverse map for error checking. */
12228 int ids_seen
[DW_SECT_MAX
+ 1];
12231 if (nr_columns
< 2)
12233 error (_("Dwarf Error: bad DWP hash table, too few columns"
12234 " in section table [in module %s]"),
12237 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12239 error (_("Dwarf Error: bad DWP hash table, too many columns"
12240 " in section table [in module %s]"),
12243 memset (ids
, 255, sizeof_ids
);
12244 memset (ids_seen
, 255, sizeof (ids_seen
));
12245 for (i
= 0; i
< nr_columns
; ++i
)
12247 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12249 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12251 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12252 " in section table [in module %s]"),
12253 id
, dwp_file
->name
);
12255 if (ids_seen
[id
] != -1)
12257 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12258 " id %d in section table [in module %s]"),
12259 id
, dwp_file
->name
);
12264 /* Must have exactly one info or types section. */
12265 if (((ids_seen
[DW_SECT_INFO
] != -1)
12266 + (ids_seen
[DW_SECT_TYPES
] != -1))
12269 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12270 " DWO info/types section [in module %s]"),
12273 /* Must have an abbrev section. */
12274 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12276 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12277 " section [in module %s]"),
12280 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12281 htab
->section_pool
.v2
.sizes
=
12282 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12283 * nr_units
* nr_columns
);
12284 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12285 * nr_units
* nr_columns
))
12288 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12289 " [in module %s]"),
12297 /* Update SECTIONS with the data from SECTP.
12299 This function is like the other "locate" section routines that are
12300 passed to bfd_map_over_sections, but in this context the sections to
12301 read comes from the DWP V1 hash table, not the full ELF section table.
12303 The result is non-zero for success, or zero if an error was found. */
12306 locate_v1_virtual_dwo_sections (asection
*sectp
,
12307 struct virtual_v1_dwo_sections
*sections
)
12309 const struct dwop_section_names
*names
= &dwop_section_names
;
12311 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12313 /* There can be only one. */
12314 if (sections
->abbrev
.s
.section
!= NULL
)
12316 sections
->abbrev
.s
.section
= sectp
;
12317 sections
->abbrev
.size
= bfd_section_size (sectp
);
12319 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12320 || section_is_p (sectp
->name
, &names
->types_dwo
))
12322 /* There can be only one. */
12323 if (sections
->info_or_types
.s
.section
!= NULL
)
12325 sections
->info_or_types
.s
.section
= sectp
;
12326 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12328 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12330 /* There can be only one. */
12331 if (sections
->line
.s
.section
!= NULL
)
12333 sections
->line
.s
.section
= sectp
;
12334 sections
->line
.size
= bfd_section_size (sectp
);
12336 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12338 /* There can be only one. */
12339 if (sections
->loc
.s
.section
!= NULL
)
12341 sections
->loc
.s
.section
= sectp
;
12342 sections
->loc
.size
= bfd_section_size (sectp
);
12344 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12346 /* There can be only one. */
12347 if (sections
->macinfo
.s
.section
!= NULL
)
12349 sections
->macinfo
.s
.section
= sectp
;
12350 sections
->macinfo
.size
= bfd_section_size (sectp
);
12352 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12354 /* There can be only one. */
12355 if (sections
->macro
.s
.section
!= NULL
)
12357 sections
->macro
.s
.section
= sectp
;
12358 sections
->macro
.size
= bfd_section_size (sectp
);
12360 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12362 /* There can be only one. */
12363 if (sections
->str_offsets
.s
.section
!= NULL
)
12365 sections
->str_offsets
.s
.section
= sectp
;
12366 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12370 /* No other kind of section is valid. */
12377 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12378 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12379 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12380 This is for DWP version 1 files. */
12382 static struct dwo_unit
*
12383 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12384 struct dwp_file
*dwp_file
,
12385 uint32_t unit_index
,
12386 const char *comp_dir
,
12387 ULONGEST signature
, int is_debug_types
)
12389 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12390 const struct dwp_hash_table
*dwp_htab
=
12391 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12392 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12393 const char *kind
= is_debug_types
? "TU" : "CU";
12394 struct dwo_file
*dwo_file
;
12395 struct dwo_unit
*dwo_unit
;
12396 struct virtual_v1_dwo_sections sections
;
12397 void **dwo_file_slot
;
12400 gdb_assert (dwp_file
->version
== 1);
12402 if (dwarf_read_debug
)
12404 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12406 pulongest (unit_index
), hex_string (signature
),
12410 /* Fetch the sections of this DWO unit.
12411 Put a limit on the number of sections we look for so that bad data
12412 doesn't cause us to loop forever. */
12414 #define MAX_NR_V1_DWO_SECTIONS \
12415 (1 /* .debug_info or .debug_types */ \
12416 + 1 /* .debug_abbrev */ \
12417 + 1 /* .debug_line */ \
12418 + 1 /* .debug_loc */ \
12419 + 1 /* .debug_str_offsets */ \
12420 + 1 /* .debug_macro or .debug_macinfo */ \
12421 + 1 /* trailing zero */)
12423 memset (§ions
, 0, sizeof (sections
));
12425 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12428 uint32_t section_nr
=
12429 read_4_bytes (dbfd
,
12430 dwp_htab
->section_pool
.v1
.indices
12431 + (unit_index
+ i
) * sizeof (uint32_t));
12433 if (section_nr
== 0)
12435 if (section_nr
>= dwp_file
->num_sections
)
12437 error (_("Dwarf Error: bad DWP hash table, section number too large"
12438 " [in module %s]"),
12442 sectp
= dwp_file
->elf_sections
[section_nr
];
12443 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12445 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12446 " [in module %s]"),
12452 || dwarf2_section_empty_p (§ions
.info_or_types
)
12453 || dwarf2_section_empty_p (§ions
.abbrev
))
12455 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12456 " [in module %s]"),
12459 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12461 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12462 " [in module %s]"),
12466 /* It's easier for the rest of the code if we fake a struct dwo_file and
12467 have dwo_unit "live" in that. At least for now.
12469 The DWP file can be made up of a random collection of CUs and TUs.
12470 However, for each CU + set of TUs that came from the same original DWO
12471 file, we can combine them back into a virtual DWO file to save space
12472 (fewer struct dwo_file objects to allocate). Remember that for really
12473 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12475 std::string virtual_dwo_name
=
12476 string_printf ("virtual-dwo/%d-%d-%d-%d",
12477 get_section_id (§ions
.abbrev
),
12478 get_section_id (§ions
.line
),
12479 get_section_id (§ions
.loc
),
12480 get_section_id (§ions
.str_offsets
));
12481 /* Can we use an existing virtual DWO file? */
12482 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12483 virtual_dwo_name
.c_str (),
12485 /* Create one if necessary. */
12486 if (*dwo_file_slot
== NULL
)
12488 if (dwarf_read_debug
)
12490 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12491 virtual_dwo_name
.c_str ());
12493 dwo_file
= new struct dwo_file
;
12494 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12496 dwo_file
->comp_dir
= comp_dir
;
12497 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12498 dwo_file
->sections
.line
= sections
.line
;
12499 dwo_file
->sections
.loc
= sections
.loc
;
12500 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12501 dwo_file
->sections
.macro
= sections
.macro
;
12502 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12503 /* The "str" section is global to the entire DWP file. */
12504 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12505 /* The info or types section is assigned below to dwo_unit,
12506 there's no need to record it in dwo_file.
12507 Also, we can't simply record type sections in dwo_file because
12508 we record a pointer into the vector in dwo_unit. As we collect more
12509 types we'll grow the vector and eventually have to reallocate space
12510 for it, invalidating all copies of pointers into the previous
12512 *dwo_file_slot
= dwo_file
;
12516 if (dwarf_read_debug
)
12518 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12519 virtual_dwo_name
.c_str ());
12521 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12524 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12525 dwo_unit
->dwo_file
= dwo_file
;
12526 dwo_unit
->signature
= signature
;
12527 dwo_unit
->section
=
12528 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12529 *dwo_unit
->section
= sections
.info_or_types
;
12530 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12535 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12536 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12537 piece within that section used by a TU/CU, return a virtual section
12538 of just that piece. */
12540 static struct dwarf2_section_info
12541 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12542 struct dwarf2_section_info
*section
,
12543 bfd_size_type offset
, bfd_size_type size
)
12545 struct dwarf2_section_info result
;
12548 gdb_assert (section
!= NULL
);
12549 gdb_assert (!section
->is_virtual
);
12551 memset (&result
, 0, sizeof (result
));
12552 result
.s
.containing_section
= section
;
12553 result
.is_virtual
= true;
12558 sectp
= get_section_bfd_section (section
);
12560 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12561 bounds of the real section. This is a pretty-rare event, so just
12562 flag an error (easier) instead of a warning and trying to cope. */
12564 || offset
+ size
> bfd_section_size (sectp
))
12566 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12567 " in section %s [in module %s]"),
12568 sectp
? bfd_section_name (sectp
) : "<unknown>",
12569 objfile_name (dwarf2_per_objfile
->objfile
));
12572 result
.virtual_offset
= offset
;
12573 result
.size
= size
;
12577 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12578 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12579 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12580 This is for DWP version 2 files. */
12582 static struct dwo_unit
*
12583 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12584 struct dwp_file
*dwp_file
,
12585 uint32_t unit_index
,
12586 const char *comp_dir
,
12587 ULONGEST signature
, int is_debug_types
)
12589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12590 const struct dwp_hash_table
*dwp_htab
=
12591 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12592 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12593 const char *kind
= is_debug_types
? "TU" : "CU";
12594 struct dwo_file
*dwo_file
;
12595 struct dwo_unit
*dwo_unit
;
12596 struct virtual_v2_dwo_sections sections
;
12597 void **dwo_file_slot
;
12600 gdb_assert (dwp_file
->version
== 2);
12602 if (dwarf_read_debug
)
12604 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12606 pulongest (unit_index
), hex_string (signature
),
12610 /* Fetch the section offsets of this DWO unit. */
12612 memset (§ions
, 0, sizeof (sections
));
12614 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12616 uint32_t offset
= read_4_bytes (dbfd
,
12617 dwp_htab
->section_pool
.v2
.offsets
12618 + (((unit_index
- 1) * dwp_htab
->nr_columns
12620 * sizeof (uint32_t)));
12621 uint32_t size
= read_4_bytes (dbfd
,
12622 dwp_htab
->section_pool
.v2
.sizes
12623 + (((unit_index
- 1) * dwp_htab
->nr_columns
12625 * sizeof (uint32_t)));
12627 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12630 case DW_SECT_TYPES
:
12631 sections
.info_or_types_offset
= offset
;
12632 sections
.info_or_types_size
= size
;
12634 case DW_SECT_ABBREV
:
12635 sections
.abbrev_offset
= offset
;
12636 sections
.abbrev_size
= size
;
12639 sections
.line_offset
= offset
;
12640 sections
.line_size
= size
;
12643 sections
.loc_offset
= offset
;
12644 sections
.loc_size
= size
;
12646 case DW_SECT_STR_OFFSETS
:
12647 sections
.str_offsets_offset
= offset
;
12648 sections
.str_offsets_size
= size
;
12650 case DW_SECT_MACINFO
:
12651 sections
.macinfo_offset
= offset
;
12652 sections
.macinfo_size
= size
;
12654 case DW_SECT_MACRO
:
12655 sections
.macro_offset
= offset
;
12656 sections
.macro_size
= size
;
12661 /* It's easier for the rest of the code if we fake a struct dwo_file and
12662 have dwo_unit "live" in that. At least for now.
12664 The DWP file can be made up of a random collection of CUs and TUs.
12665 However, for each CU + set of TUs that came from the same original DWO
12666 file, we can combine them back into a virtual DWO file to save space
12667 (fewer struct dwo_file objects to allocate). Remember that for really
12668 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12670 std::string virtual_dwo_name
=
12671 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12672 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12673 (long) (sections
.line_size
? sections
.line_offset
: 0),
12674 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12675 (long) (sections
.str_offsets_size
12676 ? sections
.str_offsets_offset
: 0));
12677 /* Can we use an existing virtual DWO file? */
12678 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12679 virtual_dwo_name
.c_str (),
12681 /* Create one if necessary. */
12682 if (*dwo_file_slot
== NULL
)
12684 if (dwarf_read_debug
)
12686 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12687 virtual_dwo_name
.c_str ());
12689 dwo_file
= new struct dwo_file
;
12690 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12692 dwo_file
->comp_dir
= comp_dir
;
12693 dwo_file
->sections
.abbrev
=
12694 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12695 sections
.abbrev_offset
, sections
.abbrev_size
);
12696 dwo_file
->sections
.line
=
12697 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12698 sections
.line_offset
, sections
.line_size
);
12699 dwo_file
->sections
.loc
=
12700 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12701 sections
.loc_offset
, sections
.loc_size
);
12702 dwo_file
->sections
.macinfo
=
12703 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12704 sections
.macinfo_offset
, sections
.macinfo_size
);
12705 dwo_file
->sections
.macro
=
12706 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12707 sections
.macro_offset
, sections
.macro_size
);
12708 dwo_file
->sections
.str_offsets
=
12709 create_dwp_v2_section (dwarf2_per_objfile
,
12710 &dwp_file
->sections
.str_offsets
,
12711 sections
.str_offsets_offset
,
12712 sections
.str_offsets_size
);
12713 /* The "str" section is global to the entire DWP file. */
12714 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12715 /* The info or types section is assigned below to dwo_unit,
12716 there's no need to record it in dwo_file.
12717 Also, we can't simply record type sections in dwo_file because
12718 we record a pointer into the vector in dwo_unit. As we collect more
12719 types we'll grow the vector and eventually have to reallocate space
12720 for it, invalidating all copies of pointers into the previous
12722 *dwo_file_slot
= dwo_file
;
12726 if (dwarf_read_debug
)
12728 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12729 virtual_dwo_name
.c_str ());
12731 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12734 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12735 dwo_unit
->dwo_file
= dwo_file
;
12736 dwo_unit
->signature
= signature
;
12737 dwo_unit
->section
=
12738 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12739 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12741 ? &dwp_file
->sections
.types
12742 : &dwp_file
->sections
.info
,
12743 sections
.info_or_types_offset
,
12744 sections
.info_or_types_size
);
12745 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12750 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12751 Returns NULL if the signature isn't found. */
12753 static struct dwo_unit
*
12754 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12755 struct dwp_file
*dwp_file
, const char *comp_dir
,
12756 ULONGEST signature
, int is_debug_types
)
12758 const struct dwp_hash_table
*dwp_htab
=
12759 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12760 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12761 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12762 uint32_t hash
= signature
& mask
;
12763 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12766 struct dwo_unit find_dwo_cu
;
12768 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12769 find_dwo_cu
.signature
= signature
;
12770 slot
= htab_find_slot (is_debug_types
12771 ? dwp_file
->loaded_tus
12772 : dwp_file
->loaded_cus
,
12773 &find_dwo_cu
, INSERT
);
12776 return (struct dwo_unit
*) *slot
;
12778 /* Use a for loop so that we don't loop forever on bad debug info. */
12779 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12781 ULONGEST signature_in_table
;
12783 signature_in_table
=
12784 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12785 if (signature_in_table
== signature
)
12787 uint32_t unit_index
=
12788 read_4_bytes (dbfd
,
12789 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12791 if (dwp_file
->version
== 1)
12793 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12794 dwp_file
, unit_index
,
12795 comp_dir
, signature
,
12800 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12801 dwp_file
, unit_index
,
12802 comp_dir
, signature
,
12805 return (struct dwo_unit
*) *slot
;
12807 if (signature_in_table
== 0)
12809 hash
= (hash
+ hash2
) & mask
;
12812 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12813 " [in module %s]"),
12817 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12818 Open the file specified by FILE_NAME and hand it off to BFD for
12819 preliminary analysis. Return a newly initialized bfd *, which
12820 includes a canonicalized copy of FILE_NAME.
12821 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12822 SEARCH_CWD is true if the current directory is to be searched.
12823 It will be searched before debug-file-directory.
12824 If successful, the file is added to the bfd include table of the
12825 objfile's bfd (see gdb_bfd_record_inclusion).
12826 If unable to find/open the file, return NULL.
12827 NOTE: This function is derived from symfile_bfd_open. */
12829 static gdb_bfd_ref_ptr
12830 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12831 const char *file_name
, int is_dwp
, int search_cwd
)
12834 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12835 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12836 to debug_file_directory. */
12837 const char *search_path
;
12838 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12840 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12843 if (*debug_file_directory
!= '\0')
12845 search_path_holder
.reset (concat (".", dirname_separator_string
,
12846 debug_file_directory
,
12848 search_path
= search_path_holder
.get ();
12854 search_path
= debug_file_directory
;
12856 openp_flags flags
= OPF_RETURN_REALPATH
;
12858 flags
|= OPF_SEARCH_IN_PATH
;
12860 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12861 desc
= openp (search_path
, flags
, file_name
,
12862 O_RDONLY
| O_BINARY
, &absolute_name
);
12866 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12868 if (sym_bfd
== NULL
)
12870 bfd_set_cacheable (sym_bfd
.get (), 1);
12872 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12875 /* Success. Record the bfd as having been included by the objfile's bfd.
12876 This is important because things like demangled_names_hash lives in the
12877 objfile's per_bfd space and may have references to things like symbol
12878 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12879 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12884 /* Try to open DWO file FILE_NAME.
12885 COMP_DIR is the DW_AT_comp_dir attribute.
12886 The result is the bfd handle of the file.
12887 If there is a problem finding or opening the file, return NULL.
12888 Upon success, the canonicalized path of the file is stored in the bfd,
12889 same as symfile_bfd_open. */
12891 static gdb_bfd_ref_ptr
12892 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12893 const char *file_name
, const char *comp_dir
)
12895 if (IS_ABSOLUTE_PATH (file_name
))
12896 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12897 0 /*is_dwp*/, 0 /*search_cwd*/);
12899 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12901 if (comp_dir
!= NULL
)
12903 gdb::unique_xmalloc_ptr
<char> path_to_try
12904 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12906 /* NOTE: If comp_dir is a relative path, this will also try the
12907 search path, which seems useful. */
12908 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12909 path_to_try
.get (),
12911 1 /*search_cwd*/));
12916 /* That didn't work, try debug-file-directory, which, despite its name,
12917 is a list of paths. */
12919 if (*debug_file_directory
== '\0')
12922 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12923 0 /*is_dwp*/, 1 /*search_cwd*/);
12926 /* This function is mapped across the sections and remembers the offset and
12927 size of each of the DWO debugging sections we are interested in. */
12930 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12932 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12933 const struct dwop_section_names
*names
= &dwop_section_names
;
12935 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12937 dwo_sections
->abbrev
.s
.section
= sectp
;
12938 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12940 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12942 dwo_sections
->info
.s
.section
= sectp
;
12943 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12945 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12947 dwo_sections
->line
.s
.section
= sectp
;
12948 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12950 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12952 dwo_sections
->loc
.s
.section
= sectp
;
12953 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12955 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12957 dwo_sections
->macinfo
.s
.section
= sectp
;
12958 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12960 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12962 dwo_sections
->macro
.s
.section
= sectp
;
12963 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12965 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12967 dwo_sections
->str
.s
.section
= sectp
;
12968 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12970 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12972 dwo_sections
->str_offsets
.s
.section
= sectp
;
12973 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
12975 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
12977 struct dwarf2_section_info type_section
;
12979 memset (&type_section
, 0, sizeof (type_section
));
12980 type_section
.s
.section
= sectp
;
12981 type_section
.size
= bfd_section_size (sectp
);
12982 dwo_sections
->types
.push_back (type_section
);
12986 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
12987 by PER_CU. This is for the non-DWP case.
12988 The result is NULL if DWO_NAME can't be found. */
12990 static struct dwo_file
*
12991 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
12992 const char *dwo_name
, const char *comp_dir
)
12994 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
12996 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
12999 if (dwarf_read_debug
)
13000 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13004 dwo_file_up
dwo_file (new struct dwo_file
);
13005 dwo_file
->dwo_name
= dwo_name
;
13006 dwo_file
->comp_dir
= comp_dir
;
13007 dwo_file
->dbfd
= std::move (dbfd
);
13009 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13010 &dwo_file
->sections
);
13012 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
13013 dwo_file
->sections
.info
, dwo_file
->cus
);
13015 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13016 dwo_file
->sections
.types
, dwo_file
->tus
);
13018 if (dwarf_read_debug
)
13019 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13021 return dwo_file
.release ();
13024 /* This function is mapped across the sections and remembers the offset and
13025 size of each of the DWP debugging sections common to version 1 and 2 that
13026 we are interested in. */
13029 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13030 void *dwp_file_ptr
)
13032 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13033 const struct dwop_section_names
*names
= &dwop_section_names
;
13034 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13036 /* Record the ELF section number for later lookup: this is what the
13037 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13038 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13039 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13041 /* Look for specific sections that we need. */
13042 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13044 dwp_file
->sections
.str
.s
.section
= sectp
;
13045 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13047 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13049 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13050 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13052 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13054 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13055 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13059 /* This function is mapped across the sections and remembers the offset and
13060 size of each of the DWP version 2 debugging sections that we are interested
13061 in. This is split into a separate function because we don't know if we
13062 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13065 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13067 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13068 const struct dwop_section_names
*names
= &dwop_section_names
;
13069 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13071 /* Record the ELF section number for later lookup: this is what the
13072 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13073 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13074 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13076 /* Look for specific sections that we need. */
13077 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13079 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13080 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13082 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13084 dwp_file
->sections
.info
.s
.section
= sectp
;
13085 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13087 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13089 dwp_file
->sections
.line
.s
.section
= sectp
;
13090 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13092 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13094 dwp_file
->sections
.loc
.s
.section
= sectp
;
13095 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13097 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13099 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13100 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13102 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13104 dwp_file
->sections
.macro
.s
.section
= sectp
;
13105 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13107 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13109 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13110 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13112 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13114 dwp_file
->sections
.types
.s
.section
= sectp
;
13115 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13119 /* Hash function for dwp_file loaded CUs/TUs. */
13122 hash_dwp_loaded_cutus (const void *item
)
13124 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13126 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13127 return dwo_unit
->signature
;
13130 /* Equality function for dwp_file loaded CUs/TUs. */
13133 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13135 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13136 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13138 return dua
->signature
== dub
->signature
;
13141 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13144 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13146 return htab_create_alloc_ex (3,
13147 hash_dwp_loaded_cutus
,
13148 eq_dwp_loaded_cutus
,
13150 &objfile
->objfile_obstack
,
13151 hashtab_obstack_allocate
,
13152 dummy_obstack_deallocate
);
13155 /* Try to open DWP file FILE_NAME.
13156 The result is the bfd handle of the file.
13157 If there is a problem finding or opening the file, return NULL.
13158 Upon success, the canonicalized path of the file is stored in the bfd,
13159 same as symfile_bfd_open. */
13161 static gdb_bfd_ref_ptr
13162 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13163 const char *file_name
)
13165 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13167 1 /*search_cwd*/));
13171 /* Work around upstream bug 15652.
13172 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13173 [Whether that's a "bug" is debatable, but it is getting in our way.]
13174 We have no real idea where the dwp file is, because gdb's realpath-ing
13175 of the executable's path may have discarded the needed info.
13176 [IWBN if the dwp file name was recorded in the executable, akin to
13177 .gnu_debuglink, but that doesn't exist yet.]
13178 Strip the directory from FILE_NAME and search again. */
13179 if (*debug_file_directory
!= '\0')
13181 /* Don't implicitly search the current directory here.
13182 If the user wants to search "." to handle this case,
13183 it must be added to debug-file-directory. */
13184 return try_open_dwop_file (dwarf2_per_objfile
,
13185 lbasename (file_name
), 1 /*is_dwp*/,
13192 /* Initialize the use of the DWP file for the current objfile.
13193 By convention the name of the DWP file is ${objfile}.dwp.
13194 The result is NULL if it can't be found. */
13196 static std::unique_ptr
<struct dwp_file
>
13197 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13199 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13201 /* Try to find first .dwp for the binary file before any symbolic links
13204 /* If the objfile is a debug file, find the name of the real binary
13205 file and get the name of dwp file from there. */
13206 std::string dwp_name
;
13207 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13209 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13210 const char *backlink_basename
= lbasename (backlink
->original_name
);
13212 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13215 dwp_name
= objfile
->original_name
;
13217 dwp_name
+= ".dwp";
13219 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13221 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13223 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13224 dwp_name
= objfile_name (objfile
);
13225 dwp_name
+= ".dwp";
13226 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13231 if (dwarf_read_debug
)
13232 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13233 return std::unique_ptr
<dwp_file
> ();
13236 const char *name
= bfd_get_filename (dbfd
.get ());
13237 std::unique_ptr
<struct dwp_file
> dwp_file
13238 (new struct dwp_file (name
, std::move (dbfd
)));
13240 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13241 dwp_file
->elf_sections
=
13242 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13243 dwp_file
->num_sections
, asection
*);
13245 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13246 dwarf2_locate_common_dwp_sections
,
13249 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13252 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13255 /* The DWP file version is stored in the hash table. Oh well. */
13256 if (dwp_file
->cus
&& dwp_file
->tus
13257 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13259 /* Technically speaking, we should try to limp along, but this is
13260 pretty bizarre. We use pulongest here because that's the established
13261 portability solution (e.g, we cannot use %u for uint32_t). */
13262 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13263 " TU version %s [in DWP file %s]"),
13264 pulongest (dwp_file
->cus
->version
),
13265 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13269 dwp_file
->version
= dwp_file
->cus
->version
;
13270 else if (dwp_file
->tus
)
13271 dwp_file
->version
= dwp_file
->tus
->version
;
13273 dwp_file
->version
= 2;
13275 if (dwp_file
->version
== 2)
13276 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13277 dwarf2_locate_v2_dwp_sections
,
13280 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13281 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13283 if (dwarf_read_debug
)
13285 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13286 fprintf_unfiltered (gdb_stdlog
,
13287 " %s CUs, %s TUs\n",
13288 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13289 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13295 /* Wrapper around open_and_init_dwp_file, only open it once. */
13297 static struct dwp_file
*
13298 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13300 if (! dwarf2_per_objfile
->dwp_checked
)
13302 dwarf2_per_objfile
->dwp_file
13303 = open_and_init_dwp_file (dwarf2_per_objfile
);
13304 dwarf2_per_objfile
->dwp_checked
= 1;
13306 return dwarf2_per_objfile
->dwp_file
.get ();
13309 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13310 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13311 or in the DWP file for the objfile, referenced by THIS_UNIT.
13312 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13313 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13315 This is called, for example, when wanting to read a variable with a
13316 complex location. Therefore we don't want to do file i/o for every call.
13317 Therefore we don't want to look for a DWO file on every call.
13318 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13319 then we check if we've already seen DWO_NAME, and only THEN do we check
13322 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13323 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13325 static struct dwo_unit
*
13326 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13327 const char *dwo_name
, const char *comp_dir
,
13328 ULONGEST signature
, int is_debug_types
)
13330 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13331 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13332 const char *kind
= is_debug_types
? "TU" : "CU";
13333 void **dwo_file_slot
;
13334 struct dwo_file
*dwo_file
;
13335 struct dwp_file
*dwp_file
;
13337 /* First see if there's a DWP file.
13338 If we have a DWP file but didn't find the DWO inside it, don't
13339 look for the original DWO file. It makes gdb behave differently
13340 depending on whether one is debugging in the build tree. */
13342 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13343 if (dwp_file
!= NULL
)
13345 const struct dwp_hash_table
*dwp_htab
=
13346 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13348 if (dwp_htab
!= NULL
)
13350 struct dwo_unit
*dwo_cutu
=
13351 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13352 signature
, is_debug_types
);
13354 if (dwo_cutu
!= NULL
)
13356 if (dwarf_read_debug
)
13358 fprintf_unfiltered (gdb_stdlog
,
13359 "Virtual DWO %s %s found: @%s\n",
13360 kind
, hex_string (signature
),
13361 host_address_to_string (dwo_cutu
));
13369 /* No DWP file, look for the DWO file. */
13371 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13372 dwo_name
, comp_dir
);
13373 if (*dwo_file_slot
== NULL
)
13375 /* Read in the file and build a table of the CUs/TUs it contains. */
13376 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13378 /* NOTE: This will be NULL if unable to open the file. */
13379 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13381 if (dwo_file
!= NULL
)
13383 struct dwo_unit
*dwo_cutu
= NULL
;
13385 if (is_debug_types
&& dwo_file
->tus
)
13387 struct dwo_unit find_dwo_cutu
;
13389 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13390 find_dwo_cutu
.signature
= signature
;
13392 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13394 else if (!is_debug_types
&& dwo_file
->cus
)
13396 struct dwo_unit find_dwo_cutu
;
13398 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13399 find_dwo_cutu
.signature
= signature
;
13400 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13404 if (dwo_cutu
!= NULL
)
13406 if (dwarf_read_debug
)
13408 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13409 kind
, dwo_name
, hex_string (signature
),
13410 host_address_to_string (dwo_cutu
));
13417 /* We didn't find it. This could mean a dwo_id mismatch, or
13418 someone deleted the DWO/DWP file, or the search path isn't set up
13419 correctly to find the file. */
13421 if (dwarf_read_debug
)
13423 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13424 kind
, dwo_name
, hex_string (signature
));
13427 /* This is a warning and not a complaint because it can be caused by
13428 pilot error (e.g., user accidentally deleting the DWO). */
13430 /* Print the name of the DWP file if we looked there, helps the user
13431 better diagnose the problem. */
13432 std::string dwp_text
;
13434 if (dwp_file
!= NULL
)
13435 dwp_text
= string_printf (" [in DWP file %s]",
13436 lbasename (dwp_file
->name
));
13438 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13439 " [in module %s]"),
13440 kind
, dwo_name
, hex_string (signature
),
13442 this_unit
->is_debug_types
? "TU" : "CU",
13443 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13448 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13449 See lookup_dwo_cutu_unit for details. */
13451 static struct dwo_unit
*
13452 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13453 const char *dwo_name
, const char *comp_dir
,
13454 ULONGEST signature
)
13456 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13459 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13460 See lookup_dwo_cutu_unit for details. */
13462 static struct dwo_unit
*
13463 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13464 const char *dwo_name
, const char *comp_dir
)
13466 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13469 /* Traversal function for queue_and_load_all_dwo_tus. */
13472 queue_and_load_dwo_tu (void **slot
, void *info
)
13474 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13475 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13476 ULONGEST signature
= dwo_unit
->signature
;
13477 struct signatured_type
*sig_type
=
13478 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13480 if (sig_type
!= NULL
)
13482 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13484 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13485 a real dependency of PER_CU on SIG_TYPE. That is detected later
13486 while processing PER_CU. */
13487 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13488 load_full_type_unit (sig_cu
);
13489 per_cu
->imported_symtabs_push (sig_cu
);
13495 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13496 The DWO may have the only definition of the type, though it may not be
13497 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13498 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13501 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13503 struct dwo_unit
*dwo_unit
;
13504 struct dwo_file
*dwo_file
;
13506 gdb_assert (!per_cu
->is_debug_types
);
13507 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13508 gdb_assert (per_cu
->cu
!= NULL
);
13510 dwo_unit
= per_cu
->cu
->dwo_unit
;
13511 gdb_assert (dwo_unit
!= NULL
);
13513 dwo_file
= dwo_unit
->dwo_file
;
13514 if (dwo_file
->tus
!= NULL
)
13515 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13518 /* Read in various DIEs. */
13520 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13521 Inherit only the children of the DW_AT_abstract_origin DIE not being
13522 already referenced by DW_AT_abstract_origin from the children of the
13526 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13528 struct die_info
*child_die
;
13529 sect_offset
*offsetp
;
13530 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13531 struct die_info
*origin_die
;
13532 /* Iterator of the ORIGIN_DIE children. */
13533 struct die_info
*origin_child_die
;
13534 struct attribute
*attr
;
13535 struct dwarf2_cu
*origin_cu
;
13536 struct pending
**origin_previous_list_in_scope
;
13538 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13542 /* Note that following die references may follow to a die in a
13546 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13548 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13550 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13551 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13553 if (die
->tag
!= origin_die
->tag
13554 && !(die
->tag
== DW_TAG_inlined_subroutine
13555 && origin_die
->tag
== DW_TAG_subprogram
))
13556 complaint (_("DIE %s and its abstract origin %s have different tags"),
13557 sect_offset_str (die
->sect_off
),
13558 sect_offset_str (origin_die
->sect_off
));
13560 std::vector
<sect_offset
> offsets
;
13562 for (child_die
= die
->child
;
13563 child_die
&& child_die
->tag
;
13564 child_die
= sibling_die (child_die
))
13566 struct die_info
*child_origin_die
;
13567 struct dwarf2_cu
*child_origin_cu
;
13569 /* We are trying to process concrete instance entries:
13570 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13571 it's not relevant to our analysis here. i.e. detecting DIEs that are
13572 present in the abstract instance but not referenced in the concrete
13574 if (child_die
->tag
== DW_TAG_call_site
13575 || child_die
->tag
== DW_TAG_GNU_call_site
)
13578 /* For each CHILD_DIE, find the corresponding child of
13579 ORIGIN_DIE. If there is more than one layer of
13580 DW_AT_abstract_origin, follow them all; there shouldn't be,
13581 but GCC versions at least through 4.4 generate this (GCC PR
13583 child_origin_die
= child_die
;
13584 child_origin_cu
= cu
;
13587 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13591 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13595 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13596 counterpart may exist. */
13597 if (child_origin_die
!= child_die
)
13599 if (child_die
->tag
!= child_origin_die
->tag
13600 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13601 && child_origin_die
->tag
== DW_TAG_subprogram
))
13602 complaint (_("Child DIE %s and its abstract origin %s have "
13604 sect_offset_str (child_die
->sect_off
),
13605 sect_offset_str (child_origin_die
->sect_off
));
13606 if (child_origin_die
->parent
!= origin_die
)
13607 complaint (_("Child DIE %s and its abstract origin %s have "
13608 "different parents"),
13609 sect_offset_str (child_die
->sect_off
),
13610 sect_offset_str (child_origin_die
->sect_off
));
13612 offsets
.push_back (child_origin_die
->sect_off
);
13615 std::sort (offsets
.begin (), offsets
.end ());
13616 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13617 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13618 if (offsetp
[-1] == *offsetp
)
13619 complaint (_("Multiple children of DIE %s refer "
13620 "to DIE %s as their abstract origin"),
13621 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13623 offsetp
= offsets
.data ();
13624 origin_child_die
= origin_die
->child
;
13625 while (origin_child_die
&& origin_child_die
->tag
)
13627 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13628 while (offsetp
< offsets_end
13629 && *offsetp
< origin_child_die
->sect_off
)
13631 if (offsetp
>= offsets_end
13632 || *offsetp
> origin_child_die
->sect_off
)
13634 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13635 Check whether we're already processing ORIGIN_CHILD_DIE.
13636 This can happen with mutually referenced abstract_origins.
13638 if (!origin_child_die
->in_process
)
13639 process_die (origin_child_die
, origin_cu
);
13641 origin_child_die
= sibling_die (origin_child_die
);
13643 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13645 if (cu
!= origin_cu
)
13646 compute_delayed_physnames (origin_cu
);
13650 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13652 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13653 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13654 struct context_stack
*newobj
;
13657 struct die_info
*child_die
;
13658 struct attribute
*attr
, *call_line
, *call_file
;
13660 CORE_ADDR baseaddr
;
13661 struct block
*block
;
13662 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13663 std::vector
<struct symbol
*> template_args
;
13664 struct template_symbol
*templ_func
= NULL
;
13668 /* If we do not have call site information, we can't show the
13669 caller of this inlined function. That's too confusing, so
13670 only use the scope for local variables. */
13671 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13672 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13673 if (call_line
== NULL
|| call_file
== NULL
)
13675 read_lexical_block_scope (die
, cu
);
13680 baseaddr
= objfile
->text_section_offset ();
13682 name
= dwarf2_name (die
, cu
);
13684 /* Ignore functions with missing or empty names. These are actually
13685 illegal according to the DWARF standard. */
13688 complaint (_("missing name for subprogram DIE at %s"),
13689 sect_offset_str (die
->sect_off
));
13693 /* Ignore functions with missing or invalid low and high pc attributes. */
13694 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13695 <= PC_BOUNDS_INVALID
)
13697 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13698 if (!attr
|| !DW_UNSND (attr
))
13699 complaint (_("cannot get low and high bounds "
13700 "for subprogram DIE at %s"),
13701 sect_offset_str (die
->sect_off
));
13705 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13706 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13708 /* If we have any template arguments, then we must allocate a
13709 different sort of symbol. */
13710 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13712 if (child_die
->tag
== DW_TAG_template_type_param
13713 || child_die
->tag
== DW_TAG_template_value_param
)
13715 templ_func
= allocate_template_symbol (objfile
);
13716 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13721 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13722 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13723 (struct symbol
*) templ_func
);
13725 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13726 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13729 /* If there is a location expression for DW_AT_frame_base, record
13731 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13732 if (attr
!= nullptr)
13733 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13735 /* If there is a location for the static link, record it. */
13736 newobj
->static_link
= NULL
;
13737 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13738 if (attr
!= nullptr)
13740 newobj
->static_link
13741 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13742 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13743 dwarf2_per_cu_addr_type (cu
->per_cu
));
13746 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13748 if (die
->child
!= NULL
)
13750 child_die
= die
->child
;
13751 while (child_die
&& child_die
->tag
)
13753 if (child_die
->tag
== DW_TAG_template_type_param
13754 || child_die
->tag
== DW_TAG_template_value_param
)
13756 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13759 template_args
.push_back (arg
);
13762 process_die (child_die
, cu
);
13763 child_die
= sibling_die (child_die
);
13767 inherit_abstract_dies (die
, cu
);
13769 /* If we have a DW_AT_specification, we might need to import using
13770 directives from the context of the specification DIE. See the
13771 comment in determine_prefix. */
13772 if (cu
->language
== language_cplus
13773 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13775 struct dwarf2_cu
*spec_cu
= cu
;
13776 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13780 child_die
= spec_die
->child
;
13781 while (child_die
&& child_die
->tag
)
13783 if (child_die
->tag
== DW_TAG_imported_module
)
13784 process_die (child_die
, spec_cu
);
13785 child_die
= sibling_die (child_die
);
13788 /* In some cases, GCC generates specification DIEs that
13789 themselves contain DW_AT_specification attributes. */
13790 spec_die
= die_specification (spec_die
, &spec_cu
);
13794 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13795 /* Make a block for the local symbols within. */
13796 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13797 cstk
.static_link
, lowpc
, highpc
);
13799 /* For C++, set the block's scope. */
13800 if ((cu
->language
== language_cplus
13801 || cu
->language
== language_fortran
13802 || cu
->language
== language_d
13803 || cu
->language
== language_rust
)
13804 && cu
->processing_has_namespace_info
)
13805 block_set_scope (block
, determine_prefix (die
, cu
),
13806 &objfile
->objfile_obstack
);
13808 /* If we have address ranges, record them. */
13809 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13811 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13813 /* Attach template arguments to function. */
13814 if (!template_args
.empty ())
13816 gdb_assert (templ_func
!= NULL
);
13818 templ_func
->n_template_arguments
= template_args
.size ();
13819 templ_func
->template_arguments
13820 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13821 templ_func
->n_template_arguments
);
13822 memcpy (templ_func
->template_arguments
,
13823 template_args
.data (),
13824 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13826 /* Make sure that the symtab is set on the new symbols. Even
13827 though they don't appear in this symtab directly, other parts
13828 of gdb assume that symbols do, and this is reasonably
13830 for (symbol
*sym
: template_args
)
13831 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13834 /* In C++, we can have functions nested inside functions (e.g., when
13835 a function declares a class that has methods). This means that
13836 when we finish processing a function scope, we may need to go
13837 back to building a containing block's symbol lists. */
13838 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13839 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13841 /* If we've finished processing a top-level function, subsequent
13842 symbols go in the file symbol list. */
13843 if (cu
->get_builder ()->outermost_context_p ())
13844 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13847 /* Process all the DIES contained within a lexical block scope. Start
13848 a new scope, process the dies, and then close the scope. */
13851 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13853 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13854 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13855 CORE_ADDR lowpc
, highpc
;
13856 struct die_info
*child_die
;
13857 CORE_ADDR baseaddr
;
13859 baseaddr
= objfile
->text_section_offset ();
13861 /* Ignore blocks with missing or invalid low and high pc attributes. */
13862 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13863 as multiple lexical blocks? Handling children in a sane way would
13864 be nasty. Might be easier to properly extend generic blocks to
13865 describe ranges. */
13866 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13868 case PC_BOUNDS_NOT_PRESENT
:
13869 /* DW_TAG_lexical_block has no attributes, process its children as if
13870 there was no wrapping by that DW_TAG_lexical_block.
13871 GCC does no longer produces such DWARF since GCC r224161. */
13872 for (child_die
= die
->child
;
13873 child_die
!= NULL
&& child_die
->tag
;
13874 child_die
= sibling_die (child_die
))
13875 process_die (child_die
, cu
);
13877 case PC_BOUNDS_INVALID
:
13880 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13881 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13883 cu
->get_builder ()->push_context (0, lowpc
);
13884 if (die
->child
!= NULL
)
13886 child_die
= die
->child
;
13887 while (child_die
&& child_die
->tag
)
13889 process_die (child_die
, cu
);
13890 child_die
= sibling_die (child_die
);
13893 inherit_abstract_dies (die
, cu
);
13894 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13896 if (*cu
->get_builder ()->get_local_symbols () != NULL
13897 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13899 struct block
*block
13900 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13901 cstk
.start_addr
, highpc
);
13903 /* Note that recording ranges after traversing children, as we
13904 do here, means that recording a parent's ranges entails
13905 walking across all its children's ranges as they appear in
13906 the address map, which is quadratic behavior.
13908 It would be nicer to record the parent's ranges before
13909 traversing its children, simply overriding whatever you find
13910 there. But since we don't even decide whether to create a
13911 block until after we've traversed its children, that's hard
13913 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13915 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13916 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13919 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13922 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13924 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13925 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13926 CORE_ADDR pc
, baseaddr
;
13927 struct attribute
*attr
;
13928 struct call_site
*call_site
, call_site_local
;
13931 struct die_info
*child_die
;
13933 baseaddr
= objfile
->text_section_offset ();
13935 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13938 /* This was a pre-DWARF-5 GNU extension alias
13939 for DW_AT_call_return_pc. */
13940 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13944 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13945 "DIE %s [in module %s]"),
13946 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13949 pc
= attr_value_as_address (attr
) + baseaddr
;
13950 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13952 if (cu
->call_site_htab
== NULL
)
13953 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13954 NULL
, &objfile
->objfile_obstack
,
13955 hashtab_obstack_allocate
, NULL
);
13956 call_site_local
.pc
= pc
;
13957 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13960 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13961 "DIE %s [in module %s]"),
13962 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13963 objfile_name (objfile
));
13967 /* Count parameters at the caller. */
13970 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13971 child_die
= sibling_die (child_die
))
13973 if (child_die
->tag
!= DW_TAG_call_site_parameter
13974 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
13976 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
13977 "DW_TAG_call_site child DIE %s [in module %s]"),
13978 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
13979 objfile_name (objfile
));
13987 = ((struct call_site
*)
13988 obstack_alloc (&objfile
->objfile_obstack
,
13989 sizeof (*call_site
)
13990 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
13992 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
13993 call_site
->pc
= pc
;
13995 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
13996 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
13998 struct die_info
*func_die
;
14000 /* Skip also over DW_TAG_inlined_subroutine. */
14001 for (func_die
= die
->parent
;
14002 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14003 && func_die
->tag
!= DW_TAG_subroutine_type
;
14004 func_die
= func_die
->parent
);
14006 /* DW_AT_call_all_calls is a superset
14007 of DW_AT_call_all_tail_calls. */
14009 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14010 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14011 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14012 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14014 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14015 not complete. But keep CALL_SITE for look ups via call_site_htab,
14016 both the initial caller containing the real return address PC and
14017 the final callee containing the current PC of a chain of tail
14018 calls do not need to have the tail call list complete. But any
14019 function candidate for a virtual tail call frame searched via
14020 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14021 determined unambiguously. */
14025 struct type
*func_type
= NULL
;
14028 func_type
= get_die_type (func_die
, cu
);
14029 if (func_type
!= NULL
)
14031 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14033 /* Enlist this call site to the function. */
14034 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14035 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14038 complaint (_("Cannot find function owning DW_TAG_call_site "
14039 "DIE %s [in module %s]"),
14040 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14044 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14046 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14048 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14051 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14052 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14054 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14055 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14056 /* Keep NULL DWARF_BLOCK. */;
14057 else if (attr_form_is_block (attr
))
14059 struct dwarf2_locexpr_baton
*dlbaton
;
14061 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14062 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14063 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14064 dlbaton
->per_cu
= cu
->per_cu
;
14066 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14068 else if (attr_form_is_ref (attr
))
14070 struct dwarf2_cu
*target_cu
= cu
;
14071 struct die_info
*target_die
;
14073 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14074 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14075 if (die_is_declaration (target_die
, target_cu
))
14077 const char *target_physname
;
14079 /* Prefer the mangled name; otherwise compute the demangled one. */
14080 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14081 if (target_physname
== NULL
)
14082 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14083 if (target_physname
== NULL
)
14084 complaint (_("DW_AT_call_target target DIE has invalid "
14085 "physname, for referencing DIE %s [in module %s]"),
14086 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14088 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14094 /* DW_AT_entry_pc should be preferred. */
14095 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14096 <= PC_BOUNDS_INVALID
)
14097 complaint (_("DW_AT_call_target target DIE has invalid "
14098 "low pc, for referencing DIE %s [in module %s]"),
14099 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14102 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14103 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14108 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14109 "block nor reference, for DIE %s [in module %s]"),
14110 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14112 call_site
->per_cu
= cu
->per_cu
;
14114 for (child_die
= die
->child
;
14115 child_die
&& child_die
->tag
;
14116 child_die
= sibling_die (child_die
))
14118 struct call_site_parameter
*parameter
;
14119 struct attribute
*loc
, *origin
;
14121 if (child_die
->tag
!= DW_TAG_call_site_parameter
14122 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14124 /* Already printed the complaint above. */
14128 gdb_assert (call_site
->parameter_count
< nparams
);
14129 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14131 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14132 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14133 register is contained in DW_AT_call_value. */
14135 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14136 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14137 if (origin
== NULL
)
14139 /* This was a pre-DWARF-5 GNU extension alias
14140 for DW_AT_call_parameter. */
14141 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14143 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14145 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14147 sect_offset sect_off
14148 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14149 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14151 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14152 binding can be done only inside one CU. Such referenced DIE
14153 therefore cannot be even moved to DW_TAG_partial_unit. */
14154 complaint (_("DW_AT_call_parameter offset is not in CU for "
14155 "DW_TAG_call_site child DIE %s [in module %s]"),
14156 sect_offset_str (child_die
->sect_off
),
14157 objfile_name (objfile
));
14160 parameter
->u
.param_cu_off
14161 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14163 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14165 complaint (_("No DW_FORM_block* DW_AT_location for "
14166 "DW_TAG_call_site child DIE %s [in module %s]"),
14167 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14172 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14173 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14174 if (parameter
->u
.dwarf_reg
!= -1)
14175 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14176 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14177 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14178 ¶meter
->u
.fb_offset
))
14179 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14182 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14183 "for DW_FORM_block* DW_AT_location is supported for "
14184 "DW_TAG_call_site child DIE %s "
14186 sect_offset_str (child_die
->sect_off
),
14187 objfile_name (objfile
));
14192 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14194 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14195 if (!attr_form_is_block (attr
))
14197 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14198 "DW_TAG_call_site child DIE %s [in module %s]"),
14199 sect_offset_str (child_die
->sect_off
),
14200 objfile_name (objfile
));
14203 parameter
->value
= DW_BLOCK (attr
)->data
;
14204 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14206 /* Parameters are not pre-cleared by memset above. */
14207 parameter
->data_value
= NULL
;
14208 parameter
->data_value_size
= 0;
14209 call_site
->parameter_count
++;
14211 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14213 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14214 if (attr
!= nullptr)
14216 if (!attr_form_is_block (attr
))
14217 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14218 "DW_TAG_call_site child DIE %s [in module %s]"),
14219 sect_offset_str (child_die
->sect_off
),
14220 objfile_name (objfile
));
14223 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14224 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14230 /* Helper function for read_variable. If DIE represents a virtual
14231 table, then return the type of the concrete object that is
14232 associated with the virtual table. Otherwise, return NULL. */
14234 static struct type
*
14235 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14237 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14241 /* Find the type DIE. */
14242 struct die_info
*type_die
= NULL
;
14243 struct dwarf2_cu
*type_cu
= cu
;
14245 if (attr_form_is_ref (attr
))
14246 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14247 if (type_die
== NULL
)
14250 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14252 return die_containing_type (type_die
, type_cu
);
14255 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14258 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14260 struct rust_vtable_symbol
*storage
= NULL
;
14262 if (cu
->language
== language_rust
)
14264 struct type
*containing_type
= rust_containing_type (die
, cu
);
14266 if (containing_type
!= NULL
)
14268 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14270 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14271 initialize_objfile_symbol (storage
);
14272 storage
->concrete_type
= containing_type
;
14273 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14277 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14278 struct attribute
*abstract_origin
14279 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14280 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14281 if (res
== NULL
&& loc
&& abstract_origin
)
14283 /* We have a variable without a name, but with a location and an abstract
14284 origin. This may be a concrete instance of an abstract variable
14285 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14287 struct dwarf2_cu
*origin_cu
= cu
;
14288 struct die_info
*origin_die
14289 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14290 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14291 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14295 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14296 reading .debug_rnglists.
14297 Callback's type should be:
14298 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14299 Return true if the attributes are present and valid, otherwise,
14302 template <typename Callback
>
14304 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14305 Callback
&&callback
)
14307 struct dwarf2_per_objfile
*dwarf2_per_objfile
14308 = cu
->per_cu
->dwarf2_per_objfile
;
14309 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14310 bfd
*obfd
= objfile
->obfd
;
14311 /* Base address selection entry. */
14314 const gdb_byte
*buffer
;
14315 CORE_ADDR baseaddr
;
14316 bool overflow
= false;
14318 found_base
= cu
->base_known
;
14319 base
= cu
->base_address
;
14321 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14322 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14324 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14328 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14330 baseaddr
= objfile
->text_section_offset ();
14334 /* Initialize it due to a false compiler warning. */
14335 CORE_ADDR range_beginning
= 0, range_end
= 0;
14336 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14337 + dwarf2_per_objfile
->rnglists
.size
);
14338 unsigned int bytes_read
;
14340 if (buffer
== buf_end
)
14345 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14348 case DW_RLE_end_of_list
:
14350 case DW_RLE_base_address
:
14351 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14356 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14358 buffer
+= bytes_read
;
14360 case DW_RLE_start_length
:
14361 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14366 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14367 buffer
+= bytes_read
;
14368 range_end
= (range_beginning
14369 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14370 buffer
+= bytes_read
;
14371 if (buffer
> buf_end
)
14377 case DW_RLE_offset_pair
:
14378 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14379 buffer
+= bytes_read
;
14380 if (buffer
> buf_end
)
14385 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14386 buffer
+= bytes_read
;
14387 if (buffer
> buf_end
)
14393 case DW_RLE_start_end
:
14394 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14399 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14400 buffer
+= bytes_read
;
14401 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14402 buffer
+= bytes_read
;
14405 complaint (_("Invalid .debug_rnglists data (no base address)"));
14408 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14410 if (rlet
== DW_RLE_base_address
)
14415 /* We have no valid base address for the ranges
14417 complaint (_("Invalid .debug_rnglists data (no base address)"));
14421 if (range_beginning
> range_end
)
14423 /* Inverted range entries are invalid. */
14424 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14428 /* Empty range entries have no effect. */
14429 if (range_beginning
== range_end
)
14432 range_beginning
+= base
;
14435 /* A not-uncommon case of bad debug info.
14436 Don't pollute the addrmap with bad data. */
14437 if (range_beginning
+ baseaddr
== 0
14438 && !dwarf2_per_objfile
->has_section_at_zero
)
14440 complaint (_(".debug_rnglists entry has start address of zero"
14441 " [in module %s]"), objfile_name (objfile
));
14445 callback (range_beginning
, range_end
);
14450 complaint (_("Offset %d is not terminated "
14451 "for DW_AT_ranges attribute"),
14459 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14460 Callback's type should be:
14461 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14462 Return 1 if the attributes are present and valid, otherwise, return 0. */
14464 template <typename Callback
>
14466 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14467 Callback
&&callback
)
14469 struct dwarf2_per_objfile
*dwarf2_per_objfile
14470 = cu
->per_cu
->dwarf2_per_objfile
;
14471 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14472 struct comp_unit_head
*cu_header
= &cu
->header
;
14473 bfd
*obfd
= objfile
->obfd
;
14474 unsigned int addr_size
= cu_header
->addr_size
;
14475 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14476 /* Base address selection entry. */
14479 unsigned int dummy
;
14480 const gdb_byte
*buffer
;
14481 CORE_ADDR baseaddr
;
14483 if (cu_header
->version
>= 5)
14484 return dwarf2_rnglists_process (offset
, cu
, callback
);
14486 found_base
= cu
->base_known
;
14487 base
= cu
->base_address
;
14489 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14490 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14492 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14496 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14498 baseaddr
= objfile
->text_section_offset ();
14502 CORE_ADDR range_beginning
, range_end
;
14504 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14505 buffer
+= addr_size
;
14506 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14507 buffer
+= addr_size
;
14508 offset
+= 2 * addr_size
;
14510 /* An end of list marker is a pair of zero addresses. */
14511 if (range_beginning
== 0 && range_end
== 0)
14512 /* Found the end of list entry. */
14515 /* Each base address selection entry is a pair of 2 values.
14516 The first is the largest possible address, the second is
14517 the base address. Check for a base address here. */
14518 if ((range_beginning
& mask
) == mask
)
14520 /* If we found the largest possible address, then we already
14521 have the base address in range_end. */
14529 /* We have no valid base address for the ranges
14531 complaint (_("Invalid .debug_ranges data (no base address)"));
14535 if (range_beginning
> range_end
)
14537 /* Inverted range entries are invalid. */
14538 complaint (_("Invalid .debug_ranges data (inverted range)"));
14542 /* Empty range entries have no effect. */
14543 if (range_beginning
== range_end
)
14546 range_beginning
+= base
;
14549 /* A not-uncommon case of bad debug info.
14550 Don't pollute the addrmap with bad data. */
14551 if (range_beginning
+ baseaddr
== 0
14552 && !dwarf2_per_objfile
->has_section_at_zero
)
14554 complaint (_(".debug_ranges entry has start address of zero"
14555 " [in module %s]"), objfile_name (objfile
));
14559 callback (range_beginning
, range_end
);
14565 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14566 Return 1 if the attributes are present and valid, otherwise, return 0.
14567 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14570 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14571 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14572 dwarf2_psymtab
*ranges_pst
)
14574 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14575 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14576 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14579 CORE_ADDR high
= 0;
14582 retval
= dwarf2_ranges_process (offset
, cu
,
14583 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14585 if (ranges_pst
!= NULL
)
14590 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14591 range_beginning
+ baseaddr
)
14593 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14594 range_end
+ baseaddr
)
14596 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14597 lowpc
, highpc
- 1, ranges_pst
);
14600 /* FIXME: This is recording everything as a low-high
14601 segment of consecutive addresses. We should have a
14602 data structure for discontiguous block ranges
14606 low
= range_beginning
;
14612 if (range_beginning
< low
)
14613 low
= range_beginning
;
14614 if (range_end
> high
)
14622 /* If the first entry is an end-of-list marker, the range
14623 describes an empty scope, i.e. no instructions. */
14629 *high_return
= high
;
14633 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14634 definition for the return value. *LOWPC and *HIGHPC are set iff
14635 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14637 static enum pc_bounds_kind
14638 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14639 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14640 dwarf2_psymtab
*pst
)
14642 struct dwarf2_per_objfile
*dwarf2_per_objfile
14643 = cu
->per_cu
->dwarf2_per_objfile
;
14644 struct attribute
*attr
;
14645 struct attribute
*attr_high
;
14647 CORE_ADDR high
= 0;
14648 enum pc_bounds_kind ret
;
14650 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14653 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14654 if (attr
!= nullptr)
14656 low
= attr_value_as_address (attr
);
14657 high
= attr_value_as_address (attr_high
);
14658 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14662 /* Found high w/o low attribute. */
14663 return PC_BOUNDS_INVALID
;
14665 /* Found consecutive range of addresses. */
14666 ret
= PC_BOUNDS_HIGH_LOW
;
14670 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14673 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14674 We take advantage of the fact that DW_AT_ranges does not appear
14675 in DW_TAG_compile_unit of DWO files. */
14676 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14677 unsigned int ranges_offset
= (DW_UNSND (attr
)
14678 + (need_ranges_base
14682 /* Value of the DW_AT_ranges attribute is the offset in the
14683 .debug_ranges section. */
14684 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14685 return PC_BOUNDS_INVALID
;
14686 /* Found discontinuous range of addresses. */
14687 ret
= PC_BOUNDS_RANGES
;
14690 return PC_BOUNDS_NOT_PRESENT
;
14693 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14695 return PC_BOUNDS_INVALID
;
14697 /* When using the GNU linker, .gnu.linkonce. sections are used to
14698 eliminate duplicate copies of functions and vtables and such.
14699 The linker will arbitrarily choose one and discard the others.
14700 The AT_*_pc values for such functions refer to local labels in
14701 these sections. If the section from that file was discarded, the
14702 labels are not in the output, so the relocs get a value of 0.
14703 If this is a discarded function, mark the pc bounds as invalid,
14704 so that GDB will ignore it. */
14705 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14706 return PC_BOUNDS_INVALID
;
14714 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14715 its low and high PC addresses. Do nothing if these addresses could not
14716 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14717 and HIGHPC to the high address if greater than HIGHPC. */
14720 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14721 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14722 struct dwarf2_cu
*cu
)
14724 CORE_ADDR low
, high
;
14725 struct die_info
*child
= die
->child
;
14727 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14729 *lowpc
= std::min (*lowpc
, low
);
14730 *highpc
= std::max (*highpc
, high
);
14733 /* If the language does not allow nested subprograms (either inside
14734 subprograms or lexical blocks), we're done. */
14735 if (cu
->language
!= language_ada
)
14738 /* Check all the children of the given DIE. If it contains nested
14739 subprograms, then check their pc bounds. Likewise, we need to
14740 check lexical blocks as well, as they may also contain subprogram
14742 while (child
&& child
->tag
)
14744 if (child
->tag
== DW_TAG_subprogram
14745 || child
->tag
== DW_TAG_lexical_block
)
14746 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14747 child
= sibling_die (child
);
14751 /* Get the low and high pc's represented by the scope DIE, and store
14752 them in *LOWPC and *HIGHPC. If the correct values can't be
14753 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14756 get_scope_pc_bounds (struct die_info
*die
,
14757 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14758 struct dwarf2_cu
*cu
)
14760 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14761 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14762 CORE_ADDR current_low
, current_high
;
14764 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14765 >= PC_BOUNDS_RANGES
)
14767 best_low
= current_low
;
14768 best_high
= current_high
;
14772 struct die_info
*child
= die
->child
;
14774 while (child
&& child
->tag
)
14776 switch (child
->tag
) {
14777 case DW_TAG_subprogram
:
14778 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14780 case DW_TAG_namespace
:
14781 case DW_TAG_module
:
14782 /* FIXME: carlton/2004-01-16: Should we do this for
14783 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14784 that current GCC's always emit the DIEs corresponding
14785 to definitions of methods of classes as children of a
14786 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14787 the DIEs giving the declarations, which could be
14788 anywhere). But I don't see any reason why the
14789 standards says that they have to be there. */
14790 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14792 if (current_low
!= ((CORE_ADDR
) -1))
14794 best_low
= std::min (best_low
, current_low
);
14795 best_high
= std::max (best_high
, current_high
);
14803 child
= sibling_die (child
);
14808 *highpc
= best_high
;
14811 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14815 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14816 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14818 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14819 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14820 struct attribute
*attr
;
14821 struct attribute
*attr_high
;
14823 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14826 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14827 if (attr
!= nullptr)
14829 CORE_ADDR low
= attr_value_as_address (attr
);
14830 CORE_ADDR high
= attr_value_as_address (attr_high
);
14832 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14835 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14836 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14837 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14841 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14842 if (attr
!= nullptr)
14844 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14845 We take advantage of the fact that DW_AT_ranges does not appear
14846 in DW_TAG_compile_unit of DWO files. */
14847 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14849 /* The value of the DW_AT_ranges attribute is the offset of the
14850 address range list in the .debug_ranges section. */
14851 unsigned long offset
= (DW_UNSND (attr
)
14852 + (need_ranges_base
? cu
->ranges_base
: 0));
14854 std::vector
<blockrange
> blockvec
;
14855 dwarf2_ranges_process (offset
, cu
,
14856 [&] (CORE_ADDR start
, CORE_ADDR end
)
14860 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14861 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14862 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14863 blockvec
.emplace_back (start
, end
);
14866 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14870 /* Check whether the producer field indicates either of GCC < 4.6, or the
14871 Intel C/C++ compiler, and cache the result in CU. */
14874 check_producer (struct dwarf2_cu
*cu
)
14878 if (cu
->producer
== NULL
)
14880 /* For unknown compilers expect their behavior is DWARF version
14883 GCC started to support .debug_types sections by -gdwarf-4 since
14884 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14885 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14886 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14887 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14889 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14891 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14892 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14894 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14896 cu
->producer_is_icc
= true;
14897 cu
->producer_is_icc_lt_14
= major
< 14;
14899 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14900 cu
->producer_is_codewarrior
= true;
14903 /* For other non-GCC compilers, expect their behavior is DWARF version
14907 cu
->checked_producer
= true;
14910 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14911 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14912 during 4.6.0 experimental. */
14915 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14917 if (!cu
->checked_producer
)
14918 check_producer (cu
);
14920 return cu
->producer_is_gxx_lt_4_6
;
14924 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14925 with incorrect is_stmt attributes. */
14928 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14930 if (!cu
->checked_producer
)
14931 check_producer (cu
);
14933 return cu
->producer_is_codewarrior
;
14936 /* Return the default accessibility type if it is not overridden by
14937 DW_AT_accessibility. */
14939 static enum dwarf_access_attribute
14940 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14942 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14944 /* The default DWARF 2 accessibility for members is public, the default
14945 accessibility for inheritance is private. */
14947 if (die
->tag
!= DW_TAG_inheritance
)
14948 return DW_ACCESS_public
;
14950 return DW_ACCESS_private
;
14954 /* DWARF 3+ defines the default accessibility a different way. The same
14955 rules apply now for DW_TAG_inheritance as for the members and it only
14956 depends on the container kind. */
14958 if (die
->parent
->tag
== DW_TAG_class_type
)
14959 return DW_ACCESS_private
;
14961 return DW_ACCESS_public
;
14965 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14966 offset. If the attribute was not found return 0, otherwise return
14967 1. If it was found but could not properly be handled, set *OFFSET
14971 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
14974 struct attribute
*attr
;
14976 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
14981 /* Note that we do not check for a section offset first here.
14982 This is because DW_AT_data_member_location is new in DWARF 4,
14983 so if we see it, we can assume that a constant form is really
14984 a constant and not a section offset. */
14985 if (attr_form_is_constant (attr
))
14986 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
14987 else if (attr_form_is_section_offset (attr
))
14988 dwarf2_complex_location_expr_complaint ();
14989 else if (attr_form_is_block (attr
))
14990 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
14992 dwarf2_complex_location_expr_complaint ();
15000 /* Add an aggregate field to the field list. */
15003 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15004 struct dwarf2_cu
*cu
)
15006 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15007 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15008 struct nextfield
*new_field
;
15009 struct attribute
*attr
;
15011 const char *fieldname
= "";
15013 if (die
->tag
== DW_TAG_inheritance
)
15015 fip
->baseclasses
.emplace_back ();
15016 new_field
= &fip
->baseclasses
.back ();
15020 fip
->fields
.emplace_back ();
15021 new_field
= &fip
->fields
.back ();
15026 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15027 if (attr
!= nullptr)
15028 new_field
->accessibility
= DW_UNSND (attr
);
15030 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15031 if (new_field
->accessibility
!= DW_ACCESS_public
)
15032 fip
->non_public_fields
= 1;
15034 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15035 if (attr
!= nullptr)
15036 new_field
->virtuality
= DW_UNSND (attr
);
15038 new_field
->virtuality
= DW_VIRTUALITY_none
;
15040 fp
= &new_field
->field
;
15042 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15046 /* Data member other than a C++ static data member. */
15048 /* Get type of field. */
15049 fp
->type
= die_type (die
, cu
);
15051 SET_FIELD_BITPOS (*fp
, 0);
15053 /* Get bit size of field (zero if none). */
15054 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15055 if (attr
!= nullptr)
15057 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15061 FIELD_BITSIZE (*fp
) = 0;
15064 /* Get bit offset of field. */
15065 if (handle_data_member_location (die
, cu
, &offset
))
15066 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15067 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15068 if (attr
!= nullptr)
15070 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15072 /* For big endian bits, the DW_AT_bit_offset gives the
15073 additional bit offset from the MSB of the containing
15074 anonymous object to the MSB of the field. We don't
15075 have to do anything special since we don't need to
15076 know the size of the anonymous object. */
15077 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15081 /* For little endian bits, compute the bit offset to the
15082 MSB of the anonymous object, subtract off the number of
15083 bits from the MSB of the field to the MSB of the
15084 object, and then subtract off the number of bits of
15085 the field itself. The result is the bit offset of
15086 the LSB of the field. */
15087 int anonymous_size
;
15088 int bit_offset
= DW_UNSND (attr
);
15090 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15091 if (attr
!= nullptr)
15093 /* The size of the anonymous object containing
15094 the bit field is explicit, so use the
15095 indicated size (in bytes). */
15096 anonymous_size
= DW_UNSND (attr
);
15100 /* The size of the anonymous object containing
15101 the bit field must be inferred from the type
15102 attribute of the data member containing the
15104 anonymous_size
= TYPE_LENGTH (fp
->type
);
15106 SET_FIELD_BITPOS (*fp
,
15107 (FIELD_BITPOS (*fp
)
15108 + anonymous_size
* bits_per_byte
15109 - bit_offset
- FIELD_BITSIZE (*fp
)));
15112 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15114 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15115 + dwarf2_get_attr_constant_value (attr
, 0)));
15117 /* Get name of field. */
15118 fieldname
= dwarf2_name (die
, cu
);
15119 if (fieldname
== NULL
)
15122 /* The name is already allocated along with this objfile, so we don't
15123 need to duplicate it for the type. */
15124 fp
->name
= fieldname
;
15126 /* Change accessibility for artificial fields (e.g. virtual table
15127 pointer or virtual base class pointer) to private. */
15128 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15130 FIELD_ARTIFICIAL (*fp
) = 1;
15131 new_field
->accessibility
= DW_ACCESS_private
;
15132 fip
->non_public_fields
= 1;
15135 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15137 /* C++ static member. */
15139 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15140 is a declaration, but all versions of G++ as of this writing
15141 (so through at least 3.2.1) incorrectly generate
15142 DW_TAG_variable tags. */
15144 const char *physname
;
15146 /* Get name of field. */
15147 fieldname
= dwarf2_name (die
, cu
);
15148 if (fieldname
== NULL
)
15151 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15153 /* Only create a symbol if this is an external value.
15154 new_symbol checks this and puts the value in the global symbol
15155 table, which we want. If it is not external, new_symbol
15156 will try to put the value in cu->list_in_scope which is wrong. */
15157 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15159 /* A static const member, not much different than an enum as far as
15160 we're concerned, except that we can support more types. */
15161 new_symbol (die
, NULL
, cu
);
15164 /* Get physical name. */
15165 physname
= dwarf2_physname (fieldname
, die
, cu
);
15167 /* The name is already allocated along with this objfile, so we don't
15168 need to duplicate it for the type. */
15169 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15170 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15171 FIELD_NAME (*fp
) = fieldname
;
15173 else if (die
->tag
== DW_TAG_inheritance
)
15177 /* C++ base class field. */
15178 if (handle_data_member_location (die
, cu
, &offset
))
15179 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15180 FIELD_BITSIZE (*fp
) = 0;
15181 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15182 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15184 else if (die
->tag
== DW_TAG_variant_part
)
15186 /* process_structure_scope will treat this DIE as a union. */
15187 process_structure_scope (die
, cu
);
15189 /* The variant part is relative to the start of the enclosing
15191 SET_FIELD_BITPOS (*fp
, 0);
15192 fp
->type
= get_die_type (die
, cu
);
15193 fp
->artificial
= 1;
15194 fp
->name
= "<<variant>>";
15196 /* Normally a DW_TAG_variant_part won't have a size, but our
15197 representation requires one, so set it to the maximum of the
15198 child sizes, being sure to account for the offset at which
15199 each child is seen. */
15200 if (TYPE_LENGTH (fp
->type
) == 0)
15203 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15205 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15206 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15210 TYPE_LENGTH (fp
->type
) = max
;
15214 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15217 /* Can the type given by DIE define another type? */
15220 type_can_define_types (const struct die_info
*die
)
15224 case DW_TAG_typedef
:
15225 case DW_TAG_class_type
:
15226 case DW_TAG_structure_type
:
15227 case DW_TAG_union_type
:
15228 case DW_TAG_enumeration_type
:
15236 /* Add a type definition defined in the scope of the FIP's class. */
15239 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15240 struct dwarf2_cu
*cu
)
15242 struct decl_field fp
;
15243 memset (&fp
, 0, sizeof (fp
));
15245 gdb_assert (type_can_define_types (die
));
15247 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15248 fp
.name
= dwarf2_name (die
, cu
);
15249 fp
.type
= read_type_die (die
, cu
);
15251 /* Save accessibility. */
15252 enum dwarf_access_attribute accessibility
;
15253 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15255 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15257 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15258 switch (accessibility
)
15260 case DW_ACCESS_public
:
15261 /* The assumed value if neither private nor protected. */
15263 case DW_ACCESS_private
:
15266 case DW_ACCESS_protected
:
15267 fp
.is_protected
= 1;
15270 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15273 if (die
->tag
== DW_TAG_typedef
)
15274 fip
->typedef_field_list
.push_back (fp
);
15276 fip
->nested_types_list
.push_back (fp
);
15279 /* Create the vector of fields, and attach it to the type. */
15282 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15283 struct dwarf2_cu
*cu
)
15285 int nfields
= fip
->nfields
;
15287 /* Record the field count, allocate space for the array of fields,
15288 and create blank accessibility bitfields if necessary. */
15289 TYPE_NFIELDS (type
) = nfields
;
15290 TYPE_FIELDS (type
) = (struct field
*)
15291 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15293 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15295 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15297 TYPE_FIELD_PRIVATE_BITS (type
) =
15298 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15299 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15301 TYPE_FIELD_PROTECTED_BITS (type
) =
15302 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15303 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15305 TYPE_FIELD_IGNORE_BITS (type
) =
15306 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15307 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15310 /* If the type has baseclasses, allocate and clear a bit vector for
15311 TYPE_FIELD_VIRTUAL_BITS. */
15312 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15314 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15315 unsigned char *pointer
;
15317 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15318 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15319 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15320 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15321 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15324 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15326 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15328 for (int index
= 0; index
< nfields
; ++index
)
15330 struct nextfield
&field
= fip
->fields
[index
];
15332 if (field
.variant
.is_discriminant
)
15333 di
->discriminant_index
= index
;
15334 else if (field
.variant
.default_branch
)
15335 di
->default_index
= index
;
15337 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15341 /* Copy the saved-up fields into the field vector. */
15342 for (int i
= 0; i
< nfields
; ++i
)
15344 struct nextfield
&field
15345 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15346 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15348 TYPE_FIELD (type
, i
) = field
.field
;
15349 switch (field
.accessibility
)
15351 case DW_ACCESS_private
:
15352 if (cu
->language
!= language_ada
)
15353 SET_TYPE_FIELD_PRIVATE (type
, i
);
15356 case DW_ACCESS_protected
:
15357 if (cu
->language
!= language_ada
)
15358 SET_TYPE_FIELD_PROTECTED (type
, i
);
15361 case DW_ACCESS_public
:
15365 /* Unknown accessibility. Complain and treat it as public. */
15367 complaint (_("unsupported accessibility %d"),
15368 field
.accessibility
);
15372 if (i
< fip
->baseclasses
.size ())
15374 switch (field
.virtuality
)
15376 case DW_VIRTUALITY_virtual
:
15377 case DW_VIRTUALITY_pure_virtual
:
15378 if (cu
->language
== language_ada
)
15379 error (_("unexpected virtuality in component of Ada type"));
15380 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15387 /* Return true if this member function is a constructor, false
15391 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15393 const char *fieldname
;
15394 const char *type_name
;
15397 if (die
->parent
== NULL
)
15400 if (die
->parent
->tag
!= DW_TAG_structure_type
15401 && die
->parent
->tag
!= DW_TAG_union_type
15402 && die
->parent
->tag
!= DW_TAG_class_type
)
15405 fieldname
= dwarf2_name (die
, cu
);
15406 type_name
= dwarf2_name (die
->parent
, cu
);
15407 if (fieldname
== NULL
|| type_name
== NULL
)
15410 len
= strlen (fieldname
);
15411 return (strncmp (fieldname
, type_name
, len
) == 0
15412 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15415 /* Check if the given VALUE is a recognized enum
15416 dwarf_defaulted_attribute constant according to DWARF5 spec,
15420 is_valid_DW_AT_defaulted (ULONGEST value
)
15424 case DW_DEFAULTED_no
:
15425 case DW_DEFAULTED_in_class
:
15426 case DW_DEFAULTED_out_of_class
:
15430 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15434 /* Add a member function to the proper fieldlist. */
15437 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15438 struct type
*type
, struct dwarf2_cu
*cu
)
15440 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15441 struct attribute
*attr
;
15443 struct fnfieldlist
*flp
= nullptr;
15444 struct fn_field
*fnp
;
15445 const char *fieldname
;
15446 struct type
*this_type
;
15447 enum dwarf_access_attribute accessibility
;
15449 if (cu
->language
== language_ada
)
15450 error (_("unexpected member function in Ada type"));
15452 /* Get name of member function. */
15453 fieldname
= dwarf2_name (die
, cu
);
15454 if (fieldname
== NULL
)
15457 /* Look up member function name in fieldlist. */
15458 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15460 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15462 flp
= &fip
->fnfieldlists
[i
];
15467 /* Create a new fnfieldlist if necessary. */
15468 if (flp
== nullptr)
15470 fip
->fnfieldlists
.emplace_back ();
15471 flp
= &fip
->fnfieldlists
.back ();
15472 flp
->name
= fieldname
;
15473 i
= fip
->fnfieldlists
.size () - 1;
15476 /* Create a new member function field and add it to the vector of
15478 flp
->fnfields
.emplace_back ();
15479 fnp
= &flp
->fnfields
.back ();
15481 /* Delay processing of the physname until later. */
15482 if (cu
->language
== language_cplus
)
15483 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15487 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15488 fnp
->physname
= physname
? physname
: "";
15491 fnp
->type
= alloc_type (objfile
);
15492 this_type
= read_type_die (die
, cu
);
15493 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15495 int nparams
= TYPE_NFIELDS (this_type
);
15497 /* TYPE is the domain of this method, and THIS_TYPE is the type
15498 of the method itself (TYPE_CODE_METHOD). */
15499 smash_to_method_type (fnp
->type
, type
,
15500 TYPE_TARGET_TYPE (this_type
),
15501 TYPE_FIELDS (this_type
),
15502 TYPE_NFIELDS (this_type
),
15503 TYPE_VARARGS (this_type
));
15505 /* Handle static member functions.
15506 Dwarf2 has no clean way to discern C++ static and non-static
15507 member functions. G++ helps GDB by marking the first
15508 parameter for non-static member functions (which is the this
15509 pointer) as artificial. We obtain this information from
15510 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15511 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15512 fnp
->voffset
= VOFFSET_STATIC
;
15515 complaint (_("member function type missing for '%s'"),
15516 dwarf2_full_name (fieldname
, die
, cu
));
15518 /* Get fcontext from DW_AT_containing_type if present. */
15519 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15520 fnp
->fcontext
= die_containing_type (die
, cu
);
15522 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15523 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15525 /* Get accessibility. */
15526 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15527 if (attr
!= nullptr)
15528 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15530 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15531 switch (accessibility
)
15533 case DW_ACCESS_private
:
15534 fnp
->is_private
= 1;
15536 case DW_ACCESS_protected
:
15537 fnp
->is_protected
= 1;
15541 /* Check for artificial methods. */
15542 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15543 if (attr
&& DW_UNSND (attr
) != 0)
15544 fnp
->is_artificial
= 1;
15546 /* Check for defaulted methods. */
15547 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15548 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15549 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15551 /* Check for deleted methods. */
15552 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15553 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15554 fnp
->is_deleted
= 1;
15556 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15558 /* Get index in virtual function table if it is a virtual member
15559 function. For older versions of GCC, this is an offset in the
15560 appropriate virtual table, as specified by DW_AT_containing_type.
15561 For everyone else, it is an expression to be evaluated relative
15562 to the object address. */
15564 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15565 if (attr
!= nullptr)
15567 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15569 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15571 /* Old-style GCC. */
15572 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15574 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15575 || (DW_BLOCK (attr
)->size
> 1
15576 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15577 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15579 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15580 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15581 dwarf2_complex_location_expr_complaint ();
15583 fnp
->voffset
/= cu
->header
.addr_size
;
15587 dwarf2_complex_location_expr_complaint ();
15589 if (!fnp
->fcontext
)
15591 /* If there is no `this' field and no DW_AT_containing_type,
15592 we cannot actually find a base class context for the
15594 if (TYPE_NFIELDS (this_type
) == 0
15595 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15597 complaint (_("cannot determine context for virtual member "
15598 "function \"%s\" (offset %s)"),
15599 fieldname
, sect_offset_str (die
->sect_off
));
15604 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15608 else if (attr_form_is_section_offset (attr
))
15610 dwarf2_complex_location_expr_complaint ();
15614 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15620 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15621 if (attr
&& DW_UNSND (attr
))
15623 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15624 complaint (_("Member function \"%s\" (offset %s) is virtual "
15625 "but the vtable offset is not specified"),
15626 fieldname
, sect_offset_str (die
->sect_off
));
15627 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15628 TYPE_CPLUS_DYNAMIC (type
) = 1;
15633 /* Create the vector of member function fields, and attach it to the type. */
15636 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15637 struct dwarf2_cu
*cu
)
15639 if (cu
->language
== language_ada
)
15640 error (_("unexpected member functions in Ada type"));
15642 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15643 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15645 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15647 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15649 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15650 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15652 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15653 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15654 fn_flp
->fn_fields
= (struct fn_field
*)
15655 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15657 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15658 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15661 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15664 /* Returns non-zero if NAME is the name of a vtable member in CU's
15665 language, zero otherwise. */
15667 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15669 static const char vptr
[] = "_vptr";
15671 /* Look for the C++ form of the vtable. */
15672 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15678 /* GCC outputs unnamed structures that are really pointers to member
15679 functions, with the ABI-specified layout. If TYPE describes
15680 such a structure, smash it into a member function type.
15682 GCC shouldn't do this; it should just output pointer to member DIEs.
15683 This is GCC PR debug/28767. */
15686 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15688 struct type
*pfn_type
, *self_type
, *new_type
;
15690 /* Check for a structure with no name and two children. */
15691 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15694 /* Check for __pfn and __delta members. */
15695 if (TYPE_FIELD_NAME (type
, 0) == NULL
15696 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15697 || TYPE_FIELD_NAME (type
, 1) == NULL
15698 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15701 /* Find the type of the method. */
15702 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15703 if (pfn_type
== NULL
15704 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15705 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15708 /* Look for the "this" argument. */
15709 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15710 if (TYPE_NFIELDS (pfn_type
) == 0
15711 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15712 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15715 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15716 new_type
= alloc_type (objfile
);
15717 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15718 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15719 TYPE_VARARGS (pfn_type
));
15720 smash_to_methodptr_type (type
, new_type
);
15723 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15724 appropriate error checking and issuing complaints if there is a
15728 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15730 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15732 if (attr
== nullptr)
15735 if (!attr_form_is_constant (attr
))
15737 complaint (_("DW_AT_alignment must have constant form"
15738 " - DIE at %s [in module %s]"),
15739 sect_offset_str (die
->sect_off
),
15740 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15745 if (attr
->form
== DW_FORM_sdata
)
15747 LONGEST val
= DW_SND (attr
);
15750 complaint (_("DW_AT_alignment value must not be negative"
15751 " - DIE at %s [in module %s]"),
15752 sect_offset_str (die
->sect_off
),
15753 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15759 align
= DW_UNSND (attr
);
15763 complaint (_("DW_AT_alignment value must not be zero"
15764 " - DIE at %s [in module %s]"),
15765 sect_offset_str (die
->sect_off
),
15766 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15769 if ((align
& (align
- 1)) != 0)
15771 complaint (_("DW_AT_alignment value must be a power of 2"
15772 " - DIE at %s [in module %s]"),
15773 sect_offset_str (die
->sect_off
),
15774 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15781 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15782 the alignment for TYPE. */
15785 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15788 if (!set_type_align (type
, get_alignment (cu
, die
)))
15789 complaint (_("DW_AT_alignment value too large"
15790 " - DIE at %s [in module %s]"),
15791 sect_offset_str (die
->sect_off
),
15792 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15795 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15796 constant for a type, according to DWARF5 spec, Table 5.5. */
15799 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15804 case DW_CC_pass_by_reference
:
15805 case DW_CC_pass_by_value
:
15809 complaint (_("unrecognized DW_AT_calling_convention value "
15810 "(%s) for a type"), pulongest (value
));
15815 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15816 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15817 also according to GNU-specific values (see include/dwarf2.h). */
15820 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15825 case DW_CC_program
:
15829 case DW_CC_GNU_renesas_sh
:
15830 case DW_CC_GNU_borland_fastcall_i386
:
15831 case DW_CC_GDB_IBM_OpenCL
:
15835 complaint (_("unrecognized DW_AT_calling_convention value "
15836 "(%s) for a subroutine"), pulongest (value
));
15841 /* Called when we find the DIE that starts a structure or union scope
15842 (definition) to create a type for the structure or union. Fill in
15843 the type's name and general properties; the members will not be
15844 processed until process_structure_scope. A symbol table entry for
15845 the type will also not be done until process_structure_scope (assuming
15846 the type has a name).
15848 NOTE: we need to call these functions regardless of whether or not the
15849 DIE has a DW_AT_name attribute, since it might be an anonymous
15850 structure or union. This gets the type entered into our set of
15851 user defined types. */
15853 static struct type
*
15854 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15856 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15858 struct attribute
*attr
;
15861 /* If the definition of this type lives in .debug_types, read that type.
15862 Don't follow DW_AT_specification though, that will take us back up
15863 the chain and we want to go down. */
15864 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15865 if (attr
!= nullptr)
15867 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15869 /* The type's CU may not be the same as CU.
15870 Ensure TYPE is recorded with CU in die_type_hash. */
15871 return set_die_type (die
, type
, cu
);
15874 type
= alloc_type (objfile
);
15875 INIT_CPLUS_SPECIFIC (type
);
15877 name
= dwarf2_name (die
, cu
);
15880 if (cu
->language
== language_cplus
15881 || cu
->language
== language_d
15882 || cu
->language
== language_rust
)
15884 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15886 /* dwarf2_full_name might have already finished building the DIE's
15887 type. If so, there is no need to continue. */
15888 if (get_die_type (die
, cu
) != NULL
)
15889 return get_die_type (die
, cu
);
15891 TYPE_NAME (type
) = full_name
;
15895 /* The name is already allocated along with this objfile, so
15896 we don't need to duplicate it for the type. */
15897 TYPE_NAME (type
) = name
;
15901 if (die
->tag
== DW_TAG_structure_type
)
15903 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15905 else if (die
->tag
== DW_TAG_union_type
)
15907 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15909 else if (die
->tag
== DW_TAG_variant_part
)
15911 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15912 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15916 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15919 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15920 TYPE_DECLARED_CLASS (type
) = 1;
15922 /* Store the calling convention in the type if it's available in
15923 the die. Otherwise the calling convention remains set to
15924 the default value DW_CC_normal. */
15925 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15926 if (attr
!= nullptr
15927 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15929 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15930 TYPE_CPLUS_CALLING_CONVENTION (type
)
15931 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15934 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15935 if (attr
!= nullptr)
15937 if (attr_form_is_constant (attr
))
15938 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15941 /* For the moment, dynamic type sizes are not supported
15942 by GDB's struct type. The actual size is determined
15943 on-demand when resolving the type of a given object,
15944 so set the type's length to zero for now. Otherwise,
15945 we record an expression as the length, and that expression
15946 could lead to a very large value, which could eventually
15947 lead to us trying to allocate that much memory when creating
15948 a value of that type. */
15949 TYPE_LENGTH (type
) = 0;
15954 TYPE_LENGTH (type
) = 0;
15957 maybe_set_alignment (cu
, die
, type
);
15959 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15961 /* ICC<14 does not output the required DW_AT_declaration on
15962 incomplete types, but gives them a size of zero. */
15963 TYPE_STUB (type
) = 1;
15966 TYPE_STUB_SUPPORTED (type
) = 1;
15968 if (die_is_declaration (die
, cu
))
15969 TYPE_STUB (type
) = 1;
15970 else if (attr
== NULL
&& die
->child
== NULL
15971 && producer_is_realview (cu
->producer
))
15972 /* RealView does not output the required DW_AT_declaration
15973 on incomplete types. */
15974 TYPE_STUB (type
) = 1;
15976 /* We need to add the type field to the die immediately so we don't
15977 infinitely recurse when dealing with pointers to the structure
15978 type within the structure itself. */
15979 set_die_type (die
, type
, cu
);
15981 /* set_die_type should be already done. */
15982 set_descriptive_type (type
, die
, cu
);
15987 /* A helper for process_structure_scope that handles a single member
15991 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
15992 struct field_info
*fi
,
15993 std::vector
<struct symbol
*> *template_args
,
15994 struct dwarf2_cu
*cu
)
15996 if (child_die
->tag
== DW_TAG_member
15997 || child_die
->tag
== DW_TAG_variable
15998 || child_die
->tag
== DW_TAG_variant_part
)
16000 /* NOTE: carlton/2002-11-05: A C++ static data member
16001 should be a DW_TAG_member that is a declaration, but
16002 all versions of G++ as of this writing (so through at
16003 least 3.2.1) incorrectly generate DW_TAG_variable
16004 tags for them instead. */
16005 dwarf2_add_field (fi
, child_die
, cu
);
16007 else if (child_die
->tag
== DW_TAG_subprogram
)
16009 /* Rust doesn't have member functions in the C++ sense.
16010 However, it does emit ordinary functions as children
16011 of a struct DIE. */
16012 if (cu
->language
== language_rust
)
16013 read_func_scope (child_die
, cu
);
16016 /* C++ member function. */
16017 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16020 else if (child_die
->tag
== DW_TAG_inheritance
)
16022 /* C++ base class field. */
16023 dwarf2_add_field (fi
, child_die
, cu
);
16025 else if (type_can_define_types (child_die
))
16026 dwarf2_add_type_defn (fi
, child_die
, cu
);
16027 else if (child_die
->tag
== DW_TAG_template_type_param
16028 || child_die
->tag
== DW_TAG_template_value_param
)
16030 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16033 template_args
->push_back (arg
);
16035 else if (child_die
->tag
== DW_TAG_variant
)
16037 /* In a variant we want to get the discriminant and also add a
16038 field for our sole member child. */
16039 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16041 for (die_info
*variant_child
= child_die
->child
;
16042 variant_child
!= NULL
;
16043 variant_child
= sibling_die (variant_child
))
16045 if (variant_child
->tag
== DW_TAG_member
)
16047 handle_struct_member_die (variant_child
, type
, fi
,
16048 template_args
, cu
);
16049 /* Only handle the one. */
16054 /* We don't handle this but we might as well report it if we see
16056 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16057 complaint (_("DW_AT_discr_list is not supported yet"
16058 " - DIE at %s [in module %s]"),
16059 sect_offset_str (child_die
->sect_off
),
16060 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16062 /* The first field was just added, so we can stash the
16063 discriminant there. */
16064 gdb_assert (!fi
->fields
.empty ());
16066 fi
->fields
.back ().variant
.default_branch
= true;
16068 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16072 /* Finish creating a structure or union type, including filling in
16073 its members and creating a symbol for it. */
16076 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16078 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16079 struct die_info
*child_die
;
16082 type
= get_die_type (die
, cu
);
16084 type
= read_structure_type (die
, cu
);
16086 /* When reading a DW_TAG_variant_part, we need to notice when we
16087 read the discriminant member, so we can record it later in the
16088 discriminant_info. */
16089 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16090 sect_offset discr_offset
{};
16091 bool has_template_parameters
= false;
16093 if (is_variant_part
)
16095 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16098 /* Maybe it's a univariant form, an extension we support.
16099 In this case arrange not to check the offset. */
16100 is_variant_part
= false;
16102 else if (attr_form_is_ref (discr
))
16104 struct dwarf2_cu
*target_cu
= cu
;
16105 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16107 discr_offset
= target_die
->sect_off
;
16111 complaint (_("DW_AT_discr does not have DIE reference form"
16112 " - DIE at %s [in module %s]"),
16113 sect_offset_str (die
->sect_off
),
16114 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16115 is_variant_part
= false;
16119 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16121 struct field_info fi
;
16122 std::vector
<struct symbol
*> template_args
;
16124 child_die
= die
->child
;
16126 while (child_die
&& child_die
->tag
)
16128 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16130 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16131 fi
.fields
.back ().variant
.is_discriminant
= true;
16133 child_die
= sibling_die (child_die
);
16136 /* Attach template arguments to type. */
16137 if (!template_args
.empty ())
16139 has_template_parameters
= true;
16140 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16141 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16142 TYPE_TEMPLATE_ARGUMENTS (type
)
16143 = XOBNEWVEC (&objfile
->objfile_obstack
,
16145 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16146 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16147 template_args
.data (),
16148 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16149 * sizeof (struct symbol
*)));
16152 /* Attach fields and member functions to the type. */
16154 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16155 if (!fi
.fnfieldlists
.empty ())
16157 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16159 /* Get the type which refers to the base class (possibly this
16160 class itself) which contains the vtable pointer for the current
16161 class from the DW_AT_containing_type attribute. This use of
16162 DW_AT_containing_type is a GNU extension. */
16164 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16166 struct type
*t
= die_containing_type (die
, cu
);
16168 set_type_vptr_basetype (type
, t
);
16173 /* Our own class provides vtbl ptr. */
16174 for (i
= TYPE_NFIELDS (t
) - 1;
16175 i
>= TYPE_N_BASECLASSES (t
);
16178 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16180 if (is_vtable_name (fieldname
, cu
))
16182 set_type_vptr_fieldno (type
, i
);
16187 /* Complain if virtual function table field not found. */
16188 if (i
< TYPE_N_BASECLASSES (t
))
16189 complaint (_("virtual function table pointer "
16190 "not found when defining class '%s'"),
16191 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16195 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16198 else if (cu
->producer
16199 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16201 /* The IBM XLC compiler does not provide direct indication
16202 of the containing type, but the vtable pointer is
16203 always named __vfp. */
16207 for (i
= TYPE_NFIELDS (type
) - 1;
16208 i
>= TYPE_N_BASECLASSES (type
);
16211 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16213 set_type_vptr_fieldno (type
, i
);
16214 set_type_vptr_basetype (type
, type
);
16221 /* Copy fi.typedef_field_list linked list elements content into the
16222 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16223 if (!fi
.typedef_field_list
.empty ())
16225 int count
= fi
.typedef_field_list
.size ();
16227 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16228 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16229 = ((struct decl_field
*)
16231 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16232 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16234 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16235 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16238 /* Copy fi.nested_types_list linked list elements content into the
16239 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16240 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16242 int count
= fi
.nested_types_list
.size ();
16244 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16245 TYPE_NESTED_TYPES_ARRAY (type
)
16246 = ((struct decl_field
*)
16247 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16248 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16250 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16251 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16255 quirk_gcc_member_function_pointer (type
, objfile
);
16256 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16257 cu
->rust_unions
.push_back (type
);
16259 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16260 snapshots) has been known to create a die giving a declaration
16261 for a class that has, as a child, a die giving a definition for a
16262 nested class. So we have to process our children even if the
16263 current die is a declaration. Normally, of course, a declaration
16264 won't have any children at all. */
16266 child_die
= die
->child
;
16268 while (child_die
!= NULL
&& child_die
->tag
)
16270 if (child_die
->tag
== DW_TAG_member
16271 || child_die
->tag
== DW_TAG_variable
16272 || child_die
->tag
== DW_TAG_inheritance
16273 || child_die
->tag
== DW_TAG_template_value_param
16274 || child_die
->tag
== DW_TAG_template_type_param
)
16279 process_die (child_die
, cu
);
16281 child_die
= sibling_die (child_die
);
16284 /* Do not consider external references. According to the DWARF standard,
16285 these DIEs are identified by the fact that they have no byte_size
16286 attribute, and a declaration attribute. */
16287 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16288 || !die_is_declaration (die
, cu
))
16290 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16292 if (has_template_parameters
)
16294 struct symtab
*symtab
;
16295 if (sym
!= nullptr)
16296 symtab
= symbol_symtab (sym
);
16297 else if (cu
->line_header
!= nullptr)
16299 /* Any related symtab will do. */
16301 = cu
->line_header
->file_names ()[0].symtab
;
16306 complaint (_("could not find suitable "
16307 "symtab for template parameter"
16308 " - DIE at %s [in module %s]"),
16309 sect_offset_str (die
->sect_off
),
16310 objfile_name (objfile
));
16313 if (symtab
!= nullptr)
16315 /* Make sure that the symtab is set on the new symbols.
16316 Even though they don't appear in this symtab directly,
16317 other parts of gdb assume that symbols do, and this is
16318 reasonably true. */
16319 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16320 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16326 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16327 update TYPE using some information only available in DIE's children. */
16330 update_enumeration_type_from_children (struct die_info
*die
,
16332 struct dwarf2_cu
*cu
)
16334 struct die_info
*child_die
;
16335 int unsigned_enum
= 1;
16339 auto_obstack obstack
;
16341 for (child_die
= die
->child
;
16342 child_die
!= NULL
&& child_die
->tag
;
16343 child_die
= sibling_die (child_die
))
16345 struct attribute
*attr
;
16347 const gdb_byte
*bytes
;
16348 struct dwarf2_locexpr_baton
*baton
;
16351 if (child_die
->tag
!= DW_TAG_enumerator
)
16354 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16358 name
= dwarf2_name (child_die
, cu
);
16360 name
= "<anonymous enumerator>";
16362 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16363 &value
, &bytes
, &baton
);
16369 else if ((mask
& value
) != 0)
16374 /* If we already know that the enum type is neither unsigned, nor
16375 a flag type, no need to look at the rest of the enumerates. */
16376 if (!unsigned_enum
&& !flag_enum
)
16381 TYPE_UNSIGNED (type
) = 1;
16383 TYPE_FLAG_ENUM (type
) = 1;
16386 /* Given a DW_AT_enumeration_type die, set its type. We do not
16387 complete the type's fields yet, or create any symbols. */
16389 static struct type
*
16390 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16392 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16394 struct attribute
*attr
;
16397 /* If the definition of this type lives in .debug_types, read that type.
16398 Don't follow DW_AT_specification though, that will take us back up
16399 the chain and we want to go down. */
16400 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16401 if (attr
!= nullptr)
16403 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16405 /* The type's CU may not be the same as CU.
16406 Ensure TYPE is recorded with CU in die_type_hash. */
16407 return set_die_type (die
, type
, cu
);
16410 type
= alloc_type (objfile
);
16412 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16413 name
= dwarf2_full_name (NULL
, die
, cu
);
16415 TYPE_NAME (type
) = name
;
16417 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16420 struct type
*underlying_type
= die_type (die
, cu
);
16422 TYPE_TARGET_TYPE (type
) = underlying_type
;
16425 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16426 if (attr
!= nullptr)
16428 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16432 TYPE_LENGTH (type
) = 0;
16435 maybe_set_alignment (cu
, die
, type
);
16437 /* The enumeration DIE can be incomplete. In Ada, any type can be
16438 declared as private in the package spec, and then defined only
16439 inside the package body. Such types are known as Taft Amendment
16440 Types. When another package uses such a type, an incomplete DIE
16441 may be generated by the compiler. */
16442 if (die_is_declaration (die
, cu
))
16443 TYPE_STUB (type
) = 1;
16445 /* Finish the creation of this type by using the enum's children.
16446 We must call this even when the underlying type has been provided
16447 so that we can determine if we're looking at a "flag" enum. */
16448 update_enumeration_type_from_children (die
, type
, cu
);
16450 /* If this type has an underlying type that is not a stub, then we
16451 may use its attributes. We always use the "unsigned" attribute
16452 in this situation, because ordinarily we guess whether the type
16453 is unsigned -- but the guess can be wrong and the underlying type
16454 can tell us the reality. However, we defer to a local size
16455 attribute if one exists, because this lets the compiler override
16456 the underlying type if needed. */
16457 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16459 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16460 if (TYPE_LENGTH (type
) == 0)
16461 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16462 if (TYPE_RAW_ALIGN (type
) == 0
16463 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16464 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16467 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16469 return set_die_type (die
, type
, cu
);
16472 /* Given a pointer to a die which begins an enumeration, process all
16473 the dies that define the members of the enumeration, and create the
16474 symbol for the enumeration type.
16476 NOTE: We reverse the order of the element list. */
16479 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16481 struct type
*this_type
;
16483 this_type
= get_die_type (die
, cu
);
16484 if (this_type
== NULL
)
16485 this_type
= read_enumeration_type (die
, cu
);
16487 if (die
->child
!= NULL
)
16489 struct die_info
*child_die
;
16490 struct symbol
*sym
;
16491 std::vector
<struct field
> fields
;
16494 child_die
= die
->child
;
16495 while (child_die
&& child_die
->tag
)
16497 if (child_die
->tag
!= DW_TAG_enumerator
)
16499 process_die (child_die
, cu
);
16503 name
= dwarf2_name (child_die
, cu
);
16506 sym
= new_symbol (child_die
, this_type
, cu
);
16508 fields
.emplace_back ();
16509 struct field
&field
= fields
.back ();
16511 FIELD_NAME (field
) = sym
->linkage_name ();
16512 FIELD_TYPE (field
) = NULL
;
16513 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16514 FIELD_BITSIZE (field
) = 0;
16518 child_die
= sibling_die (child_die
);
16521 if (!fields
.empty ())
16523 TYPE_NFIELDS (this_type
) = fields
.size ();
16524 TYPE_FIELDS (this_type
) = (struct field
*)
16525 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16526 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16527 sizeof (struct field
) * fields
.size ());
16531 /* If we are reading an enum from a .debug_types unit, and the enum
16532 is a declaration, and the enum is not the signatured type in the
16533 unit, then we do not want to add a symbol for it. Adding a
16534 symbol would in some cases obscure the true definition of the
16535 enum, giving users an incomplete type when the definition is
16536 actually available. Note that we do not want to do this for all
16537 enums which are just declarations, because C++0x allows forward
16538 enum declarations. */
16539 if (cu
->per_cu
->is_debug_types
16540 && die_is_declaration (die
, cu
))
16542 struct signatured_type
*sig_type
;
16544 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16545 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16546 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16550 new_symbol (die
, this_type
, cu
);
16553 /* Extract all information from a DW_TAG_array_type DIE and put it in
16554 the DIE's type field. For now, this only handles one dimensional
16557 static struct type
*
16558 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16560 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16561 struct die_info
*child_die
;
16563 struct type
*element_type
, *range_type
, *index_type
;
16564 struct attribute
*attr
;
16566 struct dynamic_prop
*byte_stride_prop
= NULL
;
16567 unsigned int bit_stride
= 0;
16569 element_type
= die_type (die
, cu
);
16571 /* The die_type call above may have already set the type for this DIE. */
16572 type
= get_die_type (die
, cu
);
16576 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16580 struct type
*prop_type
16581 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16584 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16585 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16589 complaint (_("unable to read array DW_AT_byte_stride "
16590 " - DIE at %s [in module %s]"),
16591 sect_offset_str (die
->sect_off
),
16592 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16593 /* Ignore this attribute. We will likely not be able to print
16594 arrays of this type correctly, but there is little we can do
16595 to help if we cannot read the attribute's value. */
16596 byte_stride_prop
= NULL
;
16600 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16602 bit_stride
= DW_UNSND (attr
);
16604 /* Irix 6.2 native cc creates array types without children for
16605 arrays with unspecified length. */
16606 if (die
->child
== NULL
)
16608 index_type
= objfile_type (objfile
)->builtin_int
;
16609 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16610 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16611 byte_stride_prop
, bit_stride
);
16612 return set_die_type (die
, type
, cu
);
16615 std::vector
<struct type
*> range_types
;
16616 child_die
= die
->child
;
16617 while (child_die
&& child_die
->tag
)
16619 if (child_die
->tag
== DW_TAG_subrange_type
)
16621 struct type
*child_type
= read_type_die (child_die
, cu
);
16623 if (child_type
!= NULL
)
16625 /* The range type was succesfully read. Save it for the
16626 array type creation. */
16627 range_types
.push_back (child_type
);
16630 child_die
= sibling_die (child_die
);
16633 /* Dwarf2 dimensions are output from left to right, create the
16634 necessary array types in backwards order. */
16636 type
= element_type
;
16638 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16642 while (i
< range_types
.size ())
16643 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16644 byte_stride_prop
, bit_stride
);
16648 size_t ndim
= range_types
.size ();
16650 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16651 byte_stride_prop
, bit_stride
);
16654 /* Understand Dwarf2 support for vector types (like they occur on
16655 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16656 array type. This is not part of the Dwarf2/3 standard yet, but a
16657 custom vendor extension. The main difference between a regular
16658 array and the vector variant is that vectors are passed by value
16660 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16661 if (attr
!= nullptr)
16662 make_vector_type (type
);
16664 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16665 implementation may choose to implement triple vectors using this
16667 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16668 if (attr
!= nullptr)
16670 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16671 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16673 complaint (_("DW_AT_byte_size for array type smaller "
16674 "than the total size of elements"));
16677 name
= dwarf2_name (die
, cu
);
16679 TYPE_NAME (type
) = name
;
16681 maybe_set_alignment (cu
, die
, type
);
16683 /* Install the type in the die. */
16684 set_die_type (die
, type
, cu
);
16686 /* set_die_type should be already done. */
16687 set_descriptive_type (type
, die
, cu
);
16692 static enum dwarf_array_dim_ordering
16693 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16695 struct attribute
*attr
;
16697 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16699 if (attr
!= nullptr)
16700 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16702 /* GNU F77 is a special case, as at 08/2004 array type info is the
16703 opposite order to the dwarf2 specification, but data is still
16704 laid out as per normal fortran.
16706 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16707 version checking. */
16709 if (cu
->language
== language_fortran
16710 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16712 return DW_ORD_row_major
;
16715 switch (cu
->language_defn
->la_array_ordering
)
16717 case array_column_major
:
16718 return DW_ORD_col_major
;
16719 case array_row_major
:
16721 return DW_ORD_row_major
;
16725 /* Extract all information from a DW_TAG_set_type DIE and put it in
16726 the DIE's type field. */
16728 static struct type
*
16729 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16731 struct type
*domain_type
, *set_type
;
16732 struct attribute
*attr
;
16734 domain_type
= die_type (die
, cu
);
16736 /* The die_type call above may have already set the type for this DIE. */
16737 set_type
= get_die_type (die
, cu
);
16741 set_type
= create_set_type (NULL
, domain_type
);
16743 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16744 if (attr
!= nullptr)
16745 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16747 maybe_set_alignment (cu
, die
, set_type
);
16749 return set_die_type (die
, set_type
, cu
);
16752 /* A helper for read_common_block that creates a locexpr baton.
16753 SYM is the symbol which we are marking as computed.
16754 COMMON_DIE is the DIE for the common block.
16755 COMMON_LOC is the location expression attribute for the common
16757 MEMBER_LOC is the location expression attribute for the particular
16758 member of the common block that we are processing.
16759 CU is the CU from which the above come. */
16762 mark_common_block_symbol_computed (struct symbol
*sym
,
16763 struct die_info
*common_die
,
16764 struct attribute
*common_loc
,
16765 struct attribute
*member_loc
,
16766 struct dwarf2_cu
*cu
)
16768 struct dwarf2_per_objfile
*dwarf2_per_objfile
16769 = cu
->per_cu
->dwarf2_per_objfile
;
16770 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16771 struct dwarf2_locexpr_baton
*baton
;
16773 unsigned int cu_off
;
16774 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16775 LONGEST offset
= 0;
16777 gdb_assert (common_loc
&& member_loc
);
16778 gdb_assert (attr_form_is_block (common_loc
));
16779 gdb_assert (attr_form_is_block (member_loc
)
16780 || attr_form_is_constant (member_loc
));
16782 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16783 baton
->per_cu
= cu
->per_cu
;
16784 gdb_assert (baton
->per_cu
);
16786 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16788 if (attr_form_is_constant (member_loc
))
16790 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16791 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16794 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16796 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16799 *ptr
++ = DW_OP_call4
;
16800 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16801 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16804 if (attr_form_is_constant (member_loc
))
16806 *ptr
++ = DW_OP_addr
;
16807 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16808 ptr
+= cu
->header
.addr_size
;
16812 /* We have to copy the data here, because DW_OP_call4 will only
16813 use a DW_AT_location attribute. */
16814 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16815 ptr
+= DW_BLOCK (member_loc
)->size
;
16818 *ptr
++ = DW_OP_plus
;
16819 gdb_assert (ptr
- baton
->data
== baton
->size
);
16821 SYMBOL_LOCATION_BATON (sym
) = baton
;
16822 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16825 /* Create appropriate locally-scoped variables for all the
16826 DW_TAG_common_block entries. Also create a struct common_block
16827 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16828 is used to separate the common blocks name namespace from regular
16832 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16834 struct attribute
*attr
;
16836 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16837 if (attr
!= nullptr)
16839 /* Support the .debug_loc offsets. */
16840 if (attr_form_is_block (attr
))
16844 else if (attr_form_is_section_offset (attr
))
16846 dwarf2_complex_location_expr_complaint ();
16851 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16852 "common block member");
16857 if (die
->child
!= NULL
)
16859 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16860 struct die_info
*child_die
;
16861 size_t n_entries
= 0, size
;
16862 struct common_block
*common_block
;
16863 struct symbol
*sym
;
16865 for (child_die
= die
->child
;
16866 child_die
&& child_die
->tag
;
16867 child_die
= sibling_die (child_die
))
16870 size
= (sizeof (struct common_block
)
16871 + (n_entries
- 1) * sizeof (struct symbol
*));
16873 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16875 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16876 common_block
->n_entries
= 0;
16878 for (child_die
= die
->child
;
16879 child_die
&& child_die
->tag
;
16880 child_die
= sibling_die (child_die
))
16882 /* Create the symbol in the DW_TAG_common_block block in the current
16884 sym
= new_symbol (child_die
, NULL
, cu
);
16887 struct attribute
*member_loc
;
16889 common_block
->contents
[common_block
->n_entries
++] = sym
;
16891 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16895 /* GDB has handled this for a long time, but it is
16896 not specified by DWARF. It seems to have been
16897 emitted by gfortran at least as recently as:
16898 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16899 complaint (_("Variable in common block has "
16900 "DW_AT_data_member_location "
16901 "- DIE at %s [in module %s]"),
16902 sect_offset_str (child_die
->sect_off
),
16903 objfile_name (objfile
));
16905 if (attr_form_is_section_offset (member_loc
))
16906 dwarf2_complex_location_expr_complaint ();
16907 else if (attr_form_is_constant (member_loc
)
16908 || attr_form_is_block (member_loc
))
16910 if (attr
!= nullptr)
16911 mark_common_block_symbol_computed (sym
, die
, attr
,
16915 dwarf2_complex_location_expr_complaint ();
16920 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16921 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16925 /* Create a type for a C++ namespace. */
16927 static struct type
*
16928 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16930 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16931 const char *previous_prefix
, *name
;
16935 /* For extensions, reuse the type of the original namespace. */
16936 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16938 struct die_info
*ext_die
;
16939 struct dwarf2_cu
*ext_cu
= cu
;
16941 ext_die
= dwarf2_extension (die
, &ext_cu
);
16942 type
= read_type_die (ext_die
, ext_cu
);
16944 /* EXT_CU may not be the same as CU.
16945 Ensure TYPE is recorded with CU in die_type_hash. */
16946 return set_die_type (die
, type
, cu
);
16949 name
= namespace_name (die
, &is_anonymous
, cu
);
16951 /* Now build the name of the current namespace. */
16953 previous_prefix
= determine_prefix (die
, cu
);
16954 if (previous_prefix
[0] != '\0')
16955 name
= typename_concat (&objfile
->objfile_obstack
,
16956 previous_prefix
, name
, 0, cu
);
16958 /* Create the type. */
16959 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16961 return set_die_type (die
, type
, cu
);
16964 /* Read a namespace scope. */
16967 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16969 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16972 /* Add a symbol associated to this if we haven't seen the namespace
16973 before. Also, add a using directive if it's an anonymous
16976 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
16980 type
= read_type_die (die
, cu
);
16981 new_symbol (die
, type
, cu
);
16983 namespace_name (die
, &is_anonymous
, cu
);
16986 const char *previous_prefix
= determine_prefix (die
, cu
);
16988 std::vector
<const char *> excludes
;
16989 add_using_directive (using_directives (cu
),
16990 previous_prefix
, TYPE_NAME (type
), NULL
,
16991 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
16995 if (die
->child
!= NULL
)
16997 struct die_info
*child_die
= die
->child
;
16999 while (child_die
&& child_die
->tag
)
17001 process_die (child_die
, cu
);
17002 child_die
= sibling_die (child_die
);
17007 /* Read a Fortran module as type. This DIE can be only a declaration used for
17008 imported module. Still we need that type as local Fortran "use ... only"
17009 declaration imports depend on the created type in determine_prefix. */
17011 static struct type
*
17012 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17014 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17015 const char *module_name
;
17018 module_name
= dwarf2_name (die
, cu
);
17019 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17021 return set_die_type (die
, type
, cu
);
17024 /* Read a Fortran module. */
17027 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17029 struct die_info
*child_die
= die
->child
;
17032 type
= read_type_die (die
, cu
);
17033 new_symbol (die
, type
, cu
);
17035 while (child_die
&& child_die
->tag
)
17037 process_die (child_die
, cu
);
17038 child_die
= sibling_die (child_die
);
17042 /* Return the name of the namespace represented by DIE. Set
17043 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17046 static const char *
17047 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17049 struct die_info
*current_die
;
17050 const char *name
= NULL
;
17052 /* Loop through the extensions until we find a name. */
17054 for (current_die
= die
;
17055 current_die
!= NULL
;
17056 current_die
= dwarf2_extension (die
, &cu
))
17058 /* We don't use dwarf2_name here so that we can detect the absence
17059 of a name -> anonymous namespace. */
17060 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17066 /* Is it an anonymous namespace? */
17068 *is_anonymous
= (name
== NULL
);
17070 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17075 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17076 the user defined type vector. */
17078 static struct type
*
17079 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17081 struct gdbarch
*gdbarch
17082 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17083 struct comp_unit_head
*cu_header
= &cu
->header
;
17085 struct attribute
*attr_byte_size
;
17086 struct attribute
*attr_address_class
;
17087 int byte_size
, addr_class
;
17088 struct type
*target_type
;
17090 target_type
= die_type (die
, cu
);
17092 /* The die_type call above may have already set the type for this DIE. */
17093 type
= get_die_type (die
, cu
);
17097 type
= lookup_pointer_type (target_type
);
17099 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17100 if (attr_byte_size
)
17101 byte_size
= DW_UNSND (attr_byte_size
);
17103 byte_size
= cu_header
->addr_size
;
17105 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17106 if (attr_address_class
)
17107 addr_class
= DW_UNSND (attr_address_class
);
17109 addr_class
= DW_ADDR_none
;
17111 ULONGEST alignment
= get_alignment (cu
, die
);
17113 /* If the pointer size, alignment, or address class is different
17114 than the default, create a type variant marked as such and set
17115 the length accordingly. */
17116 if (TYPE_LENGTH (type
) != byte_size
17117 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17118 && alignment
!= TYPE_RAW_ALIGN (type
))
17119 || addr_class
!= DW_ADDR_none
)
17121 if (gdbarch_address_class_type_flags_p (gdbarch
))
17125 type_flags
= gdbarch_address_class_type_flags
17126 (gdbarch
, byte_size
, addr_class
);
17127 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17129 type
= make_type_with_address_space (type
, type_flags
);
17131 else if (TYPE_LENGTH (type
) != byte_size
)
17133 complaint (_("invalid pointer size %d"), byte_size
);
17135 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17137 complaint (_("Invalid DW_AT_alignment"
17138 " - DIE at %s [in module %s]"),
17139 sect_offset_str (die
->sect_off
),
17140 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17144 /* Should we also complain about unhandled address classes? */
17148 TYPE_LENGTH (type
) = byte_size
;
17149 set_type_align (type
, alignment
);
17150 return set_die_type (die
, type
, cu
);
17153 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17154 the user defined type vector. */
17156 static struct type
*
17157 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17160 struct type
*to_type
;
17161 struct type
*domain
;
17163 to_type
= die_type (die
, cu
);
17164 domain
= die_containing_type (die
, cu
);
17166 /* The calls above may have already set the type for this DIE. */
17167 type
= get_die_type (die
, cu
);
17171 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17172 type
= lookup_methodptr_type (to_type
);
17173 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17175 struct type
*new_type
17176 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17178 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17179 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17180 TYPE_VARARGS (to_type
));
17181 type
= lookup_methodptr_type (new_type
);
17184 type
= lookup_memberptr_type (to_type
, domain
);
17186 return set_die_type (die
, type
, cu
);
17189 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17190 the user defined type vector. */
17192 static struct type
*
17193 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17194 enum type_code refcode
)
17196 struct comp_unit_head
*cu_header
= &cu
->header
;
17197 struct type
*type
, *target_type
;
17198 struct attribute
*attr
;
17200 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17202 target_type
= die_type (die
, cu
);
17204 /* The die_type call above may have already set the type for this DIE. */
17205 type
= get_die_type (die
, cu
);
17209 type
= lookup_reference_type (target_type
, refcode
);
17210 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17211 if (attr
!= nullptr)
17213 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17217 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17219 maybe_set_alignment (cu
, die
, type
);
17220 return set_die_type (die
, type
, cu
);
17223 /* Add the given cv-qualifiers to the element type of the array. GCC
17224 outputs DWARF type qualifiers that apply to an array, not the
17225 element type. But GDB relies on the array element type to carry
17226 the cv-qualifiers. This mimics section 6.7.3 of the C99
17229 static struct type
*
17230 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17231 struct type
*base_type
, int cnst
, int voltl
)
17233 struct type
*el_type
, *inner_array
;
17235 base_type
= copy_type (base_type
);
17236 inner_array
= base_type
;
17238 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17240 TYPE_TARGET_TYPE (inner_array
) =
17241 copy_type (TYPE_TARGET_TYPE (inner_array
));
17242 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17245 el_type
= TYPE_TARGET_TYPE (inner_array
);
17246 cnst
|= TYPE_CONST (el_type
);
17247 voltl
|= TYPE_VOLATILE (el_type
);
17248 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17250 return set_die_type (die
, base_type
, cu
);
17253 static struct type
*
17254 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17256 struct type
*base_type
, *cv_type
;
17258 base_type
= die_type (die
, cu
);
17260 /* The die_type call above may have already set the type for this DIE. */
17261 cv_type
= get_die_type (die
, cu
);
17265 /* In case the const qualifier is applied to an array type, the element type
17266 is so qualified, not the array type (section 6.7.3 of C99). */
17267 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17268 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17270 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17271 return set_die_type (die
, cv_type
, cu
);
17274 static struct type
*
17275 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17277 struct type
*base_type
, *cv_type
;
17279 base_type
= die_type (die
, cu
);
17281 /* The die_type call above may have already set the type for this DIE. */
17282 cv_type
= get_die_type (die
, cu
);
17286 /* In case the volatile qualifier is applied to an array type, the
17287 element type is so qualified, not the array type (section 6.7.3
17289 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17290 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17292 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17293 return set_die_type (die
, cv_type
, cu
);
17296 /* Handle DW_TAG_restrict_type. */
17298 static struct type
*
17299 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17301 struct type
*base_type
, *cv_type
;
17303 base_type
= die_type (die
, cu
);
17305 /* The die_type call above may have already set the type for this DIE. */
17306 cv_type
= get_die_type (die
, cu
);
17310 cv_type
= make_restrict_type (base_type
);
17311 return set_die_type (die
, cv_type
, cu
);
17314 /* Handle DW_TAG_atomic_type. */
17316 static struct type
*
17317 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17319 struct type
*base_type
, *cv_type
;
17321 base_type
= die_type (die
, cu
);
17323 /* The die_type call above may have already set the type for this DIE. */
17324 cv_type
= get_die_type (die
, cu
);
17328 cv_type
= make_atomic_type (base_type
);
17329 return set_die_type (die
, cv_type
, cu
);
17332 /* Extract all information from a DW_TAG_string_type DIE and add to
17333 the user defined type vector. It isn't really a user defined type,
17334 but it behaves like one, with other DIE's using an AT_user_def_type
17335 attribute to reference it. */
17337 static struct type
*
17338 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17340 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17341 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17342 struct type
*type
, *range_type
, *index_type
, *char_type
;
17343 struct attribute
*attr
;
17344 struct dynamic_prop prop
;
17345 bool length_is_constant
= true;
17348 /* There are a couple of places where bit sizes might be made use of
17349 when parsing a DW_TAG_string_type, however, no producer that we know
17350 of make use of these. Handling bit sizes that are a multiple of the
17351 byte size is easy enough, but what about other bit sizes? Lets deal
17352 with that problem when we have to. Warn about these attributes being
17353 unsupported, then parse the type and ignore them like we always
17355 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17356 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17358 static bool warning_printed
= false;
17359 if (!warning_printed
)
17361 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17362 "currently supported on DW_TAG_string_type."));
17363 warning_printed
= true;
17367 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17368 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17370 /* The string length describes the location at which the length of
17371 the string can be found. The size of the length field can be
17372 specified with one of the attributes below. */
17373 struct type
*prop_type
;
17374 struct attribute
*len
17375 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17376 if (len
== nullptr)
17377 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17378 if (len
!= nullptr && attr_form_is_constant (len
))
17380 /* Pass 0 as the default as we know this attribute is constant
17381 and the default value will not be returned. */
17382 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17383 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17387 /* If the size is not specified then we assume it is the size of
17388 an address on this target. */
17389 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17392 /* Convert the attribute into a dynamic property. */
17393 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17396 length_is_constant
= false;
17398 else if (attr
!= nullptr)
17400 /* This DW_AT_string_length just contains the length with no
17401 indirection. There's no need to create a dynamic property in this
17402 case. Pass 0 for the default value as we know it will not be
17403 returned in this case. */
17404 length
= dwarf2_get_attr_constant_value (attr
, 0);
17406 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17408 /* We don't currently support non-constant byte sizes for strings. */
17409 length
= dwarf2_get_attr_constant_value (attr
, 1);
17413 /* Use 1 as a fallback length if we have nothing else. */
17417 index_type
= objfile_type (objfile
)->builtin_int
;
17418 if (length_is_constant
)
17419 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17422 struct dynamic_prop low_bound
;
17424 low_bound
.kind
= PROP_CONST
;
17425 low_bound
.data
.const_val
= 1;
17426 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17428 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17429 type
= create_string_type (NULL
, char_type
, range_type
);
17431 return set_die_type (die
, type
, cu
);
17434 /* Assuming that DIE corresponds to a function, returns nonzero
17435 if the function is prototyped. */
17438 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17440 struct attribute
*attr
;
17442 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17443 if (attr
&& (DW_UNSND (attr
) != 0))
17446 /* The DWARF standard implies that the DW_AT_prototyped attribute
17447 is only meaningful for C, but the concept also extends to other
17448 languages that allow unprototyped functions (Eg: Objective C).
17449 For all other languages, assume that functions are always
17451 if (cu
->language
!= language_c
17452 && cu
->language
!= language_objc
17453 && cu
->language
!= language_opencl
)
17456 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17457 prototyped and unprototyped functions; default to prototyped,
17458 since that is more common in modern code (and RealView warns
17459 about unprototyped functions). */
17460 if (producer_is_realview (cu
->producer
))
17466 /* Handle DIES due to C code like:
17470 int (*funcp)(int a, long l);
17474 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17476 static struct type
*
17477 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17479 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17480 struct type
*type
; /* Type that this function returns. */
17481 struct type
*ftype
; /* Function that returns above type. */
17482 struct attribute
*attr
;
17484 type
= die_type (die
, cu
);
17486 /* The die_type call above may have already set the type for this DIE. */
17487 ftype
= get_die_type (die
, cu
);
17491 ftype
= lookup_function_type (type
);
17493 if (prototyped_function_p (die
, cu
))
17494 TYPE_PROTOTYPED (ftype
) = 1;
17496 /* Store the calling convention in the type if it's available in
17497 the subroutine die. Otherwise set the calling convention to
17498 the default value DW_CC_normal. */
17499 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17500 if (attr
!= nullptr
17501 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17502 TYPE_CALLING_CONVENTION (ftype
)
17503 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17504 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17505 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17507 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17509 /* Record whether the function returns normally to its caller or not
17510 if the DWARF producer set that information. */
17511 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17512 if (attr
&& (DW_UNSND (attr
) != 0))
17513 TYPE_NO_RETURN (ftype
) = 1;
17515 /* We need to add the subroutine type to the die immediately so
17516 we don't infinitely recurse when dealing with parameters
17517 declared as the same subroutine type. */
17518 set_die_type (die
, ftype
, cu
);
17520 if (die
->child
!= NULL
)
17522 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17523 struct die_info
*child_die
;
17524 int nparams
, iparams
;
17526 /* Count the number of parameters.
17527 FIXME: GDB currently ignores vararg functions, but knows about
17528 vararg member functions. */
17530 child_die
= die
->child
;
17531 while (child_die
&& child_die
->tag
)
17533 if (child_die
->tag
== DW_TAG_formal_parameter
)
17535 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17536 TYPE_VARARGS (ftype
) = 1;
17537 child_die
= sibling_die (child_die
);
17540 /* Allocate storage for parameters and fill them in. */
17541 TYPE_NFIELDS (ftype
) = nparams
;
17542 TYPE_FIELDS (ftype
) = (struct field
*)
17543 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17545 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17546 even if we error out during the parameters reading below. */
17547 for (iparams
= 0; iparams
< nparams
; iparams
++)
17548 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17551 child_die
= die
->child
;
17552 while (child_die
&& child_die
->tag
)
17554 if (child_die
->tag
== DW_TAG_formal_parameter
)
17556 struct type
*arg_type
;
17558 /* DWARF version 2 has no clean way to discern C++
17559 static and non-static member functions. G++ helps
17560 GDB by marking the first parameter for non-static
17561 member functions (which is the this pointer) as
17562 artificial. We pass this information to
17563 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17565 DWARF version 3 added DW_AT_object_pointer, which GCC
17566 4.5 does not yet generate. */
17567 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17568 if (attr
!= nullptr)
17569 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17571 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17572 arg_type
= die_type (child_die
, cu
);
17574 /* RealView does not mark THIS as const, which the testsuite
17575 expects. GCC marks THIS as const in method definitions,
17576 but not in the class specifications (GCC PR 43053). */
17577 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17578 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17581 struct dwarf2_cu
*arg_cu
= cu
;
17582 const char *name
= dwarf2_name (child_die
, cu
);
17584 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17585 if (attr
!= nullptr)
17587 /* If the compiler emits this, use it. */
17588 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17591 else if (name
&& strcmp (name
, "this") == 0)
17592 /* Function definitions will have the argument names. */
17594 else if (name
== NULL
&& iparams
== 0)
17595 /* Declarations may not have the names, so like
17596 elsewhere in GDB, assume an artificial first
17597 argument is "this". */
17601 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17605 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17608 child_die
= sibling_die (child_die
);
17615 static struct type
*
17616 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17618 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17619 const char *name
= NULL
;
17620 struct type
*this_type
, *target_type
;
17622 name
= dwarf2_full_name (NULL
, die
, cu
);
17623 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17624 TYPE_TARGET_STUB (this_type
) = 1;
17625 set_die_type (die
, this_type
, cu
);
17626 target_type
= die_type (die
, cu
);
17627 if (target_type
!= this_type
)
17628 TYPE_TARGET_TYPE (this_type
) = target_type
;
17631 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17632 spec and cause infinite loops in GDB. */
17633 complaint (_("Self-referential DW_TAG_typedef "
17634 "- DIE at %s [in module %s]"),
17635 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17636 TYPE_TARGET_TYPE (this_type
) = NULL
;
17641 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17642 (which may be different from NAME) to the architecture back-end to allow
17643 it to guess the correct format if necessary. */
17645 static struct type
*
17646 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17647 const char *name_hint
, enum bfd_endian byte_order
)
17649 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17650 const struct floatformat
**format
;
17653 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17655 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17657 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17662 /* Allocate an integer type of size BITS and name NAME. */
17664 static struct type
*
17665 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17666 int bits
, int unsigned_p
, const char *name
)
17670 /* Versions of Intel's C Compiler generate an integer type called "void"
17671 instead of using DW_TAG_unspecified_type. This has been seen on
17672 at least versions 14, 17, and 18. */
17673 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17674 && strcmp (name
, "void") == 0)
17675 type
= objfile_type (objfile
)->builtin_void
;
17677 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17682 /* Initialise and return a floating point type of size BITS suitable for
17683 use as a component of a complex number. The NAME_HINT is passed through
17684 when initialising the floating point type and is the name of the complex
17687 As DWARF doesn't currently provide an explicit name for the components
17688 of a complex number, but it can be helpful to have these components
17689 named, we try to select a suitable name based on the size of the
17691 static struct type
*
17692 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17693 struct objfile
*objfile
,
17694 int bits
, const char *name_hint
,
17695 enum bfd_endian byte_order
)
17697 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17698 struct type
*tt
= nullptr;
17700 /* Try to find a suitable floating point builtin type of size BITS.
17701 We're going to use the name of this type as the name for the complex
17702 target type that we are about to create. */
17703 switch (cu
->language
)
17705 case language_fortran
:
17709 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17712 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17714 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17716 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17724 tt
= builtin_type (gdbarch
)->builtin_float
;
17727 tt
= builtin_type (gdbarch
)->builtin_double
;
17729 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17731 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17737 /* If the type we found doesn't match the size we were looking for, then
17738 pretend we didn't find a type at all, the complex target type we
17739 create will then be nameless. */
17740 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17743 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17744 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17747 /* Find a representation of a given base type and install
17748 it in the TYPE field of the die. */
17750 static struct type
*
17751 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17753 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17755 struct attribute
*attr
;
17756 int encoding
= 0, bits
= 0;
17760 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17761 if (attr
!= nullptr)
17762 encoding
= DW_UNSND (attr
);
17763 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17764 if (attr
!= nullptr)
17765 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17766 name
= dwarf2_name (die
, cu
);
17768 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17770 arch
= get_objfile_arch (objfile
);
17771 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17773 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17776 int endianity
= DW_UNSND (attr
);
17781 byte_order
= BFD_ENDIAN_BIG
;
17783 case DW_END_little
:
17784 byte_order
= BFD_ENDIAN_LITTLE
;
17787 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17794 case DW_ATE_address
:
17795 /* Turn DW_ATE_address into a void * pointer. */
17796 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17797 type
= init_pointer_type (objfile
, bits
, name
, type
);
17799 case DW_ATE_boolean
:
17800 type
= init_boolean_type (objfile
, bits
, 1, name
);
17802 case DW_ATE_complex_float
:
17803 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17805 type
= init_complex_type (objfile
, name
, type
);
17807 case DW_ATE_decimal_float
:
17808 type
= init_decfloat_type (objfile
, bits
, name
);
17811 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17813 case DW_ATE_signed
:
17814 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17816 case DW_ATE_unsigned
:
17817 if (cu
->language
== language_fortran
17819 && startswith (name
, "character("))
17820 type
= init_character_type (objfile
, bits
, 1, name
);
17822 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17824 case DW_ATE_signed_char
:
17825 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17826 || cu
->language
== language_pascal
17827 || cu
->language
== language_fortran
)
17828 type
= init_character_type (objfile
, bits
, 0, name
);
17830 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17832 case DW_ATE_unsigned_char
:
17833 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17834 || cu
->language
== language_pascal
17835 || cu
->language
== language_fortran
17836 || cu
->language
== language_rust
)
17837 type
= init_character_type (objfile
, bits
, 1, name
);
17839 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17844 type
= builtin_type (arch
)->builtin_char16
;
17845 else if (bits
== 32)
17846 type
= builtin_type (arch
)->builtin_char32
;
17849 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17851 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17853 return set_die_type (die
, type
, cu
);
17858 complaint (_("unsupported DW_AT_encoding: '%s'"),
17859 dwarf_type_encoding_name (encoding
));
17860 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17864 if (name
&& strcmp (name
, "char") == 0)
17865 TYPE_NOSIGN (type
) = 1;
17867 maybe_set_alignment (cu
, die
, type
);
17869 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17871 return set_die_type (die
, type
, cu
);
17874 /* Parse dwarf attribute if it's a block, reference or constant and put the
17875 resulting value of the attribute into struct bound_prop.
17876 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17879 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17880 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17881 struct type
*default_type
)
17883 struct dwarf2_property_baton
*baton
;
17884 struct obstack
*obstack
17885 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17887 gdb_assert (default_type
!= NULL
);
17889 if (attr
== NULL
|| prop
== NULL
)
17892 if (attr_form_is_block (attr
))
17894 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17895 baton
->property_type
= default_type
;
17896 baton
->locexpr
.per_cu
= cu
->per_cu
;
17897 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17898 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17899 switch (attr
->name
)
17901 case DW_AT_string_length
:
17902 baton
->locexpr
.is_reference
= true;
17905 baton
->locexpr
.is_reference
= false;
17908 prop
->data
.baton
= baton
;
17909 prop
->kind
= PROP_LOCEXPR
;
17910 gdb_assert (prop
->data
.baton
!= NULL
);
17912 else if (attr_form_is_ref (attr
))
17914 struct dwarf2_cu
*target_cu
= cu
;
17915 struct die_info
*target_die
;
17916 struct attribute
*target_attr
;
17918 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17919 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17920 if (target_attr
== NULL
)
17921 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17923 if (target_attr
== NULL
)
17926 switch (target_attr
->name
)
17928 case DW_AT_location
:
17929 if (attr_form_is_section_offset (target_attr
))
17931 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17932 baton
->property_type
= die_type (target_die
, target_cu
);
17933 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17934 prop
->data
.baton
= baton
;
17935 prop
->kind
= PROP_LOCLIST
;
17936 gdb_assert (prop
->data
.baton
!= NULL
);
17938 else if (attr_form_is_block (target_attr
))
17940 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17941 baton
->property_type
= die_type (target_die
, target_cu
);
17942 baton
->locexpr
.per_cu
= cu
->per_cu
;
17943 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17944 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17945 baton
->locexpr
.is_reference
= true;
17946 prop
->data
.baton
= baton
;
17947 prop
->kind
= PROP_LOCEXPR
;
17948 gdb_assert (prop
->data
.baton
!= NULL
);
17952 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17953 "dynamic property");
17957 case DW_AT_data_member_location
:
17961 if (!handle_data_member_location (target_die
, target_cu
,
17965 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17966 baton
->property_type
= read_type_die (target_die
->parent
,
17968 baton
->offset_info
.offset
= offset
;
17969 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17970 prop
->data
.baton
= baton
;
17971 prop
->kind
= PROP_ADDR_OFFSET
;
17976 else if (attr_form_is_constant (attr
))
17978 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
17979 prop
->kind
= PROP_CONST
;
17983 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
17984 dwarf2_name (die
, cu
));
17991 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
17992 UNSIGNED_P controls if the integer is unsigned or not. */
17994 static struct type
*
17995 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
17996 int size_in_bytes
, bool unsigned_p
)
17998 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
17999 struct type
*int_type
;
18001 /* Helper macro to examine the various builtin types. */
18002 #define TRY_TYPE(F) \
18003 int_type = (unsigned_p \
18004 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18005 : objfile_type (objfile)->builtin_ ## F); \
18006 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18013 TRY_TYPE (long_long
);
18017 gdb_assert_not_reached ("unable to find suitable integer type");
18020 /* Find an integer type the same size as the address size given in the
18021 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18022 is unsigned or not. */
18024 static struct type
*
18025 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18028 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18029 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18032 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18033 present (which is valid) then compute the default type based on the
18034 compilation units address size. */
18036 static struct type
*
18037 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18039 struct type
*index_type
= die_type (die
, cu
);
18041 /* Dwarf-2 specifications explicitly allows to create subrange types
18042 without specifying a base type.
18043 In that case, the base type must be set to the type of
18044 the lower bound, upper bound or count, in that order, if any of these
18045 three attributes references an object that has a type.
18046 If no base type is found, the Dwarf-2 specifications say that
18047 a signed integer type of size equal to the size of an address should
18049 For the following C code: `extern char gdb_int [];'
18050 GCC produces an empty range DIE.
18051 FIXME: muller/2010-05-28: Possible references to object for low bound,
18052 high bound or count are not yet handled by this code. */
18053 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18054 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18059 /* Read the given DW_AT_subrange DIE. */
18061 static struct type
*
18062 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18064 struct type
*base_type
, *orig_base_type
;
18065 struct type
*range_type
;
18066 struct attribute
*attr
;
18067 struct dynamic_prop low
, high
;
18068 int low_default_is_valid
;
18069 int high_bound_is_count
= 0;
18071 ULONGEST negative_mask
;
18073 orig_base_type
= read_subrange_index_type (die
, cu
);
18075 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18076 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18077 creating the range type, but we use the result of check_typedef
18078 when examining properties of the type. */
18079 base_type
= check_typedef (orig_base_type
);
18081 /* The die_type call above may have already set the type for this DIE. */
18082 range_type
= get_die_type (die
, cu
);
18086 low
.kind
= PROP_CONST
;
18087 high
.kind
= PROP_CONST
;
18088 high
.data
.const_val
= 0;
18090 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18091 omitting DW_AT_lower_bound. */
18092 switch (cu
->language
)
18095 case language_cplus
:
18096 low
.data
.const_val
= 0;
18097 low_default_is_valid
= 1;
18099 case language_fortran
:
18100 low
.data
.const_val
= 1;
18101 low_default_is_valid
= 1;
18104 case language_objc
:
18105 case language_rust
:
18106 low
.data
.const_val
= 0;
18107 low_default_is_valid
= (cu
->header
.version
>= 4);
18111 case language_pascal
:
18112 low
.data
.const_val
= 1;
18113 low_default_is_valid
= (cu
->header
.version
>= 4);
18116 low
.data
.const_val
= 0;
18117 low_default_is_valid
= 0;
18121 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18122 if (attr
!= nullptr)
18123 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18124 else if (!low_default_is_valid
)
18125 complaint (_("Missing DW_AT_lower_bound "
18126 "- DIE at %s [in module %s]"),
18127 sect_offset_str (die
->sect_off
),
18128 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18130 struct attribute
*attr_ub
, *attr_count
;
18131 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18132 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18134 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18135 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18137 /* If bounds are constant do the final calculation here. */
18138 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18139 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18141 high_bound_is_count
= 1;
18145 if (attr_ub
!= NULL
)
18146 complaint (_("Unresolved DW_AT_upper_bound "
18147 "- DIE at %s [in module %s]"),
18148 sect_offset_str (die
->sect_off
),
18149 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18150 if (attr_count
!= NULL
)
18151 complaint (_("Unresolved DW_AT_count "
18152 "- DIE at %s [in module %s]"),
18153 sect_offset_str (die
->sect_off
),
18154 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18159 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18160 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18161 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18163 /* Normally, the DWARF producers are expected to use a signed
18164 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18165 But this is unfortunately not always the case, as witnessed
18166 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18167 is used instead. To work around that ambiguity, we treat
18168 the bounds as signed, and thus sign-extend their values, when
18169 the base type is signed. */
18171 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18172 if (low
.kind
== PROP_CONST
18173 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18174 low
.data
.const_val
|= negative_mask
;
18175 if (high
.kind
== PROP_CONST
18176 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18177 high
.data
.const_val
|= negative_mask
;
18179 /* Check for bit and byte strides. */
18180 struct dynamic_prop byte_stride_prop
;
18181 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18182 if (attr_byte_stride
!= nullptr)
18184 struct type
*prop_type
18185 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18186 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18190 struct dynamic_prop bit_stride_prop
;
18191 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18192 if (attr_bit_stride
!= nullptr)
18194 /* It only makes sense to have either a bit or byte stride. */
18195 if (attr_byte_stride
!= nullptr)
18197 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18198 "- DIE at %s [in module %s]"),
18199 sect_offset_str (die
->sect_off
),
18200 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18201 attr_bit_stride
= nullptr;
18205 struct type
*prop_type
18206 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18207 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18212 if (attr_byte_stride
!= nullptr
18213 || attr_bit_stride
!= nullptr)
18215 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18216 struct dynamic_prop
*stride
18217 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18220 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18221 &high
, bias
, stride
, byte_stride_p
);
18224 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18226 if (high_bound_is_count
)
18227 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18229 /* Ada expects an empty array on no boundary attributes. */
18230 if (attr
== NULL
&& cu
->language
!= language_ada
)
18231 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18233 name
= dwarf2_name (die
, cu
);
18235 TYPE_NAME (range_type
) = name
;
18237 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18238 if (attr
!= nullptr)
18239 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18241 maybe_set_alignment (cu
, die
, range_type
);
18243 set_die_type (die
, range_type
, cu
);
18245 /* set_die_type should be already done. */
18246 set_descriptive_type (range_type
, die
, cu
);
18251 static struct type
*
18252 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18256 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18258 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18260 /* In Ada, an unspecified type is typically used when the description
18261 of the type is deferred to a different unit. When encountering
18262 such a type, we treat it as a stub, and try to resolve it later on,
18264 if (cu
->language
== language_ada
)
18265 TYPE_STUB (type
) = 1;
18267 return set_die_type (die
, type
, cu
);
18270 /* Read a single die and all its descendents. Set the die's sibling
18271 field to NULL; set other fields in the die correctly, and set all
18272 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18273 location of the info_ptr after reading all of those dies. PARENT
18274 is the parent of the die in question. */
18276 static struct die_info
*
18277 read_die_and_children (const struct die_reader_specs
*reader
,
18278 const gdb_byte
*info_ptr
,
18279 const gdb_byte
**new_info_ptr
,
18280 struct die_info
*parent
)
18282 struct die_info
*die
;
18283 const gdb_byte
*cur_ptr
;
18286 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18289 *new_info_ptr
= cur_ptr
;
18292 store_in_ref_table (die
, reader
->cu
);
18295 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18299 *new_info_ptr
= cur_ptr
;
18302 die
->sibling
= NULL
;
18303 die
->parent
= parent
;
18307 /* Read a die, all of its descendents, and all of its siblings; set
18308 all of the fields of all of the dies correctly. Arguments are as
18309 in read_die_and_children. */
18311 static struct die_info
*
18312 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18313 const gdb_byte
*info_ptr
,
18314 const gdb_byte
**new_info_ptr
,
18315 struct die_info
*parent
)
18317 struct die_info
*first_die
, *last_sibling
;
18318 const gdb_byte
*cur_ptr
;
18320 cur_ptr
= info_ptr
;
18321 first_die
= last_sibling
= NULL
;
18325 struct die_info
*die
18326 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18330 *new_info_ptr
= cur_ptr
;
18337 last_sibling
->sibling
= die
;
18339 last_sibling
= die
;
18343 /* Read a die, all of its descendents, and all of its siblings; set
18344 all of the fields of all of the dies correctly. Arguments are as
18345 in read_die_and_children.
18346 This the main entry point for reading a DIE and all its children. */
18348 static struct die_info
*
18349 read_die_and_siblings (const struct die_reader_specs
*reader
,
18350 const gdb_byte
*info_ptr
,
18351 const gdb_byte
**new_info_ptr
,
18352 struct die_info
*parent
)
18354 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18355 new_info_ptr
, parent
);
18357 if (dwarf_die_debug
)
18359 fprintf_unfiltered (gdb_stdlog
,
18360 "Read die from %s@0x%x of %s:\n",
18361 get_section_name (reader
->die_section
),
18362 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18363 bfd_get_filename (reader
->abfd
));
18364 dump_die (die
, dwarf_die_debug
);
18370 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18372 The caller is responsible for filling in the extra attributes
18373 and updating (*DIEP)->num_attrs.
18374 Set DIEP to point to a newly allocated die with its information,
18375 except for its child, sibling, and parent fields.
18376 Set HAS_CHILDREN to tell whether the die has children or not. */
18378 static const gdb_byte
*
18379 read_full_die_1 (const struct die_reader_specs
*reader
,
18380 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18381 int *has_children
, int num_extra_attrs
)
18383 unsigned int abbrev_number
, bytes_read
, i
;
18384 struct abbrev_info
*abbrev
;
18385 struct die_info
*die
;
18386 struct dwarf2_cu
*cu
= reader
->cu
;
18387 bfd
*abfd
= reader
->abfd
;
18389 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18390 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18391 info_ptr
+= bytes_read
;
18392 if (!abbrev_number
)
18399 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18401 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18403 bfd_get_filename (abfd
));
18405 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18406 die
->sect_off
= sect_off
;
18407 die
->tag
= abbrev
->tag
;
18408 die
->abbrev
= abbrev_number
;
18410 /* Make the result usable.
18411 The caller needs to update num_attrs after adding the extra
18413 die
->num_attrs
= abbrev
->num_attrs
;
18415 std::vector
<int> indexes_that_need_reprocess
;
18416 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18418 bool need_reprocess
;
18420 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18421 info_ptr
, &need_reprocess
);
18422 if (need_reprocess
)
18423 indexes_that_need_reprocess
.push_back (i
);
18426 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18427 if (attr
!= nullptr)
18428 cu
->str_offsets_base
= DW_UNSND (attr
);
18430 auto maybe_addr_base
= lookup_addr_base(die
);
18431 if (maybe_addr_base
.has_value ())
18432 cu
->addr_base
= *maybe_addr_base
;
18433 for (int index
: indexes_that_need_reprocess
)
18434 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18436 *has_children
= abbrev
->has_children
;
18440 /* Read a die and all its attributes.
18441 Set DIEP to point to a newly allocated die with its information,
18442 except for its child, sibling, and parent fields.
18443 Set HAS_CHILDREN to tell whether the die has children or not. */
18445 static const gdb_byte
*
18446 read_full_die (const struct die_reader_specs
*reader
,
18447 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18450 const gdb_byte
*result
;
18452 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18454 if (dwarf_die_debug
)
18456 fprintf_unfiltered (gdb_stdlog
,
18457 "Read die from %s@0x%x of %s:\n",
18458 get_section_name (reader
->die_section
),
18459 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18460 bfd_get_filename (reader
->abfd
));
18461 dump_die (*diep
, dwarf_die_debug
);
18467 /* Abbreviation tables.
18469 In DWARF version 2, the description of the debugging information is
18470 stored in a separate .debug_abbrev section. Before we read any
18471 dies from a section we read in all abbreviations and install them
18472 in a hash table. */
18474 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18476 struct abbrev_info
*
18477 abbrev_table::alloc_abbrev ()
18479 struct abbrev_info
*abbrev
;
18481 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18482 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18487 /* Add an abbreviation to the table. */
18490 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18491 struct abbrev_info
*abbrev
)
18493 unsigned int hash_number
;
18495 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18496 abbrev
->next
= m_abbrevs
[hash_number
];
18497 m_abbrevs
[hash_number
] = abbrev
;
18500 /* Look up an abbrev in the table.
18501 Returns NULL if the abbrev is not found. */
18503 struct abbrev_info
*
18504 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18506 unsigned int hash_number
;
18507 struct abbrev_info
*abbrev
;
18509 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18510 abbrev
= m_abbrevs
[hash_number
];
18514 if (abbrev
->number
== abbrev_number
)
18516 abbrev
= abbrev
->next
;
18521 /* Read in an abbrev table. */
18523 static abbrev_table_up
18524 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18525 struct dwarf2_section_info
*section
,
18526 sect_offset sect_off
)
18528 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18529 bfd
*abfd
= get_section_bfd_owner (section
);
18530 const gdb_byte
*abbrev_ptr
;
18531 struct abbrev_info
*cur_abbrev
;
18532 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18533 unsigned int abbrev_form
;
18534 std::vector
<struct attr_abbrev
> cur_attrs
;
18536 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18538 dwarf2_read_section (objfile
, section
);
18539 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18540 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18541 abbrev_ptr
+= bytes_read
;
18543 /* Loop until we reach an abbrev number of 0. */
18544 while (abbrev_number
)
18546 cur_attrs
.clear ();
18547 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18549 /* read in abbrev header */
18550 cur_abbrev
->number
= abbrev_number
;
18552 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18553 abbrev_ptr
+= bytes_read
;
18554 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18557 /* now read in declarations */
18560 LONGEST implicit_const
;
18562 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18563 abbrev_ptr
+= bytes_read
;
18564 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18565 abbrev_ptr
+= bytes_read
;
18566 if (abbrev_form
== DW_FORM_implicit_const
)
18568 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18570 abbrev_ptr
+= bytes_read
;
18574 /* Initialize it due to a false compiler warning. */
18575 implicit_const
= -1;
18578 if (abbrev_name
== 0)
18581 cur_attrs
.emplace_back ();
18582 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18583 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18584 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18585 cur_attr
.implicit_const
= implicit_const
;
18586 ++cur_abbrev
->num_attrs
;
18589 cur_abbrev
->attrs
=
18590 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18591 cur_abbrev
->num_attrs
);
18592 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18593 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18595 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18597 /* Get next abbreviation.
18598 Under Irix6 the abbreviations for a compilation unit are not
18599 always properly terminated with an abbrev number of 0.
18600 Exit loop if we encounter an abbreviation which we have
18601 already read (which means we are about to read the abbreviations
18602 for the next compile unit) or if the end of the abbreviation
18603 table is reached. */
18604 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18606 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18607 abbrev_ptr
+= bytes_read
;
18608 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18612 return abbrev_table
;
18615 /* Returns nonzero if TAG represents a type that we might generate a partial
18619 is_type_tag_for_partial (int tag
)
18624 /* Some types that would be reasonable to generate partial symbols for,
18625 that we don't at present. */
18626 case DW_TAG_array_type
:
18627 case DW_TAG_file_type
:
18628 case DW_TAG_ptr_to_member_type
:
18629 case DW_TAG_set_type
:
18630 case DW_TAG_string_type
:
18631 case DW_TAG_subroutine_type
:
18633 case DW_TAG_base_type
:
18634 case DW_TAG_class_type
:
18635 case DW_TAG_interface_type
:
18636 case DW_TAG_enumeration_type
:
18637 case DW_TAG_structure_type
:
18638 case DW_TAG_subrange_type
:
18639 case DW_TAG_typedef
:
18640 case DW_TAG_union_type
:
18647 /* Load all DIEs that are interesting for partial symbols into memory. */
18649 static struct partial_die_info
*
18650 load_partial_dies (const struct die_reader_specs
*reader
,
18651 const gdb_byte
*info_ptr
, int building_psymtab
)
18653 struct dwarf2_cu
*cu
= reader
->cu
;
18654 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18655 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18656 unsigned int bytes_read
;
18657 unsigned int load_all
= 0;
18658 int nesting_level
= 1;
18663 gdb_assert (cu
->per_cu
!= NULL
);
18664 if (cu
->per_cu
->load_all_dies
)
18668 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18672 &cu
->comp_unit_obstack
,
18673 hashtab_obstack_allocate
,
18674 dummy_obstack_deallocate
);
18678 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18680 /* A NULL abbrev means the end of a series of children. */
18681 if (abbrev
== NULL
)
18683 if (--nesting_level
== 0)
18686 info_ptr
+= bytes_read
;
18687 last_die
= parent_die
;
18688 parent_die
= parent_die
->die_parent
;
18692 /* Check for template arguments. We never save these; if
18693 they're seen, we just mark the parent, and go on our way. */
18694 if (parent_die
!= NULL
18695 && cu
->language
== language_cplus
18696 && (abbrev
->tag
== DW_TAG_template_type_param
18697 || abbrev
->tag
== DW_TAG_template_value_param
))
18699 parent_die
->has_template_arguments
= 1;
18703 /* We don't need a partial DIE for the template argument. */
18704 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18709 /* We only recurse into c++ subprograms looking for template arguments.
18710 Skip their other children. */
18712 && cu
->language
== language_cplus
18713 && parent_die
!= NULL
18714 && parent_die
->tag
== DW_TAG_subprogram
)
18716 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18720 /* Check whether this DIE is interesting enough to save. Normally
18721 we would not be interested in members here, but there may be
18722 later variables referencing them via DW_AT_specification (for
18723 static members). */
18725 && !is_type_tag_for_partial (abbrev
->tag
)
18726 && abbrev
->tag
!= DW_TAG_constant
18727 && abbrev
->tag
!= DW_TAG_enumerator
18728 && abbrev
->tag
!= DW_TAG_subprogram
18729 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18730 && abbrev
->tag
!= DW_TAG_lexical_block
18731 && abbrev
->tag
!= DW_TAG_variable
18732 && abbrev
->tag
!= DW_TAG_namespace
18733 && abbrev
->tag
!= DW_TAG_module
18734 && abbrev
->tag
!= DW_TAG_member
18735 && abbrev
->tag
!= DW_TAG_imported_unit
18736 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18738 /* Otherwise we skip to the next sibling, if any. */
18739 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18743 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18746 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18748 /* This two-pass algorithm for processing partial symbols has a
18749 high cost in cache pressure. Thus, handle some simple cases
18750 here which cover the majority of C partial symbols. DIEs
18751 which neither have specification tags in them, nor could have
18752 specification tags elsewhere pointing at them, can simply be
18753 processed and discarded.
18755 This segment is also optional; scan_partial_symbols and
18756 add_partial_symbol will handle these DIEs if we chain
18757 them in normally. When compilers which do not emit large
18758 quantities of duplicate debug information are more common,
18759 this code can probably be removed. */
18761 /* Any complete simple types at the top level (pretty much all
18762 of them, for a language without namespaces), can be processed
18764 if (parent_die
== NULL
18765 && pdi
.has_specification
== 0
18766 && pdi
.is_declaration
== 0
18767 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18768 || pdi
.tag
== DW_TAG_base_type
18769 || pdi
.tag
== DW_TAG_subrange_type
))
18771 if (building_psymtab
&& pdi
.name
!= NULL
)
18772 add_psymbol_to_list (pdi
.name
, false,
18773 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18774 psymbol_placement::STATIC
,
18775 0, cu
->language
, objfile
);
18776 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18780 /* The exception for DW_TAG_typedef with has_children above is
18781 a workaround of GCC PR debug/47510. In the case of this complaint
18782 type_name_or_error will error on such types later.
18784 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18785 it could not find the child DIEs referenced later, this is checked
18786 above. In correct DWARF DW_TAG_typedef should have no children. */
18788 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18789 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18790 "- DIE at %s [in module %s]"),
18791 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18793 /* If we're at the second level, and we're an enumerator, and
18794 our parent has no specification (meaning possibly lives in a
18795 namespace elsewhere), then we can add the partial symbol now
18796 instead of queueing it. */
18797 if (pdi
.tag
== DW_TAG_enumerator
18798 && parent_die
!= NULL
18799 && parent_die
->die_parent
== NULL
18800 && parent_die
->tag
== DW_TAG_enumeration_type
18801 && parent_die
->has_specification
== 0)
18803 if (pdi
.name
== NULL
)
18804 complaint (_("malformed enumerator DIE ignored"));
18805 else if (building_psymtab
)
18806 add_psymbol_to_list (pdi
.name
, false,
18807 VAR_DOMAIN
, LOC_CONST
, -1,
18808 cu
->language
== language_cplus
18809 ? psymbol_placement::GLOBAL
18810 : psymbol_placement::STATIC
,
18811 0, cu
->language
, objfile
);
18813 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18817 struct partial_die_info
*part_die
18818 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18820 /* We'll save this DIE so link it in. */
18821 part_die
->die_parent
= parent_die
;
18822 part_die
->die_sibling
= NULL
;
18823 part_die
->die_child
= NULL
;
18825 if (last_die
&& last_die
== parent_die
)
18826 last_die
->die_child
= part_die
;
18828 last_die
->die_sibling
= part_die
;
18830 last_die
= part_die
;
18832 if (first_die
== NULL
)
18833 first_die
= part_die
;
18835 /* Maybe add the DIE to the hash table. Not all DIEs that we
18836 find interesting need to be in the hash table, because we
18837 also have the parent/sibling/child chains; only those that we
18838 might refer to by offset later during partial symbol reading.
18840 For now this means things that might have be the target of a
18841 DW_AT_specification, DW_AT_abstract_origin, or
18842 DW_AT_extension. DW_AT_extension will refer only to
18843 namespaces; DW_AT_abstract_origin refers to functions (and
18844 many things under the function DIE, but we do not recurse
18845 into function DIEs during partial symbol reading) and
18846 possibly variables as well; DW_AT_specification refers to
18847 declarations. Declarations ought to have the DW_AT_declaration
18848 flag. It happens that GCC forgets to put it in sometimes, but
18849 only for functions, not for types.
18851 Adding more things than necessary to the hash table is harmless
18852 except for the performance cost. Adding too few will result in
18853 wasted time in find_partial_die, when we reread the compilation
18854 unit with load_all_dies set. */
18857 || abbrev
->tag
== DW_TAG_constant
18858 || abbrev
->tag
== DW_TAG_subprogram
18859 || abbrev
->tag
== DW_TAG_variable
18860 || abbrev
->tag
== DW_TAG_namespace
18861 || part_die
->is_declaration
)
18865 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18866 to_underlying (part_die
->sect_off
),
18871 /* For some DIEs we want to follow their children (if any). For C
18872 we have no reason to follow the children of structures; for other
18873 languages we have to, so that we can get at method physnames
18874 to infer fully qualified class names, for DW_AT_specification,
18875 and for C++ template arguments. For C++, we also look one level
18876 inside functions to find template arguments (if the name of the
18877 function does not already contain the template arguments).
18879 For Ada and Fortran, we need to scan the children of subprograms
18880 and lexical blocks as well because these languages allow the
18881 definition of nested entities that could be interesting for the
18882 debugger, such as nested subprograms for instance. */
18883 if (last_die
->has_children
18885 || last_die
->tag
== DW_TAG_namespace
18886 || last_die
->tag
== DW_TAG_module
18887 || last_die
->tag
== DW_TAG_enumeration_type
18888 || (cu
->language
== language_cplus
18889 && last_die
->tag
== DW_TAG_subprogram
18890 && (last_die
->name
== NULL
18891 || strchr (last_die
->name
, '<') == NULL
))
18892 || (cu
->language
!= language_c
18893 && (last_die
->tag
== DW_TAG_class_type
18894 || last_die
->tag
== DW_TAG_interface_type
18895 || last_die
->tag
== DW_TAG_structure_type
18896 || last_die
->tag
== DW_TAG_union_type
))
18897 || ((cu
->language
== language_ada
18898 || cu
->language
== language_fortran
)
18899 && (last_die
->tag
== DW_TAG_subprogram
18900 || last_die
->tag
== DW_TAG_lexical_block
))))
18903 parent_die
= last_die
;
18907 /* Otherwise we skip to the next sibling, if any. */
18908 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18910 /* Back to the top, do it again. */
18914 partial_die_info::partial_die_info (sect_offset sect_off_
,
18915 struct abbrev_info
*abbrev
)
18916 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18920 /* Read a minimal amount of information into the minimal die structure.
18921 INFO_PTR should point just after the initial uleb128 of a DIE. */
18924 partial_die_info::read (const struct die_reader_specs
*reader
,
18925 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18927 struct dwarf2_cu
*cu
= reader
->cu
;
18928 struct dwarf2_per_objfile
*dwarf2_per_objfile
18929 = cu
->per_cu
->dwarf2_per_objfile
;
18931 int has_low_pc_attr
= 0;
18932 int has_high_pc_attr
= 0;
18933 int high_pc_relative
= 0;
18935 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18936 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18938 bool need_reprocess
;
18939 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18940 info_ptr
, &need_reprocess
);
18941 /* String and address offsets that need to do the reprocessing have
18942 already been read at this point, so there is no need to wait until
18943 the loop terminates to do the reprocessing. */
18944 if (need_reprocess
)
18945 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18946 attribute
&attr
= attr_vec
[i
];
18947 /* Store the data if it is of an attribute we want to keep in a
18948 partial symbol table. */
18954 case DW_TAG_compile_unit
:
18955 case DW_TAG_partial_unit
:
18956 case DW_TAG_type_unit
:
18957 /* Compilation units have a DW_AT_name that is a filename, not
18958 a source language identifier. */
18959 case DW_TAG_enumeration_type
:
18960 case DW_TAG_enumerator
:
18961 /* These tags always have simple identifiers already; no need
18962 to canonicalize them. */
18963 name
= DW_STRING (&attr
);
18967 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18970 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18971 &objfile
->per_bfd
->storage_obstack
);
18976 case DW_AT_linkage_name
:
18977 case DW_AT_MIPS_linkage_name
:
18978 /* Note that both forms of linkage name might appear. We
18979 assume they will be the same, and we only store the last
18981 linkage_name
= DW_STRING (&attr
);
18984 has_low_pc_attr
= 1;
18985 lowpc
= attr_value_as_address (&attr
);
18987 case DW_AT_high_pc
:
18988 has_high_pc_attr
= 1;
18989 highpc
= attr_value_as_address (&attr
);
18990 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
18991 high_pc_relative
= 1;
18993 case DW_AT_location
:
18994 /* Support the .debug_loc offsets. */
18995 if (attr_form_is_block (&attr
))
18997 d
.locdesc
= DW_BLOCK (&attr
);
18999 else if (attr_form_is_section_offset (&attr
))
19001 dwarf2_complex_location_expr_complaint ();
19005 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19006 "partial symbol information");
19009 case DW_AT_external
:
19010 is_external
= DW_UNSND (&attr
);
19012 case DW_AT_declaration
:
19013 is_declaration
= DW_UNSND (&attr
);
19018 case DW_AT_abstract_origin
:
19019 case DW_AT_specification
:
19020 case DW_AT_extension
:
19021 has_specification
= 1;
19022 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19023 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19024 || cu
->per_cu
->is_dwz
);
19026 case DW_AT_sibling
:
19027 /* Ignore absolute siblings, they might point outside of
19028 the current compile unit. */
19029 if (attr
.form
== DW_FORM_ref_addr
)
19030 complaint (_("ignoring absolute DW_AT_sibling"));
19033 const gdb_byte
*buffer
= reader
->buffer
;
19034 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19035 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19037 if (sibling_ptr
< info_ptr
)
19038 complaint (_("DW_AT_sibling points backwards"));
19039 else if (sibling_ptr
> reader
->buffer_end
)
19040 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19042 sibling
= sibling_ptr
;
19045 case DW_AT_byte_size
:
19048 case DW_AT_const_value
:
19049 has_const_value
= 1;
19051 case DW_AT_calling_convention
:
19052 /* DWARF doesn't provide a way to identify a program's source-level
19053 entry point. DW_AT_calling_convention attributes are only meant
19054 to describe functions' calling conventions.
19056 However, because it's a necessary piece of information in
19057 Fortran, and before DWARF 4 DW_CC_program was the only
19058 piece of debugging information whose definition refers to
19059 a 'main program' at all, several compilers marked Fortran
19060 main programs with DW_CC_program --- even when those
19061 functions use the standard calling conventions.
19063 Although DWARF now specifies a way to provide this
19064 information, we support this practice for backward
19066 if (DW_UNSND (&attr
) == DW_CC_program
19067 && cu
->language
== language_fortran
)
19068 main_subprogram
= 1;
19071 if (DW_UNSND (&attr
) == DW_INL_inlined
19072 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19073 may_be_inlined
= 1;
19077 if (tag
== DW_TAG_imported_unit
)
19079 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19080 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19081 || cu
->per_cu
->is_dwz
);
19085 case DW_AT_main_subprogram
:
19086 main_subprogram
= DW_UNSND (&attr
);
19091 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19092 but that requires a full DIE, so instead we just
19094 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19095 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19096 + (need_ranges_base
19100 /* Value of the DW_AT_ranges attribute is the offset in the
19101 .debug_ranges section. */
19102 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19113 /* For Ada, if both the name and the linkage name appear, we prefer
19114 the latter. This lets "catch exception" work better, regardless
19115 of the order in which the name and linkage name were emitted.
19116 Really, though, this is just a workaround for the fact that gdb
19117 doesn't store both the name and the linkage name. */
19118 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19119 name
= linkage_name
;
19121 if (high_pc_relative
)
19124 if (has_low_pc_attr
&& has_high_pc_attr
)
19126 /* When using the GNU linker, .gnu.linkonce. sections are used to
19127 eliminate duplicate copies of functions and vtables and such.
19128 The linker will arbitrarily choose one and discard the others.
19129 The AT_*_pc values for such functions refer to local labels in
19130 these sections. If the section from that file was discarded, the
19131 labels are not in the output, so the relocs get a value of 0.
19132 If this is a discarded function, mark the pc bounds as invalid,
19133 so that GDB will ignore it. */
19134 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19136 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19137 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19139 complaint (_("DW_AT_low_pc %s is zero "
19140 "for DIE at %s [in module %s]"),
19141 paddress (gdbarch
, lowpc
),
19142 sect_offset_str (sect_off
),
19143 objfile_name (objfile
));
19145 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19146 else if (lowpc
>= highpc
)
19148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19149 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19151 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19152 "for DIE at %s [in module %s]"),
19153 paddress (gdbarch
, lowpc
),
19154 paddress (gdbarch
, highpc
),
19155 sect_offset_str (sect_off
),
19156 objfile_name (objfile
));
19165 /* Find a cached partial DIE at OFFSET in CU. */
19167 struct partial_die_info
*
19168 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19170 struct partial_die_info
*lookup_die
= NULL
;
19171 struct partial_die_info
part_die (sect_off
);
19173 lookup_die
= ((struct partial_die_info
*)
19174 htab_find_with_hash (partial_dies
, &part_die
,
19175 to_underlying (sect_off
)));
19180 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19181 except in the case of .debug_types DIEs which do not reference
19182 outside their CU (they do however referencing other types via
19183 DW_FORM_ref_sig8). */
19185 static const struct cu_partial_die_info
19186 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19188 struct dwarf2_per_objfile
*dwarf2_per_objfile
19189 = cu
->per_cu
->dwarf2_per_objfile
;
19190 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19191 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19192 struct partial_die_info
*pd
= NULL
;
19194 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19195 && offset_in_cu_p (&cu
->header
, sect_off
))
19197 pd
= cu
->find_partial_die (sect_off
);
19200 /* We missed recording what we needed.
19201 Load all dies and try again. */
19202 per_cu
= cu
->per_cu
;
19206 /* TUs don't reference other CUs/TUs (except via type signatures). */
19207 if (cu
->per_cu
->is_debug_types
)
19209 error (_("Dwarf Error: Type Unit at offset %s contains"
19210 " external reference to offset %s [in module %s].\n"),
19211 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19212 bfd_get_filename (objfile
->obfd
));
19214 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19215 dwarf2_per_objfile
);
19217 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19218 load_partial_comp_unit (per_cu
);
19220 per_cu
->cu
->last_used
= 0;
19221 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19224 /* If we didn't find it, and not all dies have been loaded,
19225 load them all and try again. */
19227 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19229 per_cu
->load_all_dies
= 1;
19231 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19232 THIS_CU->cu may already be in use. So we can't just free it and
19233 replace its DIEs with the ones we read in. Instead, we leave those
19234 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19235 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19237 load_partial_comp_unit (per_cu
);
19239 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19243 internal_error (__FILE__
, __LINE__
,
19244 _("could not find partial DIE %s "
19245 "in cache [from module %s]\n"),
19246 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19247 return { per_cu
->cu
, pd
};
19250 /* See if we can figure out if the class lives in a namespace. We do
19251 this by looking for a member function; its demangled name will
19252 contain namespace info, if there is any. */
19255 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19256 struct dwarf2_cu
*cu
)
19258 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19259 what template types look like, because the demangler
19260 frequently doesn't give the same name as the debug info. We
19261 could fix this by only using the demangled name to get the
19262 prefix (but see comment in read_structure_type). */
19264 struct partial_die_info
*real_pdi
;
19265 struct partial_die_info
*child_pdi
;
19267 /* If this DIE (this DIE's specification, if any) has a parent, then
19268 we should not do this. We'll prepend the parent's fully qualified
19269 name when we create the partial symbol. */
19271 real_pdi
= struct_pdi
;
19272 while (real_pdi
->has_specification
)
19274 auto res
= find_partial_die (real_pdi
->spec_offset
,
19275 real_pdi
->spec_is_dwz
, cu
);
19276 real_pdi
= res
.pdi
;
19280 if (real_pdi
->die_parent
!= NULL
)
19283 for (child_pdi
= struct_pdi
->die_child
;
19285 child_pdi
= child_pdi
->die_sibling
)
19287 if (child_pdi
->tag
== DW_TAG_subprogram
19288 && child_pdi
->linkage_name
!= NULL
)
19290 gdb::unique_xmalloc_ptr
<char> actual_class_name
19291 (language_class_name_from_physname (cu
->language_defn
,
19292 child_pdi
->linkage_name
));
19293 if (actual_class_name
!= NULL
)
19295 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19297 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19298 actual_class_name
.get ());
19306 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19308 /* Once we've fixed up a die, there's no point in doing so again.
19309 This also avoids a memory leak if we were to call
19310 guess_partial_die_structure_name multiple times. */
19314 /* If we found a reference attribute and the DIE has no name, try
19315 to find a name in the referred to DIE. */
19317 if (name
== NULL
&& has_specification
)
19319 struct partial_die_info
*spec_die
;
19321 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19322 spec_die
= res
.pdi
;
19325 spec_die
->fixup (cu
);
19327 if (spec_die
->name
)
19329 name
= spec_die
->name
;
19331 /* Copy DW_AT_external attribute if it is set. */
19332 if (spec_die
->is_external
)
19333 is_external
= spec_die
->is_external
;
19337 /* Set default names for some unnamed DIEs. */
19339 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19340 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19342 /* If there is no parent die to provide a namespace, and there are
19343 children, see if we can determine the namespace from their linkage
19345 if (cu
->language
== language_cplus
19346 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19347 && die_parent
== NULL
19349 && (tag
== DW_TAG_class_type
19350 || tag
== DW_TAG_structure_type
19351 || tag
== DW_TAG_union_type
))
19352 guess_partial_die_structure_name (this, cu
);
19354 /* GCC might emit a nameless struct or union that has a linkage
19355 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19357 && (tag
== DW_TAG_class_type
19358 || tag
== DW_TAG_interface_type
19359 || tag
== DW_TAG_structure_type
19360 || tag
== DW_TAG_union_type
)
19361 && linkage_name
!= NULL
)
19363 gdb::unique_xmalloc_ptr
<char> demangled
19364 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19365 if (demangled
!= nullptr)
19369 /* Strip any leading namespaces/classes, keep only the base name.
19370 DW_AT_name for named DIEs does not contain the prefixes. */
19371 base
= strrchr (demangled
.get (), ':');
19372 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19375 base
= demangled
.get ();
19377 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19378 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19385 /* Process the attributes that had to be skipped in the first round. These
19386 attributes are the ones that need str_offsets_base or addr_base attributes.
19387 They could not have been processed in the first round, because at the time
19388 the values of str_offsets_base or addr_base may not have been known. */
19389 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19390 struct attribute
*attr
)
19392 struct dwarf2_cu
*cu
= reader
->cu
;
19393 switch (attr
->form
)
19395 case DW_FORM_addrx
:
19396 case DW_FORM_GNU_addr_index
:
19397 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19400 case DW_FORM_strx1
:
19401 case DW_FORM_strx2
:
19402 case DW_FORM_strx3
:
19403 case DW_FORM_strx4
:
19404 case DW_FORM_GNU_str_index
:
19406 unsigned int str_index
= DW_UNSND (attr
);
19407 if (reader
->dwo_file
!= NULL
)
19409 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19410 DW_STRING_IS_CANONICAL (attr
) = 0;
19414 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19415 DW_STRING_IS_CANONICAL (attr
) = 0;
19420 gdb_assert_not_reached (_("Unexpected DWARF form."));
19424 /* Read an attribute value described by an attribute form. */
19426 static const gdb_byte
*
19427 read_attribute_value (const struct die_reader_specs
*reader
,
19428 struct attribute
*attr
, unsigned form
,
19429 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19430 bool *need_reprocess
)
19432 struct dwarf2_cu
*cu
= reader
->cu
;
19433 struct dwarf2_per_objfile
*dwarf2_per_objfile
19434 = cu
->per_cu
->dwarf2_per_objfile
;
19435 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19436 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19437 bfd
*abfd
= reader
->abfd
;
19438 struct comp_unit_head
*cu_header
= &cu
->header
;
19439 unsigned int bytes_read
;
19440 struct dwarf_block
*blk
;
19441 *need_reprocess
= false;
19443 attr
->form
= (enum dwarf_form
) form
;
19446 case DW_FORM_ref_addr
:
19447 if (cu
->header
.version
== 2)
19448 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19450 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19451 &cu
->header
, &bytes_read
);
19452 info_ptr
+= bytes_read
;
19454 case DW_FORM_GNU_ref_alt
:
19455 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19456 info_ptr
+= bytes_read
;
19459 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19460 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19461 info_ptr
+= bytes_read
;
19463 case DW_FORM_block2
:
19464 blk
= dwarf_alloc_block (cu
);
19465 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19467 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19468 info_ptr
+= blk
->size
;
19469 DW_BLOCK (attr
) = blk
;
19471 case DW_FORM_block4
:
19472 blk
= dwarf_alloc_block (cu
);
19473 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19475 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19476 info_ptr
+= blk
->size
;
19477 DW_BLOCK (attr
) = blk
;
19479 case DW_FORM_data2
:
19480 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19483 case DW_FORM_data4
:
19484 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19487 case DW_FORM_data8
:
19488 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19491 case DW_FORM_data16
:
19492 blk
= dwarf_alloc_block (cu
);
19494 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19496 DW_BLOCK (attr
) = blk
;
19498 case DW_FORM_sec_offset
:
19499 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19500 info_ptr
+= bytes_read
;
19502 case DW_FORM_string
:
19503 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19504 DW_STRING_IS_CANONICAL (attr
) = 0;
19505 info_ptr
+= bytes_read
;
19508 if (!cu
->per_cu
->is_dwz
)
19510 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19511 abfd
, info_ptr
, cu_header
,
19513 DW_STRING_IS_CANONICAL (attr
) = 0;
19514 info_ptr
+= bytes_read
;
19518 case DW_FORM_line_strp
:
19519 if (!cu
->per_cu
->is_dwz
)
19521 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19523 cu_header
, &bytes_read
);
19524 DW_STRING_IS_CANONICAL (attr
) = 0;
19525 info_ptr
+= bytes_read
;
19529 case DW_FORM_GNU_strp_alt
:
19531 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19532 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19535 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19537 DW_STRING_IS_CANONICAL (attr
) = 0;
19538 info_ptr
+= bytes_read
;
19541 case DW_FORM_exprloc
:
19542 case DW_FORM_block
:
19543 blk
= dwarf_alloc_block (cu
);
19544 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19545 info_ptr
+= bytes_read
;
19546 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19547 info_ptr
+= blk
->size
;
19548 DW_BLOCK (attr
) = blk
;
19550 case DW_FORM_block1
:
19551 blk
= dwarf_alloc_block (cu
);
19552 blk
->size
= read_1_byte (abfd
, info_ptr
);
19554 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19555 info_ptr
+= blk
->size
;
19556 DW_BLOCK (attr
) = blk
;
19558 case DW_FORM_data1
:
19559 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19563 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19566 case DW_FORM_flag_present
:
19567 DW_UNSND (attr
) = 1;
19569 case DW_FORM_sdata
:
19570 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19571 info_ptr
+= bytes_read
;
19573 case DW_FORM_udata
:
19574 case DW_FORM_rnglistx
:
19575 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19576 info_ptr
+= bytes_read
;
19579 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19580 + read_1_byte (abfd
, info_ptr
));
19584 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19585 + read_2_bytes (abfd
, info_ptr
));
19589 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19590 + read_4_bytes (abfd
, info_ptr
));
19594 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19595 + read_8_bytes (abfd
, info_ptr
));
19598 case DW_FORM_ref_sig8
:
19599 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19602 case DW_FORM_ref_udata
:
19603 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19604 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19605 info_ptr
+= bytes_read
;
19607 case DW_FORM_indirect
:
19608 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19609 info_ptr
+= bytes_read
;
19610 if (form
== DW_FORM_implicit_const
)
19612 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19613 info_ptr
+= bytes_read
;
19615 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19616 info_ptr
, need_reprocess
);
19618 case DW_FORM_implicit_const
:
19619 DW_SND (attr
) = implicit_const
;
19621 case DW_FORM_addrx
:
19622 case DW_FORM_GNU_addr_index
:
19623 *need_reprocess
= true;
19624 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19625 info_ptr
+= bytes_read
;
19628 case DW_FORM_strx1
:
19629 case DW_FORM_strx2
:
19630 case DW_FORM_strx3
:
19631 case DW_FORM_strx4
:
19632 case DW_FORM_GNU_str_index
:
19634 ULONGEST str_index
;
19635 if (form
== DW_FORM_strx1
)
19637 str_index
= read_1_byte (abfd
, info_ptr
);
19640 else if (form
== DW_FORM_strx2
)
19642 str_index
= read_2_bytes (abfd
, info_ptr
);
19645 else if (form
== DW_FORM_strx3
)
19647 str_index
= read_3_bytes (abfd
, info_ptr
);
19650 else if (form
== DW_FORM_strx4
)
19652 str_index
= read_4_bytes (abfd
, info_ptr
);
19657 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19658 info_ptr
+= bytes_read
;
19660 *need_reprocess
= true;
19661 DW_UNSND (attr
) = str_index
;
19665 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19666 dwarf_form_name (form
),
19667 bfd_get_filename (abfd
));
19671 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19672 attr
->form
= DW_FORM_GNU_ref_alt
;
19674 /* We have seen instances where the compiler tried to emit a byte
19675 size attribute of -1 which ended up being encoded as an unsigned
19676 0xffffffff. Although 0xffffffff is technically a valid size value,
19677 an object of this size seems pretty unlikely so we can relatively
19678 safely treat these cases as if the size attribute was invalid and
19679 treat them as zero by default. */
19680 if (attr
->name
== DW_AT_byte_size
19681 && form
== DW_FORM_data4
19682 && DW_UNSND (attr
) >= 0xffffffff)
19685 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19686 hex_string (DW_UNSND (attr
)));
19687 DW_UNSND (attr
) = 0;
19693 /* Read an attribute described by an abbreviated attribute. */
19695 static const gdb_byte
*
19696 read_attribute (const struct die_reader_specs
*reader
,
19697 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19698 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19700 attr
->name
= abbrev
->name
;
19701 return read_attribute_value (reader
, attr
, abbrev
->form
,
19702 abbrev
->implicit_const
, info_ptr
,
19706 /* Read dwarf information from a buffer. */
19708 static unsigned int
19709 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19711 return bfd_get_8 (abfd
, buf
);
19715 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19717 return bfd_get_signed_8 (abfd
, buf
);
19720 static unsigned int
19721 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19723 return bfd_get_16 (abfd
, buf
);
19727 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19729 return bfd_get_signed_16 (abfd
, buf
);
19732 static unsigned int
19733 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19735 unsigned int result
= 0;
19736 for (int i
= 0; i
< 3; ++i
)
19738 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19740 result
|= ((unsigned int) byte
<< (i
* 8));
19745 static unsigned int
19746 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19748 return bfd_get_32 (abfd
, buf
);
19752 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19754 return bfd_get_signed_32 (abfd
, buf
);
19758 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19760 return bfd_get_64 (abfd
, buf
);
19764 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19765 unsigned int *bytes_read
)
19767 struct comp_unit_head
*cu_header
= &cu
->header
;
19768 CORE_ADDR retval
= 0;
19770 if (cu_header
->signed_addr_p
)
19772 switch (cu_header
->addr_size
)
19775 retval
= bfd_get_signed_16 (abfd
, buf
);
19778 retval
= bfd_get_signed_32 (abfd
, buf
);
19781 retval
= bfd_get_signed_64 (abfd
, buf
);
19784 internal_error (__FILE__
, __LINE__
,
19785 _("read_address: bad switch, signed [in module %s]"),
19786 bfd_get_filename (abfd
));
19791 switch (cu_header
->addr_size
)
19794 retval
= bfd_get_16 (abfd
, buf
);
19797 retval
= bfd_get_32 (abfd
, buf
);
19800 retval
= bfd_get_64 (abfd
, buf
);
19803 internal_error (__FILE__
, __LINE__
,
19804 _("read_address: bad switch, "
19805 "unsigned [in module %s]"),
19806 bfd_get_filename (abfd
));
19810 *bytes_read
= cu_header
->addr_size
;
19814 /* Read the initial length from a section. The (draft) DWARF 3
19815 specification allows the initial length to take up either 4 bytes
19816 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19817 bytes describe the length and all offsets will be 8 bytes in length
19820 An older, non-standard 64-bit format is also handled by this
19821 function. The older format in question stores the initial length
19822 as an 8-byte quantity without an escape value. Lengths greater
19823 than 2^32 aren't very common which means that the initial 4 bytes
19824 is almost always zero. Since a length value of zero doesn't make
19825 sense for the 32-bit format, this initial zero can be considered to
19826 be an escape value which indicates the presence of the older 64-bit
19827 format. As written, the code can't detect (old format) lengths
19828 greater than 4GB. If it becomes necessary to handle lengths
19829 somewhat larger than 4GB, we could allow other small values (such
19830 as the non-sensical values of 1, 2, and 3) to also be used as
19831 escape values indicating the presence of the old format.
19833 The value returned via bytes_read should be used to increment the
19834 relevant pointer after calling read_initial_length().
19836 [ Note: read_initial_length() and read_offset() are based on the
19837 document entitled "DWARF Debugging Information Format", revision
19838 3, draft 8, dated November 19, 2001. This document was obtained
19841 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19843 This document is only a draft and is subject to change. (So beware.)
19845 Details regarding the older, non-standard 64-bit format were
19846 determined empirically by examining 64-bit ELF files produced by
19847 the SGI toolchain on an IRIX 6.5 machine.
19849 - Kevin, July 16, 2002
19853 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19855 LONGEST length
= bfd_get_32 (abfd
, buf
);
19857 if (length
== 0xffffffff)
19859 length
= bfd_get_64 (abfd
, buf
+ 4);
19862 else if (length
== 0)
19864 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19865 length
= bfd_get_64 (abfd
, buf
);
19876 /* Cover function for read_initial_length.
19877 Returns the length of the object at BUF, and stores the size of the
19878 initial length in *BYTES_READ and stores the size that offsets will be in
19880 If the initial length size is not equivalent to that specified in
19881 CU_HEADER then issue a complaint.
19882 This is useful when reading non-comp-unit headers. */
19885 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19886 const struct comp_unit_head
*cu_header
,
19887 unsigned int *bytes_read
,
19888 unsigned int *offset_size
)
19890 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19892 gdb_assert (cu_header
->initial_length_size
== 4
19893 || cu_header
->initial_length_size
== 8
19894 || cu_header
->initial_length_size
== 12);
19896 if (cu_header
->initial_length_size
!= *bytes_read
)
19897 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19899 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19903 /* Read an offset from the data stream. The size of the offset is
19904 given by cu_header->offset_size. */
19907 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19908 const struct comp_unit_head
*cu_header
,
19909 unsigned int *bytes_read
)
19911 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19913 *bytes_read
= cu_header
->offset_size
;
19917 /* Read an offset from the data stream. */
19920 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19922 LONGEST retval
= 0;
19924 switch (offset_size
)
19927 retval
= bfd_get_32 (abfd
, buf
);
19930 retval
= bfd_get_64 (abfd
, buf
);
19933 internal_error (__FILE__
, __LINE__
,
19934 _("read_offset_1: bad switch [in module %s]"),
19935 bfd_get_filename (abfd
));
19941 static const gdb_byte
*
19942 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19944 /* If the size of a host char is 8 bits, we can return a pointer
19945 to the buffer, otherwise we have to copy the data to a buffer
19946 allocated on the temporary obstack. */
19947 gdb_assert (HOST_CHAR_BIT
== 8);
19951 static const char *
19952 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19953 unsigned int *bytes_read_ptr
)
19955 /* If the size of a host char is 8 bits, we can return a pointer
19956 to the string, otherwise we have to copy the string to a buffer
19957 allocated on the temporary obstack. */
19958 gdb_assert (HOST_CHAR_BIT
== 8);
19961 *bytes_read_ptr
= 1;
19964 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19965 return (const char *) buf
;
19968 /* Return pointer to string at section SECT offset STR_OFFSET with error
19969 reporting strings FORM_NAME and SECT_NAME. */
19971 static const char *
19972 read_indirect_string_at_offset_from (struct objfile
*objfile
,
19973 bfd
*abfd
, LONGEST str_offset
,
19974 struct dwarf2_section_info
*sect
,
19975 const char *form_name
,
19976 const char *sect_name
)
19978 dwarf2_read_section (objfile
, sect
);
19979 if (sect
->buffer
== NULL
)
19980 error (_("%s used without %s section [in module %s]"),
19981 form_name
, sect_name
, bfd_get_filename (abfd
));
19982 if (str_offset
>= sect
->size
)
19983 error (_("%s pointing outside of %s section [in module %s]"),
19984 form_name
, sect_name
, bfd_get_filename (abfd
));
19985 gdb_assert (HOST_CHAR_BIT
== 8);
19986 if (sect
->buffer
[str_offset
] == '\0')
19988 return (const char *) (sect
->buffer
+ str_offset
);
19991 /* Return pointer to string at .debug_str offset STR_OFFSET. */
19993 static const char *
19994 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
19995 bfd
*abfd
, LONGEST str_offset
)
19997 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
19999 &dwarf2_per_objfile
->str
,
20000 "DW_FORM_strp", ".debug_str");
20003 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
20005 static const char *
20006 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20007 bfd
*abfd
, LONGEST str_offset
)
20009 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20011 &dwarf2_per_objfile
->line_str
,
20012 "DW_FORM_line_strp",
20013 ".debug_line_str");
20016 /* Read a string at offset STR_OFFSET in the .debug_str section from
20017 the .dwz file DWZ. Throw an error if the offset is too large. If
20018 the string consists of a single NUL byte, return NULL; otherwise
20019 return a pointer to the string. */
20021 static const char *
20022 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20023 LONGEST str_offset
)
20025 dwarf2_read_section (objfile
, &dwz
->str
);
20027 if (dwz
->str
.buffer
== NULL
)
20028 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20029 "section [in module %s]"),
20030 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20031 if (str_offset
>= dwz
->str
.size
)
20032 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20033 ".debug_str section [in module %s]"),
20034 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20035 gdb_assert (HOST_CHAR_BIT
== 8);
20036 if (dwz
->str
.buffer
[str_offset
] == '\0')
20038 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20041 /* Return pointer to string at .debug_str offset as read from BUF.
20042 BUF is assumed to be in a compilation unit described by CU_HEADER.
20043 Return *BYTES_READ_PTR count of bytes read from BUF. */
20045 static const char *
20046 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20047 const gdb_byte
*buf
,
20048 const struct comp_unit_head
*cu_header
,
20049 unsigned int *bytes_read_ptr
)
20051 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20053 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20056 /* Return pointer to string at .debug_line_str offset as read from BUF.
20057 BUF is assumed to be in a compilation unit described by CU_HEADER.
20058 Return *BYTES_READ_PTR count of bytes read from BUF. */
20060 static const char *
20061 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20062 bfd
*abfd
, const gdb_byte
*buf
,
20063 const struct comp_unit_head
*cu_header
,
20064 unsigned int *bytes_read_ptr
)
20066 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20068 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20073 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20074 unsigned int *bytes_read_ptr
)
20077 unsigned int num_read
;
20079 unsigned char byte
;
20086 byte
= bfd_get_8 (abfd
, buf
);
20089 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20090 if ((byte
& 128) == 0)
20096 *bytes_read_ptr
= num_read
;
20101 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20102 unsigned int *bytes_read_ptr
)
20105 int shift
, num_read
;
20106 unsigned char byte
;
20113 byte
= bfd_get_8 (abfd
, buf
);
20116 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20118 if ((byte
& 128) == 0)
20123 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20124 result
|= -(((ULONGEST
) 1) << shift
);
20125 *bytes_read_ptr
= num_read
;
20129 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20130 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20131 ADDR_SIZE is the size of addresses from the CU header. */
20134 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20135 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
20138 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20139 bfd
*abfd
= objfile
->obfd
;
20140 const gdb_byte
*info_ptr
;
20141 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20143 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20144 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20145 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20146 objfile_name (objfile
));
20147 if (addr_base_or_zero
+ addr_index
* addr_size
20148 >= dwarf2_per_objfile
->addr
.size
)
20149 error (_("DW_FORM_addr_index pointing outside of "
20150 ".debug_addr section [in module %s]"),
20151 objfile_name (objfile
));
20152 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20153 + addr_base_or_zero
+ addr_index
* addr_size
);
20154 if (addr_size
== 4)
20155 return bfd_get_32 (abfd
, info_ptr
);
20157 return bfd_get_64 (abfd
, info_ptr
);
20160 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20163 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20165 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20166 cu
->addr_base
, cu
->header
.addr_size
);
20169 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20172 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20173 unsigned int *bytes_read
)
20175 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20176 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20178 return read_addr_index (cu
, addr_index
);
20181 /* Given an index in .debug_addr, fetch the value.
20182 NOTE: This can be called during dwarf expression evaluation,
20183 long after the debug information has been read, and thus per_cu->cu
20184 may no longer exist. */
20187 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20188 unsigned int addr_index
)
20190 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20191 struct dwarf2_cu
*cu
= per_cu
->cu
;
20192 gdb::optional
<ULONGEST
> addr_base
;
20195 /* We need addr_base and addr_size.
20196 If we don't have PER_CU->cu, we have to get it.
20197 Nasty, but the alternative is storing the needed info in PER_CU,
20198 which at this point doesn't seem justified: it's not clear how frequently
20199 it would get used and it would increase the size of every PER_CU.
20200 Entry points like dwarf2_per_cu_addr_size do a similar thing
20201 so we're not in uncharted territory here.
20202 Alas we need to be a bit more complicated as addr_base is contained
20205 We don't need to read the entire CU(/TU).
20206 We just need the header and top level die.
20208 IWBN to use the aging mechanism to let us lazily later discard the CU.
20209 For now we skip this optimization. */
20213 addr_base
= cu
->addr_base
;
20214 addr_size
= cu
->header
.addr_size
;
20218 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
20219 addr_base
= reader
.cu
->addr_base
;
20220 addr_size
= reader
.cu
->header
.addr_size
;
20223 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20227 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20228 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20231 static const char *
20232 read_str_index (struct dwarf2_cu
*cu
,
20233 struct dwarf2_section_info
*str_section
,
20234 struct dwarf2_section_info
*str_offsets_section
,
20235 ULONGEST str_offsets_base
, ULONGEST str_index
)
20237 struct dwarf2_per_objfile
*dwarf2_per_objfile
20238 = cu
->per_cu
->dwarf2_per_objfile
;
20239 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20240 const char *objf_name
= objfile_name (objfile
);
20241 bfd
*abfd
= objfile
->obfd
;
20242 const gdb_byte
*info_ptr
;
20243 ULONGEST str_offset
;
20244 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20246 dwarf2_read_section (objfile
, str_section
);
20247 dwarf2_read_section (objfile
, str_offsets_section
);
20248 if (str_section
->buffer
== NULL
)
20249 error (_("%s used without %s section"
20250 " in CU at offset %s [in module %s]"),
20251 form_name
, get_section_name (str_section
),
20252 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20253 if (str_offsets_section
->buffer
== NULL
)
20254 error (_("%s used without %s section"
20255 " in CU at offset %s [in module %s]"),
20256 form_name
, get_section_name (str_section
),
20257 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20258 info_ptr
= (str_offsets_section
->buffer
20260 + str_index
* cu
->header
.offset_size
);
20261 if (cu
->header
.offset_size
== 4)
20262 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20264 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20265 if (str_offset
>= str_section
->size
)
20266 error (_("Offset from %s pointing outside of"
20267 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20268 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20269 return (const char *) (str_section
->buffer
+ str_offset
);
20272 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20274 static const char *
20275 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20277 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20278 ? reader
->cu
->header
.addr_size
: 0;
20279 return read_str_index (reader
->cu
,
20280 &reader
->dwo_file
->sections
.str
,
20281 &reader
->dwo_file
->sections
.str_offsets
,
20282 str_offsets_base
, str_index
);
20285 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20287 static const char *
20288 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20290 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20291 const char *objf_name
= objfile_name (objfile
);
20292 static const char form_name
[] = "DW_FORM_GNU_str_index";
20293 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20295 if (!cu
->str_offsets_base
.has_value ())
20296 error (_("%s used in Fission stub without %s"
20297 " in CU at offset 0x%lx [in module %s]"),
20298 form_name
, str_offsets_attr_name
,
20299 (long) cu
->header
.offset_size
, objf_name
);
20301 return read_str_index (cu
,
20302 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20303 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20304 *cu
->str_offsets_base
, str_index
);
20307 /* Return the length of an LEB128 number in BUF. */
20310 leb128_size (const gdb_byte
*buf
)
20312 const gdb_byte
*begin
= buf
;
20318 if ((byte
& 128) == 0)
20319 return buf
- begin
;
20324 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20333 cu
->language
= language_c
;
20336 case DW_LANG_C_plus_plus
:
20337 case DW_LANG_C_plus_plus_11
:
20338 case DW_LANG_C_plus_plus_14
:
20339 cu
->language
= language_cplus
;
20342 cu
->language
= language_d
;
20344 case DW_LANG_Fortran77
:
20345 case DW_LANG_Fortran90
:
20346 case DW_LANG_Fortran95
:
20347 case DW_LANG_Fortran03
:
20348 case DW_LANG_Fortran08
:
20349 cu
->language
= language_fortran
;
20352 cu
->language
= language_go
;
20354 case DW_LANG_Mips_Assembler
:
20355 cu
->language
= language_asm
;
20357 case DW_LANG_Ada83
:
20358 case DW_LANG_Ada95
:
20359 cu
->language
= language_ada
;
20361 case DW_LANG_Modula2
:
20362 cu
->language
= language_m2
;
20364 case DW_LANG_Pascal83
:
20365 cu
->language
= language_pascal
;
20368 cu
->language
= language_objc
;
20371 case DW_LANG_Rust_old
:
20372 cu
->language
= language_rust
;
20374 case DW_LANG_Cobol74
:
20375 case DW_LANG_Cobol85
:
20377 cu
->language
= language_minimal
;
20380 cu
->language_defn
= language_def (cu
->language
);
20383 /* Return the named attribute or NULL if not there. */
20385 static struct attribute
*
20386 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20391 struct attribute
*spec
= NULL
;
20393 for (i
= 0; i
< die
->num_attrs
; ++i
)
20395 if (die
->attrs
[i
].name
== name
)
20396 return &die
->attrs
[i
];
20397 if (die
->attrs
[i
].name
== DW_AT_specification
20398 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20399 spec
= &die
->attrs
[i
];
20405 die
= follow_die_ref (die
, spec
, &cu
);
20411 /* Return the named attribute or NULL if not there,
20412 but do not follow DW_AT_specification, etc.
20413 This is for use in contexts where we're reading .debug_types dies.
20414 Following DW_AT_specification, DW_AT_abstract_origin will take us
20415 back up the chain, and we want to go down. */
20417 static struct attribute
*
20418 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20422 for (i
= 0; i
< die
->num_attrs
; ++i
)
20423 if (die
->attrs
[i
].name
== name
)
20424 return &die
->attrs
[i
];
20429 /* Return the string associated with a string-typed attribute, or NULL if it
20430 is either not found or is of an incorrect type. */
20432 static const char *
20433 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20435 struct attribute
*attr
;
20436 const char *str
= NULL
;
20438 attr
= dwarf2_attr (die
, name
, cu
);
20442 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20443 || attr
->form
== DW_FORM_string
20444 || attr
->form
== DW_FORM_strx
20445 || attr
->form
== DW_FORM_strx1
20446 || attr
->form
== DW_FORM_strx2
20447 || attr
->form
== DW_FORM_strx3
20448 || attr
->form
== DW_FORM_strx4
20449 || attr
->form
== DW_FORM_GNU_str_index
20450 || attr
->form
== DW_FORM_GNU_strp_alt
)
20451 str
= DW_STRING (attr
);
20453 complaint (_("string type expected for attribute %s for "
20454 "DIE at %s in module %s"),
20455 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20456 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20462 /* Return the dwo name or NULL if not present. If present, it is in either
20463 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20464 static const char *
20465 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20467 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20468 if (dwo_name
== nullptr)
20469 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20473 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20474 and holds a non-zero value. This function should only be used for
20475 DW_FORM_flag or DW_FORM_flag_present attributes. */
20478 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20480 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20482 return (attr
&& DW_UNSND (attr
));
20486 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20488 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20489 which value is non-zero. However, we have to be careful with
20490 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20491 (via dwarf2_flag_true_p) follows this attribute. So we may
20492 end up accidently finding a declaration attribute that belongs
20493 to a different DIE referenced by the specification attribute,
20494 even though the given DIE does not have a declaration attribute. */
20495 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20496 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20499 /* Return the die giving the specification for DIE, if there is
20500 one. *SPEC_CU is the CU containing DIE on input, and the CU
20501 containing the return value on output. If there is no
20502 specification, but there is an abstract origin, that is
20505 static struct die_info
*
20506 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20508 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20511 if (spec_attr
== NULL
)
20512 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20514 if (spec_attr
== NULL
)
20517 return follow_die_ref (die
, spec_attr
, spec_cu
);
20520 /* Stub for free_line_header to match void * callback types. */
20523 free_line_header_voidp (void *arg
)
20525 struct line_header
*lh
= (struct line_header
*) arg
;
20531 line_header::add_include_dir (const char *include_dir
)
20533 if (dwarf_line_debug
>= 2)
20537 new_size
= m_include_dirs
.size ();
20539 new_size
= m_include_dirs
.size () + 1;
20540 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20541 new_size
, include_dir
);
20543 m_include_dirs
.push_back (include_dir
);
20547 line_header::add_file_name (const char *name
,
20549 unsigned int mod_time
,
20550 unsigned int length
)
20552 if (dwarf_line_debug
>= 2)
20556 new_size
= file_names_size ();
20558 new_size
= file_names_size () + 1;
20559 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20562 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20565 /* A convenience function to find the proper .debug_line section for a CU. */
20567 static struct dwarf2_section_info
*
20568 get_debug_line_section (struct dwarf2_cu
*cu
)
20570 struct dwarf2_section_info
*section
;
20571 struct dwarf2_per_objfile
*dwarf2_per_objfile
20572 = cu
->per_cu
->dwarf2_per_objfile
;
20574 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20576 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20577 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20578 else if (cu
->per_cu
->is_dwz
)
20580 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20582 section
= &dwz
->line
;
20585 section
= &dwarf2_per_objfile
->line
;
20590 /* Read directory or file name entry format, starting with byte of
20591 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20592 entries count and the entries themselves in the described entry
20596 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20597 bfd
*abfd
, const gdb_byte
**bufp
,
20598 struct line_header
*lh
,
20599 const struct comp_unit_head
*cu_header
,
20600 void (*callback
) (struct line_header
*lh
,
20603 unsigned int mod_time
,
20604 unsigned int length
))
20606 gdb_byte format_count
, formati
;
20607 ULONGEST data_count
, datai
;
20608 const gdb_byte
*buf
= *bufp
;
20609 const gdb_byte
*format_header_data
;
20610 unsigned int bytes_read
;
20612 format_count
= read_1_byte (abfd
, buf
);
20614 format_header_data
= buf
;
20615 for (formati
= 0; formati
< format_count
; formati
++)
20617 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20619 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20623 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20625 for (datai
= 0; datai
< data_count
; datai
++)
20627 const gdb_byte
*format
= format_header_data
;
20628 struct file_entry fe
;
20630 for (formati
= 0; formati
< format_count
; formati
++)
20632 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20633 format
+= bytes_read
;
20635 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20636 format
+= bytes_read
;
20638 gdb::optional
<const char *> string
;
20639 gdb::optional
<unsigned int> uint
;
20643 case DW_FORM_string
:
20644 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20648 case DW_FORM_line_strp
:
20649 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20656 case DW_FORM_data1
:
20657 uint
.emplace (read_1_byte (abfd
, buf
));
20661 case DW_FORM_data2
:
20662 uint
.emplace (read_2_bytes (abfd
, buf
));
20666 case DW_FORM_data4
:
20667 uint
.emplace (read_4_bytes (abfd
, buf
));
20671 case DW_FORM_data8
:
20672 uint
.emplace (read_8_bytes (abfd
, buf
));
20676 case DW_FORM_data16
:
20677 /* This is used for MD5, but file_entry does not record MD5s. */
20681 case DW_FORM_udata
:
20682 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20686 case DW_FORM_block
:
20687 /* It is valid only for DW_LNCT_timestamp which is ignored by
20692 switch (content_type
)
20695 if (string
.has_value ())
20698 case DW_LNCT_directory_index
:
20699 if (uint
.has_value ())
20700 fe
.d_index
= (dir_index
) *uint
;
20702 case DW_LNCT_timestamp
:
20703 if (uint
.has_value ())
20704 fe
.mod_time
= *uint
;
20707 if (uint
.has_value ())
20713 complaint (_("Unknown format content type %s"),
20714 pulongest (content_type
));
20718 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20724 /* Read the statement program header starting at OFFSET in
20725 .debug_line, or .debug_line.dwo. Return a pointer
20726 to a struct line_header, allocated using xmalloc.
20727 Returns NULL if there is a problem reading the header, e.g., if it
20728 has a version we don't understand.
20730 NOTE: the strings in the include directory and file name tables of
20731 the returned object point into the dwarf line section buffer,
20732 and must not be freed. */
20734 static line_header_up
20735 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20737 const gdb_byte
*line_ptr
;
20738 unsigned int bytes_read
, offset_size
;
20740 const char *cur_dir
, *cur_file
;
20741 struct dwarf2_section_info
*section
;
20743 struct dwarf2_per_objfile
*dwarf2_per_objfile
20744 = cu
->per_cu
->dwarf2_per_objfile
;
20746 section
= get_debug_line_section (cu
);
20747 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20748 if (section
->buffer
== NULL
)
20750 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20751 complaint (_("missing .debug_line.dwo section"));
20753 complaint (_("missing .debug_line section"));
20757 /* We can't do this until we know the section is non-empty.
20758 Only then do we know we have such a section. */
20759 abfd
= get_section_bfd_owner (section
);
20761 /* Make sure that at least there's room for the total_length field.
20762 That could be 12 bytes long, but we're just going to fudge that. */
20763 if (to_underlying (sect_off
) + 4 >= section
->size
)
20765 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20769 line_header_up
lh (new line_header ());
20771 lh
->sect_off
= sect_off
;
20772 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20774 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20776 /* Read in the header. */
20778 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20779 &bytes_read
, &offset_size
);
20780 line_ptr
+= bytes_read
;
20782 const gdb_byte
*start_here
= line_ptr
;
20784 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20786 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20789 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20790 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20792 if (lh
->version
> 5)
20794 /* This is a version we don't understand. The format could have
20795 changed in ways we don't handle properly so just punt. */
20796 complaint (_("unsupported version in .debug_line section"));
20799 if (lh
->version
>= 5)
20801 gdb_byte segment_selector_size
;
20803 /* Skip address size. */
20804 read_1_byte (abfd
, line_ptr
);
20807 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20809 if (segment_selector_size
!= 0)
20811 complaint (_("unsupported segment selector size %u "
20812 "in .debug_line section"),
20813 segment_selector_size
);
20817 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20818 line_ptr
+= offset_size
;
20819 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20820 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20822 if (lh
->version
>= 4)
20824 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20828 lh
->maximum_ops_per_instruction
= 1;
20830 if (lh
->maximum_ops_per_instruction
== 0)
20832 lh
->maximum_ops_per_instruction
= 1;
20833 complaint (_("invalid maximum_ops_per_instruction "
20834 "in `.debug_line' section"));
20837 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20839 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20841 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20843 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20845 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20847 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20848 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20850 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20854 if (lh
->version
>= 5)
20856 /* Read directory table. */
20857 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20859 [] (struct line_header
*header
, const char *name
,
20860 dir_index d_index
, unsigned int mod_time
,
20861 unsigned int length
)
20863 header
->add_include_dir (name
);
20866 /* Read file name table. */
20867 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20869 [] (struct line_header
*header
, const char *name
,
20870 dir_index d_index
, unsigned int mod_time
,
20871 unsigned int length
)
20873 header
->add_file_name (name
, d_index
, mod_time
, length
);
20878 /* Read directory table. */
20879 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20881 line_ptr
+= bytes_read
;
20882 lh
->add_include_dir (cur_dir
);
20884 line_ptr
+= bytes_read
;
20886 /* Read file name table. */
20887 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20889 unsigned int mod_time
, length
;
20892 line_ptr
+= bytes_read
;
20893 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20894 line_ptr
+= bytes_read
;
20895 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20896 line_ptr
+= bytes_read
;
20897 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20898 line_ptr
+= bytes_read
;
20900 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20902 line_ptr
+= bytes_read
;
20905 if (line_ptr
> (section
->buffer
+ section
->size
))
20906 complaint (_("line number info header doesn't "
20907 "fit in `.debug_line' section"));
20912 /* Subroutine of dwarf_decode_lines to simplify it.
20913 Return the file name of the psymtab for the given file_entry.
20914 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20915 If space for the result is malloc'd, *NAME_HOLDER will be set.
20916 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20918 static const char *
20919 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20920 const dwarf2_psymtab
*pst
,
20921 const char *comp_dir
,
20922 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20924 const char *include_name
= fe
.name
;
20925 const char *include_name_to_compare
= include_name
;
20926 const char *pst_filename
;
20929 const char *dir_name
= fe
.include_dir (lh
);
20931 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20932 if (!IS_ABSOLUTE_PATH (include_name
)
20933 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20935 /* Avoid creating a duplicate psymtab for PST.
20936 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20937 Before we do the comparison, however, we need to account
20938 for DIR_NAME and COMP_DIR.
20939 First prepend dir_name (if non-NULL). If we still don't
20940 have an absolute path prepend comp_dir (if non-NULL).
20941 However, the directory we record in the include-file's
20942 psymtab does not contain COMP_DIR (to match the
20943 corresponding symtab(s)).
20948 bash$ gcc -g ./hello.c
20949 include_name = "hello.c"
20951 DW_AT_comp_dir = comp_dir = "/tmp"
20952 DW_AT_name = "./hello.c"
20956 if (dir_name
!= NULL
)
20958 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20959 include_name
, (char *) NULL
));
20960 include_name
= name_holder
->get ();
20961 include_name_to_compare
= include_name
;
20963 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20965 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20966 include_name
, (char *) NULL
));
20967 include_name_to_compare
= hold_compare
.get ();
20971 pst_filename
= pst
->filename
;
20972 gdb::unique_xmalloc_ptr
<char> copied_name
;
20973 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
20975 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
20976 pst_filename
, (char *) NULL
));
20977 pst_filename
= copied_name
.get ();
20980 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
20984 return include_name
;
20987 /* State machine to track the state of the line number program. */
20989 class lnp_state_machine
20992 /* Initialize a machine state for the start of a line number
20994 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
20995 bool record_lines_p
);
20997 file_entry
*current_file ()
20999 /* lh->file_names is 0-based, but the file name numbers in the
21000 statement program are 1-based. */
21001 return m_line_header
->file_name_at (m_file
);
21004 /* Record the line in the state machine. END_SEQUENCE is true if
21005 we're processing the end of a sequence. */
21006 void record_line (bool end_sequence
);
21008 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
21009 nop-out rest of the lines in this sequence. */
21010 void check_line_address (struct dwarf2_cu
*cu
,
21011 const gdb_byte
*line_ptr
,
21012 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21014 void handle_set_discriminator (unsigned int discriminator
)
21016 m_discriminator
= discriminator
;
21017 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21020 /* Handle DW_LNE_set_address. */
21021 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21024 address
+= baseaddr
;
21025 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21028 /* Handle DW_LNS_advance_pc. */
21029 void handle_advance_pc (CORE_ADDR adjust
);
21031 /* Handle a special opcode. */
21032 void handle_special_opcode (unsigned char op_code
);
21034 /* Handle DW_LNS_advance_line. */
21035 void handle_advance_line (int line_delta
)
21037 advance_line (line_delta
);
21040 /* Handle DW_LNS_set_file. */
21041 void handle_set_file (file_name_index file
);
21043 /* Handle DW_LNS_negate_stmt. */
21044 void handle_negate_stmt ()
21046 m_is_stmt
= !m_is_stmt
;
21049 /* Handle DW_LNS_const_add_pc. */
21050 void handle_const_add_pc ();
21052 /* Handle DW_LNS_fixed_advance_pc. */
21053 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21055 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21059 /* Handle DW_LNS_copy. */
21060 void handle_copy ()
21062 record_line (false);
21063 m_discriminator
= 0;
21066 /* Handle DW_LNE_end_sequence. */
21067 void handle_end_sequence ()
21069 m_currently_recording_lines
= true;
21073 /* Advance the line by LINE_DELTA. */
21074 void advance_line (int line_delta
)
21076 m_line
+= line_delta
;
21078 if (line_delta
!= 0)
21079 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21082 struct dwarf2_cu
*m_cu
;
21084 gdbarch
*m_gdbarch
;
21086 /* True if we're recording lines.
21087 Otherwise we're building partial symtabs and are just interested in
21088 finding include files mentioned by the line number program. */
21089 bool m_record_lines_p
;
21091 /* The line number header. */
21092 line_header
*m_line_header
;
21094 /* These are part of the standard DWARF line number state machine,
21095 and initialized according to the DWARF spec. */
21097 unsigned char m_op_index
= 0;
21098 /* The line table index of the current file. */
21099 file_name_index m_file
= 1;
21100 unsigned int m_line
= 1;
21102 /* These are initialized in the constructor. */
21104 CORE_ADDR m_address
;
21106 unsigned int m_discriminator
;
21108 /* Additional bits of state we need to track. */
21110 /* The last file that we called dwarf2_start_subfile for.
21111 This is only used for TLLs. */
21112 unsigned int m_last_file
= 0;
21113 /* The last file a line number was recorded for. */
21114 struct subfile
*m_last_subfile
= NULL
;
21116 /* When true, record the lines we decode. */
21117 bool m_currently_recording_lines
= false;
21119 /* The last line number that was recorded, used to coalesce
21120 consecutive entries for the same line. This can happen, for
21121 example, when discriminators are present. PR 17276. */
21122 unsigned int m_last_line
= 0;
21123 bool m_line_has_non_zero_discriminator
= false;
21127 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21129 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21130 / m_line_header
->maximum_ops_per_instruction
)
21131 * m_line_header
->minimum_instruction_length
);
21132 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21133 m_op_index
= ((m_op_index
+ adjust
)
21134 % m_line_header
->maximum_ops_per_instruction
);
21138 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21140 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21141 CORE_ADDR addr_adj
= (((m_op_index
21142 + (adj_opcode
/ m_line_header
->line_range
))
21143 / m_line_header
->maximum_ops_per_instruction
)
21144 * m_line_header
->minimum_instruction_length
);
21145 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21146 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21147 % m_line_header
->maximum_ops_per_instruction
);
21149 int line_delta
= (m_line_header
->line_base
21150 + (adj_opcode
% m_line_header
->line_range
));
21151 advance_line (line_delta
);
21152 record_line (false);
21153 m_discriminator
= 0;
21157 lnp_state_machine::handle_set_file (file_name_index file
)
21161 const file_entry
*fe
= current_file ();
21163 dwarf2_debug_line_missing_file_complaint ();
21164 else if (m_record_lines_p
)
21166 const char *dir
= fe
->include_dir (m_line_header
);
21168 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21169 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21170 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21175 lnp_state_machine::handle_const_add_pc ()
21178 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21181 = (((m_op_index
+ adjust
)
21182 / m_line_header
->maximum_ops_per_instruction
)
21183 * m_line_header
->minimum_instruction_length
);
21185 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21186 m_op_index
= ((m_op_index
+ adjust
)
21187 % m_line_header
->maximum_ops_per_instruction
);
21190 /* Return non-zero if we should add LINE to the line number table.
21191 LINE is the line to add, LAST_LINE is the last line that was added,
21192 LAST_SUBFILE is the subfile for LAST_LINE.
21193 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21194 had a non-zero discriminator.
21196 We have to be careful in the presence of discriminators.
21197 E.g., for this line:
21199 for (i = 0; i < 100000; i++);
21201 clang can emit four line number entries for that one line,
21202 each with a different discriminator.
21203 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21205 However, we want gdb to coalesce all four entries into one.
21206 Otherwise the user could stepi into the middle of the line and
21207 gdb would get confused about whether the pc really was in the
21208 middle of the line.
21210 Things are further complicated by the fact that two consecutive
21211 line number entries for the same line is a heuristic used by gcc
21212 to denote the end of the prologue. So we can't just discard duplicate
21213 entries, we have to be selective about it. The heuristic we use is
21214 that we only collapse consecutive entries for the same line if at least
21215 one of those entries has a non-zero discriminator. PR 17276.
21217 Note: Addresses in the line number state machine can never go backwards
21218 within one sequence, thus this coalescing is ok. */
21221 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21222 unsigned int line
, unsigned int last_line
,
21223 int line_has_non_zero_discriminator
,
21224 struct subfile
*last_subfile
)
21226 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21228 if (line
!= last_line
)
21230 /* Same line for the same file that we've seen already.
21231 As a last check, for pr 17276, only record the line if the line
21232 has never had a non-zero discriminator. */
21233 if (!line_has_non_zero_discriminator
)
21238 /* Use the CU's builder to record line number LINE beginning at
21239 address ADDRESS in the line table of subfile SUBFILE. */
21242 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21243 unsigned int line
, CORE_ADDR address
,
21244 struct dwarf2_cu
*cu
)
21246 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21248 if (dwarf_line_debug
)
21250 fprintf_unfiltered (gdb_stdlog
,
21251 "Recording line %u, file %s, address %s\n",
21252 line
, lbasename (subfile
->name
),
21253 paddress (gdbarch
, address
));
21257 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21260 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21261 Mark the end of a set of line number records.
21262 The arguments are the same as for dwarf_record_line_1.
21263 If SUBFILE is NULL the request is ignored. */
21266 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21267 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21269 if (subfile
== NULL
)
21272 if (dwarf_line_debug
)
21274 fprintf_unfiltered (gdb_stdlog
,
21275 "Finishing current line, file %s, address %s\n",
21276 lbasename (subfile
->name
),
21277 paddress (gdbarch
, address
));
21280 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21284 lnp_state_machine::record_line (bool end_sequence
)
21286 if (dwarf_line_debug
)
21288 fprintf_unfiltered (gdb_stdlog
,
21289 "Processing actual line %u: file %u,"
21290 " address %s, is_stmt %u, discrim %u%s\n",
21292 paddress (m_gdbarch
, m_address
),
21293 m_is_stmt
, m_discriminator
,
21294 (end_sequence
? "\t(end sequence)" : ""));
21297 file_entry
*fe
= current_file ();
21300 dwarf2_debug_line_missing_file_complaint ();
21301 /* For now we ignore lines not starting on an instruction boundary.
21302 But not when processing end_sequence for compatibility with the
21303 previous version of the code. */
21304 else if (m_op_index
== 0 || end_sequence
)
21306 fe
->included_p
= 1;
21307 if (m_record_lines_p
21308 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
21310 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21313 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21314 m_currently_recording_lines
? m_cu
: nullptr);
21319 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21320 m_line_has_non_zero_discriminator
,
21323 buildsym_compunit
*builder
= m_cu
->get_builder ();
21324 dwarf_record_line_1 (m_gdbarch
,
21325 builder
->get_current_subfile (),
21327 m_currently_recording_lines
? m_cu
: nullptr);
21329 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21330 m_last_line
= m_line
;
21336 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21337 line_header
*lh
, bool record_lines_p
)
21341 m_record_lines_p
= record_lines_p
;
21342 m_line_header
= lh
;
21344 m_currently_recording_lines
= true;
21346 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21347 was a line entry for it so that the backend has a chance to adjust it
21348 and also record it in case it needs it. This is currently used by MIPS
21349 code, cf. `mips_adjust_dwarf2_line'. */
21350 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21351 m_is_stmt
= lh
->default_is_stmt
;
21352 m_discriminator
= 0;
21356 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21357 const gdb_byte
*line_ptr
,
21358 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21360 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21361 the pc range of the CU. However, we restrict the test to only ADDRESS
21362 values of zero to preserve GDB's previous behaviour which is to handle
21363 the specific case of a function being GC'd by the linker. */
21365 if (address
== 0 && address
< unrelocated_lowpc
)
21367 /* This line table is for a function which has been
21368 GCd by the linker. Ignore it. PR gdb/12528 */
21370 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21371 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21373 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21374 line_offset
, objfile_name (objfile
));
21375 m_currently_recording_lines
= false;
21376 /* Note: m_currently_recording_lines is left as false until we see
21377 DW_LNE_end_sequence. */
21381 /* Subroutine of dwarf_decode_lines to simplify it.
21382 Process the line number information in LH.
21383 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21384 program in order to set included_p for every referenced header. */
21387 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21388 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21390 const gdb_byte
*line_ptr
, *extended_end
;
21391 const gdb_byte
*line_end
;
21392 unsigned int bytes_read
, extended_len
;
21393 unsigned char op_code
, extended_op
;
21394 CORE_ADDR baseaddr
;
21395 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21396 bfd
*abfd
= objfile
->obfd
;
21397 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21398 /* True if we're recording line info (as opposed to building partial
21399 symtabs and just interested in finding include files mentioned by
21400 the line number program). */
21401 bool record_lines_p
= !decode_for_pst_p
;
21403 baseaddr
= objfile
->text_section_offset ();
21405 line_ptr
= lh
->statement_program_start
;
21406 line_end
= lh
->statement_program_end
;
21408 /* Read the statement sequences until there's nothing left. */
21409 while (line_ptr
< line_end
)
21411 /* The DWARF line number program state machine. Reset the state
21412 machine at the start of each sequence. */
21413 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21414 bool end_sequence
= false;
21416 if (record_lines_p
)
21418 /* Start a subfile for the current file of the state
21420 const file_entry
*fe
= state_machine
.current_file ();
21423 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21426 /* Decode the table. */
21427 while (line_ptr
< line_end
&& !end_sequence
)
21429 op_code
= read_1_byte (abfd
, line_ptr
);
21432 if (op_code
>= lh
->opcode_base
)
21434 /* Special opcode. */
21435 state_machine
.handle_special_opcode (op_code
);
21437 else switch (op_code
)
21439 case DW_LNS_extended_op
:
21440 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21442 line_ptr
+= bytes_read
;
21443 extended_end
= line_ptr
+ extended_len
;
21444 extended_op
= read_1_byte (abfd
, line_ptr
);
21446 switch (extended_op
)
21448 case DW_LNE_end_sequence
:
21449 state_machine
.handle_end_sequence ();
21450 end_sequence
= true;
21452 case DW_LNE_set_address
:
21455 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21456 line_ptr
+= bytes_read
;
21458 state_machine
.check_line_address (cu
, line_ptr
,
21459 lowpc
- baseaddr
, address
);
21460 state_machine
.handle_set_address (baseaddr
, address
);
21463 case DW_LNE_define_file
:
21465 const char *cur_file
;
21466 unsigned int mod_time
, length
;
21469 cur_file
= read_direct_string (abfd
, line_ptr
,
21471 line_ptr
+= bytes_read
;
21472 dindex
= (dir_index
)
21473 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21474 line_ptr
+= bytes_read
;
21476 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21477 line_ptr
+= bytes_read
;
21479 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21480 line_ptr
+= bytes_read
;
21481 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21484 case DW_LNE_set_discriminator
:
21486 /* The discriminator is not interesting to the
21487 debugger; just ignore it. We still need to
21488 check its value though:
21489 if there are consecutive entries for the same
21490 (non-prologue) line we want to coalesce them.
21493 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21494 line_ptr
+= bytes_read
;
21496 state_machine
.handle_set_discriminator (discr
);
21500 complaint (_("mangled .debug_line section"));
21503 /* Make sure that we parsed the extended op correctly. If e.g.
21504 we expected a different address size than the producer used,
21505 we may have read the wrong number of bytes. */
21506 if (line_ptr
!= extended_end
)
21508 complaint (_("mangled .debug_line section"));
21513 state_machine
.handle_copy ();
21515 case DW_LNS_advance_pc
:
21518 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21519 line_ptr
+= bytes_read
;
21521 state_machine
.handle_advance_pc (adjust
);
21524 case DW_LNS_advance_line
:
21527 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21528 line_ptr
+= bytes_read
;
21530 state_machine
.handle_advance_line (line_delta
);
21533 case DW_LNS_set_file
:
21535 file_name_index file
21536 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21538 line_ptr
+= bytes_read
;
21540 state_machine
.handle_set_file (file
);
21543 case DW_LNS_set_column
:
21544 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21545 line_ptr
+= bytes_read
;
21547 case DW_LNS_negate_stmt
:
21548 state_machine
.handle_negate_stmt ();
21550 case DW_LNS_set_basic_block
:
21552 /* Add to the address register of the state machine the
21553 address increment value corresponding to special opcode
21554 255. I.e., this value is scaled by the minimum
21555 instruction length since special opcode 255 would have
21556 scaled the increment. */
21557 case DW_LNS_const_add_pc
:
21558 state_machine
.handle_const_add_pc ();
21560 case DW_LNS_fixed_advance_pc
:
21562 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21565 state_machine
.handle_fixed_advance_pc (addr_adj
);
21570 /* Unknown standard opcode, ignore it. */
21573 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21575 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21576 line_ptr
+= bytes_read
;
21583 dwarf2_debug_line_missing_end_sequence_complaint ();
21585 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21586 in which case we still finish recording the last line). */
21587 state_machine
.record_line (true);
21591 /* Decode the Line Number Program (LNP) for the given line_header
21592 structure and CU. The actual information extracted and the type
21593 of structures created from the LNP depends on the value of PST.
21595 1. If PST is NULL, then this procedure uses the data from the program
21596 to create all necessary symbol tables, and their linetables.
21598 2. If PST is not NULL, this procedure reads the program to determine
21599 the list of files included by the unit represented by PST, and
21600 builds all the associated partial symbol tables.
21602 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21603 It is used for relative paths in the line table.
21604 NOTE: When processing partial symtabs (pst != NULL),
21605 comp_dir == pst->dirname.
21607 NOTE: It is important that psymtabs have the same file name (via strcmp)
21608 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21609 symtab we don't use it in the name of the psymtabs we create.
21610 E.g. expand_line_sal requires this when finding psymtabs to expand.
21611 A good testcase for this is mb-inline.exp.
21613 LOWPC is the lowest address in CU (or 0 if not known).
21615 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21616 for its PC<->lines mapping information. Otherwise only the filename
21617 table is read in. */
21620 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21621 struct dwarf2_cu
*cu
, dwarf2_psymtab
*pst
,
21622 CORE_ADDR lowpc
, int decode_mapping
)
21624 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21625 const int decode_for_pst_p
= (pst
!= NULL
);
21627 if (decode_mapping
)
21628 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21630 if (decode_for_pst_p
)
21632 /* Now that we're done scanning the Line Header Program, we can
21633 create the psymtab of each included file. */
21634 for (auto &file_entry
: lh
->file_names ())
21635 if (file_entry
.included_p
== 1)
21637 gdb::unique_xmalloc_ptr
<char> name_holder
;
21638 const char *include_name
=
21639 psymtab_include_file_name (lh
, file_entry
, pst
,
21640 comp_dir
, &name_holder
);
21641 if (include_name
!= NULL
)
21642 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21647 /* Make sure a symtab is created for every file, even files
21648 which contain only variables (i.e. no code with associated
21650 buildsym_compunit
*builder
= cu
->get_builder ();
21651 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21653 for (auto &fe
: lh
->file_names ())
21655 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21656 if (builder
->get_current_subfile ()->symtab
== NULL
)
21658 builder
->get_current_subfile ()->symtab
21659 = allocate_symtab (cust
,
21660 builder
->get_current_subfile ()->name
);
21662 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21667 /* Start a subfile for DWARF. FILENAME is the name of the file and
21668 DIRNAME the name of the source directory which contains FILENAME
21669 or NULL if not known.
21670 This routine tries to keep line numbers from identical absolute and
21671 relative file names in a common subfile.
21673 Using the `list' example from the GDB testsuite, which resides in
21674 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21675 of /srcdir/list0.c yields the following debugging information for list0.c:
21677 DW_AT_name: /srcdir/list0.c
21678 DW_AT_comp_dir: /compdir
21679 files.files[0].name: list0.h
21680 files.files[0].dir: /srcdir
21681 files.files[1].name: list0.c
21682 files.files[1].dir: /srcdir
21684 The line number information for list0.c has to end up in a single
21685 subfile, so that `break /srcdir/list0.c:1' works as expected.
21686 start_subfile will ensure that this happens provided that we pass the
21687 concatenation of files.files[1].dir and files.files[1].name as the
21691 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21692 const char *dirname
)
21694 gdb::unique_xmalloc_ptr
<char> copy
;
21696 /* In order not to lose the line information directory,
21697 we concatenate it to the filename when it makes sense.
21698 Note that the Dwarf3 standard says (speaking of filenames in line
21699 information): ``The directory index is ignored for file names
21700 that represent full path names''. Thus ignoring dirname in the
21701 `else' branch below isn't an issue. */
21703 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21705 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21706 filename
= copy
.get ();
21709 cu
->get_builder ()->start_subfile (filename
);
21712 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21713 buildsym_compunit constructor. */
21715 struct compunit_symtab
*
21716 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21719 gdb_assert (m_builder
== nullptr);
21721 m_builder
.reset (new struct buildsym_compunit
21722 (per_cu
->dwarf2_per_objfile
->objfile
,
21723 name
, comp_dir
, language
, low_pc
));
21725 list_in_scope
= get_builder ()->get_file_symbols ();
21727 get_builder ()->record_debugformat ("DWARF 2");
21728 get_builder ()->record_producer (producer
);
21730 processing_has_namespace_info
= false;
21732 return get_builder ()->get_compunit_symtab ();
21736 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21737 struct dwarf2_cu
*cu
)
21739 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21740 struct comp_unit_head
*cu_header
= &cu
->header
;
21742 /* NOTE drow/2003-01-30: There used to be a comment and some special
21743 code here to turn a symbol with DW_AT_external and a
21744 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21745 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21746 with some versions of binutils) where shared libraries could have
21747 relocations against symbols in their debug information - the
21748 minimal symbol would have the right address, but the debug info
21749 would not. It's no longer necessary, because we will explicitly
21750 apply relocations when we read in the debug information now. */
21752 /* A DW_AT_location attribute with no contents indicates that a
21753 variable has been optimized away. */
21754 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21756 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21760 /* Handle one degenerate form of location expression specially, to
21761 preserve GDB's previous behavior when section offsets are
21762 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21763 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21765 if (attr_form_is_block (attr
)
21766 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21767 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21768 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21769 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21770 && (DW_BLOCK (attr
)->size
21771 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21773 unsigned int dummy
;
21775 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21776 SET_SYMBOL_VALUE_ADDRESS (sym
,
21777 read_address (objfile
->obfd
,
21778 DW_BLOCK (attr
)->data
+ 1,
21781 SET_SYMBOL_VALUE_ADDRESS
21782 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21784 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21785 fixup_symbol_section (sym
, objfile
);
21786 SET_SYMBOL_VALUE_ADDRESS
21788 SYMBOL_VALUE_ADDRESS (sym
)
21789 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21793 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21794 expression evaluator, and use LOC_COMPUTED only when necessary
21795 (i.e. when the value of a register or memory location is
21796 referenced, or a thread-local block, etc.). Then again, it might
21797 not be worthwhile. I'm assuming that it isn't unless performance
21798 or memory numbers show me otherwise. */
21800 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21802 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21803 cu
->has_loclist
= true;
21806 /* Given a pointer to a DWARF information entry, figure out if we need
21807 to make a symbol table entry for it, and if so, create a new entry
21808 and return a pointer to it.
21809 If TYPE is NULL, determine symbol type from the die, otherwise
21810 used the passed type.
21811 If SPACE is not NULL, use it to hold the new symbol. If it is
21812 NULL, allocate a new symbol on the objfile's obstack. */
21814 static struct symbol
*
21815 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21816 struct symbol
*space
)
21818 struct dwarf2_per_objfile
*dwarf2_per_objfile
21819 = cu
->per_cu
->dwarf2_per_objfile
;
21820 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21821 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21822 struct symbol
*sym
= NULL
;
21824 struct attribute
*attr
= NULL
;
21825 struct attribute
*attr2
= NULL
;
21826 CORE_ADDR baseaddr
;
21827 struct pending
**list_to_add
= NULL
;
21829 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21831 baseaddr
= objfile
->text_section_offset ();
21833 name
= dwarf2_name (die
, cu
);
21836 const char *linkagename
;
21837 int suppress_add
= 0;
21842 sym
= allocate_symbol (objfile
);
21843 OBJSTAT (objfile
, n_syms
++);
21845 /* Cache this symbol's name and the name's demangled form (if any). */
21846 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21847 linkagename
= dwarf2_physname (name
, die
, cu
);
21848 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21850 /* Fortran does not have mangling standard and the mangling does differ
21851 between gfortran, iFort etc. */
21852 if (cu
->language
== language_fortran
21853 && symbol_get_demangled_name (sym
) == NULL
)
21854 symbol_set_demangled_name (sym
,
21855 dwarf2_full_name (name
, die
, cu
),
21858 /* Default assumptions.
21859 Use the passed type or decode it from the die. */
21860 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21861 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21863 SYMBOL_TYPE (sym
) = type
;
21865 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21866 attr
= dwarf2_attr (die
,
21867 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21869 if (attr
!= nullptr)
21871 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21874 attr
= dwarf2_attr (die
,
21875 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21877 if (attr
!= nullptr)
21879 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21880 struct file_entry
*fe
;
21882 if (cu
->line_header
!= NULL
)
21883 fe
= cu
->line_header
->file_name_at (file_index
);
21888 complaint (_("file index out of range"));
21890 symbol_set_symtab (sym
, fe
->symtab
);
21896 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21897 if (attr
!= nullptr)
21901 addr
= attr_value_as_address (attr
);
21902 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21903 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21905 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21906 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21907 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21908 add_symbol_to_list (sym
, cu
->list_in_scope
);
21910 case DW_TAG_subprogram
:
21911 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21913 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21914 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21915 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21916 || cu
->language
== language_ada
21917 || cu
->language
== language_fortran
)
21919 /* Subprograms marked external are stored as a global symbol.
21920 Ada and Fortran subprograms, whether marked external or
21921 not, are always stored as a global symbol, because we want
21922 to be able to access them globally. For instance, we want
21923 to be able to break on a nested subprogram without having
21924 to specify the context. */
21925 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21929 list_to_add
= cu
->list_in_scope
;
21932 case DW_TAG_inlined_subroutine
:
21933 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21935 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21936 SYMBOL_INLINED (sym
) = 1;
21937 list_to_add
= cu
->list_in_scope
;
21939 case DW_TAG_template_value_param
:
21941 /* Fall through. */
21942 case DW_TAG_constant
:
21943 case DW_TAG_variable
:
21944 case DW_TAG_member
:
21945 /* Compilation with minimal debug info may result in
21946 variables with missing type entries. Change the
21947 misleading `void' type to something sensible. */
21948 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21949 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21951 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21952 /* In the case of DW_TAG_member, we should only be called for
21953 static const members. */
21954 if (die
->tag
== DW_TAG_member
)
21956 /* dwarf2_add_field uses die_is_declaration,
21957 so we do the same. */
21958 gdb_assert (die_is_declaration (die
, cu
));
21961 if (attr
!= nullptr)
21963 dwarf2_const_value (attr
, sym
, cu
);
21964 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21967 if (attr2
&& (DW_UNSND (attr2
) != 0))
21968 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21970 list_to_add
= cu
->list_in_scope
;
21974 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
21975 if (attr
!= nullptr)
21977 var_decode_location (attr
, sym
, cu
);
21978 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21980 /* Fortran explicitly imports any global symbols to the local
21981 scope by DW_TAG_common_block. */
21982 if (cu
->language
== language_fortran
&& die
->parent
21983 && die
->parent
->tag
== DW_TAG_common_block
)
21986 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21987 && SYMBOL_VALUE_ADDRESS (sym
) == 0
21988 && !dwarf2_per_objfile
->has_section_at_zero
)
21990 /* When a static variable is eliminated by the linker,
21991 the corresponding debug information is not stripped
21992 out, but the variable address is set to null;
21993 do not add such variables into symbol table. */
21995 else if (attr2
&& (DW_UNSND (attr2
) != 0))
21997 if (SYMBOL_CLASS (sym
) == LOC_STATIC
21998 && (objfile
->flags
& OBJF_MAINLINE
) == 0
21999 && dwarf2_per_objfile
->can_copy
)
22001 /* A global static variable might be subject to
22002 copy relocation. We first check for a local
22003 minsym, though, because maybe the symbol was
22004 marked hidden, in which case this would not
22006 bound_minimal_symbol found
22007 = (lookup_minimal_symbol_linkage
22008 (sym
->linkage_name (), objfile
));
22009 if (found
.minsym
!= nullptr)
22010 sym
->maybe_copied
= 1;
22013 /* A variable with DW_AT_external is never static,
22014 but it may be block-scoped. */
22016 = ((cu
->list_in_scope
22017 == cu
->get_builder ()->get_file_symbols ())
22018 ? cu
->get_builder ()->get_global_symbols ()
22019 : cu
->list_in_scope
);
22022 list_to_add
= cu
->list_in_scope
;
22026 /* We do not know the address of this symbol.
22027 If it is an external symbol and we have type information
22028 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22029 The address of the variable will then be determined from
22030 the minimal symbol table whenever the variable is
22032 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22034 /* Fortran explicitly imports any global symbols to the local
22035 scope by DW_TAG_common_block. */
22036 if (cu
->language
== language_fortran
&& die
->parent
22037 && die
->parent
->tag
== DW_TAG_common_block
)
22039 /* SYMBOL_CLASS doesn't matter here because
22040 read_common_block is going to reset it. */
22042 list_to_add
= cu
->list_in_scope
;
22044 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22045 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22047 /* A variable with DW_AT_external is never static, but it
22048 may be block-scoped. */
22050 = ((cu
->list_in_scope
22051 == cu
->get_builder ()->get_file_symbols ())
22052 ? cu
->get_builder ()->get_global_symbols ()
22053 : cu
->list_in_scope
);
22055 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22057 else if (!die_is_declaration (die
, cu
))
22059 /* Use the default LOC_OPTIMIZED_OUT class. */
22060 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22062 list_to_add
= cu
->list_in_scope
;
22066 case DW_TAG_formal_parameter
:
22068 /* If we are inside a function, mark this as an argument. If
22069 not, we might be looking at an argument to an inlined function
22070 when we do not have enough information to show inlined frames;
22071 pretend it's a local variable in that case so that the user can
22073 struct context_stack
*curr
22074 = cu
->get_builder ()->get_current_context_stack ();
22075 if (curr
!= nullptr && curr
->name
!= nullptr)
22076 SYMBOL_IS_ARGUMENT (sym
) = 1;
22077 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22078 if (attr
!= nullptr)
22080 var_decode_location (attr
, sym
, cu
);
22082 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22083 if (attr
!= nullptr)
22085 dwarf2_const_value (attr
, sym
, cu
);
22088 list_to_add
= cu
->list_in_scope
;
22091 case DW_TAG_unspecified_parameters
:
22092 /* From varargs functions; gdb doesn't seem to have any
22093 interest in this information, so just ignore it for now.
22096 case DW_TAG_template_type_param
:
22098 /* Fall through. */
22099 case DW_TAG_class_type
:
22100 case DW_TAG_interface_type
:
22101 case DW_TAG_structure_type
:
22102 case DW_TAG_union_type
:
22103 case DW_TAG_set_type
:
22104 case DW_TAG_enumeration_type
:
22105 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22106 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22109 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22110 really ever be static objects: otherwise, if you try
22111 to, say, break of a class's method and you're in a file
22112 which doesn't mention that class, it won't work unless
22113 the check for all static symbols in lookup_symbol_aux
22114 saves you. See the OtherFileClass tests in
22115 gdb.c++/namespace.exp. */
22119 buildsym_compunit
*builder
= cu
->get_builder ();
22121 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22122 && cu
->language
== language_cplus
22123 ? builder
->get_global_symbols ()
22124 : cu
->list_in_scope
);
22126 /* The semantics of C++ state that "struct foo {
22127 ... }" also defines a typedef for "foo". */
22128 if (cu
->language
== language_cplus
22129 || cu
->language
== language_ada
22130 || cu
->language
== language_d
22131 || cu
->language
== language_rust
)
22133 /* The symbol's name is already allocated along
22134 with this objfile, so we don't need to
22135 duplicate it for the type. */
22136 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22137 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22142 case DW_TAG_typedef
:
22143 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22144 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22145 list_to_add
= cu
->list_in_scope
;
22147 case DW_TAG_base_type
:
22148 case DW_TAG_subrange_type
:
22149 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22150 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22151 list_to_add
= cu
->list_in_scope
;
22153 case DW_TAG_enumerator
:
22154 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22155 if (attr
!= nullptr)
22157 dwarf2_const_value (attr
, sym
, cu
);
22160 /* NOTE: carlton/2003-11-10: See comment above in the
22161 DW_TAG_class_type, etc. block. */
22164 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22165 && cu
->language
== language_cplus
22166 ? cu
->get_builder ()->get_global_symbols ()
22167 : cu
->list_in_scope
);
22170 case DW_TAG_imported_declaration
:
22171 case DW_TAG_namespace
:
22172 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22173 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22175 case DW_TAG_module
:
22176 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22177 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22178 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22180 case DW_TAG_common_block
:
22181 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22182 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22183 add_symbol_to_list (sym
, cu
->list_in_scope
);
22186 /* Not a tag we recognize. Hopefully we aren't processing
22187 trash data, but since we must specifically ignore things
22188 we don't recognize, there is nothing else we should do at
22190 complaint (_("unsupported tag: '%s'"),
22191 dwarf_tag_name (die
->tag
));
22197 sym
->hash_next
= objfile
->template_symbols
;
22198 objfile
->template_symbols
= sym
;
22199 list_to_add
= NULL
;
22202 if (list_to_add
!= NULL
)
22203 add_symbol_to_list (sym
, list_to_add
);
22205 /* For the benefit of old versions of GCC, check for anonymous
22206 namespaces based on the demangled name. */
22207 if (!cu
->processing_has_namespace_info
22208 && cu
->language
== language_cplus
)
22209 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22214 /* Given an attr with a DW_FORM_dataN value in host byte order,
22215 zero-extend it as appropriate for the symbol's type. The DWARF
22216 standard (v4) is not entirely clear about the meaning of using
22217 DW_FORM_dataN for a constant with a signed type, where the type is
22218 wider than the data. The conclusion of a discussion on the DWARF
22219 list was that this is unspecified. We choose to always zero-extend
22220 because that is the interpretation long in use by GCC. */
22223 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22224 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22226 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22227 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22228 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22229 LONGEST l
= DW_UNSND (attr
);
22231 if (bits
< sizeof (*value
) * 8)
22233 l
&= ((LONGEST
) 1 << bits
) - 1;
22236 else if (bits
== sizeof (*value
) * 8)
22240 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22241 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22248 /* Read a constant value from an attribute. Either set *VALUE, or if
22249 the value does not fit in *VALUE, set *BYTES - either already
22250 allocated on the objfile obstack, or newly allocated on OBSTACK,
22251 or, set *BATON, if we translated the constant to a location
22255 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22256 const char *name
, struct obstack
*obstack
,
22257 struct dwarf2_cu
*cu
,
22258 LONGEST
*value
, const gdb_byte
**bytes
,
22259 struct dwarf2_locexpr_baton
**baton
)
22261 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22262 struct comp_unit_head
*cu_header
= &cu
->header
;
22263 struct dwarf_block
*blk
;
22264 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22265 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22271 switch (attr
->form
)
22274 case DW_FORM_addrx
:
22275 case DW_FORM_GNU_addr_index
:
22279 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22280 dwarf2_const_value_length_mismatch_complaint (name
,
22281 cu_header
->addr_size
,
22282 TYPE_LENGTH (type
));
22283 /* Symbols of this form are reasonably rare, so we just
22284 piggyback on the existing location code rather than writing
22285 a new implementation of symbol_computed_ops. */
22286 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22287 (*baton
)->per_cu
= cu
->per_cu
;
22288 gdb_assert ((*baton
)->per_cu
);
22290 (*baton
)->size
= 2 + cu_header
->addr_size
;
22291 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22292 (*baton
)->data
= data
;
22294 data
[0] = DW_OP_addr
;
22295 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22296 byte_order
, DW_ADDR (attr
));
22297 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22300 case DW_FORM_string
:
22303 case DW_FORM_GNU_str_index
:
22304 case DW_FORM_GNU_strp_alt
:
22305 /* DW_STRING is already allocated on the objfile obstack, point
22307 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22309 case DW_FORM_block1
:
22310 case DW_FORM_block2
:
22311 case DW_FORM_block4
:
22312 case DW_FORM_block
:
22313 case DW_FORM_exprloc
:
22314 case DW_FORM_data16
:
22315 blk
= DW_BLOCK (attr
);
22316 if (TYPE_LENGTH (type
) != blk
->size
)
22317 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22318 TYPE_LENGTH (type
));
22319 *bytes
= blk
->data
;
22322 /* The DW_AT_const_value attributes are supposed to carry the
22323 symbol's value "represented as it would be on the target
22324 architecture." By the time we get here, it's already been
22325 converted to host endianness, so we just need to sign- or
22326 zero-extend it as appropriate. */
22327 case DW_FORM_data1
:
22328 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22330 case DW_FORM_data2
:
22331 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22333 case DW_FORM_data4
:
22334 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22336 case DW_FORM_data8
:
22337 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22340 case DW_FORM_sdata
:
22341 case DW_FORM_implicit_const
:
22342 *value
= DW_SND (attr
);
22345 case DW_FORM_udata
:
22346 *value
= DW_UNSND (attr
);
22350 complaint (_("unsupported const value attribute form: '%s'"),
22351 dwarf_form_name (attr
->form
));
22358 /* Copy constant value from an attribute to a symbol. */
22361 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22362 struct dwarf2_cu
*cu
)
22364 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22366 const gdb_byte
*bytes
;
22367 struct dwarf2_locexpr_baton
*baton
;
22369 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22370 sym
->print_name (),
22371 &objfile
->objfile_obstack
, cu
,
22372 &value
, &bytes
, &baton
);
22376 SYMBOL_LOCATION_BATON (sym
) = baton
;
22377 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22379 else if (bytes
!= NULL
)
22381 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22382 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22386 SYMBOL_VALUE (sym
) = value
;
22387 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22391 /* Return the type of the die in question using its DW_AT_type attribute. */
22393 static struct type
*
22394 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22396 struct attribute
*type_attr
;
22398 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22401 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22402 /* A missing DW_AT_type represents a void type. */
22403 return objfile_type (objfile
)->builtin_void
;
22406 return lookup_die_type (die
, type_attr
, cu
);
22409 /* True iff CU's producer generates GNAT Ada auxiliary information
22410 that allows to find parallel types through that information instead
22411 of having to do expensive parallel lookups by type name. */
22414 need_gnat_info (struct dwarf2_cu
*cu
)
22416 /* Assume that the Ada compiler was GNAT, which always produces
22417 the auxiliary information. */
22418 return (cu
->language
== language_ada
);
22421 /* Return the auxiliary type of the die in question using its
22422 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22423 attribute is not present. */
22425 static struct type
*
22426 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22428 struct attribute
*type_attr
;
22430 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22434 return lookup_die_type (die
, type_attr
, cu
);
22437 /* If DIE has a descriptive_type attribute, then set the TYPE's
22438 descriptive type accordingly. */
22441 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22442 struct dwarf2_cu
*cu
)
22444 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22446 if (descriptive_type
)
22448 ALLOCATE_GNAT_AUX_TYPE (type
);
22449 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22453 /* Return the containing type of the die in question using its
22454 DW_AT_containing_type attribute. */
22456 static struct type
*
22457 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22459 struct attribute
*type_attr
;
22460 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22462 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22464 error (_("Dwarf Error: Problem turning containing type into gdb type "
22465 "[in module %s]"), objfile_name (objfile
));
22467 return lookup_die_type (die
, type_attr
, cu
);
22470 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22472 static struct type
*
22473 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22475 struct dwarf2_per_objfile
*dwarf2_per_objfile
22476 = cu
->per_cu
->dwarf2_per_objfile
;
22477 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22480 std::string message
22481 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22482 objfile_name (objfile
),
22483 sect_offset_str (cu
->header
.sect_off
),
22484 sect_offset_str (die
->sect_off
));
22485 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22487 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22490 /* Look up the type of DIE in CU using its type attribute ATTR.
22491 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22492 DW_AT_containing_type.
22493 If there is no type substitute an error marker. */
22495 static struct type
*
22496 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22497 struct dwarf2_cu
*cu
)
22499 struct dwarf2_per_objfile
*dwarf2_per_objfile
22500 = cu
->per_cu
->dwarf2_per_objfile
;
22501 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22502 struct type
*this_type
;
22504 gdb_assert (attr
->name
== DW_AT_type
22505 || attr
->name
== DW_AT_GNAT_descriptive_type
22506 || attr
->name
== DW_AT_containing_type
);
22508 /* First see if we have it cached. */
22510 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22512 struct dwarf2_per_cu_data
*per_cu
;
22513 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22515 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22516 dwarf2_per_objfile
);
22517 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22519 else if (attr_form_is_ref (attr
))
22521 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22523 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22525 else if (attr
->form
== DW_FORM_ref_sig8
)
22527 ULONGEST signature
= DW_SIGNATURE (attr
);
22529 return get_signatured_type (die
, signature
, cu
);
22533 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22534 " at %s [in module %s]"),
22535 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22536 objfile_name (objfile
));
22537 return build_error_marker_type (cu
, die
);
22540 /* If not cached we need to read it in. */
22542 if (this_type
== NULL
)
22544 struct die_info
*type_die
= NULL
;
22545 struct dwarf2_cu
*type_cu
= cu
;
22547 if (attr_form_is_ref (attr
))
22548 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22549 if (type_die
== NULL
)
22550 return build_error_marker_type (cu
, die
);
22551 /* If we find the type now, it's probably because the type came
22552 from an inter-CU reference and the type's CU got expanded before
22554 this_type
= read_type_die (type_die
, type_cu
);
22557 /* If we still don't have a type use an error marker. */
22559 if (this_type
== NULL
)
22560 return build_error_marker_type (cu
, die
);
22565 /* Return the type in DIE, CU.
22566 Returns NULL for invalid types.
22568 This first does a lookup in die_type_hash,
22569 and only reads the die in if necessary.
22571 NOTE: This can be called when reading in partial or full symbols. */
22573 static struct type
*
22574 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22576 struct type
*this_type
;
22578 this_type
= get_die_type (die
, cu
);
22582 return read_type_die_1 (die
, cu
);
22585 /* Read the type in DIE, CU.
22586 Returns NULL for invalid types. */
22588 static struct type
*
22589 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22591 struct type
*this_type
= NULL
;
22595 case DW_TAG_class_type
:
22596 case DW_TAG_interface_type
:
22597 case DW_TAG_structure_type
:
22598 case DW_TAG_union_type
:
22599 this_type
= read_structure_type (die
, cu
);
22601 case DW_TAG_enumeration_type
:
22602 this_type
= read_enumeration_type (die
, cu
);
22604 case DW_TAG_subprogram
:
22605 case DW_TAG_subroutine_type
:
22606 case DW_TAG_inlined_subroutine
:
22607 this_type
= read_subroutine_type (die
, cu
);
22609 case DW_TAG_array_type
:
22610 this_type
= read_array_type (die
, cu
);
22612 case DW_TAG_set_type
:
22613 this_type
= read_set_type (die
, cu
);
22615 case DW_TAG_pointer_type
:
22616 this_type
= read_tag_pointer_type (die
, cu
);
22618 case DW_TAG_ptr_to_member_type
:
22619 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22621 case DW_TAG_reference_type
:
22622 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22624 case DW_TAG_rvalue_reference_type
:
22625 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22627 case DW_TAG_const_type
:
22628 this_type
= read_tag_const_type (die
, cu
);
22630 case DW_TAG_volatile_type
:
22631 this_type
= read_tag_volatile_type (die
, cu
);
22633 case DW_TAG_restrict_type
:
22634 this_type
= read_tag_restrict_type (die
, cu
);
22636 case DW_TAG_string_type
:
22637 this_type
= read_tag_string_type (die
, cu
);
22639 case DW_TAG_typedef
:
22640 this_type
= read_typedef (die
, cu
);
22642 case DW_TAG_subrange_type
:
22643 this_type
= read_subrange_type (die
, cu
);
22645 case DW_TAG_base_type
:
22646 this_type
= read_base_type (die
, cu
);
22648 case DW_TAG_unspecified_type
:
22649 this_type
= read_unspecified_type (die
, cu
);
22651 case DW_TAG_namespace
:
22652 this_type
= read_namespace_type (die
, cu
);
22654 case DW_TAG_module
:
22655 this_type
= read_module_type (die
, cu
);
22657 case DW_TAG_atomic_type
:
22658 this_type
= read_tag_atomic_type (die
, cu
);
22661 complaint (_("unexpected tag in read_type_die: '%s'"),
22662 dwarf_tag_name (die
->tag
));
22669 /* See if we can figure out if the class lives in a namespace. We do
22670 this by looking for a member function; its demangled name will
22671 contain namespace info, if there is any.
22672 Return the computed name or NULL.
22673 Space for the result is allocated on the objfile's obstack.
22674 This is the full-die version of guess_partial_die_structure_name.
22675 In this case we know DIE has no useful parent. */
22677 static const char *
22678 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22680 struct die_info
*spec_die
;
22681 struct dwarf2_cu
*spec_cu
;
22682 struct die_info
*child
;
22683 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22686 spec_die
= die_specification (die
, &spec_cu
);
22687 if (spec_die
!= NULL
)
22693 for (child
= die
->child
;
22695 child
= child
->sibling
)
22697 if (child
->tag
== DW_TAG_subprogram
)
22699 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22701 if (linkage_name
!= NULL
)
22703 gdb::unique_xmalloc_ptr
<char> actual_name
22704 (language_class_name_from_physname (cu
->language_defn
,
22706 const char *name
= NULL
;
22708 if (actual_name
!= NULL
)
22710 const char *die_name
= dwarf2_name (die
, cu
);
22712 if (die_name
!= NULL
22713 && strcmp (die_name
, actual_name
.get ()) != 0)
22715 /* Strip off the class name from the full name.
22716 We want the prefix. */
22717 int die_name_len
= strlen (die_name
);
22718 int actual_name_len
= strlen (actual_name
.get ());
22719 const char *ptr
= actual_name
.get ();
22721 /* Test for '::' as a sanity check. */
22722 if (actual_name_len
> die_name_len
+ 2
22723 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22724 name
= obstack_strndup (
22725 &objfile
->per_bfd
->storage_obstack
,
22726 ptr
, actual_name_len
- die_name_len
- 2);
22737 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22738 prefix part in such case. See
22739 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22741 static const char *
22742 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22744 struct attribute
*attr
;
22747 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22748 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22751 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22754 attr
= dw2_linkage_name_attr (die
, cu
);
22755 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22758 /* dwarf2_name had to be already called. */
22759 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22761 /* Strip the base name, keep any leading namespaces/classes. */
22762 base
= strrchr (DW_STRING (attr
), ':');
22763 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22766 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22767 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22769 &base
[-1] - DW_STRING (attr
));
22772 /* Return the name of the namespace/class that DIE is defined within,
22773 or "" if we can't tell. The caller should not xfree the result.
22775 For example, if we're within the method foo() in the following
22785 then determine_prefix on foo's die will return "N::C". */
22787 static const char *
22788 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22790 struct dwarf2_per_objfile
*dwarf2_per_objfile
22791 = cu
->per_cu
->dwarf2_per_objfile
;
22792 struct die_info
*parent
, *spec_die
;
22793 struct dwarf2_cu
*spec_cu
;
22794 struct type
*parent_type
;
22795 const char *retval
;
22797 if (cu
->language
!= language_cplus
22798 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22799 && cu
->language
!= language_rust
)
22802 retval
= anonymous_struct_prefix (die
, cu
);
22806 /* We have to be careful in the presence of DW_AT_specification.
22807 For example, with GCC 3.4, given the code
22811 // Definition of N::foo.
22815 then we'll have a tree of DIEs like this:
22817 1: DW_TAG_compile_unit
22818 2: DW_TAG_namespace // N
22819 3: DW_TAG_subprogram // declaration of N::foo
22820 4: DW_TAG_subprogram // definition of N::foo
22821 DW_AT_specification // refers to die #3
22823 Thus, when processing die #4, we have to pretend that we're in
22824 the context of its DW_AT_specification, namely the contex of die
22827 spec_die
= die_specification (die
, &spec_cu
);
22828 if (spec_die
== NULL
)
22829 parent
= die
->parent
;
22832 parent
= spec_die
->parent
;
22836 if (parent
== NULL
)
22838 else if (parent
->building_fullname
)
22841 const char *parent_name
;
22843 /* It has been seen on RealView 2.2 built binaries,
22844 DW_TAG_template_type_param types actually _defined_ as
22845 children of the parent class:
22848 template class <class Enum> Class{};
22849 Class<enum E> class_e;
22851 1: DW_TAG_class_type (Class)
22852 2: DW_TAG_enumeration_type (E)
22853 3: DW_TAG_enumerator (enum1:0)
22854 3: DW_TAG_enumerator (enum2:1)
22856 2: DW_TAG_template_type_param
22857 DW_AT_type DW_FORM_ref_udata (E)
22859 Besides being broken debug info, it can put GDB into an
22860 infinite loop. Consider:
22862 When we're building the full name for Class<E>, we'll start
22863 at Class, and go look over its template type parameters,
22864 finding E. We'll then try to build the full name of E, and
22865 reach here. We're now trying to build the full name of E,
22866 and look over the parent DIE for containing scope. In the
22867 broken case, if we followed the parent DIE of E, we'd again
22868 find Class, and once again go look at its template type
22869 arguments, etc., etc. Simply don't consider such parent die
22870 as source-level parent of this die (it can't be, the language
22871 doesn't allow it), and break the loop here. */
22872 name
= dwarf2_name (die
, cu
);
22873 parent_name
= dwarf2_name (parent
, cu
);
22874 complaint (_("template param type '%s' defined within parent '%s'"),
22875 name
? name
: "<unknown>",
22876 parent_name
? parent_name
: "<unknown>");
22880 switch (parent
->tag
)
22882 case DW_TAG_namespace
:
22883 parent_type
= read_type_die (parent
, cu
);
22884 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22885 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22886 Work around this problem here. */
22887 if (cu
->language
== language_cplus
22888 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22890 /* We give a name to even anonymous namespaces. */
22891 return TYPE_NAME (parent_type
);
22892 case DW_TAG_class_type
:
22893 case DW_TAG_interface_type
:
22894 case DW_TAG_structure_type
:
22895 case DW_TAG_union_type
:
22896 case DW_TAG_module
:
22897 parent_type
= read_type_die (parent
, cu
);
22898 if (TYPE_NAME (parent_type
) != NULL
)
22899 return TYPE_NAME (parent_type
);
22901 /* An anonymous structure is only allowed non-static data
22902 members; no typedefs, no member functions, et cetera.
22903 So it does not need a prefix. */
22905 case DW_TAG_compile_unit
:
22906 case DW_TAG_partial_unit
:
22907 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22908 if (cu
->language
== language_cplus
22909 && !dwarf2_per_objfile
->types
.empty ()
22910 && die
->child
!= NULL
22911 && (die
->tag
== DW_TAG_class_type
22912 || die
->tag
== DW_TAG_structure_type
22913 || die
->tag
== DW_TAG_union_type
))
22915 const char *name
= guess_full_die_structure_name (die
, cu
);
22920 case DW_TAG_subprogram
:
22921 /* Nested subroutines in Fortran get a prefix with the name
22922 of the parent's subroutine. */
22923 if (cu
->language
== language_fortran
)
22925 if ((die
->tag
== DW_TAG_subprogram
)
22926 && (dwarf2_name (parent
, cu
) != NULL
))
22927 return dwarf2_name (parent
, cu
);
22929 return determine_prefix (parent
, cu
);
22930 case DW_TAG_enumeration_type
:
22931 parent_type
= read_type_die (parent
, cu
);
22932 if (TYPE_DECLARED_CLASS (parent_type
))
22934 if (TYPE_NAME (parent_type
) != NULL
)
22935 return TYPE_NAME (parent_type
);
22938 /* Fall through. */
22940 return determine_prefix (parent
, cu
);
22944 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22945 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22946 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22947 an obconcat, otherwise allocate storage for the result. The CU argument is
22948 used to determine the language and hence, the appropriate separator. */
22950 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22953 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22954 int physname
, struct dwarf2_cu
*cu
)
22956 const char *lead
= "";
22959 if (suffix
== NULL
|| suffix
[0] == '\0'
22960 || prefix
== NULL
|| prefix
[0] == '\0')
22962 else if (cu
->language
== language_d
)
22964 /* For D, the 'main' function could be defined in any module, but it
22965 should never be prefixed. */
22966 if (strcmp (suffix
, "D main") == 0)
22974 else if (cu
->language
== language_fortran
&& physname
)
22976 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
22977 DW_AT_MIPS_linkage_name is preferred and used instead. */
22985 if (prefix
== NULL
)
22987 if (suffix
== NULL
)
22994 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
22996 strcpy (retval
, lead
);
22997 strcat (retval
, prefix
);
22998 strcat (retval
, sep
);
22999 strcat (retval
, suffix
);
23004 /* We have an obstack. */
23005 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23009 /* Return sibling of die, NULL if no sibling. */
23011 static struct die_info
*
23012 sibling_die (struct die_info
*die
)
23014 return die
->sibling
;
23017 /* Get name of a die, return NULL if not found. */
23019 static const char *
23020 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23021 struct obstack
*obstack
)
23023 if (name
&& cu
->language
== language_cplus
)
23025 std::string canon_name
= cp_canonicalize_string (name
);
23027 if (!canon_name
.empty ())
23029 if (canon_name
!= name
)
23030 name
= obstack_strdup (obstack
, canon_name
);
23037 /* Get name of a die, return NULL if not found.
23038 Anonymous namespaces are converted to their magic string. */
23040 static const char *
23041 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23043 struct attribute
*attr
;
23044 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23046 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23047 if ((!attr
|| !DW_STRING (attr
))
23048 && die
->tag
!= DW_TAG_namespace
23049 && die
->tag
!= DW_TAG_class_type
23050 && die
->tag
!= DW_TAG_interface_type
23051 && die
->tag
!= DW_TAG_structure_type
23052 && die
->tag
!= DW_TAG_union_type
)
23057 case DW_TAG_compile_unit
:
23058 case DW_TAG_partial_unit
:
23059 /* Compilation units have a DW_AT_name that is a filename, not
23060 a source language identifier. */
23061 case DW_TAG_enumeration_type
:
23062 case DW_TAG_enumerator
:
23063 /* These tags always have simple identifiers already; no need
23064 to canonicalize them. */
23065 return DW_STRING (attr
);
23067 case DW_TAG_namespace
:
23068 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23069 return DW_STRING (attr
);
23070 return CP_ANONYMOUS_NAMESPACE_STR
;
23072 case DW_TAG_class_type
:
23073 case DW_TAG_interface_type
:
23074 case DW_TAG_structure_type
:
23075 case DW_TAG_union_type
:
23076 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23077 structures or unions. These were of the form "._%d" in GCC 4.1,
23078 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23079 and GCC 4.4. We work around this problem by ignoring these. */
23080 if (attr
&& DW_STRING (attr
)
23081 && (startswith (DW_STRING (attr
), "._")
23082 || startswith (DW_STRING (attr
), "<anonymous")))
23085 /* GCC might emit a nameless typedef that has a linkage name. See
23086 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23087 if (!attr
|| DW_STRING (attr
) == NULL
)
23089 attr
= dw2_linkage_name_attr (die
, cu
);
23090 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23093 /* Avoid demangling DW_STRING (attr) the second time on a second
23094 call for the same DIE. */
23095 if (!DW_STRING_IS_CANONICAL (attr
))
23097 gdb::unique_xmalloc_ptr
<char> demangled
23098 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23102 /* FIXME: we already did this for the partial symbol... */
23104 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23106 DW_STRING_IS_CANONICAL (attr
) = 1;
23108 /* Strip any leading namespaces/classes, keep only the base name.
23109 DW_AT_name for named DIEs does not contain the prefixes. */
23110 base
= strrchr (DW_STRING (attr
), ':');
23111 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23114 return DW_STRING (attr
);
23123 if (!DW_STRING_IS_CANONICAL (attr
))
23126 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23127 &objfile
->per_bfd
->storage_obstack
);
23128 DW_STRING_IS_CANONICAL (attr
) = 1;
23130 return DW_STRING (attr
);
23133 /* Return the die that this die in an extension of, or NULL if there
23134 is none. *EXT_CU is the CU containing DIE on input, and the CU
23135 containing the return value on output. */
23137 static struct die_info
*
23138 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23140 struct attribute
*attr
;
23142 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23146 return follow_die_ref (die
, attr
, ext_cu
);
23149 /* A convenience function that returns an "unknown" DWARF name,
23150 including the value of V. STR is the name of the entity being
23151 printed, e.g., "TAG". */
23153 static const char *
23154 dwarf_unknown (const char *str
, unsigned v
)
23156 char *cell
= get_print_cell ();
23157 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23161 /* Convert a DIE tag into its string name. */
23163 static const char *
23164 dwarf_tag_name (unsigned tag
)
23166 const char *name
= get_DW_TAG_name (tag
);
23169 return dwarf_unknown ("TAG", tag
);
23174 /* Convert a DWARF attribute code into its string name. */
23176 static const char *
23177 dwarf_attr_name (unsigned attr
)
23181 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23182 if (attr
== DW_AT_MIPS_fde
)
23183 return "DW_AT_MIPS_fde";
23185 if (attr
== DW_AT_HP_block_index
)
23186 return "DW_AT_HP_block_index";
23189 name
= get_DW_AT_name (attr
);
23192 return dwarf_unknown ("AT", attr
);
23197 /* Convert a unit type to corresponding DW_UT name. */
23199 static const char *
23200 dwarf_unit_type_name (int unit_type
) {
23204 return "DW_UT_compile (0x01)";
23206 return "DW_UT_type (0x02)";
23208 return "DW_UT_partial (0x03)";
23210 return "DW_UT_skeleton (0x04)";
23212 return "DW_UT_split_compile (0x05)";
23214 return "DW_UT_split_type (0x06)";
23216 return "DW_UT_lo_user (0x80)";
23218 return "DW_UT_hi_user (0xff)";
23224 /* Convert a DWARF value form code into its string name. */
23226 static const char *
23227 dwarf_form_name (unsigned form
)
23229 const char *name
= get_DW_FORM_name (form
);
23232 return dwarf_unknown ("FORM", form
);
23237 static const char *
23238 dwarf_bool_name (unsigned mybool
)
23246 /* Convert a DWARF type code into its string name. */
23248 static const char *
23249 dwarf_type_encoding_name (unsigned enc
)
23251 const char *name
= get_DW_ATE_name (enc
);
23254 return dwarf_unknown ("ATE", enc
);
23260 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23264 print_spaces (indent
, f
);
23265 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23266 dwarf_tag_name (die
->tag
), die
->abbrev
,
23267 sect_offset_str (die
->sect_off
));
23269 if (die
->parent
!= NULL
)
23271 print_spaces (indent
, f
);
23272 fprintf_unfiltered (f
, " parent at offset: %s\n",
23273 sect_offset_str (die
->parent
->sect_off
));
23276 print_spaces (indent
, f
);
23277 fprintf_unfiltered (f
, " has children: %s\n",
23278 dwarf_bool_name (die
->child
!= NULL
));
23280 print_spaces (indent
, f
);
23281 fprintf_unfiltered (f
, " attributes:\n");
23283 for (i
= 0; i
< die
->num_attrs
; ++i
)
23285 print_spaces (indent
, f
);
23286 fprintf_unfiltered (f
, " %s (%s) ",
23287 dwarf_attr_name (die
->attrs
[i
].name
),
23288 dwarf_form_name (die
->attrs
[i
].form
));
23290 switch (die
->attrs
[i
].form
)
23293 case DW_FORM_addrx
:
23294 case DW_FORM_GNU_addr_index
:
23295 fprintf_unfiltered (f
, "address: ");
23296 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23298 case DW_FORM_block2
:
23299 case DW_FORM_block4
:
23300 case DW_FORM_block
:
23301 case DW_FORM_block1
:
23302 fprintf_unfiltered (f
, "block: size %s",
23303 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23305 case DW_FORM_exprloc
:
23306 fprintf_unfiltered (f
, "expression: size %s",
23307 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23309 case DW_FORM_data16
:
23310 fprintf_unfiltered (f
, "constant of 16 bytes");
23312 case DW_FORM_ref_addr
:
23313 fprintf_unfiltered (f
, "ref address: ");
23314 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23316 case DW_FORM_GNU_ref_alt
:
23317 fprintf_unfiltered (f
, "alt ref address: ");
23318 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23324 case DW_FORM_ref_udata
:
23325 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23326 (long) (DW_UNSND (&die
->attrs
[i
])));
23328 case DW_FORM_data1
:
23329 case DW_FORM_data2
:
23330 case DW_FORM_data4
:
23331 case DW_FORM_data8
:
23332 case DW_FORM_udata
:
23333 case DW_FORM_sdata
:
23334 fprintf_unfiltered (f
, "constant: %s",
23335 pulongest (DW_UNSND (&die
->attrs
[i
])));
23337 case DW_FORM_sec_offset
:
23338 fprintf_unfiltered (f
, "section offset: %s",
23339 pulongest (DW_UNSND (&die
->attrs
[i
])));
23341 case DW_FORM_ref_sig8
:
23342 fprintf_unfiltered (f
, "signature: %s",
23343 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23345 case DW_FORM_string
:
23347 case DW_FORM_line_strp
:
23349 case DW_FORM_GNU_str_index
:
23350 case DW_FORM_GNU_strp_alt
:
23351 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23352 DW_STRING (&die
->attrs
[i
])
23353 ? DW_STRING (&die
->attrs
[i
]) : "",
23354 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23357 if (DW_UNSND (&die
->attrs
[i
]))
23358 fprintf_unfiltered (f
, "flag: TRUE");
23360 fprintf_unfiltered (f
, "flag: FALSE");
23362 case DW_FORM_flag_present
:
23363 fprintf_unfiltered (f
, "flag: TRUE");
23365 case DW_FORM_indirect
:
23366 /* The reader will have reduced the indirect form to
23367 the "base form" so this form should not occur. */
23368 fprintf_unfiltered (f
,
23369 "unexpected attribute form: DW_FORM_indirect");
23371 case DW_FORM_implicit_const
:
23372 fprintf_unfiltered (f
, "constant: %s",
23373 plongest (DW_SND (&die
->attrs
[i
])));
23376 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23377 die
->attrs
[i
].form
);
23380 fprintf_unfiltered (f
, "\n");
23385 dump_die_for_error (struct die_info
*die
)
23387 dump_die_shallow (gdb_stderr
, 0, die
);
23391 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23393 int indent
= level
* 4;
23395 gdb_assert (die
!= NULL
);
23397 if (level
>= max_level
)
23400 dump_die_shallow (f
, indent
, die
);
23402 if (die
->child
!= NULL
)
23404 print_spaces (indent
, f
);
23405 fprintf_unfiltered (f
, " Children:");
23406 if (level
+ 1 < max_level
)
23408 fprintf_unfiltered (f
, "\n");
23409 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23413 fprintf_unfiltered (f
,
23414 " [not printed, max nesting level reached]\n");
23418 if (die
->sibling
!= NULL
&& level
> 0)
23420 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23424 /* This is called from the pdie macro in gdbinit.in.
23425 It's not static so gcc will keep a copy callable from gdb. */
23428 dump_die (struct die_info
*die
, int max_level
)
23430 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23434 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23438 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23439 to_underlying (die
->sect_off
),
23445 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23449 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23451 if (attr_form_is_ref (attr
))
23452 return (sect_offset
) DW_UNSND (attr
);
23454 complaint (_("unsupported die ref attribute form: '%s'"),
23455 dwarf_form_name (attr
->form
));
23459 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23460 * the value held by the attribute is not constant. */
23463 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23465 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23466 return DW_SND (attr
);
23467 else if (attr
->form
== DW_FORM_udata
23468 || attr
->form
== DW_FORM_data1
23469 || attr
->form
== DW_FORM_data2
23470 || attr
->form
== DW_FORM_data4
23471 || attr
->form
== DW_FORM_data8
)
23472 return DW_UNSND (attr
);
23475 /* For DW_FORM_data16 see attr_form_is_constant. */
23476 complaint (_("Attribute value is not a constant (%s)"),
23477 dwarf_form_name (attr
->form
));
23478 return default_value
;
23482 /* Follow reference or signature attribute ATTR of SRC_DIE.
23483 On entry *REF_CU is the CU of SRC_DIE.
23484 On exit *REF_CU is the CU of the result. */
23486 static struct die_info
*
23487 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23488 struct dwarf2_cu
**ref_cu
)
23490 struct die_info
*die
;
23492 if (attr_form_is_ref (attr
))
23493 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23494 else if (attr
->form
== DW_FORM_ref_sig8
)
23495 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23498 dump_die_for_error (src_die
);
23499 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23500 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23506 /* Follow reference OFFSET.
23507 On entry *REF_CU is the CU of the source die referencing OFFSET.
23508 On exit *REF_CU is the CU of the result.
23509 Returns NULL if OFFSET is invalid. */
23511 static struct die_info
*
23512 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23513 struct dwarf2_cu
**ref_cu
)
23515 struct die_info temp_die
;
23516 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23517 struct dwarf2_per_objfile
*dwarf2_per_objfile
23518 = cu
->per_cu
->dwarf2_per_objfile
;
23520 gdb_assert (cu
->per_cu
!= NULL
);
23524 if (cu
->per_cu
->is_debug_types
)
23526 /* .debug_types CUs cannot reference anything outside their CU.
23527 If they need to, they have to reference a signatured type via
23528 DW_FORM_ref_sig8. */
23529 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23532 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23533 || !offset_in_cu_p (&cu
->header
, sect_off
))
23535 struct dwarf2_per_cu_data
*per_cu
;
23537 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23538 dwarf2_per_objfile
);
23540 /* If necessary, add it to the queue and load its DIEs. */
23541 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23542 load_full_comp_unit (per_cu
, false, cu
->language
);
23544 target_cu
= per_cu
->cu
;
23546 else if (cu
->dies
== NULL
)
23548 /* We're loading full DIEs during partial symbol reading. */
23549 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23550 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23553 *ref_cu
= target_cu
;
23554 temp_die
.sect_off
= sect_off
;
23556 if (target_cu
!= cu
)
23557 target_cu
->ancestor
= cu
;
23559 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23561 to_underlying (sect_off
));
23564 /* Follow reference attribute ATTR of SRC_DIE.
23565 On entry *REF_CU is the CU of SRC_DIE.
23566 On exit *REF_CU is the CU of the result. */
23568 static struct die_info
*
23569 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23570 struct dwarf2_cu
**ref_cu
)
23572 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23573 struct dwarf2_cu
*cu
= *ref_cu
;
23574 struct die_info
*die
;
23576 die
= follow_die_offset (sect_off
,
23577 (attr
->form
== DW_FORM_GNU_ref_alt
23578 || cu
->per_cu
->is_dwz
),
23581 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23582 "at %s [in module %s]"),
23583 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23584 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23589 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23590 Returned value is intended for DW_OP_call*. Returned
23591 dwarf2_locexpr_baton->data has lifetime of
23592 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23594 struct dwarf2_locexpr_baton
23595 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23596 struct dwarf2_per_cu_data
*per_cu
,
23597 CORE_ADDR (*get_frame_pc
) (void *baton
),
23598 void *baton
, bool resolve_abstract_p
)
23600 struct dwarf2_cu
*cu
;
23601 struct die_info
*die
;
23602 struct attribute
*attr
;
23603 struct dwarf2_locexpr_baton retval
;
23604 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23605 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23607 if (per_cu
->cu
== NULL
)
23608 load_cu (per_cu
, false);
23612 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23613 Instead just throw an error, not much else we can do. */
23614 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23615 sect_offset_str (sect_off
), objfile_name (objfile
));
23618 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23620 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23621 sect_offset_str (sect_off
), objfile_name (objfile
));
23623 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23624 if (!attr
&& resolve_abstract_p
23625 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23626 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23628 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23629 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23630 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23632 for (const auto &cand_off
23633 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23635 struct dwarf2_cu
*cand_cu
= cu
;
23636 struct die_info
*cand
23637 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23640 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23643 CORE_ADDR pc_low
, pc_high
;
23644 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23645 if (pc_low
== ((CORE_ADDR
) -1))
23647 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23648 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23649 if (!(pc_low
<= pc
&& pc
< pc_high
))
23653 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23660 /* DWARF: "If there is no such attribute, then there is no effect.".
23661 DATA is ignored if SIZE is 0. */
23663 retval
.data
= NULL
;
23666 else if (attr_form_is_section_offset (attr
))
23668 struct dwarf2_loclist_baton loclist_baton
;
23669 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23672 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23674 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23676 retval
.size
= size
;
23680 if (!attr_form_is_block (attr
))
23681 error (_("Dwarf Error: DIE at %s referenced in module %s "
23682 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23683 sect_offset_str (sect_off
), objfile_name (objfile
));
23685 retval
.data
= DW_BLOCK (attr
)->data
;
23686 retval
.size
= DW_BLOCK (attr
)->size
;
23688 retval
.per_cu
= cu
->per_cu
;
23690 age_cached_comp_units (dwarf2_per_objfile
);
23695 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23698 struct dwarf2_locexpr_baton
23699 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23700 struct dwarf2_per_cu_data
*per_cu
,
23701 CORE_ADDR (*get_frame_pc
) (void *baton
),
23704 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23706 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23709 /* Write a constant of a given type as target-ordered bytes into
23712 static const gdb_byte
*
23713 write_constant_as_bytes (struct obstack
*obstack
,
23714 enum bfd_endian byte_order
,
23721 *len
= TYPE_LENGTH (type
);
23722 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23723 store_unsigned_integer (result
, *len
, byte_order
, value
);
23728 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23729 pointer to the constant bytes and set LEN to the length of the
23730 data. If memory is needed, allocate it on OBSTACK. If the DIE
23731 does not have a DW_AT_const_value, return NULL. */
23734 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23735 struct dwarf2_per_cu_data
*per_cu
,
23736 struct obstack
*obstack
,
23739 struct dwarf2_cu
*cu
;
23740 struct die_info
*die
;
23741 struct attribute
*attr
;
23742 const gdb_byte
*result
= NULL
;
23745 enum bfd_endian byte_order
;
23746 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23748 if (per_cu
->cu
== NULL
)
23749 load_cu (per_cu
, false);
23753 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23754 Instead just throw an error, not much else we can do. */
23755 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23756 sect_offset_str (sect_off
), objfile_name (objfile
));
23759 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23761 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23762 sect_offset_str (sect_off
), objfile_name (objfile
));
23764 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23768 byte_order
= (bfd_big_endian (objfile
->obfd
)
23769 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23771 switch (attr
->form
)
23774 case DW_FORM_addrx
:
23775 case DW_FORM_GNU_addr_index
:
23779 *len
= cu
->header
.addr_size
;
23780 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23781 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23785 case DW_FORM_string
:
23788 case DW_FORM_GNU_str_index
:
23789 case DW_FORM_GNU_strp_alt
:
23790 /* DW_STRING is already allocated on the objfile obstack, point
23792 result
= (const gdb_byte
*) DW_STRING (attr
);
23793 *len
= strlen (DW_STRING (attr
));
23795 case DW_FORM_block1
:
23796 case DW_FORM_block2
:
23797 case DW_FORM_block4
:
23798 case DW_FORM_block
:
23799 case DW_FORM_exprloc
:
23800 case DW_FORM_data16
:
23801 result
= DW_BLOCK (attr
)->data
;
23802 *len
= DW_BLOCK (attr
)->size
;
23805 /* The DW_AT_const_value attributes are supposed to carry the
23806 symbol's value "represented as it would be on the target
23807 architecture." By the time we get here, it's already been
23808 converted to host endianness, so we just need to sign- or
23809 zero-extend it as appropriate. */
23810 case DW_FORM_data1
:
23811 type
= die_type (die
, cu
);
23812 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23813 if (result
== NULL
)
23814 result
= write_constant_as_bytes (obstack
, byte_order
,
23817 case DW_FORM_data2
:
23818 type
= die_type (die
, cu
);
23819 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23820 if (result
== NULL
)
23821 result
= write_constant_as_bytes (obstack
, byte_order
,
23824 case DW_FORM_data4
:
23825 type
= die_type (die
, cu
);
23826 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23827 if (result
== NULL
)
23828 result
= write_constant_as_bytes (obstack
, byte_order
,
23831 case DW_FORM_data8
:
23832 type
= die_type (die
, cu
);
23833 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23834 if (result
== NULL
)
23835 result
= write_constant_as_bytes (obstack
, byte_order
,
23839 case DW_FORM_sdata
:
23840 case DW_FORM_implicit_const
:
23841 type
= die_type (die
, cu
);
23842 result
= write_constant_as_bytes (obstack
, byte_order
,
23843 type
, DW_SND (attr
), len
);
23846 case DW_FORM_udata
:
23847 type
= die_type (die
, cu
);
23848 result
= write_constant_as_bytes (obstack
, byte_order
,
23849 type
, DW_UNSND (attr
), len
);
23853 complaint (_("unsupported const value attribute form: '%s'"),
23854 dwarf_form_name (attr
->form
));
23861 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23862 valid type for this die is found. */
23865 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23866 struct dwarf2_per_cu_data
*per_cu
)
23868 struct dwarf2_cu
*cu
;
23869 struct die_info
*die
;
23871 if (per_cu
->cu
== NULL
)
23872 load_cu (per_cu
, false);
23877 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23881 return die_type (die
, cu
);
23884 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23888 dwarf2_get_die_type (cu_offset die_offset
,
23889 struct dwarf2_per_cu_data
*per_cu
)
23891 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23892 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23895 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23896 On entry *REF_CU is the CU of SRC_DIE.
23897 On exit *REF_CU is the CU of the result.
23898 Returns NULL if the referenced DIE isn't found. */
23900 static struct die_info
*
23901 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23902 struct dwarf2_cu
**ref_cu
)
23904 struct die_info temp_die
;
23905 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23906 struct die_info
*die
;
23908 /* While it might be nice to assert sig_type->type == NULL here,
23909 we can get here for DW_AT_imported_declaration where we need
23910 the DIE not the type. */
23912 /* If necessary, add it to the queue and load its DIEs. */
23914 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23915 read_signatured_type (sig_type
);
23917 sig_cu
= sig_type
->per_cu
.cu
;
23918 gdb_assert (sig_cu
!= NULL
);
23919 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23920 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23921 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23922 to_underlying (temp_die
.sect_off
));
23925 struct dwarf2_per_objfile
*dwarf2_per_objfile
23926 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23928 /* For .gdb_index version 7 keep track of included TUs.
23929 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23930 if (dwarf2_per_objfile
->index_table
!= NULL
23931 && dwarf2_per_objfile
->index_table
->version
<= 7)
23933 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23938 sig_cu
->ancestor
= cu
;
23946 /* Follow signatured type referenced by ATTR in SRC_DIE.
23947 On entry *REF_CU is the CU of SRC_DIE.
23948 On exit *REF_CU is the CU of the result.
23949 The result is the DIE of the type.
23950 If the referenced type cannot be found an error is thrown. */
23952 static struct die_info
*
23953 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23954 struct dwarf2_cu
**ref_cu
)
23956 ULONGEST signature
= DW_SIGNATURE (attr
);
23957 struct signatured_type
*sig_type
;
23958 struct die_info
*die
;
23960 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23962 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23963 /* sig_type will be NULL if the signatured type is missing from
23965 if (sig_type
== NULL
)
23967 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23968 " from DIE at %s [in module %s]"),
23969 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23970 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23973 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
23976 dump_die_for_error (src_die
);
23977 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
23978 " from DIE at %s [in module %s]"),
23979 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23980 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23986 /* Get the type specified by SIGNATURE referenced in DIE/CU,
23987 reading in and processing the type unit if necessary. */
23989 static struct type
*
23990 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
23991 struct dwarf2_cu
*cu
)
23993 struct dwarf2_per_objfile
*dwarf2_per_objfile
23994 = cu
->per_cu
->dwarf2_per_objfile
;
23995 struct signatured_type
*sig_type
;
23996 struct dwarf2_cu
*type_cu
;
23997 struct die_info
*type_die
;
24000 sig_type
= lookup_signatured_type (cu
, signature
);
24001 /* sig_type will be NULL if the signatured type is missing from
24003 if (sig_type
== NULL
)
24005 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24006 " from DIE at %s [in module %s]"),
24007 hex_string (signature
), sect_offset_str (die
->sect_off
),
24008 objfile_name (dwarf2_per_objfile
->objfile
));
24009 return build_error_marker_type (cu
, die
);
24012 /* If we already know the type we're done. */
24013 if (sig_type
->type
!= NULL
)
24014 return sig_type
->type
;
24017 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24018 if (type_die
!= NULL
)
24020 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24021 is created. This is important, for example, because for c++ classes
24022 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24023 type
= read_type_die (type_die
, type_cu
);
24026 complaint (_("Dwarf Error: Cannot build signatured type %s"
24027 " referenced from DIE at %s [in module %s]"),
24028 hex_string (signature
), sect_offset_str (die
->sect_off
),
24029 objfile_name (dwarf2_per_objfile
->objfile
));
24030 type
= build_error_marker_type (cu
, die
);
24035 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24036 " from DIE at %s [in module %s]"),
24037 hex_string (signature
), sect_offset_str (die
->sect_off
),
24038 objfile_name (dwarf2_per_objfile
->objfile
));
24039 type
= build_error_marker_type (cu
, die
);
24041 sig_type
->type
= type
;
24046 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24047 reading in and processing the type unit if necessary. */
24049 static struct type
*
24050 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24051 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24053 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24054 if (attr_form_is_ref (attr
))
24056 struct dwarf2_cu
*type_cu
= cu
;
24057 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24059 return read_type_die (type_die
, type_cu
);
24061 else if (attr
->form
== DW_FORM_ref_sig8
)
24063 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24067 struct dwarf2_per_objfile
*dwarf2_per_objfile
24068 = cu
->per_cu
->dwarf2_per_objfile
;
24070 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24071 " at %s [in module %s]"),
24072 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24073 objfile_name (dwarf2_per_objfile
->objfile
));
24074 return build_error_marker_type (cu
, die
);
24078 /* Load the DIEs associated with type unit PER_CU into memory. */
24081 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24083 struct signatured_type
*sig_type
;
24085 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24086 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24088 /* We have the per_cu, but we need the signatured_type.
24089 Fortunately this is an easy translation. */
24090 gdb_assert (per_cu
->is_debug_types
);
24091 sig_type
= (struct signatured_type
*) per_cu
;
24093 gdb_assert (per_cu
->cu
== NULL
);
24095 read_signatured_type (sig_type
);
24097 gdb_assert (per_cu
->cu
!= NULL
);
24100 /* Read in a signatured type and build its CU and DIEs.
24101 If the type is a stub for the real type in a DWO file,
24102 read in the real type from the DWO file as well. */
24105 read_signatured_type (struct signatured_type
*sig_type
)
24107 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24109 gdb_assert (per_cu
->is_debug_types
);
24110 gdb_assert (per_cu
->cu
== NULL
);
24112 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
24114 if (!reader
.dummy_p
)
24116 struct dwarf2_cu
*cu
= reader
.cu
;
24117 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24119 gdb_assert (cu
->die_hash
== NULL
);
24121 htab_create_alloc_ex (cu
->header
.length
/ 12,
24125 &cu
->comp_unit_obstack
,
24126 hashtab_obstack_allocate
,
24127 dummy_obstack_deallocate
);
24129 if (reader
.has_children
)
24130 reader
.comp_unit_die
->child
24131 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24132 reader
.comp_unit_die
);
24133 cu
->dies
= reader
.comp_unit_die
;
24134 /* comp_unit_die is not stored in die_hash, no need. */
24136 /* We try not to read any attributes in this function, because
24137 not all CUs needed for references have been loaded yet, and
24138 symbol table processing isn't initialized. But we have to
24139 set the CU language, or we won't be able to build types
24140 correctly. Similarly, if we do not read the producer, we can
24141 not apply producer-specific interpretation. */
24142 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24145 sig_type
->per_cu
.tu_read
= 1;
24148 /* Decode simple location descriptions.
24149 Given a pointer to a dwarf block that defines a location, compute
24150 the location and return the value.
24152 NOTE drow/2003-11-18: This function is called in two situations
24153 now: for the address of static or global variables (partial symbols
24154 only) and for offsets into structures which are expected to be
24155 (more or less) constant. The partial symbol case should go away,
24156 and only the constant case should remain. That will let this
24157 function complain more accurately. A few special modes are allowed
24158 without complaint for global variables (for instance, global
24159 register values and thread-local values).
24161 A location description containing no operations indicates that the
24162 object is optimized out. The return value is 0 for that case.
24163 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24164 callers will only want a very basic result and this can become a
24167 Note that stack[0] is unused except as a default error return. */
24170 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24172 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24174 size_t size
= blk
->size
;
24175 const gdb_byte
*data
= blk
->data
;
24176 CORE_ADDR stack
[64];
24178 unsigned int bytes_read
, unsnd
;
24184 stack
[++stacki
] = 0;
24223 stack
[++stacki
] = op
- DW_OP_lit0
;
24258 stack
[++stacki
] = op
- DW_OP_reg0
;
24260 dwarf2_complex_location_expr_complaint ();
24264 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24266 stack
[++stacki
] = unsnd
;
24268 dwarf2_complex_location_expr_complaint ();
24272 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24277 case DW_OP_const1u
:
24278 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24282 case DW_OP_const1s
:
24283 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24287 case DW_OP_const2u
:
24288 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24292 case DW_OP_const2s
:
24293 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24297 case DW_OP_const4u
:
24298 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24302 case DW_OP_const4s
:
24303 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24307 case DW_OP_const8u
:
24308 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24313 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24319 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24324 stack
[stacki
+ 1] = stack
[stacki
];
24329 stack
[stacki
- 1] += stack
[stacki
];
24333 case DW_OP_plus_uconst
:
24334 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24340 stack
[stacki
- 1] -= stack
[stacki
];
24345 /* If we're not the last op, then we definitely can't encode
24346 this using GDB's address_class enum. This is valid for partial
24347 global symbols, although the variable's address will be bogus
24350 dwarf2_complex_location_expr_complaint ();
24353 case DW_OP_GNU_push_tls_address
:
24354 case DW_OP_form_tls_address
:
24355 /* The top of the stack has the offset from the beginning
24356 of the thread control block at which the variable is located. */
24357 /* Nothing should follow this operator, so the top of stack would
24359 /* This is valid for partial global symbols, but the variable's
24360 address will be bogus in the psymtab. Make it always at least
24361 non-zero to not look as a variable garbage collected by linker
24362 which have DW_OP_addr 0. */
24364 dwarf2_complex_location_expr_complaint ();
24368 case DW_OP_GNU_uninit
:
24372 case DW_OP_GNU_addr_index
:
24373 case DW_OP_GNU_const_index
:
24374 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24381 const char *name
= get_DW_OP_name (op
);
24384 complaint (_("unsupported stack op: '%s'"),
24387 complaint (_("unsupported stack op: '%02x'"),
24391 return (stack
[stacki
]);
24394 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24395 outside of the allocated space. Also enforce minimum>0. */
24396 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24398 complaint (_("location description stack overflow"));
24404 complaint (_("location description stack underflow"));
24408 return (stack
[stacki
]);
24411 /* memory allocation interface */
24413 static struct dwarf_block
*
24414 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24416 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24419 static struct die_info
*
24420 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24422 struct die_info
*die
;
24423 size_t size
= sizeof (struct die_info
);
24426 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24428 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24429 memset (die
, 0, sizeof (struct die_info
));
24434 /* Macro support. */
24436 /* Return file name relative to the compilation directory of file number I in
24437 *LH's file name table. The result is allocated using xmalloc; the caller is
24438 responsible for freeing it. */
24441 file_file_name (int file
, struct line_header
*lh
)
24443 /* Is the file number a valid index into the line header's file name
24444 table? Remember that file numbers start with one, not zero. */
24445 if (lh
->is_valid_file_index (file
))
24447 const file_entry
*fe
= lh
->file_name_at (file
);
24449 if (!IS_ABSOLUTE_PATH (fe
->name
))
24451 const char *dir
= fe
->include_dir (lh
);
24453 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24455 return xstrdup (fe
->name
);
24459 /* The compiler produced a bogus file number. We can at least
24460 record the macro definitions made in the file, even if we
24461 won't be able to find the file by name. */
24462 char fake_name
[80];
24464 xsnprintf (fake_name
, sizeof (fake_name
),
24465 "<bad macro file number %d>", file
);
24467 complaint (_("bad file number in macro information (%d)"),
24470 return xstrdup (fake_name
);
24474 /* Return the full name of file number I in *LH's file name table.
24475 Use COMP_DIR as the name of the current directory of the
24476 compilation. The result is allocated using xmalloc; the caller is
24477 responsible for freeing it. */
24479 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24481 /* Is the file number a valid index into the line header's file name
24482 table? Remember that file numbers start with one, not zero. */
24483 if (lh
->is_valid_file_index (file
))
24485 char *relative
= file_file_name (file
, lh
);
24487 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24489 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24490 relative
, (char *) NULL
);
24493 return file_file_name (file
, lh
);
24497 static struct macro_source_file
*
24498 macro_start_file (struct dwarf2_cu
*cu
,
24499 int file
, int line
,
24500 struct macro_source_file
*current_file
,
24501 struct line_header
*lh
)
24503 /* File name relative to the compilation directory of this source file. */
24504 char *file_name
= file_file_name (file
, lh
);
24506 if (! current_file
)
24508 /* Note: We don't create a macro table for this compilation unit
24509 at all until we actually get a filename. */
24510 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24512 /* If we have no current file, then this must be the start_file
24513 directive for the compilation unit's main source file. */
24514 current_file
= macro_set_main (macro_table
, file_name
);
24515 macro_define_special (macro_table
);
24518 current_file
= macro_include (current_file
, line
, file_name
);
24522 return current_file
;
24525 static const char *
24526 consume_improper_spaces (const char *p
, const char *body
)
24530 complaint (_("macro definition contains spaces "
24531 "in formal argument list:\n`%s'"),
24543 parse_macro_definition (struct macro_source_file
*file
, int line
,
24548 /* The body string takes one of two forms. For object-like macro
24549 definitions, it should be:
24551 <macro name> " " <definition>
24553 For function-like macro definitions, it should be:
24555 <macro name> "() " <definition>
24557 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24559 Spaces may appear only where explicitly indicated, and in the
24562 The Dwarf 2 spec says that an object-like macro's name is always
24563 followed by a space, but versions of GCC around March 2002 omit
24564 the space when the macro's definition is the empty string.
24566 The Dwarf 2 spec says that there should be no spaces between the
24567 formal arguments in a function-like macro's formal argument list,
24568 but versions of GCC around March 2002 include spaces after the
24572 /* Find the extent of the macro name. The macro name is terminated
24573 by either a space or null character (for an object-like macro) or
24574 an opening paren (for a function-like macro). */
24575 for (p
= body
; *p
; p
++)
24576 if (*p
== ' ' || *p
== '(')
24579 if (*p
== ' ' || *p
== '\0')
24581 /* It's an object-like macro. */
24582 int name_len
= p
- body
;
24583 std::string
name (body
, name_len
);
24584 const char *replacement
;
24587 replacement
= body
+ name_len
+ 1;
24590 dwarf2_macro_malformed_definition_complaint (body
);
24591 replacement
= body
+ name_len
;
24594 macro_define_object (file
, line
, name
.c_str (), replacement
);
24596 else if (*p
== '(')
24598 /* It's a function-like macro. */
24599 std::string
name (body
, p
- body
);
24602 char **argv
= XNEWVEC (char *, argv_size
);
24606 p
= consume_improper_spaces (p
, body
);
24608 /* Parse the formal argument list. */
24609 while (*p
&& *p
!= ')')
24611 /* Find the extent of the current argument name. */
24612 const char *arg_start
= p
;
24614 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24617 if (! *p
|| p
== arg_start
)
24618 dwarf2_macro_malformed_definition_complaint (body
);
24621 /* Make sure argv has room for the new argument. */
24622 if (argc
>= argv_size
)
24625 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24628 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24631 p
= consume_improper_spaces (p
, body
);
24633 /* Consume the comma, if present. */
24638 p
= consume_improper_spaces (p
, body
);
24647 /* Perfectly formed definition, no complaints. */
24648 macro_define_function (file
, line
, name
.c_str (),
24649 argc
, (const char **) argv
,
24651 else if (*p
== '\0')
24653 /* Complain, but do define it. */
24654 dwarf2_macro_malformed_definition_complaint (body
);
24655 macro_define_function (file
, line
, name
.c_str (),
24656 argc
, (const char **) argv
,
24660 /* Just complain. */
24661 dwarf2_macro_malformed_definition_complaint (body
);
24664 /* Just complain. */
24665 dwarf2_macro_malformed_definition_complaint (body
);
24670 for (i
= 0; i
< argc
; i
++)
24676 dwarf2_macro_malformed_definition_complaint (body
);
24679 /* Skip some bytes from BYTES according to the form given in FORM.
24680 Returns the new pointer. */
24682 static const gdb_byte
*
24683 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24684 enum dwarf_form form
,
24685 unsigned int offset_size
,
24686 struct dwarf2_section_info
*section
)
24688 unsigned int bytes_read
;
24692 case DW_FORM_data1
:
24697 case DW_FORM_data2
:
24701 case DW_FORM_data4
:
24705 case DW_FORM_data8
:
24709 case DW_FORM_data16
:
24713 case DW_FORM_string
:
24714 read_direct_string (abfd
, bytes
, &bytes_read
);
24715 bytes
+= bytes_read
;
24718 case DW_FORM_sec_offset
:
24720 case DW_FORM_GNU_strp_alt
:
24721 bytes
+= offset_size
;
24724 case DW_FORM_block
:
24725 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24726 bytes
+= bytes_read
;
24729 case DW_FORM_block1
:
24730 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24732 case DW_FORM_block2
:
24733 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24735 case DW_FORM_block4
:
24736 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24739 case DW_FORM_addrx
:
24740 case DW_FORM_sdata
:
24742 case DW_FORM_udata
:
24743 case DW_FORM_GNU_addr_index
:
24744 case DW_FORM_GNU_str_index
:
24745 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24748 dwarf2_section_buffer_overflow_complaint (section
);
24753 case DW_FORM_implicit_const
:
24758 complaint (_("invalid form 0x%x in `%s'"),
24759 form
, get_section_name (section
));
24767 /* A helper for dwarf_decode_macros that handles skipping an unknown
24768 opcode. Returns an updated pointer to the macro data buffer; or,
24769 on error, issues a complaint and returns NULL. */
24771 static const gdb_byte
*
24772 skip_unknown_opcode (unsigned int opcode
,
24773 const gdb_byte
**opcode_definitions
,
24774 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24776 unsigned int offset_size
,
24777 struct dwarf2_section_info
*section
)
24779 unsigned int bytes_read
, i
;
24781 const gdb_byte
*defn
;
24783 if (opcode_definitions
[opcode
] == NULL
)
24785 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24790 defn
= opcode_definitions
[opcode
];
24791 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24792 defn
+= bytes_read
;
24794 for (i
= 0; i
< arg
; ++i
)
24796 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24797 (enum dwarf_form
) defn
[i
], offset_size
,
24799 if (mac_ptr
== NULL
)
24801 /* skip_form_bytes already issued the complaint. */
24809 /* A helper function which parses the header of a macro section.
24810 If the macro section is the extended (for now called "GNU") type,
24811 then this updates *OFFSET_SIZE. Returns a pointer to just after
24812 the header, or issues a complaint and returns NULL on error. */
24814 static const gdb_byte
*
24815 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24817 const gdb_byte
*mac_ptr
,
24818 unsigned int *offset_size
,
24819 int section_is_gnu
)
24821 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24823 if (section_is_gnu
)
24825 unsigned int version
, flags
;
24827 version
= read_2_bytes (abfd
, mac_ptr
);
24828 if (version
!= 4 && version
!= 5)
24830 complaint (_("unrecognized version `%d' in .debug_macro section"),
24836 flags
= read_1_byte (abfd
, mac_ptr
);
24838 *offset_size
= (flags
& 1) ? 8 : 4;
24840 if ((flags
& 2) != 0)
24841 /* We don't need the line table offset. */
24842 mac_ptr
+= *offset_size
;
24844 /* Vendor opcode descriptions. */
24845 if ((flags
& 4) != 0)
24847 unsigned int i
, count
;
24849 count
= read_1_byte (abfd
, mac_ptr
);
24851 for (i
= 0; i
< count
; ++i
)
24853 unsigned int opcode
, bytes_read
;
24856 opcode
= read_1_byte (abfd
, mac_ptr
);
24858 opcode_definitions
[opcode
] = mac_ptr
;
24859 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24860 mac_ptr
+= bytes_read
;
24869 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24870 including DW_MACRO_import. */
24873 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24875 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24876 struct macro_source_file
*current_file
,
24877 struct line_header
*lh
,
24878 struct dwarf2_section_info
*section
,
24879 int section_is_gnu
, int section_is_dwz
,
24880 unsigned int offset_size
,
24881 htab_t include_hash
)
24883 struct dwarf2_per_objfile
*dwarf2_per_objfile
24884 = cu
->per_cu
->dwarf2_per_objfile
;
24885 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24886 enum dwarf_macro_record_type macinfo_type
;
24887 int at_commandline
;
24888 const gdb_byte
*opcode_definitions
[256];
24890 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24891 &offset_size
, section_is_gnu
);
24892 if (mac_ptr
== NULL
)
24894 /* We already issued a complaint. */
24898 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24899 GDB is still reading the definitions from command line. First
24900 DW_MACINFO_start_file will need to be ignored as it was already executed
24901 to create CURRENT_FILE for the main source holding also the command line
24902 definitions. On first met DW_MACINFO_start_file this flag is reset to
24903 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24905 at_commandline
= 1;
24909 /* Do we at least have room for a macinfo type byte? */
24910 if (mac_ptr
>= mac_end
)
24912 dwarf2_section_buffer_overflow_complaint (section
);
24916 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24919 /* Note that we rely on the fact that the corresponding GNU and
24920 DWARF constants are the same. */
24922 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24923 switch (macinfo_type
)
24925 /* A zero macinfo type indicates the end of the macro
24930 case DW_MACRO_define
:
24931 case DW_MACRO_undef
:
24932 case DW_MACRO_define_strp
:
24933 case DW_MACRO_undef_strp
:
24934 case DW_MACRO_define_sup
:
24935 case DW_MACRO_undef_sup
:
24937 unsigned int bytes_read
;
24942 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24943 mac_ptr
+= bytes_read
;
24945 if (macinfo_type
== DW_MACRO_define
24946 || macinfo_type
== DW_MACRO_undef
)
24948 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24949 mac_ptr
+= bytes_read
;
24953 LONGEST str_offset
;
24955 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24956 mac_ptr
+= offset_size
;
24958 if (macinfo_type
== DW_MACRO_define_sup
24959 || macinfo_type
== DW_MACRO_undef_sup
24962 struct dwz_file
*dwz
24963 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24965 body
= read_indirect_string_from_dwz (objfile
,
24969 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
24973 is_define
= (macinfo_type
== DW_MACRO_define
24974 || macinfo_type
== DW_MACRO_define_strp
24975 || macinfo_type
== DW_MACRO_define_sup
);
24976 if (! current_file
)
24978 /* DWARF violation as no main source is present. */
24979 complaint (_("debug info with no main source gives macro %s "
24981 is_define
? _("definition") : _("undefinition"),
24985 if ((line
== 0 && !at_commandline
)
24986 || (line
!= 0 && at_commandline
))
24987 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
24988 at_commandline
? _("command-line") : _("in-file"),
24989 is_define
? _("definition") : _("undefinition"),
24990 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
24994 /* Fedora's rpm-build's "debugedit" binary
24995 corrupted .debug_macro sections.
24998 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
24999 complaint (_("debug info gives %s invalid macro %s "
25000 "without body (corrupted?) at line %d "
25002 at_commandline
? _("command-line") : _("in-file"),
25003 is_define
? _("definition") : _("undefinition"),
25004 line
, current_file
->filename
);
25006 else if (is_define
)
25007 parse_macro_definition (current_file
, line
, body
);
25010 gdb_assert (macinfo_type
== DW_MACRO_undef
25011 || macinfo_type
== DW_MACRO_undef_strp
25012 || macinfo_type
== DW_MACRO_undef_sup
);
25013 macro_undef (current_file
, line
, body
);
25018 case DW_MACRO_start_file
:
25020 unsigned int bytes_read
;
25023 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25024 mac_ptr
+= bytes_read
;
25025 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25026 mac_ptr
+= bytes_read
;
25028 if ((line
== 0 && !at_commandline
)
25029 || (line
!= 0 && at_commandline
))
25030 complaint (_("debug info gives source %d included "
25031 "from %s at %s line %d"),
25032 file
, at_commandline
? _("command-line") : _("file"),
25033 line
== 0 ? _("zero") : _("non-zero"), line
);
25035 if (at_commandline
)
25037 /* This DW_MACRO_start_file was executed in the
25039 at_commandline
= 0;
25042 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25047 case DW_MACRO_end_file
:
25048 if (! current_file
)
25049 complaint (_("macro debug info has an unmatched "
25050 "`close_file' directive"));
25053 current_file
= current_file
->included_by
;
25054 if (! current_file
)
25056 enum dwarf_macro_record_type next_type
;
25058 /* GCC circa March 2002 doesn't produce the zero
25059 type byte marking the end of the compilation
25060 unit. Complain if it's not there, but exit no
25063 /* Do we at least have room for a macinfo type byte? */
25064 if (mac_ptr
>= mac_end
)
25066 dwarf2_section_buffer_overflow_complaint (section
);
25070 /* We don't increment mac_ptr here, so this is just
25073 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25075 if (next_type
!= 0)
25076 complaint (_("no terminating 0-type entry for "
25077 "macros in `.debug_macinfo' section"));
25084 case DW_MACRO_import
:
25085 case DW_MACRO_import_sup
:
25089 bfd
*include_bfd
= abfd
;
25090 struct dwarf2_section_info
*include_section
= section
;
25091 const gdb_byte
*include_mac_end
= mac_end
;
25092 int is_dwz
= section_is_dwz
;
25093 const gdb_byte
*new_mac_ptr
;
25095 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25096 mac_ptr
+= offset_size
;
25098 if (macinfo_type
== DW_MACRO_import_sup
)
25100 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25102 dwarf2_read_section (objfile
, &dwz
->macro
);
25104 include_section
= &dwz
->macro
;
25105 include_bfd
= get_section_bfd_owner (include_section
);
25106 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25110 new_mac_ptr
= include_section
->buffer
+ offset
;
25111 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25115 /* This has actually happened; see
25116 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25117 complaint (_("recursive DW_MACRO_import in "
25118 ".debug_macro section"));
25122 *slot
= (void *) new_mac_ptr
;
25124 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25125 include_mac_end
, current_file
, lh
,
25126 section
, section_is_gnu
, is_dwz
,
25127 offset_size
, include_hash
);
25129 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25134 case DW_MACINFO_vendor_ext
:
25135 if (!section_is_gnu
)
25137 unsigned int bytes_read
;
25139 /* This reads the constant, but since we don't recognize
25140 any vendor extensions, we ignore it. */
25141 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25142 mac_ptr
+= bytes_read
;
25143 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25144 mac_ptr
+= bytes_read
;
25146 /* We don't recognize any vendor extensions. */
25152 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25153 mac_ptr
, mac_end
, abfd
, offset_size
,
25155 if (mac_ptr
== NULL
)
25160 } while (macinfo_type
!= 0);
25164 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25165 int section_is_gnu
)
25167 struct dwarf2_per_objfile
*dwarf2_per_objfile
25168 = cu
->per_cu
->dwarf2_per_objfile
;
25169 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25170 struct line_header
*lh
= cu
->line_header
;
25172 const gdb_byte
*mac_ptr
, *mac_end
;
25173 struct macro_source_file
*current_file
= 0;
25174 enum dwarf_macro_record_type macinfo_type
;
25175 unsigned int offset_size
= cu
->header
.offset_size
;
25176 const gdb_byte
*opcode_definitions
[256];
25178 struct dwarf2_section_info
*section
;
25179 const char *section_name
;
25181 if (cu
->dwo_unit
!= NULL
)
25183 if (section_is_gnu
)
25185 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25186 section_name
= ".debug_macro.dwo";
25190 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25191 section_name
= ".debug_macinfo.dwo";
25196 if (section_is_gnu
)
25198 section
= &dwarf2_per_objfile
->macro
;
25199 section_name
= ".debug_macro";
25203 section
= &dwarf2_per_objfile
->macinfo
;
25204 section_name
= ".debug_macinfo";
25208 dwarf2_read_section (objfile
, section
);
25209 if (section
->buffer
== NULL
)
25211 complaint (_("missing %s section"), section_name
);
25214 abfd
= get_section_bfd_owner (section
);
25216 /* First pass: Find the name of the base filename.
25217 This filename is needed in order to process all macros whose definition
25218 (or undefinition) comes from the command line. These macros are defined
25219 before the first DW_MACINFO_start_file entry, and yet still need to be
25220 associated to the base file.
25222 To determine the base file name, we scan the macro definitions until we
25223 reach the first DW_MACINFO_start_file entry. We then initialize
25224 CURRENT_FILE accordingly so that any macro definition found before the
25225 first DW_MACINFO_start_file can still be associated to the base file. */
25227 mac_ptr
= section
->buffer
+ offset
;
25228 mac_end
= section
->buffer
+ section
->size
;
25230 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25231 &offset_size
, section_is_gnu
);
25232 if (mac_ptr
== NULL
)
25234 /* We already issued a complaint. */
25240 /* Do we at least have room for a macinfo type byte? */
25241 if (mac_ptr
>= mac_end
)
25243 /* Complaint is printed during the second pass as GDB will probably
25244 stop the first pass earlier upon finding
25245 DW_MACINFO_start_file. */
25249 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25252 /* Note that we rely on the fact that the corresponding GNU and
25253 DWARF constants are the same. */
25255 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25256 switch (macinfo_type
)
25258 /* A zero macinfo type indicates the end of the macro
25263 case DW_MACRO_define
:
25264 case DW_MACRO_undef
:
25265 /* Only skip the data by MAC_PTR. */
25267 unsigned int bytes_read
;
25269 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25270 mac_ptr
+= bytes_read
;
25271 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25272 mac_ptr
+= bytes_read
;
25276 case DW_MACRO_start_file
:
25278 unsigned int bytes_read
;
25281 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25282 mac_ptr
+= bytes_read
;
25283 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25284 mac_ptr
+= bytes_read
;
25286 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25290 case DW_MACRO_end_file
:
25291 /* No data to skip by MAC_PTR. */
25294 case DW_MACRO_define_strp
:
25295 case DW_MACRO_undef_strp
:
25296 case DW_MACRO_define_sup
:
25297 case DW_MACRO_undef_sup
:
25299 unsigned int bytes_read
;
25301 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25302 mac_ptr
+= bytes_read
;
25303 mac_ptr
+= offset_size
;
25307 case DW_MACRO_import
:
25308 case DW_MACRO_import_sup
:
25309 /* Note that, according to the spec, a transparent include
25310 chain cannot call DW_MACRO_start_file. So, we can just
25311 skip this opcode. */
25312 mac_ptr
+= offset_size
;
25315 case DW_MACINFO_vendor_ext
:
25316 /* Only skip the data by MAC_PTR. */
25317 if (!section_is_gnu
)
25319 unsigned int bytes_read
;
25321 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25322 mac_ptr
+= bytes_read
;
25323 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25324 mac_ptr
+= bytes_read
;
25329 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25330 mac_ptr
, mac_end
, abfd
, offset_size
,
25332 if (mac_ptr
== NULL
)
25337 } while (macinfo_type
!= 0 && current_file
== NULL
);
25339 /* Second pass: Process all entries.
25341 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25342 command-line macro definitions/undefinitions. This flag is unset when we
25343 reach the first DW_MACINFO_start_file entry. */
25345 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25347 NULL
, xcalloc
, xfree
));
25348 mac_ptr
= section
->buffer
+ offset
;
25349 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25350 *slot
= (void *) mac_ptr
;
25351 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25352 current_file
, lh
, section
,
25353 section_is_gnu
, 0, offset_size
,
25354 include_hash
.get ());
25357 /* Check if the attribute's form is a DW_FORM_block*
25358 if so return true else false. */
25361 attr_form_is_block (const struct attribute
*attr
)
25363 return (attr
== NULL
? 0 :
25364 attr
->form
== DW_FORM_block1
25365 || attr
->form
== DW_FORM_block2
25366 || attr
->form
== DW_FORM_block4
25367 || attr
->form
== DW_FORM_block
25368 || attr
->form
== DW_FORM_exprloc
);
25371 /* Return non-zero if ATTR's value is a section offset --- classes
25372 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25373 You may use DW_UNSND (attr) to retrieve such offsets.
25375 Section 7.5.4, "Attribute Encodings", explains that no attribute
25376 may have a value that belongs to more than one of these classes; it
25377 would be ambiguous if we did, because we use the same forms for all
25381 attr_form_is_section_offset (const struct attribute
*attr
)
25383 return (attr
->form
== DW_FORM_data4
25384 || attr
->form
== DW_FORM_data8
25385 || attr
->form
== DW_FORM_sec_offset
);
25388 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25389 zero otherwise. When this function returns true, you can apply
25390 dwarf2_get_attr_constant_value to it.
25392 However, note that for some attributes you must check
25393 attr_form_is_section_offset before using this test. DW_FORM_data4
25394 and DW_FORM_data8 are members of both the constant class, and of
25395 the classes that contain offsets into other debug sections
25396 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25397 that, if an attribute's can be either a constant or one of the
25398 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25399 taken as section offsets, not constants.
25401 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25402 cannot handle that. */
25405 attr_form_is_constant (const struct attribute
*attr
)
25407 switch (attr
->form
)
25409 case DW_FORM_sdata
:
25410 case DW_FORM_udata
:
25411 case DW_FORM_data1
:
25412 case DW_FORM_data2
:
25413 case DW_FORM_data4
:
25414 case DW_FORM_data8
:
25415 case DW_FORM_implicit_const
:
25423 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25424 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25427 attr_form_is_ref (const struct attribute
*attr
)
25429 switch (attr
->form
)
25431 case DW_FORM_ref_addr
:
25436 case DW_FORM_ref_udata
:
25437 case DW_FORM_GNU_ref_alt
:
25444 /* Return the .debug_loc section to use for CU.
25445 For DWO files use .debug_loc.dwo. */
25447 static struct dwarf2_section_info
*
25448 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25450 struct dwarf2_per_objfile
*dwarf2_per_objfile
25451 = cu
->per_cu
->dwarf2_per_objfile
;
25455 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25457 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25459 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25460 : &dwarf2_per_objfile
->loc
);
25463 /* A helper function that fills in a dwarf2_loclist_baton. */
25466 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25467 struct dwarf2_loclist_baton
*baton
,
25468 const struct attribute
*attr
)
25470 struct dwarf2_per_objfile
*dwarf2_per_objfile
25471 = cu
->per_cu
->dwarf2_per_objfile
;
25472 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25474 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25476 baton
->per_cu
= cu
->per_cu
;
25477 gdb_assert (baton
->per_cu
);
25478 /* We don't know how long the location list is, but make sure we
25479 don't run off the edge of the section. */
25480 baton
->size
= section
->size
- DW_UNSND (attr
);
25481 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25482 baton
->base_address
= cu
->base_address
;
25483 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25487 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25488 struct dwarf2_cu
*cu
, int is_block
)
25490 struct dwarf2_per_objfile
*dwarf2_per_objfile
25491 = cu
->per_cu
->dwarf2_per_objfile
;
25492 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25493 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25495 if (attr_form_is_section_offset (attr
)
25496 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25497 the section. If so, fall through to the complaint in the
25499 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25501 struct dwarf2_loclist_baton
*baton
;
25503 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25505 fill_in_loclist_baton (cu
, baton
, attr
);
25507 if (cu
->base_known
== 0)
25508 complaint (_("Location list used without "
25509 "specifying the CU base address."));
25511 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25512 ? dwarf2_loclist_block_index
25513 : dwarf2_loclist_index
);
25514 SYMBOL_LOCATION_BATON (sym
) = baton
;
25518 struct dwarf2_locexpr_baton
*baton
;
25520 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25521 baton
->per_cu
= cu
->per_cu
;
25522 gdb_assert (baton
->per_cu
);
25524 if (attr_form_is_block (attr
))
25526 /* Note that we're just copying the block's data pointer
25527 here, not the actual data. We're still pointing into the
25528 info_buffer for SYM's objfile; right now we never release
25529 that buffer, but when we do clean up properly this may
25531 baton
->size
= DW_BLOCK (attr
)->size
;
25532 baton
->data
= DW_BLOCK (attr
)->data
;
25536 dwarf2_invalid_attrib_class_complaint ("location description",
25537 sym
->natural_name ());
25541 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25542 ? dwarf2_locexpr_block_index
25543 : dwarf2_locexpr_index
);
25544 SYMBOL_LOCATION_BATON (sym
) = baton
;
25548 /* Return the OBJFILE associated with the compilation unit CU. If CU
25549 came from a separate debuginfo file, then the master objfile is
25553 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25555 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25557 /* Return the master objfile, so that we can report and look up the
25558 correct file containing this variable. */
25559 if (objfile
->separate_debug_objfile_backlink
)
25560 objfile
= objfile
->separate_debug_objfile_backlink
;
25565 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25566 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25567 CU_HEADERP first. */
25569 static const struct comp_unit_head
*
25570 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25571 struct dwarf2_per_cu_data
*per_cu
)
25573 const gdb_byte
*info_ptr
;
25576 return &per_cu
->cu
->header
;
25578 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25580 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25581 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25582 rcuh_kind::COMPILE
);
25587 /* Return the address size given in the compilation unit header for CU. */
25590 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25592 struct comp_unit_head cu_header_local
;
25593 const struct comp_unit_head
*cu_headerp
;
25595 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25597 return cu_headerp
->addr_size
;
25600 /* Return the offset size given in the compilation unit header for CU. */
25603 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25605 struct comp_unit_head cu_header_local
;
25606 const struct comp_unit_head
*cu_headerp
;
25608 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25610 return cu_headerp
->offset_size
;
25613 /* See its dwarf2loc.h declaration. */
25616 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25618 struct comp_unit_head cu_header_local
;
25619 const struct comp_unit_head
*cu_headerp
;
25621 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25623 if (cu_headerp
->version
== 2)
25624 return cu_headerp
->addr_size
;
25626 return cu_headerp
->offset_size
;
25629 /* Return the text offset of the CU. The returned offset comes from
25630 this CU's objfile. If this objfile came from a separate debuginfo
25631 file, then the offset may be different from the corresponding
25632 offset in the parent objfile. */
25635 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25637 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25640 /* Return a type that is a generic pointer type, the size of which matches
25641 the address size given in the compilation unit header for PER_CU. */
25642 static struct type
*
25643 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25645 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25646 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25647 struct type
*addr_type
= lookup_pointer_type (void_type
);
25648 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25650 if (TYPE_LENGTH (addr_type
) == addr_size
)
25654 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25658 /* Return DWARF version number of PER_CU. */
25661 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25663 return per_cu
->dwarf_version
;
25666 /* Locate the .debug_info compilation unit from CU's objfile which contains
25667 the DIE at OFFSET. Raises an error on failure. */
25669 static struct dwarf2_per_cu_data
*
25670 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25671 unsigned int offset_in_dwz
,
25672 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25674 struct dwarf2_per_cu_data
*this_cu
;
25678 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25681 struct dwarf2_per_cu_data
*mid_cu
;
25682 int mid
= low
+ (high
- low
) / 2;
25684 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25685 if (mid_cu
->is_dwz
> offset_in_dwz
25686 || (mid_cu
->is_dwz
== offset_in_dwz
25687 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25692 gdb_assert (low
== high
);
25693 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25694 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25696 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25697 error (_("Dwarf Error: could not find partial DIE containing "
25698 "offset %s [in module %s]"),
25699 sect_offset_str (sect_off
),
25700 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25702 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25704 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25708 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25709 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25710 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25711 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25716 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25718 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25719 : per_cu (per_cu_
),
25721 has_loclist (false),
25722 checked_producer (false),
25723 producer_is_gxx_lt_4_6 (false),
25724 producer_is_gcc_lt_4_3 (false),
25725 producer_is_icc (false),
25726 producer_is_icc_lt_14 (false),
25727 producer_is_codewarrior (false),
25728 processing_has_namespace_info (false)
25733 /* Destroy a dwarf2_cu. */
25735 dwarf2_cu::~dwarf2_cu ()
25740 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25743 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25744 enum language pretend_language
)
25746 struct attribute
*attr
;
25748 /* Set the language we're debugging. */
25749 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25750 if (attr
!= nullptr)
25751 set_cu_language (DW_UNSND (attr
), cu
);
25754 cu
->language
= pretend_language
;
25755 cu
->language_defn
= language_def (cu
->language
);
25758 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25761 /* Increase the age counter on each cached compilation unit, and free
25762 any that are too old. */
25765 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25767 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25769 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25770 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25771 while (per_cu
!= NULL
)
25773 per_cu
->cu
->last_used
++;
25774 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25775 dwarf2_mark (per_cu
->cu
);
25776 per_cu
= per_cu
->cu
->read_in_chain
;
25779 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25780 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25781 while (per_cu
!= NULL
)
25783 struct dwarf2_per_cu_data
*next_cu
;
25785 next_cu
= per_cu
->cu
->read_in_chain
;
25787 if (!per_cu
->cu
->mark
)
25790 *last_chain
= next_cu
;
25793 last_chain
= &per_cu
->cu
->read_in_chain
;
25799 /* Remove a single compilation unit from the cache. */
25802 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25804 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25805 struct dwarf2_per_objfile
*dwarf2_per_objfile
25806 = target_per_cu
->dwarf2_per_objfile
;
25808 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25809 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25810 while (per_cu
!= NULL
)
25812 struct dwarf2_per_cu_data
*next_cu
;
25814 next_cu
= per_cu
->cu
->read_in_chain
;
25816 if (per_cu
== target_per_cu
)
25820 *last_chain
= next_cu
;
25824 last_chain
= &per_cu
->cu
->read_in_chain
;
25830 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25831 We store these in a hash table separate from the DIEs, and preserve them
25832 when the DIEs are flushed out of cache.
25834 The CU "per_cu" pointer is needed because offset alone is not enough to
25835 uniquely identify the type. A file may have multiple .debug_types sections,
25836 or the type may come from a DWO file. Furthermore, while it's more logical
25837 to use per_cu->section+offset, with Fission the section with the data is in
25838 the DWO file but we don't know that section at the point we need it.
25839 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25840 because we can enter the lookup routine, get_die_type_at_offset, from
25841 outside this file, and thus won't necessarily have PER_CU->cu.
25842 Fortunately, PER_CU is stable for the life of the objfile. */
25844 struct dwarf2_per_cu_offset_and_type
25846 const struct dwarf2_per_cu_data
*per_cu
;
25847 sect_offset sect_off
;
25851 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25854 per_cu_offset_and_type_hash (const void *item
)
25856 const struct dwarf2_per_cu_offset_and_type
*ofs
25857 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25859 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25862 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25865 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25867 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25868 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25869 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25870 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25872 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25873 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25876 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25877 table if necessary. For convenience, return TYPE.
25879 The DIEs reading must have careful ordering to:
25880 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25881 reading current DIE.
25882 * Not trying to dereference contents of still incompletely read in types
25883 while reading in other DIEs.
25884 * Enable referencing still incompletely read in types just by a pointer to
25885 the type without accessing its fields.
25887 Therefore caller should follow these rules:
25888 * Try to fetch any prerequisite types we may need to build this DIE type
25889 before building the type and calling set_die_type.
25890 * After building type call set_die_type for current DIE as soon as
25891 possible before fetching more types to complete the current type.
25892 * Make the type as complete as possible before fetching more types. */
25894 static struct type
*
25895 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25897 struct dwarf2_per_objfile
*dwarf2_per_objfile
25898 = cu
->per_cu
->dwarf2_per_objfile
;
25899 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25900 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25901 struct attribute
*attr
;
25902 struct dynamic_prop prop
;
25904 /* For Ada types, make sure that the gnat-specific data is always
25905 initialized (if not already set). There are a few types where
25906 we should not be doing so, because the type-specific area is
25907 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25908 where the type-specific area is used to store the floatformat).
25909 But this is not a problem, because the gnat-specific information
25910 is actually not needed for these types. */
25911 if (need_gnat_info (cu
)
25912 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25913 && TYPE_CODE (type
) != TYPE_CODE_FLT
25914 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25915 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25916 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25917 && !HAVE_GNAT_AUX_INFO (type
))
25918 INIT_GNAT_SPECIFIC (type
);
25920 /* Read DW_AT_allocated and set in type. */
25921 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25922 if (attr_form_is_block (attr
))
25924 struct type
*prop_type
25925 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25926 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25927 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25929 else if (attr
!= NULL
)
25931 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25932 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25933 sect_offset_str (die
->sect_off
));
25936 /* Read DW_AT_associated and set in type. */
25937 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25938 if (attr_form_is_block (attr
))
25940 struct type
*prop_type
25941 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25942 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25943 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25945 else if (attr
!= NULL
)
25947 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25948 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25949 sect_offset_str (die
->sect_off
));
25952 /* Read DW_AT_data_location and set in type. */
25953 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25954 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25955 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25956 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25958 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25960 dwarf2_per_objfile
->die_type_hash
=
25961 htab_create_alloc_ex (127,
25962 per_cu_offset_and_type_hash
,
25963 per_cu_offset_and_type_eq
,
25965 &objfile
->objfile_obstack
,
25966 hashtab_obstack_allocate
,
25967 dummy_obstack_deallocate
);
25970 ofs
.per_cu
= cu
->per_cu
;
25971 ofs
.sect_off
= die
->sect_off
;
25973 slot
= (struct dwarf2_per_cu_offset_and_type
**)
25974 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
25976 complaint (_("A problem internal to GDB: DIE %s has type already set"),
25977 sect_offset_str (die
->sect_off
));
25978 *slot
= XOBNEW (&objfile
->objfile_obstack
,
25979 struct dwarf2_per_cu_offset_and_type
);
25984 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
25985 or return NULL if the die does not have a saved type. */
25987 static struct type
*
25988 get_die_type_at_offset (sect_offset sect_off
,
25989 struct dwarf2_per_cu_data
*per_cu
)
25991 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
25992 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
25994 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25997 ofs
.per_cu
= per_cu
;
25998 ofs
.sect_off
= sect_off
;
25999 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26000 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
26007 /* Look up the type for DIE in CU in die_type_hash,
26008 or return NULL if DIE does not have a saved type. */
26010 static struct type
*
26011 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26013 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26016 /* Add a dependence relationship from CU to REF_PER_CU. */
26019 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26020 struct dwarf2_per_cu_data
*ref_per_cu
)
26024 if (cu
->dependencies
== NULL
)
26026 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26027 NULL
, &cu
->comp_unit_obstack
,
26028 hashtab_obstack_allocate
,
26029 dummy_obstack_deallocate
);
26031 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26033 *slot
= ref_per_cu
;
26036 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26037 Set the mark field in every compilation unit in the
26038 cache that we must keep because we are keeping CU. */
26041 dwarf2_mark_helper (void **slot
, void *data
)
26043 struct dwarf2_per_cu_data
*per_cu
;
26045 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26047 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26048 reading of the chain. As such dependencies remain valid it is not much
26049 useful to track and undo them during QUIT cleanups. */
26050 if (per_cu
->cu
== NULL
)
26053 if (per_cu
->cu
->mark
)
26055 per_cu
->cu
->mark
= true;
26057 if (per_cu
->cu
->dependencies
!= NULL
)
26058 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26063 /* Set the mark field in CU and in every other compilation unit in the
26064 cache that we must keep because we are keeping CU. */
26067 dwarf2_mark (struct dwarf2_cu
*cu
)
26072 if (cu
->dependencies
!= NULL
)
26073 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26077 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26081 per_cu
->cu
->mark
= false;
26082 per_cu
= per_cu
->cu
->read_in_chain
;
26086 /* Trivial hash function for partial_die_info: the hash value of a DIE
26087 is its offset in .debug_info for this objfile. */
26090 partial_die_hash (const void *item
)
26092 const struct partial_die_info
*part_die
26093 = (const struct partial_die_info
*) item
;
26095 return to_underlying (part_die
->sect_off
);
26098 /* Trivial comparison function for partial_die_info structures: two DIEs
26099 are equal if they have the same offset. */
26102 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26104 const struct partial_die_info
*part_die_lhs
26105 = (const struct partial_die_info
*) item_lhs
;
26106 const struct partial_die_info
*part_die_rhs
26107 = (const struct partial_die_info
*) item_rhs
;
26109 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26112 struct cmd_list_element
*set_dwarf_cmdlist
;
26113 struct cmd_list_element
*show_dwarf_cmdlist
;
26116 set_dwarf_cmd (const char *args
, int from_tty
)
26118 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26123 show_dwarf_cmd (const char *args
, int from_tty
)
26125 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26128 bool dwarf_always_disassemble
;
26131 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26132 struct cmd_list_element
*c
, const char *value
)
26134 fprintf_filtered (file
,
26135 _("Whether to always disassemble "
26136 "DWARF expressions is %s.\n"),
26141 show_check_physname (struct ui_file
*file
, int from_tty
,
26142 struct cmd_list_element
*c
, const char *value
)
26144 fprintf_filtered (file
,
26145 _("Whether to check \"physname\" is %s.\n"),
26149 void _initialize_dwarf2_read ();
26151 _initialize_dwarf2_read ()
26153 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26154 Set DWARF specific variables.\n\
26155 Configure DWARF variables such as the cache size."),
26156 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26157 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26159 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26160 Show DWARF specific variables.\n\
26161 Show DWARF variables such as the cache size."),
26162 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26163 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26165 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26166 &dwarf_max_cache_age
, _("\
26167 Set the upper bound on the age of cached DWARF compilation units."), _("\
26168 Show the upper bound on the age of cached DWARF compilation units."), _("\
26169 A higher limit means that cached compilation units will be stored\n\
26170 in memory longer, and more total memory will be used. Zero disables\n\
26171 caching, which can slow down startup."),
26173 show_dwarf_max_cache_age
,
26174 &set_dwarf_cmdlist
,
26175 &show_dwarf_cmdlist
);
26177 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26178 &dwarf_always_disassemble
, _("\
26179 Set whether `info address' always disassembles DWARF expressions."), _("\
26180 Show whether `info address' always disassembles DWARF expressions."), _("\
26181 When enabled, DWARF expressions are always printed in an assembly-like\n\
26182 syntax. When disabled, expressions will be printed in a more\n\
26183 conversational style, when possible."),
26185 show_dwarf_always_disassemble
,
26186 &set_dwarf_cmdlist
,
26187 &show_dwarf_cmdlist
);
26189 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26190 Set debugging of the DWARF reader."), _("\
26191 Show debugging of the DWARF reader."), _("\
26192 When enabled (non-zero), debugging messages are printed during DWARF\n\
26193 reading and symtab expansion. A value of 1 (one) provides basic\n\
26194 information. A value greater than 1 provides more verbose information."),
26197 &setdebuglist
, &showdebuglist
);
26199 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26200 Set debugging of the DWARF DIE reader."), _("\
26201 Show debugging of the DWARF DIE reader."), _("\
26202 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26203 The value is the maximum depth to print."),
26206 &setdebuglist
, &showdebuglist
);
26208 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26209 Set debugging of the dwarf line reader."), _("\
26210 Show debugging of the dwarf line reader."), _("\
26211 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26212 A value of 1 (one) provides basic information.\n\
26213 A value greater than 1 provides more verbose information."),
26216 &setdebuglist
, &showdebuglist
);
26218 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26219 Set cross-checking of \"physname\" code against demangler."), _("\
26220 Show cross-checking of \"physname\" code against demangler."), _("\
26221 When enabled, GDB's internal \"physname\" code is checked against\n\
26223 NULL
, show_check_physname
,
26224 &setdebuglist
, &showdebuglist
);
26226 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26227 no_class
, &use_deprecated_index_sections
, _("\
26228 Set whether to use deprecated gdb_index sections."), _("\
26229 Show whether to use deprecated gdb_index sections."), _("\
26230 When enabled, deprecated .gdb_index sections are used anyway.\n\
26231 Normally they are ignored either because of a missing feature or\n\
26232 performance issue.\n\
26233 Warning: This option must be enabled before gdb reads the file."),
26236 &setlist
, &showlist
);
26238 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26239 &dwarf2_locexpr_funcs
);
26240 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26241 &dwarf2_loclist_funcs
);
26243 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26244 &dwarf2_block_frame_base_locexpr_funcs
);
26245 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26246 &dwarf2_block_frame_base_loclist_funcs
);
26249 selftests::register_test ("dw2_expand_symtabs_matching",
26250 selftests::dw2_expand_symtabs_matching::run_test
);