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 struct partial_symtab
*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 void dwarf2_read_symtab (struct partial_symtab
*,
1519 static void psymtab_to_symtab_1 (struct partial_symtab
*);
1521 static abbrev_table_up abbrev_table_read_table
1522 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, struct dwarf2_section_info
*,
1525 static unsigned int peek_abbrev_code (bfd
*, const gdb_byte
*);
1527 static struct partial_die_info
*load_partial_dies
1528 (const struct die_reader_specs
*, const gdb_byte
*, int);
1530 /* A pair of partial_die_info and compilation unit. */
1531 struct cu_partial_die_info
1533 /* The compilation unit of the partial_die_info. */
1534 struct dwarf2_cu
*cu
;
1535 /* A partial_die_info. */
1536 struct partial_die_info
*pdi
;
1538 cu_partial_die_info (struct dwarf2_cu
*cu
, struct partial_die_info
*pdi
)
1544 cu_partial_die_info () = delete;
1547 static const struct cu_partial_die_info
find_partial_die (sect_offset
, int,
1548 struct dwarf2_cu
*);
1550 static const gdb_byte
*read_attribute (const struct die_reader_specs
*,
1551 struct attribute
*, struct attr_abbrev
*,
1552 const gdb_byte
*, bool *need_reprocess
);
1554 static void read_attribute_reprocess (const struct die_reader_specs
*reader
,
1555 struct attribute
*attr
);
1557 static CORE_ADDR
read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
);
1559 static unsigned int read_1_byte (bfd
*, const gdb_byte
*);
1561 static int read_1_signed_byte (bfd
*, const gdb_byte
*);
1563 static unsigned int read_2_bytes (bfd
*, const gdb_byte
*);
1565 /* Read the next three bytes (little-endian order) as an unsigned integer. */
1566 static unsigned int read_3_bytes (bfd
*, const gdb_byte
*);
1568 static unsigned int read_4_bytes (bfd
*, const gdb_byte
*);
1570 static ULONGEST
read_8_bytes (bfd
*, const gdb_byte
*);
1572 static CORE_ADDR
read_address (bfd
*, const gdb_byte
*ptr
, struct dwarf2_cu
*,
1575 static LONGEST
read_initial_length (bfd
*, const gdb_byte
*, unsigned int *);
1577 static LONGEST read_checked_initial_length_and_offset
1578 (bfd
*, const gdb_byte
*, const struct comp_unit_head
*,
1579 unsigned int *, unsigned int *);
1581 static LONGEST
read_offset (bfd
*, const gdb_byte
*,
1582 const struct comp_unit_head
*,
1585 static LONGEST
read_offset_1 (bfd
*, const gdb_byte
*, unsigned int);
1587 static sect_offset read_abbrev_offset
1588 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
1589 struct dwarf2_section_info
*, sect_offset
);
1591 static const gdb_byte
*read_n_bytes (bfd
*, const gdb_byte
*, unsigned int);
1593 static const char *read_direct_string (bfd
*, const gdb_byte
*, unsigned int *);
1595 static const char *read_indirect_string
1596 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1597 const struct comp_unit_head
*, unsigned int *);
1599 static const char *read_indirect_line_string
1600 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*, const gdb_byte
*,
1601 const struct comp_unit_head
*, unsigned int *);
1603 static const char *read_indirect_string_at_offset
1604 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
1605 LONGEST str_offset
);
1607 static const char *read_indirect_string_from_dwz
1608 (struct objfile
*objfile
, struct dwz_file
*, LONGEST
);
1610 static LONGEST
read_signed_leb128 (bfd
*, const gdb_byte
*, unsigned int *);
1612 static CORE_ADDR
read_addr_index_from_leb128 (struct dwarf2_cu
*,
1616 static const char *read_dwo_str_index (const struct die_reader_specs
*reader
,
1617 ULONGEST str_index
);
1619 static const char *read_stub_str_index (struct dwarf2_cu
*cu
,
1620 ULONGEST str_index
);
1622 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
1624 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
1625 struct dwarf2_cu
*);
1627 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
1630 static const char *dwarf2_string_attr (struct die_info
*die
, unsigned int name
,
1631 struct dwarf2_cu
*cu
);
1633 static const char *dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
1635 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
1636 struct dwarf2_cu
*cu
);
1638 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
1640 static struct die_info
*die_specification (struct die_info
*die
,
1641 struct dwarf2_cu
**);
1643 static line_header_up
dwarf_decode_line_header (sect_offset sect_off
,
1644 struct dwarf2_cu
*cu
);
1646 static void dwarf_decode_lines (struct line_header
*, const char *,
1647 struct dwarf2_cu
*, struct partial_symtab
*,
1648 CORE_ADDR
, int decode_mapping
);
1650 static void dwarf2_start_subfile (struct dwarf2_cu
*, const char *,
1653 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1654 struct dwarf2_cu
*, struct symbol
* = NULL
);
1656 static void dwarf2_const_value (const struct attribute
*, struct symbol
*,
1657 struct dwarf2_cu
*);
1659 static void dwarf2_const_value_attr (const struct attribute
*attr
,
1662 struct obstack
*obstack
,
1663 struct dwarf2_cu
*cu
, LONGEST
*value
,
1664 const gdb_byte
**bytes
,
1665 struct dwarf2_locexpr_baton
**baton
);
1667 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1669 static int need_gnat_info (struct dwarf2_cu
*);
1671 static struct type
*die_descriptive_type (struct die_info
*,
1672 struct dwarf2_cu
*);
1674 static void set_descriptive_type (struct type
*, struct die_info
*,
1675 struct dwarf2_cu
*);
1677 static struct type
*die_containing_type (struct die_info
*,
1678 struct dwarf2_cu
*);
1680 static struct type
*lookup_die_type (struct die_info
*, const struct attribute
*,
1681 struct dwarf2_cu
*);
1683 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1685 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1687 static const char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1689 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1690 const char *suffix
, int physname
,
1691 struct dwarf2_cu
*cu
);
1693 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1695 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1697 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1699 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1701 static void read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
);
1703 static void read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
);
1705 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1706 struct dwarf2_cu
*, struct partial_symtab
*);
1708 /* How dwarf2_get_pc_bounds constructed its *LOWPC and *HIGHPC return
1709 values. Keep the items ordered with increasing constraints compliance. */
1712 /* No attribute DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges was found. */
1713 PC_BOUNDS_NOT_PRESENT
,
1715 /* Some of the attributes DW_AT_low_pc, DW_AT_high_pc or DW_AT_ranges
1716 were present but they do not form a valid range of PC addresses. */
1719 /* Discontiguous range was found - that is DW_AT_ranges was found. */
1722 /* Contiguous range was found - DW_AT_low_pc and DW_AT_high_pc were found. */
1726 static enum pc_bounds_kind
dwarf2_get_pc_bounds (struct die_info
*,
1727 CORE_ADDR
*, CORE_ADDR
*,
1729 struct partial_symtab
*);
1731 static void get_scope_pc_bounds (struct die_info
*,
1732 CORE_ADDR
*, CORE_ADDR
*,
1733 struct dwarf2_cu
*);
1735 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1736 CORE_ADDR
, struct dwarf2_cu
*);
1738 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1739 struct dwarf2_cu
*);
1741 static void dwarf2_attach_fields_to_type (struct field_info
*,
1742 struct type
*, struct dwarf2_cu
*);
1744 static void dwarf2_add_member_fn (struct field_info
*,
1745 struct die_info
*, struct type
*,
1746 struct dwarf2_cu
*);
1748 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1750 struct dwarf2_cu
*);
1752 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1754 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1756 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1758 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1760 static struct using_direct
**using_directives (struct dwarf2_cu
*cu
);
1762 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1764 static int read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
);
1766 static struct type
*read_module_type (struct die_info
*die
,
1767 struct dwarf2_cu
*cu
);
1769 static const char *namespace_name (struct die_info
*die
,
1770 int *is_anonymous
, struct dwarf2_cu
*);
1772 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1774 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1776 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1777 struct dwarf2_cu
*);
1779 static struct die_info
*read_die_and_siblings_1
1780 (const struct die_reader_specs
*, const gdb_byte
*, const gdb_byte
**,
1783 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*,
1784 const gdb_byte
*info_ptr
,
1785 const gdb_byte
**new_info_ptr
,
1786 struct die_info
*parent
);
1788 static const gdb_byte
*read_full_die_1 (const struct die_reader_specs
*,
1789 struct die_info
**, const gdb_byte
*,
1792 static const gdb_byte
*read_full_die (const struct die_reader_specs
*,
1793 struct die_info
**, const gdb_byte
*,
1796 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1798 static const char *dwarf2_canonicalize_name (const char *, struct dwarf2_cu
*,
1801 static const char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1803 static const char *dwarf2_full_name (const char *name
,
1804 struct die_info
*die
,
1805 struct dwarf2_cu
*cu
);
1807 static const char *dwarf2_physname (const char *name
, struct die_info
*die
,
1808 struct dwarf2_cu
*cu
);
1810 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1811 struct dwarf2_cu
**);
1813 static const char *dwarf_tag_name (unsigned int);
1815 static const char *dwarf_attr_name (unsigned int);
1817 static const char *dwarf_unit_type_name (int unit_type
);
1819 static const char *dwarf_form_name (unsigned int);
1821 static const char *dwarf_bool_name (unsigned int);
1823 static const char *dwarf_type_encoding_name (unsigned int);
1825 static struct die_info
*sibling_die (struct die_info
*);
1827 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1829 static void dump_die_for_error (struct die_info
*);
1831 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1834 /*static*/ void dump_die (struct die_info
*, int max_level
);
1836 static void store_in_ref_table (struct die_info
*,
1837 struct dwarf2_cu
*);
1839 static sect_offset
dwarf2_get_ref_die_offset (const struct attribute
*);
1841 static LONGEST
dwarf2_get_attr_constant_value (const struct attribute
*, int);
1843 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1844 const struct attribute
*,
1845 struct dwarf2_cu
**);
1847 static struct die_info
*follow_die_ref (struct die_info
*,
1848 const struct attribute
*,
1849 struct dwarf2_cu
**);
1851 static struct die_info
*follow_die_sig (struct die_info
*,
1852 const struct attribute
*,
1853 struct dwarf2_cu
**);
1855 static struct type
*get_signatured_type (struct die_info
*, ULONGEST
,
1856 struct dwarf2_cu
*);
1858 static struct type
*get_DW_AT_signature_type (struct die_info
*,
1859 const struct attribute
*,
1860 struct dwarf2_cu
*);
1862 static void load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
);
1864 static void read_signatured_type (struct signatured_type
*);
1866 static int attr_to_dynamic_prop (const struct attribute
*attr
,
1867 struct die_info
*die
, struct dwarf2_cu
*cu
,
1868 struct dynamic_prop
*prop
, struct type
*type
);
1870 /* memory allocation interface */
1872 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1874 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1876 static void dwarf_decode_macros (struct dwarf2_cu
*, unsigned int, int);
1878 static int attr_form_is_block (const struct attribute
*);
1880 static int attr_form_is_section_offset (const struct attribute
*);
1882 static int attr_form_is_constant (const struct attribute
*);
1884 static int attr_form_is_ref (const struct attribute
*);
1886 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1887 struct dwarf2_loclist_baton
*baton
,
1888 const struct attribute
*attr
);
1890 static void dwarf2_symbol_mark_computed (const struct attribute
*attr
,
1892 struct dwarf2_cu
*cu
,
1895 static const gdb_byte
*skip_one_die (const struct die_reader_specs
*reader
,
1896 const gdb_byte
*info_ptr
,
1897 struct abbrev_info
*abbrev
);
1899 static hashval_t
partial_die_hash (const void *item
);
1901 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1903 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1904 (sect_offset sect_off
, unsigned int offset_in_dwz
,
1905 struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1907 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1908 struct die_info
*comp_unit_die
,
1909 enum language pretend_language
);
1911 static void age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1913 static void free_one_cached_comp_unit (struct dwarf2_per_cu_data
*);
1915 static struct type
*set_die_type (struct die_info
*, struct type
*,
1916 struct dwarf2_cu
*);
1918 static void create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1920 static int create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1922 static void load_full_comp_unit (struct dwarf2_per_cu_data
*, bool,
1925 static void process_full_comp_unit (struct dwarf2_per_cu_data
*,
1928 static void process_full_type_unit (struct dwarf2_per_cu_data
*,
1931 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1932 struct dwarf2_per_cu_data
*);
1934 static void dwarf2_mark (struct dwarf2_cu
*);
1936 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1938 static struct type
*get_die_type_at_offset (sect_offset
,
1939 struct dwarf2_per_cu_data
*);
1941 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1943 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1944 enum language pretend_language
);
1946 static void process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
1948 static struct type
*dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
);
1949 static struct type
*dwarf2_per_cu_addr_sized_int_type
1950 (struct dwarf2_per_cu_data
*per_cu
, bool unsigned_p
);
1951 static struct type
*dwarf2_per_cu_int_type
1952 (struct dwarf2_per_cu_data
*per_cu
, int size_in_bytes
,
1955 /* Class, the destructor of which frees all allocated queue entries. This
1956 will only have work to do if an error was thrown while processing the
1957 dwarf. If no error was thrown then the queue entries should have all
1958 been processed, and freed, as we went along. */
1960 class dwarf2_queue_guard
1963 dwarf2_queue_guard () = default;
1965 /* Free any entries remaining on the queue. There should only be
1966 entries left if we hit an error while processing the dwarf. */
1967 ~dwarf2_queue_guard ()
1969 struct dwarf2_queue_item
*item
, *last
;
1971 item
= dwarf2_queue
;
1974 /* Anything still marked queued is likely to be in an
1975 inconsistent state, so discard it. */
1976 if (item
->per_cu
->queued
)
1978 if (item
->per_cu
->cu
!= NULL
)
1979 free_one_cached_comp_unit (item
->per_cu
);
1980 item
->per_cu
->queued
= 0;
1988 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
1992 /* The return type of find_file_and_directory. Note, the enclosed
1993 string pointers are only valid while this object is valid. */
1995 struct file_and_directory
1997 /* The filename. This is never NULL. */
2000 /* The compilation directory. NULL if not known. If we needed to
2001 compute a new string, this points to COMP_DIR_STORAGE, otherwise,
2002 points directly to the DW_AT_comp_dir string attribute owned by
2003 the obstack that owns the DIE. */
2004 const char *comp_dir
;
2006 /* If we needed to build a new string for comp_dir, this is what
2007 owns the storage. */
2008 std::string comp_dir_storage
;
2011 static file_and_directory
find_file_and_directory (struct die_info
*die
,
2012 struct dwarf2_cu
*cu
);
2014 static char *file_full_name (int file
, struct line_header
*lh
,
2015 const char *comp_dir
);
2017 /* Expected enum dwarf_unit_type for read_comp_unit_head. */
2018 enum class rcuh_kind
{ COMPILE
, TYPE
};
2020 static const gdb_byte
*read_and_check_comp_unit_head
2021 (struct dwarf2_per_objfile
* dwarf2_per_objfile
,
2022 struct comp_unit_head
*header
,
2023 struct dwarf2_section_info
*section
,
2024 struct dwarf2_section_info
*abbrev_section
, const gdb_byte
*info_ptr
,
2025 rcuh_kind section_kind
);
2027 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
2029 static htab_t
allocate_dwo_unit_table (struct objfile
*objfile
);
2031 static struct dwo_unit
*lookup_dwo_unit_in_dwp
2032 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
2033 struct dwp_file
*dwp_file
, const char *comp_dir
,
2034 ULONGEST signature
, int is_debug_types
);
2036 static struct dwp_file
*get_dwp_file
2037 (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2039 static struct dwo_unit
*lookup_dwo_comp_unit
2040 (struct dwarf2_per_cu_data
*, const char *, const char *, ULONGEST
);
2042 static struct dwo_unit
*lookup_dwo_type_unit
2043 (struct signatured_type
*, const char *, const char *);
2045 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*);
2047 /* A unique pointer to a dwo_file. */
2049 typedef std::unique_ptr
<struct dwo_file
> dwo_file_up
;
2051 static void process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
);
2053 static void check_producer (struct dwarf2_cu
*cu
);
2055 static void free_line_header_voidp (void *arg
);
2057 /* Various complaints about symbol reading that don't abort the process. */
2060 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
2062 complaint (_("statement list doesn't fit in .debug_line section"));
2066 dwarf2_debug_line_missing_file_complaint (void)
2068 complaint (_(".debug_line section has line data without a file"));
2072 dwarf2_debug_line_missing_end_sequence_complaint (void)
2074 complaint (_(".debug_line section has line "
2075 "program sequence without an end"));
2079 dwarf2_complex_location_expr_complaint (void)
2081 complaint (_("location expression too complex"));
2085 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
2088 complaint (_("const value length mismatch for '%s', got %d, expected %d"),
2093 dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info
*section
)
2095 complaint (_("debug info runs off end of %s section"
2097 get_section_name (section
),
2098 get_section_file_name (section
));
2102 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
2104 complaint (_("macro debug info contains a "
2105 "malformed macro definition:\n`%s'"),
2110 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
2112 complaint (_("invalid attribute class or form for '%s' in '%s'"),
2116 /* Hash function for line_header_hash. */
2119 line_header_hash (const struct line_header
*ofs
)
2121 return to_underlying (ofs
->sect_off
) ^ ofs
->offset_in_dwz
;
2124 /* Hash function for htab_create_alloc_ex for line_header_hash. */
2127 line_header_hash_voidp (const void *item
)
2129 const struct line_header
*ofs
= (const struct line_header
*) item
;
2131 return line_header_hash (ofs
);
2134 /* Equality function for line_header_hash. */
2137 line_header_eq_voidp (const void *item_lhs
, const void *item_rhs
)
2139 const struct line_header
*ofs_lhs
= (const struct line_header
*) item_lhs
;
2140 const struct line_header
*ofs_rhs
= (const struct line_header
*) item_rhs
;
2142 return (ofs_lhs
->sect_off
== ofs_rhs
->sect_off
2143 && ofs_lhs
->offset_in_dwz
== ofs_rhs
->offset_in_dwz
);
2148 /* Read the given attribute value as an address, taking the attribute's
2149 form into account. */
2152 attr_value_as_address (struct attribute
*attr
)
2156 if (attr
->form
!= DW_FORM_addr
&& attr
->form
!= DW_FORM_addrx
2157 && attr
->form
!= DW_FORM_GNU_addr_index
)
2159 /* Aside from a few clearly defined exceptions, attributes that
2160 contain an address must always be in DW_FORM_addr form.
2161 Unfortunately, some compilers happen to be violating this
2162 requirement by encoding addresses using other forms, such
2163 as DW_FORM_data4 for example. For those broken compilers,
2164 we try to do our best, without any guarantee of success,
2165 to interpret the address correctly. It would also be nice
2166 to generate a complaint, but that would require us to maintain
2167 a list of legitimate cases where a non-address form is allowed,
2168 as well as update callers to pass in at least the CU's DWARF
2169 version. This is more overhead than what we're willing to
2170 expand for a pretty rare case. */
2171 addr
= DW_UNSND (attr
);
2174 addr
= DW_ADDR (attr
);
2179 /* See declaration. */
2181 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile
*objfile_
,
2182 const dwarf2_debug_sections
*names
,
2184 : objfile (objfile_
),
2185 can_copy (can_copy_
)
2188 names
= &dwarf2_elf_names
;
2190 bfd
*obfd
= objfile
->obfd
;
2192 for (asection
*sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2193 locate_sections (obfd
, sec
, *names
);
2196 dwarf2_per_objfile::~dwarf2_per_objfile ()
2198 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
2199 free_cached_comp_units ();
2201 if (quick_file_names_table
)
2202 htab_delete (quick_file_names_table
);
2204 if (line_header_hash
)
2205 htab_delete (line_header_hash
);
2207 for (dwarf2_per_cu_data
*per_cu
: all_comp_units
)
2208 per_cu
->imported_symtabs_free ();
2210 for (signatured_type
*sig_type
: all_type_units
)
2211 sig_type
->per_cu
.imported_symtabs_free ();
2213 /* Everything else should be on the objfile obstack. */
2216 /* See declaration. */
2219 dwarf2_per_objfile::free_cached_comp_units ()
2221 dwarf2_per_cu_data
*per_cu
= read_in_chain
;
2222 dwarf2_per_cu_data
**last_chain
= &read_in_chain
;
2223 while (per_cu
!= NULL
)
2225 dwarf2_per_cu_data
*next_cu
= per_cu
->cu
->read_in_chain
;
2228 *last_chain
= next_cu
;
2233 /* A helper class that calls free_cached_comp_units on
2236 class free_cached_comp_units
2240 explicit free_cached_comp_units (dwarf2_per_objfile
*per_objfile
)
2241 : m_per_objfile (per_objfile
)
2245 ~free_cached_comp_units ()
2247 m_per_objfile
->free_cached_comp_units ();
2250 DISABLE_COPY_AND_ASSIGN (free_cached_comp_units
);
2254 dwarf2_per_objfile
*m_per_objfile
;
2257 /* Try to locate the sections we need for DWARF 2 debugging
2258 information and return true if we have enough to do something.
2259 NAMES points to the dwarf2 section names, or is NULL if the standard
2260 ELF names are used. CAN_COPY is true for formats where symbol
2261 interposition is possible and so symbol values must follow copy
2262 relocation rules. */
2265 dwarf2_has_info (struct objfile
*objfile
,
2266 const struct dwarf2_debug_sections
*names
,
2269 if (objfile
->flags
& OBJF_READNEVER
)
2272 struct dwarf2_per_objfile
*dwarf2_per_objfile
2273 = get_dwarf2_per_objfile (objfile
);
2275 if (dwarf2_per_objfile
== NULL
)
2276 dwarf2_per_objfile
= dwarf2_objfile_data_key
.emplace (objfile
, objfile
,
2280 return (!dwarf2_per_objfile
->info
.is_virtual
2281 && dwarf2_per_objfile
->info
.s
.section
!= NULL
2282 && !dwarf2_per_objfile
->abbrev
.is_virtual
2283 && dwarf2_per_objfile
->abbrev
.s
.section
!= NULL
);
2286 /* Return the containing section of virtual section SECTION. */
2288 static struct dwarf2_section_info
*
2289 get_containing_section (const struct dwarf2_section_info
*section
)
2291 gdb_assert (section
->is_virtual
);
2292 return section
->s
.containing_section
;
2295 /* Return the bfd owner of SECTION. */
2298 get_section_bfd_owner (const struct dwarf2_section_info
*section
)
2300 if (section
->is_virtual
)
2302 section
= get_containing_section (section
);
2303 gdb_assert (!section
->is_virtual
);
2305 return section
->s
.section
->owner
;
2308 /* Return the bfd section of SECTION.
2309 Returns NULL if the section is not present. */
2312 get_section_bfd_section (const struct dwarf2_section_info
*section
)
2314 if (section
->is_virtual
)
2316 section
= get_containing_section (section
);
2317 gdb_assert (!section
->is_virtual
);
2319 return section
->s
.section
;
2322 /* Return the name of SECTION. */
2325 get_section_name (const struct dwarf2_section_info
*section
)
2327 asection
*sectp
= get_section_bfd_section (section
);
2329 gdb_assert (sectp
!= NULL
);
2330 return bfd_section_name (sectp
);
2333 /* Return the name of the file SECTION is in. */
2336 get_section_file_name (const struct dwarf2_section_info
*section
)
2338 bfd
*abfd
= get_section_bfd_owner (section
);
2340 return bfd_get_filename (abfd
);
2343 /* Return the id of SECTION.
2344 Returns 0 if SECTION doesn't exist. */
2347 get_section_id (const struct dwarf2_section_info
*section
)
2349 asection
*sectp
= get_section_bfd_section (section
);
2356 /* Return the flags of SECTION.
2357 SECTION (or containing section if this is a virtual section) must exist. */
2360 get_section_flags (const struct dwarf2_section_info
*section
)
2362 asection
*sectp
= get_section_bfd_section (section
);
2364 gdb_assert (sectp
!= NULL
);
2365 return bfd_section_flags (sectp
);
2368 /* When loading sections, we look either for uncompressed section or for
2369 compressed section names. */
2372 section_is_p (const char *section_name
,
2373 const struct dwarf2_section_names
*names
)
2375 if (names
->normal
!= NULL
2376 && strcmp (section_name
, names
->normal
) == 0)
2378 if (names
->compressed
!= NULL
2379 && strcmp (section_name
, names
->compressed
) == 0)
2384 /* See declaration. */
2387 dwarf2_per_objfile::locate_sections (bfd
*abfd
, asection
*sectp
,
2388 const dwarf2_debug_sections
&names
)
2390 flagword aflag
= bfd_section_flags (sectp
);
2392 if ((aflag
& SEC_HAS_CONTENTS
) == 0)
2395 else if (elf_section_data (sectp
)->this_hdr
.sh_size
2396 > bfd_get_file_size (abfd
))
2398 bfd_size_type size
= elf_section_data (sectp
)->this_hdr
.sh_size
;
2399 warning (_("Discarding section %s which has a section size (%s"
2400 ") larger than the file size [in module %s]"),
2401 bfd_section_name (sectp
), phex_nz (size
, sizeof (size
)),
2402 bfd_get_filename (abfd
));
2404 else if (section_is_p (sectp
->name
, &names
.info
))
2406 this->info
.s
.section
= sectp
;
2407 this->info
.size
= bfd_section_size (sectp
);
2409 else if (section_is_p (sectp
->name
, &names
.abbrev
))
2411 this->abbrev
.s
.section
= sectp
;
2412 this->abbrev
.size
= bfd_section_size (sectp
);
2414 else if (section_is_p (sectp
->name
, &names
.line
))
2416 this->line
.s
.section
= sectp
;
2417 this->line
.size
= bfd_section_size (sectp
);
2419 else if (section_is_p (sectp
->name
, &names
.loc
))
2421 this->loc
.s
.section
= sectp
;
2422 this->loc
.size
= bfd_section_size (sectp
);
2424 else if (section_is_p (sectp
->name
, &names
.loclists
))
2426 this->loclists
.s
.section
= sectp
;
2427 this->loclists
.size
= bfd_section_size (sectp
);
2429 else if (section_is_p (sectp
->name
, &names
.macinfo
))
2431 this->macinfo
.s
.section
= sectp
;
2432 this->macinfo
.size
= bfd_section_size (sectp
);
2434 else if (section_is_p (sectp
->name
, &names
.macro
))
2436 this->macro
.s
.section
= sectp
;
2437 this->macro
.size
= bfd_section_size (sectp
);
2439 else if (section_is_p (sectp
->name
, &names
.str
))
2441 this->str
.s
.section
= sectp
;
2442 this->str
.size
= bfd_section_size (sectp
);
2444 else if (section_is_p (sectp
->name
, &names
.str_offsets
))
2446 this->str_offsets
.s
.section
= sectp
;
2447 this->str_offsets
.size
= bfd_section_size (sectp
);
2449 else if (section_is_p (sectp
->name
, &names
.line_str
))
2451 this->line_str
.s
.section
= sectp
;
2452 this->line_str
.size
= bfd_section_size (sectp
);
2454 else if (section_is_p (sectp
->name
, &names
.addr
))
2456 this->addr
.s
.section
= sectp
;
2457 this->addr
.size
= bfd_section_size (sectp
);
2459 else if (section_is_p (sectp
->name
, &names
.frame
))
2461 this->frame
.s
.section
= sectp
;
2462 this->frame
.size
= bfd_section_size (sectp
);
2464 else if (section_is_p (sectp
->name
, &names
.eh_frame
))
2466 this->eh_frame
.s
.section
= sectp
;
2467 this->eh_frame
.size
= bfd_section_size (sectp
);
2469 else if (section_is_p (sectp
->name
, &names
.ranges
))
2471 this->ranges
.s
.section
= sectp
;
2472 this->ranges
.size
= bfd_section_size (sectp
);
2474 else if (section_is_p (sectp
->name
, &names
.rnglists
))
2476 this->rnglists
.s
.section
= sectp
;
2477 this->rnglists
.size
= bfd_section_size (sectp
);
2479 else if (section_is_p (sectp
->name
, &names
.types
))
2481 struct dwarf2_section_info type_section
;
2483 memset (&type_section
, 0, sizeof (type_section
));
2484 type_section
.s
.section
= sectp
;
2485 type_section
.size
= bfd_section_size (sectp
);
2487 this->types
.push_back (type_section
);
2489 else if (section_is_p (sectp
->name
, &names
.gdb_index
))
2491 this->gdb_index
.s
.section
= sectp
;
2492 this->gdb_index
.size
= bfd_section_size (sectp
);
2494 else if (section_is_p (sectp
->name
, &names
.debug_names
))
2496 this->debug_names
.s
.section
= sectp
;
2497 this->debug_names
.size
= bfd_section_size (sectp
);
2499 else if (section_is_p (sectp
->name
, &names
.debug_aranges
))
2501 this->debug_aranges
.s
.section
= sectp
;
2502 this->debug_aranges
.size
= bfd_section_size (sectp
);
2505 if ((bfd_section_flags (sectp
) & (SEC_LOAD
| SEC_ALLOC
))
2506 && bfd_section_vma (sectp
) == 0)
2507 this->has_section_at_zero
= true;
2510 /* A helper function that decides whether a section is empty,
2514 dwarf2_section_empty_p (const struct dwarf2_section_info
*section
)
2516 if (section
->is_virtual
)
2517 return section
->size
== 0;
2518 return section
->s
.section
== NULL
|| section
->size
== 0;
2521 /* See dwarf2read.h. */
2524 dwarf2_read_section (struct objfile
*objfile
, dwarf2_section_info
*info
)
2528 gdb_byte
*buf
, *retbuf
;
2532 info
->buffer
= NULL
;
2533 info
->readin
= true;
2535 if (dwarf2_section_empty_p (info
))
2538 sectp
= get_section_bfd_section (info
);
2540 /* If this is a virtual section we need to read in the real one first. */
2541 if (info
->is_virtual
)
2543 struct dwarf2_section_info
*containing_section
=
2544 get_containing_section (info
);
2546 gdb_assert (sectp
!= NULL
);
2547 if ((sectp
->flags
& SEC_RELOC
) != 0)
2549 error (_("Dwarf Error: DWP format V2 with relocations is not"
2550 " supported in section %s [in module %s]"),
2551 get_section_name (info
), get_section_file_name (info
));
2553 dwarf2_read_section (objfile
, containing_section
);
2554 /* Other code should have already caught virtual sections that don't
2556 gdb_assert (info
->virtual_offset
+ info
->size
2557 <= containing_section
->size
);
2558 /* If the real section is empty or there was a problem reading the
2559 section we shouldn't get here. */
2560 gdb_assert (containing_section
->buffer
!= NULL
);
2561 info
->buffer
= containing_section
->buffer
+ info
->virtual_offset
;
2565 /* If the section has relocations, we must read it ourselves.
2566 Otherwise we attach it to the BFD. */
2567 if ((sectp
->flags
& SEC_RELOC
) == 0)
2569 info
->buffer
= gdb_bfd_map_section (sectp
, &info
->size
);
2573 buf
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
2576 /* When debugging .o files, we may need to apply relocations; see
2577 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
2578 We never compress sections in .o files, so we only need to
2579 try this when the section is not compressed. */
2580 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
2583 info
->buffer
= retbuf
;
2587 abfd
= get_section_bfd_owner (info
);
2588 gdb_assert (abfd
!= NULL
);
2590 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
2591 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
2593 error (_("Dwarf Error: Can't read DWARF data"
2594 " in section %s [in module %s]"),
2595 bfd_section_name (sectp
), bfd_get_filename (abfd
));
2599 /* A helper function that returns the size of a section in a safe way.
2600 If you are positive that the section has been read before using the
2601 size, then it is safe to refer to the dwarf2_section_info object's
2602 "size" field directly. In other cases, you must call this
2603 function, because for compressed sections the size field is not set
2604 correctly until the section has been read. */
2606 static bfd_size_type
2607 dwarf2_section_size (struct objfile
*objfile
,
2608 struct dwarf2_section_info
*info
)
2611 dwarf2_read_section (objfile
, info
);
2615 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
2619 dwarf2_get_section_info (struct objfile
*objfile
,
2620 enum dwarf2_section_enum sect
,
2621 asection
**sectp
, const gdb_byte
**bufp
,
2622 bfd_size_type
*sizep
)
2624 struct dwarf2_per_objfile
*data
= dwarf2_objfile_data_key
.get (objfile
);
2625 struct dwarf2_section_info
*info
;
2627 /* We may see an objfile without any DWARF, in which case we just
2638 case DWARF2_DEBUG_FRAME
:
2639 info
= &data
->frame
;
2641 case DWARF2_EH_FRAME
:
2642 info
= &data
->eh_frame
;
2645 gdb_assert_not_reached ("unexpected section");
2648 dwarf2_read_section (objfile
, info
);
2650 *sectp
= get_section_bfd_section (info
);
2651 *bufp
= info
->buffer
;
2652 *sizep
= info
->size
;
2655 /* A helper function to find the sections for a .dwz file. */
2658 locate_dwz_sections (bfd
*abfd
, asection
*sectp
, void *arg
)
2660 struct dwz_file
*dwz_file
= (struct dwz_file
*) arg
;
2662 /* Note that we only support the standard ELF names, because .dwz
2663 is ELF-only (at the time of writing). */
2664 if (section_is_p (sectp
->name
, &dwarf2_elf_names
.abbrev
))
2666 dwz_file
->abbrev
.s
.section
= sectp
;
2667 dwz_file
->abbrev
.size
= bfd_section_size (sectp
);
2669 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.info
))
2671 dwz_file
->info
.s
.section
= sectp
;
2672 dwz_file
->info
.size
= bfd_section_size (sectp
);
2674 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.str
))
2676 dwz_file
->str
.s
.section
= sectp
;
2677 dwz_file
->str
.size
= bfd_section_size (sectp
);
2679 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.line
))
2681 dwz_file
->line
.s
.section
= sectp
;
2682 dwz_file
->line
.size
= bfd_section_size (sectp
);
2684 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.macro
))
2686 dwz_file
->macro
.s
.section
= sectp
;
2687 dwz_file
->macro
.size
= bfd_section_size (sectp
);
2689 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.gdb_index
))
2691 dwz_file
->gdb_index
.s
.section
= sectp
;
2692 dwz_file
->gdb_index
.size
= bfd_section_size (sectp
);
2694 else if (section_is_p (sectp
->name
, &dwarf2_elf_names
.debug_names
))
2696 dwz_file
->debug_names
.s
.section
= sectp
;
2697 dwz_file
->debug_names
.size
= bfd_section_size (sectp
);
2701 /* See dwarf2read.h. */
2704 dwarf2_get_dwz_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
2706 const char *filename
;
2707 bfd_size_type buildid_len_arg
;
2711 if (dwarf2_per_objfile
->dwz_file
!= NULL
)
2712 return dwarf2_per_objfile
->dwz_file
.get ();
2714 bfd_set_error (bfd_error_no_error
);
2715 gdb::unique_xmalloc_ptr
<char> data
2716 (bfd_get_alt_debug_link_info (dwarf2_per_objfile
->objfile
->obfd
,
2717 &buildid_len_arg
, &buildid
));
2720 if (bfd_get_error () == bfd_error_no_error
)
2722 error (_("could not read '.gnu_debugaltlink' section: %s"),
2723 bfd_errmsg (bfd_get_error ()));
2726 gdb::unique_xmalloc_ptr
<bfd_byte
> buildid_holder (buildid
);
2728 buildid_len
= (size_t) buildid_len_arg
;
2730 filename
= data
.get ();
2732 std::string abs_storage
;
2733 if (!IS_ABSOLUTE_PATH (filename
))
2735 gdb::unique_xmalloc_ptr
<char> abs
2736 = gdb_realpath (objfile_name (dwarf2_per_objfile
->objfile
));
2738 abs_storage
= ldirname (abs
.get ()) + SLASH_STRING
+ filename
;
2739 filename
= abs_storage
.c_str ();
2742 /* First try the file name given in the section. If that doesn't
2743 work, try to use the build-id instead. */
2744 gdb_bfd_ref_ptr
dwz_bfd (gdb_bfd_open (filename
, gnutarget
, -1));
2745 if (dwz_bfd
!= NULL
)
2747 if (!build_id_verify (dwz_bfd
.get (), buildid_len
, buildid
))
2748 dwz_bfd
.reset (nullptr);
2751 if (dwz_bfd
== NULL
)
2752 dwz_bfd
= build_id_to_debug_bfd (buildid_len
, buildid
);
2754 if (dwz_bfd
== NULL
)
2755 error (_("could not find '.gnu_debugaltlink' file for %s"),
2756 objfile_name (dwarf2_per_objfile
->objfile
));
2758 std::unique_ptr
<struct dwz_file
> result
2759 (new struct dwz_file (std::move (dwz_bfd
)));
2761 bfd_map_over_sections (result
->dwz_bfd
.get (), locate_dwz_sections
,
2764 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
,
2765 result
->dwz_bfd
.get ());
2766 dwarf2_per_objfile
->dwz_file
= std::move (result
);
2767 return dwarf2_per_objfile
->dwz_file
.get ();
2770 /* DWARF quick_symbols_functions support. */
2772 /* TUs can share .debug_line entries, and there can be a lot more TUs than
2773 unique line tables, so we maintain a separate table of all .debug_line
2774 derived entries to support the sharing.
2775 All the quick functions need is the list of file names. We discard the
2776 line_header when we're done and don't need to record it here. */
2777 struct quick_file_names
2779 /* The data used to construct the hash key. */
2780 struct stmt_list_hash hash
;
2782 /* The number of entries in file_names, real_names. */
2783 unsigned int num_file_names
;
2785 /* The file names from the line table, after being run through
2787 const char **file_names
;
2789 /* The file names from the line table after being run through
2790 gdb_realpath. These are computed lazily. */
2791 const char **real_names
;
2794 /* When using the index (and thus not using psymtabs), each CU has an
2795 object of this type. This is used to hold information needed by
2796 the various "quick" methods. */
2797 struct dwarf2_per_cu_quick_data
2799 /* The file table. This can be NULL if there was no file table
2800 or it's currently not read in.
2801 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
2802 struct quick_file_names
*file_names
;
2804 /* The corresponding symbol table. This is NULL if symbols for this
2805 CU have not yet been read. */
2806 struct compunit_symtab
*compunit_symtab
;
2808 /* A temporary mark bit used when iterating over all CUs in
2809 expand_symtabs_matching. */
2810 unsigned int mark
: 1;
2812 /* True if we've tried to read the file table and found there isn't one.
2813 There will be no point in trying to read it again next time. */
2814 unsigned int no_file_data
: 1;
2817 /* Utility hash function for a stmt_list_hash. */
2820 hash_stmt_list_entry (const struct stmt_list_hash
*stmt_list_hash
)
2824 if (stmt_list_hash
->dwo_unit
!= NULL
)
2825 v
+= (uintptr_t) stmt_list_hash
->dwo_unit
->dwo_file
;
2826 v
+= to_underlying (stmt_list_hash
->line_sect_off
);
2830 /* Utility equality function for a stmt_list_hash. */
2833 eq_stmt_list_entry (const struct stmt_list_hash
*lhs
,
2834 const struct stmt_list_hash
*rhs
)
2836 if ((lhs
->dwo_unit
!= NULL
) != (rhs
->dwo_unit
!= NULL
))
2838 if (lhs
->dwo_unit
!= NULL
2839 && lhs
->dwo_unit
->dwo_file
!= rhs
->dwo_unit
->dwo_file
)
2842 return lhs
->line_sect_off
== rhs
->line_sect_off
;
2845 /* Hash function for a quick_file_names. */
2848 hash_file_name_entry (const void *e
)
2850 const struct quick_file_names
*file_data
2851 = (const struct quick_file_names
*) e
;
2853 return hash_stmt_list_entry (&file_data
->hash
);
2856 /* Equality function for a quick_file_names. */
2859 eq_file_name_entry (const void *a
, const void *b
)
2861 const struct quick_file_names
*ea
= (const struct quick_file_names
*) a
;
2862 const struct quick_file_names
*eb
= (const struct quick_file_names
*) b
;
2864 return eq_stmt_list_entry (&ea
->hash
, &eb
->hash
);
2867 /* Delete function for a quick_file_names. */
2870 delete_file_name_entry (void *e
)
2872 struct quick_file_names
*file_data
= (struct quick_file_names
*) e
;
2875 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2877 xfree ((void*) file_data
->file_names
[i
]);
2878 if (file_data
->real_names
)
2879 xfree ((void*) file_data
->real_names
[i
]);
2882 /* The space for the struct itself lives on objfile_obstack,
2883 so we don't free it here. */
2886 /* Create a quick_file_names hash table. */
2889 create_quick_file_names_table (unsigned int nr_initial_entries
)
2891 return htab_create_alloc (nr_initial_entries
,
2892 hash_file_name_entry
, eq_file_name_entry
,
2893 delete_file_name_entry
, xcalloc
, xfree
);
2896 /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would
2897 have to be created afterwards. You should call age_cached_comp_units after
2898 processing PER_CU->CU. dw2_setup must have been already called. */
2901 load_cu (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2903 if (per_cu
->is_debug_types
)
2904 load_full_type_unit (per_cu
);
2906 load_full_comp_unit (per_cu
, skip_partial
, language_minimal
);
2908 if (per_cu
->cu
== NULL
)
2909 return; /* Dummy CU. */
2911 dwarf2_find_base_address (per_cu
->cu
->dies
, per_cu
->cu
);
2914 /* Read in the symbols for PER_CU. */
2917 dw2_do_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2919 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2921 /* Skip type_unit_groups, reading the type units they contain
2922 is handled elsewhere. */
2923 if (IS_TYPE_UNIT_GROUP (per_cu
))
2926 /* The destructor of dwarf2_queue_guard frees any entries left on
2927 the queue. After this point we're guaranteed to leave this function
2928 with the dwarf queue empty. */
2929 dwarf2_queue_guard q_guard
;
2931 if (dwarf2_per_objfile
->using_index
2932 ? per_cu
->v
.quick
->compunit_symtab
== NULL
2933 : (per_cu
->v
.psymtab
== NULL
|| !per_cu
->v
.psymtab
->readin
))
2935 queue_comp_unit (per_cu
, language_minimal
);
2936 load_cu (per_cu
, skip_partial
);
2938 /* If we just loaded a CU from a DWO, and we're working with an index
2939 that may badly handle TUs, load all the TUs in that DWO as well.
2940 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
2941 if (!per_cu
->is_debug_types
2942 && per_cu
->cu
!= NULL
2943 && per_cu
->cu
->dwo_unit
!= NULL
2944 && dwarf2_per_objfile
->index_table
!= NULL
2945 && dwarf2_per_objfile
->index_table
->version
<= 7
2946 /* DWP files aren't supported yet. */
2947 && get_dwp_file (dwarf2_per_objfile
) == NULL
)
2948 queue_and_load_all_dwo_tus (per_cu
);
2951 process_queue (dwarf2_per_objfile
);
2953 /* Age the cache, releasing compilation units that have not
2954 been used recently. */
2955 age_cached_comp_units (dwarf2_per_objfile
);
2958 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
2959 the objfile from which this CU came. Returns the resulting symbol
2962 static struct compunit_symtab
*
2963 dw2_instantiate_symtab (struct dwarf2_per_cu_data
*per_cu
, bool skip_partial
)
2965 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
2967 gdb_assert (dwarf2_per_objfile
->using_index
);
2968 if (!per_cu
->v
.quick
->compunit_symtab
)
2970 free_cached_comp_units
freer (dwarf2_per_objfile
);
2971 scoped_restore decrementer
= increment_reading_symtab ();
2972 dw2_do_instantiate_symtab (per_cu
, skip_partial
);
2973 process_cu_includes (dwarf2_per_objfile
);
2976 return per_cu
->v
.quick
->compunit_symtab
;
2979 /* See declaration. */
2981 dwarf2_per_cu_data
*
2982 dwarf2_per_objfile::get_cutu (int index
)
2984 if (index
>= this->all_comp_units
.size ())
2986 index
-= this->all_comp_units
.size ();
2987 gdb_assert (index
< this->all_type_units
.size ());
2988 return &this->all_type_units
[index
]->per_cu
;
2991 return this->all_comp_units
[index
];
2994 /* See declaration. */
2996 dwarf2_per_cu_data
*
2997 dwarf2_per_objfile::get_cu (int index
)
2999 gdb_assert (index
>= 0 && index
< this->all_comp_units
.size ());
3001 return this->all_comp_units
[index
];
3004 /* See declaration. */
3007 dwarf2_per_objfile::get_tu (int index
)
3009 gdb_assert (index
>= 0 && index
< this->all_type_units
.size ());
3011 return this->all_type_units
[index
];
3014 /* Return a new dwarf2_per_cu_data allocated on OBJFILE's
3015 objfile_obstack, and constructed with the specified field
3018 static dwarf2_per_cu_data
*
3019 create_cu_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3020 struct dwarf2_section_info
*section
,
3022 sect_offset sect_off
, ULONGEST length
)
3024 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3025 dwarf2_per_cu_data
*the_cu
3026 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3027 struct dwarf2_per_cu_data
);
3028 the_cu
->sect_off
= sect_off
;
3029 the_cu
->length
= length
;
3030 the_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3031 the_cu
->section
= section
;
3032 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3033 struct dwarf2_per_cu_quick_data
);
3034 the_cu
->is_dwz
= is_dwz
;
3038 /* A helper for create_cus_from_index that handles a given list of
3042 create_cus_from_index_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3043 const gdb_byte
*cu_list
, offset_type n_elements
,
3044 struct dwarf2_section_info
*section
,
3047 for (offset_type i
= 0; i
< n_elements
; i
+= 2)
3049 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3051 sect_offset sect_off
3052 = (sect_offset
) extract_unsigned_integer (cu_list
, 8, BFD_ENDIAN_LITTLE
);
3053 ULONGEST length
= extract_unsigned_integer (cu_list
+ 8, 8, BFD_ENDIAN_LITTLE
);
3056 dwarf2_per_cu_data
*per_cu
3057 = create_cu_from_index_list (dwarf2_per_objfile
, section
, is_dwz
,
3059 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
3063 /* Read the CU list from the mapped index, and use it to create all
3064 the CU objects for this objfile. */
3067 create_cus_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3068 const gdb_byte
*cu_list
, offset_type cu_list_elements
,
3069 const gdb_byte
*dwz_list
, offset_type dwz_elements
)
3071 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
3072 dwarf2_per_objfile
->all_comp_units
.reserve
3073 ((cu_list_elements
+ dwz_elements
) / 2);
3075 create_cus_from_index_list (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3076 &dwarf2_per_objfile
->info
, 0);
3078 if (dwz_elements
== 0)
3081 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3082 create_cus_from_index_list (dwarf2_per_objfile
, dwz_list
, dwz_elements
,
3086 /* Create the signatured type hash table from the index. */
3089 create_signatured_type_table_from_index
3090 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3091 struct dwarf2_section_info
*section
,
3092 const gdb_byte
*bytes
,
3093 offset_type elements
)
3095 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3097 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3098 dwarf2_per_objfile
->all_type_units
.reserve (elements
/ 3);
3100 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3102 for (offset_type i
= 0; i
< elements
; i
+= 3)
3104 struct signatured_type
*sig_type
;
3107 cu_offset type_offset_in_tu
;
3109 gdb_static_assert (sizeof (ULONGEST
) >= 8);
3110 sect_offset sect_off
3111 = (sect_offset
) extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
3113 = (cu_offset
) extract_unsigned_integer (bytes
+ 8, 8,
3115 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
3118 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3119 struct signatured_type
);
3120 sig_type
->signature
= signature
;
3121 sig_type
->type_offset_in_tu
= type_offset_in_tu
;
3122 sig_type
->per_cu
.is_debug_types
= 1;
3123 sig_type
->per_cu
.section
= section
;
3124 sig_type
->per_cu
.sect_off
= sect_off
;
3125 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3126 sig_type
->per_cu
.v
.quick
3127 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3128 struct dwarf2_per_cu_quick_data
);
3130 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3133 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3136 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3139 /* Create the signatured type hash table from .debug_names. */
3142 create_signatured_type_table_from_debug_names
3143 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3144 const mapped_debug_names
&map
,
3145 struct dwarf2_section_info
*section
,
3146 struct dwarf2_section_info
*abbrev_section
)
3148 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3150 dwarf2_read_section (objfile
, section
);
3151 dwarf2_read_section (objfile
, abbrev_section
);
3153 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
3154 dwarf2_per_objfile
->all_type_units
.reserve (map
.tu_count
);
3156 htab_t sig_types_hash
= allocate_signatured_type_table (objfile
);
3158 for (uint32_t i
= 0; i
< map
.tu_count
; ++i
)
3160 struct signatured_type
*sig_type
;
3163 sect_offset sect_off
3164 = (sect_offset
) (extract_unsigned_integer
3165 (map
.tu_table_reordered
+ i
* map
.offset_size
,
3167 map
.dwarf5_byte_order
));
3169 comp_unit_head cu_header
;
3170 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
3172 section
->buffer
+ to_underlying (sect_off
),
3175 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3176 struct signatured_type
);
3177 sig_type
->signature
= cu_header
.signature
;
3178 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
3179 sig_type
->per_cu
.is_debug_types
= 1;
3180 sig_type
->per_cu
.section
= section
;
3181 sig_type
->per_cu
.sect_off
= sect_off
;
3182 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
3183 sig_type
->per_cu
.v
.quick
3184 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
3185 struct dwarf2_per_cu_quick_data
);
3187 slot
= htab_find_slot (sig_types_hash
, sig_type
, INSERT
);
3190 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
3193 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
3196 /* Read the address map data from the mapped index, and use it to
3197 populate the objfile's psymtabs_addrmap. */
3200 create_addrmap_from_index (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3201 struct mapped_index
*index
)
3203 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3204 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3205 const gdb_byte
*iter
, *end
;
3206 struct addrmap
*mutable_map
;
3209 auto_obstack temp_obstack
;
3211 mutable_map
= addrmap_create_mutable (&temp_obstack
);
3213 iter
= index
->address_table
.data ();
3214 end
= iter
+ index
->address_table
.size ();
3216 baseaddr
= objfile
->text_section_offset ();
3220 ULONGEST hi
, lo
, cu_index
;
3221 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3223 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
3225 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
3230 complaint (_(".gdb_index address table has invalid range (%s - %s)"),
3231 hex_string (lo
), hex_string (hi
));
3235 if (cu_index
>= dwarf2_per_objfile
->all_comp_units
.size ())
3237 complaint (_(".gdb_index address table has invalid CU number %u"),
3238 (unsigned) cu_index
);
3242 lo
= gdbarch_adjust_dwarf2_addr (gdbarch
, lo
+ baseaddr
) - baseaddr
;
3243 hi
= gdbarch_adjust_dwarf2_addr (gdbarch
, hi
+ baseaddr
) - baseaddr
;
3244 addrmap_set_empty (mutable_map
, lo
, hi
- 1,
3245 dwarf2_per_objfile
->get_cu (cu_index
));
3248 objfile
->partial_symtabs
->psymtabs_addrmap
3249 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3252 /* Read the address map data from DWARF-5 .debug_aranges, and use it to
3253 populate the objfile's psymtabs_addrmap. */
3256 create_addrmap_from_aranges (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3257 struct dwarf2_section_info
*section
)
3259 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3260 bfd
*abfd
= objfile
->obfd
;
3261 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3262 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
3264 auto_obstack temp_obstack
;
3265 addrmap
*mutable_map
= addrmap_create_mutable (&temp_obstack
);
3267 std::unordered_map
<sect_offset
,
3268 dwarf2_per_cu_data
*,
3269 gdb::hash_enum
<sect_offset
>>
3270 debug_info_offset_to_per_cu
;
3271 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3273 const auto insertpair
3274 = debug_info_offset_to_per_cu
.emplace (per_cu
->sect_off
, per_cu
);
3275 if (!insertpair
.second
)
3277 warning (_("Section .debug_aranges in %s has duplicate "
3278 "debug_info_offset %s, ignoring .debug_aranges."),
3279 objfile_name (objfile
), sect_offset_str (per_cu
->sect_off
));
3284 dwarf2_read_section (objfile
, section
);
3286 const bfd_endian dwarf5_byte_order
= gdbarch_byte_order (gdbarch
);
3288 const gdb_byte
*addr
= section
->buffer
;
3290 while (addr
< section
->buffer
+ section
->size
)
3292 const gdb_byte
*const entry_addr
= addr
;
3293 unsigned int bytes_read
;
3295 const LONGEST entry_length
= read_initial_length (abfd
, addr
,
3299 const gdb_byte
*const entry_end
= addr
+ entry_length
;
3300 const bool dwarf5_is_dwarf64
= bytes_read
!= 4;
3301 const uint8_t offset_size
= dwarf5_is_dwarf64
? 8 : 4;
3302 if (addr
+ entry_length
> section
->buffer
+ section
->size
)
3304 warning (_("Section .debug_aranges in %s entry at offset %s "
3305 "length %s exceeds section length %s, "
3306 "ignoring .debug_aranges."),
3307 objfile_name (objfile
),
3308 plongest (entry_addr
- section
->buffer
),
3309 plongest (bytes_read
+ entry_length
),
3310 pulongest (section
->size
));
3314 /* The version number. */
3315 const uint16_t version
= read_2_bytes (abfd
, addr
);
3319 warning (_("Section .debug_aranges in %s entry at offset %s "
3320 "has unsupported version %d, ignoring .debug_aranges."),
3321 objfile_name (objfile
),
3322 plongest (entry_addr
- section
->buffer
), version
);
3326 const uint64_t debug_info_offset
3327 = extract_unsigned_integer (addr
, offset_size
, dwarf5_byte_order
);
3328 addr
+= offset_size
;
3329 const auto per_cu_it
3330 = debug_info_offset_to_per_cu
.find (sect_offset (debug_info_offset
));
3331 if (per_cu_it
== debug_info_offset_to_per_cu
.cend ())
3333 warning (_("Section .debug_aranges in %s entry at offset %s "
3334 "debug_info_offset %s does not exists, "
3335 "ignoring .debug_aranges."),
3336 objfile_name (objfile
),
3337 plongest (entry_addr
- section
->buffer
),
3338 pulongest (debug_info_offset
));
3341 dwarf2_per_cu_data
*const per_cu
= per_cu_it
->second
;
3343 const uint8_t address_size
= *addr
++;
3344 if (address_size
< 1 || address_size
> 8)
3346 warning (_("Section .debug_aranges in %s entry at offset %s "
3347 "address_size %u is invalid, ignoring .debug_aranges."),
3348 objfile_name (objfile
),
3349 plongest (entry_addr
- section
->buffer
), address_size
);
3353 const uint8_t segment_selector_size
= *addr
++;
3354 if (segment_selector_size
!= 0)
3356 warning (_("Section .debug_aranges in %s entry at offset %s "
3357 "segment_selector_size %u is not supported, "
3358 "ignoring .debug_aranges."),
3359 objfile_name (objfile
),
3360 plongest (entry_addr
- section
->buffer
),
3361 segment_selector_size
);
3365 /* Must pad to an alignment boundary that is twice the address
3366 size. It is undocumented by the DWARF standard but GCC does
3368 for (size_t padding
= ((-(addr
- section
->buffer
))
3369 & (2 * address_size
- 1));
3370 padding
> 0; padding
--)
3373 warning (_("Section .debug_aranges in %s entry at offset %s "
3374 "padding is not zero, ignoring .debug_aranges."),
3375 objfile_name (objfile
),
3376 plongest (entry_addr
- section
->buffer
));
3382 if (addr
+ 2 * address_size
> entry_end
)
3384 warning (_("Section .debug_aranges in %s entry at offset %s "
3385 "address list is not properly terminated, "
3386 "ignoring .debug_aranges."),
3387 objfile_name (objfile
),
3388 plongest (entry_addr
- section
->buffer
));
3391 ULONGEST start
= extract_unsigned_integer (addr
, address_size
,
3393 addr
+= address_size
;
3394 ULONGEST length
= extract_unsigned_integer (addr
, address_size
,
3396 addr
+= address_size
;
3397 if (start
== 0 && length
== 0)
3399 if (start
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3401 /* Symbol was eliminated due to a COMDAT group. */
3404 ULONGEST end
= start
+ length
;
3405 start
= (gdbarch_adjust_dwarf2_addr (gdbarch
, start
+ baseaddr
)
3407 end
= (gdbarch_adjust_dwarf2_addr (gdbarch
, end
+ baseaddr
)
3409 addrmap_set_empty (mutable_map
, start
, end
- 1, per_cu
);
3413 objfile
->partial_symtabs
->psymtabs_addrmap
3414 = addrmap_create_fixed (mutable_map
, objfile
->partial_symtabs
->obstack ());
3417 /* Find a slot in the mapped index INDEX for the object named NAME.
3418 If NAME is found, set *VEC_OUT to point to the CU vector in the
3419 constant pool and return true. If NAME cannot be found, return
3423 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
3424 offset_type
**vec_out
)
3427 offset_type slot
, step
;
3428 int (*cmp
) (const char *, const char *);
3430 gdb::unique_xmalloc_ptr
<char> without_params
;
3431 if (current_language
->la_language
== language_cplus
3432 || current_language
->la_language
== language_fortran
3433 || current_language
->la_language
== language_d
)
3435 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
3438 if (strchr (name
, '(') != NULL
)
3440 without_params
= cp_remove_params (name
);
3442 if (without_params
!= NULL
)
3443 name
= without_params
.get ();
3447 /* Index version 4 did not support case insensitive searches. But the
3448 indices for case insensitive languages are built in lowercase, therefore
3449 simulate our NAME being searched is also lowercased. */
3450 hash
= mapped_index_string_hash ((index
->version
== 4
3451 && case_sensitivity
== case_sensitive_off
3452 ? 5 : index
->version
),
3455 slot
= hash
& (index
->symbol_table
.size () - 1);
3456 step
= ((hash
* 17) & (index
->symbol_table
.size () - 1)) | 1;
3457 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
3463 const auto &bucket
= index
->symbol_table
[slot
];
3464 if (bucket
.name
== 0 && bucket
.vec
== 0)
3467 str
= index
->constant_pool
+ MAYBE_SWAP (bucket
.name
);
3468 if (!cmp (name
, str
))
3470 *vec_out
= (offset_type
*) (index
->constant_pool
3471 + MAYBE_SWAP (bucket
.vec
));
3475 slot
= (slot
+ step
) & (index
->symbol_table
.size () - 1);
3479 /* A helper function that reads the .gdb_index from BUFFER and fills
3480 in MAP. FILENAME is the name of the file containing the data;
3481 it is used for error reporting. DEPRECATED_OK is true if it is
3482 ok to use deprecated sections.
3484 CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are
3485 out parameters that are filled in with information about the CU and
3486 TU lists in the section.
3488 Returns true if all went well, false otherwise. */
3491 read_gdb_index_from_buffer (struct objfile
*objfile
,
3492 const char *filename
,
3494 gdb::array_view
<const gdb_byte
> buffer
,
3495 struct mapped_index
*map
,
3496 const gdb_byte
**cu_list
,
3497 offset_type
*cu_list_elements
,
3498 const gdb_byte
**types_list
,
3499 offset_type
*types_list_elements
)
3501 const gdb_byte
*addr
= &buffer
[0];
3503 /* Version check. */
3504 offset_type version
= MAYBE_SWAP (*(offset_type
*) addr
);
3505 /* Versions earlier than 3 emitted every copy of a psymbol. This
3506 causes the index to behave very poorly for certain requests. Version 3
3507 contained incomplete addrmap. So, it seems better to just ignore such
3511 static int warning_printed
= 0;
3512 if (!warning_printed
)
3514 warning (_("Skipping obsolete .gdb_index section in %s."),
3516 warning_printed
= 1;
3520 /* Index version 4 uses a different hash function than index version
3523 Versions earlier than 6 did not emit psymbols for inlined
3524 functions. Using these files will cause GDB not to be able to
3525 set breakpoints on inlined functions by name, so we ignore these
3526 indices unless the user has done
3527 "set use-deprecated-index-sections on". */
3528 if (version
< 6 && !deprecated_ok
)
3530 static int warning_printed
= 0;
3531 if (!warning_printed
)
3534 Skipping deprecated .gdb_index section in %s.\n\
3535 Do \"set use-deprecated-index-sections on\" before the file is read\n\
3536 to use the section anyway."),
3538 warning_printed
= 1;
3542 /* Version 7 indices generated by gold refer to the CU for a symbol instead
3543 of the TU (for symbols coming from TUs),
3544 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
3545 Plus gold-generated indices can have duplicate entries for global symbols,
3546 http://sourceware.org/bugzilla/show_bug.cgi?id=15646.
3547 These are just performance bugs, and we can't distinguish gdb-generated
3548 indices from gold-generated ones, so issue no warning here. */
3550 /* Indexes with higher version than the one supported by GDB may be no
3551 longer backward compatible. */
3555 map
->version
= version
;
3557 offset_type
*metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
3560 *cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3561 *cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
3565 *types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
3566 *types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
3567 - MAYBE_SWAP (metadata
[i
]))
3571 const gdb_byte
*address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3572 const gdb_byte
*address_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3574 = gdb::array_view
<const gdb_byte
> (address_table
, address_table_end
);
3577 const gdb_byte
*symbol_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
3578 const gdb_byte
*symbol_table_end
= addr
+ MAYBE_SWAP (metadata
[i
+ 1]);
3580 = gdb::array_view
<mapped_index::symbol_table_slot
>
3581 ((mapped_index::symbol_table_slot
*) symbol_table
,
3582 (mapped_index::symbol_table_slot
*) symbol_table_end
);
3585 map
->constant_pool
= (char *) (addr
+ MAYBE_SWAP (metadata
[i
]));
3590 /* Callback types for dwarf2_read_gdb_index. */
3592 typedef gdb::function_view
3593 <gdb::array_view
<const gdb_byte
>(objfile
*, dwarf2_per_objfile
*)>
3594 get_gdb_index_contents_ftype
;
3595 typedef gdb::function_view
3596 <gdb::array_view
<const gdb_byte
>(objfile
*, dwz_file
*)>
3597 get_gdb_index_contents_dwz_ftype
;
3599 /* Read .gdb_index. If everything went ok, initialize the "quick"
3600 elements of all the CUs and return 1. Otherwise, return 0. */
3603 dwarf2_read_gdb_index
3604 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3605 get_gdb_index_contents_ftype get_gdb_index_contents
,
3606 get_gdb_index_contents_dwz_ftype get_gdb_index_contents_dwz
)
3608 const gdb_byte
*cu_list
, *types_list
, *dwz_list
= NULL
;
3609 offset_type cu_list_elements
, types_list_elements
, dwz_list_elements
= 0;
3610 struct dwz_file
*dwz
;
3611 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3613 gdb::array_view
<const gdb_byte
> main_index_contents
3614 = get_gdb_index_contents (objfile
, dwarf2_per_objfile
);
3616 if (main_index_contents
.empty ())
3619 std::unique_ptr
<struct mapped_index
> map (new struct mapped_index
);
3620 if (!read_gdb_index_from_buffer (objfile
, objfile_name (objfile
),
3621 use_deprecated_index_sections
,
3622 main_index_contents
, map
.get (), &cu_list
,
3623 &cu_list_elements
, &types_list
,
3624 &types_list_elements
))
3627 /* Don't use the index if it's empty. */
3628 if (map
->symbol_table
.empty ())
3631 /* If there is a .dwz file, read it so we can get its CU list as
3633 dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
3636 struct mapped_index dwz_map
;
3637 const gdb_byte
*dwz_types_ignore
;
3638 offset_type dwz_types_elements_ignore
;
3640 gdb::array_view
<const gdb_byte
> dwz_index_content
3641 = get_gdb_index_contents_dwz (objfile
, dwz
);
3643 if (dwz_index_content
.empty ())
3646 if (!read_gdb_index_from_buffer (objfile
,
3647 bfd_get_filename (dwz
->dwz_bfd
.get ()),
3648 1, dwz_index_content
, &dwz_map
,
3649 &dwz_list
, &dwz_list_elements
,
3651 &dwz_types_elements_ignore
))
3653 warning (_("could not read '.gdb_index' section from %s; skipping"),
3654 bfd_get_filename (dwz
->dwz_bfd
.get ()));
3659 create_cus_from_index (dwarf2_per_objfile
, cu_list
, cu_list_elements
,
3660 dwz_list
, dwz_list_elements
);
3662 if (types_list_elements
)
3664 /* We can only handle a single .debug_types when we have an
3666 if (dwarf2_per_objfile
->types
.size () != 1)
3669 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
3671 create_signatured_type_table_from_index (dwarf2_per_objfile
, section
,
3672 types_list
, types_list_elements
);
3675 create_addrmap_from_index (dwarf2_per_objfile
, map
.get ());
3677 dwarf2_per_objfile
->index_table
= std::move (map
);
3678 dwarf2_per_objfile
->using_index
= 1;
3679 dwarf2_per_objfile
->quick_file_names_table
=
3680 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
3685 /* die_reader_func for dw2_get_file_names. */
3688 dw2_get_file_names_reader (const struct die_reader_specs
*reader
,
3689 const gdb_byte
*info_ptr
,
3690 struct die_info
*comp_unit_die
,
3693 struct dwarf2_cu
*cu
= reader
->cu
;
3694 struct dwarf2_per_cu_data
*this_cu
= cu
->per_cu
;
3695 struct dwarf2_per_objfile
*dwarf2_per_objfile
3696 = cu
->per_cu
->dwarf2_per_objfile
;
3697 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
3698 struct dwarf2_per_cu_data
*lh_cu
;
3699 struct attribute
*attr
;
3701 struct quick_file_names
*qfn
;
3703 gdb_assert (! this_cu
->is_debug_types
);
3705 /* Our callers never want to match partial units -- instead they
3706 will match the enclosing full CU. */
3707 if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3709 this_cu
->v
.quick
->no_file_data
= 1;
3717 sect_offset line_offset
{};
3719 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, cu
);
3720 if (attr
!= nullptr)
3722 struct quick_file_names find_entry
;
3724 line_offset
= (sect_offset
) DW_UNSND (attr
);
3726 /* We may have already read in this line header (TU line header sharing).
3727 If we have we're done. */
3728 find_entry
.hash
.dwo_unit
= cu
->dwo_unit
;
3729 find_entry
.hash
.line_sect_off
= line_offset
;
3730 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
3731 &find_entry
, INSERT
);
3734 lh_cu
->v
.quick
->file_names
= (struct quick_file_names
*) *slot
;
3738 lh
= dwarf_decode_line_header (line_offset
, cu
);
3742 lh_cu
->v
.quick
->no_file_data
= 1;
3746 qfn
= XOBNEW (&objfile
->objfile_obstack
, struct quick_file_names
);
3747 qfn
->hash
.dwo_unit
= cu
->dwo_unit
;
3748 qfn
->hash
.line_sect_off
= line_offset
;
3749 gdb_assert (slot
!= NULL
);
3752 file_and_directory fnd
= find_file_and_directory (comp_unit_die
, cu
);
3755 if (strcmp (fnd
.name
, "<unknown>") != 0)
3758 qfn
->num_file_names
= offset
+ lh
->file_names_size ();
3760 XOBNEWVEC (&objfile
->objfile_obstack
, const char *, qfn
->num_file_names
);
3762 qfn
->file_names
[0] = xstrdup (fnd
.name
);
3763 for (int i
= 0; i
< lh
->file_names_size (); ++i
)
3764 qfn
->file_names
[i
+ offset
] = file_full_name (i
+ 1, lh
.get (), fnd
.comp_dir
);
3765 qfn
->real_names
= NULL
;
3767 lh_cu
->v
.quick
->file_names
= qfn
;
3770 /* A helper for the "quick" functions which attempts to read the line
3771 table for THIS_CU. */
3773 static struct quick_file_names
*
3774 dw2_get_file_names (struct dwarf2_per_cu_data
*this_cu
)
3776 /* This should never be called for TUs. */
3777 gdb_assert (! this_cu
->is_debug_types
);
3778 /* Nor type unit groups. */
3779 gdb_assert (! IS_TYPE_UNIT_GROUP (this_cu
));
3781 if (this_cu
->v
.quick
->file_names
!= NULL
)
3782 return this_cu
->v
.quick
->file_names
;
3783 /* If we know there is no line data, no point in looking again. */
3784 if (this_cu
->v
.quick
->no_file_data
)
3787 cutu_reader
reader (this_cu
);
3788 if (!reader
.dummy_p
)
3789 dw2_get_file_names_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
3790 reader
.has_children
);
3792 if (this_cu
->v
.quick
->no_file_data
)
3794 return this_cu
->v
.quick
->file_names
;
3797 /* A helper for the "quick" functions which computes and caches the
3798 real path for a given file name from the line table. */
3801 dw2_get_real_path (struct objfile
*objfile
,
3802 struct quick_file_names
*qfn
, int index
)
3804 if (qfn
->real_names
== NULL
)
3805 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
3806 qfn
->num_file_names
, const char *);
3808 if (qfn
->real_names
[index
] == NULL
)
3809 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]).release ();
3811 return qfn
->real_names
[index
];
3814 static struct symtab
*
3815 dw2_find_last_source_symtab (struct objfile
*objfile
)
3817 struct dwarf2_per_objfile
*dwarf2_per_objfile
3818 = get_dwarf2_per_objfile (objfile
);
3819 dwarf2_per_cu_data
*dwarf_cu
= dwarf2_per_objfile
->all_comp_units
.back ();
3820 compunit_symtab
*cust
= dw2_instantiate_symtab (dwarf_cu
, false);
3825 return compunit_primary_filetab (cust
);
3828 /* Traversal function for dw2_forget_cached_source_info. */
3831 dw2_free_cached_file_names (void **slot
, void *info
)
3833 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
3835 if (file_data
->real_names
)
3839 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
3841 xfree ((void*) file_data
->real_names
[i
]);
3842 file_data
->real_names
[i
] = NULL
;
3850 dw2_forget_cached_source_info (struct objfile
*objfile
)
3852 struct dwarf2_per_objfile
*dwarf2_per_objfile
3853 = get_dwarf2_per_objfile (objfile
);
3855 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
3856 dw2_free_cached_file_names
, NULL
);
3859 /* Helper function for dw2_map_symtabs_matching_filename that expands
3860 the symtabs and calls the iterator. */
3863 dw2_map_expand_apply (struct objfile
*objfile
,
3864 struct dwarf2_per_cu_data
*per_cu
,
3865 const char *name
, const char *real_path
,
3866 gdb::function_view
<bool (symtab
*)> callback
)
3868 struct compunit_symtab
*last_made
= objfile
->compunit_symtabs
;
3870 /* Don't visit already-expanded CUs. */
3871 if (per_cu
->v
.quick
->compunit_symtab
)
3874 /* This may expand more than one symtab, and we want to iterate over
3876 dw2_instantiate_symtab (per_cu
, false);
3878 return iterate_over_some_symtabs (name
, real_path
, objfile
->compunit_symtabs
,
3879 last_made
, callback
);
3882 /* Implementation of the map_symtabs_matching_filename method. */
3885 dw2_map_symtabs_matching_filename
3886 (struct objfile
*objfile
, const char *name
, const char *real_path
,
3887 gdb::function_view
<bool (symtab
*)> callback
)
3889 const char *name_basename
= lbasename (name
);
3890 struct dwarf2_per_objfile
*dwarf2_per_objfile
3891 = get_dwarf2_per_objfile (objfile
);
3893 /* The rule is CUs specify all the files, including those used by
3894 any TU, so there's no need to scan TUs here. */
3896 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
3898 /* We only need to look at symtabs not already expanded. */
3899 if (per_cu
->v
.quick
->compunit_symtab
)
3902 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
3903 if (file_data
== NULL
)
3906 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
3908 const char *this_name
= file_data
->file_names
[j
];
3909 const char *this_real_name
;
3911 if (compare_filenames_for_search (this_name
, name
))
3913 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3919 /* Before we invoke realpath, which can get expensive when many
3920 files are involved, do a quick comparison of the basenames. */
3921 if (! basenames_may_differ
3922 && FILENAME_CMP (lbasename (this_name
), name_basename
) != 0)
3925 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
3926 if (compare_filenames_for_search (this_real_name
, name
))
3928 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3934 if (real_path
!= NULL
)
3936 gdb_assert (IS_ABSOLUTE_PATH (real_path
));
3937 gdb_assert (IS_ABSOLUTE_PATH (name
));
3938 if (this_real_name
!= NULL
3939 && FILENAME_CMP (real_path
, this_real_name
) == 0)
3941 if (dw2_map_expand_apply (objfile
, per_cu
, name
, real_path
,
3953 /* Struct used to manage iterating over all CUs looking for a symbol. */
3955 struct dw2_symtab_iterator
3957 /* The dwarf2_per_objfile owning the CUs we are iterating on. */
3958 struct dwarf2_per_objfile
*dwarf2_per_objfile
;
3959 /* If set, only look for symbols that match that block. Valid values are
3960 GLOBAL_BLOCK and STATIC_BLOCK. */
3961 gdb::optional
<block_enum
> block_index
;
3962 /* The kind of symbol we're looking for. */
3964 /* The list of CUs from the index entry of the symbol,
3965 or NULL if not found. */
3967 /* The next element in VEC to look at. */
3969 /* The number of elements in VEC, or zero if there is no match. */
3971 /* Have we seen a global version of the symbol?
3972 If so we can ignore all further global instances.
3973 This is to work around gold/15646, inefficient gold-generated
3978 /* Initialize the index symtab iterator ITER. */
3981 dw2_symtab_iter_init (struct dw2_symtab_iterator
*iter
,
3982 struct dwarf2_per_objfile
*dwarf2_per_objfile
,
3983 gdb::optional
<block_enum
> block_index
,
3987 iter
->dwarf2_per_objfile
= dwarf2_per_objfile
;
3988 iter
->block_index
= block_index
;
3989 iter
->domain
= domain
;
3991 iter
->global_seen
= 0;
3993 mapped_index
*index
= dwarf2_per_objfile
->index_table
.get ();
3995 /* index is NULL if OBJF_READNOW. */
3996 if (index
!= NULL
&& find_slot_in_mapped_hash (index
, name
, &iter
->vec
))
3997 iter
->length
= MAYBE_SWAP (*iter
->vec
);
4005 /* Return the next matching CU or NULL if there are no more. */
4007 static struct dwarf2_per_cu_data
*
4008 dw2_symtab_iter_next (struct dw2_symtab_iterator
*iter
)
4010 struct dwarf2_per_objfile
*dwarf2_per_objfile
= iter
->dwarf2_per_objfile
;
4012 for ( ; iter
->next
< iter
->length
; ++iter
->next
)
4014 offset_type cu_index_and_attrs
=
4015 MAYBE_SWAP (iter
->vec
[iter
->next
+ 1]);
4016 offset_type cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
4017 gdb_index_symbol_kind symbol_kind
=
4018 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
4019 /* Only check the symbol attributes if they're present.
4020 Indices prior to version 7 don't record them,
4021 and indices >= 7 may elide them for certain symbols
4022 (gold does this). */
4024 (dwarf2_per_objfile
->index_table
->version
>= 7
4025 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
4027 /* Don't crash on bad data. */
4028 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
4029 + dwarf2_per_objfile
->all_type_units
.size ()))
4031 complaint (_(".gdb_index entry has bad CU index"
4033 objfile_name (dwarf2_per_objfile
->objfile
));
4037 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
4039 /* Skip if already read in. */
4040 if (per_cu
->v
.quick
->compunit_symtab
)
4043 /* Check static vs global. */
4046 bool is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
4048 if (iter
->block_index
.has_value ())
4050 bool want_static
= *iter
->block_index
== STATIC_BLOCK
;
4052 if (is_static
!= want_static
)
4056 /* Work around gold/15646. */
4057 if (!is_static
&& iter
->global_seen
)
4060 iter
->global_seen
= 1;
4063 /* Only check the symbol's kind if it has one. */
4066 switch (iter
->domain
)
4069 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
4070 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
4071 /* Some types are also in VAR_DOMAIN. */
4072 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4076 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
4080 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4084 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
4099 static struct compunit_symtab
*
4100 dw2_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
4101 const char *name
, domain_enum domain
)
4103 struct compunit_symtab
*stab_best
= NULL
;
4104 struct dwarf2_per_objfile
*dwarf2_per_objfile
4105 = get_dwarf2_per_objfile (objfile
);
4107 lookup_name_info
lookup_name (name
, symbol_name_match_type::FULL
);
4109 struct dw2_symtab_iterator iter
;
4110 struct dwarf2_per_cu_data
*per_cu
;
4112 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, block_index
, domain
, name
);
4114 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4116 struct symbol
*sym
, *with_opaque
= NULL
;
4117 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
4118 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
4119 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
4121 sym
= block_find_symbol (block
, name
, domain
,
4122 block_find_non_opaque_type_preferred
,
4125 /* Some caution must be observed with overloaded functions
4126 and methods, since the index will not contain any overload
4127 information (but NAME might contain it). */
4130 && SYMBOL_MATCHES_SEARCH_NAME (sym
, lookup_name
))
4132 if (with_opaque
!= NULL
4133 && SYMBOL_MATCHES_SEARCH_NAME (with_opaque
, lookup_name
))
4136 /* Keep looking through other CUs. */
4143 dw2_print_stats (struct objfile
*objfile
)
4145 struct dwarf2_per_objfile
*dwarf2_per_objfile
4146 = get_dwarf2_per_objfile (objfile
);
4147 int total
= (dwarf2_per_objfile
->all_comp_units
.size ()
4148 + dwarf2_per_objfile
->all_type_units
.size ());
4151 for (int i
= 0; i
< total
; ++i
)
4153 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4155 if (!per_cu
->v
.quick
->compunit_symtab
)
4158 printf_filtered (_(" Number of read CUs: %d\n"), total
- count
);
4159 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
4162 /* This dumps minimal information about the index.
4163 It is called via "mt print objfiles".
4164 One use is to verify .gdb_index has been loaded by the
4165 gdb.dwarf2/gdb-index.exp testcase. */
4168 dw2_dump (struct objfile
*objfile
)
4170 struct dwarf2_per_objfile
*dwarf2_per_objfile
4171 = get_dwarf2_per_objfile (objfile
);
4173 gdb_assert (dwarf2_per_objfile
->using_index
);
4174 printf_filtered (".gdb_index:");
4175 if (dwarf2_per_objfile
->index_table
!= NULL
)
4177 printf_filtered (" version %d\n",
4178 dwarf2_per_objfile
->index_table
->version
);
4181 printf_filtered (" faked for \"readnow\"\n");
4182 printf_filtered ("\n");
4186 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
4187 const char *func_name
)
4189 struct dwarf2_per_objfile
*dwarf2_per_objfile
4190 = get_dwarf2_per_objfile (objfile
);
4192 struct dw2_symtab_iterator iter
;
4193 struct dwarf2_per_cu_data
*per_cu
;
4195 dw2_symtab_iter_init (&iter
, dwarf2_per_objfile
, {}, VAR_DOMAIN
, func_name
);
4197 while ((per_cu
= dw2_symtab_iter_next (&iter
)) != NULL
)
4198 dw2_instantiate_symtab (per_cu
, false);
4203 dw2_expand_all_symtabs (struct objfile
*objfile
)
4205 struct dwarf2_per_objfile
*dwarf2_per_objfile
4206 = get_dwarf2_per_objfile (objfile
);
4207 int total_units
= (dwarf2_per_objfile
->all_comp_units
.size ()
4208 + dwarf2_per_objfile
->all_type_units
.size ());
4210 for (int i
= 0; i
< total_units
; ++i
)
4212 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
4214 /* We don't want to directly expand a partial CU, because if we
4215 read it with the wrong language, then assertion failures can
4216 be triggered later on. See PR symtab/23010. So, tell
4217 dw2_instantiate_symtab to skip partial CUs -- any important
4218 partial CU will be read via DW_TAG_imported_unit anyway. */
4219 dw2_instantiate_symtab (per_cu
, true);
4224 dw2_expand_symtabs_with_fullname (struct objfile
*objfile
,
4225 const char *fullname
)
4227 struct dwarf2_per_objfile
*dwarf2_per_objfile
4228 = get_dwarf2_per_objfile (objfile
);
4230 /* We don't need to consider type units here.
4231 This is only called for examining code, e.g. expand_line_sal.
4232 There can be an order of magnitude (or more) more type units
4233 than comp units, and we avoid them if we can. */
4235 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
4237 /* We only need to look at symtabs not already expanded. */
4238 if (per_cu
->v
.quick
->compunit_symtab
)
4241 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
4242 if (file_data
== NULL
)
4245 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
4247 const char *this_fullname
= file_data
->file_names
[j
];
4249 if (filename_cmp (this_fullname
, fullname
) == 0)
4251 dw2_instantiate_symtab (per_cu
, false);
4259 dw2_map_matching_symbols
4260 (struct objfile
*objfile
,
4261 const lookup_name_info
&name
, domain_enum domain
,
4263 gdb::function_view
<symbol_found_callback_ftype
> callback
,
4264 symbol_compare_ftype
*ordered_compare
)
4266 /* Currently unimplemented; used for Ada. The function can be called if the
4267 current language is Ada for a non-Ada objfile using GNU index. As Ada
4268 does not look for non-Ada symbols this function should just return. */
4271 /* Starting from a search name, return the string that finds the upper
4272 bound of all strings that start with SEARCH_NAME in a sorted name
4273 list. Returns the empty string to indicate that the upper bound is
4274 the end of the list. */
4277 make_sort_after_prefix_name (const char *search_name
)
4279 /* When looking to complete "func", we find the upper bound of all
4280 symbols that start with "func" by looking for where we'd insert
4281 the closest string that would follow "func" in lexicographical
4282 order. Usually, that's "func"-with-last-character-incremented,
4283 i.e. "fund". Mind non-ASCII characters, though. Usually those
4284 will be UTF-8 multi-byte sequences, but we can't be certain.
4285 Especially mind the 0xff character, which is a valid character in
4286 non-UTF-8 source character sets (e.g. Latin1 'ÿ'), and we can't
4287 rule out compilers allowing it in identifiers. Note that
4288 conveniently, strcmp/strcasecmp are specified to compare
4289 characters interpreted as unsigned char. So what we do is treat
4290 the whole string as a base 256 number composed of a sequence of
4291 base 256 "digits" and add 1 to it. I.e., adding 1 to 0xff wraps
4292 to 0, and carries 1 to the following more-significant position.
4293 If the very first character in SEARCH_NAME ends up incremented
4294 and carries/overflows, then the upper bound is the end of the
4295 list. The string after the empty string is also the empty
4298 Some examples of this operation:
4300 SEARCH_NAME => "+1" RESULT
4304 "\xff" "a" "\xff" => "\xff" "b"
4309 Then, with these symbols for example:
4315 completing "func" looks for symbols between "func" and
4316 "func"-with-last-character-incremented, i.e. "fund" (exclusive),
4317 which finds "func" and "func1", but not "fund".
4321 funcÿ (Latin1 'ÿ' [0xff])
4325 completing "funcÿ" looks for symbols between "funcÿ" and "fund"
4326 (exclusive), which finds "funcÿ" and "funcÿ1", but not "fund".
4330 ÿÿ (Latin1 'ÿ' [0xff])
4333 completing "ÿ" or "ÿÿ" looks for symbols between between "ÿÿ" and
4334 the end of the list.
4336 std::string after
= search_name
;
4337 while (!after
.empty () && (unsigned char) after
.back () == 0xff)
4339 if (!after
.empty ())
4340 after
.back () = (unsigned char) after
.back () + 1;
4344 /* See declaration. */
4346 std::pair
<std::vector
<name_component
>::const_iterator
,
4347 std::vector
<name_component
>::const_iterator
>
4348 mapped_index_base::find_name_components_bounds
4349 (const lookup_name_info
&lookup_name_without_params
, language lang
) const
4352 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4354 const char *lang_name
4355 = lookup_name_without_params
.language_lookup_name (lang
).c_str ();
4357 /* Comparison function object for lower_bound that matches against a
4358 given symbol name. */
4359 auto lookup_compare_lower
= [&] (const name_component
&elem
,
4362 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4363 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4364 return name_cmp (elem_name
, name
) < 0;
4367 /* Comparison function object for upper_bound that matches against a
4368 given symbol name. */
4369 auto lookup_compare_upper
= [&] (const char *name
,
4370 const name_component
&elem
)
4372 const char *elem_qualified
= this->symbol_name_at (elem
.idx
);
4373 const char *elem_name
= elem_qualified
+ elem
.name_offset
;
4374 return name_cmp (name
, elem_name
) < 0;
4377 auto begin
= this->name_components
.begin ();
4378 auto end
= this->name_components
.end ();
4380 /* Find the lower bound. */
4383 if (lookup_name_without_params
.completion_mode () && lang_name
[0] == '\0')
4386 return std::lower_bound (begin
, end
, lang_name
, lookup_compare_lower
);
4389 /* Find the upper bound. */
4392 if (lookup_name_without_params
.completion_mode ())
4394 /* In completion mode, we want UPPER to point past all
4395 symbols names that have the same prefix. I.e., with
4396 these symbols, and completing "func":
4398 function << lower bound
4400 other_function << upper bound
4402 We find the upper bound by looking for the insertion
4403 point of "func"-with-last-character-incremented,
4405 std::string after
= make_sort_after_prefix_name (lang_name
);
4408 return std::lower_bound (lower
, end
, after
.c_str (),
4409 lookup_compare_lower
);
4412 return std::upper_bound (lower
, end
, lang_name
, lookup_compare_upper
);
4415 return {lower
, upper
};
4418 /* See declaration. */
4421 mapped_index_base::build_name_components ()
4423 if (!this->name_components
.empty ())
4426 this->name_components_casing
= case_sensitivity
;
4428 = this->name_components_casing
== case_sensitive_on
? strcmp
: strcasecmp
;
4430 /* The code below only knows how to break apart components of C++
4431 symbol names (and other languages that use '::' as
4432 namespace/module separator) and Ada symbol names. */
4433 auto count
= this->symbol_name_count ();
4434 for (offset_type idx
= 0; idx
< count
; idx
++)
4436 if (this->symbol_name_slot_invalid (idx
))
4439 const char *name
= this->symbol_name_at (idx
);
4441 /* Add each name component to the name component table. */
4442 unsigned int previous_len
= 0;
4444 if (strstr (name
, "::") != nullptr)
4446 for (unsigned int current_len
= cp_find_first_component (name
);
4447 name
[current_len
] != '\0';
4448 current_len
+= cp_find_first_component (name
+ current_len
))
4450 gdb_assert (name
[current_len
] == ':');
4451 this->name_components
.push_back ({previous_len
, idx
});
4452 /* Skip the '::'. */
4454 previous_len
= current_len
;
4459 /* Handle the Ada encoded (aka mangled) form here. */
4460 for (const char *iter
= strstr (name
, "__");
4462 iter
= strstr (iter
, "__"))
4464 this->name_components
.push_back ({previous_len
, idx
});
4466 previous_len
= iter
- name
;
4470 this->name_components
.push_back ({previous_len
, idx
});
4473 /* Sort name_components elements by name. */
4474 auto name_comp_compare
= [&] (const name_component
&left
,
4475 const name_component
&right
)
4477 const char *left_qualified
= this->symbol_name_at (left
.idx
);
4478 const char *right_qualified
= this->symbol_name_at (right
.idx
);
4480 const char *left_name
= left_qualified
+ left
.name_offset
;
4481 const char *right_name
= right_qualified
+ right
.name_offset
;
4483 return name_cmp (left_name
, right_name
) < 0;
4486 std::sort (this->name_components
.begin (),
4487 this->name_components
.end (),
4491 /* Helper for dw2_expand_symtabs_matching that works with a
4492 mapped_index_base instead of the containing objfile. This is split
4493 to a separate function in order to be able to unit test the
4494 name_components matching using a mock mapped_index_base. For each
4495 symbol name that matches, calls MATCH_CALLBACK, passing it the
4496 symbol's index in the mapped_index_base symbol table. */
4499 dw2_expand_symtabs_matching_symbol
4500 (mapped_index_base
&index
,
4501 const lookup_name_info
&lookup_name_in
,
4502 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
4503 enum search_domain kind
,
4504 gdb::function_view
<bool (offset_type
)> match_callback
)
4506 lookup_name_info lookup_name_without_params
4507 = lookup_name_in
.make_ignore_params ();
4509 /* Build the symbol name component sorted vector, if we haven't
4511 index
.build_name_components ();
4513 /* The same symbol may appear more than once in the range though.
4514 E.g., if we're looking for symbols that complete "w", and we have
4515 a symbol named "w1::w2", we'll find the two name components for
4516 that same symbol in the range. To be sure we only call the
4517 callback once per symbol, we first collect the symbol name
4518 indexes that matched in a temporary vector and ignore
4520 std::vector
<offset_type
> matches
;
4522 struct name_and_matcher
4524 symbol_name_matcher_ftype
*matcher
;
4525 const std::string
&name
;
4527 bool operator== (const name_and_matcher
&other
) const
4529 return matcher
== other
.matcher
&& name
== other
.name
;
4533 /* A vector holding all the different symbol name matchers, for all
4535 std::vector
<name_and_matcher
> matchers
;
4537 for (int i
= 0; i
< nr_languages
; i
++)
4539 enum language lang_e
= (enum language
) i
;
4541 const language_defn
*lang
= language_def (lang_e
);
4542 symbol_name_matcher_ftype
*name_matcher
4543 = get_symbol_name_matcher (lang
, lookup_name_without_params
);
4545 name_and_matcher key
{
4547 lookup_name_without_params
.language_lookup_name (lang_e
)
4550 /* Don't insert the same comparison routine more than once.
4551 Note that we do this linear walk. This is not a problem in
4552 practice because the number of supported languages is
4554 if (std::find (matchers
.begin (), matchers
.end (), key
)
4557 matchers
.push_back (std::move (key
));
4560 = index
.find_name_components_bounds (lookup_name_without_params
,
4563 /* Now for each symbol name in range, check to see if we have a name
4564 match, and if so, call the MATCH_CALLBACK callback. */
4566 for (; bounds
.first
!= bounds
.second
; ++bounds
.first
)
4568 const char *qualified
= index
.symbol_name_at (bounds
.first
->idx
);
4570 if (!name_matcher (qualified
, lookup_name_without_params
, NULL
)
4571 || (symbol_matcher
!= NULL
&& !symbol_matcher (qualified
)))
4574 matches
.push_back (bounds
.first
->idx
);
4578 std::sort (matches
.begin (), matches
.end ());
4580 /* Finally call the callback, once per match. */
4582 for (offset_type idx
: matches
)
4586 if (!match_callback (idx
))
4592 /* Above we use a type wider than idx's for 'prev', since 0 and
4593 (offset_type)-1 are both possible values. */
4594 static_assert (sizeof (prev
) > sizeof (offset_type
), "");
4599 namespace selftests
{ namespace dw2_expand_symtabs_matching
{
4601 /* A mock .gdb_index/.debug_names-like name index table, enough to
4602 exercise dw2_expand_symtabs_matching_symbol, which works with the
4603 mapped_index_base interface. Builds an index from the symbol list
4604 passed as parameter to the constructor. */
4605 class mock_mapped_index
: public mapped_index_base
4608 mock_mapped_index (gdb::array_view
<const char *> symbols
)
4609 : m_symbol_table (symbols
)
4612 DISABLE_COPY_AND_ASSIGN (mock_mapped_index
);
4614 /* Return the number of names in the symbol table. */
4615 size_t symbol_name_count () const override
4617 return m_symbol_table
.size ();
4620 /* Get the name of the symbol at IDX in the symbol table. */
4621 const char *symbol_name_at (offset_type idx
) const override
4623 return m_symbol_table
[idx
];
4627 gdb::array_view
<const char *> m_symbol_table
;
4630 /* Convenience function that converts a NULL pointer to a "<null>"
4631 string, to pass to print routines. */
4634 string_or_null (const char *str
)
4636 return str
!= NULL
? str
: "<null>";
4639 /* Check if a lookup_name_info built from
4640 NAME/MATCH_TYPE/COMPLETION_MODE matches the symbols in the mock
4641 index. EXPECTED_LIST is the list of expected matches, in expected
4642 matching order. If no match expected, then an empty list is
4643 specified. Returns true on success. On failure prints a warning
4644 indicating the file:line that failed, and returns false. */
4647 check_match (const char *file
, int line
,
4648 mock_mapped_index
&mock_index
,
4649 const char *name
, symbol_name_match_type match_type
,
4650 bool completion_mode
,
4651 std::initializer_list
<const char *> expected_list
)
4653 lookup_name_info
lookup_name (name
, match_type
, completion_mode
);
4655 bool matched
= true;
4657 auto mismatch
= [&] (const char *expected_str
,
4660 warning (_("%s:%d: match_type=%s, looking-for=\"%s\", "
4661 "expected=\"%s\", got=\"%s\"\n"),
4663 (match_type
== symbol_name_match_type::FULL
4665 name
, string_or_null (expected_str
), string_or_null (got
));
4669 auto expected_it
= expected_list
.begin ();
4670 auto expected_end
= expected_list
.end ();
4672 dw2_expand_symtabs_matching_symbol (mock_index
, lookup_name
,
4674 [&] (offset_type idx
)
4676 const char *matched_name
= mock_index
.symbol_name_at (idx
);
4677 const char *expected_str
4678 = expected_it
== expected_end
? NULL
: *expected_it
++;
4680 if (expected_str
== NULL
|| strcmp (expected_str
, matched_name
) != 0)
4681 mismatch (expected_str
, matched_name
);
4685 const char *expected_str
4686 = expected_it
== expected_end
? NULL
: *expected_it
++;
4687 if (expected_str
!= NULL
)
4688 mismatch (expected_str
, NULL
);
4693 /* The symbols added to the mock mapped_index for testing (in
4695 static const char *test_symbols
[] = {
4704 "ns2::tmpl<int>::foo2",
4705 "(anonymous namespace)::A::B::C",
4707 /* These are used to check that the increment-last-char in the
4708 matching algorithm for completion doesn't match "t1_fund" when
4709 completing "t1_func". */
4715 /* A UTF-8 name with multi-byte sequences to make sure that
4716 cp-name-parser understands this as a single identifier ("função"
4717 is "function" in PT). */
4720 /* \377 (0xff) is Latin1 'ÿ'. */
4723 /* \377 (0xff) is Latin1 'ÿ'. */
4727 /* A name with all sorts of complications. Starts with "z" to make
4728 it easier for the completion tests below. */
4729 #define Z_SYM_NAME \
4730 "z::std::tuple<(anonymous namespace)::ui*, std::bar<(anonymous namespace)::ui> >" \
4731 "::tuple<(anonymous namespace)::ui*, " \
4732 "std::default_delete<(anonymous namespace)::ui>, void>"
4737 /* Returns true if the mapped_index_base::find_name_component_bounds
4738 method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME,
4739 in completion mode. */
4742 check_find_bounds_finds (mapped_index_base
&index
,
4743 const char *search_name
,
4744 gdb::array_view
<const char *> expected_syms
)
4746 lookup_name_info
lookup_name (search_name
,
4747 symbol_name_match_type::FULL
, true);
4749 auto bounds
= index
.find_name_components_bounds (lookup_name
,
4752 size_t distance
= std::distance (bounds
.first
, bounds
.second
);
4753 if (distance
!= expected_syms
.size ())
4756 for (size_t exp_elem
= 0; exp_elem
< distance
; exp_elem
++)
4758 auto nc_elem
= bounds
.first
+ exp_elem
;
4759 const char *qualified
= index
.symbol_name_at (nc_elem
->idx
);
4760 if (strcmp (qualified
, expected_syms
[exp_elem
]) != 0)
4767 /* Test the lower-level mapped_index::find_name_component_bounds
4771 test_mapped_index_find_name_component_bounds ()
4773 mock_mapped_index
mock_index (test_symbols
);
4775 mock_index
.build_name_components ();
4777 /* Test the lower-level mapped_index::find_name_component_bounds
4778 method in completion mode. */
4780 static const char *expected_syms
[] = {
4785 SELF_CHECK (check_find_bounds_finds (mock_index
,
4786 "t1_func", expected_syms
));
4789 /* Check that the increment-last-char in the name matching algorithm
4790 for completion doesn't get confused with Ansi1 'ÿ' / 0xff. */
4792 static const char *expected_syms1
[] = {
4796 SELF_CHECK (check_find_bounds_finds (mock_index
,
4797 "\377", expected_syms1
));
4799 static const char *expected_syms2
[] = {
4802 SELF_CHECK (check_find_bounds_finds (mock_index
,
4803 "\377\377", expected_syms2
));
4807 /* Test dw2_expand_symtabs_matching_symbol. */
4810 test_dw2_expand_symtabs_matching_symbol ()
4812 mock_mapped_index
mock_index (test_symbols
);
4814 /* We let all tests run until the end even if some fails, for debug
4816 bool any_mismatch
= false;
4818 /* Create the expected symbols list (an initializer_list). Needed
4819 because lists have commas, and we need to pass them to CHECK,
4820 which is a macro. */
4821 #define EXPECT(...) { __VA_ARGS__ }
4823 /* Wrapper for check_match that passes down the current
4824 __FILE__/__LINE__. */
4825 #define CHECK_MATCH(NAME, MATCH_TYPE, COMPLETION_MODE, EXPECTED_LIST) \
4826 any_mismatch |= !check_match (__FILE__, __LINE__, \
4828 NAME, MATCH_TYPE, COMPLETION_MODE, \
4831 /* Identity checks. */
4832 for (const char *sym
: test_symbols
)
4834 /* Should be able to match all existing symbols. */
4835 CHECK_MATCH (sym
, symbol_name_match_type::FULL
, false,
4838 /* Should be able to match all existing symbols with
4840 std::string with_params
= std::string (sym
) + "(int)";
4841 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4844 /* Should be able to match all existing symbols with
4845 parameters and qualifiers. */
4846 with_params
= std::string (sym
) + " ( int ) const";
4847 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4850 /* This should really find sym, but cp-name-parser.y doesn't
4851 know about lvalue/rvalue qualifiers yet. */
4852 with_params
= std::string (sym
) + " ( int ) &&";
4853 CHECK_MATCH (with_params
.c_str (), symbol_name_match_type::FULL
, false,
4857 /* Check that the name matching algorithm for completion doesn't get
4858 confused with Latin1 'ÿ' / 0xff. */
4860 static const char str
[] = "\377";
4861 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4862 EXPECT ("\377", "\377\377123"));
4865 /* Check that the increment-last-char in the matching algorithm for
4866 completion doesn't match "t1_fund" when completing "t1_func". */
4868 static const char str
[] = "t1_func";
4869 CHECK_MATCH (str
, symbol_name_match_type::FULL
, true,
4870 EXPECT ("t1_func", "t1_func1"));
4873 /* Check that completion mode works at each prefix of the expected
4876 static const char str
[] = "function(int)";
4877 size_t len
= strlen (str
);
4880 for (size_t i
= 1; i
< len
; i
++)
4882 lookup
.assign (str
, i
);
4883 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4884 EXPECT ("function"));
4888 /* While "w" is a prefix of both components, the match function
4889 should still only be called once. */
4891 CHECK_MATCH ("w", symbol_name_match_type::FULL
, true,
4893 CHECK_MATCH ("w", symbol_name_match_type::WILD
, true,
4897 /* Same, with a "complicated" symbol. */
4899 static const char str
[] = Z_SYM_NAME
;
4900 size_t len
= strlen (str
);
4903 for (size_t i
= 1; i
< len
; i
++)
4905 lookup
.assign (str
, i
);
4906 CHECK_MATCH (lookup
.c_str (), symbol_name_match_type::FULL
, true,
4907 EXPECT (Z_SYM_NAME
));
4911 /* In FULL mode, an incomplete symbol doesn't match. */
4913 CHECK_MATCH ("std::zfunction(int", symbol_name_match_type::FULL
, false,
4917 /* A complete symbol with parameters matches any overload, since the
4918 index has no overload info. */
4920 CHECK_MATCH ("std::zfunction(int)", symbol_name_match_type::FULL
, true,
4921 EXPECT ("std::zfunction", "std::zfunction2"));
4922 CHECK_MATCH ("zfunction(int)", symbol_name_match_type::WILD
, true,
4923 EXPECT ("std::zfunction", "std::zfunction2"));
4924 CHECK_MATCH ("zfunc", symbol_name_match_type::WILD
, true,
4925 EXPECT ("std::zfunction", "std::zfunction2"));
4928 /* Check that whitespace is ignored appropriately. A symbol with a
4929 template argument list. */
4931 static const char expected
[] = "ns::foo<int>";
4932 CHECK_MATCH ("ns :: foo < int > ", symbol_name_match_type::FULL
, false,
4934 CHECK_MATCH ("foo < int > ", symbol_name_match_type::WILD
, false,
4938 /* Check that whitespace is ignored appropriately. A symbol with a
4939 template argument list that includes a pointer. */
4941 static const char expected
[] = "ns::foo<char*>";
4942 /* Try both completion and non-completion modes. */
4943 static const bool completion_mode
[2] = {false, true};
4944 for (size_t i
= 0; i
< 2; i
++)
4946 CHECK_MATCH ("ns :: foo < char * >", symbol_name_match_type::FULL
,
4947 completion_mode
[i
], EXPECT (expected
));
4948 CHECK_MATCH ("foo < char * >", symbol_name_match_type::WILD
,
4949 completion_mode
[i
], EXPECT (expected
));
4951 CHECK_MATCH ("ns :: foo < char * > (int)", symbol_name_match_type::FULL
,
4952 completion_mode
[i
], EXPECT (expected
));
4953 CHECK_MATCH ("foo < char * > (int)", symbol_name_match_type::WILD
,
4954 completion_mode
[i
], EXPECT (expected
));
4959 /* Check method qualifiers are ignored. */
4960 static const char expected
[] = "ns::foo<char*>";
4961 CHECK_MATCH ("ns :: foo < char * > ( int ) const",
4962 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4963 CHECK_MATCH ("ns :: foo < char * > ( int ) &&",
4964 symbol_name_match_type::FULL
, true, EXPECT (expected
));
4965 CHECK_MATCH ("foo < char * > ( int ) const",
4966 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4967 CHECK_MATCH ("foo < char * > ( int ) &&",
4968 symbol_name_match_type::WILD
, true, EXPECT (expected
));
4971 /* Test lookup names that don't match anything. */
4973 CHECK_MATCH ("bar2", symbol_name_match_type::WILD
, false,
4976 CHECK_MATCH ("doesntexist", symbol_name_match_type::FULL
, false,
4980 /* Some wild matching tests, exercising "(anonymous namespace)",
4981 which should not be confused with a parameter list. */
4983 static const char *syms
[] = {
4987 "A :: B :: C ( int )",
4992 for (const char *s
: syms
)
4994 CHECK_MATCH (s
, symbol_name_match_type::WILD
, false,
4995 EXPECT ("(anonymous namespace)::A::B::C"));
5000 static const char expected
[] = "ns2::tmpl<int>::foo2";
5001 CHECK_MATCH ("tmp", symbol_name_match_type::WILD
, true,
5003 CHECK_MATCH ("tmpl<", symbol_name_match_type::WILD
, true,
5007 SELF_CHECK (!any_mismatch
);
5016 test_mapped_index_find_name_component_bounds ();
5017 test_dw2_expand_symtabs_matching_symbol ();
5020 }} // namespace selftests::dw2_expand_symtabs_matching
5022 #endif /* GDB_SELF_TEST */
5024 /* If FILE_MATCHER is NULL or if PER_CU has
5025 dwarf2_per_cu_quick_data::MARK set (see
5026 dw_expand_symtabs_matching_file_matcher), expand the CU and call
5027 EXPANSION_NOTIFY on it. */
5030 dw2_expand_symtabs_matching_one
5031 (struct dwarf2_per_cu_data
*per_cu
,
5032 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5033 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
)
5035 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
5037 bool symtab_was_null
5038 = (per_cu
->v
.quick
->compunit_symtab
== NULL
);
5040 dw2_instantiate_symtab (per_cu
, false);
5042 if (expansion_notify
!= NULL
5044 && per_cu
->v
.quick
->compunit_symtab
!= NULL
)
5045 expansion_notify (per_cu
->v
.quick
->compunit_symtab
);
5049 /* Helper for dw2_expand_matching symtabs. Called on each symbol
5050 matched, to expand corresponding CUs that were marked. IDX is the
5051 index of the symbol name that matched. */
5054 dw2_expand_marked_cus
5055 (struct dwarf2_per_objfile
*dwarf2_per_objfile
, offset_type idx
,
5056 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5057 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5060 offset_type
*vec
, vec_len
, vec_idx
;
5061 bool global_seen
= false;
5062 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5064 vec
= (offset_type
*) (index
.constant_pool
5065 + MAYBE_SWAP (index
.symbol_table
[idx
].vec
));
5066 vec_len
= MAYBE_SWAP (vec
[0]);
5067 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
5069 offset_type cu_index_and_attrs
= MAYBE_SWAP (vec
[vec_idx
+ 1]);
5070 /* This value is only valid for index versions >= 7. */
5071 int is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs
);
5072 gdb_index_symbol_kind symbol_kind
=
5073 GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs
);
5074 int cu_index
= GDB_INDEX_CU_VALUE (cu_index_and_attrs
);
5075 /* Only check the symbol attributes if they're present.
5076 Indices prior to version 7 don't record them,
5077 and indices >= 7 may elide them for certain symbols
5078 (gold does this). */
5081 && symbol_kind
!= GDB_INDEX_SYMBOL_KIND_NONE
);
5083 /* Work around gold/15646. */
5086 if (!is_static
&& global_seen
)
5092 /* Only check the symbol's kind if it has one. */
5097 case VARIABLES_DOMAIN
:
5098 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_VARIABLE
)
5101 case FUNCTIONS_DOMAIN
:
5102 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_FUNCTION
)
5106 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_TYPE
)
5109 case MODULES_DOMAIN
:
5110 if (symbol_kind
!= GDB_INDEX_SYMBOL_KIND_OTHER
)
5118 /* Don't crash on bad data. */
5119 if (cu_index
>= (dwarf2_per_objfile
->all_comp_units
.size ()
5120 + dwarf2_per_objfile
->all_type_units
.size ()))
5122 complaint (_(".gdb_index entry has bad CU index"
5124 objfile_name (dwarf2_per_objfile
->objfile
));
5128 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (cu_index
);
5129 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
5134 /* If FILE_MATCHER is non-NULL, set all the
5135 dwarf2_per_cu_quick_data::MARK of the current DWARF2_PER_OBJFILE
5136 that match FILE_MATCHER. */
5139 dw_expand_symtabs_matching_file_matcher
5140 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5141 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
)
5143 if (file_matcher
== NULL
)
5146 objfile
*const objfile
= dwarf2_per_objfile
->objfile
;
5148 htab_up
visited_found (htab_create_alloc (10, htab_hash_pointer
,
5150 NULL
, xcalloc
, xfree
));
5151 htab_up
visited_not_found (htab_create_alloc (10, htab_hash_pointer
,
5153 NULL
, xcalloc
, xfree
));
5155 /* The rule is CUs specify all the files, including those used by
5156 any TU, so there's no need to scan TUs here. */
5158 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5162 per_cu
->v
.quick
->mark
= 0;
5164 /* We only need to look at symtabs not already expanded. */
5165 if (per_cu
->v
.quick
->compunit_symtab
)
5168 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5169 if (file_data
== NULL
)
5172 if (htab_find (visited_not_found
.get (), file_data
) != NULL
)
5174 else if (htab_find (visited_found
.get (), file_data
) != NULL
)
5176 per_cu
->v
.quick
->mark
= 1;
5180 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5182 const char *this_real_name
;
5184 if (file_matcher (file_data
->file_names
[j
], false))
5186 per_cu
->v
.quick
->mark
= 1;
5190 /* Before we invoke realpath, which can get expensive when many
5191 files are involved, do a quick comparison of the basenames. */
5192 if (!basenames_may_differ
5193 && !file_matcher (lbasename (file_data
->file_names
[j
]),
5197 this_real_name
= dw2_get_real_path (objfile
, file_data
, j
);
5198 if (file_matcher (this_real_name
, false))
5200 per_cu
->v
.quick
->mark
= 1;
5205 void **slot
= htab_find_slot (per_cu
->v
.quick
->mark
5206 ? visited_found
.get ()
5207 : visited_not_found
.get (),
5214 dw2_expand_symtabs_matching
5215 (struct objfile
*objfile
,
5216 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
5217 const lookup_name_info
&lookup_name
,
5218 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
5219 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
5220 enum search_domain kind
)
5222 struct dwarf2_per_objfile
*dwarf2_per_objfile
5223 = get_dwarf2_per_objfile (objfile
);
5225 /* index_table is NULL if OBJF_READNOW. */
5226 if (!dwarf2_per_objfile
->index_table
)
5229 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
5231 mapped_index
&index
= *dwarf2_per_objfile
->index_table
;
5233 dw2_expand_symtabs_matching_symbol (index
, lookup_name
,
5235 kind
, [&] (offset_type idx
)
5237 dw2_expand_marked_cus (dwarf2_per_objfile
, idx
, file_matcher
,
5238 expansion_notify
, kind
);
5243 /* A helper for dw2_find_pc_sect_compunit_symtab which finds the most specific
5246 static struct compunit_symtab
*
5247 recursively_find_pc_sect_compunit_symtab (struct compunit_symtab
*cust
,
5252 if (COMPUNIT_BLOCKVECTOR (cust
) != NULL
5253 && blockvector_contains_pc (COMPUNIT_BLOCKVECTOR (cust
), pc
))
5256 if (cust
->includes
== NULL
)
5259 for (i
= 0; cust
->includes
[i
]; ++i
)
5261 struct compunit_symtab
*s
= cust
->includes
[i
];
5263 s
= recursively_find_pc_sect_compunit_symtab (s
, pc
);
5271 static struct compunit_symtab
*
5272 dw2_find_pc_sect_compunit_symtab (struct objfile
*objfile
,
5273 struct bound_minimal_symbol msymbol
,
5275 struct obj_section
*section
,
5278 struct dwarf2_per_cu_data
*data
;
5279 struct compunit_symtab
*result
;
5281 if (!objfile
->partial_symtabs
->psymtabs_addrmap
)
5284 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
5285 data
= (struct dwarf2_per_cu_data
*) addrmap_find
5286 (objfile
->partial_symtabs
->psymtabs_addrmap
, pc
- baseaddr
);
5290 if (warn_if_readin
&& data
->v
.quick
->compunit_symtab
)
5291 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
5292 paddress (get_objfile_arch (objfile
), pc
));
5295 = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data
,
5298 gdb_assert (result
!= NULL
);
5303 dw2_map_symbol_filenames (struct objfile
*objfile
, symbol_filename_ftype
*fun
,
5304 void *data
, int need_fullname
)
5306 struct dwarf2_per_objfile
*dwarf2_per_objfile
5307 = get_dwarf2_per_objfile (objfile
);
5309 if (!dwarf2_per_objfile
->filenames_cache
)
5311 dwarf2_per_objfile
->filenames_cache
.emplace ();
5313 htab_up
visited (htab_create_alloc (10,
5314 htab_hash_pointer
, htab_eq_pointer
,
5315 NULL
, xcalloc
, xfree
));
5317 /* The rule is CUs specify all the files, including those used
5318 by any TU, so there's no need to scan TUs here. We can
5319 ignore file names coming from already-expanded CUs. */
5321 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5323 if (per_cu
->v
.quick
->compunit_symtab
)
5325 void **slot
= htab_find_slot (visited
.get (),
5326 per_cu
->v
.quick
->file_names
,
5329 *slot
= per_cu
->v
.quick
->file_names
;
5333 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
5335 /* We only need to look at symtabs not already expanded. */
5336 if (per_cu
->v
.quick
->compunit_symtab
)
5339 quick_file_names
*file_data
= dw2_get_file_names (per_cu
);
5340 if (file_data
== NULL
)
5343 void **slot
= htab_find_slot (visited
.get (), file_data
, INSERT
);
5346 /* Already visited. */
5351 for (int j
= 0; j
< file_data
->num_file_names
; ++j
)
5353 const char *filename
= file_data
->file_names
[j
];
5354 dwarf2_per_objfile
->filenames_cache
->seen (filename
);
5359 dwarf2_per_objfile
->filenames_cache
->traverse ([&] (const char *filename
)
5361 gdb::unique_xmalloc_ptr
<char> this_real_name
;
5364 this_real_name
= gdb_realpath (filename
);
5365 (*fun
) (filename
, this_real_name
.get (), data
);
5370 dw2_has_symbols (struct objfile
*objfile
)
5375 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
5378 dw2_find_last_source_symtab
,
5379 dw2_forget_cached_source_info
,
5380 dw2_map_symtabs_matching_filename
,
5384 dw2_expand_symtabs_for_function
,
5385 dw2_expand_all_symtabs
,
5386 dw2_expand_symtabs_with_fullname
,
5387 dw2_map_matching_symbols
,
5388 dw2_expand_symtabs_matching
,
5389 dw2_find_pc_sect_compunit_symtab
,
5391 dw2_map_symbol_filenames
5394 /* DWARF-5 debug_names reader. */
5396 /* DWARF-5 augmentation string for GDB's DW_IDX_GNU_* extension. */
5397 static const gdb_byte dwarf5_augmentation
[] = { 'G', 'D', 'B', 0 };
5399 /* A helper function that reads the .debug_names section in SECTION
5400 and fills in MAP. FILENAME is the name of the file containing the
5401 section; it is used for error reporting.
5403 Returns true if all went well, false otherwise. */
5406 read_debug_names_from_section (struct objfile
*objfile
,
5407 const char *filename
,
5408 struct dwarf2_section_info
*section
,
5409 mapped_debug_names
&map
)
5411 if (dwarf2_section_empty_p (section
))
5414 /* Older elfutils strip versions could keep the section in the main
5415 executable while splitting it for the separate debug info file. */
5416 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
5419 dwarf2_read_section (objfile
, section
);
5421 map
.dwarf5_byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
5423 const gdb_byte
*addr
= section
->buffer
;
5425 bfd
*const abfd
= get_section_bfd_owner (section
);
5427 unsigned int bytes_read
;
5428 LONGEST length
= read_initial_length (abfd
, addr
, &bytes_read
);
5431 map
.dwarf5_is_dwarf64
= bytes_read
!= 4;
5432 map
.offset_size
= map
.dwarf5_is_dwarf64
? 8 : 4;
5433 if (bytes_read
+ length
!= section
->size
)
5435 /* There may be multiple per-CU indices. */
5436 warning (_("Section .debug_names in %s length %s does not match "
5437 "section length %s, ignoring .debug_names."),
5438 filename
, plongest (bytes_read
+ length
),
5439 pulongest (section
->size
));
5443 /* The version number. */
5444 uint16_t version
= read_2_bytes (abfd
, addr
);
5448 warning (_("Section .debug_names in %s has unsupported version %d, "
5449 "ignoring .debug_names."),
5455 uint16_t padding
= read_2_bytes (abfd
, addr
);
5459 warning (_("Section .debug_names in %s has unsupported padding %d, "
5460 "ignoring .debug_names."),
5465 /* comp_unit_count - The number of CUs in the CU list. */
5466 map
.cu_count
= read_4_bytes (abfd
, addr
);
5469 /* local_type_unit_count - The number of TUs in the local TU
5471 map
.tu_count
= read_4_bytes (abfd
, addr
);
5474 /* foreign_type_unit_count - The number of TUs in the foreign TU
5476 uint32_t foreign_tu_count
= read_4_bytes (abfd
, addr
);
5478 if (foreign_tu_count
!= 0)
5480 warning (_("Section .debug_names in %s has unsupported %lu foreign TUs, "
5481 "ignoring .debug_names."),
5482 filename
, static_cast<unsigned long> (foreign_tu_count
));
5486 /* bucket_count - The number of hash buckets in the hash lookup
5488 map
.bucket_count
= read_4_bytes (abfd
, addr
);
5491 /* name_count - The number of unique names in the index. */
5492 map
.name_count
= read_4_bytes (abfd
, addr
);
5495 /* abbrev_table_size - The size in bytes of the abbreviations
5497 uint32_t abbrev_table_size
= read_4_bytes (abfd
, addr
);
5500 /* augmentation_string_size - The size in bytes of the augmentation
5501 string. This value is rounded up to a multiple of 4. */
5502 uint32_t augmentation_string_size
= read_4_bytes (abfd
, addr
);
5504 map
.augmentation_is_gdb
= ((augmentation_string_size
5505 == sizeof (dwarf5_augmentation
))
5506 && memcmp (addr
, dwarf5_augmentation
,
5507 sizeof (dwarf5_augmentation
)) == 0);
5508 augmentation_string_size
+= (-augmentation_string_size
) & 3;
5509 addr
+= augmentation_string_size
;
5512 map
.cu_table_reordered
= addr
;
5513 addr
+= map
.cu_count
* map
.offset_size
;
5515 /* List of Local TUs */
5516 map
.tu_table_reordered
= addr
;
5517 addr
+= map
.tu_count
* map
.offset_size
;
5519 /* Hash Lookup Table */
5520 map
.bucket_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5521 addr
+= map
.bucket_count
* 4;
5522 map
.hash_table_reordered
= reinterpret_cast<const uint32_t *> (addr
);
5523 addr
+= map
.name_count
* 4;
5526 map
.name_table_string_offs_reordered
= addr
;
5527 addr
+= map
.name_count
* map
.offset_size
;
5528 map
.name_table_entry_offs_reordered
= addr
;
5529 addr
+= map
.name_count
* map
.offset_size
;
5531 const gdb_byte
*abbrev_table_start
= addr
;
5534 const ULONGEST index_num
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5539 const auto insertpair
5540 = map
.abbrev_map
.emplace (index_num
, mapped_debug_names::index_val ());
5541 if (!insertpair
.second
)
5543 warning (_("Section .debug_names in %s has duplicate index %s, "
5544 "ignoring .debug_names."),
5545 filename
, pulongest (index_num
));
5548 mapped_debug_names::index_val
&indexval
= insertpair
.first
->second
;
5549 indexval
.dwarf_tag
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5554 mapped_debug_names::index_val::attr attr
;
5555 attr
.dw_idx
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5557 attr
.form
= read_unsigned_leb128 (abfd
, addr
, &bytes_read
);
5559 if (attr
.form
== DW_FORM_implicit_const
)
5561 attr
.implicit_const
= read_signed_leb128 (abfd
, addr
,
5565 if (attr
.dw_idx
== 0 && attr
.form
== 0)
5567 indexval
.attr_vec
.push_back (std::move (attr
));
5570 if (addr
!= abbrev_table_start
+ abbrev_table_size
)
5572 warning (_("Section .debug_names in %s has abbreviation_table "
5573 "of size %s vs. written as %u, ignoring .debug_names."),
5574 filename
, plongest (addr
- abbrev_table_start
),
5578 map
.entry_pool
= addr
;
5583 /* A helper for create_cus_from_debug_names that handles the MAP's CU
5587 create_cus_from_debug_names_list (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5588 const mapped_debug_names
&map
,
5589 dwarf2_section_info
§ion
,
5592 sect_offset sect_off_prev
;
5593 for (uint32_t i
= 0; i
<= map
.cu_count
; ++i
)
5595 sect_offset sect_off_next
;
5596 if (i
< map
.cu_count
)
5599 = (sect_offset
) (extract_unsigned_integer
5600 (map
.cu_table_reordered
+ i
* map
.offset_size
,
5602 map
.dwarf5_byte_order
));
5605 sect_off_next
= (sect_offset
) section
.size
;
5608 const ULONGEST length
= sect_off_next
- sect_off_prev
;
5609 dwarf2_per_cu_data
*per_cu
5610 = create_cu_from_index_list (dwarf2_per_objfile
, §ion
, is_dwz
,
5611 sect_off_prev
, length
);
5612 dwarf2_per_objfile
->all_comp_units
.push_back (per_cu
);
5614 sect_off_prev
= sect_off_next
;
5618 /* Read the CU list from the mapped index, and use it to create all
5619 the CU objects for this dwarf2_per_objfile. */
5622 create_cus_from_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
5623 const mapped_debug_names
&map
,
5624 const mapped_debug_names
&dwz_map
)
5626 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
5627 dwarf2_per_objfile
->all_comp_units
.reserve (map
.cu_count
+ dwz_map
.cu_count
);
5629 create_cus_from_debug_names_list (dwarf2_per_objfile
, map
,
5630 dwarf2_per_objfile
->info
,
5631 false /* is_dwz */);
5633 if (dwz_map
.cu_count
== 0)
5636 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5637 create_cus_from_debug_names_list (dwarf2_per_objfile
, dwz_map
, dwz
->info
,
5641 /* Read .debug_names. If everything went ok, initialize the "quick"
5642 elements of all the CUs and return true. Otherwise, return false. */
5645 dwarf2_read_debug_names (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
5647 std::unique_ptr
<mapped_debug_names
> map
5648 (new mapped_debug_names (dwarf2_per_objfile
));
5649 mapped_debug_names
dwz_map (dwarf2_per_objfile
);
5650 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5652 if (!read_debug_names_from_section (objfile
, objfile_name (objfile
),
5653 &dwarf2_per_objfile
->debug_names
,
5657 /* Don't use the index if it's empty. */
5658 if (map
->name_count
== 0)
5661 /* If there is a .dwz file, read it so we can get its CU list as
5663 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
5666 if (!read_debug_names_from_section (objfile
,
5667 bfd_get_filename (dwz
->dwz_bfd
.get ()),
5668 &dwz
->debug_names
, dwz_map
))
5670 warning (_("could not read '.debug_names' section from %s; skipping"),
5671 bfd_get_filename (dwz
->dwz_bfd
.get ()));
5676 create_cus_from_debug_names (dwarf2_per_objfile
, *map
, dwz_map
);
5678 if (map
->tu_count
!= 0)
5680 /* We can only handle a single .debug_types when we have an
5682 if (dwarf2_per_objfile
->types
.size () != 1)
5685 dwarf2_section_info
*section
= &dwarf2_per_objfile
->types
[0];
5687 create_signatured_type_table_from_debug_names
5688 (dwarf2_per_objfile
, *map
, section
, &dwarf2_per_objfile
->abbrev
);
5691 create_addrmap_from_aranges (dwarf2_per_objfile
,
5692 &dwarf2_per_objfile
->debug_aranges
);
5694 dwarf2_per_objfile
->debug_names_table
= std::move (map
);
5695 dwarf2_per_objfile
->using_index
= 1;
5696 dwarf2_per_objfile
->quick_file_names_table
=
5697 create_quick_file_names_table (dwarf2_per_objfile
->all_comp_units
.size ());
5702 /* Type used to manage iterating over all CUs looking for a symbol for
5705 class dw2_debug_names_iterator
5708 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5709 gdb::optional
<block_enum
> block_index
,
5712 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5713 m_addr (find_vec_in_debug_names (map
, name
))
5716 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5717 search_domain search
, uint32_t namei
)
5720 m_addr (find_vec_in_debug_names (map
, namei
))
5723 dw2_debug_names_iterator (const mapped_debug_names
&map
,
5724 block_enum block_index
, domain_enum domain
,
5726 : m_map (map
), m_block_index (block_index
), m_domain (domain
),
5727 m_addr (find_vec_in_debug_names (map
, namei
))
5730 /* Return the next matching CU or NULL if there are no more. */
5731 dwarf2_per_cu_data
*next ();
5734 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5736 static const gdb_byte
*find_vec_in_debug_names (const mapped_debug_names
&map
,
5739 /* The internalized form of .debug_names. */
5740 const mapped_debug_names
&m_map
;
5742 /* If set, only look for symbols that match that block. Valid values are
5743 GLOBAL_BLOCK and STATIC_BLOCK. */
5744 const gdb::optional
<block_enum
> m_block_index
;
5746 /* The kind of symbol we're looking for. */
5747 const domain_enum m_domain
= UNDEF_DOMAIN
;
5748 const search_domain m_search
= ALL_DOMAIN
;
5750 /* The list of CUs from the index entry of the symbol, or NULL if
5752 const gdb_byte
*m_addr
;
5756 mapped_debug_names::namei_to_name (uint32_t namei
) const
5758 const ULONGEST namei_string_offs
5759 = extract_unsigned_integer ((name_table_string_offs_reordered
5760 + namei
* offset_size
),
5763 return read_indirect_string_at_offset
5764 (dwarf2_per_objfile
, dwarf2_per_objfile
->objfile
->obfd
, namei_string_offs
);
5767 /* Find a slot in .debug_names for the object named NAME. If NAME is
5768 found, return pointer to its pool data. If NAME cannot be found,
5772 dw2_debug_names_iterator::find_vec_in_debug_names
5773 (const mapped_debug_names
&map
, const char *name
)
5775 int (*cmp
) (const char *, const char *);
5777 gdb::unique_xmalloc_ptr
<char> without_params
;
5778 if (current_language
->la_language
== language_cplus
5779 || current_language
->la_language
== language_fortran
5780 || current_language
->la_language
== language_d
)
5782 /* NAME is already canonical. Drop any qualifiers as
5783 .debug_names does not contain any. */
5785 if (strchr (name
, '(') != NULL
)
5787 without_params
= cp_remove_params (name
);
5788 if (without_params
!= NULL
)
5789 name
= without_params
.get ();
5793 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
5795 const uint32_t full_hash
= dwarf5_djb_hash (name
);
5797 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5798 (map
.bucket_table_reordered
5799 + (full_hash
% map
.bucket_count
)), 4,
5800 map
.dwarf5_byte_order
);
5804 if (namei
>= map
.name_count
)
5806 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5808 namei
, map
.name_count
,
5809 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5815 const uint32_t namei_full_hash
5816 = extract_unsigned_integer (reinterpret_cast<const gdb_byte
*>
5817 (map
.hash_table_reordered
+ namei
), 4,
5818 map
.dwarf5_byte_order
);
5819 if (full_hash
% map
.bucket_count
!= namei_full_hash
% map
.bucket_count
)
5822 if (full_hash
== namei_full_hash
)
5824 const char *const namei_string
= map
.namei_to_name (namei
);
5826 #if 0 /* An expensive sanity check. */
5827 if (namei_full_hash
!= dwarf5_djb_hash (namei_string
))
5829 complaint (_("Wrong .debug_names hash for string at index %u "
5831 namei
, objfile_name (dwarf2_per_objfile
->objfile
));
5836 if (cmp (namei_string
, name
) == 0)
5838 const ULONGEST namei_entry_offs
5839 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5840 + namei
* map
.offset_size
),
5841 map
.offset_size
, map
.dwarf5_byte_order
);
5842 return map
.entry_pool
+ namei_entry_offs
;
5847 if (namei
>= map
.name_count
)
5853 dw2_debug_names_iterator::find_vec_in_debug_names
5854 (const mapped_debug_names
&map
, uint32_t namei
)
5856 if (namei
>= map
.name_count
)
5858 complaint (_("Wrong .debug_names with name index %u but name_count=%u "
5860 namei
, map
.name_count
,
5861 objfile_name (map
.dwarf2_per_objfile
->objfile
));
5865 const ULONGEST namei_entry_offs
5866 = extract_unsigned_integer ((map
.name_table_entry_offs_reordered
5867 + namei
* map
.offset_size
),
5868 map
.offset_size
, map
.dwarf5_byte_order
);
5869 return map
.entry_pool
+ namei_entry_offs
;
5872 /* See dw2_debug_names_iterator. */
5874 dwarf2_per_cu_data
*
5875 dw2_debug_names_iterator::next ()
5880 struct dwarf2_per_objfile
*dwarf2_per_objfile
= m_map
.dwarf2_per_objfile
;
5881 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
5882 bfd
*const abfd
= objfile
->obfd
;
5886 unsigned int bytes_read
;
5887 const ULONGEST abbrev
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5888 m_addr
+= bytes_read
;
5892 const auto indexval_it
= m_map
.abbrev_map
.find (abbrev
);
5893 if (indexval_it
== m_map
.abbrev_map
.cend ())
5895 complaint (_("Wrong .debug_names undefined abbrev code %s "
5897 pulongest (abbrev
), objfile_name (objfile
));
5900 const mapped_debug_names::index_val
&indexval
= indexval_it
->second
;
5901 enum class symbol_linkage
{
5905 } symbol_linkage_
= symbol_linkage::unknown
;
5906 dwarf2_per_cu_data
*per_cu
= NULL
;
5907 for (const mapped_debug_names::index_val::attr
&attr
: indexval
.attr_vec
)
5912 case DW_FORM_implicit_const
:
5913 ull
= attr
.implicit_const
;
5915 case DW_FORM_flag_present
:
5919 ull
= read_unsigned_leb128 (abfd
, m_addr
, &bytes_read
);
5920 m_addr
+= bytes_read
;
5923 complaint (_("Unsupported .debug_names form %s [in module %s]"),
5924 dwarf_form_name (attr
.form
),
5925 objfile_name (objfile
));
5928 switch (attr
.dw_idx
)
5930 case DW_IDX_compile_unit
:
5931 /* Don't crash on bad data. */
5932 if (ull
>= dwarf2_per_objfile
->all_comp_units
.size ())
5934 complaint (_(".debug_names entry has bad CU index %s"
5937 objfile_name (dwarf2_per_objfile
->objfile
));
5940 per_cu
= dwarf2_per_objfile
->get_cutu (ull
);
5942 case DW_IDX_type_unit
:
5943 /* Don't crash on bad data. */
5944 if (ull
>= dwarf2_per_objfile
->all_type_units
.size ())
5946 complaint (_(".debug_names entry has bad TU index %s"
5949 objfile_name (dwarf2_per_objfile
->objfile
));
5952 per_cu
= &dwarf2_per_objfile
->get_tu (ull
)->per_cu
;
5954 case DW_IDX_GNU_internal
:
5955 if (!m_map
.augmentation_is_gdb
)
5957 symbol_linkage_
= symbol_linkage::static_
;
5959 case DW_IDX_GNU_external
:
5960 if (!m_map
.augmentation_is_gdb
)
5962 symbol_linkage_
= symbol_linkage::extern_
;
5967 /* Skip if already read in. */
5968 if (per_cu
->v
.quick
->compunit_symtab
)
5971 /* Check static vs global. */
5972 if (symbol_linkage_
!= symbol_linkage::unknown
&& m_block_index
.has_value ())
5974 const bool want_static
= *m_block_index
== STATIC_BLOCK
;
5975 const bool symbol_is_static
=
5976 symbol_linkage_
== symbol_linkage::static_
;
5977 if (want_static
!= symbol_is_static
)
5981 /* Match dw2_symtab_iter_next, symbol_kind
5982 and debug_names::psymbol_tag. */
5986 switch (indexval
.dwarf_tag
)
5988 case DW_TAG_variable
:
5989 case DW_TAG_subprogram
:
5990 /* Some types are also in VAR_DOMAIN. */
5991 case DW_TAG_typedef
:
5992 case DW_TAG_structure_type
:
5999 switch (indexval
.dwarf_tag
)
6001 case DW_TAG_typedef
:
6002 case DW_TAG_structure_type
:
6009 switch (indexval
.dwarf_tag
)
6012 case DW_TAG_variable
:
6019 switch (indexval
.dwarf_tag
)
6031 /* Match dw2_expand_symtabs_matching, symbol_kind and
6032 debug_names::psymbol_tag. */
6035 case VARIABLES_DOMAIN
:
6036 switch (indexval
.dwarf_tag
)
6038 case DW_TAG_variable
:
6044 case FUNCTIONS_DOMAIN
:
6045 switch (indexval
.dwarf_tag
)
6047 case DW_TAG_subprogram
:
6054 switch (indexval
.dwarf_tag
)
6056 case DW_TAG_typedef
:
6057 case DW_TAG_structure_type
:
6063 case MODULES_DOMAIN
:
6064 switch (indexval
.dwarf_tag
)
6078 static struct compunit_symtab
*
6079 dw2_debug_names_lookup_symbol (struct objfile
*objfile
, block_enum block_index
,
6080 const char *name
, domain_enum domain
)
6082 struct dwarf2_per_objfile
*dwarf2_per_objfile
6083 = get_dwarf2_per_objfile (objfile
);
6085 const auto &mapp
= dwarf2_per_objfile
->debug_names_table
;
6088 /* index is NULL if OBJF_READNOW. */
6091 const auto &map
= *mapp
;
6093 dw2_debug_names_iterator
iter (map
, block_index
, domain
, name
);
6095 struct compunit_symtab
*stab_best
= NULL
;
6096 struct dwarf2_per_cu_data
*per_cu
;
6097 while ((per_cu
= iter
.next ()) != NULL
)
6099 struct symbol
*sym
, *with_opaque
= NULL
;
6100 struct compunit_symtab
*stab
= dw2_instantiate_symtab (per_cu
, false);
6101 const struct blockvector
*bv
= COMPUNIT_BLOCKVECTOR (stab
);
6102 const struct block
*block
= BLOCKVECTOR_BLOCK (bv
, block_index
);
6104 sym
= block_find_symbol (block
, name
, domain
,
6105 block_find_non_opaque_type_preferred
,
6108 /* Some caution must be observed with overloaded functions and
6109 methods, since the index will not contain any overload
6110 information (but NAME might contain it). */
6113 && strcmp_iw (sym
->search_name (), name
) == 0)
6115 if (with_opaque
!= NULL
6116 && strcmp_iw (with_opaque
->search_name (), name
) == 0)
6119 /* Keep looking through other CUs. */
6125 /* This dumps minimal information about .debug_names. It is called
6126 via "mt print objfiles". The gdb.dwarf2/gdb-index.exp testcase
6127 uses this to verify that .debug_names has been loaded. */
6130 dw2_debug_names_dump (struct objfile
*objfile
)
6132 struct dwarf2_per_objfile
*dwarf2_per_objfile
6133 = get_dwarf2_per_objfile (objfile
);
6135 gdb_assert (dwarf2_per_objfile
->using_index
);
6136 printf_filtered (".debug_names:");
6137 if (dwarf2_per_objfile
->debug_names_table
)
6138 printf_filtered (" exists\n");
6140 printf_filtered (" faked for \"readnow\"\n");
6141 printf_filtered ("\n");
6145 dw2_debug_names_expand_symtabs_for_function (struct objfile
*objfile
,
6146 const char *func_name
)
6148 struct dwarf2_per_objfile
*dwarf2_per_objfile
6149 = get_dwarf2_per_objfile (objfile
);
6151 /* dwarf2_per_objfile->debug_names_table is NULL if OBJF_READNOW. */
6152 if (dwarf2_per_objfile
->debug_names_table
)
6154 const mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6156 dw2_debug_names_iterator
iter (map
, {}, VAR_DOMAIN
, func_name
);
6158 struct dwarf2_per_cu_data
*per_cu
;
6159 while ((per_cu
= iter
.next ()) != NULL
)
6160 dw2_instantiate_symtab (per_cu
, false);
6165 dw2_debug_names_map_matching_symbols
6166 (struct objfile
*objfile
,
6167 const lookup_name_info
&name
, domain_enum domain
,
6169 gdb::function_view
<symbol_found_callback_ftype
> callback
,
6170 symbol_compare_ftype
*ordered_compare
)
6172 struct dwarf2_per_objfile
*dwarf2_per_objfile
6173 = get_dwarf2_per_objfile (objfile
);
6175 /* debug_names_table is NULL if OBJF_READNOW. */
6176 if (!dwarf2_per_objfile
->debug_names_table
)
6179 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6180 const block_enum block_kind
= global
? GLOBAL_BLOCK
: STATIC_BLOCK
;
6182 const char *match_name
= name
.ada ().lookup_name ().c_str ();
6183 auto matcher
= [&] (const char *symname
)
6185 if (ordered_compare
== nullptr)
6187 return ordered_compare (symname
, match_name
) == 0;
6190 dw2_expand_symtabs_matching_symbol (map
, name
, matcher
, ALL_DOMAIN
,
6191 [&] (offset_type namei
)
6193 /* The name was matched, now expand corresponding CUs that were
6195 dw2_debug_names_iterator
iter (map
, block_kind
, domain
, namei
);
6197 struct dwarf2_per_cu_data
*per_cu
;
6198 while ((per_cu
= iter
.next ()) != NULL
)
6199 dw2_expand_symtabs_matching_one (per_cu
, nullptr, nullptr);
6203 /* It's a shame we couldn't do this inside the
6204 dw2_expand_symtabs_matching_symbol callback, but that skips CUs
6205 that have already been expanded. Instead, this loop matches what
6206 the psymtab code does. */
6207 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
6209 struct compunit_symtab
*cust
= per_cu
->v
.quick
->compunit_symtab
;
6210 if (cust
!= nullptr)
6212 const struct block
*block
6213 = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust
), block_kind
);
6214 if (!iterate_over_symbols_terminated (block
, name
,
6222 dw2_debug_names_expand_symtabs_matching
6223 (struct objfile
*objfile
,
6224 gdb::function_view
<expand_symtabs_file_matcher_ftype
> file_matcher
,
6225 const lookup_name_info
&lookup_name
,
6226 gdb::function_view
<expand_symtabs_symbol_matcher_ftype
> symbol_matcher
,
6227 gdb::function_view
<expand_symtabs_exp_notify_ftype
> expansion_notify
,
6228 enum search_domain kind
)
6230 struct dwarf2_per_objfile
*dwarf2_per_objfile
6231 = get_dwarf2_per_objfile (objfile
);
6233 /* debug_names_table is NULL if OBJF_READNOW. */
6234 if (!dwarf2_per_objfile
->debug_names_table
)
6237 dw_expand_symtabs_matching_file_matcher (dwarf2_per_objfile
, file_matcher
);
6239 mapped_debug_names
&map
= *dwarf2_per_objfile
->debug_names_table
;
6241 dw2_expand_symtabs_matching_symbol (map
, lookup_name
,
6243 kind
, [&] (offset_type namei
)
6245 /* The name was matched, now expand corresponding CUs that were
6247 dw2_debug_names_iterator
iter (map
, kind
, namei
);
6249 struct dwarf2_per_cu_data
*per_cu
;
6250 while ((per_cu
= iter
.next ()) != NULL
)
6251 dw2_expand_symtabs_matching_one (per_cu
, file_matcher
,
6257 const struct quick_symbol_functions dwarf2_debug_names_functions
=
6260 dw2_find_last_source_symtab
,
6261 dw2_forget_cached_source_info
,
6262 dw2_map_symtabs_matching_filename
,
6263 dw2_debug_names_lookup_symbol
,
6265 dw2_debug_names_dump
,
6266 dw2_debug_names_expand_symtabs_for_function
,
6267 dw2_expand_all_symtabs
,
6268 dw2_expand_symtabs_with_fullname
,
6269 dw2_debug_names_map_matching_symbols
,
6270 dw2_debug_names_expand_symtabs_matching
,
6271 dw2_find_pc_sect_compunit_symtab
,
6273 dw2_map_symbol_filenames
6276 /* Get the content of the .gdb_index section of OBJ. SECTION_OWNER should point
6277 to either a dwarf2_per_objfile or dwz_file object. */
6279 template <typename T
>
6280 static gdb::array_view
<const gdb_byte
>
6281 get_gdb_index_contents_from_section (objfile
*obj
, T
*section_owner
)
6283 dwarf2_section_info
*section
= §ion_owner
->gdb_index
;
6285 if (dwarf2_section_empty_p (section
))
6288 /* Older elfutils strip versions could keep the section in the main
6289 executable while splitting it for the separate debug info file. */
6290 if ((get_section_flags (section
) & SEC_HAS_CONTENTS
) == 0)
6293 dwarf2_read_section (obj
, section
);
6295 /* dwarf2_section_info::size is a bfd_size_type, while
6296 gdb::array_view works with size_t. On 32-bit hosts, with
6297 --enable-64-bit-bfd, bfd_size_type is a 64-bit type, while size_t
6298 is 32-bit. So we need an explicit narrowing conversion here.
6299 This is fine, because it's impossible to allocate or mmap an
6300 array/buffer larger than what size_t can represent. */
6301 return gdb::make_array_view (section
->buffer
, section
->size
);
6304 /* Lookup the index cache for the contents of the index associated to
6307 static gdb::array_view
<const gdb_byte
>
6308 get_gdb_index_contents_from_cache (objfile
*obj
, dwarf2_per_objfile
*dwarf2_obj
)
6310 const bfd_build_id
*build_id
= build_id_bfd_get (obj
->obfd
);
6311 if (build_id
== nullptr)
6314 return global_index_cache
.lookup_gdb_index (build_id
,
6315 &dwarf2_obj
->index_cache_res
);
6318 /* Same as the above, but for DWZ. */
6320 static gdb::array_view
<const gdb_byte
>
6321 get_gdb_index_contents_from_cache_dwz (objfile
*obj
, dwz_file
*dwz
)
6323 const bfd_build_id
*build_id
= build_id_bfd_get (dwz
->dwz_bfd
.get ());
6324 if (build_id
== nullptr)
6327 return global_index_cache
.lookup_gdb_index (build_id
, &dwz
->index_cache_res
);
6330 /* See symfile.h. */
6333 dwarf2_initialize_objfile (struct objfile
*objfile
, dw_index_kind
*index_kind
)
6335 struct dwarf2_per_objfile
*dwarf2_per_objfile
6336 = get_dwarf2_per_objfile (objfile
);
6338 /* If we're about to read full symbols, don't bother with the
6339 indices. In this case we also don't care if some other debug
6340 format is making psymtabs, because they are all about to be
6342 if ((objfile
->flags
& OBJF_READNOW
))
6344 dwarf2_per_objfile
->using_index
= 1;
6345 create_all_comp_units (dwarf2_per_objfile
);
6346 create_all_type_units (dwarf2_per_objfile
);
6347 dwarf2_per_objfile
->quick_file_names_table
6348 = create_quick_file_names_table
6349 (dwarf2_per_objfile
->all_comp_units
.size ());
6351 for (int i
= 0; i
< (dwarf2_per_objfile
->all_comp_units
.size ()
6352 + dwarf2_per_objfile
->all_type_units
.size ()); ++i
)
6354 dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->get_cutu (i
);
6356 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6357 struct dwarf2_per_cu_quick_data
);
6360 /* Return 1 so that gdb sees the "quick" functions. However,
6361 these functions will be no-ops because we will have expanded
6363 *index_kind
= dw_index_kind::GDB_INDEX
;
6367 if (dwarf2_read_debug_names (dwarf2_per_objfile
))
6369 *index_kind
= dw_index_kind::DEBUG_NAMES
;
6373 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6374 get_gdb_index_contents_from_section
<struct dwarf2_per_objfile
>,
6375 get_gdb_index_contents_from_section
<dwz_file
>))
6377 *index_kind
= dw_index_kind::GDB_INDEX
;
6381 /* ... otherwise, try to find the index in the index cache. */
6382 if (dwarf2_read_gdb_index (dwarf2_per_objfile
,
6383 get_gdb_index_contents_from_cache
,
6384 get_gdb_index_contents_from_cache_dwz
))
6386 global_index_cache
.hit ();
6387 *index_kind
= dw_index_kind::GDB_INDEX
;
6391 global_index_cache
.miss ();
6397 /* Build a partial symbol table. */
6400 dwarf2_build_psymtabs (struct objfile
*objfile
)
6402 struct dwarf2_per_objfile
*dwarf2_per_objfile
6403 = get_dwarf2_per_objfile (objfile
);
6405 init_psymbol_list (objfile
, 1024);
6409 /* This isn't really ideal: all the data we allocate on the
6410 objfile's obstack is still uselessly kept around. However,
6411 freeing it seems unsafe. */
6412 psymtab_discarder
psymtabs (objfile
);
6413 dwarf2_build_psymtabs_hard (dwarf2_per_objfile
);
6416 /* (maybe) store an index in the cache. */
6417 global_index_cache
.store (dwarf2_per_objfile
);
6419 catch (const gdb_exception_error
&except
)
6421 exception_print (gdb_stderr
, except
);
6425 /* Return the total length of the CU described by HEADER. */
6428 get_cu_length (const struct comp_unit_head
*header
)
6430 return header
->initial_length_size
+ header
->length
;
6433 /* Return TRUE if SECT_OFF is within CU_HEADER. */
6436 offset_in_cu_p (const comp_unit_head
*cu_header
, sect_offset sect_off
)
6438 sect_offset bottom
= cu_header
->sect_off
;
6439 sect_offset top
= cu_header
->sect_off
+ get_cu_length (cu_header
);
6441 return sect_off
>= bottom
&& sect_off
< top
;
6444 /* Find the base address of the compilation unit for range lists and
6445 location lists. It will normally be specified by DW_AT_low_pc.
6446 In DWARF-3 draft 4, the base address could be overridden by
6447 DW_AT_entry_pc. It's been removed, but GCC still uses this for
6448 compilation units with discontinuous ranges. */
6451 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
6453 struct attribute
*attr
;
6456 cu
->base_address
= 0;
6458 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
6459 if (attr
!= nullptr)
6461 cu
->base_address
= attr_value_as_address (attr
);
6466 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6467 if (attr
!= nullptr)
6469 cu
->base_address
= attr_value_as_address (attr
);
6475 /* Read in the comp unit header information from the debug_info at info_ptr.
6476 Use rcuh_kind::COMPILE as the default type if not known by the caller.
6477 NOTE: This leaves members offset, first_die_offset to be filled in
6480 static const gdb_byte
*
6481 read_comp_unit_head (struct comp_unit_head
*cu_header
,
6482 const gdb_byte
*info_ptr
,
6483 struct dwarf2_section_info
*section
,
6484 rcuh_kind section_kind
)
6487 unsigned int bytes_read
;
6488 const char *filename
= get_section_file_name (section
);
6489 bfd
*abfd
= get_section_bfd_owner (section
);
6491 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
6492 cu_header
->initial_length_size
= bytes_read
;
6493 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
6494 info_ptr
+= bytes_read
;
6495 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
6496 if (cu_header
->version
< 2 || cu_header
->version
> 5)
6497 error (_("Dwarf Error: wrong version in compilation unit header "
6498 "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
6499 cu_header
->version
, filename
);
6501 if (cu_header
->version
< 5)
6502 switch (section_kind
)
6504 case rcuh_kind::COMPILE
:
6505 cu_header
->unit_type
= DW_UT_compile
;
6507 case rcuh_kind::TYPE
:
6508 cu_header
->unit_type
= DW_UT_type
;
6511 internal_error (__FILE__
, __LINE__
,
6512 _("read_comp_unit_head: invalid section_kind"));
6516 cu_header
->unit_type
= static_cast<enum dwarf_unit_type
>
6517 (read_1_byte (abfd
, info_ptr
));
6519 switch (cu_header
->unit_type
)
6523 case DW_UT_skeleton
:
6524 case DW_UT_split_compile
:
6525 if (section_kind
!= rcuh_kind::COMPILE
)
6526 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6527 "(is %s, should be %s) [in module %s]"),
6528 dwarf_unit_type_name (cu_header
->unit_type
),
6529 dwarf_unit_type_name (DW_UT_type
), filename
);
6532 case DW_UT_split_type
:
6533 section_kind
= rcuh_kind::TYPE
;
6536 error (_("Dwarf Error: wrong unit_type in compilation unit header "
6537 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
6538 "[in module %s]"), cu_header
->unit_type
,
6539 dwarf_unit_type_name (DW_UT_compile
),
6540 dwarf_unit_type_name (DW_UT_skeleton
),
6541 dwarf_unit_type_name (DW_UT_split_compile
),
6542 dwarf_unit_type_name (DW_UT_type
),
6543 dwarf_unit_type_name (DW_UT_split_type
), filename
);
6546 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6549 cu_header
->abbrev_sect_off
= (sect_offset
) read_offset (abfd
, info_ptr
,
6552 info_ptr
+= bytes_read
;
6553 if (cu_header
->version
< 5)
6555 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
6558 signed_addr
= bfd_get_sign_extend_vma (abfd
);
6559 if (signed_addr
< 0)
6560 internal_error (__FILE__
, __LINE__
,
6561 _("read_comp_unit_head: dwarf from non elf file"));
6562 cu_header
->signed_addr_p
= signed_addr
;
6564 bool header_has_signature
= section_kind
== rcuh_kind::TYPE
6565 || cu_header
->unit_type
== DW_UT_skeleton
6566 || cu_header
->unit_type
== DW_UT_split_compile
;
6568 if (header_has_signature
)
6570 cu_header
->signature
= read_8_bytes (abfd
, info_ptr
);
6574 if (section_kind
== rcuh_kind::TYPE
)
6576 LONGEST type_offset
;
6577 type_offset
= read_offset (abfd
, info_ptr
, cu_header
, &bytes_read
);
6578 info_ptr
+= bytes_read
;
6579 cu_header
->type_cu_offset_in_tu
= (cu_offset
) type_offset
;
6580 if (to_underlying (cu_header
->type_cu_offset_in_tu
) != type_offset
)
6581 error (_("Dwarf Error: Too big type_offset in compilation unit "
6582 "header (is %s) [in module %s]"), plongest (type_offset
),
6589 /* Helper function that returns the proper abbrev section for
6592 static struct dwarf2_section_info
*
6593 get_abbrev_section_for_cu (struct dwarf2_per_cu_data
*this_cu
)
6595 struct dwarf2_section_info
*abbrev
;
6596 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
6598 if (this_cu
->is_dwz
)
6599 abbrev
= &dwarf2_get_dwz_file (dwarf2_per_objfile
)->abbrev
;
6601 abbrev
= &dwarf2_per_objfile
->abbrev
;
6606 /* Subroutine of read_and_check_comp_unit_head and
6607 read_and_check_type_unit_head to simplify them.
6608 Perform various error checking on the header. */
6611 error_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6612 struct comp_unit_head
*header
,
6613 struct dwarf2_section_info
*section
,
6614 struct dwarf2_section_info
*abbrev_section
)
6616 const char *filename
= get_section_file_name (section
);
6618 if (to_underlying (header
->abbrev_sect_off
)
6619 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
, abbrev_section
))
6620 error (_("Dwarf Error: bad offset (%s) in compilation unit header "
6621 "(offset %s + 6) [in module %s]"),
6622 sect_offset_str (header
->abbrev_sect_off
),
6623 sect_offset_str (header
->sect_off
),
6626 /* Cast to ULONGEST to use 64-bit arithmetic when possible to
6627 avoid potential 32-bit overflow. */
6628 if (((ULONGEST
) header
->sect_off
+ get_cu_length (header
))
6630 error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
6631 "(offset %s + 0) [in module %s]"),
6632 header
->length
, sect_offset_str (header
->sect_off
),
6636 /* Read in a CU/TU header and perform some basic error checking.
6637 The contents of the header are stored in HEADER.
6638 The result is a pointer to the start of the first DIE. */
6640 static const gdb_byte
*
6641 read_and_check_comp_unit_head (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6642 struct comp_unit_head
*header
,
6643 struct dwarf2_section_info
*section
,
6644 struct dwarf2_section_info
*abbrev_section
,
6645 const gdb_byte
*info_ptr
,
6646 rcuh_kind section_kind
)
6648 const gdb_byte
*beg_of_comp_unit
= info_ptr
;
6650 header
->sect_off
= (sect_offset
) (beg_of_comp_unit
- section
->buffer
);
6652 info_ptr
= read_comp_unit_head (header
, info_ptr
, section
, section_kind
);
6654 header
->first_die_cu_offset
= (cu_offset
) (info_ptr
- beg_of_comp_unit
);
6656 error_check_comp_unit_head (dwarf2_per_objfile
, header
, section
,
6662 /* Fetch the abbreviation table offset from a comp or type unit header. */
6665 read_abbrev_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6666 struct dwarf2_section_info
*section
,
6667 sect_offset sect_off
)
6669 bfd
*abfd
= get_section_bfd_owner (section
);
6670 const gdb_byte
*info_ptr
;
6671 unsigned int initial_length_size
, offset_size
;
6674 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
6675 info_ptr
= section
->buffer
+ to_underlying (sect_off
);
6676 read_initial_length (abfd
, info_ptr
, &initial_length_size
);
6677 offset_size
= initial_length_size
== 4 ? 4 : 8;
6678 info_ptr
+= initial_length_size
;
6680 version
= read_2_bytes (abfd
, info_ptr
);
6684 /* Skip unit type and address size. */
6688 return (sect_offset
) read_offset_1 (abfd
, info_ptr
, offset_size
);
6691 /* Allocate a new partial symtab for file named NAME and mark this new
6692 partial symtab as being an include of PST. */
6695 dwarf2_create_include_psymtab (const char *name
, struct partial_symtab
*pst
,
6696 struct objfile
*objfile
)
6698 struct partial_symtab
*subpst
= new partial_symtab (name
, objfile
);
6700 if (!IS_ABSOLUTE_PATH (subpst
->filename
))
6702 /* It shares objfile->objfile_obstack. */
6703 subpst
->dirname
= pst
->dirname
;
6706 subpst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (1);
6707 subpst
->dependencies
[0] = pst
;
6708 subpst
->number_of_dependencies
= 1;
6710 subpst
->read_symtab
= pst
->read_symtab
;
6712 /* No private part is necessary for include psymtabs. This property
6713 can be used to differentiate between such include psymtabs and
6714 the regular ones. */
6715 subpst
->read_symtab_private
= NULL
;
6718 /* Read the Line Number Program data and extract the list of files
6719 included by the source file represented by PST. Build an include
6720 partial symtab for each of these included files. */
6723 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
6724 struct die_info
*die
,
6725 struct partial_symtab
*pst
)
6728 struct attribute
*attr
;
6730 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
6731 if (attr
!= nullptr)
6732 lh
= dwarf_decode_line_header ((sect_offset
) DW_UNSND (attr
), cu
);
6734 return; /* No linetable, so no includes. */
6736 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). Also note
6737 that we pass in the raw text_low here; that is ok because we're
6738 only decoding the line table to make include partial symtabs, and
6739 so the addresses aren't really used. */
6740 dwarf_decode_lines (lh
.get (), pst
->dirname
, cu
, pst
,
6741 pst
->raw_text_low (), 1);
6745 hash_signatured_type (const void *item
)
6747 const struct signatured_type
*sig_type
6748 = (const struct signatured_type
*) item
;
6750 /* This drops the top 32 bits of the signature, but is ok for a hash. */
6751 return sig_type
->signature
;
6755 eq_signatured_type (const void *item_lhs
, const void *item_rhs
)
6757 const struct signatured_type
*lhs
= (const struct signatured_type
*) item_lhs
;
6758 const struct signatured_type
*rhs
= (const struct signatured_type
*) item_rhs
;
6760 return lhs
->signature
== rhs
->signature
;
6763 /* Allocate a hash table for signatured types. */
6766 allocate_signatured_type_table (struct objfile
*objfile
)
6768 return htab_create_alloc_ex (41,
6769 hash_signatured_type
,
6772 &objfile
->objfile_obstack
,
6773 hashtab_obstack_allocate
,
6774 dummy_obstack_deallocate
);
6777 /* A helper function to add a signatured type CU to a table. */
6780 add_signatured_type_cu_to_table (void **slot
, void *datum
)
6782 struct signatured_type
*sigt
= (struct signatured_type
*) *slot
;
6783 std::vector
<signatured_type
*> *all_type_units
6784 = (std::vector
<signatured_type
*> *) datum
;
6786 all_type_units
->push_back (sigt
);
6791 /* A helper for create_debug_types_hash_table. Read types from SECTION
6792 and fill them into TYPES_HTAB. It will process only type units,
6793 therefore DW_UT_type. */
6796 create_debug_type_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6797 struct dwo_file
*dwo_file
,
6798 dwarf2_section_info
*section
, htab_t
&types_htab
,
6799 rcuh_kind section_kind
)
6801 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6802 struct dwarf2_section_info
*abbrev_section
;
6804 const gdb_byte
*info_ptr
, *end_ptr
;
6806 abbrev_section
= (dwo_file
!= NULL
6807 ? &dwo_file
->sections
.abbrev
6808 : &dwarf2_per_objfile
->abbrev
);
6810 if (dwarf_read_debug
)
6811 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
6812 get_section_name (section
),
6813 get_section_file_name (abbrev_section
));
6815 dwarf2_read_section (objfile
, section
);
6816 info_ptr
= section
->buffer
;
6818 if (info_ptr
== NULL
)
6821 /* We can't set abfd until now because the section may be empty or
6822 not present, in which case the bfd is unknown. */
6823 abfd
= get_section_bfd_owner (section
);
6825 /* We don't use cutu_reader here because we don't need to read
6826 any dies: the signature is in the header. */
6828 end_ptr
= info_ptr
+ section
->size
;
6829 while (info_ptr
< end_ptr
)
6831 struct signatured_type
*sig_type
;
6832 struct dwo_unit
*dwo_tu
;
6834 const gdb_byte
*ptr
= info_ptr
;
6835 struct comp_unit_head header
;
6836 unsigned int length
;
6838 sect_offset sect_off
= (sect_offset
) (ptr
- section
->buffer
);
6840 /* Initialize it due to a false compiler warning. */
6841 header
.signature
= -1;
6842 header
.type_cu_offset_in_tu
= (cu_offset
) -1;
6844 /* We need to read the type's signature in order to build the hash
6845 table, but we don't need anything else just yet. */
6847 ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
, &header
, section
,
6848 abbrev_section
, ptr
, section_kind
);
6850 length
= get_cu_length (&header
);
6852 /* Skip dummy type units. */
6853 if (ptr
>= info_ptr
+ length
6854 || peek_abbrev_code (abfd
, ptr
) == 0
6855 || header
.unit_type
!= DW_UT_type
)
6861 if (types_htab
== NULL
)
6864 types_htab
= allocate_dwo_unit_table (objfile
);
6866 types_htab
= allocate_signatured_type_table (objfile
);
6872 dwo_tu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6874 dwo_tu
->dwo_file
= dwo_file
;
6875 dwo_tu
->signature
= header
.signature
;
6876 dwo_tu
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6877 dwo_tu
->section
= section
;
6878 dwo_tu
->sect_off
= sect_off
;
6879 dwo_tu
->length
= length
;
6883 /* N.B.: type_offset is not usable if this type uses a DWO file.
6884 The real type_offset is in the DWO file. */
6886 sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
6887 struct signatured_type
);
6888 sig_type
->signature
= header
.signature
;
6889 sig_type
->type_offset_in_tu
= header
.type_cu_offset_in_tu
;
6890 sig_type
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
6891 sig_type
->per_cu
.is_debug_types
= 1;
6892 sig_type
->per_cu
.section
= section
;
6893 sig_type
->per_cu
.sect_off
= sect_off
;
6894 sig_type
->per_cu
.length
= length
;
6897 slot
= htab_find_slot (types_htab
,
6898 dwo_file
? (void*) dwo_tu
: (void *) sig_type
,
6900 gdb_assert (slot
!= NULL
);
6903 sect_offset dup_sect_off
;
6907 const struct dwo_unit
*dup_tu
6908 = (const struct dwo_unit
*) *slot
;
6910 dup_sect_off
= dup_tu
->sect_off
;
6914 const struct signatured_type
*dup_tu
6915 = (const struct signatured_type
*) *slot
;
6917 dup_sect_off
= dup_tu
->per_cu
.sect_off
;
6920 complaint (_("debug type entry at offset %s is duplicate to"
6921 " the entry at offset %s, signature %s"),
6922 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
6923 hex_string (header
.signature
));
6925 *slot
= dwo_file
? (void *) dwo_tu
: (void *) sig_type
;
6927 if (dwarf_read_debug
> 1)
6928 fprintf_unfiltered (gdb_stdlog
, " offset %s, signature %s\n",
6929 sect_offset_str (sect_off
),
6930 hex_string (header
.signature
));
6936 /* Create the hash table of all entries in the .debug_types
6937 (or .debug_types.dwo) section(s).
6938 If reading a DWO file, then DWO_FILE is a pointer to the DWO file object,
6939 otherwise it is NULL.
6941 The result is a pointer to the hash table or NULL if there are no types.
6943 Note: This function processes DWO files only, not DWP files. */
6946 create_debug_types_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
6947 struct dwo_file
*dwo_file
,
6948 gdb::array_view
<dwarf2_section_info
> type_sections
,
6951 for (dwarf2_section_info
§ion
: type_sections
)
6952 create_debug_type_hash_table (dwarf2_per_objfile
, dwo_file
, §ion
,
6953 types_htab
, rcuh_kind::TYPE
);
6956 /* Create the hash table of all entries in the .debug_types section,
6957 and initialize all_type_units.
6958 The result is zero if there is an error (e.g. missing .debug_types section),
6959 otherwise non-zero. */
6962 create_all_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
6964 htab_t types_htab
= NULL
;
6966 create_debug_type_hash_table (dwarf2_per_objfile
, NULL
,
6967 &dwarf2_per_objfile
->info
, types_htab
,
6968 rcuh_kind::COMPILE
);
6969 create_debug_types_hash_table (dwarf2_per_objfile
, NULL
,
6970 dwarf2_per_objfile
->types
, types_htab
);
6971 if (types_htab
== NULL
)
6973 dwarf2_per_objfile
->signatured_types
= NULL
;
6977 dwarf2_per_objfile
->signatured_types
= types_htab
;
6979 gdb_assert (dwarf2_per_objfile
->all_type_units
.empty ());
6980 dwarf2_per_objfile
->all_type_units
.reserve (htab_elements (types_htab
));
6982 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_table
,
6983 &dwarf2_per_objfile
->all_type_units
);
6988 /* Add an entry for signature SIG to dwarf2_per_objfile->signatured_types.
6989 If SLOT is non-NULL, it is the entry to use in the hash table.
6990 Otherwise we find one. */
6992 static struct signatured_type
*
6993 add_type_unit (struct dwarf2_per_objfile
*dwarf2_per_objfile
, ULONGEST sig
,
6996 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
6998 if (dwarf2_per_objfile
->all_type_units
.size ()
6999 == dwarf2_per_objfile
->all_type_units
.capacity ())
7000 ++dwarf2_per_objfile
->tu_stats
.nr_all_type_units_reallocs
;
7002 signatured_type
*sig_type
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7003 struct signatured_type
);
7005 dwarf2_per_objfile
->all_type_units
.push_back (sig_type
);
7006 sig_type
->signature
= sig
;
7007 sig_type
->per_cu
.is_debug_types
= 1;
7008 if (dwarf2_per_objfile
->using_index
)
7010 sig_type
->per_cu
.v
.quick
=
7011 OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7012 struct dwarf2_per_cu_quick_data
);
7017 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7020 gdb_assert (*slot
== NULL
);
7022 /* The rest of sig_type must be filled in by the caller. */
7026 /* Subroutine of lookup_dwo_signatured_type and lookup_dwp_signatured_type.
7027 Fill in SIG_ENTRY with DWO_ENTRY. */
7030 fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
7031 struct signatured_type
*sig_entry
,
7032 struct dwo_unit
*dwo_entry
)
7034 /* Make sure we're not clobbering something we don't expect to. */
7035 gdb_assert (! sig_entry
->per_cu
.queued
);
7036 gdb_assert (sig_entry
->per_cu
.cu
== NULL
);
7037 if (dwarf2_per_objfile
->using_index
)
7039 gdb_assert (sig_entry
->per_cu
.v
.quick
!= NULL
);
7040 gdb_assert (sig_entry
->per_cu
.v
.quick
->compunit_symtab
== NULL
);
7043 gdb_assert (sig_entry
->per_cu
.v
.psymtab
== NULL
);
7044 gdb_assert (sig_entry
->signature
== dwo_entry
->signature
);
7045 gdb_assert (to_underlying (sig_entry
->type_offset_in_section
) == 0);
7046 gdb_assert (sig_entry
->type_unit_group
== NULL
);
7047 gdb_assert (sig_entry
->dwo_unit
== NULL
);
7049 sig_entry
->per_cu
.section
= dwo_entry
->section
;
7050 sig_entry
->per_cu
.sect_off
= dwo_entry
->sect_off
;
7051 sig_entry
->per_cu
.length
= dwo_entry
->length
;
7052 sig_entry
->per_cu
.reading_dwo_directly
= 1;
7053 sig_entry
->per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
7054 sig_entry
->type_offset_in_tu
= dwo_entry
->type_offset_in_tu
;
7055 sig_entry
->dwo_unit
= dwo_entry
;
7058 /* Subroutine of lookup_signatured_type.
7059 If we haven't read the TU yet, create the signatured_type data structure
7060 for a TU to be read in directly from a DWO file, bypassing the stub.
7061 This is the "Stay in DWO Optimization": When there is no DWP file and we're
7062 using .gdb_index, then when reading a CU we want to stay in the DWO file
7063 containing that CU. Otherwise we could end up reading several other DWO
7064 files (due to comdat folding) to process the transitive closure of all the
7065 mentioned TUs, and that can be slow. The current DWO file will have every
7066 type signature that it needs.
7067 We only do this for .gdb_index because in the psymtab case we already have
7068 to read all the DWOs to build the type unit groups. */
7070 static struct signatured_type
*
7071 lookup_dwo_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7073 struct dwarf2_per_objfile
*dwarf2_per_objfile
7074 = cu
->per_cu
->dwarf2_per_objfile
;
7075 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7076 struct dwo_file
*dwo_file
;
7077 struct dwo_unit find_dwo_entry
, *dwo_entry
;
7078 struct signatured_type find_sig_entry
, *sig_entry
;
7081 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7083 /* If TU skeletons have been removed then we may not have read in any
7085 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7087 dwarf2_per_objfile
->signatured_types
7088 = allocate_signatured_type_table (objfile
);
7091 /* We only ever need to read in one copy of a signatured type.
7092 Use the global signatured_types array to do our own comdat-folding
7093 of types. If this is the first time we're reading this TU, and
7094 the TU has an entry in .gdb_index, replace the recorded data from
7095 .gdb_index with this TU. */
7097 find_sig_entry
.signature
= sig
;
7098 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7099 &find_sig_entry
, INSERT
);
7100 sig_entry
= (struct signatured_type
*) *slot
;
7102 /* We can get here with the TU already read, *or* in the process of being
7103 read. Don't reassign the global entry to point to this DWO if that's
7104 the case. Also note that if the TU is already being read, it may not
7105 have come from a DWO, the program may be a mix of Fission-compiled
7106 code and non-Fission-compiled code. */
7108 /* Have we already tried to read this TU?
7109 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7110 needn't exist in the global table yet). */
7111 if (sig_entry
!= NULL
&& sig_entry
->per_cu
.tu_read
)
7114 /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
7115 dwo_unit of the TU itself. */
7116 dwo_file
= cu
->dwo_unit
->dwo_file
;
7118 /* Ok, this is the first time we're reading this TU. */
7119 if (dwo_file
->tus
== NULL
)
7121 find_dwo_entry
.signature
= sig
;
7122 dwo_entry
= (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_entry
);
7123 if (dwo_entry
== NULL
)
7126 /* If the global table doesn't have an entry for this TU, add one. */
7127 if (sig_entry
== NULL
)
7128 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7130 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7131 sig_entry
->per_cu
.tu_read
= 1;
7135 /* Subroutine of lookup_signatured_type.
7136 Look up the type for signature SIG, and if we can't find SIG in .gdb_index
7137 then try the DWP file. If the TU stub (skeleton) has been removed then
7138 it won't be in .gdb_index. */
7140 static struct signatured_type
*
7141 lookup_dwp_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7143 struct dwarf2_per_objfile
*dwarf2_per_objfile
7144 = cu
->per_cu
->dwarf2_per_objfile
;
7145 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7146 struct dwp_file
*dwp_file
= get_dwp_file (dwarf2_per_objfile
);
7147 struct dwo_unit
*dwo_entry
;
7148 struct signatured_type find_sig_entry
, *sig_entry
;
7151 gdb_assert (cu
->dwo_unit
&& dwarf2_per_objfile
->using_index
);
7152 gdb_assert (dwp_file
!= NULL
);
7154 /* If TU skeletons have been removed then we may not have read in any
7156 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7158 dwarf2_per_objfile
->signatured_types
7159 = allocate_signatured_type_table (objfile
);
7162 find_sig_entry
.signature
= sig
;
7163 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
,
7164 &find_sig_entry
, INSERT
);
7165 sig_entry
= (struct signatured_type
*) *slot
;
7167 /* Have we already tried to read this TU?
7168 Note: sig_entry can be NULL if the skeleton TU was removed (thus it
7169 needn't exist in the global table yet). */
7170 if (sig_entry
!= NULL
)
7173 if (dwp_file
->tus
== NULL
)
7175 dwo_entry
= lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, NULL
,
7176 sig
, 1 /* is_debug_types */);
7177 if (dwo_entry
== NULL
)
7180 sig_entry
= add_type_unit (dwarf2_per_objfile
, sig
, slot
);
7181 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, sig_entry
, dwo_entry
);
7186 /* Lookup a signature based type for DW_FORM_ref_sig8.
7187 Returns NULL if signature SIG is not present in the table.
7188 It is up to the caller to complain about this. */
7190 static struct signatured_type
*
7191 lookup_signatured_type (struct dwarf2_cu
*cu
, ULONGEST sig
)
7193 struct dwarf2_per_objfile
*dwarf2_per_objfile
7194 = cu
->per_cu
->dwarf2_per_objfile
;
7197 && dwarf2_per_objfile
->using_index
)
7199 /* We're in a DWO/DWP file, and we're using .gdb_index.
7200 These cases require special processing. */
7201 if (get_dwp_file (dwarf2_per_objfile
) == NULL
)
7202 return lookup_dwo_signatured_type (cu
, sig
);
7204 return lookup_dwp_signatured_type (cu
, sig
);
7208 struct signatured_type find_entry
, *entry
;
7210 if (dwarf2_per_objfile
->signatured_types
== NULL
)
7212 find_entry
.signature
= sig
;
7213 entry
= ((struct signatured_type
*)
7214 htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
));
7219 /* Return the address base of the compile unit, which, if exists, is stored
7220 either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base. */
7221 static gdb::optional
<ULONGEST
>
7222 lookup_addr_base (struct die_info
*comp_unit_die
)
7224 struct attribute
*attr
;
7225 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_addr_base
);
7226 if (attr
== nullptr)
7227 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_addr_base
);
7228 if (attr
== nullptr)
7229 return gdb::optional
<ULONGEST
> ();
7230 return DW_UNSND (attr
);
7233 /* Return range lists base of the compile unit, which, if exists, is stored
7234 either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base. */
7236 lookup_ranges_base (struct die_info
*comp_unit_die
)
7238 struct attribute
*attr
;
7239 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_rnglists_base
);
7240 if (attr
== nullptr)
7241 attr
= dwarf2_attr_no_follow (comp_unit_die
, DW_AT_GNU_ranges_base
);
7242 if (attr
== nullptr)
7244 return DW_UNSND (attr
);
7247 /* Low level DIE reading support. */
7249 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
7252 init_cu_die_reader (struct die_reader_specs
*reader
,
7253 struct dwarf2_cu
*cu
,
7254 struct dwarf2_section_info
*section
,
7255 struct dwo_file
*dwo_file
,
7256 struct abbrev_table
*abbrev_table
)
7258 gdb_assert (section
->readin
&& section
->buffer
!= NULL
);
7259 reader
->abfd
= get_section_bfd_owner (section
);
7261 reader
->dwo_file
= dwo_file
;
7262 reader
->die_section
= section
;
7263 reader
->buffer
= section
->buffer
;
7264 reader
->buffer_end
= section
->buffer
+ section
->size
;
7265 reader
->comp_dir
= NULL
;
7266 reader
->abbrev_table
= abbrev_table
;
7269 /* Subroutine of cutu_reader to simplify it.
7270 Read in the rest of a CU/TU top level DIE from DWO_UNIT.
7271 There's just a lot of work to do, and cutu_reader is big enough
7274 STUB_COMP_UNIT_DIE is for the stub DIE, we copy over certain attributes
7275 from it to the DIE in the DWO. If NULL we are skipping the stub.
7276 STUB_COMP_DIR is similar to STUB_COMP_UNIT_DIE: When reading a TU directly
7277 from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
7278 attribute of the referencing CU. At most one of STUB_COMP_UNIT_DIE and
7279 STUB_COMP_DIR may be non-NULL.
7280 *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
7281 are filled in with the info of the DIE from the DWO file.
7282 *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
7283 from the dwo. Since *RESULT_READER references this abbrev table, it must be
7284 kept around for at least as long as *RESULT_READER.
7286 The result is non-zero if a valid (non-dummy) DIE was found. */
7289 read_cutu_die_from_dwo (struct dwarf2_per_cu_data
*this_cu
,
7290 struct dwo_unit
*dwo_unit
,
7291 struct die_info
*stub_comp_unit_die
,
7292 const char *stub_comp_dir
,
7293 struct die_reader_specs
*result_reader
,
7294 const gdb_byte
**result_info_ptr
,
7295 struct die_info
**result_comp_unit_die
,
7296 int *result_has_children
,
7297 abbrev_table_up
*result_dwo_abbrev_table
)
7299 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7300 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7301 struct dwarf2_cu
*cu
= this_cu
->cu
;
7303 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7304 struct attribute
*comp_dir
, *stmt_list
, *low_pc
, *high_pc
, *ranges
;
7305 int i
,num_extra_attrs
;
7306 struct dwarf2_section_info
*dwo_abbrev_section
;
7307 struct die_info
*comp_unit_die
;
7309 /* At most one of these may be provided. */
7310 gdb_assert ((stub_comp_unit_die
!= NULL
) + (stub_comp_dir
!= NULL
) <= 1);
7312 /* These attributes aren't processed until later:
7313 DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges.
7314 DW_AT_comp_dir is used now, to find the DWO file, but it is also
7315 referenced later. However, these attributes are found in the stub
7316 which we won't have later. In order to not impose this complication
7317 on the rest of the code, we read them here and copy them to the
7326 if (stub_comp_unit_die
!= NULL
)
7328 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
7330 if (! this_cu
->is_debug_types
)
7331 stmt_list
= dwarf2_attr (stub_comp_unit_die
, DW_AT_stmt_list
, cu
);
7332 low_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_low_pc
, cu
);
7333 high_pc
= dwarf2_attr (stub_comp_unit_die
, DW_AT_high_pc
, cu
);
7334 ranges
= dwarf2_attr (stub_comp_unit_die
, DW_AT_ranges
, cu
);
7335 comp_dir
= dwarf2_attr (stub_comp_unit_die
, DW_AT_comp_dir
, cu
);
7337 cu
->addr_base
= lookup_addr_base (stub_comp_unit_die
);
7339 /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
7340 here (if needed). We need the value before we can process
7342 cu
->ranges_base
= lookup_ranges_base (stub_comp_unit_die
);
7344 else if (stub_comp_dir
!= NULL
)
7346 /* Reconstruct the comp_dir attribute to simplify the code below. */
7347 comp_dir
= XOBNEW (&cu
->comp_unit_obstack
, struct attribute
);
7348 comp_dir
->name
= DW_AT_comp_dir
;
7349 comp_dir
->form
= DW_FORM_string
;
7350 DW_STRING_IS_CANONICAL (comp_dir
) = 0;
7351 DW_STRING (comp_dir
) = stub_comp_dir
;
7354 /* Set up for reading the DWO CU/TU. */
7355 cu
->dwo_unit
= dwo_unit
;
7356 dwarf2_section_info
*section
= dwo_unit
->section
;
7357 dwarf2_read_section (objfile
, section
);
7358 abfd
= get_section_bfd_owner (section
);
7359 begin_info_ptr
= info_ptr
= (section
->buffer
7360 + to_underlying (dwo_unit
->sect_off
));
7361 dwo_abbrev_section
= &dwo_unit
->dwo_file
->sections
.abbrev
;
7363 if (this_cu
->is_debug_types
)
7365 struct signatured_type
*sig_type
= (struct signatured_type
*) this_cu
;
7367 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7368 &cu
->header
, section
,
7370 info_ptr
, rcuh_kind::TYPE
);
7371 /* This is not an assert because it can be caused by bad debug info. */
7372 if (sig_type
->signature
!= cu
->header
.signature
)
7374 error (_("Dwarf Error: signature mismatch %s vs %s while reading"
7375 " TU at offset %s [in module %s]"),
7376 hex_string (sig_type
->signature
),
7377 hex_string (cu
->header
.signature
),
7378 sect_offset_str (dwo_unit
->sect_off
),
7379 bfd_get_filename (abfd
));
7381 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7382 /* For DWOs coming from DWP files, we don't know the CU length
7383 nor the type's offset in the TU until now. */
7384 dwo_unit
->length
= get_cu_length (&cu
->header
);
7385 dwo_unit
->type_offset_in_tu
= cu
->header
.type_cu_offset_in_tu
;
7387 /* Establish the type offset that can be used to lookup the type.
7388 For DWO files, we don't know it until now. */
7389 sig_type
->type_offset_in_section
7390 = dwo_unit
->sect_off
+ to_underlying (dwo_unit
->type_offset_in_tu
);
7394 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7395 &cu
->header
, section
,
7397 info_ptr
, rcuh_kind::COMPILE
);
7398 gdb_assert (dwo_unit
->sect_off
== cu
->header
.sect_off
);
7399 /* For DWOs coming from DWP files, we don't know the CU length
7401 dwo_unit
->length
= get_cu_length (&cu
->header
);
7404 *result_dwo_abbrev_table
7405 = abbrev_table_read_table (dwarf2_per_objfile
, dwo_abbrev_section
,
7406 cu
->header
.abbrev_sect_off
);
7407 init_cu_die_reader (result_reader
, cu
, section
, dwo_unit
->dwo_file
,
7408 result_dwo_abbrev_table
->get ());
7410 /* Read in the die, but leave space to copy over the attributes
7411 from the stub. This has the benefit of simplifying the rest of
7412 the code - all the work to maintain the illusion of a single
7413 DW_TAG_{compile,type}_unit DIE is done here. */
7414 num_extra_attrs
= ((stmt_list
!= NULL
)
7418 + (comp_dir
!= NULL
));
7419 info_ptr
= read_full_die_1 (result_reader
, result_comp_unit_die
, info_ptr
,
7420 result_has_children
, num_extra_attrs
);
7422 /* Copy over the attributes from the stub to the DIE we just read in. */
7423 comp_unit_die
= *result_comp_unit_die
;
7424 i
= comp_unit_die
->num_attrs
;
7425 if (stmt_list
!= NULL
)
7426 comp_unit_die
->attrs
[i
++] = *stmt_list
;
7428 comp_unit_die
->attrs
[i
++] = *low_pc
;
7429 if (high_pc
!= NULL
)
7430 comp_unit_die
->attrs
[i
++] = *high_pc
;
7432 comp_unit_die
->attrs
[i
++] = *ranges
;
7433 if (comp_dir
!= NULL
)
7434 comp_unit_die
->attrs
[i
++] = *comp_dir
;
7435 comp_unit_die
->num_attrs
+= num_extra_attrs
;
7437 if (dwarf_die_debug
)
7439 fprintf_unfiltered (gdb_stdlog
,
7440 "Read die from %s@0x%x of %s:\n",
7441 get_section_name (section
),
7442 (unsigned) (begin_info_ptr
- section
->buffer
),
7443 bfd_get_filename (abfd
));
7444 dump_die (comp_unit_die
, dwarf_die_debug
);
7447 /* Save the comp_dir attribute. If there is no DWP file then we'll read
7448 TUs by skipping the stub and going directly to the entry in the DWO file.
7449 However, skipping the stub means we won't get DW_AT_comp_dir, so we have
7450 to get it via circuitous means. Blech. */
7451 if (comp_dir
!= NULL
)
7452 result_reader
->comp_dir
= DW_STRING (comp_dir
);
7454 /* Skip dummy compilation units. */
7455 if (info_ptr
>= begin_info_ptr
+ dwo_unit
->length
7456 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7459 *result_info_ptr
= info_ptr
;
7463 /* Return the signature of the compile unit, if found. In DWARF 4 and before,
7464 the signature is in the DW_AT_GNU_dwo_id attribute. In DWARF 5 and later, the
7465 signature is part of the header. */
7466 static gdb::optional
<ULONGEST
>
7467 lookup_dwo_id (struct dwarf2_cu
*cu
, struct die_info
* comp_unit_die
)
7469 if (cu
->header
.version
>= 5)
7470 return cu
->header
.signature
;
7471 struct attribute
*attr
;
7472 attr
= dwarf2_attr (comp_unit_die
, DW_AT_GNU_dwo_id
, cu
);
7473 if (attr
== nullptr)
7474 return gdb::optional
<ULONGEST
> ();
7475 return DW_UNSND (attr
);
7478 /* Subroutine of cutu_reader to simplify it.
7479 Look up the DWO unit specified by COMP_UNIT_DIE of THIS_CU.
7480 Returns NULL if the specified DWO unit cannot be found. */
7482 static struct dwo_unit
*
7483 lookup_dwo_unit (struct dwarf2_per_cu_data
*this_cu
,
7484 struct die_info
*comp_unit_die
,
7485 const char *dwo_name
)
7487 struct dwarf2_cu
*cu
= this_cu
->cu
;
7488 struct dwo_unit
*dwo_unit
;
7489 const char *comp_dir
;
7491 gdb_assert (cu
!= NULL
);
7493 /* Yeah, we look dwo_name up again, but it simplifies the code. */
7494 dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7495 comp_dir
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
7497 if (this_cu
->is_debug_types
)
7499 struct signatured_type
*sig_type
;
7501 /* Since this_cu is the first member of struct signatured_type,
7502 we can go from a pointer to one to a pointer to the other. */
7503 sig_type
= (struct signatured_type
*) this_cu
;
7504 dwo_unit
= lookup_dwo_type_unit (sig_type
, dwo_name
, comp_dir
);
7508 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
7509 if (!signature
.has_value ())
7510 error (_("Dwarf Error: missing dwo_id for dwo_name %s"
7512 dwo_name
, objfile_name (this_cu
->dwarf2_per_objfile
->objfile
));
7513 dwo_unit
= lookup_dwo_comp_unit (this_cu
, dwo_name
, comp_dir
,
7520 /* Subroutine of cutu_reader to simplify it.
7521 See it for a description of the parameters.
7522 Read a TU directly from a DWO file, bypassing the stub. */
7525 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data
*this_cu
,
7526 int use_existing_cu
, int keep
)
7528 struct signatured_type
*sig_type
;
7529 struct die_reader_specs reader
;
7531 /* Verify we can do the following downcast, and that we have the
7533 gdb_assert (this_cu
->is_debug_types
&& this_cu
->reading_dwo_directly
);
7534 sig_type
= (struct signatured_type
*) this_cu
;
7535 gdb_assert (sig_type
->dwo_unit
!= NULL
);
7537 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7539 gdb_assert (this_cu
->cu
->dwo_unit
== sig_type
->dwo_unit
);
7540 /* There's no need to do the rereading_dwo_cu handling that
7541 cutu_reader does since we don't read the stub. */
7545 /* If !use_existing_cu, this_cu->cu must be NULL. */
7546 gdb_assert (this_cu
->cu
== NULL
);
7547 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7550 /* A future optimization, if needed, would be to use an existing
7551 abbrev table. When reading DWOs with skeletonless TUs, all the TUs
7552 could share abbrev tables. */
7554 if (read_cutu_die_from_dwo (this_cu
, sig_type
->dwo_unit
,
7555 NULL
/* stub_comp_unit_die */,
7556 sig_type
->dwo_unit
->dwo_file
->comp_dir
,
7558 &comp_unit_die
, &has_children
,
7559 &m_dwo_abbrev_table
) == 0)
7566 /* Initialize a CU (or TU) and read its DIEs.
7567 If the CU defers to a DWO file, read the DWO file as well.
7569 ABBREV_TABLE, if non-NULL, is the abbreviation table to use.
7570 Otherwise the table specified in the comp unit header is read in and used.
7571 This is an optimization for when we already have the abbrev table.
7573 If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
7574 Otherwise, a new CU is allocated with xmalloc.
7576 If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
7577 read_in_chain. Otherwise the dwarf2_cu data is freed at the
7580 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7581 struct abbrev_table
*abbrev_table
,
7582 int use_existing_cu
, int keep
,
7584 : die_reader_specs
{},
7585 m_this_cu (this_cu
),
7588 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7589 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7590 struct dwarf2_section_info
*section
= this_cu
->section
;
7591 bfd
*abfd
= get_section_bfd_owner (section
);
7592 struct dwarf2_cu
*cu
;
7593 const gdb_byte
*begin_info_ptr
;
7594 struct signatured_type
*sig_type
= NULL
;
7595 struct dwarf2_section_info
*abbrev_section
;
7596 /* Non-zero if CU currently points to a DWO file and we need to
7597 reread it. When this happens we need to reread the skeleton die
7598 before we can reread the DWO file (this only applies to CUs, not TUs). */
7599 int rereading_dwo_cu
= 0;
7601 if (dwarf_die_debug
)
7602 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7603 this_cu
->is_debug_types
? "type" : "comp",
7604 sect_offset_str (this_cu
->sect_off
));
7606 if (use_existing_cu
)
7609 /* If we're reading a TU directly from a DWO file, including a virtual DWO
7610 file (instead of going through the stub), short-circuit all of this. */
7611 if (this_cu
->reading_dwo_directly
)
7613 /* Narrow down the scope of possibilities to have to understand. */
7614 gdb_assert (this_cu
->is_debug_types
);
7615 gdb_assert (abbrev_table
== NULL
);
7616 init_tu_and_read_dwo_dies (this_cu
, use_existing_cu
, keep
);
7620 /* This is cheap if the section is already read in. */
7621 dwarf2_read_section (objfile
, section
);
7623 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7625 abbrev_section
= get_abbrev_section_for_cu (this_cu
);
7627 if (use_existing_cu
&& this_cu
->cu
!= NULL
)
7630 /* If this CU is from a DWO file we need to start over, we need to
7631 refetch the attributes from the skeleton CU.
7632 This could be optimized by retrieving those attributes from when we
7633 were here the first time: the previous comp_unit_die was stored in
7634 comp_unit_obstack. But there's no data yet that we need this
7636 if (cu
->dwo_unit
!= NULL
)
7637 rereading_dwo_cu
= 1;
7641 /* If !use_existing_cu, this_cu->cu must be NULL. */
7642 gdb_assert (this_cu
->cu
== NULL
);
7643 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7644 cu
= m_new_cu
.get ();
7647 /* Get the header. */
7648 if (to_underlying (cu
->header
.first_die_cu_offset
) != 0 && !rereading_dwo_cu
)
7650 /* We already have the header, there's no need to read it in again. */
7651 info_ptr
+= to_underlying (cu
->header
.first_die_cu_offset
);
7655 if (this_cu
->is_debug_types
)
7657 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7658 &cu
->header
, section
,
7659 abbrev_section
, info_ptr
,
7662 /* Since per_cu is the first member of struct signatured_type,
7663 we can go from a pointer to one to a pointer to the other. */
7664 sig_type
= (struct signatured_type
*) this_cu
;
7665 gdb_assert (sig_type
->signature
== cu
->header
.signature
);
7666 gdb_assert (sig_type
->type_offset_in_tu
7667 == cu
->header
.type_cu_offset_in_tu
);
7668 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7670 /* LENGTH has not been set yet for type units if we're
7671 using .gdb_index. */
7672 this_cu
->length
= get_cu_length (&cu
->header
);
7674 /* Establish the type offset that can be used to lookup the type. */
7675 sig_type
->type_offset_in_section
=
7676 this_cu
->sect_off
+ to_underlying (sig_type
->type_offset_in_tu
);
7678 this_cu
->dwarf_version
= cu
->header
.version
;
7682 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7683 &cu
->header
, section
,
7686 rcuh_kind::COMPILE
);
7688 gdb_assert (this_cu
->sect_off
== cu
->header
.sect_off
);
7689 gdb_assert (this_cu
->length
== get_cu_length (&cu
->header
));
7690 this_cu
->dwarf_version
= cu
->header
.version
;
7694 /* Skip dummy compilation units. */
7695 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7696 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7702 /* If we don't have them yet, read the abbrevs for this compilation unit.
7703 And if we need to read them now, make sure they're freed when we're
7705 if (abbrev_table
!= NULL
)
7706 gdb_assert (cu
->header
.abbrev_sect_off
== abbrev_table
->sect_off
);
7709 m_abbrev_table_holder
7710 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7711 cu
->header
.abbrev_sect_off
);
7712 abbrev_table
= m_abbrev_table_holder
.get ();
7715 /* Read the top level CU/TU die. */
7716 init_cu_die_reader (this, cu
, section
, NULL
, abbrev_table
);
7717 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7719 if (skip_partial
&& comp_unit_die
->tag
== DW_TAG_partial_unit
)
7725 /* If we are in a DWO stub, process it and then read in the "real" CU/TU
7726 from the DWO file. read_cutu_die_from_dwo will allocate the abbreviation
7727 table from the DWO file and pass the ownership over to us. It will be
7728 referenced from READER, so we must make sure to free it after we're done
7731 Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains a
7732 DWO CU, that this test will fail (the attribute will not be present). */
7733 const char *dwo_name
= dwarf2_dwo_name (comp_unit_die
, cu
);
7734 if (dwo_name
!= nullptr)
7736 struct dwo_unit
*dwo_unit
;
7737 struct die_info
*dwo_comp_unit_die
;
7741 complaint (_("compilation unit with DW_AT_GNU_dwo_name"
7742 " has children (offset %s) [in module %s]"),
7743 sect_offset_str (this_cu
->sect_off
),
7744 bfd_get_filename (abfd
));
7746 dwo_unit
= lookup_dwo_unit (this_cu
, comp_unit_die
, dwo_name
);
7747 if (dwo_unit
!= NULL
)
7749 if (read_cutu_die_from_dwo (this_cu
, dwo_unit
,
7750 comp_unit_die
, NULL
,
7752 &dwo_comp_unit_die
, &has_children
,
7753 &m_dwo_abbrev_table
) == 0)
7759 comp_unit_die
= dwo_comp_unit_die
;
7763 /* Yikes, we couldn't find the rest of the DIE, we only have
7764 the stub. A complaint has already been logged. There's
7765 not much more we can do except pass on the stub DIE to
7766 die_reader_func. We don't want to throw an error on bad
7772 cutu_reader::~cutu_reader ()
7774 /* Done, clean up. */
7775 if (m_new_cu
!= NULL
&& m_keep
&& !dummy_p
)
7777 struct dwarf2_per_objfile
*dwarf2_per_objfile
7778 = m_this_cu
->dwarf2_per_objfile
;
7779 /* Link this CU into read_in_chain. */
7780 m_this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7781 dwarf2_per_objfile
->read_in_chain
= m_this_cu
;
7782 /* The chain owns it now. */
7783 m_new_cu
.release ();
7787 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
7788 if present. DWO_FILE, if non-NULL, is the DWO file to read (the caller is
7789 assumed to have already done the lookup to find the DWO file).
7791 The caller is required to fill in THIS_CU->section, THIS_CU->offset, and
7792 THIS_CU->is_debug_types, but nothing else.
7794 We fill in THIS_CU->length.
7796 THIS_CU->cu is always freed when done.
7797 This is done in order to not leave THIS_CU->cu in a state where we have
7798 to care whether it refers to the "main" CU or the DWO CU.
7800 When parent_cu is passed, it is used to provide a default value for
7801 str_offsets_base and addr_base from the parent. */
7803 cutu_reader::cutu_reader (struct dwarf2_per_cu_data
*this_cu
,
7804 struct dwarf2_cu
*parent_cu
,
7805 struct dwo_file
*dwo_file
)
7806 : die_reader_specs
{},
7809 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_cu
->dwarf2_per_objfile
;
7810 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7811 struct dwarf2_section_info
*section
= this_cu
->section
;
7812 bfd
*abfd
= get_section_bfd_owner (section
);
7813 struct dwarf2_section_info
*abbrev_section
;
7814 const gdb_byte
*begin_info_ptr
, *info_ptr
;
7817 if (dwarf_die_debug
)
7818 fprintf_unfiltered (gdb_stdlog
, "Reading %s unit at offset %s\n",
7819 this_cu
->is_debug_types
? "type" : "comp",
7820 sect_offset_str (this_cu
->sect_off
));
7822 gdb_assert (this_cu
->cu
== NULL
);
7824 abbrev_section
= (dwo_file
!= NULL
7825 ? &dwo_file
->sections
.abbrev
7826 : get_abbrev_section_for_cu (this_cu
));
7828 /* This is cheap if the section is already read in. */
7829 dwarf2_read_section (objfile
, section
);
7831 m_new_cu
.reset (new dwarf2_cu (this_cu
));
7833 begin_info_ptr
= info_ptr
= section
->buffer
+ to_underlying (this_cu
->sect_off
);
7834 info_ptr
= read_and_check_comp_unit_head (dwarf2_per_objfile
,
7835 &m_new_cu
->header
, section
,
7836 abbrev_section
, info_ptr
,
7837 (this_cu
->is_debug_types
7839 : rcuh_kind::COMPILE
));
7841 if (parent_cu
!= nullptr)
7843 m_new_cu
->str_offsets_base
= parent_cu
->str_offsets_base
;
7844 m_new_cu
->addr_base
= parent_cu
->addr_base
;
7846 this_cu
->length
= get_cu_length (&m_new_cu
->header
);
7848 /* Skip dummy compilation units. */
7849 if (info_ptr
>= begin_info_ptr
+ this_cu
->length
7850 || peek_abbrev_code (abfd
, info_ptr
) == 0)
7856 m_abbrev_table_holder
7857 = abbrev_table_read_table (dwarf2_per_objfile
, abbrev_section
,
7858 m_new_cu
->header
.abbrev_sect_off
);
7860 init_cu_die_reader (this, m_new_cu
.get (), section
, dwo_file
,
7861 m_abbrev_table_holder
.get ());
7862 info_ptr
= read_full_die (this, &comp_unit_die
, info_ptr
, &has_children
);
7866 /* Type Unit Groups.
7868 Type Unit Groups are a way to collapse the set of all TUs (type units) into
7869 a more manageable set. The grouping is done by DW_AT_stmt_list entry
7870 so that all types coming from the same compilation (.o file) are grouped
7871 together. A future step could be to put the types in the same symtab as
7872 the CU the types ultimately came from. */
7875 hash_type_unit_group (const void *item
)
7877 const struct type_unit_group
*tu_group
7878 = (const struct type_unit_group
*) item
;
7880 return hash_stmt_list_entry (&tu_group
->hash
);
7884 eq_type_unit_group (const void *item_lhs
, const void *item_rhs
)
7886 const struct type_unit_group
*lhs
= (const struct type_unit_group
*) item_lhs
;
7887 const struct type_unit_group
*rhs
= (const struct type_unit_group
*) item_rhs
;
7889 return eq_stmt_list_entry (&lhs
->hash
, &rhs
->hash
);
7892 /* Allocate a hash table for type unit groups. */
7895 allocate_type_unit_groups_table (struct objfile
*objfile
)
7897 return htab_create_alloc_ex (3,
7898 hash_type_unit_group
,
7901 &objfile
->objfile_obstack
,
7902 hashtab_obstack_allocate
,
7903 dummy_obstack_deallocate
);
7906 /* Type units that don't have DW_AT_stmt_list are grouped into their own
7907 partial symtabs. We combine several TUs per psymtab to not let the size
7908 of any one psymtab grow too big. */
7909 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31)
7910 #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10
7912 /* Helper routine for get_type_unit_group.
7913 Create the type_unit_group object used to hold one or more TUs. */
7915 static struct type_unit_group
*
7916 create_type_unit_group (struct dwarf2_cu
*cu
, sect_offset line_offset_struct
)
7918 struct dwarf2_per_objfile
*dwarf2_per_objfile
7919 = cu
->per_cu
->dwarf2_per_objfile
;
7920 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
7921 struct dwarf2_per_cu_data
*per_cu
;
7922 struct type_unit_group
*tu_group
;
7924 tu_group
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7925 struct type_unit_group
);
7926 per_cu
= &tu_group
->per_cu
;
7927 per_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
7929 if (dwarf2_per_objfile
->using_index
)
7931 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
7932 struct dwarf2_per_cu_quick_data
);
7936 unsigned int line_offset
= to_underlying (line_offset_struct
);
7937 struct partial_symtab
*pst
;
7940 /* Give the symtab a useful name for debug purposes. */
7941 if ((line_offset
& NO_STMT_LIST_TYPE_UNIT_PSYMTAB
) != 0)
7942 name
= string_printf ("<type_units_%d>",
7943 (line_offset
& ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB
));
7945 name
= string_printf ("<type_units_at_0x%x>", line_offset
);
7947 pst
= create_partial_symtab (per_cu
, name
.c_str ());
7948 pst
->anonymous
= true;
7951 tu_group
->hash
.dwo_unit
= cu
->dwo_unit
;
7952 tu_group
->hash
.line_sect_off
= line_offset_struct
;
7957 /* Look up the type_unit_group for type unit CU, and create it if necessary.
7958 STMT_LIST is a DW_AT_stmt_list attribute. */
7960 static struct type_unit_group
*
7961 get_type_unit_group (struct dwarf2_cu
*cu
, const struct attribute
*stmt_list
)
7963 struct dwarf2_per_objfile
*dwarf2_per_objfile
7964 = cu
->per_cu
->dwarf2_per_objfile
;
7965 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
7966 struct type_unit_group
*tu_group
;
7968 unsigned int line_offset
;
7969 struct type_unit_group type_unit_group_for_lookup
;
7971 if (dwarf2_per_objfile
->type_unit_groups
== NULL
)
7973 dwarf2_per_objfile
->type_unit_groups
=
7974 allocate_type_unit_groups_table (dwarf2_per_objfile
->objfile
);
7977 /* Do we need to create a new group, or can we use an existing one? */
7981 line_offset
= DW_UNSND (stmt_list
);
7982 ++tu_stats
->nr_symtab_sharers
;
7986 /* Ugh, no stmt_list. Rare, but we have to handle it.
7987 We can do various things here like create one group per TU or
7988 spread them over multiple groups to split up the expansion work.
7989 To avoid worst case scenarios (too many groups or too large groups)
7990 we, umm, group them in bunches. */
7991 line_offset
= (NO_STMT_LIST_TYPE_UNIT_PSYMTAB
7992 | (tu_stats
->nr_stmt_less_type_units
7993 / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE
));
7994 ++tu_stats
->nr_stmt_less_type_units
;
7997 type_unit_group_for_lookup
.hash
.dwo_unit
= cu
->dwo_unit
;
7998 type_unit_group_for_lookup
.hash
.line_sect_off
= (sect_offset
) line_offset
;
7999 slot
= htab_find_slot (dwarf2_per_objfile
->type_unit_groups
,
8000 &type_unit_group_for_lookup
, INSERT
);
8003 tu_group
= (struct type_unit_group
*) *slot
;
8004 gdb_assert (tu_group
!= NULL
);
8008 sect_offset line_offset_struct
= (sect_offset
) line_offset
;
8009 tu_group
= create_type_unit_group (cu
, line_offset_struct
);
8011 ++tu_stats
->nr_symtabs
;
8017 /* Partial symbol tables. */
8019 /* Create a psymtab named NAME and assign it to PER_CU.
8021 The caller must fill in the following details:
8022 dirname, textlow, texthigh. */
8024 static struct partial_symtab
*
8025 create_partial_symtab (struct dwarf2_per_cu_data
*per_cu
, const char *name
)
8027 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
8028 struct partial_symtab
*pst
;
8030 pst
= start_psymtab_common (objfile
, name
, 0);
8032 pst
->psymtabs_addrmap_supported
= true;
8034 /* This is the glue that links PST into GDB's symbol API. */
8035 pst
->read_symtab_private
= per_cu
;
8036 pst
->read_symtab
= dwarf2_read_symtab
;
8037 per_cu
->v
.psymtab
= pst
;
8042 /* DIE reader function for process_psymtab_comp_unit. */
8045 process_psymtab_comp_unit_reader (const struct die_reader_specs
*reader
,
8046 const gdb_byte
*info_ptr
,
8047 struct die_info
*comp_unit_die
,
8049 int want_partial_unit
,
8050 enum language pretend_language
)
8052 struct dwarf2_cu
*cu
= reader
->cu
;
8053 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
8054 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8055 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8057 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
8058 struct partial_symtab
*pst
;
8059 enum pc_bounds_kind cu_bounds_kind
;
8060 const char *filename
;
8062 if (comp_unit_die
->tag
== DW_TAG_partial_unit
&& !want_partial_unit
)
8065 gdb_assert (! per_cu
->is_debug_types
);
8067 prepare_one_comp_unit (cu
, comp_unit_die
, pretend_language
);
8069 /* Allocate a new partial symbol table structure. */
8070 filename
= dwarf2_string_attr (comp_unit_die
, DW_AT_name
, cu
);
8071 if (filename
== NULL
)
8074 pst
= create_partial_symtab (per_cu
, filename
);
8076 /* This must be done before calling dwarf2_build_include_psymtabs. */
8077 pst
->dirname
= dwarf2_string_attr (comp_unit_die
, DW_AT_comp_dir
, cu
);
8079 baseaddr
= objfile
->text_section_offset ();
8081 dwarf2_find_base_address (comp_unit_die
, cu
);
8083 /* Possibly set the default values of LOWPC and HIGHPC from
8085 cu_bounds_kind
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
8086 &best_highpc
, cu
, pst
);
8087 if (cu_bounds_kind
== PC_BOUNDS_HIGH_LOW
&& best_lowpc
< best_highpc
)
8090 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_lowpc
+ baseaddr
)
8093 = (gdbarch_adjust_dwarf2_addr (gdbarch
, best_highpc
+ baseaddr
)
8095 /* Store the contiguous range if it is not empty; it can be
8096 empty for CUs with no code. */
8097 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
8101 /* Check if comp unit has_children.
8102 If so, read the rest of the partial symbols from this comp unit.
8103 If not, there's no more debug_info for this comp unit. */
8106 struct partial_die_info
*first_die
;
8107 CORE_ADDR lowpc
, highpc
;
8109 lowpc
= ((CORE_ADDR
) -1);
8110 highpc
= ((CORE_ADDR
) 0);
8112 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8114 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
8115 cu_bounds_kind
<= PC_BOUNDS_INVALID
, cu
);
8117 /* If we didn't find a lowpc, set it to highpc to avoid
8118 complaints from `maint check'. */
8119 if (lowpc
== ((CORE_ADDR
) -1))
8122 /* If the compilation unit didn't have an explicit address range,
8123 then use the information extracted from its child dies. */
8124 if (cu_bounds_kind
<= PC_BOUNDS_INVALID
)
8127 best_highpc
= highpc
;
8130 pst
->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch
,
8131 best_lowpc
+ baseaddr
)
8133 pst
->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch
,
8134 best_highpc
+ baseaddr
)
8137 end_psymtab_common (objfile
, pst
);
8139 if (!cu
->per_cu
->imported_symtabs_empty ())
8142 int len
= cu
->per_cu
->imported_symtabs_size ();
8144 /* Fill in 'dependencies' here; we fill in 'users' in a
8146 pst
->number_of_dependencies
= len
;
8148 = objfile
->partial_symtabs
->allocate_dependencies (len
);
8149 for (i
= 0; i
< len
; ++i
)
8151 pst
->dependencies
[i
]
8152 = cu
->per_cu
->imported_symtabs
->at (i
)->v
.psymtab
;
8155 cu
->per_cu
->imported_symtabs_free ();
8158 /* Get the list of files included in the current compilation unit,
8159 and build a psymtab for each of them. */
8160 dwarf2_build_include_psymtabs (cu
, comp_unit_die
, pst
);
8162 if (dwarf_read_debug
)
8163 fprintf_unfiltered (gdb_stdlog
,
8164 "Psymtab for %s unit @%s: %s - %s"
8165 ", %d global, %d static syms\n",
8166 per_cu
->is_debug_types
? "type" : "comp",
8167 sect_offset_str (per_cu
->sect_off
),
8168 paddress (gdbarch
, pst
->text_low (objfile
)),
8169 paddress (gdbarch
, pst
->text_high (objfile
)),
8170 pst
->n_global_syms
, pst
->n_static_syms
);
8173 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8174 Process compilation unit THIS_CU for a psymtab. */
8177 process_psymtab_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
8178 int want_partial_unit
,
8179 enum language pretend_language
)
8181 /* If this compilation unit was already read in, free the
8182 cached copy in order to read it in again. This is
8183 necessary because we skipped some symbols when we first
8184 read in the compilation unit (see load_partial_dies).
8185 This problem could be avoided, but the benefit is unclear. */
8186 if (this_cu
->cu
!= NULL
)
8187 free_one_cached_comp_unit (this_cu
);
8189 cutu_reader
reader (this_cu
, NULL
, 0, 0, false);
8195 else if (this_cu
->is_debug_types
)
8196 build_type_psymtabs_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
8197 reader
.has_children
);
8199 process_psymtab_comp_unit_reader (&reader
, reader
.info_ptr
,
8200 reader
.comp_unit_die
,
8201 reader
.has_children
,
8205 /* Age out any secondary CUs. */
8206 age_cached_comp_units (this_cu
->dwarf2_per_objfile
);
8209 /* Reader function for build_type_psymtabs. */
8212 build_type_psymtabs_reader (const struct die_reader_specs
*reader
,
8213 const gdb_byte
*info_ptr
,
8214 struct die_info
*type_unit_die
,
8217 struct dwarf2_per_objfile
*dwarf2_per_objfile
8218 = reader
->cu
->per_cu
->dwarf2_per_objfile
;
8219 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8220 struct dwarf2_cu
*cu
= reader
->cu
;
8221 struct dwarf2_per_cu_data
*per_cu
= cu
->per_cu
;
8222 struct signatured_type
*sig_type
;
8223 struct type_unit_group
*tu_group
;
8224 struct attribute
*attr
;
8225 struct partial_die_info
*first_die
;
8226 CORE_ADDR lowpc
, highpc
;
8227 struct partial_symtab
*pst
;
8229 gdb_assert (per_cu
->is_debug_types
);
8230 sig_type
= (struct signatured_type
*) per_cu
;
8235 attr
= dwarf2_attr_no_follow (type_unit_die
, DW_AT_stmt_list
);
8236 tu_group
= get_type_unit_group (cu
, attr
);
8238 if (tu_group
->tus
== nullptr)
8239 tu_group
->tus
= new std::vector
<signatured_type
*>;
8240 tu_group
->tus
->push_back (sig_type
);
8242 prepare_one_comp_unit (cu
, type_unit_die
, language_minimal
);
8243 pst
= create_partial_symtab (per_cu
, "");
8244 pst
->anonymous
= true;
8246 first_die
= load_partial_dies (reader
, info_ptr
, 1);
8248 lowpc
= (CORE_ADDR
) -1;
8249 highpc
= (CORE_ADDR
) 0;
8250 scan_partial_symbols (first_die
, &lowpc
, &highpc
, 0, cu
);
8252 end_psymtab_common (objfile
, pst
);
8255 /* Struct used to sort TUs by their abbreviation table offset. */
8257 struct tu_abbrev_offset
8259 tu_abbrev_offset (signatured_type
*sig_type_
, sect_offset abbrev_offset_
)
8260 : sig_type (sig_type_
), abbrev_offset (abbrev_offset_
)
8263 signatured_type
*sig_type
;
8264 sect_offset abbrev_offset
;
8267 /* Helper routine for build_type_psymtabs_1, passed to std::sort. */
8270 sort_tu_by_abbrev_offset (const struct tu_abbrev_offset
&a
,
8271 const struct tu_abbrev_offset
&b
)
8273 return a
.abbrev_offset
< b
.abbrev_offset
;
8276 /* Efficiently read all the type units.
8277 This does the bulk of the work for build_type_psymtabs.
8279 The efficiency is because we sort TUs by the abbrev table they use and
8280 only read each abbrev table once. In one program there are 200K TUs
8281 sharing 8K abbrev tables.
8283 The main purpose of this function is to support building the
8284 dwarf2_per_objfile->type_unit_groups table.
8285 TUs typically share the DW_AT_stmt_list of the CU they came from, so we
8286 can collapse the search space by grouping them by stmt_list.
8287 The savings can be significant, in the same program from above the 200K TUs
8288 share 8K stmt_list tables.
8290 FUNC is expected to call get_type_unit_group, which will create the
8291 struct type_unit_group if necessary and add it to
8292 dwarf2_per_objfile->type_unit_groups. */
8295 build_type_psymtabs_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8297 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8298 abbrev_table_up abbrev_table
;
8299 sect_offset abbrev_offset
;
8301 /* It's up to the caller to not call us multiple times. */
8302 gdb_assert (dwarf2_per_objfile
->type_unit_groups
== NULL
);
8304 if (dwarf2_per_objfile
->all_type_units
.empty ())
8307 /* TUs typically share abbrev tables, and there can be way more TUs than
8308 abbrev tables. Sort by abbrev table to reduce the number of times we
8309 read each abbrev table in.
8310 Alternatives are to punt or to maintain a cache of abbrev tables.
8311 This is simpler and efficient enough for now.
8313 Later we group TUs by their DW_AT_stmt_list value (as this defines the
8314 symtab to use). Typically TUs with the same abbrev offset have the same
8315 stmt_list value too so in practice this should work well.
8317 The basic algorithm here is:
8319 sort TUs by abbrev table
8320 for each TU with same abbrev table:
8321 read abbrev table if first user
8322 read TU top level DIE
8323 [IWBN if DWO skeletons had DW_AT_stmt_list]
8326 if (dwarf_read_debug
)
8327 fprintf_unfiltered (gdb_stdlog
, "Building type unit groups ...\n");
8329 /* Sort in a separate table to maintain the order of all_type_units
8330 for .gdb_index: TU indices directly index all_type_units. */
8331 std::vector
<tu_abbrev_offset
> sorted_by_abbrev
;
8332 sorted_by_abbrev
.reserve (dwarf2_per_objfile
->all_type_units
.size ());
8334 for (signatured_type
*sig_type
: dwarf2_per_objfile
->all_type_units
)
8335 sorted_by_abbrev
.emplace_back
8336 (sig_type
, read_abbrev_offset (dwarf2_per_objfile
,
8337 sig_type
->per_cu
.section
,
8338 sig_type
->per_cu
.sect_off
));
8340 std::sort (sorted_by_abbrev
.begin (), sorted_by_abbrev
.end (),
8341 sort_tu_by_abbrev_offset
);
8343 abbrev_offset
= (sect_offset
) ~(unsigned) 0;
8345 for (const tu_abbrev_offset
&tu
: sorted_by_abbrev
)
8347 /* Switch to the next abbrev table if necessary. */
8348 if (abbrev_table
== NULL
8349 || tu
.abbrev_offset
!= abbrev_offset
)
8351 abbrev_offset
= tu
.abbrev_offset
;
8353 abbrev_table_read_table (dwarf2_per_objfile
,
8354 &dwarf2_per_objfile
->abbrev
,
8356 ++tu_stats
->nr_uniq_abbrev_tables
;
8359 cutu_reader
reader (&tu
.sig_type
->per_cu
, abbrev_table
.get (),
8361 if (!reader
.dummy_p
)
8362 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8363 reader
.comp_unit_die
,
8364 reader
.has_children
);
8368 /* Print collected type unit statistics. */
8371 print_tu_stats (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8373 struct tu_stats
*tu_stats
= &dwarf2_per_objfile
->tu_stats
;
8375 fprintf_unfiltered (gdb_stdlog
, "Type unit statistics:\n");
8376 fprintf_unfiltered (gdb_stdlog
, " %zu TUs\n",
8377 dwarf2_per_objfile
->all_type_units
.size ());
8378 fprintf_unfiltered (gdb_stdlog
, " %d uniq abbrev tables\n",
8379 tu_stats
->nr_uniq_abbrev_tables
);
8380 fprintf_unfiltered (gdb_stdlog
, " %d symtabs from stmt_list entries\n",
8381 tu_stats
->nr_symtabs
);
8382 fprintf_unfiltered (gdb_stdlog
, " %d symtab sharers\n",
8383 tu_stats
->nr_symtab_sharers
);
8384 fprintf_unfiltered (gdb_stdlog
, " %d type units without a stmt_list\n",
8385 tu_stats
->nr_stmt_less_type_units
);
8386 fprintf_unfiltered (gdb_stdlog
, " %d all_type_units reallocs\n",
8387 tu_stats
->nr_all_type_units_reallocs
);
8390 /* Traversal function for build_type_psymtabs. */
8393 build_type_psymtab_dependencies (void **slot
, void *info
)
8395 struct dwarf2_per_objfile
*dwarf2_per_objfile
8396 = (struct dwarf2_per_objfile
*) info
;
8397 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8398 struct type_unit_group
*tu_group
= (struct type_unit_group
*) *slot
;
8399 struct dwarf2_per_cu_data
*per_cu
= &tu_group
->per_cu
;
8400 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8401 int len
= (tu_group
->tus
== nullptr) ? 0 : tu_group
->tus
->size ();
8404 gdb_assert (len
> 0);
8405 gdb_assert (IS_TYPE_UNIT_GROUP (per_cu
));
8407 pst
->number_of_dependencies
= len
;
8408 pst
->dependencies
= objfile
->partial_symtabs
->allocate_dependencies (len
);
8409 for (i
= 0; i
< len
; ++i
)
8411 struct signatured_type
*iter
= tu_group
->tus
->at (i
);
8412 gdb_assert (iter
->per_cu
.is_debug_types
);
8413 pst
->dependencies
[i
] = iter
->per_cu
.v
.psymtab
;
8414 iter
->type_unit_group
= tu_group
;
8417 delete tu_group
->tus
;
8418 tu_group
->tus
= nullptr;
8423 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
8424 Build partial symbol tables for the .debug_types comp-units. */
8427 build_type_psymtabs (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8429 if (! create_all_type_units (dwarf2_per_objfile
))
8432 build_type_psymtabs_1 (dwarf2_per_objfile
);
8435 /* Traversal function for process_skeletonless_type_unit.
8436 Read a TU in a DWO file and build partial symbols for it. */
8439 process_skeletonless_type_unit (void **slot
, void *info
)
8441 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
8442 struct dwarf2_per_objfile
*dwarf2_per_objfile
8443 = (struct dwarf2_per_objfile
*) info
;
8444 struct signatured_type find_entry
, *entry
;
8446 /* If this TU doesn't exist in the global table, add it and read it in. */
8448 if (dwarf2_per_objfile
->signatured_types
== NULL
)
8450 dwarf2_per_objfile
->signatured_types
8451 = allocate_signatured_type_table (dwarf2_per_objfile
->objfile
);
8454 find_entry
.signature
= dwo_unit
->signature
;
8455 slot
= htab_find_slot (dwarf2_per_objfile
->signatured_types
, &find_entry
,
8457 /* If we've already seen this type there's nothing to do. What's happening
8458 is we're doing our own version of comdat-folding here. */
8462 /* This does the job that create_all_type_units would have done for
8464 entry
= add_type_unit (dwarf2_per_objfile
, dwo_unit
->signature
, slot
);
8465 fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile
, entry
, dwo_unit
);
8468 /* This does the job that build_type_psymtabs_1 would have done. */
8469 cutu_reader
reader (&entry
->per_cu
, NULL
, 0, 0, false);
8470 if (!reader
.dummy_p
)
8471 build_type_psymtabs_reader (&reader
, reader
.info_ptr
,
8472 reader
.comp_unit_die
, reader
.has_children
);
8477 /* Traversal function for process_skeletonless_type_units. */
8480 process_dwo_file_for_skeletonless_type_units (void **slot
, void *info
)
8482 struct dwo_file
*dwo_file
= (struct dwo_file
*) *slot
;
8484 if (dwo_file
->tus
!= NULL
)
8486 htab_traverse_noresize (dwo_file
->tus
,
8487 process_skeletonless_type_unit
, info
);
8493 /* Scan all TUs of DWO files, verifying we've processed them.
8494 This is needed in case a TU was emitted without its skeleton.
8495 Note: This can't be done until we know what all the DWO files are. */
8498 process_skeletonless_type_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8500 /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */
8501 if (get_dwp_file (dwarf2_per_objfile
) == NULL
8502 && dwarf2_per_objfile
->dwo_files
!= NULL
)
8504 htab_traverse_noresize (dwarf2_per_objfile
->dwo_files
.get (),
8505 process_dwo_file_for_skeletonless_type_units
,
8506 dwarf2_per_objfile
);
8510 /* Compute the 'user' field for each psymtab in DWARF2_PER_OBJFILE. */
8513 set_partial_user (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8515 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8517 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
8522 for (int j
= 0; j
< pst
->number_of_dependencies
; ++j
)
8524 /* Set the 'user' field only if it is not already set. */
8525 if (pst
->dependencies
[j
]->user
== NULL
)
8526 pst
->dependencies
[j
]->user
= pst
;
8531 /* Build the partial symbol table by doing a quick pass through the
8532 .debug_info and .debug_abbrev sections. */
8535 dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8537 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8539 if (dwarf_read_debug
)
8541 fprintf_unfiltered (gdb_stdlog
, "Building psymtabs of objfile %s ...\n",
8542 objfile_name (objfile
));
8545 dwarf2_per_objfile
->reading_partial_symbols
= 1;
8547 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
8549 /* Any cached compilation units will be linked by the per-objfile
8550 read_in_chain. Make sure to free them when we're done. */
8551 free_cached_comp_units
freer (dwarf2_per_objfile
);
8553 build_type_psymtabs (dwarf2_per_objfile
);
8555 create_all_comp_units (dwarf2_per_objfile
);
8557 /* Create a temporary address map on a temporary obstack. We later
8558 copy this to the final obstack. */
8559 auto_obstack temp_obstack
;
8561 scoped_restore save_psymtabs_addrmap
8562 = make_scoped_restore (&objfile
->partial_symtabs
->psymtabs_addrmap
,
8563 addrmap_create_mutable (&temp_obstack
));
8565 for (dwarf2_per_cu_data
*per_cu
: dwarf2_per_objfile
->all_comp_units
)
8566 process_psymtab_comp_unit (per_cu
, 0, language_minimal
);
8568 /* This has to wait until we read the CUs, we need the list of DWOs. */
8569 process_skeletonless_type_units (dwarf2_per_objfile
);
8571 /* Now that all TUs have been processed we can fill in the dependencies. */
8572 if (dwarf2_per_objfile
->type_unit_groups
!= NULL
)
8574 htab_traverse_noresize (dwarf2_per_objfile
->type_unit_groups
,
8575 build_type_psymtab_dependencies
, dwarf2_per_objfile
);
8578 if (dwarf_read_debug
)
8579 print_tu_stats (dwarf2_per_objfile
);
8581 set_partial_user (dwarf2_per_objfile
);
8583 objfile
->partial_symtabs
->psymtabs_addrmap
8584 = addrmap_create_fixed (objfile
->partial_symtabs
->psymtabs_addrmap
,
8585 objfile
->partial_symtabs
->obstack ());
8586 /* At this point we want to keep the address map. */
8587 save_psymtabs_addrmap
.release ();
8589 if (dwarf_read_debug
)
8590 fprintf_unfiltered (gdb_stdlog
, "Done building psymtabs of %s\n",
8591 objfile_name (objfile
));
8594 /* Load the partial DIEs for a secondary CU into memory.
8595 This is also used when rereading a primary CU with load_all_dies. */
8598 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
)
8600 cutu_reader
reader (this_cu
, NULL
, 1, 1, false);
8602 if (!reader
.dummy_p
)
8604 prepare_one_comp_unit (reader
.cu
, reader
.comp_unit_die
,
8607 /* Check if comp unit has_children.
8608 If so, read the rest of the partial symbols from this comp unit.
8609 If not, there's no more debug_info for this comp unit. */
8610 if (reader
.has_children
)
8611 load_partial_dies (&reader
, reader
.info_ptr
, 0);
8616 read_comp_units_from_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
8617 struct dwarf2_section_info
*section
,
8618 struct dwarf2_section_info
*abbrev_section
,
8619 unsigned int is_dwz
)
8621 const gdb_byte
*info_ptr
;
8622 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8624 if (dwarf_read_debug
)
8625 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s\n",
8626 get_section_name (section
),
8627 get_section_file_name (section
));
8629 dwarf2_read_section (objfile
, section
);
8631 info_ptr
= section
->buffer
;
8633 while (info_ptr
< section
->buffer
+ section
->size
)
8635 struct dwarf2_per_cu_data
*this_cu
;
8637 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
->buffer
);
8639 comp_unit_head cu_header
;
8640 read_and_check_comp_unit_head (dwarf2_per_objfile
, &cu_header
, section
,
8641 abbrev_section
, info_ptr
,
8642 rcuh_kind::COMPILE
);
8644 /* Save the compilation unit for later lookup. */
8645 if (cu_header
.unit_type
!= DW_UT_type
)
8647 this_cu
= XOBNEW (&objfile
->objfile_obstack
,
8648 struct dwarf2_per_cu_data
);
8649 memset (this_cu
, 0, sizeof (*this_cu
));
8653 auto sig_type
= XOBNEW (&objfile
->objfile_obstack
,
8654 struct signatured_type
);
8655 memset (sig_type
, 0, sizeof (*sig_type
));
8656 sig_type
->signature
= cu_header
.signature
;
8657 sig_type
->type_offset_in_tu
= cu_header
.type_cu_offset_in_tu
;
8658 this_cu
= &sig_type
->per_cu
;
8660 this_cu
->is_debug_types
= (cu_header
.unit_type
== DW_UT_type
);
8661 this_cu
->sect_off
= sect_off
;
8662 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
8663 this_cu
->is_dwz
= is_dwz
;
8664 this_cu
->dwarf2_per_objfile
= dwarf2_per_objfile
;
8665 this_cu
->section
= section
;
8667 dwarf2_per_objfile
->all_comp_units
.push_back (this_cu
);
8669 info_ptr
= info_ptr
+ this_cu
->length
;
8673 /* Create a list of all compilation units in OBJFILE.
8674 This is only done for -readnow and building partial symtabs. */
8677 create_all_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
8679 gdb_assert (dwarf2_per_objfile
->all_comp_units
.empty ());
8680 read_comp_units_from_section (dwarf2_per_objfile
, &dwarf2_per_objfile
->info
,
8681 &dwarf2_per_objfile
->abbrev
, 0);
8683 dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
8685 read_comp_units_from_section (dwarf2_per_objfile
, &dwz
->info
, &dwz
->abbrev
,
8689 /* Process all loaded DIEs for compilation unit CU, starting at
8690 FIRST_DIE. The caller should pass SET_ADDRMAP == 1 if the compilation
8691 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
8692 DW_AT_ranges). See the comments of add_partial_subprogram on how
8693 SET_ADDRMAP is used and how *LOWPC and *HIGHPC are updated. */
8696 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
8697 CORE_ADDR
*highpc
, int set_addrmap
,
8698 struct dwarf2_cu
*cu
)
8700 struct partial_die_info
*pdi
;
8702 /* Now, march along the PDI's, descending into ones which have
8703 interesting children but skipping the children of the other ones,
8704 until we reach the end of the compilation unit. */
8712 /* Anonymous namespaces or modules have no name but have interesting
8713 children, so we need to look at them. Ditto for anonymous
8716 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
8717 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
8718 || pdi
->tag
== DW_TAG_imported_unit
8719 || pdi
->tag
== DW_TAG_inlined_subroutine
)
8723 case DW_TAG_subprogram
:
8724 case DW_TAG_inlined_subroutine
:
8725 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8727 case DW_TAG_constant
:
8728 case DW_TAG_variable
:
8729 case DW_TAG_typedef
:
8730 case DW_TAG_union_type
:
8731 if (!pdi
->is_declaration
)
8733 add_partial_symbol (pdi
, cu
);
8736 case DW_TAG_class_type
:
8737 case DW_TAG_interface_type
:
8738 case DW_TAG_structure_type
:
8739 if (!pdi
->is_declaration
)
8741 add_partial_symbol (pdi
, cu
);
8743 if ((cu
->language
== language_rust
8744 || cu
->language
== language_cplus
) && pdi
->has_children
)
8745 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
,
8748 case DW_TAG_enumeration_type
:
8749 if (!pdi
->is_declaration
)
8750 add_partial_enumeration (pdi
, cu
);
8752 case DW_TAG_base_type
:
8753 case DW_TAG_subrange_type
:
8754 /* File scope base type definitions are added to the partial
8756 add_partial_symbol (pdi
, cu
);
8758 case DW_TAG_namespace
:
8759 add_partial_namespace (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8762 if (!pdi
->is_declaration
)
8763 add_partial_module (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
8765 case DW_TAG_imported_unit
:
8767 struct dwarf2_per_cu_data
*per_cu
;
8769 /* For now we don't handle imported units in type units. */
8770 if (cu
->per_cu
->is_debug_types
)
8772 error (_("Dwarf Error: DW_TAG_imported_unit is not"
8773 " supported in type units [in module %s]"),
8774 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
8777 per_cu
= dwarf2_find_containing_comp_unit
8778 (pdi
->d
.sect_off
, pdi
->is_dwz
,
8779 cu
->per_cu
->dwarf2_per_objfile
);
8781 /* Go read the partial unit, if needed. */
8782 if (per_cu
->v
.psymtab
== NULL
)
8783 process_psymtab_comp_unit (per_cu
, 1, cu
->language
);
8785 cu
->per_cu
->imported_symtabs_push (per_cu
);
8788 case DW_TAG_imported_declaration
:
8789 add_partial_symbol (pdi
, cu
);
8796 /* If the die has a sibling, skip to the sibling. */
8798 pdi
= pdi
->die_sibling
;
8802 /* Functions used to compute the fully scoped name of a partial DIE.
8804 Normally, this is simple. For C++, the parent DIE's fully scoped
8805 name is concatenated with "::" and the partial DIE's name.
8806 Enumerators are an exception; they use the scope of their parent
8807 enumeration type, i.e. the name of the enumeration type is not
8808 prepended to the enumerator.
8810 There are two complexities. One is DW_AT_specification; in this
8811 case "parent" means the parent of the target of the specification,
8812 instead of the direct parent of the DIE. The other is compilers
8813 which do not emit DW_TAG_namespace; in this case we try to guess
8814 the fully qualified name of structure types from their members'
8815 linkage names. This must be done using the DIE's children rather
8816 than the children of any DW_AT_specification target. We only need
8817 to do this for structures at the top level, i.e. if the target of
8818 any DW_AT_specification (if any; otherwise the DIE itself) does not
8821 /* Compute the scope prefix associated with PDI's parent, in
8822 compilation unit CU. The result will be allocated on CU's
8823 comp_unit_obstack, or a copy of the already allocated PDI->NAME
8824 field. NULL is returned if no prefix is necessary. */
8826 partial_die_parent_scope (struct partial_die_info
*pdi
,
8827 struct dwarf2_cu
*cu
)
8829 const char *grandparent_scope
;
8830 struct partial_die_info
*parent
, *real_pdi
;
8832 /* We need to look at our parent DIE; if we have a DW_AT_specification,
8833 then this means the parent of the specification DIE. */
8836 while (real_pdi
->has_specification
)
8838 auto res
= find_partial_die (real_pdi
->spec_offset
,
8839 real_pdi
->spec_is_dwz
, cu
);
8844 parent
= real_pdi
->die_parent
;
8848 if (parent
->scope_set
)
8849 return parent
->scope
;
8853 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
8855 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
8856 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
8857 Work around this problem here. */
8858 if (cu
->language
== language_cplus
8859 && parent
->tag
== DW_TAG_namespace
8860 && strcmp (parent
->name
, "::") == 0
8861 && grandparent_scope
== NULL
)
8863 parent
->scope
= NULL
;
8864 parent
->scope_set
= 1;
8868 /* Nested subroutines in Fortran get a prefix. */
8869 if (pdi
->tag
== DW_TAG_enumerator
)
8870 /* Enumerators should not get the name of the enumeration as a prefix. */
8871 parent
->scope
= grandparent_scope
;
8872 else if (parent
->tag
== DW_TAG_namespace
8873 || parent
->tag
== DW_TAG_module
8874 || parent
->tag
== DW_TAG_structure_type
8875 || parent
->tag
== DW_TAG_class_type
8876 || parent
->tag
== DW_TAG_interface_type
8877 || parent
->tag
== DW_TAG_union_type
8878 || parent
->tag
== DW_TAG_enumeration_type
8879 || (cu
->language
== language_fortran
8880 && parent
->tag
== DW_TAG_subprogram
8881 && pdi
->tag
== DW_TAG_subprogram
))
8883 if (grandparent_scope
== NULL
)
8884 parent
->scope
= parent
->name
;
8886 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
8888 parent
->name
, 0, cu
);
8892 /* FIXME drow/2004-04-01: What should we be doing with
8893 function-local names? For partial symbols, we should probably be
8895 complaint (_("unhandled containing DIE tag %s for DIE at %s"),
8896 dwarf_tag_name (parent
->tag
),
8897 sect_offset_str (pdi
->sect_off
));
8898 parent
->scope
= grandparent_scope
;
8901 parent
->scope_set
= 1;
8902 return parent
->scope
;
8905 /* Return the fully scoped name associated with PDI, from compilation unit
8906 CU. The result will be allocated with malloc. */
8908 static gdb::unique_xmalloc_ptr
<char>
8909 partial_die_full_name (struct partial_die_info
*pdi
,
8910 struct dwarf2_cu
*cu
)
8912 const char *parent_scope
;
8914 /* If this is a template instantiation, we can not work out the
8915 template arguments from partial DIEs. So, unfortunately, we have
8916 to go through the full DIEs. At least any work we do building
8917 types here will be reused if full symbols are loaded later. */
8918 if (pdi
->has_template_arguments
)
8922 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
8924 struct die_info
*die
;
8925 struct attribute attr
;
8926 struct dwarf2_cu
*ref_cu
= cu
;
8928 /* DW_FORM_ref_addr is using section offset. */
8929 attr
.name
= (enum dwarf_attribute
) 0;
8930 attr
.form
= DW_FORM_ref_addr
;
8931 attr
.u
.unsnd
= to_underlying (pdi
->sect_off
);
8932 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
8934 return make_unique_xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
8938 parent_scope
= partial_die_parent_scope (pdi
, cu
);
8939 if (parent_scope
== NULL
)
8942 return gdb::unique_xmalloc_ptr
<char> (typename_concat (NULL
, parent_scope
,
8947 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
8949 struct dwarf2_per_objfile
*dwarf2_per_objfile
8950 = cu
->per_cu
->dwarf2_per_objfile
;
8951 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
8952 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8954 const char *actual_name
= NULL
;
8957 baseaddr
= objfile
->text_section_offset ();
8959 gdb::unique_xmalloc_ptr
<char> built_actual_name
8960 = partial_die_full_name (pdi
, cu
);
8961 if (built_actual_name
!= NULL
)
8962 actual_name
= built_actual_name
.get ();
8964 if (actual_name
== NULL
)
8965 actual_name
= pdi
->name
;
8969 case DW_TAG_inlined_subroutine
:
8970 case DW_TAG_subprogram
:
8971 addr
= (gdbarch_adjust_dwarf2_addr (gdbarch
, pdi
->lowpc
+ baseaddr
)
8973 if (pdi
->is_external
8974 || cu
->language
== language_ada
8975 || (cu
->language
== language_fortran
8976 && pdi
->die_parent
!= NULL
8977 && pdi
->die_parent
->tag
== DW_TAG_subprogram
))
8979 /* Normally, only "external" DIEs are part of the global scope.
8980 But in Ada and Fortran, we want to be able to access nested
8981 procedures globally. So all Ada and Fortran subprograms are
8982 stored in the global scope. */
8983 add_psymbol_to_list (actual_name
,
8984 built_actual_name
!= NULL
,
8985 VAR_DOMAIN
, LOC_BLOCK
,
8986 SECT_OFF_TEXT (objfile
),
8987 psymbol_placement::GLOBAL
,
8989 cu
->language
, objfile
);
8993 add_psymbol_to_list (actual_name
,
8994 built_actual_name
!= NULL
,
8995 VAR_DOMAIN
, LOC_BLOCK
,
8996 SECT_OFF_TEXT (objfile
),
8997 psymbol_placement::STATIC
,
8998 addr
, cu
->language
, objfile
);
9001 if (pdi
->main_subprogram
&& actual_name
!= NULL
)
9002 set_objfile_main_name (objfile
, actual_name
, cu
->language
);
9004 case DW_TAG_constant
:
9005 add_psymbol_to_list (actual_name
,
9006 built_actual_name
!= NULL
, VAR_DOMAIN
, LOC_STATIC
,
9007 -1, (pdi
->is_external
9008 ? psymbol_placement::GLOBAL
9009 : psymbol_placement::STATIC
),
9010 0, cu
->language
, objfile
);
9012 case DW_TAG_variable
:
9014 addr
= decode_locdesc (pdi
->d
.locdesc
, cu
);
9018 && !dwarf2_per_objfile
->has_section_at_zero
)
9020 /* A global or static variable may also have been stripped
9021 out by the linker if unused, in which case its address
9022 will be nullified; do not add such variables into partial
9023 symbol table then. */
9025 else if (pdi
->is_external
)
9028 Don't enter into the minimal symbol tables as there is
9029 a minimal symbol table entry from the ELF symbols already.
9030 Enter into partial symbol table if it has a location
9031 descriptor or a type.
9032 If the location descriptor is missing, new_symbol will create
9033 a LOC_UNRESOLVED symbol, the address of the variable will then
9034 be determined from the minimal symbol table whenever the variable
9036 The address for the partial symbol table entry is not
9037 used by GDB, but it comes in handy for debugging partial symbol
9040 if (pdi
->d
.locdesc
|| pdi
->has_type
)
9041 add_psymbol_to_list (actual_name
,
9042 built_actual_name
!= NULL
,
9043 VAR_DOMAIN
, LOC_STATIC
,
9044 SECT_OFF_TEXT (objfile
),
9045 psymbol_placement::GLOBAL
,
9046 addr
, cu
->language
, objfile
);
9050 int has_loc
= pdi
->d
.locdesc
!= NULL
;
9052 /* Static Variable. Skip symbols whose value we cannot know (those
9053 without location descriptors or constant values). */
9054 if (!has_loc
&& !pdi
->has_const_value
)
9057 add_psymbol_to_list (actual_name
,
9058 built_actual_name
!= NULL
,
9059 VAR_DOMAIN
, LOC_STATIC
,
9060 SECT_OFF_TEXT (objfile
),
9061 psymbol_placement::STATIC
,
9063 cu
->language
, objfile
);
9066 case DW_TAG_typedef
:
9067 case DW_TAG_base_type
:
9068 case DW_TAG_subrange_type
:
9069 add_psymbol_to_list (actual_name
,
9070 built_actual_name
!= NULL
,
9071 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9072 psymbol_placement::STATIC
,
9073 0, cu
->language
, objfile
);
9075 case DW_TAG_imported_declaration
:
9076 case DW_TAG_namespace
:
9077 add_psymbol_to_list (actual_name
,
9078 built_actual_name
!= NULL
,
9079 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
9080 psymbol_placement::GLOBAL
,
9081 0, cu
->language
, objfile
);
9084 /* With Fortran 77 there might be a "BLOCK DATA" module
9085 available without any name. If so, we skip the module as it
9086 doesn't bring any value. */
9087 if (actual_name
!= nullptr)
9088 add_psymbol_to_list (actual_name
,
9089 built_actual_name
!= NULL
,
9090 MODULE_DOMAIN
, LOC_TYPEDEF
, -1,
9091 psymbol_placement::GLOBAL
,
9092 0, cu
->language
, objfile
);
9094 case DW_TAG_class_type
:
9095 case DW_TAG_interface_type
:
9096 case DW_TAG_structure_type
:
9097 case DW_TAG_union_type
:
9098 case DW_TAG_enumeration_type
:
9099 /* Skip external references. The DWARF standard says in the section
9100 about "Structure, Union, and Class Type Entries": "An incomplete
9101 structure, union or class type is represented by a structure,
9102 union or class entry that does not have a byte size attribute
9103 and that has a DW_AT_declaration attribute." */
9104 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
9107 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
9108 static vs. global. */
9109 add_psymbol_to_list (actual_name
,
9110 built_actual_name
!= NULL
,
9111 STRUCT_DOMAIN
, LOC_TYPEDEF
, -1,
9112 cu
->language
== language_cplus
9113 ? psymbol_placement::GLOBAL
9114 : psymbol_placement::STATIC
,
9115 0, cu
->language
, objfile
);
9118 case DW_TAG_enumerator
:
9119 add_psymbol_to_list (actual_name
,
9120 built_actual_name
!= NULL
,
9121 VAR_DOMAIN
, LOC_CONST
, -1,
9122 cu
->language
== language_cplus
9123 ? psymbol_placement::GLOBAL
9124 : psymbol_placement::STATIC
,
9125 0, cu
->language
, objfile
);
9132 /* Read a partial die corresponding to a namespace; also, add a symbol
9133 corresponding to that namespace to the symbol table. NAMESPACE is
9134 the name of the enclosing namespace. */
9137 add_partial_namespace (struct partial_die_info
*pdi
,
9138 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9139 int set_addrmap
, struct dwarf2_cu
*cu
)
9141 /* Add a symbol for the namespace. */
9143 add_partial_symbol (pdi
, cu
);
9145 /* Now scan partial symbols in that namespace. */
9147 if (pdi
->has_children
)
9148 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9151 /* Read a partial die corresponding to a Fortran module. */
9154 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
9155 CORE_ADDR
*highpc
, int set_addrmap
, struct dwarf2_cu
*cu
)
9157 /* Add a symbol for the namespace. */
9159 add_partial_symbol (pdi
, cu
);
9161 /* Now scan partial symbols in that module. */
9163 if (pdi
->has_children
)
9164 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, set_addrmap
, cu
);
9167 /* Read a partial die corresponding to a subprogram or an inlined
9168 subprogram and create a partial symbol for that subprogram.
9169 When the CU language allows it, this routine also defines a partial
9170 symbol for each nested subprogram that this subprogram contains.
9171 If SET_ADDRMAP is true, record the covered ranges in the addrmap.
9172 Set *LOWPC and *HIGHPC to the lowest and highest PC values found in PDI.
9174 PDI may also be a lexical block, in which case we simply search
9175 recursively for subprograms defined inside that lexical block.
9176 Again, this is only performed when the CU language allows this
9177 type of definitions. */
9180 add_partial_subprogram (struct partial_die_info
*pdi
,
9181 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
9182 int set_addrmap
, struct dwarf2_cu
*cu
)
9184 if (pdi
->tag
== DW_TAG_subprogram
|| pdi
->tag
== DW_TAG_inlined_subroutine
)
9186 if (pdi
->has_pc_info
)
9188 if (pdi
->lowpc
< *lowpc
)
9189 *lowpc
= pdi
->lowpc
;
9190 if (pdi
->highpc
> *highpc
)
9191 *highpc
= pdi
->highpc
;
9194 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9195 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9197 CORE_ADDR this_highpc
;
9198 CORE_ADDR this_lowpc
;
9200 baseaddr
= objfile
->text_section_offset ();
9202 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9203 pdi
->lowpc
+ baseaddr
)
9206 = (gdbarch_adjust_dwarf2_addr (gdbarch
,
9207 pdi
->highpc
+ baseaddr
)
9209 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
9210 this_lowpc
, this_highpc
- 1,
9211 cu
->per_cu
->v
.psymtab
);
9215 if (pdi
->has_pc_info
|| (!pdi
->is_external
&& pdi
->may_be_inlined
))
9217 if (!pdi
->is_declaration
)
9218 /* Ignore subprogram DIEs that do not have a name, they are
9219 illegal. Do not emit a complaint at this point, we will
9220 do so when we convert this psymtab into a symtab. */
9222 add_partial_symbol (pdi
, cu
);
9226 if (! pdi
->has_children
)
9229 if (cu
->language
== language_ada
|| cu
->language
== language_fortran
)
9231 pdi
= pdi
->die_child
;
9235 if (pdi
->tag
== DW_TAG_subprogram
9236 || pdi
->tag
== DW_TAG_inlined_subroutine
9237 || pdi
->tag
== DW_TAG_lexical_block
)
9238 add_partial_subprogram (pdi
, lowpc
, highpc
, set_addrmap
, cu
);
9239 pdi
= pdi
->die_sibling
;
9244 /* Read a partial die corresponding to an enumeration type. */
9247 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
9248 struct dwarf2_cu
*cu
)
9250 struct partial_die_info
*pdi
;
9252 if (enum_pdi
->name
!= NULL
)
9253 add_partial_symbol (enum_pdi
, cu
);
9255 pdi
= enum_pdi
->die_child
;
9258 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
9259 complaint (_("malformed enumerator DIE ignored"));
9261 add_partial_symbol (pdi
, cu
);
9262 pdi
= pdi
->die_sibling
;
9266 /* Return the initial uleb128 in the die at INFO_PTR. */
9269 peek_abbrev_code (bfd
*abfd
, const gdb_byte
*info_ptr
)
9271 unsigned int bytes_read
;
9273 return read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9276 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit
9277 READER::CU. Use READER::ABBREV_TABLE to lookup any abbreviation.
9279 Return the corresponding abbrev, or NULL if the number is zero (indicating
9280 an empty DIE). In either case *BYTES_READ will be set to the length of
9281 the initial number. */
9283 static struct abbrev_info
*
9284 peek_die_abbrev (const die_reader_specs
&reader
,
9285 const gdb_byte
*info_ptr
, unsigned int *bytes_read
)
9287 dwarf2_cu
*cu
= reader
.cu
;
9288 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
9289 unsigned int abbrev_number
9290 = read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
9292 if (abbrev_number
== 0)
9295 abbrev_info
*abbrev
= reader
.abbrev_table
->lookup_abbrev (abbrev_number
);
9298 error (_("Dwarf Error: Could not find abbrev number %d in %s"
9299 " at offset %s [in module %s]"),
9300 abbrev_number
, cu
->per_cu
->is_debug_types
? "TU" : "CU",
9301 sect_offset_str (cu
->header
.sect_off
), bfd_get_filename (abfd
));
9307 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9308 Returns a pointer to the end of a series of DIEs, terminated by an empty
9309 DIE. Any children of the skipped DIEs will also be skipped. */
9311 static const gdb_byte
*
9312 skip_children (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
)
9316 unsigned int bytes_read
;
9317 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
9320 return info_ptr
+ bytes_read
;
9322 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
9326 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
9327 INFO_PTR should point just after the initial uleb128 of a DIE, and the
9328 abbrev corresponding to that skipped uleb128 should be passed in
9329 ABBREV. Returns a pointer to this DIE's sibling, skipping any
9332 static const gdb_byte
*
9333 skip_one_die (const struct die_reader_specs
*reader
, const gdb_byte
*info_ptr
,
9334 struct abbrev_info
*abbrev
)
9336 unsigned int bytes_read
;
9337 struct attribute attr
;
9338 bfd
*abfd
= reader
->abfd
;
9339 struct dwarf2_cu
*cu
= reader
->cu
;
9340 const gdb_byte
*buffer
= reader
->buffer
;
9341 const gdb_byte
*buffer_end
= reader
->buffer_end
;
9342 unsigned int form
, i
;
9344 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
9346 /* The only abbrev we care about is DW_AT_sibling. */
9347 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
9350 read_attribute (reader
, &attr
, &abbrev
->attrs
[i
], info_ptr
,
9352 if (attr
.form
== DW_FORM_ref_addr
)
9353 complaint (_("ignoring absolute DW_AT_sibling"));
9356 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
9357 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
9359 if (sibling_ptr
< info_ptr
)
9360 complaint (_("DW_AT_sibling points backwards"));
9361 else if (sibling_ptr
> reader
->buffer_end
)
9362 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
9368 /* If it isn't DW_AT_sibling, skip this attribute. */
9369 form
= abbrev
->attrs
[i
].form
;
9373 case DW_FORM_ref_addr
:
9374 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
9375 and later it is offset sized. */
9376 if (cu
->header
.version
== 2)
9377 info_ptr
+= cu
->header
.addr_size
;
9379 info_ptr
+= cu
->header
.offset_size
;
9381 case DW_FORM_GNU_ref_alt
:
9382 info_ptr
+= cu
->header
.offset_size
;
9385 info_ptr
+= cu
->header
.addr_size
;
9393 case DW_FORM_flag_present
:
9394 case DW_FORM_implicit_const
:
9411 case DW_FORM_ref_sig8
:
9414 case DW_FORM_data16
:
9417 case DW_FORM_string
:
9418 read_direct_string (abfd
, info_ptr
, &bytes_read
);
9419 info_ptr
+= bytes_read
;
9421 case DW_FORM_sec_offset
:
9423 case DW_FORM_GNU_strp_alt
:
9424 info_ptr
+= cu
->header
.offset_size
;
9426 case DW_FORM_exprloc
:
9428 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9429 info_ptr
+= bytes_read
;
9431 case DW_FORM_block1
:
9432 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
9434 case DW_FORM_block2
:
9435 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
9437 case DW_FORM_block4
:
9438 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
9444 case DW_FORM_ref_udata
:
9445 case DW_FORM_GNU_addr_index
:
9446 case DW_FORM_GNU_str_index
:
9447 case DW_FORM_rnglistx
:
9448 info_ptr
= safe_skip_leb128 (info_ptr
, buffer_end
);
9450 case DW_FORM_indirect
:
9451 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9452 info_ptr
+= bytes_read
;
9453 /* We need to continue parsing from here, so just go back to
9455 goto skip_attribute
;
9458 error (_("Dwarf Error: Cannot handle %s "
9459 "in DWARF reader [in module %s]"),
9460 dwarf_form_name (form
),
9461 bfd_get_filename (abfd
));
9465 if (abbrev
->has_children
)
9466 return skip_children (reader
, info_ptr
);
9471 /* Locate ORIG_PDI's sibling.
9472 INFO_PTR should point to the start of the next DIE after ORIG_PDI. */
9474 static const gdb_byte
*
9475 locate_pdi_sibling (const struct die_reader_specs
*reader
,
9476 struct partial_die_info
*orig_pdi
,
9477 const gdb_byte
*info_ptr
)
9479 /* Do we know the sibling already? */
9481 if (orig_pdi
->sibling
)
9482 return orig_pdi
->sibling
;
9484 /* Are there any children to deal with? */
9486 if (!orig_pdi
->has_children
)
9489 /* Skip the children the long way. */
9491 return skip_children (reader
, info_ptr
);
9494 /* Expand this partial symbol table into a full symbol table. SELF is
9498 dwarf2_read_symtab (struct partial_symtab
*self
,
9499 struct objfile
*objfile
)
9501 struct dwarf2_per_objfile
*dwarf2_per_objfile
9502 = get_dwarf2_per_objfile (objfile
);
9506 warning (_("bug: psymtab for %s is already read in."),
9513 printf_filtered (_("Reading in symbols for %s..."),
9515 gdb_flush (gdb_stdout
);
9518 /* If this psymtab is constructed from a debug-only objfile, the
9519 has_section_at_zero flag will not necessarily be correct. We
9520 can get the correct value for this flag by looking at the data
9521 associated with the (presumably stripped) associated objfile. */
9522 if (objfile
->separate_debug_objfile_backlink
)
9524 struct dwarf2_per_objfile
*dpo_backlink
9525 = get_dwarf2_per_objfile (objfile
->separate_debug_objfile_backlink
);
9527 dwarf2_per_objfile
->has_section_at_zero
9528 = dpo_backlink
->has_section_at_zero
;
9531 dwarf2_per_objfile
->reading_partial_symbols
= 0;
9533 psymtab_to_symtab_1 (self
);
9535 /* Finish up the debug error message. */
9537 printf_filtered (_("done.\n"));
9540 process_cu_includes (dwarf2_per_objfile
);
9543 /* Reading in full CUs. */
9545 /* Add PER_CU to the queue. */
9548 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
9549 enum language pretend_language
)
9551 struct dwarf2_queue_item
*item
;
9554 item
= XNEW (struct dwarf2_queue_item
);
9555 item
->per_cu
= per_cu
;
9556 item
->pretend_language
= pretend_language
;
9559 if (dwarf2_queue
== NULL
)
9560 dwarf2_queue
= item
;
9562 dwarf2_queue_tail
->next
= item
;
9564 dwarf2_queue_tail
= item
;
9567 /* If PER_CU is not yet queued, add it to the queue.
9568 If DEPENDENT_CU is non-NULL, it has a reference to PER_CU so add a
9570 The result is non-zero if PER_CU was queued, otherwise the result is zero
9571 meaning either PER_CU is already queued or it is already loaded.
9573 N.B. There is an invariant here that if a CU is queued then it is loaded.
9574 The caller is required to load PER_CU if we return non-zero. */
9577 maybe_queue_comp_unit (struct dwarf2_cu
*dependent_cu
,
9578 struct dwarf2_per_cu_data
*per_cu
,
9579 enum language pretend_language
)
9581 /* We may arrive here during partial symbol reading, if we need full
9582 DIEs to process an unusual case (e.g. template arguments). Do
9583 not queue PER_CU, just tell our caller to load its DIEs. */
9584 if (per_cu
->dwarf2_per_objfile
->reading_partial_symbols
)
9586 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
9591 /* Mark the dependence relation so that we don't flush PER_CU
9593 if (dependent_cu
!= NULL
)
9594 dwarf2_add_dependence (dependent_cu
, per_cu
);
9596 /* If it's already on the queue, we have nothing to do. */
9600 /* If the compilation unit is already loaded, just mark it as
9602 if (per_cu
->cu
!= NULL
)
9604 per_cu
->cu
->last_used
= 0;
9608 /* Add it to the queue. */
9609 queue_comp_unit (per_cu
, pretend_language
);
9614 /* Process the queue. */
9617 process_queue (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
9619 struct dwarf2_queue_item
*item
, *next_item
;
9621 if (dwarf_read_debug
)
9623 fprintf_unfiltered (gdb_stdlog
,
9624 "Expanding one or more symtabs of objfile %s ...\n",
9625 objfile_name (dwarf2_per_objfile
->objfile
));
9628 /* The queue starts out with one item, but following a DIE reference
9629 may load a new CU, adding it to the end of the queue. */
9630 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
9632 if ((dwarf2_per_objfile
->using_index
9633 ? !item
->per_cu
->v
.quick
->compunit_symtab
9634 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
9635 /* Skip dummy CUs. */
9636 && item
->per_cu
->cu
!= NULL
)
9638 struct dwarf2_per_cu_data
*per_cu
= item
->per_cu
;
9639 unsigned int debug_print_threshold
;
9642 if (per_cu
->is_debug_types
)
9644 struct signatured_type
*sig_type
=
9645 (struct signatured_type
*) per_cu
;
9647 sprintf (buf
, "TU %s at offset %s",
9648 hex_string (sig_type
->signature
),
9649 sect_offset_str (per_cu
->sect_off
));
9650 /* There can be 100s of TUs.
9651 Only print them in verbose mode. */
9652 debug_print_threshold
= 2;
9656 sprintf (buf
, "CU at offset %s",
9657 sect_offset_str (per_cu
->sect_off
));
9658 debug_print_threshold
= 1;
9661 if (dwarf_read_debug
>= debug_print_threshold
)
9662 fprintf_unfiltered (gdb_stdlog
, "Expanding symtab of %s\n", buf
);
9664 if (per_cu
->is_debug_types
)
9665 process_full_type_unit (per_cu
, item
->pretend_language
);
9667 process_full_comp_unit (per_cu
, item
->pretend_language
);
9669 if (dwarf_read_debug
>= debug_print_threshold
)
9670 fprintf_unfiltered (gdb_stdlog
, "Done expanding %s\n", buf
);
9673 item
->per_cu
->queued
= 0;
9674 next_item
= item
->next
;
9678 dwarf2_queue_tail
= NULL
;
9680 if (dwarf_read_debug
)
9682 fprintf_unfiltered (gdb_stdlog
, "Done expanding symtabs of %s.\n",
9683 objfile_name (dwarf2_per_objfile
->objfile
));
9687 /* Read in full symbols for PST, and anything it depends on. */
9690 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
9692 struct dwarf2_per_cu_data
*per_cu
;
9698 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
9699 if (!pst
->dependencies
[i
]->readin
9700 && pst
->dependencies
[i
]->user
== NULL
)
9702 /* Inform about additional files that need to be read in. */
9705 /* FIXME: i18n: Need to make this a single string. */
9706 fputs_filtered (" ", gdb_stdout
);
9708 fputs_filtered ("and ", gdb_stdout
);
9710 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
9711 wrap_here (""); /* Flush output. */
9712 gdb_flush (gdb_stdout
);
9714 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
9717 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
9721 /* It's an include file, no symbols to read for it.
9722 Everything is in the parent symtab. */
9727 dw2_do_instantiate_symtab (per_cu
, false);
9730 /* Trivial hash function for die_info: the hash value of a DIE
9731 is its offset in .debug_info for this objfile. */
9734 die_hash (const void *item
)
9736 const struct die_info
*die
= (const struct die_info
*) item
;
9738 return to_underlying (die
->sect_off
);
9741 /* Trivial comparison function for die_info structures: two DIEs
9742 are equal if they have the same offset. */
9745 die_eq (const void *item_lhs
, const void *item_rhs
)
9747 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
9748 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
9750 return die_lhs
->sect_off
== die_rhs
->sect_off
;
9753 /* Load the DIEs associated with PER_CU into memory. */
9756 load_full_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
9758 enum language pretend_language
)
9760 gdb_assert (! this_cu
->is_debug_types
);
9762 cutu_reader
reader (this_cu
, NULL
, 1, 1, skip_partial
);
9766 struct dwarf2_cu
*cu
= reader
.cu
;
9767 const gdb_byte
*info_ptr
= reader
.info_ptr
;
9769 gdb_assert (cu
->die_hash
== NULL
);
9771 htab_create_alloc_ex (cu
->header
.length
/ 12,
9775 &cu
->comp_unit_obstack
,
9776 hashtab_obstack_allocate
,
9777 dummy_obstack_deallocate
);
9779 if (reader
.has_children
)
9780 reader
.comp_unit_die
->child
9781 = read_die_and_siblings (&reader
, reader
.info_ptr
,
9782 &info_ptr
, reader
.comp_unit_die
);
9783 cu
->dies
= reader
.comp_unit_die
;
9784 /* comp_unit_die is not stored in die_hash, no need. */
9786 /* We try not to read any attributes in this function, because not
9787 all CUs needed for references have been loaded yet, and symbol
9788 table processing isn't initialized. But we have to set the CU language,
9789 or we won't be able to build types correctly.
9790 Similarly, if we do not read the producer, we can not apply
9791 producer-specific interpretation. */
9792 prepare_one_comp_unit (cu
, cu
->dies
, pretend_language
);
9795 /* Add a DIE to the delayed physname list. */
9798 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
9799 const char *name
, struct die_info
*die
,
9800 struct dwarf2_cu
*cu
)
9802 struct delayed_method_info mi
;
9804 mi
.fnfield_index
= fnfield_index
;
9808 cu
->method_list
.push_back (mi
);
9811 /* Check whether [PHYSNAME, PHYSNAME+LEN) ends with a modifier like
9812 "const" / "volatile". If so, decrements LEN by the length of the
9813 modifier and return true. Otherwise return false. */
9817 check_modifier (const char *physname
, size_t &len
, const char (&mod
)[N
])
9819 size_t mod_len
= sizeof (mod
) - 1;
9820 if (len
> mod_len
&& startswith (physname
+ (len
- mod_len
), mod
))
9828 /* Compute the physnames of any methods on the CU's method list.
9830 The computation of method physnames is delayed in order to avoid the
9831 (bad) condition that one of the method's formal parameters is of an as yet
9835 compute_delayed_physnames (struct dwarf2_cu
*cu
)
9837 /* Only C++ delays computing physnames. */
9838 if (cu
->method_list
.empty ())
9840 gdb_assert (cu
->language
== language_cplus
);
9842 for (const delayed_method_info
&mi
: cu
->method_list
)
9844 const char *physname
;
9845 struct fn_fieldlist
*fn_flp
9846 = &TYPE_FN_FIELDLIST (mi
.type
, mi
.fnfield_index
);
9847 physname
= dwarf2_physname (mi
.name
, mi
.die
, cu
);
9848 TYPE_FN_FIELD_PHYSNAME (fn_flp
->fn_fields
, mi
.index
)
9849 = physname
? physname
: "";
9851 /* Since there's no tag to indicate whether a method is a
9852 const/volatile overload, extract that information out of the
9854 if (physname
!= NULL
)
9856 size_t len
= strlen (physname
);
9860 if (physname
[len
] == ')') /* shortcut */
9862 else if (check_modifier (physname
, len
, " const"))
9863 TYPE_FN_FIELD_CONST (fn_flp
->fn_fields
, mi
.index
) = 1;
9864 else if (check_modifier (physname
, len
, " volatile"))
9865 TYPE_FN_FIELD_VOLATILE (fn_flp
->fn_fields
, mi
.index
) = 1;
9872 /* The list is no longer needed. */
9873 cu
->method_list
.clear ();
9876 /* Go objects should be embedded in a DW_TAG_module DIE,
9877 and it's not clear if/how imported objects will appear.
9878 To keep Go support simple until that's worked out,
9879 go back through what we've read and create something usable.
9880 We could do this while processing each DIE, and feels kinda cleaner,
9881 but that way is more invasive.
9882 This is to, for example, allow the user to type "p var" or "b main"
9883 without having to specify the package name, and allow lookups
9884 of module.object to work in contexts that use the expression
9888 fixup_go_packaging (struct dwarf2_cu
*cu
)
9890 gdb::unique_xmalloc_ptr
<char> package_name
;
9891 struct pending
*list
;
9894 for (list
= *cu
->get_builder ()->get_global_symbols ();
9898 for (i
= 0; i
< list
->nsyms
; ++i
)
9900 struct symbol
*sym
= list
->symbol
[i
];
9902 if (sym
->language () == language_go
9903 && SYMBOL_CLASS (sym
) == LOC_BLOCK
)
9905 gdb::unique_xmalloc_ptr
<char> this_package_name
9906 (go_symbol_package_name (sym
));
9908 if (this_package_name
== NULL
)
9910 if (package_name
== NULL
)
9911 package_name
= std::move (this_package_name
);
9914 struct objfile
*objfile
9915 = cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9916 if (strcmp (package_name
.get (), this_package_name
.get ()) != 0)
9917 complaint (_("Symtab %s has objects from two different Go packages: %s and %s"),
9918 (symbol_symtab (sym
) != NULL
9919 ? symtab_to_filename_for_display
9920 (symbol_symtab (sym
))
9921 : objfile_name (objfile
)),
9922 this_package_name
.get (), package_name
.get ());
9928 if (package_name
!= NULL
)
9930 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
9931 const char *saved_package_name
9932 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
, package_name
.get ());
9933 struct type
*type
= init_type (objfile
, TYPE_CODE_MODULE
, 0,
9934 saved_package_name
);
9937 sym
= allocate_symbol (objfile
);
9938 sym
->set_language (language_go
, &objfile
->objfile_obstack
);
9939 sym
->compute_and_set_names (saved_package_name
, false, objfile
->per_bfd
);
9940 /* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
9941 e.g., "main" finds the "main" module and not C's main(). */
9942 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9943 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
9944 SYMBOL_TYPE (sym
) = type
;
9946 add_symbol_to_list (sym
, cu
->get_builder ()->get_global_symbols ());
9950 /* Allocate a fully-qualified name consisting of the two parts on the
9954 rust_fully_qualify (struct obstack
*obstack
, const char *p1
, const char *p2
)
9956 return obconcat (obstack
, p1
, "::", p2
, (char *) NULL
);
9959 /* A helper that allocates a struct discriminant_info to attach to a
9962 static struct discriminant_info
*
9963 alloc_discriminant_info (struct type
*type
, int discriminant_index
,
9966 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
9967 gdb_assert (discriminant_index
== -1
9968 || (discriminant_index
>= 0
9969 && discriminant_index
< TYPE_NFIELDS (type
)));
9970 gdb_assert (default_index
== -1
9971 || (default_index
>= 0 && default_index
< TYPE_NFIELDS (type
)));
9973 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
9975 struct discriminant_info
*disc
9976 = ((struct discriminant_info
*)
9978 offsetof (struct discriminant_info
, discriminants
)
9979 + TYPE_NFIELDS (type
) * sizeof (disc
->discriminants
[0])));
9980 disc
->default_index
= default_index
;
9981 disc
->discriminant_index
= discriminant_index
;
9983 struct dynamic_prop prop
;
9984 prop
.kind
= PROP_UNDEFINED
;
9985 prop
.data
.baton
= disc
;
9987 add_dyn_prop (DYN_PROP_DISCRIMINATED
, prop
, type
);
9992 /* Some versions of rustc emitted enums in an unusual way.
9994 Ordinary enums were emitted as unions. The first element of each
9995 structure in the union was named "RUST$ENUM$DISR". This element
9996 held the discriminant.
9998 These versions of Rust also implemented the "non-zero"
9999 optimization. When the enum had two values, and one is empty and
10000 the other holds a pointer that cannot be zero, the pointer is used
10001 as the discriminant, with a zero value meaning the empty variant.
10002 Here, the union's first member is of the form
10003 RUST$ENCODED$ENUM$<fieldno>$<fieldno>$...$<variantname>
10004 where the fieldnos are the indices of the fields that should be
10005 traversed in order to find the field (which may be several fields deep)
10006 and the variantname is the name of the variant of the case when the
10009 This function recognizes whether TYPE is of one of these forms,
10010 and, if so, smashes it to be a variant type. */
10013 quirk_rust_enum (struct type
*type
, struct objfile
*objfile
)
10015 gdb_assert (TYPE_CODE (type
) == TYPE_CODE_UNION
);
10017 /* We don't need to deal with empty enums. */
10018 if (TYPE_NFIELDS (type
) == 0)
10021 #define RUST_ENUM_PREFIX "RUST$ENCODED$ENUM$"
10022 if (TYPE_NFIELDS (type
) == 1
10023 && startswith (TYPE_FIELD_NAME (type
, 0), RUST_ENUM_PREFIX
))
10025 const char *name
= TYPE_FIELD_NAME (type
, 0) + strlen (RUST_ENUM_PREFIX
);
10027 /* Decode the field name to find the offset of the
10029 ULONGEST bit_offset
= 0;
10030 struct type
*field_type
= TYPE_FIELD_TYPE (type
, 0);
10031 while (name
[0] >= '0' && name
[0] <= '9')
10034 unsigned long index
= strtoul (name
, &tail
, 10);
10037 || index
>= TYPE_NFIELDS (field_type
)
10038 || (TYPE_FIELD_LOC_KIND (field_type
, index
)
10039 != FIELD_LOC_KIND_BITPOS
))
10041 complaint (_("Could not parse Rust enum encoding string \"%s\""
10043 TYPE_FIELD_NAME (type
, 0),
10044 objfile_name (objfile
));
10049 bit_offset
+= TYPE_FIELD_BITPOS (field_type
, index
);
10050 field_type
= TYPE_FIELD_TYPE (field_type
, index
);
10053 /* Make a union to hold the variants. */
10054 struct type
*union_type
= alloc_type (objfile
);
10055 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10056 TYPE_NFIELDS (union_type
) = 3;
10057 TYPE_FIELDS (union_type
)
10058 = (struct field
*) TYPE_ZALLOC (type
, 3 * sizeof (struct field
));
10059 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10060 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10062 /* Put the discriminant must at index 0. */
10063 TYPE_FIELD_TYPE (union_type
, 0) = field_type
;
10064 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10065 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10066 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 0), bit_offset
);
10068 /* The order of fields doesn't really matter, so put the real
10069 field at index 1 and the data-less field at index 2. */
10070 struct discriminant_info
*disc
10071 = alloc_discriminant_info (union_type
, 0, 1);
10072 TYPE_FIELD (union_type
, 1) = TYPE_FIELD (type
, 0);
10073 TYPE_FIELD_NAME (union_type
, 1)
10074 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1)));
10075 TYPE_NAME (TYPE_FIELD_TYPE (union_type
, 1))
10076 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10077 TYPE_FIELD_NAME (union_type
, 1));
10079 const char *dataless_name
10080 = rust_fully_qualify (&objfile
->objfile_obstack
, TYPE_NAME (type
),
10082 struct type
*dataless_type
= init_type (objfile
, TYPE_CODE_VOID
, 0,
10084 TYPE_FIELD_TYPE (union_type
, 2) = dataless_type
;
10085 /* NAME points into the original discriminant name, which
10086 already has the correct lifetime. */
10087 TYPE_FIELD_NAME (union_type
, 2) = name
;
10088 SET_FIELD_BITPOS (TYPE_FIELD (union_type
, 2), 0);
10089 disc
->discriminants
[2] = 0;
10091 /* Smash this type to be a structure type. We have to do this
10092 because the type has already been recorded. */
10093 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10094 TYPE_NFIELDS (type
) = 1;
10096 = (struct field
*) TYPE_ZALLOC (type
, sizeof (struct field
));
10098 /* Install the variant part. */
10099 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10100 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10101 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10103 /* A union with a single anonymous field is probably an old-style
10104 univariant enum. */
10105 else if (TYPE_NFIELDS (type
) == 1 && streq (TYPE_FIELD_NAME (type
, 0), ""))
10107 /* Smash this type to be a structure type. We have to do this
10108 because the type has already been recorded. */
10109 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10111 /* Make a union to hold the variants. */
10112 struct type
*union_type
= alloc_type (objfile
);
10113 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10114 TYPE_NFIELDS (union_type
) = TYPE_NFIELDS (type
);
10115 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10116 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10117 TYPE_FIELDS (union_type
) = TYPE_FIELDS (type
);
10119 struct type
*field_type
= TYPE_FIELD_TYPE (union_type
, 0);
10120 const char *variant_name
10121 = rust_last_path_segment (TYPE_NAME (field_type
));
10122 TYPE_FIELD_NAME (union_type
, 0) = variant_name
;
10123 TYPE_NAME (field_type
)
10124 = rust_fully_qualify (&objfile
->objfile_obstack
,
10125 TYPE_NAME (type
), variant_name
);
10127 /* Install the union in the outer struct type. */
10128 TYPE_NFIELDS (type
) = 1;
10130 = (struct field
*) TYPE_ZALLOC (union_type
, sizeof (struct field
));
10131 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10132 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10133 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10135 alloc_discriminant_info (union_type
, -1, 0);
10139 struct type
*disr_type
= nullptr;
10140 for (int i
= 0; i
< TYPE_NFIELDS (type
); ++i
)
10142 disr_type
= TYPE_FIELD_TYPE (type
, i
);
10144 if (TYPE_CODE (disr_type
) != TYPE_CODE_STRUCT
)
10146 /* All fields of a true enum will be structs. */
10149 else if (TYPE_NFIELDS (disr_type
) == 0)
10151 /* Could be data-less variant, so keep going. */
10152 disr_type
= nullptr;
10154 else if (strcmp (TYPE_FIELD_NAME (disr_type
, 0),
10155 "RUST$ENUM$DISR") != 0)
10157 /* Not a Rust enum. */
10167 /* If we got here without a discriminant, then it's probably
10169 if (disr_type
== nullptr)
10172 /* Smash this type to be a structure type. We have to do this
10173 because the type has already been recorded. */
10174 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
10176 /* Make a union to hold the variants. */
10177 struct field
*disr_field
= &TYPE_FIELD (disr_type
, 0);
10178 struct type
*union_type
= alloc_type (objfile
);
10179 TYPE_CODE (union_type
) = TYPE_CODE_UNION
;
10180 TYPE_NFIELDS (union_type
) = 1 + TYPE_NFIELDS (type
);
10181 TYPE_LENGTH (union_type
) = TYPE_LENGTH (type
);
10182 set_type_align (union_type
, TYPE_RAW_ALIGN (type
));
10183 TYPE_FIELDS (union_type
)
10184 = (struct field
*) TYPE_ZALLOC (union_type
,
10185 (TYPE_NFIELDS (union_type
)
10186 * sizeof (struct field
)));
10188 memcpy (TYPE_FIELDS (union_type
) + 1, TYPE_FIELDS (type
),
10189 TYPE_NFIELDS (type
) * sizeof (struct field
));
10191 /* Install the discriminant at index 0 in the union. */
10192 TYPE_FIELD (union_type
, 0) = *disr_field
;
10193 TYPE_FIELD_ARTIFICIAL (union_type
, 0) = 1;
10194 TYPE_FIELD_NAME (union_type
, 0) = "<<discriminant>>";
10196 /* Install the union in the outer struct type. */
10197 TYPE_FIELD_TYPE (type
, 0) = union_type
;
10198 TYPE_FIELD_NAME (type
, 0) = "<<variants>>";
10199 TYPE_NFIELDS (type
) = 1;
10201 /* Set the size and offset of the union type. */
10202 SET_FIELD_BITPOS (TYPE_FIELD (type
, 0), 0);
10204 /* We need a way to find the correct discriminant given a
10205 variant name. For convenience we build a map here. */
10206 struct type
*enum_type
= FIELD_TYPE (*disr_field
);
10207 std::unordered_map
<std::string
, ULONGEST
> discriminant_map
;
10208 for (int i
= 0; i
< TYPE_NFIELDS (enum_type
); ++i
)
10210 if (TYPE_FIELD_LOC_KIND (enum_type
, i
) == FIELD_LOC_KIND_ENUMVAL
)
10213 = rust_last_path_segment (TYPE_FIELD_NAME (enum_type
, i
));
10214 discriminant_map
[name
] = TYPE_FIELD_ENUMVAL (enum_type
, i
);
10218 int n_fields
= TYPE_NFIELDS (union_type
);
10219 struct discriminant_info
*disc
10220 = alloc_discriminant_info (union_type
, 0, -1);
10221 /* Skip the discriminant here. */
10222 for (int i
= 1; i
< n_fields
; ++i
)
10224 /* Find the final word in the name of this variant's type.
10225 That name can be used to look up the correct
10227 const char *variant_name
10228 = rust_last_path_segment (TYPE_NAME (TYPE_FIELD_TYPE (union_type
,
10231 auto iter
= discriminant_map
.find (variant_name
);
10232 if (iter
!= discriminant_map
.end ())
10233 disc
->discriminants
[i
] = iter
->second
;
10235 /* Remove the discriminant field, if it exists. */
10236 struct type
*sub_type
= TYPE_FIELD_TYPE (union_type
, i
);
10237 if (TYPE_NFIELDS (sub_type
) > 0)
10239 --TYPE_NFIELDS (sub_type
);
10240 ++TYPE_FIELDS (sub_type
);
10242 TYPE_FIELD_NAME (union_type
, i
) = variant_name
;
10243 TYPE_NAME (sub_type
)
10244 = rust_fully_qualify (&objfile
->objfile_obstack
,
10245 TYPE_NAME (type
), variant_name
);
10250 /* Rewrite some Rust unions to be structures with variants parts. */
10253 rust_union_quirks (struct dwarf2_cu
*cu
)
10255 gdb_assert (cu
->language
== language_rust
);
10256 for (type
*type_
: cu
->rust_unions
)
10257 quirk_rust_enum (type_
, cu
->per_cu
->dwarf2_per_objfile
->objfile
);
10258 /* We don't need this any more. */
10259 cu
->rust_unions
.clear ();
10262 /* Return the symtab for PER_CU. This works properly regardless of
10263 whether we're using the index or psymtabs. */
10265 static struct compunit_symtab
*
10266 get_compunit_symtab (struct dwarf2_per_cu_data
*per_cu
)
10268 return (per_cu
->dwarf2_per_objfile
->using_index
10269 ? per_cu
->v
.quick
->compunit_symtab
10270 : per_cu
->v
.psymtab
->compunit_symtab
);
10273 /* A helper function for computing the list of all symbol tables
10274 included by PER_CU. */
10277 recursively_compute_inclusions (std::vector
<compunit_symtab
*> *result
,
10278 htab_t all_children
, htab_t all_type_symtabs
,
10279 struct dwarf2_per_cu_data
*per_cu
,
10280 struct compunit_symtab
*immediate_parent
)
10283 struct compunit_symtab
*cust
;
10285 slot
= htab_find_slot (all_children
, per_cu
, INSERT
);
10288 /* This inclusion and its children have been processed. */
10293 /* Only add a CU if it has a symbol table. */
10294 cust
= get_compunit_symtab (per_cu
);
10297 /* If this is a type unit only add its symbol table if we haven't
10298 seen it yet (type unit per_cu's can share symtabs). */
10299 if (per_cu
->is_debug_types
)
10301 slot
= htab_find_slot (all_type_symtabs
, cust
, INSERT
);
10305 result
->push_back (cust
);
10306 if (cust
->user
== NULL
)
10307 cust
->user
= immediate_parent
;
10312 result
->push_back (cust
);
10313 if (cust
->user
== NULL
)
10314 cust
->user
= immediate_parent
;
10318 if (!per_cu
->imported_symtabs_empty ())
10319 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10321 recursively_compute_inclusions (result
, all_children
,
10322 all_type_symtabs
, ptr
, cust
);
10326 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
10330 compute_compunit_symtab_includes (struct dwarf2_per_cu_data
*per_cu
)
10332 gdb_assert (! per_cu
->is_debug_types
);
10334 if (!per_cu
->imported_symtabs_empty ())
10337 std::vector
<compunit_symtab
*> result_symtabs
;
10338 htab_t all_children
, all_type_symtabs
;
10339 struct compunit_symtab
*cust
= get_compunit_symtab (per_cu
);
10341 /* If we don't have a symtab, we can just skip this case. */
10345 all_children
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10346 NULL
, xcalloc
, xfree
);
10347 all_type_symtabs
= htab_create_alloc (1, htab_hash_pointer
, htab_eq_pointer
,
10348 NULL
, xcalloc
, xfree
);
10350 for (dwarf2_per_cu_data
*ptr
: *per_cu
->imported_symtabs
)
10352 recursively_compute_inclusions (&result_symtabs
, all_children
,
10353 all_type_symtabs
, ptr
, cust
);
10356 /* Now we have a transitive closure of all the included symtabs. */
10357 len
= result_symtabs
.size ();
10359 = XOBNEWVEC (&per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
,
10360 struct compunit_symtab
*, len
+ 1);
10361 memcpy (cust
->includes
, result_symtabs
.data (),
10362 len
* sizeof (compunit_symtab
*));
10363 cust
->includes
[len
] = NULL
;
10365 htab_delete (all_children
);
10366 htab_delete (all_type_symtabs
);
10370 /* Compute the 'includes' field for the symtabs of all the CUs we just
10374 process_cu_includes (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
10376 for (dwarf2_per_cu_data
*iter
: dwarf2_per_objfile
->just_read_cus
)
10378 if (! iter
->is_debug_types
)
10379 compute_compunit_symtab_includes (iter
);
10382 dwarf2_per_objfile
->just_read_cus
.clear ();
10385 /* Generate full symbol information for PER_CU, whose DIEs have
10386 already been loaded into memory. */
10389 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
10390 enum language pretend_language
)
10392 struct dwarf2_cu
*cu
= per_cu
->cu
;
10393 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10394 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10395 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10396 CORE_ADDR lowpc
, highpc
;
10397 struct compunit_symtab
*cust
;
10398 CORE_ADDR baseaddr
;
10399 struct block
*static_block
;
10402 baseaddr
= objfile
->text_section_offset ();
10404 /* Clear the list here in case something was left over. */
10405 cu
->method_list
.clear ();
10407 cu
->language
= pretend_language
;
10408 cu
->language_defn
= language_def (cu
->language
);
10410 /* Do line number decoding in read_file_scope () */
10411 process_die (cu
->dies
, cu
);
10413 /* For now fudge the Go package. */
10414 if (cu
->language
== language_go
)
10415 fixup_go_packaging (cu
);
10417 /* Now that we have processed all the DIEs in the CU, all the types
10418 should be complete, and it should now be safe to compute all of the
10420 compute_delayed_physnames (cu
);
10422 if (cu
->language
== language_rust
)
10423 rust_union_quirks (cu
);
10425 /* Some compilers don't define a DW_AT_high_pc attribute for the
10426 compilation unit. If the DW_AT_high_pc is missing, synthesize
10427 it, by scanning the DIE's below the compilation unit. */
10428 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
10430 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
10431 static_block
= cu
->get_builder ()->end_symtab_get_static_block (addr
, 0, 1);
10433 /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges.
10434 Also, DW_AT_ranges may record ranges not belonging to any child DIEs
10435 (such as virtual method tables). Record the ranges in STATIC_BLOCK's
10436 addrmap to help ensure it has an accurate map of pc values belonging to
10438 dwarf2_record_block_ranges (cu
->dies
, static_block
, baseaddr
, cu
);
10440 cust
= cu
->get_builder ()->end_symtab_from_static_block (static_block
,
10441 SECT_OFF_TEXT (objfile
),
10446 int gcc_4_minor
= producer_is_gcc_ge_4 (cu
->producer
);
10448 /* Set symtab language to language from DW_AT_language. If the
10449 compilation is from a C file generated by language preprocessors, do
10450 not set the language if it was already deduced by start_subfile. */
10451 if (!(cu
->language
== language_c
10452 && COMPUNIT_FILETABS (cust
)->language
!= language_unknown
))
10453 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10455 /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can
10456 produce DW_AT_location with location lists but it can be possibly
10457 invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0
10458 there were bugs in prologue debug info, fixed later in GCC-4.5
10459 by "unwind info for epilogues" patch (which is not directly related).
10461 For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not
10462 needed, it would be wrong due to missing DW_AT_producer there.
10464 Still one can confuse GDB by using non-standard GCC compilation
10465 options - this waits on GCC PR other/32998 (-frecord-gcc-switches).
10467 if (cu
->has_loclist
&& gcc_4_minor
>= 5)
10468 cust
->locations_valid
= 1;
10470 if (gcc_4_minor
>= 5)
10471 cust
->epilogue_unwind_valid
= 1;
10473 cust
->call_site_htab
= cu
->call_site_htab
;
10476 if (dwarf2_per_objfile
->using_index
)
10477 per_cu
->v
.quick
->compunit_symtab
= cust
;
10480 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10481 pst
->compunit_symtab
= cust
;
10482 pst
->readin
= true;
10485 /* Push it for inclusion processing later. */
10486 dwarf2_per_objfile
->just_read_cus
.push_back (per_cu
);
10488 /* Not needed any more. */
10489 cu
->reset_builder ();
10492 /* Generate full symbol information for type unit PER_CU, whose DIEs have
10493 already been loaded into memory. */
10496 process_full_type_unit (struct dwarf2_per_cu_data
*per_cu
,
10497 enum language pretend_language
)
10499 struct dwarf2_cu
*cu
= per_cu
->cu
;
10500 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
10501 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
10502 struct compunit_symtab
*cust
;
10503 struct signatured_type
*sig_type
;
10505 gdb_assert (per_cu
->is_debug_types
);
10506 sig_type
= (struct signatured_type
*) per_cu
;
10508 /* Clear the list here in case something was left over. */
10509 cu
->method_list
.clear ();
10511 cu
->language
= pretend_language
;
10512 cu
->language_defn
= language_def (cu
->language
);
10514 /* The symbol tables are set up in read_type_unit_scope. */
10515 process_die (cu
->dies
, cu
);
10517 /* For now fudge the Go package. */
10518 if (cu
->language
== language_go
)
10519 fixup_go_packaging (cu
);
10521 /* Now that we have processed all the DIEs in the CU, all the types
10522 should be complete, and it should now be safe to compute all of the
10524 compute_delayed_physnames (cu
);
10526 if (cu
->language
== language_rust
)
10527 rust_union_quirks (cu
);
10529 /* TUs share symbol tables.
10530 If this is the first TU to use this symtab, complete the construction
10531 of it with end_expandable_symtab. Otherwise, complete the addition of
10532 this TU's symbols to the existing symtab. */
10533 if (sig_type
->type_unit_group
->compunit_symtab
== NULL
)
10535 buildsym_compunit
*builder
= cu
->get_builder ();
10536 cust
= builder
->end_expandable_symtab (0, SECT_OFF_TEXT (objfile
));
10537 sig_type
->type_unit_group
->compunit_symtab
= cust
;
10541 /* Set symtab language to language from DW_AT_language. If the
10542 compilation is from a C file generated by language preprocessors,
10543 do not set the language if it was already deduced by
10545 if (!(cu
->language
== language_c
10546 && COMPUNIT_FILETABS (cust
)->language
!= language_c
))
10547 COMPUNIT_FILETABS (cust
)->language
= cu
->language
;
10552 cu
->get_builder ()->augment_type_symtab ();
10553 cust
= sig_type
->type_unit_group
->compunit_symtab
;
10556 if (dwarf2_per_objfile
->using_index
)
10557 per_cu
->v
.quick
->compunit_symtab
= cust
;
10560 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
10561 pst
->compunit_symtab
= cust
;
10562 pst
->readin
= true;
10565 /* Not needed any more. */
10566 cu
->reset_builder ();
10569 /* Process an imported unit DIE. */
10572 process_imported_unit_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10574 struct attribute
*attr
;
10576 /* For now we don't handle imported units in type units. */
10577 if (cu
->per_cu
->is_debug_types
)
10579 error (_("Dwarf Error: DW_TAG_imported_unit is not"
10580 " supported in type units [in module %s]"),
10581 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
10584 attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
10587 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
10588 bool is_dwz
= (attr
->form
== DW_FORM_GNU_ref_alt
|| cu
->per_cu
->is_dwz
);
10589 dwarf2_per_cu_data
*per_cu
10590 = dwarf2_find_containing_comp_unit (sect_off
, is_dwz
,
10591 cu
->per_cu
->dwarf2_per_objfile
);
10593 /* If necessary, add it to the queue and load its DIEs. */
10594 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
10595 load_full_comp_unit (per_cu
, false, cu
->language
);
10597 cu
->per_cu
->imported_symtabs_push (per_cu
);
10601 /* RAII object that represents a process_die scope: i.e.,
10602 starts/finishes processing a DIE. */
10603 class process_die_scope
10606 process_die_scope (die_info
*die
, dwarf2_cu
*cu
)
10607 : m_die (die
), m_cu (cu
)
10609 /* We should only be processing DIEs not already in process. */
10610 gdb_assert (!m_die
->in_process
);
10611 m_die
->in_process
= true;
10614 ~process_die_scope ()
10616 m_die
->in_process
= false;
10618 /* If we're done processing the DIE for the CU that owns the line
10619 header, we don't need the line header anymore. */
10620 if (m_cu
->line_header_die_owner
== m_die
)
10622 delete m_cu
->line_header
;
10623 m_cu
->line_header
= NULL
;
10624 m_cu
->line_header_die_owner
= NULL
;
10633 /* Process a die and its children. */
10636 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10638 process_die_scope
scope (die
, cu
);
10642 case DW_TAG_padding
:
10644 case DW_TAG_compile_unit
:
10645 case DW_TAG_partial_unit
:
10646 read_file_scope (die
, cu
);
10648 case DW_TAG_type_unit
:
10649 read_type_unit_scope (die
, cu
);
10651 case DW_TAG_subprogram
:
10652 /* Nested subprograms in Fortran get a prefix. */
10653 if (cu
->language
== language_fortran
10654 && die
->parent
!= NULL
10655 && die
->parent
->tag
== DW_TAG_subprogram
)
10656 cu
->processing_has_namespace_info
= true;
10657 /* Fall through. */
10658 case DW_TAG_inlined_subroutine
:
10659 read_func_scope (die
, cu
);
10661 case DW_TAG_lexical_block
:
10662 case DW_TAG_try_block
:
10663 case DW_TAG_catch_block
:
10664 read_lexical_block_scope (die
, cu
);
10666 case DW_TAG_call_site
:
10667 case DW_TAG_GNU_call_site
:
10668 read_call_site_scope (die
, cu
);
10670 case DW_TAG_class_type
:
10671 case DW_TAG_interface_type
:
10672 case DW_TAG_structure_type
:
10673 case DW_TAG_union_type
:
10674 process_structure_scope (die
, cu
);
10676 case DW_TAG_enumeration_type
:
10677 process_enumeration_scope (die
, cu
);
10680 /* These dies have a type, but processing them does not create
10681 a symbol or recurse to process the children. Therefore we can
10682 read them on-demand through read_type_die. */
10683 case DW_TAG_subroutine_type
:
10684 case DW_TAG_set_type
:
10685 case DW_TAG_array_type
:
10686 case DW_TAG_pointer_type
:
10687 case DW_TAG_ptr_to_member_type
:
10688 case DW_TAG_reference_type
:
10689 case DW_TAG_rvalue_reference_type
:
10690 case DW_TAG_string_type
:
10693 case DW_TAG_base_type
:
10694 case DW_TAG_subrange_type
:
10695 case DW_TAG_typedef
:
10696 /* Add a typedef symbol for the type definition, if it has a
10698 new_symbol (die
, read_type_die (die
, cu
), cu
);
10700 case DW_TAG_common_block
:
10701 read_common_block (die
, cu
);
10703 case DW_TAG_common_inclusion
:
10705 case DW_TAG_namespace
:
10706 cu
->processing_has_namespace_info
= true;
10707 read_namespace (die
, cu
);
10709 case DW_TAG_module
:
10710 cu
->processing_has_namespace_info
= true;
10711 read_module (die
, cu
);
10713 case DW_TAG_imported_declaration
:
10714 cu
->processing_has_namespace_info
= true;
10715 if (read_namespace_alias (die
, cu
))
10717 /* The declaration is not a global namespace alias. */
10718 /* Fall through. */
10719 case DW_TAG_imported_module
:
10720 cu
->processing_has_namespace_info
= true;
10721 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
10722 || cu
->language
!= language_fortran
))
10723 complaint (_("Tag '%s' has unexpected children"),
10724 dwarf_tag_name (die
->tag
));
10725 read_import_statement (die
, cu
);
10728 case DW_TAG_imported_unit
:
10729 process_imported_unit_die (die
, cu
);
10732 case DW_TAG_variable
:
10733 read_variable (die
, cu
);
10737 new_symbol (die
, NULL
, cu
);
10742 /* DWARF name computation. */
10744 /* A helper function for dwarf2_compute_name which determines whether DIE
10745 needs to have the name of the scope prepended to the name listed in the
10749 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
10751 struct attribute
*attr
;
10755 case DW_TAG_namespace
:
10756 case DW_TAG_typedef
:
10757 case DW_TAG_class_type
:
10758 case DW_TAG_interface_type
:
10759 case DW_TAG_structure_type
:
10760 case DW_TAG_union_type
:
10761 case DW_TAG_enumeration_type
:
10762 case DW_TAG_enumerator
:
10763 case DW_TAG_subprogram
:
10764 case DW_TAG_inlined_subroutine
:
10765 case DW_TAG_member
:
10766 case DW_TAG_imported_declaration
:
10769 case DW_TAG_variable
:
10770 case DW_TAG_constant
:
10771 /* We only need to prefix "globally" visible variables. These include
10772 any variable marked with DW_AT_external or any variable that
10773 lives in a namespace. [Variables in anonymous namespaces
10774 require prefixing, but they are not DW_AT_external.] */
10776 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
10778 struct dwarf2_cu
*spec_cu
= cu
;
10780 return die_needs_namespace (die_specification (die
, &spec_cu
),
10784 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
10785 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
10786 && die
->parent
->tag
!= DW_TAG_module
)
10788 /* A variable in a lexical block of some kind does not need a
10789 namespace, even though in C++ such variables may be external
10790 and have a mangled name. */
10791 if (die
->parent
->tag
== DW_TAG_lexical_block
10792 || die
->parent
->tag
== DW_TAG_try_block
10793 || die
->parent
->tag
== DW_TAG_catch_block
10794 || die
->parent
->tag
== DW_TAG_subprogram
)
10803 /* Return the DIE's linkage name attribute, either DW_AT_linkage_name
10804 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10805 defined for the given DIE. */
10807 static struct attribute
*
10808 dw2_linkage_name_attr (struct die_info
*die
, struct dwarf2_cu
*cu
)
10810 struct attribute
*attr
;
10812 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
10814 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10819 /* Return the DIE's linkage name as a string, either DW_AT_linkage_name
10820 or DW_AT_MIPS_linkage_name. Returns NULL if the attribute is not
10821 defined for the given DIE. */
10823 static const char *
10824 dw2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10826 const char *linkage_name
;
10828 linkage_name
= dwarf2_string_attr (die
, DW_AT_linkage_name
, cu
);
10829 if (linkage_name
== NULL
)
10830 linkage_name
= dwarf2_string_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
10832 return linkage_name
;
10835 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
10836 compute the physname for the object, which include a method's:
10837 - formal parameters (C++),
10838 - receiver type (Go),
10840 The term "physname" is a bit confusing.
10841 For C++, for example, it is the demangled name.
10842 For Go, for example, it's the mangled name.
10844 For Ada, return the DIE's linkage name rather than the fully qualified
10845 name. PHYSNAME is ignored..
10847 The result is allocated on the objfile_obstack and canonicalized. */
10849 static const char *
10850 dwarf2_compute_name (const char *name
,
10851 struct die_info
*die
, struct dwarf2_cu
*cu
,
10854 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
10857 name
= dwarf2_name (die
, cu
);
10859 /* For Fortran GDB prefers DW_AT_*linkage_name for the physname if present
10860 but otherwise compute it by typename_concat inside GDB.
10861 FIXME: Actually this is not really true, or at least not always true.
10862 It's all very confusing. compute_and_set_names doesn't try to demangle
10863 Fortran names because there is no mangling standard. So new_symbol
10864 will set the demangled name to the result of dwarf2_full_name, and it is
10865 the demangled name that GDB uses if it exists. */
10866 if (cu
->language
== language_ada
10867 || (cu
->language
== language_fortran
&& physname
))
10869 /* For Ada unit, we prefer the linkage name over the name, as
10870 the former contains the exported name, which the user expects
10871 to be able to reference. Ideally, we want the user to be able
10872 to reference this entity using either natural or linkage name,
10873 but we haven't started looking at this enhancement yet. */
10874 const char *linkage_name
= dw2_linkage_name (die
, cu
);
10876 if (linkage_name
!= NULL
)
10877 return linkage_name
;
10880 /* These are the only languages we know how to qualify names in. */
10882 && (cu
->language
== language_cplus
10883 || cu
->language
== language_fortran
|| cu
->language
== language_d
10884 || cu
->language
== language_rust
))
10886 if (die_needs_namespace (die
, cu
))
10888 const char *prefix
;
10889 const char *canonical_name
= NULL
;
10893 prefix
= determine_prefix (die
, cu
);
10894 if (*prefix
!= '\0')
10896 gdb::unique_xmalloc_ptr
<char> prefixed_name
10897 (typename_concat (NULL
, prefix
, name
, physname
, cu
));
10899 buf
.puts (prefixed_name
.get ());
10904 /* Template parameters may be specified in the DIE's DW_AT_name, or
10905 as children with DW_TAG_template_type_param or
10906 DW_TAG_value_type_param. If the latter, add them to the name
10907 here. If the name already has template parameters, then
10908 skip this step; some versions of GCC emit both, and
10909 it is more efficient to use the pre-computed name.
10911 Something to keep in mind about this process: it is very
10912 unlikely, or in some cases downright impossible, to produce
10913 something that will match the mangled name of a function.
10914 If the definition of the function has the same debug info,
10915 we should be able to match up with it anyway. But fallbacks
10916 using the minimal symbol, for instance to find a method
10917 implemented in a stripped copy of libstdc++, will not work.
10918 If we do not have debug info for the definition, we will have to
10919 match them up some other way.
10921 When we do name matching there is a related problem with function
10922 templates; two instantiated function templates are allowed to
10923 differ only by their return types, which we do not add here. */
10925 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
10927 struct attribute
*attr
;
10928 struct die_info
*child
;
10931 die
->building_fullname
= 1;
10933 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
10937 const gdb_byte
*bytes
;
10938 struct dwarf2_locexpr_baton
*baton
;
10941 if (child
->tag
!= DW_TAG_template_type_param
10942 && child
->tag
!= DW_TAG_template_value_param
)
10953 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
10956 complaint (_("template parameter missing DW_AT_type"));
10957 buf
.puts ("UNKNOWN_TYPE");
10960 type
= die_type (child
, cu
);
10962 if (child
->tag
== DW_TAG_template_type_param
)
10964 c_print_type (type
, "", &buf
, -1, 0, cu
->language
,
10965 &type_print_raw_options
);
10969 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
10972 complaint (_("template parameter missing "
10973 "DW_AT_const_value"));
10974 buf
.puts ("UNKNOWN_VALUE");
10978 dwarf2_const_value_attr (attr
, type
, name
,
10979 &cu
->comp_unit_obstack
, cu
,
10980 &value
, &bytes
, &baton
);
10982 if (TYPE_NOSIGN (type
))
10983 /* GDB prints characters as NUMBER 'CHAR'. If that's
10984 changed, this can use value_print instead. */
10985 c_printchar (value
, type
, &buf
);
10988 struct value_print_options opts
;
10991 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
10995 else if (bytes
!= NULL
)
10997 v
= allocate_value (type
);
10998 memcpy (value_contents_writeable (v
), bytes
,
10999 TYPE_LENGTH (type
));
11002 v
= value_from_longest (type
, value
);
11004 /* Specify decimal so that we do not depend on
11006 get_formatted_print_options (&opts
, 'd');
11008 value_print (v
, &buf
, &opts
);
11013 die
->building_fullname
= 0;
11017 /* Close the argument list, with a space if necessary
11018 (nested templates). */
11019 if (!buf
.empty () && buf
.string ().back () == '>')
11026 /* For C++ methods, append formal parameter type
11027 information, if PHYSNAME. */
11029 if (physname
&& die
->tag
== DW_TAG_subprogram
11030 && cu
->language
== language_cplus
)
11032 struct type
*type
= read_type_die (die
, cu
);
11034 c_type_print_args (type
, &buf
, 1, cu
->language
,
11035 &type_print_raw_options
);
11037 if (cu
->language
== language_cplus
)
11039 /* Assume that an artificial first parameter is
11040 "this", but do not crash if it is not. RealView
11041 marks unnamed (and thus unused) parameters as
11042 artificial; there is no way to differentiate
11044 if (TYPE_NFIELDS (type
) > 0
11045 && TYPE_FIELD_ARTIFICIAL (type
, 0)
11046 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
11047 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
11049 buf
.puts (" const");
11053 const std::string
&intermediate_name
= buf
.string ();
11055 if (cu
->language
== language_cplus
)
11057 = dwarf2_canonicalize_name (intermediate_name
.c_str (), cu
,
11058 &objfile
->per_bfd
->storage_obstack
);
11060 /* If we only computed INTERMEDIATE_NAME, or if
11061 INTERMEDIATE_NAME is already canonical, then we need to
11062 copy it to the appropriate obstack. */
11063 if (canonical_name
== NULL
|| canonical_name
== intermediate_name
.c_str ())
11064 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
11065 intermediate_name
);
11067 name
= canonical_name
;
11074 /* Return the fully qualified name of DIE, based on its DW_AT_name.
11075 If scope qualifiers are appropriate they will be added. The result
11076 will be allocated on the storage_obstack, or NULL if the DIE does
11077 not have a name. NAME may either be from a previous call to
11078 dwarf2_name or NULL.
11080 The output string will be canonicalized (if C++). */
11082 static const char *
11083 dwarf2_full_name (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11085 return dwarf2_compute_name (name
, die
, cu
, 0);
11088 /* Construct a physname for the given DIE in CU. NAME may either be
11089 from a previous call to dwarf2_name or NULL. The result will be
11090 allocated on the objfile_objstack or NULL if the DIE does not have a
11093 The output string will be canonicalized (if C++). */
11095 static const char *
11096 dwarf2_physname (const char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
11098 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11099 const char *retval
, *mangled
= NULL
, *canon
= NULL
;
11102 /* In this case dwarf2_compute_name is just a shortcut not building anything
11104 if (!die_needs_namespace (die
, cu
))
11105 return dwarf2_compute_name (name
, die
, cu
, 1);
11107 mangled
= dw2_linkage_name (die
, cu
);
11109 /* rustc emits invalid values for DW_AT_linkage_name. Ignore these.
11110 See https://github.com/rust-lang/rust/issues/32925. */
11111 if (cu
->language
== language_rust
&& mangled
!= NULL
11112 && strchr (mangled
, '{') != NULL
)
11115 /* DW_AT_linkage_name is missing in some cases - depend on what GDB
11117 gdb::unique_xmalloc_ptr
<char> demangled
;
11118 if (mangled
!= NULL
)
11121 if (language_def (cu
->language
)->la_store_sym_names_in_linkage_form_p
)
11123 /* Do nothing (do not demangle the symbol name). */
11125 else if (cu
->language
== language_go
)
11127 /* This is a lie, but we already lie to the caller new_symbol.
11128 new_symbol assumes we return the mangled name.
11129 This just undoes that lie until things are cleaned up. */
11133 /* Use DMGL_RET_DROP for C++ template functions to suppress
11134 their return type. It is easier for GDB users to search
11135 for such functions as `name(params)' than `long name(params)'.
11136 In such case the minimal symbol names do not match the full
11137 symbol names but for template functions there is never a need
11138 to look up their definition from their declaration so
11139 the only disadvantage remains the minimal symbol variant
11140 `long name(params)' does not have the proper inferior type. */
11141 demangled
.reset (gdb_demangle (mangled
,
11142 (DMGL_PARAMS
| DMGL_ANSI
11143 | DMGL_RET_DROP
)));
11146 canon
= demangled
.get ();
11154 if (canon
== NULL
|| check_physname
)
11156 const char *physname
= dwarf2_compute_name (name
, die
, cu
, 1);
11158 if (canon
!= NULL
&& strcmp (physname
, canon
) != 0)
11160 /* It may not mean a bug in GDB. The compiler could also
11161 compute DW_AT_linkage_name incorrectly. But in such case
11162 GDB would need to be bug-to-bug compatible. */
11164 complaint (_("Computed physname <%s> does not match demangled <%s> "
11165 "(from linkage <%s>) - DIE at %s [in module %s]"),
11166 physname
, canon
, mangled
, sect_offset_str (die
->sect_off
),
11167 objfile_name (objfile
));
11169 /* Prefer DW_AT_linkage_name (in the CANON form) - when it
11170 is available here - over computed PHYSNAME. It is safer
11171 against both buggy GDB and buggy compilers. */
11185 retval
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, retval
);
11190 /* Inspect DIE in CU for a namespace alias. If one exists, record
11191 a new symbol for it.
11193 Returns 1 if a namespace alias was recorded, 0 otherwise. */
11196 read_namespace_alias (struct die_info
*die
, struct dwarf2_cu
*cu
)
11198 struct attribute
*attr
;
11200 /* If the die does not have a name, this is not a namespace
11202 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11206 struct die_info
*d
= die
;
11207 struct dwarf2_cu
*imported_cu
= cu
;
11209 /* If the compiler has nested DW_AT_imported_declaration DIEs,
11210 keep inspecting DIEs until we hit the underlying import. */
11211 #define MAX_NESTED_IMPORTED_DECLARATIONS 100
11212 for (num
= 0; num
< MAX_NESTED_IMPORTED_DECLARATIONS
; ++num
)
11214 attr
= dwarf2_attr (d
, DW_AT_import
, cu
);
11218 d
= follow_die_ref (d
, attr
, &imported_cu
);
11219 if (d
->tag
!= DW_TAG_imported_declaration
)
11223 if (num
== MAX_NESTED_IMPORTED_DECLARATIONS
)
11225 complaint (_("DIE at %s has too many recursively imported "
11226 "declarations"), sect_offset_str (d
->sect_off
));
11233 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
11235 type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
11236 if (type
!= NULL
&& TYPE_CODE (type
) == TYPE_CODE_NAMESPACE
)
11238 /* This declaration is a global namespace alias. Add
11239 a symbol for it whose type is the aliased namespace. */
11240 new_symbol (die
, type
, cu
);
11249 /* Return the using directives repository (global or local?) to use in the
11250 current context for CU.
11252 For Ada, imported declarations can materialize renamings, which *may* be
11253 global. However it is impossible (for now?) in DWARF to distinguish
11254 "external" imported declarations and "static" ones. As all imported
11255 declarations seem to be static in all other languages, make them all CU-wide
11256 global only in Ada. */
11258 static struct using_direct
**
11259 using_directives (struct dwarf2_cu
*cu
)
11261 if (cu
->language
== language_ada
11262 && cu
->get_builder ()->outermost_context_p ())
11263 return cu
->get_builder ()->get_global_using_directives ();
11265 return cu
->get_builder ()->get_local_using_directives ();
11268 /* Read the import statement specified by the given die and record it. */
11271 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
11273 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
11274 struct attribute
*import_attr
;
11275 struct die_info
*imported_die
, *child_die
;
11276 struct dwarf2_cu
*imported_cu
;
11277 const char *imported_name
;
11278 const char *imported_name_prefix
;
11279 const char *canonical_name
;
11280 const char *import_alias
;
11281 const char *imported_declaration
= NULL
;
11282 const char *import_prefix
;
11283 std::vector
<const char *> excludes
;
11285 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
11286 if (import_attr
== NULL
)
11288 complaint (_("Tag '%s' has no DW_AT_import"),
11289 dwarf_tag_name (die
->tag
));
11294 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
11295 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11296 if (imported_name
== NULL
)
11298 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
11300 The import in the following code:
11314 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
11315 <52> DW_AT_decl_file : 1
11316 <53> DW_AT_decl_line : 6
11317 <54> DW_AT_import : <0x75>
11318 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
11319 <59> DW_AT_name : B
11320 <5b> DW_AT_decl_file : 1
11321 <5c> DW_AT_decl_line : 2
11322 <5d> DW_AT_type : <0x6e>
11324 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
11325 <76> DW_AT_byte_size : 4
11326 <77> DW_AT_encoding : 5 (signed)
11328 imports the wrong die ( 0x75 instead of 0x58 ).
11329 This case will be ignored until the gcc bug is fixed. */
11333 /* Figure out the local name after import. */
11334 import_alias
= dwarf2_name (die
, cu
);
11336 /* Figure out where the statement is being imported to. */
11337 import_prefix
= determine_prefix (die
, cu
);
11339 /* Figure out what the scope of the imported die is and prepend it
11340 to the name of the imported die. */
11341 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
11343 if (imported_die
->tag
!= DW_TAG_namespace
11344 && imported_die
->tag
!= DW_TAG_module
)
11346 imported_declaration
= imported_name
;
11347 canonical_name
= imported_name_prefix
;
11349 else if (strlen (imported_name_prefix
) > 0)
11350 canonical_name
= obconcat (&objfile
->objfile_obstack
,
11351 imported_name_prefix
,
11352 (cu
->language
== language_d
? "." : "::"),
11353 imported_name
, (char *) NULL
);
11355 canonical_name
= imported_name
;
11357 if (die
->tag
== DW_TAG_imported_module
&& cu
->language
== language_fortran
)
11358 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
11359 child_die
= sibling_die (child_die
))
11361 /* DWARF-4: A Fortran use statement with a “rename list” may be
11362 represented by an imported module entry with an import attribute
11363 referring to the module and owned entries corresponding to those
11364 entities that are renamed as part of being imported. */
11366 if (child_die
->tag
!= DW_TAG_imported_declaration
)
11368 complaint (_("child DW_TAG_imported_declaration expected "
11369 "- DIE at %s [in module %s]"),
11370 sect_offset_str (child_die
->sect_off
),
11371 objfile_name (objfile
));
11375 import_attr
= dwarf2_attr (child_die
, DW_AT_import
, cu
);
11376 if (import_attr
== NULL
)
11378 complaint (_("Tag '%s' has no DW_AT_import"),
11379 dwarf_tag_name (child_die
->tag
));
11384 imported_die
= follow_die_ref_or_sig (child_die
, import_attr
,
11386 imported_name
= dwarf2_name (imported_die
, imported_cu
);
11387 if (imported_name
== NULL
)
11389 complaint (_("child DW_TAG_imported_declaration has unknown "
11390 "imported name - DIE at %s [in module %s]"),
11391 sect_offset_str (child_die
->sect_off
),
11392 objfile_name (objfile
));
11396 excludes
.push_back (imported_name
);
11398 process_die (child_die
, cu
);
11401 add_using_directive (using_directives (cu
),
11405 imported_declaration
,
11408 &objfile
->objfile_obstack
);
11411 /* ICC<14 does not output the required DW_AT_declaration on incomplete
11412 types, but gives them a size of zero. Starting with version 14,
11413 ICC is compatible with GCC. */
11416 producer_is_icc_lt_14 (struct dwarf2_cu
*cu
)
11418 if (!cu
->checked_producer
)
11419 check_producer (cu
);
11421 return cu
->producer_is_icc_lt_14
;
11424 /* ICC generates a DW_AT_type for C void functions. This was observed on
11425 ICC 14.0.5.212, and appears to be against the DWARF spec (V5 3.3.2)
11426 which says that void functions should not have a DW_AT_type. */
11429 producer_is_icc (struct dwarf2_cu
*cu
)
11431 if (!cu
->checked_producer
)
11432 check_producer (cu
);
11434 return cu
->producer_is_icc
;
11437 /* Check for possibly missing DW_AT_comp_dir with relative .debug_line
11438 directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed
11439 this, it was first present in GCC release 4.3.0. */
11442 producer_is_gcc_lt_4_3 (struct dwarf2_cu
*cu
)
11444 if (!cu
->checked_producer
)
11445 check_producer (cu
);
11447 return cu
->producer_is_gcc_lt_4_3
;
11450 static file_and_directory
11451 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
)
11453 file_and_directory res
;
11455 /* Find the filename. Do not use dwarf2_name here, since the filename
11456 is not a source language identifier. */
11457 res
.name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
11458 res
.comp_dir
= dwarf2_string_attr (die
, DW_AT_comp_dir
, cu
);
11460 if (res
.comp_dir
== NULL
11461 && producer_is_gcc_lt_4_3 (cu
) && res
.name
!= NULL
11462 && IS_ABSOLUTE_PATH (res
.name
))
11464 res
.comp_dir_storage
= ldirname (res
.name
);
11465 if (!res
.comp_dir_storage
.empty ())
11466 res
.comp_dir
= res
.comp_dir_storage
.c_str ();
11468 if (res
.comp_dir
!= NULL
)
11470 /* Irix 6.2 native cc prepends <machine>.: to the compilation
11471 directory, get rid of it. */
11472 const char *cp
= strchr (res
.comp_dir
, ':');
11474 if (cp
&& cp
!= res
.comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
11475 res
.comp_dir
= cp
+ 1;
11478 if (res
.name
== NULL
)
11479 res
.name
= "<unknown>";
11484 /* Handle DW_AT_stmt_list for a compilation unit.
11485 DIE is the DW_TAG_compile_unit die for CU.
11486 COMP_DIR is the compilation directory. LOWPC is passed to
11487 dwarf_decode_lines. See dwarf_decode_lines comments about it. */
11490 handle_DW_AT_stmt_list (struct die_info
*die
, struct dwarf2_cu
*cu
,
11491 const char *comp_dir
, CORE_ADDR lowpc
) /* ARI: editCase function */
11493 struct dwarf2_per_objfile
*dwarf2_per_objfile
11494 = cu
->per_cu
->dwarf2_per_objfile
;
11495 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11496 struct attribute
*attr
;
11497 struct line_header line_header_local
;
11498 hashval_t line_header_local_hash
;
11500 int decode_mapping
;
11502 gdb_assert (! cu
->per_cu
->is_debug_types
);
11504 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
11508 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11510 /* The line header hash table is only created if needed (it exists to
11511 prevent redundant reading of the line table for partial_units).
11512 If we're given a partial_unit, we'll need it. If we're given a
11513 compile_unit, then use the line header hash table if it's already
11514 created, but don't create one just yet. */
11516 if (dwarf2_per_objfile
->line_header_hash
== NULL
11517 && die
->tag
== DW_TAG_partial_unit
)
11519 dwarf2_per_objfile
->line_header_hash
11520 = htab_create_alloc_ex (127, line_header_hash_voidp
,
11521 line_header_eq_voidp
,
11522 free_line_header_voidp
,
11523 &objfile
->objfile_obstack
,
11524 hashtab_obstack_allocate
,
11525 dummy_obstack_deallocate
);
11528 line_header_local
.sect_off
= line_offset
;
11529 line_header_local
.offset_in_dwz
= cu
->per_cu
->is_dwz
;
11530 line_header_local_hash
= line_header_hash (&line_header_local
);
11531 if (dwarf2_per_objfile
->line_header_hash
!= NULL
)
11533 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11534 &line_header_local
,
11535 line_header_local_hash
, NO_INSERT
);
11537 /* For DW_TAG_compile_unit we need info like symtab::linetable which
11538 is not present in *SLOT (since if there is something in *SLOT then
11539 it will be for a partial_unit). */
11540 if (die
->tag
== DW_TAG_partial_unit
&& slot
!= NULL
)
11542 gdb_assert (*slot
!= NULL
);
11543 cu
->line_header
= (struct line_header
*) *slot
;
11548 /* dwarf_decode_line_header does not yet provide sufficient information.
11549 We always have to call also dwarf_decode_lines for it. */
11550 line_header_up lh
= dwarf_decode_line_header (line_offset
, cu
);
11554 cu
->line_header
= lh
.release ();
11555 cu
->line_header_die_owner
= die
;
11557 if (dwarf2_per_objfile
->line_header_hash
== NULL
)
11561 slot
= htab_find_slot_with_hash (dwarf2_per_objfile
->line_header_hash
,
11562 &line_header_local
,
11563 line_header_local_hash
, INSERT
);
11564 gdb_assert (slot
!= NULL
);
11566 if (slot
!= NULL
&& *slot
== NULL
)
11568 /* This newly decoded line number information unit will be owned
11569 by line_header_hash hash table. */
11570 *slot
= cu
->line_header
;
11571 cu
->line_header_die_owner
= NULL
;
11575 /* We cannot free any current entry in (*slot) as that struct line_header
11576 may be already used by multiple CUs. Create only temporary decoded
11577 line_header for this CU - it may happen at most once for each line
11578 number information unit. And if we're not using line_header_hash
11579 then this is what we want as well. */
11580 gdb_assert (die
->tag
!= DW_TAG_partial_unit
);
11582 decode_mapping
= (die
->tag
!= DW_TAG_partial_unit
);
11583 dwarf_decode_lines (cu
->line_header
, comp_dir
, cu
, NULL
, lowpc
,
11588 /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */
11591 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11593 struct dwarf2_per_objfile
*dwarf2_per_objfile
11594 = cu
->per_cu
->dwarf2_per_objfile
;
11595 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11596 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
11597 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
11598 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
11599 struct attribute
*attr
;
11600 struct die_info
*child_die
;
11601 CORE_ADDR baseaddr
;
11603 prepare_one_comp_unit (cu
, die
, cu
->language
);
11604 baseaddr
= objfile
->text_section_offset ();
11606 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
11608 /* If we didn't find a lowpc, set it to highpc to avoid complaints
11609 from finish_block. */
11610 if (lowpc
== ((CORE_ADDR
) -1))
11612 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
11614 file_and_directory fnd
= find_file_and_directory (die
, cu
);
11616 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
11617 standardised yet. As a workaround for the language detection we fall
11618 back to the DW_AT_producer string. */
11619 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
11620 cu
->language
= language_opencl
;
11622 /* Similar hack for Go. */
11623 if (cu
->producer
&& strstr (cu
->producer
, "GNU Go ") != NULL
)
11624 set_cu_language (DW_LANG_Go
, cu
);
11626 cu
->start_symtab (fnd
.name
, fnd
.comp_dir
, lowpc
);
11628 /* Decode line number information if present. We do this before
11629 processing child DIEs, so that the line header table is available
11630 for DW_AT_decl_file. */
11631 handle_DW_AT_stmt_list (die
, cu
, fnd
.comp_dir
, lowpc
);
11633 /* Process all dies in compilation unit. */
11634 if (die
->child
!= NULL
)
11636 child_die
= die
->child
;
11637 while (child_die
&& child_die
->tag
)
11639 process_die (child_die
, cu
);
11640 child_die
= sibling_die (child_die
);
11644 /* Decode macro information, if present. Dwarf 2 macro information
11645 refers to information in the line number info statement program
11646 header, so we can only read it if we've read the header
11648 attr
= dwarf2_attr (die
, DW_AT_macros
, cu
);
11650 attr
= dwarf2_attr (die
, DW_AT_GNU_macros
, cu
);
11651 if (attr
&& cu
->line_header
)
11653 if (dwarf2_attr (die
, DW_AT_macro_info
, cu
))
11654 complaint (_("CU refers to both DW_AT_macros and DW_AT_macro_info"));
11656 dwarf_decode_macros (cu
, DW_UNSND (attr
), 1);
11660 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
11661 if (attr
&& cu
->line_header
)
11663 unsigned int macro_offset
= DW_UNSND (attr
);
11665 dwarf_decode_macros (cu
, macro_offset
, 0);
11671 dwarf2_cu::setup_type_unit_groups (struct die_info
*die
)
11673 struct type_unit_group
*tu_group
;
11675 struct attribute
*attr
;
11677 struct signatured_type
*sig_type
;
11679 gdb_assert (per_cu
->is_debug_types
);
11680 sig_type
= (struct signatured_type
*) per_cu
;
11682 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, this);
11684 /* If we're using .gdb_index (includes -readnow) then
11685 per_cu->type_unit_group may not have been set up yet. */
11686 if (sig_type
->type_unit_group
== NULL
)
11687 sig_type
->type_unit_group
= get_type_unit_group (this, attr
);
11688 tu_group
= sig_type
->type_unit_group
;
11690 /* If we've already processed this stmt_list there's no real need to
11691 do it again, we could fake it and just recreate the part we need
11692 (file name,index -> symtab mapping). If data shows this optimization
11693 is useful we can do it then. */
11694 first_time
= tu_group
->compunit_symtab
== NULL
;
11696 /* We have to handle the case of both a missing DW_AT_stmt_list or bad
11701 sect_offset line_offset
= (sect_offset
) DW_UNSND (attr
);
11702 lh
= dwarf_decode_line_header (line_offset
, this);
11707 start_symtab ("", NULL
, 0);
11710 gdb_assert (tu_group
->symtabs
== NULL
);
11711 gdb_assert (m_builder
== nullptr);
11712 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11713 m_builder
.reset (new struct buildsym_compunit
11714 (COMPUNIT_OBJFILE (cust
), "",
11715 COMPUNIT_DIRNAME (cust
),
11716 compunit_language (cust
),
11722 line_header
= lh
.release ();
11723 line_header_die_owner
= die
;
11727 struct compunit_symtab
*cust
= start_symtab ("", NULL
, 0);
11729 /* Note: We don't assign tu_group->compunit_symtab yet because we're
11730 still initializing it, and our caller (a few levels up)
11731 process_full_type_unit still needs to know if this is the first
11734 tu_group
->num_symtabs
= line_header
->file_names_size ();
11735 tu_group
->symtabs
= XNEWVEC (struct symtab
*,
11736 line_header
->file_names_size ());
11738 auto &file_names
= line_header
->file_names ();
11739 for (i
= 0; i
< file_names
.size (); ++i
)
11741 file_entry
&fe
= file_names
[i
];
11742 dwarf2_start_subfile (this, fe
.name
,
11743 fe
.include_dir (line_header
));
11744 buildsym_compunit
*b
= get_builder ();
11745 if (b
->get_current_subfile ()->symtab
== NULL
)
11747 /* NOTE: start_subfile will recognize when it's been
11748 passed a file it has already seen. So we can't
11749 assume there's a simple mapping from
11750 cu->line_header->file_names to subfiles, plus
11751 cu->line_header->file_names may contain dups. */
11752 b
->get_current_subfile ()->symtab
11753 = allocate_symtab (cust
, b
->get_current_subfile ()->name
);
11756 fe
.symtab
= b
->get_current_subfile ()->symtab
;
11757 tu_group
->symtabs
[i
] = fe
.symtab
;
11762 gdb_assert (m_builder
== nullptr);
11763 struct compunit_symtab
*cust
= tu_group
->compunit_symtab
;
11764 m_builder
.reset (new struct buildsym_compunit
11765 (COMPUNIT_OBJFILE (cust
), "",
11766 COMPUNIT_DIRNAME (cust
),
11767 compunit_language (cust
),
11770 auto &file_names
= line_header
->file_names ();
11771 for (i
= 0; i
< file_names
.size (); ++i
)
11773 file_entry
&fe
= file_names
[i
];
11774 fe
.symtab
= tu_group
->symtabs
[i
];
11778 /* The main symtab is allocated last. Type units don't have DW_AT_name
11779 so they don't have a "real" (so to speak) symtab anyway.
11780 There is later code that will assign the main symtab to all symbols
11781 that don't have one. We need to handle the case of a symbol with a
11782 missing symtab (DW_AT_decl_file) anyway. */
11785 /* Process DW_TAG_type_unit.
11786 For TUs we want to skip the first top level sibling if it's not the
11787 actual type being defined by this TU. In this case the first top
11788 level sibling is there to provide context only. */
11791 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
11793 struct die_info
*child_die
;
11795 prepare_one_comp_unit (cu
, die
, language_minimal
);
11797 /* Initialize (or reinitialize) the machinery for building symtabs.
11798 We do this before processing child DIEs, so that the line header table
11799 is available for DW_AT_decl_file. */
11800 cu
->setup_type_unit_groups (die
);
11802 if (die
->child
!= NULL
)
11804 child_die
= die
->child
;
11805 while (child_die
&& child_die
->tag
)
11807 process_die (child_die
, cu
);
11808 child_die
= sibling_die (child_die
);
11815 http://gcc.gnu.org/wiki/DebugFission
11816 http://gcc.gnu.org/wiki/DebugFissionDWP
11818 To simplify handling of both DWO files ("object" files with the DWARF info)
11819 and DWP files (a file with the DWOs packaged up into one file), we treat
11820 DWP files as having a collection of virtual DWO files. */
11823 hash_dwo_file (const void *item
)
11825 const struct dwo_file
*dwo_file
= (const struct dwo_file
*) item
;
11828 hash
= htab_hash_string (dwo_file
->dwo_name
);
11829 if (dwo_file
->comp_dir
!= NULL
)
11830 hash
+= htab_hash_string (dwo_file
->comp_dir
);
11835 eq_dwo_file (const void *item_lhs
, const void *item_rhs
)
11837 const struct dwo_file
*lhs
= (const struct dwo_file
*) item_lhs
;
11838 const struct dwo_file
*rhs
= (const struct dwo_file
*) item_rhs
;
11840 if (strcmp (lhs
->dwo_name
, rhs
->dwo_name
) != 0)
11842 if (lhs
->comp_dir
== NULL
|| rhs
->comp_dir
== NULL
)
11843 return lhs
->comp_dir
== rhs
->comp_dir
;
11844 return strcmp (lhs
->comp_dir
, rhs
->comp_dir
) == 0;
11847 /* Allocate a hash table for DWO files. */
11850 allocate_dwo_file_hash_table (struct objfile
*objfile
)
11852 auto delete_dwo_file
= [] (void *item
)
11854 struct dwo_file
*dwo_file
= (struct dwo_file
*) item
;
11859 return htab_up (htab_create_alloc_ex (41,
11863 &objfile
->objfile_obstack
,
11864 hashtab_obstack_allocate
,
11865 dummy_obstack_deallocate
));
11868 /* Lookup DWO file DWO_NAME. */
11871 lookup_dwo_file_slot (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11872 const char *dwo_name
,
11873 const char *comp_dir
)
11875 struct dwo_file find_entry
;
11878 if (dwarf2_per_objfile
->dwo_files
== NULL
)
11879 dwarf2_per_objfile
->dwo_files
11880 = allocate_dwo_file_hash_table (dwarf2_per_objfile
->objfile
);
11882 find_entry
.dwo_name
= dwo_name
;
11883 find_entry
.comp_dir
= comp_dir
;
11884 slot
= htab_find_slot (dwarf2_per_objfile
->dwo_files
.get (), &find_entry
,
11891 hash_dwo_unit (const void *item
)
11893 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
11895 /* This drops the top 32 bits of the id, but is ok for a hash. */
11896 return dwo_unit
->signature
;
11900 eq_dwo_unit (const void *item_lhs
, const void *item_rhs
)
11902 const struct dwo_unit
*lhs
= (const struct dwo_unit
*) item_lhs
;
11903 const struct dwo_unit
*rhs
= (const struct dwo_unit
*) item_rhs
;
11905 /* The signature is assumed to be unique within the DWO file.
11906 So while object file CU dwo_id's always have the value zero,
11907 that's OK, assuming each object file DWO file has only one CU,
11908 and that's the rule for now. */
11909 return lhs
->signature
== rhs
->signature
;
11912 /* Allocate a hash table for DWO CUs,TUs.
11913 There is one of these tables for each of CUs,TUs for each DWO file. */
11916 allocate_dwo_unit_table (struct objfile
*objfile
)
11918 /* Start out with a pretty small number.
11919 Generally DWO files contain only one CU and maybe some TUs. */
11920 return htab_create_alloc_ex (3,
11924 &objfile
->objfile_obstack
,
11925 hashtab_obstack_allocate
,
11926 dummy_obstack_deallocate
);
11929 /* die_reader_func for create_dwo_cu. */
11932 create_dwo_cu_reader (const struct die_reader_specs
*reader
,
11933 const gdb_byte
*info_ptr
,
11934 struct die_info
*comp_unit_die
,
11936 struct dwo_file
*dwo_file
,
11937 struct dwo_unit
*dwo_unit
)
11939 struct dwarf2_cu
*cu
= reader
->cu
;
11940 sect_offset sect_off
= cu
->per_cu
->sect_off
;
11941 struct dwarf2_section_info
*section
= cu
->per_cu
->section
;
11943 gdb::optional
<ULONGEST
> signature
= lookup_dwo_id (cu
, comp_unit_die
);
11944 if (!signature
.has_value ())
11946 complaint (_("Dwarf Error: debug entry at offset %s is missing"
11947 " its dwo_id [in module %s]"),
11948 sect_offset_str (sect_off
), dwo_file
->dwo_name
);
11952 dwo_unit
->dwo_file
= dwo_file
;
11953 dwo_unit
->signature
= *signature
;
11954 dwo_unit
->section
= section
;
11955 dwo_unit
->sect_off
= sect_off
;
11956 dwo_unit
->length
= cu
->per_cu
->length
;
11958 if (dwarf_read_debug
)
11959 fprintf_unfiltered (gdb_stdlog
, " offset %s, dwo_id %s\n",
11960 sect_offset_str (sect_off
),
11961 hex_string (dwo_unit
->signature
));
11964 /* Create the dwo_units for the CUs in a DWO_FILE.
11965 Note: This function processes DWO files only, not DWP files. */
11968 create_cus_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
11969 dwarf2_cu
*cu
, struct dwo_file
&dwo_file
,
11970 dwarf2_section_info
§ion
, htab_t
&cus_htab
)
11972 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
11973 const gdb_byte
*info_ptr
, *end_ptr
;
11975 dwarf2_read_section (objfile
, §ion
);
11976 info_ptr
= section
.buffer
;
11978 if (info_ptr
== NULL
)
11981 if (dwarf_read_debug
)
11983 fprintf_unfiltered (gdb_stdlog
, "Reading %s for %s:\n",
11984 get_section_name (§ion
),
11985 get_section_file_name (§ion
));
11988 end_ptr
= info_ptr
+ section
.size
;
11989 while (info_ptr
< end_ptr
)
11991 struct dwarf2_per_cu_data per_cu
;
11992 struct dwo_unit read_unit
{};
11993 struct dwo_unit
*dwo_unit
;
11995 sect_offset sect_off
= (sect_offset
) (info_ptr
- section
.buffer
);
11997 memset (&per_cu
, 0, sizeof (per_cu
));
11998 per_cu
.dwarf2_per_objfile
= dwarf2_per_objfile
;
11999 per_cu
.is_debug_types
= 0;
12000 per_cu
.sect_off
= sect_offset (info_ptr
- section
.buffer
);
12001 per_cu
.section
= §ion
;
12003 cutu_reader
reader (&per_cu
, cu
, &dwo_file
);
12004 if (!reader
.dummy_p
)
12005 create_dwo_cu_reader (&reader
, reader
.info_ptr
, reader
.comp_unit_die
,
12006 reader
.has_children
, &dwo_file
, &read_unit
);
12007 info_ptr
+= per_cu
.length
;
12009 // If the unit could not be parsed, skip it.
12010 if (read_unit
.dwo_file
== NULL
)
12013 if (cus_htab
== NULL
)
12014 cus_htab
= allocate_dwo_unit_table (objfile
);
12016 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12017 *dwo_unit
= read_unit
;
12018 slot
= htab_find_slot (cus_htab
, dwo_unit
, INSERT
);
12019 gdb_assert (slot
!= NULL
);
12022 const struct dwo_unit
*dup_cu
= (const struct dwo_unit
*)*slot
;
12023 sect_offset dup_sect_off
= dup_cu
->sect_off
;
12025 complaint (_("debug cu entry at offset %s is duplicate to"
12026 " the entry at offset %s, signature %s"),
12027 sect_offset_str (sect_off
), sect_offset_str (dup_sect_off
),
12028 hex_string (dwo_unit
->signature
));
12030 *slot
= (void *)dwo_unit
;
12034 /* DWP file .debug_{cu,tu}_index section format:
12035 [ref: http://gcc.gnu.org/wiki/DebugFissionDWP]
12039 Both index sections have the same format, and serve to map a 64-bit
12040 signature to a set of section numbers. Each section begins with a header,
12041 followed by a hash table of 64-bit signatures, a parallel table of 32-bit
12042 indexes, and a pool of 32-bit section numbers. The index sections will be
12043 aligned at 8-byte boundaries in the file.
12045 The index section header consists of:
12047 V, 32 bit version number
12049 N, 32 bit number of compilation units or type units in the index
12050 M, 32 bit number of slots in the hash table
12052 Numbers are recorded using the byte order of the application binary.
12054 The hash table begins at offset 16 in the section, and consists of an array
12055 of M 64-bit slots. Each slot contains a 64-bit signature (using the byte
12056 order of the application binary). Unused slots in the hash table are 0.
12057 (We rely on the extreme unlikeliness of a signature being exactly 0.)
12059 The parallel table begins immediately after the hash table
12060 (at offset 16 + 8 * M from the beginning of the section), and consists of an
12061 array of 32-bit indexes (using the byte order of the application binary),
12062 corresponding 1-1 with slots in the hash table. Each entry in the parallel
12063 table contains a 32-bit index into the pool of section numbers. For unused
12064 hash table slots, the corresponding entry in the parallel table will be 0.
12066 The pool of section numbers begins immediately following the hash table
12067 (at offset 16 + 12 * M from the beginning of the section). The pool of
12068 section numbers consists of an array of 32-bit words (using the byte order
12069 of the application binary). Each item in the array is indexed starting
12070 from 0. The hash table entry provides the index of the first section
12071 number in the set. Additional section numbers in the set follow, and the
12072 set is terminated by a 0 entry (section number 0 is not used in ELF).
12074 In each set of section numbers, the .debug_info.dwo or .debug_types.dwo
12075 section must be the first entry in the set, and the .debug_abbrev.dwo must
12076 be the second entry. Other members of the set may follow in any order.
12082 DWP Version 2 combines all the .debug_info, etc. sections into one,
12083 and the entries in the index tables are now offsets into these sections.
12084 CU offsets begin at 0. TU offsets begin at the size of the .debug_info
12087 Index Section Contents:
12089 Hash Table of Signatures dwp_hash_table.hash_table
12090 Parallel Table of Indices dwp_hash_table.unit_table
12091 Table of Section Offsets dwp_hash_table.v2.{section_ids,offsets}
12092 Table of Section Sizes dwp_hash_table.v2.sizes
12094 The index section header consists of:
12096 V, 32 bit version number
12097 L, 32 bit number of columns in the table of section offsets
12098 N, 32 bit number of compilation units or type units in the index
12099 M, 32 bit number of slots in the hash table
12101 Numbers are recorded using the byte order of the application binary.
12103 The hash table has the same format as version 1.
12104 The parallel table of indices has the same format as version 1,
12105 except that the entries are origin-1 indices into the table of sections
12106 offsets and the table of section sizes.
12108 The table of offsets begins immediately following the parallel table
12109 (at offset 16 + 12 * M from the beginning of the section). The table is
12110 a two-dimensional array of 32-bit words (using the byte order of the
12111 application binary), with L columns and N+1 rows, in row-major order.
12112 Each row in the array is indexed starting from 0. The first row provides
12113 a key to the remaining rows: each column in this row provides an identifier
12114 for a debug section, and the offsets in the same column of subsequent rows
12115 refer to that section. The section identifiers are:
12117 DW_SECT_INFO 1 .debug_info.dwo
12118 DW_SECT_TYPES 2 .debug_types.dwo
12119 DW_SECT_ABBREV 3 .debug_abbrev.dwo
12120 DW_SECT_LINE 4 .debug_line.dwo
12121 DW_SECT_LOC 5 .debug_loc.dwo
12122 DW_SECT_STR_OFFSETS 6 .debug_str_offsets.dwo
12123 DW_SECT_MACINFO 7 .debug_macinfo.dwo
12124 DW_SECT_MACRO 8 .debug_macro.dwo
12126 The offsets provided by the CU and TU index sections are the base offsets
12127 for the contributions made by each CU or TU to the corresponding section
12128 in the package file. Each CU and TU header contains an abbrev_offset
12129 field, used to find the abbreviations table for that CU or TU within the
12130 contribution to the .debug_abbrev.dwo section for that CU or TU, and should
12131 be interpreted as relative to the base offset given in the index section.
12132 Likewise, offsets into .debug_line.dwo from DW_AT_stmt_list attributes
12133 should be interpreted as relative to the base offset for .debug_line.dwo,
12134 and offsets into other debug sections obtained from DWARF attributes should
12135 also be interpreted as relative to the corresponding base offset.
12137 The table of sizes begins immediately following the table of offsets.
12138 Like the table of offsets, it is a two-dimensional array of 32-bit words,
12139 with L columns and N rows, in row-major order. Each row in the array is
12140 indexed starting from 1 (row 0 is shared by the two tables).
12144 Hash table lookup is handled the same in version 1 and 2:
12146 We assume that N and M will not exceed 2^32 - 1.
12147 The size of the hash table, M, must be 2^k such that 2^k > 3*N/2.
12149 Given a 64-bit compilation unit signature or a type signature S, an entry
12150 in the hash table is located as follows:
12152 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with
12153 the low-order k bits all set to 1.
12155 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1).
12157 3) If the hash table entry at index H matches the signature, use that
12158 entry. If the hash table entry at index H is unused (all zeroes),
12159 terminate the search: the signature is not present in the table.
12161 4) Let H = (H + H') modulo M. Repeat at Step 3.
12163 Because M > N and H' and M are relatively prime, the search is guaranteed
12164 to stop at an unused slot or find the match. */
12166 /* Create a hash table to map DWO IDs to their CU/TU entry in
12167 .debug_{info,types}.dwo in DWP_FILE.
12168 Returns NULL if there isn't one.
12169 Note: This function processes DWP files only, not DWO files. */
12171 static struct dwp_hash_table
*
12172 create_dwp_hash_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12173 struct dwp_file
*dwp_file
, int is_debug_types
)
12175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12176 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12177 const gdb_byte
*index_ptr
, *index_end
;
12178 struct dwarf2_section_info
*index
;
12179 uint32_t version
, nr_columns
, nr_units
, nr_slots
;
12180 struct dwp_hash_table
*htab
;
12182 if (is_debug_types
)
12183 index
= &dwp_file
->sections
.tu_index
;
12185 index
= &dwp_file
->sections
.cu_index
;
12187 if (dwarf2_section_empty_p (index
))
12189 dwarf2_read_section (objfile
, index
);
12191 index_ptr
= index
->buffer
;
12192 index_end
= index_ptr
+ index
->size
;
12194 version
= read_4_bytes (dbfd
, index_ptr
);
12197 nr_columns
= read_4_bytes (dbfd
, index_ptr
);
12201 nr_units
= read_4_bytes (dbfd
, index_ptr
);
12203 nr_slots
= read_4_bytes (dbfd
, index_ptr
);
12206 if (version
!= 1 && version
!= 2)
12208 error (_("Dwarf Error: unsupported DWP file version (%s)"
12209 " [in module %s]"),
12210 pulongest (version
), dwp_file
->name
);
12212 if (nr_slots
!= (nr_slots
& -nr_slots
))
12214 error (_("Dwarf Error: number of slots in DWP hash table (%s)"
12215 " is not power of 2 [in module %s]"),
12216 pulongest (nr_slots
), dwp_file
->name
);
12219 htab
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwp_hash_table
);
12220 htab
->version
= version
;
12221 htab
->nr_columns
= nr_columns
;
12222 htab
->nr_units
= nr_units
;
12223 htab
->nr_slots
= nr_slots
;
12224 htab
->hash_table
= index_ptr
;
12225 htab
->unit_table
= htab
->hash_table
+ sizeof (uint64_t) * nr_slots
;
12227 /* Exit early if the table is empty. */
12228 if (nr_slots
== 0 || nr_units
== 0
12229 || (version
== 2 && nr_columns
== 0))
12231 /* All must be zero. */
12232 if (nr_slots
!= 0 || nr_units
!= 0
12233 || (version
== 2 && nr_columns
!= 0))
12235 complaint (_("Empty DWP but nr_slots,nr_units,nr_columns not"
12236 " all zero [in modules %s]"),
12244 htab
->section_pool
.v1
.indices
=
12245 htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12246 /* It's harder to decide whether the section is too small in v1.
12247 V1 is deprecated anyway so we punt. */
12251 const gdb_byte
*ids_ptr
= htab
->unit_table
+ sizeof (uint32_t) * nr_slots
;
12252 int *ids
= htab
->section_pool
.v2
.section_ids
;
12253 size_t sizeof_ids
= sizeof (htab
->section_pool
.v2
.section_ids
);
12254 /* Reverse map for error checking. */
12255 int ids_seen
[DW_SECT_MAX
+ 1];
12258 if (nr_columns
< 2)
12260 error (_("Dwarf Error: bad DWP hash table, too few columns"
12261 " in section table [in module %s]"),
12264 if (nr_columns
> MAX_NR_V2_DWO_SECTIONS
)
12266 error (_("Dwarf Error: bad DWP hash table, too many columns"
12267 " in section table [in module %s]"),
12270 memset (ids
, 255, sizeof_ids
);
12271 memset (ids_seen
, 255, sizeof (ids_seen
));
12272 for (i
= 0; i
< nr_columns
; ++i
)
12274 int id
= read_4_bytes (dbfd
, ids_ptr
+ i
* sizeof (uint32_t));
12276 if (id
< DW_SECT_MIN
|| id
> DW_SECT_MAX
)
12278 error (_("Dwarf Error: bad DWP hash table, bad section id %d"
12279 " in section table [in module %s]"),
12280 id
, dwp_file
->name
);
12282 if (ids_seen
[id
] != -1)
12284 error (_("Dwarf Error: bad DWP hash table, duplicate section"
12285 " id %d in section table [in module %s]"),
12286 id
, dwp_file
->name
);
12291 /* Must have exactly one info or types section. */
12292 if (((ids_seen
[DW_SECT_INFO
] != -1)
12293 + (ids_seen
[DW_SECT_TYPES
] != -1))
12296 error (_("Dwarf Error: bad DWP hash table, missing/duplicate"
12297 " DWO info/types section [in module %s]"),
12300 /* Must have an abbrev section. */
12301 if (ids_seen
[DW_SECT_ABBREV
] == -1)
12303 error (_("Dwarf Error: bad DWP hash table, missing DWO abbrev"
12304 " section [in module %s]"),
12307 htab
->section_pool
.v2
.offsets
= ids_ptr
+ sizeof (uint32_t) * nr_columns
;
12308 htab
->section_pool
.v2
.sizes
=
12309 htab
->section_pool
.v2
.offsets
+ (sizeof (uint32_t)
12310 * nr_units
* nr_columns
);
12311 if ((htab
->section_pool
.v2
.sizes
+ (sizeof (uint32_t)
12312 * nr_units
* nr_columns
))
12315 error (_("Dwarf Error: DWP index section is corrupt (too small)"
12316 " [in module %s]"),
12324 /* Update SECTIONS with the data from SECTP.
12326 This function is like the other "locate" section routines that are
12327 passed to bfd_map_over_sections, but in this context the sections to
12328 read comes from the DWP V1 hash table, not the full ELF section table.
12330 The result is non-zero for success, or zero if an error was found. */
12333 locate_v1_virtual_dwo_sections (asection
*sectp
,
12334 struct virtual_v1_dwo_sections
*sections
)
12336 const struct dwop_section_names
*names
= &dwop_section_names
;
12338 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12340 /* There can be only one. */
12341 if (sections
->abbrev
.s
.section
!= NULL
)
12343 sections
->abbrev
.s
.section
= sectp
;
12344 sections
->abbrev
.size
= bfd_section_size (sectp
);
12346 else if (section_is_p (sectp
->name
, &names
->info_dwo
)
12347 || section_is_p (sectp
->name
, &names
->types_dwo
))
12349 /* There can be only one. */
12350 if (sections
->info_or_types
.s
.section
!= NULL
)
12352 sections
->info_or_types
.s
.section
= sectp
;
12353 sections
->info_or_types
.size
= bfd_section_size (sectp
);
12355 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12357 /* There can be only one. */
12358 if (sections
->line
.s
.section
!= NULL
)
12360 sections
->line
.s
.section
= sectp
;
12361 sections
->line
.size
= bfd_section_size (sectp
);
12363 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12365 /* There can be only one. */
12366 if (sections
->loc
.s
.section
!= NULL
)
12368 sections
->loc
.s
.section
= sectp
;
12369 sections
->loc
.size
= bfd_section_size (sectp
);
12371 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12373 /* There can be only one. */
12374 if (sections
->macinfo
.s
.section
!= NULL
)
12376 sections
->macinfo
.s
.section
= sectp
;
12377 sections
->macinfo
.size
= bfd_section_size (sectp
);
12379 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12381 /* There can be only one. */
12382 if (sections
->macro
.s
.section
!= NULL
)
12384 sections
->macro
.s
.section
= sectp
;
12385 sections
->macro
.size
= bfd_section_size (sectp
);
12387 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12389 /* There can be only one. */
12390 if (sections
->str_offsets
.s
.section
!= NULL
)
12392 sections
->str_offsets
.s
.section
= sectp
;
12393 sections
->str_offsets
.size
= bfd_section_size (sectp
);
12397 /* No other kind of section is valid. */
12404 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12405 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12406 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12407 This is for DWP version 1 files. */
12409 static struct dwo_unit
*
12410 create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12411 struct dwp_file
*dwp_file
,
12412 uint32_t unit_index
,
12413 const char *comp_dir
,
12414 ULONGEST signature
, int is_debug_types
)
12416 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12417 const struct dwp_hash_table
*dwp_htab
=
12418 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12419 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12420 const char *kind
= is_debug_types
? "TU" : "CU";
12421 struct dwo_file
*dwo_file
;
12422 struct dwo_unit
*dwo_unit
;
12423 struct virtual_v1_dwo_sections sections
;
12424 void **dwo_file_slot
;
12427 gdb_assert (dwp_file
->version
== 1);
12429 if (dwarf_read_debug
)
12431 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V1 file: %s\n",
12433 pulongest (unit_index
), hex_string (signature
),
12437 /* Fetch the sections of this DWO unit.
12438 Put a limit on the number of sections we look for so that bad data
12439 doesn't cause us to loop forever. */
12441 #define MAX_NR_V1_DWO_SECTIONS \
12442 (1 /* .debug_info or .debug_types */ \
12443 + 1 /* .debug_abbrev */ \
12444 + 1 /* .debug_line */ \
12445 + 1 /* .debug_loc */ \
12446 + 1 /* .debug_str_offsets */ \
12447 + 1 /* .debug_macro or .debug_macinfo */ \
12448 + 1 /* trailing zero */)
12450 memset (§ions
, 0, sizeof (sections
));
12452 for (i
= 0; i
< MAX_NR_V1_DWO_SECTIONS
; ++i
)
12455 uint32_t section_nr
=
12456 read_4_bytes (dbfd
,
12457 dwp_htab
->section_pool
.v1
.indices
12458 + (unit_index
+ i
) * sizeof (uint32_t));
12460 if (section_nr
== 0)
12462 if (section_nr
>= dwp_file
->num_sections
)
12464 error (_("Dwarf Error: bad DWP hash table, section number too large"
12465 " [in module %s]"),
12469 sectp
= dwp_file
->elf_sections
[section_nr
];
12470 if (! locate_v1_virtual_dwo_sections (sectp
, §ions
))
12472 error (_("Dwarf Error: bad DWP hash table, invalid section found"
12473 " [in module %s]"),
12479 || dwarf2_section_empty_p (§ions
.info_or_types
)
12480 || dwarf2_section_empty_p (§ions
.abbrev
))
12482 error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
12483 " [in module %s]"),
12486 if (i
== MAX_NR_V1_DWO_SECTIONS
)
12488 error (_("Dwarf Error: bad DWP hash table, too many DWO sections"
12489 " [in module %s]"),
12493 /* It's easier for the rest of the code if we fake a struct dwo_file and
12494 have dwo_unit "live" in that. At least for now.
12496 The DWP file can be made up of a random collection of CUs and TUs.
12497 However, for each CU + set of TUs that came from the same original DWO
12498 file, we can combine them back into a virtual DWO file to save space
12499 (fewer struct dwo_file objects to allocate). Remember that for really
12500 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12502 std::string virtual_dwo_name
=
12503 string_printf ("virtual-dwo/%d-%d-%d-%d",
12504 get_section_id (§ions
.abbrev
),
12505 get_section_id (§ions
.line
),
12506 get_section_id (§ions
.loc
),
12507 get_section_id (§ions
.str_offsets
));
12508 /* Can we use an existing virtual DWO file? */
12509 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12510 virtual_dwo_name
.c_str (),
12512 /* Create one if necessary. */
12513 if (*dwo_file_slot
== NULL
)
12515 if (dwarf_read_debug
)
12517 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12518 virtual_dwo_name
.c_str ());
12520 dwo_file
= new struct dwo_file
;
12521 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12523 dwo_file
->comp_dir
= comp_dir
;
12524 dwo_file
->sections
.abbrev
= sections
.abbrev
;
12525 dwo_file
->sections
.line
= sections
.line
;
12526 dwo_file
->sections
.loc
= sections
.loc
;
12527 dwo_file
->sections
.macinfo
= sections
.macinfo
;
12528 dwo_file
->sections
.macro
= sections
.macro
;
12529 dwo_file
->sections
.str_offsets
= sections
.str_offsets
;
12530 /* The "str" section is global to the entire DWP file. */
12531 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12532 /* The info or types section is assigned below to dwo_unit,
12533 there's no need to record it in dwo_file.
12534 Also, we can't simply record type sections in dwo_file because
12535 we record a pointer into the vector in dwo_unit. As we collect more
12536 types we'll grow the vector and eventually have to reallocate space
12537 for it, invalidating all copies of pointers into the previous
12539 *dwo_file_slot
= dwo_file
;
12543 if (dwarf_read_debug
)
12545 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12546 virtual_dwo_name
.c_str ());
12548 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12551 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12552 dwo_unit
->dwo_file
= dwo_file
;
12553 dwo_unit
->signature
= signature
;
12554 dwo_unit
->section
=
12555 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12556 *dwo_unit
->section
= sections
.info_or_types
;
12557 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12562 /* Subroutine of create_dwo_unit_in_dwp_v2 to simplify it.
12563 Given a pointer to the containing section SECTION, and OFFSET,SIZE of the
12564 piece within that section used by a TU/CU, return a virtual section
12565 of just that piece. */
12567 static struct dwarf2_section_info
12568 create_dwp_v2_section (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12569 struct dwarf2_section_info
*section
,
12570 bfd_size_type offset
, bfd_size_type size
)
12572 struct dwarf2_section_info result
;
12575 gdb_assert (section
!= NULL
);
12576 gdb_assert (!section
->is_virtual
);
12578 memset (&result
, 0, sizeof (result
));
12579 result
.s
.containing_section
= section
;
12580 result
.is_virtual
= true;
12585 sectp
= get_section_bfd_section (section
);
12587 /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
12588 bounds of the real section. This is a pretty-rare event, so just
12589 flag an error (easier) instead of a warning and trying to cope. */
12591 || offset
+ size
> bfd_section_size (sectp
))
12593 error (_("Dwarf Error: Bad DWP V2 section info, doesn't fit"
12594 " in section %s [in module %s]"),
12595 sectp
? bfd_section_name (sectp
) : "<unknown>",
12596 objfile_name (dwarf2_per_objfile
->objfile
));
12599 result
.virtual_offset
= offset
;
12600 result
.size
= size
;
12604 /* Create a dwo_unit object for the DWO unit with signature SIGNATURE.
12605 UNIT_INDEX is the index of the DWO unit in the DWP hash table.
12606 COMP_DIR is the DW_AT_comp_dir attribute of the referencing CU.
12607 This is for DWP version 2 files. */
12609 static struct dwo_unit
*
12610 create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12611 struct dwp_file
*dwp_file
,
12612 uint32_t unit_index
,
12613 const char *comp_dir
,
12614 ULONGEST signature
, int is_debug_types
)
12616 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
12617 const struct dwp_hash_table
*dwp_htab
=
12618 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12619 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12620 const char *kind
= is_debug_types
? "TU" : "CU";
12621 struct dwo_file
*dwo_file
;
12622 struct dwo_unit
*dwo_unit
;
12623 struct virtual_v2_dwo_sections sections
;
12624 void **dwo_file_slot
;
12627 gdb_assert (dwp_file
->version
== 2);
12629 if (dwarf_read_debug
)
12631 fprintf_unfiltered (gdb_stdlog
, "Reading %s %s/%s in DWP V2 file: %s\n",
12633 pulongest (unit_index
), hex_string (signature
),
12637 /* Fetch the section offsets of this DWO unit. */
12639 memset (§ions
, 0, sizeof (sections
));
12641 for (i
= 0; i
< dwp_htab
->nr_columns
; ++i
)
12643 uint32_t offset
= read_4_bytes (dbfd
,
12644 dwp_htab
->section_pool
.v2
.offsets
12645 + (((unit_index
- 1) * dwp_htab
->nr_columns
12647 * sizeof (uint32_t)));
12648 uint32_t size
= read_4_bytes (dbfd
,
12649 dwp_htab
->section_pool
.v2
.sizes
12650 + (((unit_index
- 1) * dwp_htab
->nr_columns
12652 * sizeof (uint32_t)));
12654 switch (dwp_htab
->section_pool
.v2
.section_ids
[i
])
12657 case DW_SECT_TYPES
:
12658 sections
.info_or_types_offset
= offset
;
12659 sections
.info_or_types_size
= size
;
12661 case DW_SECT_ABBREV
:
12662 sections
.abbrev_offset
= offset
;
12663 sections
.abbrev_size
= size
;
12666 sections
.line_offset
= offset
;
12667 sections
.line_size
= size
;
12670 sections
.loc_offset
= offset
;
12671 sections
.loc_size
= size
;
12673 case DW_SECT_STR_OFFSETS
:
12674 sections
.str_offsets_offset
= offset
;
12675 sections
.str_offsets_size
= size
;
12677 case DW_SECT_MACINFO
:
12678 sections
.macinfo_offset
= offset
;
12679 sections
.macinfo_size
= size
;
12681 case DW_SECT_MACRO
:
12682 sections
.macro_offset
= offset
;
12683 sections
.macro_size
= size
;
12688 /* It's easier for the rest of the code if we fake a struct dwo_file and
12689 have dwo_unit "live" in that. At least for now.
12691 The DWP file can be made up of a random collection of CUs and TUs.
12692 However, for each CU + set of TUs that came from the same original DWO
12693 file, we can combine them back into a virtual DWO file to save space
12694 (fewer struct dwo_file objects to allocate). Remember that for really
12695 large apps there can be on the order of 8K CUs and 200K TUs, or more. */
12697 std::string virtual_dwo_name
=
12698 string_printf ("virtual-dwo/%ld-%ld-%ld-%ld",
12699 (long) (sections
.abbrev_size
? sections
.abbrev_offset
: 0),
12700 (long) (sections
.line_size
? sections
.line_offset
: 0),
12701 (long) (sections
.loc_size
? sections
.loc_offset
: 0),
12702 (long) (sections
.str_offsets_size
12703 ? sections
.str_offsets_offset
: 0));
12704 /* Can we use an existing virtual DWO file? */
12705 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
12706 virtual_dwo_name
.c_str (),
12708 /* Create one if necessary. */
12709 if (*dwo_file_slot
== NULL
)
12711 if (dwarf_read_debug
)
12713 fprintf_unfiltered (gdb_stdlog
, "Creating virtual DWO: %s\n",
12714 virtual_dwo_name
.c_str ());
12716 dwo_file
= new struct dwo_file
;
12717 dwo_file
->dwo_name
= obstack_strdup (&objfile
->objfile_obstack
,
12719 dwo_file
->comp_dir
= comp_dir
;
12720 dwo_file
->sections
.abbrev
=
12721 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.abbrev
,
12722 sections
.abbrev_offset
, sections
.abbrev_size
);
12723 dwo_file
->sections
.line
=
12724 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.line
,
12725 sections
.line_offset
, sections
.line_size
);
12726 dwo_file
->sections
.loc
=
12727 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.loc
,
12728 sections
.loc_offset
, sections
.loc_size
);
12729 dwo_file
->sections
.macinfo
=
12730 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macinfo
,
12731 sections
.macinfo_offset
, sections
.macinfo_size
);
12732 dwo_file
->sections
.macro
=
12733 create_dwp_v2_section (dwarf2_per_objfile
, &dwp_file
->sections
.macro
,
12734 sections
.macro_offset
, sections
.macro_size
);
12735 dwo_file
->sections
.str_offsets
=
12736 create_dwp_v2_section (dwarf2_per_objfile
,
12737 &dwp_file
->sections
.str_offsets
,
12738 sections
.str_offsets_offset
,
12739 sections
.str_offsets_size
);
12740 /* The "str" section is global to the entire DWP file. */
12741 dwo_file
->sections
.str
= dwp_file
->sections
.str
;
12742 /* The info or types section is assigned below to dwo_unit,
12743 there's no need to record it in dwo_file.
12744 Also, we can't simply record type sections in dwo_file because
12745 we record a pointer into the vector in dwo_unit. As we collect more
12746 types we'll grow the vector and eventually have to reallocate space
12747 for it, invalidating all copies of pointers into the previous
12749 *dwo_file_slot
= dwo_file
;
12753 if (dwarf_read_debug
)
12755 fprintf_unfiltered (gdb_stdlog
, "Using existing virtual DWO: %s\n",
12756 virtual_dwo_name
.c_str ());
12758 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
12761 dwo_unit
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct dwo_unit
);
12762 dwo_unit
->dwo_file
= dwo_file
;
12763 dwo_unit
->signature
= signature
;
12764 dwo_unit
->section
=
12765 XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_section_info
);
12766 *dwo_unit
->section
= create_dwp_v2_section (dwarf2_per_objfile
,
12768 ? &dwp_file
->sections
.types
12769 : &dwp_file
->sections
.info
,
12770 sections
.info_or_types_offset
,
12771 sections
.info_or_types_size
);
12772 /* dwo_unit->{offset,length,type_offset_in_tu} are set later. */
12777 /* Lookup the DWO unit with SIGNATURE in DWP_FILE.
12778 Returns NULL if the signature isn't found. */
12780 static struct dwo_unit
*
12781 lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12782 struct dwp_file
*dwp_file
, const char *comp_dir
,
12783 ULONGEST signature
, int is_debug_types
)
12785 const struct dwp_hash_table
*dwp_htab
=
12786 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
12787 bfd
*dbfd
= dwp_file
->dbfd
.get ();
12788 uint32_t mask
= dwp_htab
->nr_slots
- 1;
12789 uint32_t hash
= signature
& mask
;
12790 uint32_t hash2
= ((signature
>> 32) & mask
) | 1;
12793 struct dwo_unit find_dwo_cu
;
12795 memset (&find_dwo_cu
, 0, sizeof (find_dwo_cu
));
12796 find_dwo_cu
.signature
= signature
;
12797 slot
= htab_find_slot (is_debug_types
12798 ? dwp_file
->loaded_tus
12799 : dwp_file
->loaded_cus
,
12800 &find_dwo_cu
, INSERT
);
12803 return (struct dwo_unit
*) *slot
;
12805 /* Use a for loop so that we don't loop forever on bad debug info. */
12806 for (i
= 0; i
< dwp_htab
->nr_slots
; ++i
)
12808 ULONGEST signature_in_table
;
12810 signature_in_table
=
12811 read_8_bytes (dbfd
, dwp_htab
->hash_table
+ hash
* sizeof (uint64_t));
12812 if (signature_in_table
== signature
)
12814 uint32_t unit_index
=
12815 read_4_bytes (dbfd
,
12816 dwp_htab
->unit_table
+ hash
* sizeof (uint32_t));
12818 if (dwp_file
->version
== 1)
12820 *slot
= create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile
,
12821 dwp_file
, unit_index
,
12822 comp_dir
, signature
,
12827 *slot
= create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile
,
12828 dwp_file
, unit_index
,
12829 comp_dir
, signature
,
12832 return (struct dwo_unit
*) *slot
;
12834 if (signature_in_table
== 0)
12836 hash
= (hash
+ hash2
) & mask
;
12839 error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate"
12840 " [in module %s]"),
12844 /* Subroutine of open_dwo_file,open_dwp_file to simplify them.
12845 Open the file specified by FILE_NAME and hand it off to BFD for
12846 preliminary analysis. Return a newly initialized bfd *, which
12847 includes a canonicalized copy of FILE_NAME.
12848 If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file.
12849 SEARCH_CWD is true if the current directory is to be searched.
12850 It will be searched before debug-file-directory.
12851 If successful, the file is added to the bfd include table of the
12852 objfile's bfd (see gdb_bfd_record_inclusion).
12853 If unable to find/open the file, return NULL.
12854 NOTE: This function is derived from symfile_bfd_open. */
12856 static gdb_bfd_ref_ptr
12857 try_open_dwop_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12858 const char *file_name
, int is_dwp
, int search_cwd
)
12861 /* Blech. OPF_TRY_CWD_FIRST also disables searching the path list if
12862 FILE_NAME contains a '/'. So we can't use it. Instead prepend "."
12863 to debug_file_directory. */
12864 const char *search_path
;
12865 static const char dirname_separator_string
[] = { DIRNAME_SEPARATOR
, '\0' };
12867 gdb::unique_xmalloc_ptr
<char> search_path_holder
;
12870 if (*debug_file_directory
!= '\0')
12872 search_path_holder
.reset (concat (".", dirname_separator_string
,
12873 debug_file_directory
,
12875 search_path
= search_path_holder
.get ();
12881 search_path
= debug_file_directory
;
12883 openp_flags flags
= OPF_RETURN_REALPATH
;
12885 flags
|= OPF_SEARCH_IN_PATH
;
12887 gdb::unique_xmalloc_ptr
<char> absolute_name
;
12888 desc
= openp (search_path
, flags
, file_name
,
12889 O_RDONLY
| O_BINARY
, &absolute_name
);
12893 gdb_bfd_ref_ptr
sym_bfd (gdb_bfd_open (absolute_name
.get (),
12895 if (sym_bfd
== NULL
)
12897 bfd_set_cacheable (sym_bfd
.get (), 1);
12899 if (!bfd_check_format (sym_bfd
.get (), bfd_object
))
12902 /* Success. Record the bfd as having been included by the objfile's bfd.
12903 This is important because things like demangled_names_hash lives in the
12904 objfile's per_bfd space and may have references to things like symbol
12905 names that live in the DWO/DWP file's per_bfd space. PR 16426. */
12906 gdb_bfd_record_inclusion (dwarf2_per_objfile
->objfile
->obfd
, sym_bfd
.get ());
12911 /* Try to open DWO file FILE_NAME.
12912 COMP_DIR is the DW_AT_comp_dir attribute.
12913 The result is the bfd handle of the file.
12914 If there is a problem finding or opening the file, return NULL.
12915 Upon success, the canonicalized path of the file is stored in the bfd,
12916 same as symfile_bfd_open. */
12918 static gdb_bfd_ref_ptr
12919 open_dwo_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
12920 const char *file_name
, const char *comp_dir
)
12922 if (IS_ABSOLUTE_PATH (file_name
))
12923 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12924 0 /*is_dwp*/, 0 /*search_cwd*/);
12926 /* Before trying the search path, try DWO_NAME in COMP_DIR. */
12928 if (comp_dir
!= NULL
)
12930 gdb::unique_xmalloc_ptr
<char> path_to_try
12931 (concat (comp_dir
, SLASH_STRING
, file_name
, (char *) NULL
));
12933 /* NOTE: If comp_dir is a relative path, this will also try the
12934 search path, which seems useful. */
12935 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
,
12936 path_to_try
.get (),
12938 1 /*search_cwd*/));
12943 /* That didn't work, try debug-file-directory, which, despite its name,
12944 is a list of paths. */
12946 if (*debug_file_directory
== '\0')
12949 return try_open_dwop_file (dwarf2_per_objfile
, file_name
,
12950 0 /*is_dwp*/, 1 /*search_cwd*/);
12953 /* This function is mapped across the sections and remembers the offset and
12954 size of each of the DWO debugging sections we are interested in. */
12957 dwarf2_locate_dwo_sections (bfd
*abfd
, asection
*sectp
, void *dwo_sections_ptr
)
12959 struct dwo_sections
*dwo_sections
= (struct dwo_sections
*) dwo_sections_ptr
;
12960 const struct dwop_section_names
*names
= &dwop_section_names
;
12962 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
12964 dwo_sections
->abbrev
.s
.section
= sectp
;
12965 dwo_sections
->abbrev
.size
= bfd_section_size (sectp
);
12967 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
12969 dwo_sections
->info
.s
.section
= sectp
;
12970 dwo_sections
->info
.size
= bfd_section_size (sectp
);
12972 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
12974 dwo_sections
->line
.s
.section
= sectp
;
12975 dwo_sections
->line
.size
= bfd_section_size (sectp
);
12977 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
12979 dwo_sections
->loc
.s
.section
= sectp
;
12980 dwo_sections
->loc
.size
= bfd_section_size (sectp
);
12982 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
12984 dwo_sections
->macinfo
.s
.section
= sectp
;
12985 dwo_sections
->macinfo
.size
= bfd_section_size (sectp
);
12987 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
12989 dwo_sections
->macro
.s
.section
= sectp
;
12990 dwo_sections
->macro
.size
= bfd_section_size (sectp
);
12992 else if (section_is_p (sectp
->name
, &names
->str_dwo
))
12994 dwo_sections
->str
.s
.section
= sectp
;
12995 dwo_sections
->str
.size
= bfd_section_size (sectp
);
12997 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
12999 dwo_sections
->str_offsets
.s
.section
= sectp
;
13000 dwo_sections
->str_offsets
.size
= bfd_section_size (sectp
);
13002 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13004 struct dwarf2_section_info type_section
;
13006 memset (&type_section
, 0, sizeof (type_section
));
13007 type_section
.s
.section
= sectp
;
13008 type_section
.size
= bfd_section_size (sectp
);
13009 dwo_sections
->types
.push_back (type_section
);
13013 /* Initialize the use of the DWO file specified by DWO_NAME and referenced
13014 by PER_CU. This is for the non-DWP case.
13015 The result is NULL if DWO_NAME can't be found. */
13017 static struct dwo_file
*
13018 open_and_init_dwo_file (struct dwarf2_per_cu_data
*per_cu
,
13019 const char *dwo_name
, const char *comp_dir
)
13021 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
13023 gdb_bfd_ref_ptr dbfd
= open_dwo_file (dwarf2_per_objfile
, dwo_name
, comp_dir
);
13026 if (dwarf_read_debug
)
13027 fprintf_unfiltered (gdb_stdlog
, "DWO file not found: %s\n", dwo_name
);
13031 dwo_file_up
dwo_file (new struct dwo_file
);
13032 dwo_file
->dwo_name
= dwo_name
;
13033 dwo_file
->comp_dir
= comp_dir
;
13034 dwo_file
->dbfd
= std::move (dbfd
);
13036 bfd_map_over_sections (dwo_file
->dbfd
.get (), dwarf2_locate_dwo_sections
,
13037 &dwo_file
->sections
);
13039 create_cus_hash_table (dwarf2_per_objfile
, per_cu
->cu
, *dwo_file
,
13040 dwo_file
->sections
.info
, dwo_file
->cus
);
13042 create_debug_types_hash_table (dwarf2_per_objfile
, dwo_file
.get (),
13043 dwo_file
->sections
.types
, dwo_file
->tus
);
13045 if (dwarf_read_debug
)
13046 fprintf_unfiltered (gdb_stdlog
, "DWO file found: %s\n", dwo_name
);
13048 return dwo_file
.release ();
13051 /* This function is mapped across the sections and remembers the offset and
13052 size of each of the DWP debugging sections common to version 1 and 2 that
13053 we are interested in. */
13056 dwarf2_locate_common_dwp_sections (bfd
*abfd
, asection
*sectp
,
13057 void *dwp_file_ptr
)
13059 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13060 const struct dwop_section_names
*names
= &dwop_section_names
;
13061 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13063 /* Record the ELF section number for later lookup: this is what the
13064 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13065 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13066 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13068 /* Look for specific sections that we need. */
13069 if (section_is_p (sectp
->name
, &names
->str_dwo
))
13071 dwp_file
->sections
.str
.s
.section
= sectp
;
13072 dwp_file
->sections
.str
.size
= bfd_section_size (sectp
);
13074 else if (section_is_p (sectp
->name
, &names
->cu_index
))
13076 dwp_file
->sections
.cu_index
.s
.section
= sectp
;
13077 dwp_file
->sections
.cu_index
.size
= bfd_section_size (sectp
);
13079 else if (section_is_p (sectp
->name
, &names
->tu_index
))
13081 dwp_file
->sections
.tu_index
.s
.section
= sectp
;
13082 dwp_file
->sections
.tu_index
.size
= bfd_section_size (sectp
);
13086 /* This function is mapped across the sections and remembers the offset and
13087 size of each of the DWP version 2 debugging sections that we are interested
13088 in. This is split into a separate function because we don't know if we
13089 have version 1 or 2 until we parse the cu_index/tu_index sections. */
13092 dwarf2_locate_v2_dwp_sections (bfd
*abfd
, asection
*sectp
, void *dwp_file_ptr
)
13094 struct dwp_file
*dwp_file
= (struct dwp_file
*) dwp_file_ptr
;
13095 const struct dwop_section_names
*names
= &dwop_section_names
;
13096 unsigned int elf_section_nr
= elf_section_data (sectp
)->this_idx
;
13098 /* Record the ELF section number for later lookup: this is what the
13099 .debug_cu_index,.debug_tu_index tables use in DWP V1. */
13100 gdb_assert (elf_section_nr
< dwp_file
->num_sections
);
13101 dwp_file
->elf_sections
[elf_section_nr
] = sectp
;
13103 /* Look for specific sections that we need. */
13104 if (section_is_p (sectp
->name
, &names
->abbrev_dwo
))
13106 dwp_file
->sections
.abbrev
.s
.section
= sectp
;
13107 dwp_file
->sections
.abbrev
.size
= bfd_section_size (sectp
);
13109 else if (section_is_p (sectp
->name
, &names
->info_dwo
))
13111 dwp_file
->sections
.info
.s
.section
= sectp
;
13112 dwp_file
->sections
.info
.size
= bfd_section_size (sectp
);
13114 else if (section_is_p (sectp
->name
, &names
->line_dwo
))
13116 dwp_file
->sections
.line
.s
.section
= sectp
;
13117 dwp_file
->sections
.line
.size
= bfd_section_size (sectp
);
13119 else if (section_is_p (sectp
->name
, &names
->loc_dwo
))
13121 dwp_file
->sections
.loc
.s
.section
= sectp
;
13122 dwp_file
->sections
.loc
.size
= bfd_section_size (sectp
);
13124 else if (section_is_p (sectp
->name
, &names
->macinfo_dwo
))
13126 dwp_file
->sections
.macinfo
.s
.section
= sectp
;
13127 dwp_file
->sections
.macinfo
.size
= bfd_section_size (sectp
);
13129 else if (section_is_p (sectp
->name
, &names
->macro_dwo
))
13131 dwp_file
->sections
.macro
.s
.section
= sectp
;
13132 dwp_file
->sections
.macro
.size
= bfd_section_size (sectp
);
13134 else if (section_is_p (sectp
->name
, &names
->str_offsets_dwo
))
13136 dwp_file
->sections
.str_offsets
.s
.section
= sectp
;
13137 dwp_file
->sections
.str_offsets
.size
= bfd_section_size (sectp
);
13139 else if (section_is_p (sectp
->name
, &names
->types_dwo
))
13141 dwp_file
->sections
.types
.s
.section
= sectp
;
13142 dwp_file
->sections
.types
.size
= bfd_section_size (sectp
);
13146 /* Hash function for dwp_file loaded CUs/TUs. */
13149 hash_dwp_loaded_cutus (const void *item
)
13151 const struct dwo_unit
*dwo_unit
= (const struct dwo_unit
*) item
;
13153 /* This drops the top 32 bits of the signature, but is ok for a hash. */
13154 return dwo_unit
->signature
;
13157 /* Equality function for dwp_file loaded CUs/TUs. */
13160 eq_dwp_loaded_cutus (const void *a
, const void *b
)
13162 const struct dwo_unit
*dua
= (const struct dwo_unit
*) a
;
13163 const struct dwo_unit
*dub
= (const struct dwo_unit
*) b
;
13165 return dua
->signature
== dub
->signature
;
13168 /* Allocate a hash table for dwp_file loaded CUs/TUs. */
13171 allocate_dwp_loaded_cutus_table (struct objfile
*objfile
)
13173 return htab_create_alloc_ex (3,
13174 hash_dwp_loaded_cutus
,
13175 eq_dwp_loaded_cutus
,
13177 &objfile
->objfile_obstack
,
13178 hashtab_obstack_allocate
,
13179 dummy_obstack_deallocate
);
13182 /* Try to open DWP file FILE_NAME.
13183 The result is the bfd handle of the file.
13184 If there is a problem finding or opening the file, return NULL.
13185 Upon success, the canonicalized path of the file is stored in the bfd,
13186 same as symfile_bfd_open. */
13188 static gdb_bfd_ref_ptr
13189 open_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
13190 const char *file_name
)
13192 gdb_bfd_ref_ptr
abfd (try_open_dwop_file (dwarf2_per_objfile
, file_name
,
13194 1 /*search_cwd*/));
13198 /* Work around upstream bug 15652.
13199 http://sourceware.org/bugzilla/show_bug.cgi?id=15652
13200 [Whether that's a "bug" is debatable, but it is getting in our way.]
13201 We have no real idea where the dwp file is, because gdb's realpath-ing
13202 of the executable's path may have discarded the needed info.
13203 [IWBN if the dwp file name was recorded in the executable, akin to
13204 .gnu_debuglink, but that doesn't exist yet.]
13205 Strip the directory from FILE_NAME and search again. */
13206 if (*debug_file_directory
!= '\0')
13208 /* Don't implicitly search the current directory here.
13209 If the user wants to search "." to handle this case,
13210 it must be added to debug-file-directory. */
13211 return try_open_dwop_file (dwarf2_per_objfile
,
13212 lbasename (file_name
), 1 /*is_dwp*/,
13219 /* Initialize the use of the DWP file for the current objfile.
13220 By convention the name of the DWP file is ${objfile}.dwp.
13221 The result is NULL if it can't be found. */
13223 static std::unique_ptr
<struct dwp_file
>
13224 open_and_init_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13226 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13228 /* Try to find first .dwp for the binary file before any symbolic links
13231 /* If the objfile is a debug file, find the name of the real binary
13232 file and get the name of dwp file from there. */
13233 std::string dwp_name
;
13234 if (objfile
->separate_debug_objfile_backlink
!= NULL
)
13236 struct objfile
*backlink
= objfile
->separate_debug_objfile_backlink
;
13237 const char *backlink_basename
= lbasename (backlink
->original_name
);
13239 dwp_name
= ldirname (objfile
->original_name
) + SLASH_STRING
+ backlink_basename
;
13242 dwp_name
= objfile
->original_name
;
13244 dwp_name
+= ".dwp";
13246 gdb_bfd_ref_ptr
dbfd (open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ()));
13248 && strcmp (objfile
->original_name
, objfile_name (objfile
)) != 0)
13250 /* Try to find .dwp for the binary file after gdb_realpath resolving. */
13251 dwp_name
= objfile_name (objfile
);
13252 dwp_name
+= ".dwp";
13253 dbfd
= open_dwp_file (dwarf2_per_objfile
, dwp_name
.c_str ());
13258 if (dwarf_read_debug
)
13259 fprintf_unfiltered (gdb_stdlog
, "DWP file not found: %s\n", dwp_name
.c_str ());
13260 return std::unique_ptr
<dwp_file
> ();
13263 const char *name
= bfd_get_filename (dbfd
.get ());
13264 std::unique_ptr
<struct dwp_file
> dwp_file
13265 (new struct dwp_file (name
, std::move (dbfd
)));
13267 dwp_file
->num_sections
= elf_numsections (dwp_file
->dbfd
);
13268 dwp_file
->elf_sections
=
13269 OBSTACK_CALLOC (&objfile
->objfile_obstack
,
13270 dwp_file
->num_sections
, asection
*);
13272 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13273 dwarf2_locate_common_dwp_sections
,
13276 dwp_file
->cus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13279 dwp_file
->tus
= create_dwp_hash_table (dwarf2_per_objfile
, dwp_file
.get (),
13282 /* The DWP file version is stored in the hash table. Oh well. */
13283 if (dwp_file
->cus
&& dwp_file
->tus
13284 && dwp_file
->cus
->version
!= dwp_file
->tus
->version
)
13286 /* Technically speaking, we should try to limp along, but this is
13287 pretty bizarre. We use pulongest here because that's the established
13288 portability solution (e.g, we cannot use %u for uint32_t). */
13289 error (_("Dwarf Error: DWP file CU version %s doesn't match"
13290 " TU version %s [in DWP file %s]"),
13291 pulongest (dwp_file
->cus
->version
),
13292 pulongest (dwp_file
->tus
->version
), dwp_name
.c_str ());
13296 dwp_file
->version
= dwp_file
->cus
->version
;
13297 else if (dwp_file
->tus
)
13298 dwp_file
->version
= dwp_file
->tus
->version
;
13300 dwp_file
->version
= 2;
13302 if (dwp_file
->version
== 2)
13303 bfd_map_over_sections (dwp_file
->dbfd
.get (),
13304 dwarf2_locate_v2_dwp_sections
,
13307 dwp_file
->loaded_cus
= allocate_dwp_loaded_cutus_table (objfile
);
13308 dwp_file
->loaded_tus
= allocate_dwp_loaded_cutus_table (objfile
);
13310 if (dwarf_read_debug
)
13312 fprintf_unfiltered (gdb_stdlog
, "DWP file found: %s\n", dwp_file
->name
);
13313 fprintf_unfiltered (gdb_stdlog
,
13314 " %s CUs, %s TUs\n",
13315 pulongest (dwp_file
->cus
? dwp_file
->cus
->nr_units
: 0),
13316 pulongest (dwp_file
->tus
? dwp_file
->tus
->nr_units
: 0));
13322 /* Wrapper around open_and_init_dwp_file, only open it once. */
13324 static struct dwp_file
*
13325 get_dwp_file (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
13327 if (! dwarf2_per_objfile
->dwp_checked
)
13329 dwarf2_per_objfile
->dwp_file
13330 = open_and_init_dwp_file (dwarf2_per_objfile
);
13331 dwarf2_per_objfile
->dwp_checked
= 1;
13333 return dwarf2_per_objfile
->dwp_file
.get ();
13336 /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit.
13337 Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME
13338 or in the DWP file for the objfile, referenced by THIS_UNIT.
13339 If non-NULL, comp_dir is the DW_AT_comp_dir attribute.
13340 IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU.
13342 This is called, for example, when wanting to read a variable with a
13343 complex location. Therefore we don't want to do file i/o for every call.
13344 Therefore we don't want to look for a DWO file on every call.
13345 Therefore we first see if we've already seen SIGNATURE in a DWP file,
13346 then we check if we've already seen DWO_NAME, and only THEN do we check
13349 The result is a pointer to the dwo_unit object or NULL if we didn't find it
13350 (dwo_id mismatch or couldn't find the DWO/DWP file). */
13352 static struct dwo_unit
*
13353 lookup_dwo_cutu (struct dwarf2_per_cu_data
*this_unit
,
13354 const char *dwo_name
, const char *comp_dir
,
13355 ULONGEST signature
, int is_debug_types
)
13357 struct dwarf2_per_objfile
*dwarf2_per_objfile
= this_unit
->dwarf2_per_objfile
;
13358 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
13359 const char *kind
= is_debug_types
? "TU" : "CU";
13360 void **dwo_file_slot
;
13361 struct dwo_file
*dwo_file
;
13362 struct dwp_file
*dwp_file
;
13364 /* First see if there's a DWP file.
13365 If we have a DWP file but didn't find the DWO inside it, don't
13366 look for the original DWO file. It makes gdb behave differently
13367 depending on whether one is debugging in the build tree. */
13369 dwp_file
= get_dwp_file (dwarf2_per_objfile
);
13370 if (dwp_file
!= NULL
)
13372 const struct dwp_hash_table
*dwp_htab
=
13373 is_debug_types
? dwp_file
->tus
: dwp_file
->cus
;
13375 if (dwp_htab
!= NULL
)
13377 struct dwo_unit
*dwo_cutu
=
13378 lookup_dwo_unit_in_dwp (dwarf2_per_objfile
, dwp_file
, comp_dir
,
13379 signature
, is_debug_types
);
13381 if (dwo_cutu
!= NULL
)
13383 if (dwarf_read_debug
)
13385 fprintf_unfiltered (gdb_stdlog
,
13386 "Virtual DWO %s %s found: @%s\n",
13387 kind
, hex_string (signature
),
13388 host_address_to_string (dwo_cutu
));
13396 /* No DWP file, look for the DWO file. */
13398 dwo_file_slot
= lookup_dwo_file_slot (dwarf2_per_objfile
,
13399 dwo_name
, comp_dir
);
13400 if (*dwo_file_slot
== NULL
)
13402 /* Read in the file and build a table of the CUs/TUs it contains. */
13403 *dwo_file_slot
= open_and_init_dwo_file (this_unit
, dwo_name
, comp_dir
);
13405 /* NOTE: This will be NULL if unable to open the file. */
13406 dwo_file
= (struct dwo_file
*) *dwo_file_slot
;
13408 if (dwo_file
!= NULL
)
13410 struct dwo_unit
*dwo_cutu
= NULL
;
13412 if (is_debug_types
&& dwo_file
->tus
)
13414 struct dwo_unit find_dwo_cutu
;
13416 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13417 find_dwo_cutu
.signature
= signature
;
13419 = (struct dwo_unit
*) htab_find (dwo_file
->tus
, &find_dwo_cutu
);
13421 else if (!is_debug_types
&& dwo_file
->cus
)
13423 struct dwo_unit find_dwo_cutu
;
13425 memset (&find_dwo_cutu
, 0, sizeof (find_dwo_cutu
));
13426 find_dwo_cutu
.signature
= signature
;
13427 dwo_cutu
= (struct dwo_unit
*)htab_find (dwo_file
->cus
,
13431 if (dwo_cutu
!= NULL
)
13433 if (dwarf_read_debug
)
13435 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) found: @%s\n",
13436 kind
, dwo_name
, hex_string (signature
),
13437 host_address_to_string (dwo_cutu
));
13444 /* We didn't find it. This could mean a dwo_id mismatch, or
13445 someone deleted the DWO/DWP file, or the search path isn't set up
13446 correctly to find the file. */
13448 if (dwarf_read_debug
)
13450 fprintf_unfiltered (gdb_stdlog
, "DWO %s %s(%s) not found\n",
13451 kind
, dwo_name
, hex_string (signature
));
13454 /* This is a warning and not a complaint because it can be caused by
13455 pilot error (e.g., user accidentally deleting the DWO). */
13457 /* Print the name of the DWP file if we looked there, helps the user
13458 better diagnose the problem. */
13459 std::string dwp_text
;
13461 if (dwp_file
!= NULL
)
13462 dwp_text
= string_printf (" [in DWP file %s]",
13463 lbasename (dwp_file
->name
));
13465 warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
13466 " [in module %s]"),
13467 kind
, dwo_name
, hex_string (signature
),
13469 this_unit
->is_debug_types
? "TU" : "CU",
13470 sect_offset_str (this_unit
->sect_off
), objfile_name (objfile
));
13475 /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU.
13476 See lookup_dwo_cutu_unit for details. */
13478 static struct dwo_unit
*
13479 lookup_dwo_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
13480 const char *dwo_name
, const char *comp_dir
,
13481 ULONGEST signature
)
13483 return lookup_dwo_cutu (this_cu
, dwo_name
, comp_dir
, signature
, 0);
13486 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
13487 See lookup_dwo_cutu_unit for details. */
13489 static struct dwo_unit
*
13490 lookup_dwo_type_unit (struct signatured_type
*this_tu
,
13491 const char *dwo_name
, const char *comp_dir
)
13493 return lookup_dwo_cutu (&this_tu
->per_cu
, dwo_name
, comp_dir
, this_tu
->signature
, 1);
13496 /* Traversal function for queue_and_load_all_dwo_tus. */
13499 queue_and_load_dwo_tu (void **slot
, void *info
)
13501 struct dwo_unit
*dwo_unit
= (struct dwo_unit
*) *slot
;
13502 struct dwarf2_per_cu_data
*per_cu
= (struct dwarf2_per_cu_data
*) info
;
13503 ULONGEST signature
= dwo_unit
->signature
;
13504 struct signatured_type
*sig_type
=
13505 lookup_dwo_signatured_type (per_cu
->cu
, signature
);
13507 if (sig_type
!= NULL
)
13509 struct dwarf2_per_cu_data
*sig_cu
= &sig_type
->per_cu
;
13511 /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
13512 a real dependency of PER_CU on SIG_TYPE. That is detected later
13513 while processing PER_CU. */
13514 if (maybe_queue_comp_unit (NULL
, sig_cu
, per_cu
->cu
->language
))
13515 load_full_type_unit (sig_cu
);
13516 per_cu
->imported_symtabs_push (sig_cu
);
13522 /* Queue all TUs contained in the DWO of PER_CU to be read in.
13523 The DWO may have the only definition of the type, though it may not be
13524 referenced anywhere in PER_CU. Thus we have to load *all* its TUs.
13525 http://sourceware.org/bugzilla/show_bug.cgi?id=15021 */
13528 queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data
*per_cu
)
13530 struct dwo_unit
*dwo_unit
;
13531 struct dwo_file
*dwo_file
;
13533 gdb_assert (!per_cu
->is_debug_types
);
13534 gdb_assert (get_dwp_file (per_cu
->dwarf2_per_objfile
) == NULL
);
13535 gdb_assert (per_cu
->cu
!= NULL
);
13537 dwo_unit
= per_cu
->cu
->dwo_unit
;
13538 gdb_assert (dwo_unit
!= NULL
);
13540 dwo_file
= dwo_unit
->dwo_file
;
13541 if (dwo_file
->tus
!= NULL
)
13542 htab_traverse_noresize (dwo_file
->tus
, queue_and_load_dwo_tu
, per_cu
);
13545 /* Read in various DIEs. */
13547 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
13548 Inherit only the children of the DW_AT_abstract_origin DIE not being
13549 already referenced by DW_AT_abstract_origin from the children of the
13553 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
13555 struct die_info
*child_die
;
13556 sect_offset
*offsetp
;
13557 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
13558 struct die_info
*origin_die
;
13559 /* Iterator of the ORIGIN_DIE children. */
13560 struct die_info
*origin_child_die
;
13561 struct attribute
*attr
;
13562 struct dwarf2_cu
*origin_cu
;
13563 struct pending
**origin_previous_list_in_scope
;
13565 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
13569 /* Note that following die references may follow to a die in a
13573 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
13575 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
13577 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
13578 origin_cu
->list_in_scope
= cu
->list_in_scope
;
13580 if (die
->tag
!= origin_die
->tag
13581 && !(die
->tag
== DW_TAG_inlined_subroutine
13582 && origin_die
->tag
== DW_TAG_subprogram
))
13583 complaint (_("DIE %s and its abstract origin %s have different tags"),
13584 sect_offset_str (die
->sect_off
),
13585 sect_offset_str (origin_die
->sect_off
));
13587 std::vector
<sect_offset
> offsets
;
13589 for (child_die
= die
->child
;
13590 child_die
&& child_die
->tag
;
13591 child_die
= sibling_die (child_die
))
13593 struct die_info
*child_origin_die
;
13594 struct dwarf2_cu
*child_origin_cu
;
13596 /* We are trying to process concrete instance entries:
13597 DW_TAG_call_site DIEs indeed have a DW_AT_abstract_origin tag, but
13598 it's not relevant to our analysis here. i.e. detecting DIEs that are
13599 present in the abstract instance but not referenced in the concrete
13601 if (child_die
->tag
== DW_TAG_call_site
13602 || child_die
->tag
== DW_TAG_GNU_call_site
)
13605 /* For each CHILD_DIE, find the corresponding child of
13606 ORIGIN_DIE. If there is more than one layer of
13607 DW_AT_abstract_origin, follow them all; there shouldn't be,
13608 but GCC versions at least through 4.4 generate this (GCC PR
13610 child_origin_die
= child_die
;
13611 child_origin_cu
= cu
;
13614 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
13618 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
13622 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
13623 counterpart may exist. */
13624 if (child_origin_die
!= child_die
)
13626 if (child_die
->tag
!= child_origin_die
->tag
13627 && !(child_die
->tag
== DW_TAG_inlined_subroutine
13628 && child_origin_die
->tag
== DW_TAG_subprogram
))
13629 complaint (_("Child DIE %s and its abstract origin %s have "
13631 sect_offset_str (child_die
->sect_off
),
13632 sect_offset_str (child_origin_die
->sect_off
));
13633 if (child_origin_die
->parent
!= origin_die
)
13634 complaint (_("Child DIE %s and its abstract origin %s have "
13635 "different parents"),
13636 sect_offset_str (child_die
->sect_off
),
13637 sect_offset_str (child_origin_die
->sect_off
));
13639 offsets
.push_back (child_origin_die
->sect_off
);
13642 std::sort (offsets
.begin (), offsets
.end ());
13643 sect_offset
*offsets_end
= offsets
.data () + offsets
.size ();
13644 for (offsetp
= offsets
.data () + 1; offsetp
< offsets_end
; offsetp
++)
13645 if (offsetp
[-1] == *offsetp
)
13646 complaint (_("Multiple children of DIE %s refer "
13647 "to DIE %s as their abstract origin"),
13648 sect_offset_str (die
->sect_off
), sect_offset_str (*offsetp
));
13650 offsetp
= offsets
.data ();
13651 origin_child_die
= origin_die
->child
;
13652 while (origin_child_die
&& origin_child_die
->tag
)
13654 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
13655 while (offsetp
< offsets_end
13656 && *offsetp
< origin_child_die
->sect_off
)
13658 if (offsetp
>= offsets_end
13659 || *offsetp
> origin_child_die
->sect_off
)
13661 /* Found that ORIGIN_CHILD_DIE is really not referenced.
13662 Check whether we're already processing ORIGIN_CHILD_DIE.
13663 This can happen with mutually referenced abstract_origins.
13665 if (!origin_child_die
->in_process
)
13666 process_die (origin_child_die
, origin_cu
);
13668 origin_child_die
= sibling_die (origin_child_die
);
13670 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
13672 if (cu
!= origin_cu
)
13673 compute_delayed_physnames (origin_cu
);
13677 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13679 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13680 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13681 struct context_stack
*newobj
;
13684 struct die_info
*child_die
;
13685 struct attribute
*attr
, *call_line
, *call_file
;
13687 CORE_ADDR baseaddr
;
13688 struct block
*block
;
13689 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
13690 std::vector
<struct symbol
*> template_args
;
13691 struct template_symbol
*templ_func
= NULL
;
13695 /* If we do not have call site information, we can't show the
13696 caller of this inlined function. That's too confusing, so
13697 only use the scope for local variables. */
13698 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
13699 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
13700 if (call_line
== NULL
|| call_file
== NULL
)
13702 read_lexical_block_scope (die
, cu
);
13707 baseaddr
= objfile
->text_section_offset ();
13709 name
= dwarf2_name (die
, cu
);
13711 /* Ignore functions with missing or empty names. These are actually
13712 illegal according to the DWARF standard. */
13715 complaint (_("missing name for subprogram DIE at %s"),
13716 sect_offset_str (die
->sect_off
));
13720 /* Ignore functions with missing or invalid low and high pc attributes. */
13721 if (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
)
13722 <= PC_BOUNDS_INVALID
)
13724 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
13725 if (!attr
|| !DW_UNSND (attr
))
13726 complaint (_("cannot get low and high bounds "
13727 "for subprogram DIE at %s"),
13728 sect_offset_str (die
->sect_off
));
13732 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13733 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13735 /* If we have any template arguments, then we must allocate a
13736 different sort of symbol. */
13737 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
13739 if (child_die
->tag
== DW_TAG_template_type_param
13740 || child_die
->tag
== DW_TAG_template_value_param
)
13742 templ_func
= allocate_template_symbol (objfile
);
13743 templ_func
->subclass
= SYMBOL_TEMPLATE
;
13748 newobj
= cu
->get_builder ()->push_context (0, lowpc
);
13749 newobj
->name
= new_symbol (die
, read_type_die (die
, cu
), cu
,
13750 (struct symbol
*) templ_func
);
13752 if (dwarf2_flag_true_p (die
, DW_AT_main_subprogram
, cu
))
13753 set_objfile_main_name (objfile
, newobj
->name
->linkage_name (),
13756 /* If there is a location expression for DW_AT_frame_base, record
13758 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
13759 if (attr
!= nullptr)
13760 dwarf2_symbol_mark_computed (attr
, newobj
->name
, cu
, 1);
13762 /* If there is a location for the static link, record it. */
13763 newobj
->static_link
= NULL
;
13764 attr
= dwarf2_attr (die
, DW_AT_static_link
, cu
);
13765 if (attr
!= nullptr)
13767 newobj
->static_link
13768 = XOBNEW (&objfile
->objfile_obstack
, struct dynamic_prop
);
13769 attr_to_dynamic_prop (attr
, die
, cu
, newobj
->static_link
,
13770 dwarf2_per_cu_addr_type (cu
->per_cu
));
13773 cu
->list_in_scope
= cu
->get_builder ()->get_local_symbols ();
13775 if (die
->child
!= NULL
)
13777 child_die
= die
->child
;
13778 while (child_die
&& child_die
->tag
)
13780 if (child_die
->tag
== DW_TAG_template_type_param
13781 || child_die
->tag
== DW_TAG_template_value_param
)
13783 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
13786 template_args
.push_back (arg
);
13789 process_die (child_die
, cu
);
13790 child_die
= sibling_die (child_die
);
13794 inherit_abstract_dies (die
, cu
);
13796 /* If we have a DW_AT_specification, we might need to import using
13797 directives from the context of the specification DIE. See the
13798 comment in determine_prefix. */
13799 if (cu
->language
== language_cplus
13800 && dwarf2_attr (die
, DW_AT_specification
, cu
))
13802 struct dwarf2_cu
*spec_cu
= cu
;
13803 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
13807 child_die
= spec_die
->child
;
13808 while (child_die
&& child_die
->tag
)
13810 if (child_die
->tag
== DW_TAG_imported_module
)
13811 process_die (child_die
, spec_cu
);
13812 child_die
= sibling_die (child_die
);
13815 /* In some cases, GCC generates specification DIEs that
13816 themselves contain DW_AT_specification attributes. */
13817 spec_die
= die_specification (spec_die
, &spec_cu
);
13821 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13822 /* Make a block for the local symbols within. */
13823 block
= cu
->get_builder ()->finish_block (cstk
.name
, cstk
.old_blocks
,
13824 cstk
.static_link
, lowpc
, highpc
);
13826 /* For C++, set the block's scope. */
13827 if ((cu
->language
== language_cplus
13828 || cu
->language
== language_fortran
13829 || cu
->language
== language_d
13830 || cu
->language
== language_rust
)
13831 && cu
->processing_has_namespace_info
)
13832 block_set_scope (block
, determine_prefix (die
, cu
),
13833 &objfile
->objfile_obstack
);
13835 /* If we have address ranges, record them. */
13836 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13838 gdbarch_make_symbol_special (gdbarch
, cstk
.name
, objfile
);
13840 /* Attach template arguments to function. */
13841 if (!template_args
.empty ())
13843 gdb_assert (templ_func
!= NULL
);
13845 templ_func
->n_template_arguments
= template_args
.size ();
13846 templ_func
->template_arguments
13847 = XOBNEWVEC (&objfile
->objfile_obstack
, struct symbol
*,
13848 templ_func
->n_template_arguments
);
13849 memcpy (templ_func
->template_arguments
,
13850 template_args
.data (),
13851 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
13853 /* Make sure that the symtab is set on the new symbols. Even
13854 though they don't appear in this symtab directly, other parts
13855 of gdb assume that symbols do, and this is reasonably
13857 for (symbol
*sym
: template_args
)
13858 symbol_set_symtab (sym
, symbol_symtab (templ_func
));
13861 /* In C++, we can have functions nested inside functions (e.g., when
13862 a function declares a class that has methods). This means that
13863 when we finish processing a function scope, we may need to go
13864 back to building a containing block's symbol lists. */
13865 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13866 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13868 /* If we've finished processing a top-level function, subsequent
13869 symbols go in the file symbol list. */
13870 if (cu
->get_builder ()->outermost_context_p ())
13871 cu
->list_in_scope
= cu
->get_builder ()->get_file_symbols ();
13874 /* Process all the DIES contained within a lexical block scope. Start
13875 a new scope, process the dies, and then close the scope. */
13878 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13880 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13881 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13882 CORE_ADDR lowpc
, highpc
;
13883 struct die_info
*child_die
;
13884 CORE_ADDR baseaddr
;
13886 baseaddr
= objfile
->text_section_offset ();
13888 /* Ignore blocks with missing or invalid low and high pc attributes. */
13889 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
13890 as multiple lexical blocks? Handling children in a sane way would
13891 be nasty. Might be easier to properly extend generic blocks to
13892 describe ranges. */
13893 switch (dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
13895 case PC_BOUNDS_NOT_PRESENT
:
13896 /* DW_TAG_lexical_block has no attributes, process its children as if
13897 there was no wrapping by that DW_TAG_lexical_block.
13898 GCC does no longer produces such DWARF since GCC r224161. */
13899 for (child_die
= die
->child
;
13900 child_die
!= NULL
&& child_die
->tag
;
13901 child_die
= sibling_die (child_die
))
13902 process_die (child_die
, cu
);
13904 case PC_BOUNDS_INVALID
:
13907 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
13908 highpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, highpc
+ baseaddr
);
13910 cu
->get_builder ()->push_context (0, lowpc
);
13911 if (die
->child
!= NULL
)
13913 child_die
= die
->child
;
13914 while (child_die
&& child_die
->tag
)
13916 process_die (child_die
, cu
);
13917 child_die
= sibling_die (child_die
);
13920 inherit_abstract_dies (die
, cu
);
13921 struct context_stack cstk
= cu
->get_builder ()->pop_context ();
13923 if (*cu
->get_builder ()->get_local_symbols () != NULL
13924 || (*cu
->get_builder ()->get_local_using_directives ()) != NULL
)
13926 struct block
*block
13927 = cu
->get_builder ()->finish_block (0, cstk
.old_blocks
, NULL
,
13928 cstk
.start_addr
, highpc
);
13930 /* Note that recording ranges after traversing children, as we
13931 do here, means that recording a parent's ranges entails
13932 walking across all its children's ranges as they appear in
13933 the address map, which is quadratic behavior.
13935 It would be nicer to record the parent's ranges before
13936 traversing its children, simply overriding whatever you find
13937 there. But since we don't even decide whether to create a
13938 block until after we've traversed its children, that's hard
13940 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
13942 *cu
->get_builder ()->get_local_symbols () = cstk
.locals
;
13943 cu
->get_builder ()->set_local_using_directives (cstk
.local_using_directives
);
13946 /* Read in DW_TAG_call_site and insert it to CU->call_site_htab. */
13949 read_call_site_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
13951 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
13952 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
13953 CORE_ADDR pc
, baseaddr
;
13954 struct attribute
*attr
;
13955 struct call_site
*call_site
, call_site_local
;
13958 struct die_info
*child_die
;
13960 baseaddr
= objfile
->text_section_offset ();
13962 attr
= dwarf2_attr (die
, DW_AT_call_return_pc
, cu
);
13965 /* This was a pre-DWARF-5 GNU extension alias
13966 for DW_AT_call_return_pc. */
13967 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
13971 complaint (_("missing DW_AT_call_return_pc for DW_TAG_call_site "
13972 "DIE %s [in module %s]"),
13973 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
13976 pc
= attr_value_as_address (attr
) + baseaddr
;
13977 pc
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc
);
13979 if (cu
->call_site_htab
== NULL
)
13980 cu
->call_site_htab
= htab_create_alloc_ex (16, core_addr_hash
, core_addr_eq
,
13981 NULL
, &objfile
->objfile_obstack
,
13982 hashtab_obstack_allocate
, NULL
);
13983 call_site_local
.pc
= pc
;
13984 slot
= htab_find_slot (cu
->call_site_htab
, &call_site_local
, INSERT
);
13987 complaint (_("Duplicate PC %s for DW_TAG_call_site "
13988 "DIE %s [in module %s]"),
13989 paddress (gdbarch
, pc
), sect_offset_str (die
->sect_off
),
13990 objfile_name (objfile
));
13994 /* Count parameters at the caller. */
13997 for (child_die
= die
->child
; child_die
&& child_die
->tag
;
13998 child_die
= sibling_die (child_die
))
14000 if (child_die
->tag
!= DW_TAG_call_site_parameter
14001 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14003 complaint (_("Tag %d is not DW_TAG_call_site_parameter in "
14004 "DW_TAG_call_site child DIE %s [in module %s]"),
14005 child_die
->tag
, sect_offset_str (child_die
->sect_off
),
14006 objfile_name (objfile
));
14014 = ((struct call_site
*)
14015 obstack_alloc (&objfile
->objfile_obstack
,
14016 sizeof (*call_site
)
14017 + (sizeof (*call_site
->parameter
) * (nparams
- 1))));
14019 memset (call_site
, 0, sizeof (*call_site
) - sizeof (*call_site
->parameter
));
14020 call_site
->pc
= pc
;
14022 if (dwarf2_flag_true_p (die
, DW_AT_call_tail_call
, cu
)
14023 || dwarf2_flag_true_p (die
, DW_AT_GNU_tail_call
, cu
))
14025 struct die_info
*func_die
;
14027 /* Skip also over DW_TAG_inlined_subroutine. */
14028 for (func_die
= die
->parent
;
14029 func_die
&& func_die
->tag
!= DW_TAG_subprogram
14030 && func_die
->tag
!= DW_TAG_subroutine_type
;
14031 func_die
= func_die
->parent
);
14033 /* DW_AT_call_all_calls is a superset
14034 of DW_AT_call_all_tail_calls. */
14036 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_calls
, cu
)
14037 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_call_sites
, cu
)
14038 && !dwarf2_flag_true_p (func_die
, DW_AT_call_all_tail_calls
, cu
)
14039 && !dwarf2_flag_true_p (func_die
, DW_AT_GNU_all_tail_call_sites
, cu
))
14041 /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is
14042 not complete. But keep CALL_SITE for look ups via call_site_htab,
14043 both the initial caller containing the real return address PC and
14044 the final callee containing the current PC of a chain of tail
14045 calls do not need to have the tail call list complete. But any
14046 function candidate for a virtual tail call frame searched via
14047 TYPE_TAIL_CALL_LIST must have the tail call list complete to be
14048 determined unambiguously. */
14052 struct type
*func_type
= NULL
;
14055 func_type
= get_die_type (func_die
, cu
);
14056 if (func_type
!= NULL
)
14058 gdb_assert (TYPE_CODE (func_type
) == TYPE_CODE_FUNC
);
14060 /* Enlist this call site to the function. */
14061 call_site
->tail_call_next
= TYPE_TAIL_CALL_LIST (func_type
);
14062 TYPE_TAIL_CALL_LIST (func_type
) = call_site
;
14065 complaint (_("Cannot find function owning DW_TAG_call_site "
14066 "DIE %s [in module %s]"),
14067 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14071 attr
= dwarf2_attr (die
, DW_AT_call_target
, cu
);
14073 attr
= dwarf2_attr (die
, DW_AT_GNU_call_site_target
, cu
);
14075 attr
= dwarf2_attr (die
, DW_AT_call_origin
, cu
);
14078 /* This was a pre-DWARF-5 GNU extension alias for DW_AT_call_origin. */
14079 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14081 SET_FIELD_DWARF_BLOCK (call_site
->target
, NULL
);
14082 if (!attr
|| (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0))
14083 /* Keep NULL DWARF_BLOCK. */;
14084 else if (attr_form_is_block (attr
))
14086 struct dwarf2_locexpr_baton
*dlbaton
;
14088 dlbaton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
14089 dlbaton
->data
= DW_BLOCK (attr
)->data
;
14090 dlbaton
->size
= DW_BLOCK (attr
)->size
;
14091 dlbaton
->per_cu
= cu
->per_cu
;
14093 SET_FIELD_DWARF_BLOCK (call_site
->target
, dlbaton
);
14095 else if (attr_form_is_ref (attr
))
14097 struct dwarf2_cu
*target_cu
= cu
;
14098 struct die_info
*target_die
;
14100 target_die
= follow_die_ref (die
, attr
, &target_cu
);
14101 gdb_assert (target_cu
->per_cu
->dwarf2_per_objfile
->objfile
== objfile
);
14102 if (die_is_declaration (target_die
, target_cu
))
14104 const char *target_physname
;
14106 /* Prefer the mangled name; otherwise compute the demangled one. */
14107 target_physname
= dw2_linkage_name (target_die
, target_cu
);
14108 if (target_physname
== NULL
)
14109 target_physname
= dwarf2_physname (NULL
, target_die
, target_cu
);
14110 if (target_physname
== NULL
)
14111 complaint (_("DW_AT_call_target target DIE has invalid "
14112 "physname, for referencing DIE %s [in module %s]"),
14113 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14115 SET_FIELD_PHYSNAME (call_site
->target
, target_physname
);
14121 /* DW_AT_entry_pc should be preferred. */
14122 if (dwarf2_get_pc_bounds (target_die
, &lowpc
, NULL
, target_cu
, NULL
)
14123 <= PC_BOUNDS_INVALID
)
14124 complaint (_("DW_AT_call_target target DIE has invalid "
14125 "low pc, for referencing DIE %s [in module %s]"),
14126 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14129 lowpc
= gdbarch_adjust_dwarf2_addr (gdbarch
, lowpc
+ baseaddr
);
14130 SET_FIELD_PHYSADDR (call_site
->target
, lowpc
);
14135 complaint (_("DW_TAG_call_site DW_AT_call_target is neither "
14136 "block nor reference, for DIE %s [in module %s]"),
14137 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
14139 call_site
->per_cu
= cu
->per_cu
;
14141 for (child_die
= die
->child
;
14142 child_die
&& child_die
->tag
;
14143 child_die
= sibling_die (child_die
))
14145 struct call_site_parameter
*parameter
;
14146 struct attribute
*loc
, *origin
;
14148 if (child_die
->tag
!= DW_TAG_call_site_parameter
14149 && child_die
->tag
!= DW_TAG_GNU_call_site_parameter
)
14151 /* Already printed the complaint above. */
14155 gdb_assert (call_site
->parameter_count
< nparams
);
14156 parameter
= &call_site
->parameter
[call_site
->parameter_count
];
14158 /* DW_AT_location specifies the register number or DW_AT_abstract_origin
14159 specifies DW_TAG_formal_parameter. Value of the data assumed for the
14160 register is contained in DW_AT_call_value. */
14162 loc
= dwarf2_attr (child_die
, DW_AT_location
, cu
);
14163 origin
= dwarf2_attr (child_die
, DW_AT_call_parameter
, cu
);
14164 if (origin
== NULL
)
14166 /* This was a pre-DWARF-5 GNU extension alias
14167 for DW_AT_call_parameter. */
14168 origin
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
14170 if (loc
== NULL
&& origin
!= NULL
&& attr_form_is_ref (origin
))
14172 parameter
->kind
= CALL_SITE_PARAMETER_PARAM_OFFSET
;
14174 sect_offset sect_off
14175 = (sect_offset
) dwarf2_get_ref_die_offset (origin
);
14176 if (!offset_in_cu_p (&cu
->header
, sect_off
))
14178 /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
14179 binding can be done only inside one CU. Such referenced DIE
14180 therefore cannot be even moved to DW_TAG_partial_unit. */
14181 complaint (_("DW_AT_call_parameter offset is not in CU for "
14182 "DW_TAG_call_site child DIE %s [in module %s]"),
14183 sect_offset_str (child_die
->sect_off
),
14184 objfile_name (objfile
));
14187 parameter
->u
.param_cu_off
14188 = (cu_offset
) (sect_off
- cu
->header
.sect_off
);
14190 else if (loc
== NULL
|| origin
!= NULL
|| !attr_form_is_block (loc
))
14192 complaint (_("No DW_FORM_block* DW_AT_location for "
14193 "DW_TAG_call_site child DIE %s [in module %s]"),
14194 sect_offset_str (child_die
->sect_off
), objfile_name (objfile
));
14199 parameter
->u
.dwarf_reg
= dwarf_block_to_dwarf_reg
14200 (DW_BLOCK (loc
)->data
, &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
]);
14201 if (parameter
->u
.dwarf_reg
!= -1)
14202 parameter
->kind
= CALL_SITE_PARAMETER_DWARF_REG
;
14203 else if (dwarf_block_to_sp_offset (gdbarch
, DW_BLOCK (loc
)->data
,
14204 &DW_BLOCK (loc
)->data
[DW_BLOCK (loc
)->size
],
14205 ¶meter
->u
.fb_offset
))
14206 parameter
->kind
= CALL_SITE_PARAMETER_FB_OFFSET
;
14209 complaint (_("Only single DW_OP_reg or DW_OP_fbreg is supported "
14210 "for DW_FORM_block* DW_AT_location is supported for "
14211 "DW_TAG_call_site child DIE %s "
14213 sect_offset_str (child_die
->sect_off
),
14214 objfile_name (objfile
));
14219 attr
= dwarf2_attr (child_die
, DW_AT_call_value
, cu
);
14221 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_value
, cu
);
14222 if (!attr_form_is_block (attr
))
14224 complaint (_("No DW_FORM_block* DW_AT_call_value for "
14225 "DW_TAG_call_site child DIE %s [in module %s]"),
14226 sect_offset_str (child_die
->sect_off
),
14227 objfile_name (objfile
));
14230 parameter
->value
= DW_BLOCK (attr
)->data
;
14231 parameter
->value_size
= DW_BLOCK (attr
)->size
;
14233 /* Parameters are not pre-cleared by memset above. */
14234 parameter
->data_value
= NULL
;
14235 parameter
->data_value_size
= 0;
14236 call_site
->parameter_count
++;
14238 attr
= dwarf2_attr (child_die
, DW_AT_call_data_value
, cu
);
14240 attr
= dwarf2_attr (child_die
, DW_AT_GNU_call_site_data_value
, cu
);
14241 if (attr
!= nullptr)
14243 if (!attr_form_is_block (attr
))
14244 complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
14245 "DW_TAG_call_site child DIE %s [in module %s]"),
14246 sect_offset_str (child_die
->sect_off
),
14247 objfile_name (objfile
));
14250 parameter
->data_value
= DW_BLOCK (attr
)->data
;
14251 parameter
->data_value_size
= DW_BLOCK (attr
)->size
;
14257 /* Helper function for read_variable. If DIE represents a virtual
14258 table, then return the type of the concrete object that is
14259 associated with the virtual table. Otherwise, return NULL. */
14261 static struct type
*
14262 rust_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14264 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
14268 /* Find the type DIE. */
14269 struct die_info
*type_die
= NULL
;
14270 struct dwarf2_cu
*type_cu
= cu
;
14272 if (attr_form_is_ref (attr
))
14273 type_die
= follow_die_ref (die
, attr
, &type_cu
);
14274 if (type_die
== NULL
)
14277 if (dwarf2_attr (type_die
, DW_AT_containing_type
, type_cu
) == NULL
)
14279 return die_containing_type (type_die
, type_cu
);
14282 /* Read a variable (DW_TAG_variable) DIE and create a new symbol. */
14285 read_variable (struct die_info
*die
, struct dwarf2_cu
*cu
)
14287 struct rust_vtable_symbol
*storage
= NULL
;
14289 if (cu
->language
== language_rust
)
14291 struct type
*containing_type
= rust_containing_type (die
, cu
);
14293 if (containing_type
!= NULL
)
14295 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14297 storage
= new (&objfile
->objfile_obstack
) rust_vtable_symbol ();
14298 initialize_objfile_symbol (storage
);
14299 storage
->concrete_type
= containing_type
;
14300 storage
->subclass
= SYMBOL_RUST_VTABLE
;
14304 struct symbol
*res
= new_symbol (die
, NULL
, cu
, storage
);
14305 struct attribute
*abstract_origin
14306 = dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
14307 struct attribute
*loc
= dwarf2_attr (die
, DW_AT_location
, cu
);
14308 if (res
== NULL
&& loc
&& abstract_origin
)
14310 /* We have a variable without a name, but with a location and an abstract
14311 origin. This may be a concrete instance of an abstract variable
14312 referenced from an DW_OP_GNU_variable_value, so save it to find it back
14314 struct dwarf2_cu
*origin_cu
= cu
;
14315 struct die_info
*origin_die
14316 = follow_die_ref (die
, abstract_origin
, &origin_cu
);
14317 dwarf2_per_objfile
*dpo
= cu
->per_cu
->dwarf2_per_objfile
;
14318 dpo
->abstract_to_concrete
[origin_die
->sect_off
].push_back (die
->sect_off
);
14322 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET
14323 reading .debug_rnglists.
14324 Callback's type should be:
14325 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14326 Return true if the attributes are present and valid, otherwise,
14329 template <typename Callback
>
14331 dwarf2_rnglists_process (unsigned offset
, struct dwarf2_cu
*cu
,
14332 Callback
&&callback
)
14334 struct dwarf2_per_objfile
*dwarf2_per_objfile
14335 = cu
->per_cu
->dwarf2_per_objfile
;
14336 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14337 bfd
*obfd
= objfile
->obfd
;
14338 /* Base address selection entry. */
14341 const gdb_byte
*buffer
;
14342 CORE_ADDR baseaddr
;
14343 bool overflow
= false;
14345 found_base
= cu
->base_known
;
14346 base
= cu
->base_address
;
14348 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->rnglists
);
14349 if (offset
>= dwarf2_per_objfile
->rnglists
.size
)
14351 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14355 buffer
= dwarf2_per_objfile
->rnglists
.buffer
+ offset
;
14357 baseaddr
= objfile
->text_section_offset ();
14361 /* Initialize it due to a false compiler warning. */
14362 CORE_ADDR range_beginning
= 0, range_end
= 0;
14363 const gdb_byte
*buf_end
= (dwarf2_per_objfile
->rnglists
.buffer
14364 + dwarf2_per_objfile
->rnglists
.size
);
14365 unsigned int bytes_read
;
14367 if (buffer
== buf_end
)
14372 const auto rlet
= static_cast<enum dwarf_range_list_entry
>(*buffer
++);
14375 case DW_RLE_end_of_list
:
14377 case DW_RLE_base_address
:
14378 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14383 base
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14385 buffer
+= bytes_read
;
14387 case DW_RLE_start_length
:
14388 if (buffer
+ cu
->header
.addr_size
> buf_end
)
14393 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14394 buffer
+= bytes_read
;
14395 range_end
= (range_beginning
14396 + read_unsigned_leb128 (obfd
, buffer
, &bytes_read
));
14397 buffer
+= bytes_read
;
14398 if (buffer
> buf_end
)
14404 case DW_RLE_offset_pair
:
14405 range_beginning
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14406 buffer
+= bytes_read
;
14407 if (buffer
> buf_end
)
14412 range_end
= read_unsigned_leb128 (obfd
, buffer
, &bytes_read
);
14413 buffer
+= bytes_read
;
14414 if (buffer
> buf_end
)
14420 case DW_RLE_start_end
:
14421 if (buffer
+ 2 * cu
->header
.addr_size
> buf_end
)
14426 range_beginning
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14427 buffer
+= bytes_read
;
14428 range_end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
14429 buffer
+= bytes_read
;
14432 complaint (_("Invalid .debug_rnglists data (no base address)"));
14435 if (rlet
== DW_RLE_end_of_list
|| overflow
)
14437 if (rlet
== DW_RLE_base_address
)
14442 /* We have no valid base address for the ranges
14444 complaint (_("Invalid .debug_rnglists data (no base address)"));
14448 if (range_beginning
> range_end
)
14450 /* Inverted range entries are invalid. */
14451 complaint (_("Invalid .debug_rnglists data (inverted range)"));
14455 /* Empty range entries have no effect. */
14456 if (range_beginning
== range_end
)
14459 range_beginning
+= base
;
14462 /* A not-uncommon case of bad debug info.
14463 Don't pollute the addrmap with bad data. */
14464 if (range_beginning
+ baseaddr
== 0
14465 && !dwarf2_per_objfile
->has_section_at_zero
)
14467 complaint (_(".debug_rnglists entry has start address of zero"
14468 " [in module %s]"), objfile_name (objfile
));
14472 callback (range_beginning
, range_end
);
14477 complaint (_("Offset %d is not terminated "
14478 "for DW_AT_ranges attribute"),
14486 /* Call CALLBACK from DW_AT_ranges attribute value OFFSET reading .debug_ranges.
14487 Callback's type should be:
14488 void (CORE_ADDR range_beginning, CORE_ADDR range_end)
14489 Return 1 if the attributes are present and valid, otherwise, return 0. */
14491 template <typename Callback
>
14493 dwarf2_ranges_process (unsigned offset
, struct dwarf2_cu
*cu
,
14494 Callback
&&callback
)
14496 struct dwarf2_per_objfile
*dwarf2_per_objfile
14497 = cu
->per_cu
->dwarf2_per_objfile
;
14498 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
14499 struct comp_unit_head
*cu_header
= &cu
->header
;
14500 bfd
*obfd
= objfile
->obfd
;
14501 unsigned int addr_size
= cu_header
->addr_size
;
14502 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
14503 /* Base address selection entry. */
14506 unsigned int dummy
;
14507 const gdb_byte
*buffer
;
14508 CORE_ADDR baseaddr
;
14510 if (cu_header
->version
>= 5)
14511 return dwarf2_rnglists_process (offset
, cu
, callback
);
14513 found_base
= cu
->base_known
;
14514 base
= cu
->base_address
;
14516 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
14517 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
14519 complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
14523 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
14525 baseaddr
= objfile
->text_section_offset ();
14529 CORE_ADDR range_beginning
, range_end
;
14531 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
14532 buffer
+= addr_size
;
14533 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
14534 buffer
+= addr_size
;
14535 offset
+= 2 * addr_size
;
14537 /* An end of list marker is a pair of zero addresses. */
14538 if (range_beginning
== 0 && range_end
== 0)
14539 /* Found the end of list entry. */
14542 /* Each base address selection entry is a pair of 2 values.
14543 The first is the largest possible address, the second is
14544 the base address. Check for a base address here. */
14545 if ((range_beginning
& mask
) == mask
)
14547 /* If we found the largest possible address, then we already
14548 have the base address in range_end. */
14556 /* We have no valid base address for the ranges
14558 complaint (_("Invalid .debug_ranges data (no base address)"));
14562 if (range_beginning
> range_end
)
14564 /* Inverted range entries are invalid. */
14565 complaint (_("Invalid .debug_ranges data (inverted range)"));
14569 /* Empty range entries have no effect. */
14570 if (range_beginning
== range_end
)
14573 range_beginning
+= base
;
14576 /* A not-uncommon case of bad debug info.
14577 Don't pollute the addrmap with bad data. */
14578 if (range_beginning
+ baseaddr
== 0
14579 && !dwarf2_per_objfile
->has_section_at_zero
)
14581 complaint (_(".debug_ranges entry has start address of zero"
14582 " [in module %s]"), objfile_name (objfile
));
14586 callback (range_beginning
, range_end
);
14592 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
14593 Return 1 if the attributes are present and valid, otherwise, return 0.
14594 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
14597 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
14598 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
14599 struct partial_symtab
*ranges_pst
)
14601 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14602 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14603 const CORE_ADDR baseaddr
= objfile
->text_section_offset ();
14606 CORE_ADDR high
= 0;
14609 retval
= dwarf2_ranges_process (offset
, cu
,
14610 [&] (CORE_ADDR range_beginning
, CORE_ADDR range_end
)
14612 if (ranges_pst
!= NULL
)
14617 lowpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14618 range_beginning
+ baseaddr
)
14620 highpc
= (gdbarch_adjust_dwarf2_addr (gdbarch
,
14621 range_end
+ baseaddr
)
14623 addrmap_set_empty (objfile
->partial_symtabs
->psymtabs_addrmap
,
14624 lowpc
, highpc
- 1, ranges_pst
);
14627 /* FIXME: This is recording everything as a low-high
14628 segment of consecutive addresses. We should have a
14629 data structure for discontiguous block ranges
14633 low
= range_beginning
;
14639 if (range_beginning
< low
)
14640 low
= range_beginning
;
14641 if (range_end
> high
)
14649 /* If the first entry is an end-of-list marker, the range
14650 describes an empty scope, i.e. no instructions. */
14656 *high_return
= high
;
14660 /* Get low and high pc attributes from a die. See enum pc_bounds_kind
14661 definition for the return value. *LOWPC and *HIGHPC are set iff
14662 neither PC_BOUNDS_NOT_PRESENT nor PC_BOUNDS_INVALID are returned. */
14664 static enum pc_bounds_kind
14665 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
14666 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
14667 struct partial_symtab
*pst
)
14669 struct dwarf2_per_objfile
*dwarf2_per_objfile
14670 = cu
->per_cu
->dwarf2_per_objfile
;
14671 struct attribute
*attr
;
14672 struct attribute
*attr_high
;
14674 CORE_ADDR high
= 0;
14675 enum pc_bounds_kind ret
;
14677 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14680 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14681 if (attr
!= nullptr)
14683 low
= attr_value_as_address (attr
);
14684 high
= attr_value_as_address (attr_high
);
14685 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14689 /* Found high w/o low attribute. */
14690 return PC_BOUNDS_INVALID
;
14692 /* Found consecutive range of addresses. */
14693 ret
= PC_BOUNDS_HIGH_LOW
;
14697 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14700 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14701 We take advantage of the fact that DW_AT_ranges does not appear
14702 in DW_TAG_compile_unit of DWO files. */
14703 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14704 unsigned int ranges_offset
= (DW_UNSND (attr
)
14705 + (need_ranges_base
14709 /* Value of the DW_AT_ranges attribute is the offset in the
14710 .debug_ranges section. */
14711 if (!dwarf2_ranges_read (ranges_offset
, &low
, &high
, cu
, pst
))
14712 return PC_BOUNDS_INVALID
;
14713 /* Found discontinuous range of addresses. */
14714 ret
= PC_BOUNDS_RANGES
;
14717 return PC_BOUNDS_NOT_PRESENT
;
14720 /* partial_die_info::read has also the strict LOW < HIGH requirement. */
14722 return PC_BOUNDS_INVALID
;
14724 /* When using the GNU linker, .gnu.linkonce. sections are used to
14725 eliminate duplicate copies of functions and vtables and such.
14726 The linker will arbitrarily choose one and discard the others.
14727 The AT_*_pc values for such functions refer to local labels in
14728 these sections. If the section from that file was discarded, the
14729 labels are not in the output, so the relocs get a value of 0.
14730 If this is a discarded function, mark the pc bounds as invalid,
14731 so that GDB will ignore it. */
14732 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
14733 return PC_BOUNDS_INVALID
;
14741 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
14742 its low and high PC addresses. Do nothing if these addresses could not
14743 be determined. Otherwise, set LOWPC to the low address if it is smaller,
14744 and HIGHPC to the high address if greater than HIGHPC. */
14747 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
14748 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14749 struct dwarf2_cu
*cu
)
14751 CORE_ADDR low
, high
;
14752 struct die_info
*child
= die
->child
;
14754 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
) >= PC_BOUNDS_RANGES
)
14756 *lowpc
= std::min (*lowpc
, low
);
14757 *highpc
= std::max (*highpc
, high
);
14760 /* If the language does not allow nested subprograms (either inside
14761 subprograms or lexical blocks), we're done. */
14762 if (cu
->language
!= language_ada
)
14765 /* Check all the children of the given DIE. If it contains nested
14766 subprograms, then check their pc bounds. Likewise, we need to
14767 check lexical blocks as well, as they may also contain subprogram
14769 while (child
&& child
->tag
)
14771 if (child
->tag
== DW_TAG_subprogram
14772 || child
->tag
== DW_TAG_lexical_block
)
14773 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
14774 child
= sibling_die (child
);
14778 /* Get the low and high pc's represented by the scope DIE, and store
14779 them in *LOWPC and *HIGHPC. If the correct values can't be
14780 determined, set *LOWPC to -1 and *HIGHPC to 0. */
14783 get_scope_pc_bounds (struct die_info
*die
,
14784 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
14785 struct dwarf2_cu
*cu
)
14787 CORE_ADDR best_low
= (CORE_ADDR
) -1;
14788 CORE_ADDR best_high
= (CORE_ADDR
) 0;
14789 CORE_ADDR current_low
, current_high
;
14791 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
)
14792 >= PC_BOUNDS_RANGES
)
14794 best_low
= current_low
;
14795 best_high
= current_high
;
14799 struct die_info
*child
= die
->child
;
14801 while (child
&& child
->tag
)
14803 switch (child
->tag
) {
14804 case DW_TAG_subprogram
:
14805 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
14807 case DW_TAG_namespace
:
14808 case DW_TAG_module
:
14809 /* FIXME: carlton/2004-01-16: Should we do this for
14810 DW_TAG_class_type/DW_TAG_structure_type, too? I think
14811 that current GCC's always emit the DIEs corresponding
14812 to definitions of methods of classes as children of a
14813 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
14814 the DIEs giving the declarations, which could be
14815 anywhere). But I don't see any reason why the
14816 standards says that they have to be there. */
14817 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
14819 if (current_low
!= ((CORE_ADDR
) -1))
14821 best_low
= std::min (best_low
, current_low
);
14822 best_high
= std::max (best_high
, current_high
);
14830 child
= sibling_die (child
);
14835 *highpc
= best_high
;
14838 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
14842 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
14843 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
14845 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
14846 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
14847 struct attribute
*attr
;
14848 struct attribute
*attr_high
;
14850 attr_high
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
14853 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
14854 if (attr
!= nullptr)
14856 CORE_ADDR low
= attr_value_as_address (attr
);
14857 CORE_ADDR high
= attr_value_as_address (attr_high
);
14859 if (cu
->header
.version
>= 4 && attr_form_is_constant (attr_high
))
14862 low
= gdbarch_adjust_dwarf2_addr (gdbarch
, low
+ baseaddr
);
14863 high
= gdbarch_adjust_dwarf2_addr (gdbarch
, high
+ baseaddr
);
14864 cu
->get_builder ()->record_block_range (block
, low
, high
- 1);
14868 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
14869 if (attr
!= nullptr)
14871 /* DW_AT_rnglists_base does not apply to DIEs from the DWO skeleton.
14872 We take advantage of the fact that DW_AT_ranges does not appear
14873 in DW_TAG_compile_unit of DWO files. */
14874 int need_ranges_base
= die
->tag
!= DW_TAG_compile_unit
;
14876 /* The value of the DW_AT_ranges attribute is the offset of the
14877 address range list in the .debug_ranges section. */
14878 unsigned long offset
= (DW_UNSND (attr
)
14879 + (need_ranges_base
? cu
->ranges_base
: 0));
14881 std::vector
<blockrange
> blockvec
;
14882 dwarf2_ranges_process (offset
, cu
,
14883 [&] (CORE_ADDR start
, CORE_ADDR end
)
14887 start
= gdbarch_adjust_dwarf2_addr (gdbarch
, start
);
14888 end
= gdbarch_adjust_dwarf2_addr (gdbarch
, end
);
14889 cu
->get_builder ()->record_block_range (block
, start
, end
- 1);
14890 blockvec
.emplace_back (start
, end
);
14893 BLOCK_RANGES(block
) = make_blockranges (objfile
, blockvec
);
14897 /* Check whether the producer field indicates either of GCC < 4.6, or the
14898 Intel C/C++ compiler, and cache the result in CU. */
14901 check_producer (struct dwarf2_cu
*cu
)
14905 if (cu
->producer
== NULL
)
14907 /* For unknown compilers expect their behavior is DWARF version
14910 GCC started to support .debug_types sections by -gdwarf-4 since
14911 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
14912 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
14913 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
14914 interpreted incorrectly by GDB now - GCC PR debug/48229. */
14916 else if (producer_is_gcc (cu
->producer
, &major
, &minor
))
14918 cu
->producer_is_gxx_lt_4_6
= major
< 4 || (major
== 4 && minor
< 6);
14919 cu
->producer_is_gcc_lt_4_3
= major
< 4 || (major
== 4 && minor
< 3);
14921 else if (producer_is_icc (cu
->producer
, &major
, &minor
))
14923 cu
->producer_is_icc
= true;
14924 cu
->producer_is_icc_lt_14
= major
< 14;
14926 else if (startswith (cu
->producer
, "CodeWarrior S12/L-ISA"))
14927 cu
->producer_is_codewarrior
= true;
14930 /* For other non-GCC compilers, expect their behavior is DWARF version
14934 cu
->checked_producer
= true;
14937 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
14938 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
14939 during 4.6.0 experimental. */
14942 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
14944 if (!cu
->checked_producer
)
14945 check_producer (cu
);
14947 return cu
->producer_is_gxx_lt_4_6
;
14951 /* Codewarrior (at least as of version 5.0.40) generates dwarf line information
14952 with incorrect is_stmt attributes. */
14955 producer_is_codewarrior (struct dwarf2_cu
*cu
)
14957 if (!cu
->checked_producer
)
14958 check_producer (cu
);
14960 return cu
->producer_is_codewarrior
;
14963 /* Return the default accessibility type if it is not overridden by
14964 DW_AT_accessibility. */
14966 static enum dwarf_access_attribute
14967 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
14969 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
14971 /* The default DWARF 2 accessibility for members is public, the default
14972 accessibility for inheritance is private. */
14974 if (die
->tag
!= DW_TAG_inheritance
)
14975 return DW_ACCESS_public
;
14977 return DW_ACCESS_private
;
14981 /* DWARF 3+ defines the default accessibility a different way. The same
14982 rules apply now for DW_TAG_inheritance as for the members and it only
14983 depends on the container kind. */
14985 if (die
->parent
->tag
== DW_TAG_class_type
)
14986 return DW_ACCESS_private
;
14988 return DW_ACCESS_public
;
14992 /* Look for DW_AT_data_member_location. Set *OFFSET to the byte
14993 offset. If the attribute was not found return 0, otherwise return
14994 1. If it was found but could not properly be handled, set *OFFSET
14998 handle_data_member_location (struct die_info
*die
, struct dwarf2_cu
*cu
,
15001 struct attribute
*attr
;
15003 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
15008 /* Note that we do not check for a section offset first here.
15009 This is because DW_AT_data_member_location is new in DWARF 4,
15010 so if we see it, we can assume that a constant form is really
15011 a constant and not a section offset. */
15012 if (attr_form_is_constant (attr
))
15013 *offset
= dwarf2_get_attr_constant_value (attr
, 0);
15014 else if (attr_form_is_section_offset (attr
))
15015 dwarf2_complex_location_expr_complaint ();
15016 else if (attr_form_is_block (attr
))
15017 *offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15019 dwarf2_complex_location_expr_complaint ();
15027 /* Add an aggregate field to the field list. */
15030 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
15031 struct dwarf2_cu
*cu
)
15033 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15034 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
15035 struct nextfield
*new_field
;
15036 struct attribute
*attr
;
15038 const char *fieldname
= "";
15040 if (die
->tag
== DW_TAG_inheritance
)
15042 fip
->baseclasses
.emplace_back ();
15043 new_field
= &fip
->baseclasses
.back ();
15047 fip
->fields
.emplace_back ();
15048 new_field
= &fip
->fields
.back ();
15053 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15054 if (attr
!= nullptr)
15055 new_field
->accessibility
= DW_UNSND (attr
);
15057 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
15058 if (new_field
->accessibility
!= DW_ACCESS_public
)
15059 fip
->non_public_fields
= 1;
15061 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15062 if (attr
!= nullptr)
15063 new_field
->virtuality
= DW_UNSND (attr
);
15065 new_field
->virtuality
= DW_VIRTUALITY_none
;
15067 fp
= &new_field
->field
;
15069 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
15073 /* Data member other than a C++ static data member. */
15075 /* Get type of field. */
15076 fp
->type
= die_type (die
, cu
);
15078 SET_FIELD_BITPOS (*fp
, 0);
15080 /* Get bit size of field (zero if none). */
15081 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
15082 if (attr
!= nullptr)
15084 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
15088 FIELD_BITSIZE (*fp
) = 0;
15091 /* Get bit offset of field. */
15092 if (handle_data_member_location (die
, cu
, &offset
))
15093 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15094 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
15095 if (attr
!= nullptr)
15097 if (gdbarch_byte_order (gdbarch
) == BFD_ENDIAN_BIG
)
15099 /* For big endian bits, the DW_AT_bit_offset gives the
15100 additional bit offset from the MSB of the containing
15101 anonymous object to the MSB of the field. We don't
15102 have to do anything special since we don't need to
15103 know the size of the anonymous object. */
15104 SET_FIELD_BITPOS (*fp
, FIELD_BITPOS (*fp
) + DW_UNSND (attr
));
15108 /* For little endian bits, compute the bit offset to the
15109 MSB of the anonymous object, subtract off the number of
15110 bits from the MSB of the field to the MSB of the
15111 object, and then subtract off the number of bits of
15112 the field itself. The result is the bit offset of
15113 the LSB of the field. */
15114 int anonymous_size
;
15115 int bit_offset
= DW_UNSND (attr
);
15117 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15118 if (attr
!= nullptr)
15120 /* The size of the anonymous object containing
15121 the bit field is explicit, so use the
15122 indicated size (in bytes). */
15123 anonymous_size
= DW_UNSND (attr
);
15127 /* The size of the anonymous object containing
15128 the bit field must be inferred from the type
15129 attribute of the data member containing the
15131 anonymous_size
= TYPE_LENGTH (fp
->type
);
15133 SET_FIELD_BITPOS (*fp
,
15134 (FIELD_BITPOS (*fp
)
15135 + anonymous_size
* bits_per_byte
15136 - bit_offset
- FIELD_BITSIZE (*fp
)));
15139 attr
= dwarf2_attr (die
, DW_AT_data_bit_offset
, cu
);
15141 SET_FIELD_BITPOS (*fp
, (FIELD_BITPOS (*fp
)
15142 + dwarf2_get_attr_constant_value (attr
, 0)));
15144 /* Get name of field. */
15145 fieldname
= dwarf2_name (die
, cu
);
15146 if (fieldname
== NULL
)
15149 /* The name is already allocated along with this objfile, so we don't
15150 need to duplicate it for the type. */
15151 fp
->name
= fieldname
;
15153 /* Change accessibility for artificial fields (e.g. virtual table
15154 pointer or virtual base class pointer) to private. */
15155 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
15157 FIELD_ARTIFICIAL (*fp
) = 1;
15158 new_field
->accessibility
= DW_ACCESS_private
;
15159 fip
->non_public_fields
= 1;
15162 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
15164 /* C++ static member. */
15166 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
15167 is a declaration, but all versions of G++ as of this writing
15168 (so through at least 3.2.1) incorrectly generate
15169 DW_TAG_variable tags. */
15171 const char *physname
;
15173 /* Get name of field. */
15174 fieldname
= dwarf2_name (die
, cu
);
15175 if (fieldname
== NULL
)
15178 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
15180 /* Only create a symbol if this is an external value.
15181 new_symbol checks this and puts the value in the global symbol
15182 table, which we want. If it is not external, new_symbol
15183 will try to put the value in cu->list_in_scope which is wrong. */
15184 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
15186 /* A static const member, not much different than an enum as far as
15187 we're concerned, except that we can support more types. */
15188 new_symbol (die
, NULL
, cu
);
15191 /* Get physical name. */
15192 physname
= dwarf2_physname (fieldname
, die
, cu
);
15194 /* The name is already allocated along with this objfile, so we don't
15195 need to duplicate it for the type. */
15196 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
15197 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15198 FIELD_NAME (*fp
) = fieldname
;
15200 else if (die
->tag
== DW_TAG_inheritance
)
15204 /* C++ base class field. */
15205 if (handle_data_member_location (die
, cu
, &offset
))
15206 SET_FIELD_BITPOS (*fp
, offset
* bits_per_byte
);
15207 FIELD_BITSIZE (*fp
) = 0;
15208 FIELD_TYPE (*fp
) = die_type (die
, cu
);
15209 FIELD_NAME (*fp
) = TYPE_NAME (fp
->type
);
15211 else if (die
->tag
== DW_TAG_variant_part
)
15213 /* process_structure_scope will treat this DIE as a union. */
15214 process_structure_scope (die
, cu
);
15216 /* The variant part is relative to the start of the enclosing
15218 SET_FIELD_BITPOS (*fp
, 0);
15219 fp
->type
= get_die_type (die
, cu
);
15220 fp
->artificial
= 1;
15221 fp
->name
= "<<variant>>";
15223 /* Normally a DW_TAG_variant_part won't have a size, but our
15224 representation requires one, so set it to the maximum of the
15225 child sizes, being sure to account for the offset at which
15226 each child is seen. */
15227 if (TYPE_LENGTH (fp
->type
) == 0)
15230 for (int i
= 0; i
< TYPE_NFIELDS (fp
->type
); ++i
)
15232 unsigned len
= ((TYPE_FIELD_BITPOS (fp
->type
, i
) + 7) / 8
15233 + TYPE_LENGTH (TYPE_FIELD_TYPE (fp
->type
, i
)));
15237 TYPE_LENGTH (fp
->type
) = max
;
15241 gdb_assert_not_reached ("missing case in dwarf2_add_field");
15244 /* Can the type given by DIE define another type? */
15247 type_can_define_types (const struct die_info
*die
)
15251 case DW_TAG_typedef
:
15252 case DW_TAG_class_type
:
15253 case DW_TAG_structure_type
:
15254 case DW_TAG_union_type
:
15255 case DW_TAG_enumeration_type
:
15263 /* Add a type definition defined in the scope of the FIP's class. */
15266 dwarf2_add_type_defn (struct field_info
*fip
, struct die_info
*die
,
15267 struct dwarf2_cu
*cu
)
15269 struct decl_field fp
;
15270 memset (&fp
, 0, sizeof (fp
));
15272 gdb_assert (type_can_define_types (die
));
15274 /* Get name of field. NULL is okay here, meaning an anonymous type. */
15275 fp
.name
= dwarf2_name (die
, cu
);
15276 fp
.type
= read_type_die (die
, cu
);
15278 /* Save accessibility. */
15279 enum dwarf_access_attribute accessibility
;
15280 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15282 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15284 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15285 switch (accessibility
)
15287 case DW_ACCESS_public
:
15288 /* The assumed value if neither private nor protected. */
15290 case DW_ACCESS_private
:
15293 case DW_ACCESS_protected
:
15294 fp
.is_protected
= 1;
15297 complaint (_("Unhandled DW_AT_accessibility value (%x)"), accessibility
);
15300 if (die
->tag
== DW_TAG_typedef
)
15301 fip
->typedef_field_list
.push_back (fp
);
15303 fip
->nested_types_list
.push_back (fp
);
15306 /* Create the vector of fields, and attach it to the type. */
15309 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
15310 struct dwarf2_cu
*cu
)
15312 int nfields
= fip
->nfields
;
15314 /* Record the field count, allocate space for the array of fields,
15315 and create blank accessibility bitfields if necessary. */
15316 TYPE_NFIELDS (type
) = nfields
;
15317 TYPE_FIELDS (type
) = (struct field
*)
15318 TYPE_ZALLOC (type
, sizeof (struct field
) * nfields
);
15320 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
15322 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15324 TYPE_FIELD_PRIVATE_BITS (type
) =
15325 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15326 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
15328 TYPE_FIELD_PROTECTED_BITS (type
) =
15329 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15330 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
15332 TYPE_FIELD_IGNORE_BITS (type
) =
15333 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
15334 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
15337 /* If the type has baseclasses, allocate and clear a bit vector for
15338 TYPE_FIELD_VIRTUAL_BITS. */
15339 if (!fip
->baseclasses
.empty () && cu
->language
!= language_ada
)
15341 int num_bytes
= B_BYTES (fip
->baseclasses
.size ());
15342 unsigned char *pointer
;
15344 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15345 pointer
= (unsigned char *) TYPE_ALLOC (type
, num_bytes
);
15346 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
15347 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->baseclasses
.size ());
15348 TYPE_N_BASECLASSES (type
) = fip
->baseclasses
.size ();
15351 if (TYPE_FLAG_DISCRIMINATED_UNION (type
))
15353 struct discriminant_info
*di
= alloc_discriminant_info (type
, -1, -1);
15355 for (int index
= 0; index
< nfields
; ++index
)
15357 struct nextfield
&field
= fip
->fields
[index
];
15359 if (field
.variant
.is_discriminant
)
15360 di
->discriminant_index
= index
;
15361 else if (field
.variant
.default_branch
)
15362 di
->default_index
= index
;
15364 di
->discriminants
[index
] = field
.variant
.discriminant_value
;
15368 /* Copy the saved-up fields into the field vector. */
15369 for (int i
= 0; i
< nfields
; ++i
)
15371 struct nextfield
&field
15372 = ((i
< fip
->baseclasses
.size ()) ? fip
->baseclasses
[i
]
15373 : fip
->fields
[i
- fip
->baseclasses
.size ()]);
15375 TYPE_FIELD (type
, i
) = field
.field
;
15376 switch (field
.accessibility
)
15378 case DW_ACCESS_private
:
15379 if (cu
->language
!= language_ada
)
15380 SET_TYPE_FIELD_PRIVATE (type
, i
);
15383 case DW_ACCESS_protected
:
15384 if (cu
->language
!= language_ada
)
15385 SET_TYPE_FIELD_PROTECTED (type
, i
);
15388 case DW_ACCESS_public
:
15392 /* Unknown accessibility. Complain and treat it as public. */
15394 complaint (_("unsupported accessibility %d"),
15395 field
.accessibility
);
15399 if (i
< fip
->baseclasses
.size ())
15401 switch (field
.virtuality
)
15403 case DW_VIRTUALITY_virtual
:
15404 case DW_VIRTUALITY_pure_virtual
:
15405 if (cu
->language
== language_ada
)
15406 error (_("unexpected virtuality in component of Ada type"));
15407 SET_TYPE_FIELD_VIRTUAL (type
, i
);
15414 /* Return true if this member function is a constructor, false
15418 dwarf2_is_constructor (struct die_info
*die
, struct dwarf2_cu
*cu
)
15420 const char *fieldname
;
15421 const char *type_name
;
15424 if (die
->parent
== NULL
)
15427 if (die
->parent
->tag
!= DW_TAG_structure_type
15428 && die
->parent
->tag
!= DW_TAG_union_type
15429 && die
->parent
->tag
!= DW_TAG_class_type
)
15432 fieldname
= dwarf2_name (die
, cu
);
15433 type_name
= dwarf2_name (die
->parent
, cu
);
15434 if (fieldname
== NULL
|| type_name
== NULL
)
15437 len
= strlen (fieldname
);
15438 return (strncmp (fieldname
, type_name
, len
) == 0
15439 && (type_name
[len
] == '\0' || type_name
[len
] == '<'));
15442 /* Check if the given VALUE is a recognized enum
15443 dwarf_defaulted_attribute constant according to DWARF5 spec,
15447 is_valid_DW_AT_defaulted (ULONGEST value
)
15451 case DW_DEFAULTED_no
:
15452 case DW_DEFAULTED_in_class
:
15453 case DW_DEFAULTED_out_of_class
:
15457 complaint (_("unrecognized DW_AT_defaulted value (%s)"), pulongest (value
));
15461 /* Add a member function to the proper fieldlist. */
15464 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
15465 struct type
*type
, struct dwarf2_cu
*cu
)
15467 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15468 struct attribute
*attr
;
15470 struct fnfieldlist
*flp
= nullptr;
15471 struct fn_field
*fnp
;
15472 const char *fieldname
;
15473 struct type
*this_type
;
15474 enum dwarf_access_attribute accessibility
;
15476 if (cu
->language
== language_ada
)
15477 error (_("unexpected member function in Ada type"));
15479 /* Get name of member function. */
15480 fieldname
= dwarf2_name (die
, cu
);
15481 if (fieldname
== NULL
)
15484 /* Look up member function name in fieldlist. */
15485 for (i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15487 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
15489 flp
= &fip
->fnfieldlists
[i
];
15494 /* Create a new fnfieldlist if necessary. */
15495 if (flp
== nullptr)
15497 fip
->fnfieldlists
.emplace_back ();
15498 flp
= &fip
->fnfieldlists
.back ();
15499 flp
->name
= fieldname
;
15500 i
= fip
->fnfieldlists
.size () - 1;
15503 /* Create a new member function field and add it to the vector of
15505 flp
->fnfields
.emplace_back ();
15506 fnp
= &flp
->fnfields
.back ();
15508 /* Delay processing of the physname until later. */
15509 if (cu
->language
== language_cplus
)
15510 add_to_method_list (type
, i
, flp
->fnfields
.size () - 1, fieldname
,
15514 const char *physname
= dwarf2_physname (fieldname
, die
, cu
);
15515 fnp
->physname
= physname
? physname
: "";
15518 fnp
->type
= alloc_type (objfile
);
15519 this_type
= read_type_die (die
, cu
);
15520 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
15522 int nparams
= TYPE_NFIELDS (this_type
);
15524 /* TYPE is the domain of this method, and THIS_TYPE is the type
15525 of the method itself (TYPE_CODE_METHOD). */
15526 smash_to_method_type (fnp
->type
, type
,
15527 TYPE_TARGET_TYPE (this_type
),
15528 TYPE_FIELDS (this_type
),
15529 TYPE_NFIELDS (this_type
),
15530 TYPE_VARARGS (this_type
));
15532 /* Handle static member functions.
15533 Dwarf2 has no clean way to discern C++ static and non-static
15534 member functions. G++ helps GDB by marking the first
15535 parameter for non-static member functions (which is the this
15536 pointer) as artificial. We obtain this information from
15537 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
15538 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
15539 fnp
->voffset
= VOFFSET_STATIC
;
15542 complaint (_("member function type missing for '%s'"),
15543 dwarf2_full_name (fieldname
, die
, cu
));
15545 /* Get fcontext from DW_AT_containing_type if present. */
15546 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
15547 fnp
->fcontext
= die_containing_type (die
, cu
);
15549 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
15550 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
15552 /* Get accessibility. */
15553 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
15554 if (attr
!= nullptr)
15555 accessibility
= (enum dwarf_access_attribute
) DW_UNSND (attr
);
15557 accessibility
= dwarf2_default_access_attribute (die
, cu
);
15558 switch (accessibility
)
15560 case DW_ACCESS_private
:
15561 fnp
->is_private
= 1;
15563 case DW_ACCESS_protected
:
15564 fnp
->is_protected
= 1;
15568 /* Check for artificial methods. */
15569 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
15570 if (attr
&& DW_UNSND (attr
) != 0)
15571 fnp
->is_artificial
= 1;
15573 /* Check for defaulted methods. */
15574 attr
= dwarf2_attr (die
, DW_AT_defaulted
, cu
);
15575 if (attr
!= nullptr && is_valid_DW_AT_defaulted (DW_UNSND (attr
)))
15576 fnp
->defaulted
= (enum dwarf_defaulted_attribute
) DW_UNSND (attr
);
15578 /* Check for deleted methods. */
15579 attr
= dwarf2_attr (die
, DW_AT_deleted
, cu
);
15580 if (attr
!= nullptr && DW_UNSND (attr
) != 0)
15581 fnp
->is_deleted
= 1;
15583 fnp
->is_constructor
= dwarf2_is_constructor (die
, cu
);
15585 /* Get index in virtual function table if it is a virtual member
15586 function. For older versions of GCC, this is an offset in the
15587 appropriate virtual table, as specified by DW_AT_containing_type.
15588 For everyone else, it is an expression to be evaluated relative
15589 to the object address. */
15591 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
15592 if (attr
!= nullptr)
15594 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
15596 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
15598 /* Old-style GCC. */
15599 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
15601 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
15602 || (DW_BLOCK (attr
)->size
> 1
15603 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
15604 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
15606 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
15607 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
15608 dwarf2_complex_location_expr_complaint ();
15610 fnp
->voffset
/= cu
->header
.addr_size
;
15614 dwarf2_complex_location_expr_complaint ();
15616 if (!fnp
->fcontext
)
15618 /* If there is no `this' field and no DW_AT_containing_type,
15619 we cannot actually find a base class context for the
15621 if (TYPE_NFIELDS (this_type
) == 0
15622 || !TYPE_FIELD_ARTIFICIAL (this_type
, 0))
15624 complaint (_("cannot determine context for virtual member "
15625 "function \"%s\" (offset %s)"),
15626 fieldname
, sect_offset_str (die
->sect_off
));
15631 = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
15635 else if (attr_form_is_section_offset (attr
))
15637 dwarf2_complex_location_expr_complaint ();
15641 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
15647 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
15648 if (attr
&& DW_UNSND (attr
))
15650 /* GCC does this, as of 2008-08-25; PR debug/37237. */
15651 complaint (_("Member function \"%s\" (offset %s) is virtual "
15652 "but the vtable offset is not specified"),
15653 fieldname
, sect_offset_str (die
->sect_off
));
15654 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15655 TYPE_CPLUS_DYNAMIC (type
) = 1;
15660 /* Create the vector of member function fields, and attach it to the type. */
15663 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
15664 struct dwarf2_cu
*cu
)
15666 if (cu
->language
== language_ada
)
15667 error (_("unexpected member functions in Ada type"));
15669 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15670 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
15672 sizeof (struct fn_fieldlist
) * fip
->fnfieldlists
.size ());
15674 for (int i
= 0; i
< fip
->fnfieldlists
.size (); i
++)
15676 struct fnfieldlist
&nf
= fip
->fnfieldlists
[i
];
15677 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
15679 TYPE_FN_FIELDLIST_NAME (type
, i
) = nf
.name
;
15680 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = nf
.fnfields
.size ();
15681 fn_flp
->fn_fields
= (struct fn_field
*)
15682 TYPE_ALLOC (type
, sizeof (struct fn_field
) * nf
.fnfields
.size ());
15684 for (int k
= 0; k
< nf
.fnfields
.size (); ++k
)
15685 fn_flp
->fn_fields
[k
] = nf
.fnfields
[k
];
15688 TYPE_NFN_FIELDS (type
) = fip
->fnfieldlists
.size ();
15691 /* Returns non-zero if NAME is the name of a vtable member in CU's
15692 language, zero otherwise. */
15694 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
15696 static const char vptr
[] = "_vptr";
15698 /* Look for the C++ form of the vtable. */
15699 if (startswith (name
, vptr
) && is_cplus_marker (name
[sizeof (vptr
) - 1]))
15705 /* GCC outputs unnamed structures that are really pointers to member
15706 functions, with the ABI-specified layout. If TYPE describes
15707 such a structure, smash it into a member function type.
15709 GCC shouldn't do this; it should just output pointer to member DIEs.
15710 This is GCC PR debug/28767. */
15713 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
15715 struct type
*pfn_type
, *self_type
, *new_type
;
15717 /* Check for a structure with no name and two children. */
15718 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
15721 /* Check for __pfn and __delta members. */
15722 if (TYPE_FIELD_NAME (type
, 0) == NULL
15723 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
15724 || TYPE_FIELD_NAME (type
, 1) == NULL
15725 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
15728 /* Find the type of the method. */
15729 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
15730 if (pfn_type
== NULL
15731 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
15732 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
15735 /* Look for the "this" argument. */
15736 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
15737 if (TYPE_NFIELDS (pfn_type
) == 0
15738 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
15739 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
15742 self_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
15743 new_type
= alloc_type (objfile
);
15744 smash_to_method_type (new_type
, self_type
, TYPE_TARGET_TYPE (pfn_type
),
15745 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
15746 TYPE_VARARGS (pfn_type
));
15747 smash_to_methodptr_type (type
, new_type
);
15750 /* If the DIE has a DW_AT_alignment attribute, return its value, doing
15751 appropriate error checking and issuing complaints if there is a
15755 get_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
)
15757 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_alignment
, cu
);
15759 if (attr
== nullptr)
15762 if (!attr_form_is_constant (attr
))
15764 complaint (_("DW_AT_alignment must have constant form"
15765 " - DIE at %s [in module %s]"),
15766 sect_offset_str (die
->sect_off
),
15767 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15772 if (attr
->form
== DW_FORM_sdata
)
15774 LONGEST val
= DW_SND (attr
);
15777 complaint (_("DW_AT_alignment value must not be negative"
15778 " - DIE at %s [in module %s]"),
15779 sect_offset_str (die
->sect_off
),
15780 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15786 align
= DW_UNSND (attr
);
15790 complaint (_("DW_AT_alignment value must not be zero"
15791 " - DIE at %s [in module %s]"),
15792 sect_offset_str (die
->sect_off
),
15793 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15796 if ((align
& (align
- 1)) != 0)
15798 complaint (_("DW_AT_alignment value must be a power of 2"
15799 " - DIE at %s [in module %s]"),
15800 sect_offset_str (die
->sect_off
),
15801 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15808 /* If the DIE has a DW_AT_alignment attribute, use its value to set
15809 the alignment for TYPE. */
15812 maybe_set_alignment (struct dwarf2_cu
*cu
, struct die_info
*die
,
15815 if (!set_type_align (type
, get_alignment (cu
, die
)))
15816 complaint (_("DW_AT_alignment value too large"
15817 " - DIE at %s [in module %s]"),
15818 sect_offset_str (die
->sect_off
),
15819 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
15822 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15823 constant for a type, according to DWARF5 spec, Table 5.5. */
15826 is_valid_DW_AT_calling_convention_for_type (ULONGEST value
)
15831 case DW_CC_pass_by_reference
:
15832 case DW_CC_pass_by_value
:
15836 complaint (_("unrecognized DW_AT_calling_convention value "
15837 "(%s) for a type"), pulongest (value
));
15842 /* Check if the given VALUE is a valid enum dwarf_calling_convention
15843 constant for a subroutine, according to DWARF5 spec, Table 3.3, and
15844 also according to GNU-specific values (see include/dwarf2.h). */
15847 is_valid_DW_AT_calling_convention_for_subroutine (ULONGEST value
)
15852 case DW_CC_program
:
15856 case DW_CC_GNU_renesas_sh
:
15857 case DW_CC_GNU_borland_fastcall_i386
:
15858 case DW_CC_GDB_IBM_OpenCL
:
15862 complaint (_("unrecognized DW_AT_calling_convention value "
15863 "(%s) for a subroutine"), pulongest (value
));
15868 /* Called when we find the DIE that starts a structure or union scope
15869 (definition) to create a type for the structure or union. Fill in
15870 the type's name and general properties; the members will not be
15871 processed until process_structure_scope. A symbol table entry for
15872 the type will also not be done until process_structure_scope (assuming
15873 the type has a name).
15875 NOTE: we need to call these functions regardless of whether or not the
15876 DIE has a DW_AT_name attribute, since it might be an anonymous
15877 structure or union. This gets the type entered into our set of
15878 user defined types. */
15880 static struct type
*
15881 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15883 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
15885 struct attribute
*attr
;
15888 /* If the definition of this type lives in .debug_types, read that type.
15889 Don't follow DW_AT_specification though, that will take us back up
15890 the chain and we want to go down. */
15891 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
15892 if (attr
!= nullptr)
15894 type
= get_DW_AT_signature_type (die
, attr
, cu
);
15896 /* The type's CU may not be the same as CU.
15897 Ensure TYPE is recorded with CU in die_type_hash. */
15898 return set_die_type (die
, type
, cu
);
15901 type
= alloc_type (objfile
);
15902 INIT_CPLUS_SPECIFIC (type
);
15904 name
= dwarf2_name (die
, cu
);
15907 if (cu
->language
== language_cplus
15908 || cu
->language
== language_d
15909 || cu
->language
== language_rust
)
15911 const char *full_name
= dwarf2_full_name (name
, die
, cu
);
15913 /* dwarf2_full_name might have already finished building the DIE's
15914 type. If so, there is no need to continue. */
15915 if (get_die_type (die
, cu
) != NULL
)
15916 return get_die_type (die
, cu
);
15918 TYPE_NAME (type
) = full_name
;
15922 /* The name is already allocated along with this objfile, so
15923 we don't need to duplicate it for the type. */
15924 TYPE_NAME (type
) = name
;
15928 if (die
->tag
== DW_TAG_structure_type
)
15930 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15932 else if (die
->tag
== DW_TAG_union_type
)
15934 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15936 else if (die
->tag
== DW_TAG_variant_part
)
15938 TYPE_CODE (type
) = TYPE_CODE_UNION
;
15939 TYPE_FLAG_DISCRIMINATED_UNION (type
) = 1;
15943 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
15946 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
15947 TYPE_DECLARED_CLASS (type
) = 1;
15949 /* Store the calling convention in the type if it's available in
15950 the die. Otherwise the calling convention remains set to
15951 the default value DW_CC_normal. */
15952 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
15953 if (attr
!= nullptr
15954 && is_valid_DW_AT_calling_convention_for_type (DW_UNSND (attr
)))
15956 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
15957 TYPE_CPLUS_CALLING_CONVENTION (type
)
15958 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
15961 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
15962 if (attr
!= nullptr)
15964 if (attr_form_is_constant (attr
))
15965 TYPE_LENGTH (type
) = DW_UNSND (attr
);
15968 /* For the moment, dynamic type sizes are not supported
15969 by GDB's struct type. The actual size is determined
15970 on-demand when resolving the type of a given object,
15971 so set the type's length to zero for now. Otherwise,
15972 we record an expression as the length, and that expression
15973 could lead to a very large value, which could eventually
15974 lead to us trying to allocate that much memory when creating
15975 a value of that type. */
15976 TYPE_LENGTH (type
) = 0;
15981 TYPE_LENGTH (type
) = 0;
15984 maybe_set_alignment (cu
, die
, type
);
15986 if (producer_is_icc_lt_14 (cu
) && (TYPE_LENGTH (type
) == 0))
15988 /* ICC<14 does not output the required DW_AT_declaration on
15989 incomplete types, but gives them a size of zero. */
15990 TYPE_STUB (type
) = 1;
15993 TYPE_STUB_SUPPORTED (type
) = 1;
15995 if (die_is_declaration (die
, cu
))
15996 TYPE_STUB (type
) = 1;
15997 else if (attr
== NULL
&& die
->child
== NULL
15998 && producer_is_realview (cu
->producer
))
15999 /* RealView does not output the required DW_AT_declaration
16000 on incomplete types. */
16001 TYPE_STUB (type
) = 1;
16003 /* We need to add the type field to the die immediately so we don't
16004 infinitely recurse when dealing with pointers to the structure
16005 type within the structure itself. */
16006 set_die_type (die
, type
, cu
);
16008 /* set_die_type should be already done. */
16009 set_descriptive_type (type
, die
, cu
);
16014 /* A helper for process_structure_scope that handles a single member
16018 handle_struct_member_die (struct die_info
*child_die
, struct type
*type
,
16019 struct field_info
*fi
,
16020 std::vector
<struct symbol
*> *template_args
,
16021 struct dwarf2_cu
*cu
)
16023 if (child_die
->tag
== DW_TAG_member
16024 || child_die
->tag
== DW_TAG_variable
16025 || child_die
->tag
== DW_TAG_variant_part
)
16027 /* NOTE: carlton/2002-11-05: A C++ static data member
16028 should be a DW_TAG_member that is a declaration, but
16029 all versions of G++ as of this writing (so through at
16030 least 3.2.1) incorrectly generate DW_TAG_variable
16031 tags for them instead. */
16032 dwarf2_add_field (fi
, child_die
, cu
);
16034 else if (child_die
->tag
== DW_TAG_subprogram
)
16036 /* Rust doesn't have member functions in the C++ sense.
16037 However, it does emit ordinary functions as children
16038 of a struct DIE. */
16039 if (cu
->language
== language_rust
)
16040 read_func_scope (child_die
, cu
);
16043 /* C++ member function. */
16044 dwarf2_add_member_fn (fi
, child_die
, type
, cu
);
16047 else if (child_die
->tag
== DW_TAG_inheritance
)
16049 /* C++ base class field. */
16050 dwarf2_add_field (fi
, child_die
, cu
);
16052 else if (type_can_define_types (child_die
))
16053 dwarf2_add_type_defn (fi
, child_die
, cu
);
16054 else if (child_die
->tag
== DW_TAG_template_type_param
16055 || child_die
->tag
== DW_TAG_template_value_param
)
16057 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
16060 template_args
->push_back (arg
);
16062 else if (child_die
->tag
== DW_TAG_variant
)
16064 /* In a variant we want to get the discriminant and also add a
16065 field for our sole member child. */
16066 struct attribute
*discr
= dwarf2_attr (child_die
, DW_AT_discr_value
, cu
);
16068 for (die_info
*variant_child
= child_die
->child
;
16069 variant_child
!= NULL
;
16070 variant_child
= sibling_die (variant_child
))
16072 if (variant_child
->tag
== DW_TAG_member
)
16074 handle_struct_member_die (variant_child
, type
, fi
,
16075 template_args
, cu
);
16076 /* Only handle the one. */
16081 /* We don't handle this but we might as well report it if we see
16083 if (dwarf2_attr (child_die
, DW_AT_discr_list
, cu
) != nullptr)
16084 complaint (_("DW_AT_discr_list is not supported yet"
16085 " - DIE at %s [in module %s]"),
16086 sect_offset_str (child_die
->sect_off
),
16087 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16089 /* The first field was just added, so we can stash the
16090 discriminant there. */
16091 gdb_assert (!fi
->fields
.empty ());
16093 fi
->fields
.back ().variant
.default_branch
= true;
16095 fi
->fields
.back ().variant
.discriminant_value
= DW_UNSND (discr
);
16099 /* Finish creating a structure or union type, including filling in
16100 its members and creating a symbol for it. */
16103 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16105 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16106 struct die_info
*child_die
;
16109 type
= get_die_type (die
, cu
);
16111 type
= read_structure_type (die
, cu
);
16113 /* When reading a DW_TAG_variant_part, we need to notice when we
16114 read the discriminant member, so we can record it later in the
16115 discriminant_info. */
16116 bool is_variant_part
= TYPE_FLAG_DISCRIMINATED_UNION (type
);
16117 sect_offset discr_offset
{};
16118 bool has_template_parameters
= false;
16120 if (is_variant_part
)
16122 struct attribute
*discr
= dwarf2_attr (die
, DW_AT_discr
, cu
);
16125 /* Maybe it's a univariant form, an extension we support.
16126 In this case arrange not to check the offset. */
16127 is_variant_part
= false;
16129 else if (attr_form_is_ref (discr
))
16131 struct dwarf2_cu
*target_cu
= cu
;
16132 struct die_info
*target_die
= follow_die_ref (die
, discr
, &target_cu
);
16134 discr_offset
= target_die
->sect_off
;
16138 complaint (_("DW_AT_discr does not have DIE reference form"
16139 " - DIE at %s [in module %s]"),
16140 sect_offset_str (die
->sect_off
),
16141 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16142 is_variant_part
= false;
16146 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
16148 struct field_info fi
;
16149 std::vector
<struct symbol
*> template_args
;
16151 child_die
= die
->child
;
16153 while (child_die
&& child_die
->tag
)
16155 handle_struct_member_die (child_die
, type
, &fi
, &template_args
, cu
);
16157 if (is_variant_part
&& discr_offset
== child_die
->sect_off
)
16158 fi
.fields
.back ().variant
.is_discriminant
= true;
16160 child_die
= sibling_die (child_die
);
16163 /* Attach template arguments to type. */
16164 if (!template_args
.empty ())
16166 has_template_parameters
= true;
16167 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16168 TYPE_N_TEMPLATE_ARGUMENTS (type
) = template_args
.size ();
16169 TYPE_TEMPLATE_ARGUMENTS (type
)
16170 = XOBNEWVEC (&objfile
->objfile_obstack
,
16172 TYPE_N_TEMPLATE_ARGUMENTS (type
));
16173 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
16174 template_args
.data (),
16175 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
16176 * sizeof (struct symbol
*)));
16179 /* Attach fields and member functions to the type. */
16181 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
16182 if (!fi
.fnfieldlists
.empty ())
16184 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
16186 /* Get the type which refers to the base class (possibly this
16187 class itself) which contains the vtable pointer for the current
16188 class from the DW_AT_containing_type attribute. This use of
16189 DW_AT_containing_type is a GNU extension. */
16191 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
16193 struct type
*t
= die_containing_type (die
, cu
);
16195 set_type_vptr_basetype (type
, t
);
16200 /* Our own class provides vtbl ptr. */
16201 for (i
= TYPE_NFIELDS (t
) - 1;
16202 i
>= TYPE_N_BASECLASSES (t
);
16205 const char *fieldname
= TYPE_FIELD_NAME (t
, i
);
16207 if (is_vtable_name (fieldname
, cu
))
16209 set_type_vptr_fieldno (type
, i
);
16214 /* Complain if virtual function table field not found. */
16215 if (i
< TYPE_N_BASECLASSES (t
))
16216 complaint (_("virtual function table pointer "
16217 "not found when defining class '%s'"),
16218 TYPE_NAME (type
) ? TYPE_NAME (type
) : "");
16222 set_type_vptr_fieldno (type
, TYPE_VPTR_FIELDNO (t
));
16225 else if (cu
->producer
16226 && startswith (cu
->producer
, "IBM(R) XL C/C++ Advanced Edition"))
16228 /* The IBM XLC compiler does not provide direct indication
16229 of the containing type, but the vtable pointer is
16230 always named __vfp. */
16234 for (i
= TYPE_NFIELDS (type
) - 1;
16235 i
>= TYPE_N_BASECLASSES (type
);
16238 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
16240 set_type_vptr_fieldno (type
, i
);
16241 set_type_vptr_basetype (type
, type
);
16248 /* Copy fi.typedef_field_list linked list elements content into the
16249 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
16250 if (!fi
.typedef_field_list
.empty ())
16252 int count
= fi
.typedef_field_list
.size ();
16254 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16255 TYPE_TYPEDEF_FIELD_ARRAY (type
)
16256 = ((struct decl_field
*)
16258 sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * count
));
16259 TYPE_TYPEDEF_FIELD_COUNT (type
) = count
;
16261 for (int i
= 0; i
< fi
.typedef_field_list
.size (); ++i
)
16262 TYPE_TYPEDEF_FIELD (type
, i
) = fi
.typedef_field_list
[i
];
16265 /* Copy fi.nested_types_list linked list elements content into the
16266 allocated array TYPE_NESTED_TYPES_ARRAY (type). */
16267 if (!fi
.nested_types_list
.empty () && cu
->language
!= language_ada
)
16269 int count
= fi
.nested_types_list
.size ();
16271 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
16272 TYPE_NESTED_TYPES_ARRAY (type
)
16273 = ((struct decl_field
*)
16274 TYPE_ALLOC (type
, sizeof (struct decl_field
) * count
));
16275 TYPE_NESTED_TYPES_COUNT (type
) = count
;
16277 for (int i
= 0; i
< fi
.nested_types_list
.size (); ++i
)
16278 TYPE_NESTED_TYPES_FIELD (type
, i
) = fi
.nested_types_list
[i
];
16282 quirk_gcc_member_function_pointer (type
, objfile
);
16283 if (cu
->language
== language_rust
&& die
->tag
== DW_TAG_union_type
)
16284 cu
->rust_unions
.push_back (type
);
16286 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
16287 snapshots) has been known to create a die giving a declaration
16288 for a class that has, as a child, a die giving a definition for a
16289 nested class. So we have to process our children even if the
16290 current die is a declaration. Normally, of course, a declaration
16291 won't have any children at all. */
16293 child_die
= die
->child
;
16295 while (child_die
!= NULL
&& child_die
->tag
)
16297 if (child_die
->tag
== DW_TAG_member
16298 || child_die
->tag
== DW_TAG_variable
16299 || child_die
->tag
== DW_TAG_inheritance
16300 || child_die
->tag
== DW_TAG_template_value_param
16301 || child_die
->tag
== DW_TAG_template_type_param
)
16306 process_die (child_die
, cu
);
16308 child_die
= sibling_die (child_die
);
16311 /* Do not consider external references. According to the DWARF standard,
16312 these DIEs are identified by the fact that they have no byte_size
16313 attribute, and a declaration attribute. */
16314 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
16315 || !die_is_declaration (die
, cu
))
16317 struct symbol
*sym
= new_symbol (die
, type
, cu
);
16319 if (has_template_parameters
)
16321 struct symtab
*symtab
;
16322 if (sym
!= nullptr)
16323 symtab
= symbol_symtab (sym
);
16324 else if (cu
->line_header
!= nullptr)
16326 /* Any related symtab will do. */
16328 = cu
->line_header
->file_names ()[0].symtab
;
16333 complaint (_("could not find suitable "
16334 "symtab for template parameter"
16335 " - DIE at %s [in module %s]"),
16336 sect_offset_str (die
->sect_off
),
16337 objfile_name (objfile
));
16340 if (symtab
!= nullptr)
16342 /* Make sure that the symtab is set on the new symbols.
16343 Even though they don't appear in this symtab directly,
16344 other parts of gdb assume that symbols do, and this is
16345 reasonably true. */
16346 for (int i
= 0; i
< TYPE_N_TEMPLATE_ARGUMENTS (type
); ++i
)
16347 symbol_set_symtab (TYPE_TEMPLATE_ARGUMENT (type
, i
), symtab
);
16353 /* Assuming DIE is an enumeration type, and TYPE is its associated type,
16354 update TYPE using some information only available in DIE's children. */
16357 update_enumeration_type_from_children (struct die_info
*die
,
16359 struct dwarf2_cu
*cu
)
16361 struct die_info
*child_die
;
16362 int unsigned_enum
= 1;
16366 auto_obstack obstack
;
16368 for (child_die
= die
->child
;
16369 child_die
!= NULL
&& child_die
->tag
;
16370 child_die
= sibling_die (child_die
))
16372 struct attribute
*attr
;
16374 const gdb_byte
*bytes
;
16375 struct dwarf2_locexpr_baton
*baton
;
16378 if (child_die
->tag
!= DW_TAG_enumerator
)
16381 attr
= dwarf2_attr (child_die
, DW_AT_const_value
, cu
);
16385 name
= dwarf2_name (child_die
, cu
);
16387 name
= "<anonymous enumerator>";
16389 dwarf2_const_value_attr (attr
, type
, name
, &obstack
, cu
,
16390 &value
, &bytes
, &baton
);
16396 else if ((mask
& value
) != 0)
16401 /* If we already know that the enum type is neither unsigned, nor
16402 a flag type, no need to look at the rest of the enumerates. */
16403 if (!unsigned_enum
&& !flag_enum
)
16408 TYPE_UNSIGNED (type
) = 1;
16410 TYPE_FLAG_ENUM (type
) = 1;
16413 /* Given a DW_AT_enumeration_type die, set its type. We do not
16414 complete the type's fields yet, or create any symbols. */
16416 static struct type
*
16417 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16419 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16421 struct attribute
*attr
;
16424 /* If the definition of this type lives in .debug_types, read that type.
16425 Don't follow DW_AT_specification though, that will take us back up
16426 the chain and we want to go down. */
16427 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
);
16428 if (attr
!= nullptr)
16430 type
= get_DW_AT_signature_type (die
, attr
, cu
);
16432 /* The type's CU may not be the same as CU.
16433 Ensure TYPE is recorded with CU in die_type_hash. */
16434 return set_die_type (die
, type
, cu
);
16437 type
= alloc_type (objfile
);
16439 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
16440 name
= dwarf2_full_name (NULL
, die
, cu
);
16442 TYPE_NAME (type
) = name
;
16444 attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
16447 struct type
*underlying_type
= die_type (die
, cu
);
16449 TYPE_TARGET_TYPE (type
) = underlying_type
;
16452 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16453 if (attr
!= nullptr)
16455 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16459 TYPE_LENGTH (type
) = 0;
16462 maybe_set_alignment (cu
, die
, type
);
16464 /* The enumeration DIE can be incomplete. In Ada, any type can be
16465 declared as private in the package spec, and then defined only
16466 inside the package body. Such types are known as Taft Amendment
16467 Types. When another package uses such a type, an incomplete DIE
16468 may be generated by the compiler. */
16469 if (die_is_declaration (die
, cu
))
16470 TYPE_STUB (type
) = 1;
16472 /* Finish the creation of this type by using the enum's children.
16473 We must call this even when the underlying type has been provided
16474 so that we can determine if we're looking at a "flag" enum. */
16475 update_enumeration_type_from_children (die
, type
, cu
);
16477 /* If this type has an underlying type that is not a stub, then we
16478 may use its attributes. We always use the "unsigned" attribute
16479 in this situation, because ordinarily we guess whether the type
16480 is unsigned -- but the guess can be wrong and the underlying type
16481 can tell us the reality. However, we defer to a local size
16482 attribute if one exists, because this lets the compiler override
16483 the underlying type if needed. */
16484 if (TYPE_TARGET_TYPE (type
) != NULL
&& !TYPE_STUB (TYPE_TARGET_TYPE (type
)))
16486 TYPE_UNSIGNED (type
) = TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
));
16487 if (TYPE_LENGTH (type
) == 0)
16488 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
));
16489 if (TYPE_RAW_ALIGN (type
) == 0
16490 && TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)) != 0)
16491 set_type_align (type
, TYPE_RAW_ALIGN (TYPE_TARGET_TYPE (type
)));
16494 TYPE_DECLARED_CLASS (type
) = dwarf2_flag_true_p (die
, DW_AT_enum_class
, cu
);
16496 return set_die_type (die
, type
, cu
);
16499 /* Given a pointer to a die which begins an enumeration, process all
16500 the dies that define the members of the enumeration, and create the
16501 symbol for the enumeration type.
16503 NOTE: We reverse the order of the element list. */
16506 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
16508 struct type
*this_type
;
16510 this_type
= get_die_type (die
, cu
);
16511 if (this_type
== NULL
)
16512 this_type
= read_enumeration_type (die
, cu
);
16514 if (die
->child
!= NULL
)
16516 struct die_info
*child_die
;
16517 struct symbol
*sym
;
16518 std::vector
<struct field
> fields
;
16521 child_die
= die
->child
;
16522 while (child_die
&& child_die
->tag
)
16524 if (child_die
->tag
!= DW_TAG_enumerator
)
16526 process_die (child_die
, cu
);
16530 name
= dwarf2_name (child_die
, cu
);
16533 sym
= new_symbol (child_die
, this_type
, cu
);
16535 fields
.emplace_back ();
16536 struct field
&field
= fields
.back ();
16538 FIELD_NAME (field
) = sym
->linkage_name ();
16539 FIELD_TYPE (field
) = NULL
;
16540 SET_FIELD_ENUMVAL (field
, SYMBOL_VALUE (sym
));
16541 FIELD_BITSIZE (field
) = 0;
16545 child_die
= sibling_die (child_die
);
16548 if (!fields
.empty ())
16550 TYPE_NFIELDS (this_type
) = fields
.size ();
16551 TYPE_FIELDS (this_type
) = (struct field
*)
16552 TYPE_ALLOC (this_type
, sizeof (struct field
) * fields
.size ());
16553 memcpy (TYPE_FIELDS (this_type
), fields
.data (),
16554 sizeof (struct field
) * fields
.size ());
16558 /* If we are reading an enum from a .debug_types unit, and the enum
16559 is a declaration, and the enum is not the signatured type in the
16560 unit, then we do not want to add a symbol for it. Adding a
16561 symbol would in some cases obscure the true definition of the
16562 enum, giving users an incomplete type when the definition is
16563 actually available. Note that we do not want to do this for all
16564 enums which are just declarations, because C++0x allows forward
16565 enum declarations. */
16566 if (cu
->per_cu
->is_debug_types
16567 && die_is_declaration (die
, cu
))
16569 struct signatured_type
*sig_type
;
16571 sig_type
= (struct signatured_type
*) cu
->per_cu
;
16572 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
16573 if (sig_type
->type_offset_in_section
!= die
->sect_off
)
16577 new_symbol (die
, this_type
, cu
);
16580 /* Extract all information from a DW_TAG_array_type DIE and put it in
16581 the DIE's type field. For now, this only handles one dimensional
16584 static struct type
*
16585 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16587 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16588 struct die_info
*child_die
;
16590 struct type
*element_type
, *range_type
, *index_type
;
16591 struct attribute
*attr
;
16593 struct dynamic_prop
*byte_stride_prop
= NULL
;
16594 unsigned int bit_stride
= 0;
16596 element_type
= die_type (die
, cu
);
16598 /* The die_type call above may have already set the type for this DIE. */
16599 type
= get_die_type (die
, cu
);
16603 attr
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
16607 struct type
*prop_type
16608 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
16611 = (struct dynamic_prop
*) alloca (sizeof (struct dynamic_prop
));
16612 stride_ok
= attr_to_dynamic_prop (attr
, die
, cu
, byte_stride_prop
,
16616 complaint (_("unable to read array DW_AT_byte_stride "
16617 " - DIE at %s [in module %s]"),
16618 sect_offset_str (die
->sect_off
),
16619 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
16620 /* Ignore this attribute. We will likely not be able to print
16621 arrays of this type correctly, but there is little we can do
16622 to help if we cannot read the attribute's value. */
16623 byte_stride_prop
= NULL
;
16627 attr
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
16629 bit_stride
= DW_UNSND (attr
);
16631 /* Irix 6.2 native cc creates array types without children for
16632 arrays with unspecified length. */
16633 if (die
->child
== NULL
)
16635 index_type
= objfile_type (objfile
)->builtin_int
;
16636 range_type
= create_static_range_type (NULL
, index_type
, 0, -1);
16637 type
= create_array_type_with_stride (NULL
, element_type
, range_type
,
16638 byte_stride_prop
, bit_stride
);
16639 return set_die_type (die
, type
, cu
);
16642 std::vector
<struct type
*> range_types
;
16643 child_die
= die
->child
;
16644 while (child_die
&& child_die
->tag
)
16646 if (child_die
->tag
== DW_TAG_subrange_type
)
16648 struct type
*child_type
= read_type_die (child_die
, cu
);
16650 if (child_type
!= NULL
)
16652 /* The range type was succesfully read. Save it for the
16653 array type creation. */
16654 range_types
.push_back (child_type
);
16657 child_die
= sibling_die (child_die
);
16660 /* Dwarf2 dimensions are output from left to right, create the
16661 necessary array types in backwards order. */
16663 type
= element_type
;
16665 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
16669 while (i
< range_types
.size ())
16670 type
= create_array_type_with_stride (NULL
, type
, range_types
[i
++],
16671 byte_stride_prop
, bit_stride
);
16675 size_t ndim
= range_types
.size ();
16677 type
= create_array_type_with_stride (NULL
, type
, range_types
[ndim
],
16678 byte_stride_prop
, bit_stride
);
16681 /* Understand Dwarf2 support for vector types (like they occur on
16682 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
16683 array type. This is not part of the Dwarf2/3 standard yet, but a
16684 custom vendor extension. The main difference between a regular
16685 array and the vector variant is that vectors are passed by value
16687 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
16688 if (attr
!= nullptr)
16689 make_vector_type (type
);
16691 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
16692 implementation may choose to implement triple vectors using this
16694 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16695 if (attr
!= nullptr)
16697 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
16698 TYPE_LENGTH (type
) = DW_UNSND (attr
);
16700 complaint (_("DW_AT_byte_size for array type smaller "
16701 "than the total size of elements"));
16704 name
= dwarf2_name (die
, cu
);
16706 TYPE_NAME (type
) = name
;
16708 maybe_set_alignment (cu
, die
, type
);
16710 /* Install the type in the die. */
16711 set_die_type (die
, type
, cu
);
16713 /* set_die_type should be already done. */
16714 set_descriptive_type (type
, die
, cu
);
16719 static enum dwarf_array_dim_ordering
16720 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
16722 struct attribute
*attr
;
16724 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
16726 if (attr
!= nullptr)
16727 return (enum dwarf_array_dim_ordering
) DW_SND (attr
);
16729 /* GNU F77 is a special case, as at 08/2004 array type info is the
16730 opposite order to the dwarf2 specification, but data is still
16731 laid out as per normal fortran.
16733 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
16734 version checking. */
16736 if (cu
->language
== language_fortran
16737 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
16739 return DW_ORD_row_major
;
16742 switch (cu
->language_defn
->la_array_ordering
)
16744 case array_column_major
:
16745 return DW_ORD_col_major
;
16746 case array_row_major
:
16748 return DW_ORD_row_major
;
16752 /* Extract all information from a DW_TAG_set_type DIE and put it in
16753 the DIE's type field. */
16755 static struct type
*
16756 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16758 struct type
*domain_type
, *set_type
;
16759 struct attribute
*attr
;
16761 domain_type
= die_type (die
, cu
);
16763 /* The die_type call above may have already set the type for this DIE. */
16764 set_type
= get_die_type (die
, cu
);
16768 set_type
= create_set_type (NULL
, domain_type
);
16770 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
16771 if (attr
!= nullptr)
16772 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
16774 maybe_set_alignment (cu
, die
, set_type
);
16776 return set_die_type (die
, set_type
, cu
);
16779 /* A helper for read_common_block that creates a locexpr baton.
16780 SYM is the symbol which we are marking as computed.
16781 COMMON_DIE is the DIE for the common block.
16782 COMMON_LOC is the location expression attribute for the common
16784 MEMBER_LOC is the location expression attribute for the particular
16785 member of the common block that we are processing.
16786 CU is the CU from which the above come. */
16789 mark_common_block_symbol_computed (struct symbol
*sym
,
16790 struct die_info
*common_die
,
16791 struct attribute
*common_loc
,
16792 struct attribute
*member_loc
,
16793 struct dwarf2_cu
*cu
)
16795 struct dwarf2_per_objfile
*dwarf2_per_objfile
16796 = cu
->per_cu
->dwarf2_per_objfile
;
16797 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
16798 struct dwarf2_locexpr_baton
*baton
;
16800 unsigned int cu_off
;
16801 enum bfd_endian byte_order
= gdbarch_byte_order (get_objfile_arch (objfile
));
16802 LONGEST offset
= 0;
16804 gdb_assert (common_loc
&& member_loc
);
16805 gdb_assert (attr_form_is_block (common_loc
));
16806 gdb_assert (attr_form_is_block (member_loc
)
16807 || attr_form_is_constant (member_loc
));
16809 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
16810 baton
->per_cu
= cu
->per_cu
;
16811 gdb_assert (baton
->per_cu
);
16813 baton
->size
= 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
16815 if (attr_form_is_constant (member_loc
))
16817 offset
= dwarf2_get_attr_constant_value (member_loc
, 0);
16818 baton
->size
+= 1 /* DW_OP_addr */ + cu
->header
.addr_size
;
16821 baton
->size
+= DW_BLOCK (member_loc
)->size
;
16823 ptr
= (gdb_byte
*) obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
16826 *ptr
++ = DW_OP_call4
;
16827 cu_off
= common_die
->sect_off
- cu
->per_cu
->sect_off
;
16828 store_unsigned_integer (ptr
, 4, byte_order
, cu_off
);
16831 if (attr_form_is_constant (member_loc
))
16833 *ptr
++ = DW_OP_addr
;
16834 store_unsigned_integer (ptr
, cu
->header
.addr_size
, byte_order
, offset
);
16835 ptr
+= cu
->header
.addr_size
;
16839 /* We have to copy the data here, because DW_OP_call4 will only
16840 use a DW_AT_location attribute. */
16841 memcpy (ptr
, DW_BLOCK (member_loc
)->data
, DW_BLOCK (member_loc
)->size
);
16842 ptr
+= DW_BLOCK (member_loc
)->size
;
16845 *ptr
++ = DW_OP_plus
;
16846 gdb_assert (ptr
- baton
->data
== baton
->size
);
16848 SYMBOL_LOCATION_BATON (sym
) = baton
;
16849 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
16852 /* Create appropriate locally-scoped variables for all the
16853 DW_TAG_common_block entries. Also create a struct common_block
16854 listing all such variables for `info common'. COMMON_BLOCK_DOMAIN
16855 is used to separate the common blocks name namespace from regular
16859 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
16861 struct attribute
*attr
;
16863 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
16864 if (attr
!= nullptr)
16866 /* Support the .debug_loc offsets. */
16867 if (attr_form_is_block (attr
))
16871 else if (attr_form_is_section_offset (attr
))
16873 dwarf2_complex_location_expr_complaint ();
16878 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
16879 "common block member");
16884 if (die
->child
!= NULL
)
16886 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16887 struct die_info
*child_die
;
16888 size_t n_entries
= 0, size
;
16889 struct common_block
*common_block
;
16890 struct symbol
*sym
;
16892 for (child_die
= die
->child
;
16893 child_die
&& child_die
->tag
;
16894 child_die
= sibling_die (child_die
))
16897 size
= (sizeof (struct common_block
)
16898 + (n_entries
- 1) * sizeof (struct symbol
*));
16900 = (struct common_block
*) obstack_alloc (&objfile
->objfile_obstack
,
16902 memset (common_block
->contents
, 0, n_entries
* sizeof (struct symbol
*));
16903 common_block
->n_entries
= 0;
16905 for (child_die
= die
->child
;
16906 child_die
&& child_die
->tag
;
16907 child_die
= sibling_die (child_die
))
16909 /* Create the symbol in the DW_TAG_common_block block in the current
16911 sym
= new_symbol (child_die
, NULL
, cu
);
16914 struct attribute
*member_loc
;
16916 common_block
->contents
[common_block
->n_entries
++] = sym
;
16918 member_loc
= dwarf2_attr (child_die
, DW_AT_data_member_location
,
16922 /* GDB has handled this for a long time, but it is
16923 not specified by DWARF. It seems to have been
16924 emitted by gfortran at least as recently as:
16925 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */
16926 complaint (_("Variable in common block has "
16927 "DW_AT_data_member_location "
16928 "- DIE at %s [in module %s]"),
16929 sect_offset_str (child_die
->sect_off
),
16930 objfile_name (objfile
));
16932 if (attr_form_is_section_offset (member_loc
))
16933 dwarf2_complex_location_expr_complaint ();
16934 else if (attr_form_is_constant (member_loc
)
16935 || attr_form_is_block (member_loc
))
16937 if (attr
!= nullptr)
16938 mark_common_block_symbol_computed (sym
, die
, attr
,
16942 dwarf2_complex_location_expr_complaint ();
16947 sym
= new_symbol (die
, objfile_type (objfile
)->builtin_void
, cu
);
16948 SYMBOL_VALUE_COMMON_BLOCK (sym
) = common_block
;
16952 /* Create a type for a C++ namespace. */
16954 static struct type
*
16955 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
16957 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16958 const char *previous_prefix
, *name
;
16962 /* For extensions, reuse the type of the original namespace. */
16963 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
16965 struct die_info
*ext_die
;
16966 struct dwarf2_cu
*ext_cu
= cu
;
16968 ext_die
= dwarf2_extension (die
, &ext_cu
);
16969 type
= read_type_die (ext_die
, ext_cu
);
16971 /* EXT_CU may not be the same as CU.
16972 Ensure TYPE is recorded with CU in die_type_hash. */
16973 return set_die_type (die
, type
, cu
);
16976 name
= namespace_name (die
, &is_anonymous
, cu
);
16978 /* Now build the name of the current namespace. */
16980 previous_prefix
= determine_prefix (die
, cu
);
16981 if (previous_prefix
[0] != '\0')
16982 name
= typename_concat (&objfile
->objfile_obstack
,
16983 previous_prefix
, name
, 0, cu
);
16985 /* Create the type. */
16986 type
= init_type (objfile
, TYPE_CODE_NAMESPACE
, 0, name
);
16988 return set_die_type (die
, type
, cu
);
16991 /* Read a namespace scope. */
16994 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
16996 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
16999 /* Add a symbol associated to this if we haven't seen the namespace
17000 before. Also, add a using directive if it's an anonymous
17003 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
17007 type
= read_type_die (die
, cu
);
17008 new_symbol (die
, type
, cu
);
17010 namespace_name (die
, &is_anonymous
, cu
);
17013 const char *previous_prefix
= determine_prefix (die
, cu
);
17015 std::vector
<const char *> excludes
;
17016 add_using_directive (using_directives (cu
),
17017 previous_prefix
, TYPE_NAME (type
), NULL
,
17018 NULL
, excludes
, 0, &objfile
->objfile_obstack
);
17022 if (die
->child
!= NULL
)
17024 struct die_info
*child_die
= die
->child
;
17026 while (child_die
&& child_die
->tag
)
17028 process_die (child_die
, cu
);
17029 child_die
= sibling_die (child_die
);
17034 /* Read a Fortran module as type. This DIE can be only a declaration used for
17035 imported module. Still we need that type as local Fortran "use ... only"
17036 declaration imports depend on the created type in determine_prefix. */
17038 static struct type
*
17039 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17041 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17042 const char *module_name
;
17045 module_name
= dwarf2_name (die
, cu
);
17046 type
= init_type (objfile
, TYPE_CODE_MODULE
, 0, module_name
);
17048 return set_die_type (die
, type
, cu
);
17051 /* Read a Fortran module. */
17054 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
17056 struct die_info
*child_die
= die
->child
;
17059 type
= read_type_die (die
, cu
);
17060 new_symbol (die
, type
, cu
);
17062 while (child_die
&& child_die
->tag
)
17064 process_die (child_die
, cu
);
17065 child_die
= sibling_die (child_die
);
17069 /* Return the name of the namespace represented by DIE. Set
17070 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
17073 static const char *
17074 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
17076 struct die_info
*current_die
;
17077 const char *name
= NULL
;
17079 /* Loop through the extensions until we find a name. */
17081 for (current_die
= die
;
17082 current_die
!= NULL
;
17083 current_die
= dwarf2_extension (die
, &cu
))
17085 /* We don't use dwarf2_name here so that we can detect the absence
17086 of a name -> anonymous namespace. */
17087 name
= dwarf2_string_attr (die
, DW_AT_name
, cu
);
17093 /* Is it an anonymous namespace? */
17095 *is_anonymous
= (name
== NULL
);
17097 name
= CP_ANONYMOUS_NAMESPACE_STR
;
17102 /* Extract all information from a DW_TAG_pointer_type DIE and add to
17103 the user defined type vector. */
17105 static struct type
*
17106 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17108 struct gdbarch
*gdbarch
17109 = get_objfile_arch (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17110 struct comp_unit_head
*cu_header
= &cu
->header
;
17112 struct attribute
*attr_byte_size
;
17113 struct attribute
*attr_address_class
;
17114 int byte_size
, addr_class
;
17115 struct type
*target_type
;
17117 target_type
= die_type (die
, cu
);
17119 /* The die_type call above may have already set the type for this DIE. */
17120 type
= get_die_type (die
, cu
);
17124 type
= lookup_pointer_type (target_type
);
17126 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17127 if (attr_byte_size
)
17128 byte_size
= DW_UNSND (attr_byte_size
);
17130 byte_size
= cu_header
->addr_size
;
17132 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
17133 if (attr_address_class
)
17134 addr_class
= DW_UNSND (attr_address_class
);
17136 addr_class
= DW_ADDR_none
;
17138 ULONGEST alignment
= get_alignment (cu
, die
);
17140 /* If the pointer size, alignment, or address class is different
17141 than the default, create a type variant marked as such and set
17142 the length accordingly. */
17143 if (TYPE_LENGTH (type
) != byte_size
17144 || (alignment
!= 0 && TYPE_RAW_ALIGN (type
) != 0
17145 && alignment
!= TYPE_RAW_ALIGN (type
))
17146 || addr_class
!= DW_ADDR_none
)
17148 if (gdbarch_address_class_type_flags_p (gdbarch
))
17152 type_flags
= gdbarch_address_class_type_flags
17153 (gdbarch
, byte_size
, addr_class
);
17154 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
17156 type
= make_type_with_address_space (type
, type_flags
);
17158 else if (TYPE_LENGTH (type
) != byte_size
)
17160 complaint (_("invalid pointer size %d"), byte_size
);
17162 else if (TYPE_RAW_ALIGN (type
) != alignment
)
17164 complaint (_("Invalid DW_AT_alignment"
17165 " - DIE at %s [in module %s]"),
17166 sect_offset_str (die
->sect_off
),
17167 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
17171 /* Should we also complain about unhandled address classes? */
17175 TYPE_LENGTH (type
) = byte_size
;
17176 set_type_align (type
, alignment
);
17177 return set_die_type (die
, type
, cu
);
17180 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
17181 the user defined type vector. */
17183 static struct type
*
17184 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17187 struct type
*to_type
;
17188 struct type
*domain
;
17190 to_type
= die_type (die
, cu
);
17191 domain
= die_containing_type (die
, cu
);
17193 /* The calls above may have already set the type for this DIE. */
17194 type
= get_die_type (die
, cu
);
17198 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
17199 type
= lookup_methodptr_type (to_type
);
17200 else if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_FUNC
)
17202 struct type
*new_type
17203 = alloc_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
);
17205 smash_to_method_type (new_type
, domain
, TYPE_TARGET_TYPE (to_type
),
17206 TYPE_FIELDS (to_type
), TYPE_NFIELDS (to_type
),
17207 TYPE_VARARGS (to_type
));
17208 type
= lookup_methodptr_type (new_type
);
17211 type
= lookup_memberptr_type (to_type
, domain
);
17213 return set_die_type (die
, type
, cu
);
17216 /* Extract all information from a DW_TAG_{rvalue_,}reference_type DIE and add to
17217 the user defined type vector. */
17219 static struct type
*
17220 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17221 enum type_code refcode
)
17223 struct comp_unit_head
*cu_header
= &cu
->header
;
17224 struct type
*type
, *target_type
;
17225 struct attribute
*attr
;
17227 gdb_assert (refcode
== TYPE_CODE_REF
|| refcode
== TYPE_CODE_RVALUE_REF
);
17229 target_type
= die_type (die
, cu
);
17231 /* The die_type call above may have already set the type for this DIE. */
17232 type
= get_die_type (die
, cu
);
17236 type
= lookup_reference_type (target_type
, refcode
);
17237 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17238 if (attr
!= nullptr)
17240 TYPE_LENGTH (type
) = DW_UNSND (attr
);
17244 TYPE_LENGTH (type
) = cu_header
->addr_size
;
17246 maybe_set_alignment (cu
, die
, type
);
17247 return set_die_type (die
, type
, cu
);
17250 /* Add the given cv-qualifiers to the element type of the array. GCC
17251 outputs DWARF type qualifiers that apply to an array, not the
17252 element type. But GDB relies on the array element type to carry
17253 the cv-qualifiers. This mimics section 6.7.3 of the C99
17256 static struct type
*
17257 add_array_cv_type (struct die_info
*die
, struct dwarf2_cu
*cu
,
17258 struct type
*base_type
, int cnst
, int voltl
)
17260 struct type
*el_type
, *inner_array
;
17262 base_type
= copy_type (base_type
);
17263 inner_array
= base_type
;
17265 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
17267 TYPE_TARGET_TYPE (inner_array
) =
17268 copy_type (TYPE_TARGET_TYPE (inner_array
));
17269 inner_array
= TYPE_TARGET_TYPE (inner_array
);
17272 el_type
= TYPE_TARGET_TYPE (inner_array
);
17273 cnst
|= TYPE_CONST (el_type
);
17274 voltl
|= TYPE_VOLATILE (el_type
);
17275 TYPE_TARGET_TYPE (inner_array
) = make_cv_type (cnst
, voltl
, el_type
, NULL
);
17277 return set_die_type (die
, base_type
, cu
);
17280 static struct type
*
17281 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17283 struct type
*base_type
, *cv_type
;
17285 base_type
= die_type (die
, cu
);
17287 /* The die_type call above may have already set the type for this DIE. */
17288 cv_type
= get_die_type (die
, cu
);
17292 /* In case the const qualifier is applied to an array type, the element type
17293 is so qualified, not the array type (section 6.7.3 of C99). */
17294 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17295 return add_array_cv_type (die
, cu
, base_type
, 1, 0);
17297 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
17298 return set_die_type (die
, cv_type
, cu
);
17301 static struct type
*
17302 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17304 struct type
*base_type
, *cv_type
;
17306 base_type
= die_type (die
, cu
);
17308 /* The die_type call above may have already set the type for this DIE. */
17309 cv_type
= get_die_type (die
, cu
);
17313 /* In case the volatile qualifier is applied to an array type, the
17314 element type is so qualified, not the array type (section 6.7.3
17316 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
17317 return add_array_cv_type (die
, cu
, base_type
, 0, 1);
17319 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
17320 return set_die_type (die
, cv_type
, cu
);
17323 /* Handle DW_TAG_restrict_type. */
17325 static struct type
*
17326 read_tag_restrict_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17328 struct type
*base_type
, *cv_type
;
17330 base_type
= die_type (die
, cu
);
17332 /* The die_type call above may have already set the type for this DIE. */
17333 cv_type
= get_die_type (die
, cu
);
17337 cv_type
= make_restrict_type (base_type
);
17338 return set_die_type (die
, cv_type
, cu
);
17341 /* Handle DW_TAG_atomic_type. */
17343 static struct type
*
17344 read_tag_atomic_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17346 struct type
*base_type
, *cv_type
;
17348 base_type
= die_type (die
, cu
);
17350 /* The die_type call above may have already set the type for this DIE. */
17351 cv_type
= get_die_type (die
, cu
);
17355 cv_type
= make_atomic_type (base_type
);
17356 return set_die_type (die
, cv_type
, cu
);
17359 /* Extract all information from a DW_TAG_string_type DIE and add to
17360 the user defined type vector. It isn't really a user defined type,
17361 but it behaves like one, with other DIE's using an AT_user_def_type
17362 attribute to reference it. */
17364 static struct type
*
17365 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17367 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17368 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17369 struct type
*type
, *range_type
, *index_type
, *char_type
;
17370 struct attribute
*attr
;
17371 struct dynamic_prop prop
;
17372 bool length_is_constant
= true;
17375 /* There are a couple of places where bit sizes might be made use of
17376 when parsing a DW_TAG_string_type, however, no producer that we know
17377 of make use of these. Handling bit sizes that are a multiple of the
17378 byte size is easy enough, but what about other bit sizes? Lets deal
17379 with that problem when we have to. Warn about these attributes being
17380 unsupported, then parse the type and ignore them like we always
17382 if (dwarf2_attr (die
, DW_AT_bit_size
, cu
) != nullptr
17383 || dwarf2_attr (die
, DW_AT_string_length_bit_size
, cu
) != nullptr)
17385 static bool warning_printed
= false;
17386 if (!warning_printed
)
17388 warning (_("DW_AT_bit_size and DW_AT_string_length_bit_size not "
17389 "currently supported on DW_TAG_string_type."));
17390 warning_printed
= true;
17394 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
17395 if (attr
!= nullptr && !attr_form_is_constant (attr
))
17397 /* The string length describes the location at which the length of
17398 the string can be found. The size of the length field can be
17399 specified with one of the attributes below. */
17400 struct type
*prop_type
;
17401 struct attribute
*len
17402 = dwarf2_attr (die
, DW_AT_string_length_byte_size
, cu
);
17403 if (len
== nullptr)
17404 len
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17405 if (len
!= nullptr && attr_form_is_constant (len
))
17407 /* Pass 0 as the default as we know this attribute is constant
17408 and the default value will not be returned. */
17409 LONGEST sz
= dwarf2_get_attr_constant_value (len
, 0);
17410 prop_type
= dwarf2_per_cu_int_type (cu
->per_cu
, sz
, true);
17414 /* If the size is not specified then we assume it is the size of
17415 an address on this target. */
17416 prop_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, true);
17419 /* Convert the attribute into a dynamic property. */
17420 if (!attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
17423 length_is_constant
= false;
17425 else if (attr
!= nullptr)
17427 /* This DW_AT_string_length just contains the length with no
17428 indirection. There's no need to create a dynamic property in this
17429 case. Pass 0 for the default value as we know it will not be
17430 returned in this case. */
17431 length
= dwarf2_get_attr_constant_value (attr
, 0);
17433 else if ((attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
)) != nullptr)
17435 /* We don't currently support non-constant byte sizes for strings. */
17436 length
= dwarf2_get_attr_constant_value (attr
, 1);
17440 /* Use 1 as a fallback length if we have nothing else. */
17444 index_type
= objfile_type (objfile
)->builtin_int
;
17445 if (length_is_constant
)
17446 range_type
= create_static_range_type (NULL
, index_type
, 1, length
);
17449 struct dynamic_prop low_bound
;
17451 low_bound
.kind
= PROP_CONST
;
17452 low_bound
.data
.const_val
= 1;
17453 range_type
= create_range_type (NULL
, index_type
, &low_bound
, &prop
, 0);
17455 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
17456 type
= create_string_type (NULL
, char_type
, range_type
);
17458 return set_die_type (die
, type
, cu
);
17461 /* Assuming that DIE corresponds to a function, returns nonzero
17462 if the function is prototyped. */
17465 prototyped_function_p (struct die_info
*die
, struct dwarf2_cu
*cu
)
17467 struct attribute
*attr
;
17469 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
17470 if (attr
&& (DW_UNSND (attr
) != 0))
17473 /* The DWARF standard implies that the DW_AT_prototyped attribute
17474 is only meaningful for C, but the concept also extends to other
17475 languages that allow unprototyped functions (Eg: Objective C).
17476 For all other languages, assume that functions are always
17478 if (cu
->language
!= language_c
17479 && cu
->language
!= language_objc
17480 && cu
->language
!= language_opencl
)
17483 /* RealView does not emit DW_AT_prototyped. We can not distinguish
17484 prototyped and unprototyped functions; default to prototyped,
17485 since that is more common in modern code (and RealView warns
17486 about unprototyped functions). */
17487 if (producer_is_realview (cu
->producer
))
17493 /* Handle DIES due to C code like:
17497 int (*funcp)(int a, long l);
17501 ('funcp' generates a DW_TAG_subroutine_type DIE). */
17503 static struct type
*
17504 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17506 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17507 struct type
*type
; /* Type that this function returns. */
17508 struct type
*ftype
; /* Function that returns above type. */
17509 struct attribute
*attr
;
17511 type
= die_type (die
, cu
);
17513 /* The die_type call above may have already set the type for this DIE. */
17514 ftype
= get_die_type (die
, cu
);
17518 ftype
= lookup_function_type (type
);
17520 if (prototyped_function_p (die
, cu
))
17521 TYPE_PROTOTYPED (ftype
) = 1;
17523 /* Store the calling convention in the type if it's available in
17524 the subroutine die. Otherwise set the calling convention to
17525 the default value DW_CC_normal. */
17526 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
17527 if (attr
!= nullptr
17528 && is_valid_DW_AT_calling_convention_for_subroutine (DW_UNSND (attr
)))
17529 TYPE_CALLING_CONVENTION (ftype
)
17530 = (enum dwarf_calling_convention
) (DW_UNSND (attr
));
17531 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
17532 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
17534 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
17536 /* Record whether the function returns normally to its caller or not
17537 if the DWARF producer set that information. */
17538 attr
= dwarf2_attr (die
, DW_AT_noreturn
, cu
);
17539 if (attr
&& (DW_UNSND (attr
) != 0))
17540 TYPE_NO_RETURN (ftype
) = 1;
17542 /* We need to add the subroutine type to the die immediately so
17543 we don't infinitely recurse when dealing with parameters
17544 declared as the same subroutine type. */
17545 set_die_type (die
, ftype
, cu
);
17547 if (die
->child
!= NULL
)
17549 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
17550 struct die_info
*child_die
;
17551 int nparams
, iparams
;
17553 /* Count the number of parameters.
17554 FIXME: GDB currently ignores vararg functions, but knows about
17555 vararg member functions. */
17557 child_die
= die
->child
;
17558 while (child_die
&& child_die
->tag
)
17560 if (child_die
->tag
== DW_TAG_formal_parameter
)
17562 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
17563 TYPE_VARARGS (ftype
) = 1;
17564 child_die
= sibling_die (child_die
);
17567 /* Allocate storage for parameters and fill them in. */
17568 TYPE_NFIELDS (ftype
) = nparams
;
17569 TYPE_FIELDS (ftype
) = (struct field
*)
17570 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
17572 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
17573 even if we error out during the parameters reading below. */
17574 for (iparams
= 0; iparams
< nparams
; iparams
++)
17575 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
17578 child_die
= die
->child
;
17579 while (child_die
&& child_die
->tag
)
17581 if (child_die
->tag
== DW_TAG_formal_parameter
)
17583 struct type
*arg_type
;
17585 /* DWARF version 2 has no clean way to discern C++
17586 static and non-static member functions. G++ helps
17587 GDB by marking the first parameter for non-static
17588 member functions (which is the this pointer) as
17589 artificial. We pass this information to
17590 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
17592 DWARF version 3 added DW_AT_object_pointer, which GCC
17593 4.5 does not yet generate. */
17594 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
17595 if (attr
!= nullptr)
17596 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
17598 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
17599 arg_type
= die_type (child_die
, cu
);
17601 /* RealView does not mark THIS as const, which the testsuite
17602 expects. GCC marks THIS as const in method definitions,
17603 but not in the class specifications (GCC PR 43053). */
17604 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
17605 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
17608 struct dwarf2_cu
*arg_cu
= cu
;
17609 const char *name
= dwarf2_name (child_die
, cu
);
17611 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
17612 if (attr
!= nullptr)
17614 /* If the compiler emits this, use it. */
17615 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
17618 else if (name
&& strcmp (name
, "this") == 0)
17619 /* Function definitions will have the argument names. */
17621 else if (name
== NULL
&& iparams
== 0)
17622 /* Declarations may not have the names, so like
17623 elsewhere in GDB, assume an artificial first
17624 argument is "this". */
17628 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
17632 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
17635 child_die
= sibling_die (child_die
);
17642 static struct type
*
17643 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
17645 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17646 const char *name
= NULL
;
17647 struct type
*this_type
, *target_type
;
17649 name
= dwarf2_full_name (NULL
, die
, cu
);
17650 this_type
= init_type (objfile
, TYPE_CODE_TYPEDEF
, 0, name
);
17651 TYPE_TARGET_STUB (this_type
) = 1;
17652 set_die_type (die
, this_type
, cu
);
17653 target_type
= die_type (die
, cu
);
17654 if (target_type
!= this_type
)
17655 TYPE_TARGET_TYPE (this_type
) = target_type
;
17658 /* Self-referential typedefs are, it seems, not allowed by the DWARF
17659 spec and cause infinite loops in GDB. */
17660 complaint (_("Self-referential DW_TAG_typedef "
17661 "- DIE at %s [in module %s]"),
17662 sect_offset_str (die
->sect_off
), objfile_name (objfile
));
17663 TYPE_TARGET_TYPE (this_type
) = NULL
;
17668 /* Allocate a floating-point type of size BITS and name NAME. Pass NAME_HINT
17669 (which may be different from NAME) to the architecture back-end to allow
17670 it to guess the correct format if necessary. */
17672 static struct type
*
17673 dwarf2_init_float_type (struct objfile
*objfile
, int bits
, const char *name
,
17674 const char *name_hint
, enum bfd_endian byte_order
)
17676 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17677 const struct floatformat
**format
;
17680 format
= gdbarch_floatformat_for_type (gdbarch
, name_hint
, bits
);
17682 type
= init_float_type (objfile
, bits
, name
, format
, byte_order
);
17684 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17689 /* Allocate an integer type of size BITS and name NAME. */
17691 static struct type
*
17692 dwarf2_init_integer_type (struct dwarf2_cu
*cu
, struct objfile
*objfile
,
17693 int bits
, int unsigned_p
, const char *name
)
17697 /* Versions of Intel's C Compiler generate an integer type called "void"
17698 instead of using DW_TAG_unspecified_type. This has been seen on
17699 at least versions 14, 17, and 18. */
17700 if (bits
== 0 && producer_is_icc (cu
) && name
!= nullptr
17701 && strcmp (name
, "void") == 0)
17702 type
= objfile_type (objfile
)->builtin_void
;
17704 type
= init_integer_type (objfile
, bits
, unsigned_p
, name
);
17709 /* Initialise and return a floating point type of size BITS suitable for
17710 use as a component of a complex number. The NAME_HINT is passed through
17711 when initialising the floating point type and is the name of the complex
17714 As DWARF doesn't currently provide an explicit name for the components
17715 of a complex number, but it can be helpful to have these components
17716 named, we try to select a suitable name based on the size of the
17718 static struct type
*
17719 dwarf2_init_complex_target_type (struct dwarf2_cu
*cu
,
17720 struct objfile
*objfile
,
17721 int bits
, const char *name_hint
,
17722 enum bfd_endian byte_order
)
17724 gdbarch
*gdbarch
= get_objfile_arch (objfile
);
17725 struct type
*tt
= nullptr;
17727 /* Try to find a suitable floating point builtin type of size BITS.
17728 We're going to use the name of this type as the name for the complex
17729 target type that we are about to create. */
17730 switch (cu
->language
)
17732 case language_fortran
:
17736 tt
= builtin_f_type (gdbarch
)->builtin_real
;
17739 tt
= builtin_f_type (gdbarch
)->builtin_real_s8
;
17741 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17743 tt
= builtin_f_type (gdbarch
)->builtin_real_s16
;
17751 tt
= builtin_type (gdbarch
)->builtin_float
;
17754 tt
= builtin_type (gdbarch
)->builtin_double
;
17756 case 96: /* The x86-32 ABI specifies 96-bit long double. */
17758 tt
= builtin_type (gdbarch
)->builtin_long_double
;
17764 /* If the type we found doesn't match the size we were looking for, then
17765 pretend we didn't find a type at all, the complex target type we
17766 create will then be nameless. */
17767 if (tt
!= nullptr && TYPE_LENGTH (tt
) * TARGET_CHAR_BIT
!= bits
)
17770 const char *name
= (tt
== nullptr) ? nullptr : TYPE_NAME (tt
);
17771 return dwarf2_init_float_type (objfile
, bits
, name
, name_hint
, byte_order
);
17774 /* Find a representation of a given base type and install
17775 it in the TYPE field of the die. */
17777 static struct type
*
17778 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
17780 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
17782 struct attribute
*attr
;
17783 int encoding
= 0, bits
= 0;
17787 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
17788 if (attr
!= nullptr)
17789 encoding
= DW_UNSND (attr
);
17790 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
17791 if (attr
!= nullptr)
17792 bits
= DW_UNSND (attr
) * TARGET_CHAR_BIT
;
17793 name
= dwarf2_name (die
, cu
);
17795 complaint (_("DW_AT_name missing from DW_TAG_base_type"));
17797 arch
= get_objfile_arch (objfile
);
17798 enum bfd_endian byte_order
= gdbarch_byte_order (arch
);
17800 attr
= dwarf2_attr (die
, DW_AT_endianity
, cu
);
17803 int endianity
= DW_UNSND (attr
);
17808 byte_order
= BFD_ENDIAN_BIG
;
17810 case DW_END_little
:
17811 byte_order
= BFD_ENDIAN_LITTLE
;
17814 complaint (_("DW_AT_endianity has unrecognized value %d"), endianity
);
17821 case DW_ATE_address
:
17822 /* Turn DW_ATE_address into a void * pointer. */
17823 type
= init_type (objfile
, TYPE_CODE_VOID
, TARGET_CHAR_BIT
, NULL
);
17824 type
= init_pointer_type (objfile
, bits
, name
, type
);
17826 case DW_ATE_boolean
:
17827 type
= init_boolean_type (objfile
, bits
, 1, name
);
17829 case DW_ATE_complex_float
:
17830 type
= dwarf2_init_complex_target_type (cu
, objfile
, bits
/ 2, name
,
17832 type
= init_complex_type (objfile
, name
, type
);
17834 case DW_ATE_decimal_float
:
17835 type
= init_decfloat_type (objfile
, bits
, name
);
17838 type
= dwarf2_init_float_type (objfile
, bits
, name
, name
, byte_order
);
17840 case DW_ATE_signed
:
17841 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17843 case DW_ATE_unsigned
:
17844 if (cu
->language
== language_fortran
17846 && startswith (name
, "character("))
17847 type
= init_character_type (objfile
, bits
, 1, name
);
17849 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17851 case DW_ATE_signed_char
:
17852 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17853 || cu
->language
== language_pascal
17854 || cu
->language
== language_fortran
)
17855 type
= init_character_type (objfile
, bits
, 0, name
);
17857 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 0, name
);
17859 case DW_ATE_unsigned_char
:
17860 if (cu
->language
== language_ada
|| cu
->language
== language_m2
17861 || cu
->language
== language_pascal
17862 || cu
->language
== language_fortran
17863 || cu
->language
== language_rust
)
17864 type
= init_character_type (objfile
, bits
, 1, name
);
17866 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17871 type
= builtin_type (arch
)->builtin_char16
;
17872 else if (bits
== 32)
17873 type
= builtin_type (arch
)->builtin_char32
;
17876 complaint (_("unsupported DW_ATE_UTF bit size: '%d'"),
17878 type
= dwarf2_init_integer_type (cu
, objfile
, bits
, 1, name
);
17880 return set_die_type (die
, type
, cu
);
17885 complaint (_("unsupported DW_AT_encoding: '%s'"),
17886 dwarf_type_encoding_name (encoding
));
17887 type
= init_type (objfile
, TYPE_CODE_ERROR
, bits
, name
);
17891 if (name
&& strcmp (name
, "char") == 0)
17892 TYPE_NOSIGN (type
) = 1;
17894 maybe_set_alignment (cu
, die
, type
);
17896 TYPE_ENDIANITY_NOT_DEFAULT (type
) = gdbarch_byte_order (arch
) != byte_order
;
17898 return set_die_type (die
, type
, cu
);
17901 /* Parse dwarf attribute if it's a block, reference or constant and put the
17902 resulting value of the attribute into struct bound_prop.
17903 Returns 1 if ATTR could be resolved into PROP, 0 otherwise. */
17906 attr_to_dynamic_prop (const struct attribute
*attr
, struct die_info
*die
,
17907 struct dwarf2_cu
*cu
, struct dynamic_prop
*prop
,
17908 struct type
*default_type
)
17910 struct dwarf2_property_baton
*baton
;
17911 struct obstack
*obstack
17912 = &cu
->per_cu
->dwarf2_per_objfile
->objfile
->objfile_obstack
;
17914 gdb_assert (default_type
!= NULL
);
17916 if (attr
== NULL
|| prop
== NULL
)
17919 if (attr_form_is_block (attr
))
17921 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17922 baton
->property_type
= default_type
;
17923 baton
->locexpr
.per_cu
= cu
->per_cu
;
17924 baton
->locexpr
.size
= DW_BLOCK (attr
)->size
;
17925 baton
->locexpr
.data
= DW_BLOCK (attr
)->data
;
17926 switch (attr
->name
)
17928 case DW_AT_string_length
:
17929 baton
->locexpr
.is_reference
= true;
17932 baton
->locexpr
.is_reference
= false;
17935 prop
->data
.baton
= baton
;
17936 prop
->kind
= PROP_LOCEXPR
;
17937 gdb_assert (prop
->data
.baton
!= NULL
);
17939 else if (attr_form_is_ref (attr
))
17941 struct dwarf2_cu
*target_cu
= cu
;
17942 struct die_info
*target_die
;
17943 struct attribute
*target_attr
;
17945 target_die
= follow_die_ref (die
, attr
, &target_cu
);
17946 target_attr
= dwarf2_attr (target_die
, DW_AT_location
, target_cu
);
17947 if (target_attr
== NULL
)
17948 target_attr
= dwarf2_attr (target_die
, DW_AT_data_member_location
,
17950 if (target_attr
== NULL
)
17953 switch (target_attr
->name
)
17955 case DW_AT_location
:
17956 if (attr_form_is_section_offset (target_attr
))
17958 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17959 baton
->property_type
= die_type (target_die
, target_cu
);
17960 fill_in_loclist_baton (cu
, &baton
->loclist
, target_attr
);
17961 prop
->data
.baton
= baton
;
17962 prop
->kind
= PROP_LOCLIST
;
17963 gdb_assert (prop
->data
.baton
!= NULL
);
17965 else if (attr_form_is_block (target_attr
))
17967 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17968 baton
->property_type
= die_type (target_die
, target_cu
);
17969 baton
->locexpr
.per_cu
= cu
->per_cu
;
17970 baton
->locexpr
.size
= DW_BLOCK (target_attr
)->size
;
17971 baton
->locexpr
.data
= DW_BLOCK (target_attr
)->data
;
17972 baton
->locexpr
.is_reference
= true;
17973 prop
->data
.baton
= baton
;
17974 prop
->kind
= PROP_LOCEXPR
;
17975 gdb_assert (prop
->data
.baton
!= NULL
);
17979 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
17980 "dynamic property");
17984 case DW_AT_data_member_location
:
17988 if (!handle_data_member_location (target_die
, target_cu
,
17992 baton
= XOBNEW (obstack
, struct dwarf2_property_baton
);
17993 baton
->property_type
= read_type_die (target_die
->parent
,
17995 baton
->offset_info
.offset
= offset
;
17996 baton
->offset_info
.type
= die_type (target_die
, target_cu
);
17997 prop
->data
.baton
= baton
;
17998 prop
->kind
= PROP_ADDR_OFFSET
;
18003 else if (attr_form_is_constant (attr
))
18005 prop
->data
.const_val
= dwarf2_get_attr_constant_value (attr
, 0);
18006 prop
->kind
= PROP_CONST
;
18010 dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr
->form
),
18011 dwarf2_name (die
, cu
));
18018 /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
18019 UNSIGNED_P controls if the integer is unsigned or not. */
18021 static struct type
*
18022 dwarf2_per_cu_int_type (struct dwarf2_per_cu_data
*per_cu
,
18023 int size_in_bytes
, bool unsigned_p
)
18025 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
18026 struct type
*int_type
;
18028 /* Helper macro to examine the various builtin types. */
18029 #define TRY_TYPE(F) \
18030 int_type = (unsigned_p \
18031 ? objfile_type (objfile)->builtin_unsigned_ ## F \
18032 : objfile_type (objfile)->builtin_ ## F); \
18033 if (int_type != NULL && TYPE_LENGTH (int_type) == size_in_bytes) \
18040 TRY_TYPE (long_long
);
18044 gdb_assert_not_reached ("unable to find suitable integer type");
18047 /* Find an integer type the same size as the address size given in the
18048 compilation unit header for PER_CU. UNSIGNED_P controls if the integer
18049 is unsigned or not. */
18051 static struct type
*
18052 dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data
*per_cu
,
18055 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
18056 return dwarf2_per_cu_int_type (per_cu
, addr_size
, unsigned_p
);
18059 /* Read the DW_AT_type attribute for a sub-range. If this attribute is not
18060 present (which is valid) then compute the default type based on the
18061 compilation units address size. */
18063 static struct type
*
18064 read_subrange_index_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18066 struct type
*index_type
= die_type (die
, cu
);
18068 /* Dwarf-2 specifications explicitly allows to create subrange types
18069 without specifying a base type.
18070 In that case, the base type must be set to the type of
18071 the lower bound, upper bound or count, in that order, if any of these
18072 three attributes references an object that has a type.
18073 If no base type is found, the Dwarf-2 specifications say that
18074 a signed integer type of size equal to the size of an address should
18076 For the following C code: `extern char gdb_int [];'
18077 GCC produces an empty range DIE.
18078 FIXME: muller/2010-05-28: Possible references to object for low bound,
18079 high bound or count are not yet handled by this code. */
18080 if (TYPE_CODE (index_type
) == TYPE_CODE_VOID
)
18081 index_type
= dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18086 /* Read the given DW_AT_subrange DIE. */
18088 static struct type
*
18089 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18091 struct type
*base_type
, *orig_base_type
;
18092 struct type
*range_type
;
18093 struct attribute
*attr
;
18094 struct dynamic_prop low
, high
;
18095 int low_default_is_valid
;
18096 int high_bound_is_count
= 0;
18098 ULONGEST negative_mask
;
18100 orig_base_type
= read_subrange_index_type (die
, cu
);
18102 /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED,
18103 whereas the real type might be. So, we use ORIG_BASE_TYPE when
18104 creating the range type, but we use the result of check_typedef
18105 when examining properties of the type. */
18106 base_type
= check_typedef (orig_base_type
);
18108 /* The die_type call above may have already set the type for this DIE. */
18109 range_type
= get_die_type (die
, cu
);
18113 low
.kind
= PROP_CONST
;
18114 high
.kind
= PROP_CONST
;
18115 high
.data
.const_val
= 0;
18117 /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
18118 omitting DW_AT_lower_bound. */
18119 switch (cu
->language
)
18122 case language_cplus
:
18123 low
.data
.const_val
= 0;
18124 low_default_is_valid
= 1;
18126 case language_fortran
:
18127 low
.data
.const_val
= 1;
18128 low_default_is_valid
= 1;
18131 case language_objc
:
18132 case language_rust
:
18133 low
.data
.const_val
= 0;
18134 low_default_is_valid
= (cu
->header
.version
>= 4);
18138 case language_pascal
:
18139 low
.data
.const_val
= 1;
18140 low_default_is_valid
= (cu
->header
.version
>= 4);
18143 low
.data
.const_val
= 0;
18144 low_default_is_valid
= 0;
18148 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
18149 if (attr
!= nullptr)
18150 attr_to_dynamic_prop (attr
, die
, cu
, &low
, base_type
);
18151 else if (!low_default_is_valid
)
18152 complaint (_("Missing DW_AT_lower_bound "
18153 "- DIE at %s [in module %s]"),
18154 sect_offset_str (die
->sect_off
),
18155 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18157 struct attribute
*attr_ub
, *attr_count
;
18158 attr
= attr_ub
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
18159 if (!attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18161 attr
= attr_count
= dwarf2_attr (die
, DW_AT_count
, cu
);
18162 if (attr_to_dynamic_prop (attr
, die
, cu
, &high
, base_type
))
18164 /* If bounds are constant do the final calculation here. */
18165 if (low
.kind
== PROP_CONST
&& high
.kind
== PROP_CONST
)
18166 high
.data
.const_val
= low
.data
.const_val
+ high
.data
.const_val
- 1;
18168 high_bound_is_count
= 1;
18172 if (attr_ub
!= NULL
)
18173 complaint (_("Unresolved DW_AT_upper_bound "
18174 "- DIE at %s [in module %s]"),
18175 sect_offset_str (die
->sect_off
),
18176 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18177 if (attr_count
!= NULL
)
18178 complaint (_("Unresolved DW_AT_count "
18179 "- DIE at %s [in module %s]"),
18180 sect_offset_str (die
->sect_off
),
18181 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18186 struct attribute
*bias_attr
= dwarf2_attr (die
, DW_AT_GNU_bias
, cu
);
18187 if (bias_attr
!= nullptr && attr_form_is_constant (bias_attr
))
18188 bias
= dwarf2_get_attr_constant_value (bias_attr
, 0);
18190 /* Normally, the DWARF producers are expected to use a signed
18191 constant form (Eg. DW_FORM_sdata) to express negative bounds.
18192 But this is unfortunately not always the case, as witnessed
18193 with GCC, for instance, where the ambiguous DW_FORM_dataN form
18194 is used instead. To work around that ambiguity, we treat
18195 the bounds as signed, and thus sign-extend their values, when
18196 the base type is signed. */
18198 -((ULONGEST
) 1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1));
18199 if (low
.kind
== PROP_CONST
18200 && !TYPE_UNSIGNED (base_type
) && (low
.data
.const_val
& negative_mask
))
18201 low
.data
.const_val
|= negative_mask
;
18202 if (high
.kind
== PROP_CONST
18203 && !TYPE_UNSIGNED (base_type
) && (high
.data
.const_val
& negative_mask
))
18204 high
.data
.const_val
|= negative_mask
;
18206 /* Check for bit and byte strides. */
18207 struct dynamic_prop byte_stride_prop
;
18208 attribute
*attr_byte_stride
= dwarf2_attr (die
, DW_AT_byte_stride
, cu
);
18209 if (attr_byte_stride
!= nullptr)
18211 struct type
*prop_type
18212 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18213 attr_to_dynamic_prop (attr_byte_stride
, die
, cu
, &byte_stride_prop
,
18217 struct dynamic_prop bit_stride_prop
;
18218 attribute
*attr_bit_stride
= dwarf2_attr (die
, DW_AT_bit_stride
, cu
);
18219 if (attr_bit_stride
!= nullptr)
18221 /* It only makes sense to have either a bit or byte stride. */
18222 if (attr_byte_stride
!= nullptr)
18224 complaint (_("Found DW_AT_bit_stride and DW_AT_byte_stride "
18225 "- DIE at %s [in module %s]"),
18226 sect_offset_str (die
->sect_off
),
18227 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
18228 attr_bit_stride
= nullptr;
18232 struct type
*prop_type
18233 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
18234 attr_to_dynamic_prop (attr_bit_stride
, die
, cu
, &bit_stride_prop
,
18239 if (attr_byte_stride
!= nullptr
18240 || attr_bit_stride
!= nullptr)
18242 bool byte_stride_p
= (attr_byte_stride
!= nullptr);
18243 struct dynamic_prop
*stride
18244 = byte_stride_p
? &byte_stride_prop
: &bit_stride_prop
;
18247 = create_range_type_with_stride (NULL
, orig_base_type
, &low
,
18248 &high
, bias
, stride
, byte_stride_p
);
18251 range_type
= create_range_type (NULL
, orig_base_type
, &low
, &high
, bias
);
18253 if (high_bound_is_count
)
18254 TYPE_RANGE_DATA (range_type
)->flag_upper_bound_is_count
= 1;
18256 /* Ada expects an empty array on no boundary attributes. */
18257 if (attr
== NULL
&& cu
->language
!= language_ada
)
18258 TYPE_HIGH_BOUND_KIND (range_type
) = PROP_UNDEFINED
;
18260 name
= dwarf2_name (die
, cu
);
18262 TYPE_NAME (range_type
) = name
;
18264 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
18265 if (attr
!= nullptr)
18266 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
18268 maybe_set_alignment (cu
, die
, range_type
);
18270 set_die_type (die
, range_type
, cu
);
18272 /* set_die_type should be already done. */
18273 set_descriptive_type (range_type
, die
, cu
);
18278 static struct type
*
18279 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
18283 type
= init_type (cu
->per_cu
->dwarf2_per_objfile
->objfile
, TYPE_CODE_VOID
,0,
18285 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
18287 /* In Ada, an unspecified type is typically used when the description
18288 of the type is deferred to a different unit. When encountering
18289 such a type, we treat it as a stub, and try to resolve it later on,
18291 if (cu
->language
== language_ada
)
18292 TYPE_STUB (type
) = 1;
18294 return set_die_type (die
, type
, cu
);
18297 /* Read a single die and all its descendents. Set the die's sibling
18298 field to NULL; set other fields in the die correctly, and set all
18299 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
18300 location of the info_ptr after reading all of those dies. PARENT
18301 is the parent of the die in question. */
18303 static struct die_info
*
18304 read_die_and_children (const struct die_reader_specs
*reader
,
18305 const gdb_byte
*info_ptr
,
18306 const gdb_byte
**new_info_ptr
,
18307 struct die_info
*parent
)
18309 struct die_info
*die
;
18310 const gdb_byte
*cur_ptr
;
18313 cur_ptr
= read_full_die_1 (reader
, &die
, info_ptr
, &has_children
, 0);
18316 *new_info_ptr
= cur_ptr
;
18319 store_in_ref_table (die
, reader
->cu
);
18322 die
->child
= read_die_and_siblings_1 (reader
, cur_ptr
, new_info_ptr
, die
);
18326 *new_info_ptr
= cur_ptr
;
18329 die
->sibling
= NULL
;
18330 die
->parent
= parent
;
18334 /* Read a die, all of its descendents, and all of its siblings; set
18335 all of the fields of all of the dies correctly. Arguments are as
18336 in read_die_and_children. */
18338 static struct die_info
*
18339 read_die_and_siblings_1 (const struct die_reader_specs
*reader
,
18340 const gdb_byte
*info_ptr
,
18341 const gdb_byte
**new_info_ptr
,
18342 struct die_info
*parent
)
18344 struct die_info
*first_die
, *last_sibling
;
18345 const gdb_byte
*cur_ptr
;
18347 cur_ptr
= info_ptr
;
18348 first_die
= last_sibling
= NULL
;
18352 struct die_info
*die
18353 = read_die_and_children (reader
, cur_ptr
, &cur_ptr
, parent
);
18357 *new_info_ptr
= cur_ptr
;
18364 last_sibling
->sibling
= die
;
18366 last_sibling
= die
;
18370 /* Read a die, all of its descendents, and all of its siblings; set
18371 all of the fields of all of the dies correctly. Arguments are as
18372 in read_die_and_children.
18373 This the main entry point for reading a DIE and all its children. */
18375 static struct die_info
*
18376 read_die_and_siblings (const struct die_reader_specs
*reader
,
18377 const gdb_byte
*info_ptr
,
18378 const gdb_byte
**new_info_ptr
,
18379 struct die_info
*parent
)
18381 struct die_info
*die
= read_die_and_siblings_1 (reader
, info_ptr
,
18382 new_info_ptr
, parent
);
18384 if (dwarf_die_debug
)
18386 fprintf_unfiltered (gdb_stdlog
,
18387 "Read die from %s@0x%x of %s:\n",
18388 get_section_name (reader
->die_section
),
18389 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18390 bfd_get_filename (reader
->abfd
));
18391 dump_die (die
, dwarf_die_debug
);
18397 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
18399 The caller is responsible for filling in the extra attributes
18400 and updating (*DIEP)->num_attrs.
18401 Set DIEP to point to a newly allocated die with its information,
18402 except for its child, sibling, and parent fields.
18403 Set HAS_CHILDREN to tell whether the die has children or not. */
18405 static const gdb_byte
*
18406 read_full_die_1 (const struct die_reader_specs
*reader
,
18407 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18408 int *has_children
, int num_extra_attrs
)
18410 unsigned int abbrev_number
, bytes_read
, i
;
18411 struct abbrev_info
*abbrev
;
18412 struct die_info
*die
;
18413 struct dwarf2_cu
*cu
= reader
->cu
;
18414 bfd
*abfd
= reader
->abfd
;
18416 sect_offset sect_off
= (sect_offset
) (info_ptr
- reader
->buffer
);
18417 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
18418 info_ptr
+= bytes_read
;
18419 if (!abbrev_number
)
18426 abbrev
= reader
->abbrev_table
->lookup_abbrev (abbrev_number
);
18428 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
18430 bfd_get_filename (abfd
));
18432 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
+ num_extra_attrs
);
18433 die
->sect_off
= sect_off
;
18434 die
->tag
= abbrev
->tag
;
18435 die
->abbrev
= abbrev_number
;
18437 /* Make the result usable.
18438 The caller needs to update num_attrs after adding the extra
18440 die
->num_attrs
= abbrev
->num_attrs
;
18442 std::vector
<int> indexes_that_need_reprocess
;
18443 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
18445 bool need_reprocess
;
18447 read_attribute (reader
, &die
->attrs
[i
], &abbrev
->attrs
[i
],
18448 info_ptr
, &need_reprocess
);
18449 if (need_reprocess
)
18450 indexes_that_need_reprocess
.push_back (i
);
18453 struct attribute
*attr
= dwarf2_attr_no_follow (die
, DW_AT_str_offsets_base
);
18454 if (attr
!= nullptr)
18455 cu
->str_offsets_base
= DW_UNSND (attr
);
18457 auto maybe_addr_base
= lookup_addr_base(die
);
18458 if (maybe_addr_base
.has_value ())
18459 cu
->addr_base
= *maybe_addr_base
;
18460 for (int index
: indexes_that_need_reprocess
)
18461 read_attribute_reprocess (reader
, &die
->attrs
[index
]);
18463 *has_children
= abbrev
->has_children
;
18467 /* Read a die and all its attributes.
18468 Set DIEP to point to a newly allocated die with its information,
18469 except for its child, sibling, and parent fields.
18470 Set HAS_CHILDREN to tell whether the die has children or not. */
18472 static const gdb_byte
*
18473 read_full_die (const struct die_reader_specs
*reader
,
18474 struct die_info
**diep
, const gdb_byte
*info_ptr
,
18477 const gdb_byte
*result
;
18479 result
= read_full_die_1 (reader
, diep
, info_ptr
, has_children
, 0);
18481 if (dwarf_die_debug
)
18483 fprintf_unfiltered (gdb_stdlog
,
18484 "Read die from %s@0x%x of %s:\n",
18485 get_section_name (reader
->die_section
),
18486 (unsigned) (info_ptr
- reader
->die_section
->buffer
),
18487 bfd_get_filename (reader
->abfd
));
18488 dump_die (*diep
, dwarf_die_debug
);
18494 /* Abbreviation tables.
18496 In DWARF version 2, the description of the debugging information is
18497 stored in a separate .debug_abbrev section. Before we read any
18498 dies from a section we read in all abbreviations and install them
18499 in a hash table. */
18501 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */
18503 struct abbrev_info
*
18504 abbrev_table::alloc_abbrev ()
18506 struct abbrev_info
*abbrev
;
18508 abbrev
= XOBNEW (&abbrev_obstack
, struct abbrev_info
);
18509 memset (abbrev
, 0, sizeof (struct abbrev_info
));
18514 /* Add an abbreviation to the table. */
18517 abbrev_table::add_abbrev (unsigned int abbrev_number
,
18518 struct abbrev_info
*abbrev
)
18520 unsigned int hash_number
;
18522 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18523 abbrev
->next
= m_abbrevs
[hash_number
];
18524 m_abbrevs
[hash_number
] = abbrev
;
18527 /* Look up an abbrev in the table.
18528 Returns NULL if the abbrev is not found. */
18530 struct abbrev_info
*
18531 abbrev_table::lookup_abbrev (unsigned int abbrev_number
)
18533 unsigned int hash_number
;
18534 struct abbrev_info
*abbrev
;
18536 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
18537 abbrev
= m_abbrevs
[hash_number
];
18541 if (abbrev
->number
== abbrev_number
)
18543 abbrev
= abbrev
->next
;
18548 /* Read in an abbrev table. */
18550 static abbrev_table_up
18551 abbrev_table_read_table (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
18552 struct dwarf2_section_info
*section
,
18553 sect_offset sect_off
)
18555 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18556 bfd
*abfd
= get_section_bfd_owner (section
);
18557 const gdb_byte
*abbrev_ptr
;
18558 struct abbrev_info
*cur_abbrev
;
18559 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
18560 unsigned int abbrev_form
;
18561 std::vector
<struct attr_abbrev
> cur_attrs
;
18563 abbrev_table_up
abbrev_table (new struct abbrev_table (sect_off
));
18565 dwarf2_read_section (objfile
, section
);
18566 abbrev_ptr
= section
->buffer
+ to_underlying (sect_off
);
18567 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18568 abbrev_ptr
+= bytes_read
;
18570 /* Loop until we reach an abbrev number of 0. */
18571 while (abbrev_number
)
18573 cur_attrs
.clear ();
18574 cur_abbrev
= abbrev_table
->alloc_abbrev ();
18576 /* read in abbrev header */
18577 cur_abbrev
->number
= abbrev_number
;
18579 = (enum dwarf_tag
) read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18580 abbrev_ptr
+= bytes_read
;
18581 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
18584 /* now read in declarations */
18587 LONGEST implicit_const
;
18589 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18590 abbrev_ptr
+= bytes_read
;
18591 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18592 abbrev_ptr
+= bytes_read
;
18593 if (abbrev_form
== DW_FORM_implicit_const
)
18595 implicit_const
= read_signed_leb128 (abfd
, abbrev_ptr
,
18597 abbrev_ptr
+= bytes_read
;
18601 /* Initialize it due to a false compiler warning. */
18602 implicit_const
= -1;
18605 if (abbrev_name
== 0)
18608 cur_attrs
.emplace_back ();
18609 struct attr_abbrev
&cur_attr
= cur_attrs
.back ();
18610 cur_attr
.name
= (enum dwarf_attribute
) abbrev_name
;
18611 cur_attr
.form
= (enum dwarf_form
) abbrev_form
;
18612 cur_attr
.implicit_const
= implicit_const
;
18613 ++cur_abbrev
->num_attrs
;
18616 cur_abbrev
->attrs
=
18617 XOBNEWVEC (&abbrev_table
->abbrev_obstack
, struct attr_abbrev
,
18618 cur_abbrev
->num_attrs
);
18619 memcpy (cur_abbrev
->attrs
, cur_attrs
.data (),
18620 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
18622 abbrev_table
->add_abbrev (abbrev_number
, cur_abbrev
);
18624 /* Get next abbreviation.
18625 Under Irix6 the abbreviations for a compilation unit are not
18626 always properly terminated with an abbrev number of 0.
18627 Exit loop if we encounter an abbreviation which we have
18628 already read (which means we are about to read the abbreviations
18629 for the next compile unit) or if the end of the abbreviation
18630 table is reached. */
18631 if ((unsigned int) (abbrev_ptr
- section
->buffer
) >= section
->size
)
18633 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
18634 abbrev_ptr
+= bytes_read
;
18635 if (abbrev_table
->lookup_abbrev (abbrev_number
) != NULL
)
18639 return abbrev_table
;
18642 /* Returns nonzero if TAG represents a type that we might generate a partial
18646 is_type_tag_for_partial (int tag
)
18651 /* Some types that would be reasonable to generate partial symbols for,
18652 that we don't at present. */
18653 case DW_TAG_array_type
:
18654 case DW_TAG_file_type
:
18655 case DW_TAG_ptr_to_member_type
:
18656 case DW_TAG_set_type
:
18657 case DW_TAG_string_type
:
18658 case DW_TAG_subroutine_type
:
18660 case DW_TAG_base_type
:
18661 case DW_TAG_class_type
:
18662 case DW_TAG_interface_type
:
18663 case DW_TAG_enumeration_type
:
18664 case DW_TAG_structure_type
:
18665 case DW_TAG_subrange_type
:
18666 case DW_TAG_typedef
:
18667 case DW_TAG_union_type
:
18674 /* Load all DIEs that are interesting for partial symbols into memory. */
18676 static struct partial_die_info
*
18677 load_partial_dies (const struct die_reader_specs
*reader
,
18678 const gdb_byte
*info_ptr
, int building_psymtab
)
18680 struct dwarf2_cu
*cu
= reader
->cu
;
18681 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
18682 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
18683 unsigned int bytes_read
;
18684 unsigned int load_all
= 0;
18685 int nesting_level
= 1;
18690 gdb_assert (cu
->per_cu
!= NULL
);
18691 if (cu
->per_cu
->load_all_dies
)
18695 = htab_create_alloc_ex (cu
->header
.length
/ 12,
18699 &cu
->comp_unit_obstack
,
18700 hashtab_obstack_allocate
,
18701 dummy_obstack_deallocate
);
18705 abbrev_info
*abbrev
= peek_die_abbrev (*reader
, info_ptr
, &bytes_read
);
18707 /* A NULL abbrev means the end of a series of children. */
18708 if (abbrev
== NULL
)
18710 if (--nesting_level
== 0)
18713 info_ptr
+= bytes_read
;
18714 last_die
= parent_die
;
18715 parent_die
= parent_die
->die_parent
;
18719 /* Check for template arguments. We never save these; if
18720 they're seen, we just mark the parent, and go on our way. */
18721 if (parent_die
!= NULL
18722 && cu
->language
== language_cplus
18723 && (abbrev
->tag
== DW_TAG_template_type_param
18724 || abbrev
->tag
== DW_TAG_template_value_param
))
18726 parent_die
->has_template_arguments
= 1;
18730 /* We don't need a partial DIE for the template argument. */
18731 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18736 /* We only recurse into c++ subprograms looking for template arguments.
18737 Skip their other children. */
18739 && cu
->language
== language_cplus
18740 && parent_die
!= NULL
18741 && parent_die
->tag
== DW_TAG_subprogram
)
18743 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18747 /* Check whether this DIE is interesting enough to save. Normally
18748 we would not be interested in members here, but there may be
18749 later variables referencing them via DW_AT_specification (for
18750 static members). */
18752 && !is_type_tag_for_partial (abbrev
->tag
)
18753 && abbrev
->tag
!= DW_TAG_constant
18754 && abbrev
->tag
!= DW_TAG_enumerator
18755 && abbrev
->tag
!= DW_TAG_subprogram
18756 && abbrev
->tag
!= DW_TAG_inlined_subroutine
18757 && abbrev
->tag
!= DW_TAG_lexical_block
18758 && abbrev
->tag
!= DW_TAG_variable
18759 && abbrev
->tag
!= DW_TAG_namespace
18760 && abbrev
->tag
!= DW_TAG_module
18761 && abbrev
->tag
!= DW_TAG_member
18762 && abbrev
->tag
!= DW_TAG_imported_unit
18763 && abbrev
->tag
!= DW_TAG_imported_declaration
)
18765 /* Otherwise we skip to the next sibling, if any. */
18766 info_ptr
= skip_one_die (reader
, info_ptr
+ bytes_read
, abbrev
);
18770 struct partial_die_info
pdi ((sect_offset
) (info_ptr
- reader
->buffer
),
18773 info_ptr
= pdi
.read (reader
, *abbrev
, info_ptr
+ bytes_read
);
18775 /* This two-pass algorithm for processing partial symbols has a
18776 high cost in cache pressure. Thus, handle some simple cases
18777 here which cover the majority of C partial symbols. DIEs
18778 which neither have specification tags in them, nor could have
18779 specification tags elsewhere pointing at them, can simply be
18780 processed and discarded.
18782 This segment is also optional; scan_partial_symbols and
18783 add_partial_symbol will handle these DIEs if we chain
18784 them in normally. When compilers which do not emit large
18785 quantities of duplicate debug information are more common,
18786 this code can probably be removed. */
18788 /* Any complete simple types at the top level (pretty much all
18789 of them, for a language without namespaces), can be processed
18791 if (parent_die
== NULL
18792 && pdi
.has_specification
== 0
18793 && pdi
.is_declaration
== 0
18794 && ((pdi
.tag
== DW_TAG_typedef
&& !pdi
.has_children
)
18795 || pdi
.tag
== DW_TAG_base_type
18796 || pdi
.tag
== DW_TAG_subrange_type
))
18798 if (building_psymtab
&& pdi
.name
!= NULL
)
18799 add_psymbol_to_list (pdi
.name
, false,
18800 VAR_DOMAIN
, LOC_TYPEDEF
, -1,
18801 psymbol_placement::STATIC
,
18802 0, cu
->language
, objfile
);
18803 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18807 /* The exception for DW_TAG_typedef with has_children above is
18808 a workaround of GCC PR debug/47510. In the case of this complaint
18809 type_name_or_error will error on such types later.
18811 GDB skipped children of DW_TAG_typedef by the shortcut above and then
18812 it could not find the child DIEs referenced later, this is checked
18813 above. In correct DWARF DW_TAG_typedef should have no children. */
18815 if (pdi
.tag
== DW_TAG_typedef
&& pdi
.has_children
)
18816 complaint (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug "
18817 "- DIE at %s [in module %s]"),
18818 sect_offset_str (pdi
.sect_off
), objfile_name (objfile
));
18820 /* If we're at the second level, and we're an enumerator, and
18821 our parent has no specification (meaning possibly lives in a
18822 namespace elsewhere), then we can add the partial symbol now
18823 instead of queueing it. */
18824 if (pdi
.tag
== DW_TAG_enumerator
18825 && parent_die
!= NULL
18826 && parent_die
->die_parent
== NULL
18827 && parent_die
->tag
== DW_TAG_enumeration_type
18828 && parent_die
->has_specification
== 0)
18830 if (pdi
.name
== NULL
)
18831 complaint (_("malformed enumerator DIE ignored"));
18832 else if (building_psymtab
)
18833 add_psymbol_to_list (pdi
.name
, false,
18834 VAR_DOMAIN
, LOC_CONST
, -1,
18835 cu
->language
== language_cplus
18836 ? psymbol_placement::GLOBAL
18837 : psymbol_placement::STATIC
,
18838 0, cu
->language
, objfile
);
18840 info_ptr
= locate_pdi_sibling (reader
, &pdi
, info_ptr
);
18844 struct partial_die_info
*part_die
18845 = new (&cu
->comp_unit_obstack
) partial_die_info (pdi
);
18847 /* We'll save this DIE so link it in. */
18848 part_die
->die_parent
= parent_die
;
18849 part_die
->die_sibling
= NULL
;
18850 part_die
->die_child
= NULL
;
18852 if (last_die
&& last_die
== parent_die
)
18853 last_die
->die_child
= part_die
;
18855 last_die
->die_sibling
= part_die
;
18857 last_die
= part_die
;
18859 if (first_die
== NULL
)
18860 first_die
= part_die
;
18862 /* Maybe add the DIE to the hash table. Not all DIEs that we
18863 find interesting need to be in the hash table, because we
18864 also have the parent/sibling/child chains; only those that we
18865 might refer to by offset later during partial symbol reading.
18867 For now this means things that might have be the target of a
18868 DW_AT_specification, DW_AT_abstract_origin, or
18869 DW_AT_extension. DW_AT_extension will refer only to
18870 namespaces; DW_AT_abstract_origin refers to functions (and
18871 many things under the function DIE, but we do not recurse
18872 into function DIEs during partial symbol reading) and
18873 possibly variables as well; DW_AT_specification refers to
18874 declarations. Declarations ought to have the DW_AT_declaration
18875 flag. It happens that GCC forgets to put it in sometimes, but
18876 only for functions, not for types.
18878 Adding more things than necessary to the hash table is harmless
18879 except for the performance cost. Adding too few will result in
18880 wasted time in find_partial_die, when we reread the compilation
18881 unit with load_all_dies set. */
18884 || abbrev
->tag
== DW_TAG_constant
18885 || abbrev
->tag
== DW_TAG_subprogram
18886 || abbrev
->tag
== DW_TAG_variable
18887 || abbrev
->tag
== DW_TAG_namespace
18888 || part_die
->is_declaration
)
18892 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
18893 to_underlying (part_die
->sect_off
),
18898 /* For some DIEs we want to follow their children (if any). For C
18899 we have no reason to follow the children of structures; for other
18900 languages we have to, so that we can get at method physnames
18901 to infer fully qualified class names, for DW_AT_specification,
18902 and for C++ template arguments. For C++, we also look one level
18903 inside functions to find template arguments (if the name of the
18904 function does not already contain the template arguments).
18906 For Ada and Fortran, we need to scan the children of subprograms
18907 and lexical blocks as well because these languages allow the
18908 definition of nested entities that could be interesting for the
18909 debugger, such as nested subprograms for instance. */
18910 if (last_die
->has_children
18912 || last_die
->tag
== DW_TAG_namespace
18913 || last_die
->tag
== DW_TAG_module
18914 || last_die
->tag
== DW_TAG_enumeration_type
18915 || (cu
->language
== language_cplus
18916 && last_die
->tag
== DW_TAG_subprogram
18917 && (last_die
->name
== NULL
18918 || strchr (last_die
->name
, '<') == NULL
))
18919 || (cu
->language
!= language_c
18920 && (last_die
->tag
== DW_TAG_class_type
18921 || last_die
->tag
== DW_TAG_interface_type
18922 || last_die
->tag
== DW_TAG_structure_type
18923 || last_die
->tag
== DW_TAG_union_type
))
18924 || ((cu
->language
== language_ada
18925 || cu
->language
== language_fortran
)
18926 && (last_die
->tag
== DW_TAG_subprogram
18927 || last_die
->tag
== DW_TAG_lexical_block
))))
18930 parent_die
= last_die
;
18934 /* Otherwise we skip to the next sibling, if any. */
18935 info_ptr
= locate_pdi_sibling (reader
, last_die
, info_ptr
);
18937 /* Back to the top, do it again. */
18941 partial_die_info::partial_die_info (sect_offset sect_off_
,
18942 struct abbrev_info
*abbrev
)
18943 : partial_die_info (sect_off_
, abbrev
->tag
, abbrev
->has_children
)
18947 /* Read a minimal amount of information into the minimal die structure.
18948 INFO_PTR should point just after the initial uleb128 of a DIE. */
18951 partial_die_info::read (const struct die_reader_specs
*reader
,
18952 const struct abbrev_info
&abbrev
, const gdb_byte
*info_ptr
)
18954 struct dwarf2_cu
*cu
= reader
->cu
;
18955 struct dwarf2_per_objfile
*dwarf2_per_objfile
18956 = cu
->per_cu
->dwarf2_per_objfile
;
18958 int has_low_pc_attr
= 0;
18959 int has_high_pc_attr
= 0;
18960 int high_pc_relative
= 0;
18962 std::vector
<struct attribute
> attr_vec (abbrev
.num_attrs
);
18963 for (i
= 0; i
< abbrev
.num_attrs
; ++i
)
18965 bool need_reprocess
;
18966 info_ptr
= read_attribute (reader
, &attr_vec
[i
], &abbrev
.attrs
[i
],
18967 info_ptr
, &need_reprocess
);
18968 /* String and address offsets that need to do the reprocessing have
18969 already been read at this point, so there is no need to wait until
18970 the loop terminates to do the reprocessing. */
18971 if (need_reprocess
)
18972 read_attribute_reprocess (reader
, &attr_vec
[i
]);
18973 attribute
&attr
= attr_vec
[i
];
18974 /* Store the data if it is of an attribute we want to keep in a
18975 partial symbol table. */
18981 case DW_TAG_compile_unit
:
18982 case DW_TAG_partial_unit
:
18983 case DW_TAG_type_unit
:
18984 /* Compilation units have a DW_AT_name that is a filename, not
18985 a source language identifier. */
18986 case DW_TAG_enumeration_type
:
18987 case DW_TAG_enumerator
:
18988 /* These tags always have simple identifiers already; no need
18989 to canonicalize them. */
18990 name
= DW_STRING (&attr
);
18994 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
18997 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
18998 &objfile
->per_bfd
->storage_obstack
);
19003 case DW_AT_linkage_name
:
19004 case DW_AT_MIPS_linkage_name
:
19005 /* Note that both forms of linkage name might appear. We
19006 assume they will be the same, and we only store the last
19008 linkage_name
= DW_STRING (&attr
);
19011 has_low_pc_attr
= 1;
19012 lowpc
= attr_value_as_address (&attr
);
19014 case DW_AT_high_pc
:
19015 has_high_pc_attr
= 1;
19016 highpc
= attr_value_as_address (&attr
);
19017 if (cu
->header
.version
>= 4 && attr_form_is_constant (&attr
))
19018 high_pc_relative
= 1;
19020 case DW_AT_location
:
19021 /* Support the .debug_loc offsets. */
19022 if (attr_form_is_block (&attr
))
19024 d
.locdesc
= DW_BLOCK (&attr
);
19026 else if (attr_form_is_section_offset (&attr
))
19028 dwarf2_complex_location_expr_complaint ();
19032 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
19033 "partial symbol information");
19036 case DW_AT_external
:
19037 is_external
= DW_UNSND (&attr
);
19039 case DW_AT_declaration
:
19040 is_declaration
= DW_UNSND (&attr
);
19045 case DW_AT_abstract_origin
:
19046 case DW_AT_specification
:
19047 case DW_AT_extension
:
19048 has_specification
= 1;
19049 spec_offset
= dwarf2_get_ref_die_offset (&attr
);
19050 spec_is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19051 || cu
->per_cu
->is_dwz
);
19053 case DW_AT_sibling
:
19054 /* Ignore absolute siblings, they might point outside of
19055 the current compile unit. */
19056 if (attr
.form
== DW_FORM_ref_addr
)
19057 complaint (_("ignoring absolute DW_AT_sibling"));
19060 const gdb_byte
*buffer
= reader
->buffer
;
19061 sect_offset off
= dwarf2_get_ref_die_offset (&attr
);
19062 const gdb_byte
*sibling_ptr
= buffer
+ to_underlying (off
);
19064 if (sibling_ptr
< info_ptr
)
19065 complaint (_("DW_AT_sibling points backwards"));
19066 else if (sibling_ptr
> reader
->buffer_end
)
19067 dwarf2_section_buffer_overflow_complaint (reader
->die_section
);
19069 sibling
= sibling_ptr
;
19072 case DW_AT_byte_size
:
19075 case DW_AT_const_value
:
19076 has_const_value
= 1;
19078 case DW_AT_calling_convention
:
19079 /* DWARF doesn't provide a way to identify a program's source-level
19080 entry point. DW_AT_calling_convention attributes are only meant
19081 to describe functions' calling conventions.
19083 However, because it's a necessary piece of information in
19084 Fortran, and before DWARF 4 DW_CC_program was the only
19085 piece of debugging information whose definition refers to
19086 a 'main program' at all, several compilers marked Fortran
19087 main programs with DW_CC_program --- even when those
19088 functions use the standard calling conventions.
19090 Although DWARF now specifies a way to provide this
19091 information, we support this practice for backward
19093 if (DW_UNSND (&attr
) == DW_CC_program
19094 && cu
->language
== language_fortran
)
19095 main_subprogram
= 1;
19098 if (DW_UNSND (&attr
) == DW_INL_inlined
19099 || DW_UNSND (&attr
) == DW_INL_declared_inlined
)
19100 may_be_inlined
= 1;
19104 if (tag
== DW_TAG_imported_unit
)
19106 d
.sect_off
= dwarf2_get_ref_die_offset (&attr
);
19107 is_dwz
= (attr
.form
== DW_FORM_GNU_ref_alt
19108 || cu
->per_cu
->is_dwz
);
19112 case DW_AT_main_subprogram
:
19113 main_subprogram
= DW_UNSND (&attr
);
19118 /* It would be nice to reuse dwarf2_get_pc_bounds here,
19119 but that requires a full DIE, so instead we just
19121 int need_ranges_base
= tag
!= DW_TAG_compile_unit
;
19122 unsigned int ranges_offset
= (DW_UNSND (&attr
)
19123 + (need_ranges_base
19127 /* Value of the DW_AT_ranges attribute is the offset in the
19128 .debug_ranges section. */
19129 if (dwarf2_ranges_read (ranges_offset
, &lowpc
, &highpc
, cu
,
19140 /* For Ada, if both the name and the linkage name appear, we prefer
19141 the latter. This lets "catch exception" work better, regardless
19142 of the order in which the name and linkage name were emitted.
19143 Really, though, this is just a workaround for the fact that gdb
19144 doesn't store both the name and the linkage name. */
19145 if (cu
->language
== language_ada
&& linkage_name
!= nullptr)
19146 name
= linkage_name
;
19148 if (high_pc_relative
)
19151 if (has_low_pc_attr
&& has_high_pc_attr
)
19153 /* When using the GNU linker, .gnu.linkonce. sections are used to
19154 eliminate duplicate copies of functions and vtables and such.
19155 The linker will arbitrarily choose one and discard the others.
19156 The AT_*_pc values for such functions refer to local labels in
19157 these sections. If the section from that file was discarded, the
19158 labels are not in the output, so the relocs get a value of 0.
19159 If this is a discarded function, mark the pc bounds as invalid,
19160 so that GDB will ignore it. */
19161 if (lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
19163 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19164 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19166 complaint (_("DW_AT_low_pc %s is zero "
19167 "for DIE at %s [in module %s]"),
19168 paddress (gdbarch
, lowpc
),
19169 sect_offset_str (sect_off
),
19170 objfile_name (objfile
));
19172 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
19173 else if (lowpc
>= highpc
)
19175 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19176 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19178 complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
19179 "for DIE at %s [in module %s]"),
19180 paddress (gdbarch
, lowpc
),
19181 paddress (gdbarch
, highpc
),
19182 sect_offset_str (sect_off
),
19183 objfile_name (objfile
));
19192 /* Find a cached partial DIE at OFFSET in CU. */
19194 struct partial_die_info
*
19195 dwarf2_cu::find_partial_die (sect_offset sect_off
)
19197 struct partial_die_info
*lookup_die
= NULL
;
19198 struct partial_die_info
part_die (sect_off
);
19200 lookup_die
= ((struct partial_die_info
*)
19201 htab_find_with_hash (partial_dies
, &part_die
,
19202 to_underlying (sect_off
)));
19207 /* Find a partial DIE at OFFSET, which may or may not be in CU,
19208 except in the case of .debug_types DIEs which do not reference
19209 outside their CU (they do however referencing other types via
19210 DW_FORM_ref_sig8). */
19212 static const struct cu_partial_die_info
19213 find_partial_die (sect_offset sect_off
, int offset_in_dwz
, struct dwarf2_cu
*cu
)
19215 struct dwarf2_per_objfile
*dwarf2_per_objfile
19216 = cu
->per_cu
->dwarf2_per_objfile
;
19217 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19218 struct dwarf2_per_cu_data
*per_cu
= NULL
;
19219 struct partial_die_info
*pd
= NULL
;
19221 if (offset_in_dwz
== cu
->per_cu
->is_dwz
19222 && offset_in_cu_p (&cu
->header
, sect_off
))
19224 pd
= cu
->find_partial_die (sect_off
);
19227 /* We missed recording what we needed.
19228 Load all dies and try again. */
19229 per_cu
= cu
->per_cu
;
19233 /* TUs don't reference other CUs/TUs (except via type signatures). */
19234 if (cu
->per_cu
->is_debug_types
)
19236 error (_("Dwarf Error: Type Unit at offset %s contains"
19237 " external reference to offset %s [in module %s].\n"),
19238 sect_offset_str (cu
->header
.sect_off
), sect_offset_str (sect_off
),
19239 bfd_get_filename (objfile
->obfd
));
19241 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
19242 dwarf2_per_objfile
);
19244 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
19245 load_partial_comp_unit (per_cu
);
19247 per_cu
->cu
->last_used
= 0;
19248 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19251 /* If we didn't find it, and not all dies have been loaded,
19252 load them all and try again. */
19254 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
19256 per_cu
->load_all_dies
= 1;
19258 /* This is nasty. When we reread the DIEs, somewhere up the call chain
19259 THIS_CU->cu may already be in use. So we can't just free it and
19260 replace its DIEs with the ones we read in. Instead, we leave those
19261 DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
19262 and clobber THIS_CU->cu->partial_dies with the hash table for the new
19264 load_partial_comp_unit (per_cu
);
19266 pd
= per_cu
->cu
->find_partial_die (sect_off
);
19270 internal_error (__FILE__
, __LINE__
,
19271 _("could not find partial DIE %s "
19272 "in cache [from module %s]\n"),
19273 sect_offset_str (sect_off
), bfd_get_filename (objfile
->obfd
));
19274 return { per_cu
->cu
, pd
};
19277 /* See if we can figure out if the class lives in a namespace. We do
19278 this by looking for a member function; its demangled name will
19279 contain namespace info, if there is any. */
19282 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
19283 struct dwarf2_cu
*cu
)
19285 /* NOTE: carlton/2003-10-07: Getting the info this way changes
19286 what template types look like, because the demangler
19287 frequently doesn't give the same name as the debug info. We
19288 could fix this by only using the demangled name to get the
19289 prefix (but see comment in read_structure_type). */
19291 struct partial_die_info
*real_pdi
;
19292 struct partial_die_info
*child_pdi
;
19294 /* If this DIE (this DIE's specification, if any) has a parent, then
19295 we should not do this. We'll prepend the parent's fully qualified
19296 name when we create the partial symbol. */
19298 real_pdi
= struct_pdi
;
19299 while (real_pdi
->has_specification
)
19301 auto res
= find_partial_die (real_pdi
->spec_offset
,
19302 real_pdi
->spec_is_dwz
, cu
);
19303 real_pdi
= res
.pdi
;
19307 if (real_pdi
->die_parent
!= NULL
)
19310 for (child_pdi
= struct_pdi
->die_child
;
19312 child_pdi
= child_pdi
->die_sibling
)
19314 if (child_pdi
->tag
== DW_TAG_subprogram
19315 && child_pdi
->linkage_name
!= NULL
)
19317 gdb::unique_xmalloc_ptr
<char> actual_class_name
19318 (language_class_name_from_physname (cu
->language_defn
,
19319 child_pdi
->linkage_name
));
19320 if (actual_class_name
!= NULL
)
19322 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19324 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
19325 actual_class_name
.get ());
19333 partial_die_info::fixup (struct dwarf2_cu
*cu
)
19335 /* Once we've fixed up a die, there's no point in doing so again.
19336 This also avoids a memory leak if we were to call
19337 guess_partial_die_structure_name multiple times. */
19341 /* If we found a reference attribute and the DIE has no name, try
19342 to find a name in the referred to DIE. */
19344 if (name
== NULL
&& has_specification
)
19346 struct partial_die_info
*spec_die
;
19348 auto res
= find_partial_die (spec_offset
, spec_is_dwz
, cu
);
19349 spec_die
= res
.pdi
;
19352 spec_die
->fixup (cu
);
19354 if (spec_die
->name
)
19356 name
= spec_die
->name
;
19358 /* Copy DW_AT_external attribute if it is set. */
19359 if (spec_die
->is_external
)
19360 is_external
= spec_die
->is_external
;
19364 /* Set default names for some unnamed DIEs. */
19366 if (name
== NULL
&& tag
== DW_TAG_namespace
)
19367 name
= CP_ANONYMOUS_NAMESPACE_STR
;
19369 /* If there is no parent die to provide a namespace, and there are
19370 children, see if we can determine the namespace from their linkage
19372 if (cu
->language
== language_cplus
19373 && !cu
->per_cu
->dwarf2_per_objfile
->types
.empty ()
19374 && die_parent
== NULL
19376 && (tag
== DW_TAG_class_type
19377 || tag
== DW_TAG_structure_type
19378 || tag
== DW_TAG_union_type
))
19379 guess_partial_die_structure_name (this, cu
);
19381 /* GCC might emit a nameless struct or union that has a linkage
19382 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
19384 && (tag
== DW_TAG_class_type
19385 || tag
== DW_TAG_interface_type
19386 || tag
== DW_TAG_structure_type
19387 || tag
== DW_TAG_union_type
)
19388 && linkage_name
!= NULL
)
19390 gdb::unique_xmalloc_ptr
<char> demangled
19391 (gdb_demangle (linkage_name
, DMGL_TYPES
));
19392 if (demangled
!= nullptr)
19396 /* Strip any leading namespaces/classes, keep only the base name.
19397 DW_AT_name for named DIEs does not contain the prefixes. */
19398 base
= strrchr (demangled
.get (), ':');
19399 if (base
&& base
> demangled
.get () && base
[-1] == ':')
19402 base
= demangled
.get ();
19404 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
19405 name
= obstack_strdup (&objfile
->per_bfd
->storage_obstack
, base
);
19412 /* Process the attributes that had to be skipped in the first round. These
19413 attributes are the ones that need str_offsets_base or addr_base attributes.
19414 They could not have been processed in the first round, because at the time
19415 the values of str_offsets_base or addr_base may not have been known. */
19416 void read_attribute_reprocess (const struct die_reader_specs
*reader
,
19417 struct attribute
*attr
)
19419 struct dwarf2_cu
*cu
= reader
->cu
;
19420 switch (attr
->form
)
19422 case DW_FORM_addrx
:
19423 case DW_FORM_GNU_addr_index
:
19424 DW_ADDR (attr
) = read_addr_index (cu
, DW_UNSND (attr
));
19427 case DW_FORM_strx1
:
19428 case DW_FORM_strx2
:
19429 case DW_FORM_strx3
:
19430 case DW_FORM_strx4
:
19431 case DW_FORM_GNU_str_index
:
19433 unsigned int str_index
= DW_UNSND (attr
);
19434 if (reader
->dwo_file
!= NULL
)
19436 DW_STRING (attr
) = read_dwo_str_index (reader
, str_index
);
19437 DW_STRING_IS_CANONICAL (attr
) = 0;
19441 DW_STRING (attr
) = read_stub_str_index (cu
, str_index
);
19442 DW_STRING_IS_CANONICAL (attr
) = 0;
19447 gdb_assert_not_reached (_("Unexpected DWARF form."));
19451 /* Read an attribute value described by an attribute form. */
19453 static const gdb_byte
*
19454 read_attribute_value (const struct die_reader_specs
*reader
,
19455 struct attribute
*attr
, unsigned form
,
19456 LONGEST implicit_const
, const gdb_byte
*info_ptr
,
19457 bool *need_reprocess
)
19459 struct dwarf2_cu
*cu
= reader
->cu
;
19460 struct dwarf2_per_objfile
*dwarf2_per_objfile
19461 = cu
->per_cu
->dwarf2_per_objfile
;
19462 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
19463 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
19464 bfd
*abfd
= reader
->abfd
;
19465 struct comp_unit_head
*cu_header
= &cu
->header
;
19466 unsigned int bytes_read
;
19467 struct dwarf_block
*blk
;
19468 *need_reprocess
= false;
19470 attr
->form
= (enum dwarf_form
) form
;
19473 case DW_FORM_ref_addr
:
19474 if (cu
->header
.version
== 2)
19475 DW_UNSND (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19477 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
,
19478 &cu
->header
, &bytes_read
);
19479 info_ptr
+= bytes_read
;
19481 case DW_FORM_GNU_ref_alt
:
19482 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19483 info_ptr
+= bytes_read
;
19486 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
19487 DW_ADDR (attr
) = gdbarch_adjust_dwarf2_addr (gdbarch
, DW_ADDR (attr
));
19488 info_ptr
+= bytes_read
;
19490 case DW_FORM_block2
:
19491 blk
= dwarf_alloc_block (cu
);
19492 blk
->size
= read_2_bytes (abfd
, info_ptr
);
19494 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19495 info_ptr
+= blk
->size
;
19496 DW_BLOCK (attr
) = blk
;
19498 case DW_FORM_block4
:
19499 blk
= dwarf_alloc_block (cu
);
19500 blk
->size
= read_4_bytes (abfd
, info_ptr
);
19502 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19503 info_ptr
+= blk
->size
;
19504 DW_BLOCK (attr
) = blk
;
19506 case DW_FORM_data2
:
19507 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
19510 case DW_FORM_data4
:
19511 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
19514 case DW_FORM_data8
:
19515 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
19518 case DW_FORM_data16
:
19519 blk
= dwarf_alloc_block (cu
);
19521 blk
->data
= read_n_bytes (abfd
, info_ptr
, 16);
19523 DW_BLOCK (attr
) = blk
;
19525 case DW_FORM_sec_offset
:
19526 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
19527 info_ptr
+= bytes_read
;
19529 case DW_FORM_string
:
19530 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
19531 DW_STRING_IS_CANONICAL (attr
) = 0;
19532 info_ptr
+= bytes_read
;
19535 if (!cu
->per_cu
->is_dwz
)
19537 DW_STRING (attr
) = read_indirect_string (dwarf2_per_objfile
,
19538 abfd
, info_ptr
, cu_header
,
19540 DW_STRING_IS_CANONICAL (attr
) = 0;
19541 info_ptr
+= bytes_read
;
19545 case DW_FORM_line_strp
:
19546 if (!cu
->per_cu
->is_dwz
)
19548 DW_STRING (attr
) = read_indirect_line_string (dwarf2_per_objfile
,
19550 cu_header
, &bytes_read
);
19551 DW_STRING_IS_CANONICAL (attr
) = 0;
19552 info_ptr
+= bytes_read
;
19556 case DW_FORM_GNU_strp_alt
:
19558 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
19559 LONGEST str_offset
= read_offset (abfd
, info_ptr
, cu_header
,
19562 DW_STRING (attr
) = read_indirect_string_from_dwz (objfile
,
19564 DW_STRING_IS_CANONICAL (attr
) = 0;
19565 info_ptr
+= bytes_read
;
19568 case DW_FORM_exprloc
:
19569 case DW_FORM_block
:
19570 blk
= dwarf_alloc_block (cu
);
19571 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19572 info_ptr
+= bytes_read
;
19573 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19574 info_ptr
+= blk
->size
;
19575 DW_BLOCK (attr
) = blk
;
19577 case DW_FORM_block1
:
19578 blk
= dwarf_alloc_block (cu
);
19579 blk
->size
= read_1_byte (abfd
, info_ptr
);
19581 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
19582 info_ptr
+= blk
->size
;
19583 DW_BLOCK (attr
) = blk
;
19585 case DW_FORM_data1
:
19586 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19590 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
19593 case DW_FORM_flag_present
:
19594 DW_UNSND (attr
) = 1;
19596 case DW_FORM_sdata
:
19597 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19598 info_ptr
+= bytes_read
;
19600 case DW_FORM_udata
:
19601 case DW_FORM_rnglistx
:
19602 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19603 info_ptr
+= bytes_read
;
19606 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19607 + read_1_byte (abfd
, info_ptr
));
19611 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19612 + read_2_bytes (abfd
, info_ptr
));
19616 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19617 + read_4_bytes (abfd
, info_ptr
));
19621 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19622 + read_8_bytes (abfd
, info_ptr
));
19625 case DW_FORM_ref_sig8
:
19626 DW_SIGNATURE (attr
) = read_8_bytes (abfd
, info_ptr
);
19629 case DW_FORM_ref_udata
:
19630 DW_UNSND (attr
) = (to_underlying (cu
->header
.sect_off
)
19631 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
19632 info_ptr
+= bytes_read
;
19634 case DW_FORM_indirect
:
19635 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19636 info_ptr
+= bytes_read
;
19637 if (form
== DW_FORM_implicit_const
)
19639 implicit_const
= read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
19640 info_ptr
+= bytes_read
;
19642 info_ptr
= read_attribute_value (reader
, attr
, form
, implicit_const
,
19643 info_ptr
, need_reprocess
);
19645 case DW_FORM_implicit_const
:
19646 DW_SND (attr
) = implicit_const
;
19648 case DW_FORM_addrx
:
19649 case DW_FORM_GNU_addr_index
:
19650 *need_reprocess
= true;
19651 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19652 info_ptr
+= bytes_read
;
19655 case DW_FORM_strx1
:
19656 case DW_FORM_strx2
:
19657 case DW_FORM_strx3
:
19658 case DW_FORM_strx4
:
19659 case DW_FORM_GNU_str_index
:
19661 ULONGEST str_index
;
19662 if (form
== DW_FORM_strx1
)
19664 str_index
= read_1_byte (abfd
, info_ptr
);
19667 else if (form
== DW_FORM_strx2
)
19669 str_index
= read_2_bytes (abfd
, info_ptr
);
19672 else if (form
== DW_FORM_strx3
)
19674 str_index
= read_3_bytes (abfd
, info_ptr
);
19677 else if (form
== DW_FORM_strx4
)
19679 str_index
= read_4_bytes (abfd
, info_ptr
);
19684 str_index
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
19685 info_ptr
+= bytes_read
;
19687 *need_reprocess
= true;
19688 DW_UNSND (attr
) = str_index
;
19692 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
19693 dwarf_form_name (form
),
19694 bfd_get_filename (abfd
));
19698 if (cu
->per_cu
->is_dwz
&& attr_form_is_ref (attr
))
19699 attr
->form
= DW_FORM_GNU_ref_alt
;
19701 /* We have seen instances where the compiler tried to emit a byte
19702 size attribute of -1 which ended up being encoded as an unsigned
19703 0xffffffff. Although 0xffffffff is technically a valid size value,
19704 an object of this size seems pretty unlikely so we can relatively
19705 safely treat these cases as if the size attribute was invalid and
19706 treat them as zero by default. */
19707 if (attr
->name
== DW_AT_byte_size
19708 && form
== DW_FORM_data4
19709 && DW_UNSND (attr
) >= 0xffffffff)
19712 (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
19713 hex_string (DW_UNSND (attr
)));
19714 DW_UNSND (attr
) = 0;
19720 /* Read an attribute described by an abbreviated attribute. */
19722 static const gdb_byte
*
19723 read_attribute (const struct die_reader_specs
*reader
,
19724 struct attribute
*attr
, struct attr_abbrev
*abbrev
,
19725 const gdb_byte
*info_ptr
, bool *need_reprocess
)
19727 attr
->name
= abbrev
->name
;
19728 return read_attribute_value (reader
, attr
, abbrev
->form
,
19729 abbrev
->implicit_const
, info_ptr
,
19733 /* Read dwarf information from a buffer. */
19735 static unsigned int
19736 read_1_byte (bfd
*abfd
, const gdb_byte
*buf
)
19738 return bfd_get_8 (abfd
, buf
);
19742 read_1_signed_byte (bfd
*abfd
, const gdb_byte
*buf
)
19744 return bfd_get_signed_8 (abfd
, buf
);
19747 static unsigned int
19748 read_2_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19750 return bfd_get_16 (abfd
, buf
);
19754 read_2_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19756 return bfd_get_signed_16 (abfd
, buf
);
19759 static unsigned int
19760 read_3_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19762 unsigned int result
= 0;
19763 for (int i
= 0; i
< 3; ++i
)
19765 unsigned char byte
= bfd_get_8 (abfd
, buf
);
19767 result
|= ((unsigned int) byte
<< (i
* 8));
19772 static unsigned int
19773 read_4_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19775 return bfd_get_32 (abfd
, buf
);
19779 read_4_signed_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19781 return bfd_get_signed_32 (abfd
, buf
);
19785 read_8_bytes (bfd
*abfd
, const gdb_byte
*buf
)
19787 return bfd_get_64 (abfd
, buf
);
19791 read_address (bfd
*abfd
, const gdb_byte
*buf
, struct dwarf2_cu
*cu
,
19792 unsigned int *bytes_read
)
19794 struct comp_unit_head
*cu_header
= &cu
->header
;
19795 CORE_ADDR retval
= 0;
19797 if (cu_header
->signed_addr_p
)
19799 switch (cu_header
->addr_size
)
19802 retval
= bfd_get_signed_16 (abfd
, buf
);
19805 retval
= bfd_get_signed_32 (abfd
, buf
);
19808 retval
= bfd_get_signed_64 (abfd
, buf
);
19811 internal_error (__FILE__
, __LINE__
,
19812 _("read_address: bad switch, signed [in module %s]"),
19813 bfd_get_filename (abfd
));
19818 switch (cu_header
->addr_size
)
19821 retval
= bfd_get_16 (abfd
, buf
);
19824 retval
= bfd_get_32 (abfd
, buf
);
19827 retval
= bfd_get_64 (abfd
, buf
);
19830 internal_error (__FILE__
, __LINE__
,
19831 _("read_address: bad switch, "
19832 "unsigned [in module %s]"),
19833 bfd_get_filename (abfd
));
19837 *bytes_read
= cu_header
->addr_size
;
19841 /* Read the initial length from a section. The (draft) DWARF 3
19842 specification allows the initial length to take up either 4 bytes
19843 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
19844 bytes describe the length and all offsets will be 8 bytes in length
19847 An older, non-standard 64-bit format is also handled by this
19848 function. The older format in question stores the initial length
19849 as an 8-byte quantity without an escape value. Lengths greater
19850 than 2^32 aren't very common which means that the initial 4 bytes
19851 is almost always zero. Since a length value of zero doesn't make
19852 sense for the 32-bit format, this initial zero can be considered to
19853 be an escape value which indicates the presence of the older 64-bit
19854 format. As written, the code can't detect (old format) lengths
19855 greater than 4GB. If it becomes necessary to handle lengths
19856 somewhat larger than 4GB, we could allow other small values (such
19857 as the non-sensical values of 1, 2, and 3) to also be used as
19858 escape values indicating the presence of the old format.
19860 The value returned via bytes_read should be used to increment the
19861 relevant pointer after calling read_initial_length().
19863 [ Note: read_initial_length() and read_offset() are based on the
19864 document entitled "DWARF Debugging Information Format", revision
19865 3, draft 8, dated November 19, 2001. This document was obtained
19868 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
19870 This document is only a draft and is subject to change. (So beware.)
19872 Details regarding the older, non-standard 64-bit format were
19873 determined empirically by examining 64-bit ELF files produced by
19874 the SGI toolchain on an IRIX 6.5 machine.
19876 - Kevin, July 16, 2002
19880 read_initial_length (bfd
*abfd
, const gdb_byte
*buf
, unsigned int *bytes_read
)
19882 LONGEST length
= bfd_get_32 (abfd
, buf
);
19884 if (length
== 0xffffffff)
19886 length
= bfd_get_64 (abfd
, buf
+ 4);
19889 else if (length
== 0)
19891 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
19892 length
= bfd_get_64 (abfd
, buf
);
19903 /* Cover function for read_initial_length.
19904 Returns the length of the object at BUF, and stores the size of the
19905 initial length in *BYTES_READ and stores the size that offsets will be in
19907 If the initial length size is not equivalent to that specified in
19908 CU_HEADER then issue a complaint.
19909 This is useful when reading non-comp-unit headers. */
19912 read_checked_initial_length_and_offset (bfd
*abfd
, const gdb_byte
*buf
,
19913 const struct comp_unit_head
*cu_header
,
19914 unsigned int *bytes_read
,
19915 unsigned int *offset_size
)
19917 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
19919 gdb_assert (cu_header
->initial_length_size
== 4
19920 || cu_header
->initial_length_size
== 8
19921 || cu_header
->initial_length_size
== 12);
19923 if (cu_header
->initial_length_size
!= *bytes_read
)
19924 complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
19926 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
19930 /* Read an offset from the data stream. The size of the offset is
19931 given by cu_header->offset_size. */
19934 read_offset (bfd
*abfd
, const gdb_byte
*buf
,
19935 const struct comp_unit_head
*cu_header
,
19936 unsigned int *bytes_read
)
19938 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
19940 *bytes_read
= cu_header
->offset_size
;
19944 /* Read an offset from the data stream. */
19947 read_offset_1 (bfd
*abfd
, const gdb_byte
*buf
, unsigned int offset_size
)
19949 LONGEST retval
= 0;
19951 switch (offset_size
)
19954 retval
= bfd_get_32 (abfd
, buf
);
19957 retval
= bfd_get_64 (abfd
, buf
);
19960 internal_error (__FILE__
, __LINE__
,
19961 _("read_offset_1: bad switch [in module %s]"),
19962 bfd_get_filename (abfd
));
19968 static const gdb_byte
*
19969 read_n_bytes (bfd
*abfd
, const gdb_byte
*buf
, unsigned int size
)
19971 /* If the size of a host char is 8 bits, we can return a pointer
19972 to the buffer, otherwise we have to copy the data to a buffer
19973 allocated on the temporary obstack. */
19974 gdb_assert (HOST_CHAR_BIT
== 8);
19978 static const char *
19979 read_direct_string (bfd
*abfd
, const gdb_byte
*buf
,
19980 unsigned int *bytes_read_ptr
)
19982 /* If the size of a host char is 8 bits, we can return a pointer
19983 to the string, otherwise we have to copy the string to a buffer
19984 allocated on the temporary obstack. */
19985 gdb_assert (HOST_CHAR_BIT
== 8);
19988 *bytes_read_ptr
= 1;
19991 *bytes_read_ptr
= strlen ((const char *) buf
) + 1;
19992 return (const char *) buf
;
19995 /* Return pointer to string at section SECT offset STR_OFFSET with error
19996 reporting strings FORM_NAME and SECT_NAME. */
19998 static const char *
19999 read_indirect_string_at_offset_from (struct objfile
*objfile
,
20000 bfd
*abfd
, LONGEST str_offset
,
20001 struct dwarf2_section_info
*sect
,
20002 const char *form_name
,
20003 const char *sect_name
)
20005 dwarf2_read_section (objfile
, sect
);
20006 if (sect
->buffer
== NULL
)
20007 error (_("%s used without %s section [in module %s]"),
20008 form_name
, sect_name
, bfd_get_filename (abfd
));
20009 if (str_offset
>= sect
->size
)
20010 error (_("%s pointing outside of %s section [in module %s]"),
20011 form_name
, sect_name
, bfd_get_filename (abfd
));
20012 gdb_assert (HOST_CHAR_BIT
== 8);
20013 if (sect
->buffer
[str_offset
] == '\0')
20015 return (const char *) (sect
->buffer
+ str_offset
);
20018 /* Return pointer to string at .debug_str offset STR_OFFSET. */
20020 static const char *
20021 read_indirect_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20022 bfd
*abfd
, LONGEST str_offset
)
20024 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20026 &dwarf2_per_objfile
->str
,
20027 "DW_FORM_strp", ".debug_str");
20030 /* Return pointer to string at .debug_line_str offset STR_OFFSET. */
20032 static const char *
20033 read_indirect_line_string_at_offset (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20034 bfd
*abfd
, LONGEST str_offset
)
20036 return read_indirect_string_at_offset_from (dwarf2_per_objfile
->objfile
,
20038 &dwarf2_per_objfile
->line_str
,
20039 "DW_FORM_line_strp",
20040 ".debug_line_str");
20043 /* Read a string at offset STR_OFFSET in the .debug_str section from
20044 the .dwz file DWZ. Throw an error if the offset is too large. If
20045 the string consists of a single NUL byte, return NULL; otherwise
20046 return a pointer to the string. */
20048 static const char *
20049 read_indirect_string_from_dwz (struct objfile
*objfile
, struct dwz_file
*dwz
,
20050 LONGEST str_offset
)
20052 dwarf2_read_section (objfile
, &dwz
->str
);
20054 if (dwz
->str
.buffer
== NULL
)
20055 error (_("DW_FORM_GNU_strp_alt used without .debug_str "
20056 "section [in module %s]"),
20057 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20058 if (str_offset
>= dwz
->str
.size
)
20059 error (_("DW_FORM_GNU_strp_alt pointing outside of "
20060 ".debug_str section [in module %s]"),
20061 bfd_get_filename (dwz
->dwz_bfd
.get ()));
20062 gdb_assert (HOST_CHAR_BIT
== 8);
20063 if (dwz
->str
.buffer
[str_offset
] == '\0')
20065 return (const char *) (dwz
->str
.buffer
+ str_offset
);
20068 /* Return pointer to string at .debug_str offset as read from BUF.
20069 BUF is assumed to be in a compilation unit described by CU_HEADER.
20070 Return *BYTES_READ_PTR count of bytes read from BUF. */
20072 static const char *
20073 read_indirect_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
, bfd
*abfd
,
20074 const gdb_byte
*buf
,
20075 const struct comp_unit_head
*cu_header
,
20076 unsigned int *bytes_read_ptr
)
20078 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20080 return read_indirect_string_at_offset (dwarf2_per_objfile
, abfd
, str_offset
);
20083 /* Return pointer to string at .debug_line_str offset as read from BUF.
20084 BUF is assumed to be in a compilation unit described by CU_HEADER.
20085 Return *BYTES_READ_PTR count of bytes read from BUF. */
20087 static const char *
20088 read_indirect_line_string (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20089 bfd
*abfd
, const gdb_byte
*buf
,
20090 const struct comp_unit_head
*cu_header
,
20091 unsigned int *bytes_read_ptr
)
20093 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
20095 return read_indirect_line_string_at_offset (dwarf2_per_objfile
, abfd
,
20100 read_unsigned_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20101 unsigned int *bytes_read_ptr
)
20104 unsigned int num_read
;
20106 unsigned char byte
;
20113 byte
= bfd_get_8 (abfd
, buf
);
20116 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20117 if ((byte
& 128) == 0)
20123 *bytes_read_ptr
= num_read
;
20128 read_signed_leb128 (bfd
*abfd
, const gdb_byte
*buf
,
20129 unsigned int *bytes_read_ptr
)
20132 int shift
, num_read
;
20133 unsigned char byte
;
20140 byte
= bfd_get_8 (abfd
, buf
);
20143 result
|= ((ULONGEST
) (byte
& 127) << shift
);
20145 if ((byte
& 128) == 0)
20150 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
20151 result
|= -(((ULONGEST
) 1) << shift
);
20152 *bytes_read_ptr
= num_read
;
20156 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
20157 ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
20158 ADDR_SIZE is the size of addresses from the CU header. */
20161 read_addr_index_1 (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20162 unsigned int addr_index
, gdb::optional
<ULONGEST
> addr_base
,
20165 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20166 bfd
*abfd
= objfile
->obfd
;
20167 const gdb_byte
*info_ptr
;
20168 ULONGEST addr_base_or_zero
= addr_base
.has_value () ? *addr_base
: 0;
20170 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->addr
);
20171 if (dwarf2_per_objfile
->addr
.buffer
== NULL
)
20172 error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
20173 objfile_name (objfile
));
20174 if (addr_base_or_zero
+ addr_index
* addr_size
20175 >= dwarf2_per_objfile
->addr
.size
)
20176 error (_("DW_FORM_addr_index pointing outside of "
20177 ".debug_addr section [in module %s]"),
20178 objfile_name (objfile
));
20179 info_ptr
= (dwarf2_per_objfile
->addr
.buffer
20180 + addr_base_or_zero
+ addr_index
* addr_size
);
20181 if (addr_size
== 4)
20182 return bfd_get_32 (abfd
, info_ptr
);
20184 return bfd_get_64 (abfd
, info_ptr
);
20187 /* Given index ADDR_INDEX in .debug_addr, fetch the value. */
20190 read_addr_index (struct dwarf2_cu
*cu
, unsigned int addr_index
)
20192 return read_addr_index_1 (cu
->per_cu
->dwarf2_per_objfile
, addr_index
,
20193 cu
->addr_base
, cu
->header
.addr_size
);
20196 /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */
20199 read_addr_index_from_leb128 (struct dwarf2_cu
*cu
, const gdb_byte
*info_ptr
,
20200 unsigned int *bytes_read
)
20202 bfd
*abfd
= cu
->per_cu
->dwarf2_per_objfile
->objfile
->obfd
;
20203 unsigned int addr_index
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
20205 return read_addr_index (cu
, addr_index
);
20208 /* Given an index in .debug_addr, fetch the value.
20209 NOTE: This can be called during dwarf expression evaluation,
20210 long after the debug information has been read, and thus per_cu->cu
20211 may no longer exist. */
20214 dwarf2_read_addr_index (struct dwarf2_per_cu_data
*per_cu
,
20215 unsigned int addr_index
)
20217 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
20218 struct dwarf2_cu
*cu
= per_cu
->cu
;
20219 gdb::optional
<ULONGEST
> addr_base
;
20222 /* We need addr_base and addr_size.
20223 If we don't have PER_CU->cu, we have to get it.
20224 Nasty, but the alternative is storing the needed info in PER_CU,
20225 which at this point doesn't seem justified: it's not clear how frequently
20226 it would get used and it would increase the size of every PER_CU.
20227 Entry points like dwarf2_per_cu_addr_size do a similar thing
20228 so we're not in uncharted territory here.
20229 Alas we need to be a bit more complicated as addr_base is contained
20232 We don't need to read the entire CU(/TU).
20233 We just need the header and top level die.
20235 IWBN to use the aging mechanism to let us lazily later discard the CU.
20236 For now we skip this optimization. */
20240 addr_base
= cu
->addr_base
;
20241 addr_size
= cu
->header
.addr_size
;
20245 cutu_reader
reader (per_cu
, NULL
, 0, 0, false);
20246 addr_base
= reader
.cu
->addr_base
;
20247 addr_size
= reader
.cu
->header
.addr_size
;
20250 return read_addr_index_1 (dwarf2_per_objfile
, addr_index
, addr_base
,
20254 /* Given a DW_FORM_GNU_str_index value STR_INDEX, fetch the string.
20255 STR_SECTION, STR_OFFSETS_SECTION can be from a Fission stub or a
20258 static const char *
20259 read_str_index (struct dwarf2_cu
*cu
,
20260 struct dwarf2_section_info
*str_section
,
20261 struct dwarf2_section_info
*str_offsets_section
,
20262 ULONGEST str_offsets_base
, ULONGEST str_index
)
20264 struct dwarf2_per_objfile
*dwarf2_per_objfile
20265 = cu
->per_cu
->dwarf2_per_objfile
;
20266 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
20267 const char *objf_name
= objfile_name (objfile
);
20268 bfd
*abfd
= objfile
->obfd
;
20269 const gdb_byte
*info_ptr
;
20270 ULONGEST str_offset
;
20271 static const char form_name
[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
20273 dwarf2_read_section (objfile
, str_section
);
20274 dwarf2_read_section (objfile
, str_offsets_section
);
20275 if (str_section
->buffer
== NULL
)
20276 error (_("%s used without %s section"
20277 " in CU at offset %s [in module %s]"),
20278 form_name
, get_section_name (str_section
),
20279 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20280 if (str_offsets_section
->buffer
== NULL
)
20281 error (_("%s used without %s section"
20282 " in CU at offset %s [in module %s]"),
20283 form_name
, get_section_name (str_section
),
20284 sect_offset_str (cu
->header
.sect_off
), objf_name
);
20285 info_ptr
= (str_offsets_section
->buffer
20287 + str_index
* cu
->header
.offset_size
);
20288 if (cu
->header
.offset_size
== 4)
20289 str_offset
= bfd_get_32 (abfd
, info_ptr
);
20291 str_offset
= bfd_get_64 (abfd
, info_ptr
);
20292 if (str_offset
>= str_section
->size
)
20293 error (_("Offset from %s pointing outside of"
20294 " .debug_str.dwo section in CU at offset %s [in module %s]"),
20295 form_name
, sect_offset_str (cu
->header
.sect_off
), objf_name
);
20296 return (const char *) (str_section
->buffer
+ str_offset
);
20299 /* Given a DW_FORM_GNU_str_index from a DWO file, fetch the string. */
20301 static const char *
20302 read_dwo_str_index (const struct die_reader_specs
*reader
, ULONGEST str_index
)
20304 ULONGEST str_offsets_base
= reader
->cu
->header
.version
>= 5
20305 ? reader
->cu
->header
.addr_size
: 0;
20306 return read_str_index (reader
->cu
,
20307 &reader
->dwo_file
->sections
.str
,
20308 &reader
->dwo_file
->sections
.str_offsets
,
20309 str_offsets_base
, str_index
);
20312 /* Given a DW_FORM_GNU_str_index from a Fission stub, fetch the string. */
20314 static const char *
20315 read_stub_str_index (struct dwarf2_cu
*cu
, ULONGEST str_index
)
20317 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
20318 const char *objf_name
= objfile_name (objfile
);
20319 static const char form_name
[] = "DW_FORM_GNU_str_index";
20320 static const char str_offsets_attr_name
[] = "DW_AT_str_offsets";
20322 if (!cu
->str_offsets_base
.has_value ())
20323 error (_("%s used in Fission stub without %s"
20324 " in CU at offset 0x%lx [in module %s]"),
20325 form_name
, str_offsets_attr_name
,
20326 (long) cu
->header
.offset_size
, objf_name
);
20328 return read_str_index (cu
,
20329 &cu
->per_cu
->dwarf2_per_objfile
->str
,
20330 &cu
->per_cu
->dwarf2_per_objfile
->str_offsets
,
20331 *cu
->str_offsets_base
, str_index
);
20334 /* Return the length of an LEB128 number in BUF. */
20337 leb128_size (const gdb_byte
*buf
)
20339 const gdb_byte
*begin
= buf
;
20345 if ((byte
& 128) == 0)
20346 return buf
- begin
;
20351 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
20360 cu
->language
= language_c
;
20363 case DW_LANG_C_plus_plus
:
20364 case DW_LANG_C_plus_plus_11
:
20365 case DW_LANG_C_plus_plus_14
:
20366 cu
->language
= language_cplus
;
20369 cu
->language
= language_d
;
20371 case DW_LANG_Fortran77
:
20372 case DW_LANG_Fortran90
:
20373 case DW_LANG_Fortran95
:
20374 case DW_LANG_Fortran03
:
20375 case DW_LANG_Fortran08
:
20376 cu
->language
= language_fortran
;
20379 cu
->language
= language_go
;
20381 case DW_LANG_Mips_Assembler
:
20382 cu
->language
= language_asm
;
20384 case DW_LANG_Ada83
:
20385 case DW_LANG_Ada95
:
20386 cu
->language
= language_ada
;
20388 case DW_LANG_Modula2
:
20389 cu
->language
= language_m2
;
20391 case DW_LANG_Pascal83
:
20392 cu
->language
= language_pascal
;
20395 cu
->language
= language_objc
;
20398 case DW_LANG_Rust_old
:
20399 cu
->language
= language_rust
;
20401 case DW_LANG_Cobol74
:
20402 case DW_LANG_Cobol85
:
20404 cu
->language
= language_minimal
;
20407 cu
->language_defn
= language_def (cu
->language
);
20410 /* Return the named attribute or NULL if not there. */
20412 static struct attribute
*
20413 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20418 struct attribute
*spec
= NULL
;
20420 for (i
= 0; i
< die
->num_attrs
; ++i
)
20422 if (die
->attrs
[i
].name
== name
)
20423 return &die
->attrs
[i
];
20424 if (die
->attrs
[i
].name
== DW_AT_specification
20425 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
20426 spec
= &die
->attrs
[i
];
20432 die
= follow_die_ref (die
, spec
, &cu
);
20438 /* Return the named attribute or NULL if not there,
20439 but do not follow DW_AT_specification, etc.
20440 This is for use in contexts where we're reading .debug_types dies.
20441 Following DW_AT_specification, DW_AT_abstract_origin will take us
20442 back up the chain, and we want to go down. */
20444 static struct attribute
*
20445 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
)
20449 for (i
= 0; i
< die
->num_attrs
; ++i
)
20450 if (die
->attrs
[i
].name
== name
)
20451 return &die
->attrs
[i
];
20456 /* Return the string associated with a string-typed attribute, or NULL if it
20457 is either not found or is of an incorrect type. */
20459 static const char *
20460 dwarf2_string_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
20462 struct attribute
*attr
;
20463 const char *str
= NULL
;
20465 attr
= dwarf2_attr (die
, name
, cu
);
20469 if (attr
->form
== DW_FORM_strp
|| attr
->form
== DW_FORM_line_strp
20470 || attr
->form
== DW_FORM_string
20471 || attr
->form
== DW_FORM_strx
20472 || attr
->form
== DW_FORM_strx1
20473 || attr
->form
== DW_FORM_strx2
20474 || attr
->form
== DW_FORM_strx3
20475 || attr
->form
== DW_FORM_strx4
20476 || attr
->form
== DW_FORM_GNU_str_index
20477 || attr
->form
== DW_FORM_GNU_strp_alt
)
20478 str
= DW_STRING (attr
);
20480 complaint (_("string type expected for attribute %s for "
20481 "DIE at %s in module %s"),
20482 dwarf_attr_name (name
), sect_offset_str (die
->sect_off
),
20483 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
20489 /* Return the dwo name or NULL if not present. If present, it is in either
20490 DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute. */
20491 static const char *
20492 dwarf2_dwo_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
20494 const char *dwo_name
= dwarf2_string_attr (die
, DW_AT_GNU_dwo_name
, cu
);
20495 if (dwo_name
== nullptr)
20496 dwo_name
= dwarf2_string_attr (die
, DW_AT_dwo_name
, cu
);
20500 /* Return non-zero iff the attribute NAME is defined for the given DIE,
20501 and holds a non-zero value. This function should only be used for
20502 DW_FORM_flag or DW_FORM_flag_present attributes. */
20505 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
20507 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
20509 return (attr
&& DW_UNSND (attr
));
20513 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
20515 /* A DIE is a declaration if it has a DW_AT_declaration attribute
20516 which value is non-zero. However, we have to be careful with
20517 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
20518 (via dwarf2_flag_true_p) follows this attribute. So we may
20519 end up accidently finding a declaration attribute that belongs
20520 to a different DIE referenced by the specification attribute,
20521 even though the given DIE does not have a declaration attribute. */
20522 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
20523 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
20526 /* Return the die giving the specification for DIE, if there is
20527 one. *SPEC_CU is the CU containing DIE on input, and the CU
20528 containing the return value on output. If there is no
20529 specification, but there is an abstract origin, that is
20532 static struct die_info
*
20533 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
20535 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
20538 if (spec_attr
== NULL
)
20539 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
20541 if (spec_attr
== NULL
)
20544 return follow_die_ref (die
, spec_attr
, spec_cu
);
20547 /* Stub for free_line_header to match void * callback types. */
20550 free_line_header_voidp (void *arg
)
20552 struct line_header
*lh
= (struct line_header
*) arg
;
20558 line_header::add_include_dir (const char *include_dir
)
20560 if (dwarf_line_debug
>= 2)
20564 new_size
= m_include_dirs
.size ();
20566 new_size
= m_include_dirs
.size () + 1;
20567 fprintf_unfiltered (gdb_stdlog
, "Adding dir %zu: %s\n",
20568 new_size
, include_dir
);
20570 m_include_dirs
.push_back (include_dir
);
20574 line_header::add_file_name (const char *name
,
20576 unsigned int mod_time
,
20577 unsigned int length
)
20579 if (dwarf_line_debug
>= 2)
20583 new_size
= file_names_size ();
20585 new_size
= file_names_size () + 1;
20586 fprintf_unfiltered (gdb_stdlog
, "Adding file %zu: %s\n",
20589 m_file_names
.emplace_back (name
, d_index
, mod_time
, length
);
20592 /* A convenience function to find the proper .debug_line section for a CU. */
20594 static struct dwarf2_section_info
*
20595 get_debug_line_section (struct dwarf2_cu
*cu
)
20597 struct dwarf2_section_info
*section
;
20598 struct dwarf2_per_objfile
*dwarf2_per_objfile
20599 = cu
->per_cu
->dwarf2_per_objfile
;
20601 /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
20603 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20604 section
= &cu
->dwo_unit
->dwo_file
->sections
.line
;
20605 else if (cu
->per_cu
->is_dwz
)
20607 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
20609 section
= &dwz
->line
;
20612 section
= &dwarf2_per_objfile
->line
;
20617 /* Read directory or file name entry format, starting with byte of
20618 format count entries, ULEB128 pairs of entry formats, ULEB128 of
20619 entries count and the entries themselves in the described entry
20623 read_formatted_entries (struct dwarf2_per_objfile
*dwarf2_per_objfile
,
20624 bfd
*abfd
, const gdb_byte
**bufp
,
20625 struct line_header
*lh
,
20626 const struct comp_unit_head
*cu_header
,
20627 void (*callback
) (struct line_header
*lh
,
20630 unsigned int mod_time
,
20631 unsigned int length
))
20633 gdb_byte format_count
, formati
;
20634 ULONGEST data_count
, datai
;
20635 const gdb_byte
*buf
= *bufp
;
20636 const gdb_byte
*format_header_data
;
20637 unsigned int bytes_read
;
20639 format_count
= read_1_byte (abfd
, buf
);
20641 format_header_data
= buf
;
20642 for (formati
= 0; formati
< format_count
; formati
++)
20644 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20646 read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20650 data_count
= read_unsigned_leb128 (abfd
, buf
, &bytes_read
);
20652 for (datai
= 0; datai
< data_count
; datai
++)
20654 const gdb_byte
*format
= format_header_data
;
20655 struct file_entry fe
;
20657 for (formati
= 0; formati
< format_count
; formati
++)
20659 ULONGEST content_type
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20660 format
+= bytes_read
;
20662 ULONGEST form
= read_unsigned_leb128 (abfd
, format
, &bytes_read
);
20663 format
+= bytes_read
;
20665 gdb::optional
<const char *> string
;
20666 gdb::optional
<unsigned int> uint
;
20670 case DW_FORM_string
:
20671 string
.emplace (read_direct_string (abfd
, buf
, &bytes_read
));
20675 case DW_FORM_line_strp
:
20676 string
.emplace (read_indirect_line_string (dwarf2_per_objfile
,
20683 case DW_FORM_data1
:
20684 uint
.emplace (read_1_byte (abfd
, buf
));
20688 case DW_FORM_data2
:
20689 uint
.emplace (read_2_bytes (abfd
, buf
));
20693 case DW_FORM_data4
:
20694 uint
.emplace (read_4_bytes (abfd
, buf
));
20698 case DW_FORM_data8
:
20699 uint
.emplace (read_8_bytes (abfd
, buf
));
20703 case DW_FORM_data16
:
20704 /* This is used for MD5, but file_entry does not record MD5s. */
20708 case DW_FORM_udata
:
20709 uint
.emplace (read_unsigned_leb128 (abfd
, buf
, &bytes_read
));
20713 case DW_FORM_block
:
20714 /* It is valid only for DW_LNCT_timestamp which is ignored by
20719 switch (content_type
)
20722 if (string
.has_value ())
20725 case DW_LNCT_directory_index
:
20726 if (uint
.has_value ())
20727 fe
.d_index
= (dir_index
) *uint
;
20729 case DW_LNCT_timestamp
:
20730 if (uint
.has_value ())
20731 fe
.mod_time
= *uint
;
20734 if (uint
.has_value ())
20740 complaint (_("Unknown format content type %s"),
20741 pulongest (content_type
));
20745 callback (lh
, fe
.name
, fe
.d_index
, fe
.mod_time
, fe
.length
);
20751 /* Read the statement program header starting at OFFSET in
20752 .debug_line, or .debug_line.dwo. Return a pointer
20753 to a struct line_header, allocated using xmalloc.
20754 Returns NULL if there is a problem reading the header, e.g., if it
20755 has a version we don't understand.
20757 NOTE: the strings in the include directory and file name tables of
20758 the returned object point into the dwarf line section buffer,
20759 and must not be freed. */
20761 static line_header_up
20762 dwarf_decode_line_header (sect_offset sect_off
, struct dwarf2_cu
*cu
)
20764 const gdb_byte
*line_ptr
;
20765 unsigned int bytes_read
, offset_size
;
20767 const char *cur_dir
, *cur_file
;
20768 struct dwarf2_section_info
*section
;
20770 struct dwarf2_per_objfile
*dwarf2_per_objfile
20771 = cu
->per_cu
->dwarf2_per_objfile
;
20773 section
= get_debug_line_section (cu
);
20774 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
20775 if (section
->buffer
== NULL
)
20777 if (cu
->dwo_unit
&& cu
->per_cu
->is_debug_types
)
20778 complaint (_("missing .debug_line.dwo section"));
20780 complaint (_("missing .debug_line section"));
20784 /* We can't do this until we know the section is non-empty.
20785 Only then do we know we have such a section. */
20786 abfd
= get_section_bfd_owner (section
);
20788 /* Make sure that at least there's room for the total_length field.
20789 That could be 12 bytes long, but we're just going to fudge that. */
20790 if (to_underlying (sect_off
) + 4 >= section
->size
)
20792 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20796 line_header_up
lh (new line_header ());
20798 lh
->sect_off
= sect_off
;
20799 lh
->offset_in_dwz
= cu
->per_cu
->is_dwz
;
20801 line_ptr
= section
->buffer
+ to_underlying (sect_off
);
20803 /* Read in the header. */
20805 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
20806 &bytes_read
, &offset_size
);
20807 line_ptr
+= bytes_read
;
20809 const gdb_byte
*start_here
= line_ptr
;
20811 if (line_ptr
+ lh
->total_length
> (section
->buffer
+ section
->size
))
20813 dwarf2_statement_list_fits_in_line_number_section_complaint ();
20816 lh
->statement_program_end
= start_here
+ lh
->total_length
;
20817 lh
->version
= read_2_bytes (abfd
, line_ptr
);
20819 if (lh
->version
> 5)
20821 /* This is a version we don't understand. The format could have
20822 changed in ways we don't handle properly so just punt. */
20823 complaint (_("unsupported version in .debug_line section"));
20826 if (lh
->version
>= 5)
20828 gdb_byte segment_selector_size
;
20830 /* Skip address size. */
20831 read_1_byte (abfd
, line_ptr
);
20834 segment_selector_size
= read_1_byte (abfd
, line_ptr
);
20836 if (segment_selector_size
!= 0)
20838 complaint (_("unsupported segment selector size %u "
20839 "in .debug_line section"),
20840 segment_selector_size
);
20844 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
20845 line_ptr
+= offset_size
;
20846 lh
->statement_program_start
= line_ptr
+ lh
->header_length
;
20847 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
20849 if (lh
->version
>= 4)
20851 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
20855 lh
->maximum_ops_per_instruction
= 1;
20857 if (lh
->maximum_ops_per_instruction
== 0)
20859 lh
->maximum_ops_per_instruction
= 1;
20860 complaint (_("invalid maximum_ops_per_instruction "
20861 "in `.debug_line' section"));
20864 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
20866 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
20868 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
20870 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
20872 lh
->standard_opcode_lengths
.reset (new unsigned char[lh
->opcode_base
]);
20874 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
20875 for (i
= 1; i
< lh
->opcode_base
; ++i
)
20877 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
20881 if (lh
->version
>= 5)
20883 /* Read directory table. */
20884 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20886 [] (struct line_header
*header
, const char *name
,
20887 dir_index d_index
, unsigned int mod_time
,
20888 unsigned int length
)
20890 header
->add_include_dir (name
);
20893 /* Read file name table. */
20894 read_formatted_entries (dwarf2_per_objfile
, abfd
, &line_ptr
, lh
.get (),
20896 [] (struct line_header
*header
, const char *name
,
20897 dir_index d_index
, unsigned int mod_time
,
20898 unsigned int length
)
20900 header
->add_file_name (name
, d_index
, mod_time
, length
);
20905 /* Read directory table. */
20906 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20908 line_ptr
+= bytes_read
;
20909 lh
->add_include_dir (cur_dir
);
20911 line_ptr
+= bytes_read
;
20913 /* Read file name table. */
20914 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
20916 unsigned int mod_time
, length
;
20919 line_ptr
+= bytes_read
;
20920 d_index
= (dir_index
) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20921 line_ptr
+= bytes_read
;
20922 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20923 line_ptr
+= bytes_read
;
20924 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
20925 line_ptr
+= bytes_read
;
20927 lh
->add_file_name (cur_file
, d_index
, mod_time
, length
);
20929 line_ptr
+= bytes_read
;
20932 if (line_ptr
> (section
->buffer
+ section
->size
))
20933 complaint (_("line number info header doesn't "
20934 "fit in `.debug_line' section"));
20939 /* Subroutine of dwarf_decode_lines to simplify it.
20940 Return the file name of the psymtab for the given file_entry.
20941 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
20942 If space for the result is malloc'd, *NAME_HOLDER will be set.
20943 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
20945 static const char *
20946 psymtab_include_file_name (const struct line_header
*lh
, const file_entry
&fe
,
20947 const struct partial_symtab
*pst
,
20948 const char *comp_dir
,
20949 gdb::unique_xmalloc_ptr
<char> *name_holder
)
20951 const char *include_name
= fe
.name
;
20952 const char *include_name_to_compare
= include_name
;
20953 const char *pst_filename
;
20956 const char *dir_name
= fe
.include_dir (lh
);
20958 gdb::unique_xmalloc_ptr
<char> hold_compare
;
20959 if (!IS_ABSOLUTE_PATH (include_name
)
20960 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
20962 /* Avoid creating a duplicate psymtab for PST.
20963 We do this by comparing INCLUDE_NAME and PST_FILENAME.
20964 Before we do the comparison, however, we need to account
20965 for DIR_NAME and COMP_DIR.
20966 First prepend dir_name (if non-NULL). If we still don't
20967 have an absolute path prepend comp_dir (if non-NULL).
20968 However, the directory we record in the include-file's
20969 psymtab does not contain COMP_DIR (to match the
20970 corresponding symtab(s)).
20975 bash$ gcc -g ./hello.c
20976 include_name = "hello.c"
20978 DW_AT_comp_dir = comp_dir = "/tmp"
20979 DW_AT_name = "./hello.c"
20983 if (dir_name
!= NULL
)
20985 name_holder
->reset (concat (dir_name
, SLASH_STRING
,
20986 include_name
, (char *) NULL
));
20987 include_name
= name_holder
->get ();
20988 include_name_to_compare
= include_name
;
20990 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
20992 hold_compare
.reset (concat (comp_dir
, SLASH_STRING
,
20993 include_name
, (char *) NULL
));
20994 include_name_to_compare
= hold_compare
.get ();
20998 pst_filename
= pst
->filename
;
20999 gdb::unique_xmalloc_ptr
<char> copied_name
;
21000 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
21002 copied_name
.reset (concat (pst
->dirname
, SLASH_STRING
,
21003 pst_filename
, (char *) NULL
));
21004 pst_filename
= copied_name
.get ();
21007 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
21011 return include_name
;
21014 /* State machine to track the state of the line number program. */
21016 class lnp_state_machine
21019 /* Initialize a machine state for the start of a line number
21021 lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
, line_header
*lh
,
21022 bool record_lines_p
);
21024 file_entry
*current_file ()
21026 /* lh->file_names is 0-based, but the file name numbers in the
21027 statement program are 1-based. */
21028 return m_line_header
->file_name_at (m_file
);
21031 /* Record the line in the state machine. END_SEQUENCE is true if
21032 we're processing the end of a sequence. */
21033 void record_line (bool end_sequence
);
21035 /* Check ADDRESS is zero and less than UNRELOCATED_LOWPC and if true
21036 nop-out rest of the lines in this sequence. */
21037 void check_line_address (struct dwarf2_cu
*cu
,
21038 const gdb_byte
*line_ptr
,
21039 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
);
21041 void handle_set_discriminator (unsigned int discriminator
)
21043 m_discriminator
= discriminator
;
21044 m_line_has_non_zero_discriminator
|= discriminator
!= 0;
21047 /* Handle DW_LNE_set_address. */
21048 void handle_set_address (CORE_ADDR baseaddr
, CORE_ADDR address
)
21051 address
+= baseaddr
;
21052 m_address
= gdbarch_adjust_dwarf2_line (m_gdbarch
, address
, false);
21055 /* Handle DW_LNS_advance_pc. */
21056 void handle_advance_pc (CORE_ADDR adjust
);
21058 /* Handle a special opcode. */
21059 void handle_special_opcode (unsigned char op_code
);
21061 /* Handle DW_LNS_advance_line. */
21062 void handle_advance_line (int line_delta
)
21064 advance_line (line_delta
);
21067 /* Handle DW_LNS_set_file. */
21068 void handle_set_file (file_name_index file
);
21070 /* Handle DW_LNS_negate_stmt. */
21071 void handle_negate_stmt ()
21073 m_is_stmt
= !m_is_stmt
;
21076 /* Handle DW_LNS_const_add_pc. */
21077 void handle_const_add_pc ();
21079 /* Handle DW_LNS_fixed_advance_pc. */
21080 void handle_fixed_advance_pc (CORE_ADDR addr_adj
)
21082 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21086 /* Handle DW_LNS_copy. */
21087 void handle_copy ()
21089 record_line (false);
21090 m_discriminator
= 0;
21093 /* Handle DW_LNE_end_sequence. */
21094 void handle_end_sequence ()
21096 m_currently_recording_lines
= true;
21100 /* Advance the line by LINE_DELTA. */
21101 void advance_line (int line_delta
)
21103 m_line
+= line_delta
;
21105 if (line_delta
!= 0)
21106 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21109 struct dwarf2_cu
*m_cu
;
21111 gdbarch
*m_gdbarch
;
21113 /* True if we're recording lines.
21114 Otherwise we're building partial symtabs and are just interested in
21115 finding include files mentioned by the line number program. */
21116 bool m_record_lines_p
;
21118 /* The line number header. */
21119 line_header
*m_line_header
;
21121 /* These are part of the standard DWARF line number state machine,
21122 and initialized according to the DWARF spec. */
21124 unsigned char m_op_index
= 0;
21125 /* The line table index of the current file. */
21126 file_name_index m_file
= 1;
21127 unsigned int m_line
= 1;
21129 /* These are initialized in the constructor. */
21131 CORE_ADDR m_address
;
21133 unsigned int m_discriminator
;
21135 /* Additional bits of state we need to track. */
21137 /* The last file that we called dwarf2_start_subfile for.
21138 This is only used for TLLs. */
21139 unsigned int m_last_file
= 0;
21140 /* The last file a line number was recorded for. */
21141 struct subfile
*m_last_subfile
= NULL
;
21143 /* When true, record the lines we decode. */
21144 bool m_currently_recording_lines
= false;
21146 /* The last line number that was recorded, used to coalesce
21147 consecutive entries for the same line. This can happen, for
21148 example, when discriminators are present. PR 17276. */
21149 unsigned int m_last_line
= 0;
21150 bool m_line_has_non_zero_discriminator
= false;
21154 lnp_state_machine::handle_advance_pc (CORE_ADDR adjust
)
21156 CORE_ADDR addr_adj
= (((m_op_index
+ adjust
)
21157 / m_line_header
->maximum_ops_per_instruction
)
21158 * m_line_header
->minimum_instruction_length
);
21159 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21160 m_op_index
= ((m_op_index
+ adjust
)
21161 % m_line_header
->maximum_ops_per_instruction
);
21165 lnp_state_machine::handle_special_opcode (unsigned char op_code
)
21167 unsigned char adj_opcode
= op_code
- m_line_header
->opcode_base
;
21168 CORE_ADDR addr_adj
= (((m_op_index
21169 + (adj_opcode
/ m_line_header
->line_range
))
21170 / m_line_header
->maximum_ops_per_instruction
)
21171 * m_line_header
->minimum_instruction_length
);
21172 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21173 m_op_index
= ((m_op_index
+ (adj_opcode
/ m_line_header
->line_range
))
21174 % m_line_header
->maximum_ops_per_instruction
);
21176 int line_delta
= (m_line_header
->line_base
21177 + (adj_opcode
% m_line_header
->line_range
));
21178 advance_line (line_delta
);
21179 record_line (false);
21180 m_discriminator
= 0;
21184 lnp_state_machine::handle_set_file (file_name_index file
)
21188 const file_entry
*fe
= current_file ();
21190 dwarf2_debug_line_missing_file_complaint ();
21191 else if (m_record_lines_p
)
21193 const char *dir
= fe
->include_dir (m_line_header
);
21195 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21196 m_line_has_non_zero_discriminator
= m_discriminator
!= 0;
21197 dwarf2_start_subfile (m_cu
, fe
->name
, dir
);
21202 lnp_state_machine::handle_const_add_pc ()
21205 = (255 - m_line_header
->opcode_base
) / m_line_header
->line_range
;
21208 = (((m_op_index
+ adjust
)
21209 / m_line_header
->maximum_ops_per_instruction
)
21210 * m_line_header
->minimum_instruction_length
);
21212 m_address
+= gdbarch_adjust_dwarf2_line (m_gdbarch
, addr_adj
, true);
21213 m_op_index
= ((m_op_index
+ adjust
)
21214 % m_line_header
->maximum_ops_per_instruction
);
21217 /* Return non-zero if we should add LINE to the line number table.
21218 LINE is the line to add, LAST_LINE is the last line that was added,
21219 LAST_SUBFILE is the subfile for LAST_LINE.
21220 LINE_HAS_NON_ZERO_DISCRIMINATOR is non-zero if LINE has ever
21221 had a non-zero discriminator.
21223 We have to be careful in the presence of discriminators.
21224 E.g., for this line:
21226 for (i = 0; i < 100000; i++);
21228 clang can emit four line number entries for that one line,
21229 each with a different discriminator.
21230 See gdb.dwarf2/dw2-single-line-discriminators.exp for an example.
21232 However, we want gdb to coalesce all four entries into one.
21233 Otherwise the user could stepi into the middle of the line and
21234 gdb would get confused about whether the pc really was in the
21235 middle of the line.
21237 Things are further complicated by the fact that two consecutive
21238 line number entries for the same line is a heuristic used by gcc
21239 to denote the end of the prologue. So we can't just discard duplicate
21240 entries, we have to be selective about it. The heuristic we use is
21241 that we only collapse consecutive entries for the same line if at least
21242 one of those entries has a non-zero discriminator. PR 17276.
21244 Note: Addresses in the line number state machine can never go backwards
21245 within one sequence, thus this coalescing is ok. */
21248 dwarf_record_line_p (struct dwarf2_cu
*cu
,
21249 unsigned int line
, unsigned int last_line
,
21250 int line_has_non_zero_discriminator
,
21251 struct subfile
*last_subfile
)
21253 if (cu
->get_builder ()->get_current_subfile () != last_subfile
)
21255 if (line
!= last_line
)
21257 /* Same line for the same file that we've seen already.
21258 As a last check, for pr 17276, only record the line if the line
21259 has never had a non-zero discriminator. */
21260 if (!line_has_non_zero_discriminator
)
21265 /* Use the CU's builder to record line number LINE beginning at
21266 address ADDRESS in the line table of subfile SUBFILE. */
21269 dwarf_record_line_1 (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21270 unsigned int line
, CORE_ADDR address
,
21271 struct dwarf2_cu
*cu
)
21273 CORE_ADDR addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
21275 if (dwarf_line_debug
)
21277 fprintf_unfiltered (gdb_stdlog
,
21278 "Recording line %u, file %s, address %s\n",
21279 line
, lbasename (subfile
->name
),
21280 paddress (gdbarch
, address
));
21284 cu
->get_builder ()->record_line (subfile
, line
, addr
);
21287 /* Subroutine of dwarf_decode_lines_1 to simplify it.
21288 Mark the end of a set of line number records.
21289 The arguments are the same as for dwarf_record_line_1.
21290 If SUBFILE is NULL the request is ignored. */
21293 dwarf_finish_line (struct gdbarch
*gdbarch
, struct subfile
*subfile
,
21294 CORE_ADDR address
, struct dwarf2_cu
*cu
)
21296 if (subfile
== NULL
)
21299 if (dwarf_line_debug
)
21301 fprintf_unfiltered (gdb_stdlog
,
21302 "Finishing current line, file %s, address %s\n",
21303 lbasename (subfile
->name
),
21304 paddress (gdbarch
, address
));
21307 dwarf_record_line_1 (gdbarch
, subfile
, 0, address
, cu
);
21311 lnp_state_machine::record_line (bool end_sequence
)
21313 if (dwarf_line_debug
)
21315 fprintf_unfiltered (gdb_stdlog
,
21316 "Processing actual line %u: file %u,"
21317 " address %s, is_stmt %u, discrim %u%s\n",
21319 paddress (m_gdbarch
, m_address
),
21320 m_is_stmt
, m_discriminator
,
21321 (end_sequence
? "\t(end sequence)" : ""));
21324 file_entry
*fe
= current_file ();
21327 dwarf2_debug_line_missing_file_complaint ();
21328 /* For now we ignore lines not starting on an instruction boundary.
21329 But not when processing end_sequence for compatibility with the
21330 previous version of the code. */
21331 else if (m_op_index
== 0 || end_sequence
)
21333 fe
->included_p
= 1;
21334 if (m_record_lines_p
21335 && (producer_is_codewarrior (m_cu
) || m_is_stmt
|| end_sequence
))
21337 if (m_last_subfile
!= m_cu
->get_builder ()->get_current_subfile ()
21340 dwarf_finish_line (m_gdbarch
, m_last_subfile
, m_address
,
21341 m_currently_recording_lines
? m_cu
: nullptr);
21346 if (dwarf_record_line_p (m_cu
, m_line
, m_last_line
,
21347 m_line_has_non_zero_discriminator
,
21350 buildsym_compunit
*builder
= m_cu
->get_builder ();
21351 dwarf_record_line_1 (m_gdbarch
,
21352 builder
->get_current_subfile (),
21354 m_currently_recording_lines
? m_cu
: nullptr);
21356 m_last_subfile
= m_cu
->get_builder ()->get_current_subfile ();
21357 m_last_line
= m_line
;
21363 lnp_state_machine::lnp_state_machine (struct dwarf2_cu
*cu
, gdbarch
*arch
,
21364 line_header
*lh
, bool record_lines_p
)
21368 m_record_lines_p
= record_lines_p
;
21369 m_line_header
= lh
;
21371 m_currently_recording_lines
= true;
21373 /* Call `gdbarch_adjust_dwarf2_line' on the initial 0 address as if there
21374 was a line entry for it so that the backend has a chance to adjust it
21375 and also record it in case it needs it. This is currently used by MIPS
21376 code, cf. `mips_adjust_dwarf2_line'. */
21377 m_address
= gdbarch_adjust_dwarf2_line (arch
, 0, 0);
21378 m_is_stmt
= lh
->default_is_stmt
;
21379 m_discriminator
= 0;
21383 lnp_state_machine::check_line_address (struct dwarf2_cu
*cu
,
21384 const gdb_byte
*line_ptr
,
21385 CORE_ADDR unrelocated_lowpc
, CORE_ADDR address
)
21387 /* If ADDRESS < UNRELOCATED_LOWPC then it's not a usable value, it's outside
21388 the pc range of the CU. However, we restrict the test to only ADDRESS
21389 values of zero to preserve GDB's previous behaviour which is to handle
21390 the specific case of a function being GC'd by the linker. */
21392 if (address
== 0 && address
< unrelocated_lowpc
)
21394 /* This line table is for a function which has been
21395 GCd by the linker. Ignore it. PR gdb/12528 */
21397 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21398 long line_offset
= line_ptr
- get_debug_line_section (cu
)->buffer
;
21400 complaint (_(".debug_line address at offset 0x%lx is 0 [in module %s]"),
21401 line_offset
, objfile_name (objfile
));
21402 m_currently_recording_lines
= false;
21403 /* Note: m_currently_recording_lines is left as false until we see
21404 DW_LNE_end_sequence. */
21408 /* Subroutine of dwarf_decode_lines to simplify it.
21409 Process the line number information in LH.
21410 If DECODE_FOR_PST_P is non-zero, all we do is process the line number
21411 program in order to set included_p for every referenced header. */
21414 dwarf_decode_lines_1 (struct line_header
*lh
, struct dwarf2_cu
*cu
,
21415 const int decode_for_pst_p
, CORE_ADDR lowpc
)
21417 const gdb_byte
*line_ptr
, *extended_end
;
21418 const gdb_byte
*line_end
;
21419 unsigned int bytes_read
, extended_len
;
21420 unsigned char op_code
, extended_op
;
21421 CORE_ADDR baseaddr
;
21422 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21423 bfd
*abfd
= objfile
->obfd
;
21424 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21425 /* True if we're recording line info (as opposed to building partial
21426 symtabs and just interested in finding include files mentioned by
21427 the line number program). */
21428 bool record_lines_p
= !decode_for_pst_p
;
21430 baseaddr
= objfile
->text_section_offset ();
21432 line_ptr
= lh
->statement_program_start
;
21433 line_end
= lh
->statement_program_end
;
21435 /* Read the statement sequences until there's nothing left. */
21436 while (line_ptr
< line_end
)
21438 /* The DWARF line number program state machine. Reset the state
21439 machine at the start of each sequence. */
21440 lnp_state_machine
state_machine (cu
, gdbarch
, lh
, record_lines_p
);
21441 bool end_sequence
= false;
21443 if (record_lines_p
)
21445 /* Start a subfile for the current file of the state
21447 const file_entry
*fe
= state_machine
.current_file ();
21450 dwarf2_start_subfile (cu
, fe
->name
, fe
->include_dir (lh
));
21453 /* Decode the table. */
21454 while (line_ptr
< line_end
&& !end_sequence
)
21456 op_code
= read_1_byte (abfd
, line_ptr
);
21459 if (op_code
>= lh
->opcode_base
)
21461 /* Special opcode. */
21462 state_machine
.handle_special_opcode (op_code
);
21464 else switch (op_code
)
21466 case DW_LNS_extended_op
:
21467 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
21469 line_ptr
+= bytes_read
;
21470 extended_end
= line_ptr
+ extended_len
;
21471 extended_op
= read_1_byte (abfd
, line_ptr
);
21473 switch (extended_op
)
21475 case DW_LNE_end_sequence
:
21476 state_machine
.handle_end_sequence ();
21477 end_sequence
= true;
21479 case DW_LNE_set_address
:
21482 = read_address (abfd
, line_ptr
, cu
, &bytes_read
);
21483 line_ptr
+= bytes_read
;
21485 state_machine
.check_line_address (cu
, line_ptr
,
21486 lowpc
- baseaddr
, address
);
21487 state_machine
.handle_set_address (baseaddr
, address
);
21490 case DW_LNE_define_file
:
21492 const char *cur_file
;
21493 unsigned int mod_time
, length
;
21496 cur_file
= read_direct_string (abfd
, line_ptr
,
21498 line_ptr
+= bytes_read
;
21499 dindex
= (dir_index
)
21500 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21501 line_ptr
+= bytes_read
;
21503 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21504 line_ptr
+= bytes_read
;
21506 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21507 line_ptr
+= bytes_read
;
21508 lh
->add_file_name (cur_file
, dindex
, mod_time
, length
);
21511 case DW_LNE_set_discriminator
:
21513 /* The discriminator is not interesting to the
21514 debugger; just ignore it. We still need to
21515 check its value though:
21516 if there are consecutive entries for the same
21517 (non-prologue) line we want to coalesce them.
21520 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21521 line_ptr
+= bytes_read
;
21523 state_machine
.handle_set_discriminator (discr
);
21527 complaint (_("mangled .debug_line section"));
21530 /* Make sure that we parsed the extended op correctly. If e.g.
21531 we expected a different address size than the producer used,
21532 we may have read the wrong number of bytes. */
21533 if (line_ptr
!= extended_end
)
21535 complaint (_("mangled .debug_line section"));
21540 state_machine
.handle_copy ();
21542 case DW_LNS_advance_pc
:
21545 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21546 line_ptr
+= bytes_read
;
21548 state_machine
.handle_advance_pc (adjust
);
21551 case DW_LNS_advance_line
:
21554 = read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
21555 line_ptr
+= bytes_read
;
21557 state_machine
.handle_advance_line (line_delta
);
21560 case DW_LNS_set_file
:
21562 file_name_index file
21563 = (file_name_index
) read_unsigned_leb128 (abfd
, line_ptr
,
21565 line_ptr
+= bytes_read
;
21567 state_machine
.handle_set_file (file
);
21570 case DW_LNS_set_column
:
21571 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21572 line_ptr
+= bytes_read
;
21574 case DW_LNS_negate_stmt
:
21575 state_machine
.handle_negate_stmt ();
21577 case DW_LNS_set_basic_block
:
21579 /* Add to the address register of the state machine the
21580 address increment value corresponding to special opcode
21581 255. I.e., this value is scaled by the minimum
21582 instruction length since special opcode 255 would have
21583 scaled the increment. */
21584 case DW_LNS_const_add_pc
:
21585 state_machine
.handle_const_add_pc ();
21587 case DW_LNS_fixed_advance_pc
:
21589 CORE_ADDR addr_adj
= read_2_bytes (abfd
, line_ptr
);
21592 state_machine
.handle_fixed_advance_pc (addr_adj
);
21597 /* Unknown standard opcode, ignore it. */
21600 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
21602 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
21603 line_ptr
+= bytes_read
;
21610 dwarf2_debug_line_missing_end_sequence_complaint ();
21612 /* We got a DW_LNE_end_sequence (or we ran off the end of the buffer,
21613 in which case we still finish recording the last line). */
21614 state_machine
.record_line (true);
21618 /* Decode the Line Number Program (LNP) for the given line_header
21619 structure and CU. The actual information extracted and the type
21620 of structures created from the LNP depends on the value of PST.
21622 1. If PST is NULL, then this procedure uses the data from the program
21623 to create all necessary symbol tables, and their linetables.
21625 2. If PST is not NULL, this procedure reads the program to determine
21626 the list of files included by the unit represented by PST, and
21627 builds all the associated partial symbol tables.
21629 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
21630 It is used for relative paths in the line table.
21631 NOTE: When processing partial symtabs (pst != NULL),
21632 comp_dir == pst->dirname.
21634 NOTE: It is important that psymtabs have the same file name (via strcmp)
21635 as the corresponding symtab. Since COMP_DIR is not used in the name of the
21636 symtab we don't use it in the name of the psymtabs we create.
21637 E.g. expand_line_sal requires this when finding psymtabs to expand.
21638 A good testcase for this is mb-inline.exp.
21640 LOWPC is the lowest address in CU (or 0 if not known).
21642 Boolean DECODE_MAPPING specifies we need to fully decode .debug_line
21643 for its PC<->lines mapping information. Otherwise only the filename
21644 table is read in. */
21647 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
,
21648 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
,
21649 CORE_ADDR lowpc
, int decode_mapping
)
21651 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21652 const int decode_for_pst_p
= (pst
!= NULL
);
21654 if (decode_mapping
)
21655 dwarf_decode_lines_1 (lh
, cu
, decode_for_pst_p
, lowpc
);
21657 if (decode_for_pst_p
)
21659 /* Now that we're done scanning the Line Header Program, we can
21660 create the psymtab of each included file. */
21661 for (auto &file_entry
: lh
->file_names ())
21662 if (file_entry
.included_p
== 1)
21664 gdb::unique_xmalloc_ptr
<char> name_holder
;
21665 const char *include_name
=
21666 psymtab_include_file_name (lh
, file_entry
, pst
,
21667 comp_dir
, &name_holder
);
21668 if (include_name
!= NULL
)
21669 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
21674 /* Make sure a symtab is created for every file, even files
21675 which contain only variables (i.e. no code with associated
21677 buildsym_compunit
*builder
= cu
->get_builder ();
21678 struct compunit_symtab
*cust
= builder
->get_compunit_symtab ();
21680 for (auto &fe
: lh
->file_names ())
21682 dwarf2_start_subfile (cu
, fe
.name
, fe
.include_dir (lh
));
21683 if (builder
->get_current_subfile ()->symtab
== NULL
)
21685 builder
->get_current_subfile ()->symtab
21686 = allocate_symtab (cust
,
21687 builder
->get_current_subfile ()->name
);
21689 fe
.symtab
= builder
->get_current_subfile ()->symtab
;
21694 /* Start a subfile for DWARF. FILENAME is the name of the file and
21695 DIRNAME the name of the source directory which contains FILENAME
21696 or NULL if not known.
21697 This routine tries to keep line numbers from identical absolute and
21698 relative file names in a common subfile.
21700 Using the `list' example from the GDB testsuite, which resides in
21701 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
21702 of /srcdir/list0.c yields the following debugging information for list0.c:
21704 DW_AT_name: /srcdir/list0.c
21705 DW_AT_comp_dir: /compdir
21706 files.files[0].name: list0.h
21707 files.files[0].dir: /srcdir
21708 files.files[1].name: list0.c
21709 files.files[1].dir: /srcdir
21711 The line number information for list0.c has to end up in a single
21712 subfile, so that `break /srcdir/list0.c:1' works as expected.
21713 start_subfile will ensure that this happens provided that we pass the
21714 concatenation of files.files[1].dir and files.files[1].name as the
21718 dwarf2_start_subfile (struct dwarf2_cu
*cu
, const char *filename
,
21719 const char *dirname
)
21721 gdb::unique_xmalloc_ptr
<char> copy
;
21723 /* In order not to lose the line information directory,
21724 we concatenate it to the filename when it makes sense.
21725 Note that the Dwarf3 standard says (speaking of filenames in line
21726 information): ``The directory index is ignored for file names
21727 that represent full path names''. Thus ignoring dirname in the
21728 `else' branch below isn't an issue. */
21730 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
21732 copy
.reset (concat (dirname
, SLASH_STRING
, filename
, (char *) NULL
));
21733 filename
= copy
.get ();
21736 cu
->get_builder ()->start_subfile (filename
);
21739 /* Start a symtab for DWARF. NAME, COMP_DIR, LOW_PC are passed to the
21740 buildsym_compunit constructor. */
21742 struct compunit_symtab
*
21743 dwarf2_cu::start_symtab (const char *name
, const char *comp_dir
,
21746 gdb_assert (m_builder
== nullptr);
21748 m_builder
.reset (new struct buildsym_compunit
21749 (per_cu
->dwarf2_per_objfile
->objfile
,
21750 name
, comp_dir
, language
, low_pc
));
21752 list_in_scope
= get_builder ()->get_file_symbols ();
21754 get_builder ()->record_debugformat ("DWARF 2");
21755 get_builder ()->record_producer (producer
);
21757 processing_has_namespace_info
= false;
21759 return get_builder ()->get_compunit_symtab ();
21763 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
21764 struct dwarf2_cu
*cu
)
21766 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
21767 struct comp_unit_head
*cu_header
= &cu
->header
;
21769 /* NOTE drow/2003-01-30: There used to be a comment and some special
21770 code here to turn a symbol with DW_AT_external and a
21771 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
21772 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
21773 with some versions of binutils) where shared libraries could have
21774 relocations against symbols in their debug information - the
21775 minimal symbol would have the right address, but the debug info
21776 would not. It's no longer necessary, because we will explicitly
21777 apply relocations when we read in the debug information now. */
21779 /* A DW_AT_location attribute with no contents indicates that a
21780 variable has been optimized away. */
21781 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
21783 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21787 /* Handle one degenerate form of location expression specially, to
21788 preserve GDB's previous behavior when section offsets are
21789 specified. If this is just a DW_OP_addr, DW_OP_addrx, or
21790 DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC. */
21792 if (attr_form_is_block (attr
)
21793 && ((DW_BLOCK (attr
)->data
[0] == DW_OP_addr
21794 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
)
21795 || ((DW_BLOCK (attr
)->data
[0] == DW_OP_GNU_addr_index
21796 || DW_BLOCK (attr
)->data
[0] == DW_OP_addrx
)
21797 && (DW_BLOCK (attr
)->size
21798 == 1 + leb128_size (&DW_BLOCK (attr
)->data
[1])))))
21800 unsigned int dummy
;
21802 if (DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
21803 SET_SYMBOL_VALUE_ADDRESS (sym
,
21804 read_address (objfile
->obfd
,
21805 DW_BLOCK (attr
)->data
+ 1,
21808 SET_SYMBOL_VALUE_ADDRESS
21809 (sym
, read_addr_index_from_leb128 (cu
, DW_BLOCK (attr
)->data
+ 1,
21811 SYMBOL_ACLASS_INDEX (sym
) = LOC_STATIC
;
21812 fixup_symbol_section (sym
, objfile
);
21813 SET_SYMBOL_VALUE_ADDRESS
21815 SYMBOL_VALUE_ADDRESS (sym
)
21816 + objfile
->section_offsets
[SYMBOL_SECTION (sym
)]);
21820 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
21821 expression evaluator, and use LOC_COMPUTED only when necessary
21822 (i.e. when the value of a register or memory location is
21823 referenced, or a thread-local block, etc.). Then again, it might
21824 not be worthwhile. I'm assuming that it isn't unless performance
21825 or memory numbers show me otherwise. */
21827 dwarf2_symbol_mark_computed (attr
, sym
, cu
, 0);
21829 if (SYMBOL_COMPUTED_OPS (sym
)->location_has_loclist
)
21830 cu
->has_loclist
= true;
21833 /* Given a pointer to a DWARF information entry, figure out if we need
21834 to make a symbol table entry for it, and if so, create a new entry
21835 and return a pointer to it.
21836 If TYPE is NULL, determine symbol type from the die, otherwise
21837 used the passed type.
21838 If SPACE is not NULL, use it to hold the new symbol. If it is
21839 NULL, allocate a new symbol on the objfile's obstack. */
21841 static struct symbol
*
21842 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
21843 struct symbol
*space
)
21845 struct dwarf2_per_objfile
*dwarf2_per_objfile
21846 = cu
->per_cu
->dwarf2_per_objfile
;
21847 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
21848 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
21849 struct symbol
*sym
= NULL
;
21851 struct attribute
*attr
= NULL
;
21852 struct attribute
*attr2
= NULL
;
21853 CORE_ADDR baseaddr
;
21854 struct pending
**list_to_add
= NULL
;
21856 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
21858 baseaddr
= objfile
->text_section_offset ();
21860 name
= dwarf2_name (die
, cu
);
21863 const char *linkagename
;
21864 int suppress_add
= 0;
21869 sym
= allocate_symbol (objfile
);
21870 OBJSTAT (objfile
, n_syms
++);
21872 /* Cache this symbol's name and the name's demangled form (if any). */
21873 sym
->set_language (cu
->language
, &objfile
->objfile_obstack
);
21874 linkagename
= dwarf2_physname (name
, die
, cu
);
21875 sym
->compute_and_set_names (linkagename
, false, objfile
->per_bfd
);
21877 /* Fortran does not have mangling standard and the mangling does differ
21878 between gfortran, iFort etc. */
21879 if (cu
->language
== language_fortran
21880 && symbol_get_demangled_name (sym
) == NULL
)
21881 symbol_set_demangled_name (sym
,
21882 dwarf2_full_name (name
, die
, cu
),
21885 /* Default assumptions.
21886 Use the passed type or decode it from the die. */
21887 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
21888 SYMBOL_ACLASS_INDEX (sym
) = LOC_OPTIMIZED_OUT
;
21890 SYMBOL_TYPE (sym
) = type
;
21892 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
21893 attr
= dwarf2_attr (die
,
21894 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
21896 if (attr
!= nullptr)
21898 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
21901 attr
= dwarf2_attr (die
,
21902 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
21904 if (attr
!= nullptr)
21906 file_name_index file_index
= (file_name_index
) DW_UNSND (attr
);
21907 struct file_entry
*fe
;
21909 if (cu
->line_header
!= NULL
)
21910 fe
= cu
->line_header
->file_name_at (file_index
);
21915 complaint (_("file index out of range"));
21917 symbol_set_symtab (sym
, fe
->symtab
);
21923 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
21924 if (attr
!= nullptr)
21928 addr
= attr_value_as_address (attr
);
21929 addr
= gdbarch_adjust_dwarf2_addr (gdbarch
, addr
+ baseaddr
);
21930 SET_SYMBOL_VALUE_ADDRESS (sym
, addr
);
21932 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
21933 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
21934 SYMBOL_ACLASS_INDEX (sym
) = LOC_LABEL
;
21935 add_symbol_to_list (sym
, cu
->list_in_scope
);
21937 case DW_TAG_subprogram
:
21938 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21940 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21941 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21942 if ((attr2
&& (DW_UNSND (attr2
) != 0))
21943 || cu
->language
== language_ada
21944 || cu
->language
== language_fortran
)
21946 /* Subprograms marked external are stored as a global symbol.
21947 Ada and Fortran subprograms, whether marked external or
21948 not, are always stored as a global symbol, because we want
21949 to be able to access them globally. For instance, we want
21950 to be able to break on a nested subprogram without having
21951 to specify the context. */
21952 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21956 list_to_add
= cu
->list_in_scope
;
21959 case DW_TAG_inlined_subroutine
:
21960 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
21962 SYMBOL_ACLASS_INDEX (sym
) = LOC_BLOCK
;
21963 SYMBOL_INLINED (sym
) = 1;
21964 list_to_add
= cu
->list_in_scope
;
21966 case DW_TAG_template_value_param
:
21968 /* Fall through. */
21969 case DW_TAG_constant
:
21970 case DW_TAG_variable
:
21971 case DW_TAG_member
:
21972 /* Compilation with minimal debug info may result in
21973 variables with missing type entries. Change the
21974 misleading `void' type to something sensible. */
21975 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
21976 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_int
;
21978 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
21979 /* In the case of DW_TAG_member, we should only be called for
21980 static const members. */
21981 if (die
->tag
== DW_TAG_member
)
21983 /* dwarf2_add_field uses die_is_declaration,
21984 so we do the same. */
21985 gdb_assert (die_is_declaration (die
, cu
));
21988 if (attr
!= nullptr)
21990 dwarf2_const_value (attr
, sym
, cu
);
21991 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
21994 if (attr2
&& (DW_UNSND (attr2
) != 0))
21995 list_to_add
= cu
->get_builder ()->get_global_symbols ();
21997 list_to_add
= cu
->list_in_scope
;
22001 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22002 if (attr
!= nullptr)
22004 var_decode_location (attr
, sym
, cu
);
22005 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22007 /* Fortran explicitly imports any global symbols to the local
22008 scope by DW_TAG_common_block. */
22009 if (cu
->language
== language_fortran
&& die
->parent
22010 && die
->parent
->tag
== DW_TAG_common_block
)
22013 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22014 && SYMBOL_VALUE_ADDRESS (sym
) == 0
22015 && !dwarf2_per_objfile
->has_section_at_zero
)
22017 /* When a static variable is eliminated by the linker,
22018 the corresponding debug information is not stripped
22019 out, but the variable address is set to null;
22020 do not add such variables into symbol table. */
22022 else if (attr2
&& (DW_UNSND (attr2
) != 0))
22024 if (SYMBOL_CLASS (sym
) == LOC_STATIC
22025 && (objfile
->flags
& OBJF_MAINLINE
) == 0
22026 && dwarf2_per_objfile
->can_copy
)
22028 /* A global static variable might be subject to
22029 copy relocation. We first check for a local
22030 minsym, though, because maybe the symbol was
22031 marked hidden, in which case this would not
22033 bound_minimal_symbol found
22034 = (lookup_minimal_symbol_linkage
22035 (sym
->linkage_name (), objfile
));
22036 if (found
.minsym
!= nullptr)
22037 sym
->maybe_copied
= 1;
22040 /* A variable with DW_AT_external is never static,
22041 but it may be block-scoped. */
22043 = ((cu
->list_in_scope
22044 == cu
->get_builder ()->get_file_symbols ())
22045 ? cu
->get_builder ()->get_global_symbols ()
22046 : cu
->list_in_scope
);
22049 list_to_add
= cu
->list_in_scope
;
22053 /* We do not know the address of this symbol.
22054 If it is an external symbol and we have type information
22055 for it, enter the symbol as a LOC_UNRESOLVED symbol.
22056 The address of the variable will then be determined from
22057 the minimal symbol table whenever the variable is
22059 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
22061 /* Fortran explicitly imports any global symbols to the local
22062 scope by DW_TAG_common_block. */
22063 if (cu
->language
== language_fortran
&& die
->parent
22064 && die
->parent
->tag
== DW_TAG_common_block
)
22066 /* SYMBOL_CLASS doesn't matter here because
22067 read_common_block is going to reset it. */
22069 list_to_add
= cu
->list_in_scope
;
22071 else if (attr2
&& (DW_UNSND (attr2
) != 0)
22072 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
22074 /* A variable with DW_AT_external is never static, but it
22075 may be block-scoped. */
22077 = ((cu
->list_in_scope
22078 == cu
->get_builder ()->get_file_symbols ())
22079 ? cu
->get_builder ()->get_global_symbols ()
22080 : cu
->list_in_scope
);
22082 SYMBOL_ACLASS_INDEX (sym
) = LOC_UNRESOLVED
;
22084 else if (!die_is_declaration (die
, cu
))
22086 /* Use the default LOC_OPTIMIZED_OUT class. */
22087 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
22089 list_to_add
= cu
->list_in_scope
;
22093 case DW_TAG_formal_parameter
:
22095 /* If we are inside a function, mark this as an argument. If
22096 not, we might be looking at an argument to an inlined function
22097 when we do not have enough information to show inlined frames;
22098 pretend it's a local variable in that case so that the user can
22100 struct context_stack
*curr
22101 = cu
->get_builder ()->get_current_context_stack ();
22102 if (curr
!= nullptr && curr
->name
!= nullptr)
22103 SYMBOL_IS_ARGUMENT (sym
) = 1;
22104 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
22105 if (attr
!= nullptr)
22107 var_decode_location (attr
, sym
, cu
);
22109 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22110 if (attr
!= nullptr)
22112 dwarf2_const_value (attr
, sym
, cu
);
22115 list_to_add
= cu
->list_in_scope
;
22118 case DW_TAG_unspecified_parameters
:
22119 /* From varargs functions; gdb doesn't seem to have any
22120 interest in this information, so just ignore it for now.
22123 case DW_TAG_template_type_param
:
22125 /* Fall through. */
22126 case DW_TAG_class_type
:
22127 case DW_TAG_interface_type
:
22128 case DW_TAG_structure_type
:
22129 case DW_TAG_union_type
:
22130 case DW_TAG_set_type
:
22131 case DW_TAG_enumeration_type
:
22132 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22133 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
22136 /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't
22137 really ever be static objects: otherwise, if you try
22138 to, say, break of a class's method and you're in a file
22139 which doesn't mention that class, it won't work unless
22140 the check for all static symbols in lookup_symbol_aux
22141 saves you. See the OtherFileClass tests in
22142 gdb.c++/namespace.exp. */
22146 buildsym_compunit
*builder
= cu
->get_builder ();
22148 = (cu
->list_in_scope
== builder
->get_file_symbols ()
22149 && cu
->language
== language_cplus
22150 ? builder
->get_global_symbols ()
22151 : cu
->list_in_scope
);
22153 /* The semantics of C++ state that "struct foo {
22154 ... }" also defines a typedef for "foo". */
22155 if (cu
->language
== language_cplus
22156 || cu
->language
== language_ada
22157 || cu
->language
== language_d
22158 || cu
->language
== language_rust
)
22160 /* The symbol's name is already allocated along
22161 with this objfile, so we don't need to
22162 duplicate it for the type. */
22163 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
22164 TYPE_NAME (SYMBOL_TYPE (sym
)) = sym
->search_name ();
22169 case DW_TAG_typedef
:
22170 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22171 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22172 list_to_add
= cu
->list_in_scope
;
22174 case DW_TAG_base_type
:
22175 case DW_TAG_subrange_type
:
22176 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22177 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
22178 list_to_add
= cu
->list_in_scope
;
22180 case DW_TAG_enumerator
:
22181 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
22182 if (attr
!= nullptr)
22184 dwarf2_const_value (attr
, sym
, cu
);
22187 /* NOTE: carlton/2003-11-10: See comment above in the
22188 DW_TAG_class_type, etc. block. */
22191 = (cu
->list_in_scope
== cu
->get_builder ()->get_file_symbols ()
22192 && cu
->language
== language_cplus
22193 ? cu
->get_builder ()->get_global_symbols ()
22194 : cu
->list_in_scope
);
22197 case DW_TAG_imported_declaration
:
22198 case DW_TAG_namespace
:
22199 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22200 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22202 case DW_TAG_module
:
22203 SYMBOL_ACLASS_INDEX (sym
) = LOC_TYPEDEF
;
22204 SYMBOL_DOMAIN (sym
) = MODULE_DOMAIN
;
22205 list_to_add
= cu
->get_builder ()->get_global_symbols ();
22207 case DW_TAG_common_block
:
22208 SYMBOL_ACLASS_INDEX (sym
) = LOC_COMMON_BLOCK
;
22209 SYMBOL_DOMAIN (sym
) = COMMON_BLOCK_DOMAIN
;
22210 add_symbol_to_list (sym
, cu
->list_in_scope
);
22213 /* Not a tag we recognize. Hopefully we aren't processing
22214 trash data, but since we must specifically ignore things
22215 we don't recognize, there is nothing else we should do at
22217 complaint (_("unsupported tag: '%s'"),
22218 dwarf_tag_name (die
->tag
));
22224 sym
->hash_next
= objfile
->template_symbols
;
22225 objfile
->template_symbols
= sym
;
22226 list_to_add
= NULL
;
22229 if (list_to_add
!= NULL
)
22230 add_symbol_to_list (sym
, list_to_add
);
22232 /* For the benefit of old versions of GCC, check for anonymous
22233 namespaces based on the demangled name. */
22234 if (!cu
->processing_has_namespace_info
22235 && cu
->language
== language_cplus
)
22236 cp_scan_for_anonymous_namespaces (cu
->get_builder (), sym
, objfile
);
22241 /* Given an attr with a DW_FORM_dataN value in host byte order,
22242 zero-extend it as appropriate for the symbol's type. The DWARF
22243 standard (v4) is not entirely clear about the meaning of using
22244 DW_FORM_dataN for a constant with a signed type, where the type is
22245 wider than the data. The conclusion of a discussion on the DWARF
22246 list was that this is unspecified. We choose to always zero-extend
22247 because that is the interpretation long in use by GCC. */
22250 dwarf2_const_value_data (const struct attribute
*attr
, struct obstack
*obstack
,
22251 struct dwarf2_cu
*cu
, LONGEST
*value
, int bits
)
22253 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22254 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
22255 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
22256 LONGEST l
= DW_UNSND (attr
);
22258 if (bits
< sizeof (*value
) * 8)
22260 l
&= ((LONGEST
) 1 << bits
) - 1;
22263 else if (bits
== sizeof (*value
) * 8)
22267 gdb_byte
*bytes
= (gdb_byte
*) obstack_alloc (obstack
, bits
/ 8);
22268 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
22275 /* Read a constant value from an attribute. Either set *VALUE, or if
22276 the value does not fit in *VALUE, set *BYTES - either already
22277 allocated on the objfile obstack, or newly allocated on OBSTACK,
22278 or, set *BATON, if we translated the constant to a location
22282 dwarf2_const_value_attr (const struct attribute
*attr
, struct type
*type
,
22283 const char *name
, struct obstack
*obstack
,
22284 struct dwarf2_cu
*cu
,
22285 LONGEST
*value
, const gdb_byte
**bytes
,
22286 struct dwarf2_locexpr_baton
**baton
)
22288 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22289 struct comp_unit_head
*cu_header
= &cu
->header
;
22290 struct dwarf_block
*blk
;
22291 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
22292 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
22298 switch (attr
->form
)
22301 case DW_FORM_addrx
:
22302 case DW_FORM_GNU_addr_index
:
22306 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
22307 dwarf2_const_value_length_mismatch_complaint (name
,
22308 cu_header
->addr_size
,
22309 TYPE_LENGTH (type
));
22310 /* Symbols of this form are reasonably rare, so we just
22311 piggyback on the existing location code rather than writing
22312 a new implementation of symbol_computed_ops. */
22313 *baton
= XOBNEW (obstack
, struct dwarf2_locexpr_baton
);
22314 (*baton
)->per_cu
= cu
->per_cu
;
22315 gdb_assert ((*baton
)->per_cu
);
22317 (*baton
)->size
= 2 + cu_header
->addr_size
;
22318 data
= (gdb_byte
*) obstack_alloc (obstack
, (*baton
)->size
);
22319 (*baton
)->data
= data
;
22321 data
[0] = DW_OP_addr
;
22322 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
22323 byte_order
, DW_ADDR (attr
));
22324 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
22327 case DW_FORM_string
:
22330 case DW_FORM_GNU_str_index
:
22331 case DW_FORM_GNU_strp_alt
:
22332 /* DW_STRING is already allocated on the objfile obstack, point
22334 *bytes
= (const gdb_byte
*) DW_STRING (attr
);
22336 case DW_FORM_block1
:
22337 case DW_FORM_block2
:
22338 case DW_FORM_block4
:
22339 case DW_FORM_block
:
22340 case DW_FORM_exprloc
:
22341 case DW_FORM_data16
:
22342 blk
= DW_BLOCK (attr
);
22343 if (TYPE_LENGTH (type
) != blk
->size
)
22344 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
22345 TYPE_LENGTH (type
));
22346 *bytes
= blk
->data
;
22349 /* The DW_AT_const_value attributes are supposed to carry the
22350 symbol's value "represented as it would be on the target
22351 architecture." By the time we get here, it's already been
22352 converted to host endianness, so we just need to sign- or
22353 zero-extend it as appropriate. */
22354 case DW_FORM_data1
:
22355 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 8);
22357 case DW_FORM_data2
:
22358 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 16);
22360 case DW_FORM_data4
:
22361 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 32);
22363 case DW_FORM_data8
:
22364 *bytes
= dwarf2_const_value_data (attr
, obstack
, cu
, value
, 64);
22367 case DW_FORM_sdata
:
22368 case DW_FORM_implicit_const
:
22369 *value
= DW_SND (attr
);
22372 case DW_FORM_udata
:
22373 *value
= DW_UNSND (attr
);
22377 complaint (_("unsupported const value attribute form: '%s'"),
22378 dwarf_form_name (attr
->form
));
22385 /* Copy constant value from an attribute to a symbol. */
22388 dwarf2_const_value (const struct attribute
*attr
, struct symbol
*sym
,
22389 struct dwarf2_cu
*cu
)
22391 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22393 const gdb_byte
*bytes
;
22394 struct dwarf2_locexpr_baton
*baton
;
22396 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
22397 sym
->print_name (),
22398 &objfile
->objfile_obstack
, cu
,
22399 &value
, &bytes
, &baton
);
22403 SYMBOL_LOCATION_BATON (sym
) = baton
;
22404 SYMBOL_ACLASS_INDEX (sym
) = dwarf2_locexpr_index
;
22406 else if (bytes
!= NULL
)
22408 SYMBOL_VALUE_BYTES (sym
) = bytes
;
22409 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST_BYTES
;
22413 SYMBOL_VALUE (sym
) = value
;
22414 SYMBOL_ACLASS_INDEX (sym
) = LOC_CONST
;
22418 /* Return the type of the die in question using its DW_AT_type attribute. */
22420 static struct type
*
22421 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22423 struct attribute
*type_attr
;
22425 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
22428 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22429 /* A missing DW_AT_type represents a void type. */
22430 return objfile_type (objfile
)->builtin_void
;
22433 return lookup_die_type (die
, type_attr
, cu
);
22436 /* True iff CU's producer generates GNAT Ada auxiliary information
22437 that allows to find parallel types through that information instead
22438 of having to do expensive parallel lookups by type name. */
22441 need_gnat_info (struct dwarf2_cu
*cu
)
22443 /* Assume that the Ada compiler was GNAT, which always produces
22444 the auxiliary information. */
22445 return (cu
->language
== language_ada
);
22448 /* Return the auxiliary type of the die in question using its
22449 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
22450 attribute is not present. */
22452 static struct type
*
22453 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22455 struct attribute
*type_attr
;
22457 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
22461 return lookup_die_type (die
, type_attr
, cu
);
22464 /* If DIE has a descriptive_type attribute, then set the TYPE's
22465 descriptive type accordingly. */
22468 set_descriptive_type (struct type
*type
, struct die_info
*die
,
22469 struct dwarf2_cu
*cu
)
22471 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
22473 if (descriptive_type
)
22475 ALLOCATE_GNAT_AUX_TYPE (type
);
22476 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
22480 /* Return the containing type of the die in question using its
22481 DW_AT_containing_type attribute. */
22483 static struct type
*
22484 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
22486 struct attribute
*type_attr
;
22487 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22489 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
22491 error (_("Dwarf Error: Problem turning containing type into gdb type "
22492 "[in module %s]"), objfile_name (objfile
));
22494 return lookup_die_type (die
, type_attr
, cu
);
22497 /* Return an error marker type to use for the ill formed type in DIE/CU. */
22499 static struct type
*
22500 build_error_marker_type (struct dwarf2_cu
*cu
, struct die_info
*die
)
22502 struct dwarf2_per_objfile
*dwarf2_per_objfile
22503 = cu
->per_cu
->dwarf2_per_objfile
;
22504 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22507 std::string message
22508 = string_printf (_("<unknown type in %s, CU %s, DIE %s>"),
22509 objfile_name (objfile
),
22510 sect_offset_str (cu
->header
.sect_off
),
22511 sect_offset_str (die
->sect_off
));
22512 saved
= obstack_strdup (&objfile
->objfile_obstack
, message
);
22514 return init_type (objfile
, TYPE_CODE_ERROR
, 0, saved
);
22517 /* Look up the type of DIE in CU using its type attribute ATTR.
22518 ATTR must be one of: DW_AT_type, DW_AT_GNAT_descriptive_type,
22519 DW_AT_containing_type.
22520 If there is no type substitute an error marker. */
22522 static struct type
*
22523 lookup_die_type (struct die_info
*die
, const struct attribute
*attr
,
22524 struct dwarf2_cu
*cu
)
22526 struct dwarf2_per_objfile
*dwarf2_per_objfile
22527 = cu
->per_cu
->dwarf2_per_objfile
;
22528 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
22529 struct type
*this_type
;
22531 gdb_assert (attr
->name
== DW_AT_type
22532 || attr
->name
== DW_AT_GNAT_descriptive_type
22533 || attr
->name
== DW_AT_containing_type
);
22535 /* First see if we have it cached. */
22537 if (attr
->form
== DW_FORM_GNU_ref_alt
)
22539 struct dwarf2_per_cu_data
*per_cu
;
22540 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22542 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, 1,
22543 dwarf2_per_objfile
);
22544 this_type
= get_die_type_at_offset (sect_off
, per_cu
);
22546 else if (attr_form_is_ref (attr
))
22548 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
22550 this_type
= get_die_type_at_offset (sect_off
, cu
->per_cu
);
22552 else if (attr
->form
== DW_FORM_ref_sig8
)
22554 ULONGEST signature
= DW_SIGNATURE (attr
);
22556 return get_signatured_type (die
, signature
, cu
);
22560 complaint (_("Dwarf Error: Bad type attribute %s in DIE"
22561 " at %s [in module %s]"),
22562 dwarf_attr_name (attr
->name
), sect_offset_str (die
->sect_off
),
22563 objfile_name (objfile
));
22564 return build_error_marker_type (cu
, die
);
22567 /* If not cached we need to read it in. */
22569 if (this_type
== NULL
)
22571 struct die_info
*type_die
= NULL
;
22572 struct dwarf2_cu
*type_cu
= cu
;
22574 if (attr_form_is_ref (attr
))
22575 type_die
= follow_die_ref (die
, attr
, &type_cu
);
22576 if (type_die
== NULL
)
22577 return build_error_marker_type (cu
, die
);
22578 /* If we find the type now, it's probably because the type came
22579 from an inter-CU reference and the type's CU got expanded before
22581 this_type
= read_type_die (type_die
, type_cu
);
22584 /* If we still don't have a type use an error marker. */
22586 if (this_type
== NULL
)
22587 return build_error_marker_type (cu
, die
);
22592 /* Return the type in DIE, CU.
22593 Returns NULL for invalid types.
22595 This first does a lookup in die_type_hash,
22596 and only reads the die in if necessary.
22598 NOTE: This can be called when reading in partial or full symbols. */
22600 static struct type
*
22601 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
22603 struct type
*this_type
;
22605 this_type
= get_die_type (die
, cu
);
22609 return read_type_die_1 (die
, cu
);
22612 /* Read the type in DIE, CU.
22613 Returns NULL for invalid types. */
22615 static struct type
*
22616 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
22618 struct type
*this_type
= NULL
;
22622 case DW_TAG_class_type
:
22623 case DW_TAG_interface_type
:
22624 case DW_TAG_structure_type
:
22625 case DW_TAG_union_type
:
22626 this_type
= read_structure_type (die
, cu
);
22628 case DW_TAG_enumeration_type
:
22629 this_type
= read_enumeration_type (die
, cu
);
22631 case DW_TAG_subprogram
:
22632 case DW_TAG_subroutine_type
:
22633 case DW_TAG_inlined_subroutine
:
22634 this_type
= read_subroutine_type (die
, cu
);
22636 case DW_TAG_array_type
:
22637 this_type
= read_array_type (die
, cu
);
22639 case DW_TAG_set_type
:
22640 this_type
= read_set_type (die
, cu
);
22642 case DW_TAG_pointer_type
:
22643 this_type
= read_tag_pointer_type (die
, cu
);
22645 case DW_TAG_ptr_to_member_type
:
22646 this_type
= read_tag_ptr_to_member_type (die
, cu
);
22648 case DW_TAG_reference_type
:
22649 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_REF
);
22651 case DW_TAG_rvalue_reference_type
:
22652 this_type
= read_tag_reference_type (die
, cu
, TYPE_CODE_RVALUE_REF
);
22654 case DW_TAG_const_type
:
22655 this_type
= read_tag_const_type (die
, cu
);
22657 case DW_TAG_volatile_type
:
22658 this_type
= read_tag_volatile_type (die
, cu
);
22660 case DW_TAG_restrict_type
:
22661 this_type
= read_tag_restrict_type (die
, cu
);
22663 case DW_TAG_string_type
:
22664 this_type
= read_tag_string_type (die
, cu
);
22666 case DW_TAG_typedef
:
22667 this_type
= read_typedef (die
, cu
);
22669 case DW_TAG_subrange_type
:
22670 this_type
= read_subrange_type (die
, cu
);
22672 case DW_TAG_base_type
:
22673 this_type
= read_base_type (die
, cu
);
22675 case DW_TAG_unspecified_type
:
22676 this_type
= read_unspecified_type (die
, cu
);
22678 case DW_TAG_namespace
:
22679 this_type
= read_namespace_type (die
, cu
);
22681 case DW_TAG_module
:
22682 this_type
= read_module_type (die
, cu
);
22684 case DW_TAG_atomic_type
:
22685 this_type
= read_tag_atomic_type (die
, cu
);
22688 complaint (_("unexpected tag in read_type_die: '%s'"),
22689 dwarf_tag_name (die
->tag
));
22696 /* See if we can figure out if the class lives in a namespace. We do
22697 this by looking for a member function; its demangled name will
22698 contain namespace info, if there is any.
22699 Return the computed name or NULL.
22700 Space for the result is allocated on the objfile's obstack.
22701 This is the full-die version of guess_partial_die_structure_name.
22702 In this case we know DIE has no useful parent. */
22704 static const char *
22705 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
22707 struct die_info
*spec_die
;
22708 struct dwarf2_cu
*spec_cu
;
22709 struct die_info
*child
;
22710 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22713 spec_die
= die_specification (die
, &spec_cu
);
22714 if (spec_die
!= NULL
)
22720 for (child
= die
->child
;
22722 child
= child
->sibling
)
22724 if (child
->tag
== DW_TAG_subprogram
)
22726 const char *linkage_name
= dw2_linkage_name (child
, cu
);
22728 if (linkage_name
!= NULL
)
22730 gdb::unique_xmalloc_ptr
<char> actual_name
22731 (language_class_name_from_physname (cu
->language_defn
,
22733 const char *name
= NULL
;
22735 if (actual_name
!= NULL
)
22737 const char *die_name
= dwarf2_name (die
, cu
);
22739 if (die_name
!= NULL
22740 && strcmp (die_name
, actual_name
.get ()) != 0)
22742 /* Strip off the class name from the full name.
22743 We want the prefix. */
22744 int die_name_len
= strlen (die_name
);
22745 int actual_name_len
= strlen (actual_name
.get ());
22746 const char *ptr
= actual_name
.get ();
22748 /* Test for '::' as a sanity check. */
22749 if (actual_name_len
> die_name_len
+ 2
22750 && ptr
[actual_name_len
- die_name_len
- 1] == ':')
22751 name
= obstack_strndup (
22752 &objfile
->per_bfd
->storage_obstack
,
22753 ptr
, actual_name_len
- die_name_len
- 2);
22764 /* GCC might emit a nameless typedef that has a linkage name. Determine the
22765 prefix part in such case. See
22766 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
22768 static const char *
22769 anonymous_struct_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22771 struct attribute
*attr
;
22774 if (die
->tag
!= DW_TAG_class_type
&& die
->tag
!= DW_TAG_interface_type
22775 && die
->tag
!= DW_TAG_structure_type
&& die
->tag
!= DW_TAG_union_type
)
22778 if (dwarf2_string_attr (die
, DW_AT_name
, cu
) != NULL
)
22781 attr
= dw2_linkage_name_attr (die
, cu
);
22782 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
22785 /* dwarf2_name had to be already called. */
22786 gdb_assert (DW_STRING_IS_CANONICAL (attr
));
22788 /* Strip the base name, keep any leading namespaces/classes. */
22789 base
= strrchr (DW_STRING (attr
), ':');
22790 if (base
== NULL
|| base
== DW_STRING (attr
) || base
[-1] != ':')
22793 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
22794 return obstack_strndup (&objfile
->per_bfd
->storage_obstack
,
22796 &base
[-1] - DW_STRING (attr
));
22799 /* Return the name of the namespace/class that DIE is defined within,
22800 or "" if we can't tell. The caller should not xfree the result.
22802 For example, if we're within the method foo() in the following
22812 then determine_prefix on foo's die will return "N::C". */
22814 static const char *
22815 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
22817 struct dwarf2_per_objfile
*dwarf2_per_objfile
22818 = cu
->per_cu
->dwarf2_per_objfile
;
22819 struct die_info
*parent
, *spec_die
;
22820 struct dwarf2_cu
*spec_cu
;
22821 struct type
*parent_type
;
22822 const char *retval
;
22824 if (cu
->language
!= language_cplus
22825 && cu
->language
!= language_fortran
&& cu
->language
!= language_d
22826 && cu
->language
!= language_rust
)
22829 retval
= anonymous_struct_prefix (die
, cu
);
22833 /* We have to be careful in the presence of DW_AT_specification.
22834 For example, with GCC 3.4, given the code
22838 // Definition of N::foo.
22842 then we'll have a tree of DIEs like this:
22844 1: DW_TAG_compile_unit
22845 2: DW_TAG_namespace // N
22846 3: DW_TAG_subprogram // declaration of N::foo
22847 4: DW_TAG_subprogram // definition of N::foo
22848 DW_AT_specification // refers to die #3
22850 Thus, when processing die #4, we have to pretend that we're in
22851 the context of its DW_AT_specification, namely the contex of die
22854 spec_die
= die_specification (die
, &spec_cu
);
22855 if (spec_die
== NULL
)
22856 parent
= die
->parent
;
22859 parent
= spec_die
->parent
;
22863 if (parent
== NULL
)
22865 else if (parent
->building_fullname
)
22868 const char *parent_name
;
22870 /* It has been seen on RealView 2.2 built binaries,
22871 DW_TAG_template_type_param types actually _defined_ as
22872 children of the parent class:
22875 template class <class Enum> Class{};
22876 Class<enum E> class_e;
22878 1: DW_TAG_class_type (Class)
22879 2: DW_TAG_enumeration_type (E)
22880 3: DW_TAG_enumerator (enum1:0)
22881 3: DW_TAG_enumerator (enum2:1)
22883 2: DW_TAG_template_type_param
22884 DW_AT_type DW_FORM_ref_udata (E)
22886 Besides being broken debug info, it can put GDB into an
22887 infinite loop. Consider:
22889 When we're building the full name for Class<E>, we'll start
22890 at Class, and go look over its template type parameters,
22891 finding E. We'll then try to build the full name of E, and
22892 reach here. We're now trying to build the full name of E,
22893 and look over the parent DIE for containing scope. In the
22894 broken case, if we followed the parent DIE of E, we'd again
22895 find Class, and once again go look at its template type
22896 arguments, etc., etc. Simply don't consider such parent die
22897 as source-level parent of this die (it can't be, the language
22898 doesn't allow it), and break the loop here. */
22899 name
= dwarf2_name (die
, cu
);
22900 parent_name
= dwarf2_name (parent
, cu
);
22901 complaint (_("template param type '%s' defined within parent '%s'"),
22902 name
? name
: "<unknown>",
22903 parent_name
? parent_name
: "<unknown>");
22907 switch (parent
->tag
)
22909 case DW_TAG_namespace
:
22910 parent_type
= read_type_die (parent
, cu
);
22911 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
22912 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
22913 Work around this problem here. */
22914 if (cu
->language
== language_cplus
22915 && strcmp (TYPE_NAME (parent_type
), "::") == 0)
22917 /* We give a name to even anonymous namespaces. */
22918 return TYPE_NAME (parent_type
);
22919 case DW_TAG_class_type
:
22920 case DW_TAG_interface_type
:
22921 case DW_TAG_structure_type
:
22922 case DW_TAG_union_type
:
22923 case DW_TAG_module
:
22924 parent_type
= read_type_die (parent
, cu
);
22925 if (TYPE_NAME (parent_type
) != NULL
)
22926 return TYPE_NAME (parent_type
);
22928 /* An anonymous structure is only allowed non-static data
22929 members; no typedefs, no member functions, et cetera.
22930 So it does not need a prefix. */
22932 case DW_TAG_compile_unit
:
22933 case DW_TAG_partial_unit
:
22934 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
22935 if (cu
->language
== language_cplus
22936 && !dwarf2_per_objfile
->types
.empty ()
22937 && die
->child
!= NULL
22938 && (die
->tag
== DW_TAG_class_type
22939 || die
->tag
== DW_TAG_structure_type
22940 || die
->tag
== DW_TAG_union_type
))
22942 const char *name
= guess_full_die_structure_name (die
, cu
);
22947 case DW_TAG_subprogram
:
22948 /* Nested subroutines in Fortran get a prefix with the name
22949 of the parent's subroutine. */
22950 if (cu
->language
== language_fortran
)
22952 if ((die
->tag
== DW_TAG_subprogram
)
22953 && (dwarf2_name (parent
, cu
) != NULL
))
22954 return dwarf2_name (parent
, cu
);
22956 return determine_prefix (parent
, cu
);
22957 case DW_TAG_enumeration_type
:
22958 parent_type
= read_type_die (parent
, cu
);
22959 if (TYPE_DECLARED_CLASS (parent_type
))
22961 if (TYPE_NAME (parent_type
) != NULL
)
22962 return TYPE_NAME (parent_type
);
22965 /* Fall through. */
22967 return determine_prefix (parent
, cu
);
22971 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
22972 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
22973 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
22974 an obconcat, otherwise allocate storage for the result. The CU argument is
22975 used to determine the language and hence, the appropriate separator. */
22977 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
22980 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
22981 int physname
, struct dwarf2_cu
*cu
)
22983 const char *lead
= "";
22986 if (suffix
== NULL
|| suffix
[0] == '\0'
22987 || prefix
== NULL
|| prefix
[0] == '\0')
22989 else if (cu
->language
== language_d
)
22991 /* For D, the 'main' function could be defined in any module, but it
22992 should never be prefixed. */
22993 if (strcmp (suffix
, "D main") == 0)
23001 else if (cu
->language
== language_fortran
&& physname
)
23003 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
23004 DW_AT_MIPS_linkage_name is preferred and used instead. */
23012 if (prefix
== NULL
)
23014 if (suffix
== NULL
)
23021 xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1));
23023 strcpy (retval
, lead
);
23024 strcat (retval
, prefix
);
23025 strcat (retval
, sep
);
23026 strcat (retval
, suffix
);
23031 /* We have an obstack. */
23032 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
23036 /* Return sibling of die, NULL if no sibling. */
23038 static struct die_info
*
23039 sibling_die (struct die_info
*die
)
23041 return die
->sibling
;
23044 /* Get name of a die, return NULL if not found. */
23046 static const char *
23047 dwarf2_canonicalize_name (const char *name
, struct dwarf2_cu
*cu
,
23048 struct obstack
*obstack
)
23050 if (name
&& cu
->language
== language_cplus
)
23052 std::string canon_name
= cp_canonicalize_string (name
);
23054 if (!canon_name
.empty ())
23056 if (canon_name
!= name
)
23057 name
= obstack_strdup (obstack
, canon_name
);
23064 /* Get name of a die, return NULL if not found.
23065 Anonymous namespaces are converted to their magic string. */
23067 static const char *
23068 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
23070 struct attribute
*attr
;
23071 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
23073 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
23074 if ((!attr
|| !DW_STRING (attr
))
23075 && die
->tag
!= DW_TAG_namespace
23076 && die
->tag
!= DW_TAG_class_type
23077 && die
->tag
!= DW_TAG_interface_type
23078 && die
->tag
!= DW_TAG_structure_type
23079 && die
->tag
!= DW_TAG_union_type
)
23084 case DW_TAG_compile_unit
:
23085 case DW_TAG_partial_unit
:
23086 /* Compilation units have a DW_AT_name that is a filename, not
23087 a source language identifier. */
23088 case DW_TAG_enumeration_type
:
23089 case DW_TAG_enumerator
:
23090 /* These tags always have simple identifiers already; no need
23091 to canonicalize them. */
23092 return DW_STRING (attr
);
23094 case DW_TAG_namespace
:
23095 if (attr
!= NULL
&& DW_STRING (attr
) != NULL
)
23096 return DW_STRING (attr
);
23097 return CP_ANONYMOUS_NAMESPACE_STR
;
23099 case DW_TAG_class_type
:
23100 case DW_TAG_interface_type
:
23101 case DW_TAG_structure_type
:
23102 case DW_TAG_union_type
:
23103 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
23104 structures or unions. These were of the form "._%d" in GCC 4.1,
23105 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
23106 and GCC 4.4. We work around this problem by ignoring these. */
23107 if (attr
&& DW_STRING (attr
)
23108 && (startswith (DW_STRING (attr
), "._")
23109 || startswith (DW_STRING (attr
), "<anonymous")))
23112 /* GCC might emit a nameless typedef that has a linkage name. See
23113 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
23114 if (!attr
|| DW_STRING (attr
) == NULL
)
23116 attr
= dw2_linkage_name_attr (die
, cu
);
23117 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
23120 /* Avoid demangling DW_STRING (attr) the second time on a second
23121 call for the same DIE. */
23122 if (!DW_STRING_IS_CANONICAL (attr
))
23124 gdb::unique_xmalloc_ptr
<char> demangled
23125 (gdb_demangle (DW_STRING (attr
), DMGL_TYPES
));
23129 /* FIXME: we already did this for the partial symbol... */
23131 = obstack_strdup (&objfile
->per_bfd
->storage_obstack
,
23133 DW_STRING_IS_CANONICAL (attr
) = 1;
23135 /* Strip any leading namespaces/classes, keep only the base name.
23136 DW_AT_name for named DIEs does not contain the prefixes. */
23137 base
= strrchr (DW_STRING (attr
), ':');
23138 if (base
&& base
> DW_STRING (attr
) && base
[-1] == ':')
23141 return DW_STRING (attr
);
23150 if (!DW_STRING_IS_CANONICAL (attr
))
23153 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
23154 &objfile
->per_bfd
->storage_obstack
);
23155 DW_STRING_IS_CANONICAL (attr
) = 1;
23157 return DW_STRING (attr
);
23160 /* Return the die that this die in an extension of, or NULL if there
23161 is none. *EXT_CU is the CU containing DIE on input, and the CU
23162 containing the return value on output. */
23164 static struct die_info
*
23165 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
23167 struct attribute
*attr
;
23169 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
23173 return follow_die_ref (die
, attr
, ext_cu
);
23176 /* A convenience function that returns an "unknown" DWARF name,
23177 including the value of V. STR is the name of the entity being
23178 printed, e.g., "TAG". */
23180 static const char *
23181 dwarf_unknown (const char *str
, unsigned v
)
23183 char *cell
= get_print_cell ();
23184 xsnprintf (cell
, PRINT_CELL_SIZE
, "DW_%s_<unknown: %u>", str
, v
);
23188 /* Convert a DIE tag into its string name. */
23190 static const char *
23191 dwarf_tag_name (unsigned tag
)
23193 const char *name
= get_DW_TAG_name (tag
);
23196 return dwarf_unknown ("TAG", tag
);
23201 /* Convert a DWARF attribute code into its string name. */
23203 static const char *
23204 dwarf_attr_name (unsigned attr
)
23208 #ifdef MIPS /* collides with DW_AT_HP_block_index */
23209 if (attr
== DW_AT_MIPS_fde
)
23210 return "DW_AT_MIPS_fde";
23212 if (attr
== DW_AT_HP_block_index
)
23213 return "DW_AT_HP_block_index";
23216 name
= get_DW_AT_name (attr
);
23219 return dwarf_unknown ("AT", attr
);
23224 /* Convert a unit type to corresponding DW_UT name. */
23226 static const char *
23227 dwarf_unit_type_name (int unit_type
) {
23231 return "DW_UT_compile (0x01)";
23233 return "DW_UT_type (0x02)";
23235 return "DW_UT_partial (0x03)";
23237 return "DW_UT_skeleton (0x04)";
23239 return "DW_UT_split_compile (0x05)";
23241 return "DW_UT_split_type (0x06)";
23243 return "DW_UT_lo_user (0x80)";
23245 return "DW_UT_hi_user (0xff)";
23251 /* Convert a DWARF value form code into its string name. */
23253 static const char *
23254 dwarf_form_name (unsigned form
)
23256 const char *name
= get_DW_FORM_name (form
);
23259 return dwarf_unknown ("FORM", form
);
23264 static const char *
23265 dwarf_bool_name (unsigned mybool
)
23273 /* Convert a DWARF type code into its string name. */
23275 static const char *
23276 dwarf_type_encoding_name (unsigned enc
)
23278 const char *name
= get_DW_ATE_name (enc
);
23281 return dwarf_unknown ("ATE", enc
);
23287 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
23291 print_spaces (indent
, f
);
23292 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset %s)\n",
23293 dwarf_tag_name (die
->tag
), die
->abbrev
,
23294 sect_offset_str (die
->sect_off
));
23296 if (die
->parent
!= NULL
)
23298 print_spaces (indent
, f
);
23299 fprintf_unfiltered (f
, " parent at offset: %s\n",
23300 sect_offset_str (die
->parent
->sect_off
));
23303 print_spaces (indent
, f
);
23304 fprintf_unfiltered (f
, " has children: %s\n",
23305 dwarf_bool_name (die
->child
!= NULL
));
23307 print_spaces (indent
, f
);
23308 fprintf_unfiltered (f
, " attributes:\n");
23310 for (i
= 0; i
< die
->num_attrs
; ++i
)
23312 print_spaces (indent
, f
);
23313 fprintf_unfiltered (f
, " %s (%s) ",
23314 dwarf_attr_name (die
->attrs
[i
].name
),
23315 dwarf_form_name (die
->attrs
[i
].form
));
23317 switch (die
->attrs
[i
].form
)
23320 case DW_FORM_addrx
:
23321 case DW_FORM_GNU_addr_index
:
23322 fprintf_unfiltered (f
, "address: ");
23323 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
23325 case DW_FORM_block2
:
23326 case DW_FORM_block4
:
23327 case DW_FORM_block
:
23328 case DW_FORM_block1
:
23329 fprintf_unfiltered (f
, "block: size %s",
23330 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23332 case DW_FORM_exprloc
:
23333 fprintf_unfiltered (f
, "expression: size %s",
23334 pulongest (DW_BLOCK (&die
->attrs
[i
])->size
));
23336 case DW_FORM_data16
:
23337 fprintf_unfiltered (f
, "constant of 16 bytes");
23339 case DW_FORM_ref_addr
:
23340 fprintf_unfiltered (f
, "ref address: ");
23341 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23343 case DW_FORM_GNU_ref_alt
:
23344 fprintf_unfiltered (f
, "alt ref address: ");
23345 fputs_filtered (hex_string (DW_UNSND (&die
->attrs
[i
])), f
);
23351 case DW_FORM_ref_udata
:
23352 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
23353 (long) (DW_UNSND (&die
->attrs
[i
])));
23355 case DW_FORM_data1
:
23356 case DW_FORM_data2
:
23357 case DW_FORM_data4
:
23358 case DW_FORM_data8
:
23359 case DW_FORM_udata
:
23360 case DW_FORM_sdata
:
23361 fprintf_unfiltered (f
, "constant: %s",
23362 pulongest (DW_UNSND (&die
->attrs
[i
])));
23364 case DW_FORM_sec_offset
:
23365 fprintf_unfiltered (f
, "section offset: %s",
23366 pulongest (DW_UNSND (&die
->attrs
[i
])));
23368 case DW_FORM_ref_sig8
:
23369 fprintf_unfiltered (f
, "signature: %s",
23370 hex_string (DW_SIGNATURE (&die
->attrs
[i
])));
23372 case DW_FORM_string
:
23374 case DW_FORM_line_strp
:
23376 case DW_FORM_GNU_str_index
:
23377 case DW_FORM_GNU_strp_alt
:
23378 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
23379 DW_STRING (&die
->attrs
[i
])
23380 ? DW_STRING (&die
->attrs
[i
]) : "",
23381 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
23384 if (DW_UNSND (&die
->attrs
[i
]))
23385 fprintf_unfiltered (f
, "flag: TRUE");
23387 fprintf_unfiltered (f
, "flag: FALSE");
23389 case DW_FORM_flag_present
:
23390 fprintf_unfiltered (f
, "flag: TRUE");
23392 case DW_FORM_indirect
:
23393 /* The reader will have reduced the indirect form to
23394 the "base form" so this form should not occur. */
23395 fprintf_unfiltered (f
,
23396 "unexpected attribute form: DW_FORM_indirect");
23398 case DW_FORM_implicit_const
:
23399 fprintf_unfiltered (f
, "constant: %s",
23400 plongest (DW_SND (&die
->attrs
[i
])));
23403 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
23404 die
->attrs
[i
].form
);
23407 fprintf_unfiltered (f
, "\n");
23412 dump_die_for_error (struct die_info
*die
)
23414 dump_die_shallow (gdb_stderr
, 0, die
);
23418 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
23420 int indent
= level
* 4;
23422 gdb_assert (die
!= NULL
);
23424 if (level
>= max_level
)
23427 dump_die_shallow (f
, indent
, die
);
23429 if (die
->child
!= NULL
)
23431 print_spaces (indent
, f
);
23432 fprintf_unfiltered (f
, " Children:");
23433 if (level
+ 1 < max_level
)
23435 fprintf_unfiltered (f
, "\n");
23436 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
23440 fprintf_unfiltered (f
,
23441 " [not printed, max nesting level reached]\n");
23445 if (die
->sibling
!= NULL
&& level
> 0)
23447 dump_die_1 (f
, level
, max_level
, die
->sibling
);
23451 /* This is called from the pdie macro in gdbinit.in.
23452 It's not static so gcc will keep a copy callable from gdb. */
23455 dump_die (struct die_info
*die
, int max_level
)
23457 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
23461 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
23465 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
,
23466 to_underlying (die
->sect_off
),
23472 /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the
23476 dwarf2_get_ref_die_offset (const struct attribute
*attr
)
23478 if (attr_form_is_ref (attr
))
23479 return (sect_offset
) DW_UNSND (attr
);
23481 complaint (_("unsupported die ref attribute form: '%s'"),
23482 dwarf_form_name (attr
->form
));
23486 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
23487 * the value held by the attribute is not constant. */
23490 dwarf2_get_attr_constant_value (const struct attribute
*attr
, int default_value
)
23492 if (attr
->form
== DW_FORM_sdata
|| attr
->form
== DW_FORM_implicit_const
)
23493 return DW_SND (attr
);
23494 else if (attr
->form
== DW_FORM_udata
23495 || attr
->form
== DW_FORM_data1
23496 || attr
->form
== DW_FORM_data2
23497 || attr
->form
== DW_FORM_data4
23498 || attr
->form
== DW_FORM_data8
)
23499 return DW_UNSND (attr
);
23502 /* For DW_FORM_data16 see attr_form_is_constant. */
23503 complaint (_("Attribute value is not a constant (%s)"),
23504 dwarf_form_name (attr
->form
));
23505 return default_value
;
23509 /* Follow reference or signature attribute ATTR of SRC_DIE.
23510 On entry *REF_CU is the CU of SRC_DIE.
23511 On exit *REF_CU is the CU of the result. */
23513 static struct die_info
*
23514 follow_die_ref_or_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23515 struct dwarf2_cu
**ref_cu
)
23517 struct die_info
*die
;
23519 if (attr_form_is_ref (attr
))
23520 die
= follow_die_ref (src_die
, attr
, ref_cu
);
23521 else if (attr
->form
== DW_FORM_ref_sig8
)
23522 die
= follow_die_sig (src_die
, attr
, ref_cu
);
23525 dump_die_for_error (src_die
);
23526 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
23527 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
23533 /* Follow reference OFFSET.
23534 On entry *REF_CU is the CU of the source die referencing OFFSET.
23535 On exit *REF_CU is the CU of the result.
23536 Returns NULL if OFFSET is invalid. */
23538 static struct die_info
*
23539 follow_die_offset (sect_offset sect_off
, int offset_in_dwz
,
23540 struct dwarf2_cu
**ref_cu
)
23542 struct die_info temp_die
;
23543 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
23544 struct dwarf2_per_objfile
*dwarf2_per_objfile
23545 = cu
->per_cu
->dwarf2_per_objfile
;
23547 gdb_assert (cu
->per_cu
!= NULL
);
23551 if (cu
->per_cu
->is_debug_types
)
23553 /* .debug_types CUs cannot reference anything outside their CU.
23554 If they need to, they have to reference a signatured type via
23555 DW_FORM_ref_sig8. */
23556 if (!offset_in_cu_p (&cu
->header
, sect_off
))
23559 else if (offset_in_dwz
!= cu
->per_cu
->is_dwz
23560 || !offset_in_cu_p (&cu
->header
, sect_off
))
23562 struct dwarf2_per_cu_data
*per_cu
;
23564 per_cu
= dwarf2_find_containing_comp_unit (sect_off
, offset_in_dwz
,
23565 dwarf2_per_objfile
);
23567 /* If necessary, add it to the queue and load its DIEs. */
23568 if (maybe_queue_comp_unit (cu
, per_cu
, cu
->language
))
23569 load_full_comp_unit (per_cu
, false, cu
->language
);
23571 target_cu
= per_cu
->cu
;
23573 else if (cu
->dies
== NULL
)
23575 /* We're loading full DIEs during partial symbol reading. */
23576 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
23577 load_full_comp_unit (cu
->per_cu
, false, language_minimal
);
23580 *ref_cu
= target_cu
;
23581 temp_die
.sect_off
= sect_off
;
23583 if (target_cu
!= cu
)
23584 target_cu
->ancestor
= cu
;
23586 return (struct die_info
*) htab_find_with_hash (target_cu
->die_hash
,
23588 to_underlying (sect_off
));
23591 /* Follow reference attribute ATTR of SRC_DIE.
23592 On entry *REF_CU is the CU of SRC_DIE.
23593 On exit *REF_CU is the CU of the result. */
23595 static struct die_info
*
23596 follow_die_ref (struct die_info
*src_die
, const struct attribute
*attr
,
23597 struct dwarf2_cu
**ref_cu
)
23599 sect_offset sect_off
= dwarf2_get_ref_die_offset (attr
);
23600 struct dwarf2_cu
*cu
= *ref_cu
;
23601 struct die_info
*die
;
23603 die
= follow_die_offset (sect_off
,
23604 (attr
->form
== DW_FORM_GNU_ref_alt
23605 || cu
->per_cu
->is_dwz
),
23608 error (_("Dwarf Error: Cannot find DIE at %s referenced from DIE "
23609 "at %s [in module %s]"),
23610 sect_offset_str (sect_off
), sect_offset_str (src_die
->sect_off
),
23611 objfile_name (cu
->per_cu
->dwarf2_per_objfile
->objfile
));
23616 /* Return DWARF block referenced by DW_AT_location of DIE at SECT_OFF at PER_CU.
23617 Returned value is intended for DW_OP_call*. Returned
23618 dwarf2_locexpr_baton->data has lifetime of
23619 PER_CU->DWARF2_PER_OBJFILE->OBJFILE. */
23621 struct dwarf2_locexpr_baton
23622 dwarf2_fetch_die_loc_sect_off (sect_offset sect_off
,
23623 struct dwarf2_per_cu_data
*per_cu
,
23624 CORE_ADDR (*get_frame_pc
) (void *baton
),
23625 void *baton
, bool resolve_abstract_p
)
23627 struct dwarf2_cu
*cu
;
23628 struct die_info
*die
;
23629 struct attribute
*attr
;
23630 struct dwarf2_locexpr_baton retval
;
23631 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
23632 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
23634 if (per_cu
->cu
== NULL
)
23635 load_cu (per_cu
, false);
23639 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23640 Instead just throw an error, not much else we can do. */
23641 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23642 sect_offset_str (sect_off
), objfile_name (objfile
));
23645 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23647 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23648 sect_offset_str (sect_off
), objfile_name (objfile
));
23650 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23651 if (!attr
&& resolve_abstract_p
23652 && (dwarf2_per_objfile
->abstract_to_concrete
.find (die
->sect_off
)
23653 != dwarf2_per_objfile
->abstract_to_concrete
.end ()))
23655 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23656 CORE_ADDR baseaddr
= objfile
->text_section_offset ();
23657 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
23659 for (const auto &cand_off
23660 : dwarf2_per_objfile
->abstract_to_concrete
[die
->sect_off
])
23662 struct dwarf2_cu
*cand_cu
= cu
;
23663 struct die_info
*cand
23664 = follow_die_offset (cand_off
, per_cu
->is_dwz
, &cand_cu
);
23667 || cand
->parent
->tag
!= DW_TAG_subprogram
)
23670 CORE_ADDR pc_low
, pc_high
;
23671 get_scope_pc_bounds (cand
->parent
, &pc_low
, &pc_high
, cu
);
23672 if (pc_low
== ((CORE_ADDR
) -1))
23674 pc_low
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_low
+ baseaddr
);
23675 pc_high
= gdbarch_adjust_dwarf2_addr (gdbarch
, pc_high
+ baseaddr
);
23676 if (!(pc_low
<= pc
&& pc
< pc_high
))
23680 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
23687 /* DWARF: "If there is no such attribute, then there is no effect.".
23688 DATA is ignored if SIZE is 0. */
23690 retval
.data
= NULL
;
23693 else if (attr_form_is_section_offset (attr
))
23695 struct dwarf2_loclist_baton loclist_baton
;
23696 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
23699 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
23701 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
23703 retval
.size
= size
;
23707 if (!attr_form_is_block (attr
))
23708 error (_("Dwarf Error: DIE at %s referenced in module %s "
23709 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
23710 sect_offset_str (sect_off
), objfile_name (objfile
));
23712 retval
.data
= DW_BLOCK (attr
)->data
;
23713 retval
.size
= DW_BLOCK (attr
)->size
;
23715 retval
.per_cu
= cu
->per_cu
;
23717 age_cached_comp_units (dwarf2_per_objfile
);
23722 /* Like dwarf2_fetch_die_loc_sect_off, but take a CU
23725 struct dwarf2_locexpr_baton
23726 dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu
,
23727 struct dwarf2_per_cu_data
*per_cu
,
23728 CORE_ADDR (*get_frame_pc
) (void *baton
),
23731 sect_offset sect_off
= per_cu
->sect_off
+ to_underlying (offset_in_cu
);
23733 return dwarf2_fetch_die_loc_sect_off (sect_off
, per_cu
, get_frame_pc
, baton
);
23736 /* Write a constant of a given type as target-ordered bytes into
23739 static const gdb_byte
*
23740 write_constant_as_bytes (struct obstack
*obstack
,
23741 enum bfd_endian byte_order
,
23748 *len
= TYPE_LENGTH (type
);
23749 result
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23750 store_unsigned_integer (result
, *len
, byte_order
, value
);
23755 /* If the DIE at OFFSET in PER_CU has a DW_AT_const_value, return a
23756 pointer to the constant bytes and set LEN to the length of the
23757 data. If memory is needed, allocate it on OBSTACK. If the DIE
23758 does not have a DW_AT_const_value, return NULL. */
23761 dwarf2_fetch_constant_bytes (sect_offset sect_off
,
23762 struct dwarf2_per_cu_data
*per_cu
,
23763 struct obstack
*obstack
,
23766 struct dwarf2_cu
*cu
;
23767 struct die_info
*die
;
23768 struct attribute
*attr
;
23769 const gdb_byte
*result
= NULL
;
23772 enum bfd_endian byte_order
;
23773 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
23775 if (per_cu
->cu
== NULL
)
23776 load_cu (per_cu
, false);
23780 /* We shouldn't get here for a dummy CU, but don't crash on the user.
23781 Instead just throw an error, not much else we can do. */
23782 error (_("Dwarf Error: Dummy CU at %s referenced in module %s"),
23783 sect_offset_str (sect_off
), objfile_name (objfile
));
23786 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23788 error (_("Dwarf Error: Cannot find DIE at %s referenced in module %s"),
23789 sect_offset_str (sect_off
), objfile_name (objfile
));
23791 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
23795 byte_order
= (bfd_big_endian (objfile
->obfd
)
23796 ? BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
23798 switch (attr
->form
)
23801 case DW_FORM_addrx
:
23802 case DW_FORM_GNU_addr_index
:
23806 *len
= cu
->header
.addr_size
;
23807 tem
= (gdb_byte
*) obstack_alloc (obstack
, *len
);
23808 store_unsigned_integer (tem
, *len
, byte_order
, DW_ADDR (attr
));
23812 case DW_FORM_string
:
23815 case DW_FORM_GNU_str_index
:
23816 case DW_FORM_GNU_strp_alt
:
23817 /* DW_STRING is already allocated on the objfile obstack, point
23819 result
= (const gdb_byte
*) DW_STRING (attr
);
23820 *len
= strlen (DW_STRING (attr
));
23822 case DW_FORM_block1
:
23823 case DW_FORM_block2
:
23824 case DW_FORM_block4
:
23825 case DW_FORM_block
:
23826 case DW_FORM_exprloc
:
23827 case DW_FORM_data16
:
23828 result
= DW_BLOCK (attr
)->data
;
23829 *len
= DW_BLOCK (attr
)->size
;
23832 /* The DW_AT_const_value attributes are supposed to carry the
23833 symbol's value "represented as it would be on the target
23834 architecture." By the time we get here, it's already been
23835 converted to host endianness, so we just need to sign- or
23836 zero-extend it as appropriate. */
23837 case DW_FORM_data1
:
23838 type
= die_type (die
, cu
);
23839 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 8);
23840 if (result
== NULL
)
23841 result
= write_constant_as_bytes (obstack
, byte_order
,
23844 case DW_FORM_data2
:
23845 type
= die_type (die
, cu
);
23846 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 16);
23847 if (result
== NULL
)
23848 result
= write_constant_as_bytes (obstack
, byte_order
,
23851 case DW_FORM_data4
:
23852 type
= die_type (die
, cu
);
23853 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 32);
23854 if (result
== NULL
)
23855 result
= write_constant_as_bytes (obstack
, byte_order
,
23858 case DW_FORM_data8
:
23859 type
= die_type (die
, cu
);
23860 result
= dwarf2_const_value_data (attr
, obstack
, cu
, &value
, 64);
23861 if (result
== NULL
)
23862 result
= write_constant_as_bytes (obstack
, byte_order
,
23866 case DW_FORM_sdata
:
23867 case DW_FORM_implicit_const
:
23868 type
= die_type (die
, cu
);
23869 result
= write_constant_as_bytes (obstack
, byte_order
,
23870 type
, DW_SND (attr
), len
);
23873 case DW_FORM_udata
:
23874 type
= die_type (die
, cu
);
23875 result
= write_constant_as_bytes (obstack
, byte_order
,
23876 type
, DW_UNSND (attr
), len
);
23880 complaint (_("unsupported const value attribute form: '%s'"),
23881 dwarf_form_name (attr
->form
));
23888 /* Return the type of the die at OFFSET in PER_CU. Return NULL if no
23889 valid type for this die is found. */
23892 dwarf2_fetch_die_type_sect_off (sect_offset sect_off
,
23893 struct dwarf2_per_cu_data
*per_cu
)
23895 struct dwarf2_cu
*cu
;
23896 struct die_info
*die
;
23898 if (per_cu
->cu
== NULL
)
23899 load_cu (per_cu
, false);
23904 die
= follow_die_offset (sect_off
, per_cu
->is_dwz
, &cu
);
23908 return die_type (die
, cu
);
23911 /* Return the type of the DIE at DIE_OFFSET in the CU named by
23915 dwarf2_get_die_type (cu_offset die_offset
,
23916 struct dwarf2_per_cu_data
*per_cu
)
23918 sect_offset die_offset_sect
= per_cu
->sect_off
+ to_underlying (die_offset
);
23919 return get_die_type_at_offset (die_offset_sect
, per_cu
);
23922 /* Follow type unit SIG_TYPE referenced by SRC_DIE.
23923 On entry *REF_CU is the CU of SRC_DIE.
23924 On exit *REF_CU is the CU of the result.
23925 Returns NULL if the referenced DIE isn't found. */
23927 static struct die_info
*
23928 follow_die_sig_1 (struct die_info
*src_die
, struct signatured_type
*sig_type
,
23929 struct dwarf2_cu
**ref_cu
)
23931 struct die_info temp_die
;
23932 struct dwarf2_cu
*sig_cu
, *cu
= *ref_cu
;
23933 struct die_info
*die
;
23935 /* While it might be nice to assert sig_type->type == NULL here,
23936 we can get here for DW_AT_imported_declaration where we need
23937 the DIE not the type. */
23939 /* If necessary, add it to the queue and load its DIEs. */
23941 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
, language_minimal
))
23942 read_signatured_type (sig_type
);
23944 sig_cu
= sig_type
->per_cu
.cu
;
23945 gdb_assert (sig_cu
!= NULL
);
23946 gdb_assert (to_underlying (sig_type
->type_offset_in_section
) != 0);
23947 temp_die
.sect_off
= sig_type
->type_offset_in_section
;
23948 die
= (struct die_info
*) htab_find_with_hash (sig_cu
->die_hash
, &temp_die
,
23949 to_underlying (temp_die
.sect_off
));
23952 struct dwarf2_per_objfile
*dwarf2_per_objfile
23953 = (*ref_cu
)->per_cu
->dwarf2_per_objfile
;
23955 /* For .gdb_index version 7 keep track of included TUs.
23956 http://sourceware.org/bugzilla/show_bug.cgi?id=15021. */
23957 if (dwarf2_per_objfile
->index_table
!= NULL
23958 && dwarf2_per_objfile
->index_table
->version
<= 7)
23960 (*ref_cu
)->per_cu
->imported_symtabs_push (sig_cu
->per_cu
);
23965 sig_cu
->ancestor
= cu
;
23973 /* Follow signatured type referenced by ATTR in SRC_DIE.
23974 On entry *REF_CU is the CU of SRC_DIE.
23975 On exit *REF_CU is the CU of the result.
23976 The result is the DIE of the type.
23977 If the referenced type cannot be found an error is thrown. */
23979 static struct die_info
*
23980 follow_die_sig (struct die_info
*src_die
, const struct attribute
*attr
,
23981 struct dwarf2_cu
**ref_cu
)
23983 ULONGEST signature
= DW_SIGNATURE (attr
);
23984 struct signatured_type
*sig_type
;
23985 struct die_info
*die
;
23987 gdb_assert (attr
->form
== DW_FORM_ref_sig8
);
23989 sig_type
= lookup_signatured_type (*ref_cu
, signature
);
23990 /* sig_type will be NULL if the signatured type is missing from
23992 if (sig_type
== NULL
)
23994 error (_("Dwarf Error: Cannot find signatured DIE %s referenced"
23995 " from DIE at %s [in module %s]"),
23996 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
23997 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24000 die
= follow_die_sig_1 (src_die
, sig_type
, ref_cu
);
24003 dump_die_for_error (src_die
);
24004 error (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24005 " from DIE at %s [in module %s]"),
24006 hex_string (signature
), sect_offset_str (src_die
->sect_off
),
24007 objfile_name ((*ref_cu
)->per_cu
->dwarf2_per_objfile
->objfile
));
24013 /* Get the type specified by SIGNATURE referenced in DIE/CU,
24014 reading in and processing the type unit if necessary. */
24016 static struct type
*
24017 get_signatured_type (struct die_info
*die
, ULONGEST signature
,
24018 struct dwarf2_cu
*cu
)
24020 struct dwarf2_per_objfile
*dwarf2_per_objfile
24021 = cu
->per_cu
->dwarf2_per_objfile
;
24022 struct signatured_type
*sig_type
;
24023 struct dwarf2_cu
*type_cu
;
24024 struct die_info
*type_die
;
24027 sig_type
= lookup_signatured_type (cu
, signature
);
24028 /* sig_type will be NULL if the signatured type is missing from
24030 if (sig_type
== NULL
)
24032 complaint (_("Dwarf Error: Cannot find signatured DIE %s referenced"
24033 " from DIE at %s [in module %s]"),
24034 hex_string (signature
), sect_offset_str (die
->sect_off
),
24035 objfile_name (dwarf2_per_objfile
->objfile
));
24036 return build_error_marker_type (cu
, die
);
24039 /* If we already know the type we're done. */
24040 if (sig_type
->type
!= NULL
)
24041 return sig_type
->type
;
24044 type_die
= follow_die_sig_1 (die
, sig_type
, &type_cu
);
24045 if (type_die
!= NULL
)
24047 /* N.B. We need to call get_die_type to ensure only one type for this DIE
24048 is created. This is important, for example, because for c++ classes
24049 we need TYPE_NAME set which is only done by new_symbol. Blech. */
24050 type
= read_type_die (type_die
, type_cu
);
24053 complaint (_("Dwarf Error: Cannot build signatured type %s"
24054 " referenced from DIE at %s [in module %s]"),
24055 hex_string (signature
), sect_offset_str (die
->sect_off
),
24056 objfile_name (dwarf2_per_objfile
->objfile
));
24057 type
= build_error_marker_type (cu
, die
);
24062 complaint (_("Dwarf Error: Problem reading signatured DIE %s referenced"
24063 " from DIE at %s [in module %s]"),
24064 hex_string (signature
), sect_offset_str (die
->sect_off
),
24065 objfile_name (dwarf2_per_objfile
->objfile
));
24066 type
= build_error_marker_type (cu
, die
);
24068 sig_type
->type
= type
;
24073 /* Get the type specified by the DW_AT_signature ATTR in DIE/CU,
24074 reading in and processing the type unit if necessary. */
24076 static struct type
*
24077 get_DW_AT_signature_type (struct die_info
*die
, const struct attribute
*attr
,
24078 struct dwarf2_cu
*cu
) /* ARI: editCase function */
24080 /* Yes, DW_AT_signature can use a non-ref_sig8 reference. */
24081 if (attr_form_is_ref (attr
))
24083 struct dwarf2_cu
*type_cu
= cu
;
24084 struct die_info
*type_die
= follow_die_ref (die
, attr
, &type_cu
);
24086 return read_type_die (type_die
, type_cu
);
24088 else if (attr
->form
== DW_FORM_ref_sig8
)
24090 return get_signatured_type (die
, DW_SIGNATURE (attr
), cu
);
24094 struct dwarf2_per_objfile
*dwarf2_per_objfile
24095 = cu
->per_cu
->dwarf2_per_objfile
;
24097 complaint (_("Dwarf Error: DW_AT_signature has bad form %s in DIE"
24098 " at %s [in module %s]"),
24099 dwarf_form_name (attr
->form
), sect_offset_str (die
->sect_off
),
24100 objfile_name (dwarf2_per_objfile
->objfile
));
24101 return build_error_marker_type (cu
, die
);
24105 /* Load the DIEs associated with type unit PER_CU into memory. */
24108 load_full_type_unit (struct dwarf2_per_cu_data
*per_cu
)
24110 struct signatured_type
*sig_type
;
24112 /* Caller is responsible for ensuring type_unit_groups don't get here. */
24113 gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu
));
24115 /* We have the per_cu, but we need the signatured_type.
24116 Fortunately this is an easy translation. */
24117 gdb_assert (per_cu
->is_debug_types
);
24118 sig_type
= (struct signatured_type
*) per_cu
;
24120 gdb_assert (per_cu
->cu
== NULL
);
24122 read_signatured_type (sig_type
);
24124 gdb_assert (per_cu
->cu
!= NULL
);
24127 /* Read in a signatured type and build its CU and DIEs.
24128 If the type is a stub for the real type in a DWO file,
24129 read in the real type from the DWO file as well. */
24132 read_signatured_type (struct signatured_type
*sig_type
)
24134 struct dwarf2_per_cu_data
*per_cu
= &sig_type
->per_cu
;
24136 gdb_assert (per_cu
->is_debug_types
);
24137 gdb_assert (per_cu
->cu
== NULL
);
24139 cutu_reader
reader (per_cu
, NULL
, 0, 1, false);
24141 if (!reader
.dummy_p
)
24143 struct dwarf2_cu
*cu
= reader
.cu
;
24144 const gdb_byte
*info_ptr
= reader
.info_ptr
;
24146 gdb_assert (cu
->die_hash
== NULL
);
24148 htab_create_alloc_ex (cu
->header
.length
/ 12,
24152 &cu
->comp_unit_obstack
,
24153 hashtab_obstack_allocate
,
24154 dummy_obstack_deallocate
);
24156 if (reader
.has_children
)
24157 reader
.comp_unit_die
->child
24158 = read_die_and_siblings (&reader
, info_ptr
, &info_ptr
,
24159 reader
.comp_unit_die
);
24160 cu
->dies
= reader
.comp_unit_die
;
24161 /* comp_unit_die is not stored in die_hash, no need. */
24163 /* We try not to read any attributes in this function, because
24164 not all CUs needed for references have been loaded yet, and
24165 symbol table processing isn't initialized. But we have to
24166 set the CU language, or we won't be able to build types
24167 correctly. Similarly, if we do not read the producer, we can
24168 not apply producer-specific interpretation. */
24169 prepare_one_comp_unit (cu
, cu
->dies
, language_minimal
);
24172 sig_type
->per_cu
.tu_read
= 1;
24175 /* Decode simple location descriptions.
24176 Given a pointer to a dwarf block that defines a location, compute
24177 the location and return the value.
24179 NOTE drow/2003-11-18: This function is called in two situations
24180 now: for the address of static or global variables (partial symbols
24181 only) and for offsets into structures which are expected to be
24182 (more or less) constant. The partial symbol case should go away,
24183 and only the constant case should remain. That will let this
24184 function complain more accurately. A few special modes are allowed
24185 without complaint for global variables (for instance, global
24186 register values and thread-local values).
24188 A location description containing no operations indicates that the
24189 object is optimized out. The return value is 0 for that case.
24190 FIXME drow/2003-11-16: No callers check for this case any more; soon all
24191 callers will only want a very basic result and this can become a
24194 Note that stack[0] is unused except as a default error return. */
24197 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
24199 struct objfile
*objfile
= cu
->per_cu
->dwarf2_per_objfile
->objfile
;
24201 size_t size
= blk
->size
;
24202 const gdb_byte
*data
= blk
->data
;
24203 CORE_ADDR stack
[64];
24205 unsigned int bytes_read
, unsnd
;
24211 stack
[++stacki
] = 0;
24250 stack
[++stacki
] = op
- DW_OP_lit0
;
24285 stack
[++stacki
] = op
- DW_OP_reg0
;
24287 dwarf2_complex_location_expr_complaint ();
24291 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
24293 stack
[++stacki
] = unsnd
;
24295 dwarf2_complex_location_expr_complaint ();
24299 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
24304 case DW_OP_const1u
:
24305 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
24309 case DW_OP_const1s
:
24310 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
24314 case DW_OP_const2u
:
24315 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
24319 case DW_OP_const2s
:
24320 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
24324 case DW_OP_const4u
:
24325 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
24329 case DW_OP_const4s
:
24330 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
24334 case DW_OP_const8u
:
24335 stack
[++stacki
] = read_8_bytes (objfile
->obfd
, &data
[i
]);
24340 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
24346 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
24351 stack
[stacki
+ 1] = stack
[stacki
];
24356 stack
[stacki
- 1] += stack
[stacki
];
24360 case DW_OP_plus_uconst
:
24361 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
24367 stack
[stacki
- 1] -= stack
[stacki
];
24372 /* If we're not the last op, then we definitely can't encode
24373 this using GDB's address_class enum. This is valid for partial
24374 global symbols, although the variable's address will be bogus
24377 dwarf2_complex_location_expr_complaint ();
24380 case DW_OP_GNU_push_tls_address
:
24381 case DW_OP_form_tls_address
:
24382 /* The top of the stack has the offset from the beginning
24383 of the thread control block at which the variable is located. */
24384 /* Nothing should follow this operator, so the top of stack would
24386 /* This is valid for partial global symbols, but the variable's
24387 address will be bogus in the psymtab. Make it always at least
24388 non-zero to not look as a variable garbage collected by linker
24389 which have DW_OP_addr 0. */
24391 dwarf2_complex_location_expr_complaint ();
24395 case DW_OP_GNU_uninit
:
24399 case DW_OP_GNU_addr_index
:
24400 case DW_OP_GNU_const_index
:
24401 stack
[++stacki
] = read_addr_index_from_leb128 (cu
, &data
[i
],
24408 const char *name
= get_DW_OP_name (op
);
24411 complaint (_("unsupported stack op: '%s'"),
24414 complaint (_("unsupported stack op: '%02x'"),
24418 return (stack
[stacki
]);
24421 /* Enforce maximum stack depth of SIZE-1 to avoid writing
24422 outside of the allocated space. Also enforce minimum>0. */
24423 if (stacki
>= ARRAY_SIZE (stack
) - 1)
24425 complaint (_("location description stack overflow"));
24431 complaint (_("location description stack underflow"));
24435 return (stack
[stacki
]);
24438 /* memory allocation interface */
24440 static struct dwarf_block
*
24441 dwarf_alloc_block (struct dwarf2_cu
*cu
)
24443 return XOBNEW (&cu
->comp_unit_obstack
, struct dwarf_block
);
24446 static struct die_info
*
24447 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
24449 struct die_info
*die
;
24450 size_t size
= sizeof (struct die_info
);
24453 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
24455 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
24456 memset (die
, 0, sizeof (struct die_info
));
24461 /* Macro support. */
24463 /* Return file name relative to the compilation directory of file number I in
24464 *LH's file name table. The result is allocated using xmalloc; the caller is
24465 responsible for freeing it. */
24468 file_file_name (int file
, struct line_header
*lh
)
24470 /* Is the file number a valid index into the line header's file name
24471 table? Remember that file numbers start with one, not zero. */
24472 if (lh
->is_valid_file_index (file
))
24474 const file_entry
*fe
= lh
->file_name_at (file
);
24476 if (!IS_ABSOLUTE_PATH (fe
->name
))
24478 const char *dir
= fe
->include_dir (lh
);
24480 return concat (dir
, SLASH_STRING
, fe
->name
, (char *) NULL
);
24482 return xstrdup (fe
->name
);
24486 /* The compiler produced a bogus file number. We can at least
24487 record the macro definitions made in the file, even if we
24488 won't be able to find the file by name. */
24489 char fake_name
[80];
24491 xsnprintf (fake_name
, sizeof (fake_name
),
24492 "<bad macro file number %d>", file
);
24494 complaint (_("bad file number in macro information (%d)"),
24497 return xstrdup (fake_name
);
24501 /* Return the full name of file number I in *LH's file name table.
24502 Use COMP_DIR as the name of the current directory of the
24503 compilation. The result is allocated using xmalloc; the caller is
24504 responsible for freeing it. */
24506 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
24508 /* Is the file number a valid index into the line header's file name
24509 table? Remember that file numbers start with one, not zero. */
24510 if (lh
->is_valid_file_index (file
))
24512 char *relative
= file_file_name (file
, lh
);
24514 if (IS_ABSOLUTE_PATH (relative
) || comp_dir
== NULL
)
24516 return reconcat (relative
, comp_dir
, SLASH_STRING
,
24517 relative
, (char *) NULL
);
24520 return file_file_name (file
, lh
);
24524 static struct macro_source_file
*
24525 macro_start_file (struct dwarf2_cu
*cu
,
24526 int file
, int line
,
24527 struct macro_source_file
*current_file
,
24528 struct line_header
*lh
)
24530 /* File name relative to the compilation directory of this source file. */
24531 char *file_name
= file_file_name (file
, lh
);
24533 if (! current_file
)
24535 /* Note: We don't create a macro table for this compilation unit
24536 at all until we actually get a filename. */
24537 struct macro_table
*macro_table
= cu
->get_builder ()->get_macro_table ();
24539 /* If we have no current file, then this must be the start_file
24540 directive for the compilation unit's main source file. */
24541 current_file
= macro_set_main (macro_table
, file_name
);
24542 macro_define_special (macro_table
);
24545 current_file
= macro_include (current_file
, line
, file_name
);
24549 return current_file
;
24552 static const char *
24553 consume_improper_spaces (const char *p
, const char *body
)
24557 complaint (_("macro definition contains spaces "
24558 "in formal argument list:\n`%s'"),
24570 parse_macro_definition (struct macro_source_file
*file
, int line
,
24575 /* The body string takes one of two forms. For object-like macro
24576 definitions, it should be:
24578 <macro name> " " <definition>
24580 For function-like macro definitions, it should be:
24582 <macro name> "() " <definition>
24584 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
24586 Spaces may appear only where explicitly indicated, and in the
24589 The Dwarf 2 spec says that an object-like macro's name is always
24590 followed by a space, but versions of GCC around March 2002 omit
24591 the space when the macro's definition is the empty string.
24593 The Dwarf 2 spec says that there should be no spaces between the
24594 formal arguments in a function-like macro's formal argument list,
24595 but versions of GCC around March 2002 include spaces after the
24599 /* Find the extent of the macro name. The macro name is terminated
24600 by either a space or null character (for an object-like macro) or
24601 an opening paren (for a function-like macro). */
24602 for (p
= body
; *p
; p
++)
24603 if (*p
== ' ' || *p
== '(')
24606 if (*p
== ' ' || *p
== '\0')
24608 /* It's an object-like macro. */
24609 int name_len
= p
- body
;
24610 std::string
name (body
, name_len
);
24611 const char *replacement
;
24614 replacement
= body
+ name_len
+ 1;
24617 dwarf2_macro_malformed_definition_complaint (body
);
24618 replacement
= body
+ name_len
;
24621 macro_define_object (file
, line
, name
.c_str (), replacement
);
24623 else if (*p
== '(')
24625 /* It's a function-like macro. */
24626 std::string
name (body
, p
- body
);
24629 char **argv
= XNEWVEC (char *, argv_size
);
24633 p
= consume_improper_spaces (p
, body
);
24635 /* Parse the formal argument list. */
24636 while (*p
&& *p
!= ')')
24638 /* Find the extent of the current argument name. */
24639 const char *arg_start
= p
;
24641 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
24644 if (! *p
|| p
== arg_start
)
24645 dwarf2_macro_malformed_definition_complaint (body
);
24648 /* Make sure argv has room for the new argument. */
24649 if (argc
>= argv_size
)
24652 argv
= XRESIZEVEC (char *, argv
, argv_size
);
24655 argv
[argc
++] = savestring (arg_start
, p
- arg_start
);
24658 p
= consume_improper_spaces (p
, body
);
24660 /* Consume the comma, if present. */
24665 p
= consume_improper_spaces (p
, body
);
24674 /* Perfectly formed definition, no complaints. */
24675 macro_define_function (file
, line
, name
.c_str (),
24676 argc
, (const char **) argv
,
24678 else if (*p
== '\0')
24680 /* Complain, but do define it. */
24681 dwarf2_macro_malformed_definition_complaint (body
);
24682 macro_define_function (file
, line
, name
.c_str (),
24683 argc
, (const char **) argv
,
24687 /* Just complain. */
24688 dwarf2_macro_malformed_definition_complaint (body
);
24691 /* Just complain. */
24692 dwarf2_macro_malformed_definition_complaint (body
);
24697 for (i
= 0; i
< argc
; i
++)
24703 dwarf2_macro_malformed_definition_complaint (body
);
24706 /* Skip some bytes from BYTES according to the form given in FORM.
24707 Returns the new pointer. */
24709 static const gdb_byte
*
24710 skip_form_bytes (bfd
*abfd
, const gdb_byte
*bytes
, const gdb_byte
*buffer_end
,
24711 enum dwarf_form form
,
24712 unsigned int offset_size
,
24713 struct dwarf2_section_info
*section
)
24715 unsigned int bytes_read
;
24719 case DW_FORM_data1
:
24724 case DW_FORM_data2
:
24728 case DW_FORM_data4
:
24732 case DW_FORM_data8
:
24736 case DW_FORM_data16
:
24740 case DW_FORM_string
:
24741 read_direct_string (abfd
, bytes
, &bytes_read
);
24742 bytes
+= bytes_read
;
24745 case DW_FORM_sec_offset
:
24747 case DW_FORM_GNU_strp_alt
:
24748 bytes
+= offset_size
;
24751 case DW_FORM_block
:
24752 bytes
+= read_unsigned_leb128 (abfd
, bytes
, &bytes_read
);
24753 bytes
+= bytes_read
;
24756 case DW_FORM_block1
:
24757 bytes
+= 1 + read_1_byte (abfd
, bytes
);
24759 case DW_FORM_block2
:
24760 bytes
+= 2 + read_2_bytes (abfd
, bytes
);
24762 case DW_FORM_block4
:
24763 bytes
+= 4 + read_4_bytes (abfd
, bytes
);
24766 case DW_FORM_addrx
:
24767 case DW_FORM_sdata
:
24769 case DW_FORM_udata
:
24770 case DW_FORM_GNU_addr_index
:
24771 case DW_FORM_GNU_str_index
:
24772 bytes
= gdb_skip_leb128 (bytes
, buffer_end
);
24775 dwarf2_section_buffer_overflow_complaint (section
);
24780 case DW_FORM_implicit_const
:
24785 complaint (_("invalid form 0x%x in `%s'"),
24786 form
, get_section_name (section
));
24794 /* A helper for dwarf_decode_macros that handles skipping an unknown
24795 opcode. Returns an updated pointer to the macro data buffer; or,
24796 on error, issues a complaint and returns NULL. */
24798 static const gdb_byte
*
24799 skip_unknown_opcode (unsigned int opcode
,
24800 const gdb_byte
**opcode_definitions
,
24801 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24803 unsigned int offset_size
,
24804 struct dwarf2_section_info
*section
)
24806 unsigned int bytes_read
, i
;
24808 const gdb_byte
*defn
;
24810 if (opcode_definitions
[opcode
] == NULL
)
24812 complaint (_("unrecognized DW_MACFINO opcode 0x%x"),
24817 defn
= opcode_definitions
[opcode
];
24818 arg
= read_unsigned_leb128 (abfd
, defn
, &bytes_read
);
24819 defn
+= bytes_read
;
24821 for (i
= 0; i
< arg
; ++i
)
24823 mac_ptr
= skip_form_bytes (abfd
, mac_ptr
, mac_end
,
24824 (enum dwarf_form
) defn
[i
], offset_size
,
24826 if (mac_ptr
== NULL
)
24828 /* skip_form_bytes already issued the complaint. */
24836 /* A helper function which parses the header of a macro section.
24837 If the macro section is the extended (for now called "GNU") type,
24838 then this updates *OFFSET_SIZE. Returns a pointer to just after
24839 the header, or issues a complaint and returns NULL on error. */
24841 static const gdb_byte
*
24842 dwarf_parse_macro_header (const gdb_byte
**opcode_definitions
,
24844 const gdb_byte
*mac_ptr
,
24845 unsigned int *offset_size
,
24846 int section_is_gnu
)
24848 memset (opcode_definitions
, 0, 256 * sizeof (gdb_byte
*));
24850 if (section_is_gnu
)
24852 unsigned int version
, flags
;
24854 version
= read_2_bytes (abfd
, mac_ptr
);
24855 if (version
!= 4 && version
!= 5)
24857 complaint (_("unrecognized version `%d' in .debug_macro section"),
24863 flags
= read_1_byte (abfd
, mac_ptr
);
24865 *offset_size
= (flags
& 1) ? 8 : 4;
24867 if ((flags
& 2) != 0)
24868 /* We don't need the line table offset. */
24869 mac_ptr
+= *offset_size
;
24871 /* Vendor opcode descriptions. */
24872 if ((flags
& 4) != 0)
24874 unsigned int i
, count
;
24876 count
= read_1_byte (abfd
, mac_ptr
);
24878 for (i
= 0; i
< count
; ++i
)
24880 unsigned int opcode
, bytes_read
;
24883 opcode
= read_1_byte (abfd
, mac_ptr
);
24885 opcode_definitions
[opcode
] = mac_ptr
;
24886 arg
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24887 mac_ptr
+= bytes_read
;
24896 /* A helper for dwarf_decode_macros that handles the GNU extensions,
24897 including DW_MACRO_import. */
24900 dwarf_decode_macro_bytes (struct dwarf2_cu
*cu
,
24902 const gdb_byte
*mac_ptr
, const gdb_byte
*mac_end
,
24903 struct macro_source_file
*current_file
,
24904 struct line_header
*lh
,
24905 struct dwarf2_section_info
*section
,
24906 int section_is_gnu
, int section_is_dwz
,
24907 unsigned int offset_size
,
24908 htab_t include_hash
)
24910 struct dwarf2_per_objfile
*dwarf2_per_objfile
24911 = cu
->per_cu
->dwarf2_per_objfile
;
24912 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
24913 enum dwarf_macro_record_type macinfo_type
;
24914 int at_commandline
;
24915 const gdb_byte
*opcode_definitions
[256];
24917 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
24918 &offset_size
, section_is_gnu
);
24919 if (mac_ptr
== NULL
)
24921 /* We already issued a complaint. */
24925 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
24926 GDB is still reading the definitions from command line. First
24927 DW_MACINFO_start_file will need to be ignored as it was already executed
24928 to create CURRENT_FILE for the main source holding also the command line
24929 definitions. On first met DW_MACINFO_start_file this flag is reset to
24930 normally execute all the remaining DW_MACINFO_start_file macinfos. */
24932 at_commandline
= 1;
24936 /* Do we at least have room for a macinfo type byte? */
24937 if (mac_ptr
>= mac_end
)
24939 dwarf2_section_buffer_overflow_complaint (section
);
24943 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
24946 /* Note that we rely on the fact that the corresponding GNU and
24947 DWARF constants are the same. */
24949 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
24950 switch (macinfo_type
)
24952 /* A zero macinfo type indicates the end of the macro
24957 case DW_MACRO_define
:
24958 case DW_MACRO_undef
:
24959 case DW_MACRO_define_strp
:
24960 case DW_MACRO_undef_strp
:
24961 case DW_MACRO_define_sup
:
24962 case DW_MACRO_undef_sup
:
24964 unsigned int bytes_read
;
24969 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
24970 mac_ptr
+= bytes_read
;
24972 if (macinfo_type
== DW_MACRO_define
24973 || macinfo_type
== DW_MACRO_undef
)
24975 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
24976 mac_ptr
+= bytes_read
;
24980 LONGEST str_offset
;
24982 str_offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
24983 mac_ptr
+= offset_size
;
24985 if (macinfo_type
== DW_MACRO_define_sup
24986 || macinfo_type
== DW_MACRO_undef_sup
24989 struct dwz_file
*dwz
24990 = dwarf2_get_dwz_file (dwarf2_per_objfile
);
24992 body
= read_indirect_string_from_dwz (objfile
,
24996 body
= read_indirect_string_at_offset (dwarf2_per_objfile
,
25000 is_define
= (macinfo_type
== DW_MACRO_define
25001 || macinfo_type
== DW_MACRO_define_strp
25002 || macinfo_type
== DW_MACRO_define_sup
);
25003 if (! current_file
)
25005 /* DWARF violation as no main source is present. */
25006 complaint (_("debug info with no main source gives macro %s "
25008 is_define
? _("definition") : _("undefinition"),
25012 if ((line
== 0 && !at_commandline
)
25013 || (line
!= 0 && at_commandline
))
25014 complaint (_("debug info gives %s macro %s with %s line %d: %s"),
25015 at_commandline
? _("command-line") : _("in-file"),
25016 is_define
? _("definition") : _("undefinition"),
25017 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
25021 /* Fedora's rpm-build's "debugedit" binary
25022 corrupted .debug_macro sections.
25025 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
25026 complaint (_("debug info gives %s invalid macro %s "
25027 "without body (corrupted?) at line %d "
25029 at_commandline
? _("command-line") : _("in-file"),
25030 is_define
? _("definition") : _("undefinition"),
25031 line
, current_file
->filename
);
25033 else if (is_define
)
25034 parse_macro_definition (current_file
, line
, body
);
25037 gdb_assert (macinfo_type
== DW_MACRO_undef
25038 || macinfo_type
== DW_MACRO_undef_strp
25039 || macinfo_type
== DW_MACRO_undef_sup
);
25040 macro_undef (current_file
, line
, body
);
25045 case DW_MACRO_start_file
:
25047 unsigned int bytes_read
;
25050 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25051 mac_ptr
+= bytes_read
;
25052 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25053 mac_ptr
+= bytes_read
;
25055 if ((line
== 0 && !at_commandline
)
25056 || (line
!= 0 && at_commandline
))
25057 complaint (_("debug info gives source %d included "
25058 "from %s at %s line %d"),
25059 file
, at_commandline
? _("command-line") : _("file"),
25060 line
== 0 ? _("zero") : _("non-zero"), line
);
25062 if (at_commandline
)
25064 /* This DW_MACRO_start_file was executed in the
25066 at_commandline
= 0;
25069 current_file
= macro_start_file (cu
, file
, line
, current_file
,
25074 case DW_MACRO_end_file
:
25075 if (! current_file
)
25076 complaint (_("macro debug info has an unmatched "
25077 "`close_file' directive"));
25080 current_file
= current_file
->included_by
;
25081 if (! current_file
)
25083 enum dwarf_macro_record_type next_type
;
25085 /* GCC circa March 2002 doesn't produce the zero
25086 type byte marking the end of the compilation
25087 unit. Complain if it's not there, but exit no
25090 /* Do we at least have room for a macinfo type byte? */
25091 if (mac_ptr
>= mac_end
)
25093 dwarf2_section_buffer_overflow_complaint (section
);
25097 /* We don't increment mac_ptr here, so this is just
25100 = (enum dwarf_macro_record_type
) read_1_byte (abfd
,
25102 if (next_type
!= 0)
25103 complaint (_("no terminating 0-type entry for "
25104 "macros in `.debug_macinfo' section"));
25111 case DW_MACRO_import
:
25112 case DW_MACRO_import_sup
:
25116 bfd
*include_bfd
= abfd
;
25117 struct dwarf2_section_info
*include_section
= section
;
25118 const gdb_byte
*include_mac_end
= mac_end
;
25119 int is_dwz
= section_is_dwz
;
25120 const gdb_byte
*new_mac_ptr
;
25122 offset
= read_offset_1 (abfd
, mac_ptr
, offset_size
);
25123 mac_ptr
+= offset_size
;
25125 if (macinfo_type
== DW_MACRO_import_sup
)
25127 struct dwz_file
*dwz
= dwarf2_get_dwz_file (dwarf2_per_objfile
);
25129 dwarf2_read_section (objfile
, &dwz
->macro
);
25131 include_section
= &dwz
->macro
;
25132 include_bfd
= get_section_bfd_owner (include_section
);
25133 include_mac_end
= dwz
->macro
.buffer
+ dwz
->macro
.size
;
25137 new_mac_ptr
= include_section
->buffer
+ offset
;
25138 slot
= htab_find_slot (include_hash
, new_mac_ptr
, INSERT
);
25142 /* This has actually happened; see
25143 http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */
25144 complaint (_("recursive DW_MACRO_import in "
25145 ".debug_macro section"));
25149 *slot
= (void *) new_mac_ptr
;
25151 dwarf_decode_macro_bytes (cu
, include_bfd
, new_mac_ptr
,
25152 include_mac_end
, current_file
, lh
,
25153 section
, section_is_gnu
, is_dwz
,
25154 offset_size
, include_hash
);
25156 htab_remove_elt (include_hash
, (void *) new_mac_ptr
);
25161 case DW_MACINFO_vendor_ext
:
25162 if (!section_is_gnu
)
25164 unsigned int bytes_read
;
25166 /* This reads the constant, but since we don't recognize
25167 any vendor extensions, we ignore it. */
25168 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25169 mac_ptr
+= bytes_read
;
25170 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25171 mac_ptr
+= bytes_read
;
25173 /* We don't recognize any vendor extensions. */
25179 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25180 mac_ptr
, mac_end
, abfd
, offset_size
,
25182 if (mac_ptr
== NULL
)
25187 } while (macinfo_type
!= 0);
25191 dwarf_decode_macros (struct dwarf2_cu
*cu
, unsigned int offset
,
25192 int section_is_gnu
)
25194 struct dwarf2_per_objfile
*dwarf2_per_objfile
25195 = cu
->per_cu
->dwarf2_per_objfile
;
25196 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25197 struct line_header
*lh
= cu
->line_header
;
25199 const gdb_byte
*mac_ptr
, *mac_end
;
25200 struct macro_source_file
*current_file
= 0;
25201 enum dwarf_macro_record_type macinfo_type
;
25202 unsigned int offset_size
= cu
->header
.offset_size
;
25203 const gdb_byte
*opcode_definitions
[256];
25205 struct dwarf2_section_info
*section
;
25206 const char *section_name
;
25208 if (cu
->dwo_unit
!= NULL
)
25210 if (section_is_gnu
)
25212 section
= &cu
->dwo_unit
->dwo_file
->sections
.macro
;
25213 section_name
= ".debug_macro.dwo";
25217 section
= &cu
->dwo_unit
->dwo_file
->sections
.macinfo
;
25218 section_name
= ".debug_macinfo.dwo";
25223 if (section_is_gnu
)
25225 section
= &dwarf2_per_objfile
->macro
;
25226 section_name
= ".debug_macro";
25230 section
= &dwarf2_per_objfile
->macinfo
;
25231 section_name
= ".debug_macinfo";
25235 dwarf2_read_section (objfile
, section
);
25236 if (section
->buffer
== NULL
)
25238 complaint (_("missing %s section"), section_name
);
25241 abfd
= get_section_bfd_owner (section
);
25243 /* First pass: Find the name of the base filename.
25244 This filename is needed in order to process all macros whose definition
25245 (or undefinition) comes from the command line. These macros are defined
25246 before the first DW_MACINFO_start_file entry, and yet still need to be
25247 associated to the base file.
25249 To determine the base file name, we scan the macro definitions until we
25250 reach the first DW_MACINFO_start_file entry. We then initialize
25251 CURRENT_FILE accordingly so that any macro definition found before the
25252 first DW_MACINFO_start_file can still be associated to the base file. */
25254 mac_ptr
= section
->buffer
+ offset
;
25255 mac_end
= section
->buffer
+ section
->size
;
25257 mac_ptr
= dwarf_parse_macro_header (opcode_definitions
, abfd
, mac_ptr
,
25258 &offset_size
, section_is_gnu
);
25259 if (mac_ptr
== NULL
)
25261 /* We already issued a complaint. */
25267 /* Do we at least have room for a macinfo type byte? */
25268 if (mac_ptr
>= mac_end
)
25270 /* Complaint is printed during the second pass as GDB will probably
25271 stop the first pass earlier upon finding
25272 DW_MACINFO_start_file. */
25276 macinfo_type
= (enum dwarf_macro_record_type
) read_1_byte (abfd
, mac_ptr
);
25279 /* Note that we rely on the fact that the corresponding GNU and
25280 DWARF constants are the same. */
25282 DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES
25283 switch (macinfo_type
)
25285 /* A zero macinfo type indicates the end of the macro
25290 case DW_MACRO_define
:
25291 case DW_MACRO_undef
:
25292 /* Only skip the data by MAC_PTR. */
25294 unsigned int bytes_read
;
25296 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25297 mac_ptr
+= bytes_read
;
25298 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25299 mac_ptr
+= bytes_read
;
25303 case DW_MACRO_start_file
:
25305 unsigned int bytes_read
;
25308 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25309 mac_ptr
+= bytes_read
;
25310 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25311 mac_ptr
+= bytes_read
;
25313 current_file
= macro_start_file (cu
, file
, line
, current_file
, lh
);
25317 case DW_MACRO_end_file
:
25318 /* No data to skip by MAC_PTR. */
25321 case DW_MACRO_define_strp
:
25322 case DW_MACRO_undef_strp
:
25323 case DW_MACRO_define_sup
:
25324 case DW_MACRO_undef_sup
:
25326 unsigned int bytes_read
;
25328 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25329 mac_ptr
+= bytes_read
;
25330 mac_ptr
+= offset_size
;
25334 case DW_MACRO_import
:
25335 case DW_MACRO_import_sup
:
25336 /* Note that, according to the spec, a transparent include
25337 chain cannot call DW_MACRO_start_file. So, we can just
25338 skip this opcode. */
25339 mac_ptr
+= offset_size
;
25342 case DW_MACINFO_vendor_ext
:
25343 /* Only skip the data by MAC_PTR. */
25344 if (!section_is_gnu
)
25346 unsigned int bytes_read
;
25348 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
25349 mac_ptr
+= bytes_read
;
25350 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
25351 mac_ptr
+= bytes_read
;
25356 mac_ptr
= skip_unknown_opcode (macinfo_type
, opcode_definitions
,
25357 mac_ptr
, mac_end
, abfd
, offset_size
,
25359 if (mac_ptr
== NULL
)
25364 } while (macinfo_type
!= 0 && current_file
== NULL
);
25366 /* Second pass: Process all entries.
25368 Use the AT_COMMAND_LINE flag to determine whether we are still processing
25369 command-line macro definitions/undefinitions. This flag is unset when we
25370 reach the first DW_MACINFO_start_file entry. */
25372 htab_up
include_hash (htab_create_alloc (1, htab_hash_pointer
,
25374 NULL
, xcalloc
, xfree
));
25375 mac_ptr
= section
->buffer
+ offset
;
25376 slot
= htab_find_slot (include_hash
.get (), mac_ptr
, INSERT
);
25377 *slot
= (void *) mac_ptr
;
25378 dwarf_decode_macro_bytes (cu
, abfd
, mac_ptr
, mac_end
,
25379 current_file
, lh
, section
,
25380 section_is_gnu
, 0, offset_size
,
25381 include_hash
.get ());
25384 /* Check if the attribute's form is a DW_FORM_block*
25385 if so return true else false. */
25388 attr_form_is_block (const struct attribute
*attr
)
25390 return (attr
== NULL
? 0 :
25391 attr
->form
== DW_FORM_block1
25392 || attr
->form
== DW_FORM_block2
25393 || attr
->form
== DW_FORM_block4
25394 || attr
->form
== DW_FORM_block
25395 || attr
->form
== DW_FORM_exprloc
);
25398 /* Return non-zero if ATTR's value is a section offset --- classes
25399 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
25400 You may use DW_UNSND (attr) to retrieve such offsets.
25402 Section 7.5.4, "Attribute Encodings", explains that no attribute
25403 may have a value that belongs to more than one of these classes; it
25404 would be ambiguous if we did, because we use the same forms for all
25408 attr_form_is_section_offset (const struct attribute
*attr
)
25410 return (attr
->form
== DW_FORM_data4
25411 || attr
->form
== DW_FORM_data8
25412 || attr
->form
== DW_FORM_sec_offset
);
25415 /* Return non-zero if ATTR's value falls in the 'constant' class, or
25416 zero otherwise. When this function returns true, you can apply
25417 dwarf2_get_attr_constant_value to it.
25419 However, note that for some attributes you must check
25420 attr_form_is_section_offset before using this test. DW_FORM_data4
25421 and DW_FORM_data8 are members of both the constant class, and of
25422 the classes that contain offsets into other debug sections
25423 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
25424 that, if an attribute's can be either a constant or one of the
25425 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
25426 taken as section offsets, not constants.
25428 DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
25429 cannot handle that. */
25432 attr_form_is_constant (const struct attribute
*attr
)
25434 switch (attr
->form
)
25436 case DW_FORM_sdata
:
25437 case DW_FORM_udata
:
25438 case DW_FORM_data1
:
25439 case DW_FORM_data2
:
25440 case DW_FORM_data4
:
25441 case DW_FORM_data8
:
25442 case DW_FORM_implicit_const
:
25450 /* DW_ADDR is always stored already as sect_offset; despite for the forms
25451 besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */
25454 attr_form_is_ref (const struct attribute
*attr
)
25456 switch (attr
->form
)
25458 case DW_FORM_ref_addr
:
25463 case DW_FORM_ref_udata
:
25464 case DW_FORM_GNU_ref_alt
:
25471 /* Return the .debug_loc section to use for CU.
25472 For DWO files use .debug_loc.dwo. */
25474 static struct dwarf2_section_info
*
25475 cu_debug_loc_section (struct dwarf2_cu
*cu
)
25477 struct dwarf2_per_objfile
*dwarf2_per_objfile
25478 = cu
->per_cu
->dwarf2_per_objfile
;
25482 struct dwo_sections
*sections
= &cu
->dwo_unit
->dwo_file
->sections
;
25484 return cu
->header
.version
>= 5 ? §ions
->loclists
: §ions
->loc
;
25486 return (cu
->header
.version
>= 5 ? &dwarf2_per_objfile
->loclists
25487 : &dwarf2_per_objfile
->loc
);
25490 /* A helper function that fills in a dwarf2_loclist_baton. */
25493 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
25494 struct dwarf2_loclist_baton
*baton
,
25495 const struct attribute
*attr
)
25497 struct dwarf2_per_objfile
*dwarf2_per_objfile
25498 = cu
->per_cu
->dwarf2_per_objfile
;
25499 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25501 dwarf2_read_section (dwarf2_per_objfile
->objfile
, section
);
25503 baton
->per_cu
= cu
->per_cu
;
25504 gdb_assert (baton
->per_cu
);
25505 /* We don't know how long the location list is, but make sure we
25506 don't run off the edge of the section. */
25507 baton
->size
= section
->size
- DW_UNSND (attr
);
25508 baton
->data
= section
->buffer
+ DW_UNSND (attr
);
25509 baton
->base_address
= cu
->base_address
;
25510 baton
->from_dwo
= cu
->dwo_unit
!= NULL
;
25514 dwarf2_symbol_mark_computed (const struct attribute
*attr
, struct symbol
*sym
,
25515 struct dwarf2_cu
*cu
, int is_block
)
25517 struct dwarf2_per_objfile
*dwarf2_per_objfile
25518 = cu
->per_cu
->dwarf2_per_objfile
;
25519 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25520 struct dwarf2_section_info
*section
= cu_debug_loc_section (cu
);
25522 if (attr_form_is_section_offset (attr
)
25523 /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
25524 the section. If so, fall through to the complaint in the
25526 && DW_UNSND (attr
) < dwarf2_section_size (objfile
, section
))
25528 struct dwarf2_loclist_baton
*baton
;
25530 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_loclist_baton
);
25532 fill_in_loclist_baton (cu
, baton
, attr
);
25534 if (cu
->base_known
== 0)
25535 complaint (_("Location list used without "
25536 "specifying the CU base address."));
25538 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25539 ? dwarf2_loclist_block_index
25540 : dwarf2_loclist_index
);
25541 SYMBOL_LOCATION_BATON (sym
) = baton
;
25545 struct dwarf2_locexpr_baton
*baton
;
25547 baton
= XOBNEW (&objfile
->objfile_obstack
, struct dwarf2_locexpr_baton
);
25548 baton
->per_cu
= cu
->per_cu
;
25549 gdb_assert (baton
->per_cu
);
25551 if (attr_form_is_block (attr
))
25553 /* Note that we're just copying the block's data pointer
25554 here, not the actual data. We're still pointing into the
25555 info_buffer for SYM's objfile; right now we never release
25556 that buffer, but when we do clean up properly this may
25558 baton
->size
= DW_BLOCK (attr
)->size
;
25559 baton
->data
= DW_BLOCK (attr
)->data
;
25563 dwarf2_invalid_attrib_class_complaint ("location description",
25564 sym
->natural_name ());
25568 SYMBOL_ACLASS_INDEX (sym
) = (is_block
25569 ? dwarf2_locexpr_block_index
25570 : dwarf2_locexpr_index
);
25571 SYMBOL_LOCATION_BATON (sym
) = baton
;
25575 /* Return the OBJFILE associated with the compilation unit CU. If CU
25576 came from a separate debuginfo file, then the master objfile is
25580 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
25582 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25584 /* Return the master objfile, so that we can report and look up the
25585 correct file containing this variable. */
25586 if (objfile
->separate_debug_objfile_backlink
)
25587 objfile
= objfile
->separate_debug_objfile_backlink
;
25592 /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
25593 (CU_HEADERP is unused in such case) or prepare a temporary copy at
25594 CU_HEADERP first. */
25596 static const struct comp_unit_head
*
25597 per_cu_header_read_in (struct comp_unit_head
*cu_headerp
,
25598 struct dwarf2_per_cu_data
*per_cu
)
25600 const gdb_byte
*info_ptr
;
25603 return &per_cu
->cu
->header
;
25605 info_ptr
= per_cu
->section
->buffer
+ to_underlying (per_cu
->sect_off
);
25607 memset (cu_headerp
, 0, sizeof (*cu_headerp
));
25608 read_comp_unit_head (cu_headerp
, info_ptr
, per_cu
->section
,
25609 rcuh_kind::COMPILE
);
25614 /* Return the address size given in the compilation unit header for CU. */
25617 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25619 struct comp_unit_head cu_header_local
;
25620 const struct comp_unit_head
*cu_headerp
;
25622 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25624 return cu_headerp
->addr_size
;
25627 /* Return the offset size given in the compilation unit header for CU. */
25630 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
25632 struct comp_unit_head cu_header_local
;
25633 const struct comp_unit_head
*cu_headerp
;
25635 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25637 return cu_headerp
->offset_size
;
25640 /* See its dwarf2loc.h declaration. */
25643 dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data
*per_cu
)
25645 struct comp_unit_head cu_header_local
;
25646 const struct comp_unit_head
*cu_headerp
;
25648 cu_headerp
= per_cu_header_read_in (&cu_header_local
, per_cu
);
25650 if (cu_headerp
->version
== 2)
25651 return cu_headerp
->addr_size
;
25653 return cu_headerp
->offset_size
;
25656 /* Return the text offset of the CU. The returned offset comes from
25657 this CU's objfile. If this objfile came from a separate debuginfo
25658 file, then the offset may be different from the corresponding
25659 offset in the parent objfile. */
25662 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
25664 return per_cu
->dwarf2_per_objfile
->objfile
->text_section_offset ();
25667 /* Return a type that is a generic pointer type, the size of which matches
25668 the address size given in the compilation unit header for PER_CU. */
25669 static struct type
*
25670 dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data
*per_cu
)
25672 struct objfile
*objfile
= per_cu
->dwarf2_per_objfile
->objfile
;
25673 struct type
*void_type
= objfile_type (objfile
)->builtin_void
;
25674 struct type
*addr_type
= lookup_pointer_type (void_type
);
25675 int addr_size
= dwarf2_per_cu_addr_size (per_cu
);
25677 if (TYPE_LENGTH (addr_type
) == addr_size
)
25681 = dwarf2_per_cu_addr_sized_int_type (per_cu
, TYPE_UNSIGNED (addr_type
));
25685 /* Return DWARF version number of PER_CU. */
25688 dwarf2_version (struct dwarf2_per_cu_data
*per_cu
)
25690 return per_cu
->dwarf_version
;
25693 /* Locate the .debug_info compilation unit from CU's objfile which contains
25694 the DIE at OFFSET. Raises an error on failure. */
25696 static struct dwarf2_per_cu_data
*
25697 dwarf2_find_containing_comp_unit (sect_offset sect_off
,
25698 unsigned int offset_in_dwz
,
25699 struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25701 struct dwarf2_per_cu_data
*this_cu
;
25705 high
= dwarf2_per_objfile
->all_comp_units
.size () - 1;
25708 struct dwarf2_per_cu_data
*mid_cu
;
25709 int mid
= low
+ (high
- low
) / 2;
25711 mid_cu
= dwarf2_per_objfile
->all_comp_units
[mid
];
25712 if (mid_cu
->is_dwz
> offset_in_dwz
25713 || (mid_cu
->is_dwz
== offset_in_dwz
25714 && mid_cu
->sect_off
+ mid_cu
->length
>= sect_off
))
25719 gdb_assert (low
== high
);
25720 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
25721 if (this_cu
->is_dwz
!= offset_in_dwz
|| this_cu
->sect_off
> sect_off
)
25723 if (low
== 0 || this_cu
->is_dwz
!= offset_in_dwz
)
25724 error (_("Dwarf Error: could not find partial DIE containing "
25725 "offset %s [in module %s]"),
25726 sect_offset_str (sect_off
),
25727 bfd_get_filename (dwarf2_per_objfile
->objfile
->obfd
));
25729 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->sect_off
25731 return dwarf2_per_objfile
->all_comp_units
[low
-1];
25735 if (low
== dwarf2_per_objfile
->all_comp_units
.size () - 1
25736 && sect_off
>= this_cu
->sect_off
+ this_cu
->length
)
25737 error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off
));
25738 gdb_assert (sect_off
< this_cu
->sect_off
+ this_cu
->length
);
25743 /* Initialize dwarf2_cu CU, owned by PER_CU. */
25745 dwarf2_cu::dwarf2_cu (struct dwarf2_per_cu_data
*per_cu_
)
25746 : per_cu (per_cu_
),
25748 has_loclist (false),
25749 checked_producer (false),
25750 producer_is_gxx_lt_4_6 (false),
25751 producer_is_gcc_lt_4_3 (false),
25752 producer_is_icc (false),
25753 producer_is_icc_lt_14 (false),
25754 producer_is_codewarrior (false),
25755 processing_has_namespace_info (false)
25760 /* Destroy a dwarf2_cu. */
25762 dwarf2_cu::~dwarf2_cu ()
25767 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
25770 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
,
25771 enum language pretend_language
)
25773 struct attribute
*attr
;
25775 /* Set the language we're debugging. */
25776 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
25777 if (attr
!= nullptr)
25778 set_cu_language (DW_UNSND (attr
), cu
);
25781 cu
->language
= pretend_language
;
25782 cu
->language_defn
= language_def (cu
->language
);
25785 cu
->producer
= dwarf2_string_attr (comp_unit_die
, DW_AT_producer
, cu
);
25788 /* Increase the age counter on each cached compilation unit, and free
25789 any that are too old. */
25792 age_cached_comp_units (struct dwarf2_per_objfile
*dwarf2_per_objfile
)
25794 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25796 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
25797 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25798 while (per_cu
!= NULL
)
25800 per_cu
->cu
->last_used
++;
25801 if (per_cu
->cu
->last_used
<= dwarf_max_cache_age
)
25802 dwarf2_mark (per_cu
->cu
);
25803 per_cu
= per_cu
->cu
->read_in_chain
;
25806 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25807 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25808 while (per_cu
!= NULL
)
25810 struct dwarf2_per_cu_data
*next_cu
;
25812 next_cu
= per_cu
->cu
->read_in_chain
;
25814 if (!per_cu
->cu
->mark
)
25817 *last_chain
= next_cu
;
25820 last_chain
= &per_cu
->cu
->read_in_chain
;
25826 /* Remove a single compilation unit from the cache. */
25829 free_one_cached_comp_unit (struct dwarf2_per_cu_data
*target_per_cu
)
25831 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
25832 struct dwarf2_per_objfile
*dwarf2_per_objfile
25833 = target_per_cu
->dwarf2_per_objfile
;
25835 per_cu
= dwarf2_per_objfile
->read_in_chain
;
25836 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
25837 while (per_cu
!= NULL
)
25839 struct dwarf2_per_cu_data
*next_cu
;
25841 next_cu
= per_cu
->cu
->read_in_chain
;
25843 if (per_cu
== target_per_cu
)
25847 *last_chain
= next_cu
;
25851 last_chain
= &per_cu
->cu
->read_in_chain
;
25857 /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer.
25858 We store these in a hash table separate from the DIEs, and preserve them
25859 when the DIEs are flushed out of cache.
25861 The CU "per_cu" pointer is needed because offset alone is not enough to
25862 uniquely identify the type. A file may have multiple .debug_types sections,
25863 or the type may come from a DWO file. Furthermore, while it's more logical
25864 to use per_cu->section+offset, with Fission the section with the data is in
25865 the DWO file but we don't know that section at the point we need it.
25866 We have to use something in dwarf2_per_cu_data (or the pointer to it)
25867 because we can enter the lookup routine, get_die_type_at_offset, from
25868 outside this file, and thus won't necessarily have PER_CU->cu.
25869 Fortunately, PER_CU is stable for the life of the objfile. */
25871 struct dwarf2_per_cu_offset_and_type
25873 const struct dwarf2_per_cu_data
*per_cu
;
25874 sect_offset sect_off
;
25878 /* Hash function for a dwarf2_per_cu_offset_and_type. */
25881 per_cu_offset_and_type_hash (const void *item
)
25883 const struct dwarf2_per_cu_offset_and_type
*ofs
25884 = (const struct dwarf2_per_cu_offset_and_type
*) item
;
25886 return (uintptr_t) ofs
->per_cu
+ to_underlying (ofs
->sect_off
);
25889 /* Equality function for a dwarf2_per_cu_offset_and_type. */
25892 per_cu_offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
25894 const struct dwarf2_per_cu_offset_and_type
*ofs_lhs
25895 = (const struct dwarf2_per_cu_offset_and_type
*) item_lhs
;
25896 const struct dwarf2_per_cu_offset_and_type
*ofs_rhs
25897 = (const struct dwarf2_per_cu_offset_and_type
*) item_rhs
;
25899 return (ofs_lhs
->per_cu
== ofs_rhs
->per_cu
25900 && ofs_lhs
->sect_off
== ofs_rhs
->sect_off
);
25903 /* Set the type associated with DIE to TYPE. Save it in CU's hash
25904 table if necessary. For convenience, return TYPE.
25906 The DIEs reading must have careful ordering to:
25907 * Not cause infinite loops trying to read in DIEs as a prerequisite for
25908 reading current DIE.
25909 * Not trying to dereference contents of still incompletely read in types
25910 while reading in other DIEs.
25911 * Enable referencing still incompletely read in types just by a pointer to
25912 the type without accessing its fields.
25914 Therefore caller should follow these rules:
25915 * Try to fetch any prerequisite types we may need to build this DIE type
25916 before building the type and calling set_die_type.
25917 * After building type call set_die_type for current DIE as soon as
25918 possible before fetching more types to complete the current type.
25919 * Make the type as complete as possible before fetching more types. */
25921 static struct type
*
25922 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
25924 struct dwarf2_per_objfile
*dwarf2_per_objfile
25925 = cu
->per_cu
->dwarf2_per_objfile
;
25926 struct dwarf2_per_cu_offset_and_type
**slot
, ofs
;
25927 struct objfile
*objfile
= dwarf2_per_objfile
->objfile
;
25928 struct attribute
*attr
;
25929 struct dynamic_prop prop
;
25931 /* For Ada types, make sure that the gnat-specific data is always
25932 initialized (if not already set). There are a few types where
25933 we should not be doing so, because the type-specific area is
25934 already used to hold some other piece of info (eg: TYPE_CODE_FLT
25935 where the type-specific area is used to store the floatformat).
25936 But this is not a problem, because the gnat-specific information
25937 is actually not needed for these types. */
25938 if (need_gnat_info (cu
)
25939 && TYPE_CODE (type
) != TYPE_CODE_FUNC
25940 && TYPE_CODE (type
) != TYPE_CODE_FLT
25941 && TYPE_CODE (type
) != TYPE_CODE_METHODPTR
25942 && TYPE_CODE (type
) != TYPE_CODE_MEMBERPTR
25943 && TYPE_CODE (type
) != TYPE_CODE_METHOD
25944 && !HAVE_GNAT_AUX_INFO (type
))
25945 INIT_GNAT_SPECIFIC (type
);
25947 /* Read DW_AT_allocated and set in type. */
25948 attr
= dwarf2_attr (die
, DW_AT_allocated
, cu
);
25949 if (attr_form_is_block (attr
))
25951 struct type
*prop_type
25952 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25953 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25954 add_dyn_prop (DYN_PROP_ALLOCATED
, prop
, type
);
25956 else if (attr
!= NULL
)
25958 complaint (_("DW_AT_allocated has the wrong form (%s) at DIE %s"),
25959 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25960 sect_offset_str (die
->sect_off
));
25963 /* Read DW_AT_associated and set in type. */
25964 attr
= dwarf2_attr (die
, DW_AT_associated
, cu
);
25965 if (attr_form_is_block (attr
))
25967 struct type
*prop_type
25968 = dwarf2_per_cu_addr_sized_int_type (cu
->per_cu
, false);
25969 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
, prop_type
))
25970 add_dyn_prop (DYN_PROP_ASSOCIATED
, prop
, type
);
25972 else if (attr
!= NULL
)
25974 complaint (_("DW_AT_associated has the wrong form (%s) at DIE %s"),
25975 (attr
!= NULL
? dwarf_form_name (attr
->form
) : "n/a"),
25976 sect_offset_str (die
->sect_off
));
25979 /* Read DW_AT_data_location and set in type. */
25980 attr
= dwarf2_attr (die
, DW_AT_data_location
, cu
);
25981 if (attr_to_dynamic_prop (attr
, die
, cu
, &prop
,
25982 dwarf2_per_cu_addr_type (cu
->per_cu
)))
25983 add_dyn_prop (DYN_PROP_DATA_LOCATION
, prop
, type
);
25985 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
25987 dwarf2_per_objfile
->die_type_hash
=
25988 htab_create_alloc_ex (127,
25989 per_cu_offset_and_type_hash
,
25990 per_cu_offset_and_type_eq
,
25992 &objfile
->objfile_obstack
,
25993 hashtab_obstack_allocate
,
25994 dummy_obstack_deallocate
);
25997 ofs
.per_cu
= cu
->per_cu
;
25998 ofs
.sect_off
= die
->sect_off
;
26000 slot
= (struct dwarf2_per_cu_offset_and_type
**)
26001 htab_find_slot (dwarf2_per_objfile
->die_type_hash
, &ofs
, INSERT
);
26003 complaint (_("A problem internal to GDB: DIE %s has type already set"),
26004 sect_offset_str (die
->sect_off
));
26005 *slot
= XOBNEW (&objfile
->objfile_obstack
,
26006 struct dwarf2_per_cu_offset_and_type
);
26011 /* Look up the type for the die at SECT_OFF in PER_CU in die_type_hash,
26012 or return NULL if the die does not have a saved type. */
26014 static struct type
*
26015 get_die_type_at_offset (sect_offset sect_off
,
26016 struct dwarf2_per_cu_data
*per_cu
)
26018 struct dwarf2_per_cu_offset_and_type
*slot
, ofs
;
26019 struct dwarf2_per_objfile
*dwarf2_per_objfile
= per_cu
->dwarf2_per_objfile
;
26021 if (dwarf2_per_objfile
->die_type_hash
== NULL
)
26024 ofs
.per_cu
= per_cu
;
26025 ofs
.sect_off
= sect_off
;
26026 slot
= ((struct dwarf2_per_cu_offset_and_type
*)
26027 htab_find (dwarf2_per_objfile
->die_type_hash
, &ofs
));
26034 /* Look up the type for DIE in CU in die_type_hash,
26035 or return NULL if DIE does not have a saved type. */
26037 static struct type
*
26038 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
26040 return get_die_type_at_offset (die
->sect_off
, cu
->per_cu
);
26043 /* Add a dependence relationship from CU to REF_PER_CU. */
26046 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
26047 struct dwarf2_per_cu_data
*ref_per_cu
)
26051 if (cu
->dependencies
== NULL
)
26053 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
26054 NULL
, &cu
->comp_unit_obstack
,
26055 hashtab_obstack_allocate
,
26056 dummy_obstack_deallocate
);
26058 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
26060 *slot
= ref_per_cu
;
26063 /* Subroutine of dwarf2_mark to pass to htab_traverse.
26064 Set the mark field in every compilation unit in the
26065 cache that we must keep because we are keeping CU. */
26068 dwarf2_mark_helper (void **slot
, void *data
)
26070 struct dwarf2_per_cu_data
*per_cu
;
26072 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
26074 /* cu->dependencies references may not yet have been ever read if QUIT aborts
26075 reading of the chain. As such dependencies remain valid it is not much
26076 useful to track and undo them during QUIT cleanups. */
26077 if (per_cu
->cu
== NULL
)
26080 if (per_cu
->cu
->mark
)
26082 per_cu
->cu
->mark
= true;
26084 if (per_cu
->cu
->dependencies
!= NULL
)
26085 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26090 /* Set the mark field in CU and in every other compilation unit in the
26091 cache that we must keep because we are keeping CU. */
26094 dwarf2_mark (struct dwarf2_cu
*cu
)
26099 if (cu
->dependencies
!= NULL
)
26100 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
26104 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
26108 per_cu
->cu
->mark
= false;
26109 per_cu
= per_cu
->cu
->read_in_chain
;
26113 /* Trivial hash function for partial_die_info: the hash value of a DIE
26114 is its offset in .debug_info for this objfile. */
26117 partial_die_hash (const void *item
)
26119 const struct partial_die_info
*part_die
26120 = (const struct partial_die_info
*) item
;
26122 return to_underlying (part_die
->sect_off
);
26125 /* Trivial comparison function for partial_die_info structures: two DIEs
26126 are equal if they have the same offset. */
26129 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
26131 const struct partial_die_info
*part_die_lhs
26132 = (const struct partial_die_info
*) item_lhs
;
26133 const struct partial_die_info
*part_die_rhs
26134 = (const struct partial_die_info
*) item_rhs
;
26136 return part_die_lhs
->sect_off
== part_die_rhs
->sect_off
;
26139 struct cmd_list_element
*set_dwarf_cmdlist
;
26140 struct cmd_list_element
*show_dwarf_cmdlist
;
26143 set_dwarf_cmd (const char *args
, int from_tty
)
26145 help_list (set_dwarf_cmdlist
, "maintenance set dwarf ", all_commands
,
26150 show_dwarf_cmd (const char *args
, int from_tty
)
26152 cmd_show_list (show_dwarf_cmdlist
, from_tty
, "");
26155 bool dwarf_always_disassemble
;
26158 show_dwarf_always_disassemble (struct ui_file
*file
, int from_tty
,
26159 struct cmd_list_element
*c
, const char *value
)
26161 fprintf_filtered (file
,
26162 _("Whether to always disassemble "
26163 "DWARF expressions is %s.\n"),
26168 show_check_physname (struct ui_file
*file
, int from_tty
,
26169 struct cmd_list_element
*c
, const char *value
)
26171 fprintf_filtered (file
,
26172 _("Whether to check \"physname\" is %s.\n"),
26176 void _initialize_dwarf2_read ();
26178 _initialize_dwarf2_read ()
26180 add_prefix_cmd ("dwarf", class_maintenance
, set_dwarf_cmd
, _("\
26181 Set DWARF specific variables.\n\
26182 Configure DWARF variables such as the cache size."),
26183 &set_dwarf_cmdlist
, "maintenance set dwarf ",
26184 0/*allow-unknown*/, &maintenance_set_cmdlist
);
26186 add_prefix_cmd ("dwarf", class_maintenance
, show_dwarf_cmd
, _("\
26187 Show DWARF specific variables.\n\
26188 Show DWARF variables such as the cache size."),
26189 &show_dwarf_cmdlist
, "maintenance show dwarf ",
26190 0/*allow-unknown*/, &maintenance_show_cmdlist
);
26192 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
26193 &dwarf_max_cache_age
, _("\
26194 Set the upper bound on the age of cached DWARF compilation units."), _("\
26195 Show the upper bound on the age of cached DWARF compilation units."), _("\
26196 A higher limit means that cached compilation units will be stored\n\
26197 in memory longer, and more total memory will be used. Zero disables\n\
26198 caching, which can slow down startup."),
26200 show_dwarf_max_cache_age
,
26201 &set_dwarf_cmdlist
,
26202 &show_dwarf_cmdlist
);
26204 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
26205 &dwarf_always_disassemble
, _("\
26206 Set whether `info address' always disassembles DWARF expressions."), _("\
26207 Show whether `info address' always disassembles DWARF expressions."), _("\
26208 When enabled, DWARF expressions are always printed in an assembly-like\n\
26209 syntax. When disabled, expressions will be printed in a more\n\
26210 conversational style, when possible."),
26212 show_dwarf_always_disassemble
,
26213 &set_dwarf_cmdlist
,
26214 &show_dwarf_cmdlist
);
26216 add_setshow_zuinteger_cmd ("dwarf-read", no_class
, &dwarf_read_debug
, _("\
26217 Set debugging of the DWARF reader."), _("\
26218 Show debugging of the DWARF reader."), _("\
26219 When enabled (non-zero), debugging messages are printed during DWARF\n\
26220 reading and symtab expansion. A value of 1 (one) provides basic\n\
26221 information. A value greater than 1 provides more verbose information."),
26224 &setdebuglist
, &showdebuglist
);
26226 add_setshow_zuinteger_cmd ("dwarf-die", no_class
, &dwarf_die_debug
, _("\
26227 Set debugging of the DWARF DIE reader."), _("\
26228 Show debugging of the DWARF DIE reader."), _("\
26229 When enabled (non-zero), DIEs are dumped after they are read in.\n\
26230 The value is the maximum depth to print."),
26233 &setdebuglist
, &showdebuglist
);
26235 add_setshow_zuinteger_cmd ("dwarf-line", no_class
, &dwarf_line_debug
, _("\
26236 Set debugging of the dwarf line reader."), _("\
26237 Show debugging of the dwarf line reader."), _("\
26238 When enabled (non-zero), line number entries are dumped as they are read in.\n\
26239 A value of 1 (one) provides basic information.\n\
26240 A value greater than 1 provides more verbose information."),
26243 &setdebuglist
, &showdebuglist
);
26245 add_setshow_boolean_cmd ("check-physname", no_class
, &check_physname
, _("\
26246 Set cross-checking of \"physname\" code against demangler."), _("\
26247 Show cross-checking of \"physname\" code against demangler."), _("\
26248 When enabled, GDB's internal \"physname\" code is checked against\n\
26250 NULL
, show_check_physname
,
26251 &setdebuglist
, &showdebuglist
);
26253 add_setshow_boolean_cmd ("use-deprecated-index-sections",
26254 no_class
, &use_deprecated_index_sections
, _("\
26255 Set whether to use deprecated gdb_index sections."), _("\
26256 Show whether to use deprecated gdb_index sections."), _("\
26257 When enabled, deprecated .gdb_index sections are used anyway.\n\
26258 Normally they are ignored either because of a missing feature or\n\
26259 performance issue.\n\
26260 Warning: This option must be enabled before gdb reads the file."),
26263 &setlist
, &showlist
);
26265 dwarf2_locexpr_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26266 &dwarf2_locexpr_funcs
);
26267 dwarf2_loclist_index
= register_symbol_computed_impl (LOC_COMPUTED
,
26268 &dwarf2_loclist_funcs
);
26270 dwarf2_locexpr_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26271 &dwarf2_block_frame_base_locexpr_funcs
);
26272 dwarf2_loclist_block_index
= register_symbol_block_impl (LOC_BLOCK
,
26273 &dwarf2_block_frame_base_loclist_funcs
);
26276 selftests::register_test ("dw2_expand_symtabs_matching",
26277 selftests::dw2_expand_symtabs_matching::run_test
);